From 40736c5763bf61337c8c14e16d8587db021a87d4 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 6 Jan 2012 14:44:00 +0100 Subject: Imported WebKit commit 2ea9d364d0f6efa8fa64acf19f451504c59be0e4 (http://svn.webkit.org/repository/webkit/trunk@104285) --- .../UIProcess/API/gtk/tests/WebViewTest.cpp | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp (limited to 'Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp') 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(testLoadTimeoutFinishLoop), m_mainLoop); + g_main_loop_run(m_mainLoop); +} -- cgit v1.2.1