diff options
Diffstat (limited to 'Tools/TestWebKitAPI/gtk')
-rw-r--r-- | Tools/TestWebKitAPI/gtk/PlatformUtilitiesGtk.cpp | 6 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/PlatformWebViewGtk.cpp | 40 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp | 83 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.h | 6 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/WebKit2Gtk/TestMain.cpp | 23 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/WebKit2Gtk/TestMain.h | 80 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.cpp | 59 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.h | 6 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.cpp | 26 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.h | 13 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp | 100 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h | 31 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/main.cpp | 2 |
13 files changed, 338 insertions, 137 deletions
diff --git a/Tools/TestWebKitAPI/gtk/PlatformUtilitiesGtk.cpp b/Tools/TestWebKitAPI/gtk/PlatformUtilitiesGtk.cpp index ee65dcab2..f7b231fcc 100644 --- a/Tools/TestWebKitAPI/gtk/PlatformUtilitiesGtk.cpp +++ b/Tools/TestWebKitAPI/gtk/PlatformUtilitiesGtk.cpp @@ -27,8 +27,8 @@ #include "PlatformUtilities.h" #include <gtk/gtk.h> -#include <wtf/gobject/GRefPtr.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GRefPtr.h> +#include <wtf/glib/GUniquePtr.h> namespace TestWebKitAPI { namespace Util { @@ -68,7 +68,7 @@ static char* getFilenameFromEnvironmentVariableAsUTF8(const char* variableName) WKStringRef createInjectedBundlePath() { GUniquePtr<char> injectedBundlePath(getFilenameFromEnvironmentVariableAsUTF8("TEST_WEBKIT_API_WEBKIT2_INJECTED_BUNDLE_PATH")); - GUniquePtr<char> injectedBundleFilename(g_build_filename(injectedBundlePath.get(), "libTestWebKitAPIInjectedBundle.la", nullptr)); + GUniquePtr<char> injectedBundleFilename(g_build_filename(injectedBundlePath.get(), "libTestWebKitAPIInjectedBundle.so", nullptr)); return WKStringCreateWithUTF8CString(injectedBundleFilename.get()); } diff --git a/Tools/TestWebKitAPI/gtk/PlatformWebViewGtk.cpp b/Tools/TestWebKitAPI/gtk/PlatformWebViewGtk.cpp index 03160419e..0feb2b54a 100644 --- a/Tools/TestWebKitAPI/gtk/PlatformWebViewGtk.cpp +++ b/Tools/TestWebKitAPI/gtk/PlatformWebViewGtk.cpp @@ -27,18 +27,35 @@ #include "PlatformWebView.h" #include <WebCore/GUniquePtrGtk.h> +#include <WebKit/WKRetainPtr.h> +#include <WebKit/WKView.h> #include <gtk/gtk.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GUniquePtr.h> namespace TestWebKitAPI { PlatformWebView::PlatformWebView(WKContextRef contextRef, WKPageGroupRef pageGroupRef) { - m_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - m_view = WKViewCreate(contextRef, pageGroupRef); - gtk_container_add(GTK_CONTAINER(m_window), GTK_WIDGET(m_view)); - gtk_widget_show(GTK_WIDGET(m_view)); - gtk_widget_show(m_window); + WKRetainPtr<WKPageConfigurationRef> configuration = adoptWK(WKPageConfigurationCreate()); + WKPageConfigurationSetContext(configuration.get(), contextRef); + WKPageConfigurationSetPageGroup(configuration.get(), pageGroupRef); + + initialize(configuration.get()); +} + +PlatformWebView::PlatformWebView(WKPageConfigurationRef configuration) +{ + initialize(configuration); +} + +PlatformWebView::PlatformWebView(WKPageRef relatedPage) +{ + WKRetainPtr<WKPageConfigurationRef> configuration = adoptWK(WKPageConfigurationCreate()); + WKPageConfigurationSetContext(configuration.get(), WKPageGetContext(relatedPage)); + WKPageConfigurationSetPageGroup(configuration.get(), WKPageGetPageGroup(relatedPage)); + WKPageConfigurationSetRelatedPage(configuration.get(), relatedPage); + + initialize(configuration.get()); } PlatformWebView::~PlatformWebView() @@ -46,6 +63,15 @@ PlatformWebView::~PlatformWebView() gtk_widget_destroy(m_window); } +void PlatformWebView::initialize(WKPageConfigurationRef configuration) +{ + m_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + m_view = WKViewCreate(configuration); + gtk_container_add(GTK_CONTAINER(m_window), GTK_WIDGET(m_view)); + gtk_widget_show(GTK_WIDGET(m_view)); + gtk_widget_show(m_window); +} + WKPageRef PlatformWebView::page() const { return WKViewGetPage(m_view); @@ -122,7 +148,7 @@ void PlatformWebView::simulateRightClick(unsigned x, unsigned y) doMouseButtonEvent(viewWidget, GDK_BUTTON_RELEASE, x, y, 3); } -void PlatformWebView::simulateMouseMove(unsigned x, unsigned y) +void PlatformWebView::simulateMouseMove(unsigned x, unsigned y, WKEventModifiers) { GUniquePtr<GdkEvent> event(gdk_event_new(GDK_MOTION_NOTIFY)); event->motion.x = x; diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp index 211fa8b82..4a260b812 100644 --- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp +++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp @@ -39,7 +39,7 @@ static void loadChangedCallback(WebKitWebView* webView, WebKitLoadEvent loadEven 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)); + test->m_activeURI = 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); @@ -50,9 +50,15 @@ static void loadChangedCallback(WebKitWebView* webView, WebKitLoadEvent loadEven break; } case WEBKIT_LOAD_FINISHED: - g_assert(!webkit_web_view_is_loading(webView)); - if (!test->m_loadFailed) + if (!test->m_loadFailed) { + g_assert(!webkit_web_view_is_loading(webView)); g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(webView)); + } else if (!g_error_matches(test->m_error.get(), WEBKIT_NETWORK_ERROR, WEBKIT_NETWORK_ERROR_CANCELLED)) { + // When a new load is started before the previous one has finished, we receive the load-finished signal + // of the ongoing load while we already have a provisional URL for the new load. This is the only case + // where isloading is true when the load has finished. + g_assert(!webkit_web_view_is_loading(webView)); + } test->loadFinished(); break; default: @@ -63,19 +69,24 @@ static void loadChangedCallback(WebKitWebView* webView, WebKitLoadEvent loadEven static void loadFailedCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, const char* failingURI, GError* error, LoadTrackingTest* test) { test->m_loadFailed = true; + + g_assert(error); test->m_error.reset(g_error_copy(error)); + if (!g_error_matches(error, WEBKIT_NETWORK_ERROR, WEBKIT_NETWORK_ERROR_CANCELLED)) { + // When a new load is started before the previous one has finished, we receive the load-failed signal + // of the ongoing load while we already have a provisional URL for the new load. This is the only case + // where is-loading is true when the load has failed. + g_assert(!webkit_web_view_is_loading(webView)); + } + 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); + g_assert_cmpstr(test->m_activeURI.data(), ==, failingURI); 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: @@ -83,6 +94,16 @@ static void loadFailedCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent } } +static gboolean loadFailedWithTLSErrorsCallback(WebKitWebView* webView, const char* failingURI, GTlsCertificate* certificate, GTlsCertificateFlags tlsErrors, LoadTrackingTest* test) +{ + test->m_loadFailed = true; + g_assert(!webkit_web_view_is_loading(webView)); + g_assert_cmpstr(test->m_activeURI.data(), ==, failingURI); + g_assert(G_IS_TLS_CERTIFICATE(certificate)); + g_assert(tlsErrors); + return test->loadFailedWithTLSErrors(failingURI, certificate, tlsErrors); +} + static void estimatedProgressChangedCallback(GObject*, GParamSpec*, LoadTrackingTest* test) { test->estimatedProgressChanged(); @@ -94,6 +115,7 @@ LoadTrackingTest::LoadTrackingTest() { 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, "load-failed-with-tls-errors", G_CALLBACK(loadFailedWithTLSErrorsCallback), this); g_signal_connect(m_webView, "notify::estimated-load-progress", G_CALLBACK(estimatedProgressChangedCallback), this); g_assert(!webkit_web_view_get_uri(m_webView)); @@ -143,6 +165,12 @@ void LoadTrackingTest::loadFailed(const gchar* failingURI, GError* error) m_loadEvents.append(LoadFailed); } +bool LoadTrackingTest::loadFailedWithTLSErrors(const gchar* /*failingURI*/, GTlsCertificate*, GTlsCertificateFlags) +{ + m_loadEvents.append(LoadFailedWithTLSErrors); + return false; +} + void LoadTrackingTest::estimatedProgressChanged() { double progress = webkit_web_view_get_estimated_load_progress(m_webView); @@ -152,56 +180,57 @@ void LoadTrackingTest::estimatedProgressChanged() void LoadTrackingTest::loadURI(const char* uri) { - m_loadEvents.clear(); - m_estimatedProgress = 0; - m_error.reset(); + reset(); WebViewTest::loadURI(uri); } void LoadTrackingTest::loadHtml(const char* html, const char* baseURI) { - m_loadEvents.clear(); - m_estimatedProgress = 0; - m_error.reset(); + reset(); WebViewTest::loadHtml(html, baseURI); } void LoadTrackingTest::loadPlainText(const char* plainText) { - m_loadEvents.clear(); - m_estimatedProgress = 0; - m_error.reset(); + reset(); WebViewTest::loadPlainText(plainText); } +void LoadTrackingTest::loadBytes(GBytes* bytes, const char* mimeType, const char* encoding, const char* baseURI) +{ + reset(); + WebViewTest::loadBytes(bytes, mimeType, encoding, baseURI); +} + void LoadTrackingTest::loadRequest(WebKitURIRequest* request) { - m_loadEvents.clear(); - m_estimatedProgress = 0; - m_error.reset(); + reset(); WebViewTest::loadRequest(request); } void LoadTrackingTest::reload() { - m_loadEvents.clear(); - m_estimatedProgress = 0; - m_error.reset(); + reset(); webkit_web_view_reload(m_webView); } void LoadTrackingTest::goBack() { - m_loadEvents.clear(); - m_estimatedProgress = 0; - m_error.reset(); + reset(); WebViewTest::goBack(); } void LoadTrackingTest::goForward() { + reset(); + WebViewTest::goForward(); +} + +void LoadTrackingTest::reset() +{ + m_runLoadUntilCompletion = false; + m_loadFailed = false; m_loadEvents.clear(); m_estimatedProgress = 0; m_error.reset(); - WebViewTest::goForward(); } diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.h b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.h index d0ed1e57f..d6f3129b0 100644 --- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.h +++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.h @@ -34,6 +34,7 @@ public: virtual void provisionalLoadStarted(); virtual void provisionalLoadReceivedServerRedirect(); virtual void provisionalLoadFailed(const gchar* failingURI, GError*); + virtual bool loadFailedWithTLSErrors(const gchar* failingURI, GTlsCertificate*, GTlsCertificateFlags); virtual void loadCommitted(); virtual void loadFinished(); virtual void loadFailed(const char* failingURI, GError*); @@ -43,9 +44,11 @@ public: void loadHtml(const char* html, const char* baseURI); void loadPlainText(const char* plainText); void loadRequest(WebKitURIRequest*); + void loadBytes(GBytes*, const char* mimeType, const char* encoding, const char* baseURI); void reload(); void goBack(); void goForward(); + void reset(); void setRedirectURI(const char* uri) { m_redirectURI = uri; } @@ -55,7 +58,8 @@ public: ProvisionalLoadFailed, LoadCommitted, LoadFinished, - LoadFailed + LoadFailed, + LoadFailedWithTLSErrors }; bool m_runLoadUntilCompletion; bool m_loadFailed; diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/TestMain.cpp b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/TestMain.cpp index 61331a3d3..80809400d 100644 --- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/TestMain.cpp +++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/TestMain.cpp @@ -22,12 +22,19 @@ #include <glib/gstdio.h> #include <gtk/gtk.h> -#include <webkit2/webkit2.h> -#include <wtf/gobject/GUniquePtr.h> + +uint32_t Test::s_webExtensionID = 0; void beforeAll(); void afterAll(); +static GUniquePtr<char> testDataDirectory(g_dir_make_tmp("WebKit2GtkTests-XXXXXX", nullptr)); + +const char* Test::dataDirectory() +{ + return testDataDirectory.get(); +} + static void registerGResource(void) { GUniquePtr<char> resourcesPath(g_build_filename(WEBKIT_EXEC_PATH, "TestWebKitAPI", "WebKit2Gtk", "resources", "webkit2gtk-tests-resources.gresource", nullptr)); @@ -45,7 +52,10 @@ static void removeNonEmptyDirectory(const char* directoryPath) const char* fileName; while ((fileName = g_dir_read_name(directory))) { GUniquePtr<char> filePath(g_build_filename(directoryPath, fileName, nullptr)); - g_unlink(filePath.get()); + if (g_file_test(filePath.get(), G_FILE_TEST_IS_DIR)) + removeNonEmptyDirectory(filePath.get()); + else + g_unlink(filePath.get()); } g_dir_close(directory); g_rmdir(directoryPath); @@ -66,15 +76,12 @@ int main(int argc, char** argv) registerGResource(); - GUniquePtr<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()); + removeNonEmptyDirectory(testDataDirectory.get()); return returnValue; } + diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/TestMain.h b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/TestMain.h index 9fab0b2ff..f68af2a96 100644 --- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/TestMain.h +++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/TestMain.h @@ -22,8 +22,10 @@ #include <cairo.h> #include <glib-object.h> +#include <webkit2/webkit2.h> #include <wtf/HashSet.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GRefPtr.h> +#include <wtf/glib/GUniquePtr.h> #include <wtf/text/CString.h> #define MAKE_GLIB_TEST_FIXTURE(ClassName) \ @@ -41,6 +43,25 @@ g_test_add(testPath.get(), ClassName, 0, ClassName::setUp, testFunc, ClassName::tearDown); \ } +#define MAKE_GLIB_TEST_FIXTURE_WITH_SETUP_TEARDOWN(ClassName, setup, teardown) \ + static void setUp(ClassName* fixture, gconstpointer data) \ + { \ + if (setup) \ + setup(); \ + new (fixture) ClassName; \ + } \ + static void tearDown(ClassName* fixture, gconstpointer data) \ + { \ + fixture->~ClassName(); \ + if (teardown) \ + teardown(); \ + } \ + static void add(const char* suiteName, const char* testName, void (*testFunc)(ClassName*, const void*)) \ + { \ + GUniquePtr<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); \ @@ -56,8 +77,33 @@ class Test { public: MAKE_GLIB_TEST_FIXTURE(Test); + static const char* dataDirectory(); + + static void initializeWebExtensionsCallback(WebKitWebContext* context, Test* test) + { + test->initializeWebExtensions(); + } + + Test() + { + GUniquePtr<char> localStorageDirectory(g_build_filename(dataDirectory(), "local-storage", nullptr)); + GUniquePtr<char> indexedDBDirectory(g_build_filename(dataDirectory(), "indexeddb", nullptr)); + GUniquePtr<char> diskCacheDirectory(g_build_filename(dataDirectory(), "disk-cache", nullptr)); + GUniquePtr<char> applicationCacheDirectory(g_build_filename(dataDirectory(), "appcache", nullptr)); + GUniquePtr<char> webSQLDirectory(g_build_filename(dataDirectory(), "websql", nullptr)); + GRefPtr<WebKitWebsiteDataManager> websiteDataManager = adoptGRef(webkit_website_data_manager_new( + "local-storage-directory", localStorageDirectory.get(), "indexeddb-directory", indexedDBDirectory.get(), + "disk-cache-directory", diskCacheDirectory.get(), "offline-application-cache-directory", applicationCacheDirectory.get(), + "websql-directory", webSQLDirectory.get(), nullptr)); + + m_webContext = adoptGRef(webkit_web_context_new_with_website_data_manager(websiteDataManager.get())); + g_signal_connect(m_webContext.get(), "initialize-web-extensions", G_CALLBACK(initializeWebExtensionsCallback), this); + } + ~Test() { + g_signal_handlers_disconnect_matched(m_webContext.get(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, this); + m_webContext = nullptr; if (m_watchedObjects.isEmpty()) return; @@ -70,6 +116,12 @@ public: g_assert(m_watchedObjects.isEmpty()); } + virtual void initializeWebExtensions() + { + webkit_web_context_set_web_extensions_directory(m_webContext.get(), WEBKIT_TEST_WEB_EXTENSIONS_DIR); + webkit_web_context_set_web_extensions_initialization_user_data(m_webContext.get(), g_variant_new_uint32(++s_webExtensionID)); + } + static void objectFinalized(Test* test, GObject* finalizedObject) { test->m_watchedObjects.remove(finalizedObject); @@ -81,16 +133,24 @@ public: g_object_weak_ref(object, reinterpret_cast<GWeakNotify>(objectFinalized), this); } - static CString getWebKit1TestResoucesDir() - { - GUniquePtr<char> resourcesDir(g_build_filename(WEBKIT_SRC_DIR, "Tools", "TestWebKitAPI", "Tests", "WebKitGtk", "resources", nullptr)); - return resourcesDir.get(); - } - static CString getResourcesDir() + enum ResourcesDir { + WebKit2GTKResources, + WebKit2Resources, + }; + + static CString getResourcesDir(ResourcesDir resourcesDir = WebKit2GTKResources) { - GUniquePtr<char> resourcesDir(g_build_filename(WEBKIT_SRC_DIR, "Tools", "TestWebKitAPI", "Tests", "WebKit2Gtk", "resources", nullptr)); - return resourcesDir.get(); + switch (resourcesDir) { + case WebKit2GTKResources: { + GUniquePtr<char> resourcesDir(g_build_filename(WEBKIT_SRC_DIR, "Tools", "TestWebKitAPI", "Tests", "WebKit2Gtk", "resources", nullptr)); + return resourcesDir.get(); + } + case WebKit2Resources: { + GUniquePtr<char> resourcesDir(g_build_filename(WEBKIT_SRC_DIR, "Tools", "TestWebKitAPI", "Tests", "WebKit2", nullptr)); + return resourcesDir.get(); + } + } } void addLogFatalFlag(unsigned flag) @@ -119,6 +179,8 @@ public: } HashSet<GObject*> m_watchedObjects; + GRefPtr<WebKitWebContext> m_webContext; + static uint32_t s_webExtensionID; }; #endif // TestMain_h diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.cpp b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.cpp index 35bcf1bd6..88456ce4f 100644 --- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.cpp +++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.cpp @@ -20,53 +20,23 @@ #include "config.h" #include "WebKitTestBus.h" -#include <wtf/gobject/GUniquePtr.h> -#include <wtf/text/WTFString.h> - WebKitTestBus::WebKitTestBus() - : m_pid(-1) + : m_bus(adoptGRef(g_test_dbus_new(G_TEST_DBUS_NONE))) { } -bool WebKitTestBus::run() +WebKitTestBus::~WebKitTestBus() { - // FIXME: Use GTestDBus when we bump glib to 2.34. - GUniquePtr<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; - } - - GUniqueOutPtr<char> output; - GUniqueOutPtr<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; + g_test_dbus_down(m_bus.get()); } -WebKitTestBus::~WebKitTestBus() +bool WebKitTestBus::run() { - g_unsetenv("DBUS_SESSION_BUS_ADDRESS"); - - if (m_pid != -1) - kill(m_pid, SIGTERM); + CString display = g_getenv("DISPLAY"); + g_test_dbus_up(m_bus.get()); + m_address = g_test_dbus_get_bus_address(m_bus.get()); + g_setenv("DISPLAY", display.data(), FALSE); + return !m_address.isNull(); } GDBusConnection* WebKitTestBus::getOrCreateConnection() @@ -77,7 +47,8 @@ GDBusConnection* WebKitTestBus::getOrCreateConnection() 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)); + nullptr, nullptr, nullptr)); + g_assert(m_connection.get()); return m_connection.get(); } @@ -88,19 +59,19 @@ static void onNameAppeared(GDBusConnection*, const char*, const char*, gpointer 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); + unsigned watcherID = g_bus_watch_name_on_connection(getOrCreateConnection(), serviceName, G_BUS_NAME_WATCHER_FLAGS_NONE, onNameAppeared, nullptr, mainLoop, nullptr); 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 + nullptr, // GDBusInterfaceInfo serviceName, objectPath, interfaceName, - 0, // GCancellable - 0); + nullptr, // GCancellable + nullptr); g_assert(proxy); return proxy; } diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.h b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.h index b9f856b27..b8a8e6041 100644 --- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.h +++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.h @@ -21,13 +21,13 @@ #define WebKitTestBus_h #include <gio/gio.h> -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> class WebKitTestBus { public: WebKitTestBus(); - virtual ~WebKitTestBus(); + ~WebKitTestBus(); bool run(); GDBusProxy* createProxy(const char* serviceName, const char* objectPath, const char* interfaceName, GMainLoop*); @@ -36,7 +36,7 @@ public: private: GDBusConnection* getOrCreateConnection(); - pid_t m_pid; + GRefPtr<GTestDBus> m_bus; CString m_address; GRefPtr<GDBusConnection> m_connection; }; diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.cpp b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.cpp index 8736771fa..de9466c39 100644 --- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.cpp +++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.cpp @@ -21,13 +21,19 @@ #include "WebKitTestServer.h" #include "TestMain.h" -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/Threading.h> +#include <wtf/glib/GUniquePtr.h> -WebKitTestServer::WebKitTestServer(ServerType type) +WebKitTestServer::WebKitTestServer(ServerOptions options) { + if (options & ServerRunInThread) { + WTF::initializeThreading(); + m_queue = WorkQueue::create("WebKitTestServer"); + } + GUniquePtr<char> sslCertificateFile; GUniquePtr<char> sslKeyFile; - if (type == ServerHTTPS) { + if (options & ServerHTTPS) { CString resourcesDir = Test::getResourcesDir(); sslCertificateFile.reset(g_build_filename(resourcesDir.data(), "test-cert.pem", NULL)); sslKeyFile.reset(g_build_filename(resourcesDir.data(), "test-key.pem", NULL)); @@ -37,9 +43,10 @@ WebKitTestServer::WebKitTestServer(ServerType type) soup_address_resolve_sync(address.get(), 0); m_soupServer = adoptGRef(soup_server_new(SOUP_SERVER_INTERFACE, address.get(), + SOUP_SERVER_ASYNC_CONTEXT, m_queue ? m_queue->runLoop().mainContext() : nullptr, SOUP_SERVER_SSL_CERT_FILE, sslCertificateFile.get(), SOUP_SERVER_SSL_KEY_FILE, sslKeyFile.get(), nullptr)); - m_baseURI = type == ServerHTTPS ? soup_uri_new("https://127.0.0.1/") : soup_uri_new("http://127.0.0.1/"); + m_baseURI = options & 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())); } @@ -50,8 +57,15 @@ WebKitTestServer::~WebKitTestServer() void WebKitTestServer::run(SoupServerCallback serverCallback) { - soup_server_run_async(m_soupServer.get()); - soup_server_add_handler(m_soupServer.get(), 0, serverCallback, 0, 0); + if (m_queue) { + m_queue->dispatch([this, serverCallback] { + soup_server_run_async(m_soupServer.get()); + soup_server_add_handler(m_soupServer.get(), nullptr, serverCallback, nullptr, nullptr); + }); + } else { + soup_server_run_async(m_soupServer.get()); + soup_server_add_handler(m_soupServer.get(), nullptr, serverCallback, nullptr, nullptr); + } } CString WebKitTestServer::getURIForPath(const char* path) diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.h b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.h index 502f7fad0..58f019fab 100644 --- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.h +++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestServer.h @@ -22,18 +22,20 @@ #include <libsoup/soup.h> #include <webkit2/webkit2.h> -#include <wtf/gobject/GRefPtr.h> +#include <wtf/WorkQueue.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> class WebKitTestServer { public: - enum ServerType { - ServerHTTP, - ServerHTTPS + enum ServerOptions { + ServerHTTP = 0, + ServerHTTPS = 1 << 1, + ServerRunInThread = 1 << 2, }; - WebKitTestServer(ServerType = ServerHTTP); + WebKitTestServer(ServerOptions = ServerHTTP); virtual ~WebKitTestServer(); SoupURI* baseURI() { return m_baseURI; } @@ -44,6 +46,7 @@ public: private: GRefPtr<SoupServer> m_soupServer; SoupURI* m_baseURI; + RefPtr<WorkQueue> m_queue; }; #endif // WebKitTestServer_h diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp index f08bb4694..7071910e4 100644 --- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp +++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp @@ -24,15 +24,15 @@ #include <JavaScriptCore/JSRetainPtr.h> #include <WebCore/GUniquePtrGtk.h> +bool WebViewTest::shouldInitializeWebViewInConstructor = true; + 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) + : m_userContentManager(adoptGRef(webkit_user_content_manager_new())) + , m_mainLoop(g_main_loop_new(nullptr, TRUE)) { - assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_webView)); + if (shouldInitializeWebViewInConstructor) + initializeWebView(); + assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_userContentManager.get())); } WebViewTest::~WebViewTest() @@ -47,10 +47,31 @@ WebViewTest::~WebViewTest() g_main_loop_unref(m_mainLoop); } +void WebViewTest::initializeWebView() +{ + g_assert(!m_webView); + m_webView = WEBKIT_WEB_VIEW(g_object_ref_sink(g_object_new(WEBKIT_TYPE_WEB_VIEW, "web-context", m_webContext.get(), "user-content-manager", m_userContentManager.get(), nullptr))); + assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_webView)); + + g_signal_connect(m_webView, "web-process-crashed", G_CALLBACK(WebViewTest::webProcessCrashed), this); +} + +gboolean WebViewTest::webProcessCrashed(WebKitWebView*, WebViewTest* test) +{ + if (test->m_expectedWebProcessCrash) { + test->m_expectedWebProcessCrash = false; + return FALSE; + } + g_assert_not_reached(); + return TRUE; +} + void WebViewTest::loadURI(const char* uri) { m_activeURI = uri; webkit_web_view_load_uri(m_webView, uri); + g_assert(webkit_web_view_is_loading(m_webView)); + g_assert_cmpstr(webkit_web_view_get_uri(m_webView), ==, m_activeURI.data()); } void WebViewTest::loadHtml(const char* html, const char* baseURI) @@ -60,29 +81,49 @@ void WebViewTest::loadHtml(const char* html, const char* baseURI) else m_activeURI = baseURI; webkit_web_view_load_html(m_webView, html, baseURI); + g_assert(webkit_web_view_is_loading(m_webView)); + g_assert_cmpstr(webkit_web_view_get_uri(m_webView), ==, m_activeURI.data()); } void WebViewTest::loadPlainText(const char* plainText) { m_activeURI = "about:blank"; webkit_web_view_load_plain_text(m_webView, plainText); + g_assert(webkit_web_view_is_loading(m_webView)); + g_assert_cmpstr(webkit_web_view_get_uri(m_webView), ==, m_activeURI.data()); +} + +void WebViewTest::loadBytes(GBytes* bytes, const char* mimeType, const char* encoding, const char* baseURI) +{ + if (!baseURI) + m_activeURI = "about:blank"; + else + m_activeURI = baseURI; + webkit_web_view_load_bytes(m_webView, bytes, mimeType, encoding, baseURI); + g_assert(webkit_web_view_is_loading(m_webView)); + g_assert_cmpstr(webkit_web_view_get_uri(m_webView), ==, m_activeURI.data()); } void WebViewTest::loadRequest(WebKitURIRequest* request) { m_activeURI = webkit_uri_request_get_uri(request); webkit_web_view_load_request(m_webView, request); + g_assert(webkit_web_view_is_loading(m_webView)); + g_assert_cmpstr(webkit_web_view_get_uri(m_webView), ==, m_activeURI.data()); } 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); + g_assert(webkit_web_view_is_loading(m_webView)); + g_assert_cmpstr(webkit_web_view_get_uri(m_webView), ==, m_activeURI.data()); } void WebViewTest::goBack() { - if (webkit_web_view_can_go_back(m_webView)) { + bool canGoBack = webkit_web_view_can_go_back(m_webView); + if (canGoBack) { 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); @@ -90,11 +131,16 @@ void WebViewTest::goBack() // Call go_back even when can_go_back returns FALSE to check nothing happens. webkit_web_view_go_back(m_webView); + if (canGoBack) { + g_assert(webkit_web_view_is_loading(m_webView)); + g_assert_cmpstr(webkit_web_view_get_uri(m_webView), ==, m_activeURI.data()); + } } void WebViewTest::goForward() { - if (webkit_web_view_can_go_forward(m_webView)) { + bool canGoForward = webkit_web_view_can_go_forward(m_webView); + if (canGoForward) { 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); @@ -102,12 +148,18 @@ void WebViewTest::goForward() // Call go_forward even when can_go_forward returns FALSE to check nothing happens. webkit_web_view_go_forward(m_webView); + if (canGoForward) { + g_assert(webkit_web_view_is_loading(m_webView)); + g_assert_cmpstr(webkit_web_view_get_uri(m_webView), ==, m_activeURI.data()); + } } 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); + g_assert(webkit_web_view_is_loading(m_webView)); + g_assert_cmpstr(webkit_web_view_get_uri(m_webView), ==, m_activeURI.data()); } void WebViewTest::quitMainLoop() @@ -122,15 +174,12 @@ void WebViewTest::quitMainLoopAfterProcessingPendingEvents() 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_timeout_add(seconds * 1000, [](gpointer userData) -> gboolean { + static_cast<WebViewTest*>(userData)->quitMainLoop(); + return G_SOURCE_REMOVE; + }, this); g_main_loop_run(m_mainLoop); } @@ -217,6 +266,16 @@ void WebViewTest::selectAll() webkit_web_view_execute_editing_command(m_webView, "SelectAll"); } +bool WebViewTest::isEditable() +{ + return webkit_web_view_is_editable(m_webView); +} + +void WebViewTest::setEditable(bool editable) +{ + webkit_web_view_set_editable(m_webView, editable); +} + static void resourceGetDataCallback(GObject* object, GAsyncResult* result, gpointer userData) { size_t dataSize; @@ -274,6 +333,15 @@ void WebViewTest::clickMouseButton(int x, int y, unsigned button, unsigned mouse doMouseButtonEvent(GDK_BUTTON_RELEASE, x, y, button, mouseModifiers); } +void WebViewTest::emitPopupMenuSignal() +{ + GtkWidget* viewWidget = GTK_WIDGET(m_webView); + g_assert(gtk_widget_get_realized(viewWidget)); + + gboolean handled; + g_signal_emit_by_name(viewWidget, "popup-menu", &handled); +} + void WebViewTest::keyStroke(unsigned keyVal, unsigned keyModifiers) { g_assert(m_parentWindow); diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h index 93a78a4d7..cfcc6c7dc 100644 --- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h +++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h @@ -31,10 +31,14 @@ public: WebViewTest(); virtual ~WebViewTest(); + static bool shouldInitializeWebViewInConstructor; + void initializeWebView(); + 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*); + virtual void loadBytes(GBytes*, const char* mimeType, const char* encoding, const char* baseURI); void loadAlternateHTML(const char* html, const char* contentURI, const char* baseURI); void goBack(); void goForward(); @@ -52,10 +56,15 @@ public: void selectAll(); const char* mainResourceData(size_t& mainResourceDataSize); + bool isEditable(); + void setEditable(bool); + void mouseMoveTo(int x, int y, unsigned mouseModifiers = 0); void clickMouseButton(int x, int y, unsigned button = 1, unsigned mouseModifiers = 0); void keyStroke(unsigned keyVal, unsigned keyModifiers = 0); + void emitPopupMenuSignal(); + WebKitJavascriptResult* runJavaScriptAndWaitUntilFinished(const char* javascript, GError**); WebKitJavascriptResult* runJavaScriptFromGResourceAndWaitUntilFinished(const char* resource, GError**); @@ -70,16 +79,24 @@ public: bool runWebProcessTest(const char* suiteName, const char* testName); - WebKitWebView* m_webView; + // Prohibit overrides because this is called when the web view is created + // in our constructor, before a derived class's vtable is ready. + void initializeWebExtensions() final { Test::initializeWebExtensions(); } + + static gboolean webProcessCrashed(WebKitWebView*, WebViewTest*); + + GRefPtr<WebKitUserContentManager> m_userContentManager; + WebKitWebView* m_webView { nullptr }; GMainLoop* m_mainLoop; CString m_activeURI; - GtkWidget* m_parentWindow; + GtkWidget* m_parentWindow { nullptr }; CString m_expectedTitle; - WebKitJavascriptResult* m_javascriptResult; - GError** m_javascriptError; - GUniquePtr<char> m_resourceData; - size_t m_resourceDataSize; - cairo_surface_t* m_surface; + WebKitJavascriptResult* m_javascriptResult { nullptr }; + GError** m_javascriptError { nullptr }; + GUniquePtr<char> m_resourceData { nullptr }; + size_t m_resourceDataSize { 0 }; + cairo_surface_t* m_surface { nullptr }; + bool m_expectedWebProcessCrash { false }; private: void doMouseButtonEvent(GdkEventType, int, int, unsigned, unsigned); diff --git a/Tools/TestWebKitAPI/gtk/main.cpp b/Tools/TestWebKitAPI/gtk/main.cpp index 1b7fef64f..2c6856595 100644 --- a/Tools/TestWebKitAPI/gtk/main.cpp +++ b/Tools/TestWebKitAPI/gtk/main.cpp @@ -32,5 +32,5 @@ int main(int argc, char** argv) { gtk_init(&argc, &argv); - return TestWebKitAPI::TestsController::shared().run(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE; + return TestWebKitAPI::TestsController::singleton().run(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE; } |