summaryrefslogtreecommitdiff
path: root/Source/WebKit2/UIProcess/API/gtk/tests
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit2/UIProcess/API/gtk/tests')
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am58
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/InspectorTestServer.cpp4
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp8
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h1
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestContextMenu.cpp8
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestDownloads.cpp59
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestInspector.cpp52
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestInspectorServer.cpp9
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp123
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp24
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h18
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp2
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp115
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp121
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestWebExtensions.cpp118
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitAccessibility.cpp5
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp41
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp71
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp20
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp53
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp196
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebViewGroup.cpp206
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp158
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.cpp106
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.h44
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp36
-rw-r--r--Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h5
27 files changed, 1461 insertions, 200 deletions
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am b/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am
index a8f9976fd..7510b617c 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am
@@ -12,6 +12,7 @@ TEST_PROGS += \
Programs/WebKit2APITests/TestPrinting \
Programs/WebKit2APITests/TestResources \
Programs/WebKit2APITests/TestSSL \
+ Programs/WebKit2APITests/TestWebExtensions \
Programs/WebKit2APITests/TestWebKitVersion \
Programs/WebKit2APITests/TestWebKitFaviconDatabase \
Programs/WebKit2APITests/TestWebKitFindController \
@@ -19,6 +20,7 @@ TEST_PROGS += \
Programs/WebKit2APITests/TestWebKitSettings \
Programs/WebKit2APITests/TestWebKitWebContext \
Programs/WebKit2APITests/TestWebKitWebView \
+ Programs/WebKit2APITests/TestWebKitWebViewGroup \
Programs/WebKit2APITests/TestWebViewEditor
noinst_PROGRAMS += $(TEST_PROGS)
@@ -34,6 +36,8 @@ webkit2_tests_cppflags = \
-DWEBKIT_SRC_DIR=\"${shell pwd}/${srcdir}\" \
-DWEBKIT_DERIVED_SRC_DIR=\"${shell pwd}/${top_builddir}/DerivedSources\" \
-DWEBKIT_TEST_PLUGIN_DIR=\"${shell pwd}/${top_builddir}/TestNetscapePlugin/.libs\" \
+ -DWEBKIT_TEST_WEB_EXTENSIONS_DIR=\"${shell pwd}/${top_builddir}/Libraries/WebExtensions/.libs\" \
+ -DWEBKIT_INJECTED_BUNDLE_PATH=\"${shell pwd}/$(top_builddir)/.libs\" \
$(javascriptcore_cppflags) \
-I$(srcdir)/Source/JavaScriptCore \
-I$(srcdir)/Source \
@@ -43,6 +47,7 @@ webkit2_tests_cppflags = \
-I$(top_builddir)/DerivedSources/WebKit2/webkit2gtk/include \
-I$(srcdir)/Source/WebKit2/UIProcess/API/gtk \
$(global_cppflags) \
+ $(FREETYPE_CFLAGS) \
$(GLIB_CFLAGS) \
$(GTK_CFLAGS) \
$(LIBSOUP_CFLAGS)
@@ -51,6 +56,7 @@ webkit2_tests_ldadd = \
Libraries/libWebKit2APITestCore.la \
libjavascriptcoregtk-@WEBKITGTK_API_MAJOR_VERSION@.@WEBKITGTK_API_MINOR_VERSION@.la \
libwebkit2gtk-@WEBKITGTK_API_MAJOR_VERSION@.@WEBKITGTK_API_MINOR_VERSION@.la \
+ $(FREETYPE_LIBS) \
$(GEOCLUE_LIBS) \
$(GLIB_LIBS) \
$(GTK_LIBS) \
@@ -61,15 +67,27 @@ webkit2_tests_ldflags = \
-no-fast-install
Programs/resources/webkit2gtk-tests-resources.gresource: Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml)
+ $(AM_V_at)mkdir -p ${GENPROGRAMS}/resources
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) $<
-DISTCLEANFILES += Programs/resources/webkit2gtk-tests-resources.gresource
-noinst_DATA += Programs/resources/webkit2gtk-tests-resources.gresource
+Programs/resources/inspector/inspectorPageIndex.html: Source/WebKit2/UIProcess/InspectorServer/front-end/inspectorPageIndex.html
+ $(AM_V_at)mkdir -p ${GENPROGRAMS}/resources/inspector
+ $(AM_V_GEN)cp $(srcdir)/Source/WebKit2/UIProcess/InspectorServer/front-end/inspectorPageIndex.html ${GENPROGRAMS}/resources/inspector
+
+DISTCLEANFILES += \
+ Programs/resources/webkit2gtk-tests-resources.gresource \
+ Programs/resources/inspector/inspectorPageIndex.html
+
+noinst_DATA += \
+ Programs/resources/webkit2gtk-tests-resources.gresource \
+ Programs/resources/inspector/inspectorPageIndex.html
noinst_LTLIBRARIES += Libraries/libWebKit2APITestCore.la
Libraries_libWebKit2APITestCore_la_SOURCES = \
Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp \
Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h \
+ Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.cpp \
+ Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.h \
Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.cpp \
Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.h \
Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp \
@@ -78,6 +96,30 @@ Libraries_libWebKit2APITestCore_la_SOURCES = \
Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h
Libraries_libWebKit2APITestCore_la_CPPFLAGS = $(webkit2_tests_cppflags)
+noinst_LTLIBRARIES += Libraries/WebExtensions/libWebExtensionTest.la
+Libraries_WebExtensions_libWebExtensionTest_la_SOURCES = \
+ Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp
+
+Libraries_WebExtensions_libWebExtensionTest_la_LDFLAGS = \
+ -rpath ${shell pwd}/$(top_builddir)/Libraries/WebExtensions/.libs \
+ $(no_undefined) \
+ -avoid-version \
+ -module
+
+Libraries_WebExtensions_libWebExtensionTest_la_CPPFLAGS = \
+ -I$(srcdir)/Source/WebKit2/WebProcess/InjectedBundle/API/gtk \
+ -I$(top_builddir)/DerivedSources \
+ -I$(top_builddir)/DerivedSources/WebKit2/webkit2extension/include \
+ -DWEBKIT2_COMPILATION \
+ $(webkit2_tests_cppflags)
+
+Libraries_WebExtensions_libWebExtensionTest_la_CXXFLAGS = \
+ $(global_cxxflags)
+
+Libraries_WebExtensions_libWebExtensionTest_la_CFLAGS = \
+ $(global_cflags)
+
+
EXTRA_DIST += \
Source/WebKit2/UIProcess/API/gtk/tests/resources/test-cert.pem \
Source/WebKit2/UIProcess/API/gtk/tests/resources/test-key.pem \
@@ -214,4 +256,16 @@ Programs_WebKit2APITests_TestSSL_CPPFLAGS = $(webkit2_tests_cppflags)
Programs_WebKit2APITests_TestSSL_LDADD = $(webkit2_tests_ldadd)
Programs_WebKit2APITests_TestSSL_LDFLAGS = $(webkit2_tests_ldflags)
+Programs_WebKit2APITests_TestWebExtensions_SOURCES = \
+ Source/WebKit2/UIProcess/API/gtk/tests/TestWebExtensions.cpp
+Programs_WebKit2APITests_TestWebExtensions_CPPFLAGS = $(webkit2_tests_cppflags)
+Programs_WebKit2APITests_TestWebExtensions_LDADD = $(webkit2_tests_ldadd)
+Programs_WebKit2APITests_TestWebExtensions_LDFLAGS = $(webkit2_tests_ldflags)
+
+Programs_WebKit2APITests_TestWebKitWebViewGroup_SOURCES = \
+ Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebViewGroup.cpp
+Programs_WebKit2APITests_TestWebKitWebViewGroup_CPPFLAGS = $(webkit2_tests_cppflags)
+Programs_WebKit2APITests_TestWebKitWebViewGroup_LDADD = $(webkit2_tests_ldadd)
+Programs_WebKit2APITests_TestWebKitWebViewGroup_LDFLAGS = $(webkit2_tests_ldflags)
+
endif # ENABLE_WEBKIT2
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/InspectorTestServer.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/InspectorTestServer.cpp
index f13b043df..7c9dc900c 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/InspectorTestServer.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/InspectorTestServer.cpp
@@ -40,6 +40,10 @@ int main(int argc, char** argv)
// Overwrite WEBKIT_INSPECTOR_SERVER variable with default value.
g_setenv("WEBKIT_INSPECTOR_SERVER", "127.0.0.1:2999", TRUE);
+
+ // Overwrite WEBKIT_INSPECTOR_SERVER_PATH variable to point to inspector resources folder.
+ const gchar* inspectorResourcesPath = g_getenv("WEBKIT_INSPECTOR_PATH");
+ g_setenv("WEBKIT_INSPECTOR_SERVER_PATH", inspectorResourcesPath, TRUE);
WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
webkit_settings_set_enable_developer_extras(webkit_web_view_get_settings(webView), TRUE);
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp
index b904111f4..df3420492 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp
@@ -63,6 +63,7 @@ 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;
+ test->m_error.set(g_error_copy(error));
switch (loadEvent) {
case WEBKIT_LOAD_STARTED:
@@ -153,6 +154,7 @@ void LoadTrackingTest::loadURI(const char* uri)
{
m_loadEvents.clear();
m_estimatedProgress = 0;
+ m_error.clear();
WebViewTest::loadURI(uri);
}
@@ -160,6 +162,7 @@ void LoadTrackingTest::loadHtml(const char* html, const char* baseURI)
{
m_loadEvents.clear();
m_estimatedProgress = 0;
+ m_error.clear();
WebViewTest::loadHtml(html, baseURI);
}
@@ -167,6 +170,7 @@ void LoadTrackingTest::loadPlainText(const char* plainText)
{
m_loadEvents.clear();
m_estimatedProgress = 0;
+ m_error.clear();
WebViewTest::loadPlainText(plainText);
}
@@ -174,6 +178,7 @@ void LoadTrackingTest::loadRequest(WebKitURIRequest* request)
{
m_loadEvents.clear();
m_estimatedProgress = 0;
+ m_error.clear();
WebViewTest::loadRequest(request);
}
@@ -181,6 +186,7 @@ void LoadTrackingTest::reload()
{
m_loadEvents.clear();
m_estimatedProgress = 0;
+ m_error.clear();
webkit_web_view_reload(m_webView);
}
@@ -188,6 +194,7 @@ void LoadTrackingTest::goBack()
{
m_loadEvents.clear();
m_estimatedProgress = 0;
+ m_error.clear();
WebViewTest::goBack();
}
@@ -195,5 +202,6 @@ void LoadTrackingTest::goForward()
{
m_loadEvents.clear();
m_estimatedProgress = 0;
+ m_error.clear();
WebViewTest::goForward();
}
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h b/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h
index 562f7f038..a3cf7843d 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h
@@ -59,6 +59,7 @@ public:
};
bool m_runLoadUntilCompletion;
bool m_loadFailed;
+ GOwnPtr<GError> m_error;
Vector<LoadEvents> m_loadEvents;
float m_estimatedProgress;
CString m_redirectURI;
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestContextMenu.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestContextMenu.cpp
index eff59862b..c361f8baf 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestContextMenu.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestContextMenu.cpp
@@ -354,8 +354,8 @@ static void testContextMenuDefaultMenu(ContextMenuDefaultTest* test, gconstpoint
" <a style='position:absolute; left:1; top:1' href='http://www.webkitgtk.org' title='WebKitGTK+ Title'>WebKitGTK+ Website</a>"
" <img style='position:absolute; left:1; top:10' src='0xdeadbeef' width=5 height=5></img>"
" <a style='position:absolute; left:1; top:20' href='http://www.webkitgtk.org/logo' title='WebKitGTK+ Logo'><img src='0xdeadbeef' width=5 height=5></img></a>"
- " <video style='position:absolute; left:1; top:30' width=10 height=10 controls='controls'><source src='movie.ogg' type='video/ogg' /></video>"
- " <input style='position:absolute; left:1; top:50' size='10'></input>"
+ " <input style='position:absolute; left:1; top:30' size='10'></input>"
+ " <video style='position:absolute; left:1; top:50' width='300' height='300' controls='controls' preload='none'><source src='movie.ogg' type='video/ogg' /></video>"
"</body></html>";
test->loadHtml(linksHTML, "file:///");
test->waitUntilLoadFinished();
@@ -382,11 +382,11 @@ static void testContextMenuDefaultMenu(ContextMenuDefaultTest* test, gconstpoint
// Context menu for image video.
test->m_expectedMenuType = ContextMenuDefaultTest::Video;
- test->showContextMenuAtPositionAndWaitUntilFinished(1, 30);
+ test->showContextMenuAtPositionAndWaitUntilFinished(1, 50);
// Context menu for editable.
test->m_expectedMenuType = ContextMenuDefaultTest::Editable;
- test->showContextMenuAtPositionAndWaitUntilFinished(5, 55);
+ test->showContextMenuAtPositionAndWaitUntilFinished(5, 35);
}
class ContextMenuCustomTest: public ContextMenuTest {
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestDownloads.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestDownloads.cpp
index 56a62cd09..ce159906c 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestDownloads.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestDownloads.cpp
@@ -153,9 +153,18 @@ public:
webkit_download_set_destination(download, destinationURI.get());
}
- void waitUntilDownloadFinishes()
+ WebKitDownload* downloadURIAndWaitUntilFinishes(const CString& requestURI)
{
+ WebKitDownload* download = webkit_web_context_download_uri(m_webContext, requestURI.data());
+ assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download));
+
+ WebKitURIRequest* request = webkit_download_get_request(download);
+ g_assert(request);
+ ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, requestURI);
+
g_main_loop_run(m_mainLoop);
+
+ return download;
}
void checkDestinationAndDeleteFile(WebKitDownload* download, const char* expectedName)
@@ -181,9 +190,7 @@ static void testDownloadLocalFile(DownloadTest* test, gconstpointer)
GRefPtr<GFile> source = adoptGRef(g_file_new_for_path(sourcePath.get()));
GRefPtr<GFileInfo> sourceInfo = adoptGRef(g_file_query_info(source.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE, static_cast<GFileQueryInfoFlags>(0), 0, 0));
GOwnPtr<char> sourceURI(g_file_get_uri(source.get()));
- GRefPtr<WebKitDownload> download = adoptGRef(webkit_web_context_download_uri(test->m_webContext, sourceURI.get()));
- test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download.get()));
- test->waitUntilDownloadFinishes();
+ GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes(sourceURI.get()));
g_assert(!webkit_download_get_web_view(download.get()));
Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents;
@@ -246,9 +253,7 @@ public:
static void testDownloadLocalFileError(DownloadErrorTest* test, gconstpointer)
{
test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_NETWORK;
- GRefPtr<WebKitDownload> download = adoptGRef(webkit_web_context_download_uri(test->m_webContext, "file:///foo/bar"));
- test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download.get()));
- test->waitUntilDownloadFinishes();
+ GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes("file:///foo/bar"));
g_assert(!webkit_download_get_web_view(download.get()));
Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents;
@@ -263,12 +268,9 @@ static void testDownloadLocalFileError(DownloadErrorTest* test, gconstpointer)
GOwnPtr<char> path(g_build_filename(Test::getWebKit1TestResoucesDir().data(), "test.pdf", NULL));
GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(path.get()));
GOwnPtr<char> uri(g_file_get_uri(file.get()));
- download = adoptGRef(webkit_web_context_download_uri(test->m_webContext, uri.get()));
- test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download.get()));
- test->waitUntilDownloadFinishes();
+ download = adoptGRef(test->downloadURIAndWaitUntilFinishes(uri.get()));
g_assert(!webkit_download_get_web_view(download.get()));
- events = test->m_downloadEvents;
g_assert_cmpint(events.size(), ==, 4);
g_assert_cmpint(events[0], ==, DownloadTest::Started);
g_assert_cmpint(events[1], ==, DownloadTest::ReceivedResponse);
@@ -279,12 +281,9 @@ static void testDownloadLocalFileError(DownloadErrorTest* test, gconstpointer)
test->checkDestinationAndDeleteFile(download.get(), "bar");
test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER;
- download = adoptGRef(webkit_web_context_download_uri(test->m_webContext, uri.get()));
- test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download.get()));
- test->waitUntilDownloadFinishes();
+ download = adoptGRef(test->downloadURIAndWaitUntilFinishes(uri.get()));
g_assert(!webkit_download_get_web_view(download.get()));
- events = test->m_downloadEvents;
g_assert_cmpint(events.size(), ==, 4);
g_assert_cmpint(events[0], ==, DownloadTest::Started);
g_assert_cmpint(events[1], ==, DownloadTest::ReceivedResponse);
@@ -325,9 +324,7 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
static void testDownloadRemoteFile(DownloadTest* test, gconstpointer)
{
- GRefPtr<WebKitDownload> download = adoptGRef(webkit_web_context_download_uri(test->m_webContext, kServer->getURIForPath("/test.pdf").data()));
- test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download.get()));
- test->waitUntilDownloadFinishes();
+ GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/test.pdf")));
g_assert(!webkit_download_get_web_view(download.get()));
Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents;
@@ -341,8 +338,7 @@ static void testDownloadRemoteFile(DownloadTest* test, gconstpointer)
WebKitURIRequest* request = webkit_download_get_request(download.get());
g_assert(request);
- CString requestURI = kServer->getURIForPath("/test.pdf");
- g_assert_cmpstr(webkit_uri_request_get_uri(request), ==, requestURI.data());
+ ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, kServer->getURIForPath("/test.pdf"));
g_assert(webkit_download_get_destination(download.get()));
g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), ==, 1);
@@ -352,10 +348,7 @@ static void testDownloadRemoteFile(DownloadTest* test, gconstpointer)
static void testDownloadRemoteFileError(DownloadErrorTest* test, gconstpointer)
{
test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_NETWORK;
- GRefPtr<WebKitDownload> download = adoptGRef(webkit_web_context_download_uri(test->m_webContext,
- kServer->getURIForPath("/foo").data()));
- test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download.get()));
- test->waitUntilDownloadFinishes();
+ GRefPtr<WebKitDownload> download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/foo")));
g_assert(!webkit_download_get_web_view(download.get()));
Vector<DownloadTest::DownloadEvent>& events = test->m_downloadEvents;
@@ -370,12 +363,9 @@ static void testDownloadRemoteFileError(DownloadErrorTest* test, gconstpointer)
g_assert_cmpfloat(webkit_download_get_estimated_progress(download.get()), <, 1);
test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_DESTINATION;
- download = adoptGRef(webkit_web_context_download_uri(test->m_webContext, kServer->getURIForPath("/test.pdf").data()));
- test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download.get()));
- test->waitUntilDownloadFinishes();
+ download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/test.pdf")));
g_assert(!webkit_download_get_web_view(download.get()));
- events = test->m_downloadEvents;
g_assert_cmpint(events.size(), ==, 4);
g_assert_cmpint(events[0], ==, DownloadTest::Started);
g_assert_cmpint(events[1], ==, DownloadTest::ReceivedResponse);
@@ -386,12 +376,9 @@ static void testDownloadRemoteFileError(DownloadErrorTest* test, gconstpointer)
test->checkDestinationAndDeleteFile(download.get(), "bar");
test->m_expectedError = WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER;
- download = adoptGRef(webkit_web_context_download_uri(test->m_webContext, kServer->getURIForPath("/test.pdf").data()));
- test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(download.get()));
- test->waitUntilDownloadFinishes();
+ download = adoptGRef(test->downloadURIAndWaitUntilFinishes(kServer->getURIForPath("/test.pdf")));
g_assert(!webkit_download_get_web_view(download.get()));
- events = test->m_downloadEvents;
g_assert_cmpint(events.size(), ==, 4);
g_assert_cmpint(events[0], ==, DownloadTest::Started);
g_assert_cmpint(events[1], ==, DownloadTest::ReceivedResponse);
@@ -500,8 +487,14 @@ public:
static void testPolicyResponseDownload(PolicyResponseDownloadTest* test, gconstpointer)
{
// Test that a download started by the the policy checker contains the web view.
- test->loadURI(kServer->getURIForPath("/test.pdf").data());
+ CString requestURI = kServer->getURIForPath("/test.pdf").data();
+ test->loadURI(requestURI.data());
test->waitUntilDownloadStarted();
+
+ WebKitURIRequest* request = webkit_download_get_request(test->m_download.get());
+ g_assert(request);
+ ASSERT_CMP_CSTRING(webkit_uri_request_get_uri(request), ==, requestURI);
+
g_assert(test->m_webView == webkit_download_get_web_view(test->m_download.get()));
test->cancelDownloadAndWaitUntilFinished();
}
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestInspector.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestInspector.cpp
index 673749411..aa80888b3 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestInspector.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestInspector.cpp
@@ -59,12 +59,12 @@ public:
return test->detach();
}
+ static const unsigned gMinimumAttachedInspectorWidth = 750;
static const unsigned gMinimumAttachedInspectorHeight = 250;
InspectorTest()
: WebViewTest()
, m_inspector(webkit_web_view_get_inspector(m_webView))
- , m_quitOnBringToFront(false)
{
webkit_settings_set_enable_developer_extras(webkit_web_view_get_settings(m_webView), TRUE);
assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_inspector));
@@ -90,15 +90,13 @@ public:
virtual bool bringToFront()
{
m_events.append(BringToFront);
- if (m_quitOnBringToFront)
- g_main_loop_quit(m_mainLoop);
+ g_main_loop_quit(m_mainLoop);
return FALSE;
}
virtual void closed()
{
m_events.append(Closed);
- g_main_loop_quit(m_mainLoop);
}
virtual bool attach()
@@ -113,18 +111,23 @@ public:
return TRUE;
}
- void showAndWaitUntilFinished(bool quitOnBringToFront)
+
+ static gboolean showIdle(InspectorTest* test)
{
- m_quitOnBringToFront = quitOnBringToFront;
- webkit_web_inspector_show(m_inspector);
+ webkit_web_inspector_show(test->m_inspector);
+ return FALSE;
+ }
+
+ void show()
+ {
+ g_idle_add(reinterpret_cast<GSourceFunc>(showIdle), this);
g_main_loop_run(m_mainLoop);
- m_quitOnBringToFront = false;
}
void resizeViewAndAttach()
{
// Resize the view to make room for the inspector.
- resizeView(300, (gMinimumAttachedInspectorHeight + 1) * 4 / 3);
+ resizeView(gMinimumAttachedInspectorWidth, (gMinimumAttachedInspectorHeight + 1) * 4 / 3);
webkit_web_inspector_attach(m_inspector);
}
@@ -140,14 +143,12 @@ public:
g_main_loop_run(m_mainLoop);
}
- void closeAndWaitUntilClosed()
+ void close()
{
webkit_web_inspector_close(m_inspector);
- g_main_loop_run(m_mainLoop);
}
WebKitWebInspector* m_inspector;
- bool m_quitOnBringToFront;
Vector<InspectorEvents> m_events;
};
@@ -158,7 +159,7 @@ static void testInspectorDefault(InspectorTest* test, gconstpointer)
test->loadHtml("<html><body><p>WebKitGTK+ Inspector test</p></body></html>", 0);
test->waitUntilLoadFinished();
- test->showAndWaitUntilFinished(false);
+ test->show();
// We don't add the view to a container, so consume the weak ref with GRefPtr.
GRefPtr<WebKitWebViewBase> inspectorView = webkit_web_inspector_get_web_view(test->m_inspector);
g_assert(inspectorView.get());
@@ -166,12 +167,11 @@ static void testInspectorDefault(InspectorTest* test, gconstpointer)
g_assert(!webkit_web_inspector_is_attached(test->m_inspector));
g_assert_cmpuint(webkit_web_inspector_get_attached_height(test->m_inspector), ==, 0);
Vector<InspectorTest::InspectorEvents>& events = test->m_events;
- g_assert_cmpint(events.size(), ==, 2);
- g_assert_cmpint(events[0], ==, InspectorTest::BringToFront);
- g_assert_cmpint(events[1], ==, InspectorTest::OpenWindow);
+ g_assert_cmpint(events.size(), ==, 1);
+ g_assert_cmpint(events[0], ==, InspectorTest::OpenWindow);
test->m_events.clear();
- test->showAndWaitUntilFinished(true);
+ test->show();
events = test->m_events;
g_assert_cmpint(events.size(), ==, 1);
g_assert_cmpint(events[0], ==, InspectorTest::BringToFront);
@@ -193,7 +193,7 @@ static void testInspectorDefault(InspectorTest* test, gconstpointer)
g_assert_cmpint(events[1], ==, InspectorTest::OpenWindow);
test->m_events.clear();
- test->closeAndWaitUntilClosed();
+ test->close();
events = test->m_events;
g_assert_cmpint(events.size(), ==, 1);
g_assert_cmpint(events[0], ==, InspectorTest::Closed);
@@ -272,12 +272,11 @@ public:
return InspectorTest::detach();
}
- void destroyWindowAndWaitUntilClosed()
+ void destroyWindow()
{
g_assert(m_inspectorWindow);
gtk_widget_destroy(m_inspectorWindow);
m_inspectorWindow = 0;
- g_main_loop_run(m_mainLoop);
}
GtkWidget* m_inspectorWindow;
@@ -290,13 +289,12 @@ static void testInspectorManualAttachDetach(CustomInspectorTest* test, gconstpoi
test->loadHtml("<html><body><p>WebKitGTK+ Inspector test</p></body></html>", 0);
test->waitUntilLoadFinished();
- test->showAndWaitUntilFinished(false);
+ test->show();
test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_web_inspector_get_web_view(test->m_inspector)));
g_assert(!webkit_web_inspector_is_attached(test->m_inspector));
Vector<InspectorTest::InspectorEvents>& events = test->m_events;
- g_assert_cmpint(events.size(), ==, 2);
- g_assert_cmpint(events[0], ==, InspectorTest::BringToFront);
- g_assert_cmpint(events[1], ==, InspectorTest::OpenWindow);
+ g_assert_cmpint(events.size(), ==, 1);
+ g_assert_cmpint(events[0], ==, InspectorTest::OpenWindow);
test->m_events.clear();
test->resizeViewAndAttach();
@@ -318,7 +316,7 @@ static void testInspectorManualAttachDetach(CustomInspectorTest* test, gconstpoi
test->resizeViewAndAttach();
g_assert(webkit_web_inspector_is_attached(test->m_inspector));
test->m_events.clear();
- test->closeAndWaitUntilClosed();
+ test->close();
events = test->m_events;
g_assert_cmpint(events.size(), ==, 2);
g_assert_cmpint(events[0], ==, InspectorTest::Detach);
@@ -333,12 +331,12 @@ static void testInspectorCustomContainerDestroyed(CustomInspectorTest* test, gco
test->loadHtml("<html><body><p>WebKitGTK+ Inspector test</p></body></html>", 0);
test->waitUntilLoadFinished();
- test->showAndWaitUntilFinished(false);
+ test->show();
test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webkit_web_inspector_get_web_view(test->m_inspector)));
g_assert(!webkit_web_inspector_is_attached(test->m_inspector));
test->m_events.clear();
- test->destroyWindowAndWaitUntilClosed();
+ test->destroyWindow();
Vector<InspectorTest::InspectorEvents>& events = test->m_events;
g_assert_cmpint(events.size(), ==, 1);
g_assert_cmpint(events[0], ==, InspectorTest::Closed);
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestInspectorServer.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestInspectorServer.cpp
index 30d8fac0c..35fb3fcdc 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestInspectorServer.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestInspectorServer.cpp
@@ -73,12 +73,7 @@ static gpointer testServerMonitorThreadFunc(gpointer)
static void startTestServerMonitor()
{
gChildIsReady = false;
-
-#if (!GLIB_CHECK_VERSION(2, 31, 0))
- g_thread_create(testServerMonitorThreadFunc, 0, FALSE, 0);
-#else
g_thread_new("TestServerMonitor", testServerMonitorThreadFunc, 0);
-#endif
}
static void startTestServer()
@@ -189,8 +184,8 @@ static void testInspectorServerPageList(InspectorServerTest* test, gconstpointer
g_assert(javascriptResult);
g_assert(!error.get());
valueString.set(WebViewTest::javascriptResultToCString(javascriptResult));
- String validInspectorURL = String("/webinspector/inspector.html?page=") + String::number(pageId);
- g_assert_cmpstr(valueString.get(), ==, validInspectorURL.utf8().data());
+ String validInspectorURL = String("/inspector.html?page=") + String::number(pageId);
+ ASSERT_CMP_CSTRING(valueString.get(), ==, validInspectorURL.utf8());
}
// Test sending a raw remote debugging message through our web socket server.
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp
index 8fcf33009..331915e00 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestLoaderClient.cpp
@@ -22,13 +22,18 @@
#include "config.h"
#include "LoadTrackingTest.h"
+#include "WebKitTestBus.h"
#include "WebKitTestServer.h"
+#include "WebViewTest.h"
#include <gtk/gtk.h>
#include <libsoup/soup.h>
#include <wtf/text/CString.h>
+static WebKitTestBus* bus;
static WebKitTestServer* kServer;
+const char* kDNTHeaderNotPresent = "DNT header not present";
+
static void testLoadingStatus(LoadTrackingTest* test, gconstpointer data)
{
test->setRedirectURI(kServer->getURIForPath("/normal").data());
@@ -214,9 +219,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));
}
};
@@ -282,6 +285,105 @@ static void testWebViewIsLoading(ViewIsLoadingTest* test, gconstpointer)
test->waitUntilLoadFinished();
}
+class WebPageURITest: public WebViewTest {
+public:
+ MAKE_GLIB_TEST_FIXTURE(WebPageURITest);
+
+ static void webPageURIChangedCallback(GDBusConnection*, const char*, const char*, const char*, const char*, GVariant* result, WebPageURITest* test)
+ {
+ const char* uri;
+ g_variant_get(result, "(&s)", &uri);
+ test->m_webPageURIs.append(uri);
+ }
+
+ static void webViewURIChanged(GObject*, GParamSpec*, WebPageURITest* test)
+ {
+ test->m_webViewURIs.append(webkit_web_view_get_uri(test->m_webView));
+ }
+
+ WebPageURITest()
+ {
+ GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy("org.webkit.gtk.WebExtensionTest",
+ "/org/webkit/gtk/WebExtensionTest", "org.webkit.gtk.WebExtensionTest", m_mainLoop));
+ m_uriChangedSignalID = g_dbus_connection_signal_subscribe(
+ g_dbus_proxy_get_connection(proxy.get()),
+ 0,
+ "org.webkit.gtk.WebExtensionTest",
+ "URIChanged",
+ "/org/webkit/gtk/WebExtensionTest",
+ 0,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ reinterpret_cast<GDBusSignalCallback>(webPageURIChangedCallback),
+ this,
+ 0);
+ g_assert(m_uriChangedSignalID);
+
+ g_signal_connect(m_webView, "notify::uri", G_CALLBACK(webViewURIChanged), this);
+ }
+
+ ~WebPageURITest()
+ {
+ g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this);
+ g_dbus_connection_signal_unsubscribe(bus->connection(), m_uriChangedSignalID);
+ }
+
+ unsigned m_uriChangedSignalID;
+ Vector<CString> m_webPageURIs;
+ Vector<CString> m_webViewURIs;
+};
+
+static void testWebPageURI(WebPageURITest* test, gconstpointer)
+{
+ test->loadURI(kServer->getURIForPath("/redirect").data());
+ test->waitUntilLoadFinished();
+
+ g_assert_cmpint(test->m_webPageURIs.size(), ==, test->m_webViewURIs.size());
+ for (size_t i = 0; i < test->m_webPageURIs.size(); ++i)
+ ASSERT_CMP_CSTRING(test->m_webPageURIs[i], ==, test->m_webViewURIs[i]);
+
+ g_assert_cmpint(test->m_webPageURIs.size(), ==, 2);
+ ASSERT_CMP_CSTRING(test->m_webPageURIs[0], ==, kServer->getURIForPath("/redirect"));
+ ASSERT_CMP_CSTRING(test->m_webPageURIs[1], ==, kServer->getURIForPath("/normal"));
+
+}
+
+static void testURIRequestHTTPHeaders(WebViewTest* test, gconstpointer)
+{
+ GRefPtr<WebKitURIRequest> uriRequest = adoptGRef(webkit_uri_request_new("file:///foo/bar"));
+ g_assert(uriRequest.get());
+ g_assert_cmpstr(webkit_uri_request_get_uri(uriRequest.get()), ==, "file:///foo/bar");
+ g_assert(!webkit_uri_request_get_http_headers(uriRequest.get()));
+
+ // Load a request with no Do Not Track header.
+ webkit_uri_request_set_uri(uriRequest.get(), kServer->getURIForPath("/do-not-track-header").data());
+ test->loadRequest(uriRequest.get());
+ test->waitUntilLoadFinished();
+
+ size_t mainResourceDataSize = 0;
+ const char* mainResourceData = test->mainResourceData(mainResourceDataSize);
+ g_assert_cmpint(mainResourceDataSize, ==, strlen(kDNTHeaderNotPresent));
+ g_assert(!strncmp(mainResourceData, kDNTHeaderNotPresent, mainResourceDataSize));
+
+ // Add the Do Not Track header and load the request again.
+ SoupMessageHeaders* headers = webkit_uri_request_get_http_headers(uriRequest.get());
+ g_assert(headers);
+ soup_message_headers_append(headers, "DNT", "1");
+ test->loadRequest(uriRequest.get());
+ test->waitUntilLoadFinished();
+
+ mainResourceData = test->mainResourceData(mainResourceDataSize);
+ g_assert_cmpint(mainResourceDataSize, ==, 1);
+ g_assert(!strncmp(mainResourceData, "1", mainResourceDataSize));
+
+ // Load a URI for which the web extension will add the Do Not Track header.
+ test->loadURI(kServer->getURIForPath("/add-do-not-track-header").data());
+ test->waitUntilLoadFinished();
+
+ mainResourceData = test->mainResourceData(mainResourceDataSize);
+ g_assert_cmpint(mainResourceDataSize, ==, 1);
+ g_assert(!strncmp(mainResourceData, "1", mainResourceDataSize));
+}
+
static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
{
static const char* responseString = "<html><body>Testing!Testing!Testing!Testing!Testing!Testing!Testing!"
@@ -312,6 +414,13 @@ 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 if (g_str_equal(path, "/do-not-track-header") || g_str_equal(path, "/add-do-not-track-header")) {
+ const char* doNotTrack = soup_message_headers_get_one(message->request_headers, "DNT");
+ if (doNotTrack)
+ soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, doNotTrack, strlen(doNotTrack));
+ else
+ soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kDNTHeaderNotPresent, strlen(kDNTHeaderNotPresent));
+ soup_message_set_status(message, SOUP_STATUS_OK);
} else
soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
@@ -320,6 +429,11 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
void beforeAll()
{
+ webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), WEBKIT_TEST_WEB_EXTENSIONS_DIR);
+ bus = new WebKitTestBus();
+ if (!bus->run())
+ return;
+
kServer = new WebKitTestServer();
kServer->run(serverCallback);
@@ -340,9 +454,12 @@ void beforeAll()
ViewURITrackingTest::add("WebKitWebView", "active-uri", testWebViewActiveURI);
ViewIsLoadingTest::add("WebKitWebView", "is-loading", testWebViewIsLoading);
+ WebPageURITest::add("WebKitWebPage", "get-uri", testWebPageURI);
+ WebViewTest::add("WebKitURIRequest", "http-headers", testURIRequestHTTPHeaders);
}
void afterAll()
{
+ delete bus;
delete kServer;
}
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp
index 2044ab52e..6ac35f8ca 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp
@@ -20,7 +20,10 @@
#include "config.h"
#include "TestMain.h"
+#include <glib/gstdio.h>
#include <gtk/gtk.h>
+#include <webkit2/webkit2.h>
+#include <wtf/gobject/GOwnPtr.h>
void beforeAll();
void afterAll();
@@ -35,17 +38,38 @@ static void registerGResource(void)
g_resource_unref(resource);
}
+static void removeNonEmptyDirectory(const char* directoryPath)
+{
+ GDir* directory = g_dir_open(directoryPath, 0, 0);
+ g_assert(directory);
+ const char* fileName;
+ while ((fileName = g_dir_read_name(directory))) {
+ GOwnPtr<char> filePath(g_build_filename(directoryPath, fileName, NULL));
+ g_unlink(filePath.get());
+ }
+ g_dir_close(directory);
+ g_rmdir(directoryPath);
+}
+
int main(int argc, char** argv)
{
gtk_test_init(&argc, &argv, 0);
g_setenv("WEBKIT_EXEC_PATH", WEBKIT_EXEC_PATH, FALSE);
+ g_setenv("WEBKIT_INJECTED_BUNDLE_PATH", WEBKIT_INJECTED_BUNDLE_PATH, FALSE);
+ g_setenv("LC_ALL", "C", TRUE);
g_test_bug_base("https://bugs.webkit.org/");
registerGResource();
+ GOwnPtr<char> diskCacheTempDirectory(g_dir_make_tmp("WebKit2TestsDiskCache-XXXXXX", 0));
+ g_assert(diskCacheTempDirectory.get());
+ webkit_web_context_set_disk_cache_directory(webkit_web_context_get_default(), diskCacheTempDirectory.get());
+
beforeAll();
int returnValue = g_test_run();
afterAll();
+ removeNonEmptyDirectory(diskCacheTempDirectory.get());
+
return returnValue;
}
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h
index 6fe9de86d..02c90709c 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h
@@ -20,6 +20,7 @@
#ifndef TestMain_h
#define TestMain_h
+#include <cairo.h>
#include <glib-object.h>
#include <wtf/HashSet.h>
#include <wtf/gobject/GOwnPtr.h>
@@ -40,6 +41,12 @@
g_test_add(testPath.get(), ClassName, 0, ClassName::setUp, testFunc, ClassName::tearDown); \
}
+#define ASSERT_CMP_CSTRING(s1, cmp, s2) \
+ do { CString __s1 = (s1); CString __s2 = (s2); \
+ if (g_strcmp0(__s1.data(), __s2.data()) cmp 0) ; else \
+ g_assertion_message_cmpstr(G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
+ #s1 " " #cmp " " #s2, __s1.data(), #cmp, __s2.data()); } while (0)
+
class Test {
public:
MAKE_GLIB_TEST_FIXTURE(Test);
@@ -95,6 +102,17 @@ public:
g_log_set_always_fatal(static_cast<GLogLevelFlags>(fatalMask));
}
+ static bool cairoSurfacesEqual(cairo_surface_t* s1, cairo_surface_t* s2)
+ {
+ return (cairo_image_surface_get_format(s1) == cairo_image_surface_get_format(s2)
+ && cairo_image_surface_get_width(s1) == cairo_image_surface_get_width(s2)
+ && cairo_image_surface_get_height(s1) == cairo_image_surface_get_height(s2)
+ && cairo_image_surface_get_stride(s1) == cairo_image_surface_get_stride(s2)
+ && !memcmp(const_cast<const void*>(reinterpret_cast<void*>(cairo_image_surface_get_data(s1))),
+ const_cast<const void*>(reinterpret_cast<void*>(cairo_image_surface_get_data(s2))),
+ cairo_image_surface_get_height(s1)*cairo_image_surface_get_stride(s1)));
+ }
+
HashSet<GObject*> m_watchedObjects;
};
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp
index 123831f76..72c2cfbbd 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestPrinting.cpp
@@ -146,7 +146,7 @@ static void testPrintOperationPrint(PrintTest* test, gconstpointer)
webkit_print_operation_print(test->m_printOperation.get());
test->waitUntilPrintFinished();
- GRefPtr<GFileInfo> fileInfo = adoptGRef(g_file_query_info(outputFile.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE","G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ GRefPtr<GFileInfo> fileInfo = adoptGRef(g_file_query_info(outputFile.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
static_cast<GFileQueryInfoFlags>(0), 0, 0));
g_assert(fileInfo.get());
g_assert_cmpint(g_file_info_get_size(fileInfo.get()), >, 0);
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()
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp
index 8fa013dc4..db6ccc852 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestSSL.cpp
@@ -23,8 +23,11 @@
#include "WebKitTestServer.h"
#include <gtk/gtk.h>
-static WebKitTestServer* kServer;
+static WebKitTestServer* kHttpsServer;
+static WebKitTestServer* kHttpServer;
+
static const char* indexHTML = "<html><body>Testing WebKit2GTK+ SSL</body></htmll>";
+static const char* insecureContentHTML = "<html><script src=\"%s\"></script><body><p>Text + image <img src=\"%s\" align=\"right\"/></p></body></html>";
class SSLTest: public LoadTrackingTest {
public:
@@ -35,16 +38,18 @@ public:
{
}
- virtual void loadCommitted()
+ virtual void provisionalLoadFailed(const gchar* failingURI, GError* error)
{
- WebKitWebResource* resource = webkit_web_view_get_main_resource(m_webView);
- g_assert(resource);
- WebKitURIResponse* response = webkit_web_resource_get_response(resource);
- g_assert(response);
+ g_assert_error(error, SOUP_HTTP_ERROR, SOUP_STATUS_SSL_FAILED);
+ LoadTrackingTest::provisionalLoadFailed(failingURI, error);
+ }
+ virtual void loadCommitted()
+ {
GTlsCertificate* certificate = 0;
- webkit_uri_response_get_https_status(response, &certificate, &m_tlsErrors);
+ webkit_web_view_get_tls_info(m_webView, &certificate, &m_tlsErrors);
m_certificate = certificate;
+ LoadTrackingTest::loadCommitted();
}
void waitUntilLoadFinished()
@@ -60,7 +65,7 @@ public:
static void testSSL(SSLTest* test, gconstpointer)
{
- test->loadURI(kServer->getURIForPath("/").data());
+ test->loadURI(kHttpsServer->getURIForPath("/").data());
test->waitUntilLoadFinished();
g_assert(test->m_certificate);
// We always expect errors because we are using a self-signed certificate,
@@ -75,7 +80,59 @@ static void testSSL(SSLTest* test, gconstpointer)
g_assert(!test->m_tlsErrors);
}
-static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
+class InsecureContentTest: public WebViewTest {
+public:
+ MAKE_GLIB_TEST_FIXTURE(InsecureContentTest);
+
+ InsecureContentTest()
+ : m_insecureContentRun(false)
+ , m_insecureContentDisplayed(false)
+ {
+ g_signal_connect(m_webView, "insecure-content-detected", G_CALLBACK(insecureContentDetectedCallback), this);
+ }
+
+ static void insecureContentDetectedCallback(WebKitWebView* webView, WebKitInsecureContentEvent event, InsecureContentTest* test)
+ {
+ g_assert(webView == test->m_webView);
+
+ if (event == WEBKIT_INSECURE_CONTENT_RUN)
+ test->m_insecureContentRun = true;
+
+ if (event == WEBKIT_INSECURE_CONTENT_DISPLAYED)
+ test->m_insecureContentDisplayed = true;
+ }
+
+ bool m_insecureContentRun;
+ bool m_insecureContentDisplayed;
+};
+
+static void testInsecureContent(InsecureContentTest* test, gconstpointer)
+{
+ test->loadURI(kHttpsServer->getURIForPath("/insecure-content/").data());
+ test->waitUntilLoadFinished();
+
+ g_assert(test->m_insecureContentRun);
+ g_assert(test->m_insecureContentDisplayed);
+}
+
+static void testTLSErrorsPolicy(SSLTest* test, gconstpointer)
+{
+ WebKitWebContext* context = webkit_web_view_get_context(test->m_webView);
+ // TLS errors are ignored by default.
+ g_assert(webkit_web_context_get_tls_errors_policy(context) == WEBKIT_TLS_ERRORS_POLICY_IGNORE);
+ test->loadURI(kHttpsServer->getURIForPath("/").data());
+ test->waitUntilLoadFinished();
+ g_assert(!test->m_loadFailed);
+
+ webkit_web_context_set_tls_errors_policy(context, WEBKIT_TLS_ERRORS_POLICY_FAIL);
+ test->loadURI(kHttpsServer->getURIForPath("/").data());
+ test->waitUntilLoadFinished();
+ g_assert(test->m_loadFailed);
+ g_assert(test->m_loadEvents.contains(LoadTrackingTest::ProvisionalLoadFailed));
+ g_assert(!test->m_loadEvents.contains(LoadTrackingTest::LoadCommitted));
+}
+
+static void httpsServerCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
{
if (message->method != SOUP_METHOD_GET) {
soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
@@ -86,19 +143,59 @@ static void serverCallback(SoupServer* server, SoupMessage* message, const char*
soup_message_set_status(message, SOUP_STATUS_OK);
soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, indexHTML, strlen(indexHTML));
soup_message_body_complete(message->response_body);
+ } else if (g_str_equal(path, "/insecure-content/")) {
+ GOwnPtr<char> responseHTML(g_strdup_printf(insecureContentHTML, kHttpServer->getURIForPath("/test-script").data(), kHttpServer->getURIForPath("/test-image").data()));
+ soup_message_body_append(message->response_body, SOUP_MEMORY_COPY, responseHTML.get(), strlen(responseHTML.get()));
+ soup_message_set_status(message, SOUP_STATUS_OK);
+ soup_message_body_complete(message->response_body);
+ } else
+ soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
+}
+
+static void httpServerCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
+{
+ if (message->method != SOUP_METHOD_GET) {
+ soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
+ return;
+ }
+
+ if (g_str_equal(path, "/test-script")) {
+ GOwnPtr<char> pathToFile(g_build_filename(Test::getResourcesDir().data(), "link-title.js", NULL));
+ char* contents;
+ gsize length;
+ g_file_get_contents(pathToFile.get(), &contents, &length, 0);
+
+ soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length);
+ soup_message_set_status(message, SOUP_STATUS_OK);
+ soup_message_body_complete(message->response_body);
+ } else if (g_str_equal(path, "/test-image")) {
+ GOwnPtr<char> pathToFile(g_build_filename(Test::getWebKit1TestResoucesDir().data(), "blank.ico", NULL));
+ char* contents;
+ gsize length;
+ g_file_get_contents(pathToFile.get(), &contents, &length, 0);
+
+ soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length);
+ soup_message_set_status(message, SOUP_STATUS_OK);
+ soup_message_body_complete(message->response_body);
} else
soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
}
void beforeAll()
{
- kServer = new WebKitTestServer(WebKitTestServer::ServerHTTPS);
- kServer->run(serverCallback);
+ kHttpsServer = new WebKitTestServer(WebKitTestServer::ServerHTTPS);
+ kHttpsServer->run(httpsServerCallback);
+
+ kHttpServer = new WebKitTestServer(WebKitTestServer::ServerHTTP);
+ kHttpServer->run(httpServerCallback);
SSLTest::add("WebKitWebView", "ssl", testSSL);
+ InsecureContentTest::add("WebKitWebView", "insecure-content", testInsecureContent);
+ SSLTest::add("WebKitWebContext", "tls-errors-policy", testTLSErrorsPolicy);
}
void afterAll()
{
- delete kServer;
+ delete kHttpsServer;
+ delete kHttpServer;
}
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebExtensions.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebExtensions.cpp
new file mode 100644
index 000000000..527cc936c
--- /dev/null
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebExtensions.cpp
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2,1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include "WebKitTestBus.h"
+#include "WebViewTest.h"
+#include <wtf/gobject/GRefPtr.h>
+
+static WebKitTestBus* bus;
+
+static void testWebExtensionGetTitle(WebViewTest* test, gconstpointer)
+{
+ test->loadHtml("<html><head><title>WebKitGTK+ Web Extensions Test</title></head><body></body></html>", 0);
+ test->waitUntilLoadFinished();
+
+ GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy("org.webkit.gtk.WebExtensionTest",
+ "/org/webkit/gtk/WebExtensionTest" , "org.webkit.gtk.WebExtensionTest", test->m_mainLoop));
+ GRefPtr<GVariant> result = adoptGRef(g_dbus_proxy_call_sync(
+ proxy.get(),
+ "GetTitle",
+ g_variant_new("(t)", webkit_web_view_get_page_id(test->m_webView)),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, 0, 0));
+ g_assert(result);
+
+ const char* title;
+ g_variant_get(result.get(), "(&s)", &title);
+ g_assert_cmpstr(title, ==, "WebKitGTK+ Web Extensions Test");
+}
+
+static void documentLoadedCallback(GDBusConnection*, const char*, const char*, const char*, const char*, GVariant*, WebViewTest* test)
+{
+ g_main_loop_quit(test->m_mainLoop);
+}
+
+static void testDocumentLoadedSignal(WebViewTest* test, gconstpointer)
+{
+ GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy("org.webkit.gtk.WebExtensionTest",
+ "/org/webkit/gtk/WebExtensionTest", "org.webkit.gtk.WebExtensionTest", test->m_mainLoop));
+ GDBusConnection* connection = g_dbus_proxy_get_connection(proxy.get());
+ guint id = g_dbus_connection_signal_subscribe(connection,
+ 0,
+ "org.webkit.gtk.WebExtensionTest",
+ "DocumentLoaded",
+ "/org/webkit/gtk/WebExtensionTest",
+ 0,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ reinterpret_cast<GDBusSignalCallback>(documentLoadedCallback),
+ test,
+ 0);
+ g_assert(id);
+
+ test->loadHtml("<html><head><title>WebKitGTK+ Web Extensions Test</title></head><body></body></html>", 0);
+ g_main_loop_run(test->m_mainLoop);
+ g_dbus_connection_signal_unsubscribe(connection, id);
+}
+
+static gboolean webProcessCrashedCallback(WebKitWebView*, WebViewTest* test)
+{
+ test->quitMainLoop();
+
+ return FALSE;
+}
+
+static void testWebKitWebViewProcessCrashed(WebViewTest* test, gconstpointer)
+{
+ test->loadHtml("<html></html>", 0);
+ test->waitUntilLoadFinished();
+
+ g_signal_connect(test->m_webView, "web-process-crashed",
+ G_CALLBACK(webProcessCrashedCallback), test);
+
+ GRefPtr<GDBusProxy> proxy = adoptGRef(bus->createProxy("org.webkit.gtk.WebExtensionTest",
+ "/org/webkit/gtk/WebExtensionTest", "org.webkit.gtk.WebExtensionTest", test->m_mainLoop));
+
+ GRefPtr<GVariant> result = adoptGRef(g_dbus_proxy_call_sync(
+ proxy.get(),
+ "AbortProcess",
+ 0,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, 0, 0));
+ g_assert(!result);
+ g_main_loop_run(test->m_mainLoop);
+}
+
+void beforeAll()
+{
+ webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), WEBKIT_TEST_WEB_EXTENSIONS_DIR);
+ bus = new WebKitTestBus();
+ if (!bus->run())
+ return;
+
+ WebViewTest::add("WebKitWebExtension", "dom-document-title", testWebExtensionGetTitle);
+ WebViewTest::add("WebKitWebExtension", "document-loaded-signal", testDocumentLoadedSignal);
+ WebViewTest::add("WebKitWebView", "web-process-crashed", testWebKitWebViewProcessCrashed);
+}
+
+void afterAll()
+{
+ delete bus;
+}
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitAccessibility.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitAccessibility.cpp
index 3db9094a5..d3750c005 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitAccessibility.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitAccessibility.cpp
@@ -81,12 +81,7 @@ static gpointer testServerMonitorThreadFunc(gpointer)
static void startTestServerMonitor()
{
kChildIsReady = false;
-
-#if (!GLIB_CHECK_VERSION(2, 31, 0))
- g_thread_create(testServerMonitorThreadFunc, 0, FALSE, 0);
-#else
g_thread_new("TestServerMonitor", testServerMonitorThreadFunc, 0);
-#endif
}
static void startTestServer()
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp
index ac13e4d07..1a06f7496 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFaviconDatabase.cpp
@@ -133,7 +133,7 @@ serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHash
soup_message_body_complete(message->response_body);
}
-static void testNotInitialized(FaviconDatabaseTest* test, gconstpointer)
+static void testNotInitialized(FaviconDatabaseTest* test)
{
// Try to retrieve a valid favicon from a not initialized database.
test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/foo").data());
@@ -142,22 +142,22 @@ static void testNotInitialized(FaviconDatabaseTest* test, gconstpointer)
g_assert_cmpint(test->m_error->code, ==, WEBKIT_FAVICON_DATABASE_ERROR_NOT_INITIALIZED);
}
-static void testSetDirectory(FaviconDatabaseTest* test, gconstpointer)
+static void testSetDirectory(FaviconDatabaseTest* test)
{
webkit_web_context_set_favicon_database_directory(test->m_webContext, kTempDirectory);
g_assert_cmpstr(kTempDirectory, ==, webkit_web_context_get_favicon_database_directory(test->m_webContext));
}
-static void testClearDatabase(FaviconDatabaseTest* test, gconstpointer)
+static void testClearDatabase(FaviconDatabaseTest* test)
{
WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext);
webkit_favicon_database_clear(database);
- GOwnPtr<char> iconURI(webkit_favicon_database_get_favicon_uri(database, kServer->getURIForPath("/").data()));
+ GOwnPtr<char> iconURI(webkit_favicon_database_get_favicon_uri(database, kServer->getURIForPath("/foo").data()));
g_assert(!iconURI);
}
-static void testGetFavicon(FaviconDatabaseTest* test, gconstpointer)
+static void testGetFavicon(FaviconDatabaseTest* test)
{
// We need to load the page first to ensure the icon data will be
// in the database in case there's an associated favicon.
@@ -198,17 +198,19 @@ static void testGetFavicon(FaviconDatabaseTest* test, gconstpointer)
g_assert(test->m_error);
}
-static void testGetFaviconURI(FaviconDatabaseTest* test, gconstpointer)
+static void testGetFaviconURI(FaviconDatabaseTest* test)
{
WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext);
- const char* baseURI = kServer->getURIForPath("/foo").data();
- GOwnPtr<char> iconURI(webkit_favicon_database_get_favicon_uri(database, baseURI));
- g_assert_cmpstr(iconURI.get(), ==, kServer->getURIForPath("/icon/favicon.ico").data());
+ CString baseURI = kServer->getURIForPath("/foo");
+ GOwnPtr<char> iconURI(webkit_favicon_database_get_favicon_uri(database, baseURI.data()));
+ ASSERT_CMP_CSTRING(iconURI.get(), ==, kServer->getURIForPath("/icon/favicon.ico"));
}
-static void testWebViewFavicon(FaviconDatabaseTest* test, gconstpointer)
+static void testWebViewFavicon(FaviconDatabaseTest* test)
{
+ test->m_faviconURI = CString();
+
cairo_surface_t* iconFromWebView = webkit_web_view_get_favicon(test->m_webView);
g_assert(!iconFromWebView);
@@ -225,6 +227,18 @@ static void testWebViewFavicon(FaviconDatabaseTest* test, gconstpointer)
g_assert_cmpuint(cairo_image_surface_get_height(iconFromWebView), ==, 16);
}
+static void testFaviconDatabase(FaviconDatabaseTest* test, gconstpointer)
+{
+ // These tests depend on this order to run properly so we declare them in a single one.
+ // See https://bugs.webkit.org/show_bug.cgi?id=111434.
+ testNotInitialized(test);
+ testSetDirectory(test);
+ testGetFavicon(test);
+ testGetFaviconURI(test);
+ testWebViewFavicon(test);
+ testClearDatabase(test);
+}
+
void beforeAll()
{
// Start a soup server for testing.
@@ -235,12 +249,7 @@ void beforeAll()
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("WebKitWebView", "favicon", testWebViewFavicon);
- FaviconDatabaseTest::add("WebKitFaviconDatabase", "clear-database", testClearDatabase);
+ FaviconDatabaseTest::add("WebKitFaviconDatabase", "favicon-database-test", testFaviconDatabase);
}
static void webkitFaviconDatabaseFinalizedCallback(gpointer, GObject*)
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp
index 90159b87f..d2eef4ca4 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitFindController.cpp
@@ -62,12 +62,6 @@ public:
g_main_loop_run(m_mainLoop);
}
- void waitUntilWebViewDrawSignal()
- {
- g_signal_connect_after(m_webView, "draw", G_CALLBACK(webViewDraw), this);
- g_main_loop_run(m_mainLoop);
- }
-
GRefPtr<WebKitFindController> m_findController;
bool m_textFound;
unsigned m_matchCount;
@@ -75,12 +69,6 @@ public:
private:
bool m_runFindUntilCompletion;
- static void webViewDraw(GtkWidget *widget, cairo_t *cr, FindControllerTest* test)
- {
- g_main_loop_quit(test->m_mainLoop);
- g_signal_handlers_disconnect_matched(widget, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, test);
- }
-
static void foundTextCallback(WebKitFindController*, guint matchCount, FindControllerTest* test)
{
test->m_textFound = true;
@@ -271,67 +259,38 @@ static void testFindControllerOptions(FindControllerTest* test, gconstpointer)
g_assert(test->m_textFound);
}
-static gboolean gdkPixbufEqual(GdkPixbuf* firstPixbuf, GdkPixbuf* secondPixbuf)
-{
- if (gdk_pixbuf_get_bits_per_sample(firstPixbuf) != gdk_pixbuf_get_bits_per_sample(secondPixbuf)
- || gdk_pixbuf_get_has_alpha(firstPixbuf) != gdk_pixbuf_get_has_alpha(secondPixbuf)
- || gdk_pixbuf_get_height(firstPixbuf) != gdk_pixbuf_get_height(secondPixbuf)
- || gdk_pixbuf_get_n_channels(firstPixbuf) != gdk_pixbuf_get_n_channels(secondPixbuf)
- || gdk_pixbuf_get_rowstride(firstPixbuf) != gdk_pixbuf_get_rowstride(secondPixbuf)
- || gdk_pixbuf_get_width(firstPixbuf) != gdk_pixbuf_get_width(secondPixbuf))
- return FALSE;
-
- int pixbufRowstride = gdk_pixbuf_get_rowstride(firstPixbuf);
- int pixbufHeight = gdk_pixbuf_get_height(firstPixbuf);
- int pixbufWidth = gdk_pixbuf_get_width(firstPixbuf);
- int numberOfChannels = gdk_pixbuf_get_n_channels(firstPixbuf);
- int bitsPerSample = gdk_pixbuf_get_bits_per_sample(firstPixbuf);
-
- // Last row can be of different length. Taken from gdk-pixbuf documentation.
- int totalLength = (pixbufHeight - 1) * pixbufRowstride \
- + pixbufWidth * ((numberOfChannels * bitsPerSample + 7) / 8);
-
- guchar* firstPixels = gdk_pixbuf_get_pixels(firstPixbuf);
- guchar* secondPixels = gdk_pixbuf_get_pixels(secondPixbuf);
- for (int i = 0; i < totalLength; i++)
- if (firstPixels[i] != secondPixels[i])
- return FALSE;
-
- return TRUE;
-}
-
static void testFindControllerHide(FindControllerTest* test, gconstpointer)
{
test->loadHtml(testString, 0);
test->waitUntilLoadFinished();
test->showInWindowAndWaitUntilMapped();
- int allocatedHeight = gtk_widget_get_allocated_height(GTK_WIDGET(test->m_webView));
- int allocatedWidth = gtk_widget_get_allocated_width(GTK_WIDGET(test->m_webView));
- GdkWindow* webViewGdkWindow = gtk_widget_get_window(GTK_WIDGET(test->m_webView));
- g_assert(webViewGdkWindow);
- test->waitUntilWebViewDrawSignal();
- GRefPtr<GdkPixbuf> originalPixbuf = adoptGRef(gdk_pixbuf_get_from_window(webViewGdkWindow, 0, 0, allocatedHeight, allocatedWidth));
- g_assert(originalPixbuf);
+ cairo_surface_t* originalSurface = cairo_surface_reference(
+ test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE));
+ g_assert(originalSurface);
test->find("testing", WEBKIT_FIND_OPTIONS_NONE, 1);
test->waitUntilFindFinished();
g_assert(test->m_textFound);
- test->waitUntilWebViewDrawSignal();
- GRefPtr<GdkPixbuf> highlightPixbuf = adoptGRef(gdk_pixbuf_get_from_window(webViewGdkWindow, 0, 0, allocatedHeight, allocatedWidth));
- g_assert(highlightPixbuf);
- g_assert(!gdkPixbufEqual(originalPixbuf.get(), highlightPixbuf.get()));
+ cairo_surface_t* highlightSurface = cairo_surface_reference(
+ test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE));
+ g_assert(highlightSurface);
+ g_assert(!Test::cairoSurfacesEqual(originalSurface, highlightSurface));
WebKitFindController* findController = webkit_web_view_get_find_controller(test->m_webView);
webkit_find_controller_search_finish(findController);
webkit_web_view_execute_editing_command(test->m_webView, "Unselect");
- test->waitUntilWebViewDrawSignal();
- GRefPtr<GdkPixbuf> unhighlightPixbuf = adoptGRef(gdk_pixbuf_get_from_window(webViewGdkWindow, 0, 0, allocatedHeight, allocatedWidth));
- g_assert(unhighlightPixbuf);
- g_assert(gdkPixbufEqual(originalPixbuf.get(), unhighlightPixbuf.get()));
+ cairo_surface_t* unhighlightSurface = cairo_surface_reference(
+ test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE));
+ g_assert(unhighlightSurface);
+ g_assert(Test::cairoSurfacesEqual(originalSurface, unhighlightSurface));
+
+ cairo_surface_destroy(originalSurface);
+ cairo_surface_destroy(highlightSurface);
+ cairo_surface_destroy(unhighlightSurface);
}
static void testFindControllerInstance(FindControllerTest* test, gconstpointer)
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp
index c7a0dc259..1ee3843f9 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp
@@ -248,6 +248,16 @@ static void testWebKitSettings(Test*, gconstpointer)
webkit_settings_set_enable_smooth_scrolling(settings, TRUE);
g_assert(webkit_settings_get_enable_smooth_scrolling(settings));
+ // By default, accelerated 2D canvas is disabled.
+ g_assert(!webkit_settings_get_enable_accelerated_2d_canvas(settings));
+ webkit_settings_set_enable_accelerated_2d_canvas(settings, TRUE);
+ g_assert(webkit_settings_get_enable_accelerated_2d_canvas(settings));
+
+ // By default, writing of console messages to stdout is disabled.
+ g_assert(!webkit_settings_get_enable_write_console_messages_to_stdout(settings));
+ webkit_settings_set_enable_write_console_messages_to_stdout(settings, TRUE);
+ g_assert(webkit_settings_get_enable_write_console_messages_to_stdout(settings));
+
g_object_unref(G_OBJECT(settings));
}
@@ -274,7 +284,7 @@ static void assertThatUserAgentIsSentInHeaders(WebViewTest* test, const CString&
{
test->loadURI(gServer->getURIForPath("/").data());
test->waitUntilLoadFinished();
- g_assert_cmpstr(convertWebViewMainResourceDataToCString(test).data(), ==, userAgent.data());
+ ASSERT_CMP_CSTRING(convertWebViewMainResourceDataToCString(test), ==, userAgent);
}
static void testWebKitSettingsUserAgent(WebViewTest* test, gconstpointer)
@@ -300,12 +310,12 @@ static void testWebKitSettingsUserAgent(WebViewTest* test, gconstpointer)
assertThatUserAgentIsSentInHeaders(test, funkyUserAgent);
webkit_settings_set_user_agent_with_application_details(settings.get(), "WebKitGTK+", 0);
- CString userAgentWithNullVersion = webkit_settings_get_user_agent(settings.get());
- g_assert_cmpstr(g_strstr_len(userAgentWithNullVersion.data(), -1, defaultUserAgent.data()), ==, userAgentWithNullVersion.data());
- g_assert(g_strstr_len(userAgentWithNullVersion.data(), -1, "WebKitGTK+"));
+ const char* userAgentWithNullVersion = webkit_settings_get_user_agent(settings.get());
+ g_assert_cmpstr(g_strstr_len(userAgentWithNullVersion, -1, defaultUserAgent.data()), ==, userAgentWithNullVersion);
+ g_assert(g_strstr_len(userAgentWithNullVersion, -1, "WebKitGTK+"));
webkit_settings_set_user_agent_with_application_details(settings.get(), "WebKitGTK+", "");
- g_assert_cmpstr(webkit_settings_get_user_agent(settings.get()), ==, userAgentWithNullVersion.data());
+ g_assert_cmpstr(webkit_settings_get_user_agent(settings.get()), ==, userAgentWithNullVersion);
webkit_settings_set_user_agent_with_application_details(settings.get(), "WebCatGTK+", "3.4.5");
const char* newUserAgent = webkit_settings_get_user_agent(settings.get());
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp
index 185c06cfe..54e44d682 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp
@@ -114,6 +114,9 @@ static void testWebContextGetPlugins(PluginsTest* test, gconstpointer)
static const char* kBarHTML = "<html><body>Bar</body></html>";
static const char* kEchoHTMLFormat = "<html><body>%s</body></html>";
+static const char* errorDomain = "test";
+static const int errorCode = 10;
+static const char* errorMessage = "Error message.";
class URISchemeTest: public LoadTrackingTest {
public:
@@ -122,22 +125,19 @@ public:
struct URISchemeHandler {
URISchemeHandler()
: replyLength(0)
- , replyWithPath(false)
{
}
- URISchemeHandler(const char* reply, int replyLength, const char* mimeType, bool replyWithPath = false)
+ URISchemeHandler(const char* reply, int replyLength, const char* mimeType)
: reply(reply)
, replyLength(replyLength)
, mimeType(mimeType)
- , replyWithPath(replyWithPath)
{
}
CString reply;
int replyLength;
CString mimeType;
- bool replyWithPath;
};
static void uriSchemeRequestCallback(WebKitURISchemeRequest* request, gpointer userData)
@@ -151,22 +151,32 @@ public:
GRefPtr<GInputStream> inputStream = adoptGRef(g_memory_input_stream_new());
test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(inputStream.get()));
- String scheme(String::fromUTF8(webkit_uri_scheme_request_get_scheme(request)));
- g_assert(!scheme.isEmpty());
- g_assert(test->m_handlersMap.contains(scheme));
- const URISchemeHandler& handler = test->m_handlersMap.get(scheme);
+ const char* scheme = webkit_uri_scheme_request_get_scheme(request);
+ g_assert(scheme);
+ g_assert(test->m_handlersMap.contains(String::fromUTF8(scheme)));
- if (handler.replyWithPath) {
+ if (!g_strcmp0(scheme, "error")) {
+ GOwnPtr<GError> error(g_error_new_literal(g_quark_from_string(errorDomain), errorCode, errorMessage));
+ webkit_uri_scheme_request_finish_error(request, error.get());
+ return;
+ }
+
+ const URISchemeHandler& handler = test->m_handlersMap.get(String::fromUTF8(scheme));
+
+ if (!g_strcmp0(scheme, "echo")) {
char* replyHTML = g_strdup_printf(handler.reply.data(), webkit_uri_scheme_request_get_path(request));
g_memory_input_stream_add_data(G_MEMORY_INPUT_STREAM(inputStream.get()), replyHTML, strlen(replyHTML), g_free);
- } else if (!handler.reply.isNull())
+ } else if (!g_strcmp0(scheme, "closed"))
+ g_input_stream_close(inputStream.get(), 0, 0);
+ else if (!handler.reply.isNull())
g_memory_input_stream_add_data(G_MEMORY_INPUT_STREAM(inputStream.get()), handler.reply.data(), handler.reply.length(), 0);
+
webkit_uri_scheme_request_finish(request, inputStream.get(), handler.replyLength, handler.mimeType.data());
}
- void registerURISchemeHandler(const char* scheme, const char* reply, int replyLength, const char* mimeType, bool replyWithPath = false)
+ void registerURISchemeHandler(const char* scheme, const char* reply, int replyLength, const char* mimeType)
{
- m_handlersMap.set(String::fromUTF8(scheme), URISchemeHandler(reply, replyLength, mimeType, replyWithPath));
+ m_handlersMap.set(String::fromUTF8(scheme), URISchemeHandler(reply, replyLength, mimeType));
webkit_web_context_register_uri_scheme(webkit_web_context_get_default(), scheme, uriSchemeRequestCallback, this, 0);
}
@@ -184,7 +194,7 @@ static void testWebContextURIScheme(URISchemeTest* test, gconstpointer)
g_assert_cmpint(mainResourceDataSize, ==, strlen(kBarHTML));
g_assert(!strncmp(mainResourceData, kBarHTML, mainResourceDataSize));
- test->registerURISchemeHandler("echo", kEchoHTMLFormat, -1, "text/html", true);
+ test->registerURISchemeHandler("echo", kEchoHTMLFormat, -1, "text/html");
test->loadURI("echo:hello world");
test->waitUntilLoadFinished();
GOwnPtr<char> echoHTML(g_strdup_printf(kEchoHTMLFormat, webkit_uri_scheme_request_get_path(test->m_uriSchemeRequest.get())));
@@ -205,6 +215,23 @@ static void testWebContextURIScheme(URISchemeTest* test, gconstpointer)
test->waitUntilLoadFinished();
g_assert(!test->m_loadEvents.contains(LoadTrackingTest::ProvisionalLoadFailed));
g_assert(!test->m_loadEvents.contains(LoadTrackingTest::LoadFailed));
+
+ test->registerURISchemeHandler("error", 0, 0, 0);
+ test->m_loadEvents.clear();
+ test->loadURI("error:error");
+ test->waitUntilLoadFinished();
+ g_assert(test->m_loadEvents.contains(LoadTrackingTest::ProvisionalLoadFailed));
+ g_assert(test->m_loadFailed);
+ g_assert_error(test->m_error.get(), g_quark_from_string(errorDomain), errorCode);
+ g_assert_cmpstr(test->m_error->message, ==, errorMessage);
+
+ test->registerURISchemeHandler("closed", 0, 0, 0);
+ test->m_loadEvents.clear();
+ test->loadURI("closed:input-stream");
+ test->waitUntilLoadFinished();
+ g_assert(test->m_loadEvents.contains(LoadTrackingTest::ProvisionalLoadFailed));
+ g_assert(test->m_loadFailed);
+ g_assert_error(test->m_error.get(), G_IO_ERROR, G_IO_ERROR_CLOSED);
}
static void testWebContextSpellChecker(Test* test, gconstpointer)
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp
index 08cdbe82a..88d77f286 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp
@@ -48,12 +48,10 @@ static void testWebViewCustomCharset(WebViewTest* test, gconstpointer)
static void testWebViewSettings(WebViewTest* test, gconstpointer)
{
WebKitSettings* defaultSettings = webkit_web_view_get_settings(test->m_webView);
- test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(defaultSettings));
g_assert(defaultSettings);
g_assert(webkit_settings_get_enable_javascript(defaultSettings));
GRefPtr<WebKitSettings> newSettings = adoptGRef(webkit_settings_new());
- test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(newSettings.get()));
g_object_set(G_OBJECT(newSettings.get()), "enable-javascript", FALSE, NULL);
webkit_web_view_set_settings(test->m_webView, newSettings.get());
@@ -67,7 +65,6 @@ static void testWebViewSettings(WebViewTest* test, gconstpointer)
g_assert(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webView2.get())) == settings);
GRefPtr<WebKitSettings> newSettings2 = adoptGRef(webkit_settings_new());
- test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(newSettings2.get()));
webkit_web_view_set_settings(WEBKIT_WEB_VIEW(webView2.get()), newSettings2.get());
settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webView2.get()));
g_assert(settings == newSettings2.get());
@@ -479,8 +476,9 @@ static void testWebViewMouseTarget(UIClientTest* test, gconstpointer)
" <a style='position:absolute; left:1; top:1' href='http://www.webkitgtk.org' title='WebKitGTK+ Title'>WebKitGTK+ Website</a>"
" <img style='position:absolute; left:1; top:10' src='0xdeadbeef' width=5 height=5></img>"
" <a style='position:absolute; left:1; top:20' href='http://www.webkitgtk.org/logo' title='WebKitGTK+ Logo'><img src='0xdeadbeef' width=5 height=5></img></a>"
- " <video style='position:absolute; left:1; top:30' width=10 height=10 controls='controls'><source src='movie.ogg' type='video/ogg' /></video>"
- " <input style='position:absolute; left:1; top:50' size='10'></input>"
+ " <input style='position:absolute; left:1; top:30' size='10'></input>"
+ " <div style='position:absolute; left:1; top:50; width:30; height:30; overflow:scroll'>&nbsp;</div>"
+ " <video style='position:absolute; left:1; top:100' width='300' height='300' controls='controls' preload='none'><source src='movie.ogg' type='video/ogg' /></video>"
"</body></html>";
test->loadHtml(linksHoveredHTML, "file:///");
@@ -511,6 +509,7 @@ static void testWebViewMouseTarget(UIClientTest* test, gconstpointer)
g_assert(webkit_hit_test_result_context_is_image(hitTestResult));
g_assert(!webkit_hit_test_result_context_is_media(hitTestResult));
g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
+ g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult));
g_assert_cmpstr(webkit_hit_test_result_get_image_uri(hitTestResult), ==, "file:///0xdeadbeef");
g_assert(test->m_mouseTargetModifiers & GDK_CONTROL_MASK);
@@ -520,6 +519,7 @@ static void testWebViewMouseTarget(UIClientTest* test, gconstpointer)
g_assert(webkit_hit_test_result_context_is_image(hitTestResult));
g_assert(!webkit_hit_test_result_context_is_media(hitTestResult));
g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
+ g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult));
g_assert_cmpstr(webkit_hit_test_result_get_link_uri(hitTestResult), ==, "http://www.webkitgtk.org/logo");
g_assert_cmpstr(webkit_hit_test_result_get_image_uri(hitTestResult), ==, "file:///0xdeadbeef");
g_assert_cmpstr(webkit_hit_test_result_get_link_title(hitTestResult), ==, "WebKitGTK+ Logo");
@@ -527,21 +527,32 @@ static void testWebViewMouseTarget(UIClientTest* test, gconstpointer)
g_assert(!test->m_mouseTargetModifiers);
// Move over media.
- hitTestResult = test->moveMouseAndWaitUntilMouseTargetChanged(1, 30);
+ hitTestResult = test->moveMouseAndWaitUntilMouseTargetChanged(1, 100);
g_assert(!webkit_hit_test_result_context_is_link(hitTestResult));
g_assert(!webkit_hit_test_result_context_is_image(hitTestResult));
g_assert(webkit_hit_test_result_context_is_media(hitTestResult));
g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
+ g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult));
g_assert_cmpstr(webkit_hit_test_result_get_media_uri(hitTestResult), ==, "file:///movie.ogg");
g_assert(!test->m_mouseTargetModifiers);
// Mover over input.
- hitTestResult = test->moveMouseAndWaitUntilMouseTargetChanged(5, 55);
+ hitTestResult = test->moveMouseAndWaitUntilMouseTargetChanged(5, 35);
g_assert(!webkit_hit_test_result_context_is_link(hitTestResult));
g_assert(!webkit_hit_test_result_context_is_image(hitTestResult));
g_assert(!webkit_hit_test_result_context_is_media(hitTestResult));
+ g_assert(!webkit_hit_test_result_context_is_scrollbar(hitTestResult));
g_assert(webkit_hit_test_result_context_is_editable(hitTestResult));
g_assert(!test->m_mouseTargetModifiers);
+
+ // Move over scrollbar.
+ hitTestResult = test->moveMouseAndWaitUntilMouseTargetChanged(5, 75);
+ g_assert(!webkit_hit_test_result_context_is_link(hitTestResult));
+ g_assert(!webkit_hit_test_result_context_is_image(hitTestResult));
+ g_assert(!webkit_hit_test_result_context_is_media(hitTestResult));
+ g_assert(!webkit_hit_test_result_context_is_editable(hitTestResult));
+ g_assert(webkit_hit_test_result_context_is_scrollbar(hitTestResult));
+ g_assert(!test->m_mouseTargetModifiers);
}
static void testWebViewPermissionRequests(UIClientTest* test, gconstpointer)
@@ -1050,6 +1061,174 @@ static void testWebViewSave(SaveWebViewTest* test, gconstpointer)
g_assert_cmpint(g_file_info_get_size(fileInfo.get()), ==, totalBytesFromStream);
}
+static void testWebViewMode(WebViewTest* test, gconstpointer)
+{
+ static const char* indexHTML = "<html><body><p>Test Web View Mode</p></body></html>";
+
+ // Web mode.
+ g_assert_cmpuint(webkit_web_view_get_view_mode(test->m_webView), ==, WEBKIT_VIEW_MODE_WEB);
+ test->loadHtml(indexHTML, 0);
+ test->waitUntilLoadFinished();
+ WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished("window.document.body.textContent;", 0);
+ GOwnPtr<char> valueString(WebViewTest::javascriptResultToCString(javascriptResult));
+ g_assert_cmpstr(valueString.get(), ==, "Test Web View Mode");
+
+ // Source mode.
+ webkit_web_view_set_view_mode(test->m_webView, WEBKIT_VIEW_MODE_SOURCE);
+ test->loadHtml(indexHTML, 0);
+ test->waitUntilLoadFinished();
+ javascriptResult = test->runJavaScriptAndWaitUntilFinished("window.document.body.textContent;", 0);
+ valueString.set(WebViewTest::javascriptResultToCString(javascriptResult));
+ g_assert_cmpstr(valueString.get(), ==, indexHTML);
+}
+
+// To test page visibility API. Currently only 'visible' and 'hidden' states are implemented fully in WebCore.
+// See also http://www.w3.org/TR/2011/WD-page-visibility-20110602/ and https://developers.google.com/chrome/whitepapers/pagevisibility
+static void testWebViewPageVisibility(WebViewTest* test, gconstpointer)
+{
+ test->loadHtml("<html><title></title>"
+ "<body><p>Test Web Page Visibility</p>"
+ "<script>"
+ "document.addEventListener(\"webkitvisibilitychange\", onVisibilityChange, false);"
+ "function onVisibilityChange() {"
+ " document.title = document.webkitVisibilityState;"
+ "}"
+ "</script>"
+ "</body></html>",
+ 0);
+
+ // Wait untill the page is loaded. Initial visibility should be 'hidden'.
+ test->waitUntilLoadFinished();
+
+ GOwnPtr<GError> error;
+ WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished("document.webkitVisibilityState;", &error.outPtr());
+ g_assert(javascriptResult);
+ g_assert(!error.get());
+ GOwnPtr<char> valueString(WebViewTest::javascriptResultToCString(javascriptResult));
+ g_assert_cmpstr(valueString.get(), ==, "hidden");
+
+ javascriptResult = test->runJavaScriptAndWaitUntilFinished("document.webkitHidden;", &error.outPtr());
+ g_assert(javascriptResult);
+ g_assert(!error.get());
+ g_assert(WebViewTest::javascriptResultToBoolean(javascriptResult));
+
+ // Show the page. The visibility should be updated to 'visible'.
+ test->showInWindow();
+ test->waitUntilTitleChanged();
+
+ javascriptResult = test->runJavaScriptAndWaitUntilFinished("document.webkitVisibilityState;", &error.outPtr());
+ g_assert(javascriptResult);
+ g_assert(!error.get());
+ valueString.set(WebViewTest::javascriptResultToCString(javascriptResult));
+ g_assert_cmpstr(valueString.get(), ==, "visible");
+
+ javascriptResult = test->runJavaScriptAndWaitUntilFinished("document.webkitHidden;", &error.outPtr());
+ g_assert(javascriptResult);
+ g_assert(!error.get());
+ g_assert(!WebViewTest::javascriptResultToBoolean(javascriptResult));
+
+ // Hide the page. The visibility should be updated to 'hidden'.
+ gtk_widget_hide(GTK_WIDGET(test->m_webView));
+ test->waitUntilTitleChanged();
+
+ javascriptResult = test->runJavaScriptAndWaitUntilFinished("document.webkitVisibilityState;", &error.outPtr());
+ g_assert(javascriptResult);
+ g_assert(!error.get());
+ valueString.set(WebViewTest::javascriptResultToCString(javascriptResult));
+ g_assert_cmpstr(valueString.get(), ==, "hidden");
+
+ javascriptResult = test->runJavaScriptAndWaitUntilFinished("document.webkitHidden;", &error.outPtr());
+ g_assert(javascriptResult);
+ g_assert(!error.get());
+ g_assert(WebViewTest::javascriptResultToBoolean(javascriptResult));
+}
+
+class SnapshotWebViewTest: public WebViewTest {
+public:
+ MAKE_GLIB_TEST_FIXTURE(SnapshotWebViewTest);
+
+ static void onSnapshotCancelledReady(WebKitWebView* web_view, GAsyncResult* res, SnapshotWebViewTest* test)
+ {
+ GOwnPtr<GError> error;
+ test->m_surface = webkit_web_view_get_snapshot_finish(web_view, res, &error.outPtr());
+ g_assert(!test->m_surface);
+ g_assert_error(error.get(), G_IO_ERROR, G_IO_ERROR_CANCELLED);
+ test->quitMainLoop();
+ }
+
+ gboolean getSnapshotAndCancel()
+ {
+ if (m_surface)
+ cairo_surface_destroy(m_surface);
+ m_surface = 0;
+ GRefPtr<GCancellable> cancellable = adoptGRef(g_cancellable_new());
+ webkit_web_view_get_snapshot(m_webView, WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE, cancellable.get(), reinterpret_cast<GAsyncReadyCallback>(onSnapshotCancelledReady), this);
+ g_cancellable_cancel(cancellable.get());
+ g_main_loop_run(m_mainLoop);
+
+ return true;
+ }
+
+};
+
+static void testWebViewSnapshot(SnapshotWebViewTest* test, gconstpointer)
+{
+ test->loadHtml("<html><body><p>Whatever</p></body></html>", 0);
+ test->waitUntilLoadFinished();
+
+ // WebView not visible.
+ cairo_surface_t* surface1 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE);
+ g_assert(!surface1);
+
+ // Show surface, resize to 50x50, try again.
+ test->showInWindowAndWaitUntilMapped();
+ test->resizeView(50, 50);
+ surface1 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE);
+ g_assert(surface1);
+
+ // obtained surface should be at the most 50x50. Store the size
+ // for comparison later.
+ int width = cairo_image_surface_get_width(surface1);
+ int height = cairo_image_surface_get_height(surface1);
+ g_assert_cmpint(width, <=, 50);
+ g_assert_cmpint(height, <=, 50);
+
+ // Select all text in the WebView, request a snapshot ignoring selection.
+ test->selectAll();
+ surface1 = cairo_surface_reference(test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE));
+ g_assert(surface1);
+ g_assert_cmpint(cairo_image_surface_get_width(surface1), ==, width);
+ g_assert_cmpint(cairo_image_surface_get_height(surface1), ==, height);
+
+ // Create identical surface.
+ cairo_surface_t* surface2 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_NONE);
+ g_assert(surface2);
+
+ // Compare these two, they should be identical.
+ g_assert(Test::cairoSurfacesEqual(surface1, surface2));
+
+ // Request a new snapshot, including the selection this time. The
+ // size should be the same but the result must be different to the
+ // one previously obtained.
+ surface2 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_VISIBLE, WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING);
+ g_assert(surface2);
+ g_assert_cmpint(cairo_image_surface_get_width(surface2), ==, width);
+ g_assert_cmpint(cairo_image_surface_get_height(surface2), ==, height);
+ g_assert(!Test::cairoSurfacesEqual(surface1, surface2));
+
+ // Request a snapshot of the whole document in the WebView. The
+ // result should be different from the size obtained previously.
+ surface2 = test->getSnapshotAndWaitUntilReady(WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT, WEBKIT_SNAPSHOT_OPTIONS_NONE);
+ g_assert(surface2);
+ g_assert_cmpint(cairo_image_surface_get_width(surface2), >, width);
+ g_assert_cmpint(cairo_image_surface_get_height(surface2), >, height);
+ g_assert(!Test::cairoSurfacesEqual(surface1, surface2));
+
+ cairo_surface_destroy(surface1);
+
+ g_assert(test->getSnapshotAndCancel());
+}
+
void beforeAll()
{
WebViewTest::add("WebKitWebView", "default-context", testWebViewDefaultContext);
@@ -1069,6 +1248,9 @@ void beforeAll()
WebViewTest::add("WebKitWebView", "can-show-mime-type", testWebViewCanShowMIMEType);
FormClientTest::add("WebKitWebView", "submit-form", testWebViewSubmitForm);
SaveWebViewTest::add("WebKitWebView", "save", testWebViewSave);
+ WebViewTest::add("WebKitWebView", "view-mode", testWebViewMode);
+ SnapshotWebViewTest::add("WebKitWebView", "snapshot", testWebViewSnapshot);
+ WebViewTest::add("WebKitWebView", "page-visibility", testWebViewPageVisibility);
}
void afterAll()
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebViewGroup.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebViewGroup.cpp
new file mode 100644
index 000000000..026c5c5b9
--- /dev/null
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebViewGroup.cpp
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2013 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2,1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include "WebKitTestServer.h"
+#include "WebViewTest.h"
+#include <cstdarg>
+#include <gtk/gtk.h>
+#include <webkit2/webkit2.h>
+#include <wtf/gobject/GRefPtr.h>
+
+static WebKitTestServer* kServer;
+
+// These are all here so that they can be changed easily, if necessary.
+static const char* kStyleSheetHTML = "<html><div id=\"styledElement\">Sweet stylez!</div></html>";
+static const char* kInjectedStyleSheet = "#styledElement { font-weight: bold; }";
+static const char* kStyleSheetTestScript = "getComputedStyle(document.getElementById('styledElement'))['font-weight']";
+static const char* kStyleSheetTestScriptResult = "bold";
+
+static void testWebViewGroupDefault(Test* test, gconstpointer)
+{
+ // Default group is shared by all WebViews by default.
+ GRefPtr<WebKitWebView> webView1 = WEBKIT_WEB_VIEW(webkit_web_view_new());
+ GRefPtr<WebKitWebView> webView2 = WEBKIT_WEB_VIEW(webkit_web_view_new());
+ g_assert(webkit_web_view_get_group(webView1.get()) == webkit_web_view_get_group(webView2.get()));
+
+ // Settings are shared by all web view in the same group.
+ g_assert(webkit_web_view_get_settings(webView1.get()) == webkit_web_view_get_settings(webView2.get()));
+ g_assert(webkit_web_view_get_settings(webView1.get()) == webkit_web_view_group_get_settings(webkit_web_view_get_group(webView2.get())));
+}
+
+static void testWebViewGroupNewGroup(Test* test, gconstpointer)
+{
+ // Passing 0 as group name generates the name automatically.
+ GRefPtr<WebKitWebViewGroup> viewGroup1 = adoptGRef(webkit_web_view_group_new(0));
+ test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(viewGroup1.get()));
+ g_assert(webkit_web_view_group_get_name(viewGroup1.get()));
+
+ // New group with a given name.
+ GRefPtr<WebKitWebViewGroup> viewGroup2 = adoptGRef(webkit_web_view_group_new("TestGroup2"));
+ test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(viewGroup2.get()));
+ g_assert_cmpstr(webkit_web_view_group_get_name(viewGroup2.get()), ==, "TestGroup2");
+ g_assert_cmpstr(webkit_web_view_group_get_name(viewGroup2.get()), !=, webkit_web_view_group_get_name(viewGroup1.get()));
+
+ // Every group has its own settings.
+ g_assert(webkit_web_view_group_get_settings(viewGroup1.get()) != webkit_web_view_group_get_settings(viewGroup2.get()));
+}
+
+static void testWebViewNewWithGroup(Test* test, gconstpointer)
+{
+ GRefPtr<WebKitWebViewGroup> viewGroup1 = adoptGRef(webkit_web_view_group_new("TestGroup1"));
+ test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(viewGroup1.get()));
+ GRefPtr<WebKitWebView> webView1 = WEBKIT_WEB_VIEW(webkit_web_view_new_with_group(viewGroup1.get()));
+ g_assert(webkit_web_view_get_group(webView1.get()) == viewGroup1.get());
+
+ GRefPtr<WebKitWebView> webView2 = WEBKIT_WEB_VIEW(webkit_web_view_new());
+ g_assert(webkit_web_view_get_group(webView2.get()) != viewGroup1.get());
+
+ // Settings should be different for views in different groups.
+ g_assert(webkit_web_view_get_settings(webView1.get()) != webkit_web_view_get_settings(webView2.get()));
+}
+
+static void testWebViewGroupSettings(Test* test, gconstpointer)
+{
+ GRefPtr<WebKitWebViewGroup> viewGroup1 = adoptGRef(webkit_web_view_group_new("TestGroup1"));
+ test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(viewGroup1.get()));
+ GRefPtr<WebKitSettings> newSettings = adoptGRef(webkit_settings_new_with_settings("enable-javascript", FALSE, NULL));
+ test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(newSettings.get()));
+ webkit_web_view_group_set_settings(viewGroup1.get(), newSettings.get());
+ g_assert(webkit_web_view_group_get_settings(viewGroup1.get()) == newSettings.get());
+
+ GRefPtr<WebKitWebView> webView1 = WEBKIT_WEB_VIEW(webkit_web_view_new_with_group(viewGroup1.get()));
+ GRefPtr<WebKitWebView> webView2 = WEBKIT_WEB_VIEW(webkit_web_view_new());
+ WebKitSettings* webView1Settings = webkit_web_view_get_settings(webView1.get());
+ WebKitSettings* webView2Settings = webkit_web_view_get_settings(webView2.get());
+ g_assert(webView1Settings != webView2Settings);
+ g_assert(webkit_settings_get_enable_javascript(webView1Settings) != webkit_settings_get_enable_javascript(webView2Settings));
+
+ webkit_web_view_set_settings(webView1.get(), webView2Settings);
+ g_assert(webkit_web_view_get_settings(webView1.get()) == webView2Settings);
+ g_assert(webkit_web_view_group_get_settings(webkit_web_view_get_group(webView1.get())) == webView2Settings);
+}
+
+static bool isStyleSheetInjectedForURLAtPath(WebViewTest* test, const char* path)
+{
+ test->loadURI(kServer->getURIForPath(path).data());
+ test->waitUntilLoadFinished();
+
+ GOwnPtr<GError> error;
+ WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished(kStyleSheetTestScript, &error.outPtr());
+ g_assert(javascriptResult);
+ g_assert(!error.get());
+
+ GOwnPtr<char> resultString(WebViewTest::javascriptResultToCString(javascriptResult));
+ return !g_strcmp0(resultString.get(), kStyleSheetTestScriptResult);
+}
+
+static void fillURLListFromPaths(char** list, const char* path, ...)
+{
+ va_list argumentList;
+ va_start(argumentList, path);
+
+ int i = 0;
+ while (path) {
+ // FIXME: We must use a wildcard for the host here until http://wkbug.com/112476 is fixed.
+ // Until that time patterns with port numbers in them will not properly match URLs with port numbers.
+ list[i++] = g_strdup_printf("http://*/%s*", path);
+ path = va_arg(argumentList, const char*);
+ }
+}
+
+static void removeOldInjectedStyleSheetsAndResetLists(WebKitWebViewGroup* group, char** whitelist, char** blacklist)
+{
+ webkit_web_view_group_remove_all_user_style_sheets(group);
+
+ while (*whitelist) {
+ g_free(*whitelist);
+ *whitelist = 0;
+ whitelist++;
+ }
+
+ while (*blacklist) {
+ g_free(*blacklist);
+ *blacklist = 0;
+ blacklist++;
+ }
+}
+
+static void testWebViewGroupInjectedStyleSheet(WebViewTest* test, gconstpointer)
+{
+ WebKitWebViewGroup* group = webkit_web_view_get_group(test->m_webView);
+ char* whitelist[3] = { 0, 0, 0 };
+ char* blacklist[3] = { 0, 0, 0 };
+
+ removeOldInjectedStyleSheetsAndResetLists(group, whitelist, blacklist);
+
+ // Without a whitelist or a blacklist all URLs should have the injected style sheet.
+ static const char* randomPath = "somerandompath";
+ g_assert(!isStyleSheetInjectedForURLAtPath(test, randomPath));
+ webkit_web_view_group_add_user_style_sheet(group, kInjectedStyleSheet, 0, 0, 0, WEBKIT_INJECTED_CONTENT_FRAMES_ALL);
+ g_assert(isStyleSheetInjectedForURLAtPath(test, randomPath));
+
+ removeOldInjectedStyleSheetsAndResetLists(group, whitelist, blacklist);
+
+ fillURLListFromPaths(blacklist, randomPath, 0);
+ webkit_web_view_group_add_user_style_sheet(group, kInjectedStyleSheet, 0, 0, blacklist, WEBKIT_INJECTED_CONTENT_FRAMES_ALL);
+ g_assert(!isStyleSheetInjectedForURLAtPath(test, randomPath));
+ g_assert(isStyleSheetInjectedForURLAtPath(test, "someotherrandompath"));
+
+ removeOldInjectedStyleSheetsAndResetLists(group, whitelist, blacklist);
+
+ static const char* inTheWhiteList = "inthewhitelist";
+ static const char* notInWhitelist = "notinthewhitelist";
+ static const char* inTheWhiteListAndBlackList = "inthewhitelistandblacklist";
+
+ fillURLListFromPaths(whitelist, inTheWhiteList, inTheWhiteListAndBlackList, 0);
+ fillURLListFromPaths(blacklist, inTheWhiteListAndBlackList, 0);
+ webkit_web_view_group_add_user_style_sheet(group, kInjectedStyleSheet, 0, whitelist, blacklist, WEBKIT_INJECTED_CONTENT_FRAMES_ALL);
+ g_assert(isStyleSheetInjectedForURLAtPath(test, inTheWhiteList));
+ g_assert(!isStyleSheetInjectedForURLAtPath(test, inTheWhiteListAndBlackList));
+ g_assert(!isStyleSheetInjectedForURLAtPath(test, notInWhitelist));
+
+ // It's important to clean up the environment before other tests.
+ removeOldInjectedStyleSheetsAndResetLists(group, whitelist, blacklist);
+}
+
+static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
+{
+ soup_message_set_status(message, SOUP_STATUS_OK);
+ soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kStyleSheetHTML, strlen(kStyleSheetHTML));
+ soup_message_body_complete(message->response_body);
+}
+
+void beforeAll()
+{
+ kServer = new WebKitTestServer();
+ kServer->run(serverCallback);
+
+ Test::add("WebKitWebViewGroup", "default-group", testWebViewGroupDefault);
+ Test::add("WebKitWebViewGroup", "new-group", testWebViewGroupNewGroup);
+ Test::add("WebKitWebView", "new-with-group", testWebViewNewWithGroup);
+ Test::add("WebKitWebViewGroup", "settings", testWebViewGroupSettings);
+ WebViewTest::add("WebKitWebViewGroup", "injected-style-sheet", testWebViewGroupInjectedStyleSheet);
+}
+
+void afterAll()
+{
+ delete kServer;
+}
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp
new file mode 100644
index 000000000..692663e33
--- /dev/null
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include <gio/gio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <webkit2/webkit-web-extension.h>
+#include <wtf/gobject/GOwnPtr.h>
+
+static const char introspectionXML[] =
+ "<node>"
+ " <interface name='org.webkit.gtk.WebExtensionTest'>"
+ " <method name='GetTitle'>"
+ " <arg type='t' name='pageID' direction='in'/>"
+ " <arg type='s' name='title' direction='out'/>"
+ " </method>"
+ " <method name='AbortProcess'>"
+ " </method>"
+ " <signal name='DocumentLoaded'/>"
+ " <signal name='URIChanged'>"
+ " <arg type='s' name='uri' direction='out'/>"
+ " </signal>"
+ " </interface>"
+ "</node>";
+
+static void documentLoadedCallback(WebKitWebPage*, gpointer userData)
+{
+ bool ok = g_dbus_connection_emit_signal(G_DBUS_CONNECTION(userData),
+ 0,
+ "/org/webkit/gtk/WebExtensionTest",
+ "org.webkit.gtk.WebExtensionTest",
+ "DocumentLoaded",
+ 0,
+ 0);
+ g_assert(ok);
+}
+
+static void uriChangedCallback(WebKitWebPage* webPage, GParamSpec* pspec, gpointer userData)
+{
+ bool ok = g_dbus_connection_emit_signal(
+ G_DBUS_CONNECTION(userData),
+ 0,
+ "/org/webkit/gtk/WebExtensionTest",
+ "org.webkit.gtk.WebExtensionTest",
+ "URIChanged",
+ g_variant_new("(s)", webkit_web_page_get_uri(webPage)),
+ 0);
+ g_assert(ok);
+}
+
+static gboolean sendRequestCallback(WebKitWebPage*, WebKitURIRequest* request, WebKitURIResponse*, gpointer)
+{
+ const char* requestURI = webkit_uri_request_get_uri(request);
+ g_assert(requestURI);
+
+ if (const char* suffix = g_strrstr(requestURI, "/remove-this/javascript.js")) {
+ GOwnPtr<char> prefix(g_strndup(requestURI, strlen(requestURI) - strlen(suffix)));
+ GOwnPtr<char> newURI(g_strdup_printf("%s/javascript.js", prefix.get()));
+ webkit_uri_request_set_uri(request, newURI.get());
+ } else if (g_str_has_suffix(requestURI, "/add-do-not-track-header")) {
+ SoupMessageHeaders* headers = webkit_uri_request_get_http_headers(request);
+ g_assert(headers);
+ soup_message_headers_append(headers, "DNT", "1");
+ } else if (g_str_has_suffix(requestURI, "/cancel-this.js"))
+ return TRUE;
+
+ return FALSE;
+}
+
+static void pageCreatedCallback(WebKitWebExtension*, WebKitWebPage* webPage, gpointer userData)
+{
+ g_signal_connect(webPage, "document-loaded", G_CALLBACK(documentLoadedCallback), userData);
+ g_signal_connect(webPage, "notify::uri", G_CALLBACK(uriChangedCallback), userData);
+ g_signal_connect(webPage, "send-request", G_CALLBACK(sendRequestCallback), 0);
+}
+
+static void methodCallCallback(GDBusConnection* connection, const char* sender, const char* objectPath, const char* interfaceName, const char* methodName, GVariant* parameters, GDBusMethodInvocation* invocation, gpointer userData)
+{
+ if (g_strcmp0(interfaceName, "org.webkit.gtk.WebExtensionTest"))
+ return;
+
+ if (!g_strcmp0(methodName, "GetTitle")) {
+ uint64_t pageID;
+ g_variant_get(parameters, "(t)", &pageID);
+
+ WebKitWebExtension* extension = WEBKIT_WEB_EXTENSION(userData);
+ WebKitWebPage* page = webkit_web_extension_get_page(extension, pageID);
+ if (!page) {
+ g_dbus_method_invocation_return_error(
+ invocation, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
+ "Invalid page ID: %" G_GUINT64_FORMAT, pageID);
+ return;
+ }
+ g_assert_cmpuint(webkit_web_page_get_id(page), ==, pageID);
+
+ WebKitDOMDocument* document = webkit_web_page_get_dom_document(page);
+ GOwnPtr<char> title(webkit_dom_document_get_title(document));
+ g_dbus_method_invocation_return_value(invocation, g_variant_new("(s)", title.get()));
+ } else if (!g_strcmp0(methodName, "AbortProcess")) {
+ abort();
+ }
+}
+
+static const GDBusInterfaceVTable interfaceVirtualTable = {
+ methodCallCallback, 0, 0, { 0, }
+};
+
+static void busAcquiredCallback(GDBusConnection* connection, const char* name, gpointer userData)
+{
+ static GDBusNodeInfo *introspectionData = 0;
+ if (!introspectionData)
+ introspectionData = g_dbus_node_info_new_for_xml(introspectionXML, 0);
+
+ GOwnPtr<GError> error;
+ unsigned registrationID = g_dbus_connection_register_object(
+ connection,
+ "/org/webkit/gtk/WebExtensionTest",
+ introspectionData->interfaces[0],
+ &interfaceVirtualTable,
+ g_object_ref(userData),
+ static_cast<GDestroyNotify>(g_object_unref),
+ &error.outPtr());
+ if (!registrationID)
+ g_warning("Failed to register object: %s\n", error->message);
+
+ g_signal_connect(WEBKIT_WEB_EXTENSION(userData), "page-created", G_CALLBACK(pageCreatedCallback), connection);
+}
+
+extern "C" void webkit_web_extension_initialize(WebKitWebExtension* extension)
+{
+ g_bus_own_name(
+ G_BUS_TYPE_SESSION,
+ "org.webkit.gtk.WebExtensionTest",
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ busAcquiredCallback,
+ 0, 0,
+ g_object_ref(extension),
+ static_cast<GDestroyNotify>(g_object_unref));
+}
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.cpp
new file mode 100644
index 000000000..8c2d3f638
--- /dev/null
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.cpp
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebKitTestBus.h"
+
+#include <wtf/gobject/GOwnPtr.h>
+#include <wtf/text/WTFString.h>
+
+WebKitTestBus::WebKitTestBus()
+ : m_pid(-1)
+{
+}
+
+bool WebKitTestBus::run()
+{
+ // FIXME: Use GTestDBus when we bump glib to 2.34.
+ GOwnPtr<char> dbusLaunch(g_find_program_in_path("dbus-launch"));
+ if (!dbusLaunch) {
+ g_warning("Error starting DBUS daemon: dbus-launch not found in path");
+ return false;
+ }
+
+ GOwnPtr<char> output;
+ GOwnPtr<GError> error;
+ if (!g_spawn_command_line_sync(dbusLaunch.get(), &output.outPtr(), 0, 0, &error.outPtr())) {
+ g_warning("Error starting DBUS daemon: %s", error->message);
+ return false;
+ }
+
+ String outputString = String::fromUTF8(output.get());
+ Vector<String> lines;
+ outputString.split(UChar('\n'), /* allowEmptyEntries */ false, lines);
+ for (size_t i = 0; i < lines.size(); ++i) {
+ char** keyValue = g_strsplit(lines[i].utf8().data(), "=", 2);
+ g_assert_cmpuint(g_strv_length(keyValue), ==, 2);
+ if (!g_strcmp0(keyValue[0], "DBUS_SESSION_BUS_ADDRESS")) {
+ m_address = keyValue[1];
+ g_setenv("DBUS_SESSION_BUS_ADDRESS", keyValue[1], TRUE);
+ } else if (!g_strcmp0(keyValue[0], "DBUS_SESSION_BUS_PID"))
+ m_pid = g_ascii_strtoll(keyValue[1], 0, 10);
+ g_strfreev(keyValue);
+ }
+
+ return m_pid > 0;
+}
+
+WebKitTestBus::~WebKitTestBus()
+{
+ g_unsetenv("DBUS_SESSION_BUS_ADDRESS");
+
+ if (m_pid != -1)
+ kill(m_pid, SIGTERM);
+}
+
+GDBusConnection* WebKitTestBus::getOrCreateConnection()
+{
+ if (m_connection)
+ return m_connection.get();
+
+ g_assert(!m_address.isNull());
+ m_connection = adoptGRef(g_dbus_connection_new_for_address_sync(m_address.data(),
+ static_cast<GDBusConnectionFlags>(G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION),
+ 0, 0, 0));
+ return m_connection.get();
+}
+
+static void onNameAppeared(GDBusConnection*, const char*, const char*, gpointer userData)
+{
+ g_main_loop_quit(static_cast<GMainLoop*>(userData));
+}
+
+GDBusProxy* WebKitTestBus::createProxy(const char* serviceName, const char* objectPath, const char* interfaceName, GMainLoop* mainLoop)
+{
+ unsigned watcherID = g_bus_watch_name_on_connection(getOrCreateConnection(), serviceName, G_BUS_NAME_WATCHER_FLAGS_NONE, onNameAppeared, 0, mainLoop, 0);
+ g_main_loop_run(mainLoop);
+ g_bus_unwatch_name(watcherID);
+
+ GDBusProxy* proxy = g_dbus_proxy_new_sync(
+ connection(),
+ G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+ 0, // GDBusInterfaceInfo
+ serviceName,
+ objectPath,
+ interfaceName,
+ 0, // GCancellable
+ 0);
+ g_assert(proxy);
+ return proxy;
+}
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.h b/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.h
new file mode 100644
index 000000000..b9f856b27
--- /dev/null
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestBus.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebKitTestBus_h
+#define WebKitTestBus_h
+
+#include <gio/gio.h>
+#include <wtf/gobject/GRefPtr.h>
+#include <wtf/text/CString.h>
+
+class WebKitTestBus {
+public:
+ WebKitTestBus();
+ virtual ~WebKitTestBus();
+
+ bool run();
+ GDBusProxy* createProxy(const char* serviceName, const char* objectPath, const char* interfaceName, GMainLoop*);
+ GDBusConnection* connection() const { return m_connection.get(); }
+
+private:
+ GDBusConnection* getOrCreateConnection();
+
+ pid_t m_pid;
+ CString m_address;
+ GRefPtr<GDBusConnection> m_connection;
+};
+
+#endif // WebKitTestBus_h
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp
index 7e7eb0167..e6c843456 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp
@@ -30,6 +30,7 @@ WebViewTest::WebViewTest()
, m_parentWindow(0)
, m_javascriptResult(0)
, m_resourceDataSize(0)
+ , m_surface(0)
{
assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_webView));
}
@@ -40,6 +41,8 @@ WebViewTest::~WebViewTest()
gtk_widget_destroy(m_parentWindow);
if (m_javascriptResult)
webkit_javascript_result_unref(m_javascriptResult);
+ if (m_surface)
+ cairo_surface_destroy(m_surface);
g_object_unref(m_webView);
g_main_loop_unref(m_mainLoop);
}
@@ -175,6 +178,15 @@ static gboolean parentWindowMapped(GtkWidget* widget, GdkEvent*, WebViewTest* te
return FALSE;
}
+void WebViewTest::showInWindow(GtkWindowType windowType)
+{
+ g_assert(!m_parentWindow);
+ m_parentWindow = gtk_window_new(windowType);
+ gtk_container_add(GTK_CONTAINER(m_parentWindow), GTK_WIDGET(m_webView));
+ gtk_widget_show(GTK_WIDGET(m_webView));
+ gtk_widget_show(m_parentWindow);
+}
+
void WebViewTest::showInWindowAndWaitUntilMapped(GtkWindowType windowType)
{
g_assert(!m_parentWindow);
@@ -198,6 +210,11 @@ void WebViewTest::resizeView(int width, int height)
gtk_widget_size_allocate(GTK_WIDGET(m_webView), &allocation);
}
+void WebViewTest::selectAll()
+{
+ webkit_web_view_execute_editing_command(m_webView, "SelectAll");
+}
+
static void resourceGetDataCallback(GObject* object, GAsyncResult* result, gpointer userData)
{
size_t dataSize;
@@ -406,3 +423,22 @@ bool WebViewTest::javascriptResultIsUndefined(WebKitJavascriptResult* javascript
return JSValueIsUndefined(context, value);
}
+static void onSnapshotReady(WebKitWebView* web_view, GAsyncResult* res, WebViewTest* test)
+{
+ GOwnPtr<GError> error;
+ test->m_surface = webkit_web_view_get_snapshot_finish(web_view, res, &error.outPtr());
+ g_assert(!test->m_surface || !error.get());
+ if (error)
+ g_assert_error(error.get(), WEBKIT_SNAPSHOT_ERROR, WEBKIT_SNAPSHOT_ERROR_FAILED_TO_CREATE);
+ test->quitMainLoop();
+}
+
+cairo_surface_t* WebViewTest::getSnapshotAndWaitUntilReady(WebKitSnapshotRegion region, WebKitSnapshotOptions options)
+{
+ if (m_surface)
+ cairo_surface_destroy(m_surface);
+ m_surface = 0;
+ webkit_web_view_get_snapshot(m_webView, region, options, 0, reinterpret_cast<GAsyncReadyCallback>(onSnapshotReady), this);
+ g_main_loop_run(m_mainLoop);
+ return m_surface;
+}
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h
index 06f398f96..a460e22b4 100644
--- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h
+++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h
@@ -46,8 +46,10 @@ public:
void waitUntilLoadFinished();
void waitUntilTitleChangedTo(const char* expectedTitle);
void waitUntilTitleChanged();
+ void showInWindow(GtkWindowType = GTK_WINDOW_POPUP);
void showInWindowAndWaitUntilMapped(GtkWindowType = GTK_WINDOW_POPUP);
void resizeView(int width, int height);
+ void selectAll();
const char* mainResourceData(size_t& mainResourceDataSize);
void mouseMoveTo(int x, int y, unsigned int mouseModifiers = 0);
@@ -64,6 +66,8 @@ public:
static bool javascriptResultIsNull(WebKitJavascriptResult*);
static bool javascriptResultIsUndefined(WebKitJavascriptResult*);
+ cairo_surface_t* getSnapshotAndWaitUntilReady(WebKitSnapshotRegion, WebKitSnapshotOptions);
+
WebKitWebView* m_webView;
GMainLoop* m_mainLoop;
CString m_activeURI;
@@ -73,6 +77,7 @@ public:
GError** m_javascriptError;
GOwnPtr<char> m_resourceData;
size_t m_resourceDataSize;
+ cairo_surface_t* m_surface;
private:
void doMouseButtonEvent(GdkEventType, int, int, unsigned int, unsigned int);