6327bde92a66dea3e427a3dd22ba1110c0314993
[WebKit-https.git] / Tools / TestWebKitAPI / Tests / WebKit2Gtk / TestDOMNode.cpp
1 /*
2  * Copyright (C) 2013 Igalia S.L.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2,1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include "config.h"
21
22 #include "WebProcessTestRunner.h"
23 #include "WebViewTest.h"
24 #include <gtk/gtk.h>
25 #include <webkit2/webkit2.h>
26
27 static WebProcessTestRunner* testRunner;
28
29 static void testWebKitDOMNodeHierarchyNavigation(WebViewTest* test, gconstpointer)
30 {
31     static const char* testHTML = "<html><head><title>This is the title</title></head><body><p>1</p><p>2</p><p>3</p></body></html>";
32     test->loadHtml(testHTML, 0);
33     test->waitUntilLoadFinished();
34
35     GVariantBuilder builder;
36     g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
37     g_variant_builder_add(&builder, "{sv}", "pageID", g_variant_new_uint64(webkit_web_view_get_page_id(test->m_webView)));
38     g_assert(testRunner->runTest("WebKitDOMNode", "hierarchy-navigation", Test::s_webExtensionID, g_variant_builder_end(&builder)));
39 }
40
41 static void testWebKitDOMNodeInsertion(WebViewTest* test, gconstpointer)
42 {
43     static const char* testHTML = "<html><body></body></html>";
44     test->loadHtml(testHTML, 0);
45     test->waitUntilLoadFinished();
46
47     GVariantBuilder builder;
48     g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
49     g_variant_builder_add(&builder, "{sv}", "pageID", g_variant_new_uint64(webkit_web_view_get_page_id(test->m_webView)));
50     g_assert(testRunner->runTest("WebKitDOMNode", "insertion", Test::s_webExtensionID, g_variant_builder_end(&builder)));
51 }
52
53 static void testWebKitDOMNodeTagNames(WebViewTest* test, gconstpointer)
54 {
55     static const char* testHTML = "<html><head></head><body>"
56         "<video id='video' preload='none'>"
57         "    <source src='movie.ogg' type='video/ogg'>"
58         "        Your browser does not support the video tag."
59         "</video>"
60         "<video id='video2' preload='none'>"
61         "     <source src='movie.ogg' type='video/ogg'>"
62         "        Your browser does not support the video tag."
63         "</video>"
64         "<input type='hidden' id='test' name='finish' value='false'></body></html>";
65     test->loadHtml(testHTML, 0);
66     test->waitUntilLoadFinished();
67
68     GVariantBuilder builder;
69     g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
70     g_variant_builder_add(&builder, "{sv}", "pageID", g_variant_new_uint64(webkit_web_view_get_page_id(test->m_webView)));
71     g_assert(testRunner->runTest("WebKitDOMNode", "tag-names", Test::s_webExtensionID, g_variant_builder_end(&builder)));
72 }
73
74 void beforeAll()
75 {
76     testRunner = new WebProcessTestRunner();
77
78     WebViewTest::add("WebKitDOMNode", "hierarchy-navigation", testWebKitDOMNodeHierarchyNavigation);
79     WebViewTest::add("WebKitDOMNode", "insertion", testWebKitDOMNodeInsertion);
80     WebViewTest::add("WebKitDOMNode", "tag-names", testWebKitDOMNodeTagNames);
81 }
82
83 void afterAll()
84 {
85     delete testRunner;
86 }