diff options
Diffstat (limited to 'Tools/DumpRenderTree/gtk')
-rw-r--r-- | Tools/DumpRenderTree/gtk/AccessibilityControllerGtk.cpp | 79 | ||||
-rw-r--r-- | Tools/DumpRenderTree/gtk/DumpRenderTree.cpp | 1557 | ||||
-rw-r--r-- | Tools/DumpRenderTree/gtk/DumpRenderTreeGtk.h | 50 | ||||
-rw-r--r-- | Tools/DumpRenderTree/gtk/EditingCallbacks.cpp | 202 | ||||
-rw-r--r-- | Tools/DumpRenderTree/gtk/EditingCallbacks.h | 35 | ||||
-rw-r--r-- | Tools/DumpRenderTree/gtk/EventSender.cpp | 1004 | ||||
-rw-r--r-- | Tools/DumpRenderTree/gtk/EventSender.h | 42 | ||||
-rw-r--r-- | Tools/DumpRenderTree/gtk/GCControllerGtk.cpp | 50 | ||||
-rw-r--r-- | Tools/DumpRenderTree/gtk/PixelDumpSupportGtk.cpp | 115 | ||||
-rw-r--r-- | Tools/DumpRenderTree/gtk/SelfScrollingWebKitWebView.cpp | 78 | ||||
-rw-r--r-- | Tools/DumpRenderTree/gtk/SelfScrollingWebKitWebView.h | 51 | ||||
-rw-r--r-- | Tools/DumpRenderTree/gtk/TestRunnerGtk.cpp | 914 | ||||
-rw-r--r-- | Tools/DumpRenderTree/gtk/TextInputController.cpp | 215 | ||||
-rw-r--r-- | Tools/DumpRenderTree/gtk/TextInputController.h | 37 | ||||
-rw-r--r-- | Tools/DumpRenderTree/gtk/WorkQueueItemGtk.cpp | 102 |
15 files changed, 0 insertions, 4531 deletions
diff --git a/Tools/DumpRenderTree/gtk/AccessibilityControllerGtk.cpp b/Tools/DumpRenderTree/gtk/AccessibilityControllerGtk.cpp deleted file mode 100644 index 7ee1d9460..000000000 --- a/Tools/DumpRenderTree/gtk/AccessibilityControllerGtk.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2008, 2009, 2010 Apple Inc. All Rights Reserved. - * Copyright (C) 2009 Jan Michael Alonzo - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 APPLE INC. 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" - -#if HAVE(ACCESSIBILITY) - -#include "AccessibilityController.h" - -#include "AccessibilityCallbacks.h" -#include "AccessibilityUIElement.h" -#include "DumpRenderTree.h" -#include "WebCoreSupport/DumpRenderTreeSupportGtk.h" - -#include <atk/atk.h> -#include <gtk/gtk.h> -#include <webkit/webkit.h> -#include <wtf/gobject/GUniquePtr.h> - -AccessibilityUIElement AccessibilityController::focusedElement() -{ - AtkObject* accessible = DumpRenderTreeSupportGtk::getFocusedAccessibleElement(mainFrame); - if (!accessible) - return 0; - - return AccessibilityUIElement(accessible); -} - -AccessibilityUIElement AccessibilityController::rootElement() -{ - AtkObject* accessible = DumpRenderTreeSupportGtk::getRootAccessibleElement(mainFrame); - if (!accessible) - return 0; - - return AccessibilityUIElement(accessible); -} - -AccessibilityUIElement AccessibilityController::accessibleElementById(JSStringRef id) -{ - AtkObject* root = DumpRenderTreeSupportGtk::getRootAccessibleElement(mainFrame); - if (!root) - return 0; - - size_t bufferSize = JSStringGetMaximumUTF8CStringSize(id); - GUniquePtr<gchar> idBuffer(static_cast<gchar*>(g_malloc(bufferSize))); - JSStringGetUTF8CString(id, idBuffer.get(), bufferSize); - - AtkObject* result = childElementById(root, idBuffer.get()); - if (ATK_IS_OBJECT(result)) - return AccessibilityUIElement(result); - - return 0; - -} - -#endif // HAVE(ACCESSIBILITY) diff --git a/Tools/DumpRenderTree/gtk/DumpRenderTree.cpp b/Tools/DumpRenderTree/gtk/DumpRenderTree.cpp deleted file mode 100644 index 73d710a04..000000000 --- a/Tools/DumpRenderTree/gtk/DumpRenderTree.cpp +++ /dev/null @@ -1,1557 +0,0 @@ -/* - * Copyright (C) 2007 Eric Seidel <eric@webkit.org> - * Copyright (C) 2008 Alp Toker <alp@nuanti.com> - * Copyright (C) 2009 Jan Alonzo <jmalonzo@gmail.com> - * Copyright (C) 2010, 2011 Igalia S.L. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "DumpRenderTree.h" - -#include "AccessibilityController.h" -#include "EditingCallbacks.h" -#include "EventSender.h" -#include "GCController.h" -#include "PixelDumpSupport.h" -#include "SelfScrollingWebKitWebView.h" -#include "TestRunner.h" -#include "TextInputController.h" -#include "WebCoreSupport/DumpRenderTreeSupportGtk.h" -#include "WebCoreTestSupport.h" -#include "WorkQueue.h" -#include "WorkQueueItem.h" -#include <JavaScriptCore/JavaScript.h> -#include <WebCore/platform/network/soup/GUniquePtrSoup.h> -#include <cassert> -#include <cstdlib> -#include <cstring> -#include <getopt.h> -#include <gtk/gtk.h> -#include <locale.h> -#include <webkit/webkit.h> -#include <wtf/Assertions.h> -#include <wtf/gobject/GlibUtilities.h> -#include <wtf/text/WTFString.h> - -#if PLATFORM(X11) -#include <fontconfig/fontconfig.h> -#endif - - -using namespace std; - -extern "C" { -// This API is not yet public. -extern gchar* webkit_web_history_item_get_target(WebKitWebHistoryItem*); -extern gboolean webkit_web_history_item_is_target_item(WebKitWebHistoryItem*); -extern GList* webkit_web_history_item_get_children(WebKitWebHistoryItem*); -extern void webkit_web_settings_add_extra_plugin_directory(WebKitWebView* view, const gchar* directory); -extern gchar* webkit_web_frame_get_response_mime_type(WebKitWebFrame* frame); -} - -volatile bool done; -static bool printSeparators; -static int dumpPixelsForAllTests = false; -static bool dumpPixelsForCurrentTest; -static int dumpTree = 1; -static int useTimeoutWatchdog = 1; - -#if HAVE(ACCESSIBILITY) -AccessibilityController* axController = 0; -#endif -RefPtr<TestRunner> gTestRunner; -static GCController* gcController = 0; -static WebKitWebView* webView; -static GtkWidget* window; -static GtkWidget* container; -static GtkWidget* webInspectorWindow; -WebKitWebFrame* mainFrame = 0; -WebKitWebFrame* topLoadingFrame = 0; -guint waitToDumpWatchdog = 0; -bool waitForPolicy = false; - -// This is a list of opened webviews -GSList* webViewList = 0; - -// current b/f item at the end of the previous test -static WebKitWebHistoryItem* prevTestBFItem = NULL; - -const unsigned historyItemIndent = 8; - -static void runTest(const string& inputLine); - -static void didRunInsecureContent(WebKitWebFrame*, WebKitSecurityOrigin*, const char* url); - -static bool shouldLogFrameLoadDelegates(const string& pathOrURL) -{ - return pathOrURL.find("loading/") != string::npos; -} - -static bool shouldOpenWebInspector(const string& pathOrURL) -{ - return pathOrURL.find("inspector/") != string::npos; -} - -static bool shouldDumpAsText(const string& pathOrURL) -{ - return pathOrURL.find("dumpAsText/") != string::npos; -} - -static bool shouldEnableDeveloperExtras(const string& pathOrURL) -{ - return true; -} - -void dumpFrameScrollPosition(WebKitWebFrame* frame) -{ - WebKitDOMDocument* document = webkit_web_frame_get_dom_document(frame); - if (!document) - return; - - WebKitDOMDOMWindow* domWindow = webkit_dom_document_get_default_view(document); - if (!domWindow) - return; - - glong x = webkit_dom_dom_window_get_page_x_offset(domWindow); - glong y = webkit_dom_dom_window_get_page_y_offset(domWindow); - - if (abs(x) > 0 || abs(y) > 0) { - if (webkit_web_frame_get_parent(frame)) - printf("frame '%s' ", webkit_web_frame_get_name(frame)); - printf("scrolled to %ld,%ld\n", x, y); - } - - if (gTestRunner->dumpChildFrameScrollPositions()) { - GSList* children = DumpRenderTreeSupportGtk::getFrameChildren(frame); - for (GSList* child = children; child; child = g_slist_next(child)) - dumpFrameScrollPosition(static_cast<WebKitWebFrame*>(child->data)); - g_slist_free(children); - } -} - -void displayWebView() -{ - DumpRenderTreeSupportGtk::forceWebViewPaint(webView); - DumpRenderTreeSupportGtk::setTracksRepaints(mainFrame, true); - DumpRenderTreeSupportGtk::resetTrackedRepaints(mainFrame); -} - -static void appendString(gchar*& target, const gchar* string) -{ - gchar* oldString = target; - target = g_strconcat(target, string, NULL); - g_free(oldString); -} - -static void initializeGtkFontSettings(const char* testURL) -{ - GtkSettings* settings = gtk_settings_get_default(); - if (!settings) - return; - g_object_set(settings, - "gtk-xft-dpi", 98304, // This is 96 * 1024 or 96 DPI according to the GTK+ docs. - "gtk-xft-antialias", 1, - "gtk-xft-hinting", 0, - "gtk-font-name", "Liberation Sans 12", - "gtk-icon-theme-name", "gnome", - NULL); - gdk_screen_set_resolution(gdk_screen_get_default(), 96.0); - - // One test needs subpixel anti-aliasing turned on, but generally we - // want all text in other tests to use to grayscale anti-aliasing. - if (testURL && strstr(testURL, "xsettings_antialias_settings.html")) - g_object_set(settings, "gtk-xft-rgba", "rgb", NULL); - else - g_object_set(settings, "gtk-xft-rgba", "none", NULL); -} - -CString getTopLevelPath() -{ - if (const gchar* topLevel = g_getenv("WEBKIT_TOP_LEVEL")) - return topLevel; - - g_setenv("WEBKIT_TOP_LEVEL", TOP_LEVEL_DIR, FALSE); - return TOP_LEVEL_DIR; -} - -CString getOutputDir() -{ - const char* webkitOutputDir = g_getenv("WEBKIT_OUTPUTDIR"); - if (webkitOutputDir) - return webkitOutputDir; - - CString topLevelPath = getTopLevelPath(); - GUniquePtr<char> outputDir(g_build_filename(topLevelPath.data(), "WebKitBuild", NULL)); - return outputDir.get(); -} - -static CString getFontsPath() -{ - CString webkitOutputDir = getOutputDir(); - GUniquePtr<char> fontsPath(g_build_filename(webkitOutputDir.data(), "Dependencies", "Root", "webkitgtk-test-fonts", NULL)); - if (g_file_test(fontsPath.get(), static_cast<GFileTest>(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) - return fontsPath.get(); - - // Try alternative fonts path. - fontsPath.reset(g_build_filename(webkitOutputDir.data(), "webkitgtk-test-fonts", NULL)); - if (g_file_test(fontsPath.get(), static_cast<GFileTest>(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) - return fontsPath.get(); - - return CString(); -} - -static void initializeFonts(const char* testURL = 0) -{ -#if PLATFORM(X11) - initializeGtkFontSettings(testURL); - - FcInit(); - - // If a test resulted a font being added or removed via the @font-face rule, then - // we want to reset the FontConfig configuration to prevent it from affecting other tests. - static int numFonts = 0; - FcFontSet* appFontSet = FcConfigGetFonts(0, FcSetApplication); - if (appFontSet && numFonts && appFontSet->nfont == numFonts) - return; - - // Load our configuration file, which sets up proper aliases for family - // names like sans, serif and monospace. - FcConfig* config = FcConfigCreate(); - GUniquePtr<gchar> fontConfigFilename(g_build_filename(FONTS_CONF_DIR, "fonts.conf", nullptr)); - if (!FcConfigParseAndLoad(config, reinterpret_cast<FcChar8*>(fontConfigFilename.get()), true)) - g_error("Couldn't load font configuration file from: %s", fontConfigFilename.get()); - - CString fontsPath = getFontsPath(); - if (fontsPath.isNull()) - g_error("Could not locate test fonts at $WEBKIT_TOP_LEVEL/WebKitBuild/Dependencies/Root/webkitgtk-test-fonts. " - "WEBKIT_TOP_LEVEL is your WebKit checkout by default, and can be overridden by setting it as an environment variable."); - - GUniquePtr<GDir> fontsDirectory(g_dir_open(fontsPath.data(), 0, nullptr)); - while (const char* directoryEntry = g_dir_read_name(fontsDirectory.get())) { - if (!g_str_has_suffix(directoryEntry, ".ttf") && !g_str_has_suffix(directoryEntry, ".otf")) - continue; - GUniquePtr<gchar> fontPath(g_build_filename(fontsPath.data(), directoryEntry, nullptr)); - if (!FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(fontPath.get()))) - g_error("Could not load font at %s!", fontPath.get()); - - } - - // Ahem is used by many layout tests. - GUniquePtr<gchar> ahemFontFilename(g_build_filename(FONTS_CONF_DIR, "AHEM____.TTF", nullptr)); - if (!FcConfigAppFontAddFile(config, reinterpret_cast<FcChar8*>(ahemFontFilename.get()))) - g_error("Could not load font at %s!", ahemFontFilename.get()); - - for (int i = 1; i <= 9; i++) { - GUniquePtr<gchar> fontFilename(g_strdup_printf("WebKitWeightWatcher%i00.ttf", i)); - GUniquePtr<gchar> fontPath(g_build_filename(FONTS_CONF_DIR, "..", "..", "fonts", fontFilename.get(), nullptr)); - if (!FcConfigAppFontAddFile(config, reinterpret_cast<FcChar8*>(fontPath.get()))) - g_error("Could not load font at %s!", fontPath.get()); - } - - // A font with no valid Fontconfig encoding to test https://bugs.webkit.org/show_bug.cgi?id=47452 - GUniquePtr<gchar> fontWithNoValidEncodingFilename(g_build_filename(FONTS_CONF_DIR, "FontWithNoValidEncoding.fon", nullptr)); - if (!FcConfigAppFontAddFile(config, reinterpret_cast<FcChar8*>(fontWithNoValidEncodingFilename.get()))) - g_error("Could not load font at %s!", fontWithNoValidEncodingFilename.get()); - - if (!FcConfigSetCurrent(config)) - g_error("Could not set the current font configuration!"); - - numFonts = FcConfigGetFonts(config, FcSetApplication)->nfont; -#endif -} - -static gchar* dumpFramesAsText(WebKitWebFrame* frame) -{ - gchar* result = 0; - - // Add header for all but the main frame. - bool isMainFrame = (webkit_web_view_get_main_frame(webView) == frame); - - CString innerText = DumpRenderTreeSupportGtk::getInnerText(frame); - if (isMainFrame) - result = g_strdup_printf("%s\n", innerText.data()); - else { - const gchar* frameName = webkit_web_frame_get_name(frame); - result = g_strdup_printf("\n--------\nFrame: '%s'\n--------\n%s\n", frameName, innerText.data()); - } - - if (gTestRunner->dumpChildFramesAsText()) { - GSList* children = DumpRenderTreeSupportGtk::getFrameChildren(frame); - for (GSList* child = children; child; child = g_slist_next(child)) { - GUniquePtr<gchar> childData(dumpFramesAsText(static_cast<WebKitWebFrame*>(child->data))); - appendString(result, childData.get()); - } - g_slist_free(children); - } - - return result; -} - -static gint compareHistoryItems(gpointer* item1, gpointer* item2) -{ - GUniquePtr<gchar> firstItemTarget(webkit_web_history_item_get_target(WEBKIT_WEB_HISTORY_ITEM(item1))); - GUniquePtr<gchar> secondItemTarget(webkit_web_history_item_get_target(WEBKIT_WEB_HISTORY_ITEM(item2))); - return g_ascii_strcasecmp(firstItemTarget.get(), secondItemTarget.get()); -} - -static void dumpHistoryItem(WebKitWebHistoryItem* item, int indent, bool current) -{ - ASSERT(item != NULL); - int start = 0; - g_object_ref(item); - if (current) { - printf("curr->"); - start = 6; - } - for (int i = start; i < indent; i++) - putchar(' '); - - // normalize file URLs. - const gchar* uri = webkit_web_history_item_get_uri(item); - gchar* uriScheme = g_uri_parse_scheme(uri); - if (g_strcmp0(uriScheme, "file") == 0) { - gchar* pos = g_strstr_len(uri, -1, "/LayoutTests/"); - if (!pos) { - g_free(uriScheme); - return; - } - - GString* result = g_string_sized_new(strlen(uri)); - result = g_string_append(result, "(file test):"); - result = g_string_append(result, pos + strlen("/LayoutTests/")); - printf("%s", result->str); - g_string_free(result, TRUE); - } else - printf("%s", uri); - - g_free(uriScheme); - - GUniquePtr<gchar> target(webkit_web_history_item_get_target(item)); - if (target.get() && strlen(target.get()) > 0) - printf(" (in frame \"%s\")", target.get()); - if (webkit_web_history_item_is_target_item(item)) - printf(" **nav target**"); - putchar('\n'); - - if (GList* kids = webkit_web_history_item_get_children(item)) { - // must sort to eliminate arbitrary result ordering which defeats reproducible testing - for (GList* kid = g_list_sort(kids, (GCompareFunc) compareHistoryItems); kid; kid = g_list_next(kid)) { - WebKitWebHistoryItem* item = WEBKIT_WEB_HISTORY_ITEM(kid->data); - dumpHistoryItem(item, indent + 4, FALSE); - g_object_unref(item); - } - g_list_free(kids); - } - g_object_unref(item); -} - -static void dumpBackForwardListForWebView(WebKitWebView* view) -{ - printf("\n============== Back Forward List ==============\n"); - WebKitWebBackForwardList* bfList = webkit_web_view_get_back_forward_list(view); - - // Print out all items in the list after prevTestBFItem, which was from the previous test - // Gather items from the end of the list, the print them out from oldest to newest - GList* itemsToPrint = NULL; - gint forwardListCount = webkit_web_back_forward_list_get_forward_length(bfList); - for (int i = forwardListCount; i > 0; i--) { - WebKitWebHistoryItem* item = webkit_web_back_forward_list_get_nth_item(bfList, i); - // something is wrong if the item from the last test is in the forward part of the b/f list - ASSERT(item != prevTestBFItem); - g_object_ref(item); - itemsToPrint = g_list_prepend(itemsToPrint, item); - } - - WebKitWebHistoryItem* currentItem = webkit_web_back_forward_list_get_current_item(bfList); - g_object_ref(currentItem); - itemsToPrint = g_list_prepend(itemsToPrint, currentItem); - - gint backListCount = webkit_web_back_forward_list_get_back_length(bfList); - for (int i = -1; i >= -(backListCount); i--) { - WebKitWebHistoryItem* item = webkit_web_back_forward_list_get_nth_item(bfList, i); - if (item == prevTestBFItem) - break; - g_object_ref(item); - itemsToPrint = g_list_prepend(itemsToPrint, item); - } - - for (GList* itemToPrint = itemsToPrint; itemToPrint; itemToPrint = g_list_next(itemToPrint)) { - WebKitWebHistoryItem* item = WEBKIT_WEB_HISTORY_ITEM(itemToPrint->data); - dumpHistoryItem(item, historyItemIndent, item == currentItem); - g_object_unref(item); - } - - g_list_free(itemsToPrint); - printf("===============================================\n"); -} - -static void dumpBackForwardListForAllWebViews() -{ - // Dump the back forward list of the main WebView first - dumpBackForwardListForWebView(webView); - - // The view list is prepended. Reverse the list so we get the order right. - for (GSList* currentView = g_slist_reverse(webViewList); currentView; currentView = g_slist_next(currentView)) - dumpBackForwardListForWebView(WEBKIT_WEB_VIEW(currentView->data)); -} - -void setWaitToDumpWatchdog(guint timer) -{ - waitToDumpWatchdog = timer; -} - -bool shouldSetWaitToDumpWatchdog() -{ - return !waitToDumpWatchdog && useTimeoutWatchdog; -} - -CString soupURIToStringPreservingPassword(SoupURI* soupURI) -{ - if (!soupURI->password) { - GUniquePtr<char> uriString(soup_uri_to_string(soupURI, FALSE)); - return uriString.get(); - } - - // soup_uri_to_string does not insert the password into the string, so we need to create the - // URI string and then reinsert any credentials that were present in the SoupURI. All tests that - // use URL-embedded credentials use HTTP, so it's safe here. - GUniquePtr<char> password(soupURI->password); - GUniquePtr<char> user(soupURI->user); - soupURI->password = 0; - soupURI->user = 0; - - GUniquePtr<char> uriString(soup_uri_to_string(soupURI, FALSE)); - String absoluteURIWithoutCredentialString = String::fromUTF8(uriString.get()); - String protocolAndCredential = String::format("http://%s:%s@", user ? user.get() : "", password.get()); - return absoluteURIWithoutCredentialString.replace("http://", protocolAndCredential).utf8(); -} - -static void invalidateAnyPreviousWaitToDumpWatchdog() -{ - if (waitToDumpWatchdog) { - g_source_remove(waitToDumpWatchdog); - waitToDumpWatchdog = 0; - } - - waitForPolicy = false; -} - -static void resetDefaultsToConsistentValues() -{ - WebKitWebSettings* settings = webkit_web_view_get_settings(webView); - GUniquePtr<gchar> localStoragePath(g_build_filename(g_get_user_data_dir(), "DumpRenderTreeGtk", "databases", nullptr)); - g_object_set(G_OBJECT(settings), - "enable-accelerated-compositing", FALSE, - "enable-private-browsing", FALSE, - "enable-developer-extras", FALSE, - "enable-spell-checking", TRUE, - "enable-html5-database", TRUE, - "enable-html5-local-storage", TRUE, - "html5-local-storage-database-path", localStoragePath.get(), - "enable-xss-auditor", FALSE, - "enable-spatial-navigation", FALSE, - "javascript-can-access-clipboard", TRUE, - "javascript-can-open-windows-automatically", TRUE, - "enable-offline-web-application-cache", TRUE, - "enable-universal-access-from-file-uris", TRUE, - "enable-file-access-from-file-uris", TRUE, - "enable-scripts", TRUE, - "enable-dom-paste", TRUE, - "default-font-family", "Times", - "monospace-font-family", "Courier", - "serif-font-family", "Times", - "sans-serif-font-family", "Helvetica", - "cursive-font-family", "cursive", - "fantasy-font-family", "fantasy", - "default-font-size", 12, - "default-monospace-font-size", 10, - "minimum-font-size", 0, - "enable-caret-browsing", FALSE, - "enable-page-cache", FALSE, - "auto-resize-window", TRUE, - "auto-load-images", TRUE, - "enable-java-applet", FALSE, - "enable-plugins", TRUE, - "enable-hyperlink-auditing", FALSE, - "editing-behavior", WEBKIT_EDITING_BEHAVIOR_UNIX, - "enable-fullscreen", TRUE, - "enable-mediasource", TRUE, - NULL); - webkit_web_view_set_settings(webView, settings); - webkit_set_cache_model(WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER); - - DumpRenderTreeSupportGtk::clearMainFrameName(mainFrame); - DumpRenderTreeSupportGtk::scalePageBy(webView, 1, 0, 0); - - WebKitWebInspector* inspector = webkit_web_view_get_inspector(webView); - g_object_set(G_OBJECT(inspector), "javascript-profiling-enabled", FALSE, NULL); - - webkit_web_view_set_zoom_level(webView, 1.0); - - DumpRenderTreeSupportGtk::resetOriginAccessWhiteLists(); - - WebKitWebBackForwardList* list = webkit_web_view_get_back_forward_list(webView); - webkit_web_back_forward_list_clear(list); - - SoupSession* session = webkit_get_default_session(); - SoupCookieJar* jar = reinterpret_cast<SoupCookieJar*>(soup_session_get_feature(session, SOUP_TYPE_COOKIE_JAR)); - - // We only create the jar when the soup backend needs to do - // HTTP. Should we initialize it earlier, perhaps? - if (jar) - g_object_set(G_OBJECT(jar), SOUP_COOKIE_JAR_ACCEPT_POLICY, SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY, NULL); - - setlocale(LC_ALL, ""); - - DumpRenderTreeSupportGtk::setLinksIncludedInFocusChain(true); - webkit_icon_database_set_path(webkit_get_icon_database(), 0); - DumpRenderTreeSupportGtk::setDefersLoading(webView, false); - DumpRenderTreeSupportGtk::setSerializeHTTPLoads(false); - -#if HAVE(ACCESSIBILITY) - if (axController) - axController->resetToConsistentState(); -#endif - - DumpRenderTreeSupportGtk::clearOpener(mainFrame); - DumpRenderTreeSupportGtk::setTracksRepaints(mainFrame, false); - - DumpRenderTreeSupportGtk::resetGeolocationClientMock(webView); - - DumpRenderTreeSupportGtk::setCSSGridLayoutEnabled(webView, false); - DumpRenderTreeSupportGtk::setCSSRegionsEnabled(webView, true); - DumpRenderTreeSupportGtk::setExperimentalContentSecurityPolicyFeaturesEnabled(true); - DumpRenderTreeSupportGtk::setSeamlessIFramesEnabled(true); - DumpRenderTreeSupportGtk::setShadowDOMEnabled(true); - - if (gTestRunner) { - gTestRunner->setAuthenticationPassword(""); - gTestRunner->setAuthenticationUsername(""); - gTestRunner->setHandlesAuthenticationChallenges(false); - } - - gtk_widget_set_direction(GTK_WIDGET(webView), GTK_TEXT_DIR_NONE); -} - -static bool useLongRunningServerMode(int argc, char *argv[]) -{ - // This assumes you've already called getopt_long - return (argc == optind+1 && !strcmp(argv[optind], "-")); -} - -static void runTestingServerLoop() -{ - // When DumpRenderTree runs in server mode, we just wait around for file names - // to be passed to us and read each in turn, passing the results back to the client - char filenameBuffer[2048]; - while (fgets(filenameBuffer, sizeof(filenameBuffer), stdin)) { - char* newLineCharacter = strchr(filenameBuffer, '\n'); - if (newLineCharacter) - *newLineCharacter = '\0'; - - if (!strlen(filenameBuffer)) - continue; - - runTest(filenameBuffer); - } -} - -static void initializeGlobalsFromCommandLineOptions(int argc, char *argv[]) -{ - struct option options[] = { - {"notree", no_argument, &dumpTree, false}, - {"pixel-tests", no_argument, &dumpPixelsForAllTests, true}, - {"tree", no_argument, &dumpTree, true}, - {"no-timeout", no_argument, &useTimeoutWatchdog, false}, - {NULL, 0, NULL, 0} - }; - - int option; - while ((option = getopt_long(argc, (char * const *)argv, "", options, NULL)) != -1) { - switch (option) { - case '?': // unknown or ambiguous option - case ':': // missing argument - exit(1); - break; - } - } -} - - -void dump() -{ - invalidateAnyPreviousWaitToDumpWatchdog(); - - // Grab widget focus before dumping the contents of a widget, in - // case it was lost in the course of the test. - gtk_widget_grab_focus(GTK_WIDGET(webView)); - - if (dumpTree) { - char* result = 0; - gchar* responseMimeType = webkit_web_frame_get_response_mime_type(mainFrame); - - if (g_str_equal(responseMimeType, "text/plain")) { - gTestRunner->setDumpAsText(true); - gTestRunner->setGeneratePixelResults(false); - } - g_free(responseMimeType); - - if (gTestRunner->dumpAsText()) - result = dumpFramesAsText(mainFrame); - else { - // Widget resizing is done asynchronously in GTK+. We pump the main - // loop here, to flush any pending resize requests. This prevents - // timing issues which affect the size of elements in the output. - // We only enable this workaround for tests that print the render tree - // because this seems to break some dumpAsText tests: see bug 39988 - // After fixing that test, we should apply this approach to all dumps. - while (gtk_events_pending()) - gtk_main_iteration(); - - result = g_strdup(DumpRenderTreeSupportGtk::dumpRenderTree(mainFrame).data()); - } - - if (!result) { - const char* errorMessage; - if (gTestRunner->dumpAsText()) - errorMessage = "[documentElement innerText]"; - else if (gTestRunner->dumpDOMAsWebArchive()) - errorMessage = "[[mainFrame DOMDocument] webArchive]"; - else if (gTestRunner->dumpSourceAsWebArchive()) - errorMessage = "[[mainFrame dataSource] webArchive]"; - else - errorMessage = "[mainFrame renderTreeAsExternalRepresentation]"; - printf("ERROR: nil result from %s", errorMessage); - } else { - printf("%s", result); - g_free(result); - if (!gTestRunner->dumpAsText() && !gTestRunner->dumpDOMAsWebArchive() && !gTestRunner->dumpSourceAsWebArchive()) - dumpFrameScrollPosition(mainFrame); - - if (gTestRunner->dumpBackForwardList()) - dumpBackForwardListForAllWebViews(); - } - - if (printSeparators) { - puts("#EOF"); // terminate the content block - fputs("#EOF\n", stderr); - fflush(stdout); - fflush(stderr); - } - } - - if (dumpPixelsForCurrentTest - && gTestRunner->generatePixelResults() - && !gTestRunner->dumpDOMAsWebArchive() - && !gTestRunner->dumpSourceAsWebArchive()) { - DumpRenderTreeSupportGtk::forceWebViewPaint(webView); - dumpWebViewAsPixelsAndCompareWithExpected(gTestRunner->expectedPixelHash()); - } - - // FIXME: call displayWebView here when we support --paint - - done = true; - gtk_main_quit(); -} - -static CString temporaryDatabaseDirectory() -{ - const char* directoryFromEnvironment = g_getenv("DUMPRENDERTREE_TEMP"); - if (directoryFromEnvironment) - return directoryFromEnvironment; - GUniquePtr<char> fallback(g_build_filename(g_get_user_data_dir(), "gtkwebkitdrt", "databases", NULL)); - return fallback.get(); -} - -static void setDefaultsToConsistentStateValuesForTesting() -{ - resetDefaultsToConsistentValues(); - -#if PLATFORM(X11) - webkit_web_settings_add_extra_plugin_directory(webView, TEST_PLUGIN_DIR); -#endif - - webkit_set_web_database_directory_path(temporaryDatabaseDirectory().data()); - -#if defined(GTK_API_VERSION_2) - gtk_rc_parse_string("style \"nix_scrollbar_spacing\" " - "{ " - " GtkScrolledWindow::scrollbar-spacing = 0 " - "} " - "class \"GtkWidget\" style \"nix_scrollbar_spacing\""); - -#else - GtkCssProvider* cssProvider = gtk_css_provider_new(); - gtk_css_provider_load_from_data(cssProvider, - "@binding-set NoKeyboardNavigation { " - " unbind \"<shift>F10\"; " - "} " - " * { " - " -GtkScrolledWindow-scrollbar-spacing: 0;" - " gtk-key-bindings: NoKeyboardNavigation; " - "} ", - -1, 0); - gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()), - GTK_STYLE_PROVIDER(cssProvider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - g_object_unref(cssProvider); -#endif -} - -static void sendPixelResultsEOF() -{ - puts("#EOF"); - - fflush(stdout); - fflush(stderr); -} - -static void runTest(const string& inputLine) -{ - ASSERT(!inputLine.empty()); - - TestCommand command = parseInputLine(inputLine); - string& testURL = command.pathOrURL; - dumpPixelsForCurrentTest = command.shouldDumpPixels || dumpPixelsForAllTests; - - // Convert the path into a full file URL if it does not look - // like an HTTP/S URL (doesn't start with http:// or https://). - if (testURL.find("http://") && testURL.find("https://")) { - GFile* testFile = g_file_new_for_path(testURL.c_str()); - gchar* testURLCString = g_file_get_uri(testFile); - testURL = testURLCString; - g_free(testURLCString); - g_object_unref(testFile); - } - - resetDefaultsToConsistentValues(); - - gTestRunner = TestRunner::create(testURL, command.expectedPixelHash); - topLoadingFrame = 0; - done = false; - - gTestRunner->setIconDatabaseEnabled(false); - - if (shouldLogFrameLoadDelegates(testURL)) - gTestRunner->setDumpFrameLoadCallbacks(true); - - if (shouldEnableDeveloperExtras(testURL)) { - gTestRunner->setDeveloperExtrasEnabled(true); - if (shouldOpenWebInspector(testURL)) - gTestRunner->showWebInspector(); - if (shouldDumpAsText(testURL)) { - gTestRunner->setDumpAsText(true); - gTestRunner->setGeneratePixelResults(false); - } - } - - WorkQueue::shared()->clear(); - WorkQueue::shared()->setFrozen(false); - - bool isSVGW3CTest = (testURL.find("svg/W3C-SVG-1.1") != string::npos); - GtkAllocation size; - size.x = size.y = 0; - size.width = isSVGW3CTest ? TestRunner::w3cSVGViewWidth : TestRunner::viewWidth; - size.height = isSVGW3CTest ? TestRunner::w3cSVGViewHeight : TestRunner::viewHeight; - gtk_window_resize(GTK_WINDOW(window), size.width, size.height); - gtk_widget_size_allocate(container, &size); - - if (prevTestBFItem) - g_object_unref(prevTestBFItem); - WebKitWebBackForwardList* bfList = webkit_web_view_get_back_forward_list(webView); - prevTestBFItem = webkit_web_back_forward_list_get_current_item(bfList); - if (prevTestBFItem) - g_object_ref(prevTestBFItem); - - initializeFonts(testURL.c_str()); - - // Focus the web view before loading the test to avoid focusing problems - gtk_widget_grab_focus(GTK_WIDGET(webView)); - webkit_web_view_open(webView, testURL.c_str()); - - gtk_main(); - - // If developer extras enabled Web Inspector may have been open by the test. - if (shouldEnableDeveloperExtras(testURL)) { - gTestRunner->closeWebInspector(); - gTestRunner->setDeveloperExtrasEnabled(false); - } - - // Also check if we still have opened webViews and free them. - if (gTestRunner->closeRemainingWindowsWhenComplete() || webViewList) { - while (webViewList) { - g_object_unref(WEBKIT_WEB_VIEW(webViewList->data)); - webViewList = g_slist_next(webViewList); - } - g_slist_free(webViewList); - webViewList = 0; - } - - WebCoreTestSupport::resetInternalsObject(webkit_web_frame_get_global_context(mainFrame)); - DumpRenderTreeSupportGtk::clearMemoryCache(); - DumpRenderTreeSupportGtk::clearApplicationCache(); - - // A blank load seems to be necessary to reset state after certain tests. - webkit_web_view_open(webView, "about:blank"); - - gTestRunner.clear(); - - // terminate the (possibly empty) pixels block after all the state reset - sendPixelResultsEOF(); -} - -void webViewLoadStarted(WebKitWebView* view, WebKitWebFrame* frame, void*) -{ - // Make sure we only set this once per test. If it gets cleared, and then set again, we might - // end up doing two dumps for one test. - if (!topLoadingFrame && !done) - topLoadingFrame = frame; -} - -static gboolean processWork(void* data) -{ - // if we finish all the commands, we're ready to dump state - if (WorkQueue::shared()->processWork() && !gTestRunner->waitToDump()) - dump(); - - return FALSE; -} - -static char* getFrameNameSuitableForTestResult(WebKitWebView* view, WebKitWebFrame* frame) -{ - char* frameName = g_strdup(webkit_web_frame_get_name(frame)); - - if (frame == webkit_web_view_get_main_frame(view)) { - // This is a bit strange. Shouldn't web_frame_get_name return NULL? - if (frameName && (frameName[0] != '\0')) { - char* tmp = g_strdup_printf("main frame \"%s\"", frameName); - g_free(frameName); - frameName = tmp; - } else { - g_free(frameName); - frameName = g_strdup("main frame"); - } - } else if (!frameName || (frameName[0] == '\0')) { - g_free(frameName); - frameName = g_strdup("frame (anonymous)"); - } else { - char* tmp = g_strdup_printf("frame \"%s\"", frameName); - g_free(frameName); - frameName = tmp; - } - - return frameName; -} - -static void webViewLoadFinished(WebKitWebView* view, WebKitWebFrame* frame, void*) -{ - // The deprecated "load-finished" signal is triggered by postProgressFinishedNotification(), - // so we can use it here in the DRT to provide the correct dump. - if (frame != topLoadingFrame) - return; - if (gTestRunner->dumpProgressFinishedCallback()) - printf("postProgressFinishedNotification\n"); -} - -static gboolean webViewLoadError(WebKitWebView*, WebKitWebFrame*, gchar*, gpointer, gpointer) -{ - return TRUE; // Return true here to disable the default error page. -} - -static void webViewDocumentLoadFinished(WebKitWebView* view, WebKitWebFrame* frame, void*) -{ - if (!done && gTestRunner->dumpFrameLoadCallbacks()) { - char* frameName = getFrameNameSuitableForTestResult(view, frame); - printf("%s - didFinishDocumentLoadForFrame\n", frameName); - g_free(frameName); - } else if (!done) { - guint pendingFrameUnloadEvents = DumpRenderTreeSupportGtk::getPendingUnloadEventCount(frame); - if (pendingFrameUnloadEvents) { - char* frameName = getFrameNameSuitableForTestResult(view, frame); - printf("%s - has %u onunload handler(s)\n", frameName, pendingFrameUnloadEvents); - g_free(frameName); - } - } -} - -static void webViewOnloadEvent(WebKitWebView* view, WebKitWebFrame* frame, void*) -{ - if (!done && gTestRunner->dumpFrameLoadCallbacks()) { - char* frameName = getFrameNameSuitableForTestResult(view, frame); - printf("%s - didHandleOnloadEventsForFrame\n", frameName); - g_free(frameName); - } -} - -static void addControllerToWindow(JSContextRef context, JSObjectRef windowObject, const char* controllerName, JSValueRef controller) -{ - JSStringRef controllerNameStr = JSStringCreateWithUTF8CString(controllerName); - JSObjectSetProperty(context, windowObject, controllerNameStr, controller, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, 0); - JSStringRelease(controllerNameStr); -} - -static void webViewWindowObjectCleared(WebKitWebView* view, WebKitWebFrame* frame, JSGlobalContextRef context, JSObjectRef windowObject, gpointer data) -{ - JSValueRef exception = 0; - ASSERT(gTestRunner); - - gTestRunner->makeWindowObject(context, windowObject, &exception); - ASSERT(!exception); - - gcController->makeWindowObject(context, windowObject, &exception); - ASSERT(!exception); - -#if HAVE(ACCESSIBILITY) - axController->makeWindowObject(context, windowObject, &exception); - ASSERT(!exception); -#endif - - addControllerToWindow(context, windowObject, "eventSender", makeEventSender(context, !webkit_web_frame_get_parent(frame))); - addControllerToWindow(context, windowObject, "textInputController", makeTextInputController(context)); - WebCoreTestSupport::injectInternalsObject(context); -} - -static gboolean webViewConsoleMessage(WebKitWebView* view, const gchar* message, unsigned int line, const gchar* sourceId, gpointer data) -{ - gchar* testMessage = 0; - const gchar* uriScheme; - - // Tests expect only the filename part of local URIs - uriScheme = g_strstr_len(message, -1, "file://"); - if (uriScheme) { - GString* tempString = g_string_sized_new(strlen(message)); - gchar* filename = g_strrstr(uriScheme, G_DIR_SEPARATOR_S); - - if (filename) { - // If the path is a lone slash, keep it to avoid empty output. - if (strlen(filename) > 1) - filename += strlen(G_DIR_SEPARATOR_S); - tempString = g_string_append_len(tempString, message, (uriScheme - message)); - tempString = g_string_append_len(tempString, filename, strlen(filename)); - testMessage = g_string_free(tempString, FALSE); - } - } - - fprintf(stdout, "CONSOLE MESSAGE: "); - if (line) - fprintf(stdout, "line %d: ", line); - fprintf(stdout, "%s\n", testMessage ? testMessage : message); - g_free(testMessage); - - return TRUE; -} - - -static gboolean webViewScriptAlert(WebKitWebView* view, WebKitWebFrame* frame, const gchar* message, gpointer data) -{ - fprintf(stdout, "ALERT: %s\n", message); - fflush(stdout); - return TRUE; -} - -static gboolean webViewScriptPrompt(WebKitWebView* webView, WebKitWebFrame* frame, const gchar* message, const gchar* defaultValue, gchar** value, gpointer data) -{ - fprintf(stdout, "PROMPT: %s, default text: %s\n", message, defaultValue); - *value = g_strdup(defaultValue); - return TRUE; -} - -static gboolean webViewScriptConfirm(WebKitWebView* view, WebKitWebFrame* frame, const gchar* message, gboolean* didConfirm, gpointer data) -{ - fprintf(stdout, "CONFIRM: %s\n", message); - *didConfirm = TRUE; - return TRUE; -} - -static void webViewTitleChanged(WebKitWebView* view, WebKitWebFrame* frame, const gchar* title, gpointer data) -{ - if (gTestRunner->dumpFrameLoadCallbacks() && !done) { - GUniquePtr<char> frameName(getFrameNameSuitableForTestResult(view, frame)); - printf("%s - didReceiveTitle: %s\n", frameName.get(), title ? title : ""); - } - - if (gTestRunner->dumpTitleChanges() && !done) - printf("TITLE CHANGED: '%s'\n", title ? title : ""); -} - -static bool webViewNavigationPolicyDecisionRequested(WebKitWebView* view, WebKitWebFrame* frame, - WebKitNetworkRequest* request, - WebKitWebNavigationAction* navAction, - WebKitWebPolicyDecision* policyDecision) -{ - // Use the default handler if we're not waiting for policy, - // i.e., TestRunner::waitForPolicyDelegate - if (!waitForPolicy) - return FALSE; - - gchar* typeDescription; - WebKitWebNavigationReason reason; - g_object_get(G_OBJECT(navAction), "reason", &reason, NULL); - - switch(reason) { - case WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED: - typeDescription = g_strdup("link clicked"); - break; - case WEBKIT_WEB_NAVIGATION_REASON_FORM_SUBMITTED: - typeDescription = g_strdup("form submitted"); - break; - case WEBKIT_WEB_NAVIGATION_REASON_BACK_FORWARD: - typeDescription = g_strdup("back/forward"); - break; - case WEBKIT_WEB_NAVIGATION_REASON_RELOAD: - typeDescription = g_strdup("reload"); - break; - case WEBKIT_WEB_NAVIGATION_REASON_FORM_RESUBMITTED: - typeDescription = g_strdup("form resubmitted"); - break; - case WEBKIT_WEB_NAVIGATION_REASON_OTHER: - typeDescription = g_strdup("other"); - break; - default: - typeDescription = g_strdup("illegal value"); - } - - printf("Policy delegate: attempt to load %s with navigation type '%s'\n", webkit_network_request_get_uri(request), typeDescription); - g_free(typeDescription); - - webkit_web_policy_decision_ignore(policyDecision); - gTestRunner->notifyDone(); - - return TRUE; -} - -static void webViewStatusBarTextChanged(WebKitWebView* view, const gchar* message, gpointer data) -{ - // Are we doing anything wrong? One test that does not call - // dumpStatusCallbacks gets true here - if (gTestRunner->dumpStatusCallbacks()) - printf("UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", message); -} - -static gboolean webViewClose(WebKitWebView* view) -{ - ASSERT(view); - - webViewList = g_slist_remove(webViewList, view); - g_object_unref(view); - - return TRUE; -} - -static void databaseQuotaExceeded(WebKitWebView* view, WebKitWebFrame* frame, WebKitWebDatabase *database) -{ - ASSERT(view); - ASSERT(frame); - ASSERT(database); - - WebKitSecurityOrigin* origin = webkit_web_database_get_security_origin(database); - if (gTestRunner->dumpDatabaseCallbacks()) { - printf("UI DELEGATE DATABASE CALLBACK: exceededDatabaseQuotaForSecurityOrigin:{%s, %s, %i} database:%s\n", - webkit_security_origin_get_protocol(origin), - webkit_security_origin_get_host(origin), - webkit_security_origin_get_port(origin), - webkit_web_database_get_name(database)); - } - webkit_security_origin_set_web_database_quota(origin, 5 * 1024 * 1024); -} - -static bool -geolocationPolicyDecisionRequested(WebKitWebView*, WebKitWebFrame*, WebKitGeolocationPolicyDecision* decision) -{ - if (!gTestRunner->isGeolocationPermissionSet()) - return FALSE; - if (gTestRunner->geolocationPermission()) - webkit_geolocation_policy_allow(decision); - else - webkit_geolocation_policy_deny(decision); - - return TRUE; -} - - -static WebKitWebView* webViewCreate(WebKitWebView*, WebKitWebFrame*); - -static gboolean webInspectorShowWindow(WebKitWebInspector*, gpointer data) -{ - gtk_window_set_default_size(GTK_WINDOW(webInspectorWindow), TestRunner::viewWidth, TestRunner::viewHeight); - gtk_widget_show_all(webInspectorWindow); - return TRUE; -} - -static gboolean webInspectorCloseWindow(WebKitWebInspector*, gpointer data) -{ - gtk_widget_destroy(webInspectorWindow); - webInspectorWindow = 0; - return TRUE; -} - -static WebKitWebView* webInspectorInspectWebView(WebKitWebInspector*, gpointer data) -{ - webInspectorWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); - - GtkWidget* webView = self_scrolling_webkit_web_view_new(); - gtk_container_add(GTK_CONTAINER(webInspectorWindow), - webView); - - return WEBKIT_WEB_VIEW(webView); -} - -static void topLoadingFrameLoadFinished() -{ - topLoadingFrame = 0; - WorkQueue::shared()->setFrozen(true); // first complete load freezes the queue for the rest of this test - if (gTestRunner->waitToDump()) - return; - - if (WorkQueue::shared()->count()) - g_idle_add_full(G_PRIORITY_DEFAULT, processWork, 0, 0); - else - dump(); -} - -static void webFrameLoadStatusNotified(WebKitWebFrame* frame, gpointer user_data) -{ - WebKitLoadStatus loadStatus = webkit_web_frame_get_load_status(frame); - - if (gTestRunner->dumpFrameLoadCallbacks()) { - GUniquePtr<char> frameName(getFrameNameSuitableForTestResult(webkit_web_frame_get_web_view(frame), frame)); - - switch (loadStatus) { - case WEBKIT_LOAD_PROVISIONAL: - if (!done) - printf("%s - didStartProvisionalLoadForFrame\n", frameName.get()); - break; - case WEBKIT_LOAD_COMMITTED: - if (!done) - printf("%s - didCommitLoadForFrame\n", frameName.get()); - break; - case WEBKIT_LOAD_FINISHED: - if (!done) - printf("%s - didFinishLoadForFrame\n", frameName.get()); - break; - case WEBKIT_LOAD_FAILED: - if (!done) - printf("%s - didFailLoadWithError\n", frameName.get()); - break; - default: - break; - } - } - - if ((loadStatus == WEBKIT_LOAD_FINISHED || loadStatus == WEBKIT_LOAD_FAILED) - && frame == topLoadingFrame) - topLoadingFrameLoadFinished(); -} - -static void frameCreatedCallback(WebKitWebView* webView, WebKitWebFrame* webFrame, gpointer user_data) -{ - g_signal_connect(webFrame, "notify::load-status", G_CALLBACK(webFrameLoadStatusNotified), NULL); - g_signal_connect(webFrame, "insecure-content-run", G_CALLBACK(didRunInsecureContent), NULL); -} - -static String pathFromSoupURI(SoupURI* uri) -{ - if (!uri) - return "(null)"; - - if (!g_str_equal(uri->scheme, "file")) - return soupURIToStringPreservingPassword(uri).data(); - - String pathString = uri->path; - GUniquePtr<gchar> pathBasename(g_path_get_basename(pathString.utf8().data())); - - WebKitWebFrame* mainFrame = webkit_web_view_get_main_frame(webView); - GUniquePtr<SoupURI> mainFrameUri(soup_uri_new(webkit_web_frame_get_uri(mainFrame))); - - String mainFrameUriPathString = mainFrameUri.get()->path; - String basePath = mainFrameUriPathString.substring(0, mainFrameUriPathString.reverseFind('/') + 1); - - if (!basePath.isEmpty() && pathString.startsWith(basePath)) - return pathString.substring(basePath.length()); - - return pathBasename.get(); -} - -static CString convertSoupMessageToURLPath(SoupMessage* soupMessage) -{ - if (!soupMessage) - return CString("(null)"); - if (SoupURI* requestURI = soup_message_get_uri(soupMessage)) - return pathFromSoupURI(requestURI).utf8(); - return CString("(null)"); -} - -static CString convertNetworkRequestToURLPath(WebKitNetworkRequest* request) -{ - return convertSoupMessageToURLPath(webkit_network_request_get_message(request)); -} - -static CString convertWebResourceToURLPath(WebKitWebResource* webResource) -{ - GUniquePtr<SoupURI> uri(soup_uri_new(webkit_web_resource_get_uri(webResource))); - return pathFromSoupURI(uri.get()).utf8(); -} - -static CString urlSuitableForTestResult(const char* uriString) -{ - if (!g_str_has_prefix(uriString, "file://")) - return CString(uriString); - - GUniquePtr<gchar> basename(g_path_get_basename(uriString)); - return CString(basename.get()); -} - -static CString descriptionSuitableForTestResult(SoupURI* uri) -{ - if (!uri) - return CString("(null)"); - - GUniquePtr<char> uriString(soup_uri_to_string(uri, false)); - return urlSuitableForTestResult(uriString.get()); -} - -static CString descriptionSuitableForTestResult(GError* error, WebKitWebResource* webResource) -{ - const gchar* errorDomain = g_quark_to_string(error->domain); - CString resourceURIString(urlSuitableForTestResult(webkit_web_resource_get_uri(webResource))); - - if (g_str_equal(errorDomain, "webkit-network-error-quark") || g_str_equal(errorDomain, "soup_http_error_quark")) - errorDomain = "NSURLErrorDomain"; - - if (g_str_equal(errorDomain, "WebKitPolicyError")) - errorDomain = "WebKitErrorDomain"; - - // TODO: the other ports get the failingURL from the ResourceError - GUniquePtr<char> errorString(g_strdup_printf("<NSError domain %s, code %d, failing URL \"%s\">", - errorDomain, error->code, resourceURIString.data())); - return CString(errorString.get()); -} - -static CString descriptionSuitableForTestResult(WebKitNetworkRequest* request) -{ - SoupMessage* soupMessage = webkit_network_request_get_message(request); - - if (!soupMessage) - return CString("(null)"); - - SoupURI* mainDocumentURI = soup_message_get_first_party(soupMessage); - CString mainDocumentURIString(descriptionSuitableForTestResult(mainDocumentURI)); - CString path(convertNetworkRequestToURLPath(request)); - GUniquePtr<char> description(g_strdup_printf("<NSURLRequest URL %s, main document URL %s, http method %s>", - path.data(), mainDocumentURIString.data(), soupMessage->method)); - return CString(description.get()); -} - -static CString descriptionSuitableForTestResult(WebKitNetworkResponse* response) -{ - if (!response) - return CString("(null)"); - - int statusCode = 0; - CString responseURIString(urlSuitableForTestResult(webkit_network_response_get_uri(response))); - SoupMessage* soupMessage = webkit_network_response_get_message(response); - CString path; - - if (soupMessage) { - statusCode = soupMessage->status_code; - path = convertSoupMessageToURLPath(soupMessage); - } else - path = CString("(null)"); - - GUniquePtr<char> description(g_strdup_printf("<NSURLResponse %s, http status code %d>", path.data(), statusCode)); - return CString(description.get()); -} - -static void willSendRequestCallback(WebKitWebView* webView, WebKitWebFrame* webFrame, WebKitWebResource* resource, WebKitNetworkRequest* request, WebKitNetworkResponse* response) -{ - - - if (!done && gTestRunner->willSendRequestReturnsNull()) { - // As requested by the TestRunner, don't perform the request. - webkit_network_request_set_uri(request, "about:blank"); - return; - } - - if (!done && gTestRunner->dumpResourceLoadCallbacks()) - printf("%s - willSendRequest %s redirectResponse %s\n", - convertNetworkRequestToURLPath(request).data(), - descriptionSuitableForTestResult(request).data(), - descriptionSuitableForTestResult(response).data()); - - SoupMessage* soupMessage = webkit_network_request_get_message(request); - SoupURI* uri = soup_uri_new(webkit_network_request_get_uri(request)); - - if (SOUP_URI_IS_VALID(uri)) { - GUniquePtr<char> uriString(soup_uri_to_string(uri, FALSE)); - - if (SOUP_URI_VALID_FOR_HTTP(uri) && g_strcmp0(uri->host, "127.0.0.1") - && g_strcmp0(uri->host, "255.255.255.255") - && g_ascii_strncasecmp(uri->host, "localhost", 9)) { - printf("Blocked access to external URL %s\n", uriString.get()); - // Cancel load of blocked resource to avoid potential - // network-related timeouts in tests. - webkit_network_request_set_uri(request, "about:blank"); - soup_uri_free(uri); - return; - } - - const string& destination = gTestRunner->redirectionDestinationForURL(uriString.get()); - if (!destination.empty()) - webkit_network_request_set_uri(request, destination.c_str()); - } - - if (uri) - soup_uri_free(uri); - - if (soupMessage) { - const set<string>& clearHeaders = gTestRunner->willSendRequestClearHeaders(); - for (set<string>::const_iterator header = clearHeaders.begin(); header != clearHeaders.end(); ++header) - soup_message_headers_remove(soupMessage->request_headers, header->c_str()); - } -} - - -static void didReceiveResponse(WebKitWebView* webView, WebKitWebFrame*, WebKitWebResource* webResource, WebKitNetworkResponse* response) -{ - if (!done && gTestRunner->dumpResourceLoadCallbacks()) { - CString responseDescription(descriptionSuitableForTestResult(response)); - CString path(convertWebResourceToURLPath(webResource)); - printf("%s - didReceiveResponse %s\n", path.data(), responseDescription.data()); - } - - // TODO: add "has MIME type" whenever dumpResourceResponseMIMETypes() is supported. - // See https://bugs.webkit.org/show_bug.cgi?id=58222. -} - -static void didFinishLoading(WebKitWebView* webView, WebKitWebFrame* webFrame, WebKitWebResource* webResource) -{ - if (!done && gTestRunner->dumpResourceLoadCallbacks()) - printf("%s - didFinishLoading\n", convertWebResourceToURLPath(webResource).data()); -} - -static void didFailLoadingWithError(WebKitWebView* webView, WebKitWebFrame* webFrame, WebKitWebResource* webResource, GError* webError) -{ - if (!done && gTestRunner->dumpResourceLoadCallbacks()) { - CString webErrorString(descriptionSuitableForTestResult(webError, webResource)); - printf("%s - didFailLoadingWithError: %s\n", convertWebResourceToURLPath(webResource).data(), - webErrorString.data()); - } -} - -static void didRunInsecureContent(WebKitWebFrame*, WebKitSecurityOrigin*, const char* url) -{ - if (!done && gTestRunner->dumpFrameLoadCallbacks()) - printf("didRunInsecureContent\n"); -} - -static gboolean webViewRunFileChooser(WebKitWebView*, WebKitFileChooserRequest*) -{ - // We return TRUE to not propagate the event further so the - // default file chooser dialog is not shown. - return TRUE; -} - -static void frameLoadEventCallback(WebKitWebFrame* frame, DumpRenderTreeSupportGtk::FrameLoadEvent event, const char* url) -{ - if (done || !gTestRunner->dumpFrameLoadCallbacks()) - return; - - GUniquePtr<char> frameName(getFrameNameSuitableForTestResult(webkit_web_frame_get_web_view(frame), frame)); - switch (event) { - case DumpRenderTreeSupportGtk::WillPerformClientRedirectToURL: - ASSERT(url); - printf("%s - willPerformClientRedirectToURL: %s \n", frameName.get(), url); - break; - case DumpRenderTreeSupportGtk::DidCancelClientRedirect: - printf("%s - didCancelClientRedirectForFrame\n", frameName.get()); - break; - case DumpRenderTreeSupportGtk::DidReceiveServerRedirectForProvisionalLoad: - printf("%s - didReceiveServerRedirectForProvisionalLoadForFrame\n", frameName.get()); - break; - case DumpRenderTreeSupportGtk::DidDisplayInsecureContent: - printf ("didDisplayInsecureContent\n"); - break; - case DumpRenderTreeSupportGtk::DidDetectXSS: - printf ("didDetectXSS\n"); - break; - default: - ASSERT_NOT_REACHED(); - } -} - -static bool authenticationCallback(CString& username, CString& password, WebKitWebResource* webResource) -{ - CString description(convertWebResourceToURLPath(webResource)); - - if (!gTestRunner->handlesAuthenticationChallenges()) { - printf("%s - didReceiveAuthenticationChallenge - Simulating cancelled authentication sheet\n", description.data()); - return false; - } - - username = gTestRunner->authenticationUsername().c_str(); - password = gTestRunner->authenticationPassword().c_str(); - printf("%s - didReceiveAuthenticationChallenge - Responding with %s:%s\n", description.data(), username.data(), password.data()); - return true; -} - -static WebKitWebView* createWebView() -{ - // It is important to declare DRT is running early so when creating - // web view mock clients are used instead of proper ones. - DumpRenderTreeSupportGtk::setDumpRenderTreeModeEnabled(true); - - DumpRenderTreeSupportGtk::setFrameLoadEventCallback(frameLoadEventCallback); - DumpRenderTreeSupportGtk::setAuthenticationCallback(authenticationCallback); - - WebKitWebView* view = WEBKIT_WEB_VIEW(self_scrolling_webkit_web_view_new()); - - g_object_connect(G_OBJECT(view), - "signal::load-started", webViewLoadStarted, 0, - "signal::load-finished", webViewLoadFinished, 0, - "signal::load-error", webViewLoadError, 0, - "signal::window-object-cleared", webViewWindowObjectCleared, 0, - "signal::console-message", webViewConsoleMessage, 0, - "signal::script-alert", webViewScriptAlert, 0, - "signal::script-prompt", webViewScriptPrompt, 0, - "signal::script-confirm", webViewScriptConfirm, 0, - "signal::title-changed", webViewTitleChanged, 0, - "signal::navigation-policy-decision-requested", webViewNavigationPolicyDecisionRequested, 0, - "signal::status-bar-text-changed", webViewStatusBarTextChanged, 0, - "signal::create-web-view", webViewCreate, 0, - "signal::close-web-view", webViewClose, 0, - "signal::database-quota-exceeded", databaseQuotaExceeded, 0, - "signal::document-load-finished", webViewDocumentLoadFinished, 0, - "signal::geolocation-policy-decision-requested", geolocationPolicyDecisionRequested, 0, - "signal::onload-event", webViewOnloadEvent, 0, - "signal::drag-begin", dragBeginCallback, 0, - "signal::drag-end", dragEndCallback, 0, - "signal::drag-failed", dragFailedCallback, 0, - "signal::frame-created", frameCreatedCallback, 0, - "signal::resource-request-starting", willSendRequestCallback, 0, - "signal::resource-response-received", didReceiveResponse, 0, - "signal::resource-load-finished", didFinishLoading, 0, - "signal::resource-load-failed", didFailLoadingWithError, 0, - "signal::run-file-chooser", webViewRunFileChooser, 0, - NULL); - connectEditingCallbacks(view); - - WebKitWebInspector* inspector = webkit_web_view_get_inspector(view); - g_object_connect(G_OBJECT(inspector), - "signal::inspect-web-view", webInspectorInspectWebView, 0, - "signal::show-window", webInspectorShowWindow, 0, - "signal::close-window", webInspectorCloseWindow, 0, - NULL); - - if (webView) { - WebKitWebSettings* settings = webkit_web_view_get_settings(webView); - webkit_web_view_set_settings(view, settings); - } - - // frame-created is not issued for main frame. That's why we must do this here - WebKitWebFrame* frame = webkit_web_view_get_main_frame(view); - g_signal_connect(frame, "notify::load-status", G_CALLBACK(webFrameLoadStatusNotified), NULL); - g_signal_connect(frame, "insecure-content-run", G_CALLBACK(didRunInsecureContent), NULL); - - return view; -} - -static WebKitWebView* webViewCreate(WebKitWebView* view, WebKitWebFrame* frame) -{ - if (!gTestRunner->canOpenWindows()) - return 0; - - // Make sure that waitUntilDone has been called. - ASSERT(gTestRunner->waitToDump()); - - WebKitWebView* newWebView = createWebView(); - g_object_ref_sink(G_OBJECT(newWebView)); - webViewList = g_slist_prepend(webViewList, newWebView); - return newWebView; -} - -static void logHandler(const gchar* domain, GLogLevelFlags level, const gchar* message, gpointer data) -{ - if (level < G_LOG_LEVEL_DEBUG) - fprintf(stderr, "%s\n", message); -} - -int main(int argc, char* argv[]) -{ - gtk_init(&argc, &argv); - - // Some plugins might try to use the GLib logger for printing debug - // messages. This will cause tests to fail because of unexpected output. - // We squelch all debug messages sent to the logger. - g_log_set_default_handler(logHandler, 0); - - initializeGlobalsFromCommandLineOptions(argc, argv); - initializeFonts(); - - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); -#ifdef GTK_API_VERSION_2 - container = gtk_hbox_new(TRUE, 0); -#else - container = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_set_homogeneous(GTK_BOX(container), TRUE); -#endif - gtk_container_add(GTK_CONTAINER(window), container); - gtk_widget_show_all(window); - - webView = createWebView(); - gtk_box_pack_start(GTK_BOX(container), GTK_WIDGET(webView), TRUE, TRUE, 0); - gtk_widget_realize(GTK_WIDGET(webView)); - gtk_widget_show_all(container); - mainFrame = webkit_web_view_get_main_frame(webView); - - setDefaultsToConsistentStateValuesForTesting(); - - gcController = new GCController(); -#if HAVE(ACCESSIBILITY) - axController = new AccessibilityController(); -#endif - - if (useLongRunningServerMode(argc, argv)) { - printSeparators = true; - runTestingServerLoop(); - } else { - printSeparators = (optind < argc-1 || (dumpPixelsForCurrentTest && dumpTree)); - for (int i = optind; i != argc; ++i) - runTest(argv[i]); - } - - delete gcController; - gcController = 0; - -#if HAVE(ACCESSIBILITY) - delete axController; - axController = 0; -#endif - - gtk_widget_destroy(window); - - return 0; -} diff --git a/Tools/DumpRenderTree/gtk/DumpRenderTreeGtk.h b/Tools/DumpRenderTree/gtk/DumpRenderTreeGtk.h deleted file mode 100644 index 4b33458f3..000000000 --- a/Tools/DumpRenderTree/gtk/DumpRenderTreeGtk.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2007 Eric Seidel <eric@webkit.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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. - */ - -#ifndef DumpRenderTreeGtk_h -#define DumpRenderTreeGtk_h - -#include <JavaScriptCore/JSBase.h> -#include <glib.h> -#include <libsoup/soup.h> -#include <webkit/webkitdefines.h> -#include <wtf/text/CString.h> - -extern WebKitWebFrame* mainFrame; -extern WebKitWebFrame* topLoadingFrame; -extern bool waitForPolicy; -extern GSList* webViewList; - -gchar* JSStringCopyUTF8CString(JSStringRef jsString); -CString getTopLevelPath(); - -void setWaitToDumpWatchdog(guint timer); -bool shouldSetWaitToDumpWatchdog(); -CString soupURIToStringPreservingPassword(SoupURI* soupURI); - -#endif // DumpRenderTreeGtk_h diff --git a/Tools/DumpRenderTree/gtk/EditingCallbacks.cpp b/Tools/DumpRenderTree/gtk/EditingCallbacks.cpp deleted file mode 100644 index 3c08f80b3..000000000 --- a/Tools/DumpRenderTree/gtk/EditingCallbacks.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/* - * Copyright (C) 2010 Igalia S.L. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "EditingCallbacks.h" - -#include "DumpRenderTree.h" -#include "TestRunner.h" -#include <gtk/gtk.h> -#include <webkit/webkit.h> -#include <wtf/gobject/GUniquePtr.h> -#include <wtf/text/CString.h> - -static CString dumpNodePath(WebKitDOMNode* node) -{ - GUniquePtr<gchar> nodeName(webkit_dom_node_get_node_name(node)); - GString* path = g_string_new(nodeName.get()); - - WebKitDOMNode* parent = webkit_dom_node_get_parent_node(node); - while (parent) { - GUniquePtr<gchar> parentName(webkit_dom_node_get_node_name(parent)); - - g_string_append(path, " > "); - g_string_append(path, parentName.get()); - parent = webkit_dom_node_get_parent_node(parent); - } - - GUniquePtr<gchar> pathBuffer(g_string_free(path, FALSE)); - return pathBuffer.get(); -} - -static CString dumpRange(WebKitDOMRange* range) -{ - if (!range) - return "(null)"; - - GUniquePtr<gchar> dump(g_strdup_printf("range from %li of %s to %li of %s", - webkit_dom_range_get_start_offset(range, 0), - dumpNodePath(webkit_dom_range_get_start_container(range, 0)).data(), - webkit_dom_range_get_end_offset(range, 0), - dumpNodePath(webkit_dom_range_get_end_container(range, 0)).data())); - - return dump.get(); -} - -static const char* insertActionString(WebKitInsertAction action) -{ - switch (action) { - case WEBKIT_INSERT_ACTION_TYPED: - return "WebViewInsertActionTyped"; - case WEBKIT_INSERT_ACTION_PASTED: - return "WebViewInsertActionPasted"; - case WEBKIT_INSERT_ACTION_DROPPED: - return "WebViewInsertActionDropped"; - } - ASSERT_NOT_REACHED(); - return "WebViewInsertActionTyped"; -} - -static const char* selectionAffinityString(WebKitSelectionAffinity affinity) -{ - switch (affinity) { - case WEBKIT_SELECTION_AFFINITY_UPSTREAM: - return "NSSelectionAffinityUpstream"; - case WEBKIT_SELECTION_AFFINITY_DOWNSTREAM: - return "NSSelectionAffinityDownstream"; - } - ASSERT_NOT_REACHED(); - return "NSSelectionAffinityUpstream"; -} - -gboolean shouldBeginEditing(WebKitWebView* webView, WebKitDOMRange* range) -{ - if (!done && gTestRunner->dumpEditingCallbacks()) - printf("EDITING DELEGATE: shouldBeginEditingInDOMRange:%s\n", dumpRange(range).data()); - return TRUE; -} - -gboolean shouldEndEditing(WebKitWebView* webView, WebKitDOMRange* range) -{ - if (!done && gTestRunner->dumpEditingCallbacks()) - printf("EDITING DELEGATE: shouldEndEditingInDOMRange:%s\n", dumpRange(range).data()); - return TRUE; -} - -gboolean shouldInsertNode(WebKitWebView* webView, WebKitDOMNode* node, WebKitDOMRange* range, WebKitInsertAction action) -{ - if (!done && gTestRunner->dumpEditingCallbacks()) { - printf("EDITING DELEGATE: shouldInsertNode:%s replacingDOMRange:%s givenAction:%s\n", - dumpNodePath(node).data(), dumpRange(range).data(), insertActionString(action)); - } - return TRUE; -} - -gboolean shouldInsertText(WebKitWebView* webView, const gchar* text, WebKitDOMRange* range, WebKitInsertAction action) -{ - if (!done && gTestRunner->dumpEditingCallbacks()) { - printf("EDITING DELEGATE: shouldInsertText:%s replacingDOMRange:%s givenAction:%s\n", - text, dumpRange(range).data(), insertActionString(action)); - } - return TRUE; -} - -gboolean shouldDeleteRange(WebKitWebView* webView, WebKitDOMRange* range) -{ - if (!done && gTestRunner->dumpEditingCallbacks()) - printf("EDITING DELEGATE: shouldDeleteDOMRange:%s\n", dumpRange(range).data()); - return TRUE; -} - -gboolean shouldShowDeleteInterfaceForElement(WebKitWebView* webView, WebKitDOMHTMLElement* element) -{ - return FALSE; -} - -gboolean shouldChangeSelectedRange(WebKitWebView* webView, WebKitDOMRange* fromRange, WebKitDOMRange* toRange, WebKitSelectionAffinity affinity, gboolean stillSelecting) -{ - if (!done && gTestRunner->dumpEditingCallbacks()) { - printf("EDITING DELEGATE: shouldChangeSelectedDOMRange:%s toDOMRange:%s affinity:%s stillSelecting:%s\n", - dumpRange(fromRange).data(), dumpRange(toRange).data(), selectionAffinityString(affinity), - stillSelecting ? "TRUE" : "FALSE"); - } - return TRUE; -} - -gboolean shouldApplyStyle(WebKitWebView* webView, WebKitDOMCSSStyleDeclaration* style, WebKitDOMRange* range) -{ - if (!done && gTestRunner->dumpEditingCallbacks()) { - GUniquePtr<gchar> styleText(webkit_dom_css_style_declaration_get_css_text(style)); - printf("EDITING DELEGATE: shouldApplyStyle:%s toElementsInDOMRange:%s\n", - styleText.get(), dumpRange(range).data()); - } - return TRUE; -} - -void editingBegan(WebKitWebView*) -{ - if (!done && gTestRunner->dumpEditingCallbacks()) - printf("EDITING DELEGATE: webViewDidBeginEditing:WebViewDidBeginEditingNotification\n"); -} - -void userChangedContents(WebKitWebView*) -{ - if (!done && gTestRunner->dumpEditingCallbacks()) - printf("EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification\n"); -} - -void editingEnded(WebKitWebView*) -{ - if (!done && gTestRunner->dumpEditingCallbacks()) - printf("EDITING DELEGATE: webViewDidEndEditing:WebViewDidEndEditingNotification\n"); -} - -void selectionChanged(WebKitWebView*) -{ - if (!done && gTestRunner->dumpEditingCallbacks()) - printf("EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification\n"); -} - -void connectEditingCallbacks(WebKitWebView* webView) -{ - g_object_connect(G_OBJECT(webView), - "signal::should-begin-editing", shouldBeginEditing, 0, - "signal::should-end-editing", shouldEndEditing, 0, - "signal::should-insert-node", shouldInsertNode, 0, - "signal::should-insert-text", shouldInsertText, 0, - "signal::should-delete-range", shouldDeleteRange, 0, - "signal::should-show-delete-interface-for-element", shouldShowDeleteInterfaceForElement, 0, - "signal::should-change-selected-range", shouldChangeSelectedRange, 0, - "signal::should-apply-style", shouldApplyStyle, 0, - "signal::editing-began", editingBegan, 0, - "signal::user-changed-contents", userChangedContents, 0, - "signal::editing-ended", editingEnded, 0, - "signal::selection-changed", selectionChanged, 0, - NULL); -} - diff --git a/Tools/DumpRenderTree/gtk/EditingCallbacks.h b/Tools/DumpRenderTree/gtk/EditingCallbacks.h deleted file mode 100644 index 7a9514917..000000000 --- a/Tools/DumpRenderTree/gtk/EditingCallbacks.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2010 Igalia S.L. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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. - */ - -#ifndef EditingCallbacks_h -#define EditingCallbacks_h - -typedef struct _WebKitWebView WebKitWebView; -void connectEditingCallbacks(WebKitWebView*); - -#endif diff --git a/Tools/DumpRenderTree/gtk/EventSender.cpp b/Tools/DumpRenderTree/gtk/EventSender.cpp deleted file mode 100644 index bd8e4fb8f..000000000 --- a/Tools/DumpRenderTree/gtk/EventSender.cpp +++ /dev/null @@ -1,1004 +0,0 @@ -/* - * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. - * Copyright (C) 2009 Zan Dobersek <zandobersek@gmail.com> - * Copyright (C) 2009 Holger Hans Peter Freyther - * Copyright (C) 2010 Igalia S.L. - * Copyright (C) 2012 ChangSeok Oh <shivamidow@gmail.com> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "EventSender.h" - -#include "DumpRenderTree.h" -#include "WebCoreSupport/DumpRenderTreeSupportGtk.h" -#include <GRefPtrGtk.h> -#include <GtkVersioning.h> -#include <JavaScriptCore/JSObjectRef.h> -#include <JavaScriptCore/JSRetainPtr.h> -#include <JavaScriptCore/JSStringRef.h> -#include <cstring> -#include <gdk/gdk.h> -#include <gdk/gdkkeysyms.h> -#include <webkit/webkitwebframe.h> -#include <webkit/webkitwebview.h> -#include <wtf/ASCIICType.h> -#include <wtf/Platform.h> -#include <wtf/gobject/GUniquePtr.h> -#include <wtf/text/CString.h> - -extern "C" { - extern GtkMenu* webkit_web_view_get_context_menu(WebKitWebView*); -} - -static bool dragMode; -static int timeOffset = 0; - -static int lastMousePositionX; -static int lastMousePositionY; -static int lastClickPositionX; -static int lastClickPositionY; -static int lastClickTimeOffset; -static int lastClickButton; -static unsigned buttonCurrentlyDown; -static int clickCount; -GdkDragContext* currentDragSourceContext; - -struct DelayedMessage { - GdkEvent* event; - gulong delay; -}; - -static DelayedMessage msgQueue[1024]; - -static unsigned endOfQueue; -static unsigned startOfQueue; - -static const float zoomMultiplierRatio = 1.2f; - -// WebCore and layout tests assume this value. -static const float pixelsPerScrollTick = 40; - -// Key event location code defined in DOM Level 3. -enum KeyLocationCode { - DOM_KEY_LOCATION_STANDARD = 0x00, - DOM_KEY_LOCATION_LEFT = 0x01, - DOM_KEY_LOCATION_RIGHT = 0x02, - DOM_KEY_LOCATION_NUMPAD = 0x03 -}; - -static void sendOrQueueEvent(GdkEvent*, bool = true); -static void dispatchEvent(GdkEvent* event); -static guint getStateFlags(); - -static JSValueRef getDragModeCallback(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) -{ - return JSValueMakeBoolean(context, dragMode); -} - -static bool setDragModeCallback(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) -{ - dragMode = JSValueToBoolean(context, value); - return true; -} - -static JSValueRef leapForwardCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - if (argumentCount > 0) { - msgQueue[endOfQueue].delay = JSValueToNumber(context, arguments[0], exception); - timeOffset += msgQueue[endOfQueue].delay; - ASSERT(!exception || !*exception); - } - - return JSValueMakeUndefined(context); -} - -bool prepareMouseButtonEvent(GdkEvent* event, int eventSenderButtonNumber, guint modifiers) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - if (!view) - return false; - - // The logic for mapping EventSender button numbers to GDK button - // numbers originates from the Windows EventSender. - int gdkButtonNumber = 3; - if (eventSenderButtonNumber >= 0 && eventSenderButtonNumber <= 2) - gdkButtonNumber = eventSenderButtonNumber + 1; - - // fast/events/mouse-click-events expects the 4th button - // to be event->button = 1, so send a middle-button event. - else if (eventSenderButtonNumber == 3) - gdkButtonNumber = 2; - - event->button.button = gdkButtonNumber; - event->button.x = lastMousePositionX; - event->button.y = lastMousePositionY; - event->button.window = gtk_widget_get_window(GTK_WIDGET(view)); - g_object_ref(event->button.window); - event->button.device = getDefaultGDKPointerDevice(event->button.window); - event->button.state = modifiers | getStateFlags(); - event->button.time = GDK_CURRENT_TIME; - event->button.axes = 0; - - int xRoot, yRoot; - gdk_window_get_root_coords(gtk_widget_get_window(GTK_WIDGET(view)), lastMousePositionX, lastMousePositionY, &xRoot, &yRoot); - event->button.x_root = xRoot; - event->button.y_root = yRoot; - - return true; -} - -static JSValueRef getMenuItemTitleCallback(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) -{ - GtkWidget* widget = GTK_WIDGET(JSObjectGetPrivate(object)); - CString label; - if (GTK_IS_SEPARATOR_MENU_ITEM(widget)) - label = "<separator>"; - else - label = gtk_menu_item_get_label(GTK_MENU_ITEM(widget)); - - JSRetainPtr<JSStringRef> itemText(Adopt, JSStringCreateWithUTF8CString(label.data())); - return JSValueMakeString(context, itemText.get()); -} - -static bool setMenuItemTitleCallback(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) -{ - return true; -} - -static JSValueRef menuItemClickCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - GtkMenuItem* item = GTK_MENU_ITEM(JSObjectGetPrivate(thisObject)); - gtk_menu_item_activate(item); - return JSValueMakeUndefined(context); -} - -static JSStaticFunction staticMenuItemFunctions[] = { - { "click", menuItemClickCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { 0, 0, 0 } -}; - -static JSStaticValue staticMenuItemValues[] = { - { "title", getMenuItemTitleCallback, setMenuItemTitleCallback, kJSPropertyAttributeNone }, - { 0, 0, 0, 0 } -}; - -static JSClassRef getMenuItemClass() -{ - static JSClassRef menuItemClass = 0; - - if (!menuItemClass) { - JSClassDefinition classDefinition = { - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - classDefinition.staticFunctions = staticMenuItemFunctions; - classDefinition.staticValues = staticMenuItemValues; - - menuItemClass = JSClassCreate(&classDefinition); - } - - return menuItemClass; -} - - -static JSValueRef contextClickCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - GdkEvent* pressEvent = gdk_event_new(GDK_BUTTON_PRESS); - - if (!prepareMouseButtonEvent(pressEvent, 2, 0)) { - gdk_event_free(pressEvent); - return JSObjectMakeArray(context, 0, 0, 0); - } - - GdkEvent* releaseEvent = gdk_event_copy(pressEvent); - sendOrQueueEvent(pressEvent); - - JSValueRef valueRef = JSObjectMakeArray(context, 0, 0, 0); - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - GtkMenu* gtkMenu = webkit_web_view_get_context_menu(view); - if (gtkMenu) { - GUniquePtr<GList> items(gtk_container_get_children(GTK_CONTAINER(gtkMenu))); - JSValueRef arrayValues[g_list_length(items.get())]; - int index = 0; - for (GList* item = g_list_first(items.get()); item; item = g_list_next(item)) { - arrayValues[index] = JSObjectMake(context, getMenuItemClass(), item->data); - index++; - } - if (index) - valueRef = JSObjectMakeArray(context, index - 1, arrayValues, 0); - } - - releaseEvent->type = GDK_BUTTON_RELEASE; - sendOrQueueEvent(releaseEvent); - return valueRef; -} - -static gboolean sendClick(gpointer) -{ - GdkEvent* pressEvent = gdk_event_new(GDK_BUTTON_PRESS); - - if (!prepareMouseButtonEvent(pressEvent, 1, 0)) { - gdk_event_free(pressEvent); - return FALSE; - } - - GdkEvent* releaseEvent = gdk_event_copy(pressEvent); - dispatchEvent(pressEvent); - releaseEvent->type = GDK_BUTTON_RELEASE; - dispatchEvent(releaseEvent); - - return FALSE; -} - -static JSValueRef scheduleAsynchronousClickCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - g_idle_add_full(G_PRIORITY_DEFAULT, sendClick, 0, 0); - return JSValueMakeUndefined(context); -} - -static void updateClickCount(int button) -{ - if (lastClickPositionX != lastMousePositionX - || lastClickPositionY != lastMousePositionY - || lastClickButton != button - || timeOffset - lastClickTimeOffset >= 1) - clickCount = 1; - else - clickCount++; -} - -static guint gdkModifierFromJSValue(JSContextRef context, const JSValueRef value) -{ - JSStringRef string = JSValueToStringCopy(context, value, 0); - guint gdkModifier = 0; - if (JSStringIsEqualToUTF8CString(string, "ctrlKey") - || JSStringIsEqualToUTF8CString(string, "addSelectionKey")) - gdkModifier = GDK_CONTROL_MASK; - else if (JSStringIsEqualToUTF8CString(string, "shiftKey") - || JSStringIsEqualToUTF8CString(string, "rangeSelectionKey")) - gdkModifier = GDK_SHIFT_MASK; - else if (JSStringIsEqualToUTF8CString(string, "altKey")) - gdkModifier = GDK_MOD1_MASK; - - // Currently the metaKey as defined in WebCore/platform/gtk/PlatformMouseEventGtk.cpp - // is GDK_META_MASK. This code must be kept in sync with that file. - else if (JSStringIsEqualToUTF8CString(string, "metaKey")) - gdkModifier = GDK_META_MASK; - - JSStringRelease(string); - return gdkModifier; -} - -static guint gdkModifersFromJSValue(JSContextRef context, const JSValueRef modifiers) -{ - // The value may either be a string with a single modifier or an array of modifiers. - if (JSValueIsString(context, modifiers)) - return gdkModifierFromJSValue(context, modifiers); - - JSObjectRef modifiersArray = JSValueToObject(context, modifiers, 0); - if (!modifiersArray) - return 0; - - guint gdkModifiers = 0; - JSRetainPtr<JSStringRef> lengthProperty(Adopt, JSStringCreateWithUTF8CString("length")); - int modifiersCount = JSValueToNumber(context, JSObjectGetProperty(context, modifiersArray, lengthProperty.get(), 0), 0); - for (int i = 0; i < modifiersCount; ++i) - gdkModifiers |= gdkModifierFromJSValue(context, JSObjectGetPropertyAtIndex(context, modifiersArray, i, 0)); - return gdkModifiers; -} - -static JSValueRef mouseDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - int button = 0; - if (argumentCount == 1) { - button = static_cast<int>(JSValueToNumber(context, arguments[0], exception)); - g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); - } - guint modifiers = argumentCount >= 2 ? gdkModifersFromJSValue(context, arguments[1]) : 0; - - GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS); - if (!prepareMouseButtonEvent(event, button, modifiers)) { - gdk_event_free(event); - return JSValueMakeUndefined(context); - } - - // If the same mouse button is already in the down position don't send another event as it may confuse Xvfb. - if (buttonCurrentlyDown == event->button.button) { - gdk_event_free(event); - return JSValueMakeUndefined(context); - } - - buttonCurrentlyDown = event->button.button; - - // Normally GDK will send both GDK_BUTTON_PRESS and GDK_2BUTTON_PRESS for - // the second button press during double-clicks. WebKit GTK+ selectively - // ignores the first GDK_BUTTON_PRESS of that pair using gdk_event_peek. - // Since our events aren't ever going onto the GDK event queue, WebKit won't - // be able to filter out the first GDK_BUTTON_PRESS, so we just don't send - // it here. Eventually this code should probably figure out a way to get all - // appropriate events onto the event queue and this work-around should be - // removed. - updateClickCount(event->button.button); - if (clickCount == 2) - event->type = GDK_2BUTTON_PRESS; - else if (clickCount == 3) - event->type = GDK_3BUTTON_PRESS; - - sendOrQueueEvent(event); - return JSValueMakeUndefined(context); -} - -static guint getStateFlags() -{ - if (buttonCurrentlyDown == 1) - return GDK_BUTTON1_MASK; - if (buttonCurrentlyDown == 2) - return GDK_BUTTON2_MASK; - if (buttonCurrentlyDown == 3) - return GDK_BUTTON3_MASK; - return 0; -} - -static JSValueRef mouseUpCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - int button = 0; - if (argumentCount == 1) { - button = static_cast<int>(JSValueToNumber(context, arguments[0], exception)); - g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); - } - guint modifiers = argumentCount >= 2 ? gdkModifersFromJSValue(context, arguments[1]) : 0; - - GdkEvent* event = gdk_event_new(GDK_BUTTON_RELEASE); - if (!prepareMouseButtonEvent(event, button, modifiers)) { - gdk_event_free(event); - return JSValueMakeUndefined(context); - } - - lastClickPositionX = lastMousePositionX; - lastClickPositionY = lastMousePositionY; - lastClickButton = buttonCurrentlyDown; - lastClickTimeOffset = timeOffset; - buttonCurrentlyDown = 0; - - sendOrQueueEvent(event); - return JSValueMakeUndefined(context); -} - -static JSValueRef mouseMoveToCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - if (!view) - return JSValueMakeUndefined(context); - - if (argumentCount < 2) - return JSValueMakeUndefined(context); - - lastMousePositionX = (int)JSValueToNumber(context, arguments[0], exception); - g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); - lastMousePositionY = (int)JSValueToNumber(context, arguments[1], exception); - g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); - - GdkEvent* event = gdk_event_new(GDK_MOTION_NOTIFY); - event->motion.x = lastMousePositionX; - event->motion.y = lastMousePositionY; - - event->motion.time = GDK_CURRENT_TIME; - event->motion.window = gtk_widget_get_window(GTK_WIDGET(view)); - g_object_ref(event->motion.window); - event->button.device = getDefaultGDKPointerDevice(event->motion.window); - - guint modifiers = argumentCount >= 3 ? gdkModifersFromJSValue(context, arguments[2]) : 0; - event->motion.state = modifiers | getStateFlags(); - event->motion.axes = 0; - - int xRoot, yRoot; - gdk_window_get_root_coords(gtk_widget_get_window(GTK_WIDGET(view)), lastMousePositionX, lastMousePositionY, &xRoot, &yRoot); - event->motion.x_root = xRoot; - event->motion.y_root = yRoot; - - sendOrQueueEvent(event, false); - return JSValueMakeUndefined(context); -} - -static JSValueRef mouseScrollByCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - if (!view) - return JSValueMakeUndefined(context); - - if (argumentCount < 2) - return JSValueMakeUndefined(context); - - int horizontal = (int)JSValueToNumber(context, arguments[0], exception); - g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); - int vertical = (int)JSValueToNumber(context, arguments[1], exception); - g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); - - // Copy behaviour of Qt and EFL - just return in case of (0,0) mouse scroll - if (!horizontal && !vertical) - return JSValueMakeUndefined(context); - - GdkEvent* event = gdk_event_new(GDK_SCROLL); - event->scroll.x = lastMousePositionX; - event->scroll.y = lastMousePositionY; - event->scroll.time = GDK_CURRENT_TIME; - event->scroll.window = gtk_widget_get_window(GTK_WIDGET(view)); - g_object_ref(event->scroll.window); - - // GTK+ only supports one tick in each scroll event that is not smooth. For the cases of more than one direction, - // and more than one step in a direction, we can only use smooth events, supported from Gtk 3.3.18. -#if GTK_CHECK_VERSION(3, 3, 18) - if ((horizontal && vertical) || horizontal > 1 || horizontal < -1 || vertical > 1 || vertical < -1) { - event->scroll.direction = GDK_SCROLL_SMOOTH; - event->scroll.delta_x = -horizontal; - event->scroll.delta_y = -vertical; - - sendOrQueueEvent(event); - return JSValueMakeUndefined(context); - } -#else - g_return_val_if_fail((!vertical || !horizontal), JSValueMakeUndefined(context)); -#endif - - if (horizontal < 0) - event->scroll.direction = GDK_SCROLL_RIGHT; - else if (horizontal > 0) - event->scroll.direction = GDK_SCROLL_LEFT; - else if (vertical < 0) - event->scroll.direction = GDK_SCROLL_DOWN; - else if (vertical > 0) - event->scroll.direction = GDK_SCROLL_UP; - else - g_assert_not_reached(); - - sendOrQueueEvent(event); - return JSValueMakeUndefined(context); -} - -static JSValueRef continuousMouseScrollByCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ -#if GTK_CHECK_VERSION(3, 3, 18) - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - if (!view) - return JSValueMakeUndefined(context); - - if (argumentCount < 2) - return JSValueMakeUndefined(context); - - int horizontal = JSValueToNumber(context, arguments[0], exception); - g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); - int vertical = JSValueToNumber(context, arguments[1], exception); - g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context)); - - // We do not yet support continuous scrolling by page. - if (argumentCount >= 3 && JSValueToBoolean(context, arguments[2])) - return JSValueMakeUndefined(context); - - GdkEvent* event = gdk_event_new(GDK_SCROLL); - event->scroll.x = lastMousePositionX; - event->scroll.y = lastMousePositionY; - event->scroll.time = GDK_CURRENT_TIME; - event->scroll.window = gtk_widget_get_window(GTK_WIDGET(view)); - g_object_ref(event->scroll.window); - - event->scroll.direction = GDK_SCROLL_SMOOTH; - event->scroll.delta_x = -horizontal / pixelsPerScrollTick; - event->scroll.delta_y = -vertical / pixelsPerScrollTick; - - sendOrQueueEvent(event); -#endif - return JSValueMakeUndefined(context); -} - -static void dragWithFilesDragDataGetCallback(GtkWidget*, GdkDragContext*, GtkSelectionData *data, guint, guint, gpointer userData) -{ - gtk_selection_data_set_uris(data, static_cast<gchar**>(userData)); -} - -static void dragWithFilesDragEndCallback(GtkWidget* widget, GdkDragContext*, gpointer userData) -{ - g_signal_handlers_disconnect_by_func(widget, reinterpret_cast<void*>(dragWithFilesDragEndCallback), userData); - g_signal_handlers_disconnect_by_func(widget, reinterpret_cast<void*>(dragWithFilesDragDataGetCallback), userData); - g_strfreev(static_cast<gchar**>(userData)); -} - -static JSValueRef beginDragWithFilesCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - if (argumentCount < 1) - return JSValueMakeUndefined(context); - - JSObjectRef filesArray = JSValueToObject(context, arguments[0], exception); - ASSERT(!exception || !*exception); - - const gchar* mainFrameURI = webkit_web_frame_get_uri(mainFrame); - GRefPtr<GFile> testFile(adoptGRef(g_file_new_for_uri(mainFrameURI))); - GRefPtr<GFile> parentDirectory(g_file_get_parent(testFile.get())); - if (!parentDirectory) - return JSValueMakeUndefined(context); - - // If this is an HTTP test, we still need to pass a local file path - // to WebCore. Even though the file doesn't exist, this should be fine - // for most tests. - GUniquePtr<gchar> scheme(g_file_get_uri_scheme(parentDirectory.get())); - if (g_str_equal(scheme.get(), "http") || g_str_equal(scheme.get(), "https")) { - GUniquePtr<gchar> currentDirectory(g_get_current_dir()); - parentDirectory = adoptGRef(g_file_new_for_path(currentDirectory.get())); - } - - JSStringRef lengthProperty = JSStringCreateWithUTF8CString("length"); - int filesArrayLength = JSValueToNumber(context, JSObjectGetProperty(context, filesArray, lengthProperty, 0), 0); - JSStringRelease(lengthProperty); - - gchar** draggedFilesURIList = g_new0(gchar*, filesArrayLength + 1); - for (int i = 0; i < filesArrayLength; ++i) { - JSStringRef filenameString = JSValueToStringCopy(context, - JSObjectGetPropertyAtIndex(context, filesArray, i, 0), 0); - size_t bufferSize = JSStringGetMaximumUTF8CStringSize(filenameString); - GUniquePtr<gchar> filenameBuffer(static_cast<gchar*>(g_malloc(bufferSize))); - JSStringGetUTF8CString(filenameString, filenameBuffer.get(), bufferSize); - JSStringRelease(filenameString); - - GRefPtr<GFile> dragFile(g_file_get_child(parentDirectory.get(), filenameBuffer.get())); - draggedFilesURIList[i] = g_file_get_uri(dragFile.get()); - } - - GtkWidget* view = GTK_WIDGET(webkit_web_frame_get_web_view(mainFrame)); - g_object_connect(G_OBJECT(view), - "signal::drag-end", dragWithFilesDragEndCallback, draggedFilesURIList, - "signal::drag-data-get", dragWithFilesDragDataGetCallback, draggedFilesURIList, - NULL); - - GdkEvent event; - GdkWindow* viewGDKWindow = gtk_widget_get_window(view); - memset(&event, 0, sizeof(event)); - event.type = GDK_MOTION_NOTIFY; - event.motion.x = lastMousePositionX; - event.motion.y = lastMousePositionY; - event.motion.time = GDK_CURRENT_TIME; - event.motion.window = viewGDKWindow; - event.motion.device = getDefaultGDKPointerDevice(viewGDKWindow); - event.motion.state = GDK_BUTTON1_MASK; - - int xRoot, yRoot; - gdk_window_get_root_coords(viewGDKWindow, lastMousePositionX, lastMousePositionY, &xRoot, &yRoot); - event.motion.x_root = xRoot; - event.motion.y_root = yRoot; - - GtkTargetList* targetList = gtk_target_list_new(0, 0); - gtk_target_list_add_uri_targets(targetList, 0); - gtk_drag_begin(view, targetList, GDK_ACTION_COPY, 1, &event); - gtk_target_list_unref(targetList); - - return JSValueMakeUndefined(context); -} - -static void sendOrQueueEvent(GdkEvent* event, bool shouldReplaySavedEvents) -{ - // Mouse move events are queued if the previous event was queued or if a - // delay was set up by leapForward(). - if ((dragMode && buttonCurrentlyDown) || endOfQueue != startOfQueue || msgQueue[endOfQueue].delay) { - msgQueue[endOfQueue++].event = event; - - if (shouldReplaySavedEvents) - replaySavedEvents(); - - return; - } - - dispatchEvent(event); -} - -static void dispatchEvent(GdkEvent* event) -{ - DumpRenderTreeSupportGtk::layoutFrame(mainFrame); - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - if (!view) { - gdk_event_free(event); - return; - } - - // The widget focus may have been lost in the course of the test, - // so force another explicit focus grab here. - gtk_widget_grab_focus(GTK_WIDGET(view)); - gtk_main_do_event(event); - - if (!currentDragSourceContext) { - gdk_event_free(event); - return; - } - - if (event->type == GDK_MOTION_NOTIFY) { - // WebKit has called gtk_drag_start(), but because the main loop isn't - // running GDK internals don't know that the drag has started yet. Pump - // the main loop a little bit so that GDK is in the correct state. - while (gtk_events_pending()) - gtk_main_iteration(); - - // Simulate a drag motion on the top-level GDK window. - GtkWidget* parentWidget = gtk_widget_get_parent(GTK_WIDGET(view)); - GdkWindow* parentWidgetWindow = gtk_widget_get_window(parentWidget); - gdk_drag_motion(currentDragSourceContext, parentWidgetWindow, GDK_DRAG_PROTO_XDND, - event->motion.x_root, event->motion.y_root, - gdk_drag_context_get_selected_action(currentDragSourceContext), - gdk_drag_context_get_actions(currentDragSourceContext), - GDK_CURRENT_TIME); - - } else if (currentDragSourceContext && event->type == GDK_BUTTON_RELEASE) { - // We've released the mouse button, we should just be able to spin the - // event loop here and have GTK+ send the appropriate notifications for - // the end of the drag. - while (gtk_events_pending()) - gtk_main_iteration(); - } - - gdk_event_free(event); -} - -void replaySavedEvents() -{ - // First send all the events that are ready to be sent - while (startOfQueue < endOfQueue) { - if (msgQueue[startOfQueue].delay) { - g_usleep(msgQueue[startOfQueue].delay * 1000); - msgQueue[startOfQueue].delay = 0; - } - - dispatchEvent(msgQueue[startOfQueue++].event); - } - - startOfQueue = 0; - endOfQueue = 0; -} - -static GdkEvent* createKeyPressEvent(JSContextRef context, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - g_return_val_if_fail(argumentCount >= 1, 0); - guint modifiers = argumentCount >= 2 ? gdkModifersFromJSValue(context, arguments[1]) : 0; - - // handle location argument. - int location = DOM_KEY_LOCATION_STANDARD; - if (argumentCount > 2) - location = (int)JSValueToNumber(context, arguments[2], exception); - - JSStringRef character = JSValueToStringCopy(context, arguments[0], exception); - g_return_val_if_fail((!exception || !*exception), 0); - - int gdkKeySym = GDK_VoidSymbol; - if (location == DOM_KEY_LOCATION_NUMPAD) { - if (JSStringIsEqualToUTF8CString(character, "leftArrow")) - gdkKeySym = GDK_KP_Left; - else if (JSStringIsEqualToUTF8CString(character, "rightArrow")) - gdkKeySym = GDK_KP_Right; - else if (JSStringIsEqualToUTF8CString(character, "upArrow")) - gdkKeySym = GDK_KP_Up; - else if (JSStringIsEqualToUTF8CString(character, "downArrow")) - gdkKeySym = GDK_KP_Down; - else if (JSStringIsEqualToUTF8CString(character, "pageUp")) - gdkKeySym = GDK_KP_Page_Up; - else if (JSStringIsEqualToUTF8CString(character, "pageDown")) - gdkKeySym = GDK_KP_Page_Down; - else if (JSStringIsEqualToUTF8CString(character, "home")) - gdkKeySym = GDK_KP_Home; - else if (JSStringIsEqualToUTF8CString(character, "end")) - gdkKeySym = GDK_KP_End; - else if (JSStringIsEqualToUTF8CString(character, "insert")) - gdkKeySym = GDK_KP_Insert; - else if (JSStringIsEqualToUTF8CString(character, "delete")) - gdkKeySym = GDK_KP_Delete; - else - // If we get some other key specified with the numpad location, - // crash here, so we add it sooner rather than later. - g_assert_not_reached(); - } else { - if (JSStringIsEqualToUTF8CString(character, "leftArrow")) - gdkKeySym = GDK_Left; - else if (JSStringIsEqualToUTF8CString(character, "rightArrow")) - gdkKeySym = GDK_Right; - else if (JSStringIsEqualToUTF8CString(character, "upArrow")) - gdkKeySym = GDK_Up; - else if (JSStringIsEqualToUTF8CString(character, "downArrow")) - gdkKeySym = GDK_Down; - else if (JSStringIsEqualToUTF8CString(character, "pageUp")) - gdkKeySym = GDK_Page_Up; - else if (JSStringIsEqualToUTF8CString(character, "pageDown")) - gdkKeySym = GDK_Page_Down; - else if (JSStringIsEqualToUTF8CString(character, "home")) - gdkKeySym = GDK_Home; - else if (JSStringIsEqualToUTF8CString(character, "end")) - gdkKeySym = GDK_End; - else if (JSStringIsEqualToUTF8CString(character, "insert")) - gdkKeySym = GDK_Insert; - else if (JSStringIsEqualToUTF8CString(character, "delete")) - gdkKeySym = GDK_Delete; - else if (JSStringIsEqualToUTF8CString(character, "printScreen")) - gdkKeySym = GDK_Print; - else if (JSStringIsEqualToUTF8CString(character, "menu")) - gdkKeySym = GDK_Menu; - else if (JSStringIsEqualToUTF8CString(character, "F1")) - gdkKeySym = GDK_F1; - else if (JSStringIsEqualToUTF8CString(character, "F2")) - gdkKeySym = GDK_F2; - else if (JSStringIsEqualToUTF8CString(character, "F3")) - gdkKeySym = GDK_F3; - else if (JSStringIsEqualToUTF8CString(character, "F4")) - gdkKeySym = GDK_F4; - else if (JSStringIsEqualToUTF8CString(character, "F5")) - gdkKeySym = GDK_F5; - else if (JSStringIsEqualToUTF8CString(character, "F6")) - gdkKeySym = GDK_F6; - else if (JSStringIsEqualToUTF8CString(character, "F7")) - gdkKeySym = GDK_F7; - else if (JSStringIsEqualToUTF8CString(character, "F8")) - gdkKeySym = GDK_F8; - else if (JSStringIsEqualToUTF8CString(character, "F9")) - gdkKeySym = GDK_F9; - else if (JSStringIsEqualToUTF8CString(character, "F10")) - gdkKeySym = GDK_F10; - else if (JSStringIsEqualToUTF8CString(character, "F11")) - gdkKeySym = GDK_F11; - else if (JSStringIsEqualToUTF8CString(character, "F12")) - gdkKeySym = GDK_F12; - else if (JSStringIsEqualToUTF8CString(character, "leftAlt")) - gdkKeySym = GDK_Alt_L; - else if (JSStringIsEqualToUTF8CString(character, "leftControl")) - gdkKeySym = GDK_Control_L; - else if (JSStringIsEqualToUTF8CString(character, "leftShift")) - gdkKeySym = GDK_Shift_L; - else if (JSStringIsEqualToUTF8CString(character, "rightAlt")) - gdkKeySym = GDK_Alt_R; - else if (JSStringIsEqualToUTF8CString(character, "rightControl")) - gdkKeySym = GDK_Control_R; - else if (JSStringIsEqualToUTF8CString(character, "rightShift")) - gdkKeySym = GDK_Shift_R; - else { - int charCode = JSStringGetCharactersPtr(character)[0]; - if (charCode == '\n' || charCode == '\r') - gdkKeySym = GDK_Return; - else if (charCode == '\t') - gdkKeySym = GDK_Tab; - else if (charCode == '\x8') - gdkKeySym = GDK_BackSpace; - else { - gdkKeySym = gdk_unicode_to_keyval(charCode); - if (WTF::isASCIIUpper(charCode)) - modifiers |= GDK_SHIFT_MASK; - } - } - } - JSStringRelease(character); - - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - g_return_val_if_fail(view, 0); - - GdkEvent* pressEvent = gdk_event_new(GDK_KEY_PRESS); - pressEvent->key.keyval = gdkKeySym; - pressEvent->key.state = modifiers; - pressEvent->key.window = gtk_widget_get_window(GTK_WIDGET(view)); - g_object_ref(pressEvent->key.window); -#ifndef GTK_API_VERSION_2 - gdk_event_set_device(pressEvent, getDefaultGDKPointerDevice(pressEvent->key.window)); -#endif - - // When synthesizing an event, an invalid hardware_keycode value - // can cause it to be badly processed by Gtk+. - GUniqueOutPtr<GdkKeymapKey> keys; - gint nKeys; - if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), gdkKeySym, &keys.outPtr(), &nKeys)) - pressEvent->key.hardware_keycode = keys.get()[0].keycode; - - return pressEvent; -} - -static void sendKeyDown(GdkEvent* pressEvent) -{ - g_return_if_fail(pressEvent); - GdkEvent* releaseEvent = gdk_event_copy(pressEvent); - releaseEvent->type = GDK_KEY_RELEASE; - - dispatchEvent(pressEvent); - dispatchEvent(releaseEvent); - - DumpRenderTreeSupportGtk::deliverAllMutationsIfNecessary(); -} - -static JSValueRef keyDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - GdkEvent* pressEvent = createKeyPressEvent(context, argumentCount, arguments, exception); - sendKeyDown(pressEvent); - - return JSValueMakeUndefined(context); -} - -static void zoomIn(gboolean fullContentsZoom) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - if (!view) - return; - - webkit_web_view_set_full_content_zoom(view, fullContentsZoom); - gfloat currentZoom = webkit_web_view_get_zoom_level(view); - webkit_web_view_set_zoom_level(view, currentZoom * zoomMultiplierRatio); -} - -static void zoomOut(gboolean fullContentsZoom) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - if (!view) - return; - - webkit_web_view_set_full_content_zoom(view, fullContentsZoom); - gfloat currentZoom = webkit_web_view_get_zoom_level(view); - webkit_web_view_set_zoom_level(view, currentZoom / zoomMultiplierRatio); -} - -static JSValueRef textZoomInCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - zoomIn(FALSE); - return JSValueMakeUndefined(context); -} - -static JSValueRef textZoomOutCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - zoomOut(FALSE); - return JSValueMakeUndefined(context); -} - -static JSValueRef zoomPageInCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - zoomIn(TRUE); - return JSValueMakeUndefined(context); -} - -static JSValueRef zoomPageOutCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - zoomOut(TRUE); - return JSValueMakeUndefined(context); -} - -static JSValueRef scalePageByCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - if (argumentCount < 3) - return JSValueMakeUndefined(context); - - float scaleFactor = JSValueToNumber(context, arguments[0], exception); - float x = JSValueToNumber(context, arguments[1], exception); - float y = JSValueToNumber(context, arguments[2], exception); - - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - if (!view) - return JSValueMakeUndefined(context); - - DumpRenderTreeSupportGtk::scalePageBy(view, scaleFactor, x, y); - - return JSValueMakeUndefined(context); -} - -static gboolean sendAsynchronousKeyDown(gpointer userData) -{ - sendKeyDown(static_cast<GdkEvent*>(userData)); - return FALSE; -} - -static JSValueRef scheduleAsynchronousKeyDownCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - GdkEvent* pressEvent = createKeyPressEvent(context, argumentCount, arguments, exception); - if (pressEvent) - g_idle_add_full(G_PRIORITY_DEFAULT, sendAsynchronousKeyDown, static_cast<gpointer>(pressEvent), 0); - - return JSValueMakeUndefined(context); -} - -static JSValueRef clearTouchPointsCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - return JSValueMakeUndefined(context); -} - -static JSStaticFunction staticFunctions[] = { - { "mouseScrollBy", mouseScrollByCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "continuousMouseScrollBy", continuousMouseScrollByCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "contextClick", contextClickCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "mouseDown", mouseDownCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "mouseUp", mouseUpCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "mouseMoveTo", mouseMoveToCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "beginDragWithFiles", beginDragWithFilesCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "leapForward", leapForwardCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "keyDown", keyDownCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "textZoomIn", textZoomInCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "textZoomOut", textZoomOutCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "zoomPageIn", zoomPageInCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "zoomPageOut", zoomPageOutCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "scheduleAsynchronousClick", scheduleAsynchronousClickCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "scalePageBy", scalePageByCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "scheduleAsynchronousKeyDown", scheduleAsynchronousKeyDownCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - - { 0, 0, 0 } -}; - -static JSStaticValue staticValues[] = { - { "dragMode", getDragModeCallback, setDragModeCallback, kJSPropertyAttributeNone }, - { 0, 0, 0, 0 } -}; - -static JSClassRef getClass(JSContextRef context) -{ - static JSClassRef eventSenderClass = 0; - - if (!eventSenderClass) { - JSClassDefinition classDefinition = { - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - classDefinition.staticFunctions = staticFunctions; - classDefinition.staticValues = staticValues; - - eventSenderClass = JSClassCreate(&classDefinition); - } - - return eventSenderClass; -} - -JSObjectRef makeEventSender(JSContextRef context, bool isTopFrame) -{ - if (isTopFrame) { - dragMode = true; - - // Fly forward in time one second when the main frame loads. This will - // ensure that when a test begins clicking in the same location as - // a previous test, those clicks won't be interpreted as continuations - // of the previous test's click sequences. - timeOffset += 1000; - - lastMousePositionX = lastMousePositionY = 0; - lastClickPositionX = lastClickPositionY = 0; - lastClickTimeOffset = 0; - lastClickButton = 0; - buttonCurrentlyDown = 0; - clickCount = 0; - - endOfQueue = 0; - startOfQueue = 0; - - currentDragSourceContext = 0; - } - - return JSObjectMake(context, getClass(context), 0); -} - -void dragBeginCallback(GtkWidget*, GdkDragContext* context, gpointer) -{ - currentDragSourceContext = context; -} - -void dragEndCallback(GtkWidget*, GdkDragContext* context, gpointer) -{ - currentDragSourceContext = 0; -} - -gboolean dragFailedCallback(GtkWidget*, GdkDragContext* context, gpointer) -{ - // Return TRUE here to disable the stupid GTK+ drag failed animation, - // which introduces asynchronous behavior into our drags. - return TRUE; -} diff --git a/Tools/DumpRenderTree/gtk/EventSender.h b/Tools/DumpRenderTree/gtk/EventSender.h deleted file mode 100644 index f440f0d3d..000000000 --- a/Tools/DumpRenderTree/gtk/EventSender.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2007 Apple Inc. All rights reserved. - * Copyright (C) 2009 Holger Hans Peter Freyther - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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. - */ - -#ifndef EventSender_h -#define EventSender_h - -typedef const struct OpaqueJSContext* JSContextRef; -typedef struct OpaqueJSValue* JSObjectRef; - -JSObjectRef makeEventSender(JSContextRef context, bool isTopFrame); -void replaySavedEvents(); -void dragBeginCallback(GtkWidget*, GdkDragContext*, gpointer); -void dragEndCallback(GtkWidget*, GdkDragContext*, gpointer); -gboolean dragFailedCallback(GtkWidget*, GdkDragContext*, gpointer); - -#endif diff --git a/Tools/DumpRenderTree/gtk/GCControllerGtk.cpp b/Tools/DumpRenderTree/gtk/GCControllerGtk.cpp deleted file mode 100644 index 4eb5d6ec9..000000000 --- a/Tools/DumpRenderTree/gtk/GCControllerGtk.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2007 Eric Seidel <eric@webkit.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "GCController.h" - -#include "WebCoreSupport/DumpRenderTreeSupportGtk.h" - -#include <glib.h> -#include <webkit/webkit.h> - -void GCController::collect() const -{ - DumpRenderTreeSupportGtk::gcCollectJavascriptObjects(); -} - -void GCController::collectOnAlternateThread(bool waitUntilDone) const -{ - DumpRenderTreeSupportGtk::gcCollectJavascriptObjectsOnAlternateThread(waitUntilDone); -} - -size_t GCController::getJSObjectCount() const -{ - return DumpRenderTreeSupportGtk::gcCountJavascriptObjects(); -} diff --git a/Tools/DumpRenderTree/gtk/PixelDumpSupportGtk.cpp b/Tools/DumpRenderTree/gtk/PixelDumpSupportGtk.cpp deleted file mode 100644 index 0a800ec13..000000000 --- a/Tools/DumpRenderTree/gtk/PixelDumpSupportGtk.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2009 Zan Dobersek <zandobersek@gmail.com> - * Copyright (C) 2010 Igalia S.L. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "DumpRenderTree.h" -#include "GtkVersioning.h" -#include "PixelDumpSupportCairo.h" -#include "WebCoreSupport/DumpRenderTreeSupportGtk.h" -#include <webkit/webkit.h> - -static void paintOverlay(cairo_surface_t* surface) -{ - cairo_t* context = cairo_create(surface); - - // Paint a transparent black overlay from which the repainted rectangles are then cleared. - // The alpha component of the overlay should have a value of 0.66, as on other ports. - cairo_set_source_rgba(context, 0.0, 0.0, 0.0, 0.66); - cairo_rectangle(context, 0, 0, cairo_image_surface_get_width(surface), cairo_image_surface_get_height(surface)); - cairo_fill(context); - - GSList* trackedRectsList = DumpRenderTreeSupportGtk::trackedRepaintRects(mainFrame); - for (GSList* listElement = trackedRectsList; listElement; listElement = g_slist_next(listElement)) { - GdkRectangle* rect = static_cast<GdkRectangle*>(listElement->data); - - cairo_set_operator(context, CAIRO_OPERATOR_CLEAR); - cairo_rectangle(context, rect->x, rect->y, rect->width, rect->height); - cairo_fill(context); - } - - g_slist_free_full(trackedRectsList, g_free); - cairo_destroy(context); -} - -static void fillRepaintOverlayIntoContext(cairo_t* context, gint width, gint height) -{ - cairo_surface_t* overlaySurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); - paintOverlay(overlaySurface); - - cairo_set_source_surface(context, overlaySurface, 0, 0); - cairo_rectangle(context, 0, 0, width, height); - cairo_fill(context); - - cairo_surface_destroy(overlaySurface); -} - -PassRefPtr<BitmapContext> createBitmapContextFromWebView(bool, bool, bool, bool drawSelectionRect) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - GtkWidget* viewContainer = gtk_widget_get_parent(GTK_WIDGET(view)); - gint width, height; -#ifdef GTK_API_VERSION_2 - GdkPixmap* pixmap = gtk_widget_get_snapshot(viewContainer, 0); - gdk_pixmap_get_size(pixmap, &width, &height); -#else - width = gtk_widget_get_allocated_width(viewContainer); - height = gtk_widget_get_allocated_height(viewContainer); -#endif - - while (gtk_events_pending()) - gtk_main_iteration(); - - cairo_surface_t* imageSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); - cairo_t* context = cairo_create(imageSurface); - -#ifdef GTK_API_VERSION_2 - gdk_cairo_set_source_pixmap(context, pixmap, 0, 0); - cairo_paint(context); - g_object_unref(pixmap); -#else - gtk_widget_draw(viewContainer, context); -#endif - - if (DumpRenderTreeSupportGtk::isTrackingRepaints(mainFrame)) - fillRepaintOverlayIntoContext(context, width, height); - - if (drawSelectionRect) { - cairo_rectangle_int_t rectangle; - DumpRenderTreeSupportGtk::rectangleForSelection(mainFrame, &rectangle); - - cairo_set_line_width(context, 1.0); - cairo_rectangle(context, rectangle.x, rectangle.y, rectangle.width, rectangle.height); - cairo_set_source_rgba(context, 1.0, 0.0, 0.0, 1.0); - cairo_stroke(context); - } - - cairo_surface_destroy(imageSurface); - return BitmapContext::createByAdoptingBitmapAndContext(0, context); -} diff --git a/Tools/DumpRenderTree/gtk/SelfScrollingWebKitWebView.cpp b/Tools/DumpRenderTree/gtk/SelfScrollingWebKitWebView.cpp deleted file mode 100644 index d77cfd5f1..000000000 --- a/Tools/DumpRenderTree/gtk/SelfScrollingWebKitWebView.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2011 Igalia S.L. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "SelfScrollingWebKitWebView.h" - -#include <webkit/webkit.h> - -G_BEGIN_DECLS - -#ifdef GTK_API_VERSION_2 -static void sizeRequestMethod(GtkWidget*, GtkRequisition*); -#else -static void getPreferredSizeMethod(GtkWidget*, gint* minimum, gint* natural); -#endif - -G_DEFINE_TYPE(SelfScrollingWebKitWebView, self_scrolling_webkit_web_view, WEBKIT_TYPE_WEB_VIEW) - -static void self_scrolling_webkit_web_view_class_init(SelfScrollingWebKitWebViewClass* klass) -{ - GtkWidgetClass* widgetClass = GTK_WIDGET_CLASS(klass); -#ifdef GTK_API_VERSION_2 - widgetClass->size_request = sizeRequestMethod; -#else - widgetClass->get_preferred_width = getPreferredSizeMethod; - widgetClass->get_preferred_height = getPreferredSizeMethod; -#endif -} - -static void self_scrolling_webkit_web_view_init(SelfScrollingWebKitWebView* webView) -{ -} - -GtkWidget* self_scrolling_webkit_web_view_new() -{ - return GTK_WIDGET(g_object_new(self_scrolling_webkit_web_view_get_type(), "self-scrolling", TRUE, NULL)); -} - -#ifdef GTK_API_VERSION_2 -static void sizeRequestMethod(GtkWidget*, GtkRequisition* requisition) -{ - requisition->width = 1; - requisition->height = 1; -} -#else -static void getPreferredSizeMethod(GtkWidget*, gint* minimum, gint* natural) -{ - *minimum = 1; - *natural = 1; -} -#endif - -G_END_DECLS diff --git a/Tools/DumpRenderTree/gtk/SelfScrollingWebKitWebView.h b/Tools/DumpRenderTree/gtk/SelfScrollingWebKitWebView.h deleted file mode 100644 index 648d38c97..000000000 --- a/Tools/DumpRenderTree/gtk/SelfScrollingWebKitWebView.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2011 Igalia S.L. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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. - */ - -#ifndef SelfScrollingWebKitWebView_h -#define SelfScrollingWebKitWebView_h - -#include <webkit/webkit.h> - -G_BEGIN_DECLS - -typedef struct _SelfScrollingWebKitWebView SelfScrollingWebKitWebView; -typedef struct _SelfScrollingWebKitWebViewClass SelfScrollingWebKitWebViewClass; - -struct _SelfScrollingWebKitWebView { - WebKitWebView web_view; -}; - -struct _SelfScrollingWebKitWebViewClass { - WebKitWebViewClass parent_class; -}; - -GtkWidget* self_scrolling_webkit_web_view_new(); - -G_END_DECLS - -#endif // SelfScrollingWebKitWebView_h diff --git a/Tools/DumpRenderTree/gtk/TestRunnerGtk.cpp b/Tools/DumpRenderTree/gtk/TestRunnerGtk.cpp deleted file mode 100644 index c0b2deca2..000000000 --- a/Tools/DumpRenderTree/gtk/TestRunnerGtk.cpp +++ /dev/null @@ -1,914 +0,0 @@ -/* - * Copyright (C) 2007, 2012 Apple Inc. All rights reserved. - * Copyright (C) 2007 Eric Seidel <eric@webkit.org> - * Copyright (C) 2008 Nuanti Ltd. - * Copyright (C) 2009 Jan Michael Alonzo <jmalonzo@gmail.com> - * Copyright (C) 2009,2011 Collabora Ltd. - * Copyright (C) 2010 Joone Hur <joone@kldp.org> - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "TestRunner.h" - -#include "DumpRenderTree.h" -#include "WebCoreSupport/DumpRenderTreeSupportGtk.h" -#include "WorkQueue.h" -#include "WorkQueueItem.h" -#include <JavaScriptCore/JSRetainPtr.h> -#include <JavaScriptCore/JSStringRef.h> -#include <cstring> -#include <iostream> -#include <sstream> -#include <stdio.h> -#include <glib.h> -#include <libsoup/soup.h> -#include <webkit/webkit.h> -#include <wtf/gobject/GUniquePtr.h> -#include <wtf/text/WTFString.h> - -extern "C" { -void webkit_web_inspector_execute_script(WebKitWebInspector* inspector, long callId, const gchar* script); -} - -TestRunner::~TestRunner() -{ - // FIXME: implement -} - -void TestRunner::addDisallowedURL(JSStringRef url) -{ - // FIXME: implement -} - -void TestRunner::clearBackForwardList() -{ - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - WebKitWebBackForwardList* list = webkit_web_view_get_back_forward_list(webView); - WebKitWebHistoryItem* item = webkit_web_back_forward_list_get_current_item(list); - g_object_ref(item); - - // We clear the history by setting the back/forward list's capacity to 0 - // then restoring it back and adding back the current item. - gint limit = webkit_web_back_forward_list_get_limit(list); - webkit_web_back_forward_list_set_limit(list, 0); - webkit_web_back_forward_list_set_limit(list, limit); - webkit_web_back_forward_list_add_item(list, item); - webkit_web_back_forward_list_go_to_item(list, item); - g_object_unref(item); -} - -JSStringRef TestRunner::copyDecodedHostName(JSStringRef name) -{ - // FIXME: implement - return 0; -} - -JSStringRef TestRunner::copyEncodedHostName(JSStringRef name) -{ - // FIXME: implement - return 0; -} - -void TestRunner::dispatchPendingLoadRequests() -{ - // FIXME: Implement for testing fix for 6727495 -} - -void TestRunner::display() -{ - displayWebView(); -} - -void TestRunner::keepWebHistory() -{ - // FIXME: implement -} - -size_t TestRunner::webHistoryItemCount() -{ - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - WebKitWebBackForwardList* list = webkit_web_view_get_back_forward_list(webView); - - if (!list) - return -1; - - // We do not add the current page to the total count as it's not - // considered in DRT tests - return webkit_web_back_forward_list_get_back_length(list) + - webkit_web_back_forward_list_get_forward_length(list); -} - -void TestRunner::notifyDone() -{ - if (m_waitToDump && !topLoadingFrame && !WorkQueue::shared()->count()) - dump(); - m_waitToDump = false; - waitForPolicy = false; -} - -JSStringRef TestRunner::pathToLocalResource(JSContextRef context, JSStringRef url) -{ - GUniquePtr<char> urlCString(JSStringCopyUTF8CString(url)); - if (!g_str_has_prefix(urlCString.get(), "file:///tmp/LayoutTests/")) - return JSStringRetain(url); - - const char* layoutTestsSuffix = urlCString.get() + strlen("file:///tmp/"); - GUniquePtr<char> testPath(g_build_filename(getTopLevelPath().data(), layoutTestsSuffix, nullptr)); - GUniquePtr<char> testURI(g_filename_to_uri(testPath.get(), 0, 0)); - return JSStringCreateWithUTF8CString(testURI.get()); -} - -void TestRunner::queueLoad(JSStringRef url, JSStringRef target) -{ - GUniquePtr<gchar> relativeURL(JSStringCopyUTF8CString(url)); - SoupURI* baseURI = soup_uri_new(webkit_web_frame_get_uri(mainFrame)); - SoupURI* absoluteURI = soup_uri_new_with_base(baseURI, relativeURL.get()); - soup_uri_free(baseURI); - - if (!absoluteURI) { - WorkQueue::shared()->queue(new LoadItem(url, target)); - return; - } - - CString absoluteURIString = soupURIToStringPreservingPassword(absoluteURI); - JSRetainPtr<JSStringRef> absoluteURL(Adopt, JSStringCreateWithUTF8CString(absoluteURIString.data())); - WorkQueue::shared()->queue(new LoadItem(absoluteURL.get(), target)); - soup_uri_free(absoluteURI); -} - -void TestRunner::setAcceptsEditing(bool acceptsEditing) -{ - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - webkit_web_view_set_editable(webView, acceptsEditing); -} - -void TestRunner::setAlwaysAcceptCookies(bool alwaysAcceptCookies) -{ - SoupSession* session = webkit_get_default_session(); - SoupCookieJar* jar = reinterpret_cast<SoupCookieJar*>(soup_session_get_feature(session, SOUP_TYPE_COOKIE_JAR)); - - /* If the jar was not created - we create it on demand, i.e, just - in case we have HTTP requests - then we must create it here in - order to set the proper accept policy */ - if (!jar) { - jar = soup_cookie_jar_new(); - soup_session_add_feature(session, SOUP_SESSION_FEATURE(jar)); - g_object_unref(jar); - } - - SoupCookieJarAcceptPolicy policy; - - if (alwaysAcceptCookies) - policy = SOUP_COOKIE_JAR_ACCEPT_ALWAYS; - else - policy = SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY; - - g_object_set(G_OBJECT(jar), SOUP_COOKIE_JAR_ACCEPT_POLICY, policy, NULL); -} - -void TestRunner::setCustomPolicyDelegate(bool setDelegate, bool permissive) -{ - // FIXME: implement -} - -void TestRunner::waitForPolicyDelegate() -{ - waitForPolicy = true; - setWaitToDump(true); -} - -void TestRunner::setScrollbarPolicy(JSStringRef orientation, JSStringRef policy) -{ - // FIXME: implement -} - -void TestRunner::addOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef protocol, JSStringRef host, bool includeSubdomains) -{ - gchar* sourceOriginGChar = JSStringCopyUTF8CString(sourceOrigin); - gchar* protocolGChar = JSStringCopyUTF8CString(protocol); - gchar* hostGChar = JSStringCopyUTF8CString(host); - DumpRenderTreeSupportGtk::whiteListAccessFromOrigin(sourceOriginGChar, protocolGChar, hostGChar, includeSubdomains); - g_free(sourceOriginGChar); - g_free(protocolGChar); - g_free(hostGChar); -} - -void TestRunner::removeOriginAccessWhitelistEntry(JSStringRef sourceOrigin, JSStringRef protocol, JSStringRef host, bool includeSubdomains) -{ - GUniquePtr<gchar> sourceOriginGChar(JSStringCopyUTF8CString(sourceOrigin)); - GUniquePtr<gchar> protocolGChar(JSStringCopyUTF8CString(protocol)); - GUniquePtr<gchar> hostGChar(JSStringCopyUTF8CString(host)); - DumpRenderTreeSupportGtk::removeWhiteListAccessFromOrigin(sourceOriginGChar.get(), protocolGChar.get(), hostGChar.get(), includeSubdomains); -} - -void TestRunner::setMainFrameIsFirstResponder(bool flag) -{ - // FIXME: implement -} - -void TestRunner::setTabKeyCyclesThroughElements(bool cycles) -{ - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - WebKitWebSettings* settings = webkit_web_view_get_settings(webView); - g_object_set(G_OBJECT(settings), "tab-key-cycles-through-elements", cycles, NULL); -} - -void TestRunner::setUseDashboardCompatibilityMode(bool flag) -{ - // FIXME: implement -} - -static gchar* userStyleSheet = NULL; -static gboolean userStyleSheetEnabled = TRUE; - -void TestRunner::setUserStyleSheetEnabled(bool flag) -{ - userStyleSheetEnabled = flag; - - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - WebKitWebSettings* settings = webkit_web_view_get_settings(webView); - if (flag && userStyleSheet) - g_object_set(G_OBJECT(settings), "user-stylesheet-uri", userStyleSheet, NULL); - else - g_object_set(G_OBJECT(settings), "user-stylesheet-uri", "", NULL); -} - -void TestRunner::setUserStyleSheetLocation(JSStringRef path) -{ - g_free(userStyleSheet); - userStyleSheet = JSStringCopyUTF8CString(path); - if (userStyleSheetEnabled) - setUserStyleSheetEnabled(true); -} - -void TestRunner::setValueForUser(JSContextRef context, JSValueRef nodeObject, JSStringRef value) -{ - DumpRenderTreeSupportGtk::setValueForUser(context, nodeObject, value); -} - -void TestRunner::setViewModeMediaFeature(JSStringRef mode) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - char* viewMode = JSStringCopyUTF8CString(mode); - - if (!g_strcmp0(viewMode, "windowed")) - webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_WINDOWED); - else if (!g_strcmp0(viewMode, "floating")) - webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_FLOATING); - else if (!g_strcmp0(viewMode, "fullscreen")) - webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_FULLSCREEN); - else if (!g_strcmp0(viewMode, "maximized")) - webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_MAXIMIZED); - else if (!g_strcmp0(viewMode, "minimized")) - webkit_web_view_set_view_mode(view, WEBKIT_WEB_VIEW_VIEW_MODE_MINIMIZED); - - g_free(viewMode); -} - -void TestRunner::setWindowIsKey(bool windowIsKey) -{ - // FIXME: implement -} - -static gboolean waitToDumpWatchdogFired(void*) -{ - setWaitToDumpWatchdog(0); - gTestRunner->waitToDumpWatchdogTimerFired(); - return FALSE; -} - -void TestRunner::setWaitToDump(bool waitUntilDone) -{ - static const int timeoutSeconds = 30; - - m_waitToDump = waitUntilDone; - if (m_waitToDump && shouldSetWaitToDumpWatchdog()) { - guint id = g_timeout_add_seconds(timeoutSeconds, waitToDumpWatchdogFired, 0); - g_source_set_name_by_id(id, "[WebKit] waitToDumpWatchdogFired"); - setWaitToDumpWatchdog(id); - } -} - -int TestRunner::windowCount() -{ - // +1 -> including the main view - return g_slist_length(webViewList) + 1; -} - -void TestRunner::setPrivateBrowsingEnabled(bool flag) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - WebKitWebSettings* settings = webkit_web_view_get_settings(view); - g_object_set(G_OBJECT(settings), "enable-private-browsing", flag, NULL); -} - -void TestRunner::setJavaScriptCanAccessClipboard(bool flag) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - WebKitWebSettings* settings = webkit_web_view_get_settings(view); - g_object_set(G_OBJECT(settings), "javascript-can-access-clipboard", flag, NULL); -} - -void TestRunner::setXSSAuditorEnabled(bool flag) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - WebKitWebSettings* settings = webkit_web_view_get_settings(view); - g_object_set(G_OBJECT(settings), "enable-xss-auditor", flag, NULL); -} - -void TestRunner::setSpatialNavigationEnabled(bool flag) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - WebKitWebSettings* settings = webkit_web_view_get_settings(view); - g_object_set(G_OBJECT(settings), "enable-spatial-navigation", flag, NULL); -} - -void TestRunner::setAllowUniversalAccessFromFileURLs(bool flag) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - WebKitWebSettings* settings = webkit_web_view_get_settings(view); - g_object_set(G_OBJECT(settings), "enable-universal-access-from-file-uris", flag, NULL); -} - -void TestRunner::setAllowFileAccessFromFileURLs(bool flag) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - WebKitWebSettings* settings = webkit_web_view_get_settings(view); - g_object_set(G_OBJECT(settings), "enable-file-access-from-file-uris", flag, NULL); -} - -void TestRunner::setAuthorAndUserStylesEnabled(bool flag) -{ - // FIXME: implement -} - -void TestRunner::setMockDeviceOrientation(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma) -{ - // FIXME: Implement for DeviceOrientation layout tests. - // See https://bugs.webkit.org/show_bug.cgi?id=30335. -} - -void TestRunner::setMockGeolocationPosition(double latitude, double longitude, double accuracy, bool, double, bool, double, bool, double, bool, double) -{ - WebKitWebView* view = WEBKIT_WEB_VIEW(g_slist_nth_data(webViewList, 0)); - if (!view) - view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - DumpRenderTreeSupportGtk::setMockGeolocationPosition(view, latitude, longitude, accuracy); -} - -void TestRunner::setMockGeolocationPositionUnavailableError(JSStringRef message) -{ - WebKitWebView* view = WEBKIT_WEB_VIEW(g_slist_nth_data(webViewList, 0)); - if (!view) - view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - GUniquePtr<gchar> cMessage(JSStringCopyUTF8CString(message)); - DumpRenderTreeSupportGtk::setMockGeolocationPositionUnavailableError(view, cMessage.get()); -} - -void TestRunner::setGeolocationPermission(bool allow) -{ - setGeolocationPermissionCommon(allow); - WebKitWebView* view = WEBKIT_WEB_VIEW(g_slist_nth_data(webViewList, 0)); - if (!view) - view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - DumpRenderTreeSupportGtk::setMockGeolocationPermission(view, allow); -} - -int TestRunner::numberOfPendingGeolocationPermissionRequests() -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - if (!view) - view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - return DumpRenderTreeSupportGtk::numberOfPendingGeolocationPermissionRequests(view); -} - -void TestRunner::addMockSpeechInputResult(JSStringRef result, double confidence, JSStringRef language) -{ - // FIXME: Implement for speech input layout tests. - // See https://bugs.webkit.org/show_bug.cgi?id=39485. -} - -void TestRunner::setMockSpeechInputDumpRect(bool flag) -{ - // FIXME: Implement for speech input layout tests. - // See https://bugs.webkit.org/show_bug.cgi?id=39485. -} - -void TestRunner::startSpeechInput(JSContextRef inputElement) -{ - // FIXME: Implement for speech input layout tests. - // See https://bugs.webkit.org/show_bug.cgi?id=39485. -} - -void TestRunner::setIconDatabaseEnabled(bool enabled) -{ - WebKitIconDatabase* database = webkit_get_icon_database(); - if (enabled) { - GUniquePtr<gchar> iconDatabasePath(g_build_filename(g_get_tmp_dir(), "DumpRenderTree", "icondatabase", nullptr)); - webkit_icon_database_set_path(database, iconDatabasePath.get()); - } else - webkit_icon_database_set_path(database, 0); -} - -void TestRunner::setPopupBlockingEnabled(bool flag) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - WebKitWebSettings* settings = webkit_web_view_get_settings(view); - g_object_set(G_OBJECT(settings), "javascript-can-open-windows-automatically", !flag, NULL); - -} - -void TestRunner::setPluginsEnabled(bool flag) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - WebKitWebSettings* settings = webkit_web_view_get_settings(view); - g_object_set(G_OBJECT(settings), "enable-plugins", flag, NULL); -} - -void TestRunner::execCommand(JSStringRef name, JSStringRef value) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - gchar* cName = JSStringCopyUTF8CString(name); - gchar* cValue = JSStringCopyUTF8CString(value); - DumpRenderTreeSupportGtk::executeCoreCommandByName(view, cName, cValue); - g_free(cName); - g_free(cValue); -} - -bool TestRunner::findString(JSContextRef context, JSStringRef target, JSObjectRef optionsArray) -{ - WebKitFindOptions findOptions = 0; - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - ASSERT(webView); - - JSRetainPtr<JSStringRef> lengthPropertyName(Adopt, JSStringCreateWithUTF8CString("length")); - JSValueRef lengthValue = JSObjectGetProperty(context, optionsArray, lengthPropertyName.get(), 0); - if (!JSValueIsNumber(context, lengthValue)) - return false; - - GUniquePtr<gchar> targetString(JSStringCopyUTF8CString(target)); - - size_t length = static_cast<size_t>(JSValueToNumber(context, lengthValue, 0)); - for (size_t i = 0; i < length; ++i) { - JSValueRef value = JSObjectGetPropertyAtIndex(context, optionsArray, i, 0); - if (!JSValueIsString(context, value)) - continue; - - JSRetainPtr<JSStringRef> optionName(Adopt, JSValueToStringCopy(context, value, 0)); - - if (JSStringIsEqualToUTF8CString(optionName.get(), "CaseInsensitive")) - findOptions |= WebKit::WebFindOptionsCaseInsensitive; - else if (JSStringIsEqualToUTF8CString(optionName.get(), "AtWordStarts")) - findOptions |= WebKit::WebFindOptionsAtWordStarts; - else if (JSStringIsEqualToUTF8CString(optionName.get(), "TreatMedialCapitalAsWordStart")) - findOptions |= WebKit::WebFindOptionsTreatMedialCapitalAsWordStart; - else if (JSStringIsEqualToUTF8CString(optionName.get(), "Backwards")) - findOptions |= WebKit::WebFindOptionsBackwards; - else if (JSStringIsEqualToUTF8CString(optionName.get(), "WrapAround")) - findOptions |= WebKit::WebFindOptionsWrapAround; - else if (JSStringIsEqualToUTF8CString(optionName.get(), "StartInSelection")) - findOptions |= WebKit::WebFindOptionsStartInSelection; - } - - return DumpRenderTreeSupportGtk::findString(webView, targetString.get(), findOptions); -} - -bool TestRunner::isCommandEnabled(JSStringRef name) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - gchar* cName = JSStringCopyUTF8CString(name); - bool result = DumpRenderTreeSupportGtk::isCommandEnabled(view, cName); - g_free(cName); - return result; -} - -void TestRunner::setCacheModel(int cacheModel) -{ - // These constants are derived from the Mac cache model enum in Source/WebKit/mac/WebView/WebPreferences.h. - switch (cacheModel) { - case 0: - webkit_set_cache_model(WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER); - break; - case 1: - webkit_set_cache_model(WEBKIT_CACHE_MODEL_DOCUMENT_BROWSER); - break; - case 2: - webkit_set_cache_model(WEBKIT_CACHE_MODEL_WEB_BROWSER); - break; - default: - ASSERT_NOT_REACHED(); - } -} - -void TestRunner::setPersistentUserStyleSheetLocation(JSStringRef jsURL) -{ - // FIXME: implement -} - -void TestRunner::clearPersistentUserStyleSheet() -{ - // FIXME: implement -} - -void TestRunner::clearAllApplicationCaches() -{ - // FIXME: Implement to support application cache quotas. -} - -void TestRunner::clearApplicationCacheForOrigin(OpaqueJSString*) -{ - // FIXME: Implement to support deleting all application caches for an origin. -} - -long long TestRunner::localStorageDiskUsageForOrigin(JSStringRef originIdentifier) -{ - // FIXME: Implement to support getting disk usage in bytes for an origin. - return 0; -} - -JSValueRef TestRunner::originsWithApplicationCache(JSContextRef context) -{ - // FIXME: Implement to get origins that contain application caches. - return JSValueMakeUndefined(context); -} - -long long TestRunner::applicationCacheDiskUsageForOrigin(JSStringRef name) -{ - // FIXME: implement - return 0; -} - -void TestRunner::clearAllDatabases() -{ - webkit_remove_all_web_databases(); -} - -void TestRunner::setDatabaseQuota(unsigned long long quota) -{ - WebKitSecurityOrigin* origin = webkit_web_frame_get_security_origin(mainFrame); - webkit_security_origin_set_web_database_quota(origin, quota); -} - -JSValueRef TestRunner::originsWithLocalStorage(JSContextRef context) -{ - // FIXME: implement - return JSValueMakeUndefined(context); -} - -void TestRunner::deleteAllLocalStorage() -{ - // FIXME: implement -} - -void TestRunner::deleteLocalStorageForOrigin(JSStringRef originIdentifier) -{ - // FIXME: implement -} - -void TestRunner::observeStorageTrackerNotifications(unsigned number) -{ - // FIXME: implement -} - -void TestRunner::syncLocalStorage() -{ - // FIXME: implement -} - -void TestRunner::setDomainRelaxationForbiddenForURLScheme(bool forbidden, JSStringRef scheme) -{ - GUniquePtr<gchar> urlScheme(JSStringCopyUTF8CString(scheme)); - DumpRenderTreeSupportGtk::setDomainRelaxationForbiddenForURLScheme(forbidden, urlScheme.get()); -} - -void TestRunner::goBack() -{ - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - webkit_web_view_go_back(webView); -} - -void TestRunner::setDefersLoading(bool defers) -{ - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - DumpRenderTreeSupportGtk::setDefersLoading(webView, defers); -} - -void TestRunner::setAppCacheMaximumSize(unsigned long long size) -{ - webkit_application_cache_set_maximum_size(size); -} - -static gboolean booleanFromValue(gchar* value) -{ - return !g_ascii_strcasecmp(value, "true") || !g_ascii_strcasecmp(value, "1"); -} - -void TestRunner::overridePreference(JSStringRef key, JSStringRef value) -{ - GUniquePtr<gchar> originalName(JSStringCopyUTF8CString(key)); - GUniquePtr<gchar> valueAsString(JSStringCopyUTF8CString(value)); - - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - // This transformation could be handled by a hash table (and it once was), but - // having it prominent, makes it easier for people from other ports to keep the - // list up to date. - const gchar* propertyName = 0; - if (g_str_equal(originalName.get(), "WebKitJavaScriptEnabled")) - propertyName = "enable-scripts"; - else if (g_str_equal(originalName.get(), "WebKitDefaultFontSize")) - propertyName = "default-font-size"; - else if (g_str_equal(originalName.get(), "WebKitEnableCaretBrowsing")) - propertyName = "enable-caret-browsing"; - else if (g_str_equal(originalName.get(), "WebKitUsesPageCachePreferenceKey")) - propertyName = "enable-page-cache"; - else if (g_str_equal(originalName.get(), "WebKitPluginsEnabled")) - propertyName = "enable-plugins"; - else if (g_str_equal(originalName.get(), "WebKitHyperlinkAuditingEnabled")) - propertyName = "enable-hyperlink-auditing"; - else if (g_str_equal(originalName.get(), "WebKitWebGLEnabled")) - propertyName = "enable-webgl"; - else if (g_str_equal(originalName.get(), "WebKitWebAudioEnabled")) - propertyName = "enable-webaudio"; - else if (g_str_equal(originalName.get(), "WebKitDisplayImagesKey")) - propertyName = "auto-load-images"; - else if (g_str_equal(originalName.get(), "WebKitShouldRespectImageOrientation")) - propertyName = "respect-image-orientation"; - else if (g_str_equal(originalName.get(), "WebKitMediaSourceEnabled")) - propertyName = "enable-mediasource"; - else if (g_str_equal(originalName.get(), "WebKitTabToLinksPreferenceKey")) { - DumpRenderTreeSupportGtk::setLinksIncludedInFocusChain(booleanFromValue(valueAsString.get())); - return; - } else if (g_str_equal(originalName.get(), "WebKitPageCacheSupportsPluginsPreferenceKey")) { - DumpRenderTreeSupportGtk::setPageCacheSupportsPlugins(webkit_web_frame_get_web_view(mainFrame), booleanFromValue(valueAsString.get())); - return; - } else if (g_str_equal(originalName.get(), "WebKitCSSGridLayoutEnabled")) { - DumpRenderTreeSupportGtk::setCSSGridLayoutEnabled(webkit_web_frame_get_web_view(mainFrame), booleanFromValue(valueAsString.get())); - return; - } else if (g_str_equal(originalName.get(), "WebKitCSSRegionsEnabled")) { - DumpRenderTreeSupportGtk::setCSSRegionsEnabled(webkit_web_frame_get_web_view(mainFrame), booleanFromValue(valueAsString.get())); - return; - } else { - fprintf(stderr, "TestRunner::overridePreference tried to override " - "unknown preference '%s'.\n", originalName.get()); - return; - } - - WebKitWebSettings* settings = webkit_web_view_get_settings(view); - GParamSpec* pspec = g_object_class_find_property(G_OBJECT_CLASS( - WEBKIT_WEB_SETTINGS_GET_CLASS(settings)), propertyName); - GValue currentPropertyValue = { 0, { { 0 } } }; - g_value_init(¤tPropertyValue, pspec->value_type); - - if (G_VALUE_HOLDS_STRING(¤tPropertyValue)) - g_object_set(settings, propertyName, valueAsString.get(), NULL); - else if (G_VALUE_HOLDS_BOOLEAN(¤tPropertyValue)) - g_object_set(G_OBJECT(settings), propertyName, booleanFromValue(valueAsString.get()), NULL); - else if (G_VALUE_HOLDS_INT(¤tPropertyValue)) - g_object_set(G_OBJECT(settings), propertyName, atoi(valueAsString.get()), NULL); - else if (G_VALUE_HOLDS_FLOAT(¤tPropertyValue)) { - gfloat newValue = g_ascii_strtod(valueAsString.get(), 0); - g_object_set(G_OBJECT(settings), propertyName, newValue, NULL); - } else - fprintf(stderr, "TestRunner::overridePreference failed to override " - "preference '%s'.\n", originalName.get()); -} - -void TestRunner::addUserScript(JSStringRef source, bool runAtStart, bool allFrames) -{ - GUniquePtr<gchar> sourceCode(JSStringCopyUTF8CString(source)); - DumpRenderTreeSupportGtk::addUserScript(mainFrame, sourceCode.get(), runAtStart, allFrames); -} - -void TestRunner::addUserStyleSheet(JSStringRef source, bool allFrames) -{ - GUniquePtr<gchar> sourceCode(JSStringCopyUTF8CString(source)); - DumpRenderTreeSupportGtk::addUserStyleSheet(mainFrame, sourceCode.get(), allFrames); - // FIXME: needs more investigation why userscripts/user-style-top-frame-only.html fails when allFrames is false. - -} - -void TestRunner::setDeveloperExtrasEnabled(bool enabled) -{ - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - WebKitWebSettings* webSettings = webkit_web_view_get_settings(webView); - - g_object_set(webSettings, "enable-developer-extras", enabled, NULL); -} - -void TestRunner::showWebInspector() -{ - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - WebKitWebInspector* inspector = webkit_web_view_get_inspector(webView); - - webkit_web_inspector_show(inspector); -} - -void TestRunner::closeWebInspector() -{ - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - WebKitWebInspector* inspector = webkit_web_view_get_inspector(webView); - - webkit_web_inspector_close(inspector); -} - -void TestRunner::evaluateInWebInspector(long callId, JSStringRef script) -{ - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - WebKitWebInspector* inspector = webkit_web_view_get_inspector(webView); - char* scriptString = JSStringCopyUTF8CString(script); - - webkit_web_inspector_execute_script(inspector, callId, scriptString); - g_free(scriptString); -} - -void TestRunner::evaluateScriptInIsolatedWorldAndReturnValue(unsigned worldID, JSObjectRef globalObject, JSStringRef script) -{ - // FIXME: Implement this. -} - -void TestRunner::evaluateScriptInIsolatedWorld(unsigned worldID, JSObjectRef globalObject, JSStringRef script) -{ - // FIXME: Implement this. -} - -void TestRunner::removeAllVisitedLinks() -{ - // FIXME: Implement this. -} - -bool TestRunner::callShouldCloseOnWebView() -{ - return DumpRenderTreeSupportGtk::shouldClose(mainFrame); -} - -void TestRunner::apiTestNewWindowDataLoadBaseURL(JSStringRef utf8Data, JSStringRef baseURL) -{ - -} - -void TestRunner::apiTestGoToCurrentBackForwardItem() -{ - -} - -void TestRunner::setWebViewEditable(bool) -{ -} - -void TestRunner::authenticateSession(JSStringRef, JSStringRef, JSStringRef) -{ -} - -void TestRunner::abortModal() -{ -} - -void TestRunner::setSerializeHTTPLoads(bool serialize) -{ - DumpRenderTreeSupportGtk::setSerializeHTTPLoads(serialize); -} - -void TestRunner::setTextDirection(JSStringRef direction) -{ - GUniquePtr<gchar> writingDirection(JSStringCopyUTF8CString(direction)); - - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - if (g_str_equal(writingDirection.get(), "auto")) - gtk_widget_set_direction(GTK_WIDGET(view), GTK_TEXT_DIR_NONE); - else if (g_str_equal(writingDirection.get(), "ltr")) - gtk_widget_set_direction(GTK_WIDGET(view), GTK_TEXT_DIR_LTR); - else if (g_str_equal(writingDirection.get(), "rtl")) - gtk_widget_set_direction(GTK_WIDGET(view), GTK_TEXT_DIR_RTL); - else - fprintf(stderr, "TestRunner::setTextDirection called with unknown direction: '%s'.\n", writingDirection.get()); -} - -void TestRunner::addChromeInputField() -{ -} - -void TestRunner::removeChromeInputField() -{ -} - -void TestRunner::focusWebView() -{ -} - -void TestRunner::setBackingScaleFactor(double) -{ -} - -void TestRunner::grantWebNotificationPermission(JSStringRef origin) -{ -} - -void TestRunner::denyWebNotificationPermission(JSStringRef jsOrigin) -{ -} - -void TestRunner::removeAllWebNotificationPermissions() -{ -} - -void TestRunner::simulateWebNotificationClick(JSValueRef jsNotification) -{ -} - -void TestRunner::simulateLegacyWebNotificationClick(JSStringRef title) -{ -} - -void TestRunner::resetPageVisibility() -{ - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - DumpRenderTreeSupportGtk::setPageVisibility(webView, WebCore::PageVisibilityStateVisible, true); -} - -void TestRunner::setPageVisibility(const char* visibility) -{ - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - String visibilityString(visibility); - WebCore::PageVisibilityState visibilityState = WebCore::PageVisibilityStateVisible; - - if (visibilityString == "visible") - visibilityState = WebCore::PageVisibilityStateVisible; - else if (visibilityString == "hidden") - visibilityState = WebCore::PageVisibilityStateHidden; - else - return; - - DumpRenderTreeSupportGtk::setPageVisibility(webView, visibilityState, false); -} - -void TestRunner::setAutomaticLinkDetectionEnabled(bool) -{ - // FIXME: Implement this. -} - -void TestRunner::setStorageDatabaseIdleInterval(double) -{ - // FIXME: Implement this. -} - -void TestRunner::closeIdleLocalStorageDatabases() -{ -} diff --git a/Tools/DumpRenderTree/gtk/TextInputController.cpp b/Tools/DumpRenderTree/gtk/TextInputController.cpp deleted file mode 100644 index aee5597ed..000000000 --- a/Tools/DumpRenderTree/gtk/TextInputController.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (C) 2011 Igalia S.L. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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 "TextInputController.h" - -#include "DumpRenderTree.h" -#include "WebCoreSupport/DumpRenderTreeSupportGtk.h" -#include <GUniquePtrGtk.h> -#include <JavaScriptCore/JSObjectRef.h> -#include <JavaScriptCore/JSRetainPtr.h> -#include <JavaScriptCore/JSStringRef.h> -#include <cstring> -#include <webkit/webkit.h> - -static JSValueRef setMarkedTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - if (argumentCount < 3) - return JSValueMakeUndefined(context); - - JSStringRef string = JSValueToStringCopy(context, arguments[0], exception); - ASSERT(!exception || !*exception); - - size_t bufferSize = JSStringGetMaximumUTF8CStringSize(string); - GUniquePtr<gchar> stringBuffer(static_cast<gchar*>(g_malloc(bufferSize))); - JSStringGetUTF8CString(string, stringBuffer.get(), bufferSize); - JSStringRelease(string); - - int start = static_cast<int>(JSValueToNumber(context, arguments[1], exception)); - ASSERT(!exception || !*exception); - - int length = static_cast<int>(JSValueToNumber(context, arguments[2], exception)); - ASSERT(!exception || !*exception); - - DumpRenderTreeSupportGtk::setComposition(view, stringBuffer.get(), start, length); - return JSValueMakeUndefined(context); -} - -static JSValueRef hasMarkedTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - return JSValueMakeBoolean(context, DumpRenderTreeSupportGtk::hasComposition(view)); -} - -static JSValueRef markedRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - int start, length; - if (!DumpRenderTreeSupportGtk::compositionRange(view, &start, &length)) - return JSValueMakeUndefined(context); - - JSValueRef arrayValues[2]; - arrayValues[0] = JSValueMakeNumber(context, start); - arrayValues[1] = JSValueMakeNumber(context, length); - JSObjectRef arrayObject = JSObjectMakeArray(context, 2, arrayValues, exception); - ASSERT(!exception || !*exception); - return arrayObject; -} - -static JSValueRef insertTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - if (argumentCount < 1) - return JSValueMakeUndefined(context); - - JSStringRef string = JSValueToStringCopy(context, arguments[0], exception); - ASSERT(!exception || !*exception); - - size_t bufferSize = JSStringGetMaximumUTF8CStringSize(string); - GUniquePtr<gchar> stringBuffer(static_cast<gchar*>(g_malloc(bufferSize))); - JSStringGetUTF8CString(string, stringBuffer.get(), bufferSize); - JSStringRelease(string); - - DumpRenderTreeSupportGtk::confirmComposition(view, stringBuffer.get()); - return JSValueMakeUndefined(context); -} - -static JSValueRef unmarkTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - DumpRenderTreeSupportGtk::confirmComposition(view, 0); - return JSValueMakeUndefined(context); -} - -static JSValueRef firstRectForCharacterRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - if (argumentCount < 2) - return JSValueMakeUndefined(context); - - int location = static_cast<int>(JSValueToNumber(context, arguments[0], exception)); - ASSERT(!exception || !*exception); - - int length = static_cast<int>(JSValueToNumber(context, arguments[1], exception)); - ASSERT(!exception || !*exception); - - cairo_rectangle_int_t rect; - if (!DumpRenderTreeSupportGtk::firstRectForCharacterRange(view, location, length, &rect)) - return JSValueMakeUndefined(context); - - JSValueRef arrayValues[4]; - arrayValues[0] = JSValueMakeNumber(context, rect.x); - arrayValues[1] = JSValueMakeNumber(context, rect.y); - arrayValues[2] = JSValueMakeNumber(context, rect.width); - arrayValues[3] = JSValueMakeNumber(context, rect.height); - JSObjectRef arrayObject = JSObjectMakeArray(context, 4, arrayValues, exception); - ASSERT(!exception || !*exception); - - return arrayObject; -} - -static JSValueRef selectedRangeCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - - int start, length; - if (!DumpRenderTreeSupportGtk::selectedRange(view, &start, &length)) - return JSValueMakeUndefined(context); - - JSValueRef arrayValues[2]; - arrayValues[0] = JSValueMakeNumber(context, start); - arrayValues[1] = JSValueMakeNumber(context, length); - JSObjectRef arrayObject = JSObjectMakeArray(context, 2, arrayValues, exception); - ASSERT(!exception || !*exception); - - return arrayObject; -} - -static JSValueRef doCommandCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) -{ - WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame); - ASSERT(view); - if (argumentCount < 1) - return JSValueMakeUndefined(context); - - JSStringRef string = JSValueToStringCopy(context, arguments[0], exception); - ASSERT(!exception || !*exception); - - size_t bufferSize = JSStringGetMaximumUTF8CStringSize(string); - GUniquePtr<gchar> stringBuffer(static_cast<gchar*>(g_malloc(bufferSize))); - JSStringGetUTF8CString(string, stringBuffer.get(), bufferSize); - JSStringRelease(string); - - DumpRenderTreeSupportGtk::doCommand(view, stringBuffer.get()); - return JSValueMakeUndefined(context); -} - -static JSStaticFunction staticFunctions[] = { - { "setMarkedText", setMarkedTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "hasMarkedText", hasMarkedTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "markedRange", markedRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "insertText", insertTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "unmarkText", unmarkTextCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "firstRectForCharacterRange", firstRectForCharacterRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "selectedRange", selectedRangeCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { "doCommand", doCommandCallback, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete }, - { 0, 0, 0 } -}; - -static JSClassRef getClass(JSContextRef context) -{ - static JSClassRef textInputControllerClass = 0; - - if (!textInputControllerClass) { - JSClassDefinition classDefinition = { - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - classDefinition.staticFunctions = staticFunctions; - - textInputControllerClass = JSClassCreate(&classDefinition); - } - - return textInputControllerClass; -} - -JSObjectRef makeTextInputController(JSContextRef context) -{ - return JSObjectMake(context, getClass(context), 0); -} diff --git a/Tools/DumpRenderTree/gtk/TextInputController.h b/Tools/DumpRenderTree/gtk/TextInputController.h deleted file mode 100644 index 53793f637..000000000 --- a/Tools/DumpRenderTree/gtk/TextInputController.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2011 Igalia S.L. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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. - */ - -#ifndef TextInputController_h -#define TextInputController_h - -typedef const struct OpaqueJSContext* JSContextRef; -typedef struct OpaqueJSValue* JSObjectRef; - -JSObjectRef makeTextInputController(JSContextRef); - -#endif diff --git a/Tools/DumpRenderTree/gtk/WorkQueueItemGtk.cpp b/Tools/DumpRenderTree/gtk/WorkQueueItemGtk.cpp deleted file mode 100644 index 95461276e..000000000 --- a/Tools/DumpRenderTree/gtk/WorkQueueItemGtk.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2007 Alp Toker <alp@atoker.com> - * - * 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 "WorkQueueItem.h" - -#include "DumpRenderTree.h" - -#include <JavaScriptCore/JSStringRef.h> -#include <string.h> -#include <webkit/webkit.h> -#include <wtf/gobject/GUniquePtr.h> - -// Returns a newly allocated UTF-8 character buffer which must be freed with g_free() -gchar* JSStringCopyUTF8CString(JSStringRef jsString) -{ - size_t dataSize = JSStringGetMaximumUTF8CStringSize(jsString); - gchar* utf8 = (gchar*)g_malloc(dataSize); - JSStringGetUTF8CString(jsString, utf8, dataSize); - - return utf8; -} - -bool LoadItem::invoke() const -{ - gchar* targetString = JSStringCopyUTF8CString(m_target.get()); - - WebKitWebFrame* targetFrame; - if (!strlen(targetString)) - targetFrame = mainFrame; - else - targetFrame = webkit_web_frame_find_frame(mainFrame, targetString); - g_free(targetString); - - gchar* urlString = JSStringCopyUTF8CString(m_url.get()); - WebKitNetworkRequest* request = webkit_network_request_new(urlString); - g_free(urlString); - webkit_web_frame_load_request(targetFrame, request); - g_object_unref(request); - - return true; -} - -bool LoadHTMLStringItem::invoke() const -{ - GUniquePtr<gchar> content(JSStringCopyUTF8CString(m_content.get())); - GUniquePtr<gchar> baseURL(JSStringCopyUTF8CString(m_baseURL.get())); - - if (m_unreachableURL) { - GUniquePtr<gchar> unreachableURL(JSStringCopyUTF8CString(m_unreachableURL.get())); - webkit_web_frame_load_alternate_string(mainFrame, content.get(), baseURL.get(), unreachableURL.get()); - return true; - } - webkit_web_frame_load_string(mainFrame, content.get(), 0, 0, baseURL.get()); - return true; -} - -bool ReloadItem::invoke() const -{ - webkit_web_frame_reload(mainFrame); - return true; -} - -bool ScriptItem::invoke() const -{ - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - gchar* scriptString = JSStringCopyUTF8CString(m_script.get()); - webkit_web_view_execute_script(webView, scriptString); - g_free(scriptString); - return true; -} - -bool BackForwardItem::invoke() const -{ - WebKitWebView* webView = webkit_web_frame_get_web_view(mainFrame); - if (m_howFar == 1) - webkit_web_view_go_forward(webView); - else if (m_howFar == -1) - webkit_web_view_go_back(webView); - else { - WebKitWebBackForwardList* webBackForwardList = webkit_web_view_get_back_forward_list(webView); - WebKitWebHistoryItem* item = webkit_web_back_forward_list_get_nth_item(webBackForwardList, m_howFar); - webkit_web_view_go_to_back_forward_item(webView, item); - } - return true; -} |