a45e701cb1c4eb63111a35d500b38eaef8453fe0
[WebKit-https.git] / Tools / TestWebKitAPI / Tests / WebKit2Gtk / TestDOMXPathNSResolver.cpp
1 /*
2  * Copyright (C) 2014 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 runTest(WebViewTest* test, const char* name)
30 {
31     GVariantBuilder builder;
32     g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
33     g_variant_builder_add(&builder, "{sv}", "pageID", g_variant_new_uint64(webkit_web_view_get_page_id(test->m_webView)));
34     g_assert(testRunner->runTest("WebKitDOMXPathNSResolver", name, Test::s_webExtensionID, g_variant_builder_end(&builder)));
35 }
36
37 static void testWebKitDOMXPathNSResolverNative(WebViewTest* test, gconstpointer)
38 {
39     static const char* nativeXML = "<root xmlns:foo='http://www.example.org'><foo:child>SUCCESS</foo:child></root>";
40     GRefPtr<GBytes> bytes = adoptGRef(g_bytes_new_static(nativeXML, strlen(nativeXML)));
41     test->loadBytes(bytes.get(), "text/xml", nullptr, nullptr);
42     test->waitUntilLoadFinished();
43     runTest(test, "native");
44 }
45
46 static void testWebKitDOMXPathNSResolverCustom(WebViewTest* test, gconstpointer)
47 {
48     static const char* customXML = "<root xmlns='http://www.example.com'><child>SUCCESS</child></root>";
49     GRefPtr<GBytes> bytes = adoptGRef(g_bytes_new_static(customXML, strlen(customXML)));
50     test->loadBytes(bytes.get(), "text/xml", nullptr, nullptr);
51     test->waitUntilLoadFinished();
52     runTest(test, "custom");
53 }
54
55 void beforeAll()
56 {
57     testRunner = new WebProcessTestRunner();
58
59     WebViewTest::add("WebKitDOMXPathNSResolver", "native", testWebKitDOMXPathNSResolverNative);
60     WebViewTest::add("WebKitDOMXPathNSResolver", "custom", testWebKitDOMXPathNSResolverCustom);
61 }
62
63 void afterAll()
64 {
65     delete testRunner;
66 }