summaryrefslogtreecommitdiff
path: root/Source/WebKit2/UIProcess/API/gtk/tests
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2012-10-15 16:08:57 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2012-10-15 16:08:57 +0200
commit5466563f4b5b6b86523e3f89bb7f77e5b5270c78 (patch)
tree8caccf7cd03a15207cde3ba282c88bf132482a91 /Source/WebKit2/UIProcess/API/gtk/tests
parent33b26980cb24288b5a9f2590ccf32a949281bb79 (diff)
downloadqtwebkit-5466563f4b5b6b86523e3f89bb7f77e5b5270c78.tar.gz
Imported WebKit commit 0dc6cd75e1d4836eaffbb520be96fac4847cc9d2 (http://svn.webkit.org/repository/webkit/trunk@131300)
WebKit update which introduces the QtWebKitWidgets module that contains the WK1 widgets based API. (In fact it renames QtWebKit to QtWebKitWidgets while we're working on completing the entire split as part of https://bugs.webkit.org/show_bug.cgi?id=99314
Diffstat (limited to 'Source/WebKit2/UIProcess/API/gtk/tests')
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am18
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp5
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp2
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp3
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp12
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp32
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp9
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp246
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp12
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp16
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp13
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp11
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp18
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h1
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js1
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml6
16 files changed, 380 insertions, 25 deletions
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am b/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am
index 3fadf40b4..06ea1af7c 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am
@@ -11,6 +11,7 @@ TEST_PROGS += \
Programs/WebKit2APITests/TestResources \
Programs/WebKit2APITests/TestSSL \
Programs/WebKit2APITests/TestWebKitVersion \
+ Programs/WebKit2APITests/TestWebKitFaviconDatabase \
Programs/WebKit2APITests/TestWebKitFindController \
Programs/WebKit2APITests/TestWebKitPolicyClient \
Programs/WebKit2APITests/TestWebKitSettings \
@@ -29,6 +30,7 @@ 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\" \
$(javascriptcore_cppflags) \
-I$(srcdir)/Source/JavaScriptCore \
-I$(srcdir)/Source \
@@ -55,6 +57,12 @@ webkit2_tests_ldflags = \
-no-install \
-no-fast-install
+DerivedSources/WebKit2/webkit2gtk-tests-resources.gresource: Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies $(srcdir)/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml)
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) $<
+
+DISTCLEANFILES += DerivedSources/WebKit2/webkit2gtk-tests-resources.gresource
+noinst_DATA += DerivedSources/WebKit2/webkit2gtk-tests-resources.gresource
+
noinst_LTLIBRARIES += Libraries/libWebKit2APITestCore.la
Libraries_libWebKit2APITestCore_la_SOURCES = \
Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp \
@@ -69,7 +77,9 @@ Libraries_libWebKit2APITestCore_la_CPPFLAGS = $(webkit2_tests_cppflags)
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/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
@@ -141,6 +151,12 @@ Programs_WebKit2APITests_TestPrinting_CPPFLAGS = $(webkit2_tests_cppflags) $(GTK
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)
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp
index e70e391ff..b479366a4 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp
@@ -38,6 +38,11 @@ static void serverCallback(SoupServer* server, SoupMessage* msg, const char* pat
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);
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp
index 2fe8998b5..94aeef6e1 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestCookieManager.cpp
@@ -295,7 +295,7 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
} else if (g_str_equal(path, "/image.png"))
soup_message_headers_replace(message->response_headers, "Set-Cookie", "baz=qux; Max-Age=60");
else
- g_assert_not_reached();
+ soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
soup_message_body_complete(message->response_body);
}
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp
index c3a14193d..8fcf33009 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp
@@ -312,7 +312,8 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString));
soup_server_unpause_message(server, message);
return;
- }
+ } else
+ soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
soup_message_body_complete(message->response_body);
}
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp
index 8622af19c..9db47f82b 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp
@@ -25,12 +25,24 @@
void beforeAll();
void afterAll();
+static void registerGResource(void)
+{
+ GOwnPtr<char> resourcesPath(g_build_filename(WEBKIT_DERIVED_SRC_DIR, "WebKit2", "webkit2gtk-tests-resources.gresource", NULL));
+ GResource* resource = g_resource_load(resourcesPath.get(), 0);
+ g_assert(resource);
+
+ g_resources_register(resource);
+ g_resource_unref(resource);
+}
+
int main(int argc, char** argv)
{
gtk_test_init(&argc, &argv, 0);
g_setenv("WEBKIT_EXEC_PATH", WEBKIT_EXEC_PATH, FALSE);
g_test_bug_base("https://bugs.webkit.org/");
+ registerGResource();
+
beforeAll();
int returnValue = g_test_run();
afterAll();
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp
index 7e2e5de61..20b90b0b4 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp
@@ -80,6 +80,11 @@ public:
{
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);
@@ -507,21 +512,31 @@ static void testWebResourceGetData(ResourcesTest* test, gconstpointer)
static void testWebViewResourcesHistoryCache(SingleResourceLoadTest* test, gconstpointer)
{
- test->loadURI(kServer->getURIForPath("/").data());
+ CString javascriptURI = kServer->getURIForPath("/javascript.html");
+ test->loadURI(javascriptURI.data());
test->waitUntilResourceLoadFinished();
- g_assert(webkit_web_view_get_main_resource(test->m_webView));
+ 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());
- test->loadURI(kServer->getURIForPath("/javascript.html").data());
+ CString simpleStyleCSSURI = kServer->getURIForPath("/simple-style-css.html");
+ test->loadURI(simpleStyleCSSURI.data());
test->waitUntilResourceLoadFinished();
- g_assert(webkit_web_view_get_main_resource(test->m_webView));
+ 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();
- g_assert(webkit_web_view_get_main_resource(test->m_webView));
+ 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();
- g_assert(webkit_web_view_get_main_resource(test->m_webView));
+ resource = webkit_web_view_get_main_resource(test->m_webView);
+ g_assert(resource);
+ g_assert_cmpstr(webkit_web_resource_get_uri(resource), ==, simpleStyleCSSURI.data());
}
static void addCacheHTTPHeadersToResponse(SoupMessage* message)
@@ -567,6 +582,9 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
} 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);
@@ -594,6 +612,8 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
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);
}
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp
index 40e9fbeee..8fa013dc4 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp
@@ -82,9 +82,12 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
return;
}
- 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);
+ 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
+ soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
}
void beforeAll()
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp
new file mode 100644
index 000000000..40fb5a17a
--- /dev/null
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp
@@ -0,0 +1,246 @@
+/*
+ * 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_iconReadySignalReceived(false)
+ , m_faviconNotificationReceived(false)
+ {
+ WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext);
+ g_signal_connect(database, "favicon-ready", G_CALLBACK(iconReadyCallback), 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 iconReadyCallback(WebKitFaviconDatabase* database, const char* pageURI, FaviconDatabaseTest* test)
+ {
+ g_assert_cmpstr(webkit_web_view_get_uri(test->m_webView), ==, pageURI);
+ test->m_iconReadySignalReceived = true;
+ }
+
+ static void faviconChangedCallback(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(faviconChangedCallback), 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;
+ GOwnPtr<GError> m_error;
+ bool m_iconReadySignalReceived;
+ 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;
+ }
+
+ char* contents;
+ gsize length;
+ if (g_str_equal(path, "/favicon.ico")) {
+ GOwnPtr<char> pathToFavicon(g_build_filename(Test::getWebKit1TestResoucesDir().data(), "blank.ico", NULL));
+ g_file_get_contents(pathToFavicon.get(), &contents, &length, 0);
+ } else if (g_str_equal(path, "/nofavicon/favicon.ico")) {
+ soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
+ soup_message_body_complete(message->response_body);
+ return;
+ } else {
+ contents = g_strdup("<html><body>test</body></html>");
+ length = strlen(contents);
+ }
+
+ soup_message_set_status(message, SOUP_STATUS_OK);
+ soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length);
+ soup_message_body_complete(message->response_body);
+}
+
+static void testNotInitialized(FaviconDatabaseTest* test, gconstpointer)
+{
+ // Try to retrieve a valid favicon from a not initialized database.
+ test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/").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, gconstpointer)
+{
+ 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, gconstpointer)
+{
+ 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("/").data()));
+ g_assert(!iconURI);
+}
+
+static void testGetFavicon(FaviconDatabaseTest* test, gconstpointer)
+{
+ // 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("/").data());
+ test->waitUntilFaviconChanged();
+ g_assert(test->m_iconReadySignalReceived);
+
+ // Check the API retrieving a valid favicon.
+ test->m_iconReadySignalReceived = false;
+ test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/").data());
+ g_assert(test->m_favicon);
+ g_assert(!test->m_error);
+ g_assert(!test->m_iconReadySignalReceived);
+
+ // 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 the API retrieving an invalid favicon.
+ test->loadURI(kServer->getURIForPath("/nofavicon").data());
+ test->waitUntilFaviconChanged();
+ g_assert(!test->m_iconReadySignalReceived);
+
+ test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/nofavicon/").data());
+ g_assert(!test->m_favicon);
+ g_assert(test->m_error);
+ g_assert(!test->m_iconReadySignalReceived);
+}
+
+static void testGetFaviconURI(FaviconDatabaseTest* test, gconstpointer)
+{
+ WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext);
+
+ const char* baseURI = kServer->getURIForPath("/").data();
+ GOwnPtr<char> iconURI(webkit_favicon_database_get_favicon_uri(database, baseURI));
+ g_assert_cmpstr(iconURI.get(), ==, kServer->getURIForPath("/favicon.ico").data());
+}
+
+static void testWebViewFavicon(FaviconDatabaseTest* test, gconstpointer)
+{
+ cairo_surface_t* iconFromWebView = webkit_web_view_get_favicon(test->m_webView);
+ g_assert(!iconFromWebView);
+
+ test->loadURI(kServer->getURIForPath("/").data());
+ test->waitUntilFaviconChanged();
+ g_assert(test->m_faviconNotificationReceived);
+
+ 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);
+}
+
+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", "not-initialized", testNotInitialized);
+ FaviconDatabaseTest::add("WebKitFaviconDatabase", "set-directory", testSetDirectory);
+ FaviconDatabaseTest::add("WebKitFaviconDatabase", "get-favicon", testGetFavicon);
+ FaviconDatabaseTest::add("WebKitFaviconDatabase", "get-favicon-uri", testGetFaviconURI);
+ FaviconDatabaseTest::add("WebKitFaviconDatabase", "clear-database", testClearDatabase);
+ FaviconDatabaseTest::add("WebKitWebView", "favicon", testWebViewFavicon);
+}
+
+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/TestWebKitPolicyClient.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp
index 9f6ce7819..abbfd652a 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitPolicyClient.cpp
@@ -232,11 +232,13 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
return;
}
- soup_message_set_status(message, SOUP_STATUS_OK);
-
- static const char* responseString = "<html><body>Testing!</body></html>";
- soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString));
- soup_message_body_complete(message->response_body);
+ 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()
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp
index d8e355472..c7a0dc259 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp
@@ -243,6 +243,11 @@ static void testWebKitSettings(Test*, gconstpointer)
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));
+
g_object_unref(G_OBJECT(settings));
}
@@ -315,10 +320,13 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
return;
}
- soup_message_set_status(message, SOUP_STATUS_OK);
- const char* userAgent = soup_message_headers_get_one(message->request_headers, "User-Agent");
- soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, userAgent, strlen(userAgent));
- soup_message_body_complete(message->response_body);
+ 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()
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp
index 7a13d285d..185c06cfe 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp
@@ -146,6 +146,8 @@ public:
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()));
@@ -291,10 +293,13 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
return;
}
- soup_message_set_status(message, SOUP_STATUS_OK);
- const char* acceptLanguage = soup_message_headers_get_one(message->request_headers, "Accept-Language");
- soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, acceptLanguage, strlen(acceptLanguage));
- soup_message_body_complete(message->response_body);
+ 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 {
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp
index 02e8138de..f5197b936 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp
@@ -643,6 +643,17 @@ static void testWebViewRunJavaScript(WebViewTest* test, gconstpointer)
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);
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp
index 04747480e..7e7eb0167 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp
@@ -313,6 +313,12 @@ static void runJavaScriptReadyCallback(GObject*, GAsyncResult* result, WebViewTe
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)
@@ -325,6 +331,18 @@ WebKitJavascriptResult* WebViewTest::runJavaScriptAndWaitUntilFinished(const cha
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);
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h
index 25209caa3..06f398f96 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h
@@ -55,6 +55,7 @@ public:
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*);
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js b/Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js
new file mode 100644
index 000000000..2c824da38
--- /dev/null
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js
@@ -0,0 +1 @@
+window.document.getElementById('WebKitLink').title;
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
new file mode 100644
index 000000000..4f1e5a654
--- /dev/null
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml
@@ -0,0 +1,6 @@
+<?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>