diff options
Diffstat (limited to 'Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp')
-rw-r--r-- | Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp | 115 |
1 files changed, 106 insertions, 9 deletions
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp index 20b90b0b4..a24b6fdff 100644 --- a/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp @@ -93,15 +93,27 @@ public: 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) { } @@ -121,6 +133,8 @@ public: 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); } @@ -134,9 +148,15 @@ public: { 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; @@ -177,13 +197,14 @@ public: 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(!webkit_web_view_get_subresources(test->m_webView)); + g_assert(!test->subresources()); // Load simple page without subresources. test->loadHtml("<html><body>Testing WebKitGTK+</body></html>", 0); @@ -191,7 +212,7 @@ static void testWebViewResources(ResourcesTest* test, gconstpointer) 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(!webkit_web_view_get_subresources(test->m_webView)); + g_assert(!test->subresources()); // Load simple page with subresources. test->loadURI(kServer->getURIForPath("/").data()); @@ -200,9 +221,9 @@ static void testWebViewResources(ResourcesTest* test, gconstpointer) 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)); - GOwnPtr<GList> subresources(webkit_web_view_get_subresources(test->m_webView)); + GList* subresources = test->subresources(); g_assert(subresources); - g_assert_cmpint(g_list_length(subresources.get()), ==, 3); + g_assert_cmpint(g_list_length(subresources), ==, 3); #if 0 // Load the same URI again. @@ -482,9 +503,7 @@ public: private: void checkActiveURI(const char* uri) { - // g_assert_cmpstr is a macro, so we need to cache the temporary string. - CString serverURI = kServer->getURIForPath(uri); - g_assert_cmpstr(m_activeURI.data(), ==, serverURI.data()); + ASSERT_CMP_CSTRING(m_activeURI, ==, kServer->getURIForPath(uri)); } }; @@ -505,8 +524,8 @@ static void testWebResourceGetData(ResourcesTest* test, gconstpointer) g_assert(resource); test->checkResourceData(resource); - GOwnPtr<GList> subresources(webkit_web_view_get_subresources(test->m_webView)); - for (GList* item = subresources.get(); item; item = g_list_next(item)) + GList* subresources = test->subresources(); + for (GList* item = subresources; item; item = g_list_next(item)) test->checkResourceData(WEBKIT_WEB_RESOURCE(item->data)); } @@ -539,6 +558,75 @@ static void testWebViewResourcesHistoryCache(SingleResourceLoadTest* test, gcons 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. @@ -592,6 +680,12 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char* 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; @@ -622,6 +716,8 @@ 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); @@ -630,6 +726,7 @@ void beforeAll() 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() |