diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-05-24 08:28:08 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2016-05-24 08:28:08 +0000 |
commit | a4e969f4965059196ca948db781e52f7cfebf19e (patch) | |
tree | 6ca352808c8fdc52006a0f33f6ae3c593b23867d /Tools/TestWebKitAPI/gtk | |
parent | 41386e9cb918eed93b3f13648cbef387e371e451 (diff) | |
download | WebKitGtk-tarball-a4e969f4965059196ca948db781e52f7cfebf19e.tar.gz |
webkitgtk-2.12.3webkitgtk-2.12.3
Diffstat (limited to 'Tools/TestWebKitAPI/gtk')
-rw-r--r-- | Tools/TestWebKitAPI/gtk/PlatformUtilitiesGtk.cpp | 6 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/PlatformWebViewGtk.cpp | 38 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp | 81 | ||||
-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 | 61 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.cpp | 2 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.h | 2 | ||||
-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 | 82 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h | 13 | ||||
-rw-r--r-- | Tools/TestWebKitAPI/gtk/main.cpp | 2 |
13 files changed, 272 insertions, 83 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..b37ced74e 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); diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp index 211fa8b82..e78ce45ee 100644 --- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp +++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp @@ -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..6054fe09d 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) \ @@ -56,8 +58,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 +97,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 +114,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 +160,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..1cf241461 100644 --- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.cpp +++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.cpp @@ -20,7 +20,7 @@ #include "config.h" #include "WebKitTestBus.h" -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GUniquePtr.h> #include <wtf/text/WTFString.h> WebKitTestBus::WebKitTestBus() diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.h b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.h index b9f856b27..03bcc3ae5 100644 --- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.h +++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebKitTestBus.h @@ -21,7 +21,7 @@ #define WebKitTestBus_h #include <gio/gio.h> -#include <wtf/gobject/GRefPtr.h> +#include <wtf/glib/GRefPtr.h> #include <wtf/text/CString.h> class WebKitTestBus { 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..b0217ae2b 100644 --- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp +++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp @@ -24,15 +24,17 @@ #include <JavaScriptCore/JSRetainPtr.h> #include <WebCore/GUniquePtrGtk.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) +WebViewTest::WebViewTest(WebKitUserContentManager* userContentManager) + : m_webView(WEBKIT_WEB_VIEW(g_object_ref_sink(g_object_new(WEBKIT_TYPE_WEB_VIEW, "web-context", m_webContext.get(), "user-content-manager", userContentManager, nullptr)))) + , m_mainLoop(g_main_loop_new(nullptr, TRUE)) + , m_parentWindow(nullptr) + , m_javascriptResult(nullptr) , m_resourceDataSize(0) - , m_surface(0) + , m_surface(nullptr) + , m_expectedWebProcessCrash(false) { assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_webView)); + g_signal_connect(m_webView, "web-process-crashed", G_CALLBACK(WebViewTest::webProcessCrashed), this); } WebViewTest::~WebViewTest() @@ -47,10 +49,22 @@ WebViewTest::~WebViewTest() g_main_loop_unref(m_mainLoop); } +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 +74,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 +124,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 +141,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 +167,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 +259,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; diff --git a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h index 93a78a4d7..3f99d21ec 100644 --- a/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h +++ b/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h @@ -28,13 +28,14 @@ class WebViewTest: public Test { public: MAKE_GLIB_TEST_FIXTURE(WebViewTest); - WebViewTest(); + WebViewTest(WebKitUserContentManager* = nullptr); 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*); + 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,6 +53,9 @@ 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); @@ -70,6 +74,12 @@ public: bool runWebProcessTest(const char* suiteName, const char* testName); + // 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() override final { Test::initializeWebExtensions(); } + + static gboolean webProcessCrashed(WebKitWebView*, WebViewTest*); + WebKitWebView* m_webView; GMainLoop* m_mainLoop; CString m_activeURI; @@ -80,6 +90,7 @@ public: GUniquePtr<char> m_resourceData; size_t m_resourceDataSize; cairo_surface_t* m_surface; + bool m_expectedWebProcessCrash; 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; } |