diff options
Diffstat (limited to 'Source/WebKit2/UIProcess/API/gtk/tests')
14 files changed, 1807 insertions, 0 deletions
diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am b/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am new file mode 100644 index 000000000..d912b657e --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am @@ -0,0 +1,78 @@ +TEST_PROGS += \ + Programs/WebKit2APITests/TestWebKitWebContext \ + Programs/WebKit2APITests/TestWebKitWebView \ + Programs/WebKit2APITests/TestWebKitWebLoaderClient \ + Programs/WebKit2APITests/TestWebKitSettings \ + Programs/WebKit2APITests/TestBackForwardList + +noinst_PROGRAMS += $(TEST_PROGS) +webkit2_tests_cppflags = \ + -DWEBKIT_EXEC_PATH=\"${shell pwd}/$(top_builddir)/Programs\" \ + $(javascriptcore_cppflags) \ + -I$(srcdir)/Source/JavaScriptCore \ + -I$(srcdir)/Source \ + -I$(srcdir)/Source/WebKit2 \ + -I$(top_builddir)/DerivedSources/WebKit2/include \ + -I$(top_builddir)/DerivedSources/WebKit2/webkit2gtk \ + -I$(top_builddir)/DerivedSources/WebKit2/webkit2gtk/include \ + -I$(srcdir)/Source/WebKit2/UIProcess/API/gtk \ + $(global_cppflags) \ + $(GLIB_CFLAGS) \ + $(GTK_CFLAGS) \ + $(LIBSOUP_CFLAGS) + +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 \ + $(GEOCLUE_LIBS) \ + $(GLIB_LIBS) \ + $(GTK_LIBS) \ + $(LIBSOUP_LIBS) + +webkit2_tests_ldflags = \ + -no-install \ + -no-fast-install + +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/WebKitTestServer.cpp \ + Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.h \ + Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp \ + Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h \ + Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp \ + Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h +Libraries_libWebKit2APITestCore_la_CPPFLAGS = $(webkit2_tests_cppflags) + +Programs_WebKit2APITests_TestWebKitWebContext_SOURCES = \ + Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp +Programs_WebKit2APITests_TestWebKitWebContext_CPPFLAGS = $(webkit2_tests_cppflags) +Programs_WebKit2APITests_TestWebKitWebContext_LDADD = $(webkit2_tests_ldadd) +Programs_WebKit2APITests_TestWebKitWebContext_LDFLAGS = $(webkit2_tests_ldflags) + +Programs_WebKit2APITests_TestWebKitWebView_SOURCES = \ + Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp +Programs_WebKit2APITests_TestWebKitWebView_CPPFLAGS = $(webkit2_tests_cppflags) +Programs_WebKit2APITests_TestWebKitWebView_LDADD = $(webkit2_tests_ldadd) +Programs_WebKit2APITests_TestWebKitWebView_LDFLAGS = $(webkit2_tests_ldflags) + +Programs_WebKit2APITests_TestWebKitWebLoaderClient_SOURCES = \ + Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp +Programs_WebKit2APITests_TestWebKitWebLoaderClient_CPPFLAGS = $(webkit2_tests_cppflags) +Programs_WebKit2APITests_TestWebKitWebLoaderClient_LDADD = $(webkit2_tests_ldadd) +Programs_WebKit2APITests_TestWebKitWebLoaderClient_LDFLAGS = $(webkit2_tests_ldflags) + +Programs_WebKit2APITests_TestWebKitSettings_SOURCES = \ + Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp +Programs_WebKit2APITests_TestWebKitSettings_CPPFLAGS = $(webkit2_tests_cppflags) +Programs_WebKit2APITests_TestWebKitSettings_LDADD = $(webkit2_tests_ldadd) +Programs_WebKit2APITests_TestWebKitSettings_LDFLAGS = $(webkit2_tests_ldflags) + +Programs_WebKit2APITests_TestBackForwardList_SOURCES = \ + Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp +Programs_WebKit2APITests_TestBackForwardList_CPPFLAGS = $(webkit2_tests_cppflags) +Programs_WebKit2APITests_TestBackForwardList_LDADD = $(webkit2_tests_ldadd) +Programs_WebKit2APITests_TestBackForwardList_LDFLAGS = $(webkit2_tests_ldflags) + diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp new file mode 100644 index 000000000..7581f2f6e --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2011 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 "LoadTrackingTest.h" + +#include <webkit2/webkit2.h> + +static void loadChangedCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, LoadTrackingTest* test) +{ + switch (loadEvent) { + case WEBKIT_LOAD_STARTED: + g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(webView)); + test->provisionalLoadStarted(); + break; + case WEBKIT_LOAD_REDIRECTED: + test->m_activeURI = webkit_web_view_get_uri(webView); + if (!test->m_redirectURI.isNull()) + g_assert_cmpstr(test->m_redirectURI.data(), ==, test->m_activeURI.data()); + test->provisionalLoadReceivedServerRedirect(); + break; + case WEBKIT_LOAD_COMMITTED: + g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(webView)); + test->loadCommitted(); + break; + case WEBKIT_LOAD_FINISHED: + if (!test->m_loadFailed) + g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(webView)); + test->loadFinished(); + break; + default: + g_assert_not_reached(); + } +} + +static void loadFailedCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, const char* failingURI, GError* error, LoadTrackingTest* test) +{ + test->m_loadFailed = true; + + switch (loadEvent) { + case WEBKIT_LOAD_STARTED: + g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(webView)); + g_assert(error); + test->provisionalLoadFailed(failingURI, error); + break; + case WEBKIT_LOAD_COMMITTED: + g_assert_cmpstr(test->m_activeURI.data(), ==, webkit_web_view_get_uri(webView)); + g_assert(error); + test->loadFailed(failingURI, error); + break; + default: + g_assert_not_reached(); + } +} + +static void estimatedProgressChangedCallback(GObject*, GParamSpec*, LoadTrackingTest* test) +{ + test->estimatedProgressChanged(); +} + +LoadTrackingTest::LoadTrackingTest() + : m_runLoadUntilCompletion(false) + , m_loadFailed(false) +{ + g_signal_connect(m_webView, "load-changed", G_CALLBACK(loadChangedCallback), this); + g_signal_connect(m_webView, "load-failed", G_CALLBACK(loadFailedCallback), this); + g_signal_connect(m_webView, "notify::estimated-load-progress", G_CALLBACK(estimatedProgressChangedCallback), this); + + g_assert(!webkit_web_view_get_uri(m_webView)); +} + +LoadTrackingTest::~LoadTrackingTest() +{ + g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); +} + +void LoadTrackingTest::waitUntilLoadFinished() +{ + m_estimatedProgress = 0; + m_runLoadUntilCompletion = true; + g_main_loop_run(m_mainLoop); +} + +void LoadTrackingTest::provisionalLoadStarted() +{ + m_loadEvents.append(ProvisionalLoadStarted); +} + +void LoadTrackingTest::provisionalLoadReceivedServerRedirect() +{ + m_loadEvents.append(ProvisionalLoadReceivedServerRedirect); +} + +void LoadTrackingTest::provisionalLoadFailed(const gchar* failingURI, GError* error) +{ + m_loadEvents.append(ProvisionalLoadFailed); + if (m_runLoadUntilCompletion) + g_main_loop_quit(m_mainLoop); +} + +void LoadTrackingTest::loadCommitted() +{ + m_loadEvents.append(LoadCommitted); +} + +void LoadTrackingTest::loadFinished() +{ + m_loadEvents.append(LoadFinished); + if (m_runLoadUntilCompletion) + g_main_loop_quit(m_mainLoop); +} + +void LoadTrackingTest::loadFailed(const gchar* failingURI, GError* error) +{ + m_loadEvents.append(LoadFailed); +} + +void LoadTrackingTest::estimatedProgressChanged() +{ + double progress = webkit_web_view_get_estimated_load_progress(m_webView); + g_assert_cmpfloat(m_estimatedProgress, <, progress); + m_estimatedProgress = progress; +} + diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h b/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h new file mode 100644 index 000000000..308aa9ce1 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.h @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2011 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 LoadTrackingTest_h +#define LoadTrackingTest_h + +#include "TestMain.h" +#include "WebViewTest.h" +#include <wtf/Vector.h> + +class LoadTrackingTest : public WebViewTest { +public: + MAKE_GLIB_TEST_FIXTURE(LoadTrackingTest); + LoadTrackingTest(); + virtual ~LoadTrackingTest(); + void waitUntilLoadFinished(); + + virtual void provisionalLoadStarted(); + virtual void provisionalLoadReceivedServerRedirect(); + virtual void provisionalLoadFailed(const gchar* failingURI, GError*); + virtual void loadCommitted(); + virtual void loadFinished(); + virtual void loadFailed(const char* failingURI, GError*); + virtual void estimatedProgressChanged(); + + void setRedirectURI(const char* uri) { m_redirectURI = uri; } + + enum LoadEvents { + ProvisionalLoadStarted, + ProvisionalLoadReceivedServerRedirect, + ProvisionalLoadFailed, + LoadCommitted, + LoadFinished, + LoadFailed + }; + bool m_runLoadUntilCompletion; + bool m_loadFailed; + Vector<LoadEvents> m_loadEvents; + float m_estimatedProgress; + CString m_redirectURI; +}; + +#endif // LoadTrackingTest_h diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp new file mode 100644 index 000000000..ac2a57235 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestBackForwardList.cpp @@ -0,0 +1,275 @@ +/* + * Copyright (C) 2011 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 "LoadTrackingTest.h" +#include "WebKitTestServer.h" +#include <gtk/gtk.h> +#include <libsoup/soup.h> +#include <string.h> +#include <webkit2/webkit2.h> + +// Back forward list limit is 100 by default. +static const size_t kBackForwardListLimit = 100; + +static WebKitTestServer* kServer; + +static void serverCallback(SoupServer* server, SoupMessage* msg, const char* path, GHashTable* query, SoupClientContext* context, gpointer data) +{ + if (msg->method != SOUP_METHOD_GET) { + soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED); + return; + } + + soup_message_set_status(msg, SOUP_STATUS_OK); + + char* body = g_strdup_printf("<html><title>%s</title><body>%s</body></html>", path + 1, path + 1); + soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, body, strlen(body)); + + soup_message_body_complete(msg->response_body); +} + +class BackForwardListTest: public LoadTrackingTest { +public: + MAKE_GLIB_TEST_FIXTURE(BackForwardListTest); + + enum { + Backward, + Forward + }; + + enum { + CurrentItem = 1 << 0, + AddedItem = 1 << 1, + RemovedItems = 1 << 2 + }; + + static void checkItem(WebKitBackForwardListItem* item, const char* title, const char* uri, const char* originalURI) + { + g_assert(item); + g_assert_cmpstr(webkit_back_forward_list_item_get_uri(item), ==, uri); + g_assert_cmpstr(webkit_back_forward_list_item_get_title(item), == , title); + g_assert_cmpstr(webkit_back_forward_list_item_get_original_uri(item), ==, originalURI); + } + + static void checkItemIndex(WebKitBackForwardList* list) + { + g_assert(webkit_back_forward_list_get_nth_item(list, -1) == webkit_back_forward_list_get_back_item(list)); + g_assert(webkit_back_forward_list_get_nth_item(list, 0) == webkit_back_forward_list_get_current_item(list)); + g_assert(webkit_back_forward_list_get_nth_item(list, 1) == webkit_back_forward_list_get_forward_item(list)); + } + + static void checkList(WebKitBackForwardList* list, unsigned type, WebKitBackForwardListItem** items, unsigned nItems) + { + GList* listItems = type == BackForwardListTest::Backward ? webkit_back_forward_list_get_back_list(list) : + webkit_back_forward_list_get_forward_list(list); + g_assert(listItems); + + unsigned i = 0; + for (GList* listItem = listItems; listItem; listItem = g_list_next(listItem), i++) { + g_assert_cmpuint(i, <, nItems); + g_assert(listItem->data == items[i]); + } + g_list_free(listItems); + } + + static void backForwardListChanged(WebKitBackForwardList* list, WebKitBackForwardListItem* addedItem, GList* removedItems, BackForwardListTest* test) + { + test->m_hasChanged = true; + + if (test->m_changedFlags & BackForwardListTest::AddedItem) { + g_assert(WEBKIT_IS_BACK_FORWARD_LIST_ITEM(addedItem)); + test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(addedItem)); + } else + g_assert(!addedItem); + + if (test->m_changedFlags & BackForwardListTest::RemovedItems) { + g_assert(removedItems); + for (GList* iter = removedItems; iter; iter = iter->next) { + g_assert(WEBKIT_IS_BACK_FORWARD_LIST_ITEM(iter->data)); + if (test->m_expectedRemovedItems) + g_assert(g_list_find(test->m_expectedRemovedItems, iter->data)); + } + + } else + g_assert(!removedItems); + } + + BackForwardListTest() + : m_list(webkit_web_view_get_back_forward_list(m_webView)) + , m_changedFlags(0) + , m_hasChanged(false) + , m_expectedRemovedItems(0) + { + g_signal_connect(m_list, "changed", G_CALLBACK(backForwardListChanged), this); + assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_list)); + } + + ~BackForwardListTest() + { + g_signal_handlers_disconnect_matched(m_list, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); + } + + void waitUntilLoadFinished() + { + m_hasChanged = false; + LoadTrackingTest::waitUntilLoadFinished(); + g_assert(m_hasChanged); + } + + void waitUntilLoadFinishedAndCheckRemovedItems(GList* removedItems) + { + m_expectedRemovedItems = removedItems; + waitUntilLoadFinished(); + m_expectedRemovedItems = 0; + } + + WebKitBackForwardList* m_list; + unsigned long m_changedFlags; + bool m_hasChanged; + GList* m_expectedRemovedItems; +}; + +static void testBackForwardListNavigation(BackForwardListTest* test, gconstpointer) +{ + WebKitBackForwardListItem* items[1]; + + g_assert(!webkit_web_view_can_go_back(test->m_webView)); + g_assert(!webkit_web_view_can_go_forward(test->m_webView)); + + g_assert_cmpuint(webkit_back_forward_list_get_length(test->m_list), ==, 0); + g_assert(!webkit_back_forward_list_get_current_item(test->m_list)); + g_assert(!webkit_back_forward_list_get_back_item(test->m_list)); + g_assert(!webkit_back_forward_list_get_forward_item(test->m_list)); + BackForwardListTest::checkItemIndex(test->m_list); + g_assert(!webkit_back_forward_list_get_back_list(test->m_list)); + g_assert(!webkit_back_forward_list_get_forward_list(test->m_list)); + + CString uriPage1 = kServer->getURIForPath("/Page1"); + test->m_changedFlags = BackForwardListTest::CurrentItem | BackForwardListTest::AddedItem; + test->loadURI(uriPage1.data()); + test->waitUntilLoadFinished(); + + g_assert(!webkit_web_view_can_go_back(test->m_webView)); + g_assert(!webkit_web_view_can_go_forward(test->m_webView)); + + g_assert_cmpuint(webkit_back_forward_list_get_length(test->m_list), ==, 1); + WebKitBackForwardListItem* itemPage1 = webkit_back_forward_list_get_current_item(test->m_list); + BackForwardListTest::checkItem(itemPage1, "Page1", uriPage1.data(), uriPage1.data()); + g_assert(!webkit_back_forward_list_get_back_item(test->m_list)); + g_assert(!webkit_back_forward_list_get_forward_item(test->m_list)); + BackForwardListTest::checkItemIndex(test->m_list); + g_assert(!webkit_back_forward_list_get_back_list(test->m_list)); + g_assert(!webkit_back_forward_list_get_forward_list(test->m_list)); + + CString uriPage2 = kServer->getURIForPath("/Page2"); + test->m_changedFlags = BackForwardListTest::CurrentItem | BackForwardListTest::AddedItem; + test->loadURI(uriPage2.data()); + test->waitUntilLoadFinished(); + + g_assert(webkit_web_view_can_go_back(test->m_webView)); + g_assert(!webkit_web_view_can_go_forward(test->m_webView)); + + g_assert_cmpuint(webkit_back_forward_list_get_length(test->m_list), ==, 2); + WebKitBackForwardListItem* itemPage2 = webkit_back_forward_list_get_current_item(test->m_list); + BackForwardListTest::checkItem(itemPage2, "Page2", uriPage2.data(), uriPage2.data()); + g_assert(webkit_back_forward_list_get_back_item(test->m_list) == itemPage1); + g_assert(!webkit_back_forward_list_get_forward_item(test->m_list)); + BackForwardListTest::checkItemIndex(test->m_list); + items[0] = itemPage1; + BackForwardListTest::checkList(test->m_list, BackForwardListTest::Backward, items, 1); + g_assert(!webkit_back_forward_list_get_forward_list(test->m_list)); + + test->m_changedFlags = BackForwardListTest::CurrentItem; + test->goBack(); + test->waitUntilLoadFinished(); + + g_assert(!webkit_web_view_can_go_back(test->m_webView)); + g_assert(webkit_web_view_can_go_forward(test->m_webView)); + + g_assert_cmpuint(webkit_back_forward_list_get_length(test->m_list), ==, 2); + g_assert(itemPage1 == webkit_back_forward_list_get_current_item(test->m_list)); + BackForwardListTest::checkItem(webkit_back_forward_list_get_current_item(test->m_list), "Page1", uriPage1.data(), uriPage1.data()); + g_assert(!webkit_back_forward_list_get_back_item(test->m_list)); + g_assert(webkit_back_forward_list_get_forward_item(test->m_list) == itemPage2); + BackForwardListTest::checkItemIndex(test->m_list); + g_assert(!webkit_back_forward_list_get_back_list(test->m_list)); + items[0] = itemPage2; + BackForwardListTest::checkList(test->m_list, BackForwardListTest::Forward, items, 1); + + test->m_changedFlags = BackForwardListTest::CurrentItem; + test->goForward(); + test->waitUntilLoadFinished(); + + g_assert(webkit_web_view_can_go_back(test->m_webView)); + g_assert(!webkit_web_view_can_go_forward(test->m_webView)); + + g_assert_cmpuint(webkit_back_forward_list_get_length(test->m_list), ==, 2); + g_assert(itemPage2 == webkit_back_forward_list_get_current_item(test->m_list)); + BackForwardListTest::checkItem(webkit_back_forward_list_get_current_item(test->m_list), "Page2", uriPage2.data(), uriPage2.data()); + g_assert(webkit_back_forward_list_get_back_item(test->m_list) == itemPage1); + g_assert(!webkit_back_forward_list_get_forward_item(test->m_list)); + BackForwardListTest::checkItemIndex(test->m_list); + items[0] = itemPage1; + BackForwardListTest::checkList(test->m_list, BackForwardListTest::Backward, items, 1); + g_assert(!webkit_back_forward_list_get_forward_list(test->m_list)); + + test->m_changedFlags = BackForwardListTest::CurrentItem; + test->goToBackForwardListItem(itemPage1); + test->waitUntilLoadFinished(); + + g_assert(itemPage1 == webkit_back_forward_list_get_current_item(test->m_list)); +} + +static void testBackForwardListLimitAndCache(BackForwardListTest* test, gconstpointer) +{ + for (size_t i = 0; i < kBackForwardListLimit; i++) { + GOwnPtr<char> path(g_strdup_printf("/Page%d", i)); + test->m_changedFlags = BackForwardListTest::CurrentItem | BackForwardListTest::AddedItem; + test->loadURI(kServer->getURIForPath(path.get()).data()); + test->waitUntilLoadFinished(); + } + + g_assert_cmpuint(webkit_back_forward_list_get_length(test->m_list), ==, kBackForwardListLimit); + WebKitBackForwardListItem* itemPageFirst = webkit_back_forward_list_get_nth_item(test->m_list, -(kBackForwardListLimit - 1)); + GOwnPtr<GList> removedItems(g_list_prepend(0, itemPageFirst)); + + GOwnPtr<char> path(g_strdup_printf("/Page%d", kBackForwardListLimit)); + test->m_changedFlags = BackForwardListTest::CurrentItem | BackForwardListTest::AddedItem | BackForwardListTest::RemovedItems; + test->loadURI(kServer->getURIForPath(path.get()).data()); + test->waitUntilLoadFinishedAndCheckRemovedItems(removedItems.get()); + + g_assert_cmpuint(webkit_back_forward_list_get_length(test->m_list), ==, kBackForwardListLimit); +} + +void beforeAll() +{ + kServer = new WebKitTestServer(); + kServer->run(serverCallback); + + BackForwardListTest::add("BackForwardList", "navigation", testBackForwardListNavigation); + BackForwardListTest::add("BackForwardList", "list-limit-and-cache", testBackForwardListLimitAndCache); +} + +void afterAll() +{ + delete kServer; +} + diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp new file mode 100644 index 000000000..8622af19c --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2011 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 "TestMain.h" + +#include <gtk/gtk.h> + +void beforeAll(); +void afterAll(); + +int main(int argc, char** argv) +{ + gtk_test_init(&argc, &argv, 0); + g_setenv("WEBKIT_EXEC_PATH", WEBKIT_EXEC_PATH, FALSE); + g_test_bug_base("https://bugs.webkit.org/"); + + beforeAll(); + int returnValue = g_test_run(); + afterAll(); + + return returnValue; +} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h new file mode 100644 index 000000000..631096a76 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2011 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 TestMain_h +#define TestMain_h + +#include <glib-object.h> +#include <JavaScriptCore/GOwnPtr.h> +#include <JavaScriptCore/HashSet.h> + +#define MAKE_GLIB_TEST_FIXTURE(ClassName) \ + static void setUp(ClassName* fixture, gconstpointer data) \ + { \ + new (fixture) ClassName; \ + } \ + static void tearDown(ClassName* fixture, gconstpointer data) \ + { \ + fixture->~ClassName(); \ + } \ + static void add(const char* suiteName, const char* testName, void (*testFunc)(ClassName*, const void*)) \ + { \ + GOwnPtr<gchar> testPath(g_strdup_printf("/webkit2/%s/%s", suiteName, testName)); \ + g_test_add(testPath.get(), ClassName, 0, ClassName::setUp, testFunc, ClassName::tearDown); \ + } + +class Test +{ +public: + MAKE_GLIB_TEST_FIXTURE(Test); + + ~Test() + { + g_assert(m_watchedObjects.isEmpty()); + } + + static void objectFinalized(Test* test, GObject* finalizedObject) + { + test->m_watchedObjects.remove(finalizedObject); + } + + void assertObjectIsDeletedWhenTestFinishes(GObject* object) + { + m_watchedObjects.add(object); + g_object_weak_ref(object, reinterpret_cast<GWeakNotify>(objectFinalized), this); + } + + HashSet<GObject*> m_watchedObjects; +}; + +#endif // TestMain_h diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp new file mode 100644 index 000000000..93e9c9cd2 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitSettings.cpp @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * Neither the name of Motorola Mobility, Inc. nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "TestMain.h" +#include <JavaScriptCore/GRefPtr.h> +#include <gtk/gtk.h> +#include <webkit2/webkit2.h> + +static void testWebKitSettings(Test*, gconstpointer) +{ + WebKitSettings* settings = webkit_settings_new(); + + // JavaScript is enabled by default. + g_assert(webkit_settings_get_enable_javascript(settings)); + webkit_settings_set_enable_javascript(settings, FALSE); + g_assert(!webkit_settings_get_enable_javascript(settings)); + + // By default auto-load-image is true. + g_assert(webkit_settings_get_auto_load_images(settings)); + webkit_settings_set_auto_load_images(settings, FALSE); + g_assert(!webkit_settings_get_auto_load_images(settings)); + + // load-icons-ignoring-image-load-setting is false by default. + g_assert(!webkit_settings_get_load_icons_ignoring_image_load_setting(settings)); + webkit_settings_set_load_icons_ignoring_image_load_setting(settings, TRUE); + g_assert(webkit_settings_get_load_icons_ignoring_image_load_setting(settings)); + + // Offline application cache is true by default. + g_assert(webkit_settings_get_enable_offline_web_application_cache(settings)); + webkit_settings_set_enable_offline_web_application_cache(settings, FALSE); + g_assert(!webkit_settings_get_enable_offline_web_application_cache(settings)); + + // Local storage is enable by default. + g_assert(webkit_settings_get_enable_html5_local_storage(settings)); + webkit_settings_set_enable_html5_local_storage(settings, FALSE); + g_assert(!webkit_settings_get_enable_html5_local_storage(settings)); + + // HTML5 database is enabled by default. + g_assert(webkit_settings_get_enable_html5_database(settings)); + webkit_settings_set_enable_html5_database(settings, FALSE); + g_assert(!webkit_settings_get_enable_html5_database(settings)); + + // XSS Auditor is enabled by default. + g_assert(webkit_settings_get_enable_xss_auditor(settings)); + webkit_settings_set_enable_xss_auditor(settings, FALSE); + g_assert(!webkit_settings_get_enable_xss_auditor(settings)); + + // Frame flattening is disabled by default. + g_assert(!webkit_settings_get_enable_frame_flattening(settings)); + webkit_settings_set_enable_frame_flattening(settings, TRUE); + g_assert(webkit_settings_get_enable_frame_flattening(settings)); + + // Plugins are enabled by default. + g_assert(webkit_settings_get_enable_plugins(settings)); + webkit_settings_set_enable_plugins(settings, FALSE); + g_assert(!webkit_settings_get_enable_plugins(settings)); + + // Java is enabled by default. + g_assert(webkit_settings_get_enable_java(settings)); + webkit_settings_set_enable_java(settings, FALSE); + g_assert(!webkit_settings_get_enable_java(settings)); + + // By default, JavaScript can open windows automatically is disabled. + g_assert(!webkit_settings_get_javascript_can_open_windows_automatically(settings)); + webkit_settings_set_javascript_can_open_windows_automatically(settings, TRUE); + g_assert(webkit_settings_get_javascript_can_open_windows_automatically(settings)); + + // By default hyper link auditing is disabled. + g_assert(!webkit_settings_get_enable_hyperlink_auditing(settings)); + webkit_settings_set_enable_hyperlink_auditing(settings, TRUE); + g_assert(webkit_settings_get_enable_hyperlink_auditing(settings)); + + // Default font family is "sans-serif". + g_assert_cmpstr(webkit_settings_get_default_font_family(settings), ==, "sans-serif"); + webkit_settings_set_default_font_family(settings, "monospace"); + g_assert_cmpstr(webkit_settings_get_default_font_family(settings), ==, "monospace"); + + // Default monospace font family font family is "monospace". + g_assert_cmpstr(webkit_settings_get_monospace_font_family(settings), ==, "monospace"); + webkit_settings_set_monospace_font_family(settings, "sans-serif"); + g_assert_cmpstr(webkit_settings_get_monospace_font_family(settings), ==, "sans-serif"); + + // Default serif font family is "serif". + g_assert_cmpstr(webkit_settings_get_serif_font_family(settings), ==, "serif"); + webkit_settings_set_serif_font_family(settings, "sans-serif"); + g_assert_cmpstr(webkit_settings_get_serif_font_family(settings), ==, "sans-serif"); + + // Default sans serif font family is "sans-serif". + g_assert_cmpstr(webkit_settings_get_sans_serif_font_family(settings), ==, "sans-serif"); + webkit_settings_set_sans_serif_font_family(settings, "serif"); + g_assert_cmpstr(webkit_settings_get_sans_serif_font_family(settings), ==, "serif"); + + // Default cursive font family "serif". + g_assert_cmpstr(webkit_settings_get_cursive_font_family(settings), ==, "serif"); + webkit_settings_set_cursive_font_family(settings, "sans-serif"); + g_assert_cmpstr(webkit_settings_get_cursive_font_family(settings), ==, "sans-serif"); + + // Default fantasy font family is "serif". + g_assert_cmpstr(webkit_settings_get_fantasy_font_family(settings), ==, "serif"); + webkit_settings_set_fantasy_font_family(settings, "sans-serif"); + g_assert_cmpstr(webkit_settings_get_fantasy_font_family(settings), ==, "sans-serif"); + + // Default pictograph font family is "serif". + g_assert_cmpstr(webkit_settings_get_pictograph_font_family(settings), ==, "serif"); + webkit_settings_set_pictograph_font_family(settings, "sans-serif"); + g_assert_cmpstr(webkit_settings_get_pictograph_font_family(settings), ==, "sans-serif"); + + // Default font size is 16. + g_assert_cmpuint(webkit_settings_get_default_font_size(settings), ==, 16); + webkit_settings_set_default_font_size(settings, 14); + g_assert_cmpuint(webkit_settings_get_default_font_size(settings), ==, 14); + + // Default monospace font size is 13. + g_assert_cmpuint(webkit_settings_get_default_monospace_font_size(settings), ==, 13); + webkit_settings_set_default_monospace_font_size(settings, 10); + g_assert_cmpuint(webkit_settings_get_default_monospace_font_size(settings), ==, 10); + + // Default minimum font size is 0. + g_assert_cmpuint(webkit_settings_get_minimum_font_size(settings), ==, 0); + webkit_settings_set_minimum_font_size(settings, 7); + g_assert_cmpuint(webkit_settings_get_minimum_font_size(settings), ==, 7); + + // Default charset is "iso-8859-1". + g_assert_cmpstr(webkit_settings_get_default_charset(settings), ==, "iso-8859-1"); + webkit_settings_set_default_charset(settings, "utf8"); + g_assert_cmpstr(webkit_settings_get_default_charset(settings), ==, "utf8"); + + g_assert(!webkit_settings_get_enable_private_browsing(settings)); + webkit_settings_set_enable_private_browsing(settings, TRUE); + g_assert(webkit_settings_get_enable_private_browsing(settings)); + + g_assert(!webkit_settings_get_enable_developer_extras(settings)); + webkit_settings_set_enable_developer_extras(settings, TRUE); + g_assert(webkit_settings_get_enable_developer_extras(settings)); + + g_assert(webkit_settings_get_enable_resizable_text_areas(settings)); + webkit_settings_set_enable_resizable_text_areas(settings, FALSE); + g_assert(!webkit_settings_get_enable_resizable_text_areas(settings)); + + g_assert(webkit_settings_get_enable_tabs_to_links(settings)); + webkit_settings_set_enable_tabs_to_links(settings, FALSE); + g_assert(!webkit_settings_get_enable_tabs_to_links(settings)); + + g_assert(!webkit_settings_get_enable_dns_prefetching(settings)); + webkit_settings_set_enable_dns_prefetching(settings, TRUE); + g_assert(webkit_settings_get_enable_dns_prefetching(settings)); + + // Caret browsing is disabled by default. + g_assert(!webkit_settings_get_enable_caret_browsing(settings)); + webkit_settings_set_enable_caret_browsing(settings, TRUE); + g_assert(webkit_settings_get_enable_caret_browsing(settings)); + + // Fullscreen JavaScript API is disabled by default. + g_assert(!webkit_settings_get_enable_fullscreen(settings)); + webkit_settings_set_enable_fullscreen(settings, TRUE); + g_assert(webkit_settings_get_enable_fullscreen(settings)); + + g_object_unref(G_OBJECT(settings)); +} + +void testWebKitSettingsNewWithSettings(Test* test, gconstpointer) +{ + GRefPtr<WebKitSettings> settings = adoptGRef(webkit_settings_new_with_settings("enable-javascript", FALSE, + "auto-load-images", FALSE, + "load-icons-ignoring-image-load-setting", TRUE, + NULL)); + test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(settings.get())); + g_assert(!webkit_settings_get_enable_javascript(settings.get())); + g_assert(!webkit_settings_get_auto_load_images(settings.get())); + g_assert(webkit_settings_get_load_icons_ignoring_image_load_setting(settings.get())); +} + +void beforeAll() +{ + Test::add("WebKitSettings", "webkit-settings", testWebKitSettings); + Test::add("WebKitSettings", "new-with-settings", testWebKitSettingsNewWithSettings); +} + +void afterAll() +{ +} + diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp new file mode 100644 index 000000000..ad7ce5b8b --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2011 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 "TestMain.h" +#include <gtk/gtk.h> +#include <webkit2/webkit2.h> + +static void testWebContextDefault(Test* test, gconstpointer) +{ + // Check there's a single instance of the default web context. + g_assert(webkit_web_context_get_default() == webkit_web_context_get_default()); +} + +void beforeAll() +{ + Test::add("WebKitWebContext", "default-context", testWebContextDefault); +} + +void afterAll() +{ +} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp new file mode 100644 index 000000000..aaa9ff873 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp @@ -0,0 +1,261 @@ +/* + * Copyright (C) 2009, 2010 Gustavo Noronha Silva + * Copyright (C) 2009, 2011 Igalia S.L. + * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. + * + * 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 "LoadTrackingTest.h" +#include "WebKitTestServer.h" +#include <gtk/gtk.h> +#include <libsoup/soup.h> +#include <wtf/text/CString.h> + +static WebKitTestServer* kServer; + +static void testLoadingStatus(LoadTrackingTest* test, gconstpointer data) +{ + test->setRedirectURI(kServer->getURIForPath("/normal").data()); + test->loadURI(kServer->getURIForPath("/redirect").data()); + test->waitUntilLoadFinished(); + + Vector<LoadTrackingTest::LoadEvents>& events = test->m_loadEvents; + g_assert_cmpint(events.size(), ==, 4); + g_assert_cmpint(events[0], ==, LoadTrackingTest::ProvisionalLoadStarted); + g_assert_cmpint(events[1], ==, LoadTrackingTest::ProvisionalLoadReceivedServerRedirect); + g_assert_cmpint(events[2], ==, LoadTrackingTest::LoadCommitted); + g_assert_cmpint(events[3], ==, LoadTrackingTest::LoadFinished); +} + +static void testLoadingError(LoadTrackingTest* test, gconstpointer) +{ + test->loadURI(kServer->getURIForPath("/error").data()); + test->waitUntilLoadFinished(); + + Vector<LoadTrackingTest::LoadEvents>& events = test->m_loadEvents; + g_assert_cmpint(events.size(), ==, 3); + g_assert_cmpint(events[0], ==, LoadTrackingTest::ProvisionalLoadStarted); + g_assert_cmpint(events[1], ==, LoadTrackingTest::ProvisionalLoadFailed); + g_assert_cmpint(events[2], ==, LoadTrackingTest::LoadFinished); +} + +static void assertNormalLoadHappenedAndClearEvents(Vector<LoadTrackingTest::LoadEvents>& events) +{ + g_assert_cmpint(events.size(), ==, 3); + g_assert_cmpint(events[0], ==, LoadTrackingTest::ProvisionalLoadStarted); + g_assert_cmpint(events[1], ==, LoadTrackingTest::LoadCommitted); + g_assert_cmpint(events[2], ==, LoadTrackingTest::LoadFinished); + events.clear(); +} + +static void testLoadHtml(LoadTrackingTest* test, gconstpointer) +{ + test->loadHtml("<html><body>Hello WebKit-GTK+</body></html>", 0); + test->waitUntilLoadFinished(); + assertNormalLoadHappenedAndClearEvents(test->m_loadEvents); +} + +static void testLoadPlainText(LoadTrackingTest* test, gconstpointer) +{ + test->loadPlainText("Hello WebKit-GTK+"); + test->waitUntilLoadFinished(); + assertNormalLoadHappenedAndClearEvents(test->m_loadEvents); +} + +static void testLoadRequest(LoadTrackingTest* test, gconstpointer) +{ + GRefPtr<WebKitURIRequest> request(webkit_uri_request_new(kServer->getURIForPath("/normal").data())); + test->loadRequest(request.get()); + test->waitUntilLoadFinished(); + assertNormalLoadHappenedAndClearEvents(test->m_loadEvents); +} + +class LoadStopTrackingTest : public LoadTrackingTest { +public: + MAKE_GLIB_TEST_FIXTURE(LoadStopTrackingTest); + + virtual void loadCommitted() + { + LoadTrackingTest::loadCommitted(); + webkit_web_view_stop_loading(m_webView); + } + virtual void loadFailed(const gchar* failingURI, GError* error) + { + g_assert(g_error_matches(error, WEBKIT_NETWORK_ERROR, WEBKIT_NETWORK_ERROR_CANCELLED)); + LoadTrackingTest::loadFailed(failingURI, error); + } +}; + +static void testLoadCancelled(LoadStopTrackingTest* test, gconstpointer) +{ + test->loadURI(kServer->getURIForPath("/cancelled").data()); + test->waitUntilLoadFinished(); + + Vector<LoadTrackingTest::LoadEvents>& events = test->m_loadEvents; + g_assert_cmpint(events.size(), ==, 4); + g_assert_cmpint(events[0], ==, LoadTrackingTest::ProvisionalLoadStarted); + g_assert_cmpint(events[1], ==, LoadTrackingTest::LoadCommitted); + g_assert_cmpint(events[2], ==, LoadTrackingTest::LoadFailed); + g_assert_cmpint(events[3], ==, LoadTrackingTest::LoadFinished); +} + +static void testWebViewTitle(LoadTrackingTest* test, gconstpointer) +{ + g_assert(!webkit_web_view_get_title(test->m_webView)); + test->loadHtml("<html><head><title>Welcome to WebKit-GTK+!</title></head></html>", 0); + test->waitUntilLoadFinished(); + g_assert_cmpstr(webkit_web_view_get_title(test->m_webView), ==, "Welcome to WebKit-GTK+!"); +} + +static void testWebViewReload(LoadTrackingTest* test, gconstpointer) +{ + // Check that nothing happens when there's nothing to reload. + webkit_web_view_reload(test->m_webView); + test->wait(0.25); // Wait for a quarter of a second. + + test->loadURI(kServer->getURIForPath("/normal").data()); + test->waitUntilLoadFinished(); + assertNormalLoadHappenedAndClearEvents(test->m_loadEvents); + + webkit_web_view_reload(test->m_webView); + test->waitUntilLoadFinished(); + assertNormalLoadHappenedAndClearEvents(test->m_loadEvents); +} + +static void testLoadProgress(LoadTrackingTest* test, gconstpointer) +{ + test->loadURI(kServer->getURIForPath("/normal").data()); + test->waitUntilLoadFinished(); + g_assert_cmpfloat(test->m_estimatedProgress, ==, 1); +} + +class ViewURITrackingTest: public LoadTrackingTest { +public: + MAKE_GLIB_TEST_FIXTURE(ViewURITrackingTest); + + static void uriChanged(GObject*, GParamSpec*, ViewURITrackingTest* test) + { + g_assert_cmpstr(test->m_activeURI.data(), !=, webkit_web_view_get_uri(test->m_webView)); + test->m_activeURI = webkit_web_view_get_uri(test->m_webView); + } + + ViewURITrackingTest() + : m_activeURI(webkit_web_view_get_uri(m_webView)) + { + g_assert(m_activeURI.isNull()); + g_signal_connect(m_webView, "notify::uri", G_CALLBACK(uriChanged), this); + } + + void provisionalLoadStarted() + { + checkActiveURI("/redirect"); + } + + void provisionalLoadReceivedServerRedirect() + { + checkActiveURI("/normal"); + } + + void loadCommitted() + { + checkActiveURI("/normal"); + } + + void loadFinished() + { + checkActiveURI("/normal"); + LoadTrackingTest::loadFinished(); + } + + CString m_activeURI; + +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()); + } +}; + +static void testWebViewActiveURI(ViewURITrackingTest* test, gconstpointer) +{ + test->loadURI(kServer->getURIForPath("/redirect").data()); + test->waitUntilLoadFinished(); +} + +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!" + "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!" + "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!" + "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!" + "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!" + "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!" + "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!" + "Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!</body></html>"; + + if (message->method != SOUP_METHOD_GET) { + soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED); + return; + } + + soup_message_set_status(message, SOUP_STATUS_OK); + + if (g_str_equal(path, "/normal")) + soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString)); + else if (g_str_equal(path, "/error")) + soup_message_set_status(message, SOUP_STATUS_CANT_CONNECT); + else if (g_str_equal(path, "/redirect")) { + soup_message_set_status(message, SOUP_STATUS_MOVED_PERMANENTLY); + soup_message_headers_append(message->response_headers, "Location", "/normal"); + } else if (g_str_equal(path, "/cancelled")) { + soup_message_headers_set_encoding(message->response_headers, SOUP_ENCODING_CHUNKED); + soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, responseString, strlen(responseString)); + soup_server_unpause_message(server, message); + return; + } + + soup_message_body_complete(message->response_body); +} + +void beforeAll() +{ + kServer = new WebKitTestServer(); + kServer->run(serverCallback); + + LoadTrackingTest::add("WebKitWebLoaderClient", "loading-status", testLoadingStatus); + LoadTrackingTest::add("WebKitWebLoaderClient", "loading-error", testLoadingError); + LoadTrackingTest::add("WebKitWebView", "load-html", testLoadHtml); + LoadTrackingTest::add("WebKitWebView", "load-plain-text", testLoadPlainText); + LoadTrackingTest::add("WebKitWebView", "load-request", testLoadRequest); + LoadStopTrackingTest::add("WebKitWebView", "stop-loading", testLoadCancelled); + LoadTrackingTest::add("WebKitWebView", "title", testWebViewTitle); + LoadTrackingTest::add("WebKitWebView", "progress", testLoadProgress); + LoadTrackingTest::add("WebKitWebView", "reload", testWebViewReload); + + // This test checks that web view notify::uri signal is correctly emitted + // and the uri is already updated when loader client signals are emitted. + ViewURITrackingTest::add("WebKitWebView", "active-uri", testWebViewActiveURI); +} + +void afterAll() +{ + delete kServer; +} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp new file mode 100644 index 000000000..16375ed20 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp @@ -0,0 +1,381 @@ +/* + * Copyright (C) 2011 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 "WebViewTest.h" +#include <wtf/HashSet.h> +#include <wtf/gobject/GRefPtr.h> +#include <wtf/text/StringHash.h> + +static void testWebViewDefaultContext(WebViewTest* test, gconstpointer) +{ + g_assert(webkit_web_view_get_context(test->m_webView) == webkit_web_context_get_default()); +} + +static void testWebViewCustomCharset(WebViewTest* test, gconstpointer) +{ + g_assert(!webkit_web_view_get_custom_charset(test->m_webView)); + webkit_web_view_set_custom_charset(test->m_webView, "utf8"); + g_assert_cmpstr(webkit_web_view_get_custom_charset(test->m_webView), ==, "utf8"); + // Go back to the default charset. + webkit_web_view_set_custom_charset(test->m_webView, 0); + g_assert(!webkit_web_view_get_custom_charset(test->m_webView)); +} + +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()); + + WebKitSettings* settings = webkit_web_view_get_settings(test->m_webView); + g_assert(settings != defaultSettings); + g_assert(!webkit_settings_get_enable_javascript(settings)); + + GRefPtr<GtkWidget> webView2 = webkit_web_view_new(); + test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webView2.get())); + webkit_web_view_set_settings(WEBKIT_WEB_VIEW(webView2.get()), settings); + 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()); + g_assert(webkit_settings_get_enable_javascript(settings)); +} + +static void replaceContentTitleChangedCallback(WebViewTest* test) +{ + g_main_loop_quit(test->m_mainLoop); +} + +static void replaceContentLoadCallback() +{ + g_assert_not_reached(); +} + +static void testWebViewReplaceContent(WebViewTest* test, gconstpointer) +{ + g_signal_connect_swapped(test->m_webView, "notify::title", G_CALLBACK(replaceContentTitleChangedCallback), test); + g_signal_connect(test->m_webView, "load-changed", G_CALLBACK(replaceContentLoadCallback), test); + g_signal_connect(test->m_webView, "load-failed", G_CALLBACK(replaceContentLoadCallback), test); + test->replaceContent("<html><head><title>Content Replaced</title></head><body>New Content</body></html>", + "http://foo.com/bar", 0); + g_main_loop_run(test->m_mainLoop); +} + +static const char* kAlertDialogMessage = "WebKitGTK+ alert dialog message"; +static const char* kConfirmDialogMessage = "WebKitGTK+ confirm dialog message"; +static const char* kPromptDialogMessage = "WebKitGTK+ prompt dialog message"; +static const char* kPromptDialogReturnedText = "WebKitGTK+ prompt dialog returned text"; + +class UIClientTest: public WebViewTest { +public: + MAKE_GLIB_TEST_FIXTURE(UIClientTest); + + enum WebViewEvents { + Create, + ReadyToShow, + Close + }; + + enum ScriptType { + Alert, + Confirm, + Prompt + }; + + class WindowProperties { + public: + WindowProperties() + : m_toolbarVisible(true) + , m_statusbarVisible(true) + , m_scrollbarsVisible(true) + , m_menubarVisible(true) + , m_locationbarVisible(true) + , m_resizable(true) + , m_fullscreen(false) + { + memset(&m_geometry, 0, sizeof(GdkRectangle)); + } + + WindowProperties(WebKitWindowProperties* windowProperties) + : m_toolbarVisible(webkit_window_properties_get_toolbar_visible(windowProperties)) + , m_statusbarVisible(webkit_window_properties_get_statusbar_visible(windowProperties)) + , m_scrollbarsVisible(webkit_window_properties_get_scrollbars_visible(windowProperties)) + , m_menubarVisible(webkit_window_properties_get_menubar_visible(windowProperties)) + , m_locationbarVisible(webkit_window_properties_get_locationbar_visible(windowProperties)) + , m_resizable(webkit_window_properties_get_resizable(windowProperties)) + , m_fullscreen(webkit_window_properties_get_fullscreen(windowProperties)) + { + webkit_window_properties_get_geometry(windowProperties, &m_geometry); + } + + WindowProperties(GdkRectangle* geometry, bool toolbarVisible, bool statusbarVisible, bool scrollbarsVisible, bool menubarVisible, + bool locationbarVisible, bool resizable, bool fullscreen) + : m_geometry(*geometry) + , m_toolbarVisible(toolbarVisible) + , m_statusbarVisible(statusbarVisible) + , m_scrollbarsVisible(scrollbarsVisible) + , m_menubarVisible(menubarVisible) + , m_locationbarVisible(locationbarVisible) + , m_resizable(resizable) + , m_fullscreen(fullscreen) + { + } + + void assertEqual(const WindowProperties& other) const + { + // FIXME: We should assert x and y are equal, but we are getting an incorrect + // value from WebCore (280 instead of 150). + g_assert_cmpint(m_geometry.width, ==, other.m_geometry.width); + g_assert_cmpint(m_geometry.height, ==, other.m_geometry.height); + g_assert_cmpint(static_cast<int>(m_toolbarVisible), ==, static_cast<int>(other.m_toolbarVisible)); + g_assert_cmpint(static_cast<int>(m_statusbarVisible), ==, static_cast<int>(other.m_statusbarVisible)); + g_assert_cmpint(static_cast<int>(m_scrollbarsVisible), ==, static_cast<int>(other.m_scrollbarsVisible)); + g_assert_cmpint(static_cast<int>(m_menubarVisible), ==, static_cast<int>(other.m_menubarVisible)); + g_assert_cmpint(static_cast<int>(m_locationbarVisible), ==, static_cast<int>(other.m_locationbarVisible)); + g_assert_cmpint(static_cast<int>(m_resizable), ==, static_cast<int>(other.m_resizable)); + g_assert_cmpint(static_cast<int>(m_fullscreen), ==, static_cast<int>(other.m_fullscreen)); + } + + private: + GdkRectangle m_geometry; + + bool m_toolbarVisible; + bool m_statusbarVisible; + bool m_scrollbarsVisible; + bool m_menubarVisible; + bool m_locationbarVisible; + + bool m_resizable; + bool m_fullscreen; + }; + + static void windowPropertiesNotifyCallback(GObject*, GParamSpec* paramSpec, UIClientTest* test) + { + test->m_windowPropertiesChanged.add(g_param_spec_get_name(paramSpec)); + } + + static void viewClose(WebKitWebView* webView, UIClientTest* test) + { + g_assert(webView != test->m_webView); + + test->m_webViewEvents.append(Close); + g_object_unref(webView); + + g_main_loop_quit(test->m_mainLoop); + } + + static void viewReadyToShow(WebKitWebView* webView, UIClientTest* test) + { + g_assert(webView != test->m_webView); + + WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(webView); + g_assert(windowProperties); + WindowProperties(windowProperties).assertEqual(test->m_windowProperties); + + test->m_webViewEvents.append(ReadyToShow); + } + + static GtkWidget* viewCreate(WebKitWebView* webView, UIClientTest* test) + { + g_assert(webView == test->m_webView); + + GtkWidget* newWebView = webkit_web_view_new_with_context(webkit_web_view_get_context(webView)); + g_object_ref_sink(newWebView); + + test->m_webViewEvents.append(Create); + + WebKitWindowProperties* windowProperties = webkit_web_view_get_window_properties(WEBKIT_WEB_VIEW(newWebView)); + g_assert(windowProperties); + test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(windowProperties)); + test->m_windowPropertiesChanged.clear(); + g_signal_connect(windowProperties, "notify", G_CALLBACK(windowPropertiesNotifyCallback), test); + + g_signal_connect(newWebView, "ready-to-show", G_CALLBACK(viewReadyToShow), test); + g_signal_connect(newWebView, "close", G_CALLBACK(viewClose), test); + + return newWebView; + } + + static gboolean scriptAlert(WebKitWebView*, const char* message, UIClientTest* test) + { + switch (test->m_scriptType) { + case UIClientTest::Alert: + g_assert_cmpstr(message, ==, kAlertDialogMessage); + break; + case UIClientTest::Confirm: + g_assert(test->m_scriptDialogConfirmed); + g_assert_cmpstr(message, ==, "confirmed"); + + break; + case UIClientTest::Prompt: + g_assert_cmpstr(message, ==, kPromptDialogReturnedText); + break; + } + + g_main_loop_quit(test->m_mainLoop); + + return TRUE; + } + + static gboolean scriptConfirm(WebKitWebView*, const char* message, gboolean* confirmed, UIClientTest* test) + { + g_assert_cmpstr(message, ==, kConfirmDialogMessage); + g_assert(confirmed); + test->m_scriptDialogConfirmed = !test->m_scriptDialogConfirmed; + *confirmed = test->m_scriptDialogConfirmed; + + return TRUE; + } + + static gboolean scriptPrompt(WebKitWebView*, const char* message, const char* defaultText, char **text, UIClientTest* test) + { + g_assert_cmpstr(message, ==, kPromptDialogMessage); + g_assert_cmpstr(defaultText, ==, "default"); + g_assert(text); + *text = g_strdup(kPromptDialogReturnedText); + + return TRUE; + } + + UIClientTest() + : m_scriptType(Alert) + , m_scriptDialogConfirmed(true) + { + webkit_settings_set_javascript_can_open_windows_automatically(webkit_web_view_get_settings(m_webView), TRUE); + g_signal_connect(m_webView, "create", G_CALLBACK(viewCreate), this); + g_signal_connect(m_webView, "script-alert", G_CALLBACK(scriptAlert), this); + g_signal_connect(m_webView, "script-confirm", G_CALLBACK(scriptConfirm), this); + g_signal_connect(m_webView, "script-prompt", G_CALLBACK(scriptPrompt), this); + } + + ~UIClientTest() + { + g_signal_handlers_disconnect_matched(m_webView, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, this); + } + + void waitUntilMainLoopFinishes() + { + g_main_loop_run(m_mainLoop); + } + + void setExpectedWindowProperties(const WindowProperties& windowProperties) + { + m_windowProperties = windowProperties; + } + + Vector<WebViewEvents> m_webViewEvents; + ScriptType m_scriptType; + bool m_scriptDialogConfirmed; + WindowProperties m_windowProperties; + HashSet<WTF::String> m_windowPropertiesChanged; +}; + +static void testWebViewCreateReadyClose(UIClientTest* test, gconstpointer) +{ + test->loadHtml("<html><body onLoad=\"window.open().close();\"></html>", 0); + test->waitUntilMainLoopFinishes(); + + Vector<UIClientTest::WebViewEvents>& events = test->m_webViewEvents; + g_assert_cmpint(events.size(), ==, 3); + g_assert_cmpint(events[0], ==, UIClientTest::Create); + g_assert_cmpint(events[1], ==, UIClientTest::ReadyToShow); + g_assert_cmpint(events[2], ==, UIClientTest::Close); +} + +static void testWebViewJavaScriptDialogs(UIClientTest* test, gconstpointer) +{ + static const char* htmlOnLoadFormat = "<html><body onLoad=\"%s\"></body></html>"; + static const char* jsAlertFormat = "alert('%s')"; + static const char* jsConfirmFormat = "do { confirmed = confirm('%s'); } while (!confirmed); alert('confirmed');"; + static const char* jsPromptFormat = "alert(prompt('%s', 'default'));"; + + test->m_scriptType = UIClientTest::Alert; + GOwnPtr<char> alertDialogMessage(g_strdup_printf(jsAlertFormat, kAlertDialogMessage)); + GOwnPtr<char> alertHTML(g_strdup_printf(htmlOnLoadFormat, alertDialogMessage.get())); + test->loadHtml(alertHTML.get(), 0); + test->waitUntilMainLoopFinishes(); + + test->m_scriptType = UIClientTest::Confirm; + GOwnPtr<char> confirmDialogMessage(g_strdup_printf(jsConfirmFormat, kConfirmDialogMessage)); + GOwnPtr<char> confirmHTML(g_strdup_printf(htmlOnLoadFormat, confirmDialogMessage.get())); + test->loadHtml(confirmHTML.get(), 0); + test->waitUntilMainLoopFinishes(); + + test->m_scriptType = UIClientTest::Prompt; + GOwnPtr<char> promptDialogMessage(g_strdup_printf(jsPromptFormat, kPromptDialogMessage)); + GOwnPtr<char> promptHTML(g_strdup_printf(htmlOnLoadFormat, promptDialogMessage.get())); + test->loadHtml(promptHTML.get(), 0); + test->waitUntilMainLoopFinishes(); +} + +static void testWebViewWindowProperties(UIClientTest* test, gconstpointer) +{ + static const char* windowProrpertiesString = "left=100,top=150,width=400,height=400,location=no,menubar=no,status=no,toolbar=no,scrollbars=no"; + GdkRectangle geometry = { 100, 150, 400, 400 }; + test->setExpectedWindowProperties(UIClientTest::WindowProperties(&geometry, false, false, false, false, false, true, false)); + + GOwnPtr<char> htmlString(g_strdup_printf("<html><body onLoad=\"window.open('', '', '%s').close();\"></body></html>", windowProrpertiesString)); + test->loadHtml(htmlString.get(), 0); + test->waitUntilMainLoopFinishes(); + + static const char* propertiesChanged[] = { + "geometry", "locationbar-visible", "menubar-visible", "statusbar-visible", "toolbar-visible", "scrollbars-visible" + }; + for (size_t i = 0; i < G_N_ELEMENTS(propertiesChanged); ++i) + g_assert(test->m_windowPropertiesChanged.contains(propertiesChanged[i])); + + Vector<UIClientTest::WebViewEvents>& events = test->m_webViewEvents; + g_assert_cmpint(events.size(), ==, 3); + g_assert_cmpint(events[0], ==, UIClientTest::Create); + g_assert_cmpint(events[1], ==, UIClientTest::ReadyToShow); + g_assert_cmpint(events[2], ==, UIClientTest::Close); +} + +static void testWebViewZoomLevel(WebViewTest* test, gconstpointer) +{ + g_assert_cmpfloat(webkit_web_view_get_zoom_level(test->m_webView), ==, 1); + webkit_web_view_set_zoom_level(test->m_webView, 2.5); + g_assert_cmpfloat(webkit_web_view_get_zoom_level(test->m_webView), ==, 2.5); +} + +void beforeAll() +{ + WebViewTest::add("WebKitWebView", "default-context", testWebViewDefaultContext); + WebViewTest::add("WebKitWebView", "custom-charset", testWebViewCustomCharset); + WebViewTest::add("WebKitWebView", "settings", testWebViewSettings); + WebViewTest::add("WebKitWebView", "replace-content", testWebViewReplaceContent); + UIClientTest::add("WebKitWebView", "create-ready-close", testWebViewCreateReadyClose); + UIClientTest::add("WebKitWebView", "javascript-dialogs", testWebViewJavaScriptDialogs); + UIClientTest::add("WebKitWebView", "window-properties", testWebViewWindowProperties); + WebViewTest::add("WebKitWebView", "zoom-level", testWebViewZoomLevel); +} + +void afterAll() +{ +} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.cpp new file mode 100644 index 000000000..55a93de87 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011 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 "WebKitTestServer.h" + +#include <wtf/gobject/GOwnPtr.h> + +WebKitTestServer::WebKitTestServer() + : m_soupServer(adoptGRef(soup_server_new(SOUP_SERVER_PORT, 0, NULL))) + , m_baseURI(soup_uri_new("http://127.0.0.1/")) +{ + soup_uri_set_port(m_baseURI, soup_server_get_port(m_soupServer.get())); +} + +WebKitTestServer::~WebKitTestServer() +{ + soup_uri_free(m_baseURI); +} + +void WebKitTestServer::run(SoupServerCallback serverCallback) +{ + soup_server_run_async(m_soupServer.get()); + soup_server_add_handler(m_soupServer.get(), 0, serverCallback, 0, 0); +} + +CString WebKitTestServer::getURIForPath(const char* path) +{ + SoupURI* uri = soup_uri_new_with_base(m_baseURI, path); + GOwnPtr<gchar> uriString(soup_uri_to_string(uri, FALSE)); + soup_uri_free(uri); + return uriString.get(); +} + diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.h b/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.h new file mode 100644 index 000000000..9f00349e0 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebKitTestServer.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2011 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 WebKitTestServer_h +#define WebKitTestServer_h + +#include <libsoup/soup.h> +#include <webkit2/webkit2.h> +#include <wtf/gobject/GRefPtr.h> +#include <wtf/text/CString.h> + +class WebKitTestServer { +public: + WebKitTestServer(); + virtual ~WebKitTestServer(); + + SoupURI* baseURI() { return m_baseURI; } + + CString getURIForPath(const char* path); + void run(SoupServerCallback); + +private: + GRefPtr<SoupServer> m_soupServer; + SoupURI* m_baseURI; +}; + +#endif // WebKitTestServer_h diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp new file mode 100644 index 000000000..dfd9da475 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2011 Igalia S.L. + * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. + * + * 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 "WebViewTest.h" + +WebViewTest::WebViewTest() + : m_webView(WEBKIT_WEB_VIEW(g_object_ref_sink(webkit_web_view_new()))) + , m_mainLoop(g_main_loop_new(0, TRUE)) +{ + assertObjectIsDeletedWhenTestFinishes(G_OBJECT(m_webView)); +} + +WebViewTest::~WebViewTest() +{ + g_object_unref(m_webView); + g_main_loop_unref(m_mainLoop); +} + +static gboolean testLoadTimeoutFinishLoop(GMainLoop* loop) +{ + g_main_loop_quit(loop); + return FALSE; +} + +void WebViewTest::loadURI(const char* uri) +{ + m_activeURI = uri; + webkit_web_view_load_uri(m_webView, uri); +} + +void WebViewTest::loadHtml(const char* html, const char* baseURI) +{ + m_activeURI = "about:blank"; + webkit_web_view_load_html(m_webView, html, baseURI); +} + +void WebViewTest::loadPlainText(const char* plainText) +{ + m_activeURI = "about:blank"; + webkit_web_view_load_plain_text(m_webView, plainText); +} + +void WebViewTest::loadRequest(WebKitURIRequest* request) +{ + m_activeURI = webkit_uri_request_get_uri(request); + webkit_web_view_load_request(m_webView, request); +} + +void WebViewTest::replaceContent(const char* html, const char* contentURI, const char* baseURI) +{ + // FIXME: The active uri should be the contentURI, + // but WebPageProxy doesn't return the unreachableURL + // when the page has been loaded with AlternateHTML() + // See https://bugs.webkit.org/show_bug.cgi?id=75465. +#if 0 + m_activeURI = contentURI; +#else + m_activeURI = "about:blank"; +#endif + webkit_web_view_replace_content(m_webView, html, contentURI, baseURI); +} + +void WebViewTest::goBack() +{ + if (webkit_web_view_can_go_back(m_webView)) { + WebKitBackForwardList* list = webkit_web_view_get_back_forward_list(m_webView); + WebKitBackForwardListItem* item = webkit_back_forward_list_get_nth_item(list, -1); + m_activeURI = webkit_back_forward_list_item_get_original_uri(item); + } + + // Call go_back even when can_go_back returns FALSE to check nothing happens. + webkit_web_view_go_back(m_webView); +} + +void WebViewTest::goForward() +{ + if (webkit_web_view_can_go_forward(m_webView)) { + WebKitBackForwardList* list = webkit_web_view_get_back_forward_list(m_webView); + WebKitBackForwardListItem* item = webkit_back_forward_list_get_nth_item(list, 1); + m_activeURI = webkit_back_forward_list_item_get_original_uri(item); + } + + // Call go_forward even when can_go_forward returns FALSE to check nothing happens. + webkit_web_view_go_forward(m_webView); +} + +void WebViewTest::goToBackForwardListItem(WebKitBackForwardListItem* item) +{ + m_activeURI = webkit_back_forward_list_item_get_original_uri(item); + webkit_web_view_go_to_back_forward_list_item(m_webView, item); +} + +void WebViewTest::wait(double seconds) +{ + g_timeout_add_seconds(seconds, reinterpret_cast<GSourceFunc>(testLoadTimeoutFinishLoop), m_mainLoop); + g_main_loop_run(m_mainLoop); +} diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h new file mode 100644 index 000000000..662354032 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2011 Igalia S.L. + * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. + * + * 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 WebViewTest_h +#define WebViewTest_h + +#include "TestMain.h" +#include <webkit2/webkit2.h> +#include <wtf/text/CString.h> + +class WebViewTest: public Test { +public: + MAKE_GLIB_TEST_FIXTURE(WebViewTest); + WebViewTest(); + virtual ~WebViewTest(); + + void loadURI(const char* uri); + void loadHtml(const char* html, const char* baseURI); + void loadPlainText(const char* plainText); + void loadRequest(WebKitURIRequest*); + void replaceContent(const char* html, const char* contentURI, const char* baseURI); + void goBack(); + void goForward(); + void goToBackForwardListItem(WebKitBackForwardListItem*); + + void wait(double seconds); + + WebKitWebView* m_webView; + GMainLoop* m_mainLoop; + CString m_activeURI; +}; + +#endif // WebViewTest_h |