diff options
author | Konstantin Tokarev <annulen@yandex.ru> | 2016-08-25 19:20:41 +0300 |
---|---|---|
committer | Konstantin Tokarev <annulen@yandex.ru> | 2017-02-02 12:30:55 +0000 |
commit | 6882a04fb36642862b11efe514251d32070c3d65 (patch) | |
tree | b7959826000b061fd5ccc7512035c7478742f7b0 /Source/WebKit2/UIProcess/API/gtk/tests | |
parent | ab6df191029eeeb0b0f16f127d553265659f739e (diff) | |
download | qtwebkit-6882a04fb36642862b11efe514251d32070c3d65.tar.gz |
Imported QtWebKit TP3 (git b57bc6801f1876c3220d5a4bfea33d620d477443)
Change-Id: I3b1d8a2808782c9f34d50240000e20cb38d3680f
Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'Source/WebKit2/UIProcess/API/gtk/tests')
39 files changed, 0 insertions, 9757 deletions
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/AccessibilityTestServer.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/AccessibilityTestServer.cpp deleted file mode 100644 index a8bbbc3fa..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/AccessibilityTestServer.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2,1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include <gtk/gtk.h> -#include <webkit2/webkit2.h> - -static void loadChangedCallback(WebKitWebView*, WebKitLoadEvent loadEvent, gpointer) -{ - // Send a message to the parent process when we're ready. - if (loadEvent == WEBKIT_LOAD_FINISHED) - g_print("OK"); -} - -int main(int argc, char** argv) -{ - // Make sure that both GAIL and the ATK bridge are loaded. - g_setenv("GTK_MODULES", "gail:atk-bridge", TRUE); - - gtk_init(&argc, &argv); - - WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); - webkit_web_view_load_html(webView, - "<html>" - " <body>" - " <h1>This is a test</h1>" - " <p>This is a paragraph with some plain text.</p>" - " <p>This paragraph contains <a href=\"http://www.webkitgtk.org\">a link</a> in the middle.</p>" - " </body>" - "</html>", - 0); - - GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(webView)); - gtk_widget_show_all(window); - - g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), 0); - g_signal_connect(webView, "load-changed", G_CALLBACK(loadChangedCallback), 0); - - gtk_main(); -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am b/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am deleted file mode 100644 index 7510b617c..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am +++ /dev/null @@ -1,271 +0,0 @@ -if ENABLE_WEBKIT2 - -TEST_PROGS += \ - Programs/WebKit2APITests/InspectorTestServer \ - Programs/WebKit2APITests/TestBackForwardList \ - Programs/WebKit2APITests/TestContextMenu \ - Programs/WebKit2APITests/TestCookieManager \ - Programs/WebKit2APITests/TestDownloads \ - Programs/WebKit2APITests/TestInspector \ - Programs/WebKit2APITests/TestInspectorServer \ - Programs/WebKit2APITests/TestLoaderClient \ - Programs/WebKit2APITests/TestPrinting \ - Programs/WebKit2APITests/TestResources \ - Programs/WebKit2APITests/TestSSL \ - Programs/WebKit2APITests/TestWebExtensions \ - Programs/WebKit2APITests/TestWebKitVersion \ - Programs/WebKit2APITests/TestWebKitFaviconDatabase \ - Programs/WebKit2APITests/TestWebKitFindController \ - Programs/WebKit2APITests/TestWebKitPolicyClient \ - Programs/WebKit2APITests/TestWebKitSettings \ - Programs/WebKit2APITests/TestWebKitWebContext \ - Programs/WebKit2APITests/TestWebKitWebView \ - Programs/WebKit2APITests/TestWebKitWebViewGroup \ - Programs/WebKit2APITests/TestWebViewEditor - -noinst_PROGRAMS += $(TEST_PROGS) - -if HAVE_ATSPI2 -TEST_PROGS += Programs/WebKit2APITests/TestWebKitAccessibility - -noinst_PROGRAMS += Programs/WebKit2APITests/AccessibilityTestServer -endif - -webkit2_tests_cppflags = \ - -DWEBKIT_EXEC_PATH=\"${shell pwd}/$(top_builddir)/Programs\" \ - -DWEBKIT_SRC_DIR=\"${shell pwd}/${srcdir}\" \ - -DWEBKIT_DERIVED_SRC_DIR=\"${shell pwd}/${top_builddir}/DerivedSources\" \ - -DWEBKIT_TEST_PLUGIN_DIR=\"${shell pwd}/${top_builddir}/TestNetscapePlugin/.libs\" \ - -DWEBKIT_TEST_WEB_EXTENSIONS_DIR=\"${shell pwd}/${top_builddir}/Libraries/WebExtensions/.libs\" \ - -DWEBKIT_INJECTED_BUNDLE_PATH=\"${shell pwd}/$(top_builddir)/.libs\" \ - $(javascriptcore_cppflags) \ - -I$(srcdir)/Source/JavaScriptCore \ - -I$(srcdir)/Source \ - -I$(srcdir)/Source/WebKit2 \ - -I$(top_builddir)/DerivedSources/WebKit2/include \ - -I$(top_builddir)/DerivedSources/WebKit2/webkit2gtk \ - -I$(top_builddir)/DerivedSources/WebKit2/webkit2gtk/include \ - -I$(srcdir)/Source/WebKit2/UIProcess/API/gtk \ - $(global_cppflags) \ - $(FREETYPE_CFLAGS) \ - $(GLIB_CFLAGS) \ - $(GTK_CFLAGS) \ - $(LIBSOUP_CFLAGS) - -webkit2_tests_ldadd = \ - Libraries/libWebKit2APITestCore.la \ - libjavascriptcoregtk-@WEBKITGTK_API_MAJOR_VERSION@.@WEBKITGTK_API_MINOR_VERSION@.la \ - libwebkit2gtk-@WEBKITGTK_API_MAJOR_VERSION@.@WEBKITGTK_API_MINOR_VERSION@.la \ - $(FREETYPE_LIBS) \ - $(GEOCLUE_LIBS) \ - $(GLIB_LIBS) \ - $(GTK_LIBS) \ - $(LIBSOUP_LIBS) - -webkit2_tests_ldflags = \ - -no-install \ - -no-fast-install - -Programs/resources/webkit2gtk-tests-resources.gresource: Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml) - $(AM_V_at)mkdir -p ${GENPROGRAMS}/resources - $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) $< - -Programs/resources/inspector/inspectorPageIndex.html: Source/WebKit2/UIProcess/InspectorServer/front-end/inspectorPageIndex.html - $(AM_V_at)mkdir -p ${GENPROGRAMS}/resources/inspector - $(AM_V_GEN)cp $(srcdir)/Source/WebKit2/UIProcess/InspectorServer/front-end/inspectorPageIndex.html ${GENPROGRAMS}/resources/inspector - -DISTCLEANFILES += \ - Programs/resources/webkit2gtk-tests-resources.gresource \ - Programs/resources/inspector/inspectorPageIndex.html - -noinst_DATA += \ - Programs/resources/webkit2gtk-tests-resources.gresource \ - Programs/resources/inspector/inspectorPageIndex.html - -noinst_LTLIBRARIES += Libraries/libWebKit2APITestCore.la -Libraries_libWebKit2APITestCore_la_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp \ - Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h \ - Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.cpp \ - Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.h \ - Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.cpp \ - Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.h \ - Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp \ - Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h \ - Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp \ - Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h -Libraries_libWebKit2APITestCore_la_CPPFLAGS = $(webkit2_tests_cppflags) - -noinst_LTLIBRARIES += Libraries/WebExtensions/libWebExtensionTest.la -Libraries_WebExtensions_libWebExtensionTest_la_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp - -Libraries_WebExtensions_libWebExtensionTest_la_LDFLAGS = \ - -rpath ${shell pwd}/$(top_builddir)/Libraries/WebExtensions/.libs \ - $(no_undefined) \ - -avoid-version \ - -module - -Libraries_WebExtensions_libWebExtensionTest_la_CPPFLAGS = \ - -I$(srcdir)/Source/WebKit2/WebProcess/InjectedBundle/API/gtk \ - -I$(top_builddir)/DerivedSources \ - -I$(top_builddir)/DerivedSources/WebKit2/webkit2extension/include \ - -DWEBKIT2_COMPILATION \ - $(webkit2_tests_cppflags) - -Libraries_WebExtensions_libWebExtensionTest_la_CXXFLAGS = \ - $(global_cxxflags) - -Libraries_WebExtensions_libWebExtensionTest_la_CFLAGS = \ - $(global_cflags) - - -EXTRA_DIST += \ - Source/WebKit2/UIProcess/API/gtk/tests/resources/test-cert.pem \ - Source/WebKit2/UIProcess/API/gtk/tests/resources/test-key.pem \ - Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml \ - Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js - -Programs_WebKit2APITests_TestWebKitWebContext_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp -Programs_WebKit2APITests_TestWebKitWebContext_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestWebKitWebContext_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestWebKitWebContext_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestWebKitWebView_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp -Programs_WebKit2APITests_TestWebKitWebView_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestWebKitWebView_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestWebKitWebView_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestLoaderClient_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp -Programs_WebKit2APITests_TestLoaderClient_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestLoaderClient_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestLoaderClient_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestWebKitSettings_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp -Programs_WebKit2APITests_TestWebKitSettings_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestWebKitSettings_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestWebKitSettings_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_InspectorTestServer_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/InspectorTestServer.cpp -Programs_WebKit2APITests_InspectorTestServer_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_InspectorTestServer_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_InspectorTestServer_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestBackForwardList_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp -Programs_WebKit2APITests_TestBackForwardList_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestBackForwardList_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestBackForwardList_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestWebKitPolicyClient_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp -Programs_WebKit2APITests_TestWebKitPolicyClient_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestWebKitPolicyClient_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestWebKitPolicyClient_LDFLAGS = $(webkit2_tests_ldflags) - -if HAVE_ATSPI2 -Programs_WebKit2APITests_AccessibilityTestServer_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/AccessibilityTestServer.cpp -Programs_WebKit2APITests_AccessibilityTestServer_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_AccessibilityTestServer_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_AccessibilityTestServer_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestWebKitAccessibility_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitAccessibility.cpp -Programs_WebKit2APITests_TestWebKitAccessibility_CPPFLAGS = $(webkit2_tests_cppflags) $(ATSPI2_CFLAGS) -Programs_WebKit2APITests_TestWebKitAccessibility_LDADD = $(webkit2_tests_ldadd) $(ATSPI2_LIBS) -Programs_WebKit2APITests_TestWebKitAccessibility_LDFLAGS = $(webkit2_tests_ldflags) -endif - -Programs_WebKit2APITests_TestDownloads_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestDownloads.cpp -Programs_WebKit2APITests_TestDownloads_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestDownloads_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestDownloads_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestWebViewEditor_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestWebViewEditor.cpp -Programs_WebKit2APITests_TestWebViewEditor_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestWebViewEditor_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestWebViewEditor_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestPrinting_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp -Programs_WebKit2APITests_TestPrinting_CPPFLAGS = $(webkit2_tests_cppflags) $(GTK_UNIX_PRINTING_CFLAGS) -Programs_WebKit2APITests_TestPrinting_LDADD = $(webkit2_tests_ldadd) $(GTK_UNIX_PRINTING_LIBS) -Programs_WebKit2APITests_TestPrinting_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestWebKitFaviconDatabase_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp -Programs_WebKit2APITests_TestWebKitFaviconDatabase_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestWebKitFaviconDatabase_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestWebKitFaviconDatabase_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestWebKitFindController_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp -Programs_WebKit2APITests_TestWebKitFindController_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestWebKitFindController_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestWebKitFindController_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestResources_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp -Programs_WebKit2APITests_TestResources_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestResources_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestResources_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestCookieManager_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp -Programs_WebKit2APITests_TestCookieManager_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestCookieManager_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestCookieManager_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestInspector_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestInspector.cpp -Programs_WebKit2APITests_TestInspector_CPPFLAGS = \ - -DWEBKIT_INSPECTOR_PATH=\"${shell pwd}/${top_builddir}/resources/inspector\" \ - $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestInspector_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestInspector_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestInspectorServer_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestInspectorServer.cpp -Programs_WebKit2APITests_TestInspectorServer_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestInspectorServer_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestInspectorServer_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestWebKitVersion_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitVersion.cpp -Programs_WebKit2APITests_TestWebKitVersion_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestWebKitVersion_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestWebKitVersion_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestContextMenu_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestContextMenu.cpp -Programs_WebKit2APITests_TestContextMenu_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestContextMenu_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestContextMenu_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestSSL_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp -Programs_WebKit2APITests_TestSSL_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestSSL_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestSSL_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestWebExtensions_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestWebExtensions.cpp -Programs_WebKit2APITests_TestWebExtensions_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestWebExtensions_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestWebExtensions_LDFLAGS = $(webkit2_tests_ldflags) - -Programs_WebKit2APITests_TestWebKitWebViewGroup_SOURCES = \ - Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebViewGroup.cpp -Programs_WebKit2APITests_TestWebKitWebViewGroup_CPPFLAGS = $(webkit2_tests_cppflags) -Programs_WebKit2APITests_TestWebKitWebViewGroup_LDADD = $(webkit2_tests_ldadd) -Programs_WebKit2APITests_TestWebKitWebViewGroup_LDFLAGS = $(webkit2_tests_ldflags) - -endif # ENABLE_WEBKIT2 diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/InspectorTestServer.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/InspectorTestServer.cpp deleted file mode 100644 index 7c9dc900c..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/InspectorTestServer.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2012 Samsung Electronics Ltd. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#include <gtk/gtk.h> -#include <webkit2/webkit2.h> - -static void loadChangedCallback(WebKitWebView*, WebKitLoadEvent loadEvent, gpointer) -{ - // Send a message to the parent process when we're ready. - if (loadEvent == WEBKIT_LOAD_FINISHED) - g_print("OK"); -} - -int main(int argc, char** argv) -{ - gtk_init(&argc, &argv); - - // Overwrite WEBKIT_INSPECTOR_SERVER variable with default value. - g_setenv("WEBKIT_INSPECTOR_SERVER", "127.0.0.1:2999", TRUE); - - // Overwrite WEBKIT_INSPECTOR_SERVER_PATH variable to point to inspector resources folder. - const gchar* inspectorResourcesPath = g_getenv("WEBKIT_INSPECTOR_PATH"); - g_setenv("WEBKIT_INSPECTOR_SERVER_PATH", inspectorResourcesPath, TRUE); - - WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); - webkit_settings_set_enable_developer_extras(webkit_web_view_get_settings(webView), TRUE); - webkit_web_view_load_html(webView, - "<html><body><p>WebKitGTK+ Inspector Test Server</p></body></html>", - "http://127.0.0.1:2999/"); - - GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(webView)); - gtk_widget_show_all(window); - - g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), 0); - g_signal_connect(webView, "load-changed", G_CALLBACK(loadChangedCallback), 0); - - gtk_main(); -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp deleted file mode 100644 index df3420492..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) 2011 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "LoadTrackingTest.h" - -#include <webkit2/webkit2.h> - -static void loadChangedCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, LoadTrackingTest* test) -{ - switch (loadEvent) { - case WEBKIT_LOAD_STARTED: - g_assert(webkit_web_view_is_loading(webView)); - g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(webView)); - test->provisionalLoadStarted(); - break; - case WEBKIT_LOAD_REDIRECTED: - g_assert(webkit_web_view_is_loading(webView)); - test->m_activeURI = webkit_web_view_get_uri(webView); - if (!test->m_redirectURI.isNull()) - g_assert_cmpstr(test->m_redirectURI.data(), ==, test->m_activeURI.data()); - test->provisionalLoadReceivedServerRedirect(); - break; - case WEBKIT_LOAD_COMMITTED: { - g_assert(webkit_web_view_is_loading(webView)); - g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(webView)); - - // Check that on committed we always have a main resource with a response. - WebKitWebResource* resource = webkit_web_view_get_main_resource(webView); - g_assert(resource); - g_assert(webkit_web_resource_get_response(resource)); - - test->loadCommitted(); - break; - } - case WEBKIT_LOAD_FINISHED: - g_assert(!webkit_web_view_is_loading(webView)); - if (!test->m_loadFailed) - g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(webView)); - test->loadFinished(); - break; - default: - g_assert_not_reached(); - } -} - -static void loadFailedCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, const char* failingURI, GError* error, LoadTrackingTest* test) -{ - test->m_loadFailed = true; - test->m_error.set(g_error_copy(error)); - - switch (loadEvent) { - case WEBKIT_LOAD_STARTED: - g_assert(!webkit_web_view_is_loading(webView)); - g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(webView)); - g_assert(error); - test->provisionalLoadFailed(failingURI, error); - break; - case WEBKIT_LOAD_COMMITTED: - g_assert(!webkit_web_view_is_loading(webView)); - g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(webView)); - g_assert(error); - test->loadFailed(failingURI, error); - break; - default: - g_assert_not_reached(); - } -} - -static void estimatedProgressChangedCallback(GObject*, GParamSpec*, LoadTrackingTest* test) -{ - test->estimatedProgressChanged(); -} - -LoadTrackingTest::LoadTrackingTest() - : m_runLoadUntilCompletion(false) - , m_loadFailed(false) -{ - g_signal_connect(m_webView, "load-changed", G_CALLBACK(loadChangedCallback), this); - g_signal_connect(m_webView, "load-failed", G_CALLBACK(loadFailedCallback), this); - g_signal_connect(m_webView, "notify::estimated-load-progress", G_CALLBACK(estimatedProgressChangedCallback), this); - - g_assert(!webkit_web_view_get_uri(m_webView)); -} - -LoadTrackingTest::~LoadTrackingTest() -{ - g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); -} - -void LoadTrackingTest::waitUntilLoadFinished() -{ - m_estimatedProgress = 0; - m_runLoadUntilCompletion = true; - g_main_loop_run(m_mainLoop); -} - -void LoadTrackingTest::provisionalLoadStarted() -{ - m_loadEvents.append(ProvisionalLoadStarted); -} - -void LoadTrackingTest::provisionalLoadReceivedServerRedirect() -{ - m_loadEvents.append(ProvisionalLoadReceivedServerRedirect); -} - -void LoadTrackingTest::provisionalLoadFailed(const gchar* failingURI, GError* error) -{ - m_loadEvents.append(ProvisionalLoadFailed); -} - -void LoadTrackingTest::loadCommitted() -{ - m_loadEvents.append(LoadCommitted); -} - -void LoadTrackingTest::loadFinished() -{ - m_loadEvents.append(LoadFinished); - if (m_runLoadUntilCompletion) - g_main_loop_quit(m_mainLoop); -} - -void LoadTrackingTest::loadFailed(const gchar* failingURI, GError* error) -{ - m_loadEvents.append(LoadFailed); -} - -void LoadTrackingTest::estimatedProgressChanged() -{ - double progress = webkit_web_view_get_estimated_load_progress(m_webView); - g_assert_cmpfloat(m_estimatedProgress, <, progress); - m_estimatedProgress = progress; -} - -void LoadTrackingTest::loadURI(const char* uri) -{ - m_loadEvents.clear(); - m_estimatedProgress = 0; - m_error.clear(); - WebViewTest::loadURI(uri); -} - -void LoadTrackingTest::loadHtml(const char* html, const char* baseURI) -{ - m_loadEvents.clear(); - m_estimatedProgress = 0; - m_error.clear(); - WebViewTest::loadHtml(html, baseURI); -} - -void LoadTrackingTest::loadPlainText(const char* plainText) -{ - m_loadEvents.clear(); - m_estimatedProgress = 0; - m_error.clear(); - WebViewTest::loadPlainText(plainText); -} - -void LoadTrackingTest::loadRequest(WebKitURIRequest* request) -{ - m_loadEvents.clear(); - m_estimatedProgress = 0; - m_error.clear(); - WebViewTest::loadRequest(request); -} - -void LoadTrackingTest::reload() -{ - m_loadEvents.clear(); - m_estimatedProgress = 0; - m_error.clear(); - webkit_web_view_reload(m_webView); -} - -void LoadTrackingTest::goBack() -{ - m_loadEvents.clear(); - m_estimatedProgress = 0; - m_error.clear(); - WebViewTest::goBack(); -} - -void LoadTrackingTest::goForward() -{ - m_loadEvents.clear(); - m_estimatedProgress = 0; - m_error.clear(); - WebViewTest::goForward(); -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h b/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h deleted file mode 100644 index a3cf7843d..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2011 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef LoadTrackingTest_h -#define LoadTrackingTest_h - -#include "TestMain.h" -#include "WebViewTest.h" -#include <wtf/Vector.h> - -class LoadTrackingTest : public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(LoadTrackingTest); - LoadTrackingTest(); - virtual ~LoadTrackingTest(); - void waitUntilLoadFinished(); - - virtual void provisionalLoadStarted(); - virtual void provisionalLoadReceivedServerRedirect(); - virtual void provisionalLoadFailed(const gchar* failingURI, GError*); - virtual void loadCommitted(); - virtual void loadFinished(); - virtual void loadFailed(const char* failingURI, GError*); - virtual void estimatedProgressChanged(); - - void loadURI(const char* uri); - void loadHtml(const char* html, const char* baseURI); - void loadPlainText(const char* plainText); - void loadRequest(WebKitURIRequest*); - void reload(); - void goBack(); - void goForward(); - - void setRedirectURI(const char* uri) { m_redirectURI = uri; } - - enum LoadEvents { - ProvisionalLoadStarted, - ProvisionalLoadReceivedServerRedirect, - ProvisionalLoadFailed, - LoadCommitted, - LoadFinished, - LoadFailed - }; - bool m_runLoadUntilCompletion; - bool m_loadFailed; - GOwnPtr<GError> m_error; - Vector<LoadEvents> m_loadEvents; - float m_estimatedProgress; - CString m_redirectURI; -}; - -#endif // LoadTrackingTest_h diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp deleted file mode 100644 index b479366a4..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright (C) 2011 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include "WebKitTestServer.h" -#include "WebViewTest.h" -#include <gtk/gtk.h> -#include <libsoup/soup.h> -#include <string.h> -#include <webkit2/webkit2.h> - -// Back forward list limit is 100 by default. -static const int kBackForwardListLimit = 100; - -static WebKitTestServer* kServer; - -static void serverCallback(SoupServer* server, SoupMessage* msg, const char* path, GHashTable* query, SoupClientContext* context, gpointer data) -{ - if (msg->method != SOUP_METHOD_GET) { - soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED); - return; - } - - if (g_str_has_suffix(path, "favicon.ico")) { - soup_message_set_status(msg, SOUP_STATUS_NOT_FOUND); - return; - } - - soup_message_set_status(msg, SOUP_STATUS_OK); - - char* body = g_strdup_printf("<html><title>%s</title><body>%s</body></html>", path + 1, path + 1); - soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, body, strlen(body)); - - soup_message_body_complete(msg->response_body); -} - -class BackForwardListTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(BackForwardListTest); - - enum { - Backward, - Forward - }; - - enum { - CurrentItem = 1 << 0, - AddedItem = 1 << 1, - RemovedItems = 1 << 2 - }; - - static void checkItem(WebKitBackForwardListItem* item, const char* title, const char* uri, const char* originalURI) - { - g_assert(item); - g_assert_cmpstr(webkit_back_forward_list_item_get_uri(item), ==, uri); - g_assert_cmpstr(webkit_back_forward_list_item_get_title(item), == , title); - g_assert_cmpstr(webkit_back_forward_list_item_get_original_uri(item), ==, originalURI); - } - - static void checkItemIndex(WebKitBackForwardList* list) - { - g_assert(webkit_back_forward_list_get_nth_item(list, -1) == webkit_back_forward_list_get_back_item(list)); - g_assert(webkit_back_forward_list_get_nth_item(list, 0) == webkit_back_forward_list_get_current_item(list)); - g_assert(webkit_back_forward_list_get_nth_item(list, 1) == webkit_back_forward_list_get_forward_item(list)); - } - - static void checkList(WebKitBackForwardList* list, unsigned type, WebKitBackForwardListItem** items, unsigned nItems) - { - GList* listItems = type == BackForwardListTest::Backward ? webkit_back_forward_list_get_back_list(list) : - webkit_back_forward_list_get_forward_list(list); - g_assert(listItems); - - unsigned i = 0; - for (GList* listItem = listItems; listItem; listItem = g_list_next(listItem), i++) { - g_assert_cmpuint(i, <, nItems); - g_assert(listItem->data == items[i]); - } - g_list_free(listItems); - } - - static void backForwardListChanged(WebKitBackForwardList* list, WebKitBackForwardListItem* addedItem, GList* removedItems, BackForwardListTest* test) - { - test->m_hasChanged = true; - - if (test->m_changedFlags & BackForwardListTest::AddedItem) { - g_assert(WEBKIT_IS_BACK_FORWARD_LIST_ITEM(addedItem)); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(addedItem)); - } else - g_assert(!addedItem); - - if (test->m_changedFlags & BackForwardListTest::RemovedItems) { - g_assert(removedItems); - for (GList* iter = removedItems; iter; iter = iter->next) { - g_assert(WEBKIT_IS_BACK_FORWARD_LIST_ITEM(iter->data)); - if (test->m_expectedRemovedItems) - g_assert(g_list_find(test->m_expectedRemovedItems, iter->data)); - } - - } else - g_assert(!removedItems); - } - - BackForwardListTest() - : m_list(webkit_web_view_get_back_forward_list(m_webView)) - , m_changedFlags(0) - , m_hasChanged(false) - , m_expectedRemovedItems(0) - { - g_signal_connect(m_list, "changed", G_CALLBACK(backForwardListChanged), this); - assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_list)); - } - - ~BackForwardListTest() - { - g_signal_handlers_disconnect_matched(m_list, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); - } - - void waitUntilLoadFinished() - { - m_hasChanged = false; - WebViewTest::waitUntilLoadFinished(); - g_assert(m_hasChanged); - } - - void waitUntilLoadFinishedAndCheckRemovedItems(GList* removedItems) - { - m_expectedRemovedItems = removedItems; - waitUntilLoadFinished(); - m_expectedRemovedItems = 0; - } - - WebKitBackForwardList* m_list; - unsigned long m_changedFlags; - bool m_hasChanged; - GList* m_expectedRemovedItems; -}; - -static void testBackForwardListNavigation(BackForwardListTest* test, gconstpointer) -{ - WebKitBackForwardListItem* items[1]; - - g_assert(!webkit_web_view_can_go_back(test->m_webView)); - g_assert(!webkit_web_view_can_go_forward(test->m_webView)); - - g_assert_cmpuint(webkit_back_forward_list_get_length(test->m_list), ==, 0); - g_assert(!webkit_back_forward_list_get_current_item(test->m_list)); - g_assert(!webkit_back_forward_list_get_back_item(test->m_list)); - g_assert(!webkit_back_forward_list_get_forward_item(test->m_list)); - BackForwardListTest::checkItemIndex(test->m_list); - g_assert(!webkit_back_forward_list_get_back_list(test->m_list)); - g_assert(!webkit_back_forward_list_get_forward_list(test->m_list)); - - CString uriPage1 = kServer->getURIForPath("/Page1"); - test->m_changedFlags = BackForwardListTest::CurrentItem | BackForwardListTest::AddedItem; - test->loadURI(uriPage1.data()); - test->waitUntilLoadFinished(); - - g_assert(!webkit_web_view_can_go_back(test->m_webView)); - g_assert(!webkit_web_view_can_go_forward(test->m_webView)); - - g_assert_cmpuint(webkit_back_forward_list_get_length(test->m_list), ==, 1); - WebKitBackForwardListItem* itemPage1 = webkit_back_forward_list_get_current_item(test->m_list); - BackForwardListTest::checkItem(itemPage1, "Page1", uriPage1.data(), uriPage1.data()); - g_assert(!webkit_back_forward_list_get_back_item(test->m_list)); - g_assert(!webkit_back_forward_list_get_forward_item(test->m_list)); - BackForwardListTest::checkItemIndex(test->m_list); - g_assert(!webkit_back_forward_list_get_back_list(test->m_list)); - g_assert(!webkit_back_forward_list_get_forward_list(test->m_list)); - - CString uriPage2 = kServer->getURIForPath("/Page2"); - test->m_changedFlags = BackForwardListTest::CurrentItem | BackForwardListTest::AddedItem; - test->loadURI(uriPage2.data()); - test->waitUntilLoadFinished(); - - g_assert(webkit_web_view_can_go_back(test->m_webView)); - g_assert(!webkit_web_view_can_go_forward(test->m_webView)); - - g_assert_cmpuint(webkit_back_forward_list_get_length(test->m_list), ==, 2); - WebKitBackForwardListItem* itemPage2 = webkit_back_forward_list_get_current_item(test->m_list); - BackForwardListTest::checkItem(itemPage2, "Page2", uriPage2.data(), uriPage2.data()); - g_assert(webkit_back_forward_list_get_back_item(test->m_list) == itemPage1); - g_assert(!webkit_back_forward_list_get_forward_item(test->m_list)); - BackForwardListTest::checkItemIndex(test->m_list); - items[0] = itemPage1; - BackForwardListTest::checkList(test->m_list, BackForwardListTest::Backward, items, 1); - g_assert(!webkit_back_forward_list_get_forward_list(test->m_list)); - - test->m_changedFlags = BackForwardListTest::CurrentItem; - test->goBack(); - test->waitUntilLoadFinished(); - - g_assert(!webkit_web_view_can_go_back(test->m_webView)); - g_assert(webkit_web_view_can_go_forward(test->m_webView)); - - g_assert_cmpuint(webkit_back_forward_list_get_length(test->m_list), ==, 2); - g_assert(itemPage1 == webkit_back_forward_list_get_current_item(test->m_list)); - BackForwardListTest::checkItem(webkit_back_forward_list_get_current_item(test->m_list), "Page1", uriPage1.data(), uriPage1.data()); - g_assert(!webkit_back_forward_list_get_back_item(test->m_list)); - g_assert(webkit_back_forward_list_get_forward_item(test->m_list) == itemPage2); - BackForwardListTest::checkItemIndex(test->m_list); - g_assert(!webkit_back_forward_list_get_back_list(test->m_list)); - items[0] = itemPage2; - BackForwardListTest::checkList(test->m_list, BackForwardListTest::Forward, items, 1); - - test->m_changedFlags = BackForwardListTest::CurrentItem; - test->goForward(); - test->waitUntilLoadFinished(); - - g_assert(webkit_web_view_can_go_back(test->m_webView)); - g_assert(!webkit_web_view_can_go_forward(test->m_webView)); - - g_assert_cmpuint(webkit_back_forward_list_get_length(test->m_list), ==, 2); - g_assert(itemPage2 == webkit_back_forward_list_get_current_item(test->m_list)); - BackForwardListTest::checkItem(webkit_back_forward_list_get_current_item(test->m_list), "Page2", uriPage2.data(), uriPage2.data()); - g_assert(webkit_back_forward_list_get_back_item(test->m_list) == itemPage1); - g_assert(!webkit_back_forward_list_get_forward_item(test->m_list)); - BackForwardListTest::checkItemIndex(test->m_list); - items[0] = itemPage1; - BackForwardListTest::checkList(test->m_list, BackForwardListTest::Backward, items, 1); - g_assert(!webkit_back_forward_list_get_forward_list(test->m_list)); - - test->m_changedFlags = BackForwardListTest::CurrentItem; - test->goToBackForwardListItem(itemPage1); - test->waitUntilLoadFinished(); - - g_assert(itemPage1 == webkit_back_forward_list_get_current_item(test->m_list)); -} - -static void testBackForwardListLimitAndCache(BackForwardListTest* test, gconstpointer) -{ - for (int i = 0; i < kBackForwardListLimit; i++) { - GOwnPtr<char> path(g_strdup_printf("/Page%d", i)); - test->m_changedFlags = BackForwardListTest::CurrentItem | BackForwardListTest::AddedItem; - test->loadURI(kServer->getURIForPath(path.get()).data()); - test->waitUntilLoadFinished(); - } - - g_assert_cmpuint(webkit_back_forward_list_get_length(test->m_list), ==, kBackForwardListLimit); - WebKitBackForwardListItem* itemPageFirst = webkit_back_forward_list_get_nth_item(test->m_list, -(kBackForwardListLimit - 1)); - GOwnPtr<GList> removedItems(g_list_prepend(0, itemPageFirst)); - - GOwnPtr<char> path(g_strdup_printf("/Page%d", kBackForwardListLimit)); - test->m_changedFlags = BackForwardListTest::CurrentItem | BackForwardListTest::AddedItem | BackForwardListTest::RemovedItems; - test->loadURI(kServer->getURIForPath(path.get()).data()); - test->waitUntilLoadFinishedAndCheckRemovedItems(removedItems.get()); - - g_assert_cmpuint(webkit_back_forward_list_get_length(test->m_list), ==, kBackForwardListLimit); -} - -void beforeAll() -{ - kServer = new WebKitTestServer(); - kServer->run(serverCallback); - - BackForwardListTest::add("BackForwardList", "navigation", testBackForwardListNavigation); - BackForwardListTest::add("BackForwardList", "list-limit-and-cache", testBackForwardListLimitAndCache); -} - -void afterAll() -{ - delete kServer; -} - diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestContextMenu.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestContextMenu.cpp deleted file mode 100644 index c361f8baf..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestContextMenu.cpp +++ /dev/null @@ -1,846 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2,1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "WebViewTest.h" -#include <wtf/gobject/GRefPtr.h> - -class ContextMenuTest: public WebViewTest { -public: - enum ContextMenuItemStateFlags { - Visible = 1 << 0, - Enabled = 1 << 1, - Checked = 1 << 2 - }; - - void checkContextMenuEvent(GdkEvent* event) - { - g_assert(event); - g_assert_cmpint(event->type, ==, GDK_BUTTON_PRESS); - g_assert_cmpint(event->button.button, ==, 3); - g_assert_cmpint(event->button.x, ==, m_menuPositionX); - g_assert_cmpint(event->button.y, ==, m_menuPositionY); - } - - static gboolean contextMenuCallback(WebKitWebView* webView, WebKitContextMenu* contextMenu, GdkEvent* event, WebKitHitTestResult* hitTestResult, ContextMenuTest* test) - { - g_assert(WEBKIT_IS_CONTEXT_MENU(contextMenu)); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(contextMenu)); - test->checkContextMenuEvent(event); - g_assert(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult)); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(hitTestResult)); - - return test->contextMenu(contextMenu, event, hitTestResult); - } - - static void contextMenuDismissedCallback(WebKitWebView*, ContextMenuTest* test) - { - test->contextMenuDismissed(); - } - - ContextMenuTest() - : m_menuPositionX(0) - , m_menuPositionY(0) - { - g_signal_connect(m_webView, "context-menu", G_CALLBACK(contextMenuCallback), this); - g_signal_connect(m_webView, "context-menu-dismissed", G_CALLBACK(contextMenuDismissedCallback), this); - } - - ~ContextMenuTest() - { - g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); - } - - virtual bool contextMenu(WebKitContextMenu*, GdkEvent*, WebKitHitTestResult*) = 0; - - virtual void contextMenuDismissed() - { - quitMainLoop(); - } - - GtkMenu* getPopupMenu() - { - GOwnPtr<GList> toplevels(gtk_window_list_toplevels()); - for (GList* iter = toplevels.get(); iter; iter = g_list_next(iter)) { - if (!GTK_IS_WINDOW(iter->data)) - continue; - - GtkWidget* child = gtk_bin_get_child(GTK_BIN(iter->data)); - if (!GTK_IS_MENU(child)) - continue; - - if (gtk_menu_get_attach_widget(GTK_MENU(child)) == GTK_WIDGET(m_webView)) - return GTK_MENU(child); - } - g_assert_not_reached(); - return 0; - } - - bool shouldShowInputMethodsMenu() - { - GtkSettings* settings = gtk_widget_get_settings(GTK_WIDGET(m_webView)); - if (!settings) - return true; - - gboolean showInputMethodMenu; - g_object_get(settings, "gtk-show-input-method-menu", &showInputMethodMenu, NULL); - return showInputMethodMenu; - } - - void checkActionState(GtkAction* action, unsigned state) - { - if (state & Visible) - g_assert(gtk_action_get_visible(action)); - else - g_assert(!gtk_action_get_visible(action)); - - if (state & Enabled) - g_assert(gtk_action_get_sensitive(action)); - else - g_assert(!gtk_action_get_sensitive(action)); - - if (GTK_IS_TOGGLE_ACTION(action)) { - if (state & Checked) - g_assert(gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))); - else - g_assert(!gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action))); - } - } - - GList* checkCurrentItemIsStockActionAndGetNext(GList* items, WebKitContextMenuAction stockAction, unsigned state) - { - g_assert(items); - g_assert(WEBKIT_IS_CONTEXT_MENU_ITEM(items->data)); - - WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(items->data); - assertObjectIsDeletedWhenTestFinishes(G_OBJECT(item)); - - GtkAction* action = webkit_context_menu_item_get_action(item); - g_assert(GTK_IS_ACTION(action)); - - g_assert_cmpint(webkit_context_menu_item_get_stock_action(item), ==, stockAction); - - checkActionState(action, state); - - return g_list_next(items); - } - - GList* checkCurrentItemIsCustomActionAndGetNext(GList* items, const char* label, unsigned state) - { - g_assert(items); - g_assert(WEBKIT_IS_CONTEXT_MENU_ITEM(items->data)); - - WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(items->data); - assertObjectIsDeletedWhenTestFinishes(G_OBJECT(item)); - - GtkAction* action = webkit_context_menu_item_get_action(item); - g_assert(GTK_IS_ACTION(action)); - - g_assert_cmpint(webkit_context_menu_item_get_stock_action(item), ==, WEBKIT_CONTEXT_MENU_ACTION_CUSTOM); - g_assert_cmpstr(gtk_action_get_label(action), ==, label); - - checkActionState(action, state); - - return g_list_next(items); - } - - GList* checkCurrentItemIsSubMenuAndGetNext(GList* items, const char* label, unsigned state, GList** subMenuIter) - { - g_assert(items); - g_assert(WEBKIT_IS_CONTEXT_MENU_ITEM(items->data)); - - WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(items->data); - assertObjectIsDeletedWhenTestFinishes(G_OBJECT(item)); - - GtkAction* action = webkit_context_menu_item_get_action(item); - g_assert(GTK_IS_ACTION(action)); - - g_assert_cmpstr(gtk_action_get_label(action), ==, label); - checkActionState(action, state); - - WebKitContextMenu* subMenu = webkit_context_menu_item_get_submenu(item); - g_assert(WEBKIT_IS_CONTEXT_MENU(subMenu)); - if (subMenuIter) - *subMenuIter = webkit_context_menu_get_items(subMenu); - - return g_list_next(items); - } - - GList* checkCurrentItemIsSeparatorAndGetNext(GList* items) - { - g_assert(items); - g_assert(WEBKIT_IS_CONTEXT_MENU_ITEM(items->data)); - - WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(items->data); - g_assert(webkit_context_menu_item_is_separator(item)); - - return g_list_next(items); - } - - static gboolean doRightClickIdleCallback(ContextMenuTest* test) - { - test->clickMouseButton(test->m_menuPositionX, test->m_menuPositionY, 3); - return FALSE; - } - - void showContextMenuAtPositionAndWaitUntilFinished(int x, int y) - { - m_menuPositionX = x; - m_menuPositionY = y; - g_idle_add(reinterpret_cast<GSourceFunc>(doRightClickIdleCallback), this); - g_main_loop_run(m_mainLoop); - } - - void showContextMenuAndWaitUntilFinished() - { - showContextMenuAtPositionAndWaitUntilFinished(0, 0); - } - - static gboolean simulateEscKeyIdleCallback(ContextMenuTest* test) - { - test->keyStroke(GDK_KEY_Escape); - return FALSE; - } - - void dismissContextMenuAndWaitUntilFinished() - { - g_idle_add(reinterpret_cast<GSourceFunc>(simulateEscKeyIdleCallback), this); - g_main_loop_run(m_mainLoop); - } - - double m_menuPositionX; - double m_menuPositionY; -}; - -class ContextMenuDefaultTest: public ContextMenuTest { -public: - MAKE_GLIB_TEST_FIXTURE(ContextMenuDefaultTest); - - enum DefaultMenuType { - Navigation, - Link, - Image, - LinkImage, - Video, - Editable - }; - - ContextMenuDefaultTest() - : m_expectedMenuType(Navigation) - { - } - - bool contextMenu(WebKitContextMenu* contextMenu, GdkEvent* event, WebKitHitTestResult* hitTestResult) - { - GList* iter = webkit_context_menu_get_items(contextMenu); - - switch (m_expectedMenuType) { - case Navigation: - g_assert(!webkit_hit_test_result_context_is_link(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_image(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_GO_BACK, Visible); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_GO_FORWARD, Visible); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_STOP, Visible); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_RELOAD, Visible | Enabled); - break; - case Link: - g_assert(webkit_hit_test_result_context_is_link(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_image(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK_IN_NEW_WINDOW, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_LINK_TO_DISK, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_COPY_LINK_TO_CLIPBOARD, Visible | Enabled); - break; - case Image: - g_assert(!webkit_hit_test_result_context_is_link(hitTestResult)); - g_assert(webkit_hit_test_result_context_is_image(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_IMAGE_IN_NEW_WINDOW, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_IMAGE_TO_DISK, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_COPY_IMAGE_TO_CLIPBOARD, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_COPY_IMAGE_URL_TO_CLIPBOARD, Visible | Enabled); - break; - case LinkImage: - g_assert(webkit_hit_test_result_context_is_link(hitTestResult)); - g_assert(webkit_hit_test_result_context_is_image(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK_IN_NEW_WINDOW, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_LINK_TO_DISK, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_COPY_LINK_TO_CLIPBOARD, Visible | Enabled); - iter = checkCurrentItemIsSeparatorAndGetNext(iter); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_IMAGE_IN_NEW_WINDOW, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_IMAGE_TO_DISK, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_COPY_IMAGE_TO_CLIPBOARD, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_COPY_IMAGE_URL_TO_CLIPBOARD, Visible | Enabled); - break; - case Video: - g_assert(!webkit_hit_test_result_context_is_link(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_image(hitTestResult)); - g_assert(webkit_hit_test_result_context_is_media(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PLAY, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_MEDIA_MUTE, Visible); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_CONTROLS, Visible | Enabled | Checked); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_LOOP, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_ENTER_VIDEO_FULLSCREEN, Visible); - iter = checkCurrentItemIsSeparatorAndGetNext(iter); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_COPY_VIDEO_LINK_TO_CLIPBOARD, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_VIDEO_IN_NEW_WINDOW, Visible | Enabled); - break; - case Editable: - g_assert(!webkit_hit_test_result_context_is_link(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_image(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); - g_assert(webkit_hit_test_result_context_is_editable(hitTestResult)); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_CUT, Visible); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_COPY, Visible); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_PASTE, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_DELETE, Visible); - iter = checkCurrentItemIsSeparatorAndGetNext(iter); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_SELECT_ALL, Visible | Enabled); - if (shouldShowInputMethodsMenu()) { - iter = checkCurrentItemIsSeparatorAndGetNext(iter); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_UNICODE, Visible | Enabled); - } - break; - default: - g_assert_not_reached(); - } - - if (webkit_settings_get_enable_developer_extras(webkit_web_view_get_settings(m_webView))) { - iter = checkCurrentItemIsSeparatorAndGetNext(iter); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_INSPECT_ELEMENT, Visible | Enabled); - } - g_assert(!iter); - - quitMainLoop(); - - return true; - } - - DefaultMenuType m_expectedMenuType; -}; - -static void testContextMenuDefaultMenu(ContextMenuDefaultTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(); - - const char* linksHTML = - "<html><body>" - " <a style='position:absolute; left:1; top:1' href='http://www.webkitgtk.org' title='WebKitGTK+ Title'>WebKitGTK+ Website</a>" - " <img style='position:absolute; left:1; top:10' src='0xdeadbeef' width=5 height=5></img>" - " <a style='position:absolute; left:1; top:20' href='http://www.webkitgtk.org/logo' title='WebKitGTK+ Logo'><img src='0xdeadbeef' width=5 height=5></img></a>" - " <input style='position:absolute; left:1; top:30' size='10'></input>" - " <video style='position:absolute; left:1; top:50' width='300' height='300' controls='controls' preload='none'><source src='movie.ogg' type='video/ogg' /></video>" - "</body></html>"; - test->loadHtml(linksHTML, "file:///"); - test->waitUntilLoadFinished(); - - // Context menu for document. - test->m_expectedMenuType = ContextMenuDefaultTest::Navigation; - test->showContextMenuAtPositionAndWaitUntilFinished(0, 0); - - // Context menu for link. - test->m_expectedMenuType = ContextMenuDefaultTest::Link; - test->showContextMenuAtPositionAndWaitUntilFinished(1, 1); - - // Context menu for image. - test->m_expectedMenuType = ContextMenuDefaultTest::Image; - test->showContextMenuAtPositionAndWaitUntilFinished(1, 10); - - // Enable developer extras now, so that inspector element - // will be shown in the default context menu. - webkit_settings_set_enable_developer_extras(webkit_web_view_get_settings(test->m_webView), TRUE); - - // Context menu for image link. - test->m_expectedMenuType = ContextMenuDefaultTest::LinkImage; - test->showContextMenuAtPositionAndWaitUntilFinished(1, 20); - - // Context menu for image video. - test->m_expectedMenuType = ContextMenuDefaultTest::Video; - test->showContextMenuAtPositionAndWaitUntilFinished(1, 50); - - // Context menu for editable. - test->m_expectedMenuType = ContextMenuDefaultTest::Editable; - test->showContextMenuAtPositionAndWaitUntilFinished(5, 35); -} - -class ContextMenuCustomTest: public ContextMenuTest { -public: - MAKE_GLIB_TEST_FIXTURE(ContextMenuCustomTest); - - ContextMenuCustomTest() - : m_itemToActivateLabel(0) - , m_activated(false) - , m_toggled(false) - { - } - - bool contextMenu(WebKitContextMenu* contextMenu, GdkEvent*, WebKitHitTestResult* hitTestResult) - { - // Append our custom item to the default menu. - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new(m_action.get())); - quitMainLoop(); - - return false; - } - - GtkMenuItem* getMenuItem(GtkMenu* menu, const gchar* itemLabel) - { - GOwnPtr<GList> items(gtk_container_get_children(GTK_CONTAINER(menu))); - for (GList* iter = items.get(); iter; iter = g_list_next(iter)) { - GtkMenuItem* child = GTK_MENU_ITEM(iter->data); - if (g_str_equal(itemLabel, gtk_menu_item_get_label(child))) - return child; - } - g_assert_not_reached(); - return 0; - } - - void activateMenuItem() - { - g_assert(m_itemToActivateLabel); - GtkMenu* menu = getPopupMenu(); - GtkMenuItem* item = getMenuItem(menu, m_itemToActivateLabel); - gtk_menu_shell_activate_item(GTK_MENU_SHELL(menu), GTK_WIDGET(item), TRUE); - m_itemToActivateLabel = 0; - } - - static gboolean activateMenuItemIdleCallback(gpointer userData) - { - ContextMenuCustomTest* test = static_cast<ContextMenuCustomTest*>(userData); - test->activateMenuItem(); - return FALSE; - } - - void activateCustomMenuItemAndWaitUntilActivated(const char* actionLabel) - { - m_activated = m_toggled = false; - m_itemToActivateLabel = actionLabel; - g_idle_add(activateMenuItemIdleCallback, this); - g_main_loop_run(m_mainLoop); - } - - void toggleCustomMenuItemAndWaitUntilToggled(const char* actionLabel) - { - activateCustomMenuItemAndWaitUntilActivated(actionLabel); - } - - static void actionActivatedCallback(GtkAction*, ContextMenuCustomTest* test) - { - test->m_activated = true; - } - - static void actionToggledCallback(GtkAction*, ContextMenuCustomTest* test) - { - test->m_toggled = true; - } - - void setAction(GtkAction* action) - { - m_action = action; - if (GTK_IS_TOGGLE_ACTION(action)) - g_signal_connect(action, "toggled", G_CALLBACK(actionToggledCallback), this); - else - g_signal_connect(action, "activate", G_CALLBACK(actionActivatedCallback), this); - } - - GRefPtr<GtkAction> m_action; - const char* m_itemToActivateLabel; - bool m_activated; - bool m_toggled; -}; - -static void testContextMenuPopulateMenu(ContextMenuCustomTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(); - - test->loadHtml("<html><body>WebKitGTK+ Context menu tests</body></html>", "file:///"); - test->waitUntilLoadFinished(); - - // Create a custom menu item. - GRefPtr<GtkAction> action = adoptGRef(gtk_action_new("WebKitGTK+CustomAction", "Custom _Action", 0, 0)); - test->setAction(action.get()); - test->showContextMenuAndWaitUntilFinished(); - test->activateCustomMenuItemAndWaitUntilActivated(gtk_action_get_label(action.get())); - g_assert(test->m_activated); - g_assert(!test->m_toggled); - - // Create a custom toggle menu item. - GRefPtr<GtkAction> toggleAction = adoptGRef(GTK_ACTION(gtk_toggle_action_new("WebKitGTK+CustomToggleAction", "Custom _Toggle Action", 0, 0))); - test->setAction(toggleAction.get()); - test->showContextMenuAndWaitUntilFinished(); - test->toggleCustomMenuItemAndWaitUntilToggled(gtk_action_get_label(toggleAction.get())); - g_assert(!test->m_activated); - g_assert(test->m_toggled); -} - -class ContextMenuCustomFullTest: public ContextMenuTest { -public: - MAKE_GLIB_TEST_FIXTURE(ContextMenuCustomFullTest); - - bool contextMenu(WebKitContextMenu* contextMenu, GdkEvent*, WebKitHitTestResult*) - { - // Clear proposed menu and build our own. - webkit_context_menu_remove_all(contextMenu); - g_assert_cmpint(webkit_context_menu_get_n_items(contextMenu), ==, 0); - - // Add actions from stock. - webkit_context_menu_prepend(contextMenu, webkit_context_menu_item_new_from_stock_action(WEBKIT_CONTEXT_MENU_ACTION_GO_BACK)); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_from_stock_action(WEBKIT_CONTEXT_MENU_ACTION_GO_FORWARD)); - webkit_context_menu_insert(contextMenu, webkit_context_menu_item_new_separator(), 2); - - // Add custom actions. - GRefPtr<GtkAction> action = adoptGRef(gtk_action_new("WebKitGTK+CustomAction", "Custom _Action", 0, 0)); - gtk_action_set_sensitive(action.get(), FALSE); - webkit_context_menu_insert(contextMenu, webkit_context_menu_item_new(action.get()), -1); - GRefPtr<GtkAction> toggleAction = adoptGRef(GTK_ACTION(gtk_toggle_action_new("WebKitGTK+CustomToggleAction", "Custom _Toggle Action", 0, 0))); - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(toggleAction.get()), TRUE); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new(toggleAction.get())); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); - - // Add a submenu. - GRefPtr<WebKitContextMenu> subMenu = adoptGRef(webkit_context_menu_new()); - assertObjectIsDeletedWhenTestFinishes(G_OBJECT(subMenu.get())); - webkit_context_menu_insert(subMenu.get(), webkit_context_menu_item_new_from_stock_action_with_label(WEBKIT_CONTEXT_MENU_ACTION_STOP, "Stop Load"), 0); - webkit_context_menu_insert(subMenu.get(), webkit_context_menu_item_new_from_stock_action(WEBKIT_CONTEXT_MENU_ACTION_RELOAD), -1); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_with_submenu("Load options", subMenu.get())); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); - - // Move Load submenu before custom actions. - webkit_context_menu_move_item(contextMenu, webkit_context_menu_last(contextMenu), 3); - webkit_context_menu_move_item(contextMenu, webkit_context_menu_last(contextMenu), 3); - - // If last item is a separator, remove it. - if (webkit_context_menu_item_is_separator(webkit_context_menu_last(contextMenu))) - webkit_context_menu_remove(contextMenu, webkit_context_menu_last(contextMenu)); - - // Check the menu. - GList* iter = webkit_context_menu_get_items(contextMenu); - - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_GO_BACK, Visible | Enabled); - iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_GO_FORWARD, Visible | Enabled); - iter = checkCurrentItemIsSeparatorAndGetNext(iter); - - GList* subMenuIter = 0; - iter = checkCurrentItemIsSubMenuAndGetNext(iter, "Load options", Visible | Enabled, &subMenuIter); - subMenuIter = checkCurrentItemIsStockActionAndGetNext(subMenuIter, WEBKIT_CONTEXT_MENU_ACTION_STOP, Visible | Enabled); - subMenuIter = checkCurrentItemIsStockActionAndGetNext(subMenuIter, WEBKIT_CONTEXT_MENU_ACTION_RELOAD, Visible | Enabled); - iter = checkCurrentItemIsSeparatorAndGetNext(iter); - - iter = checkCurrentItemIsCustomActionAndGetNext(iter, "Custom _Action", Visible); - iter = checkCurrentItemIsCustomActionAndGetNext(iter, "Custom _Toggle Action", Visible | Enabled | Checked); - g_assert(!iter); - - quitMainLoop(); - - return true; - } -}; - -static void testContextMenuCustomMenu(ContextMenuCustomFullTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(); - - test->loadHtml("<html><body>WebKitGTK+ Context menu tests</body></html>", "file:///"); - test->waitUntilLoadFinished(); - - test->showContextMenuAndWaitUntilFinished(); -} - -class ContextMenuDisabledTest: public ContextMenuTest { -public: - MAKE_GLIB_TEST_FIXTURE(ContextMenuDisabledTest); - - enum DisableMode { - IgnoreClicks, - IgnoreDefaultMenu - }; - - static gboolean buttonPressEventCallback(GtkWidget*, GdkEvent* event, ContextMenuDisabledTest* test) - { - if (event->button.button != 3) - return FALSE; - return test->rightButtonPressed(); - } - - ContextMenuDisabledTest() - : m_disableMode(IgnoreClicks) - { - g_signal_connect(m_webView, "button-press-event", G_CALLBACK(buttonPressEventCallback), this); - } - - bool contextMenu(WebKitContextMenu* contextMenu, GdkEvent*, WebKitHitTestResult*) - { - if (m_disableMode == IgnoreClicks) - g_assert_not_reached(); - else - quitMainLoop(); - - return true; - } - - bool rightButtonPressed() - { - if (m_disableMode == IgnoreClicks) { - quitMainLoopAfterProcessingPendingEvents(); - return true; - } - return false; - } - - DisableMode m_disableMode; -}; - -static void testContextMenuDisableMenu(ContextMenuDisabledTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(); - - test->loadHtml("<html><body>WebKitGTK+ Context menu tests</body></html>", "file:///"); - test->waitUntilLoadFinished(); - - test->m_disableMode = ContextMenuDisabledTest::IgnoreDefaultMenu; - test->showContextMenuAndWaitUntilFinished(); - - test->m_disableMode = ContextMenuDisabledTest::IgnoreClicks; - test->showContextMenuAndWaitUntilFinished(); -} - -class ContextMenuSubmenuTest: public ContextMenuTest { -public: - MAKE_GLIB_TEST_FIXTURE(ContextMenuSubmenuTest); - - bool contextMenu(WebKitContextMenu* contextMenu, GdkEvent*, WebKitHitTestResult*) - { - size_t menuSize = webkit_context_menu_get_n_items(contextMenu); - GRefPtr<WebKitContextMenu> subMenu = adoptGRef(webkit_context_menu_new()); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_with_submenu("SubMenuItem", subMenu.get())); - g_assert_cmpuint(webkit_context_menu_get_n_items(contextMenu), ==, menuSize + 1); - - GRefPtr<WebKitContextMenu> subMenu2 = adoptGRef(webkit_context_menu_new()); - GRefPtr<WebKitContextMenuItem> item = webkit_context_menu_item_new_from_stock_action(WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK); - - // Add submenu to newly created item. - g_assert(!webkit_context_menu_item_get_submenu(item.get())); - webkit_context_menu_item_set_submenu(item.get(), subMenu2.get()); - g_assert(webkit_context_menu_item_get_submenu(item.get()) == subMenu2.get()); - - // Replace the submenu. - webkit_context_menu_item_set_submenu(item.get(), 0); - g_assert(!webkit_context_menu_item_get_submenu(item.get())); - - // Try to add a submenu already added to another item. - removeLogFatalFlag(G_LOG_LEVEL_WARNING); - webkit_context_menu_item_set_submenu(item.get(), subMenu.get()); - addLogFatalFlag(G_LOG_LEVEL_WARNING); - g_assert(!webkit_context_menu_item_get_submenu(item.get())); - - // A removed submenu shouldn't have a parent. - webkit_context_menu_item_set_submenu(item.get(), subMenu2.get()); - g_assert(webkit_context_menu_item_get_submenu(item.get()) == subMenu2.get()); - - quitMainLoop(); - - return true; - } -}; - -static void testContextMenuSubMenu(ContextMenuSubmenuTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(); - - test->loadHtml("<html><body>WebKitGTK+ Context menu tests</body></html>", "file:///"); - test->waitUntilLoadFinished(); - - test->showContextMenuAndWaitUntilFinished(); -} - -class ContextMenuDismissedTest: public ContextMenuTest { -public: - MAKE_GLIB_TEST_FIXTURE(ContextMenuDismissedTest); - - ContextMenuDismissedTest() - : m_dismissed(false) - { - } - - bool contextMenu(WebKitContextMenu* contextMenu, GdkEvent*, WebKitHitTestResult*) - { - quitMainLoop(); - // Show the default context menu. - return false; - } - - void contextMenuDismissed() - { - m_dismissed = true; - ContextMenuTest::contextMenuDismissed(); - } - - void showContextMenuAndWaitUntilDismissed() - { - showContextMenuAndWaitUntilFinished(); - dismissContextMenuAndWaitUntilFinished(); - } - - bool m_dismissed; -}; - -static void testContextMenuDismissed(ContextMenuDismissedTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(); - - test->loadHtml("<html><body>WebKitGTK+ Context menu tests</body></html>", "file:///"); - test->waitUntilLoadFinished(); - - test->showContextMenuAndWaitUntilDismissed(); - g_assert(test->m_dismissed); -} - -class ContextMenuSmartSeparatorsTest: public ContextMenuTest { -public: - MAKE_GLIB_TEST_FIXTURE(ContextMenuSmartSeparatorsTest); - - bool contextMenu(WebKitContextMenu* contextMenu, GdkEvent*, WebKitHitTestResult*) - { - webkit_context_menu_remove_all(contextMenu); - - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_from_stock_action(WEBKIT_CONTEXT_MENU_ACTION_GO_BACK)); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_from_stock_action(WEBKIT_CONTEXT_MENU_ACTION_GO_FORWARD)); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_from_stock_action(WEBKIT_CONTEXT_MENU_ACTION_COPY)); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_from_stock_action(WEBKIT_CONTEXT_MENU_ACTION_INSPECT_ELEMENT)); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); - webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator()); - - quitMainLoop(); - - return false; - } - - GtkMenu* showContextMenuAndGetGtkMenu() - { - showContextMenuAndWaitUntilFinished(); - return getPopupMenu(); - } -}; - -static void testContextMenuSmartSeparators(ContextMenuSmartSeparatorsTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(); - - test->loadHtml("<html><body>WebKitGTK+ Context menu tests</body></html>", "file:///"); - test->waitUntilLoadFinished(); - - GtkMenu* menu = test->showContextMenuAndGetGtkMenu(); - g_assert(menu); - - // Leading and trailing separators are not added to the context menu. - GOwnPtr<GList> menuItems(gtk_container_get_children(GTK_CONTAINER(menu))); - g_assert_cmpuint(g_list_length(menuItems.get()), ==, 6); - GtkWidget* item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 0)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 1)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 2)); - g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 3)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 4)); - g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 5)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - - // Hiding a menu item between two separators hides the following separator. - GtkAction* action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(g_list_nth_data(menuItems.get(), 3))); - gtk_action_set_visible(action, FALSE); - menuItems.set(gtk_container_get_children(GTK_CONTAINER(menu))); - g_assert_cmpuint(g_list_length(menuItems.get()), ==, 6); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 0)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 1)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 2)); - g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 3)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && !gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 4)); - g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && !gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 5)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - gtk_action_set_visible(action, TRUE); - - // Showing an action between two separators shows the hidden separator. - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 0)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 1)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 2)); - g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 3)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 4)); - g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 5)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - - // Trailing separators are hidden too. - action = gtk_activatable_get_related_action(GTK_ACTIVATABLE(g_list_nth_data(menuItems.get(), 5))); - gtk_action_set_visible(action, FALSE); - menuItems.set(gtk_container_get_children(GTK_CONTAINER(menu))); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 0)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 1)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 2)); - g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 3)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 4)); - g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item) && !gtk_widget_get_visible(item)); - item = GTK_WIDGET(g_list_nth_data(menuItems.get(), 5)); - g_assert(!GTK_IS_SEPARATOR_MENU_ITEM(item) && !gtk_widget_get_visible(item)); -} - -void beforeAll() -{ - ContextMenuDefaultTest::add("WebKitWebView", "default-menu", testContextMenuDefaultMenu); - ContextMenuCustomTest::add("WebKitWebView", "populate-menu", testContextMenuPopulateMenu); - ContextMenuCustomFullTest::add("WebKitWebView", "custom-menu", testContextMenuCustomMenu); - ContextMenuDisabledTest::add("WebKitWebView", "disable-menu", testContextMenuDisableMenu); - ContextMenuSubmenuTest::add("WebKitWebView", "submenu", testContextMenuSubMenu); - ContextMenuDismissedTest::add("WebKitWebView", "menu-dismissed", testContextMenuDismissed); - ContextMenuSmartSeparatorsTest::add("WebKitWebView", "smart-separators", testContextMenuSmartSeparators); -} - -void afterAll() -{ -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp deleted file mode 100644 index adc6b5b9b..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp +++ /dev/null @@ -1,331 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include "WebKitTestServer.h" -#include "WebViewTest.h" -#include <glib/gstdio.h> - -static WebKitTestServer* kServer; -static char* kTempDirectory; - -static const char* kFirstPartyDomain = "127.0.0.1"; -static const char* kThirdPartyDomain = "localhost"; -static const char* kIndexHtmlFormat = - "<html><body>" - " <p>WebKitGTK+ Cookie Manager test</p>" - " <img src='http://localhost:%u/image.png' width=5 height=5></img>" - "</body></html>"; - -class CookieManagerTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(CookieManagerTest); - - static void cookiesChangedCallback(WebKitCookieManager*, CookieManagerTest* test) - { - test->m_cookiesChanged = true; - if (test->m_finishLoopWhenCookiesChange) - g_main_loop_quit(test->m_mainLoop); - } - - CookieManagerTest() - : WebViewTest() - , m_cookieManager(webkit_web_context_get_cookie_manager(webkit_web_view_get_context(m_webView))) - , m_acceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY) - , m_domains(0) - , m_cookiesChanged(false) - , m_finishLoopWhenCookiesChange(false) - { - g_signal_connect(m_cookieManager, "changed", G_CALLBACK(cookiesChangedCallback), this); - } - - ~CookieManagerTest() - { - g_strfreev(m_domains); - g_signal_handlers_disconnect_matched(m_cookieManager, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); - if (m_cookiesTextFile) - g_unlink(m_cookiesTextFile.get()); - if (m_cookiesSQLiteFile) - g_unlink(m_cookiesSQLiteFile.get()); - } - - void setPersistentStorage(WebKitCookiePersistentStorage storage) - { - const char* filename = 0; - switch (storage) { - case WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT: - if (!m_cookiesTextFile) - m_cookiesTextFile.set(g_build_filename(kTempDirectory, "cookies.txt", NULL)); - filename = m_cookiesTextFile.get(); - break; - case WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE: - if (!m_cookiesSQLiteFile) - m_cookiesSQLiteFile.set(g_build_filename(kTempDirectory, "cookies.db", NULL)); - filename = m_cookiesSQLiteFile.get(); - break; - default: - g_assert_not_reached(); - } - webkit_cookie_manager_set_persistent_storage(m_cookieManager, filename, storage); - } - - static void getAcceptPolicyReadyCallback(GObject* object, GAsyncResult* result, gpointer userData) - { - GOwnPtr<GError> error; - WebKitCookieAcceptPolicy policy = webkit_cookie_manager_get_accept_policy_finish(WEBKIT_COOKIE_MANAGER(object), result, &error.outPtr()); - g_assert(!error.get()); - - CookieManagerTest* test = static_cast<CookieManagerTest*>(userData); - test->m_acceptPolicy = policy; - g_main_loop_quit(test->m_mainLoop); - } - - WebKitCookieAcceptPolicy getAcceptPolicy() - { - m_acceptPolicy = WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY; - webkit_cookie_manager_get_accept_policy(m_cookieManager, 0, getAcceptPolicyReadyCallback, this); - g_main_loop_run(m_mainLoop); - - return m_acceptPolicy; - } - - void setAcceptPolicy(WebKitCookieAcceptPolicy policy) - { - webkit_cookie_manager_set_accept_policy(m_cookieManager, policy); - } - - static void getDomainsReadyCallback(GObject* object, GAsyncResult* result, gpointer userData) - { - GOwnPtr<GError> error; - char** domains = webkit_cookie_manager_get_domains_with_cookies_finish(WEBKIT_COOKIE_MANAGER(object), result, &error.outPtr()); - g_assert(!error.get()); - - CookieManagerTest* test = static_cast<CookieManagerTest*>(userData); - test->m_domains = domains; - g_main_loop_quit(test->m_mainLoop); - } - - char** getDomains() - { - g_strfreev(m_domains); - m_domains = 0; - webkit_cookie_manager_get_domains_with_cookies(m_cookieManager, 0, getDomainsReadyCallback, this); - g_main_loop_run(m_mainLoop); - - return m_domains; - } - - bool hasDomain(const char* domain) - { - if (!m_domains) - return false; - - for (size_t i = 0; m_domains[i]; ++i) - if (g_str_equal(m_domains[i], domain)) - return true; - return false; - } - - void deleteCookiesForDomain(const char* domain) - { - webkit_cookie_manager_delete_cookies_for_domain(m_cookieManager, domain); - } - - void deleteAllCookies() - { - webkit_cookie_manager_delete_all_cookies(m_cookieManager); - } - - void waitUntilCookiesChanged() - { - m_cookiesChanged = false; - m_finishLoopWhenCookiesChange = true; - g_main_loop_run(m_mainLoop); - m_finishLoopWhenCookiesChange = false; - } - - WebKitCookieManager* m_cookieManager; - WebKitCookieAcceptPolicy m_acceptPolicy; - char** m_domains; - bool m_cookiesChanged; - bool m_finishLoopWhenCookiesChange; - GOwnPtr<char> m_cookiesTextFile; - GOwnPtr<char> m_cookiesSQLiteFile; -}; - -static void testCookieManagerAcceptPolicy(CookieManagerTest* test, gconstpointer) -{ - // Default policy is NO_THIRD_PARTY. - g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_NO_THIRD_PARTY); - test->loadURI(kServer->getURIForPath("/index.html").data()); - test->waitUntilLoadFinished(); - char** domains = test->getDomains(); - g_assert(domains); - g_assert_cmpint(g_strv_length(domains), ==, 1); - g_assert_cmpstr(domains[0], ==, kFirstPartyDomain); - test->deleteAllCookies(); - - test->setAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS); - g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS); - test->loadURI(kServer->getURIForPath("/index.html").data()); - test->waitUntilLoadFinished(); - domains = test->getDomains(); - g_assert(domains); - g_assert_cmpint(g_strv_length(domains), ==, 2); - g_assert(test->hasDomain(kFirstPartyDomain)); - g_assert(test->hasDomain(kThirdPartyDomain)); - test->deleteAllCookies(); - - test->setAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_NEVER); - g_assert_cmpint(test->getAcceptPolicy(), ==, WEBKIT_COOKIE_POLICY_ACCEPT_NEVER); - test->loadURI(kServer->getURIForPath("/index.html").data()); - test->waitUntilLoadFinished(); - domains = test->getDomains(); - g_assert(domains); - g_assert_cmpint(g_strv_length(domains), ==, 0); -} - -static void testCookieManagerDeleteCookies(CookieManagerTest* test, gconstpointer) -{ - test->setAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS); - test->loadURI(kServer->getURIForPath("/index.html").data()); - test->waitUntilLoadFinished(); - g_assert_cmpint(g_strv_length(test->getDomains()), ==, 2); - - // Delete first party cookies. - test->deleteCookiesForDomain(kFirstPartyDomain); - g_assert_cmpint(g_strv_length(test->getDomains()), ==, 1); - - // Delete third party cookies. - test->deleteCookiesForDomain(kThirdPartyDomain); - g_assert_cmpint(g_strv_length(test->getDomains()), ==, 0); - - test->loadURI(kServer->getURIForPath("/index.html").data()); - test->waitUntilLoadFinished(); - g_assert_cmpint(g_strv_length(test->getDomains()), ==, 2); - - // Delete all cookies. - test->deleteAllCookies(); - g_assert_cmpint(g_strv_length(test->getDomains()), ==, 0); -} - -static void testCookieManagerCookiesChanged(CookieManagerTest* test, gconstpointer) -{ - g_assert(!test->m_cookiesChanged); - test->setAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS); - test->loadURI(kServer->getURIForPath("/index.html").data()); - test->waitUntilLoadFinished(); - g_assert(test->m_cookiesChanged); - - test->deleteCookiesForDomain(kFirstPartyDomain); - test->waitUntilCookiesChanged(); - g_assert(test->m_cookiesChanged); - - test->deleteAllCookies(); - test->waitUntilCookiesChanged(); - g_assert(test->m_cookiesChanged); -} - -static void testCookieManagerPersistentStorage(CookieManagerTest* test, gconstpointer) -{ - test->setAcceptPolicy(WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS); - - // Text storage using a new file. - test->setPersistentStorage(WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT); - char** domains = test->getDomains(); - g_assert(domains); - g_assert_cmpint(g_strv_length(domains), ==, 0); - - test->loadURI(kServer->getURIForPath("/index.html").data()); - test->waitUntilLoadFinished(); - g_assert(test->m_cookiesChanged); - domains = test->getDomains(); - g_assert(domains); - g_assert_cmpint(g_strv_length(domains), ==, 2); - - - // SQLite storage using a new file. - test->setPersistentStorage(WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE); - domains = test->getDomains(); - g_assert(domains); - g_assert_cmpint(g_strv_length(domains), ==, 0); - - test->loadURI(kServer->getURIForPath("/index.html").data()); - test->waitUntilLoadFinished(); - g_assert(test->m_cookiesChanged); - domains = test->getDomains(); - g_assert(domains); - g_assert_cmpint(g_strv_length(domains), ==, 2); - - // Text storage using an existing file. - test->setPersistentStorage(WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT); - domains = test->getDomains(); - g_assert(domains); - g_assert_cmpint(g_strv_length(domains), ==, 2); - test->deleteAllCookies(); - g_assert_cmpint(g_strv_length(test->getDomains()), ==, 0); - - // SQLite storage with an existing file. - test->setPersistentStorage(WEBKIT_COOKIE_PERSISTENT_STORAGE_SQLITE); - domains = test->getDomains(); - g_assert(domains); - g_assert_cmpint(g_strv_length(domains), ==, 2); - test->deleteAllCookies(); - g_assert_cmpint(g_strv_length(test->getDomains()), ==, 0); -} - -static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) -{ - if (message->method != SOUP_METHOD_GET) { - soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); - return; - } - - soup_message_set_status(message, SOUP_STATUS_OK); - if (g_str_equal(path, "/index.html")) { - char* indexHtml = g_strdup_printf(kIndexHtmlFormat, soup_server_get_port(server)); - soup_message_headers_replace(message->response_headers, "Set-Cookie", "foo=bar; Max-Age=60"); - soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, indexHtml, strlen(indexHtml)); - } else if (g_str_equal(path, "/image.png")) - soup_message_headers_replace(message->response_headers, "Set-Cookie", "baz=qux; Max-Age=60"); - else - soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); - soup_message_body_complete(message->response_body); -} - -void beforeAll() -{ - kServer = new WebKitTestServer(); - kServer->run(serverCallback); - - kTempDirectory = g_dir_make_tmp("WebKit2Tests-XXXXXX", 0); - g_assert(kTempDirectory); - - CookieManagerTest::add("WebKitCookieManager", "accept-policy", testCookieManagerAcceptPolicy); - CookieManagerTest::add("WebKitCookieManager", "delete-cookies", testCookieManagerDeleteCookies); - CookieManagerTest::add("WebKitCookieManager", "cookies-changed", testCookieManagerCookiesChanged); - CookieManagerTest::add("WebKitCookieManager", "persistent-storage", testCookieManagerPersistentStorage); -} - -void afterAll() -{ - delete kServer; - g_rmdir(kTempDirectory); -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestDownloads.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestDownloads.cpp deleted file mode 100644 index ce159906c..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestDownloads.cpp +++ /dev/null @@ -1,522 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include "WebKitTestServer.h" -#include "WebViewTest.h" -#include <glib/gstdio.h> -#include <gtk/gtk.h> -#include <libsoup/soup.h> -#include <string.h> -#include <webkit2/webkit2.h> -#include <wtf/Vector.h> -#include <wtf/gobject/GOwnPtr.h> -#include <wtf/gobject/GRefPtr.h> -#include <wtf/text/CString.h> - -static char* kTempDirectory; - -class DownloadTest: public Test { -public: - MAKE_GLIB_TEST_FIXTURE(DownloadTest); - - enum DownloadEvent { - Started, - ReceivedResponse, - CreatedDestination, - ReceivedData, - Failed, - Finished - }; - - static void receivedResponseCallback(WebKitDownload* download, GParamSpec*, DownloadTest* test) - { - g_assert(webkit_download_get_response(download)); - test->receivedResponse(download); - } - - static gboolean createdDestinationCallback(WebKitDownload* download, const gchar* destination, DownloadTest* test) - { - g_assert(webkit_download_get_destination(download)); - g_assert_cmpstr(webkit_download_get_destination(download), ==, destination); - test->createdDestination(download, destination); - return TRUE; - } - - static gboolean receivedDataCallback(WebKitDownload* download, guint64 dataLength, DownloadTest* test) - { - test->receivedData(download, dataLength); - return TRUE; - } - - static gboolean finishedCallback(WebKitDownload* download, DownloadTest* test) - { - test->finished(download); - return TRUE; - } - - static gboolean failedCallback(WebKitDownload* download, GError* error, DownloadTest* test) - { - g_assert(error); - test->failed(download, error); - return TRUE; - } - - static gboolean decideDestinationCallback(WebKitDownload* download, const gchar* suggestedFilename, DownloadTest* test) - { - g_assert(suggestedFilename); - test->decideDestination(download, suggestedFilename); - return TRUE; - } - - static void downloadStartedCallback(WebKitWebContext* context, WebKitDownload* download, DownloadTest* test) - { - g_assert(webkit_download_get_request(download)); - test->started(download); - g_signal_connect(download, "notify::response", G_CALLBACK(receivedResponseCallback), test); - g_signal_connect(download, "created-destination", G_CALLBACK(createdDestinationCallback), test); - g_signal_connect(download, "received-data", G_CALLBACK(receivedDataCallback), test); - g_signal_connect(download, "finished", G_CALLBACK(finishedCallback), test); - g_signal_connect(download, "failed", G_CALLBACK(failedCallback), test); - g_signal_connect(download, "decide-destination", G_CALLBACK(decideDestinationCallback), test); - } - - DownloadTest() - : m_webContext(webkit_web_context_get_default()) - , m_mainLoop(g_main_loop_new(0, TRUE)) - , m_downloadSize(0) - { - g_signal_connect(m_webContext, "download-started", G_CALLBACK(downloadStartedCallback), this); - } - - ~DownloadTest() - { - g_signal_handlers_disconnect_matched(m_webContext, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); - g_main_loop_unref(m_mainLoop); - } - - virtual void started(WebKitDownload* download) - { - m_downloadEvents.append(Started); - } - - virtual void receivedResponse(WebKitDownload* download) - { - m_downloadEvents.append(ReceivedResponse); - } - - virtual void createdDestination(WebKitDownload* download, const char* destination) - { - m_downloadEvents.append(CreatedDestination); - } - - virtual void receivedData(WebKitDownload* download, guint64 dataLength) - { - m_downloadSize += dataLength; - if (!m_downloadEvents.contains(ReceivedData)) - m_downloadEvents.append(ReceivedData); - } - - virtual void finished(WebKitDownload* download) - { - g_assert_cmpuint(m_downloadSize, ==, webkit_download_get_received_data_length(download)); - m_downloadEvents.append(Finished); - g_main_loop_quit(m_mainLoop); - } - - virtual void failed(WebKitDownload* download, GError* error) - { - m_downloadEvents.append(Failed); - } - - virtual void decideDestination(WebKitDownload* download, const gchar* suggestedFilename) - { - GOwnPtr<char> destination(g_build_filename(kTempDirectory, suggestedFilename, NULL)); - GOwnPtr<char> destinationURI(g_filename_to_uri(destination.get(), 0, 0)); - webkit_download_set_destination(download, destinationURI.get()); - } - - WebKitDownload* downloadURIAndWaitUntilFinishes(const CString& requestURI) - { - WebKitDownload* download = webkit_web_context_download_uri(m_webContext, requestURI.data()); - assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download)); - - WebKitURIRequest* request = webkit_download_get_request(download); - g_assert(request); - ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, requestURI); - - g_main_loop_run(m_mainLoop); - - return download; - } - - void checkDestinationAndDeleteFile(WebKitDownload* download, const char* expectedName) - { - if (!webkit_download_get_destination(download)) - return; - GRefPtr<GFile> destFile = adoptGRef(g_file_new_for_uri(webkit_download_get_destination(download))); - GOwnPtr<char> destBasename(g_file_get_basename(destFile.get())); - g_assert_cmpstr(destBasename.get(), ==, expectedName); - - g_file_delete(destFile.get(), 0, 0); - } - - WebKitWebContext* m_webContext; - GMainLoop* m_mainLoop; - Vector<DownloadEvent> m_downloadEvents; - guint64 m_downloadSize; -}; - -static void testDownloadLocalFile(DownloadTest* test, gconstpointer) -{ - GOwnPtr<char> sourcePath(g_build_filename(Test::getWebKit1TestResoucesDir().data(), "test.pdf", NULL)); - GRefPtr<GFile> source = adoptGRef(g_file_new_for_path(sourcePath.get())); - GRefPtr<GFileInfo> sourceInfo = adoptGRef(g_file_query_info(source.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE, static_cast<GFileQueryInfoFlags>(0), 0, 0)); - GOwnPtr<char> sourceURI(g_file_get_uri(source.get())); - GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes(sourceURI.get())); - g_assert(!webkit_download_get_web_view(download.get())); - - Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents; - g_assert_cmpint(events.size(), ==, 5); - g_assert_cmpint(events[0], ==, DownloadTest::Started); - g_assert_cmpint(events[1], ==, DownloadTest::ReceivedResponse); - g_assert_cmpint(events[2], ==, DownloadTest::CreatedDestination); - g_assert_cmpint(events[3], ==, DownloadTest::ReceivedData); - g_assert_cmpint(events[4], ==, DownloadTest::Finished); - - WebKitURIRequest* request = webkit_download_get_request(download.get()); - g_assert(request); - g_assert_cmpstr(webkit_uri_request_get_uri(request), ==, sourceURI.get()); - - g_assert_cmpint(test->m_downloadSize, ==, g_file_info_get_size(sourceInfo.get())); - g_assert(webkit_download_get_destination(download.get())); - g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), ==, 1); - test->checkDestinationAndDeleteFile(download.get(), "test.pdf"); -} - -class DownloadErrorTest: public DownloadTest { -public: - MAKE_GLIB_TEST_FIXTURE(DownloadErrorTest); - - DownloadErrorTest() - : m_expectedError(WEBKIT_DOWNLOAD_ERROR_NETWORK) - { - } - - void receivedResponse(WebKitDownload* download) - { - DownloadTest::receivedResponse(download); - if (m_expectedError == WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER) - webkit_download_cancel(download); - } - - void createdDestination(WebKitDownload* download, const char* destination) - { - g_assert_not_reached(); - } - - void failed(WebKitDownload* download, GError* error) - { - g_assert(g_error_matches(error, WEBKIT_DOWNLOAD_ERROR, m_expectedError)); - DownloadTest::failed(download, error); - } - - void decideDestination(WebKitDownload* download, const gchar* suggestedFilename) - { - if (m_expectedError != WEBKIT_DOWNLOAD_ERROR_DESTINATION) { - DownloadTest::decideDestination(download, suggestedFilename); - return; - } - webkit_download_set_destination(download, "file:///foo/bar"); - } - - WebKitDownloadError m_expectedError; -}; - -static void testDownloadLocalFileError(DownloadErrorTest* test, gconstpointer) -{ - test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_NETWORK; - GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes("file:///foo/bar")); - g_assert(!webkit_download_get_web_view(download.get())); - - Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents; - g_assert_cmpint(events.size(), ==, 3); - g_assert_cmpint(events[0], ==, DownloadTest::Started); - g_assert_cmpint(events[1], ==, DownloadTest::Failed); - g_assert_cmpint(events[2], ==, DownloadTest::Finished); - events.clear(); - g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), <, 1); - - test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_DESTINATION; - GOwnPtr<char> path(g_build_filename(Test::getWebKit1TestResoucesDir().data(), "test.pdf", NULL)); - GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(path.get())); - GOwnPtr<char> uri(g_file_get_uri(file.get())); - download = adoptGRef(test->downloadURIAndWaitUntilFinishes(uri.get())); - g_assert(!webkit_download_get_web_view(download.get())); - - g_assert_cmpint(events.size(), ==, 4); - g_assert_cmpint(events[0], ==, DownloadTest::Started); - g_assert_cmpint(events[1], ==, DownloadTest::ReceivedResponse); - g_assert_cmpint(events[2], ==, DownloadTest::Failed); - g_assert_cmpint(events[3], ==, DownloadTest::Finished); - events.clear(); - g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), <, 1); - test->checkDestinationAndDeleteFile(download.get(), "bar"); - - test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER; - download = adoptGRef(test->downloadURIAndWaitUntilFinishes(uri.get())); - g_assert(!webkit_download_get_web_view(download.get())); - - g_assert_cmpint(events.size(), ==, 4); - g_assert_cmpint(events[0], ==, DownloadTest::Started); - g_assert_cmpint(events[1], ==, DownloadTest::ReceivedResponse); - g_assert_cmpint(events[2], ==, DownloadTest::Failed); - g_assert_cmpint(events[3], ==, DownloadTest::Finished); - events.clear(); - g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), <, 1); - test->checkDestinationAndDeleteFile(download.get(), "test.pdf"); -} - -static WebKitTestServer* kServer; -static const char* kServerSuggestedFilename = "webkit-downloaded-file"; - -static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) -{ - if (message->method != SOUP_METHOD_GET) { - soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); - return; - } - - GOwnPtr<char> filePath(g_build_filename(Test::getWebKit1TestResoucesDir().data(), path, NULL)); - char* contents; - gsize contentsLength; - if (!g_file_get_contents(filePath.get(), &contents, &contentsLength, 0)) { - soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); - soup_message_body_complete(message->response_body); - return; - } - - soup_message_set_status(message, SOUP_STATUS_OK); - - GOwnPtr<char> contentDisposition(g_strdup_printf("filename=%s", kServerSuggestedFilename)); - soup_message_headers_append(message->response_headers, "Content-Disposition", contentDisposition.get()); - soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, contentsLength); - - soup_message_body_complete(message->response_body); -} - -static void testDownloadRemoteFile(DownloadTest* test, gconstpointer) -{ - GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/test.pdf"))); - g_assert(!webkit_download_get_web_view(download.get())); - - Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents; - g_assert_cmpint(events.size(), ==, 5); - g_assert_cmpint(events[0], ==, DownloadTest::Started); - g_assert_cmpint(events[1], ==, DownloadTest::ReceivedResponse); - g_assert_cmpint(events[2], ==, DownloadTest::CreatedDestination); - g_assert_cmpint(events[3], ==, DownloadTest::ReceivedData); - g_assert_cmpint(events[4], ==, DownloadTest::Finished); - events.clear(); - - WebKitURIRequest* request = webkit_download_get_request(download.get()); - g_assert(request); - ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, kServer->getURIForPath("/test.pdf")); - - g_assert(webkit_download_get_destination(download.get())); - g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), ==, 1); - test->checkDestinationAndDeleteFile(download.get(), kServerSuggestedFilename); -} - -static void testDownloadRemoteFileError(DownloadErrorTest* test, gconstpointer) -{ - test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_NETWORK; - GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/foo"))); - g_assert(!webkit_download_get_web_view(download.get())); - - Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents; - g_assert_cmpint(events.size(), ==, 4); - g_assert_cmpint(events[0], ==, DownloadTest::Started); - g_assert_cmpint(events[1], ==, DownloadTest::ReceivedResponse); - g_assert_cmpint(events[2], ==, DownloadTest::Failed); - g_assert_cmpint(events[3], ==, DownloadTest::Finished); - events.clear(); - WebKitURIResponse* response = webkit_download_get_response(download.get()); - g_assert_cmpuint(webkit_uri_response_get_status_code(response), ==, 404); - g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), <, 1); - - test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_DESTINATION; - download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/test.pdf"))); - g_assert(!webkit_download_get_web_view(download.get())); - - g_assert_cmpint(events.size(), ==, 4); - g_assert_cmpint(events[0], ==, DownloadTest::Started); - g_assert_cmpint(events[1], ==, DownloadTest::ReceivedResponse); - g_assert_cmpint(events[2], ==, DownloadTest::Failed); - g_assert_cmpint(events[3], ==, DownloadTest::Finished); - events.clear(); - g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), <, 1); - test->checkDestinationAndDeleteFile(download.get(), "bar"); - - test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER; - download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/test.pdf"))); - g_assert(!webkit_download_get_web_view(download.get())); - - g_assert_cmpint(events.size(), ==, 4); - g_assert_cmpint(events[0], ==, DownloadTest::Started); - g_assert_cmpint(events[1], ==, DownloadTest::ReceivedResponse); - g_assert_cmpint(events[2], ==, DownloadTest::Failed); - g_assert_cmpint(events[3], ==, DownloadTest::Finished); - events.clear(); - g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), <, 1); - test->checkDestinationAndDeleteFile(download.get(), kServerSuggestedFilename); -} - -class WebViewDownloadTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(WebViewDownloadTest); - - static void downloadStartedCallback(WebKitWebContext* context, WebKitDownload* download, WebViewDownloadTest* test) - { - test->m_download = download; - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download)); - test->quitMainLoop(); - } - - WebViewDownloadTest() - { - g_signal_connect(webkit_web_view_get_context(m_webView), "download-started", G_CALLBACK(downloadStartedCallback), this); - } - - ~WebViewDownloadTest() - { - g_signal_handlers_disconnect_matched(webkit_web_view_get_context(m_webView), G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); - } - - void waitUntilDownloadStarted() - { - m_download = 0; - g_main_loop_run(m_mainLoop); - g_assert(m_download.get()); - } - - static gboolean downloadDecideDestinationCallback(WebKitDownload* download, const gchar* suggestedFilename, WebViewDownloadTest* test) - { - GOwnPtr<char> destination(g_build_filename(kTempDirectory, suggestedFilename, NULL)); - GOwnPtr<char> destinationURI(g_filename_to_uri(destination.get(), 0, 0)); - webkit_download_set_destination(download, destinationURI.get()); - return TRUE; - } - - static void downloadFinishedCallback(WebKitDownload* download, WebViewDownloadTest* test) - { - test->quitMainLoop(); - } - - void waitUntilDownloadFinished() - { - g_signal_connect(m_download.get(), "decide-destination", G_CALLBACK(downloadDecideDestinationCallback), this); - g_signal_connect(m_download.get(), "finished", G_CALLBACK(downloadFinishedCallback), this); - g_main_loop_run(m_mainLoop); - } - - GRefPtr<WebKitDownload> m_download; -}; - -static void testWebViewDownloadURI(WebViewDownloadTest* test, gconstpointer) -{ - GRefPtr<WebKitDownload> download = adoptGRef(webkit_web_view_download_uri(test->m_webView, kServer->getURIForPath("/test.pdf").data())); - test->waitUntilDownloadStarted(); - g_assert(test->m_webView == webkit_download_get_web_view(download.get())); - test->waitUntilDownloadFinished(); - - GRefPtr<GFile> downloadFile = adoptGRef(g_file_new_for_uri(webkit_download_get_destination(download.get()))); - GRefPtr<GFileInfo> downloadFileInfo = adoptGRef(g_file_query_info(downloadFile.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE, static_cast<GFileQueryInfoFlags>(0), 0, 0)); - g_assert_cmpint(g_file_info_get_size(downloadFileInfo.get()), >, 0); - g_file_delete(downloadFile.get(), 0, 0); -} - -class PolicyResponseDownloadTest: public WebViewDownloadTest { -public: - MAKE_GLIB_TEST_FIXTURE(PolicyResponseDownloadTest); - - static gboolean decidePolicyCallback(WebKitWebView* webView, WebKitPolicyDecision* decision, WebKitPolicyDecisionType type, PolicyResponseDownloadTest* test) - { - if (type != WEBKIT_POLICY_DECISION_TYPE_RESPONSE) - return FALSE; - - webkit_policy_decision_download(decision); - return TRUE; - } - - PolicyResponseDownloadTest() - { - g_signal_connect(m_webView, "decide-policy", G_CALLBACK(decidePolicyCallback), this); - } - - ~PolicyResponseDownloadTest() - { - g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); - } - - void cancelDownloadAndWaitUntilFinished() - { - webkit_download_cancel(m_download.get()); - waitUntilDownloadFinished(); - m_download = 0; - } -}; - -static void testPolicyResponseDownload(PolicyResponseDownloadTest* test, gconstpointer) -{ - // Test that a download started by the the policy checker contains the web view. - CString requestURI = kServer->getURIForPath("/test.pdf").data(); - test->loadURI(requestURI.data()); - test->waitUntilDownloadStarted(); - - WebKitURIRequest* request = webkit_download_get_request(test->m_download.get()); - g_assert(request); - ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, requestURI); - - g_assert(test->m_webView == webkit_download_get_web_view(test->m_download.get())); - test->cancelDownloadAndWaitUntilFinished(); -} - -void beforeAll() -{ - kServer = new WebKitTestServer(); - kServer->run(serverCallback); - - kTempDirectory = g_dir_make_tmp("WebKit2Tests-XXXXXX", 0); - g_assert(kTempDirectory); - - DownloadTest::add("Downloads", "local-file", testDownloadLocalFile); - DownloadErrorTest::add("Downloads", "local-file-error", testDownloadLocalFileError); - DownloadTest::add("Downloads", "remote-file", testDownloadRemoteFile); - DownloadErrorTest::add("Downloads", "remote-file-error", testDownloadRemoteFileError); - WebViewDownloadTest::add("WebKitWebView", "download-uri", testWebViewDownloadURI); - PolicyResponseDownloadTest::add("Downloads", "policy-decision-download", testPolicyResponseDownload); -} - -void afterAll() -{ - delete kServer; - g_rmdir(kTempDirectory); -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestInspector.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestInspector.cpp deleted file mode 100644 index aa80888b3..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestInspector.cpp +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include "WebViewTest.h" -#include <wtf/gobject/GRefPtr.h> - -class InspectorTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(InspectorTest); - - enum InspectorEvents { - OpenWindow, - BringToFront, - Closed, - Attach, - Detach - }; - - static gboolean openWindowCallback(WebKitWebInspector*, InspectorTest* test) - { - return test->openWindow(); - } - - static gboolean bringToFrontCallback(WebKitWebInspector*, InspectorTest* test) - { - return test->bringToFront(); - } - - static void closedCallback(WebKitWebInspector*, InspectorTest* test) - { - return test->closed(); - } - - static gboolean attachCallback(WebKitWebInspector*, InspectorTest* test) - { - return test->attach(); - } - - static gboolean detachCallback(WebKitWebInspector*, InspectorTest* test) - { - return test->detach(); - } - - static const unsigned gMinimumAttachedInspectorWidth = 750; - static const unsigned gMinimumAttachedInspectorHeight = 250; - - InspectorTest() - : WebViewTest() - , m_inspector(webkit_web_view_get_inspector(m_webView)) - { - webkit_settings_set_enable_developer_extras(webkit_web_view_get_settings(m_webView), TRUE); - assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_inspector)); - g_signal_connect(m_inspector, "open-window", G_CALLBACK(openWindowCallback), this); - g_signal_connect(m_inspector, "bring-to-front", G_CALLBACK(bringToFrontCallback), this); - g_signal_connect(m_inspector, "closed", G_CALLBACK(closedCallback), this); - g_signal_connect(m_inspector, "attach", G_CALLBACK(attachCallback), this); - g_signal_connect(m_inspector, "detach", G_CALLBACK(detachCallback), this); - } - - ~InspectorTest() - { - g_signal_handlers_disconnect_matched(m_inspector, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); - } - - virtual bool openWindow() - { - m_events.append(OpenWindow); - g_main_loop_quit(m_mainLoop); - return TRUE; - } - - virtual bool bringToFront() - { - m_events.append(BringToFront); - g_main_loop_quit(m_mainLoop); - return FALSE; - } - - virtual void closed() - { - m_events.append(Closed); - } - - virtual bool attach() - { - m_events.append(Attach); - return TRUE; - } - - virtual bool detach() - { - m_events.append(Detach); - return TRUE; - } - - - static gboolean showIdle(InspectorTest* test) - { - webkit_web_inspector_show(test->m_inspector); - return FALSE; - } - - void show() - { - g_idle_add(reinterpret_cast<GSourceFunc>(showIdle), this); - g_main_loop_run(m_mainLoop); - } - - void resizeViewAndAttach() - { - // Resize the view to make room for the inspector. - resizeView(gMinimumAttachedInspectorWidth, (gMinimumAttachedInspectorHeight + 1) * 4 / 3); - webkit_web_inspector_attach(m_inspector); - } - - static gboolean detachIdle(InspectorTest* test) - { - webkit_web_inspector_detach(test->m_inspector); - return FALSE; - } - - void detachAndWaitUntilWindowOpened() - { - g_idle_add(reinterpret_cast<GSourceFunc>(detachIdle), this); - g_main_loop_run(m_mainLoop); - } - - void close() - { - webkit_web_inspector_close(m_inspector); - } - - WebKitWebInspector* m_inspector; - Vector<InspectorEvents> m_events; -}; - -static void testInspectorDefault(InspectorTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(GTK_WINDOW_TOPLEVEL); - test->resizeView(200, 200); - test->loadHtml("<html><body><p>WebKitGTK+ Inspector test</p></body></html>", 0); - test->waitUntilLoadFinished(); - - test->show(); - // We don't add the view to a container, so consume the weak ref with GRefPtr. - GRefPtr<WebKitWebViewBase> inspectorView = webkit_web_inspector_get_web_view(test->m_inspector); - g_assert(inspectorView.get()); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(inspectorView.get())); - g_assert(!webkit_web_inspector_is_attached(test->m_inspector)); - g_assert_cmpuint(webkit_web_inspector_get_attached_height(test->m_inspector), ==, 0); - Vector<InspectorTest::InspectorEvents>& events = test->m_events; - g_assert_cmpint(events.size(), ==, 1); - g_assert_cmpint(events[0], ==, InspectorTest::OpenWindow); - test->m_events.clear(); - - test->show(); - events = test->m_events; - g_assert_cmpint(events.size(), ==, 1); - g_assert_cmpint(events[0], ==, InspectorTest::BringToFront); - test->m_events.clear(); - - test->resizeViewAndAttach(); - g_assert(webkit_web_inspector_is_attached(test->m_inspector)); - g_assert_cmpuint(webkit_web_inspector_get_attached_height(test->m_inspector), >=, InspectorTest::gMinimumAttachedInspectorHeight); - events = test->m_events; - g_assert_cmpint(events.size(), ==, 1); - g_assert_cmpint(events[0], ==, InspectorTest::Attach); - test->m_events.clear(); - - test->detachAndWaitUntilWindowOpened(); - g_assert(!webkit_web_inspector_is_attached(test->m_inspector)); - events = test->m_events; - g_assert_cmpint(events.size(), ==, 2); - g_assert_cmpint(events[0], ==, InspectorTest::Detach); - g_assert_cmpint(events[1], ==, InspectorTest::OpenWindow); - test->m_events.clear(); - - test->close(); - events = test->m_events; - g_assert_cmpint(events.size(), ==, 1); - g_assert_cmpint(events[0], ==, InspectorTest::Closed); - test->m_events.clear(); -} - -class CustomInspectorTest: public InspectorTest { -public: - MAKE_GLIB_TEST_FIXTURE(CustomInspectorTest); - - CustomInspectorTest() - : InspectorTest() - , m_inspectorWindow(0) - { - } - - ~CustomInspectorTest() - { - if (m_inspectorWindow) - gtk_widget_destroy(m_inspectorWindow); - } - - bool openWindow() - { - g_assert(!m_inspectorWindow); - m_inspectorWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); - WebKitWebViewBase* inspectorView = webkit_web_inspector_get_web_view(m_inspector); - g_assert(inspectorView); - gtk_container_add(GTK_CONTAINER(m_inspectorWindow), GTK_WIDGET(inspectorView)); - gtk_widget_show_all(m_inspectorWindow); - - return InspectorTest::openWindow(); - } - - void closed() - { - if (m_inspectorWindow) { - gtk_widget_destroy(m_inspectorWindow); - m_inspectorWindow = 0; - } - - return InspectorTest::closed(); - } - - bool attach() - { - GRefPtr<WebKitWebViewBase> inspectorView = webkit_web_inspector_get_web_view(m_inspector); - if (m_inspectorWindow) { - gtk_container_remove(GTK_CONTAINER(m_inspectorWindow), GTK_WIDGET(inspectorView.get())); - gtk_widget_destroy(m_inspectorWindow); - m_inspectorWindow = 0; - } - - GtkWidget* pane; - if (gtk_bin_get_child(GTK_BIN(m_parentWindow)) == GTK_WIDGET(m_webView)) { - GRefPtr<WebKitWebView> inspectedView = m_webView; - gtk_container_remove(GTK_CONTAINER(m_parentWindow), GTK_WIDGET(m_webView)); - pane = gtk_paned_new(GTK_ORIENTATION_VERTICAL); - gtk_paned_add1(GTK_PANED(pane), GTK_WIDGET(m_webView)); - gtk_container_add(GTK_CONTAINER(m_parentWindow), pane); - gtk_widget_show_all(pane); - } else - pane = gtk_bin_get_child(GTK_BIN(m_parentWindow)); - gtk_paned_set_position(GTK_PANED(pane), webkit_web_inspector_get_attached_height(m_inspector)); - gtk_paned_add2(GTK_PANED(pane), GTK_WIDGET(inspectorView.get())); - - return InspectorTest::attach(); - } - - bool detach() - { - GRefPtr<WebKitWebViewBase> inspectorView = webkit_web_inspector_get_web_view(m_inspector); - GtkWidget* pane = gtk_bin_get_child(GTK_BIN(m_parentWindow)); - g_assert(GTK_IS_PANED(pane)); - gtk_container_remove(GTK_CONTAINER(pane), GTK_WIDGET(inspectorView.get())); - return InspectorTest::detach(); - } - - void destroyWindow() - { - g_assert(m_inspectorWindow); - gtk_widget_destroy(m_inspectorWindow); - m_inspectorWindow = 0; - } - - GtkWidget* m_inspectorWindow; -}; - -static void testInspectorManualAttachDetach(CustomInspectorTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(GTK_WINDOW_TOPLEVEL); - test->resizeView(200, 200); - test->loadHtml("<html><body><p>WebKitGTK+ Inspector test</p></body></html>", 0); - test->waitUntilLoadFinished(); - - test->show(); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_web_inspector_get_web_view(test->m_inspector))); - g_assert(!webkit_web_inspector_is_attached(test->m_inspector)); - Vector<InspectorTest::InspectorEvents>& events = test->m_events; - g_assert_cmpint(events.size(), ==, 1); - g_assert_cmpint(events[0], ==, InspectorTest::OpenWindow); - test->m_events.clear(); - - test->resizeViewAndAttach(); - g_assert(webkit_web_inspector_is_attached(test->m_inspector)); - g_assert_cmpuint(webkit_web_inspector_get_attached_height(test->m_inspector), >=, InspectorTest::gMinimumAttachedInspectorHeight); - events = test->m_events; - g_assert_cmpint(events.size(), ==, 1); - g_assert_cmpint(events[0], ==, InspectorTest::Attach); - test->m_events.clear(); - - test->detachAndWaitUntilWindowOpened(); - g_assert(!webkit_web_inspector_is_attached(test->m_inspector)); - events = test->m_events; - g_assert_cmpint(events.size(), ==, 2); - g_assert_cmpint(events[0], ==, InspectorTest::Detach); - g_assert_cmpint(events[1], ==, InspectorTest::OpenWindow); - test->m_events.clear(); - - test->resizeViewAndAttach(); - g_assert(webkit_web_inspector_is_attached(test->m_inspector)); - test->m_events.clear(); - test->close(); - events = test->m_events; - g_assert_cmpint(events.size(), ==, 2); - g_assert_cmpint(events[0], ==, InspectorTest::Detach); - g_assert_cmpint(events[1], ==, InspectorTest::Closed); - test->m_events.clear(); -} - -static void testInspectorCustomContainerDestroyed(CustomInspectorTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(GTK_WINDOW_TOPLEVEL); - test->resizeView(200, 200); - test->loadHtml("<html><body><p>WebKitGTK+ Inspector test</p></body></html>", 0); - test->waitUntilLoadFinished(); - - test->show(); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_web_inspector_get_web_view(test->m_inspector))); - g_assert(!webkit_web_inspector_is_attached(test->m_inspector)); - - test->m_events.clear(); - test->destroyWindow(); - Vector<InspectorTest::InspectorEvents>& events = test->m_events; - g_assert_cmpint(events.size(), ==, 1); - g_assert_cmpint(events[0], ==, InspectorTest::Closed); - test->m_events.clear(); -} - -void beforeAll() -{ - g_setenv("WEBKIT_INSPECTOR_PATH", WEBKIT_INSPECTOR_PATH, FALSE); - InspectorTest::add("WebKitWebInspector", "default", testInspectorDefault); - CustomInspectorTest::add("WebKitWebInspector", "manual-attach-detach", testInspectorManualAttachDetach); - CustomInspectorTest::add("WebKitWebInspector", "custom-container-destroyed", testInspectorCustomContainerDestroyed); -} - -void afterAll() -{ -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestInspectorServer.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestInspectorServer.cpp deleted file mode 100644 index 35fb3fcdc..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestInspectorServer.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright (C) 2012 Samsung Electronics Ltd. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#include "WebViewTest.h" -#include <wtf/gobject/GRefPtr.h> -#include <wtf/text/WTFString.h> - -// Name of the test server application creating the webView object. -static const char* gTestServerAppName = "InspectorTestServer"; - -// Max seconds to wait for the test server before inspecting it. -static const int gMaxWaitForChild = 5; - -// The PID for the test server running, so we can kill it if needed. -static GPid gChildProcessPid = 0; - -// Whether the child has replied and it's ready. -static bool gChildIsReady = false; - -static void stopTestServer() -{ - // Do nothing if there's no server running. - if (!gChildProcessPid) - return; - - g_spawn_close_pid(gChildProcessPid); - kill(gChildProcessPid, SIGTERM); - gChildProcessPid = 0; -} - -static void sigAbortHandler(int sigNum) -{ - // Just stop the test server if SIGABRT was received. - stopTestServer(); -} - -static gpointer testServerMonitorThreadFunc(gpointer) -{ - // Wait for the specified timeout to happen. - g_usleep(gMaxWaitForChild * G_USEC_PER_SEC); - - // Kill the child process if not ready yet. - if (!gChildIsReady) - stopTestServer(); - - g_thread_exit(0); - return 0; -} - -static void startTestServerMonitor() -{ - gChildIsReady = false; - g_thread_new("TestServerMonitor", testServerMonitorThreadFunc, 0); -} - -static void startTestServer() -{ - // Prepare argv[] for spawning the server process. - GOwnPtr<char> testServerPath(g_build_filename(WEBKIT_EXEC_PATH, "WebKit2APITests", gTestServerAppName, NULL)); - - // We install a handler to ensure that we kill the child process - // if the parent dies because of whatever the reason is. - signal(SIGABRT, sigAbortHandler); - - char* testServerArgv[2]; - testServerArgv[0] = testServerPath.get(); - testServerArgv[1] = 0; - - // Spawn the server, getting its stdout file descriptor to set a - // communication channel, so we know when it's ready. - int childStdout = 0; - g_assert(g_spawn_async_with_pipes(0, testServerArgv, 0, static_cast<GSpawnFlags>(0), 0, 0, - &gChildProcessPid, 0, &childStdout, 0, 0)); - - // Start monitoring the test server (in a separate thread) to - // ensure we don't block on the child process more than a timeout. - startTestServerMonitor(); - - char msg[2]; - GIOChannel* ioChannel = g_io_channel_unix_new(childStdout); - if (g_io_channel_read_chars(ioChannel, msg, 2, 0, 0) == G_IO_STATUS_NORMAL) { - // Check whether the server sent a message saying it's ready - // and store the result globally, so the monitor can see it. - gChildIsReady = msg[0] == 'O' && msg[1] == 'K'; - } - g_io_channel_unref(ioChannel); - close(childStdout); - - // The timeout was reached and the server is not ready yet, so - // stop it inmediately, and let the unit tests fail. - if (!gChildIsReady) - stopTestServer(); -} - -class InspectorServerTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(InspectorServerTest); - - InspectorServerTest() - : WebViewTest() - { - } - - bool getPageList() - { - loadHtml("<script type=\"text/javascript\">\n" - "var pages;\n" - "var xhr = new XMLHttpRequest;\n" - "xhr.open(\"GET\", \"/pagelist.json\");\n" - "xhr.onload = function(e) {\n" - "if (xhr.status == 200) {\n" - "pages = JSON.parse(xhr.responseText);\n" - "document.title = \"OK\";\n" - "} else \n" - "document.title = \"FAIL\";\n" - "}\n" - "xhr.send();\n" - "</script>\n", - "http://127.0.0.1:2999/"); - - waitUntilTitleChanged(); - - if (!strcmp(webkit_web_view_get_title(m_webView), "OK")) - return true; - - return false; - } - - ~InspectorServerTest() - { - } -}; - -// Test to get inspector server page list from the test server. -// Should contain only one entry pointing to http://127.0.0.1:2999/webinspector/inspector.html?page=1 -static void testInspectorServerPageList(InspectorServerTest* test, gconstpointer) -{ - GOwnPtr<GError> error; - - test->showInWindowAndWaitUntilMapped(GTK_WINDOW_TOPLEVEL); - g_assert(test->getPageList()); - - WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished("pages.length;", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - g_assert_cmpint(WebViewTest::javascriptResultToNumber(javascriptResult), ==, 1); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("pages[0].id;", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - int pageId = WebViewTest::javascriptResultToNumber(javascriptResult); - - GOwnPtr<char> valueString; - javascriptResult = test->runJavaScriptAndWaitUntilFinished("pages[0].url;", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - valueString.set(WebViewTest::javascriptResultToCString(javascriptResult)); - g_assert_cmpstr(valueString.get(), ==, "http://127.0.0.1:2999/"); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("pages[0].inspectorUrl;", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - valueString.set(WebViewTest::javascriptResultToCString(javascriptResult)); - String validInspectorURL = String("/inspector.html?page=") + String::number(pageId); - ASSERT_CMP_CSTRING(valueString.get(), ==, validInspectorURL.utf8()); -} - -// Test sending a raw remote debugging message through our web socket server. -// For this specific message see: http://code.google.com/chrome/devtools/docs/protocol/tot/runtime.html#command-evaluate -static void testRemoteDebuggingMessage(InspectorServerTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(GTK_WINDOW_TOPLEVEL); - - test->loadHtml("<script type=\"text/javascript\">\n" - "var socket = new WebSocket('ws://127.0.0.1:2999/devtools/page/1');\n" - "socket.onmessage = function(message) {\n" - "var response = JSON.parse(message.data);\n" - "if (response.id === 1)\n" - "document.title = response.result.result.value;\n" - "else\n" - "document.title = \"FAIL\";\n" - "}\n" - "socket.onopen = function() {\n" - "socket.send('{\"id\": 1, \"method\": \"Runtime.evaluate\", \"params\": {\"expression\": \"2 + 2\" } }');\n" - "}\n" - "</script>", - "http://127.0.0.1:2999/"); - test->waitUntilTitleChanged(); - - g_assert_cmpstr(webkit_web_view_get_title(test->m_webView), ==, "4"); -} - -static void openRemoteDebuggingSession(InspectorServerTest* test, gconstpointer) -{ - // To test the whole pipeline this exploits a behavior of the inspector front-end which won't provide any title unless the - // debugging session was established correctly through web socket. It should be something like "Web Inspector - <Page URL>". - // In our case page URL should be http://127.0.0.1:2999/ - // So this test case will fail if: - // - The page list didn't return a valid inspector URL - // - Or the front-end couldn't be loaded through the inspector HTTP server - // - Or the web socket connection couldn't be established between the front-end and the page through the inspector server - // Let's see if this test isn't raising too many false positives, in which case we should use a better predicate if available. - - test->showInWindowAndWaitUntilMapped(GTK_WINDOW_TOPLEVEL); - - g_assert(test->getPageList()); - - GOwnPtr<GError> error; - WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished("pages[0].inspectorUrl;", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - - String resolvedURL = String("http://127.0.0.1:2999/") + String::fromUTF8(WebViewTest::javascriptResultToCString(javascriptResult)); - test->loadURI(resolvedURL.utf8().data()); - test->waitUntilTitleChanged(); - - g_assert_cmpstr(webkit_web_view_get_title(test->m_webView), ==, "Web Inspector - http://127.0.0.1:2999/"); -} - - -void beforeAll() -{ - // Overwrite WEBKIT_INSPECTOR_SERVER variable with default IP address but different port to avoid conflict with the test inspector server page. - g_setenv("WEBKIT_INSPECTOR_SERVER", "127.0.0.1:2998", TRUE); - - startTestServer(); - InspectorServerTest::add("WebKitWebInspectorServer", "test-page-list", testInspectorServerPageList); - InspectorServerTest::add("WebKitWebInspectorServer", "test-remote-debugging-message", testRemoteDebuggingMessage); - InspectorServerTest::add("WebKitWebInspectorServer", "test-open-debugging-session", openRemoteDebuggingSession); - -} - -void afterAll() -{ - stopTestServer(); -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp deleted file mode 100644 index 331915e00..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp +++ /dev/null @@ -1,465 +0,0 @@ -/* - * Copyright (C) 2009, 2010 Gustavo Noronha Silva - * Copyright (C) 2009, 2011 Igalia S.L. - * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include "LoadTrackingTest.h" -#include "WebKitTestBus.h" -#include "WebKitTestServer.h" -#include "WebViewTest.h" -#include <gtk/gtk.h> -#include <libsoup/soup.h> -#include <wtf/text/CString.h> - -static WebKitTestBus* bus; -static WebKitTestServer* kServer; - -const char* kDNTHeaderNotPresent = "DNT header not present"; - -static void testLoadingStatus(LoadTrackingTest* test, gconstpointer data) -{ - test->setRedirectURI(kServer->getURIForPath("/normal").data()); - test->loadURI(kServer->getURIForPath("/redirect").data()); - test->waitUntilLoadFinished(); - - Vector<LoadTrackingTest::LoadEvents>& events = test->m_loadEvents; - g_assert_cmpint(events.size(), ==, 4); - g_assert_cmpint(events[0], ==, LoadTrackingTest::ProvisionalLoadStarted); - g_assert_cmpint(events[1], ==, LoadTrackingTest::ProvisionalLoadReceivedServerRedirect); - g_assert_cmpint(events[2], ==, LoadTrackingTest::LoadCommitted); - g_assert_cmpint(events[3], ==, LoadTrackingTest::LoadFinished); -} - -static void testLoadingError(LoadTrackingTest* test, gconstpointer) -{ - test->loadURI(kServer->getURIForPath("/error").data()); - test->waitUntilLoadFinished(); - - Vector<LoadTrackingTest::LoadEvents>& events = test->m_loadEvents; - g_assert_cmpint(events.size(), ==, 3); - g_assert_cmpint(events[0], ==, LoadTrackingTest::ProvisionalLoadStarted); - g_assert_cmpint(events[1], ==, LoadTrackingTest::ProvisionalLoadFailed); - g_assert_cmpint(events[2], ==, LoadTrackingTest::LoadFinished); -} - -static void assertNormalLoadHappened(Vector<LoadTrackingTest::LoadEvents>& events) -{ - g_assert_cmpint(events.size(), ==, 3); - g_assert_cmpint(events[0], ==, LoadTrackingTest::ProvisionalLoadStarted); - g_assert_cmpint(events[1], ==, LoadTrackingTest::LoadCommitted); - g_assert_cmpint(events[2], ==, LoadTrackingTest::LoadFinished); -} - -static void testLoadHtml(LoadTrackingTest* test, gconstpointer) -{ - test->loadHtml("<html><body>Hello WebKit-GTK+</body></html>", 0); - test->waitUntilLoadFinished(); - assertNormalLoadHappened(test->m_loadEvents); -} - -static void testLoadAlternateHTML(LoadTrackingTest* test, gconstpointer) -{ - test->loadAlternateHTML("<html><body>Alternate page</body></html>", "http://error-page.foo/", 0); - test->waitUntilLoadFinished(); - assertNormalLoadHappened(test->m_loadEvents); -} - -static void testLoadPlainText(LoadTrackingTest* test, gconstpointer) -{ - test->loadPlainText("Hello WebKit-GTK+"); - test->waitUntilLoadFinished(); - assertNormalLoadHappened(test->m_loadEvents); -} - -static void testLoadRequest(LoadTrackingTest* test, gconstpointer) -{ - GRefPtr<WebKitURIRequest> request(webkit_uri_request_new(kServer->getURIForPath("/normal").data())); - test->loadRequest(request.get()); - test->waitUntilLoadFinished(); - assertNormalLoadHappened(test->m_loadEvents); -} - -class LoadStopTrackingTest : public LoadTrackingTest { -public: - MAKE_GLIB_TEST_FIXTURE(LoadStopTrackingTest); - - virtual void loadCommitted() - { - LoadTrackingTest::loadCommitted(); - webkit_web_view_stop_loading(m_webView); - } - virtual void loadFailed(const gchar* failingURI, GError* error) - { - g_assert(g_error_matches(error, WEBKIT_NETWORK_ERROR, WEBKIT_NETWORK_ERROR_CANCELLED)); - LoadTrackingTest::loadFailed(failingURI, error); - } -}; - -static void testLoadCancelled(LoadStopTrackingTest* test, gconstpointer) -{ - test->loadURI(kServer->getURIForPath("/cancelled").data()); - test->waitUntilLoadFinished(); - - Vector<LoadTrackingTest::LoadEvents>& events = test->m_loadEvents; - g_assert_cmpint(events.size(), ==, 4); - g_assert_cmpint(events[0], ==, LoadTrackingTest::ProvisionalLoadStarted); - g_assert_cmpint(events[1], ==, LoadTrackingTest::LoadCommitted); - g_assert_cmpint(events[2], ==, LoadTrackingTest::LoadFailed); - g_assert_cmpint(events[3], ==, LoadTrackingTest::LoadFinished); -} - -static void testWebViewTitle(LoadTrackingTest* test, gconstpointer) -{ - g_assert(!webkit_web_view_get_title(test->m_webView)); - test->loadHtml("<html><head><title>Welcome to WebKit-GTK+!</title></head></html>", 0); - test->waitUntilLoadFinished(); - g_assert_cmpstr(webkit_web_view_get_title(test->m_webView), ==, "Welcome to WebKit-GTK+!"); -} - -static void testWebViewReload(LoadTrackingTest* test, gconstpointer) -{ - // Check that nothing happens when there's nothing to reload. - test->reload(); - test->wait(0.25); // Wait for a quarter of a second. - - test->loadURI(kServer->getURIForPath("/normal").data()); - test->waitUntilLoadFinished(); - assertNormalLoadHappened(test->m_loadEvents); - - test->reload(); - test->waitUntilLoadFinished(); - assertNormalLoadHappened(test->m_loadEvents); -} - -static void testLoadProgress(LoadTrackingTest* test, gconstpointer) -{ - test->loadURI(kServer->getURIForPath("/normal").data()); - test->waitUntilLoadFinished(); - g_assert_cmpfloat(test->m_estimatedProgress, ==, 1); -} - -static void testWebViewHistoryLoad(LoadTrackingTest* test, gconstpointer) -{ - test->loadURI(kServer->getURIForPath("/normal").data()); - test->waitUntilLoadFinished(); - assertNormalLoadHappened(test->m_loadEvents); - - test->loadURI(kServer->getURIForPath("/normal2").data()); - test->waitUntilLoadFinished(); - assertNormalLoadHappened(test->m_loadEvents); - - // Check that load process is the same for pages loaded from history cache. - test->goBack(); - test->waitUntilLoadFinished(); - assertNormalLoadHappened(test->m_loadEvents); - - test->goForward(); - test->waitUntilLoadFinished(); - assertNormalLoadHappened(test->m_loadEvents); -} - -class ViewURITrackingTest: public LoadTrackingTest { -public: - MAKE_GLIB_TEST_FIXTURE(ViewURITrackingTest); - - static void uriChanged(GObject*, GParamSpec*, ViewURITrackingTest* test) - { - g_assert_cmpstr(test->m_activeURI.data(), !=, webkit_web_view_get_uri(test->m_webView)); - test->m_activeURI = webkit_web_view_get_uri(test->m_webView); - } - - ViewURITrackingTest() - : m_activeURI(webkit_web_view_get_uri(m_webView)) - { - g_assert(m_activeURI.isNull()); - g_signal_connect(m_webView, "notify::uri", G_CALLBACK(uriChanged), this); - } - - void provisionalLoadStarted() - { - checkActiveURI("/redirect"); - } - - void provisionalLoadReceivedServerRedirect() - { - checkActiveURI("/normal"); - } - - void loadCommitted() - { - checkActiveURI("/normal"); - } - - void loadFinished() - { - checkActiveURI("/normal"); - LoadTrackingTest::loadFinished(); - } - - CString m_activeURI; - -private: - void checkActiveURI(const char* uri) - { - ASSERT_CMP_CSTRING(m_activeURI, ==, kServer->getURIForPath(uri)); - } -}; - -static void testWebViewActiveURI(ViewURITrackingTest* test, gconstpointer) -{ - test->loadURI(kServer->getURIForPath("/redirect").data()); - test->waitUntilLoadFinished(); -} - -class ViewIsLoadingTest: public LoadTrackingTest { -public: - MAKE_GLIB_TEST_FIXTURE(ViewIsLoadingTest); - - static void isLoadingChanged(GObject*, GParamSpec*, ViewIsLoadingTest* test) - { - if (webkit_web_view_is_loading(test->m_webView)) - test->beginLoad(); - else - test->endLoad(); - } - - ViewIsLoadingTest() - { - g_signal_connect(m_webView, "notify::is-loading", G_CALLBACK(isLoadingChanged), this); - } - - void beginLoad() - { - // New load, load-started hasn't been emitted yet. - g_assert(m_loadEvents.isEmpty()); - g_assert_cmpstr(webkit_web_view_get_uri(m_webView), ==, m_activeURI.data()); - } - - void endLoad() - { - // Load finish, load-finished and load-failed haven't been emitted yet. - g_assert(!m_loadEvents.isEmpty()); - g_assert(!m_loadEvents.contains(LoadTrackingTest::LoadFinished)); - g_assert(!m_loadEvents.contains(LoadTrackingTest::LoadFailed)); - } -}; - -static void testWebViewIsLoading(ViewIsLoadingTest* test, gconstpointer) -{ - test->loadURI(kServer->getURIForPath("/normal").data()); - test->waitUntilLoadFinished(); - - test->reload(); - test->waitUntilLoadFinished(); - - test->loadURI(kServer->getURIForPath("/error").data()); - test->waitUntilLoadFinished(); - - test->loadURI(kServer->getURIForPath("/normal").data()); - test->waitUntilLoadFinished(); - test->loadURI(kServer->getURIForPath("/normal2").data()); - test->waitUntilLoadFinished(); - - test->goBack(); - test->waitUntilLoadFinished(); - - test->goForward(); - test->waitUntilLoadFinished(); -} - -class WebPageURITest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(WebPageURITest); - - static void webPageURIChangedCallback(GDBusConnection*, const char*, const char*, const char*, const char*, GVariant* result, WebPageURITest* test) - { - const char* uri; - g_variant_get(result, "(&s)", &uri); - test->m_webPageURIs.append(uri); - } - - static void webViewURIChanged(GObject*, GParamSpec*, WebPageURITest* test) - { - test->m_webViewURIs.append(webkit_web_view_get_uri(test->m_webView)); - } - - WebPageURITest() - { - GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy("org.webkit.gtk.WebExtensionTest", - "/org/webkit/gtk/WebExtensionTest", "org.webkit.gtk.WebExtensionTest", m_mainLoop)); - m_uriChangedSignalID = g_dbus_connection_signal_subscribe( - g_dbus_proxy_get_connection(proxy.get()), - 0, - "org.webkit.gtk.WebExtensionTest", - "URIChanged", - "/org/webkit/gtk/WebExtensionTest", - 0, - G_DBUS_SIGNAL_FLAGS_NONE, - reinterpret_cast<GDBusSignalCallback>(webPageURIChangedCallback), - this, - 0); - g_assert(m_uriChangedSignalID); - - g_signal_connect(m_webView, "notify::uri", G_CALLBACK(webViewURIChanged), this); - } - - ~WebPageURITest() - { - g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); - g_dbus_connection_signal_unsubscribe(bus->connection(), m_uriChangedSignalID); - } - - unsigned m_uriChangedSignalID; - Vector<CString> m_webPageURIs; - Vector<CString> m_webViewURIs; -}; - -static void testWebPageURI(WebPageURITest* test, gconstpointer) -{ - test->loadURI(kServer->getURIForPath("/redirect").data()); - test->waitUntilLoadFinished(); - - g_assert_cmpint(test->m_webPageURIs.size(), ==, test->m_webViewURIs.size()); - for (size_t i = 0; i < test->m_webPageURIs.size(); ++i) - ASSERT_CMP_CSTRING(test->m_webPageURIs[i], ==, test->m_webViewURIs[i]); - - g_assert_cmpint(test->m_webPageURIs.size(), ==, 2); - ASSERT_CMP_CSTRING(test->m_webPageURIs[0], ==, kServer->getURIForPath("/redirect")); - ASSERT_CMP_CSTRING(test->m_webPageURIs[1], ==, kServer->getURIForPath("/normal")); - -} - -static void testURIRequestHTTPHeaders(WebViewTest* test, gconstpointer) -{ - GRefPtr<WebKitURIRequest> uriRequest = adoptGRef(webkit_uri_request_new("file:///foo/bar")); - g_assert(uriRequest.get()); - g_assert_cmpstr(webkit_uri_request_get_uri(uriRequest.get()), ==, "file:///foo/bar"); - g_assert(!webkit_uri_request_get_http_headers(uriRequest.get())); - - // Load a request with no Do Not Track header. - webkit_uri_request_set_uri(uriRequest.get(), kServer->getURIForPath("/do-not-track-header").data()); - test->loadRequest(uriRequest.get()); - test->waitUntilLoadFinished(); - - size_t mainResourceDataSize = 0; - const char* mainResourceData = test->mainResourceData(mainResourceDataSize); - g_assert_cmpint(mainResourceDataSize, ==, strlen(kDNTHeaderNotPresent)); - g_assert(!strncmp(mainResourceData, kDNTHeaderNotPresent, mainResourceDataSize)); - - // Add the Do Not Track header and load the request again. - SoupMessageHeaders* headers = webkit_uri_request_get_http_headers(uriRequest.get()); - g_assert(headers); - soup_message_headers_append(headers, "DNT", "1"); - test->loadRequest(uriRequest.get()); - test->waitUntilLoadFinished(); - - mainResourceData = test->mainResourceData(mainResourceDataSize); - g_assert_cmpint(mainResourceDataSize, ==, 1); - g_assert(!strncmp(mainResourceData, "1", mainResourceDataSize)); - - // Load a URI for which the web extension will add the Do Not Track header. - test->loadURI(kServer->getURIForPath("/add-do-not-track-header").data()); - test->waitUntilLoadFinished(); - - mainResourceData = test->mainResourceData(mainResourceDataSize); - g_assert_cmpint(mainResourceDataSize, ==, 1); - g_assert(!strncmp(mainResourceData, "1", mainResourceDataSize)); -} - -static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) -{ - static const char* responseString = "<html><body>Testing!Testing!Testing!Testing!Testing!Testing!Testing!" - "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!" - "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!" - "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!" - "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!" - "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!" - "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!" - "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!</body></html>"; - - if (message->method != SOUP_METHOD_GET) { - soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); - return; - } - - soup_message_set_status(message, SOUP_STATUS_OK); - - if (g_str_has_prefix(path, "/normal")) - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString)); - else if (g_str_equal(path, "/error")) - soup_message_set_status(message, SOUP_STATUS_CANT_CONNECT); - else if (g_str_equal(path, "/redirect")) { - soup_message_set_status(message, SOUP_STATUS_MOVED_PERMANENTLY); - soup_message_headers_append(message->response_headers, "Location", "/normal"); - } else if (g_str_equal(path, "/cancelled")) { - soup_message_headers_set_encoding(message->response_headers, SOUP_ENCODING_CHUNKED); - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString)); - soup_server_unpause_message(server, message); - return; - } else if (g_str_equal(path, "/do-not-track-header") || g_str_equal(path, "/add-do-not-track-header")) { - const char* doNotTrack = soup_message_headers_get_one(message->request_headers, "DNT"); - if (doNotTrack) - soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, doNotTrack, strlen(doNotTrack)); - else - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kDNTHeaderNotPresent, strlen(kDNTHeaderNotPresent)); - soup_message_set_status(message, SOUP_STATUS_OK); - } else - soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); - - soup_message_body_complete(message->response_body); -} - -void beforeAll() -{ - webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), WEBKIT_TEST_WEB_EXTENSIONS_DIR); - bus = new WebKitTestBus(); - if (!bus->run()) - return; - - kServer = new WebKitTestServer(); - kServer->run(serverCallback); - - LoadTrackingTest::add("WebKitWebView", "loading-status", testLoadingStatus); - LoadTrackingTest::add("WebKitWebView", "loading-error", testLoadingError); - LoadTrackingTest::add("WebKitWebView", "load-html", testLoadHtml); - LoadTrackingTest::add("WebKitWebView", "load-alternate-html", testLoadAlternateHTML); - LoadTrackingTest::add("WebKitWebView", "load-plain-text", testLoadPlainText); - LoadTrackingTest::add("WebKitWebView", "load-request", testLoadRequest); - LoadStopTrackingTest::add("WebKitWebView", "stop-loading", testLoadCancelled); - LoadTrackingTest::add("WebKitWebView", "title", testWebViewTitle); - LoadTrackingTest::add("WebKitWebView", "progress", testLoadProgress); - LoadTrackingTest::add("WebKitWebView", "reload", testWebViewReload); - LoadTrackingTest::add("WebKitWebView", "history-load", testWebViewHistoryLoad); - - // This test checks that web view notify::uri signal is correctly emitted - // and the uri is already updated when loader client signals are emitted. - ViewURITrackingTest::add("WebKitWebView", "active-uri", testWebViewActiveURI); - - ViewIsLoadingTest::add("WebKitWebView", "is-loading", testWebViewIsLoading); - WebPageURITest::add("WebKitWebPage", "get-uri", testWebPageURI); - WebViewTest::add("WebKitURIRequest", "http-headers", testURIRequestHTTPHeaders); -} - -void afterAll() -{ - delete bus; - delete kServer; -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp deleted file mode 100644 index 6ac35f8ca..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2011 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "TestMain.h" - -#include <glib/gstdio.h> -#include <gtk/gtk.h> -#include <webkit2/webkit2.h> -#include <wtf/gobject/GOwnPtr.h> - -void beforeAll(); -void afterAll(); - -static void registerGResource(void) -{ - GOwnPtr<char> resourcesPath(g_build_filename(WEBKIT_EXEC_PATH, "resources", "webkit2gtk-tests-resources.gresource", NULL)); - GResource* resource = g_resource_load(resourcesPath.get(), 0); - g_assert(resource); - - g_resources_register(resource); - g_resource_unref(resource); -} - -static void removeNonEmptyDirectory(const char* directoryPath) -{ - GDir* directory = g_dir_open(directoryPath, 0, 0); - g_assert(directory); - const char* fileName; - while ((fileName = g_dir_read_name(directory))) { - GOwnPtr<char> filePath(g_build_filename(directoryPath, fileName, NULL)); - g_unlink(filePath.get()); - } - g_dir_close(directory); - g_rmdir(directoryPath); -} - -int main(int argc, char** argv) -{ - gtk_test_init(&argc, &argv, 0); - g_setenv("WEBKIT_EXEC_PATH", WEBKIT_EXEC_PATH, FALSE); - g_setenv("WEBKIT_INJECTED_BUNDLE_PATH", WEBKIT_INJECTED_BUNDLE_PATH, FALSE); - g_setenv("LC_ALL", "C", TRUE); - g_test_bug_base("https://bugs.webkit.org/"); - - registerGResource(); - - GOwnPtr<char> diskCacheTempDirectory(g_dir_make_tmp("WebKit2TestsDiskCache-XXXXXX", 0)); - g_assert(diskCacheTempDirectory.get()); - webkit_web_context_set_disk_cache_directory(webkit_web_context_get_default(), diskCacheTempDirectory.get()); - - beforeAll(); - int returnValue = g_test_run(); - afterAll(); - - removeNonEmptyDirectory(diskCacheTempDirectory.get()); - - return returnValue; -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h deleted file mode 100644 index 02c90709c..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (C) 2011 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef TestMain_h -#define TestMain_h - -#include <cairo.h> -#include <glib-object.h> -#include <wtf/HashSet.h> -#include <wtf/gobject/GOwnPtr.h> -#include <wtf/text/CString.h> - -#define MAKE_GLIB_TEST_FIXTURE(ClassName) \ - static void setUp(ClassName* fixture, gconstpointer data) \ - { \ - new (fixture) ClassName; \ - } \ - static void tearDown(ClassName* fixture, gconstpointer data) \ - { \ - fixture->~ClassName(); \ - } \ - static void add(const char* suiteName, const char* testName, void (*testFunc)(ClassName*, const void*)) \ - { \ - GOwnPtr<gchar> testPath(g_strdup_printf("/webkit2/%s/%s", suiteName, testName)); \ - g_test_add(testPath.get(), ClassName, 0, ClassName::setUp, testFunc, ClassName::tearDown); \ - } - -#define ASSERT_CMP_CSTRING(s1, cmp, s2) \ - do { CString __s1 = (s1); CString __s2 = (s2); \ - if (g_strcmp0(__s1.data(), __s2.data()) cmp 0) ; else \ - g_assertion_message_cmpstr(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ - #s1 " " #cmp " " #s2, __s1.data(), #cmp, __s2.data()); } while (0) - -class Test { -public: - MAKE_GLIB_TEST_FIXTURE(Test); - - ~Test() - { - if (m_watchedObjects.isEmpty()) - return; - - g_print("Leaked objects:"); - HashSet<GObject*>::const_iterator end = m_watchedObjects.end(); - for (HashSet<GObject*>::const_iterator it = m_watchedObjects.begin(); it != end; ++it) - g_print(" %s(%p)", g_type_name_from_instance(reinterpret_cast<GTypeInstance*>(*it)), *it); - g_print("\n"); - - g_assert(m_watchedObjects.isEmpty()); - } - - static void objectFinalized(Test* test, GObject* finalizedObject) - { - test->m_watchedObjects.remove(finalizedObject); - } - - void assertObjectIsDeletedWhenTestFinishes(GObject* object) - { - m_watchedObjects.add(object); - g_object_weak_ref(object, reinterpret_cast<GWeakNotify>(objectFinalized), this); - } - - static CString getWebKit1TestResoucesDir() - { - GOwnPtr<char> resourcesDir(g_build_filename(WEBKIT_SRC_DIR, "Source", "WebKit", "gtk", "tests", "resources", NULL)); - return resourcesDir.get(); - } - - static CString getResourcesDir() - { - GOwnPtr<char> resourcesDir(g_build_filename(WEBKIT_SRC_DIR, "Source", "WebKit2", "UIProcess", "API", "gtk", "tests", "resources", NULL)); - return resourcesDir.get(); - } - - void addLogFatalFlag(unsigned flag) - { - unsigned fatalMask = g_log_set_always_fatal(static_cast<GLogLevelFlags>(G_LOG_FATAL_MASK)); - fatalMask |= flag; - g_log_set_always_fatal(static_cast<GLogLevelFlags>(fatalMask)); - } - - void removeLogFatalFlag(unsigned flag) - { - unsigned fatalMask = g_log_set_always_fatal(static_cast<GLogLevelFlags>(G_LOG_FATAL_MASK)); - fatalMask &= ~flag; - g_log_set_always_fatal(static_cast<GLogLevelFlags>(fatalMask)); - } - - static bool cairoSurfacesEqual(cairo_surface_t* s1, cairo_surface_t* s2) - { - return (cairo_image_surface_get_format(s1) == cairo_image_surface_get_format(s2) - && cairo_image_surface_get_width(s1) == cairo_image_surface_get_width(s2) - && cairo_image_surface_get_height(s1) == cairo_image_surface_get_height(s2) - && cairo_image_surface_get_stride(s1) == cairo_image_surface_get_stride(s2) - && !memcmp(const_cast<const void*>(reinterpret_cast<void*>(cairo_image_surface_get_data(s1))), - const_cast<const void*>(reinterpret_cast<void*>(cairo_image_surface_get_data(s2))), - cairo_image_surface_get_height(s1)*cairo_image_surface_get_stride(s1))); - } - - HashSet<GObject*> m_watchedObjects; -}; - -#endif // TestMain_h diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp deleted file mode 100644 index 72c2cfbbd..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2,1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "WebViewTest.h" -#include <glib/gstdio.h> -#include <wtf/gobject/GRefPtr.h> - -#ifdef HAVE_GTK_UNIX_PRINTING -#include <gtk/gtkunixprint.h> -#endif - -static char* kTempDirectory; - -static void testPrintOperationPrintSettings(WebViewTest* test, gconstpointer) -{ - GRefPtr<WebKitPrintOperation> printOperation = adoptGRef(webkit_print_operation_new(test->m_webView)); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(printOperation.get())); - - g_assert(!webkit_print_operation_get_print_settings(printOperation.get())); - g_assert(!webkit_print_operation_get_page_setup(printOperation.get())); - - GRefPtr<GtkPrintSettings> printSettings = adoptGRef(gtk_print_settings_new()); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(printSettings.get())); - - GRefPtr<GtkPageSetup> pageSetup = adoptGRef(gtk_page_setup_new()); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(pageSetup.get())); - - webkit_print_operation_set_print_settings(printOperation.get(), printSettings.get()); - webkit_print_operation_set_page_setup(printOperation.get(), pageSetup.get()); - - g_assert(webkit_print_operation_get_print_settings(printOperation.get()) == printSettings.get()); - g_assert(webkit_print_operation_get_page_setup(printOperation.get()) == pageSetup.get()); -} - -static gboolean webViewPrintCallback(WebKitWebView* webView, WebKitPrintOperation* printOperation, WebViewTest* test) -{ - g_assert(webView == test->m_webView); - - g_assert(WEBKIT_IS_PRINT_OPERATION(printOperation)); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(printOperation)); - - g_assert(!webkit_print_operation_get_print_settings(printOperation)); - g_assert(!webkit_print_operation_get_page_setup(printOperation)); - - g_main_loop_quit(test->m_mainLoop); - - return TRUE; -} - -static void testWebViewPrint(WebViewTest* test, gconstpointer) -{ - g_signal_connect(test->m_webView, "print", G_CALLBACK(webViewPrintCallback), test); - test->loadHtml("<html><body onLoad=\"print();\">WebKitGTK+ printing test</body></html>", 0); - g_main_loop_run(test->m_mainLoop); -} - -#ifdef HAVE_GTK_UNIX_PRINTING -class PrintTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(PrintTest); - - static void printFinishedCallback(WebKitPrintOperation*, PrintTest* test) - { - g_main_loop_quit(test->m_mainLoop); - } - - static void printFailedCallback(WebKitPrintOperation*, GError* error, PrintTest* test) - { - g_assert(test->m_expectedError); - g_assert(error); - g_assert(g_error_matches(error, WEBKIT_PRINT_ERROR, test->m_expectedError)); - } - - PrintTest() - : m_expectedError(0) - { - m_printOperation = adoptGRef(webkit_print_operation_new(m_webView)); - assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_printOperation.get())); - g_signal_connect(m_printOperation.get(), "finished", G_CALLBACK(printFinishedCallback), this); - g_signal_connect(m_printOperation.get(), "failed", G_CALLBACK(printFailedCallback), this); - } - - static gboolean testPrintOperationPrintPrinter(GtkPrinter* printer, gpointer userData) - { - if (strcmp(gtk_printer_get_name(printer), "Print to File")) - return FALSE; - - GtkPrinter** foundPrinter = static_cast<GtkPrinter**>(userData); - *foundPrinter = static_cast<GtkPrinter*>(g_object_ref(printer)); - return TRUE; - } - - GtkPrinter* findPrintToFilePrinter() - { - GtkPrinter* printer = 0; - gtk_enumerate_printers(testPrintOperationPrintPrinter, &printer, 0, TRUE); - return printer; - } - - void waitUntilPrintFinished() - { - g_main_loop_run(m_mainLoop); - } - - GRefPtr<WebKitPrintOperation> m_printOperation; - unsigned int m_expectedError; -}; - -static void testPrintOperationPrint(PrintTest* test, gconstpointer) -{ - test->loadHtml("<html><body>WebKitGTK+ printing test</body></html>", 0); - test->waitUntilLoadFinished(); - - GRefPtr<GtkPrinter> printer = adoptGRef(test->findPrintToFilePrinter()); - if (!printer) { - g_message("%s", "Cannot test WebKitPrintOperation/print: no suitable printer found"); - return; - } - - GOwnPtr<char> outputFilename(g_build_filename(kTempDirectory, "webkit-print.pdf", NULL)); - GRefPtr<GFile> outputFile = adoptGRef(g_file_new_for_path(outputFilename.get())); - GOwnPtr<char> outputURI(g_file_get_uri(outputFile.get())); - - GRefPtr<GtkPrintSettings> printSettings = adoptGRef(gtk_print_settings_new()); - gtk_print_settings_set_printer(printSettings.get(), gtk_printer_get_name(printer.get())); - gtk_print_settings_set(printSettings.get(), GTK_PRINT_SETTINGS_OUTPUT_URI, outputURI.get()); - - webkit_print_operation_set_print_settings(test->m_printOperation.get(), printSettings.get()); - webkit_print_operation_print(test->m_printOperation.get()); - test->waitUntilPrintFinished(); - - GRefPtr<GFileInfo> fileInfo = adoptGRef(g_file_query_info(outputFile.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, - static_cast<GFileQueryInfoFlags>(0), 0, 0)); - g_assert(fileInfo.get()); - g_assert_cmpint(g_file_info_get_size(fileInfo.get()), >, 0); - g_assert_cmpstr(g_file_info_get_content_type(fileInfo.get()), ==, "application/pdf"); - - g_file_delete(outputFile.get(), 0, 0); -} - -static void testPrintOperationErrors(PrintTest* test, gconstpointer) -{ - test->loadHtml("<html><body>WebKitGTK+ printing errors test</body></html>", 0); - test->waitUntilLoadFinished(); - - GRefPtr<GtkPrinter> printer = adoptGRef(test->findPrintToFilePrinter()); - if (!printer) { - g_message("%s", "Cannot test WebKitPrintOperation/print: no suitable printer found"); - return; - } - - // General Error: invalid filename. - test->m_expectedError = WEBKIT_PRINT_ERROR_GENERAL; - GRefPtr<GtkPrintSettings> printSettings = adoptGRef(gtk_print_settings_new()); - gtk_print_settings_set_printer(printSettings.get(), gtk_printer_get_name(printer.get())); - gtk_print_settings_set(printSettings.get(), GTK_PRINT_SETTINGS_OUTPUT_URI, "file:///foo/bar"); - webkit_print_operation_set_print_settings(test->m_printOperation.get(), printSettings.get()); - webkit_print_operation_print(test->m_printOperation.get()); - test->waitUntilPrintFinished(); - - // Printer not found error. - test->m_expectedError = WEBKIT_PRINT_ERROR_PRINTER_NOT_FOUND; - gtk_print_settings_set_printer(printSettings.get(), "The fake WebKit printer"); - webkit_print_operation_print(test->m_printOperation.get()); - test->waitUntilPrintFinished(); - - // No pages to print: print even pages for a single page document. - test->m_expectedError = WEBKIT_PRINT_ERROR_INVALID_PAGE_RANGE; - gtk_print_settings_set_printer(printSettings.get(), gtk_printer_get_name(printer.get())); - gtk_print_settings_set_page_set(printSettings.get(), GTK_PAGE_SET_EVEN); - webkit_print_operation_print(test->m_printOperation.get()); - test->waitUntilPrintFinished(); -} -#endif // HAVE_GTK_UNIX_PRINTING - -void beforeAll() -{ - kTempDirectory = g_dir_make_tmp("WebKit2Tests-XXXXXX", 0); - g_assert(kTempDirectory); - - WebViewTest::add("WebKitPrintOperation", "printing-settings", testPrintOperationPrintSettings); - WebViewTest::add("WebKitWebView", "print", testWebViewPrint); -#ifdef HAVE_GTK_UNIX_PRINTING - PrintTest::add("WebKitPrintOperation", "print", testPrintOperationPrint); - PrintTest::add("WebKitPrintOperation", "print-errors", testPrintOperationErrors); -#endif -} - -void afterAll() -{ - g_rmdir(kTempDirectory); -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp deleted file mode 100644 index a24b6fdff..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp +++ /dev/null @@ -1,735 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include "WebKitTestServer.h" -#include "WebViewTest.h" -#include <wtf/gobject/GRefPtr.h> - -static WebKitTestServer* kServer; - -static const char* kIndexHtml = - "<html><head>" - " <link rel='stylesheet' href='/style.css' type='text/css'>" - " <script language='javascript' src='/javascript.js'></script>" - "</head><body>WebKitGTK+ resources test</body></html>"; - -static const char* kStyleCSS = - "body {" - " margin: 0px;" - " padding: 0px;" - " font-family: sans-serif;" - " background: url(/blank.ico) 0 0 no-repeat;" - " color: black;" - "}"; - -static const char* kJavascript = "function foo () { var a = 1; }"; - -class ResourcesTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(ResourcesTest); - - static void resourceSentRequestCallback(WebKitWebResource* resource, WebKitURIRequest* request, WebKitURIResponse* redirectResponse, ResourcesTest* test) - { - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request)); - if (redirectResponse) - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(redirectResponse)); - test->resourceSentRequest(resource, request, redirectResponse); - } - - static void resourceReceivedResponseCallback(WebKitWebResource* resource, GParamSpec*, ResourcesTest* test) - { - g_assert(webkit_web_resource_get_response(resource)); - test->resourceReceivedResponse(resource); - } - - static void resourceReceivedDataCallback(WebKitWebResource* resource, guint64 bytesReceived, ResourcesTest* test) - { - test->resourceReceivedData(resource, bytesReceived); - } - - static void resourceFinishedCallback(WebKitWebResource* resource, ResourcesTest* test) - { - test->resourceFinished(resource); - } - - static void resourceFailedCallback(WebKitWebResource* resource, GError* error, ResourcesTest* test) - { - g_assert(error); - test->resourceFailed(resource, error); - } - - static void resourceLoadStartedCallback(WebKitWebView* webView, WebKitWebResource* resource, WebKitURIRequest* request, ResourcesTest* test) - { - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(resource)); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request)); - - // Ignore favicons. - if (g_str_has_suffix(webkit_uri_request_get_uri(request), "favicon.ico")) - return; - - test->resourceLoadStarted(resource, request); - g_signal_connect(resource, "sent-request", G_CALLBACK(resourceSentRequestCallback), test); - g_signal_connect(resource, "notify::response", G_CALLBACK(resourceReceivedResponseCallback), test); - g_signal_connect(resource, "received-data", G_CALLBACK(resourceReceivedDataCallback), test); - g_signal_connect(resource, "finished", G_CALLBACK(resourceFinishedCallback), test); - g_signal_connect(resource, "failed", G_CALLBACK(resourceFailedCallback), test); - } - - void clearSubresources() - { - g_list_free_full(m_subresources, reinterpret_cast<GDestroyNotify>(g_object_unref)); - m_subresources = 0; - } - - ResourcesTest() - : WebViewTest() - , m_resourcesLoaded(0) - , m_resourcesToLoad(0) - , m_resourceDataSize(0) - , m_subresources(0) - { - g_signal_connect(m_webView, "resource-load-started", G_CALLBACK(resourceLoadStartedCallback), this); - } - - ~ResourcesTest() - { - clearSubresources(); - } - - virtual void resourceLoadStarted(WebKitWebResource* resource, WebKitURIRequest* request) - { - } - - virtual void resourceSentRequest(WebKitWebResource* resource, WebKitURIRequest* request, WebKitURIResponse* redirectResponse) - { - } - - virtual void resourceReceivedResponse(WebKitWebResource* resource) - { - } - - virtual void resourceReceivedData(WebKitWebResource* resource, guint64 bytesReceived) - { - } - - virtual void resourceFinished(WebKitWebResource* resource) - { - g_signal_handlers_disconnect_matched(resource, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); - if (webkit_web_view_get_main_resource(m_webView) != resource) - m_subresources = g_list_prepend(m_subresources, g_object_ref(resource)); - if (++m_resourcesLoaded == m_resourcesToLoad) - g_main_loop_quit(m_mainLoop); - } - - virtual void resourceFailed(WebKitWebResource* resource, GError* error) - { - g_assert_not_reached(); - } - - void waitUntilResourcesLoaded(size_t resourcesCount) - { - m_resourcesLoaded = 0; - m_resourcesToLoad = resourcesCount; - clearSubresources(); - g_main_loop_run(m_mainLoop); - } - - GList* subresources() - { - return m_subresources; - } - - static void resourceGetDataCallback(GObject* object, GAsyncResult* result, gpointer userData) - { - size_t dataSize; - GOwnPtr<GError> error; - unsigned char* data = webkit_web_resource_get_data_finish(WEBKIT_WEB_RESOURCE(object), result, &dataSize, &error.outPtr()); - g_assert(!error.get()); - g_assert(data); - g_assert_cmpint(dataSize, >, 0); - - ResourcesTest* test = static_cast<ResourcesTest*>(userData); - test->m_resourceData.set(reinterpret_cast<char*>(data)); - test->m_resourceDataSize = dataSize; - g_main_loop_quit(test->m_mainLoop); - } - - void checkResourceData(WebKitWebResource* resource) - { - m_resourceDataSize = 0; - webkit_web_resource_get_data(resource, 0, resourceGetDataCallback, this); - g_main_loop_run(m_mainLoop); - - const char* uri = webkit_web_resource_get_uri(resource); - if (uri == kServer->getURIForPath("/")) { - g_assert_cmpint(m_resourceDataSize, ==, strlen(kIndexHtml)); - g_assert(!strncmp(m_resourceData.get(), kIndexHtml, m_resourceDataSize)); - } else if (uri == kServer->getURIForPath("/style.css")) { - g_assert_cmpint(m_resourceDataSize, ==, strlen(kStyleCSS)); - g_assert(!strncmp(m_resourceData.get(), kStyleCSS, m_resourceDataSize)); - } else if (uri == kServer->getURIForPath("/javascript.js")) { - g_assert_cmpint(m_resourceDataSize, ==, strlen(kJavascript)); - g_assert(!strncmp(m_resourceData.get(), kJavascript, m_resourceDataSize)); - } else - g_assert_not_reached(); - m_resourceData.clear(); - } - - size_t m_resourcesLoaded; - size_t m_resourcesToLoad; - GOwnPtr<char> m_resourceData; - size_t m_resourceDataSize; - GList* m_subresources; -}; - -static void testWebViewResources(ResourcesTest* test, gconstpointer) -{ - // Nothing loaded yet, there shoulnd't be resources. - g_assert(!webkit_web_view_get_main_resource(test->m_webView)); - g_assert(!test->subresources()); - - // Load simple page without subresources. - test->loadHtml("<html><body>Testing WebKitGTK+</body></html>", 0); - test->waitUntilLoadFinished(); - WebKitWebResource* resource = webkit_web_view_get_main_resource(test->m_webView); - g_assert(resource); - g_assert_cmpstr(webkit_web_view_get_uri(test->m_webView), ==, webkit_web_resource_get_uri(resource)); - g_assert(!test->subresources()); - - // Load simple page with subresources. - test->loadURI(kServer->getURIForPath("/").data()); - test->waitUntilResourcesLoaded(4); - - resource = webkit_web_view_get_main_resource(test->m_webView); - g_assert(resource); - g_assert_cmpstr(webkit_web_view_get_uri(test->m_webView), ==, webkit_web_resource_get_uri(resource)); - GList* subresources = test->subresources(); - g_assert(subresources); - g_assert_cmpint(g_list_length(subresources), ==, 3); - -#if 0 - // Load the same URI again. - // FIXME: we need a workaround for bug https://bugs.webkit.org/show_bug.cgi?id=78510. - test->loadURI(kServer->getURIForPath("/").data()); - test->waitUntilResourcesLoaded(4); -#endif - - // Reload. - webkit_web_view_reload_bypass_cache(test->m_webView); - test->waitUntilResourcesLoaded(4); -} - -class SingleResourceLoadTest: public ResourcesTest { -public: - MAKE_GLIB_TEST_FIXTURE(SingleResourceLoadTest); - - enum LoadEvents { - Started, - SentRequest, - Redirected, - ReceivedResponse, - ReceivedData, - Finished, - Failed - }; - - SingleResourceLoadTest() - : ResourcesTest() - , m_resourceDataReceived(0) - { - m_resourcesToLoad = 2; - } - - void resourceLoadStarted(WebKitWebResource* resource, WebKitURIRequest* request) - { - if (resource == webkit_web_view_get_main_resource(m_webView)) - return; - - m_resourceDataReceived = 0; - m_resource = resource; - m_loadEvents.append(Started); - } - - void resourceSentRequest(WebKitWebResource* resource, WebKitURIRequest* request, WebKitURIResponse* redirectResponse) - { - if (resource != m_resource) - return; - - if (redirectResponse) - m_loadEvents.append(Redirected); - else - m_loadEvents.append(SentRequest); - } - - void resourceReceivedResponse(WebKitWebResource* resource) - { - if (resource != m_resource) - return; - - m_loadEvents.append(ReceivedResponse); - } - - void resourceReceivedData(WebKitWebResource* resource, guint64 bytesReceived) - { - if (resource != m_resource) - return; - - m_resourceDataReceived += bytesReceived; - if (!m_loadEvents.contains(ReceivedData)) - m_loadEvents.append(ReceivedData); - } - - void resourceFinished(WebKitWebResource* resource) - { - if (resource != m_resource) { - ResourcesTest::resourceFinished(resource); - return; - } - - if (!m_loadEvents.contains(Failed)) { - WebKitURIResponse* response = webkit_web_resource_get_response(m_resource.get()); - g_assert(response); - g_assert_cmpint(webkit_uri_response_get_content_length(response), ==, m_resourceDataReceived); - } - m_loadEvents.append(Finished); - ResourcesTest::resourceFinished(resource); - } - - void resourceFailed(WebKitWebResource* resource, GError* error) - { - if (resource == m_resource) - m_loadEvents.append(Failed); - } - - void waitUntilResourceLoadFinished() - { - m_resource = 0; - m_resourcesLoaded = 0; - g_main_loop_run(m_mainLoop); - } - - WebKitURIResponse* waitUntilResourceLoadFinishedAndReturnURIResponse() - { - waitUntilResourceLoadFinished(); - g_assert(m_resource); - return webkit_web_resource_get_response(m_resource.get()); - } - - GRefPtr<WebKitWebResource> m_resource; - Vector<LoadEvents> m_loadEvents; - guint64 m_resourceDataReceived; -}; - -static void testWebResourceLoading(SingleResourceLoadTest* test, gconstpointer) -{ - test->loadURI(kServer->getURIForPath("/javascript.html").data()); - test->waitUntilResourceLoadFinished(); - g_assert(test->m_resource); - Vector<SingleResourceLoadTest::LoadEvents>& events = test->m_loadEvents; - g_assert_cmpint(events.size(), ==, 5); - g_assert_cmpint(events[0], ==, SingleResourceLoadTest::Started); - g_assert_cmpint(events[1], ==, SingleResourceLoadTest::SentRequest); - g_assert_cmpint(events[2], ==, SingleResourceLoadTest::ReceivedResponse); - g_assert_cmpint(events[3], ==, SingleResourceLoadTest::ReceivedData); - g_assert_cmpint(events[4], ==, SingleResourceLoadTest::Finished); - events.clear(); - - test->loadURI(kServer->getURIForPath("/redirected-css.html").data()); - test->waitUntilResourceLoadFinished(); - g_assert(test->m_resource); - g_assert_cmpint(events.size(), ==, 6); - g_assert_cmpint(events[0], ==, SingleResourceLoadTest::Started); - g_assert_cmpint(events[1], ==, SingleResourceLoadTest::SentRequest); - g_assert_cmpint(events[2], ==, SingleResourceLoadTest::Redirected); - g_assert_cmpint(events[3], ==, SingleResourceLoadTest::ReceivedResponse); - g_assert_cmpint(events[4], ==, SingleResourceLoadTest::ReceivedData); - g_assert_cmpint(events[5], ==, SingleResourceLoadTest::Finished); - events.clear(); - - test->loadURI(kServer->getURIForPath("/invalid-css.html").data()); - test->waitUntilResourceLoadFinished(); - g_assert(test->m_resource); - g_assert_cmpint(events.size(), ==, 4); - g_assert_cmpint(events[0], ==, SingleResourceLoadTest::Started); - g_assert_cmpint(events[1], ==, SingleResourceLoadTest::SentRequest); - g_assert_cmpint(events[2], ==, SingleResourceLoadTest::Failed); - g_assert_cmpint(events[3], ==, SingleResourceLoadTest::Finished); - events.clear(); -} - -static void testWebResourceResponse(SingleResourceLoadTest* test, gconstpointer) -{ - // No cached resource: First load. - test->loadURI(kServer->getURIForPath("/javascript.html").data()); - WebKitURIResponse* response = test->waitUntilResourceLoadFinishedAndReturnURIResponse(); - g_assert_cmpint(webkit_uri_response_get_status_code(response), ==, SOUP_STATUS_OK); - - // No cached resource: Second load. - test->loadURI(kServer->getURIForPath("/javascript.html").data()); - response = test->waitUntilResourceLoadFinishedAndReturnURIResponse(); - g_assert_cmpint(webkit_uri_response_get_status_code(response), ==, SOUP_STATUS_OK); - - // No cached resource: Reload. - webkit_web_view_reload(test->m_webView); - response = test->waitUntilResourceLoadFinishedAndReturnURIResponse(); - g_assert_cmpint(webkit_uri_response_get_status_code(response), ==, SOUP_STATUS_OK); - - // Cached resource: First load. - test->loadURI(kServer->getURIForPath("/image.html").data()); - response = test->waitUntilResourceLoadFinishedAndReturnURIResponse(); - g_assert_cmpint(webkit_uri_response_get_status_code(response), ==, SOUP_STATUS_OK); - - // Cached resource: Second load. - test->loadURI(kServer->getURIForPath("/image.html").data()); - response = test->waitUntilResourceLoadFinishedAndReturnURIResponse(); - g_assert_cmpint(webkit_uri_response_get_status_code(response), ==, SOUP_STATUS_OK); - - // Cached resource: Reload. - webkit_web_view_reload(test->m_webView); - response = test->waitUntilResourceLoadFinishedAndReturnURIResponse(); - g_assert_cmpint(webkit_uri_response_get_status_code(response), ==, SOUP_STATUS_NOT_MODIFIED); -} - -static void testWebResourceMimeType(SingleResourceLoadTest* test, gconstpointer) -{ - test->loadURI(kServer->getURIForPath("/javascript.html").data()); - WebKitURIResponse* response = test->waitUntilResourceLoadFinishedAndReturnURIResponse(); - g_assert_cmpstr(webkit_uri_response_get_mime_type(response), ==, "text/javascript"); - - test->loadURI(kServer->getURIForPath("/image.html").data()); - response = test->waitUntilResourceLoadFinishedAndReturnURIResponse(); - g_assert_cmpstr(webkit_uri_response_get_mime_type(response), ==, "image/vnd.microsoft.icon"); - - test->loadURI(kServer->getURIForPath("/redirected-css.html").data()); - response = test->waitUntilResourceLoadFinishedAndReturnURIResponse(); - g_assert_cmpstr(webkit_uri_response_get_mime_type(response), ==, "text/css"); -} - -static void testWebResourceSuggestedFilename(SingleResourceLoadTest* test, gconstpointer) -{ - test->loadURI(kServer->getURIForPath("/javascript.html").data()); - WebKitURIResponse* response = test->waitUntilResourceLoadFinishedAndReturnURIResponse(); - g_assert_cmpstr(webkit_uri_response_get_suggested_filename(response), ==, "JavaScript.js"); - - test->loadURI(kServer->getURIForPath("/image.html").data()); - response = test->waitUntilResourceLoadFinishedAndReturnURIResponse(); - g_assert(!webkit_uri_response_get_suggested_filename(response)); -} - -class ResourceURITrackingTest: public SingleResourceLoadTest { -public: - MAKE_GLIB_TEST_FIXTURE(ResourceURITrackingTest); - - ResourceURITrackingTest() - : SingleResourceLoadTest() - { - } - - static void uriChanged(WebKitWebResource* resource, GParamSpec*, ResourceURITrackingTest* test) - { - g_assert(resource == test->m_resource.get()); - g_assert_cmpstr(test->m_activeURI.data(), !=, webkit_web_resource_get_uri(test->m_resource.get())); - test->m_activeURI = webkit_web_resource_get_uri(test->m_resource.get()); - } - - void resourceLoadStarted(WebKitWebResource* resource, WebKitURIRequest* request) - { - if (resource == webkit_web_view_get_main_resource(m_webView)) - return; - - m_resource = resource; - m_activeURI = webkit_web_resource_get_uri(resource); - checkActiveURI("/redirected.css"); - g_assert_cmpstr(m_activeURI.data(), ==, webkit_uri_request_get_uri(request)); - g_signal_connect(resource, "notify::uri", G_CALLBACK(uriChanged), this); - } - - void resourceSentRequest(WebKitWebResource* resource, WebKitURIRequest* request, WebKitURIResponse* redirectResponse) - { - if (resource != m_resource) - return; - - if (redirectResponse) - checkActiveURI("/simple-style.css"); - else - checkActiveURI("/redirected.css"); - g_assert_cmpstr(m_activeURI.data(), ==, webkit_uri_request_get_uri(request)); - } - - void resourceReceivedResponse(WebKitWebResource* resource) - { - if (resource != m_resource) - return; - - checkActiveURI("/simple-style.css"); - } - - void resourceReceivedData(WebKitWebResource* resource, guint64 bytesReceived) - { - } - - void resourceFinished(WebKitWebResource* resource) - { - if (resource == m_resource) - checkActiveURI("/simple-style.css"); - ResourcesTest::resourceFinished(resource); - } - - void resourceFailed(WebKitWebResource*, GError*) - { - g_assert_not_reached(); - } - - CString m_activeURI; - -private: - void checkActiveURI(const char* uri) - { - ASSERT_CMP_CSTRING(m_activeURI, ==, kServer->getURIForPath(uri)); - } -}; - -static void testWebResourceActiveURI(ResourceURITrackingTest* test, gconstpointer) -{ - test->loadURI(kServer->getURIForPath("/redirected-css.html").data()); - test->waitUntilResourceLoadFinished(); -} - -static void testWebResourceGetData(ResourcesTest* test, gconstpointer) -{ - test->loadURI(kServer->getURIForPath("/").data()); - // FIXME: this should be 4 instead of 3, but we don't get the css image resource - // due to bug https://bugs.webkit.org/show_bug.cgi?id=78510. - test->waitUntilResourcesLoaded(3); - - WebKitWebResource* resource = webkit_web_view_get_main_resource(test->m_webView); - g_assert(resource); - test->checkResourceData(resource); - - GList* subresources = test->subresources(); - for (GList* item = subresources; item; item = g_list_next(item)) - test->checkResourceData(WEBKIT_WEB_RESOURCE(item->data)); -} - -static void testWebViewResourcesHistoryCache(SingleResourceLoadTest* test, gconstpointer) -{ - CString javascriptURI = kServer->getURIForPath("/javascript.html"); - test->loadURI(javascriptURI.data()); - test->waitUntilResourceLoadFinished(); - WebKitWebResource* resource = webkit_web_view_get_main_resource(test->m_webView); - g_assert(resource); - g_assert_cmpstr(webkit_web_resource_get_uri(resource), ==, javascriptURI.data()); - - CString simpleStyleCSSURI = kServer->getURIForPath("/simple-style-css.html"); - test->loadURI(simpleStyleCSSURI.data()); - test->waitUntilResourceLoadFinished(); - resource = webkit_web_view_get_main_resource(test->m_webView); - g_assert(resource); - g_assert_cmpstr(webkit_web_resource_get_uri(resource), ==, simpleStyleCSSURI.data()); - - test->goBack(); - test->waitUntilResourceLoadFinished(); - resource = webkit_web_view_get_main_resource(test->m_webView); - g_assert(resource); - g_assert_cmpstr(webkit_web_resource_get_uri(resource), ==, javascriptURI.data()); - - test->goForward(); - test->waitUntilResourceLoadFinished(); - resource = webkit_web_view_get_main_resource(test->m_webView); - g_assert(resource); - g_assert_cmpstr(webkit_web_resource_get_uri(resource), ==, simpleStyleCSSURI.data()); -} - -class SendRequestTest: public SingleResourceLoadTest { -public: - MAKE_GLIB_TEST_FIXTURE(SendRequestTest); - - void resourceSentRequest(WebKitWebResource* resource, WebKitURIRequest* request, WebKitURIResponse* redirectResponse) - { - if (resource != m_resource) - return; - - g_assert_cmpstr(webkit_uri_request_get_uri(request), ==, m_expectedNewResourceURI.data()); - g_assert_cmpstr(webkit_uri_request_get_uri(request), ==, webkit_web_resource_get_uri(resource)); - - SingleResourceLoadTest::resourceSentRequest(resource, request, redirectResponse); - } - - void resourceFailed(WebKitWebResource* resource, GError* error) - { - if (resource != m_resource) - return; - - g_assert_cmpstr(webkit_web_resource_get_uri(resource), ==, m_expectedCancelledResourceURI.data()); - g_assert_error(error, WEBKIT_NETWORK_ERROR, WEBKIT_NETWORK_ERROR_CANCELLED); - - SingleResourceLoadTest::resourceFailed(resource, error); - } - - void setExpectedNewResourceURI(const CString& uri) - { - m_expectedNewResourceURI = uri; - } - - void setExpectedCancelledResourceURI(const CString& uri) - { - m_expectedCancelledResourceURI = uri; - } - - CString m_expectedNewResourceURI; - CString m_expectedCancelledResourceURI; -}; - -static void testWebResourceSendRequest(SendRequestTest* test, gconstpointer) -{ - test->setExpectedNewResourceURI(kServer->getURIForPath("/javascript.js")); - test->loadURI(kServer->getURIForPath("relative-javascript.html").data()); - test->waitUntilResourceLoadFinished(); - g_assert(test->m_resource); - - Vector<SingleResourceLoadTest::LoadEvents>& events = test->m_loadEvents; - g_assert_cmpint(events.size(), ==, 5); - g_assert_cmpint(events[0], ==, SingleResourceLoadTest::Started); - g_assert_cmpint(events[1], ==, SingleResourceLoadTest::SentRequest); - g_assert_cmpint(events[2], ==, SingleResourceLoadTest::ReceivedResponse); - g_assert_cmpint(events[3], ==, SingleResourceLoadTest::ReceivedData); - g_assert_cmpint(events[4], ==, SingleResourceLoadTest::Finished); - events.clear(); - - // Cancel request. - test->setExpectedCancelledResourceURI(kServer->getURIForPath("/cancel-this.js")); - test->loadURI(kServer->getURIForPath("/resource-to-cancel.html").data()); - test->waitUntilResourceLoadFinished(); - g_assert(test->m_resource); - - g_assert_cmpint(events.size(), ==, 3); - g_assert_cmpint(events[0], ==, SingleResourceLoadTest::Started); - g_assert_cmpint(events[1], ==, SingleResourceLoadTest::Failed); - g_assert_cmpint(events[2], ==, SingleResourceLoadTest::Finished); - events.clear(); -} - -static void addCacheHTTPHeadersToResponse(SoupMessage* message) -{ - // The actual date doesn't really matter. - SoupDate* soupDate = soup_date_new_from_now(0); - GOwnPtr<char> date(soup_date_to_string(soupDate, SOUP_DATE_HTTP)); - soup_message_headers_append(message->response_headers, "Last-Modified", date.get()); - soup_date_free(soupDate); - soup_message_headers_append(message->response_headers, "Cache-control", "public, max-age=31536000"); - soupDate = soup_date_new_from_now(3600); - date.set(soup_date_to_string(soupDate, SOUP_DATE_HTTP)); - soup_message_headers_append(message->response_headers, "Expires", date.get()); - soup_date_free(soupDate); -} - -static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) -{ - if (message->method != SOUP_METHOD_GET) { - soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); - return; - } - - soup_message_set_status(message, SOUP_STATUS_OK); - - if (soup_message_headers_get_one(message->request_headers, "If-Modified-Since")) { - soup_message_set_status(message, SOUP_STATUS_NOT_MODIFIED); - soup_message_body_complete(message->response_body); - return; - } - - if (g_str_equal(path, "/")) { - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kIndexHtml, strlen(kIndexHtml)); - } else if (g_str_equal(path, "/javascript.html")) { - static const char* javascriptHtml = "<html><head><script language='javascript' src='/javascript.js'></script></head><body></body></html>"; - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, javascriptHtml, strlen(javascriptHtml)); - } else if (g_str_equal(path, "/image.html")) { - static const char* imageHTML = "<html><body><img src='/blank.ico'></img></body></html>"; - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, imageHTML, strlen(imageHTML)); - } else if (g_str_equal(path, "/redirected-css.html")) { - static const char* redirectedCSSHtml = "<html><head><link rel='stylesheet' href='/redirected.css' type='text/css'></head><body></html>"; - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, redirectedCSSHtml, strlen(redirectedCSSHtml)); - } else if (g_str_equal(path, "/invalid-css.html")) { - static const char* invalidCSSHtml = "<html><head><link rel='stylesheet' href='/invalid.css' type='text/css'></head><body></html>"; - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, invalidCSSHtml, strlen(invalidCSSHtml)); - } else if (g_str_equal(path, "/simple-style-css.html")) { - static const char* simpleStyleCSSHtml = "<html><head><link rel='stylesheet' href='/simple-style.css' type='text/css'></head><body></html>"; - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, simpleStyleCSSHtml, strlen(simpleStyleCSSHtml)); - } else if (g_str_equal(path, "/style.css")) { - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kStyleCSS, strlen(kStyleCSS)); - addCacheHTTPHeadersToResponse(message); - } else if (g_str_equal(path, "/javascript.js")) { - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kJavascript, strlen(kJavascript)); - soup_message_headers_append(message->response_headers, "Content-Type", "text/javascript"); - soup_message_headers_append(message->response_headers, "Content-Disposition", "filename=JavaScript.js"); - } else if (g_str_equal(path, "/relative-javascript.html")) { - static const char* javascriptRelativeHTML = "<html><head><script language='javascript' src='remove-this/javascript.js'></script></head><body></body></html>"; - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, javascriptRelativeHTML, strlen(javascriptRelativeHTML)); - } else if (g_str_equal(path, "/resource-to-cancel.html")) { - static const char* resourceToCancelHTML = "<html><head><script language='javascript' src='cancel-this.js'></script></head><body></body></html>"; - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, resourceToCancelHTML, strlen(resourceToCancelHTML)); - } else if (g_str_equal(path, "/blank.ico")) { - GOwnPtr<char> filePath(g_build_filename(Test::getWebKit1TestResoucesDir().data(), path, NULL)); - char* contents; - gsize contentsLength; - g_file_get_contents(filePath.get(), &contents, &contentsLength, 0); - soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, contentsLength); - addCacheHTTPHeadersToResponse(message); - } else if (g_str_equal(path, "/simple-style.css")) { - static const char* simpleCSS = - "body {" - " margin: 0px;" - " padding: 0px;" - "}"; - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, simpleCSS, strlen(simpleCSS)); - soup_message_headers_append(message->response_headers, "Content-Type", "text/css"); - } else if (g_str_equal(path, "/redirected.css")) { - soup_message_set_status(message, SOUP_STATUS_MOVED_PERMANENTLY); - soup_message_headers_append(message->response_headers, "Location", "/simple-style.css"); - } else if (g_str_equal(path, "/invalid.css")) - soup_message_set_status(message, SOUP_STATUS_CANT_CONNECT); - else - soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); - soup_message_body_complete(message->response_body); -} - -void beforeAll() -{ - kServer = new WebKitTestServer(); - kServer->run(serverCallback); - - webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), WEBKIT_TEST_WEB_EXTENSIONS_DIR); - - ResourcesTest::add("WebKitWebView", "resources", testWebViewResources); - SingleResourceLoadTest::add("WebKitWebResource", "loading", testWebResourceLoading); - SingleResourceLoadTest::add("WebKitWebResource", "response", testWebResourceResponse); - SingleResourceLoadTest::add("WebKitWebResource", "mime-type", testWebResourceMimeType); - SingleResourceLoadTest::add("WebKitWebResource", "suggested-filename", testWebResourceSuggestedFilename); - ResourceURITrackingTest::add("WebKitWebResource", "active-uri", testWebResourceActiveURI); - ResourcesTest::add("WebKitWebResource", "get-data", testWebResourceGetData); - SingleResourceLoadTest::add("WebKitWebView", "history-cache", testWebViewResourcesHistoryCache); - SendRequestTest::add("WebKitWebPage", "send-request", testWebResourceSendRequest); -} - -void afterAll() -{ - delete kServer; -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp deleted file mode 100644 index db6ccc852..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include "LoadTrackingTest.h" -#include "WebKitTestServer.h" -#include <gtk/gtk.h> - -static WebKitTestServer* kHttpsServer; -static WebKitTestServer* kHttpServer; - -static const char* indexHTML = "<html><body>Testing WebKit2GTK+ SSL</body></htmll>"; -static const char* insecureContentHTML = "<html><script src=\"%s\"></script><body><p>Text + image <img src=\"%s\" align=\"right\"/></p></body></html>"; - -class SSLTest: public LoadTrackingTest { -public: - MAKE_GLIB_TEST_FIXTURE(SSLTest); - - SSLTest() - : m_tlsErrors(static_cast<GTlsCertificateFlags>(0)) - { - } - - virtual void provisionalLoadFailed(const gchar* failingURI, GError* error) - { - g_assert_error(error, SOUP_HTTP_ERROR, SOUP_STATUS_SSL_FAILED); - LoadTrackingTest::provisionalLoadFailed(failingURI, error); - } - - virtual void loadCommitted() - { - GTlsCertificate* certificate = 0; - webkit_web_view_get_tls_info(m_webView, &certificate, &m_tlsErrors); - m_certificate = certificate; - LoadTrackingTest::loadCommitted(); - } - - void waitUntilLoadFinished() - { - m_certificate = 0; - m_tlsErrors = static_cast<GTlsCertificateFlags>(0); - LoadTrackingTest::waitUntilLoadFinished(); - } - - GRefPtr<GTlsCertificate> m_certificate; - GTlsCertificateFlags m_tlsErrors; -}; - -static void testSSL(SSLTest* test, gconstpointer) -{ - test->loadURI(kHttpsServer->getURIForPath("/").data()); - test->waitUntilLoadFinished(); - g_assert(test->m_certificate); - // We always expect errors because we are using a self-signed certificate, - // but only G_TLS_CERTIFICATE_UNKNOWN_CA flags should be present. - g_assert(test->m_tlsErrors); - g_assert_cmpuint(test->m_tlsErrors, ==, G_TLS_CERTIFICATE_UNKNOWN_CA); - - // Non HTTPS loads shouldn't have a certificate nor errors. - test->loadHtml(indexHTML, 0); - test->waitUntilLoadFinished(); - g_assert(!test->m_certificate); - g_assert(!test->m_tlsErrors); -} - -class InsecureContentTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(InsecureContentTest); - - InsecureContentTest() - : m_insecureContentRun(false) - , m_insecureContentDisplayed(false) - { - g_signal_connect(m_webView, "insecure-content-detected", G_CALLBACK(insecureContentDetectedCallback), this); - } - - static void insecureContentDetectedCallback(WebKitWebView* webView, WebKitInsecureContentEvent event, InsecureContentTest* test) - { - g_assert(webView == test->m_webView); - - if (event == WEBKIT_INSECURE_CONTENT_RUN) - test->m_insecureContentRun = true; - - if (event == WEBKIT_INSECURE_CONTENT_DISPLAYED) - test->m_insecureContentDisplayed = true; - } - - bool m_insecureContentRun; - bool m_insecureContentDisplayed; -}; - -static void testInsecureContent(InsecureContentTest* test, gconstpointer) -{ - test->loadURI(kHttpsServer->getURIForPath("/insecure-content/").data()); - test->waitUntilLoadFinished(); - - g_assert(test->m_insecureContentRun); - g_assert(test->m_insecureContentDisplayed); -} - -static void testTLSErrorsPolicy(SSLTest* test, gconstpointer) -{ - WebKitWebContext* context = webkit_web_view_get_context(test->m_webView); - // TLS errors are ignored by default. - g_assert(webkit_web_context_get_tls_errors_policy(context) == WEBKIT_TLS_ERRORS_POLICY_IGNORE); - test->loadURI(kHttpsServer->getURIForPath("/").data()); - test->waitUntilLoadFinished(); - g_assert(!test->m_loadFailed); - - webkit_web_context_set_tls_errors_policy(context, WEBKIT_TLS_ERRORS_POLICY_FAIL); - test->loadURI(kHttpsServer->getURIForPath("/").data()); - test->waitUntilLoadFinished(); - g_assert(test->m_loadFailed); - g_assert(test->m_loadEvents.contains(LoadTrackingTest::ProvisionalLoadFailed)); - g_assert(!test->m_loadEvents.contains(LoadTrackingTest::LoadCommitted)); -} - -static void httpsServerCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) -{ - if (message->method != SOUP_METHOD_GET) { - soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); - return; - } - - if (g_str_equal(path, "/")) { - soup_message_set_status(message, SOUP_STATUS_OK); - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, indexHTML, strlen(indexHTML)); - soup_message_body_complete(message->response_body); - } else if (g_str_equal(path, "/insecure-content/")) { - GOwnPtr<char> responseHTML(g_strdup_printf(insecureContentHTML, kHttpServer->getURIForPath("/test-script").data(), kHttpServer->getURIForPath("/test-image").data())); - soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, responseHTML.get(), strlen(responseHTML.get())); - soup_message_set_status(message, SOUP_STATUS_OK); - soup_message_body_complete(message->response_body); - } else - soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); -} - -static void httpServerCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) -{ - if (message->method != SOUP_METHOD_GET) { - soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); - return; - } - - if (g_str_equal(path, "/test-script")) { - GOwnPtr<char> pathToFile(g_build_filename(Test::getResourcesDir().data(), "link-title.js", NULL)); - char* contents; - gsize length; - g_file_get_contents(pathToFile.get(), &contents, &length, 0); - - soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length); - soup_message_set_status(message, SOUP_STATUS_OK); - soup_message_body_complete(message->response_body); - } else if (g_str_equal(path, "/test-image")) { - GOwnPtr<char> pathToFile(g_build_filename(Test::getWebKit1TestResoucesDir().data(), "blank.ico", NULL)); - char* contents; - gsize length; - g_file_get_contents(pathToFile.get(), &contents, &length, 0); - - soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length); - soup_message_set_status(message, SOUP_STATUS_OK); - soup_message_body_complete(message->response_body); - } else - soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); -} - -void beforeAll() -{ - kHttpsServer = new WebKitTestServer(WebKitTestServer::ServerHTTPS); - kHttpsServer->run(httpsServerCallback); - - kHttpServer = new WebKitTestServer(WebKitTestServer::ServerHTTP); - kHttpServer->run(httpServerCallback); - - SSLTest::add("WebKitWebView", "ssl", testSSL); - InsecureContentTest::add("WebKitWebView", "insecure-content", testInsecureContent); - SSLTest::add("WebKitWebContext", "tls-errors-policy", testTLSErrorsPolicy); -} - -void afterAll() -{ - delete kHttpsServer; - delete kHttpServer; -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebExtensions.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebExtensions.cpp deleted file mode 100644 index 527cc936c..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebExtensions.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2,1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include "WebKitTestBus.h" -#include "WebViewTest.h" -#include <wtf/gobject/GRefPtr.h> - -static WebKitTestBus* bus; - -static void testWebExtensionGetTitle(WebViewTest* test, gconstpointer) -{ - test->loadHtml("<html><head><title>WebKitGTK+ Web Extensions Test</title></head><body></body></html>", 0); - test->waitUntilLoadFinished(); - - GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy("org.webkit.gtk.WebExtensionTest", - "/org/webkit/gtk/WebExtensionTest" , "org.webkit.gtk.WebExtensionTest", test->m_mainLoop)); - GRefPtr<GVariant> result = adoptGRef(g_dbus_proxy_call_sync( - proxy.get(), - "GetTitle", - g_variant_new("(t)", webkit_web_view_get_page_id(test->m_webView)), - G_DBUS_CALL_FLAGS_NONE, - -1, 0, 0)); - g_assert(result); - - const char* title; - g_variant_get(result.get(), "(&s)", &title); - g_assert_cmpstr(title, ==, "WebKitGTK+ Web Extensions Test"); -} - -static void documentLoadedCallback(GDBusConnection*, const char*, const char*, const char*, const char*, GVariant*, WebViewTest* test) -{ - g_main_loop_quit(test->m_mainLoop); -} - -static void testDocumentLoadedSignal(WebViewTest* test, gconstpointer) -{ - GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy("org.webkit.gtk.WebExtensionTest", - "/org/webkit/gtk/WebExtensionTest", "org.webkit.gtk.WebExtensionTest", test->m_mainLoop)); - GDBusConnection* connection = g_dbus_proxy_get_connection(proxy.get()); - guint id = g_dbus_connection_signal_subscribe(connection, - 0, - "org.webkit.gtk.WebExtensionTest", - "DocumentLoaded", - "/org/webkit/gtk/WebExtensionTest", - 0, - G_DBUS_SIGNAL_FLAGS_NONE, - reinterpret_cast<GDBusSignalCallback>(documentLoadedCallback), - test, - 0); - g_assert(id); - - test->loadHtml("<html><head><title>WebKitGTK+ Web Extensions Test</title></head><body></body></html>", 0); - g_main_loop_run(test->m_mainLoop); - g_dbus_connection_signal_unsubscribe(connection, id); -} - -static gboolean webProcessCrashedCallback(WebKitWebView*, WebViewTest* test) -{ - test->quitMainLoop(); - - return FALSE; -} - -static void testWebKitWebViewProcessCrashed(WebViewTest* test, gconstpointer) -{ - test->loadHtml("<html></html>", 0); - test->waitUntilLoadFinished(); - - g_signal_connect(test->m_webView, "web-process-crashed", - G_CALLBACK(webProcessCrashedCallback), test); - - GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy("org.webkit.gtk.WebExtensionTest", - "/org/webkit/gtk/WebExtensionTest", "org.webkit.gtk.WebExtensionTest", test->m_mainLoop)); - - GRefPtr<GVariant> result = adoptGRef(g_dbus_proxy_call_sync( - proxy.get(), - "AbortProcess", - 0, - G_DBUS_CALL_FLAGS_NONE, - -1, 0, 0)); - g_assert(!result); - g_main_loop_run(test->m_mainLoop); -} - -void beforeAll() -{ - webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), WEBKIT_TEST_WEB_EXTENSIONS_DIR); - bus = new WebKitTestBus(); - if (!bus->run()) - return; - - WebViewTest::add("WebKitWebExtension", "dom-document-title", testWebExtensionGetTitle); - WebViewTest::add("WebKitWebExtension", "document-loaded-signal", testDocumentLoadedSignal); - WebViewTest::add("WebKitWebView", "web-process-crashed", testWebKitWebViewProcessCrashed); -} - -void afterAll() -{ - delete bus; -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitAccessibility.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitAccessibility.cpp deleted file mode 100644 index d3750c005..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitAccessibility.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2,1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include "TestMain.h" -#include "WebViewTest.h" - -// The libatspi headers don't use G_BEGIN_DECLS -extern "C" { -#include <atspi/atspi.h> -} - -#include <errno.h> -#include <fcntl.h> -#include <glib.h> -#include <signal.h> -#include <unistd.h> -#include <wtf/PassRefPtr.h> -#include <wtf/gobject/GOwnPtr.h> -#include <wtf/gobject/GRefPtr.h> - -// Name of the test server application creating the webView object. -static const char* kTestServerAppName = "AccessibilityTestServer"; - -// Max seconds to wait for the test server before inspecting it. -static const int kMaxWaitForChild = 5; - -// The PID for the test server running, so we can kill it if needed. -static GPid kChildProcessPid = 0; - -// Whether the child has replied and it's ready. -static bool kChildIsReady = false; - -static void stopTestServer() -{ - // Do nothing if there's no server running. - if (!kChildProcessPid) - return; - - g_spawn_close_pid(kChildProcessPid); - kill(kChildProcessPid, SIGTERM); - kChildProcessPid = 0; -} - -static void sigAbortHandler(int sigNum) -{ - // Just stop the test server if SIGABRT was received. - stopTestServer(); -} - -static gpointer testServerMonitorThreadFunc(gpointer) -{ - // Wait for the specified timeout to happen. - g_usleep(kMaxWaitForChild * G_USEC_PER_SEC); - - // Kill the child process if not ready yet. - if (!kChildIsReady) - stopTestServer(); - - g_thread_exit(0); - return 0; -} - -static void startTestServerMonitor() -{ - kChildIsReady = false; - g_thread_new("TestServerMonitor", testServerMonitorThreadFunc, 0); -} - -static void startTestServer() -{ - // Prepare argv[] for spawning the server process. - GOwnPtr<char> testServerPath(g_build_filename(WEBKIT_EXEC_PATH, "WebKit2APITests", kTestServerAppName, NULL)); - - char* testServerArgv[2]; - testServerArgv[0] = testServerPath.get(); - testServerArgv[1] = 0; - - // Spawn the server, getting its stdout file descriptor to set a - // communication channel, so we know when it's ready. - int childStdout = 0; - if (!g_spawn_async_with_pipes(0, testServerArgv, 0, static_cast<GSpawnFlags>(0), 0, 0, - &kChildProcessPid, 0, &childStdout, 0, 0)) { - close(childStdout); - return; - } - - // Start monitoring the test server (in a separate thread) to - // ensure we don't block on the child process more than a timeout. - startTestServerMonitor(); - - char msg[2]; - GIOChannel* ioChannel = g_io_channel_unix_new(childStdout); - if (g_io_channel_read_chars(ioChannel, msg, 2, 0, 0) == G_IO_STATUS_NORMAL) { - // Check whether the server sent a message saying it's ready - // and store the result globally, so the monitor can see it. - kChildIsReady = msg[0] == 'O' && msg[1] == 'K'; - } - g_io_channel_unref(ioChannel); - close(childStdout); - - // The timeout was reached and the server is not ready yet, so - // stop it inmediately, and let the unit tests fail. - if (!kChildIsReady) - stopTestServer(); -} - -static void checkAtspiAccessible(AtspiAccessible* accessible, const char* targetName, AtspiRole targetRole) -{ - g_assert(ATSPI_IS_ACCESSIBLE(accessible)); - - GOwnPtr<char> name(atspi_accessible_get_name(accessible, 0)); - g_assert_cmpstr(targetName, ==, name.get()); - g_assert_cmpint(targetRole, ==, atspi_accessible_get_role(accessible, 0)); -} - -static GRefPtr<AtspiAccessible> findTestServerApplication() -{ - // Only one desktop is supported by ATSPI at the moment. - GRefPtr<AtspiAccessible> desktop = adoptGRef(atspi_get_desktop(0)); - - // Look for the server application in the list of apps. - GRefPtr<AtspiAccessible> current; - int childCount = atspi_accessible_get_child_count(desktop.get(), 0); - for (int i = 0; i < childCount; i++) { - current = adoptGRef(atspi_accessible_get_child_at_index(desktop.get(), i, 0)); - if (!g_strcmp0(atspi_accessible_get_name(current.get(), 0), kTestServerAppName)) - return current; - } - - return 0; -} - -static void testAtspiBasicHierarchy(WebViewTest* test, gconstpointer) -{ - // The test server's accessibility object (UI Process). - GRefPtr<AtspiAccessible> testServerApp = findTestServerApplication(); - g_assert(ATSPI_IS_ACCESSIBLE(testServerApp.get())); - checkAtspiAccessible(testServerApp.get(), "AccessibilityTestServer", ATSPI_ROLE_APPLICATION); - - // The main window's accessibility object (UI Process). - GRefPtr<AtspiAccessible> currentParent = testServerApp; - GRefPtr<AtspiAccessible> currentChild = adoptGRef(atspi_accessible_get_child_at_index(currentParent.get(), 0, 0)); - g_assert(ATSPI_IS_ACCESSIBLE(currentChild.get())); - checkAtspiAccessible(currentChild.get(), "", ATSPI_ROLE_FRAME); - - // The WebView's accessibility object (UI Process). - currentParent = currentChild; - currentChild = atspi_accessible_get_child_at_index(currentParent.get(), 0, 0); - g_assert(ATSPI_IS_ACCESSIBLE(currentChild.get())); - checkAtspiAccessible(currentChild.get(), "", ATSPI_ROLE_FILLER); - - // The WebPage's accessibility object (Web Process). - currentParent = currentChild; - currentChild = atspi_accessible_get_child_at_index(currentParent.get(), 0, 0); - g_assert(ATSPI_IS_ACCESSIBLE(currentChild.get())); - checkAtspiAccessible(currentChild.get(), "", ATSPI_ROLE_FILLER); - - // HTML root element's accessible element (Web Process). - currentParent = currentChild; - currentChild = atspi_accessible_get_child_at_index(currentParent.get(), 0, 0); - g_assert(ATSPI_IS_ACCESSIBLE(currentChild.get())); - - // HTML body's accessible element (Web Process). - currentParent = currentChild; - currentChild = atspi_accessible_get_child_at_index(currentParent.get(), 0, 0); - g_assert(ATSPI_IS_ACCESSIBLE(currentChild.get())); - checkAtspiAccessible(currentChild.get(), "", ATSPI_ROLE_DOCUMENT_FRAME); - - // HTML H1's accessible element (Web Process). - currentParent = currentChild; - currentChild = atspi_accessible_get_child_at_index(currentParent.get(), 0, 0); - g_assert(ATSPI_IS_ACCESSIBLE(currentChild.get())); - checkAtspiAccessible(currentChild.get(), "This is a test", ATSPI_ROLE_HEADING); - - // HTML first paragraph's accessible element (Web Process). - currentChild = atspi_accessible_get_child_at_index(currentParent.get(), 1, 0); - g_assert(ATSPI_IS_ACCESSIBLE(currentChild.get())); - checkAtspiAccessible(currentChild.get(), "", ATSPI_ROLE_PARAGRAPH); - - // HTML second paragraph's accessible element (Web Process). - currentChild = atspi_accessible_get_child_at_index(currentParent.get(), 2, 0); - g_assert(ATSPI_IS_ACCESSIBLE(currentChild.get())); - checkAtspiAccessible(currentChild.get(), "", ATSPI_ROLE_PARAGRAPH); - - // HTML link's accessible element (Web Process). - currentParent = currentChild; - currentChild = atspi_accessible_get_child_at_index(currentParent.get(), 0, 0); - g_assert(ATSPI_IS_ACCESSIBLE(currentChild.get())); - checkAtspiAccessible(currentChild.get(), "a link", ATSPI_ROLE_LINK); -} - -void beforeAll() -{ - // We install a handler to ensure that we kill the child process - // if the parent dies because of whatever the reason is. - signal(SIGABRT, sigAbortHandler); - - // Start the accessibility test server and load the tests. - startTestServer(); - WebViewTest::add("WebKitAccessibility", "atspi-basic-hierarchy", testAtspiBasicHierarchy); -} - -void afterAll() -{ - // Ensure we stop the server. - stopTestServer(); -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp deleted file mode 100644 index 1a06f7496..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2,1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include "WebKitTestServer.h" -#include "WebViewTest.h" -#include <glib/gstdio.h> -#include <libsoup/soup.h> -#include <wtf/gobject/GOwnPtr.h> - -static WebKitTestServer* kServer; -static char* kTempDirectory; - -class FaviconDatabaseTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(FaviconDatabaseTest); - - FaviconDatabaseTest() - : m_webContext(webkit_web_context_get_default()) - , m_favicon(0) - , m_error(0) - , m_faviconNotificationReceived(false) - { - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext); - g_signal_connect(database, "favicon-changed", G_CALLBACK(faviconChangedCallback), this); - } - - ~FaviconDatabaseTest() - { - if (m_favicon) - cairo_surface_destroy(m_favicon); - - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext); - g_signal_handlers_disconnect_matched(database, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); - } - - static void faviconChangedCallback(WebKitFaviconDatabase* database, const char* pageURI, const char* faviconURI, FaviconDatabaseTest* test) - { - if (!g_strcmp0(webkit_web_view_get_uri(test->m_webView), pageURI)) - test->m_faviconURI = faviconURI; - } - - static void viewFaviconChangedCallback(WebKitWebView* webView, GParamSpec* pspec, gpointer data) - { - FaviconDatabaseTest* test = static_cast<FaviconDatabaseTest*>(data); - g_assert(test->m_webView == webView); - test->m_faviconNotificationReceived = true; - test->quitMainLoop(); - } - - static void getFaviconCallback(GObject* sourceObject, GAsyncResult* result, void* data) - { - FaviconDatabaseTest* test = static_cast<FaviconDatabaseTest*>(data); - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext); - test->m_favicon = webkit_favicon_database_get_favicon_finish(database, result, &test->m_error.outPtr()); - test->quitMainLoop(); - } - - void waitUntilFaviconChanged() - { - m_faviconNotificationReceived = false; - unsigned long handlerID = g_signal_connect(m_webView, "notify::favicon", G_CALLBACK(viewFaviconChangedCallback), this); - g_main_loop_run(m_mainLoop); - g_signal_handler_disconnect(m_webView, handlerID); - } - - void getFaviconForPageURIAndWaitUntilReady(const char* pageURI) - { - m_error.clear(); - if (m_favicon) { - cairo_surface_destroy(m_favicon); - m_favicon = 0; - } - - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext); - webkit_favicon_database_get_favicon(database, pageURI, 0, getFaviconCallback, this); - g_main_loop_run(m_mainLoop); - } - - WebKitWebContext* m_webContext; - cairo_surface_t* m_favicon; - CString m_faviconURI; - GOwnPtr<GError> m_error; - bool m_faviconNotificationReceived; -}; - -static void -serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable* query, SoupClientContext* context, void* data) -{ - if (message->method != SOUP_METHOD_GET) { - soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); - return; - } - - if (g_str_equal(path, "/favicon.ico")) { - soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); - soup_message_body_complete(message->response_body); - return; - } - - char* contents; - gsize length; - if (g_str_equal(path, "/icon/favicon.ico")) { - GOwnPtr<char> pathToFavicon(g_build_filename(Test::getWebKit1TestResoucesDir().data(), "blank.ico", NULL)); - g_file_get_contents(pathToFavicon.get(), &contents, &length, 0); - soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length); - } else if (g_str_equal(path, "/nofavicon")) { - static const char* noFaviconHTML = "<html><head><body>test</body></html>"; - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, noFaviconHTML, strlen(noFaviconHTML)); - } else { - static const char* contentsHTML = "<html><head><link rel='icon' href='/icon/favicon.ico' type='image/x-ico; charset=binary'></head><body>test</body></html>"; - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, contentsHTML, strlen(contentsHTML)); - } - - soup_message_set_status(message, SOUP_STATUS_OK); - soup_message_body_complete(message->response_body); -} - -static void testNotInitialized(FaviconDatabaseTest* test) -{ - // Try to retrieve a valid favicon from a not initialized database. - test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/foo").data()); - g_assert(!test->m_favicon); - g_assert(test->m_error); - g_assert_cmpint(test->m_error->code, ==, WEBKIT_FAVICON_DATABASE_ERROR_NOT_INITIALIZED); -} - -static void testSetDirectory(FaviconDatabaseTest* test) -{ - webkit_web_context_set_favicon_database_directory(test->m_webContext, kTempDirectory); - g_assert_cmpstr(kTempDirectory, ==, webkit_web_context_get_favicon_database_directory(test->m_webContext)); -} - -static void testClearDatabase(FaviconDatabaseTest* test) -{ - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext); - webkit_favicon_database_clear(database); - - GOwnPtr<char> iconURI(webkit_favicon_database_get_favicon_uri(database, kServer->getURIForPath("/foo").data())); - g_assert(!iconURI); -} - -static void testGetFavicon(FaviconDatabaseTest* test) -{ - // We need to load the page first to ensure the icon data will be - // in the database in case there's an associated favicon. - test->loadURI(kServer->getURIForPath("/foo").data()); - test->waitUntilFaviconChanged(); - CString faviconURI = kServer->getURIForPath("/icon/favicon.ico"); - - // Check the API retrieving a valid favicon. - test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/foo").data()); - g_assert(test->m_favicon); - g_assert_cmpstr(test->m_faviconURI.data(), ==, faviconURI.data()); - g_assert(!test->m_error); - - // Check that width and height match those from blank.ico (16x16 favicon). - g_assert_cmpint(cairo_image_surface_get_width(test->m_favicon), ==, 16); - g_assert_cmpint(cairo_image_surface_get_height(test->m_favicon), ==, 16); - - // Check that another page with the same favicon return the same icon. - cairo_surface_t* favicon = cairo_surface_reference(test->m_favicon); - test->loadURI(kServer->getURIForPath("/bar").data()); - // It's a new page in the database, so favicon will change twice, first to reset it - // and then when the icon is loaded. - test->waitUntilFaviconChanged(); - test->waitUntilFaviconChanged(); - test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/bar").data()); - g_assert(test->m_favicon); - g_assert_cmpstr(test->m_faviconURI.data(), ==, faviconURI.data()); - g_assert(test->m_favicon == favicon); - g_assert(!test->m_error); - cairo_surface_destroy(favicon); - - // Check the API retrieving an invalid favicon. - test->loadURI(kServer->getURIForPath("/nofavicon").data()); - test->waitUntilFaviconChanged(); - - test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/nofavicon").data()); - g_assert(!test->m_favicon); - g_assert(test->m_error); -} - -static void testGetFaviconURI(FaviconDatabaseTest* test) -{ - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext); - - CString baseURI = kServer->getURIForPath("/foo"); - GOwnPtr<char> iconURI(webkit_favicon_database_get_favicon_uri(database, baseURI.data())); - ASSERT_CMP_CSTRING(iconURI.get(), ==, kServer->getURIForPath("/icon/favicon.ico")); -} - -static void testWebViewFavicon(FaviconDatabaseTest* test) -{ - test->m_faviconURI = CString(); - - cairo_surface_t* iconFromWebView = webkit_web_view_get_favicon(test->m_webView); - g_assert(!iconFromWebView); - - test->loadURI(kServer->getURIForPath("/foo").data()); - test->waitUntilFaviconChanged(); - g_assert(test->m_faviconNotificationReceived); - // The icon is known and hasn't changed in the database, so notify::favicon is emitted - // but WebKitFaviconDatabase::icon-changed isn't. - g_assert(test->m_faviconURI.isNull()); - - iconFromWebView = webkit_web_view_get_favicon(test->m_webView); - g_assert(iconFromWebView); - g_assert_cmpuint(cairo_image_surface_get_width(iconFromWebView), ==, 16); - g_assert_cmpuint(cairo_image_surface_get_height(iconFromWebView), ==, 16); -} - -static void testFaviconDatabase(FaviconDatabaseTest* test, gconstpointer) -{ - // These tests depend on this order to run properly so we declare them in a single one. - // See https://bugs.webkit.org/show_bug.cgi?id=111434. - testNotInitialized(test); - testSetDirectory(test); - testGetFavicon(test); - testGetFaviconURI(test); - testWebViewFavicon(test); - testClearDatabase(test); -} - -void beforeAll() -{ - // Start a soup server for testing. - kServer = new WebKitTestServer(); - kServer->run(serverCallback); - - kTempDirectory = g_dir_make_tmp("WebKit2Tests-XXXXXX", 0); - g_assert(kTempDirectory); - - // Add tests to the suite. - FaviconDatabaseTest::add("WebKitFaviconDatabase", "favicon-database-test", testFaviconDatabase); -} - -static void webkitFaviconDatabaseFinalizedCallback(gpointer, GObject*) -{ - if (!g_file_test(kTempDirectory, G_FILE_TEST_IS_DIR)) - return; - - GOwnPtr<char> filename(g_build_filename(kTempDirectory, "WebpageIcons.db", NULL)); - g_unlink(filename.get()); - - g_rmdir(kTempDirectory); -} - -void afterAll() -{ - delete kServer; - - // Delete the temporary files after the IconDatabase has been - // closed, that is, once WebKitFaviconDatabase is being destroyed. - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(webkit_web_context_get_default()); - g_object_weak_ref(G_OBJECT(database), webkitFaviconDatabaseFinalizedCallback, 0); -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp deleted file mode 100644 index d2eef4ca4..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2,1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include "LoadTrackingTest.h" -#include <gtk/gtk.h> -#include <webkit2/webkit2.h> -#include <wtf/gobject/GRefPtr.h> - -static const char* testString = "<html><body>first testing second testing secondHalf</body></html>"; - -class FindControllerTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(FindControllerTest); - - FindControllerTest() - : m_findController(webkit_web_view_get_find_controller(m_webView)) - , m_runFindUntilCompletion(false) - { - assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_findController.get())); - } - - ~FindControllerTest() - { - if (m_findController) - g_signal_handlers_disconnect_matched(m_findController.get(), G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); - } - - void find(const char* searchText, guint32 findOptions, guint maxMatchCount) - { - g_signal_connect(m_findController.get(), "found-text", G_CALLBACK(foundTextCallback), this); - g_signal_connect(m_findController.get(), "failed-to-find-text", G_CALLBACK(failedToFindTextCallback), this); - webkit_find_controller_search(m_findController.get(), searchText, findOptions, maxMatchCount); - } - - void count(const char* searchText, guint32 findOptions, guint maxMatchCount) - { - g_signal_connect(m_findController.get(), "counted-matches", G_CALLBACK(countedMatchesCallback), this); - webkit_find_controller_count_matches(m_findController.get(), searchText, findOptions, maxMatchCount); - } - - void waitUntilFindFinished() - { - m_runFindUntilCompletion = true; - g_main_loop_run(m_mainLoop); - } - - GRefPtr<WebKitFindController> m_findController; - bool m_textFound; - unsigned m_matchCount; - -private: - bool m_runFindUntilCompletion; - - static void foundTextCallback(WebKitFindController*, guint matchCount, FindControllerTest* test) - { - test->m_textFound = true; - test->m_matchCount = matchCount; - if (test->m_runFindUntilCompletion) - g_main_loop_quit(test->m_mainLoop); - } - - static void failedToFindTextCallback(WebKitFindController*, FindControllerTest* test) - { - test->m_textFound = false; - if (test->m_runFindUntilCompletion) - g_main_loop_quit(test->m_mainLoop); - } - - static void countedMatchesCallback(WebKitFindController*, guint matchCount, FindControllerTest* test) - { - test->m_matchCount = matchCount; - if (test->m_runFindUntilCompletion) - g_main_loop_quit(test->m_mainLoop); - } -}; - -static void testFindControllerTextFound(FindControllerTest* test, gconstpointer) -{ - test->loadHtml(testString, 0); - test->waitUntilLoadFinished(); - - test->find("testing", WEBKIT_FIND_OPTIONS_NONE, 1); - test->waitUntilFindFinished(); - - g_assert(test->m_textFound); -} - -static void testFindControllerTextNotFound(FindControllerTest* test, gconstpointer) -{ - test->loadHtml(testString, 0); - test->waitUntilLoadFinished(); - - test->find("notFound", WEBKIT_FIND_OPTIONS_NONE, 1); - test->waitUntilFindFinished(); - - g_assert(!test->m_textFound); -} - -static void testFindControllerMatchCount(FindControllerTest* test, gconstpointer) -{ - test->loadHtml(testString, 0); - test->waitUntilLoadFinished(); - - test->find("testing", WEBKIT_FIND_OPTIONS_NONE, 2); - test->waitUntilFindFinished(); - - g_assert(test->m_matchCount == 2); - g_assert(test->m_textFound); -} - -static void testFindControllerMaxMatchCount(FindControllerTest* test, gconstpointer) -{ - test->loadHtml(testString, 0); - test->waitUntilLoadFinished(); - - test->find("testing", WEBKIT_FIND_OPTIONS_NONE, 1); - test->waitUntilFindFinished(); - - g_assert(test->m_matchCount == G_MAXUINT); - g_assert(test->m_textFound); -} - -static void testFindControllerNext(FindControllerTest* test, gconstpointer) -{ - test->loadHtml(testString, 0); - test->waitUntilLoadFinished(); - - test->find("testing", WEBKIT_FIND_OPTIONS_NONE, 2); - test->waitUntilFindFinished(); - - g_assert(test->m_textFound); - g_assert(test->m_matchCount == 2); - - webkit_find_controller_search_next(test->m_findController.get()); - test->waitUntilFindFinished(); - - g_assert(test->m_textFound); - g_assert(test->m_matchCount == 1); - g_assert(!(webkit_find_controller_get_options(test->m_findController.get()) & WEBKIT_FIND_OPTIONS_BACKWARDS)); - - webkit_find_controller_search_next(test->m_findController.get()); - test->waitUntilFindFinished(); - - g_assert(!test->m_textFound); - g_assert(test->m_matchCount == 1); - g_assert(!(webkit_find_controller_get_options(test->m_findController.get()) & WEBKIT_FIND_OPTIONS_BACKWARDS)); -} - -static void testFindControllerPrevious(FindControllerTest* test, gconstpointer) -{ - test->loadHtml(testString, 0); - test->waitUntilLoadFinished(); - - test->find("testing", WEBKIT_FIND_OPTIONS_NONE, 2); - test->waitUntilFindFinished(); - - g_assert(test->m_matchCount == 2); - g_assert(test->m_textFound); - - webkit_find_controller_search_next(test->m_findController.get()); - test->waitUntilFindFinished(); - - g_assert(test->m_textFound); - g_assert(test->m_matchCount == 1); - g_assert(!(webkit_find_controller_get_options(test->m_findController.get()) & WEBKIT_FIND_OPTIONS_BACKWARDS)); - - webkit_find_controller_search_previous(test->m_findController.get()); - test->waitUntilFindFinished(); - - g_assert(test->m_textFound); - g_assert(test->m_matchCount == 1); - g_assert(webkit_find_controller_get_options(test->m_findController.get()) & WEBKIT_FIND_OPTIONS_BACKWARDS); -} - -static void testFindControllerCountedMatches(FindControllerTest* test, gconstpointer) -{ - test->loadHtml(testString, 0); - test->waitUntilLoadFinished(); - - test->count("testing", WEBKIT_FIND_OPTIONS_NONE, 2); - test->waitUntilFindFinished(); - - g_assert(test->m_matchCount == 2); - - test->count("first", WEBKIT_FIND_OPTIONS_NONE, 2); - test->waitUntilFindFinished(); - - g_assert(test->m_matchCount == 1); - - test->count("notFound", WEBKIT_FIND_OPTIONS_NONE, 2); - test->waitUntilFindFinished(); - - g_assert(!test->m_matchCount); -} - -static void testFindControllerOptions(FindControllerTest* test, gconstpointer) -{ - test->loadHtml(testString, 0); - test->waitUntilLoadFinished(); - - test->find("Testing", WEBKIT_FIND_OPTIONS_NONE, 2); - test->waitUntilFindFinished(); - - g_assert(!test->m_textFound); - - test->find("Testing", WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE, 2); - test->waitUntilFindFinished(); - - g_assert(test->m_textFound); - - test->find("esting", WEBKIT_FIND_OPTIONS_NONE, 2); - test->waitUntilFindFinished(); - - g_assert(test->m_textFound); - - test->find("esting", WEBKIT_FIND_OPTIONS_AT_WORD_STARTS, 2); - test->waitUntilFindFinished(); - - g_assert(!test->m_textFound); - - test->find("Half", WEBKIT_FIND_OPTIONS_AT_WORD_STARTS, 2); - test->waitUntilFindFinished(); - - g_assert(!test->m_textFound); - - test->find("Half", WEBKIT_FIND_OPTIONS_AT_WORD_STARTS | WEBKIT_FIND_OPTIONS_TREAT_MEDIAL_CAPITAL_AS_WORD_START, 2); - test->waitUntilFindFinished(); - - g_assert(test->m_textFound); - - test->find("testing", WEBKIT_FIND_OPTIONS_WRAP_AROUND, 3); - test->waitUntilFindFinished(); - g_assert(test->m_textFound); - - webkit_find_controller_search_next(test->m_findController.get()); - test->waitUntilFindFinished(); - g_assert(test->m_textFound); - - webkit_find_controller_search_next(test->m_findController.get()); - test->waitUntilFindFinished(); - g_assert(test->m_textFound); -} - -static void testFindControllerHide(FindControllerTest* test, gconstpointer) -{ - test->loadHtml(testString, 0); - test->waitUntilLoadFinished(); - - test->showInWindowAndWaitUntilMapped(); - - cairo_surface_t* originalSurface = cairo_surface_reference( - test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE)); - g_assert(originalSurface); - - test->find("testing", WEBKIT_FIND_OPTIONS_NONE, 1); - test->waitUntilFindFinished(); - g_assert(test->m_textFound); - - cairo_surface_t* highlightSurface = cairo_surface_reference( - test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE)); - g_assert(highlightSurface); - g_assert(!Test::cairoSurfacesEqual(originalSurface, highlightSurface)); - - WebKitFindController* findController = webkit_web_view_get_find_controller(test->m_webView); - webkit_find_controller_search_finish(findController); - webkit_web_view_execute_editing_command(test->m_webView, "Unselect"); - - cairo_surface_t* unhighlightSurface = cairo_surface_reference( - test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE)); - g_assert(unhighlightSurface); - g_assert(Test::cairoSurfacesEqual(originalSurface, unhighlightSurface)); - - cairo_surface_destroy(originalSurface); - cairo_surface_destroy(highlightSurface); - cairo_surface_destroy(unhighlightSurface); -} - -static void testFindControllerInstance(FindControllerTest* test, gconstpointer) -{ - WebKitFindController* findController1 = webkit_web_view_get_find_controller(test->m_webView); - WebKitFindController* findController2 = webkit_web_view_get_find_controller(test->m_webView); - - g_assert(findController1 == findController2); -} - -static void testFindControllerGetters(FindControllerTest* test, gconstpointer) -{ - const char* searchText = "testing"; - guint maxMatchCount = 1; - guint32 findOptions = WEBKIT_FIND_OPTIONS_WRAP_AROUND | WEBKIT_FIND_OPTIONS_AT_WORD_STARTS; - WebKitFindController* findController = webkit_web_view_get_find_controller(test->m_webView); - - webkit_find_controller_search(findController, searchText, findOptions, maxMatchCount); - g_assert(webkit_find_controller_get_web_view(findController) == test->m_webView); - g_assert(!g_strcmp0(webkit_find_controller_get_search_text(findController), searchText)); - g_assert(webkit_find_controller_get_max_match_count(findController) == maxMatchCount); - g_assert(webkit_find_controller_get_options(findController) == findOptions); -} - -void beforeAll() -{ - FindControllerTest::add("WebKitFindController", "getters", testFindControllerGetters); - FindControllerTest::add("WebKitFindController", "instance", testFindControllerInstance); - FindControllerTest::add("WebKitFindController", "text-found", testFindControllerTextFound); - FindControllerTest::add("WebKitFindController", "text-not-found", testFindControllerTextNotFound); - FindControllerTest::add("WebKitFindController", "match-count", testFindControllerMatchCount); - FindControllerTest::add("WebKitFindController", "max-match-count", testFindControllerMaxMatchCount); - FindControllerTest::add("WebKitFindController", "next", testFindControllerNext); - FindControllerTest::add("WebKitFindController", "previous", testFindControllerPrevious); - FindControllerTest::add("WebKitFindController", "counted-matches", testFindControllerCountedMatches); - FindControllerTest::add("WebKitFindController", "options", testFindControllerOptions); - FindControllerTest::add("WebKitFindController", "hide", testFindControllerHide); -} - -void afterAll() -{ -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp deleted file mode 100644 index abbfd652a..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include "LoadTrackingTest.h" -#include "WebKitTestServer.h" -#include <wtf/gobject/GRefPtr.h> -#include <wtf/text/CString.h> - -static WebKitTestServer* kServer; - -class PolicyClientTest: public LoadTrackingTest { -public: - MAKE_GLIB_TEST_FIXTURE(PolicyClientTest); - - enum PolicyDecisionResponse { - Use, - Ignore, - Download, - None - }; - - PolicyClientTest() - : LoadTrackingTest() - , m_policyDecisionResponse(None) - , m_policyDecisionTypeFilter(0) - , m_respondToPolicyDecisionAsynchronously(false) - , m_haltMainLoopAfterMakingDecision(false) - { - g_signal_connect(m_webView, "decide-policy", G_CALLBACK(decidePolicyCallback), this); - } - - static gboolean quitMainLoopLater(GMainLoop* loop) - { - g_main_loop_quit(loop); - return FALSE; - } - - static void respondToPolicyDecision(PolicyClientTest* test, WebKitPolicyDecision* decision) - { - switch (test->m_policyDecisionResponse) { - case Use: - webkit_policy_decision_use(decision); - break; - case Ignore: - webkit_policy_decision_ignore(decision); - break; - case Download: - webkit_policy_decision_download(decision); - break; - case None: - break; - } - - if (test->m_haltMainLoopAfterMakingDecision) - g_idle_add(reinterpret_cast<GSourceFunc>(quitMainLoopLater), test->m_mainLoop); - } - - static gboolean respondToPolicyDecisionLater(PolicyClientTest* test) - { - respondToPolicyDecision(test, test->m_previousPolicyDecision.get()); - test->m_previousPolicyDecision = 0; - return FALSE; - } - - static gboolean decidePolicyCallback(WebKitWebView* webView, WebKitPolicyDecision* decision, WebKitPolicyDecisionType type, PolicyClientTest* test) - { - if (test->m_policyDecisionTypeFilter != type) - return FALSE; - - test->m_previousPolicyDecision = decision; - if (test->m_respondToPolicyDecisionAsynchronously) { - g_idle_add(reinterpret_cast<GSourceFunc>(respondToPolicyDecisionLater), test); - return TRUE; - } - - respondToPolicyDecision(test, decision); - - // We return FALSE here to ensure that the default policy decision - // handler doesn't override whatever we use here. - return FALSE; - } - - PolicyDecisionResponse m_policyDecisionResponse; - int m_policyDecisionTypeFilter; - bool m_respondToPolicyDecisionAsynchronously; - bool m_haltMainLoopAfterMakingDecision; - GRefPtr<WebKitPolicyDecision> m_previousPolicyDecision; -}; - -static void testNavigationPolicy(PolicyClientTest* test, gconstpointer) -{ - test->m_policyDecisionTypeFilter = WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION; - - test->m_policyDecisionResponse = PolicyClientTest::Use; - test->loadHtml("<html/>", "http://webkitgtk.org/"); - test->waitUntilLoadFinished(); - g_assert_cmpint(test->m_loadEvents.size(), ==, 3); - - // Ideally we'd like to have a more intensive test here, but it's still pretty tricky - // to trigger different types of navigations with the GTK+ WebKit2 API. - WebKitNavigationPolicyDecision* decision = WEBKIT_NAVIGATION_POLICY_DECISION(test->m_previousPolicyDecision.get()); - g_assert_cmpint(webkit_navigation_policy_decision_get_navigation_type(decision), ==, WEBKIT_NAVIGATION_TYPE_OTHER); - g_assert_cmpint(webkit_navigation_policy_decision_get_mouse_button(decision), ==, 0); - g_assert_cmpint(webkit_navigation_policy_decision_get_modifiers(decision), ==, 0); - g_assert_cmpstr(webkit_navigation_policy_decision_get_frame_name(decision), ==, 0); - WebKitURIRequest* request = webkit_navigation_policy_decision_get_request(decision); - g_assert_cmpstr(webkit_uri_request_get_uri(request), ==, "http://webkitgtk.org/"); - - test->m_policyDecisionResponse = PolicyClientTest::Use; - test->m_respondToPolicyDecisionAsynchronously = true; - test->loadHtml("<html/>", "http://webkitgtk.org/"); - test->waitUntilLoadFinished(); - g_assert_cmpint(test->m_loadEvents.size(), ==, 3); - - // If we are waiting until load completion, it will never complete if we ignore the - // navigation. So we tell the main loop to quit sometime later. - test->m_policyDecisionResponse = PolicyClientTest::Ignore; - test->m_respondToPolicyDecisionAsynchronously = false; - test->m_haltMainLoopAfterMakingDecision = true; - test->loadHtml("<html/>", "http://webkitgtk.org/"); - test->waitUntilLoadFinished(); - g_assert_cmpint(test->m_loadEvents.size(), ==, 0); - - test->m_policyDecisionResponse = PolicyClientTest::Ignore; - test->loadHtml("<html/>", "http://webkitgtk.org/"); - test->waitUntilLoadFinished(); - g_assert_cmpint(test->m_loadEvents.size(), ==, 0); -} - -static void testResponsePolicy(PolicyClientTest* test, gconstpointer) -{ - test->m_policyDecisionTypeFilter = WEBKIT_POLICY_DECISION_TYPE_RESPONSE; - - test->m_policyDecisionResponse = PolicyClientTest::Use; - test->loadURI(kServer->getURIForPath("/").data()); - test->waitUntilLoadFinished(); - g_assert_cmpint(test->m_loadEvents.size(), ==, 3); - g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted); - g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::LoadCommitted); - g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished); - - test->m_respondToPolicyDecisionAsynchronously = true; - test->loadURI(kServer->getURIForPath("/").data()); - test->waitUntilLoadFinished(); - g_assert_cmpint(test->m_loadEvents.size(), ==, 3); - g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted); - g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::LoadCommitted); - g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished); - - test->m_respondToPolicyDecisionAsynchronously = false; - test->m_policyDecisionResponse = PolicyClientTest::Ignore; - test->loadURI(kServer->getURIForPath("/").data()); - test->waitUntilLoadFinished(); - - g_assert_cmpint(test->m_loadEvents.size(), ==, 3); - g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted); - g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::ProvisionalLoadFailed); - g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished); -} - -struct CreateCallbackData { - bool triedToOpenWindow; - GMainLoop* mainLoop; -}; - -static WebKitWebView* createCallback(WebKitWebView* webView, CreateCallbackData* data) -{ - data->triedToOpenWindow = true; - g_main_loop_quit(data->mainLoop); - return 0; -} - -static void testNewWindowPolicy(PolicyClientTest* test, gconstpointer) -{ - static const char* windowOpeningHTML = - "<html><body>" - " <a id=\"link\" href=\"http://www.google.com\" target=\"_blank\">Link</a>" - " <script>" - " var event = document.createEvent('MouseEvents');" - " event.initEvent('click', true, false);" - " document.getElementById('link').dispatchEvent(event);" - " </script>" - "</body></html>"; - test->m_policyDecisionTypeFilter = WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION; - webkit_settings_set_javascript_can_open_windows_automatically(webkit_web_view_get_settings(test->m_webView), TRUE); - - CreateCallbackData data; - data.triedToOpenWindow = false; - data.mainLoop = test->m_mainLoop; - - g_signal_connect(test->m_webView, "create", G_CALLBACK(createCallback), &data); - test->m_policyDecisionResponse = PolicyClientTest::Use; - test->loadHtml(windowOpeningHTML, "http://webkitgtk.org/"); - test->wait(1); - g_assert(data.triedToOpenWindow); - - WebKitNavigationPolicyDecision* decision = WEBKIT_NAVIGATION_POLICY_DECISION(test->m_previousPolicyDecision.get()); - g_assert_cmpstr(webkit_navigation_policy_decision_get_frame_name(decision), ==, "_blank"); - - // Using a short timeout is a bit ugly here, but it's hard to get around because if we block - // the new window signal we cannot halt the main loop in the create callback. If we - // halt the main loop in the policy decision, the create callback never executes. - data.triedToOpenWindow = false; - test->m_policyDecisionResponse = PolicyClientTest::Ignore; - test->loadHtml(windowOpeningHTML, "http://webkitgtk.org/"); - test->wait(.2); - g_assert(!data.triedToOpenWindow); -} - -static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) -{ - if (message->method != SOUP_METHOD_GET) { - soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); - return; - } - - if (g_str_equal(path, "/")) { - static const char* responseString = "<html><body>Testing!</body></html>"; - soup_message_set_status(message, SOUP_STATUS_OK); - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString)); - soup_message_body_complete(message->response_body); - } else - soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); -} - -void beforeAll() -{ - kServer = new WebKitTestServer(); - kServer->run(serverCallback); - - PolicyClientTest::add("WebKitPolicyClient", "navigation-policy", testNavigationPolicy); - PolicyClientTest::add("WebKitPolicyClient", "response-policy", testResponsePolicy); - PolicyClientTest::add("WebKitPolicyClient", "new-window-policy", testNewWindowPolicy); -} - -void afterAll() -{ - delete kServer; -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp deleted file mode 100644 index 1ee3843f9..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation and/or - * other materials provided with the distribution. - * - * Neither the name of Motorola Mobility, Inc. nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#include "TestMain.h" -#include "WebViewTest.h" -#include "WebKitTestServer.h" -#include <gtk/gtk.h> -#include <webkit2/webkit2.h> -#include <wtf/gobject/GRefPtr.h> - -static WebKitTestServer* gServer; - -static void testWebKitSettings(Test*, gconstpointer) -{ - WebKitSettings* settings = webkit_settings_new(); - - // JavaScript is enabled by default. - g_assert(webkit_settings_get_enable_javascript(settings)); - webkit_settings_set_enable_javascript(settings, FALSE); - g_assert(!webkit_settings_get_enable_javascript(settings)); - - // By default auto-load-image is true. - g_assert(webkit_settings_get_auto_load_images(settings)); - webkit_settings_set_auto_load_images(settings, FALSE); - g_assert(!webkit_settings_get_auto_load_images(settings)); - - // load-icons-ignoring-image-load-setting is false by default. - g_assert(!webkit_settings_get_load_icons_ignoring_image_load_setting(settings)); - webkit_settings_set_load_icons_ignoring_image_load_setting(settings, TRUE); - g_assert(webkit_settings_get_load_icons_ignoring_image_load_setting(settings)); - - // Offline application cache is true by default. - g_assert(webkit_settings_get_enable_offline_web_application_cache(settings)); - webkit_settings_set_enable_offline_web_application_cache(settings, FALSE); - g_assert(!webkit_settings_get_enable_offline_web_application_cache(settings)); - - // Local storage is enable by default. - g_assert(webkit_settings_get_enable_html5_local_storage(settings)); - webkit_settings_set_enable_html5_local_storage(settings, FALSE); - g_assert(!webkit_settings_get_enable_html5_local_storage(settings)); - - // HTML5 database is enabled by default. - g_assert(webkit_settings_get_enable_html5_database(settings)); - webkit_settings_set_enable_html5_database(settings, FALSE); - g_assert(!webkit_settings_get_enable_html5_database(settings)); - - // XSS Auditor is enabled by default. - g_assert(webkit_settings_get_enable_xss_auditor(settings)); - webkit_settings_set_enable_xss_auditor(settings, FALSE); - g_assert(!webkit_settings_get_enable_xss_auditor(settings)); - - // Frame flattening is disabled by default. - g_assert(!webkit_settings_get_enable_frame_flattening(settings)); - webkit_settings_set_enable_frame_flattening(settings, TRUE); - g_assert(webkit_settings_get_enable_frame_flattening(settings)); - - // Plugins are enabled by default. - g_assert(webkit_settings_get_enable_plugins(settings)); - webkit_settings_set_enable_plugins(settings, FALSE); - g_assert(!webkit_settings_get_enable_plugins(settings)); - - // Java is enabled by default. - g_assert(webkit_settings_get_enable_java(settings)); - webkit_settings_set_enable_java(settings, FALSE); - g_assert(!webkit_settings_get_enable_java(settings)); - - // By default, JavaScript can open windows automatically is disabled. - g_assert(!webkit_settings_get_javascript_can_open_windows_automatically(settings)); - webkit_settings_set_javascript_can_open_windows_automatically(settings, TRUE); - g_assert(webkit_settings_get_javascript_can_open_windows_automatically(settings)); - - // By default hyper link auditing is disabled. - g_assert(!webkit_settings_get_enable_hyperlink_auditing(settings)); - webkit_settings_set_enable_hyperlink_auditing(settings, TRUE); - g_assert(webkit_settings_get_enable_hyperlink_auditing(settings)); - - // Default font family is "sans-serif". - g_assert_cmpstr(webkit_settings_get_default_font_family(settings), ==, "sans-serif"); - webkit_settings_set_default_font_family(settings, "monospace"); - g_assert_cmpstr(webkit_settings_get_default_font_family(settings), ==, "monospace"); - - // Default monospace font family font family is "monospace". - g_assert_cmpstr(webkit_settings_get_monospace_font_family(settings), ==, "monospace"); - webkit_settings_set_monospace_font_family(settings, "sans-serif"); - g_assert_cmpstr(webkit_settings_get_monospace_font_family(settings), ==, "sans-serif"); - - // Default serif font family is "serif". - g_assert_cmpstr(webkit_settings_get_serif_font_family(settings), ==, "serif"); - webkit_settings_set_serif_font_family(settings, "sans-serif"); - g_assert_cmpstr(webkit_settings_get_serif_font_family(settings), ==, "sans-serif"); - - // Default sans serif font family is "sans-serif". - g_assert_cmpstr(webkit_settings_get_sans_serif_font_family(settings), ==, "sans-serif"); - webkit_settings_set_sans_serif_font_family(settings, "serif"); - g_assert_cmpstr(webkit_settings_get_sans_serif_font_family(settings), ==, "serif"); - - // Default cursive font family "serif". - g_assert_cmpstr(webkit_settings_get_cursive_font_family(settings), ==, "serif"); - webkit_settings_set_cursive_font_family(settings, "sans-serif"); - g_assert_cmpstr(webkit_settings_get_cursive_font_family(settings), ==, "sans-serif"); - - // Default fantasy font family is "serif". - g_assert_cmpstr(webkit_settings_get_fantasy_font_family(settings), ==, "serif"); - webkit_settings_set_fantasy_font_family(settings, "sans-serif"); - g_assert_cmpstr(webkit_settings_get_fantasy_font_family(settings), ==, "sans-serif"); - - // Default pictograph font family is "serif". - g_assert_cmpstr(webkit_settings_get_pictograph_font_family(settings), ==, "serif"); - webkit_settings_set_pictograph_font_family(settings, "sans-serif"); - g_assert_cmpstr(webkit_settings_get_pictograph_font_family(settings), ==, "sans-serif"); - - // Default font size is 16. - g_assert_cmpuint(webkit_settings_get_default_font_size(settings), ==, 16); - webkit_settings_set_default_font_size(settings, 14); - g_assert_cmpuint(webkit_settings_get_default_font_size(settings), ==, 14); - - // Default monospace font size is 13. - g_assert_cmpuint(webkit_settings_get_default_monospace_font_size(settings), ==, 13); - webkit_settings_set_default_monospace_font_size(settings, 10); - g_assert_cmpuint(webkit_settings_get_default_monospace_font_size(settings), ==, 10); - - // Default minimum font size is 0. - g_assert_cmpuint(webkit_settings_get_minimum_font_size(settings), ==, 0); - webkit_settings_set_minimum_font_size(settings, 7); - g_assert_cmpuint(webkit_settings_get_minimum_font_size(settings), ==, 7); - - // Default charset is "iso-8859-1". - g_assert_cmpstr(webkit_settings_get_default_charset(settings), ==, "iso-8859-1"); - webkit_settings_set_default_charset(settings, "utf8"); - g_assert_cmpstr(webkit_settings_get_default_charset(settings), ==, "utf8"); - - g_assert(!webkit_settings_get_enable_private_browsing(settings)); - webkit_settings_set_enable_private_browsing(settings, TRUE); - g_assert(webkit_settings_get_enable_private_browsing(settings)); - - g_assert(!webkit_settings_get_enable_developer_extras(settings)); - webkit_settings_set_enable_developer_extras(settings, TRUE); - g_assert(webkit_settings_get_enable_developer_extras(settings)); - - g_assert(webkit_settings_get_enable_resizable_text_areas(settings)); - webkit_settings_set_enable_resizable_text_areas(settings, FALSE); - g_assert(!webkit_settings_get_enable_resizable_text_areas(settings)); - - g_assert(webkit_settings_get_enable_tabs_to_links(settings)); - webkit_settings_set_enable_tabs_to_links(settings, FALSE); - g_assert(!webkit_settings_get_enable_tabs_to_links(settings)); - - g_assert(!webkit_settings_get_enable_dns_prefetching(settings)); - webkit_settings_set_enable_dns_prefetching(settings, TRUE); - g_assert(webkit_settings_get_enable_dns_prefetching(settings)); - - // Caret browsing is disabled by default. - g_assert(!webkit_settings_get_enable_caret_browsing(settings)); - webkit_settings_set_enable_caret_browsing(settings, TRUE); - g_assert(webkit_settings_get_enable_caret_browsing(settings)); - - // Fullscreen JavaScript API is disabled by default. - g_assert(!webkit_settings_get_enable_fullscreen(settings)); - webkit_settings_set_enable_fullscreen(settings, TRUE); - g_assert(webkit_settings_get_enable_fullscreen(settings)); - - // Print backgrounds is enabled by default - g_assert(webkit_settings_get_print_backgrounds(settings)); - webkit_settings_set_print_backgrounds(settings, FALSE); - g_assert(!webkit_settings_get_print_backgrounds(settings)); - - // WebAudio is disabled by default. - g_assert(!webkit_settings_get_enable_webaudio(settings)); - webkit_settings_set_enable_webaudio(settings, TRUE); - g_assert(webkit_settings_get_enable_webaudio(settings)); - - // WebGL is disabled by default. - g_assert(!webkit_settings_get_enable_webgl(settings)); - webkit_settings_set_enable_webgl(settings, TRUE); - g_assert(webkit_settings_get_enable_webgl(settings)); - - // Allow Modal Dialogs is disabled by default. - g_assert(!webkit_settings_get_allow_modal_dialogs(settings)); - webkit_settings_set_allow_modal_dialogs(settings, TRUE); - g_assert(webkit_settings_get_allow_modal_dialogs(settings)); - - // Zoom text only is disabled by default. - g_assert(!webkit_settings_get_zoom_text_only(settings)); - webkit_settings_set_zoom_text_only(settings, TRUE); - g_assert(webkit_settings_get_zoom_text_only(settings)); - - // By default, JavaScript cannot access the clipboard. - g_assert(!webkit_settings_get_javascript_can_access_clipboard(settings)); - webkit_settings_set_javascript_can_access_clipboard(settings, TRUE); - g_assert(webkit_settings_get_javascript_can_access_clipboard(settings)); - - // By default, media playback doesn't require user gestures. - g_assert(!webkit_settings_get_media_playback_requires_user_gesture(settings)); - webkit_settings_set_media_playback_requires_user_gesture(settings, TRUE); - g_assert(webkit_settings_get_media_playback_requires_user_gesture(settings)); - - // By default, inline media playback is allowed - g_assert(webkit_settings_get_media_playback_allows_inline(settings)); - webkit_settings_set_media_playback_allows_inline(settings, FALSE); - g_assert(!webkit_settings_get_media_playback_allows_inline(settings)); - - // By default, debug indicators are disabled. - g_assert(!webkit_settings_get_draw_compositing_indicators(settings)); - webkit_settings_set_draw_compositing_indicators(settings, TRUE); - g_assert(webkit_settings_get_draw_compositing_indicators(settings)); - - // By default, site specific quirks are disabled. - g_assert(!webkit_settings_get_enable_site_specific_quirks(settings)); - webkit_settings_set_enable_site_specific_quirks(settings, TRUE); - g_assert(webkit_settings_get_enable_site_specific_quirks(settings)); - - // By default, page cache is enabled. - g_assert(webkit_settings_get_enable_page_cache(settings)); - webkit_settings_set_enable_page_cache(settings, FALSE); - g_assert(!webkit_settings_get_enable_page_cache(settings)); - - // By default, smooth scrolling is disabled. - g_assert(!webkit_settings_get_enable_smooth_scrolling(settings)); - webkit_settings_set_enable_smooth_scrolling(settings, TRUE); - g_assert(webkit_settings_get_enable_smooth_scrolling(settings)); - - // By default, accelerated 2D canvas is disabled. - g_assert(!webkit_settings_get_enable_accelerated_2d_canvas(settings)); - webkit_settings_set_enable_accelerated_2d_canvas(settings, TRUE); - g_assert(webkit_settings_get_enable_accelerated_2d_canvas(settings)); - - // By default, writing of console messages to stdout is disabled. - g_assert(!webkit_settings_get_enable_write_console_messages_to_stdout(settings)); - webkit_settings_set_enable_write_console_messages_to_stdout(settings, TRUE); - g_assert(webkit_settings_get_enable_write_console_messages_to_stdout(settings)); - - g_object_unref(G_OBJECT(settings)); -} - -void testWebKitSettingsNewWithSettings(Test* test, gconstpointer) -{ - GRefPtr<WebKitSettings> settings = adoptGRef(webkit_settings_new_with_settings("enable-javascript", FALSE, - "auto-load-images", FALSE, - "load-icons-ignoring-image-load-setting", TRUE, - NULL)); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(settings.get())); - g_assert(!webkit_settings_get_enable_javascript(settings.get())); - g_assert(!webkit_settings_get_auto_load_images(settings.get())); - g_assert(webkit_settings_get_load_icons_ignoring_image_load_setting(settings.get())); -} - -static CString convertWebViewMainResourceDataToCString(WebViewTest* test) -{ - size_t mainResourceDataSize = 0; - const char* mainResourceData = test->mainResourceData(mainResourceDataSize); - return CString(mainResourceData, mainResourceDataSize); -} - -static void assertThatUserAgentIsSentInHeaders(WebViewTest* test, const CString& userAgent) -{ - test->loadURI(gServer->getURIForPath("/").data()); - test->waitUntilLoadFinished(); - ASSERT_CMP_CSTRING(convertWebViewMainResourceDataToCString(test), ==, userAgent); -} - -static void testWebKitSettingsUserAgent(WebViewTest* test, gconstpointer) -{ - GRefPtr<WebKitSettings> settings = adoptGRef(webkit_settings_new()); - CString defaultUserAgent = webkit_settings_get_user_agent(settings.get()); - webkit_web_view_set_settings(test->m_webView, settings.get()); - - g_assert(g_strstr_len(defaultUserAgent.data(), -1, "Safari")); - g_assert(g_strstr_len(defaultUserAgent.data(), -1, "Chromium")); - g_assert(g_strstr_len(defaultUserAgent.data(), -1, "Chrome")); - - webkit_settings_set_user_agent(settings.get(), 0); - g_assert_cmpstr(defaultUserAgent.data(), ==, webkit_settings_get_user_agent(settings.get())); - assertThatUserAgentIsSentInHeaders(test, defaultUserAgent.data()); - - webkit_settings_set_user_agent(settings.get(), ""); - g_assert_cmpstr(defaultUserAgent.data(), ==, webkit_settings_get_user_agent(settings.get())); - - const char* funkyUserAgent = "Funky!"; - webkit_settings_set_user_agent(settings.get(), funkyUserAgent); - g_assert_cmpstr(funkyUserAgent, ==, webkit_settings_get_user_agent(settings.get())); - assertThatUserAgentIsSentInHeaders(test, funkyUserAgent); - - webkit_settings_set_user_agent_with_application_details(settings.get(), "WebKitGTK+", 0); - const char* userAgentWithNullVersion = webkit_settings_get_user_agent(settings.get()); - g_assert_cmpstr(g_strstr_len(userAgentWithNullVersion, -1, defaultUserAgent.data()), ==, userAgentWithNullVersion); - g_assert(g_strstr_len(userAgentWithNullVersion, -1, "WebKitGTK+")); - - webkit_settings_set_user_agent_with_application_details(settings.get(), "WebKitGTK+", ""); - g_assert_cmpstr(webkit_settings_get_user_agent(settings.get()), ==, userAgentWithNullVersion); - - webkit_settings_set_user_agent_with_application_details(settings.get(), "WebCatGTK+", "3.4.5"); - const char* newUserAgent = webkit_settings_get_user_agent(settings.get()); - g_assert(g_strstr_len(newUserAgent, -1, "3.4.5")); - g_assert(g_strstr_len(newUserAgent, -1, "WebCatGTK+")); -} - -static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) -{ - if (message->method != SOUP_METHOD_GET) { - soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); - return; - } - - if (g_str_equal(path, "/")) { - const char* userAgent = soup_message_headers_get_one(message->request_headers, "User-Agent"); - soup_message_set_status(message, SOUP_STATUS_OK); - soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, userAgent, strlen(userAgent)); - soup_message_body_complete(message->response_body); - } else - soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); -} - -void beforeAll() -{ - gServer = new WebKitTestServer(); - gServer->run(serverCallback); - - Test::add("WebKitSettings", "webkit-settings", testWebKitSettings); - Test::add("WebKitSettings", "new-with-settings", testWebKitSettingsNewWithSettings); - WebViewTest::add("WebKitSettings", "user-agent", testWebKitSettingsUserAgent); -} - -void afterAll() -{ - delete gServer; -} - diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitVersion.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitVersion.cpp deleted file mode 100644 index e747ff962..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitVersion.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2,1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include "TestMain.h" -#include <gtk/gtk.h> -#include <webkit2/webkit2.h> - - -static void testWebKitVersion(Test*, gconstpointer) -{ - g_assert_cmpuint(webkit_get_major_version(), ==, WEBKIT_MAJOR_VERSION); - g_assert_cmpuint(webkit_get_minor_version(), ==, WEBKIT_MINOR_VERSION); - g_assert_cmpuint(webkit_get_micro_version(), ==, WEBKIT_MICRO_VERSION); -} - -static void testWebKitCheckVersion(Test*, gconstpointer) -{ - g_assert(WEBKIT_CHECK_VERSION(WEBKIT_MAJOR_VERSION, WEBKIT_MINOR_VERSION, WEBKIT_MICRO_VERSION)); - g_assert(!WEBKIT_CHECK_VERSION(WEBKIT_MAJOR_VERSION + 1, WEBKIT_MINOR_VERSION, WEBKIT_MICRO_VERSION)); - g_assert(!WEBKIT_CHECK_VERSION(WEBKIT_MAJOR_VERSION, WEBKIT_MINOR_VERSION + 1, WEBKIT_MICRO_VERSION)); - g_assert(!WEBKIT_CHECK_VERSION(WEBKIT_MAJOR_VERSION, WEBKIT_MINOR_VERSION, WEBKIT_MICRO_VERSION + 1)); -} - -void beforeAll() -{ - Test::add("WebKitVersion", "version", testWebKitVersion); - Test::add("WebKitVersion", "check-version", testWebKitCheckVersion); -} - -void afterAll() -{ -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp deleted file mode 100644 index 54e44d682..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Copyright (C) 2011 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2,1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include "LoadTrackingTest.h" -#include "WebKitTestServer.h" -#include <gtk/gtk.h> -#include <webkit2/webkit2.h> -#include <wtf/HashMap.h> -#include <wtf/gobject/GOwnPtr.h> -#include <wtf/gobject/GRefPtr.h> -#include <wtf/text/StringHash.h> - -static WebKitTestServer* kServer; - -static void testWebContextDefault(Test* test, gconstpointer) -{ - // Check there's a single instance of the default web context. - g_assert(webkit_web_context_get_default() == webkit_web_context_get_default()); -} - -class PluginsTest: public Test { -public: - MAKE_GLIB_TEST_FIXTURE(PluginsTest); - - PluginsTest() - : m_context(webkit_web_context_get_default()) - , m_mainLoop(g_main_loop_new(0, TRUE)) - , m_plugins(0) - { - webkit_web_context_set_additional_plugins_directory(m_context, WEBKIT_TEST_PLUGIN_DIR); - } - - ~PluginsTest() - { - g_main_loop_unref(m_mainLoop); - g_list_free_full(m_plugins, g_object_unref); - } - - static void getPluginsAsyncReadyCallback(GObject*, GAsyncResult* result, PluginsTest* test) - { - test->m_plugins = webkit_web_context_get_plugins_finish(test->m_context, result, 0); - g_main_loop_quit(test->m_mainLoop); - } - - GList* getPlugins() - { - g_list_free_full(m_plugins, g_object_unref); - webkit_web_context_get_plugins(m_context, 0, reinterpret_cast<GAsyncReadyCallback>(getPluginsAsyncReadyCallback), this); - g_main_loop_run(m_mainLoop); - return m_plugins; - } - - WebKitWebContext* m_context; - GMainLoop* m_mainLoop; - GList* m_plugins; -}; - -static void testWebContextGetPlugins(PluginsTest* test, gconstpointer) -{ - GList* plugins = test->getPlugins(); - g_assert(plugins); - - GRefPtr<WebKitPlugin> testPlugin; - for (GList* item = plugins; item; item = g_list_next(item)) { - WebKitPlugin* plugin = WEBKIT_PLUGIN(item->data); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(plugin)); - if (!g_strcmp0(webkit_plugin_get_name(plugin), "WebKit Test PlugIn")) { - testPlugin = plugin; - break; - } - } - g_assert(WEBKIT_IS_PLUGIN(testPlugin.get())); - - GOwnPtr<char> pluginPath(g_build_filename(WEBKIT_TEST_PLUGIN_DIR, "libtestnetscapeplugin.so", NULL)); - g_assert_cmpstr(webkit_plugin_get_path(testPlugin.get()), ==, pluginPath.get()); - g_assert_cmpstr(webkit_plugin_get_description(testPlugin.get()), ==, "Simple Netscape® plug-in that handles test content for WebKit"); - GList* mimeInfoList = webkit_plugin_get_mime_info_list(testPlugin.get()); - g_assert(mimeInfoList); - g_assert_cmpuint(g_list_length(mimeInfoList), ==, 2); - - WebKitMimeInfo* mimeInfo = static_cast<WebKitMimeInfo*>(mimeInfoList->data); - g_assert_cmpstr(webkit_mime_info_get_mime_type(mimeInfo), ==, "image/png"); - g_assert_cmpstr(webkit_mime_info_get_description(mimeInfo), ==, "png image"); - const gchar* const* extensions = webkit_mime_info_get_extensions(mimeInfo); - g_assert(extensions); - g_assert_cmpstr(extensions[0], ==, "png"); - - mimeInfoList = g_list_next(mimeInfoList); - mimeInfo = static_cast<WebKitMimeInfo*>(mimeInfoList->data); - g_assert_cmpstr(webkit_mime_info_get_mime_type(mimeInfo), ==, "application/x-webkit-test-netscape"); - g_assert_cmpstr(webkit_mime_info_get_description(mimeInfo), ==, "test netscape content"); - extensions = webkit_mime_info_get_extensions(mimeInfo); - g_assert(extensions); - g_assert_cmpstr(extensions[0], ==, "testnetscape"); -} - -static const char* kBarHTML = "<html><body>Bar</body></html>"; -static const char* kEchoHTMLFormat = "<html><body>%s</body></html>"; -static const char* errorDomain = "test"; -static const int errorCode = 10; -static const char* errorMessage = "Error message."; - -class URISchemeTest: public LoadTrackingTest { -public: - MAKE_GLIB_TEST_FIXTURE(URISchemeTest); - - struct URISchemeHandler { - URISchemeHandler() - : replyLength(0) - { - } - - URISchemeHandler(const char* reply, int replyLength, const char* mimeType) - : reply(reply) - , replyLength(replyLength) - , mimeType(mimeType) - { - } - - CString reply; - int replyLength; - CString mimeType; - }; - - static void uriSchemeRequestCallback(WebKitURISchemeRequest* request, gpointer userData) - { - URISchemeTest* test = static_cast<URISchemeTest*>(userData); - test->m_uriSchemeRequest = request; - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request)); - - g_assert(webkit_uri_scheme_request_get_web_view(request) == test->m_webView); - - GRefPtr<GInputStream> inputStream = adoptGRef(g_memory_input_stream_new()); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(inputStream.get())); - - const char* scheme = webkit_uri_scheme_request_get_scheme(request); - g_assert(scheme); - g_assert(test->m_handlersMap.contains(String::fromUTF8(scheme))); - - if (!g_strcmp0(scheme, "error")) { - GOwnPtr<GError> error(g_error_new_literal(g_quark_from_string(errorDomain), errorCode, errorMessage)); - webkit_uri_scheme_request_finish_error(request, error.get()); - return; - } - - const URISchemeHandler& handler = test->m_handlersMap.get(String::fromUTF8(scheme)); - - if (!g_strcmp0(scheme, "echo")) { - char* replyHTML = g_strdup_printf(handler.reply.data(), webkit_uri_scheme_request_get_path(request)); - g_memory_input_stream_add_data(G_MEMORY_INPUT_STREAM(inputStream.get()), replyHTML, strlen(replyHTML), g_free); - } else if (!g_strcmp0(scheme, "closed")) - g_input_stream_close(inputStream.get(), 0, 0); - else if (!handler.reply.isNull()) - g_memory_input_stream_add_data(G_MEMORY_INPUT_STREAM(inputStream.get()), handler.reply.data(), handler.reply.length(), 0); - - webkit_uri_scheme_request_finish(request, inputStream.get(), handler.replyLength, handler.mimeType.data()); - } - - void registerURISchemeHandler(const char* scheme, const char* reply, int replyLength, const char* mimeType) - { - m_handlersMap.set(String::fromUTF8(scheme), URISchemeHandler(reply, replyLength, mimeType)); - webkit_web_context_register_uri_scheme(webkit_web_context_get_default(), scheme, uriSchemeRequestCallback, this, 0); - } - - GRefPtr<WebKitURISchemeRequest> m_uriSchemeRequest; - HashMap<String, URISchemeHandler> m_handlersMap; -}; - -static void testWebContextURIScheme(URISchemeTest* test, gconstpointer) -{ - test->registerURISchemeHandler("foo", kBarHTML, strlen(kBarHTML), "text/html"); - test->loadURI("foo:blank"); - test->waitUntilLoadFinished(); - size_t mainResourceDataSize = 0; - const char* mainResourceData = test->mainResourceData(mainResourceDataSize); - g_assert_cmpint(mainResourceDataSize, ==, strlen(kBarHTML)); - g_assert(!strncmp(mainResourceData, kBarHTML, mainResourceDataSize)); - - test->registerURISchemeHandler("echo", kEchoHTMLFormat, -1, "text/html"); - test->loadURI("echo:hello world"); - test->waitUntilLoadFinished(); - GOwnPtr<char> echoHTML(g_strdup_printf(kEchoHTMLFormat, webkit_uri_scheme_request_get_path(test->m_uriSchemeRequest.get()))); - mainResourceDataSize = 0; - mainResourceData = test->mainResourceData(mainResourceDataSize); - g_assert_cmpint(mainResourceDataSize, ==, strlen(echoHTML.get())); - g_assert(!strncmp(mainResourceData, echoHTML.get(), mainResourceDataSize)); - - test->registerURISchemeHandler("nomime", kBarHTML, -1, 0); - test->m_loadEvents.clear(); - test->loadURI("nomime:foo bar"); - test->waitUntilLoadFinished(); - g_assert(test->m_loadEvents.contains(LoadTrackingTest::ProvisionalLoadFailed)); - - test->registerURISchemeHandler("empty", 0, 0, "text/html"); - test->m_loadEvents.clear(); - test->loadURI("empty:nothing"); - test->waitUntilLoadFinished(); - g_assert(!test->m_loadEvents.contains(LoadTrackingTest::ProvisionalLoadFailed)); - g_assert(!test->m_loadEvents.contains(LoadTrackingTest::LoadFailed)); - - test->registerURISchemeHandler("error", 0, 0, 0); - test->m_loadEvents.clear(); - test->loadURI("error:error"); - test->waitUntilLoadFinished(); - g_assert(test->m_loadEvents.contains(LoadTrackingTest::ProvisionalLoadFailed)); - g_assert(test->m_loadFailed); - g_assert_error(test->m_error.get(), g_quark_from_string(errorDomain), errorCode); - g_assert_cmpstr(test->m_error->message, ==, errorMessage); - - test->registerURISchemeHandler("closed", 0, 0, 0); - test->m_loadEvents.clear(); - test->loadURI("closed:input-stream"); - test->waitUntilLoadFinished(); - g_assert(test->m_loadEvents.contains(LoadTrackingTest::ProvisionalLoadFailed)); - g_assert(test->m_loadFailed); - g_assert_error(test->m_error.get(), G_IO_ERROR, G_IO_ERROR_CLOSED); -} - -static void testWebContextSpellChecker(Test* test, gconstpointer) -{ - WebKitWebContext* webContext = webkit_web_context_get_default(); - - // Check what happens if no spell checking language has been set. - const gchar* const* currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); - g_assert(!currentLanguage); - - // Set the language to a specific one. - GRefPtr<GPtrArray> languages = adoptGRef(g_ptr_array_new()); - g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("en_US"))); - g_ptr_array_add(languages.get(), 0); - webkit_web_context_set_spell_checking_languages(webContext, reinterpret_cast<const char* const*>(languages->pdata)); - currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); - g_assert_cmpuint(g_strv_length(const_cast<char**>(currentLanguage)), ==, 1); - g_assert_cmpstr(currentLanguage[0], ==, "en_US"); - - // Set the language string to list of valid languages. - g_ptr_array_remove_index_fast(languages.get(), languages->len - 1); - g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("en_GB"))); - g_ptr_array_add(languages.get(), 0); - webkit_web_context_set_spell_checking_languages(webContext, reinterpret_cast<const char* const*>(languages->pdata)); - currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); - g_assert_cmpuint(g_strv_length(const_cast<char**>(currentLanguage)), ==, 2); - g_assert_cmpstr(currentLanguage[0], ==, "en_US"); - g_assert_cmpstr(currentLanguage[1], ==, "en_GB"); - - // Try passing a wrong language along with good ones. - g_ptr_array_remove_index_fast(languages.get(), languages->len - 1); - g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("bd_WR"))); - g_ptr_array_add(languages.get(), 0); - webkit_web_context_set_spell_checking_languages(webContext, reinterpret_cast<const char* const*>(languages->pdata)); - currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); - g_assert_cmpuint(g_strv_length(const_cast<char**>(currentLanguage)), ==, 2); - g_assert_cmpstr(currentLanguage[0], ==, "en_US"); - g_assert_cmpstr(currentLanguage[1], ==, "en_GB"); - - // Try passing a list with only wrong languages. - languages = adoptGRef(g_ptr_array_new()); - g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("bd_WR"))); - g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("wr_BD"))); - g_ptr_array_add(languages.get(), 0); - webkit_web_context_set_spell_checking_languages(webContext, reinterpret_cast<const char* const*>(languages->pdata)); - currentLanguage = webkit_web_context_get_spell_checking_languages(webContext); - g_assert(!currentLanguage); - - // Check disabling and re-enabling spell checking. - webkit_web_context_set_spell_checking_enabled(webContext, FALSE); - g_assert(!webkit_web_context_get_spell_checking_enabled(webContext)); - webkit_web_context_set_spell_checking_enabled(webContext, TRUE); - g_assert(webkit_web_context_get_spell_checking_enabled(webContext)); -} - -static void testWebContextLanguages(WebViewTest* test, gconstpointer) -{ - static const char* expectedDefaultLanguage = "en"; - test->loadURI(kServer->getURIForPath("/").data()); - test->waitUntilLoadFinished(); - size_t mainResourceDataSize = 0; - const char* mainResourceData = test->mainResourceData(mainResourceDataSize); - g_assert_cmpuint(mainResourceDataSize, ==, strlen(expectedDefaultLanguage)); - g_assert(!strncmp(mainResourceData, expectedDefaultLanguage, mainResourceDataSize)); - - GRefPtr<GPtrArray> languages = adoptGRef(g_ptr_array_new()); - g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("en"))); - g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("ES_es"))); - g_ptr_array_add(languages.get(), const_cast<gpointer>(static_cast<const void*>("dE"))); - g_ptr_array_add(languages.get(), 0); - webkit_web_context_set_preferred_languages(webkit_web_context_get_default(), reinterpret_cast<const char* const*>(languages->pdata)); - - static const char* expectedLanguages = "en, es-es;q=0.90, de;q=0.80"; - test->loadURI(kServer->getURIForPath("/").data()); - test->waitUntilLoadFinished(); - mainResourceDataSize = 0; - mainResourceData = test->mainResourceData(mainResourceDataSize); - g_assert_cmpuint(mainResourceDataSize, ==, strlen(expectedLanguages)); - g_assert(!strncmp(mainResourceData, expectedLanguages, mainResourceDataSize)); -} - -static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) -{ - if (message->method != SOUP_METHOD_GET) { - soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); - return; - } - - if (g_str_equal(path, "/")) { - const char* acceptLanguage = soup_message_headers_get_one(message->request_headers, "Accept-Language"); - soup_message_set_status(message, SOUP_STATUS_OK); - soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, acceptLanguage, strlen(acceptLanguage)); - soup_message_body_complete(message->response_body); - } else - soup_message_set_status(message, SOUP_STATUS_NOT_FOUND); -} - -class SecurityPolicyTest: public Test { -public: - MAKE_GLIB_TEST_FIXTURE(SecurityPolicyTest); - - enum SecurityPolicy { - Local = 1 << 1, - NoAccess = 1 << 2, - DisplayIsolated = 1 << 3, - Secure = 1 << 4, - CORSEnabled = 1 << 5, - EmptyDocument = 1 << 6 - }; - - SecurityPolicyTest() - : m_manager(webkit_web_context_get_security_manager(webkit_web_context_get_default())) - { - } - - void verifyThatSchemeMatchesPolicy(const char* scheme, unsigned policy) - { - if (policy & Local) - g_assert(webkit_security_manager_uri_scheme_is_local(m_manager, scheme)); - else - g_assert(!webkit_security_manager_uri_scheme_is_local(m_manager, scheme)); - if (policy & NoAccess) - g_assert(webkit_security_manager_uri_scheme_is_no_access(m_manager, scheme)); - else - g_assert(!webkit_security_manager_uri_scheme_is_no_access(m_manager, scheme)); - if (policy & DisplayIsolated) - g_assert(webkit_security_manager_uri_scheme_is_display_isolated(m_manager, scheme)); - else - g_assert(!webkit_security_manager_uri_scheme_is_display_isolated(m_manager, scheme)); - if (policy & Secure) - g_assert(webkit_security_manager_uri_scheme_is_secure(m_manager, scheme)); - else - g_assert(!webkit_security_manager_uri_scheme_is_secure(m_manager, scheme)); - if (policy & CORSEnabled) - g_assert(webkit_security_manager_uri_scheme_is_cors_enabled(m_manager, scheme)); - else - g_assert(!webkit_security_manager_uri_scheme_is_cors_enabled(m_manager, scheme)); - if (policy & EmptyDocument) - g_assert(webkit_security_manager_uri_scheme_is_empty_document(m_manager, scheme)); - else - g_assert(!webkit_security_manager_uri_scheme_is_empty_document(m_manager, scheme)); - } - - WebKitSecurityManager* m_manager; -}; - -static void testWebContextSecurityPolicy(SecurityPolicyTest* test, gconstpointer) -{ - // VerifyThatSchemeMatchesPolicy default policy for well known schemes. - test->verifyThatSchemeMatchesPolicy("http", SecurityPolicyTest::CORSEnabled); - test->verifyThatSchemeMatchesPolicy("https", SecurityPolicyTest::CORSEnabled | SecurityPolicyTest::Secure); - test->verifyThatSchemeMatchesPolicy("file", SecurityPolicyTest::Local); - test->verifyThatSchemeMatchesPolicy("data", SecurityPolicyTest::NoAccess | SecurityPolicyTest::Secure); - test->verifyThatSchemeMatchesPolicy("about", SecurityPolicyTest::NoAccess | SecurityPolicyTest::Secure | SecurityPolicyTest::EmptyDocument); - - // Custom scheme. - test->verifyThatSchemeMatchesPolicy("foo", 0); - - webkit_security_manager_register_uri_scheme_as_local(test->m_manager, "foo"); - test->verifyThatSchemeMatchesPolicy("foo", SecurityPolicyTest::Local); - webkit_security_manager_register_uri_scheme_as_no_access(test->m_manager, "foo"); - test->verifyThatSchemeMatchesPolicy("foo", SecurityPolicyTest::Local | SecurityPolicyTest::NoAccess); - webkit_security_manager_register_uri_scheme_as_display_isolated(test->m_manager, "foo"); - test->verifyThatSchemeMatchesPolicy("foo", SecurityPolicyTest::Local | SecurityPolicyTest::NoAccess | SecurityPolicyTest::DisplayIsolated); - webkit_security_manager_register_uri_scheme_as_secure(test->m_manager, "foo"); - test->verifyThatSchemeMatchesPolicy("foo", SecurityPolicyTest::Local | SecurityPolicyTest::NoAccess | SecurityPolicyTest::DisplayIsolated | SecurityPolicyTest::Secure); - webkit_security_manager_register_uri_scheme_as_cors_enabled(test->m_manager, "foo"); - test->verifyThatSchemeMatchesPolicy("foo", SecurityPolicyTest::Local | SecurityPolicyTest::NoAccess | SecurityPolicyTest::DisplayIsolated | SecurityPolicyTest::Secure - | SecurityPolicyTest::CORSEnabled); - webkit_security_manager_register_uri_scheme_as_empty_document(test->m_manager, "foo"); - test->verifyThatSchemeMatchesPolicy("foo", SecurityPolicyTest::Local | SecurityPolicyTest::NoAccess | SecurityPolicyTest::DisplayIsolated | SecurityPolicyTest::Secure - | SecurityPolicyTest::CORSEnabled | SecurityPolicyTest::EmptyDocument); -} - -void beforeAll() -{ - kServer = new WebKitTestServer(); - kServer->run(serverCallback); - - Test::add("WebKitWebContext", "default-context", testWebContextDefault); - PluginsTest::add("WebKitWebContext", "get-plugins", testWebContextGetPlugins); - URISchemeTest::add("WebKitWebContext", "uri-scheme", testWebContextURIScheme); - Test::add("WebKitWebContext", "spell-checker", testWebContextSpellChecker); - WebViewTest::add("WebKitWebContext", "languages", testWebContextLanguages); - SecurityPolicyTest::add("WebKitSecurityManager", "security-policy", testWebContextSecurityPolicy); -} - -void afterAll() -{ - delete kServer; -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp deleted file mode 100644 index 88d77f286..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp +++ /dev/null @@ -1,1258 +0,0 @@ -/* - * Copyright (C) 2011 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2,1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "WebViewTest.h" -#include <JavaScriptCore/JSStringRef.h> -#include <JavaScriptCore/JSValueRef.h> -#include <glib/gstdio.h> -#include <wtf/HashSet.h> -#include <wtf/gobject/GRefPtr.h> -#include <wtf/text/StringHash.h> - -static void testWebViewDefaultContext(WebViewTest* test, gconstpointer) -{ - g_assert(webkit_web_view_get_context(test->m_webView) == webkit_web_context_get_default()); - - // Check that a web view created with g_object_new has the default context. - GRefPtr<WebKitWebView> webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW, NULL)); - g_assert(webkit_web_view_get_context(webView.get()) == webkit_web_context_get_default()); -} - -static void testWebViewCustomCharset(WebViewTest* test, gconstpointer) -{ - g_assert(!webkit_web_view_get_custom_charset(test->m_webView)); - webkit_web_view_set_custom_charset(test->m_webView, "utf8"); - g_assert_cmpstr(webkit_web_view_get_custom_charset(test->m_webView), ==, "utf8"); - // Go back to the default charset. - webkit_web_view_set_custom_charset(test->m_webView, 0); - g_assert(!webkit_web_view_get_custom_charset(test->m_webView)); -} - -static void testWebViewSettings(WebViewTest* test, gconstpointer) -{ - WebKitSettings* defaultSettings = webkit_web_view_get_settings(test->m_webView); - g_assert(defaultSettings); - g_assert(webkit_settings_get_enable_javascript(defaultSettings)); - - GRefPtr<WebKitSettings> newSettings = adoptGRef(webkit_settings_new()); - g_object_set(G_OBJECT(newSettings.get()), "enable-javascript", FALSE, NULL); - webkit_web_view_set_settings(test->m_webView, newSettings.get()); - - WebKitSettings* settings = webkit_web_view_get_settings(test->m_webView); - g_assert(settings != defaultSettings); - g_assert(!webkit_settings_get_enable_javascript(settings)); - - GRefPtr<GtkWidget> webView2 = webkit_web_view_new(); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webView2.get())); - webkit_web_view_set_settings(WEBKIT_WEB_VIEW(webView2.get()), settings); - g_assert(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webView2.get())) == settings); - - GRefPtr<WebKitSettings> newSettings2 = adoptGRef(webkit_settings_new()); - webkit_web_view_set_settings(WEBKIT_WEB_VIEW(webView2.get()), newSettings2.get()); - settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webView2.get())); - g_assert(settings == newSettings2.get()); - g_assert(webkit_settings_get_enable_javascript(settings)); -} - -static const char* kAlertDialogMessage = "WebKitGTK+ alert dialog message"; -static const char* kConfirmDialogMessage = "WebKitGTK+ confirm dialog message"; -static const char* kPromptDialogMessage = "WebKitGTK+ prompt dialog message"; -static const char* kPromptDialogReturnedText = "WebKitGTK+ prompt dialog returned text"; - -class UIClientTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(UIClientTest); - - enum WebViewEvents { - Create, - ReadyToShow, - RunAsModal, - Close - }; - - class WindowProperties { - public: - WindowProperties() - : m_isNull(true) - , m_toolbarVisible(true) - , m_statusbarVisible(true) - , m_scrollbarsVisible(true) - , m_menubarVisible(true) - , m_locationbarVisible(true) - , m_resizable(true) - , m_fullscreen(false) - { - memset(&m_geometry, 0, sizeof(GdkRectangle)); - } - - WindowProperties(WebKitWindowProperties* windowProperties) - : m_isNull(false) - , m_toolbarVisible(webkit_window_properties_get_toolbar_visible(windowProperties)) - , m_statusbarVisible(webkit_window_properties_get_statusbar_visible(windowProperties)) - , m_scrollbarsVisible(webkit_window_properties_get_scrollbars_visible(windowProperties)) - , m_menubarVisible(webkit_window_properties_get_menubar_visible(windowProperties)) - , m_locationbarVisible(webkit_window_properties_get_locationbar_visible(windowProperties)) - , m_resizable(webkit_window_properties_get_resizable(windowProperties)) - , m_fullscreen(webkit_window_properties_get_fullscreen(windowProperties)) - { - webkit_window_properties_get_geometry(windowProperties, &m_geometry); - } - - WindowProperties(GdkRectangle* geometry, bool toolbarVisible, bool statusbarVisible, bool scrollbarsVisible, bool menubarVisible, - bool locationbarVisible, bool resizable, bool fullscreen) - : m_isNull(false) - , m_geometry(*geometry) - , m_toolbarVisible(toolbarVisible) - , m_statusbarVisible(statusbarVisible) - , m_scrollbarsVisible(scrollbarsVisible) - , m_menubarVisible(menubarVisible) - , m_locationbarVisible(locationbarVisible) - , m_resizable(resizable) - , m_fullscreen(fullscreen) - { - } - - bool isNull() const { return m_isNull; } - - void assertEqual(const WindowProperties& other) const - { - g_assert_cmpint(m_geometry.x, ==, other.m_geometry.x); - g_assert_cmpint(m_geometry.y, ==, other.m_geometry.y); - g_assert_cmpint(m_geometry.width, ==, other.m_geometry.width); - g_assert_cmpint(m_geometry.height, ==, other.m_geometry.height); - g_assert_cmpint(static_cast<int>(m_toolbarVisible), ==, static_cast<int>(other.m_toolbarVisible)); - g_assert_cmpint(static_cast<int>(m_statusbarVisible), ==, static_cast<int>(other.m_statusbarVisible)); - g_assert_cmpint(static_cast<int>(m_scrollbarsVisible), ==, static_cast<int>(other.m_scrollbarsVisible)); - g_assert_cmpint(static_cast<int>(m_menubarVisible), ==, static_cast<int>(other.m_menubarVisible)); - g_assert_cmpint(static_cast<int>(m_locationbarVisible), ==, static_cast<int>(other.m_locationbarVisible)); - g_assert_cmpint(static_cast<int>(m_resizable), ==, static_cast<int>(other.m_resizable)); - g_assert_cmpint(static_cast<int>(m_fullscreen), ==, static_cast<int>(other.m_fullscreen)); - } - - private: - bool m_isNull; - - GdkRectangle m_geometry; - - bool m_toolbarVisible; - bool m_statusbarVisible; - bool m_scrollbarsVisible; - bool m_menubarVisible; - bool m_locationbarVisible; - - bool m_resizable; - bool m_fullscreen; - }; - - static void windowPropertiesNotifyCallback(GObject*, GParamSpec* paramSpec, UIClientTest* test) - { - test->m_windowPropertiesChanged.add(g_param_spec_get_name(paramSpec)); - } - - static GtkWidget* viewCreateCallback(WebKitWebView* webView, UIClientTest* test) - { - return test->viewCreate(webView); - } - - static void viewReadyToShowCallback(WebKitWebView* webView, UIClientTest* test) - { - test->viewReadyToShow(webView); - } - - static void viewCloseCallback(WebKitWebView* webView, UIClientTest* test) - { - test->viewClose(webView); - } - - void scriptAlert(WebKitScriptDialog* dialog) - { - switch (m_scriptDialogType) { - case WEBKIT_SCRIPT_DIALOG_ALERT: - g_assert_cmpstr(webkit_script_dialog_get_message(dialog), ==, kAlertDialogMessage); - break; - case WEBKIT_SCRIPT_DIALOG_CONFIRM: - g_assert(m_scriptDialogConfirmed); - g_assert_cmpstr(webkit_script_dialog_get_message(dialog), ==, "confirmed"); - - break; - case WEBKIT_SCRIPT_DIALOG_PROMPT: - g_assert_cmpstr(webkit_script_dialog_get_message(dialog), ==, kPromptDialogReturnedText); - break; - } - - g_main_loop_quit(m_mainLoop); - } - - void scriptConfirm(WebKitScriptDialog* dialog) - { - g_assert_cmpstr(webkit_script_dialog_get_message(dialog), ==, kConfirmDialogMessage); - m_scriptDialogConfirmed = !m_scriptDialogConfirmed; - webkit_script_dialog_confirm_set_confirmed(dialog, m_scriptDialogConfirmed); - } - - void scriptPrompt(WebKitScriptDialog* dialog) - { - g_assert_cmpstr(webkit_script_dialog_get_message(dialog), ==, kPromptDialogMessage); - g_assert_cmpstr(webkit_script_dialog_prompt_get_default_text(dialog), ==, "default"); - webkit_script_dialog_prompt_set_text(dialog, kPromptDialogReturnedText); - } - - static gboolean scriptDialog(WebKitWebView*, WebKitScriptDialog* dialog, UIClientTest* test) - { - switch (webkit_script_dialog_get_dialog_type(dialog)) { - case WEBKIT_SCRIPT_DIALOG_ALERT: - test->scriptAlert(dialog); - break; - case WEBKIT_SCRIPT_DIALOG_CONFIRM: - test->scriptConfirm(dialog); - break; - case WEBKIT_SCRIPT_DIALOG_PROMPT: - test->scriptPrompt(dialog); - break; - } - - return TRUE; - } - - static void mouseTargetChanged(WebKitWebView*, WebKitHitTestResult* hitTestResult, guint modifiers, UIClientTest* test) - { - g_assert(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult)); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(hitTestResult)); - - test->m_mouseTargetHitTestResult = hitTestResult; - test->m_mouseTargetModifiers = modifiers; - g_main_loop_quit(test->m_mainLoop); - } - - static gboolean permissionRequested(WebKitWebView*, WebKitPermissionRequest* request, UIClientTest* test) - { - g_assert(WEBKIT_IS_PERMISSION_REQUEST(request)); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request)); - - if (test->m_allowPermissionRequests) - webkit_permission_request_allow(request); - else - webkit_permission_request_deny(request); - - return TRUE; - } - - UIClientTest() - : m_scriptDialogType(WEBKIT_SCRIPT_DIALOG_ALERT) - , m_scriptDialogConfirmed(true) - , m_allowPermissionRequests(false) - , m_mouseTargetModifiers(0) - { - webkit_settings_set_javascript_can_open_windows_automatically(webkit_web_view_get_settings(m_webView), TRUE); - g_signal_connect(m_webView, "create", G_CALLBACK(viewCreateCallback), this); - g_signal_connect(m_webView, "script-dialog", G_CALLBACK(scriptDialog), this); - g_signal_connect(m_webView, "mouse-target-changed", G_CALLBACK(mouseTargetChanged), this); - g_signal_connect(m_webView, "permission-request", G_CALLBACK(permissionRequested), this); - } - - ~UIClientTest() - { - g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); - } - - void waitUntilMainLoopFinishes() - { - g_main_loop_run(m_mainLoop); - } - - void setExpectedWindowProperties(const WindowProperties& windowProperties) - { - m_windowProperties = windowProperties; - } - - WebKitHitTestResult* moveMouseAndWaitUntilMouseTargetChanged(int x, int y, unsigned int mouseModifiers = 0) - { - mouseMoveTo(x, y, mouseModifiers); - g_main_loop_run(m_mainLoop); - return m_mouseTargetHitTestResult.get(); - } - - virtual GtkWidget* viewCreate(WebKitWebView* webView) - { - g_assert(webView == m_webView); - - GtkWidget* newWebView = webkit_web_view_new_with_context(webkit_web_view_get_context(webView)); - g_object_ref_sink(newWebView); - - m_webViewEvents.append(Create); - - WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(newWebView)); - g_assert(windowProperties); - assertObjectIsDeletedWhenTestFinishes(G_OBJECT(windowProperties)); - m_windowPropertiesChanged.clear(); - - g_signal_connect(windowProperties, "notify", G_CALLBACK(windowPropertiesNotifyCallback), this); - g_signal_connect(newWebView, "ready-to-show", G_CALLBACK(viewReadyToShowCallback), this); - g_signal_connect(newWebView, "close", G_CALLBACK(viewCloseCallback), this); - - return newWebView; - } - - virtual void viewReadyToShow(WebKitWebView* webView) - { - g_assert(webView != m_webView); - - WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(webView); - g_assert(windowProperties); - if (!m_windowProperties.isNull()) - WindowProperties(windowProperties).assertEqual(m_windowProperties); - - m_webViewEvents.append(ReadyToShow); - } - - virtual void viewClose(WebKitWebView* webView) - { - g_assert(webView != m_webView); - - m_webViewEvents.append(Close); - g_object_unref(webView); - - g_main_loop_quit(m_mainLoop); - } - - Vector<WebViewEvents> m_webViewEvents; - WebKitScriptDialogType m_scriptDialogType; - bool m_scriptDialogConfirmed; - bool m_allowPermissionRequests; - WindowProperties m_windowProperties; - HashSet<WTF::String> m_windowPropertiesChanged; - GRefPtr<WebKitHitTestResult> m_mouseTargetHitTestResult; - unsigned int m_mouseTargetModifiers; -}; - -static void testWebViewCreateReadyClose(UIClientTest* test, gconstpointer) -{ - test->loadHtml("<html><body onLoad=\"window.open().close();\"></html>", 0); - test->waitUntilMainLoopFinishes(); - - Vector<UIClientTest::WebViewEvents>& events = test->m_webViewEvents; - g_assert_cmpint(events.size(), ==, 3); - g_assert_cmpint(events[0], ==, UIClientTest::Create); - g_assert_cmpint(events[1], ==, UIClientTest::ReadyToShow); - g_assert_cmpint(events[2], ==, UIClientTest::Close); -} - -static gboolean checkMimeTypeForFilter(GtkFileFilter* filter, const gchar* mimeType) -{ - GtkFileFilterInfo filterInfo; - filterInfo.contains = GTK_FILE_FILTER_MIME_TYPE; - filterInfo.mime_type = mimeType; - return gtk_file_filter_filter(filter, &filterInfo); -} - -class ModalDialogsTest: public UIClientTest { -public: - MAKE_GLIB_TEST_FIXTURE(ModalDialogsTest); - - static void dialogRunAsModalCallback(WebKitWebView* webView, ModalDialogsTest* test) - { - g_assert(webView != test->m_webView); - test->m_webViewEvents.append(RunAsModal); - } - - GtkWidget* viewCreate(WebKitWebView* webView) - { - g_assert(webView == m_webView); - - GtkWidget* newWebView = UIClientTest::viewCreate(webView); - g_signal_connect(newWebView, "run-as-modal", G_CALLBACK(dialogRunAsModalCallback), this); - return newWebView; - } - - void viewReadyToShow(WebKitWebView* webView) - { - g_assert(webView != m_webView); - m_webViewEvents.append(ReadyToShow); - } -}; - -static void testWebViewAllowModalDialogs(ModalDialogsTest* test, gconstpointer) -{ - WebKitSettings* settings = webkit_web_view_get_settings(test->m_webView); - webkit_settings_set_allow_modal_dialogs(settings, TRUE); - - test->loadHtml("<html><body onload=\"window.showModalDialog('data:text/html,<html><body/><script>window.close();</script></html>')\"></body></html>", 0); - test->waitUntilMainLoopFinishes(); - - Vector<UIClientTest::WebViewEvents>& events = test->m_webViewEvents; - g_assert_cmpint(events.size(), ==, 4); - g_assert_cmpint(events[0], ==, UIClientTest::Create); - g_assert_cmpint(events[1], ==, UIClientTest::ReadyToShow); - g_assert_cmpint(events[2], ==, UIClientTest::RunAsModal); - g_assert_cmpint(events[3], ==, UIClientTest::Close); -} - -static void testWebViewDisallowModalDialogs(ModalDialogsTest* test, gconstpointer) -{ - WebKitSettings* settings = webkit_web_view_get_settings(test->m_webView); - webkit_settings_set_allow_modal_dialogs(settings, FALSE); - - test->loadHtml("<html><body onload=\"window.showModalDialog('data:text/html,<html><body/><script>window.close();</script></html>')\"></body></html>", 0); - // We need to use a timeout here because the viewClose() function - // won't ever be called as the dialog won't be created. - test->wait(1); - - Vector<UIClientTest::WebViewEvents>& events = test->m_webViewEvents; - g_assert_cmpint(events.size(), ==, 0); -} - -static void testWebViewJavaScriptDialogs(UIClientTest* test, gconstpointer) -{ - static const char* htmlOnLoadFormat = "<html><body onLoad=\"%s\"></body></html>"; - static const char* jsAlertFormat = "alert('%s')"; - static const char* jsConfirmFormat = "do { confirmed = confirm('%s'); } while (!confirmed); alert('confirmed');"; - static const char* jsPromptFormat = "alert(prompt('%s', 'default'));"; - - test->m_scriptDialogType = WEBKIT_SCRIPT_DIALOG_ALERT; - GOwnPtr<char> alertDialogMessage(g_strdup_printf(jsAlertFormat, kAlertDialogMessage)); - GOwnPtr<char> alertHTML(g_strdup_printf(htmlOnLoadFormat, alertDialogMessage.get())); - test->loadHtml(alertHTML.get(), 0); - test->waitUntilMainLoopFinishes(); - - test->m_scriptDialogType = WEBKIT_SCRIPT_DIALOG_CONFIRM; - GOwnPtr<char> confirmDialogMessage(g_strdup_printf(jsConfirmFormat, kConfirmDialogMessage)); - GOwnPtr<char> confirmHTML(g_strdup_printf(htmlOnLoadFormat, confirmDialogMessage.get())); - test->loadHtml(confirmHTML.get(), 0); - test->waitUntilMainLoopFinishes(); - - test->m_scriptDialogType = WEBKIT_SCRIPT_DIALOG_PROMPT; - GOwnPtr<char> promptDialogMessage(g_strdup_printf(jsPromptFormat, kPromptDialogMessage)); - GOwnPtr<char> promptHTML(g_strdup_printf(htmlOnLoadFormat, promptDialogMessage.get())); - test->loadHtml(promptHTML.get(), 0); - test->waitUntilMainLoopFinishes(); -} - -static void testWebViewWindowProperties(UIClientTest* test, gconstpointer) -{ - static const char* windowProrpertiesString = "left=100,top=150,width=400,height=400,location=no,menubar=no,status=no,toolbar=no,scrollbars=no"; - GdkRectangle geometry = { 100, 150, 400, 400 }; - test->setExpectedWindowProperties(UIClientTest::WindowProperties(&geometry, false, false, false, false, false, true, false)); - - GOwnPtr<char> htmlString(g_strdup_printf("<html><body onLoad=\"window.open('', '', '%s').close();\"></body></html>", windowProrpertiesString)); - test->loadHtml(htmlString.get(), 0); - test->waitUntilMainLoopFinishes(); - - static const char* propertiesChanged[] = { - "geometry", "locationbar-visible", "menubar-visible", "statusbar-visible", "toolbar-visible", "scrollbars-visible" - }; - for (size_t i = 0; i < G_N_ELEMENTS(propertiesChanged); ++i) - g_assert(test->m_windowPropertiesChanged.contains(propertiesChanged[i])); - - Vector<UIClientTest::WebViewEvents>& events = test->m_webViewEvents; - g_assert_cmpint(events.size(), ==, 3); - g_assert_cmpint(events[0], ==, UIClientTest::Create); - g_assert_cmpint(events[1], ==, UIClientTest::ReadyToShow); - g_assert_cmpint(events[2], ==, UIClientTest::Close); -} - -static void testWebViewMouseTarget(UIClientTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(GTK_WINDOW_TOPLEVEL); - - const char* linksHoveredHTML = - "<html><body>" - " <a style='position:absolute; left:1; top:1' href='http://www.webkitgtk.org' title='WebKitGTK+ Title'>WebKitGTK+ Website</a>" - " <img style='position:absolute; left:1; top:10' src='0xdeadbeef' width=5 height=5></img>" - " <a style='position:absolute; left:1; top:20' href='http://www.webkitgtk.org/logo' title='WebKitGTK+ Logo'><img src='0xdeadbeef' width=5 height=5></img></a>" - " <input style='position:absolute; left:1; top:30' size='10'></input>" - " <div style='position:absolute; left:1; top:50; width:30; height:30; overflow:scroll'> </div>" - " <video style='position:absolute; left:1; top:100' width='300' height='300' controls='controls' preload='none'><source src='movie.ogg' type='video/ogg' /></video>" - "</body></html>"; - - test->loadHtml(linksHoveredHTML, "file:///"); - test->waitUntilLoadFinished(); - - // Move over link. - WebKitHitTestResult* hitTestResult = test->moveMouseAndWaitUntilMouseTargetChanged(1, 1); - g_assert(webkit_hit_test_result_context_is_link(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_image(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); - g_assert_cmpstr(webkit_hit_test_result_get_link_uri(hitTestResult), ==, "http://www.webkitgtk.org/"); - g_assert_cmpstr(webkit_hit_test_result_get_link_title(hitTestResult), ==, "WebKitGTK+ Title"); - g_assert_cmpstr(webkit_hit_test_result_get_link_label(hitTestResult), ==, "WebKitGTK+ Website"); - g_assert(!test->m_mouseTargetModifiers); - - // Move out of the link. - hitTestResult = test->moveMouseAndWaitUntilMouseTargetChanged(0, 0); - g_assert(!webkit_hit_test_result_context_is_link(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_image(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); - g_assert(!test->m_mouseTargetModifiers); - - // Move over image with GDK_CONTROL_MASK. - hitTestResult = test->moveMouseAndWaitUntilMouseTargetChanged(1, 10, GDK_CONTROL_MASK); - g_assert(!webkit_hit_test_result_context_is_link(hitTestResult)); - g_assert(webkit_hit_test_result_context_is_image(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult)); - g_assert_cmpstr(webkit_hit_test_result_get_image_uri(hitTestResult), ==, "file:///0xdeadbeef"); - g_assert(test->m_mouseTargetModifiers & GDK_CONTROL_MASK); - - // Move over image link. - hitTestResult = test->moveMouseAndWaitUntilMouseTargetChanged(1, 20); - g_assert(webkit_hit_test_result_context_is_link(hitTestResult)); - g_assert(webkit_hit_test_result_context_is_image(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult)); - g_assert_cmpstr(webkit_hit_test_result_get_link_uri(hitTestResult), ==, "http://www.webkitgtk.org/logo"); - g_assert_cmpstr(webkit_hit_test_result_get_image_uri(hitTestResult), ==, "file:///0xdeadbeef"); - g_assert_cmpstr(webkit_hit_test_result_get_link_title(hitTestResult), ==, "WebKitGTK+ Logo"); - g_assert(!webkit_hit_test_result_get_link_label(hitTestResult)); - g_assert(!test->m_mouseTargetModifiers); - - // Move over media. - hitTestResult = test->moveMouseAndWaitUntilMouseTargetChanged(1, 100); - g_assert(!webkit_hit_test_result_context_is_link(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_image(hitTestResult)); - g_assert(webkit_hit_test_result_context_is_media(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult)); - g_assert_cmpstr(webkit_hit_test_result_get_media_uri(hitTestResult), ==, "file:///movie.ogg"); - g_assert(!test->m_mouseTargetModifiers); - - // Mover over input. - hitTestResult = test->moveMouseAndWaitUntilMouseTargetChanged(5, 35); - g_assert(!webkit_hit_test_result_context_is_link(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_image(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult)); - g_assert(webkit_hit_test_result_context_is_editable(hitTestResult)); - g_assert(!test->m_mouseTargetModifiers); - - // Move over scrollbar. - hitTestResult = test->moveMouseAndWaitUntilMouseTargetChanged(5, 75); - g_assert(!webkit_hit_test_result_context_is_link(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_image(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_media(hitTestResult)); - g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult)); - g_assert(webkit_hit_test_result_context_is_scrollbar(hitTestResult)); - g_assert(!test->m_mouseTargetModifiers); -} - -static void testWebViewPermissionRequests(UIClientTest* test, gconstpointer) -{ - // Some versions of geoclue give a runtime warning because it tries - // to register the error quark twice. See https://bugs.webkit.org/show_bug.cgi?id=89858. - // Make warnings non-fatal for this test to make it pass. - test->removeLogFatalFlag(G_LOG_LEVEL_WARNING); - test->showInWindowAndWaitUntilMapped(); - static const char* geolocationRequestHTML = - "<html>" - " <script>" - " function runTest()" - " {" - " navigator.geolocation.getCurrentPosition(function(p) { document.title = \"OK\" }," - " function(e) { document.title = e.code });" - " }" - " </script>" - " <body onload='runTest();'></body>" - "</html>"; - - // Test denying a permission request. - test->m_allowPermissionRequests = false; - test->loadHtml(geolocationRequestHTML, 0); - test->waitUntilTitleChanged(); - - // According to the Geolocation API specification, '1' is the - // error code returned for the PERMISSION_DENIED error. - // http://dev.w3.org/geo/api/spec-source.html#position_error_interface - const gchar* result = webkit_web_view_get_title(test->m_webView); - g_assert_cmpstr(result, ==, "1"); - - // Test allowing a permission request. - test->m_allowPermissionRequests = true; - test->loadHtml(geolocationRequestHTML, 0); - test->waitUntilTitleChanged(); - - // Check that we did not get the PERMISSION_DENIED error now. - result = webkit_web_view_get_title(test->m_webView); - g_assert_cmpstr(result, !=, "1"); - test->addLogFatalFlag(G_LOG_LEVEL_WARNING); -} - -static void testWebViewZoomLevel(WebViewTest* test, gconstpointer) -{ - g_assert_cmpfloat(webkit_web_view_get_zoom_level(test->m_webView), ==, 1); - webkit_web_view_set_zoom_level(test->m_webView, 2.5); - g_assert_cmpfloat(webkit_web_view_get_zoom_level(test->m_webView), ==, 2.5); - - webkit_settings_set_zoom_text_only(webkit_web_view_get_settings(test->m_webView), TRUE); - // The zoom level shouldn't change when zoom-text-only setting changes. - g_assert_cmpfloat(webkit_web_view_get_zoom_level(test->m_webView), ==, 2.5); -} - -static void testWebViewRunJavaScript(WebViewTest* test, gconstpointer) -{ - static const char* html = "<html><body><a id='WebKitLink' href='http://www.webkitgtk.org/' title='WebKitGTK+ Title'>WebKitGTK+ Website</a></body></html>"; - test->loadHtml(html, 0); - test->waitUntilLoadFinished(); - - GOwnPtr<GError> error; - WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished("window.document.getElementById('WebKitLink').title;", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - GOwnPtr<char> valueString(WebViewTest::javascriptResultToCString(javascriptResult)); - g_assert_cmpstr(valueString.get(), ==, "WebKitGTK+ Title"); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("window.document.getElementById('WebKitLink').href;", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - valueString.set(WebViewTest::javascriptResultToCString(javascriptResult)); - g_assert_cmpstr(valueString.get(), ==, "http://www.webkitgtk.org/"); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("window.document.getElementById('WebKitLink').textContent", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - valueString.set(WebViewTest::javascriptResultToCString(javascriptResult)); - g_assert_cmpstr(valueString.get(), ==, "WebKitGTK+ Website"); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("a = 25;", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - g_assert_cmpfloat(WebViewTest::javascriptResultToNumber(javascriptResult), ==, 25); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("a = 2.5;", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - g_assert_cmpfloat(WebViewTest::javascriptResultToNumber(javascriptResult), ==, 2.5); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("a = true", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - g_assert(WebViewTest::javascriptResultToBoolean(javascriptResult)); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("a = false", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - g_assert(!WebViewTest::javascriptResultToBoolean(javascriptResult)); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("a = null", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - g_assert(WebViewTest::javascriptResultIsNull(javascriptResult)); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("function Foo() { a = 25; } Foo();", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - g_assert(WebViewTest::javascriptResultIsUndefined(javascriptResult)); - - javascriptResult = test->runJavaScriptFromGResourceAndWaitUntilFinished("/org/webkit/webkit2gtk/tests/link-title.js", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - valueString.set(WebViewTest::javascriptResultToCString(javascriptResult)); - g_assert_cmpstr(valueString.get(), ==, "WebKitGTK+ Title"); - - javascriptResult = test->runJavaScriptFromGResourceAndWaitUntilFinished("/wrong/path/to/resource.js", &error.outPtr()); - g_assert(!javascriptResult); - g_assert_error(error.get(), G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND); - error.clear(); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("foo();", &error.outPtr()); - g_assert(!javascriptResult); - g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED); -} - -class FileChooserTest: public UIClientTest { -public: - MAKE_GLIB_TEST_FIXTURE(FileChooserTest); - - FileChooserTest() - { - g_signal_connect(m_webView, "run-file-chooser", G_CALLBACK(runFileChooserCallback), this); - } - - static gboolean runFileChooserCallback(WebKitWebView*, WebKitFileChooserRequest* request, FileChooserTest* test) - { - test->runFileChooser(request); - return TRUE; - } - - void runFileChooser(WebKitFileChooserRequest* request) - { - assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request)); - m_fileChooserRequest = request; - g_main_loop_quit(m_mainLoop); - } - - WebKitFileChooserRequest* clickMouseButtonAndWaitForFileChooserRequest(int x, int y) - { - clickMouseButton(x, y); - g_main_loop_run(m_mainLoop); - return m_fileChooserRequest.get(); - } - -private: - GRefPtr<WebKitFileChooserRequest> m_fileChooserRequest; -}; - -static void testWebViewFileChooserRequest(FileChooserTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(); - static const char* fileChooserHTMLFormat = "<html><body><input style='position:absolute;left:0;top:0;margin:0;padding:0' type='file' %s/></body></html>"; - - // Multiple selections not allowed, no MIME filtering. - GOwnPtr<char> simpleFileUploadHTML(g_strdup_printf(fileChooserHTMLFormat, "")); - test->loadHtml(simpleFileUploadHTML.get(), 0); - test->waitUntilLoadFinished(); - WebKitFileChooserRequest* fileChooserRequest = test->clickMouseButtonAndWaitForFileChooserRequest(5, 5); - g_assert(!webkit_file_chooser_request_get_select_multiple(fileChooserRequest)); - - const gchar* const* mimeTypes = webkit_file_chooser_request_get_mime_types(fileChooserRequest); - g_assert(!mimeTypes); - GtkFileFilter* filter = webkit_file_chooser_request_get_mime_types_filter(fileChooserRequest); - g_assert(!filter); - const gchar* const* selectedFiles = webkit_file_chooser_request_get_selected_files(fileChooserRequest); - g_assert(!selectedFiles); - webkit_file_chooser_request_cancel(fileChooserRequest); - - // Multiple selections allowed, no MIME filtering, some pre-selected files. - GOwnPtr<char> multipleSelectionFileUploadHTML(g_strdup_printf(fileChooserHTMLFormat, "multiple")); - test->loadHtml(multipleSelectionFileUploadHTML.get(), 0); - test->waitUntilLoadFinished(); - fileChooserRequest = test->clickMouseButtonAndWaitForFileChooserRequest(5, 5); - g_assert(webkit_file_chooser_request_get_select_multiple(fileChooserRequest)); - - mimeTypes = webkit_file_chooser_request_get_mime_types(fileChooserRequest); - g_assert(!mimeTypes); - filter = webkit_file_chooser_request_get_mime_types_filter(fileChooserRequest); - g_assert(!filter); - selectedFiles = webkit_file_chooser_request_get_selected_files(fileChooserRequest); - g_assert(!selectedFiles); - - // Select some files. - const gchar* filesToSelect[4] = { "/foo", "/foo/bar", "/foo/bar/baz", 0 }; - webkit_file_chooser_request_select_files(fileChooserRequest, filesToSelect); - - // Check the files that have been just selected. - selectedFiles = webkit_file_chooser_request_get_selected_files(fileChooserRequest); - g_assert(selectedFiles); - g_assert_cmpstr(selectedFiles[0], ==, "/foo"); - g_assert_cmpstr(selectedFiles[1], ==, "/foo/bar"); - g_assert_cmpstr(selectedFiles[2], ==, "/foo/bar/baz"); - g_assert(!selectedFiles[3]); - - // Perform another request to check if the list of files selected - // in the previous step appears now as part of the new request. - fileChooserRequest = test->clickMouseButtonAndWaitForFileChooserRequest(5, 5); - selectedFiles = webkit_file_chooser_request_get_selected_files(fileChooserRequest); - g_assert(selectedFiles); - g_assert_cmpstr(selectedFiles[0], ==, "/foo"); - g_assert_cmpstr(selectedFiles[1], ==, "/foo/bar"); - g_assert_cmpstr(selectedFiles[2], ==, "/foo/bar/baz"); - g_assert(!selectedFiles[3]); - webkit_file_chooser_request_cancel(fileChooserRequest); - - // Multiple selections not allowed, only accept images, audio and video files.. - GOwnPtr<char> mimeFilteredFileUploadHTML(g_strdup_printf(fileChooserHTMLFormat, "accept='audio/*,video/*,image/*'")); - test->loadHtml(mimeFilteredFileUploadHTML.get(), 0); - test->waitUntilLoadFinished(); - fileChooserRequest = test->clickMouseButtonAndWaitForFileChooserRequest(5, 5); - g_assert(!webkit_file_chooser_request_get_select_multiple(fileChooserRequest)); - - mimeTypes = webkit_file_chooser_request_get_mime_types(fileChooserRequest); - g_assert(mimeTypes); - g_assert_cmpstr(mimeTypes[0], ==, "audio/*"); - g_assert_cmpstr(mimeTypes[1], ==, "video/*"); - g_assert_cmpstr(mimeTypes[2], ==, "image/*"); - g_assert(!mimeTypes[3]); - - filter = webkit_file_chooser_request_get_mime_types_filter(fileChooserRequest); - g_assert(GTK_IS_FILE_FILTER(filter)); - g_assert(checkMimeTypeForFilter(filter, "audio/*")); - g_assert(checkMimeTypeForFilter(filter, "video/*")); - g_assert(checkMimeTypeForFilter(filter, "image/*")); - - selectedFiles = webkit_file_chooser_request_get_selected_files(fileChooserRequest); - g_assert(!selectedFiles); - webkit_file_chooser_request_cancel(fileChooserRequest); -} - -class FullScreenClientTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(FullScreenClientTest); - - enum FullScreenEvent { - None, - Enter, - Leave - }; - - static gboolean viewEnterFullScreenCallback(WebKitWebView*, FullScreenClientTest* test) - { - test->m_event = Enter; - g_main_loop_quit(test->m_mainLoop); - return FALSE; - } - - static gboolean viewLeaveFullScreenCallback(WebKitWebView*, FullScreenClientTest* test) - { - test->m_event = Leave; - g_main_loop_quit(test->m_mainLoop); - return FALSE; - } - - FullScreenClientTest() - : m_event(None) - { - webkit_settings_set_enable_fullscreen(webkit_web_view_get_settings(m_webView), TRUE); - g_signal_connect(m_webView, "enter-fullscreen", G_CALLBACK(viewEnterFullScreenCallback), this); - g_signal_connect(m_webView, "leave-fullscreen", G_CALLBACK(viewLeaveFullScreenCallback), this); - } - - ~FullScreenClientTest() - { - g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); - } - - void requestFullScreenAndWaitUntilEnteredFullScreen() - { - m_event = None; - webkit_web_view_run_javascript(m_webView, "document.documentElement.webkitRequestFullScreen();", 0, 0, 0); - g_main_loop_run(m_mainLoop); - } - - static gboolean leaveFullScreenIdle(FullScreenClientTest* test) - { - test->keyStroke(GDK_KEY_Escape); - return FALSE; - } - - void leaveFullScreenAndWaitUntilLeftFullScreen() - { - m_event = None; - g_idle_add(reinterpret_cast<GSourceFunc>(leaveFullScreenIdle), this); - g_main_loop_run(m_mainLoop); - } - - FullScreenEvent m_event; -}; - -static void testWebViewFullScreen(FullScreenClientTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(); - test->loadHtml("<html><body>FullScreen test</body></html>", 0); - test->waitUntilLoadFinished(); - test->requestFullScreenAndWaitUntilEnteredFullScreen(); - g_assert_cmpint(test->m_event, ==, FullScreenClientTest::Enter); - test->leaveFullScreenAndWaitUntilLeftFullScreen(); - g_assert_cmpint(test->m_event, ==, FullScreenClientTest::Leave); -} - -static void testWebViewCanShowMIMEType(WebViewTest* test, gconstpointer) -{ - // Supported MIME types. - g_assert(webkit_web_view_can_show_mime_type(test->m_webView, "text/html")); - g_assert(webkit_web_view_can_show_mime_type(test->m_webView, "text/plain")); - g_assert(webkit_web_view_can_show_mime_type(test->m_webView, "image/jpeg")); - - // Unsupported MIME types. - g_assert(!webkit_web_view_can_show_mime_type(test->m_webView, "text/vcard")); - g_assert(!webkit_web_view_can_show_mime_type(test->m_webView, "application/pdf")); - g_assert(!webkit_web_view_can_show_mime_type(test->m_webView, "application/zip")); - g_assert(!webkit_web_view_can_show_mime_type(test->m_webView, "application/octet-stream")); - - // Plugins are only supported when enabled. - webkit_web_context_set_additional_plugins_directory(webkit_web_view_get_context(test->m_webView), WEBKIT_TEST_PLUGIN_DIR); - g_assert(webkit_web_view_can_show_mime_type(test->m_webView, "application/x-webkit-test-netscape")); - webkit_settings_set_enable_plugins(webkit_web_view_get_settings(test->m_webView), FALSE); - g_assert(!webkit_web_view_can_show_mime_type(test->m_webView, "application/x-webkit-test-netscape")); -} - -class FormClientTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(FormClientTest); - - static void submitFormCallback(WebKitWebView*, WebKitFormSubmissionRequest* request, FormClientTest* test) - { - test->submitForm(request); - } - - FormClientTest() - : m_submitPositionX(0) - , m_submitPositionY(0) - { - g_signal_connect(m_webView, "submit-form", G_CALLBACK(submitFormCallback), this); - } - - ~FormClientTest() - { - g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); - } - - void submitForm(WebKitFormSubmissionRequest* request) - { - assertObjectIsDeletedWhenTestFinishes(G_OBJECT(request)); - m_request = request; - webkit_form_submission_request_submit(request); - quitMainLoop(); - } - - GHashTable* waitUntilFormSubmittedAndGetTextFields() - { - g_main_loop_run(m_mainLoop); - return webkit_form_submission_request_get_text_fields(m_request.get()); - } - - static gboolean doClickIdleCallback(FormClientTest* test) - { - test->clickMouseButton(test->m_submitPositionX, test->m_submitPositionY, 1); - return FALSE; - } - - void submitFormAtPosition(int x, int y) - { - m_submitPositionX = x; - m_submitPositionY = y; - g_idle_add(reinterpret_cast<GSourceFunc>(doClickIdleCallback), this); - } - - int m_submitPositionX; - int m_submitPositionY; - GRefPtr<WebKitFormSubmissionRequest> m_request; -}; - -static void testWebViewSubmitForm(FormClientTest* test, gconstpointer) -{ - test->showInWindowAndWaitUntilMapped(); - - const char* formHTML = - "<html><body>" - " <form action='#'>" - " <input type='text' name='text1' value='value1'>" - " <input type='text' name='text2' value='value2'>" - " <input type='password' name='password' value='secret'>" - " <textarea cols='5' rows='5' name='textarea'>Text</textarea>" - " <input type='hidden' name='hidden1' value='hidden1'>" - " <input type='submit' value='Submit' style='position:absolute; left:1; top:1' size='10'>" - " </form>" - "</body></html>"; - - test->loadHtml(formHTML, "file:///"); - test->waitUntilLoadFinished(); - - test->submitFormAtPosition(5, 5); - GHashTable* values = test->waitUntilFormSubmittedAndGetTextFields(); - g_assert(values); - g_assert_cmpuint(g_hash_table_size(values), ==, 3); - g_assert_cmpstr(static_cast<char*>(g_hash_table_lookup(values, "text1")), ==, "value1"); - g_assert_cmpstr(static_cast<char*>(g_hash_table_lookup(values, "text2")), ==, "value2"); - g_assert_cmpstr(static_cast<char*>(g_hash_table_lookup(values, "password")), ==, "secret"); -} - -class SaveWebViewTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(SaveWebViewTest); - - SaveWebViewTest() - : m_tempDirectory(g_dir_make_tmp("WebKit2SaveViewTest-XXXXXX", 0)) - { - } - - ~SaveWebViewTest() - { - if (G_IS_FILE(m_file.get())) - g_file_delete(m_file.get(), 0, 0); - - if (G_IS_INPUT_STREAM(m_inputStream.get())) - g_input_stream_close(m_inputStream.get(), 0, 0); - - if (m_tempDirectory) - g_rmdir(m_tempDirectory.get()); - } - - static void webViewSavedToStreamCallback(GObject* object, GAsyncResult* result, SaveWebViewTest* test) - { - GOwnPtr<GError> error; - test->m_inputStream = adoptGRef(webkit_web_view_save_finish(test->m_webView, result, &error.outPtr())); - g_assert(G_IS_INPUT_STREAM(test->m_inputStream.get())); - g_assert(!error); - - test->quitMainLoop(); - } - - static void webViewSavedToFileCallback(GObject* object, GAsyncResult* result, SaveWebViewTest* test) - { - GOwnPtr<GError> error; - g_assert(webkit_web_view_save_to_file_finish(test->m_webView, result, &error.outPtr())); - g_assert(!error); - - test->quitMainLoop(); - } - - void saveAndWaitForStream() - { - webkit_web_view_save(m_webView, WEBKIT_SAVE_MODE_MHTML, 0, reinterpret_cast<GAsyncReadyCallback>(webViewSavedToStreamCallback), this); - g_main_loop_run(m_mainLoop); - } - - void saveAndWaitForFile() - { - m_saveDestinationFilePath.set(g_build_filename(m_tempDirectory.get(), "testWebViewSaveResult.mht", NULL)); - m_file = adoptGRef(g_file_new_for_path(m_saveDestinationFilePath.get())); - webkit_web_view_save_to_file(m_webView, m_file.get(), WEBKIT_SAVE_MODE_MHTML, 0, reinterpret_cast<GAsyncReadyCallback>(webViewSavedToFileCallback), this); - g_main_loop_run(m_mainLoop); - } - - GOwnPtr<char> m_tempDirectory; - GOwnPtr<char> m_saveDestinationFilePath; - GRefPtr<GInputStream> m_inputStream; - GRefPtr<GFile> m_file; -}; - -static void testWebViewSave(SaveWebViewTest* test, gconstpointer) -{ - test->loadHtml("<html>" - "<body>" - " <p>A paragraph with plain text</p>" - " <p>" - " A red box: <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3AYWDTMVwnSZnwAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAAFklEQVQI12P8z8DAwMDAxMDAwMDAAAANHQEDK+mmyAAAAABJRU5ErkJggg=='></br>" - " A blue box: <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3AYWDTMvBHhALQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAAFklEQVQI12Nk4PnPwMDAxMDAwMDAAAALrwEPPIs1pgAAAABJRU5ErkJggg=='>" - " </p>" - "</body>" - "</html>", 0); - test->waitUntilLoadFinished(); - - // Write to a file and to an input stream. - test->saveAndWaitForFile(); - test->saveAndWaitForStream(); - - // We should have exactly the same amount of bytes in the file - // than those coming from the GInputStream. We don't compare the - // strings read since the 'Date' field and the boundaries will be - // different on each case. MHTML functionality will be tested by - // Layout tests, so checking the amount of bytes is enough. - GOwnPtr<GError> error; - gchar buffer[512] = { 0 }; - gssize readBytes = 0; - gssize totalBytesFromStream = 0; - while (readBytes = g_input_stream_read(test->m_inputStream.get(), &buffer, 512, 0, &error.outPtr())) { - g_assert(!error); - totalBytesFromStream += readBytes; - } - - // Check that the file exists and that it contains the same amount of bytes. - GRefPtr<GFileInfo> fileInfo = adoptGRef(g_file_query_info(test->m_file.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE, static_cast<GFileQueryInfoFlags>(0), 0, 0)); - g_assert_cmpint(g_file_info_get_size(fileInfo.get()), ==, totalBytesFromStream); -} - -static void testWebViewMode(WebViewTest* test, gconstpointer) -{ - static const char* indexHTML = "<html><body><p>Test Web View Mode</p></body></html>"; - - // Web mode. - g_assert_cmpuint(webkit_web_view_get_view_mode(test->m_webView), ==, WEBKIT_VIEW_MODE_WEB); - test->loadHtml(indexHTML, 0); - test->waitUntilLoadFinished(); - WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished("window.document.body.textContent;", 0); - GOwnPtr<char> valueString(WebViewTest::javascriptResultToCString(javascriptResult)); - g_assert_cmpstr(valueString.get(), ==, "Test Web View Mode"); - - // Source mode. - webkit_web_view_set_view_mode(test->m_webView, WEBKIT_VIEW_MODE_SOURCE); - test->loadHtml(indexHTML, 0); - test->waitUntilLoadFinished(); - javascriptResult = test->runJavaScriptAndWaitUntilFinished("window.document.body.textContent;", 0); - valueString.set(WebViewTest::javascriptResultToCString(javascriptResult)); - g_assert_cmpstr(valueString.get(), ==, indexHTML); -} - -// To test page visibility API. Currently only 'visible' and 'hidden' states are implemented fully in WebCore. -// See also http://www.w3.org/TR/2011/WD-page-visibility-20110602/ and https://developers.google.com/chrome/whitepapers/pagevisibility -static void testWebViewPageVisibility(WebViewTest* test, gconstpointer) -{ - test->loadHtml("<html><title></title>" - "<body><p>Test Web Page Visibility</p>" - "<script>" - "document.addEventListener(\"webkitvisibilitychange\", onVisibilityChange, false);" - "function onVisibilityChange() {" - " document.title = document.webkitVisibilityState;" - "}" - "</script>" - "</body></html>", - 0); - - // Wait untill the page is loaded. Initial visibility should be 'hidden'. - test->waitUntilLoadFinished(); - - GOwnPtr<GError> error; - WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished("document.webkitVisibilityState;", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - GOwnPtr<char> valueString(WebViewTest::javascriptResultToCString(javascriptResult)); - g_assert_cmpstr(valueString.get(), ==, "hidden"); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("document.webkitHidden;", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - g_assert(WebViewTest::javascriptResultToBoolean(javascriptResult)); - - // Show the page. The visibility should be updated to 'visible'. - test->showInWindow(); - test->waitUntilTitleChanged(); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("document.webkitVisibilityState;", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - valueString.set(WebViewTest::javascriptResultToCString(javascriptResult)); - g_assert_cmpstr(valueString.get(), ==, "visible"); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("document.webkitHidden;", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - g_assert(!WebViewTest::javascriptResultToBoolean(javascriptResult)); - - // Hide the page. The visibility should be updated to 'hidden'. - gtk_widget_hide(GTK_WIDGET(test->m_webView)); - test->waitUntilTitleChanged(); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("document.webkitVisibilityState;", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - valueString.set(WebViewTest::javascriptResultToCString(javascriptResult)); - g_assert_cmpstr(valueString.get(), ==, "hidden"); - - javascriptResult = test->runJavaScriptAndWaitUntilFinished("document.webkitHidden;", &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - g_assert(WebViewTest::javascriptResultToBoolean(javascriptResult)); -} - -class SnapshotWebViewTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(SnapshotWebViewTest); - - static void onSnapshotCancelledReady(WebKitWebView* web_view, GAsyncResult* res, SnapshotWebViewTest* test) - { - GOwnPtr<GError> error; - test->m_surface = webkit_web_view_get_snapshot_finish(web_view, res, &error.outPtr()); - g_assert(!test->m_surface); - g_assert_error(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED); - test->quitMainLoop(); - } - - gboolean getSnapshotAndCancel() - { - if (m_surface) - cairo_surface_destroy(m_surface); - m_surface = 0; - GRefPtr<GCancellable> cancellable = adoptGRef(g_cancellable_new()); - webkit_web_view_get_snapshot(m_webView, WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE, cancellable.get(), reinterpret_cast<GAsyncReadyCallback>(onSnapshotCancelledReady), this); - g_cancellable_cancel(cancellable.get()); - g_main_loop_run(m_mainLoop); - - return true; - } - -}; - -static void testWebViewSnapshot(SnapshotWebViewTest* test, gconstpointer) -{ - test->loadHtml("<html><body><p>Whatever</p></body></html>", 0); - test->waitUntilLoadFinished(); - - // WebView not visible. - cairo_surface_t* surface1 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE); - g_assert(!surface1); - - // Show surface, resize to 50x50, try again. - test->showInWindowAndWaitUntilMapped(); - test->resizeView(50, 50); - surface1 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE); - g_assert(surface1); - - // obtained surface should be at the most 50x50. Store the size - // for comparison later. - int width = cairo_image_surface_get_width(surface1); - int height = cairo_image_surface_get_height(surface1); - g_assert_cmpint(width, <=, 50); - g_assert_cmpint(height, <=, 50); - - // Select all text in the WebView, request a snapshot ignoring selection. - test->selectAll(); - surface1 = cairo_surface_reference(test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE)); - g_assert(surface1); - g_assert_cmpint(cairo_image_surface_get_width(surface1), ==, width); - g_assert_cmpint(cairo_image_surface_get_height(surface1), ==, height); - - // Create identical surface. - cairo_surface_t* surface2 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE); - g_assert(surface2); - - // Compare these two, they should be identical. - g_assert(Test::cairoSurfacesEqual(surface1, surface2)); - - // Request a new snapshot, including the selection this time. The - // size should be the same but the result must be different to the - // one previously obtained. - surface2 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING); - g_assert(surface2); - g_assert_cmpint(cairo_image_surface_get_width(surface2), ==, width); - g_assert_cmpint(cairo_image_surface_get_height(surface2), ==, height); - g_assert(!Test::cairoSurfacesEqual(surface1, surface2)); - - // Request a snapshot of the whole document in the WebView. The - // result should be different from the size obtained previously. - surface2 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE); - g_assert(surface2); - g_assert_cmpint(cairo_image_surface_get_width(surface2), >, width); - g_assert_cmpint(cairo_image_surface_get_height(surface2), >, height); - g_assert(!Test::cairoSurfacesEqual(surface1, surface2)); - - cairo_surface_destroy(surface1); - - g_assert(test->getSnapshotAndCancel()); -} - -void beforeAll() -{ - WebViewTest::add("WebKitWebView", "default-context", testWebViewDefaultContext); - WebViewTest::add("WebKitWebView", "custom-charset", testWebViewCustomCharset); - WebViewTest::add("WebKitWebView", "settings", testWebViewSettings); - UIClientTest::add("WebKitWebView", "create-ready-close", testWebViewCreateReadyClose); - ModalDialogsTest::add("WebKitWebView", "allow-modal-dialogs", testWebViewAllowModalDialogs); - ModalDialogsTest::add("WebKitWebView", "disallow-modal-dialogs", testWebViewDisallowModalDialogs); - UIClientTest::add("WebKitWebView", "javascript-dialogs", testWebViewJavaScriptDialogs); - UIClientTest::add("WebKitWebView", "window-properties", testWebViewWindowProperties); - UIClientTest::add("WebKitWebView", "mouse-target", testWebViewMouseTarget); - UIClientTest::add("WebKitWebView", "permission-requests", testWebViewPermissionRequests); - WebViewTest::add("WebKitWebView", "zoom-level", testWebViewZoomLevel); - WebViewTest::add("WebKitWebView", "run-javascript", testWebViewRunJavaScript); - FileChooserTest::add("WebKitWebView", "file-chooser-request", testWebViewFileChooserRequest); - FullScreenClientTest::add("WebKitWebView", "fullscreen", testWebViewFullScreen); - WebViewTest::add("WebKitWebView", "can-show-mime-type", testWebViewCanShowMIMEType); - FormClientTest::add("WebKitWebView", "submit-form", testWebViewSubmitForm); - SaveWebViewTest::add("WebKitWebView", "save", testWebViewSave); - WebViewTest::add("WebKitWebView", "view-mode", testWebViewMode); - SnapshotWebViewTest::add("WebKitWebView", "snapshot", testWebViewSnapshot); - WebViewTest::add("WebKitWebView", "page-visibility", testWebViewPageVisibility); -} - -void afterAll() -{ -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebViewGroup.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebViewGroup.cpp deleted file mode 100644 index 026c5c5b9..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebViewGroup.cpp +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright (C) 2013 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2,1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include "WebKitTestServer.h" -#include "WebViewTest.h" -#include <cstdarg> -#include <gtk/gtk.h> -#include <webkit2/webkit2.h> -#include <wtf/gobject/GRefPtr.h> - -static WebKitTestServer* kServer; - -// These are all here so that they can be changed easily, if necessary. -static const char* kStyleSheetHTML = "<html><div id=\"styledElement\">Sweet stylez!</div></html>"; -static const char* kInjectedStyleSheet = "#styledElement { font-weight: bold; }"; -static const char* kStyleSheetTestScript = "getComputedStyle(document.getElementById('styledElement'))['font-weight']"; -static const char* kStyleSheetTestScriptResult = "bold"; - -static void testWebViewGroupDefault(Test* test, gconstpointer) -{ - // Default group is shared by all WebViews by default. - GRefPtr<WebKitWebView> webView1 = WEBKIT_WEB_VIEW(webkit_web_view_new()); - GRefPtr<WebKitWebView> webView2 = WEBKIT_WEB_VIEW(webkit_web_view_new()); - g_assert(webkit_web_view_get_group(webView1.get()) == webkit_web_view_get_group(webView2.get())); - - // Settings are shared by all web view in the same group. - g_assert(webkit_web_view_get_settings(webView1.get()) == webkit_web_view_get_settings(webView2.get())); - g_assert(webkit_web_view_get_settings(webView1.get()) == webkit_web_view_group_get_settings(webkit_web_view_get_group(webView2.get()))); -} - -static void testWebViewGroupNewGroup(Test* test, gconstpointer) -{ - // Passing 0 as group name generates the name automatically. - GRefPtr<WebKitWebViewGroup> viewGroup1 = adoptGRef(webkit_web_view_group_new(0)); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(viewGroup1.get())); - g_assert(webkit_web_view_group_get_name(viewGroup1.get())); - - // New group with a given name. - GRefPtr<WebKitWebViewGroup> viewGroup2 = adoptGRef(webkit_web_view_group_new("TestGroup2")); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(viewGroup2.get())); - g_assert_cmpstr(webkit_web_view_group_get_name(viewGroup2.get()), ==, "TestGroup2"); - g_assert_cmpstr(webkit_web_view_group_get_name(viewGroup2.get()), !=, webkit_web_view_group_get_name(viewGroup1.get())); - - // Every group has its own settings. - g_assert(webkit_web_view_group_get_settings(viewGroup1.get()) != webkit_web_view_group_get_settings(viewGroup2.get())); -} - -static void testWebViewNewWithGroup(Test* test, gconstpointer) -{ - GRefPtr<WebKitWebViewGroup> viewGroup1 = adoptGRef(webkit_web_view_group_new("TestGroup1")); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(viewGroup1.get())); - GRefPtr<WebKitWebView> webView1 = WEBKIT_WEB_VIEW(webkit_web_view_new_with_group(viewGroup1.get())); - g_assert(webkit_web_view_get_group(webView1.get()) == viewGroup1.get()); - - GRefPtr<WebKitWebView> webView2 = WEBKIT_WEB_VIEW(webkit_web_view_new()); - g_assert(webkit_web_view_get_group(webView2.get()) != viewGroup1.get()); - - // Settings should be different for views in different groups. - g_assert(webkit_web_view_get_settings(webView1.get()) != webkit_web_view_get_settings(webView2.get())); -} - -static void testWebViewGroupSettings(Test* test, gconstpointer) -{ - GRefPtr<WebKitWebViewGroup> viewGroup1 = adoptGRef(webkit_web_view_group_new("TestGroup1")); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(viewGroup1.get())); - GRefPtr<WebKitSettings> newSettings = adoptGRef(webkit_settings_new_with_settings("enable-javascript", FALSE, NULL)); - test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(newSettings.get())); - webkit_web_view_group_set_settings(viewGroup1.get(), newSettings.get()); - g_assert(webkit_web_view_group_get_settings(viewGroup1.get()) == newSettings.get()); - - GRefPtr<WebKitWebView> webView1 = WEBKIT_WEB_VIEW(webkit_web_view_new_with_group(viewGroup1.get())); - GRefPtr<WebKitWebView> webView2 = WEBKIT_WEB_VIEW(webkit_web_view_new()); - WebKitSettings* webView1Settings = webkit_web_view_get_settings(webView1.get()); - WebKitSettings* webView2Settings = webkit_web_view_get_settings(webView2.get()); - g_assert(webView1Settings != webView2Settings); - g_assert(webkit_settings_get_enable_javascript(webView1Settings) != webkit_settings_get_enable_javascript(webView2Settings)); - - webkit_web_view_set_settings(webView1.get(), webView2Settings); - g_assert(webkit_web_view_get_settings(webView1.get()) == webView2Settings); - g_assert(webkit_web_view_group_get_settings(webkit_web_view_get_group(webView1.get())) == webView2Settings); -} - -static bool isStyleSheetInjectedForURLAtPath(WebViewTest* test, const char* path) -{ - test->loadURI(kServer->getURIForPath(path).data()); - test->waitUntilLoadFinished(); - - GOwnPtr<GError> error; - WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished(kStyleSheetTestScript, &error.outPtr()); - g_assert(javascriptResult); - g_assert(!error.get()); - - GOwnPtr<char> resultString(WebViewTest::javascriptResultToCString(javascriptResult)); - return !g_strcmp0(resultString.get(), kStyleSheetTestScriptResult); -} - -static void fillURLListFromPaths(char** list, const char* path, ...) -{ - va_list argumentList; - va_start(argumentList, path); - - int i = 0; - while (path) { - // FIXME: We must use a wildcard for the host here until http://wkbug.com/112476 is fixed. - // Until that time patterns with port numbers in them will not properly match URLs with port numbers. - list[i++] = g_strdup_printf("http://*/%s*", path); - path = va_arg(argumentList, const char*); - } -} - -static void removeOldInjectedStyleSheetsAndResetLists(WebKitWebViewGroup* group, char** whitelist, char** blacklist) -{ - webkit_web_view_group_remove_all_user_style_sheets(group); - - while (*whitelist) { - g_free(*whitelist); - *whitelist = 0; - whitelist++; - } - - while (*blacklist) { - g_free(*blacklist); - *blacklist = 0; - blacklist++; - } -} - -static void testWebViewGroupInjectedStyleSheet(WebViewTest* test, gconstpointer) -{ - WebKitWebViewGroup* group = webkit_web_view_get_group(test->m_webView); - char* whitelist[3] = { 0, 0, 0 }; - char* blacklist[3] = { 0, 0, 0 }; - - removeOldInjectedStyleSheetsAndResetLists(group, whitelist, blacklist); - - // Without a whitelist or a blacklist all URLs should have the injected style sheet. - static const char* randomPath = "somerandompath"; - g_assert(!isStyleSheetInjectedForURLAtPath(test, randomPath)); - webkit_web_view_group_add_user_style_sheet(group, kInjectedStyleSheet, 0, 0, 0, WEBKIT_INJECTED_CONTENT_FRAMES_ALL); - g_assert(isStyleSheetInjectedForURLAtPath(test, randomPath)); - - removeOldInjectedStyleSheetsAndResetLists(group, whitelist, blacklist); - - fillURLListFromPaths(blacklist, randomPath, 0); - webkit_web_view_group_add_user_style_sheet(group, kInjectedStyleSheet, 0, 0, blacklist, WEBKIT_INJECTED_CONTENT_FRAMES_ALL); - g_assert(!isStyleSheetInjectedForURLAtPath(test, randomPath)); - g_assert(isStyleSheetInjectedForURLAtPath(test, "someotherrandompath")); - - removeOldInjectedStyleSheetsAndResetLists(group, whitelist, blacklist); - - static const char* inTheWhiteList = "inthewhitelist"; - static const char* notInWhitelist = "notinthewhitelist"; - static const char* inTheWhiteListAndBlackList = "inthewhitelistandblacklist"; - - fillURLListFromPaths(whitelist, inTheWhiteList, inTheWhiteListAndBlackList, 0); - fillURLListFromPaths(blacklist, inTheWhiteListAndBlackList, 0); - webkit_web_view_group_add_user_style_sheet(group, kInjectedStyleSheet, 0, whitelist, blacklist, WEBKIT_INJECTED_CONTENT_FRAMES_ALL); - g_assert(isStyleSheetInjectedForURLAtPath(test, inTheWhiteList)); - g_assert(!isStyleSheetInjectedForURLAtPath(test, inTheWhiteListAndBlackList)); - g_assert(!isStyleSheetInjectedForURLAtPath(test, notInWhitelist)); - - // It's important to clean up the environment before other tests. - removeOldInjectedStyleSheetsAndResetLists(group, whitelist, blacklist); -} - -static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) -{ - soup_message_set_status(message, SOUP_STATUS_OK); - soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kStyleSheetHTML, strlen(kStyleSheetHTML)); - soup_message_body_complete(message->response_body); -} - -void beforeAll() -{ - kServer = new WebKitTestServer(); - kServer->run(serverCallback); - - Test::add("WebKitWebViewGroup", "default-group", testWebViewGroupDefault); - Test::add("WebKitWebViewGroup", "new-group", testWebViewGroupNewGroup); - Test::add("WebKitWebView", "new-with-group", testWebViewNewWithGroup); - Test::add("WebKitWebViewGroup", "settings", testWebViewGroupSettings); - WebViewTest::add("WebKitWebViewGroup", "injected-style-sheet", testWebViewGroupInjectedStyleSheet); -} - -void afterAll() -{ - delete kServer; -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebViewEditor.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebViewEditor.cpp deleted file mode 100644 index 93315db68..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebViewEditor.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2,1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "WebViewTest.h" -#include <wtf/gobject/GRefPtr.h> - -class EditorTest: public WebViewTest { -public: - MAKE_GLIB_TEST_FIXTURE(EditorTest); - - static const unsigned int kClipboardWaitTimeout = 50; - static const unsigned int kClipboardWaitMaxTries = 2; - - EditorTest() - : m_clipboard(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD)) - , m_canExecuteEditingCommand(false) - , m_triesCount(0) - { - gtk_clipboard_clear(m_clipboard); - } - - static void canExecuteEditingCommandReadyCallback(GObject*, GAsyncResult* result, EditorTest* test) - { - GOwnPtr<GError> error; - test->m_canExecuteEditingCommand = webkit_web_view_can_execute_editing_command_finish(test->m_webView, result, &error.outPtr()); - g_assert(!error.get()); - g_main_loop_quit(test->m_mainLoop); - } - - bool canExecuteEditingCommand(const char* command) - { - m_canExecuteEditingCommand = false; - webkit_web_view_can_execute_editing_command(m_webView, command, 0, reinterpret_cast<GAsyncReadyCallback>(canExecuteEditingCommandReadyCallback), this); - g_main_loop_run(m_mainLoop); - return m_canExecuteEditingCommand; - } - - static gboolean waitForClipboardText(EditorTest* test) - { - test->m_triesCount++; - if (gtk_clipboard_wait_is_text_available(test->m_clipboard) || test->m_triesCount > kClipboardWaitMaxTries) { - g_main_loop_quit(test->m_mainLoop); - return FALSE; - } - - return TRUE; - } - - void copyClipboard() - { - webkit_web_view_execute_editing_command(m_webView, WEBKIT_EDITING_COMMAND_COPY); - // There's no way to know when the selection has been copied to - // the clipboard, so use a timeout source to query the clipboard. - m_triesCount = 0; - g_timeout_add(kClipboardWaitTimeout, reinterpret_cast<GSourceFunc>(waitForClipboardText), this); - g_main_loop_run(m_mainLoop); - } - - GtkClipboard* m_clipboard; - bool m_canExecuteEditingCommand; - size_t m_triesCount; -}; - -static void testWebViewEditorCutCopyPasteNonEditable(EditorTest* test, gconstpointer) -{ - static const char* selectedSpanHTML = "<html><body contentEditable=\"false\">" - "<span id=\"mainspan\">All work and no play <span id=\"subspan\">make Jack a dull</span> boy.</span>" - "<script>document.getSelection().collapse();\n" - "document.getSelection().selectAllChildren(document.getElementById('subspan'));\n" - "</script></body></html>"; - - // Nothing loaded yet. - g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT)); - g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_COPY)); - g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE)); - - test->loadHtml(selectedSpanHTML, 0); - test->waitUntilLoadFinished(); - - g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_COPY)); - // It's not possible to cut and paste when content is not editable - // even if there's a selection. - g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT)); - g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE)); - - test->copyClipboard(); - GOwnPtr<char> clipboardText(gtk_clipboard_wait_for_text(test->m_clipboard)); - g_assert_cmpstr(clipboardText.get(), ==, "make Jack a dull"); -} - -static void testWebViewEditorCutCopyPasteEditable(EditorTest* test, gconstpointer) -{ - static const char* selectedSpanHTML = "<html><body contentEditable=\"true\">" - "<span id=\"mainspan\">All work and no play <span>make Jack a dull</span> boy.</span>" - "<script>document.getSelection().collapse();\n" - "document.getSelection().selectAllChildren(document.getElementById('mainspan'));\n" - "</script></body></html>"; - - // Nothing loaded yet. - g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT)); - g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_COPY)); - g_assert(!test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE)); - - test->loadHtml(selectedSpanHTML, 0); - test->waitUntilLoadFinished(); - - // There's a selection. - g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_CUT)); - g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_COPY)); - g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_PASTE)); - - test->copyClipboard(); - GOwnPtr<char> clipboardText(gtk_clipboard_wait_for_text(test->m_clipboard)); - g_assert_cmpstr(clipboardText.get(), ==, "All work and no play make Jack a dull boy."); -} - -static void testWebViewEditorSelectAllNonEditable(EditorTest* test, gconstpointer) -{ - static const char* selectedSpanHTML = "<html><body contentEditable=\"false\">" - "<span id=\"mainspan\">All work and no play <span id=\"subspan\">make Jack a dull</span> boy.</span>" - "<script>document.getSelection().collapse();\n" - "document.getSelection().selectAllChildren(document.getElementById('subspan'));\n" - "</script></body></html>"; - - g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_SELECT_ALL)); - - test->loadHtml(selectedSpanHTML, 0); - test->waitUntilLoadFinished(); - - g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_SELECT_ALL)); - - test->copyClipboard(); - GOwnPtr<char> clipboardText(gtk_clipboard_wait_for_text(test->m_clipboard)); - - // Initially only the subspan is selected. - g_assert_cmpstr(clipboardText.get(), ==, "make Jack a dull"); - - webkit_web_view_execute_editing_command(test->m_webView, WEBKIT_EDITING_COMMAND_SELECT_ALL); - test->copyClipboard(); - clipboardText.set(gtk_clipboard_wait_for_text(test->m_clipboard)); - - // The mainspan should be selected after calling SELECT_ALL. - g_assert_cmpstr(clipboardText.get(), ==, "All work and no play make Jack a dull boy."); -} - -static void testWebViewEditorSelectAllEditable(EditorTest* test, gconstpointer) -{ - static const char* selectedSpanHTML = "<html><body contentEditable=\"true\">" - "<span id=\"mainspan\">All work and no play <span id=\"subspan\">make Jack a dull</span> boy.</span>" - "<script>document.getSelection().collapse();\n" - "document.getSelection().selectAllChildren(document.getElementById('subspan'));\n" - "</script></body></html>"; - - g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_SELECT_ALL)); - - test->loadHtml(selectedSpanHTML, 0); - test->waitUntilLoadFinished(); - - g_assert(test->canExecuteEditingCommand(WEBKIT_EDITING_COMMAND_SELECT_ALL)); - - test->copyClipboard(); - GOwnPtr<char> clipboardText(gtk_clipboard_wait_for_text(test->m_clipboard)); - - // Initially only the subspan is selected. - g_assert_cmpstr(clipboardText.get(), ==, "make Jack a dull"); - - webkit_web_view_execute_editing_command(test->m_webView, WEBKIT_EDITING_COMMAND_SELECT_ALL); - test->copyClipboard(); - clipboardText.set(gtk_clipboard_wait_for_text(test->m_clipboard)); - - // The mainspan should be selected after calling SELECT_ALL. - g_assert_cmpstr(clipboardText.get(), ==, "All work and no play make Jack a dull boy."); -} - -void beforeAll() -{ - EditorTest::add("WebKitWebView", "cut-copy-paste/non-editable", testWebViewEditorCutCopyPasteNonEditable); - EditorTest::add("WebKitWebView", "cut-copy-paste/editable", testWebViewEditorCutCopyPasteEditable); - EditorTest::add("WebKitWebView", "select-all/non-editable", testWebViewEditorSelectAllNonEditable); - EditorTest::add("WebKitWebView", "select-all/editable", testWebViewEditorSelectAllEditable); -} - -void afterAll() -{ -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp deleted file mode 100644 index 692663e33..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#include <gio/gio.h> -#include <stdlib.h> -#include <string.h> - -#include <webkit2/webkit-web-extension.h> -#include <wtf/gobject/GOwnPtr.h> - -static const char introspectionXML[] = - "<node>" - " <interface name='org.webkit.gtk.WebExtensionTest'>" - " <method name='GetTitle'>" - " <arg type='t' name='pageID' direction='in'/>" - " <arg type='s' name='title' direction='out'/>" - " </method>" - " <method name='AbortProcess'>" - " </method>" - " <signal name='DocumentLoaded'/>" - " <signal name='URIChanged'>" - " <arg type='s' name='uri' direction='out'/>" - " </signal>" - " </interface>" - "</node>"; - -static void documentLoadedCallback(WebKitWebPage*, gpointer userData) -{ - bool ok = g_dbus_connection_emit_signal(G_DBUS_CONNECTION(userData), - 0, - "/org/webkit/gtk/WebExtensionTest", - "org.webkit.gtk.WebExtensionTest", - "DocumentLoaded", - 0, - 0); - g_assert(ok); -} - -static void uriChangedCallback(WebKitWebPage* webPage, GParamSpec* pspec, gpointer userData) -{ - bool ok = g_dbus_connection_emit_signal( - G_DBUS_CONNECTION(userData), - 0, - "/org/webkit/gtk/WebExtensionTest", - "org.webkit.gtk.WebExtensionTest", - "URIChanged", - g_variant_new("(s)", webkit_web_page_get_uri(webPage)), - 0); - g_assert(ok); -} - -static gboolean sendRequestCallback(WebKitWebPage*, WebKitURIRequest* request, WebKitURIResponse*, gpointer) -{ - const char* requestURI = webkit_uri_request_get_uri(request); - g_assert(requestURI); - - if (const char* suffix = g_strrstr(requestURI, "/remove-this/javascript.js")) { - GOwnPtr<char> prefix(g_strndup(requestURI, strlen(requestURI) - strlen(suffix))); - GOwnPtr<char> newURI(g_strdup_printf("%s/javascript.js", prefix.get())); - webkit_uri_request_set_uri(request, newURI.get()); - } else if (g_str_has_suffix(requestURI, "/add-do-not-track-header")) { - SoupMessageHeaders* headers = webkit_uri_request_get_http_headers(request); - g_assert(headers); - soup_message_headers_append(headers, "DNT", "1"); - } else if (g_str_has_suffix(requestURI, "/cancel-this.js")) - return TRUE; - - return FALSE; -} - -static void pageCreatedCallback(WebKitWebExtension*, WebKitWebPage* webPage, gpointer userData) -{ - g_signal_connect(webPage, "document-loaded", G_CALLBACK(documentLoadedCallback), userData); - g_signal_connect(webPage, "notify::uri", G_CALLBACK(uriChangedCallback), userData); - g_signal_connect(webPage, "send-request", G_CALLBACK(sendRequestCallback), 0); -} - -static void methodCallCallback(GDBusConnection* connection, const char* sender, const char* objectPath, const char* interfaceName, const char* methodName, GVariant* parameters, GDBusMethodInvocation* invocation, gpointer userData) -{ - if (g_strcmp0(interfaceName, "org.webkit.gtk.WebExtensionTest")) - return; - - if (!g_strcmp0(methodName, "GetTitle")) { - uint64_t pageID; - g_variant_get(parameters, "(t)", &pageID); - - WebKitWebExtension* extension = WEBKIT_WEB_EXTENSION(userData); - WebKitWebPage* page = webkit_web_extension_get_page(extension, pageID); - if (!page) { - g_dbus_method_invocation_return_error( - invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, - "Invalid page ID: %" G_GUINT64_FORMAT, pageID); - return; - } - g_assert_cmpuint(webkit_web_page_get_id(page), ==, pageID); - - WebKitDOMDocument* document = webkit_web_page_get_dom_document(page); - GOwnPtr<char> title(webkit_dom_document_get_title(document)); - g_dbus_method_invocation_return_value(invocation, g_variant_new("(s)", title.get())); - } else if (!g_strcmp0(methodName, "AbortProcess")) { - abort(); - } -} - -static const GDBusInterfaceVTable interfaceVirtualTable = { - methodCallCallback, 0, 0, { 0, } -}; - -static void busAcquiredCallback(GDBusConnection* connection, const char* name, gpointer userData) -{ - static GDBusNodeInfo *introspectionData = 0; - if (!introspectionData) - introspectionData = g_dbus_node_info_new_for_xml(introspectionXML, 0); - - GOwnPtr<GError> error; - unsigned registrationID = g_dbus_connection_register_object( - connection, - "/org/webkit/gtk/WebExtensionTest", - introspectionData->interfaces[0], - &interfaceVirtualTable, - g_object_ref(userData), - static_cast<GDestroyNotify>(g_object_unref), - &error.outPtr()); - if (!registrationID) - g_warning("Failed to register object: %s\n", error->message); - - g_signal_connect(WEBKIT_WEB_EXTENSION(userData), "page-created", G_CALLBACK(pageCreatedCallback), connection); -} - -extern "C" void webkit_web_extension_initialize(WebKitWebExtension* extension) -{ - g_bus_own_name( - G_BUS_TYPE_SESSION, - "org.webkit.gtk.WebExtensionTest", - G_BUS_NAME_OWNER_FLAGS_NONE, - busAcquiredCallback, - 0, 0, - g_object_ref(extension), - static_cast<GDestroyNotify>(g_object_unref)); -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.cpp deleted file mode 100644 index 8c2d3f638..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "WebKitTestBus.h" - -#include <wtf/gobject/GOwnPtr.h> -#include <wtf/text/WTFString.h> - -WebKitTestBus::WebKitTestBus() - : m_pid(-1) -{ -} - -bool WebKitTestBus::run() -{ - // FIXME: Use GTestDBus when we bump glib to 2.34. - GOwnPtr<char> dbusLaunch(g_find_program_in_path("dbus-launch")); - if (!dbusLaunch) { - g_warning("Error starting DBUS daemon: dbus-launch not found in path"); - return false; - } - - GOwnPtr<char> output; - GOwnPtr<GError> error; - if (!g_spawn_command_line_sync(dbusLaunch.get(), &output.outPtr(), 0, 0, &error.outPtr())) { - g_warning("Error starting DBUS daemon: %s", error->message); - return false; - } - - String outputString = String::fromUTF8(output.get()); - Vector<String> lines; - outputString.split(UChar('\n'), /* allowEmptyEntries */ false, lines); - for (size_t i = 0; i < lines.size(); ++i) { - char** keyValue = g_strsplit(lines[i].utf8().data(), "=", 2); - g_assert_cmpuint(g_strv_length(keyValue), ==, 2); - if (!g_strcmp0(keyValue[0], "DBUS_SESSION_BUS_ADDRESS")) { - m_address = keyValue[1]; - g_setenv("DBUS_SESSION_BUS_ADDRESS", keyValue[1], TRUE); - } else if (!g_strcmp0(keyValue[0], "DBUS_SESSION_BUS_PID")) - m_pid = g_ascii_strtoll(keyValue[1], 0, 10); - g_strfreev(keyValue); - } - - return m_pid > 0; -} - -WebKitTestBus::~WebKitTestBus() -{ - g_unsetenv("DBUS_SESSION_BUS_ADDRESS"); - - if (m_pid != -1) - kill(m_pid, SIGTERM); -} - -GDBusConnection* WebKitTestBus::getOrCreateConnection() -{ - if (m_connection) - return m_connection.get(); - - g_assert(!m_address.isNull()); - m_connection = adoptGRef(g_dbus_connection_new_for_address_sync(m_address.data(), - static_cast<GDBusConnectionFlags>(G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION), - 0, 0, 0)); - return m_connection.get(); -} - -static void onNameAppeared(GDBusConnection*, const char*, const char*, gpointer userData) -{ - g_main_loop_quit(static_cast<GMainLoop*>(userData)); -} - -GDBusProxy* WebKitTestBus::createProxy(const char* serviceName, const char* objectPath, const char* interfaceName, GMainLoop* mainLoop) -{ - unsigned watcherID = g_bus_watch_name_on_connection(getOrCreateConnection(), serviceName, G_BUS_NAME_WATCHER_FLAGS_NONE, onNameAppeared, 0, mainLoop, 0); - g_main_loop_run(mainLoop); - g_bus_unwatch_name(watcherID); - - GDBusProxy* proxy = g_dbus_proxy_new_sync( - connection(), - G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, - 0, // GDBusInterfaceInfo - serviceName, - objectPath, - interfaceName, - 0, // GCancellable - 0); - g_assert(proxy); - return proxy; -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.h b/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.h deleted file mode 100644 index b9f856b27..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2012 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef WebKitTestBus_h -#define WebKitTestBus_h - -#include <gio/gio.h> -#include <wtf/gobject/GRefPtr.h> -#include <wtf/text/CString.h> - -class WebKitTestBus { -public: - WebKitTestBus(); - virtual ~WebKitTestBus(); - - bool run(); - GDBusProxy* createProxy(const char* serviceName, const char* objectPath, const char* interfaceName, GMainLoop*); - GDBusConnection* connection() const { return m_connection.get(); } - -private: - GDBusConnection* getOrCreateConnection(); - - pid_t m_pid; - CString m_address; - GRefPtr<GDBusConnection> m_connection; -}; - -#endif // WebKitTestBus_h diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.cpp deleted file mode 100644 index 98b4a9a2b..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2011 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "WebKitTestServer.h" - -#include "TestMain.h" -#include <wtf/gobject/GOwnPtr.h> - -WebKitTestServer::WebKitTestServer(ServerType type) -{ - GOwnPtr<char> sslCertificateFile; - GOwnPtr<char> sslKeyFile; - if (type == ServerHTTPS) { - CString resourcesDir = Test::getResourcesDir(); - sslCertificateFile.set(g_build_filename(resourcesDir.data(), "test-cert.pem", NULL)); - sslKeyFile.set(g_build_filename(resourcesDir.data(), "test-key.pem", NULL)); - } - - GRefPtr<SoupAddress> address = adoptGRef(soup_address_new("127.0.0.1", SOUP_ADDRESS_ANY_PORT)); - soup_address_resolve_sync(address.get(), 0); - - m_soupServer = adoptGRef(soup_server_new(SOUP_SERVER_INTERFACE, address.get(), - SOUP_SERVER_SSL_CERT_FILE, sslCertificateFile.get(), - SOUP_SERVER_SSL_KEY_FILE, sslKeyFile.get(), NULL)); - m_baseURI = type == ServerHTTPS ? soup_uri_new("https://127.0.0.1/") : soup_uri_new("http://127.0.0.1/"); - soup_uri_set_port(m_baseURI, soup_server_get_port(m_soupServer.get())); -} - -WebKitTestServer::~WebKitTestServer() -{ - soup_uri_free(m_baseURI); -} - -void WebKitTestServer::run(SoupServerCallback serverCallback) -{ - soup_server_run_async(m_soupServer.get()); - soup_server_add_handler(m_soupServer.get(), 0, serverCallback, 0, 0); -} - -CString WebKitTestServer::getURIForPath(const char* path) -{ - SoupURI* uri = soup_uri_new_with_base(m_baseURI, path); - GOwnPtr<gchar> uriString(soup_uri_to_string(uri, FALSE)); - soup_uri_free(uri); - return uriString.get(); -} - diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.h b/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.h deleted file mode 100644 index d4626f6b1..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2011 Igalia S.L. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef WebKitTestServer_h -#define WebKitTestServer_h - -#include <libsoup/soup.h> -#include <webkit2/webkit2.h> -#include <wtf/gobject/GRefPtr.h> -#include <wtf/text/CString.h> - -class WebKitTestServer { -public: - - enum ServerType { - ServerHTTP, - ServerHTTPS - }; - - WebKitTestServer(ServerType type = ServerHTTP); - virtual ~WebKitTestServer(); - - SoupURI* baseURI() { return m_baseURI; } - - CString getURIForPath(const char* path); - void run(SoupServerCallback); - -private: - GRefPtr<SoupServer> m_soupServer; - SoupURI* m_baseURI; -}; - -#endif // WebKitTestServer_h diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp deleted file mode 100644 index e6c843456..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp +++ /dev/null @@ -1,444 +0,0 @@ -/* - * Copyright (C) 2011 Igalia S.L. - * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" -#include "WebViewTest.h" - -#include <JavaScriptCore/JSRetainPtr.h> -#include <WebCore/GOwnPtrGtk.h> - -WebViewTest::WebViewTest() - : m_webView(WEBKIT_WEB_VIEW(g_object_ref_sink(webkit_web_view_new()))) - , m_mainLoop(g_main_loop_new(0, TRUE)) - , m_parentWindow(0) - , m_javascriptResult(0) - , m_resourceDataSize(0) - , m_surface(0) -{ - assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_webView)); -} - -WebViewTest::~WebViewTest() -{ - if (m_parentWindow) - gtk_widget_destroy(m_parentWindow); - if (m_javascriptResult) - webkit_javascript_result_unref(m_javascriptResult); - if (m_surface) - cairo_surface_destroy(m_surface); - g_object_unref(m_webView); - g_main_loop_unref(m_mainLoop); -} - -void WebViewTest::loadURI(const char* uri) -{ - m_activeURI = uri; - webkit_web_view_load_uri(m_webView, uri); -} - -void WebViewTest::loadHtml(const char* html, const char* baseURI) -{ - if (!baseURI) - m_activeURI = "about:blank"; - else - m_activeURI = baseURI; - webkit_web_view_load_html(m_webView, html, baseURI); -} - -void WebViewTest::loadPlainText(const char* plainText) -{ - m_activeURI = "about:blank"; - webkit_web_view_load_plain_text(m_webView, plainText); -} - -void WebViewTest::loadRequest(WebKitURIRequest* request) -{ - m_activeURI = webkit_uri_request_get_uri(request); - webkit_web_view_load_request(m_webView, request); -} - -void WebViewTest::loadAlternateHTML(const char* html, const char* contentURI, const char* baseURI) -{ - m_activeURI = contentURI; - webkit_web_view_load_alternate_html(m_webView, html, contentURI, baseURI); -} - -void WebViewTest::goBack() -{ - if (webkit_web_view_can_go_back(m_webView)) { - WebKitBackForwardList* list = webkit_web_view_get_back_forward_list(m_webView); - WebKitBackForwardListItem* item = webkit_back_forward_list_get_nth_item(list, -1); - m_activeURI = webkit_back_forward_list_item_get_original_uri(item); - } - - // Call go_back even when can_go_back returns FALSE to check nothing happens. - webkit_web_view_go_back(m_webView); -} - -void WebViewTest::goForward() -{ - if (webkit_web_view_can_go_forward(m_webView)) { - WebKitBackForwardList* list = webkit_web_view_get_back_forward_list(m_webView); - WebKitBackForwardListItem* item = webkit_back_forward_list_get_nth_item(list, 1); - m_activeURI = webkit_back_forward_list_item_get_original_uri(item); - } - - // Call go_forward even when can_go_forward returns FALSE to check nothing happens. - webkit_web_view_go_forward(m_webView); -} - -void WebViewTest::goToBackForwardListItem(WebKitBackForwardListItem* item) -{ - m_activeURI = webkit_back_forward_list_item_get_original_uri(item); - webkit_web_view_go_to_back_forward_list_item(m_webView, item); -} - -void WebViewTest::quitMainLoop() -{ - g_main_loop_quit(m_mainLoop); -} - -void WebViewTest::quitMainLoopAfterProcessingPendingEvents() -{ - while (gtk_events_pending()) - gtk_main_iteration(); - quitMainLoop(); -} - -static gboolean quitMainLoopIdleCallback(WebViewTest* test) -{ - test->quitMainLoop(); - return FALSE; -} - -void WebViewTest::wait(double seconds) -{ - g_timeout_add_seconds(seconds, reinterpret_cast<GSourceFunc>(quitMainLoopIdleCallback), this); - g_main_loop_run(m_mainLoop); -} - -static void loadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent, WebViewTest* test) -{ - if (loadEvent != WEBKIT_LOAD_FINISHED) - return; - g_signal_handlers_disconnect_by_func(webView, reinterpret_cast<void*>(loadChanged), test); - g_main_loop_quit(test->m_mainLoop); -} - -void WebViewTest::waitUntilLoadFinished() -{ - g_signal_connect(m_webView, "load-changed", G_CALLBACK(loadChanged), this); - g_main_loop_run(m_mainLoop); -} - -static void titleChanged(WebKitWebView* webView, GParamSpec*, WebViewTest* test) -{ - if (!test->m_expectedTitle.isNull() && test->m_expectedTitle != webkit_web_view_get_title(webView)) - return; - - g_signal_handlers_disconnect_by_func(webView, reinterpret_cast<void*>(titleChanged), test); - g_main_loop_quit(test->m_mainLoop); -} - -void WebViewTest::waitUntilTitleChangedTo(const char* expectedTitle) -{ - m_expectedTitle = expectedTitle; - g_signal_connect(m_webView, "notify::title", G_CALLBACK(titleChanged), this); - g_main_loop_run(m_mainLoop); - m_expectedTitle = CString(); -} - -void WebViewTest::waitUntilTitleChanged() -{ - waitUntilTitleChangedTo(0); -} - -static gboolean parentWindowMapped(GtkWidget* widget, GdkEvent*, WebViewTest* test) -{ - g_signal_handlers_disconnect_by_func(widget, reinterpret_cast<void*>(parentWindowMapped), test); - g_main_loop_quit(test->m_mainLoop); - - return FALSE; -} - -void WebViewTest::showInWindow(GtkWindowType windowType) -{ - g_assert(!m_parentWindow); - m_parentWindow = gtk_window_new(windowType); - gtk_container_add(GTK_CONTAINER(m_parentWindow), GTK_WIDGET(m_webView)); - gtk_widget_show(GTK_WIDGET(m_webView)); - gtk_widget_show(m_parentWindow); -} - -void WebViewTest::showInWindowAndWaitUntilMapped(GtkWindowType windowType) -{ - g_assert(!m_parentWindow); - m_parentWindow = gtk_window_new(windowType); - gtk_container_add(GTK_CONTAINER(m_parentWindow), GTK_WIDGET(m_webView)); - gtk_widget_show(GTK_WIDGET(m_webView)); - - g_signal_connect(m_parentWindow, "map-event", G_CALLBACK(parentWindowMapped), this); - gtk_widget_show(m_parentWindow); - g_main_loop_run(m_mainLoop); -} - -void WebViewTest::resizeView(int width, int height) -{ - GtkAllocation allocation; - gtk_widget_get_allocation(GTK_WIDGET(m_webView), &allocation); - if (width != -1) - allocation.width = width; - if (height != -1) - allocation.height = height; - gtk_widget_size_allocate(GTK_WIDGET(m_webView), &allocation); -} - -void WebViewTest::selectAll() -{ - webkit_web_view_execute_editing_command(m_webView, "SelectAll"); -} - -static void resourceGetDataCallback(GObject* object, GAsyncResult* result, gpointer userData) -{ - size_t dataSize; - GOwnPtr<GError> error; - unsigned char* data = webkit_web_resource_get_data_finish(WEBKIT_WEB_RESOURCE(object), result, &dataSize, &error.outPtr()); - g_assert(data); - - WebViewTest* test = static_cast<WebViewTest*>(userData); - test->m_resourceData.set(reinterpret_cast<char*>(data)); - test->m_resourceDataSize = dataSize; - g_main_loop_quit(test->m_mainLoop); -} - -const char* WebViewTest::mainResourceData(size_t& mainResourceDataSize) -{ - m_resourceDataSize = 0; - m_resourceData.clear(); - WebKitWebResource* resource = webkit_web_view_get_main_resource(m_webView); - g_assert(resource); - - webkit_web_resource_get_data(resource, 0, resourceGetDataCallback, this); - g_main_loop_run(m_mainLoop); - - mainResourceDataSize = m_resourceDataSize; - return m_resourceData.get(); -} - -void WebViewTest::mouseMoveTo(int x, int y, unsigned int mouseModifiers) -{ - g_assert(m_parentWindow); - GtkWidget* viewWidget = GTK_WIDGET(m_webView); - g_assert(gtk_widget_get_realized(viewWidget)); - - GOwnPtr<GdkEvent> event(gdk_event_new(GDK_MOTION_NOTIFY)); - event->motion.x = x; - event->motion.y = y; - - event->motion.time = GDK_CURRENT_TIME; - event->motion.window = gtk_widget_get_window(viewWidget); - g_object_ref(event->motion.window); - event->motion.device = gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gtk_widget_get_display(viewWidget))); - event->motion.state = mouseModifiers; - event->motion.axes = 0; - - int xRoot, yRoot; - gdk_window_get_root_coords(gtk_widget_get_window(viewWidget), x, y, &xRoot, &yRoot); - event->motion.x_root = xRoot; - event->motion.y_root = yRoot; - gtk_main_do_event(event.get()); -} - -void WebViewTest::clickMouseButton(int x, int y, unsigned int button, unsigned int mouseModifiers) -{ - doMouseButtonEvent(GDK_BUTTON_PRESS, x, y, button, mouseModifiers); - doMouseButtonEvent(GDK_BUTTON_RELEASE, x, y, button, mouseModifiers); -} - -void WebViewTest::keyStroke(unsigned int keyVal, unsigned int keyModifiers) -{ - g_assert(m_parentWindow); - GtkWidget* viewWidget = GTK_WIDGET(m_webView); - g_assert(gtk_widget_get_realized(viewWidget)); - - GOwnPtr<GdkEvent> event(gdk_event_new(GDK_KEY_PRESS)); - event->key.keyval = keyVal; - - event->key.time = GDK_CURRENT_TIME; - event->key.window = gtk_widget_get_window(viewWidget); - g_object_ref(event->key.window); - gdk_event_set_device(event.get(), gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gtk_widget_get_display(viewWidget)))); - event->key.state = keyModifiers; - - // When synthesizing an event, an invalid hardware_keycode value can cause it to be badly processed by GTK+. - GOwnPtr<GdkKeymapKey> keys; - int keysCount; - if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), keyVal, &keys.outPtr(), &keysCount)) - event->key.hardware_keycode = keys.get()[0].keycode; - - gtk_main_do_event(event.get()); - event->key.type = GDK_KEY_RELEASE; - gtk_main_do_event(event.get()); -} - -void WebViewTest::doMouseButtonEvent(GdkEventType eventType, int x, int y, unsigned int button, unsigned int mouseModifiers) -{ - g_assert(m_parentWindow); - GtkWidget* viewWidget = GTK_WIDGET(m_webView); - g_assert(gtk_widget_get_realized(viewWidget)); - - GOwnPtr<GdkEvent> event(gdk_event_new(eventType)); - event->button.window = gtk_widget_get_window(viewWidget); - g_object_ref(event->button.window); - - event->button.time = GDK_CURRENT_TIME; - event->button.x = x; - event->button.y = y; - event->button.axes = 0; - event->button.state = mouseModifiers; - event->button.button = button; - - event->button.device = gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gtk_widget_get_display(viewWidget))); - - int xRoot, yRoot; - gdk_window_get_root_coords(gtk_widget_get_window(viewWidget), x, y, &xRoot, &yRoot); - event->button.x_root = xRoot; - event->button.y_root = yRoot; - gtk_main_do_event(event.get()); -} - -static void runJavaScriptReadyCallback(GObject*, GAsyncResult* result, WebViewTest* test) -{ - test->m_javascriptResult = webkit_web_view_run_javascript_finish(test->m_webView, result, test->m_javascriptError); - g_main_loop_quit(test->m_mainLoop); -} - -static void runJavaScriptFromGResourceReadyCallback(GObject*, GAsyncResult* result, WebViewTest* test) -{ - test->m_javascriptResult = webkit_web_view_run_javascript_from_gresource_finish(test->m_webView, result, test->m_javascriptError); - g_main_loop_quit(test->m_mainLoop); -} - -WebKitJavascriptResult* WebViewTest::runJavaScriptAndWaitUntilFinished(const char* javascript, GError** error) -{ - if (m_javascriptResult) - webkit_javascript_result_unref(m_javascriptResult); - m_javascriptResult = 0; - m_javascriptError = error; - webkit_web_view_run_javascript(m_webView, javascript, 0, reinterpret_cast<GAsyncReadyCallback>(runJavaScriptReadyCallback), this); - g_main_loop_run(m_mainLoop); - - return m_javascriptResult; -} - -WebKitJavascriptResult* WebViewTest::runJavaScriptFromGResourceAndWaitUntilFinished(const char* resource, GError** error) -{ - if (m_javascriptResult) - webkit_javascript_result_unref(m_javascriptResult); - m_javascriptResult = 0; - m_javascriptError = error; - webkit_web_view_run_javascript_from_gresource(m_webView, resource, 0, reinterpret_cast<GAsyncReadyCallback>(runJavaScriptFromGResourceReadyCallback), this); - g_main_loop_run(m_mainLoop); - - return m_javascriptResult; -} - -static char* jsValueToCString(JSGlobalContextRef context, JSValueRef value) -{ - g_assert(value); - g_assert(JSValueIsString(context, value)); - - JSRetainPtr<JSStringRef> stringValue(Adopt, JSValueToStringCopy(context, value, 0)); - g_assert(stringValue); - - size_t cStringLength = JSStringGetMaximumUTF8CStringSize(stringValue.get()); - char* cString = static_cast<char*>(g_malloc(cStringLength)); - JSStringGetUTF8CString(stringValue.get(), cString, cStringLength); - return cString; -} - -char* WebViewTest::javascriptResultToCString(WebKitJavascriptResult* javascriptResult) -{ - JSGlobalContextRef context = webkit_javascript_result_get_global_context(javascriptResult); - g_assert(context); - return jsValueToCString(context, webkit_javascript_result_get_value(javascriptResult)); -} - -double WebViewTest::javascriptResultToNumber(WebKitJavascriptResult* javascriptResult) -{ - JSGlobalContextRef context = webkit_javascript_result_get_global_context(javascriptResult); - g_assert(context); - JSValueRef value = webkit_javascript_result_get_value(javascriptResult); - g_assert(value); - g_assert(JSValueIsNumber(context, value)); - - return JSValueToNumber(context, value, 0); -} - -bool WebViewTest::javascriptResultToBoolean(WebKitJavascriptResult* javascriptResult) -{ - JSGlobalContextRef context = webkit_javascript_result_get_global_context(javascriptResult); - g_assert(context); - JSValueRef value = webkit_javascript_result_get_value(javascriptResult); - g_assert(value); - g_assert(JSValueIsBoolean(context, value)); - - return JSValueToBoolean(context, value); -} - -bool WebViewTest::javascriptResultIsNull(WebKitJavascriptResult* javascriptResult) -{ - JSGlobalContextRef context = webkit_javascript_result_get_global_context(javascriptResult); - g_assert(context); - JSValueRef value = webkit_javascript_result_get_value(javascriptResult); - g_assert(value); - - return JSValueIsNull(context, value); -} - -bool WebViewTest::javascriptResultIsUndefined(WebKitJavascriptResult* javascriptResult) -{ - JSGlobalContextRef context = webkit_javascript_result_get_global_context(javascriptResult); - g_assert(context); - JSValueRef value = webkit_javascript_result_get_value(javascriptResult); - g_assert(value); - - return JSValueIsUndefined(context, value); -} - -static void onSnapshotReady(WebKitWebView* web_view, GAsyncResult* res, WebViewTest* test) -{ - GOwnPtr<GError> error; - test->m_surface = webkit_web_view_get_snapshot_finish(web_view, res, &error.outPtr()); - g_assert(!test->m_surface || !error.get()); - if (error) - g_assert_error(error.get(), WEBKIT_SNAPSHOT_ERROR, WEBKIT_SNAPSHOT_ERROR_FAILED_TO_CREATE); - test->quitMainLoop(); -} - -cairo_surface_t* WebViewTest::getSnapshotAndWaitUntilReady(WebKitSnapshotRegion region, WebKitSnapshotOptions options) -{ - if (m_surface) - cairo_surface_destroy(m_surface); - m_surface = 0; - webkit_web_view_get_snapshot(m_webView, region, options, 0, reinterpret_cast<GAsyncReadyCallback>(onSnapshotReady), this); - g_main_loop_run(m_mainLoop); - return m_surface; -} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h deleted file mode 100644 index a460e22b4..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2011 Igalia S.L. - * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public License - * along with this library; see the file COPYING.LIB. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef WebViewTest_h -#define WebViewTest_h - -#include "TestMain.h" -#include <webkit2/webkit2.h> -#include <wtf/text/CString.h> - -class WebViewTest: public Test { -public: - MAKE_GLIB_TEST_FIXTURE(WebViewTest); - WebViewTest(); - virtual ~WebViewTest(); - - virtual void loadURI(const char* uri); - virtual void loadHtml(const char* html, const char* baseURI); - virtual void loadPlainText(const char* plainText); - virtual void loadRequest(WebKitURIRequest*); - void loadAlternateHTML(const char* html, const char* contentURI, const char* baseURI); - void goBack(); - void goForward(); - void goToBackForwardListItem(WebKitBackForwardListItem*); - - void quitMainLoop(); - void quitMainLoopAfterProcessingPendingEvents(); - void wait(double seconds); - void waitUntilLoadFinished(); - void waitUntilTitleChangedTo(const char* expectedTitle); - void waitUntilTitleChanged(); - void showInWindow(GtkWindowType = GTK_WINDOW_POPUP); - void showInWindowAndWaitUntilMapped(GtkWindowType = GTK_WINDOW_POPUP); - void resizeView(int width, int height); - void selectAll(); - const char* mainResourceData(size_t& mainResourceDataSize); - - void mouseMoveTo(int x, int y, unsigned int mouseModifiers = 0); - void clickMouseButton(int x, int y, unsigned int button = 1, unsigned int mouseModifiers = 0); - void keyStroke(unsigned int keyVal, unsigned int keyModifiers = 0); - - WebKitJavascriptResult* runJavaScriptAndWaitUntilFinished(const char* javascript, GError**); - WebKitJavascriptResult* runJavaScriptFromGResourceAndWaitUntilFinished(const char* resource, GError**); - - // Javascript result helpers. - static char* javascriptResultToCString(WebKitJavascriptResult*); - static double javascriptResultToNumber(WebKitJavascriptResult*); - static bool javascriptResultToBoolean(WebKitJavascriptResult*); - static bool javascriptResultIsNull(WebKitJavascriptResult*); - static bool javascriptResultIsUndefined(WebKitJavascriptResult*); - - cairo_surface_t* getSnapshotAndWaitUntilReady(WebKitSnapshotRegion, WebKitSnapshotOptions); - - WebKitWebView* m_webView; - GMainLoop* m_mainLoop; - CString m_activeURI; - GtkWidget* m_parentWindow; - CString m_expectedTitle; - WebKitJavascriptResult* m_javascriptResult; - GError** m_javascriptError; - GOwnPtr<char> m_resourceData; - size_t m_resourceDataSize; - cairo_surface_t* m_surface; - -private: - void doMouseButtonEvent(GdkEventType, int, int, unsigned int, unsigned int); -}; - -#endif // WebViewTest_h diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js b/Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js deleted file mode 100644 index 2c824da38..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js +++ /dev/null @@ -1 +0,0 @@ -window.document.getElementById('WebKitLink').title; diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/resources/test-cert.pem b/Source/WebKit2/UIProcess/API/gtk/tests/resources/test-cert.pem deleted file mode 100644 index b34301f25..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/resources/test-cert.pem +++ /dev/null @@ -1,13 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIB9jCCAV+gAwIBAgIJALeuXBo+vwz9MA0GCSqGSIb3DQEBBQUAMBQxEjAQBgNV -BAMMCTEyNy4wLjAuMTAeFw0xMjA3MTIxMjQ4MjRaFw0yMjA3MTAxMjQ4MjRaMBQx -EjAQBgNVBAMMCTEyNy4wLjAuMTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA -0TUzOQxHBIKDD2mkuq+tU92mQvDZg73B0G+Nhr2T2G6MbcLqIwjg1QYtBZWJ83tZ -xMMEfiweHLF85Z9ohavAgxJlKG7YmvZO79KkFpmjV2W5CVRm0eYMPnzmxNCoaYqo -DLl0zsH6KZOLPKu/fX4eDX9XpAP1f83hWB1UFBmHKN8CAwEAAaNQME4wHQYDVR0O -BBYEFDHv5ZQ1BdmhzTsDUEoY55EXyUdKMB8GA1UdIwQYMBaAFDHv5ZQ1BdmhzTsD -UEoY55EXyUdKMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAh3qMBx7v -jSodMf3OyTqTLE7deLnmnCeBVpgzxRZEoizcGqYcjiqO27i5N5Z6KVQsnITnLiyC -mUtuR5KnF69uTKUw4m/ugZe5whjig5Mq2l410KVK6EeG4tdLlfXR+wi4U5K4KjP6 -p4nchQUXLa2zcbJn+VBexJn6/9wdhr+DUGY= ------END CERTIFICATE----- diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/resources/test-key.pem b/Source/WebKit2/UIProcess/API/gtk/tests/resources/test-key.pem deleted file mode 100644 index 9036222ce..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/resources/test-key.pem +++ /dev/null @@ -1,16 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBANE1MzkMRwSCgw9p -pLqvrVPdpkLw2YO9wdBvjYa9k9hujG3C6iMI4NUGLQWVifN7WcTDBH4sHhyxfOWf -aIWrwIMSZShu2Jr2Tu/SpBaZo1dluQlUZtHmDD585sTQqGmKqAy5dM7B+imTizyr -v31+Hg1/V6QD9X/N4VgdVBQZhyjfAgMBAAECgYB2QwOUsRsIMprRwJ9tJNfvO7G7 -z5i1/zOrlxPC4jHMPBnIBlICwgcOhLI4oOLdr5H8R12n0VqoT7DRwP396iwlJipF -iO1heDMn/8z8LPGwkCK/+ck04rMDksxWIdMwYKBXt9ahnJ/xRLzQ1/3AJiAGnoe5 -/QLXQweofd4mmfsjKQJBAO2CwT7uMP6nMjXgtVMJq5QP8UbeCS1sEOPJJbHuDxJB -/HePQHBjq4kzG6CL4oO7T+5fDv4g+fIIHzuXerZ0imsCQQDhfmiTIc9OucEIfg6/ -ms0JiKSmWc+qoiOCtrILuQvFoNwJRciQANqeJs6wpaDvevSUvBLGfG/7b3HvaE5X -iqBdAkBEQIvp2qcHtuJN60oQF7pPrRknxUyb2e8sljQX4pJAK+gyL19ULMAxiBdL -Vod8VYqNtJFpY+6Pp9fZ1xjzb6ALAkEA4JzrDAw0lQXA+3WduUw4ixOadr2ldyG0 -36KebcDwsfZO18m0Q4UmPz0Gy7zgN0wxzuochaw0W6+iPUiYKOlEXQJBAMWQrPlu -rrinoZS2f8doJ9BNNUa+RNpMug6UXc55qoUJlyiXEh+tu4AaMOtxuGIyC0sAcuw6 -XdAPVPXKd7Mne70= ------END PRIVATE KEY----- diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml b/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml deleted file mode 100644 index 4f1e5a654..000000000 --- a/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<gresources> - <gresource prefix="/org/webkit/webkit2gtk/tests/"> - <file alias="link-title.js">Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js</file> - </gresource> -</gresources> |