diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp')
-rw-r--r-- | Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp | 69 |
1 files changed, 36 insertions, 33 deletions
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp b/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp index 0f5a82042..5a3b057fd 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp +++ b/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitFaviconDatabase.cpp @@ -23,21 +23,19 @@ #include "WebViewTest.h" #include <glib/gstdio.h> #include <libsoup/soup.h> -#include <wtf/gobject/GUniquePtr.h> +#include <wtf/glib/GUniquePtr.h> static WebKitTestServer* kServer; -static char* kTempDirectory; class FaviconDatabaseTest: public WebViewTest { public: MAKE_GLIB_TEST_FIXTURE(FaviconDatabaseTest); FaviconDatabaseTest() - : m_webContext(webkit_web_context_get_default()) - , m_favicon(0) + : m_favicon(nullptr) , m_faviconNotificationReceived(false) { - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext); + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext.get()); g_signal_connect(database, "favicon-changed", G_CALLBACK(faviconChangedCallback), this); } @@ -46,7 +44,7 @@ public: if (m_favicon) cairo_surface_destroy(m_favicon); - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext); + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext.get()); g_signal_handlers_disconnect_matched(database, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); } @@ -67,7 +65,7 @@ public: static void getFaviconCallback(GObject* sourceObject, GAsyncResult* result, void* data) { FaviconDatabaseTest* test = static_cast<FaviconDatabaseTest*>(data); - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext); + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext.get()); test->m_favicon = webkit_favicon_database_get_favicon_finish(database, result, &test->m_error.outPtr()); test->quitMainLoop(); } @@ -87,12 +85,11 @@ public: m_favicon = 0; } - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext); + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(m_webContext.get()); webkit_favicon_database_get_favicon(database, pageURI, 0, getFaviconCallback, this); g_main_loop_run(m_mainLoop); } - WebKitWebContext* m_webContext; cairo_surface_t* m_favicon; CString m_faviconURI; GUniqueOutPtr<GError> m_error; @@ -116,7 +113,7 @@ serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHash char* contents; gsize length; if (g_str_equal(path, "/icon/favicon.ico")) { - GUniquePtr<char> pathToFavicon(g_build_filename(Test::getWebKit1TestResoucesDir().data(), "blank.ico", NULL)); + GUniquePtr<char> pathToFavicon(g_build_filename(Test::getResourcesDir().data(), "blank.ico", nullptr)); g_file_get_contents(pathToFavicon.get(), &contents, &length, 0); soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length); } else if (g_str_equal(path, "/nofavicon")) { @@ -142,19 +139,43 @@ static void testNotInitialized(FaviconDatabaseTest* test) 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)); + webkit_web_context_set_favicon_database_directory(test->m_webContext.get(), Test::dataDirectory()); + g_assert_cmpstr(Test::dataDirectory(), ==, webkit_web_context_get_favicon_database_directory(test->m_webContext.get())); } static void testClearDatabase(FaviconDatabaseTest* test) { - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext); + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext.get()); webkit_favicon_database_clear(database); GUniquePtr<char> iconURI(webkit_favicon_database_get_favicon_uri(database, kServer->getURIForPath("/foo").data())); g_assert(!iconURI); } +static void ephemeralViewLoadChanged(WebKitWebView* webView, WebKitLoadEvent loadEvent, WebViewTest* test) +{ + if (loadEvent != WEBKIT_LOAD_FINISHED) + return; + g_signal_handlers_disconnect_by_func(webView, reinterpret_cast<void*>(ephemeralViewLoadChanged), test); + test->quitMainLoop(); +} + +static void testPrivateBrowsing(FaviconDatabaseTest* test) +{ + GRefPtr<WebKitWebView> webView = WEBKIT_WEB_VIEW(g_object_new(WEBKIT_TYPE_WEB_VIEW, + "web-context", test->m_webContext.get(), + "is-ephemeral", TRUE, + nullptr)); + g_signal_connect(webView.get(), "load-changed", G_CALLBACK(ephemeralViewLoadChanged), test); + webkit_web_view_load_uri(webView.get(), kServer->getURIForPath("/foo").data()); + g_main_loop_run(test->m_mainLoop); + + // An ephemeral web view should not write to the database. + test->getFaviconForPageURIAndWaitUntilReady(kServer->getURIForPath("/foo").data()); + g_assert(!test->m_favicon); + g_assert(test->m_error); +} + static void testGetFavicon(FaviconDatabaseTest* test) { // We need to load the page first to ensure the icon data will be @@ -198,7 +219,7 @@ static void testGetFavicon(FaviconDatabaseTest* test) static void testGetFaviconURI(FaviconDatabaseTest* test) { - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext); + WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(test->m_webContext.get()); CString baseURI = kServer->getURIForPath("/foo"); GUniquePtr<char> iconURI(webkit_favicon_database_get_favicon_uri(database, baseURI.data())); @@ -231,6 +252,7 @@ static void testFaviconDatabase(FaviconDatabaseTest* test, gconstpointer) // See https://bugs.webkit.org/show_bug.cgi?id=111434. testNotInitialized(test); testSetDirectory(test); + testPrivateBrowsing(test); testGetFavicon(test); testGetFaviconURI(test); testWebViewFavicon(test); @@ -243,30 +265,11 @@ void beforeAll() kServer = new WebKitTestServer(); kServer->run(serverCallback); - kTempDirectory = g_dir_make_tmp("WebKit2Tests-XXXXXX", 0); - g_assert(kTempDirectory); - // Add tests to the suite. FaviconDatabaseTest::add("WebKitFaviconDatabase", "favicon-database-test", testFaviconDatabase); } -static void webkitFaviconDatabaseFinalizedCallback(gpointer, GObject*) -{ - if (!g_file_test(kTempDirectory, G_FILE_TEST_IS_DIR)) - return; - - GUniquePtr<char> filename(g_build_filename(kTempDirectory, "WebpageIcons.db", nullptr)); - g_unlink(filename.get()); - - g_rmdir(kTempDirectory); -} - void afterAll() { delete kServer; - - // Delete the temporary files after the IconDatabase has been - // closed, that is, once WebKitFaviconDatabase is being destroyed. - WebKitFaviconDatabase* database = webkit_web_context_get_favicon_database(webkit_web_context_get_default()); - g_object_weak_ref(G_OBJECT(database), webkitFaviconDatabaseFinalizedCallback, 0); } |