summaryrefslogtreecommitdiff
path: root/Tools/TestWebKitAPI/Tests/WebKitGtk
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/TestWebKitAPI/Tests/WebKitGtk')
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/test_utils.c51
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testapplicationcache.c49
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testatk.c1476
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testatkroles.c426
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testcontextmenu.c317
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testcopyandpaste.c266
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testdomdocument.c445
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testdomdomwindow.c258
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testdomnode.c219
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testdownload.c325
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testfavicondatabase.c279
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testglobals.c110
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testhittestresult.c171
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testhttpbackend.c75
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testkeyevents.c390
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testloading.c437
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testmimehandling.c206
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testnetworkrequest.c96
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testnetworkresponse.c97
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testwebbackforwardlist.c326
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testwebdatasource.c242
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testwebframe.c220
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testwebhistoryitem.c70
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testwebinspector.c173
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testwebplugindatabase.c78
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testwebresource.c334
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testwebsettings.c110
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testwebview.c749
-rw-r--r--Tools/TestWebKitAPI/Tests/WebKitGtk/testwindow.c119
29 files changed, 0 insertions, 8114 deletions
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/test_utils.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/test_utils.c
deleted file mode 100644
index 6bb645d0d..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/test_utils.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2010 Arno Renevier
- *
- * 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 "test_utils.h"
-
-#include <glib.h>
-#include <glib/gstdio.h>
-
-int testutils_relative_chdir(const gchar *targetFilename, const gchar *executablePath)
-{
- /* user can set location of the webkit repository directory if it differs from build directory */
- const gchar *repoPath = g_getenv("WEBKITREPODIR");
- if (repoPath) {
- if (g_chdir(repoPath))
- return -1;
- } else if (g_chdir(g_path_get_dirname(executablePath)))
- return -1;
-
- while (!g_file_test(targetFilename, G_FILE_TEST_EXISTS)) {
- gchar *pathName;
- if (g_chdir(".."))
- return -1;
- g_assert(!g_str_equal((pathName = g_get_current_dir()), "/"));
- g_free(pathName);
- }
-
- gchar *dirName = g_path_get_dirname(targetFilename);
- if (g_chdir(dirName)) {
- g_free(dirName);
- return -1;
- }
-
- g_free(dirName);
- return 0;
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testapplicationcache.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testapplicationcache.c
deleted file mode 100644
index 718f401a7..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testapplicationcache.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2011 Lukasz Slachciak
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2,1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include <glib.h>
-#include <glib/gprintf.h>
-#include <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-static void test_application_cache_maximum_size()
-{
- unsigned long long maxSize = 8192;
- webkit_application_cache_set_maximum_size(maxSize);
-
- // Creating a WebView - make sure that it didn't change anything
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- g_object_unref(webView);
-
- g_assert(maxSize == webkit_application_cache_get_maximum_size());
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_func("/webkit/application_cache/maximum_size",
- test_application_cache_maximum_size);
-
- return g_test_run();
-}
-
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testatk.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testatk.c
deleted file mode 100644
index 2a2db6146..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testatk.c
+++ /dev/null
@@ -1,1476 +0,0 @@
-/*
- * Copyright (C) 2009 Igalia S.L.
- * Copyright (C) 2013 Samsung Electronics. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include <errno.h>
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <gtk/gtk.h>
-#include <locale.h>
-#include <unistd.h>
-#include <webkit/webkit.h>
-
-static const char* centeredContents = "<html><body><p style='text-align: center;'>Short line</p><p style='text-align: center;'>Long-size line with some foo bar baz content</p><p style='text-align: center;'>Short line</p><p style='text-align: center;'>This is a multi-line paragraph<br />where the first line<br />is the biggest one</p></body></html>";
-
-static const char* contents = "<html><body><p>This is a test. This is the second sentence. And this the third.</p></body></html>";
-
-static const char* contentsInTableWithHeaders = "<html><body><table><tr><th>foo</th><th>bar</th><th colspan='2'>baz</th></tr><tr><th>qux</th><td>1</td><td>2</td><td>3</td></tr><tr><th rowspan='2'>quux</th><td>4</td><td>5</td><td>6</td></tr><tr><td>6</td><td>7</td><td>8</td></tr><tr><th>corge</th><td>9</td><td>10</td><td>11</td></tr></table><table><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></table></body></html>";
-
-static const char* contentsWithExtraneousWhiteSpaces = "<html><head><body><p>This\n paragraph\n is\n borked!</p></body></html>";
-
-static const char* comboBoxSelector = "<html><body><select><option selected value='foo'>foo</option><option value='bar'>bar</option></select></body></html>";
-
-static const char* embeddedObjects = "<html><body><p>Choose: <input value='foo' type='checkbox'/>foo <input value='bar' type='checkbox'/>bar (pick one)</p><p>Choose: <select name='foo'><option>bar</option><option>baz</option></select> (pick one)</p><p><input name='foobarbutton' value='foobar' type='button'/></p></body></html>";
-
-static const char* formWithTextInputs = "<html><body><form><input type='text' name='entry' /><input type='password' name='passwordEntry' /></form></body></html>";
-
-static const char* hypertextAndHyperlinks = "<html><body><p>A paragraph with no links at all</p><p><a href='http://foo.bar.baz/'>A line</a> with <a href='http://bar.baz.foo/'>a link in the middle</a> as well as at the beginning and <a href='http://baz.foo.bar/'>at the end</a></p><ol><li>List item with a <span><a href='http://foo.bar.baz/'>link inside a span node</a></span></li></ol></body></html>";
-
-static const char* layoutAndDataTables = "<html><body><table><tr><th>Odd</th><th>Even</th></tr><tr><td>1</td><td>2</td></tr></table><table><tr><td>foo</td><td>bar</td></tr></table></body></html>";
-
-static const char* linksWithInlineImages = "<html><head><style>a.http:before {content: url(no-image.png);}</style><body><p><a class='http' href='foo'>foo</a> bar baz</p><p>foo <a class='http' href='bar'>bar</a> baz</p><p>foo bar <a class='http' href='baz'>baz</a></p></body></html>";
-
-static const char* listsOfItems = "<html><body><ul><li>text only</li><li><a href='foo'>link only</a></li><li>text and a <a href='bar'>link</a></li></ul><ol><li>text only</li><li><a href='foo'>link only</a></li><li>text and a <a href='bar'>link</a></li></ol></body></html>";
-
-static const char* textForCaretBrowsing = "<html><body><h1>A text header</h1><p>A paragraph <a href='http://foo.bar.baz/'>with a link</a> in the middle</p><ol><li>A list item</li><li><span style='display:block;'>Block span in a list item</span><span>Inline span in a list item</span></li><li><a href='foo'><span style='display:block;'>Block span in a link in a list item</span><span>Inline span in a link in a list item</span></a></li></ol><select><option selected value='foo'>An option in a combo box</option></select><input type='text' name='foo' value='foo bar baz' /><table><tr><td>a table cell</td><td></td><td><a href='foo'><span style='display:block;'>Block span in a link in a table cell</span><span>Inline span in a link in a table cell</span></a></td><td><span style='display:block;'>Block span in a table cell</span><span>Inline span in a table cell</span></td></tr></table><h4><a href='foo'><span style='display:block;'>Block span in a link in a heading</span><span>Inline span in a link in a heading</span></h4><h4><span style='display:block;'>Block span in a heading</span><span>Inline span in a heading</span></h4></body></html>";
-
-static const char* textForSelections = "<html><body><p>A paragraph with plain text</p><p>A paragraph with <a href='http://webkit.org'>a link</a> in the middle</p><ol><li>A list item</li></ol><select></body></html>";
-
-static const char* textWithAttributes = "<html><head><style>.st1 {font-family: monospace; color:rgb(120,121,122);} .st2 {text-decoration:underline; background-color:rgb(80,81,82);}</style></head><body><p style=\"font-size:14; text-align:right;\">This is the <i>first</i><b> sentence of this text.</b></p><p class=\"st1\">This sentence should have an style applied <span class=\"st2\">and this part should have another one</span>.</p><p>x<sub>1</sub><sup>2</sup>=x<sub>2</sub><sup>3</sup></p><p style=\"text-align:center;\">This sentence is the <strike>last</strike> one.</p></body></html>";
-
-static AtkObject* getWebAreaObject(WebKitWebView* webView)
-{
- /* Manually spin the main context to make sure the accessible
- objects are properly created before continuing. */
- while (g_main_context_pending(0))
- g_main_context_iteration(0, TRUE);
-
- AtkObject* rootObject = gtk_widget_get_accessible(GTK_WIDGET(webView));
- if (!rootObject)
- return NULL;
-
- AtkObject* webAreaObject = atk_object_ref_accessible_child(rootObject, 0);
- if (!webAreaObject)
- return NULL;
-
- /* We don't need the extra ref here. */
- g_object_unref(webAreaObject);
-
- return webAreaObject;
-}
-
-static gchar* textCaretMovedResult = 0;
-
-static void textCaretMovedCallback(AtkText* text, gint pos, gpointer data)
-{
- g_assert(ATK_IS_TEXT(text));
-
- g_free(textCaretMovedResult);
- AtkRole role = atk_object_get_role(ATK_OBJECT(text));
- textCaretMovedResult = g_strdup_printf("|%s|%d|", atk_role_get_name(role), pos);
-}
-
-static void testWebkitAtkCaretOffsets()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
- webkit_web_view_load_string(webView, textForCaretBrowsing, 0, 0, 0);
-
- AtkObject* object = getWebAreaObject(webView);
- g_assert(object);
-
- AtkObject* header = atk_object_ref_accessible_child(object, 0);
- g_assert(ATK_IS_TEXT(header));
- g_signal_connect(header, "text-caret-moved", G_CALLBACK(textCaretMovedCallback), 0);
-
- /* It should be possible to place the caret inside a header. */
- gboolean result = atk_text_set_caret_offset(ATK_TEXT(header), 5);
- g_assert_cmpint(result, ==, TRUE);
- gint offset = atk_text_get_caret_offset(ATK_TEXT(header));
- g_assert_cmpint(offset, ==, 5);
- g_assert_cmpstr(textCaretMovedResult, ==, "|heading|5|");
-
- AtkObject* paragraph = atk_object_ref_accessible_child(object, 1);
- g_assert(ATK_IS_TEXT(paragraph));
- g_signal_connect(paragraph, "text-caret-moved", G_CALLBACK(textCaretMovedCallback), 0);
-
- /* It should be possible to place the caret inside a paragraph and a link. */
- result = atk_text_set_caret_offset(ATK_TEXT(paragraph), 5);
- g_assert_cmpint(result, ==, TRUE);
- offset = atk_text_get_caret_offset(ATK_TEXT(paragraph));
- g_assert_cmpint(offset, ==, 5);
- g_assert_cmpstr(textCaretMovedResult, ==, "|paragraph|5|");
-
- result = atk_text_set_caret_offset(ATK_TEXT(paragraph), 20);
- g_assert_cmpint(result, ==, TRUE);
- offset = atk_text_get_caret_offset(ATK_TEXT(paragraph));
- g_assert_cmpint(offset, ==, 20);
- g_assert_cmpstr(textCaretMovedResult, ==, "|paragraph|20|");
-
- result = atk_text_set_caret_offset(ATK_TEXT(paragraph), 30);
- g_assert_cmpint(result, ==, TRUE);
- offset = atk_text_get_caret_offset(ATK_TEXT(paragraph));
- g_assert_cmpint(offset, ==, 30);
- g_assert_cmpstr(textCaretMovedResult, ==, "|paragraph|30|");
-
- AtkObject* link = atk_object_ref_accessible_child(paragraph, 0);
- g_assert(ATK_IS_TEXT(link));
-
- result = atk_text_set_caret_offset(ATK_TEXT(link), 5);
- g_assert_cmpint(result, ==, TRUE);
- offset = atk_text_get_caret_offset(ATK_TEXT(link));
- g_assert_cmpint(offset, ==, 5);
- /* Positions inside links are reported relative to the paragraph. */
- g_assert_cmpstr(textCaretMovedResult, ==, "|paragraph|17|");
-
- AtkObject* list = atk_object_ref_accessible_child(object, 2);
- g_assert(ATK_OBJECT(list));
- g_assert(atk_object_get_role(list) == ATK_ROLE_LIST);
- g_assert_cmpint(atk_object_get_n_accessible_children(list), ==, 3);
-
- AtkObject* listItem = atk_object_ref_accessible_child(list, 0);
- listItem = atk_object_ref_accessible_child(list, 2);
- g_assert(ATK_IS_TEXT(listItem));
-
- /* It's not possible to place the caret inside an item's marker. */
- result = atk_text_set_caret_offset(ATK_TEXT(listItem), 1);
- g_assert_cmpint(result, ==, FALSE);
-
- /* It should be possible to place the caret inside an item's text. */
- result = atk_text_set_caret_offset(ATK_TEXT(listItem), 5);
- g_assert_cmpint(result, ==, TRUE);
- offset = atk_text_get_caret_offset(ATK_TEXT(listItem));
- g_assert_cmpint(offset, ==, 5);
-
- AtkObject* panel = atk_object_ref_accessible_child(object, 3);
- g_assert(ATK_IS_OBJECT(panel));
- g_assert(atk_object_get_role(panel) == ATK_ROLE_PANEL);
-
- AtkObject* comboBox = atk_object_ref_accessible_child(panel, 0);
- g_assert(ATK_IS_OBJECT(comboBox));
- g_assert(atk_object_get_role(comboBox) == ATK_ROLE_COMBO_BOX);
-
- AtkObject* menuPopup = atk_object_ref_accessible_child(comboBox, 0);
- g_assert(ATK_IS_OBJECT(menuPopup));
- g_assert(atk_object_get_role(menuPopup) == ATK_ROLE_MENU);
-
- AtkObject* comboBoxOption = atk_object_ref_accessible_child(menuPopup, 0);
- g_assert(ATK_IS_OBJECT(comboBoxOption));
- g_assert(atk_object_get_role(comboBoxOption) == ATK_ROLE_MENU_ITEM);
-
- /* It's not possible to place the caret inside an option for a combobox. */
- result = atk_text_set_caret_offset(ATK_TEXT(comboBoxOption), 1);
- g_assert_cmpint(result, ==, FALSE);
-
- AtkObject* textEntry = atk_object_ref_accessible_child(panel, 1);
- g_assert(ATK_IS_OBJECT(textEntry));
- g_assert(atk_object_get_role(textEntry) == ATK_ROLE_ENTRY);
-
- result = atk_text_set_caret_offset(ATK_TEXT(textEntry), 5);
- g_assert_cmpint(result, ==, TRUE);
- offset = atk_text_get_caret_offset(ATK_TEXT(textEntry));
- g_assert_cmpint(offset, ==, 5);
-
- AtkObject* table = atk_object_ref_accessible_child(object, 4);
- g_assert(ATK_IS_OBJECT(table));
- g_assert(atk_object_get_role(table) == ATK_ROLE_TABLE);
- g_assert_cmpint(atk_object_get_n_accessible_children(table), ==, 4);
-
- AtkObject* tableCell = atk_object_ref_accessible_child(table, 0);
- g_assert(atk_object_get_role(tableCell) == ATK_ROLE_TABLE_CELL);
- result = atk_text_set_caret_offset(ATK_TEXT(tableCell), 2);
- g_assert_cmpint(result, ==, TRUE);
- offset = atk_text_get_caret_offset(ATK_TEXT(tableCell));
- g_assert_cmpint(offset, ==, 2);
-
- g_free(textCaretMovedResult);
-
- g_object_unref(paragraph);
- g_object_unref(link);
- g_object_unref(list);
- g_object_unref(listItem);
- g_object_unref(panel);
- g_object_unref(comboBox);
- g_object_unref(menuPopup);
- g_object_unref(comboBoxOption);
- g_object_unref(textEntry);
- g_object_unref(table);
- g_object_unref(tableCell);
- g_object_unref(webView);
-}
-
-static void testWebkitAtkCaretOffsetsAndExtranousWhiteSpaces()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
- webkit_web_view_load_string(webView, contentsWithExtraneousWhiteSpaces, 0, 0, 0);
-
- /* Enable caret browsing. */
- WebKitWebSettings* settings = webkit_web_view_get_settings(webView);
- g_object_set(G_OBJECT(settings), "enable-caret-browsing", TRUE, NULL);
-
- /* Get to the inner AtkText object. */
- AtkObject* object = getWebAreaObject(webView);
- g_assert(object);
- object = atk_object_ref_accessible_child(object, 0);
- g_assert(object);
-
- AtkText* textObject = ATK_TEXT(object);
- g_assert(ATK_IS_TEXT(textObject));
-
- gint characterCount = atk_text_get_character_count(textObject);
- g_assert_cmpint(characterCount, ==, 25);
-
- gboolean result = atk_text_set_caret_offset(textObject, characterCount - 1);
- g_assert_cmpint(result, ==, TRUE);
-
- gint caretOffset = atk_text_get_caret_offset(textObject);
- g_assert_cmpint(caretOffset, ==, characterCount - 1);
-
- result = atk_text_set_caret_offset(textObject, characterCount);
- g_assert_cmpint(result, ==, TRUE);
-
- caretOffset = atk_text_get_caret_offset(textObject);
- g_assert_cmpint(caretOffset, ==, characterCount);
-
- g_object_unref(object);
- g_object_unref(webView);
-}
-
-static void testWebkitAtkComboBox()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
- webkit_web_view_load_string(webView, comboBoxSelector, 0, 0, 0);
-
- AtkObject* object = getWebAreaObject(webView);
- g_assert(object);
-
- AtkObject* formObject = atk_object_ref_accessible_child(object, 0);
- g_assert(formObject);
-
- AtkObject* comboBox = atk_object_ref_accessible_child(formObject, 0);
- g_assert(ATK_IS_OBJECT(comboBox));
-
- AtkObject* menuPopup = atk_object_ref_accessible_child(comboBox, 0);
- g_assert(ATK_IS_OBJECT(menuPopup));
-
- AtkObject* item1 = atk_object_ref_accessible_child(menuPopup, 0);
- g_assert(ATK_IS_OBJECT(item1));
-
- AtkObject* item2 = atk_object_ref_accessible_child(menuPopup, 1);
- g_assert(ATK_IS_OBJECT(item2));
-
- /* Check roles. */
- g_assert(atk_object_get_role(comboBox) == ATK_ROLE_COMBO_BOX);
- g_assert(atk_object_get_role(menuPopup) == ATK_ROLE_MENU);
- g_assert(atk_object_get_role(item1) == ATK_ROLE_MENU_ITEM);
- g_assert(atk_object_get_role(item2) == ATK_ROLE_MENU_ITEM);
-
- /* Check the implementation of the AtkSelection interface. */
- g_assert(ATK_IS_SELECTION(comboBox));
- AtkSelection* atkSelection = ATK_SELECTION(comboBox);
- g_assert_cmpint(atk_selection_get_selection_count(atkSelection), ==, 1);
- g_assert(atk_selection_is_child_selected(atkSelection, 0));
- g_assert(!atk_selection_is_child_selected(atkSelection, 1));
- AtkObject* selectedItem = atk_selection_ref_selection(atkSelection, 0);
- g_assert(selectedItem == item1);
- g_object_unref(selectedItem);
-
- /* Check that the menu popup has 0 links and doesn't crash from checking. */
- gint nLinks = atk_hypertext_get_n_links(ATK_HYPERTEXT(menuPopup));
- g_assert_cmpint(nLinks, ==, 0);
-
- /* Check the implementations of the AtkAction interface. */
- g_assert(ATK_IS_ACTION(comboBox));
- AtkAction* atkAction = ATK_ACTION(comboBox);
- g_assert_cmpint(atk_action_get_n_actions(atkAction), ==, 1);
- g_assert(atk_action_do_action(atkAction, 0));
-
- g_assert(ATK_IS_ACTION(menuPopup));
- atkAction = ATK_ACTION(menuPopup);
- g_assert_cmpint(atk_action_get_n_actions(atkAction), ==, 1);
- g_assert(atk_action_do_action(atkAction, 0));
-
- g_assert(ATK_IS_ACTION(item1));
- atkAction = ATK_ACTION(item1);
- g_assert_cmpint(atk_action_get_n_actions(atkAction), ==, 1);
- g_assert(atk_action_do_action(atkAction, 0));
-
- g_assert(ATK_IS_ACTION(item2));
- atkAction = ATK_ACTION(item2);
- g_assert_cmpint(atk_action_get_n_actions(atkAction), ==, 1);
- g_assert(atk_action_do_action(atkAction, 0));
-
- /* After selecting the second item, selection should have changed. */
- g_assert_cmpint(atk_selection_get_selection_count(atkSelection), ==, 1);
- g_assert(!atk_selection_is_child_selected(atkSelection, 0));
- g_assert(atk_selection_is_child_selected(atkSelection, 1));
- selectedItem = atk_selection_ref_selection(atkSelection, 0);
- g_assert(selectedItem == item2);
- g_object_unref(selectedItem);
-
- g_object_unref(formObject);
- g_object_unref(comboBox);
- g_object_unref(menuPopup);
- g_object_unref(item1);
- g_object_unref(item2);
- g_object_unref(webView);
-}
-
-static gchar* loadingEventsResult = 0;
-
-static void updateLoadingEventsResult(const gchar* signalName)
-{
- g_assert(signalName);
-
- gchar* previousResult = loadingEventsResult;
- loadingEventsResult = g_strdup_printf("%s|%s", previousResult, signalName);
- g_free(previousResult);
-}
-
-static gboolean documentLoadingEventCallback(GSignalInvocationHint *signalHint, guint numParamValues, const GValue *paramValues, gpointer data)
-{
- // At least we should receive the instance emitting the signal.
- if (numParamValues < 1)
- return TRUE;
-
- GSignalQuery signal_query;
- g_signal_query(signalHint->signal_id, &signal_query);
-
- updateLoadingEventsResult(signal_query.signal_name);
- return TRUE;
-}
-
-static void testWebkitAtkDocumentLoadingEvents()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
-
- /* Connect globally to see those events during a future load. */
- guint loadCompleteListenerId = atk_add_global_event_listener(documentLoadingEventCallback, "ATK:AtkDocument:load-complete");
-
- /* Do the load, so we can see those events happening. */
- loadingEventsResult = g_strdup("");
- webkit_web_view_load_string(webView, contents, 0, 0, 0);
-
- /* Trigger the creation of the full accessibility hierarchy by
- asking for the webArea object, so we can listen to events. */
- getWebAreaObject(webView);
-
- atk_remove_global_event_listener(loadCompleteListenerId);
-
- g_assert_cmpstr(loadingEventsResult, ==, "|load-complete");
-
- g_free(loadingEventsResult);
- g_object_unref(webView);
-}
-
-static void testWebkitAtkEmbeddedObjects()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
- webkit_web_view_load_string(webView, embeddedObjects, 0, 0, 0);
-
- AtkObject* object = getWebAreaObject(webView);
- g_assert(object);
-
- AtkText* paragraph1 = ATK_TEXT(atk_object_ref_accessible_child(object, 0));
- g_assert(ATK_IS_TEXT(paragraph1));
- g_assert(ATK_IS_HYPERTEXT(paragraph1));
-
- gint nLinks = atk_hypertext_get_n_links(ATK_HYPERTEXT(paragraph1));
- g_assert_cmpint(nLinks, ==, 2);
-
- AtkHyperlink* hLink = atk_hypertext_get_link(ATK_HYPERTEXT(paragraph1), 0);
- g_assert(ATK_HYPERLINK(hLink));
- AtkObject* hLinkObject = atk_hyperlink_get_object(hLink, 0);
- g_assert(ATK_OBJECT(hLinkObject));
- g_assert(atk_object_get_role(hLinkObject) == ATK_ROLE_CHECK_BOX);
- g_assert_cmpint(atk_hyperlink_get_start_index(hLink), ==, 8);
- g_assert_cmpint(atk_hyperlink_get_end_index(hLink), ==, 9);
- g_assert_cmpint(atk_hyperlink_get_n_anchors(hLink), ==, 1);
- g_assert_cmpstr(atk_hyperlink_get_uri(hLink, 0), ==, 0);
-
- AtkText* paragraph2 = ATK_TEXT(atk_object_ref_accessible_child(object, 1));
- g_assert(ATK_IS_HYPERTEXT(paragraph2));
-
- nLinks = atk_hypertext_get_n_links(ATK_HYPERTEXT(paragraph2));
- g_assert_cmpint(nLinks, ==, 1);
-
- hLink = atk_hypertext_get_link(ATK_HYPERTEXT(paragraph2), 0);
- g_assert(ATK_HYPERLINK(hLink));
- hLinkObject = atk_hyperlink_get_object(hLink, 0);
- g_assert(ATK_OBJECT(hLinkObject));
- g_assert(atk_object_get_role(hLinkObject) == ATK_ROLE_COMBO_BOX);
- g_assert_cmpint(atk_hyperlink_get_start_index(hLink), ==, 8);
- g_assert_cmpint(atk_hyperlink_get_end_index(hLink), ==, 9);
- g_assert_cmpint(atk_hyperlink_get_n_anchors(hLink), ==, 1);
- g_assert_cmpstr(atk_hyperlink_get_uri(hLink, 0), ==, 0);
-
- AtkText* paragraph3 = ATK_TEXT(atk_object_ref_accessible_child(object, 2));
- g_assert(ATK_IS_HYPERTEXT(paragraph3));
-
- nLinks = atk_hypertext_get_n_links(ATK_HYPERTEXT(paragraph3));
- g_assert_cmpint(nLinks, ==, 1);
-
- hLink = atk_hypertext_get_link(ATK_HYPERTEXT(paragraph3), 0);
- g_assert(ATK_HYPERLINK(hLink));
- hLinkObject = atk_hyperlink_get_object(hLink, 0);
- g_assert(ATK_OBJECT(hLinkObject));
- g_assert(atk_object_get_role(hLinkObject) == ATK_ROLE_PUSH_BUTTON);
- g_assert_cmpint(atk_hyperlink_get_start_index(hLink), ==, 0);
- g_assert_cmpint(atk_hyperlink_get_end_index(hLink), ==, 1);
- g_assert_cmpint(atk_hyperlink_get_n_anchors(hLink), ==, 1);
- g_assert_cmpstr(atk_hyperlink_get_uri(hLink, 0), ==, 0);
-
- g_object_unref(paragraph1);
- g_object_unref(paragraph2);
- g_object_unref(paragraph3);
- g_object_unref(webView);
-}
-
-static void testWebkitAtkGetHeadersInTable()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
- webkit_web_view_load_string(webView, contentsInTableWithHeaders, 0, 0, 0);
-
- AtkObject* axWebView = getWebAreaObject(webView);
- g_assert(axWebView);
-
- /* Check table with both column and row headers. */
- AtkObject* table = atk_object_ref_accessible_child(axWebView, 0);
- g_assert(table);
- g_assert(atk_object_get_role(table) == ATK_ROLE_TABLE);
-
- AtkObject* colHeader = atk_table_get_column_header(ATK_TABLE(table), 0);
- g_assert(colHeader);
- g_assert(atk_object_get_role(colHeader) == ATK_ROLE_TABLE_CELL);
- g_assert(atk_object_get_index_in_parent(colHeader) == 0);
-
- colHeader = atk_table_get_column_header(ATK_TABLE(table), 1);
- g_assert(colHeader);
- g_assert(atk_object_get_role(colHeader) == ATK_ROLE_TABLE_CELL);
- g_assert(atk_object_get_index_in_parent(colHeader) == 1);
-
- colHeader = atk_table_get_column_header(ATK_TABLE(table), 2);
- g_assert(colHeader);
- g_assert(atk_object_get_role(colHeader) == ATK_ROLE_TABLE_CELL);
- g_assert(atk_object_get_index_in_parent(colHeader) == 2);
-
- colHeader = atk_table_get_column_header(ATK_TABLE(table), 3);
- g_assert(colHeader);
- g_assert(atk_object_get_role(colHeader) == ATK_ROLE_TABLE_CELL);
- g_assert(atk_object_get_index_in_parent(colHeader) == 2);
-
- AtkObject* rowHeader = atk_table_get_row_header(ATK_TABLE(table), 0);
- g_assert(rowHeader);
- g_assert(atk_object_get_role(rowHeader) == ATK_ROLE_TABLE_CELL);
- g_assert(atk_object_get_index_in_parent(rowHeader) == 0);
-
- rowHeader = atk_table_get_row_header(ATK_TABLE(table), 1);
- g_assert(rowHeader);
- g_assert(atk_object_get_role(rowHeader) == ATK_ROLE_TABLE_CELL);
- g_assert(atk_object_get_index_in_parent(rowHeader) == 3);
-
- rowHeader = atk_table_get_row_header(ATK_TABLE(table), 2);
- g_assert(rowHeader);
- g_assert(atk_object_get_role(rowHeader) == ATK_ROLE_TABLE_CELL);
- g_assert(atk_object_get_index_in_parent(rowHeader) == 7);
-
- rowHeader = atk_table_get_row_header(ATK_TABLE(table), 3);
- g_assert(rowHeader);
- g_assert(atk_object_get_role(rowHeader) == ATK_ROLE_TABLE_CELL);
- g_assert(atk_object_get_index_in_parent(rowHeader) == 7);
-
- g_object_unref(table);
-
- /* Check table with no headers at all. */
- table = atk_object_ref_accessible_child(axWebView, 1);
- g_assert(table);
- g_assert(atk_object_get_role(table) == ATK_ROLE_TABLE);
-
- colHeader = atk_table_get_column_header(ATK_TABLE(table), 0);
- g_assert(colHeader == 0);
-
- colHeader = atk_table_get_column_header(ATK_TABLE(table), 1);
- g_assert(colHeader == 0);
-
- rowHeader = atk_table_get_row_header(ATK_TABLE(table), 0);
- g_assert(rowHeader == 0);
-
- rowHeader = atk_table_get_row_header(ATK_TABLE(table), 1);
- g_assert(rowHeader == 0);
-
- g_object_unref(table);
- g_object_unref(webView);
-}
-
-static gint compAtkAttribute(AtkAttribute* a1, AtkAttribute* a2)
-{
- gint strcmpVal = g_strcmp0(a1->name, a2->name);
- if (strcmpVal)
- return strcmpVal;
- return g_strcmp0(a1->value, a2->value);
-}
-
-static gint compAtkAttributeName(AtkAttribute* a1, AtkAttribute* a2)
-{
- return g_strcmp0(a1->name, a2->name);
-}
-
-static gboolean atkAttributeSetAttributeNameHasValue(AtkAttributeSet* set, const gchar* attributeName, const gchar* value)
-{
- AtkAttribute at;
- at.name = (gchar*)attributeName;
- GSList* element = g_slist_find_custom(set, &at, (GCompareFunc)compAtkAttributeName);
- return element && !g_strcmp0(((AtkAttribute*)(element->data))->value, value);
-}
-
-static gboolean atkAttributeSetContainsAttributeName(AtkAttributeSet* set, const gchar* attributeName)
-{
- AtkAttribute at;
- at.name = (gchar*)attributeName;
- return g_slist_find_custom(set, &at, (GCompareFunc)compAtkAttributeName) ? true : false;
-}
-
-static gboolean atkAttributeSetAttributeHasValue(AtkAttributeSet* set, AtkTextAttribute attribute, const gchar* value)
-{
- return atkAttributeSetAttributeNameHasValue(set, atk_text_attribute_get_name(attribute), value);
-}
-
-static gboolean atkAttributeSetAreEqual(AtkAttributeSet* set1, AtkAttributeSet* set2)
-{
- if (!set1)
- return !set2;
-
- set1 = g_slist_sort(set1, (GCompareFunc)compAtkAttribute);
- set2 = g_slist_sort(set2, (GCompareFunc)compAtkAttribute);
-
- while (set1) {
- if (!set2 || compAtkAttribute(set1->data, set2->data))
- return FALSE;
-
- set1 = set1->next;
- set2 = set2->next;
- }
-
- return (!set2);
-}
-
-static void testWebkitAtkTextAttributes()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
- webkit_web_view_load_string(webView, textWithAttributes, 0, 0, 0);
-
- AtkObject* object = getWebAreaObject(webView);
- g_assert(object);
-
- AtkObject* child = atk_object_ref_accessible_child(object, 0);
- g_assert(child && ATK_IS_TEXT(child));
- AtkText* childText = ATK_TEXT(child);
-
- gint startOffset;
- gint endOffset;
- AtkAttributeSet* set1 = atk_text_get_run_attributes(childText, 0, &startOffset, &endOffset);
- g_assert_cmpint(startOffset, ==, 0);
- g_assert_cmpint(endOffset, ==, 12);
- g_assert(atkAttributeSetAreEqual(set1, 0));
-
- AtkAttributeSet* set2 = atk_text_get_run_attributes(childText, 15, &startOffset, &endOffset);
- g_assert_cmpint(startOffset, ==, 12);
- g_assert_cmpint(endOffset, ==, 17);
- g_assert(atkAttributeSetAttributeHasValue(set2, ATK_TEXT_ATTR_STYLE, "italic"));
-
- AtkAttributeSet* set3 = atk_text_get_run_attributes(childText, 17, &startOffset, &endOffset);
- g_assert_cmpint(startOffset, ==, 17);
- g_assert_cmpint(endOffset, ==, 40);
- g_assert(atkAttributeSetAttributeHasValue(set3, ATK_TEXT_ATTR_WEIGHT, "700"));
-
- AtkAttributeSet* set4 = atk_text_get_default_attributes(childText);
- g_assert(atkAttributeSetAttributeHasValue(set4, ATK_TEXT_ATTR_STYLE, "normal"));
- g_assert(atkAttributeSetAttributeHasValue(set4, ATK_TEXT_ATTR_JUSTIFICATION, "right"));
- g_assert(atkAttributeSetAttributeHasValue(set4, ATK_TEXT_ATTR_SIZE, "14"));
- atk_attribute_set_free(set1);
- atk_attribute_set_free(set2);
- atk_attribute_set_free(set3);
- atk_attribute_set_free(set4);
-
- g_object_unref(child);
- child = atk_object_ref_accessible_child(object, 1);
- g_assert(child && ATK_IS_TEXT(child));
- childText = ATK_TEXT(child);
-
- set1 = atk_text_get_default_attributes(childText);
- g_assert(atkAttributeSetAttributeHasValue(set1, ATK_TEXT_ATTR_FAMILY_NAME, "monospace"));
- g_assert(atkAttributeSetAttributeHasValue(set1, ATK_TEXT_ATTR_STYLE, "normal"));
- g_assert(atkAttributeSetAttributeHasValue(set1, ATK_TEXT_ATTR_STRIKETHROUGH, "false"));
- g_assert(atkAttributeSetAttributeHasValue(set1, ATK_TEXT_ATTR_WEIGHT, "400"));
- g_assert(atkAttributeSetAttributeHasValue(set1, ATK_TEXT_ATTR_FG_COLOR, "120,121,122"));
-
- set2 = atk_text_get_run_attributes(childText, 43, &startOffset, &endOffset);
- g_assert_cmpint(startOffset, ==, 43);
- g_assert_cmpint(endOffset, ==, 80);
- /* Checks that default attributes of text are not returned when called to atk_text_get_run_attributes. */
- g_assert(!atkAttributeSetAttributeHasValue(set2, ATK_TEXT_ATTR_FG_COLOR, "120,121,122"));
- g_assert(atkAttributeSetAttributeHasValue(set2, ATK_TEXT_ATTR_UNDERLINE, "single"));
- g_assert(atkAttributeSetAttributeHasValue(set2, ATK_TEXT_ATTR_BG_COLOR, "80,81,82"));
- atk_attribute_set_free(set1);
- atk_attribute_set_free(set2);
- g_object_unref(child);
-
- child = atk_object_ref_accessible_child(object, 2);
- g_assert(child && ATK_IS_TEXT(child));
- childText = ATK_TEXT(child);
-
- set1 = atk_text_get_run_attributes(childText, 0, &startOffset, &endOffset);
- set2 = atk_text_get_run_attributes(childText, 3, &startOffset, &endOffset);
- g_assert(atkAttributeSetAreEqual(set1, set2));
- atk_attribute_set_free(set2);
-
- set2 = atk_text_get_run_attributes(childText, 1, &startOffset, &endOffset);
- set3 = atk_text_get_run_attributes(childText, 5, &startOffset, &endOffset);
- g_assert(atkAttributeSetAreEqual(set2, set3));
- g_assert(!atkAttributeSetAreEqual(set1, set2));
- atk_attribute_set_free(set3);
-
- set3 = atk_text_get_run_attributes(childText, 2, &startOffset, &endOffset);
- set4 = atk_text_get_run_attributes(childText, 6, &startOffset, &endOffset);
- g_assert(atkAttributeSetAreEqual(set3, set4));
- g_assert(!atkAttributeSetAreEqual(set1, set3));
- g_assert(!atkAttributeSetAreEqual(set2, set3));
- atk_attribute_set_free(set1);
- atk_attribute_set_free(set2);
- atk_attribute_set_free(set3);
- atk_attribute_set_free(set4);
- g_object_unref(child);
-
- child = atk_object_ref_accessible_child(object, 3);
- g_assert(child && ATK_IS_TEXT(child));
- childText = ATK_TEXT(child);
- set1 = atk_text_get_run_attributes(childText, 24, &startOffset, &endOffset);
- g_assert_cmpint(startOffset, ==, 21);
- g_assert_cmpint(endOffset, ==, 25);
- g_assert(atkAttributeSetAttributeHasValue(set1, ATK_TEXT_ATTR_STRIKETHROUGH, "true"));
-
- set2 = atk_text_get_run_attributes(childText, 25, &startOffset, &endOffset);
- g_assert_cmpint(startOffset, ==, 25);
- g_assert_cmpint(endOffset, ==, 30);
- g_assert(atkAttributeSetAreEqual(set2, 0));
-
- set3 = atk_text_get_default_attributes(childText);
- g_assert(atkAttributeSetAttributeHasValue(set3, ATK_TEXT_ATTR_JUSTIFICATION, "center"));
- atk_attribute_set_free(set1);
- atk_attribute_set_free(set2);
- atk_attribute_set_free(set3);
-
- g_object_unref(child);
-}
-
-static gchar* textSelectionChangedResult = 0;
-
-static void textSelectionChangedCallback(AtkText* text, gpointer data)
-{
- g_assert(ATK_IS_TEXT(text));
-
- g_free(textSelectionChangedResult);
- AtkRole role = atk_object_get_role(ATK_OBJECT(text));
- int startOffset = 0;
- int endOffset = 0;
- atk_text_get_selection(ATK_TEXT(text), 0, &startOffset, &endOffset);
- textSelectionChangedResult = g_strdup_printf("|%s|%d|%d|", atk_role_get_name(role), startOffset, endOffset);
-}
-
-static void testWebkitAtkTextSelections()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
- webkit_web_view_load_string(webView, textForSelections, 0, 0, 0);
-
- AtkObject* object = getWebAreaObject(webView);
- g_assert(object);
-
- AtkText* paragraph1 = ATK_TEXT(atk_object_ref_accessible_child(object, 0));
- g_assert(ATK_IS_TEXT(paragraph1));
- g_signal_connect(paragraph1, "text-selection-changed", G_CALLBACK(textSelectionChangedCallback), 0);
-
- AtkText* paragraph2 = ATK_TEXT(atk_object_ref_accessible_child(object, 1));
- g_assert(ATK_IS_TEXT(paragraph2));
- g_signal_connect(paragraph2, "text-selection-changed", G_CALLBACK(textSelectionChangedCallback), 0);
-
- AtkText* link = ATK_TEXT(atk_object_ref_accessible_child(ATK_OBJECT(paragraph2), 0));
- g_assert(ATK_IS_TEXT(link));
-
- AtkObject* list = atk_object_ref_accessible_child(object, 2);
- g_assert(ATK_OBJECT(list));
-
- AtkText* listItem = ATK_TEXT(atk_object_ref_accessible_child(list, 0));
- g_assert(ATK_IS_TEXT(listItem));
-
- /* First paragraph (simple text). */
-
- /* Basic initial checks. */
- g_assert_cmpint(atk_text_get_n_selections(paragraph1), ==, 0);
-
- gint startOffset;
- gint endOffset;
- gchar* selectedText = atk_text_get_selection(paragraph1, 0, &startOffset, &endOffset);
- g_assert_cmpint(startOffset, ==, 0);
- g_assert_cmpint(endOffset, ==, 0);
- g_assert_cmpstr(selectedText, ==, 0);
- g_free (selectedText);
-
- /* Try removing a non existing (yet) selection. */
- gboolean result = atk_text_remove_selection(paragraph1, 0);
- g_assert(!result);
-
- /* Try setting a 0-char selection. */
- result = atk_text_set_selection(paragraph1, 0, 5, 5);
- g_assert(result);
-
- /* Make a selection and test it. */
- result = atk_text_set_selection(paragraph1, 0, 5, 25);
- g_assert(result);
- g_assert_cmpint(atk_text_get_n_selections(paragraph1), ==, 1);
- g_assert_cmpstr(textSelectionChangedResult, ==, "|paragraph|5|25|");
- selectedText = atk_text_get_selection(paragraph1, 0, &startOffset, &endOffset);
- g_assert_cmpint(startOffset, ==, 5);
- g_assert_cmpint(endOffset, ==, 25);
- g_assert_cmpstr(selectedText, ==, "agraph with plain te");
- g_free (selectedText);
-
- /* Try removing the selection from other AtkText object (should fail). */
- result = atk_text_remove_selection(paragraph2, 0);
- g_assert(!result);
-
- /* Remove the selection and test everything again. */
- result = atk_text_remove_selection(paragraph1, 0);
- g_assert(result);
- g_assert_cmpint(atk_text_get_n_selections(paragraph1), ==, 0);
- selectedText = atk_text_get_selection(paragraph1, 0, &startOffset, &endOffset);
- /* Now offsets should be the same, set to the last position of the caret. */
- g_assert_cmpint(startOffset, ==, endOffset);
- g_assert_cmpint(startOffset, ==, 25);
- g_assert_cmpint(endOffset, ==, 25);
- g_assert_cmpstr(selectedText, ==, 0);
- g_free (selectedText);
-
- /* Second paragraph (text + link + text). */
-
- /* Set a selection partially covering the link and test it. */
- result = atk_text_set_selection(paragraph2, 0, 7, 21);
- g_assert(result);
-
- /* Test the paragraph first. */
- g_assert_cmpint(atk_text_get_n_selections(paragraph2), ==, 1);
- selectedText = atk_text_get_selection(paragraph2, 0, &startOffset, &endOffset);
- g_assert_cmpint(startOffset, ==, 7);
- g_assert_cmpint(endOffset, ==, 21);
- g_assert_cmpstr(selectedText, ==, "raph with a li");
- g_free (selectedText);
-
- /* Now test just the link. */
- g_assert_cmpint(atk_text_get_n_selections(link), ==, 1);
- selectedText = atk_text_get_selection(link, 0, &startOffset, &endOffset);
- g_assert_cmpint(startOffset, ==, 0);
- g_assert_cmpint(endOffset, ==, 4);
- g_assert_cmpstr(selectedText, ==, "a li");
- g_free (selectedText);
-
- /* Make a selection after the link and check selection for the whole paragraph. */
- result = atk_text_set_selection(paragraph2, 0, 27, 37);
- g_assert(result);
- g_assert_cmpint(atk_text_get_n_selections(paragraph2), ==, 1);
- g_assert_cmpstr(textSelectionChangedResult, ==, "|paragraph|27|37|");
- selectedText = atk_text_get_selection(paragraph2, 0, &startOffset, &endOffset);
- g_assert_cmpint(startOffset, ==, 27);
- g_assert_cmpint(endOffset, ==, 37);
- g_assert_cmpstr(selectedText, ==, "the middle");
- g_free (selectedText);
-
- /* Remove selections and text everything again. */
- result = atk_text_remove_selection(paragraph2, 0);
- g_assert(result);
- g_assert_cmpint(atk_text_get_n_selections(paragraph2), ==, 0);
- selectedText = atk_text_get_selection(paragraph2, 0, &startOffset, &endOffset);
- /* Now offsets should be the same (no selection). */
- g_assert_cmpint(startOffset, ==, endOffset);
- g_assert_cmpstr(selectedText, ==, 0);
- g_free (selectedText);
-
- g_assert_cmpint(atk_text_get_n_selections(link), ==, 0);
- selectedText = atk_text_get_selection(link, 0, &startOffset, &endOffset);
- /* Now offsets should be the same (no selection). */
- g_assert_cmpint(startOffset, ==, endOffset);
- g_assert_cmpstr(selectedText, ==, 0);
- g_free (selectedText);
-
- /* List item */
-
- g_assert(atk_object_get_role(list) == ATK_ROLE_LIST);
- g_assert_cmpint(atk_object_get_n_accessible_children(list), ==, 1);
-
- /* It's not possible to select text inside an item's marker. */
- result = atk_text_set_selection (listItem, 0, 0, 9);
- g_assert(!result);
- result = atk_text_set_selection (listItem, 0, 9, 1);
- g_assert(!result);
-
- /* It should be possible to select text inside an item's text. */
- result = atk_text_set_selection (listItem, 0, 3, 9);
- g_assert(result);
-
- g_assert_cmpint(atk_text_get_n_selections(listItem), ==, 1);
- selectedText = atk_text_get_selection(listItem, 0, &startOffset, &endOffset);
- g_assert_cmpint(startOffset, ==, 3);
- g_assert_cmpint(endOffset, ==, 9);
- g_assert_cmpstr(selectedText, ==, "A list");
- g_free (selectedText);
-
- g_free(textSelectionChangedResult);
-
- g_object_unref(paragraph1);
- g_object_unref(paragraph2);
- g_object_unref(link);
- g_object_unref(list);
- g_object_unref(listItem);
- g_object_unref(webView);
-}
-
-static void testWebkitAtkGetExtents()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
- webkit_web_view_load_string(webView, centeredContents, 0, 0, 0);
-
- AtkObject* object = getWebAreaObject(webView);
- g_assert(object);
-
- AtkText* shortText1 = ATK_TEXT(atk_object_ref_accessible_child(object, 0));
- g_assert(ATK_IS_TEXT(shortText1));
- AtkText* longText = ATK_TEXT(atk_object_ref_accessible_child(object, 1));
- g_assert(ATK_IS_TEXT(longText));
- AtkText* shortText2 = ATK_TEXT(atk_object_ref_accessible_child(object, 2));
- g_assert(ATK_IS_TEXT(shortText2));
- AtkText* multilineText = ATK_TEXT(atk_object_ref_accessible_child(object, 3));
- g_assert(ATK_IS_TEXT(multilineText));
-
- /* Start with window extents. */
- AtkTextRectangle sline_window1, sline_window2, lline_window, mline_window;
- atk_text_get_range_extents(shortText1, 0, 10, ATK_XY_WINDOW, &sline_window1);
- atk_text_get_range_extents(longText, 0, 44, ATK_XY_WINDOW, &lline_window);
- atk_text_get_range_extents(shortText2, 0, 10, ATK_XY_WINDOW, &sline_window2);
- atk_text_get_range_extents(multilineText, 0, 60, ATK_XY_WINDOW, &mline_window);
-
- /* Check vertical line position. */
- g_assert_cmpint(sline_window1.y + sline_window1.height, <=, lline_window.y);
- g_assert_cmpint(lline_window.y + lline_window.height + sline_window2.height, <=, mline_window.y);
-
- /* Paragraphs 1 and 3 have identical text and alignment. */
- g_assert_cmpint(sline_window1.x, ==, sline_window2.x);
- g_assert_cmpint(sline_window1.width, ==, sline_window2.width);
- g_assert_cmpint(sline_window1.height, ==, sline_window2.height);
-
- /* All lines should be the same height; line 2 is the widest line. */
- g_assert_cmpint(sline_window1.height, ==, lline_window.height);
- g_assert_cmpint(sline_window1.width, <, lline_window.width);
-
- /* Make sure the character extents jive with the range extents. */
- gint x;
- gint y;
- gint width;
- gint height;
-
- /* First paragraph (short text). */
- atk_text_get_character_extents(shortText1, 0, &x, &y, &width, &height, ATK_XY_WINDOW);
- g_assert_cmpint(x, ==, sline_window1.x);
- g_assert_cmpint(y, ==, sline_window1.y);
- g_assert_cmpint(height, ==, sline_window1.height);
-
- atk_text_get_character_extents(shortText1, 9, &x, &y, &width, &height, ATK_XY_WINDOW);
- g_assert_cmpint(x, ==, sline_window1.x + sline_window1.width - width);
- g_assert_cmpint(y, ==, sline_window1.y);
- g_assert_cmpint(height, ==, sline_window1.height);
-
- /* Second paragraph (long text). */
- atk_text_get_character_extents(longText, 0, &x, &y, &width, &height, ATK_XY_WINDOW);
- g_assert_cmpint(x, ==, lline_window.x);
- g_assert_cmpint(y, ==, lline_window.y);
- g_assert_cmpint(height, ==, lline_window.height);
-
- atk_text_get_character_extents(longText, 43, &x, &y, &width, &height, ATK_XY_WINDOW);
- g_assert_cmpint(x, ==, lline_window.x + lline_window.width - width);
- g_assert_cmpint(y, ==, lline_window.y);
- g_assert_cmpint(height, ==, lline_window.height);
-
- /* Third paragraph (short text). */
- atk_text_get_character_extents(shortText2, 0, &x, &y, &width, &height, ATK_XY_WINDOW);
- g_assert_cmpint(x, ==, sline_window2.x);
- g_assert_cmpint(y, ==, sline_window2.y);
- g_assert_cmpint(height, ==, sline_window2.height);
-
- atk_text_get_character_extents(shortText2, 9, &x, &y, &width, &height, ATK_XY_WINDOW);
- g_assert_cmpint(x, ==, sline_window2.x + sline_window2.width - width);
- g_assert_cmpint(y, ==, sline_window2.y);
- g_assert_cmpint(height, ==, sline_window2.height);
-
- /* Four paragraph (3 lines multi-line text). */
- atk_text_get_character_extents(multilineText, 0, &x, &y, &width, &height, ATK_XY_WINDOW);
- g_assert_cmpint(x, ==, mline_window.x);
- g_assert_cmpint(y, ==, mline_window.y);
- g_assert_cmpint(3 * height, ==, mline_window.height);
-
- atk_text_get_character_extents(multilineText, 59, &x, &y, &width, &height, ATK_XY_WINDOW);
- /* Last line won't fill the whole width of the rectangle. */
- g_assert_cmpint(x, <=, mline_window.x + mline_window.width - width);
- g_assert_cmpint(y, ==, mline_window.y + mline_window.height - height);
- g_assert_cmpint(height, <=, mline_window.height);
-
- /* Check that extent for a full line are the same height than for
- a partial section of the same line */
- gint startOffset;
- gint endOffset;
-
-#if !ATK_CHECK_VERSION(2, 10, 0)
- gchar* text = atk_text_get_text_at_offset(multilineText, 0, ATK_TEXT_BOUNDARY_LINE_START, &startOffset, &endOffset);
- g_free(text);
-#else
- gchar* text = atk_text_get_string_at_offset(multilineText, 0, ATK_TEXT_GRANULARITY_LINE, &startOffset, &endOffset);
- g_free(text);
-#endif
-
- AtkTextRectangle fline_window;
- AtkTextRectangle afline_window;
- atk_text_get_range_extents(multilineText, startOffset, endOffset, ATK_XY_WINDOW, &fline_window);
- atk_text_get_range_extents(multilineText, startOffset, endOffset - 1, ATK_XY_WINDOW, &afline_window);
- g_assert_cmpint(fline_window.x, ==, afline_window.x);
- g_assert_cmpint(fline_window.y, ==, afline_window.y);
- g_assert_cmpint(fline_window.height, ==, afline_window.height);
-
- g_object_unref(shortText1);
- g_object_unref(shortText2);
- g_object_unref(longText);
- g_object_unref(multilineText);
- g_object_unref(webView);
-}
-
-static void testWebkitAtkLayoutAndDataTables()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
- webkit_web_view_load_string(webView, layoutAndDataTables, 0, 0, 0);
-
- AtkObject* object = getWebAreaObject(webView);
- g_assert(object);
-
- /* Check the non-layout table (data table). */
-
- AtkObject* table1 = atk_object_ref_accessible_child(object, 0);
- g_assert(ATK_IS_TABLE(table1));
- AtkAttributeSet* set1 = atk_object_get_attributes(table1);
- g_assert(set1);
- g_assert(!atkAttributeSetContainsAttributeName(set1, "layout-guess"));
- atk_attribute_set_free(set1);
-
- /* Check the layout table. */
-
- AtkObject* table2 = atk_object_ref_accessible_child(object, 1);
- g_assert(ATK_IS_TABLE(table2));
- AtkAttributeSet* set2 = atk_object_get_attributes(table2);
- g_assert(set2);
- g_assert(atkAttributeSetContainsAttributeName(set2, "layout-guess"));
- g_assert(atkAttributeSetAttributeNameHasValue(set2, "layout-guess", "true"));
- atk_attribute_set_free(set2);
-
- g_object_unref(table1);
- g_object_unref(table2);
- g_object_unref(webView);
-}
-
-static void testWebkitAtkLinksWithInlineImages()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
- webkit_web_view_load_string(webView, linksWithInlineImages, 0, 0, 0);
-
- AtkObject* object = getWebAreaObject(webView);
- g_assert(object);
-
- /* First paragraph (link at the beginning). */
- AtkObject* paragraph = atk_object_ref_accessible_child(object, 0);
- g_assert(ATK_IS_TEXT(paragraph));
- gint startOffset;
- gint endOffset;
-
-#if !ATK_CHECK_VERSION(2, 10, 0)
- gchar* text = atk_text_get_text_at_offset(ATK_TEXT(paragraph), 0, ATK_TEXT_BOUNDARY_LINE_START, &startOffset, &endOffset);
- g_assert(text);
- g_assert_cmpstr(text, ==, "foo bar baz");
- g_assert_cmpint(startOffset, ==, 0);
- g_assert_cmpint(endOffset, ==, 11);
- g_free(text);
-#else
- gchar* text = atk_text_get_string_at_offset(ATK_TEXT(paragraph), 0, ATK_TEXT_GRANULARITY_LINE, &startOffset, &endOffset);
- g_assert(text);
- g_assert_cmpstr(text, ==, "foo bar baz");
- g_assert_cmpint(startOffset, ==, 0);
- g_assert_cmpint(endOffset, ==, 11);
- g_free(text);
-#endif
-
- g_object_unref(paragraph);
-
- /* Second paragraph (link in the middle). */
- paragraph = atk_object_ref_accessible_child(object, 1);
- g_assert(ATK_IS_TEXT(paragraph));
-
-#if !ATK_CHECK_VERSION(2, 10, 0)
- text = atk_text_get_text_at_offset(ATK_TEXT(paragraph), 0, ATK_TEXT_BOUNDARY_LINE_START, &startOffset, &endOffset);
- g_assert(text);
- g_assert_cmpstr(text, ==, "foo bar baz");
- g_assert_cmpint(startOffset, ==, 0);
- g_assert_cmpint(endOffset, ==, 11);
- g_free(text);
-#else
- text = atk_text_get_string_at_offset(ATK_TEXT(paragraph), 0, ATK_TEXT_GRANULARITY_LINE, &startOffset, &endOffset);
- g_assert(text);
- g_assert_cmpstr(text, ==, "foo bar baz");
- g_assert_cmpint(startOffset, ==, 0);
- g_assert_cmpint(endOffset, ==, 11);
- g_free(text);
-#endif
-
- g_object_unref(paragraph);
-
- /* Third paragraph (link at the end). */
- paragraph = atk_object_ref_accessible_child(object, 2);
- g_assert(ATK_IS_TEXT(paragraph));
-
-#if !ATK_CHECK_VERSION(2, 10, 0)
- text = atk_text_get_text_at_offset(ATK_TEXT(paragraph), 0, ATK_TEXT_BOUNDARY_LINE_START, &startOffset, &endOffset);
- g_assert(text);
- g_assert_cmpstr(text, ==, "foo bar baz");
- g_assert_cmpint(startOffset, ==, 0);
- g_assert_cmpint(endOffset, ==, 11);
- g_free(text);
-#else
- text = atk_text_get_string_at_offset(ATK_TEXT(paragraph), 0, ATK_TEXT_GRANULARITY_LINE, &startOffset, &endOffset);
- g_assert(text);
- g_assert_cmpstr(text, ==, "foo bar baz");
- g_assert_cmpint(startOffset, ==, 0);
- g_assert_cmpint(endOffset, ==, 11);
- g_free(text);
-#endif
-
- g_object_unref(paragraph);
- g_object_unref(webView);
-}
-
-static void testWebkitAtkHypertextAndHyperlinks()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
- webkit_web_view_load_string(webView, hypertextAndHyperlinks, 0, 0, 0);
-
- AtkObject* object = getWebAreaObject(webView);
- g_assert(object);
-
- AtkObject* paragraph1 = atk_object_ref_accessible_child(object, 0);
- g_assert(ATK_OBJECT(paragraph1));
- g_assert(atk_object_get_role(paragraph1) == ATK_ROLE_PARAGRAPH);
- g_assert(ATK_IS_HYPERTEXT(paragraph1));
-
- /* No links in the first paragraph. */
- gint nLinks = atk_hypertext_get_n_links(ATK_HYPERTEXT(paragraph1));
- g_assert_cmpint(nLinks, ==, 0);
-
- AtkObject* paragraph2 = atk_object_ref_accessible_child(object, 1);
- g_assert(ATK_OBJECT(paragraph2));
- g_assert(atk_object_get_role(paragraph2) == ATK_ROLE_PARAGRAPH);
- g_assert(ATK_IS_HYPERTEXT(paragraph2));
-
- /* Check links in the second paragraph.
- nLinks = atk_hypertext_get_n_links(ATK_HYPERTEXT(paragraph2));
- g_assert_cmpint(nLinks, ==, 3); */
-
- AtkHyperlink* hLink1 = atk_hypertext_get_link(ATK_HYPERTEXT(paragraph2), 0);
- g_assert(ATK_HYPERLINK(hLink1));
- AtkObject* hLinkObject1 = atk_hyperlink_get_object(hLink1, 0);
- g_assert(ATK_OBJECT(hLinkObject1));
- g_assert(atk_object_get_role(hLinkObject1) == ATK_ROLE_LINK);
- g_assert_cmpint(atk_hyperlink_get_start_index(hLink1), ==, 0);
- g_assert_cmpint(atk_hyperlink_get_end_index(hLink1), ==, 6);
- g_assert_cmpint(atk_hyperlink_get_n_anchors(hLink1), ==, 1);
- g_assert_cmpstr(atk_hyperlink_get_uri(hLink1, 0), ==, "http://foo.bar.baz/");
-
- AtkHyperlink* hLink2 = atk_hypertext_get_link(ATK_HYPERTEXT(paragraph2), 1);
- g_assert(ATK_HYPERLINK(hLink2));
- AtkObject* hLinkObject2 = atk_hyperlink_get_object(hLink2, 0);
- g_assert(ATK_OBJECT(hLinkObject2));
- g_assert(atk_object_get_role(hLinkObject2) == ATK_ROLE_LINK);
- g_assert_cmpint(atk_hyperlink_get_start_index(hLink2), ==, 12);
- g_assert_cmpint(atk_hyperlink_get_end_index(hLink2), ==, 32);
- g_assert_cmpint(atk_hyperlink_get_n_anchors(hLink2), ==, 1);
- g_assert_cmpstr(atk_hyperlink_get_uri(hLink2, 0), ==, "http://bar.baz.foo/");
-
- AtkHyperlink* hLink3 = atk_hypertext_get_link(ATK_HYPERTEXT(paragraph2), 2);
- g_assert(ATK_HYPERLINK(hLink3));
- AtkObject* hLinkObject3 = atk_hyperlink_get_object(hLink3, 0);
- g_assert(ATK_OBJECT(hLinkObject3));
- g_assert(atk_object_get_role(hLinkObject3) == ATK_ROLE_LINK);
- g_assert_cmpint(atk_hyperlink_get_start_index(hLink3), ==, 65);
- g_assert_cmpint(atk_hyperlink_get_end_index(hLink3), ==, 75);
- g_assert_cmpint(atk_hyperlink_get_n_anchors(hLink3), ==, 1);
- g_assert_cmpstr(atk_hyperlink_get_uri(hLink3, 0), ==, "http://baz.foo.bar/");
-
- AtkObject* list = atk_object_ref_accessible_child(object, 2);
- g_assert(ATK_OBJECT(list));
- g_assert(atk_object_get_role(list) == ATK_ROLE_LIST);
- g_assert_cmpint(atk_object_get_n_accessible_children(list), ==, 1);
-
- AtkObject* listItem = atk_object_ref_accessible_child(list, 0);
- g_assert(ATK_IS_TEXT(listItem));
- g_assert(ATK_IS_HYPERTEXT(listItem));
-
- AtkHyperlink* hLinkInListItem = atk_hypertext_get_link(ATK_HYPERTEXT(listItem), 0);
- g_assert(ATK_HYPERLINK(hLinkInListItem));
- AtkObject* hLinkObject = atk_hyperlink_get_object(hLinkInListItem, 0);
- g_assert(ATK_OBJECT(hLinkObject));
- g_assert(atk_object_get_role(hLinkObject) == ATK_ROLE_LINK);
- g_assert_cmpint(atk_hyperlink_get_start_index(hLinkInListItem), ==, 20);
- g_assert_cmpint(atk_hyperlink_get_end_index(hLinkInListItem), ==, 43);
- g_assert_cmpint(atk_hyperlink_get_n_anchors(hLinkInListItem), ==, 1);
- g_assert_cmpstr(atk_hyperlink_get_uri(hLinkInListItem, 0), ==, "http://foo.bar.baz/");
-
- /* Finally check the AtkAction interface for a given AtkHyperlink. */
- g_assert(ATK_IS_ACTION(hLink1));
- g_assert_cmpint(atk_action_get_n_actions(ATK_ACTION(hLink1)), ==, 1);
- g_assert_cmpstr(atk_action_get_keybinding(ATK_ACTION(hLink1), 0), ==, "");
- g_assert_cmpstr(atk_action_get_name(ATK_ACTION(hLink1), 0), ==, "jump");
- g_assert(atk_action_do_action(ATK_ACTION(hLink1), 0));
-
- g_object_unref(paragraph1);
- g_object_unref(paragraph2);
- g_object_unref(list);
- g_object_unref(listItem);
- g_object_unref(webView);
-}
-
-static void testWebkitAtkListsOfItems()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
- webkit_web_view_load_string(webView, listsOfItems, 0, 0, 0);
-
- AtkObject* object = getWebAreaObject(webView);
- g_assert(object);
-
- /* Unordered list. */
-
- AtkObject* uList = atk_object_ref_accessible_child(object, 0);
- g_assert(ATK_OBJECT(uList));
- g_assert(atk_object_get_role(uList) == ATK_ROLE_LIST);
- g_assert_cmpint(atk_object_get_n_accessible_children(uList), ==, 3);
-
- AtkObject* item1 = atk_object_ref_accessible_child(uList, 0);
- AtkObject* item2 = atk_object_ref_accessible_child(uList, 1);
- AtkObject* item3 = atk_object_ref_accessible_child(uList, 2);
-
- g_assert_cmpint(atk_object_get_n_accessible_children(item1), ==, 0);
- g_assert_cmpint(atk_object_get_n_accessible_children(item2), ==, 1);
- g_assert_cmpint(atk_object_get_n_accessible_children(item3), ==, 1);
-
- g_object_unref(item1);
- g_object_unref(item2);
- g_object_unref(item3);
-
- /* Ordered list. */
-
- AtkObject* oList = atk_object_ref_accessible_child(object, 1);
- g_assert(ATK_OBJECT(oList));
- g_assert(atk_object_get_role(oList) == ATK_ROLE_LIST);
- g_assert_cmpint(atk_object_get_n_accessible_children(oList), ==, 3);
-
- item1 = atk_object_ref_accessible_child(oList, 0);
- item2 = atk_object_ref_accessible_child(oList, 1);
- item3 = atk_object_ref_accessible_child(oList, 2);
-
- g_assert_cmpint(atk_object_get_n_accessible_children(item1), ==, 0);
- g_assert_cmpint(atk_object_get_n_accessible_children(item2), ==, 1);
- g_assert_cmpint(atk_object_get_n_accessible_children(item3), ==, 1);
-
- g_object_unref(item1);
- g_object_unref(item2);
- g_object_unref(item3);
-
- g_object_unref(uList);
- g_object_unref(oList);
- g_object_unref(webView);
-}
-
-typedef enum {
- TEXT_CHANGE_INSERT = 1,
- TEXT_CHANGE_REMOVE = 2
-} TextChangeType;
-
-static gchar* textChangedResult = 0;
-
-static void textChangedCb(AtkText* text, gint pos, gint len, gchar* modifiedText, gpointer data)
-{
- g_assert(text && ATK_IS_OBJECT(text));
-
- TextChangeType type = GPOINTER_TO_INT(data);
- g_free(textChangedResult);
- textChangedResult = g_strdup_printf("|%d|%d|%d|'%s'|", type, pos, len, modifiedText);
-}
-
-static void testWebkitAtkTextChangedNotifications()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
- webkit_web_view_load_string(webView, formWithTextInputs, 0, 0, 0);
-
- AtkObject* object = getWebAreaObject(webView);
- g_assert(object);
-
- AtkObject* form = atk_object_ref_accessible_child(object, 0);
- g_assert(ATK_IS_OBJECT(form));
-
- /* First check normal text entries. */
- AtkObject* textEntry = atk_object_ref_accessible_child(form, 0);
- g_assert(ATK_IS_EDITABLE_TEXT(textEntry));
- g_assert(atk_object_get_role(ATK_OBJECT(textEntry)) == ATK_ROLE_ENTRY);
-
- g_signal_connect(textEntry, "text-insert",
- G_CALLBACK(textChangedCb),
- GINT_TO_POINTER(TEXT_CHANGE_INSERT));
- g_signal_connect(textEntry, "text-remove",
- G_CALLBACK(textChangedCb),
- GINT_TO_POINTER(TEXT_CHANGE_REMOVE));
-
- gint pos = 0;
- atk_editable_text_insert_text(ATK_EDITABLE_TEXT(textEntry), "foo bar baz", 11, &pos);
- char* text = atk_text_get_text(ATK_TEXT(textEntry), 0, -1);
- g_assert_cmpstr(text, ==, "foo bar baz");
- g_assert_cmpstr(textChangedResult, ==, "|1|0|11|'foo bar baz'|");
- g_free(text);
-
- atk_editable_text_delete_text(ATK_EDITABLE_TEXT(textEntry), 4, 7);
- text = atk_text_get_text(ATK_TEXT(textEntry), 0, -1);
- g_assert_cmpstr(text, ==, "foo baz");
- g_assert_cmpstr(textChangedResult, ==, "|2|4|3|'bar'|");
- g_free(text);
-
- pos = 4;
- atk_editable_text_insert_text(ATK_EDITABLE_TEXT(textEntry), "qux quux tobeignored", 8, &pos);
- text = atk_text_get_text(ATK_TEXT(textEntry), 0, -1);
- g_assert_cmpstr(text, ==, "foo qux quux baz");
- g_assert_cmpstr(textChangedResult, ==, "|1|4|8|'qux quux'|");
- g_free(text);
-
- /* Now check for password entries. */
- AtkObject* passwordEntry = atk_object_ref_accessible_child(form, 1);
- g_assert(ATK_IS_EDITABLE_TEXT(passwordEntry));
- g_assert(atk_object_get_role(ATK_OBJECT(passwordEntry)) == ATK_ROLE_PASSWORD_TEXT);
-
- g_signal_connect(passwordEntry, "text-insert",
- G_CALLBACK(textChangedCb),
- GINT_TO_POINTER(TEXT_CHANGE_INSERT));
- g_signal_connect(passwordEntry, "text-remove",
- G_CALLBACK(textChangedCb),
- GINT_TO_POINTER(TEXT_CHANGE_REMOVE));
-
- pos = 0;
- /* A single bullet character is '\342\200\242' */
- atk_editable_text_insert_text(ATK_EDITABLE_TEXT(passwordEntry), "foobar", 6, &pos);
- g_assert_cmpstr(textChangedResult, ==, "|1|0|6|'\342\200\242\342\200\242\342\200\242\342\200\242\342\200\242\342\200\242'|");
- text = atk_text_get_text(ATK_TEXT(passwordEntry), 0, -1);
- g_assert_cmpstr(text, ==, "\342\200\242\342\200\242\342\200\242\342\200\242\342\200\242\342\200\242");
- g_free(text);
-
- atk_editable_text_delete_text(ATK_EDITABLE_TEXT(passwordEntry), 2, 4);
- g_assert_cmpstr(textChangedResult, ==, "|2|2|2|'\342\200\242\342\200\242'|");
-
- text = atk_text_get_text(ATK_TEXT(passwordEntry), 0, -1);
- g_assert_cmpstr(text, ==, "\342\200\242\342\200\242\342\200\242\342\200\242");
- g_free(text);
-
- pos = 3;
- atk_editable_text_insert_text(ATK_EDITABLE_TEXT(passwordEntry), "qux tobeignored", 3, &pos);
- g_assert_cmpstr(textChangedResult, ==, "|1|3|3|'\342\200\242\342\200\242\342\200\242'|");
-
- text = atk_text_get_text(ATK_TEXT(passwordEntry), 0, -1);
- g_assert_cmpstr(text, ==, "\342\200\242\342\200\242\342\200\242\342\200\242\342\200\242\342\200\242\342\200\242");
- g_free(text);
-
- g_free(textChangedResult);
-
- g_object_unref(form);
- g_object_unref(textEntry);
- g_object_unref(passwordEntry);
- g_object_unref(webView);
-}
-
-static void testWebkitAtkParentForRootObject()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
- webkit_web_view_load_string(webView, contents, 0, 0, 0);
-
- /* We need a parent container widget for the webview. */
- GtkWidget* parentContainer = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- g_object_ref_sink(parentContainer);
- gtk_container_add(GTK_CONTAINER(parentContainer), GTK_WIDGET(webView));
-
- AtkObject* axParent = gtk_widget_get_accessible(parentContainer);
- g_assert(ATK_IS_OBJECT(axParent));
-
- AtkObject* axRoot = gtk_widget_get_accessible(GTK_WIDGET(webView));
- g_assert(ATK_IS_OBJECT(axRoot));
-
- /* The child for the parent container's accessibility object
- should be the accessibility object for the WebView's root. */
- AtkObject* axParentChild = atk_object_ref_accessible_child(axParent, 0);
- g_assert(axParentChild == axRoot);
-
- /* Bottom-up navigation should match top-down one. */
- g_assert(atk_object_get_parent(axParentChild) == axParent);
-
- g_object_unref(axParentChild);
- g_object_unref(parentContainer);
-}
-
-static void testWebkitAtkSetParentForObject()
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- GtkAllocation allocation = { 0, 0, 800, 600 };
- gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
- webkit_web_view_load_string(webView, contents, 0, 0, 0);
-
- /* Put the webview in a parent container widget to check that the
- normal behaviour keeps working as expected by default. */
- GtkWidget* parentContainer = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- g_object_ref_sink(parentContainer);
- gtk_container_add(GTK_CONTAINER(parentContainer), GTK_WIDGET(webView));
-
- AtkObject* axRoot = gtk_widget_get_accessible(GTK_WIDGET(webView));
- g_assert(ATK_IS_OBJECT(axRoot));
-
- AtkObject* axParent = gtk_widget_get_accessible(parentContainer);
- g_assert(ATK_IS_OBJECT(axParent));
-
- /* The parent of the root object is the parent container's a11y object. */
- g_assert(atk_object_get_parent(axRoot) == axParent);
-
- /* We now need to use something as a an alternative parent for
- the a11y object associated with the root of the DOM tree. */
- GtkWidget* alternativeParent = gtk_button_new();
- g_object_ref_sink(alternativeParent);
-
- AtkObject* axAlternativeParent = gtk_widget_get_accessible(alternativeParent);
- g_assert(ATK_IS_OBJECT(axAlternativeParent));
-
- /* Manually set the alternative parent's accessibility object as
- the parent for the WebKit accessibility root object and check. */
- atk_object_set_parent(axRoot, axAlternativeParent);
- g_assert(atk_object_get_parent(axRoot) == axAlternativeParent);
-
- g_object_unref(alternativeParent);
- g_object_unref(parentContainer);
-}
-
-#ifdef GTK_API_VERSION_2
-static void initializeTestingFramework(int argc, char** argv)
-{
- /* Ensure GAIL is the only module loaded. */
- g_setenv("GTK_MODULES", "gail", TRUE);
-
- /* Following lines were taken from gtk_test_init(). */
- g_test_init(&argc, &argv, 0);
- gtk_disable_setlocale();
- setlocale(LC_ALL, "C");
-
- gtk_init(&argc, &argv);
-}
-#endif
-
-int main(int argc, char** argv)
-{
-#ifdef GTK_API_VERSION_2
- /* We can't just call to gtk_test_init() in this case because its
- implementation makes sure that no GTK+ module will be loaded, and
- we will need to load GAIL for tests that need to use AtkObjects
- from non-WebKit GtkWidgets (e.g parentForRootObject).*/
- initializeTestingFramework(argc, argv);
-#else
- gtk_test_init(&argc, &argv, NULL);
-#endif
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_func("/webkit/atk/caretOffsets", testWebkitAtkCaretOffsets);
- g_test_add_func("/webkit/atk/caretOffsetsAndExtranousWhiteSpaces", testWebkitAtkCaretOffsetsAndExtranousWhiteSpaces);
- g_test_add_func("/webkit/atk/comboBox", testWebkitAtkComboBox);
- g_test_add_func("/webkit/atk/documentLoadingEvents", testWebkitAtkDocumentLoadingEvents);
- g_test_add_func("/webkit/atk/embeddedObjects", testWebkitAtkEmbeddedObjects);
- g_test_add_func("/webkit/atk/getHeadersInTable", testWebkitAtkGetHeadersInTable);
- g_test_add_func("/webkit/atk/textAttributes", testWebkitAtkTextAttributes);
- g_test_add_func("/webkit/atk/textSelections", testWebkitAtkTextSelections);
- g_test_add_func("/webkit/atk/getExtents", testWebkitAtkGetExtents);
- g_test_add_func("/webkit/atk/hypertextAndHyperlinks", testWebkitAtkHypertextAndHyperlinks);
- g_test_add_func("/webkit/atk/layoutAndDataTables", testWebkitAtkLayoutAndDataTables);
- g_test_add_func("/webkit/atk/linksWithInlineImages", testWebkitAtkLinksWithInlineImages);
- g_test_add_func("/webkit/atk/listsOfItems", testWebkitAtkListsOfItems);
- g_test_add_func("/webkit/atk/textChangedNotifications", testWebkitAtkTextChangedNotifications);
- g_test_add_func("/webkit/atk/parentForRootObject", testWebkitAtkParentForRootObject);
- g_test_add_func("/webkit/atk/setParentForObject", testWebkitAtkSetParentForObject);
- return g_test_run ();
-}
-
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testatkroles.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testatkroles.c
deleted file mode 100644
index 88817cf8a..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testatkroles.c
+++ /dev/null
@@ -1,426 +0,0 @@
-/*
- * Copyright © 2010 Joanmarie Diggs
- * Copyright © 2010 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-/* Non form roles */
-#define HTML_DOCUMENT_FRAME "<html><body>This is a test.</body></html>"
-#define HTML_HEADING "<html><body><h1>1</h1><h2>2</h2><h3>3</h3><h4>4</h4><h5>5</h5><h6>6</h6></body></html>"
-#define HTML_IMAGE "<html><body><img src='foobar.png' alt='This is a test.'/></body></html>"
-#define HTML_LINK_TEXT "<html><body><a href='foobar.html'>This is a test.</a></body></html>"
-#define HTML_LIST "<html><body><ul><li>1</li><li>2</li></ul><ol><li>1</li><li>2</li></ol></body></html>"
-#define HTML_PARAGRAPH "<html><body><p>This is a test.</p></body></html>"
-#define HTML_SECTION "<html><body><div>This is a test.</div></body></html>"
-#define HTML_TABLE "<html><body><table border='1'><tr><td>This is</td><td>a test.</td></tr></table></body></html>"
-#define HTML_SEPARATOR "<html><body><hr/></body></html>"
-#define HTML_COMBOBOX "<html><body><select size='1'><option>one</option><option>two</option><option>three</option></select></body></html>"
-/* Form roles */
-#define HTML_FORM "<html><body><form>This is a test.</form></body></html>"
-#define HTML_CHECK_BOX "<html><body><input type='checkbox' />This is a test.</body></html>"
-#define HTML_LABELED_ENTRY "<html><body><label for='foo'>Name:</label><input type='text' id='foo' /></body></html>"
-#define HTML_LISTBOX "<html><body><select size='3'><option>one</option><option>two</option><option>three</option></select></body></html>"
-#define HTML_PASSWORD_TEXT "<html><body><input type='password' /></body></html>"
-#define HTML_PUSH_BUTTON "<html><body><input type='submit' value='ok' />This is a test.</body></html>"
-#define HTML_RADIO_BUTTON "<html><body><input type='radio' />This is a test.</body></html>"
-
-typedef struct {
- AtkObject* document;
- AtkObject* obj;
- AtkRole role;
- GtkWidget* webView;
- GtkAllocation alloc;
- GMainLoop* loop;
-} AtkRolesFixture;
-
-static gboolean finish_loading(AtkRolesFixture* fixture)
-{
- if (g_main_loop_is_running(fixture->loop))
- g_main_loop_quit(fixture->loop);
-
- // With the change to support WK2 accessibility, the root object
- // has changed and it's no longer the document frame, but a scroll
- // pane containing the document frame as its only child. See the
- // bug 72390 for more details on this change.
- // https://bugs.webkit.org/show_bug.cgi?id=72390
- AtkObject* rootObject = gtk_widget_get_accessible(fixture->webView);
- fixture->document = atk_object_ref_accessible_child(rootObject, 0);
- g_assert(fixture->document);
-
- // Remove the reference added by ref_accessible_child() and
- // return, since we don't need to keep that extra ref at all.
- g_object_unref(fixture->document);
- return FALSE;
-}
-
-static void atk_roles_fixture_setup(AtkRolesFixture* fixture, gconstpointer data)
-{
- fixture->loop = g_main_loop_new(NULL, TRUE);
- fixture->alloc = (GtkAllocation) { 0, 0, 800, 600 };
- fixture->webView = webkit_web_view_new();
- g_object_ref_sink(fixture->webView);
-
- gtk_widget_size_allocate(fixture->webView, &fixture->alloc);
-
- if (data != NULL)
- webkit_web_view_load_string(WEBKIT_WEB_VIEW (fixture->webView), (const char*) data, NULL, NULL, NULL);
-
- g_idle_add((GSourceFunc) finish_loading, fixture);
- g_main_loop_run(fixture->loop);
-}
-
-static void atk_roles_fixture_teardown(AtkRolesFixture* fixture, gconstpointer data)
-{
- g_object_unref(fixture->webView);
- g_main_loop_unref(fixture->loop);
-}
-
-static void get_child_and_test_role(AtkObject* obj, gint pos, AtkRole role)
-{
- AtkObject* child;
- AtkRole child_role;
-
- child = atk_object_ref_accessible_child(obj, pos);
- g_assert(child);
- child_role = atk_object_get_role(child);
- g_assert(child_role == role);
-
- g_object_unref(child);
-}
-
-static void test_webkit_atk_get_role_document_frame(AtkRolesFixture* fixture, gconstpointer data)
-{
- fixture->role = atk_object_get_role(fixture->document);
- g_assert(fixture->role == ATK_ROLE_DOCUMENT_WEB);
-}
-
-static void test_webkit_atk_get_role_heading(AtkRolesFixture* fixture, gconstpointer data)
-{
- get_child_and_test_role(fixture->document, 0, ATK_ROLE_HEADING);
- get_child_and_test_role(fixture->document, 1, ATK_ROLE_HEADING);
- get_child_and_test_role(fixture->document, 2, ATK_ROLE_HEADING);
- get_child_and_test_role(fixture->document, 3, ATK_ROLE_HEADING);
- get_child_and_test_role(fixture->document, 4, ATK_ROLE_HEADING);
- get_child_and_test_role(fixture->document, 5, ATK_ROLE_HEADING);
-}
-
-static void test_webkit_atk_get_role_image(AtkRolesFixture* fixture, gconstpointer data)
-{
- // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
- fixture->obj = atk_object_ref_accessible_child(fixture->document, 0);
- g_assert(fixture->obj);
-
- get_child_and_test_role(fixture->obj, 0, ATK_ROLE_IMAGE);
-
- g_object_unref(fixture->obj);
-}
-
-static void test_webkit_atk_get_role_link(AtkRolesFixture* fixture, gconstpointer data)
-{
- // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
- fixture->obj = atk_object_ref_accessible_child(fixture->document, 0);
- g_assert(fixture->obj);
-
- get_child_and_test_role(fixture->obj, 0, ATK_ROLE_LINK);
-
- g_object_unref(fixture->obj);
-}
-
-static void test_webkit_atk_get_role_list_and_item(AtkRolesFixture* fixture, gconstpointer data)
-{
- AtkObject* listObj;
-
- listObj = atk_object_ref_accessible_child(fixture->document, 0);
- g_assert(listObj);
- fixture->role = atk_object_get_role(listObj);
- g_assert(fixture->role == ATK_ROLE_LIST);
-
- get_child_and_test_role(listObj, 0, ATK_ROLE_LIST_ITEM);
- get_child_and_test_role(listObj, 1, ATK_ROLE_LIST_ITEM);
- g_object_unref(listObj);
-
- listObj = atk_object_ref_accessible_child(fixture->document, 1);
- g_assert(listObj);
- fixture->role = atk_object_get_role(listObj);
- g_assert(fixture->role == ATK_ROLE_LIST);
-
- get_child_and_test_role(listObj, 0, ATK_ROLE_LIST_ITEM);
- get_child_and_test_role(listObj, 1, ATK_ROLE_LIST_ITEM);
- g_object_unref(listObj);
-}
-
-static void test_webkit_atk_get_role_paragraph(AtkRolesFixture* fixture, gconstpointer data)
-{
- get_child_and_test_role(fixture->document, 0, ATK_ROLE_PARAGRAPH);
-}
-
-static void test_webkit_atk_get_role_section(AtkRolesFixture* fixture, gconstpointer data)
-{
- get_child_and_test_role(fixture->document, 0, ATK_ROLE_SECTION);
-}
-
-// Does not yet test table cells because of bug 30895.
-static void test_webkit_atk_get_role_table(AtkRolesFixture* fixture, gconstpointer data)
-{
- get_child_and_test_role(fixture->document, 0, ATK_ROLE_TABLE);
-}
-
-static void test_webkit_atk_get_role_separator(AtkRolesFixture *fixture, gconstpointer data)
-{
- get_child_and_test_role(fixture->document, 0, ATK_ROLE_SEPARATOR);
-}
-
-static void test_webkit_atk_get_role_combobox(AtkRolesFixture *fixture, gconstpointer data)
-{
- AtkObject* comboboxMenu;
-
- // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
- fixture->obj = atk_object_ref_accessible_child(fixture->document, 0);
- g_assert(fixture->obj);
-
- fixture->obj = atk_object_ref_accessible_child(fixture->obj, 0);
- g_assert(fixture->obj);
- fixture->role = atk_object_get_role(fixture->obj);
- g_assert(fixture->role == ATK_ROLE_COMBO_BOX);
-
- comboboxMenu = atk_object_ref_accessible_child(fixture->obj, 0);
- g_assert(comboboxMenu);
- fixture->role = atk_object_get_role(comboboxMenu);
- g_assert(fixture->role == ATK_ROLE_MENU);
-
- get_child_and_test_role(comboboxMenu, 0, ATK_ROLE_MENU_ITEM);
- get_child_and_test_role(comboboxMenu, 1, ATK_ROLE_MENU_ITEM);
- get_child_and_test_role(comboboxMenu, 2, ATK_ROLE_MENU_ITEM);
-
- g_object_unref(fixture->obj);
- g_object_unref(comboboxMenu);
-}
-
-/* Form roles */
-static void test_webkit_atk_get_role_form(AtkRolesFixture *fixture, gconstpointer data)
-{
- get_child_and_test_role(fixture->document, 0, ATK_ROLE_FORM);
-}
-
-static void test_webkit_atk_get_role_check_box(AtkRolesFixture* fixture, gconstpointer data)
-{
- // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
- fixture->obj = atk_object_ref_accessible_child(fixture->document, 0);
- g_assert(fixture->obj);
-
- get_child_and_test_role(fixture->obj, 0, ATK_ROLE_CHECK_BOX);
-
- g_object_unref(fixture->obj);
-}
-
-static void test_webkit_atk_get_role_entry(AtkRolesFixture* fixture, gconstpointer data)
-{
- // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
- fixture->obj = atk_object_ref_accessible_child(fixture->document, 0);
- g_assert(fixture->obj);
-
- get_child_and_test_role(fixture->obj, 1, ATK_ROLE_ENTRY);
-
- g_object_unref(fixture->obj);
-}
-
-static void test_webkit_atk_get_role_label(AtkRolesFixture* fixture, gconstpointer data)
-{
- // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
- fixture->obj = atk_object_ref_accessible_child(fixture->document, 0);
- g_assert(fixture->obj);
-
- get_child_and_test_role(fixture->obj, 0, ATK_ROLE_LABEL);
-
- g_object_unref(fixture->obj);
-}
-
-static void test_webkit_atk_get_role_listbox(AtkRolesFixture* fixture, gconstpointer data)
-{
- AtkObject* listboxObj;
- // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
- fixture->obj = atk_object_ref_accessible_child(fixture->document, 0);
- g_assert(fixture->obj);
-
- listboxObj = atk_object_ref_accessible_child(fixture->obj, 0);
- g_assert(listboxObj);
- fixture->role = atk_object_get_role(listboxObj);
- g_assert(fixture->role == ATK_ROLE_LIST);
-
- get_child_and_test_role(listboxObj, 0, ATK_ROLE_LIST_ITEM);
- get_child_and_test_role(listboxObj, 1, ATK_ROLE_LIST_ITEM);
- get_child_and_test_role(listboxObj, 2, ATK_ROLE_LIST_ITEM);
-
- g_object_unref(fixture->obj);
- g_object_unref(listboxObj);
-}
-
-static void test_webkit_atk_get_role_password_text(AtkRolesFixture* fixture, gconstpointer data)
-{
- // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
- fixture->obj = atk_object_ref_accessible_child(fixture->document, 0);
- g_assert(fixture->obj);
-
- get_child_and_test_role(fixture->obj, 0, ATK_ROLE_PASSWORD_TEXT);
-
- g_object_unref(fixture->obj);
-}
-
-static void test_webkit_atk_get_role_push_button(AtkRolesFixture* fixture, gconstpointer data)
-{
- // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
- fixture->obj = atk_object_ref_accessible_child(fixture->document, 0);
- g_assert(fixture->obj);
-
- get_child_and_test_role(fixture->obj, 0, ATK_ROLE_PUSH_BUTTON);
-
- g_object_unref(fixture->obj);
-}
-
-static void test_webkit_atk_get_role_radio_button(AtkRolesFixture* fixture, gconstpointer data)
-{
- // This is an extraneous object of ATK_ROLE_PANEL which we should get rid of.
- fixture->obj = atk_object_ref_accessible_child(fixture->document, 0);
- g_assert(fixture->obj);
-
- get_child_and_test_role(fixture->obj, 0, ATK_ROLE_RADIO_BUTTON);
-
- g_object_unref(fixture->obj);
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_document_frame",
- AtkRolesFixture, HTML_DOCUMENT_FRAME,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_document_frame,
- atk_roles_fixture_teardown);
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_heading",
- AtkRolesFixture, HTML_HEADING,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_heading,
- atk_roles_fixture_teardown);
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_image",
- AtkRolesFixture, HTML_IMAGE,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_image,
- atk_roles_fixture_teardown);
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_link",
- AtkRolesFixture, HTML_LINK_TEXT,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_link,
- atk_roles_fixture_teardown);
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_list_and_item",
- AtkRolesFixture, HTML_LIST,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_list_and_item,
- atk_roles_fixture_teardown);
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_paragraph",
- AtkRolesFixture, HTML_PARAGRAPH,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_paragraph,
- atk_roles_fixture_teardown);
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_section",
- AtkRolesFixture, HTML_SECTION,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_section,
- atk_roles_fixture_teardown);
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_table",
- AtkRolesFixture, HTML_TABLE,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_table,
- atk_roles_fixture_teardown);
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_separator",
- AtkRolesFixture, HTML_SEPARATOR,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_separator,
- atk_roles_fixture_teardown);
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_combobox",
- AtkRolesFixture, HTML_COMBOBOX,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_combobox,
- atk_roles_fixture_teardown);
-
- /* Form roles */
- g_test_add("/webkit/atk/test_webkit_atk_get_role_form",
- AtkRolesFixture, HTML_FORM,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_form,
- atk_roles_fixture_teardown);
- g_test_add("/webkit/atk/test_webkit_atk_get_role_check_box",
- AtkRolesFixture, HTML_CHECK_BOX,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_check_box,
- atk_roles_fixture_teardown);
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_entry",
- AtkRolesFixture, HTML_LABELED_ENTRY,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_entry,
- atk_roles_fixture_teardown);
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_label",
- AtkRolesFixture, HTML_LABELED_ENTRY,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_label,
- atk_roles_fixture_teardown);
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_listbox",
- AtkRolesFixture, HTML_LISTBOX,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_listbox,
- atk_roles_fixture_teardown);
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_password_text",
- AtkRolesFixture, HTML_PASSWORD_TEXT,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_password_text,
- atk_roles_fixture_teardown);
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_push_button",
- AtkRolesFixture, HTML_PUSH_BUTTON,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_push_button,
- atk_roles_fixture_teardown);
-
- g_test_add("/webkit/atk/test_webkit_atk_get_role_radio_button",
- AtkRolesFixture, HTML_RADIO_BUTTON,
- atk_roles_fixture_setup,
- test_webkit_atk_get_role_radio_button,
- atk_roles_fixture_teardown);
-
- return g_test_run();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testcontextmenu.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testcontextmenu.c
deleted file mode 100644
index bc941a756..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testcontextmenu.c
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- * Copyright (C) 2012 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2,1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include <webkit/webkit.h>
-
-typedef struct {
- char *data;
- guint flag;
-} TestInfo;
-
-static GMainLoop *loop;
-
-typedef struct {
- WebKitWebView *webView;
- TestInfo *info;
-} ContextMenuFixture;
-
-static TestInfo *testInfoNew(const char *data, guint flag)
-{
- TestInfo *info = g_slice_new(TestInfo);
- info->data = g_strdup(data);
- info->flag = flag;
-
- return info;
-}
-
-static void testInfoDestroy(TestInfo *info)
-{
- g_free(info->data);
- g_slice_free(TestInfo, info);
-}
-
-static void contextMenuFixtureSetup(ContextMenuFixture *fixture, gconstpointer data)
-{
- fixture->webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- loop = g_main_loop_new(NULL, TRUE);
- fixture->info = (TestInfo *)data;
-}
-
-static void contextMenuFixtureTeardown(ContextMenuFixture *fixture, gconstpointer data)
-{
- g_object_unref(fixture->webView);
- g_main_loop_unref(loop);
- testInfoDestroy(fixture->info);
-}
-
-static GList *checkAction(GList *iter, WebKitContextMenuAction action)
-{
- GtkMenuItem *item = (GtkMenuItem *)iter->data;
-
- g_assert(GTK_IS_MENU_ITEM(item));
- g_assert(webkit_context_menu_item_get_action(item) == action);
-
- return iter->next;
-}
-
-static GList *checkActionWithSubmenu(GList *iter, WebKitContextMenuAction action)
-{
- GtkMenuItem *item = (GtkMenuItem *)iter->data;
-
- g_assert(GTK_IS_MENU_ITEM(item));
- g_assert(webkit_context_menu_item_get_action(item) == action);
- g_assert(GTK_IS_MENU(gtk_menu_item_get_submenu(item)));
-
- return iter->next;
-}
-
-static GList *checkSeparator(GList *iter)
-{
- GtkMenuItem *item = (GtkMenuItem *)iter->data;
-
- g_assert(GTK_IS_SEPARATOR_MENU_ITEM(item));
-
- return iter->next;
-}
-
-static gboolean contextMenuCallback(WebKitWebView *webView, GtkWidget *defaultMenu, WebKitHitTestResult *hitTestResult, gboolean keyboardMode, gpointer userData)
-{
- TestInfo *info = (TestInfo *)userData;
- guint context;
- GList *items;
- GList *iter;
-
- /* Check signal parameters */
- g_assert(WEBKIT_IS_WEB_VIEW(webView));
- g_assert(GTK_IS_MENU(defaultMenu));
- g_assert(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult));
- g_assert(!keyboardMode);
-
- g_object_get(hitTestResult, "context", &context, NULL);
- g_assert(context & info->flag);
-
- items = gtk_container_get_children(GTK_CONTAINER(defaultMenu));
- switch (info->flag) {
- case WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT:
- iter = items;
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_GO_BACK);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_GO_FORWARD);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_STOP);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_RELOAD);
- g_assert(!iter);
-
- break;
- case WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE:
- iter = items;
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_IMAGE_IN_NEW_WINDOW);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_IMAGE_TO_DISK);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_COPY_IMAGE_TO_CLIPBOARD);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_COPY_IMAGE_URL_TO_CLIPBOARD);
- g_assert(!iter);
-
- break;
- case WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE:
- iter = items;
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_CUT);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_COPY);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_PASTE);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_DELETE);
- iter = checkSeparator(iter);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_SELECT_ALL);
- iter = checkSeparator(iter);
- iter = checkActionWithSubmenu(iter, WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS);
- iter = checkActionWithSubmenu(iter, WEBKIT_CONTEXT_MENU_ACTION_UNICODE);
- g_assert(!iter);
-
- break;
- case WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK:
- iter = items;
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK_IN_NEW_WINDOW);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_LINK_TO_DISK);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_COPY_LINK_TO_CLIPBOARD);
- g_assert(!iter);
-
- break;
- default:
- g_assert_not_reached();
- }
-
- g_list_free(items);
- g_main_loop_quit(loop);
-
- return TRUE;
-}
-
-static void pushEvent(WebKitWebView *webView)
-{
- GdkEvent *event = gdk_event_new(GDK_BUTTON_PRESS);
-#if GTK_CHECK_VERSION(3, 0, 0)
- GdkDeviceManager *deviceManager;
-#endif
-
- event->any.window = g_object_ref(gtk_widget_get_window(GTK_WIDGET(webView)));
- event->any.send_event = FALSE;
- event->button.time = GDK_CURRENT_TIME;
- event->button.button = 3;
- event->button.x = event->button.y = 5;
- event->button.x_root = event->button.x;
- event->button.y_root = event->button.y;
-#if GTK_CHECK_VERSION(3, 0, 0)
- deviceManager = gdk_display_get_device_manager(gdk_display_get_default());
- event->button.device = gdk_device_manager_get_client_pointer(deviceManager);
-#endif
-
- gdk_event_put(event);
- gdk_event_free(event);
-}
-
-static void loadStatusCallback(WebKitWebView *webView, GParamSpec *spec, gpointer data)
-{
- WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
- TestInfo *info = (TestInfo *)data;
-
- g_assert(status != WEBKIT_LOAD_FAILED);
-
- if (status != WEBKIT_LOAD_FINISHED)
- return;
-
- g_signal_connect(webView, "context-menu", G_CALLBACK(contextMenuCallback), info);
- pushEvent(webView);
-}
-
-static gboolean mapEventCallback(GtkWidget *widget, GdkEvent *event, gpointer data)
-{
- gtk_widget_grab_focus(widget);
- ContextMenuFixture *fixture = (ContextMenuFixture *)data;
- webkit_web_view_load_string(fixture->webView,
- fixture->info->data,
- "text/html",
- "utf-8",
- "file://");
- g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(loadStatusCallback), fixture->info);
- return FALSE;
-}
-
-static void testContextMenu(ContextMenuFixture *fixture, gconstpointer data)
-{
- GtkAllocation allocation = { 0, 0, 50, 50 };
- GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
-
- gtk_window_resize(GTK_WINDOW(window), 50, 50);
- gtk_window_move(GTK_WINDOW(window), 0, 0);
- gtk_widget_size_allocate(GTK_WIDGET(fixture->webView), &allocation);
- gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(fixture->webView));
- g_signal_connect(window, "map-event", G_CALLBACK(mapEventCallback), fixture);
- gtk_widget_show_all(window);
-
- g_main_loop_run(loop);
-}
-
-static gboolean contextMenuCustomItemCallback(WebKitWebView *webView, GtkWidget *defaultMenu, WebKitHitTestResult *hitTestResult, gboolean keyboardMode, gpointer userData)
-{
- TestInfo *info = (TestInfo *)userData;
- guint context;
- GList *items;
- GList *iter;
- GtkWidget *menuItem;
- GtkAction *action;
-
- /* Check signal parameters */
- g_assert(WEBKIT_IS_WEB_VIEW(webView));
- g_assert(GTK_IS_MENU(defaultMenu));
- g_assert(WEBKIT_IS_HIT_TEST_RESULT(hitTestResult));
- g_assert(!keyboardMode);
-
- g_object_get(hitTestResult, "context", &context, NULL);
- g_assert(context & info->flag);
-
- action = gtk_action_new("TestAction", "Custom Action", "Custom Action Tooltip", NULL);
- menuItem = gtk_action_create_menu_item(action);
- g_object_unref(action);
-
- gtk_menu_shell_append(GTK_MENU_SHELL(defaultMenu), menuItem);
- gtk_widget_show(menuItem);
-
- items = gtk_container_get_children(GTK_CONTAINER(defaultMenu));
- iter = items;
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_GO_BACK);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_GO_FORWARD);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_STOP);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_RELOAD);
- iter = checkAction(iter, WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION);
- g_assert(!iter);
-
- g_list_free(items);
- g_main_loop_quit(loop);
-
- return TRUE;
-}
-
-static void testContextMenuCustomItem(ContextMenuFixture *fixture, gconstpointer data)
-{
- GtkWidget *window = gtk_window_new(GTK_WINDOW_POPUP);
- gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(fixture->webView));
- gtk_widget_show_all(window);
- gtk_widget_grab_focus(GTK_WIDGET(fixture->webView));
-
- webkit_web_view_load_string(fixture->webView,
- fixture->info->data,
- "text/html",
- "utf-8",
- "file://");
- g_signal_connect(fixture->webView, "context-menu", G_CALLBACK(contextMenuCustomItemCallback), fixture->info);
- pushEvent(fixture->webView);
-}
-
-int main(int argc, char **argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- // Get rid of runtime warnings about deprecated properties and signals, since they break the tests.
- g_setenv("G_ENABLE_DIAGNOSTIC", "0", TRUE);
-
- g_test_bug_base("https://bugs.webkit.org/");
-
- g_test_add("/webkit/testcontextmenu/document", ContextMenuFixture,
- testInfoNew("<html><body><h1>WebKitGTK+!</h1></body></html>",
- WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT),
- contextMenuFixtureSetup, testContextMenu, contextMenuFixtureTeardown);
- /* We hardcode all elements to be at 0,0 so that we know where to generate the button events */
- g_test_add("/webkit/testcontextmenu/image", ContextMenuFixture,
- testInfoNew("<html><body><img style='position:absolute; left:0; top:0' src='0xdeadbeef' width=50 height=50></img></body></html>",
- WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE),
- contextMenuFixtureSetup, testContextMenu, contextMenuFixtureTeardown);
- g_test_add("/webkit/testcontextmenu/editable", ContextMenuFixture,
- testInfoNew("<html><body><input style='position:absolute; left:0; top:0' size='35'></input>></body></html>",
- WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE),
- contextMenuFixtureSetup, testContextMenu, contextMenuFixtureTeardown);
- g_test_add("/webkit/testcontextmenu/link", ContextMenuFixture,
- testInfoNew("<html><body><a style='position:absolute; left:0; top:0' href='http://www.example.com'>HELLO WORLD</a></body></html>",
- WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK),
- contextMenuFixtureSetup, testContextMenu, contextMenuFixtureTeardown);
- g_test_add("/webkit/testcontextmenu/customitem", ContextMenuFixture,
- testInfoNew("<html><body><h1>WebKitGTK+!</h1></body></html>",
- WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT),
- contextMenuFixtureSetup, testContextMenuCustomItem, contextMenuFixtureTeardown);
-
- return g_test_run();
-}
-
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testcopyandpaste.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testcopyandpaste.c
deleted file mode 100644
index bb38ea66b..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testcopyandpaste.c
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Copyright (C) 2010 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2,1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-#include <glib/gstdio.h>
-#include <webkit/webkit.h>
-#include <JavaScriptCore/JSStringRef.h>
-#include <JavaScriptCore/JSContextRef.h>
-
-typedef struct {
- char* page;
- char* expectedContent;
-} TestInfo;
-
-typedef struct {
- GtkWidget* window;
- WebKitWebView* webView;
- GMainLoop* loop;
- TestInfo* info;
-} CopyAndPasteFixture;
-
-TestInfo*
-test_info_new(const char* page, const char* expectedContent)
-{
- TestInfo* info;
- info = g_slice_new0(TestInfo);
- info->page = g_strdup(page);
- if (expectedContent)
- info->expectedContent = g_strdup(expectedContent);
- return info;
-}
-
-void
-test_info_destroy(TestInfo* info)
-{
- g_free(info->page);
- g_free(info->expectedContent);
- g_slice_free(TestInfo, info);
-}
-
-static void copy_and_paste_fixture_setup(CopyAndPasteFixture* fixture, gconstpointer data)
-{
- fixture->loop = g_main_loop_new(NULL, TRUE);
-
- fixture->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- fixture->webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
-
- gtk_container_add(GTK_CONTAINER(fixture->window), GTK_WIDGET(fixture->webView));
-}
-
-static void copy_and_paste_fixture_teardown(CopyAndPasteFixture* fixture, gconstpointer data)
-{
- gtk_widget_destroy(fixture->window);
- g_main_loop_unref(fixture->loop);
- test_info_destroy(fixture->info);
-}
-
-static void load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data)
-{
- CopyAndPasteFixture* fixture = (CopyAndPasteFixture*)data;
- WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
- if (status != WEBKIT_LOAD_FINISHED)
- return;
-
- GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
- gtk_clipboard_clear(clipboard);
-
- webkit_web_view_copy_clipboard(webView);
-
- gchar* text = gtk_clipboard_wait_for_text(clipboard);
- g_assert(text || !fixture->info->expectedContent);
- g_assert(!text || !strcmp(text, fixture->info->expectedContent));
- g_free(text);
-
- // Verify that the markup starts with the proper content-type meta tag prefix.
- GtkSelectionData* selectionData = gtk_clipboard_wait_for_contents(clipboard, gdk_atom_intern("text/html", FALSE));
- if (selectionData) {
- static const char* markupPrefix = "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">";
- char* markup = g_strndup((const char*) gtk_selection_data_get_data(selectionData),
- gtk_selection_data_get_length(selectionData));
- g_assert(strlen(markupPrefix) <= strlen(markup));
- g_assert(!strncmp(markupPrefix, markup, strlen(markupPrefix)));
- g_free(markup);
- }
-
- g_assert(!gtk_clipboard_wait_is_uris_available(clipboard));
- g_assert(!gtk_clipboard_wait_is_image_available(clipboard));
-
- g_main_loop_quit(fixture->loop);
-}
-
-gboolean map_event_cb(GtkWidget *widget, GdkEvent* event, gpointer data)
-{
- CopyAndPasteFixture* fixture = (CopyAndPasteFixture*)data;
- webkit_web_view_load_string(fixture->webView, fixture->info->page,
- "text/html", "utf-8", "file://");
- return FALSE;
-}
-
-static void test_copy_and_paste(CopyAndPasteFixture* fixture, gconstpointer data)
-{
- fixture->info = (TestInfo*)data;
- g_signal_connect(fixture->window, "map-event",
- G_CALLBACK(map_event_cb), fixture);
-
- gtk_widget_show(fixture->window);
- gtk_widget_show(GTK_WIDGET(fixture->webView));
- gtk_window_present(GTK_WINDOW(fixture->window));
- gtk_widget_grab_focus(GTK_WIDGET(fixture->webView));
-
- g_signal_connect(fixture->webView, "notify::load-status",
- G_CALLBACK(load_status_cb), fixture);
-
- g_main_loop_run(fixture->loop);
-}
-
-static CopyAndPasteFixture* currentFixture;
-static JSValueRef runPasteTestCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
-{
- gtk_widget_grab_focus(GTK_WIDGET(currentFixture->webView));
-
- // Simulate a paste keyboard sequence.
- GdkEvent* event = gdk_event_new(GDK_KEY_PRESS);
- event->key.keyval = gdk_unicode_to_keyval('v');
- event->key.state = GDK_CONTROL_MASK;
- event->key.window = gtk_widget_get_window(GTK_WIDGET(currentFixture->webView));
- g_object_ref(event->key.window);
-#ifndef GTK_API_VERSION_2
- GdkDeviceManager* manager = gdk_display_get_device_manager(gdk_window_get_display(event->key.window));
- gdk_event_set_device(event, gdk_device_manager_get_client_pointer(manager));
-#endif
-
- GdkKeymapKey* keys;
- gint n_keys;
- if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), event->key.keyval, &keys, &n_keys)) {
- event->key.hardware_keycode = keys[0].keycode;
- g_free(keys);
- }
-
- gtk_main_do_event(event);
- event->key.type = GDK_KEY_RELEASE;
- gtk_main_do_event(event);
- gdk_event_free(event);
-
- JSStringRef scriptString = JSStringCreateWithUTF8CString("document.body.innerHTML;");
- JSValueRef value = JSEvaluateScript(context, scriptString, 0, 0, 0, 0);
- JSStringRelease(scriptString);
-
- g_assert(JSValueIsString(context, value));
- JSStringRef actual = JSValueToStringCopy(context, value, exception);
- g_assert(!exception || !*exception);
- g_assert(currentFixture->info->expectedContent);
- JSStringRef expected = JSStringCreateWithUTF8CString(currentFixture->info->expectedContent);
- g_assert(JSStringIsEqual(expected, actual));
-
- JSStringRelease(expected);
- JSStringRelease(actual);
- g_main_loop_quit(currentFixture->loop);
- return JSValueMakeUndefined(context);
-}
-
-static void window_object_cleared_callback(WebKitWebView* web_view, WebKitWebFrame* web_frame, JSGlobalContextRef context, JSObjectRef window_object, gpointer data)
-{
- JSStringRef name = JSStringCreateWithUTF8CString("runTest");
- JSObjectRef testComplete = JSObjectMakeFunctionWithCallback(context, name, runPasteTestCallback);
- JSObjectSetProperty(context, window_object, name, testComplete, kJSPropertyAttributeNone, 0);
- JSStringRelease(name);
-}
-
-static void pasting_test_get_data_callback(GtkClipboard* clipboard, GtkSelectionData* selection_data, guint info, gpointer data)
-{
- gtk_selection_data_set(selection_data, gdk_atom_intern("text/html", FALSE), 8, (const guchar*) data, strlen((char*)data) + 1);
-}
-
-static void pasting_test_clear_data_callback(GtkClipboard* clipboard, gpointer data)
-{
- g_free(data);
-}
-
-static void test_pasting_markup(CopyAndPasteFixture* fixture, gconstpointer data)
-{
- fixture->info = (TestInfo*)data;
- currentFixture = fixture;
-
- GtkTargetList* targetList = gtk_target_list_new(0, 0);
- gtk_target_list_add(targetList, gdk_atom_intern("text/html", FALSE), 0, 0);
-
- int numberOfTargets = 1;
- GtkTargetEntry* targetTable = gtk_target_table_new_from_list(targetList, &numberOfTargets);
- gtk_clipboard_set_with_data(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD),
- targetTable, numberOfTargets,
- pasting_test_get_data_callback,
- pasting_test_clear_data_callback,
- g_strdup(fixture->info->expectedContent));
- gtk_target_list_unref(targetList);
- gtk_target_table_free(targetTable, numberOfTargets);
-
- g_signal_connect(fixture->window, "map-event",
- G_CALLBACK(map_event_cb), fixture);
- g_signal_connect(fixture->webView, "window-object-cleared",
- G_CALLBACK(window_object_cleared_callback), fixture);
-
- gtk_widget_show(fixture->window);
- gtk_widget_show(GTK_WIDGET(fixture->webView));
- gtk_window_present(GTK_WINDOW(fixture->window));
-
- g_main_loop_run(fixture->loop);
-}
-
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
- const char* selected_span_html = "<html><body>"
- "<span id=\"mainspan\">All work and no play <span>make Jack a dull</span> boy.</span>"
- "<script>document.getSelection().collapse();\n"
- "document.getSelection().selectAllChildren(document.getElementById('mainspan'));\n"
- "</script></body></html>";
- const char* no_selection_html = "<html><body>"
- "<span id=\"mainspan\">All work and no play <span>make Jack a dull</span> boy</span>"
- "<script>document.getSelection().collapse();\n"
- "</script></body></html>";
-
- g_test_add("/webkit/copyandpaste/selection", CopyAndPasteFixture,
- test_info_new(selected_span_html, "All work and no play make Jack a dull boy."),
- copy_and_paste_fixture_setup,
- test_copy_and_paste,
- copy_and_paste_fixture_teardown);
- g_test_add("/webkit/copyandpaste/no-selection", CopyAndPasteFixture,
- test_info_new(no_selection_html, 0),
- copy_and_paste_fixture_setup,
- test_copy_and_paste,
- copy_and_paste_fixture_teardown);
-
- const char* paste_test_html = "<html>"
- "<body onLoad=\"document.body.focus(); runTest();\" contentEditable=\"true\">"
- "</body></html>";
- g_test_add("/webkit/copyandpaste/paste-markup", CopyAndPasteFixture,
- test_info_new(paste_test_html, "bobby"),
- copy_and_paste_fixture_setup,
- test_pasting_markup,
- copy_and_paste_fixture_teardown);
-
- return g_test_run();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testdomdocument.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testdomdocument.c
deleted file mode 100644
index 8e46c030d..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testdomdocument.c
+++ /dev/null
@@ -1,445 +0,0 @@
-/*
- * Copyright (C) 2010 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include "test_utils.h"
-
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-#define HTML_DOCUMENT_TITLE "<html><head><title>This is the title</title></head><body></body></html>"
-#define HTML_DOCUMENT_ELEMENTS "<html><body><ul><li>1</li><li>2</li><li>3</li></ul></body></html>"
-#define HTML_DOCUMENT_ELEMENTS_CLASS "<html><body><div class=\"test\"></div><div class=\"strange\"></div><div class=\"test\"></div></body></html>"
-#define HTML_DOCUMENT_ELEMENTS_ID "<html><body><div id=\"testok\"></div><div id=\"testbad\">first</div><div id=\"testbad\">second</div></body></html>"
-#define HTML_DOCUMENT_LINKS "<html><head><title>Title</title></head><body><a href=\"about:blank\">blank</a><a href=\"http://www.google.com\">google</a><a href=\"http://www.webkit.org\">webkit</a></body></html>"
-#define HTML_DOCUMENT_IFRAME "<html><head><title>IFrame</title></head><body><iframe id='iframe'></iframe><div id='test'></div></body></html>"
-#define HTML_DOCUMENT_TABLE "<html><body><table id=\"table\"></table></body></html>"
-#define HTML_DOCUMENT_EVALUATE "<html><head><title></title></head><body><div>First div</div><div>Second div</div></body></html>"
-
-typedef struct {
- GtkWidget* webView;
- GMainLoop* loop;
-} DomDocumentFixture;
-
-static gboolean finish_loading(DomDocumentFixture* fixture)
-{
- if (g_main_loop_is_running(fixture->loop))
- g_main_loop_quit(fixture->loop);
-
- return FALSE;
-}
-
-static void dom_document_fixture_setup(DomDocumentFixture* fixture, gconstpointer data)
-{
- fixture->loop = g_main_loop_new(NULL, TRUE);
- fixture->webView = webkit_web_view_new();
- g_object_ref_sink(fixture->webView);
-
- if (data != NULL)
- webkit_web_view_load_string(WEBKIT_WEB_VIEW (fixture->webView), (const char*) data, NULL, NULL, NULL);
-
- g_idle_add((GSourceFunc)finish_loading, fixture);
- g_main_loop_run(fixture->loop);
-}
-
-static void dom_document_fixture_teardown(DomDocumentFixture* fixture, gconstpointer data)
-{
- if (fixture->webView)
- g_object_unref(fixture->webView);
- g_main_loop_unref(fixture->loop);
-}
-
-static void test_dom_document_title(DomDocumentFixture* fixture, gconstpointer data)
-{
- g_assert(fixture);
- WebKitWebView* view = (WebKitWebView*)fixture->webView;
- g_assert(view);
- WebKitDOMDocument* document = webkit_web_view_get_dom_document(view);
- g_assert(document);
- gchar* title = webkit_dom_document_get_title(document);
- g_assert(title);
- g_assert_cmpstr(title, ==, "This is the title");
- g_free(title);
- webkit_dom_document_set_title(document, "This is the second title");
- title = webkit_dom_document_get_title(document);
- g_assert(title);
- g_assert_cmpstr(title, ==, "This is the second title");
- g_free(title);
-}
-
-static void test_dom_document_get_elements_by_tag_name(DomDocumentFixture* fixture, gconstpointer data)
-{
- g_assert(fixture);
- WebKitWebView* view = (WebKitWebView*)fixture->webView;
- g_assert(view);
- WebKitDOMDocument* document = webkit_web_view_get_dom_document(view);
- g_assert(document);
- WebKitDOMNodeList* list = webkit_dom_document_get_elements_by_tag_name(document, "li");
- g_assert(list);
- gulong length = webkit_dom_node_list_get_length(list);
- g_assert_cmpint(length, ==, 3);
-
- guint i;
-
- for (i = 0; i < length; i++) {
- WebKitDOMNode* item = webkit_dom_node_list_item(list, i);
- g_assert(item);
- WebKitDOMElement* element = (WebKitDOMElement*)item;
- g_assert(element);
- g_assert_cmpstr(webkit_dom_element_get_tag_name(element), ==, "LI");
- WebKitDOMHTMLElement* htmlElement = (WebKitDOMHTMLElement*)element;
- char* n = g_strdup_printf("%d", i+1);
- g_assert_cmpstr(webkit_dom_html_element_get_inner_text(htmlElement), ==, n);
- g_free(n);
- }
-
- g_object_unref(list);
-}
-
-static void test_dom_document_get_elements_by_class_name(DomDocumentFixture* fixture, gconstpointer data)
-{
- g_assert(fixture);
- WebKitWebView* view = (WebKitWebView*)fixture->webView;
- g_assert(view);
- WebKitDOMDocument* document = webkit_web_view_get_dom_document(view);
- g_assert(document);
- WebKitDOMNodeList* list = webkit_dom_document_get_elements_by_class_name(document, "test");
- g_assert(list);
- gulong length = webkit_dom_node_list_get_length(list);
- g_assert_cmpint(length, ==, 2);
-
- guint i;
-
- for (i = 0; i < length; i++) {
- WebKitDOMNode* item = webkit_dom_node_list_item(list, i);
- g_assert(item);
- WebKitDOMElement* element = (WebKitDOMElement*)item;
- g_assert(element);
- g_assert_cmpstr(webkit_dom_element_get_tag_name(element), ==, "DIV");
- }
-
- g_object_unref(list);
-}
-
-static void test_dom_document_get_element_by_id(DomDocumentFixture* fixture, gconstpointer data)
-{
- g_assert(fixture);
- WebKitWebView* view = (WebKitWebView*)fixture->webView;
- g_assert(view);
- WebKitDOMDocument* document = webkit_web_view_get_dom_document(view);
- g_assert(document);
- WebKitDOMElement* element = webkit_dom_document_get_element_by_id(document, "testok");
- g_assert(element);
- element = webkit_dom_document_get_element_by_id(document, "this-id-does-not-exist");
- g_assert(element == 0);
- /* The DOM spec says the return value is undefined when there's
- * more than one element with the same id; in our case the first
- * one will be returned */
- element = webkit_dom_document_get_element_by_id(document, "testbad");
- g_assert(element);
- WebKitDOMHTMLElement* htmlElement = (WebKitDOMHTMLElement*)element;
- g_assert_cmpstr(webkit_dom_html_element_get_inner_text(htmlElement), ==, "first");
-}
-
-static void test_dom_document_get_links(DomDocumentFixture* fixture, gconstpointer data)
-{
- g_assert(fixture);
- WebKitWebView* view = (WebKitWebView*)fixture->webView;
- g_assert(view);
- WebKitDOMDocument* document = webkit_web_view_get_dom_document(view);
- g_assert(document);
- WebKitDOMHTMLCollection *collection = webkit_dom_document_get_links(document);
- g_assert(collection);
- gulong length = webkit_dom_html_collection_get_length(collection);
- g_assert_cmpint(length, ==, 3);
-
- guint i;
-
- for (i = 0; i < length; i++) {
- static const char* names[] = { "blank", "google", "webkit" };
- static const char* uris[] = { "about:blank", "http://www.google.com/", "http://www.webkit.org/" };
- WebKitDOMNode *node = webkit_dom_html_collection_item(collection, i);
- g_assert(node);
- WebKitDOMElement* element = (WebKitDOMElement*)node;
- g_assert_cmpstr(webkit_dom_element_get_tag_name(element), ==, "A");
- WebKitDOMHTMLElement *htmlElement = (WebKitDOMHTMLElement*)element;
- g_assert_cmpstr(webkit_dom_html_element_get_inner_text(htmlElement), ==, names[i]);
- WebKitDOMHTMLAnchorElement *anchor = (WebKitDOMHTMLAnchorElement*)element;
- g_assert_cmpstr(webkit_dom_html_anchor_element_get_href(anchor), ==, uris[i]);
- }
- g_object_unref(collection);
-}
-
-static void test_dom_document_insert_row(DomDocumentFixture* fixture, gconstpointer data)
-{
- g_assert(fixture);
- WebKitWebView* view = (WebKitWebView*)fixture->webView;
- g_assert(view);
- WebKitDOMDocument* document = webkit_web_view_get_dom_document(view);
- g_assert(WEBKIT_DOM_IS_DOCUMENT(document));
- WebKitDOMElement* table = webkit_dom_document_get_element_by_id(document, "table");
- g_assert(WEBKIT_DOM_IS_HTML_ELEMENT(table));
- WebKitDOMHTMLCollection* rows = webkit_dom_html_table_element_get_rows(WEBKIT_DOM_HTML_TABLE_ELEMENT(table));
- g_assert(WEBKIT_DOM_IS_HTML_COLLECTION(rows));
-
- // Table is initially empty.
- g_assert_cmpint(webkit_dom_html_collection_get_length(rows), ==, 0);
- WebKitDOMHTMLElement* row = webkit_dom_html_table_element_insert_row(WEBKIT_DOM_HTML_TABLE_ELEMENT(table), -1, NULL);
- g_assert(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(row));
- rows = webkit_dom_html_table_element_get_rows(WEBKIT_DOM_HTML_TABLE_ELEMENT(table));
- g_assert(WEBKIT_DOM_IS_HTML_COLLECTION(rows));
- g_assert_cmpint(webkit_dom_html_collection_get_length(rows), ==, 1);
-}
-
-static void test_dom_document_evaluate(DomDocumentFixture* fixture, gconstpointer data)
-{
- g_assert(fixture);
- WebKitWebView* view = (WebKitWebView*)fixture->webView;
- g_assert(view);
- WebKitDOMDocument* document = webkit_web_view_get_dom_document(view);
- g_assert(WEBKIT_DOM_IS_DOCUMENT(document));
- WebKitDOMNodeList* list = webkit_dom_document_get_elements_by_tag_name(document, "html");
- g_assert(list);
- gulong length = webkit_dom_node_list_get_length(list);
- g_assert_cmpint(length, ==, 1);
- WebKitDOMNode* html = webkit_dom_node_list_item(list, 0);
- g_assert(WEBKIT_DOM_IS_NODE(html));
-
- WebKitDOMXPathResult* result = webkit_dom_document_evaluate(document, "//div", html, NULL, 0, NULL, NULL);
- g_assert(WEBKIT_DOM_IS_XPATH_RESULT(result));
-
- int i = 0;
- WebKitDOMNode* node;
- while ( (node = webkit_dom_xpath_result_iterate_next(result, NULL)) != NULL) {
- g_assert(node);
- WebKitDOMElement* element = (WebKitDOMElement*)node;
- g_assert_cmpstr(webkit_dom_element_get_tag_name(element), ==, "DIV");
- i++;
- }
- g_assert_cmpint(i, ==, 2);
-
- g_object_unref(list);
-}
-
-static void weak_notify(gpointer data, GObject* zombie)
-{
- guint* count = (guint*)data;
- (*count)++;
-}
-
-static void test_dom_document_garbage_collection(DomDocumentFixture* fixture, gconstpointer data)
-{
- guint count = 0;
- g_assert(fixture);
- WebKitWebView* view = (WebKitWebView*)fixture->webView;
- g_assert(view);
- WebKitDOMDocument* document = webkit_web_view_get_dom_document(view);
- g_assert(document);
- g_object_weak_ref(G_OBJECT(document), (GWeakNotify)weak_notify, &count);
- WebKitDOMHTMLHeadElement* head = webkit_dom_document_get_head(document);
- g_assert(head);
- g_object_weak_ref(G_OBJECT(head), (GWeakNotify)weak_notify, &count);
- WebKitDOMHTMLElement* body = webkit_dom_document_get_body(document);
- g_assert(body);
- g_object_weak_ref(G_OBJECT(body), (GWeakNotify)weak_notify, &count);
- WebKitDOMHTMLCollection *collection = webkit_dom_document_get_links(document);
- g_assert(collection);
- g_object_weak_ref(G_OBJECT(collection), (GWeakNotify)weak_notify, &count);
-
- webkit_web_view_load_string(WEBKIT_WEB_VIEW(view), HTML_DOCUMENT_LINKS, NULL, NULL, NULL);
-
- while (g_main_context_pending(NULL))
- g_main_context_iteration(NULL, FALSE);
-
- g_assert_cmpuint(count, ==, 3);
-
- g_object_unref(collection);
- g_assert_cmpuint(count, ==, 4);
-
- count = 0;
-
- document = webkit_web_view_get_dom_document(view);
- g_assert(document);
- g_object_weak_ref(G_OBJECT(document), (GWeakNotify)weak_notify, &count);
- head = webkit_dom_document_get_head(document);
- g_assert(head);
- g_object_weak_ref(G_OBJECT(head), (GWeakNotify)weak_notify, &count);
- body = webkit_dom_document_get_body(document);
- g_assert(body);
- g_object_weak_ref(G_OBJECT(body), (GWeakNotify)weak_notify, &count);
- collection = webkit_dom_document_get_links(document);
- g_assert(collection);
- g_object_weak_ref(G_OBJECT(collection), (GWeakNotify)weak_notify, &count);
- /* Ask twice for the same object */
- WebKitDOMHTMLCollection* collection2 = webkit_dom_document_get_links(document);
- g_assert(collection2);
- g_object_weak_ref(G_OBJECT(collection2), (GWeakNotify)weak_notify, &count);
-
- g_object_unref(document);
- g_object_unref(head);
- g_object_unref(body);
- g_object_unref(collection);
- g_object_unref(collection2);
-
- g_assert_cmpuint(count, ==, 5);
-
- webkit_web_view_load_string(WEBKIT_WEB_VIEW(view), HTML_DOCUMENT_IFRAME, NULL, NULL, NULL);
-
- while (g_main_context_pending(NULL))
- g_main_context_iteration(NULL, FALSE);
-
- count = 0;
-
- document = webkit_web_view_get_dom_document(view);
- body = webkit_dom_document_get_body(document);
- WebKitDOMElement* p = webkit_dom_document_create_element(document, "P", NULL);
- webkit_dom_node_append_child(WEBKIT_DOM_NODE(body), WEBKIT_DOM_NODE(p), NULL);
- g_object_weak_ref(G_OBJECT(p), (GWeakNotify)weak_notify, &count);
- /* This is wrong, p is transfer none and owned by the cache, but we shouldn't crash in that case. */
- g_object_unref(p);
-
- webkit_web_view_load_string(WEBKIT_WEB_VIEW(view), HTML_DOCUMENT_IFRAME, NULL, NULL, NULL);
-
- while (g_main_context_pending(NULL))
- g_main_context_iteration(NULL, FALSE);
-
- g_assert_cmpuint(count, ==, 1);
-
- count = 0;
-
- document = webkit_web_view_get_dom_document(view);
- WebKitDOMElement* div = webkit_dom_document_get_element_by_id(document, "test");
- g_assert(div);
- g_object_weak_ref(G_OBJECT(div), (GWeakNotify)weak_notify, &count);
- WebKitDOMElement* iframe = webkit_dom_document_get_element_by_id(document, "iframe");
- g_assert(iframe);
-
- webkit_dom_element_set_attribute(iframe, "src", "data:<html><head></head></html>", NULL);
-
- while (g_main_context_pending(NULL))
- g_main_context_iteration(NULL, FALSE);
-
- WebKitDOMDocument* iframeDocument = webkit_dom_html_iframe_element_get_content_document(WEBKIT_DOM_HTML_IFRAME_ELEMENT(iframe));
- g_assert(iframeDocument);
- head = webkit_dom_document_get_head(iframeDocument);
- g_assert(head);
- g_object_weak_ref(G_OBJECT(head), (GWeakNotify)weak_notify, &count);
-
- webkit_dom_element_set_attribute(iframe, "src", "about:blank", NULL);
-
- while (g_main_context_pending(NULL))
- g_main_context_iteration(NULL, FALSE);
-
- g_assert_cmpuint(count, ==, 1);
-
- webkit_web_view_load_string(WEBKIT_WEB_VIEW(view), HTML_DOCUMENT_LINKS, NULL, NULL, NULL);
-
- while (g_main_context_pending(NULL))
- g_main_context_iteration(NULL, FALSE);
-
- g_assert_cmpuint(count, ==, 2);
-
- count = 0;
-
- document = webkit_web_view_get_dom_document(view);
- g_assert(document);
- g_object_weak_ref(G_OBJECT(document), (GWeakNotify)weak_notify, &count);
- /* Ask twice for the Document */
- WebKitDOMDocument* document2 = webkit_web_view_get_dom_document(view);
- g_assert(document2);
- g_object_weak_ref(G_OBJECT(document2), (GWeakNotify)weak_notify, &count);
- head = webkit_dom_document_get_head(document);
- g_assert(head);
- g_object_weak_ref(G_OBJECT(head), (GWeakNotify)weak_notify, &count);
- body = webkit_dom_document_get_body(document);
- g_assert(body);
- g_object_weak_ref(G_OBJECT(body), (GWeakNotify)weak_notify, &count);
- collection = webkit_dom_document_get_links(document);
- g_assert(collection);
- g_object_weak_ref(G_OBJECT(collection), (GWeakNotify)weak_notify, &count);
-
- gtk_widget_destroy(fixture->webView);
- fixture->webView = NULL;
-
- g_assert_cmpuint(count, ==, 4);
-
- g_object_unref(collection);
-
- g_assert_cmpuint(count, ==, 5);
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
-
- g_test_add("/webkit/domdocument/test_title",
- DomDocumentFixture, HTML_DOCUMENT_TITLE,
- dom_document_fixture_setup,
- test_dom_document_title,
- dom_document_fixture_teardown);
-
- g_test_add("/webkit/domdocument/test_get_elements_by_tag_name",
- DomDocumentFixture, HTML_DOCUMENT_ELEMENTS,
- dom_document_fixture_setup,
- test_dom_document_get_elements_by_tag_name,
- dom_document_fixture_teardown);
-
- g_test_add("/webkit/domdocument/test_get_elements_by_class_name",
- DomDocumentFixture, HTML_DOCUMENT_ELEMENTS_CLASS,
- dom_document_fixture_setup,
- test_dom_document_get_elements_by_class_name,
- dom_document_fixture_teardown);
-
- g_test_add("/webkit/domdocument/test_get_element_by_id",
- DomDocumentFixture, HTML_DOCUMENT_ELEMENTS_ID,
- dom_document_fixture_setup,
- test_dom_document_get_element_by_id,
- dom_document_fixture_teardown);
-
- g_test_add("/webkit/domdocument/test_get_links",
- DomDocumentFixture, HTML_DOCUMENT_LINKS,
- dom_document_fixture_setup,
- test_dom_document_get_links,
- dom_document_fixture_teardown);
-
- g_test_add("/webkit/domdocument/test_table_insert_row",
- DomDocumentFixture, HTML_DOCUMENT_TABLE,
- dom_document_fixture_setup,
- test_dom_document_insert_row,
- dom_document_fixture_teardown);
-
- g_test_add("/webkit/domdocument/test_document_evaluate",
- DomDocumentFixture, HTML_DOCUMENT_EVALUATE,
- dom_document_fixture_setup,
- test_dom_document_evaluate,
- dom_document_fixture_teardown);
-
- g_test_add("/webkit/domdocument/test_garbage_collection",
- DomDocumentFixture, HTML_DOCUMENT_LINKS,
- dom_document_fixture_setup,
- test_dom_document_garbage_collection,
- dom_document_fixture_teardown);
-
- return g_test_run();
-}
-
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testdomdomwindow.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testdomdomwindow.c
deleted file mode 100644
index 14fcd186a..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testdomdomwindow.c
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- * Copyright (C) 2010 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include "test_utils.h"
-
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-#define HTML_DOCUMENT "<html><head><title></title></head><style type='text/css'>#test { font-size: 16px; }</style><body><p id='test'>test</p></body></html>"
-
-typedef struct {
- GtkWidget* webView;
- GtkWidget* window;
- WebKitDOMDOMWindow* domWindow;
- GMainLoop* loop;
-
- gboolean loaded;
- gboolean clicked;
- gconstpointer data;
-} DomDomviewFixture;
-
-static gboolean finish_loading(DomDomviewFixture* fixture)
-{
- if (g_main_loop_is_running(fixture->loop))
- g_main_loop_quit(fixture->loop);
-
- return FALSE;
-}
-
-static void dom_domview_fixture_setup(DomDomviewFixture* fixture, gconstpointer data)
-{
- fixture->loop = g_main_loop_new(NULL, TRUE);
- fixture->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- fixture->webView = webkit_web_view_new();
- fixture->data = data;
-
- gtk_container_add(GTK_CONTAINER(fixture->window), GTK_WIDGET(fixture->webView));
-}
-
-static void dom_domview_fixture_teardown(DomDomviewFixture* fixture, gconstpointer data)
-{
- gtk_widget_destroy(fixture->window);
- g_main_loop_unref(fixture->loop);
-}
-
-static void dom_dom_window_fixture_setup(DomDomviewFixture* fixture, gconstpointer data)
-{
- fixture->loop = g_main_loop_new(NULL, TRUE);
- fixture->webView = webkit_web_view_new();
- g_object_ref_sink(fixture->webView);
-
- if (data != NULL)
- webkit_web_view_load_string(WEBKIT_WEB_VIEW (fixture->webView), (const char*) data, NULL, NULL, NULL);
-
- g_idle_add((GSourceFunc)finish_loading, fixture);
- g_main_loop_run(fixture->loop);
-}
-
-static void dom_dom_window_fixture_teardown(DomDomviewFixture* fixture, gconstpointer data)
-{
- if (fixture->webView)
- g_object_unref(fixture->webView);
- g_main_loop_unref(fixture->loop);
-}
-
-static gboolean loadedCallback(WebKitDOMDOMWindow* view, WebKitDOMEvent* event, DomDomviewFixture* fixture)
-{
- g_assert(fixture->loaded == FALSE);
- fixture->loaded = TRUE;
-
- return FALSE;
-}
-
-static gboolean clickedCallback(WebKitDOMDOMWindow* view, WebKitDOMEvent* event, DomDomviewFixture* fixture)
-{
- WebKitDOMEventTarget* target;
- gushort phase;
-
- g_assert(event);
- g_assert(WEBKIT_DOM_IS_EVENT(event));
-
- // We should catch this in the bubbling up phase, since we are connecting to the toplevel object
- phase = webkit_dom_event_get_event_phase(event);
- g_assert_cmpint(phase, ==, 3);
-
- target = webkit_dom_event_get_current_target(event);
- g_assert(target == WEBKIT_DOM_EVENT_TARGET(view));
-
- g_assert(fixture->clicked == FALSE);
- fixture->clicked = TRUE;
-
- finish_loading(fixture);
-
- return FALSE;
-}
-
-gboolean map_event_cb(GtkWidget *widget, GdkEvent* event, DomDomviewFixture* fixture)
-{
- webkit_web_view_load_string(WEBKIT_WEB_VIEW (fixture->webView), (const char*)fixture->data, NULL, NULL, NULL);
-
- return FALSE;
-}
-
-static void load_event_callback(WebKitWebView* webView, GParamSpec* spec, DomDomviewFixture* fixture)
-{
- WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
- if (status == WEBKIT_LOAD_FINISHED) {
- webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(fixture->domWindow), "click", G_CALLBACK(clickedCallback), false, fixture);
-
- g_assert(fixture->clicked == FALSE);
- gtk_test_widget_click(GTK_WIDGET(fixture->webView), 1, 0);
- }
-
-}
-
-static void test_dom_domview_signals(DomDomviewFixture* fixture, gconstpointer data)
-{
- g_assert(fixture);
- WebKitWebView* view = (WebKitWebView*)fixture->webView;
- g_assert(view);
- WebKitDOMDocument* document = webkit_web_view_get_dom_document(view);
- g_assert(document);
- WebKitDOMDOMWindow* domWindow = webkit_dom_document_get_default_view(document);
- g_assert(domWindow);
-
- fixture->domWindow = domWindow;
-
- webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(fixture->domWindow), "load", G_CALLBACK(loadedCallback), false, fixture);
- g_signal_connect(fixture->window, "map-event", G_CALLBACK(map_event_cb), fixture);
- g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_event_callback), fixture);
-
- gtk_widget_show_all(fixture->window);
- gtk_window_present(GTK_WINDOW(fixture->window));
-
- g_main_loop_run(fixture->loop);
-
- g_assert(fixture->loaded);
- g_assert(fixture->clicked);
-}
-
-static gboolean
-clicked_cb(WebKitDOMEventTarget* target, WebKitDOMEvent* event, DomDomviewFixture* fixture)
-{
- g_assert(fixture->clicked == FALSE);
- fixture->clicked = TRUE;
- finish_loading(fixture);
- return FALSE;
-}
-
-static void load_status_callback(WebKitWebView* webView, GParamSpec* spec, DomDomviewFixture* fixture)
-{
- WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
- if (status == WEBKIT_LOAD_FINISHED) {
- WebKitDOMDocument* document;
- WebKitDOMDOMWindow* domWindow;
- WebKitDOMElement* element;
- WebKitDOMEvent* event;
- glong clientX, clientY;
-
- document = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(fixture->webView));
- g_assert(document);
- domWindow = webkit_dom_document_get_default_view(document);
- g_assert(domWindow);
- fixture->domWindow = domWindow;
-
- element = webkit_dom_document_get_element_by_id(document, "test");
- g_assert(element);
- event = webkit_dom_document_create_event(document, "MouseEvent", NULL);
- g_assert(event);
- g_assert(WEBKIT_DOM_IS_EVENT(event));
- g_assert(WEBKIT_DOM_IS_MOUSE_EVENT(event));
- clientX = webkit_dom_element_get_client_left(element);
- clientY = webkit_dom_element_get_client_top(element);
- webkit_dom_mouse_event_init_mouse_event(WEBKIT_DOM_MOUSE_EVENT(event),
- "click", TRUE, TRUE,
- fixture->domWindow, 0, 0, 0, clientX, clientY,
- FALSE, FALSE, FALSE, FALSE,
- 1, WEBKIT_DOM_EVENT_TARGET(element));
- webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(element), "click", G_CALLBACK(clicked_cb), false, fixture);
- g_assert(fixture->clicked == FALSE);
- webkit_dom_event_target_dispatch_event(WEBKIT_DOM_EVENT_TARGET(element), event, NULL);
- }
-
-}
-
-static void test_dom_domview_dispatch_event(DomDomviewFixture* fixture, gconstpointer data)
-{
- g_signal_connect(fixture->window, "map-event", G_CALLBACK(map_event_cb), fixture);
- g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_status_callback), fixture);
-
- gtk_widget_show_all(fixture->window);
- gtk_window_present(GTK_WINDOW(fixture->window));
-
- g_main_loop_run (fixture->loop);
- g_assert(fixture->clicked);
-}
-
-static void test_dom_dom_window_get_computed_style(DomDomviewFixture* fixture, gconstpointer data)
-{
- WebKitDOMDocument* document = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(fixture->webView));
- g_assert(document);
- WebKitDOMDOMWindow* domWindow = webkit_dom_document_get_default_view(document);
- g_assert(domWindow);
-
- WebKitDOMElement* element = webkit_dom_document_get_element_by_id(document, "test");
- g_assert(element);
- g_assert(WEBKIT_DOM_IS_ELEMENT(element));
- WebKitDOMCSSStyleDeclaration* cssStyle = webkit_dom_dom_window_get_computed_style(domWindow, element, NULL);
- gchar* fontSize = webkit_dom_css_style_declaration_get_property_value(cssStyle, "font-size");
- g_assert_cmpstr(fontSize, ==, "16px");
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
-
- g_test_add("/webkit/domdomview/signals",
- DomDomviewFixture, HTML_DOCUMENT,
- dom_domview_fixture_setup,
- test_dom_domview_signals,
- dom_domview_fixture_teardown);
-
- g_test_add("/webkit/domdomview/dispatch_event",
- DomDomviewFixture, HTML_DOCUMENT,
- dom_domview_fixture_setup,
- test_dom_domview_dispatch_event,
- dom_domview_fixture_teardown);
-
- g_test_add("/webkit/domdomwindow/get_computed_style",
- DomDomviewFixture, HTML_DOCUMENT,
- dom_dom_window_fixture_setup,
- test_dom_dom_window_get_computed_style,
- dom_dom_window_fixture_teardown);
-
- return g_test_run();
-}
-
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testdomnode.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testdomnode.c
deleted file mode 100644
index ed4bcbdaa..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testdomnode.c
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * Copyright (C) 2010 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include "test_utils.h"
-
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-#define HTML_DOCUMENT_HIERARCHY_NAVIGATION "<html><head><title>This is the title</title></head><body><p>1</p><p>2</p><p>3</p></body></html>"
-#define HTML_DOCUMENT_NODE_INSERTION "<html><body></body></html>"
-
-typedef struct {
- GtkWidget* webView;
- GMainLoop* loop;
-} DomNodeFixture;
-
-static gboolean finish_loading(DomNodeFixture* fixture)
-{
- if (g_main_loop_is_running(fixture->loop))
- g_main_loop_quit(fixture->loop);
-
- return FALSE;
-}
-
-static void dom_node_fixture_setup(DomNodeFixture* fixture, gconstpointer data)
-{
- fixture->loop = g_main_loop_new(NULL, TRUE);
- fixture->webView = webkit_web_view_new();
- g_object_ref_sink(fixture->webView);
-
- if (data != NULL)
- webkit_web_view_load_string(WEBKIT_WEB_VIEW(fixture->webView), (const char*)data, NULL, NULL, NULL);
-
- g_idle_add((GSourceFunc)finish_loading, fixture);
- g_main_loop_run(fixture->loop);
-}
-
-static void dom_node_fixture_teardown(DomNodeFixture* fixture, gconstpointer data)
-{
- g_object_unref(fixture->webView);
- g_main_loop_unref(fixture->loop);
-}
-
-static void test_dom_node_hierarchy_navigation(DomNodeFixture* fixture, gconstpointer data)
-{
- WebKitDOMDocument* document;
- WebKitDOMHTMLHeadElement* head;
- WebKitDOMHTMLBodyElement* body;
- WebKitDOMNodeList* list;
- WebKitDOMNode* ptr;
- gulong i, length;
-
- document = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(fixture->webView));
- g_assert(document);
- g_assert(WEBKIT_DOM_IS_DOCUMENT(document));
- head = webkit_dom_document_get_head(document);
- g_assert(head);
- g_assert(WEBKIT_DOM_IS_HTML_HEAD_ELEMENT(head));
-
- /* Title, head's child */
- g_assert(webkit_dom_node_has_child_nodes(WEBKIT_DOM_NODE(head)));
- list = webkit_dom_node_get_child_nodes(WEBKIT_DOM_NODE(head));
- g_assert_cmpint(webkit_dom_node_list_get_length(list), ==, 1);
- ptr = webkit_dom_node_list_item(list, 0);
- g_assert(ptr);
- g_assert(WEBKIT_DOM_IS_HTML_TITLE_ELEMENT(ptr));
- g_object_unref(list);
-
- /* Body, Head sibling */
- ptr = webkit_dom_node_get_next_sibling(WEBKIT_DOM_NODE(head));
- g_assert(ptr);
- body = WEBKIT_DOM_HTML_BODY_ELEMENT(ptr);
- g_assert(WEBKIT_DOM_IS_HTML_BODY_ELEMENT(body));
-
- /* There is no third sibling */
- ptr = webkit_dom_node_get_next_sibling(ptr);
- g_assert(ptr == NULL);
-
- /* Body's previous sibling is Head */
- ptr = webkit_dom_node_get_previous_sibling(WEBKIT_DOM_NODE(body));
- g_assert(ptr);
- g_assert(WEBKIT_DOM_IS_HTML_HEAD_ELEMENT(ptr));
-
- /* Body has 3 children */
- g_assert(webkit_dom_node_has_child_nodes(WEBKIT_DOM_NODE(body)));
- list = webkit_dom_node_get_child_nodes(WEBKIT_DOM_NODE(body));
- length = webkit_dom_node_list_get_length(list);
- g_assert_cmpint(length, ==, 3);
-
- /* The three of them are P tags */
- for (i = 0; i < length; i++) {
- ptr = webkit_dom_node_list_item(list, i);
- g_assert(ptr);
- g_assert(WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT(ptr));
- }
-
- /* Go backwards */
- for (i = 0; ptr; ptr = webkit_dom_node_get_previous_sibling(ptr), i++)
- /* Nothing */;
-
- g_assert_cmpint(i, ==, 3);
- g_object_unref(list);
-}
-
-static void test_dom_node_insertion(DomNodeFixture* fixture, gconstpointer data)
-{
- WebKitDOMDocument* document;
- WebKitDOMHTMLElement* body;
- WebKitDOMElement* p, *div;
- WebKitDOMNodeList* list;
- WebKitDOMNode* node;
-
- document = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(fixture->webView));
- g_assert(document);
- body = webkit_dom_document_get_body(document);
- g_assert(body);
- g_assert(WEBKIT_DOM_IS_HTML_ELEMENT(body));
-
- /* Body shouldn't have any children at this point */
- g_assert(webkit_dom_node_has_child_nodes(WEBKIT_DOM_NODE(body)) == FALSE);
-
- /* Insert one P element */
- p = webkit_dom_document_create_element(document, "P", NULL);
- webkit_dom_node_append_child(WEBKIT_DOM_NODE(body), WEBKIT_DOM_NODE(p), NULL);
-
- /* Now it should have one, the same that we inserted */
- g_assert(webkit_dom_node_has_child_nodes(WEBKIT_DOM_NODE(body)));
- list = webkit_dom_node_get_child_nodes(WEBKIT_DOM_NODE(body));
- g_assert_cmpint(webkit_dom_node_list_get_length(list), ==, 1);
- node = webkit_dom_node_list_item(list, 0);
- g_assert(node);
- g_assert(webkit_dom_node_is_same_node(WEBKIT_DOM_NODE(p), node));
- g_object_unref(list);
-
- /* Replace the P tag with a DIV tag */
- div = webkit_dom_document_create_element(document, "DIV", NULL);
- webkit_dom_node_replace_child(WEBKIT_DOM_NODE(body), WEBKIT_DOM_NODE(div), WEBKIT_DOM_NODE(p), NULL);
- g_assert(webkit_dom_node_has_child_nodes(WEBKIT_DOM_NODE(body)));
- list = webkit_dom_node_get_child_nodes(WEBKIT_DOM_NODE(body));
- g_assert_cmpint(webkit_dom_node_list_get_length(list), ==, 1);
- node = webkit_dom_node_list_item(list, 0);
- g_assert(node);
- g_assert(webkit_dom_node_is_same_node(WEBKIT_DOM_NODE(div), node));
- g_object_unref(list);
-
- /* Now remove the tag */
- webkit_dom_node_remove_child(WEBKIT_DOM_NODE(body), node, NULL);
- list = webkit_dom_node_get_child_nodes(WEBKIT_DOM_NODE(body));
- g_assert_cmpint(webkit_dom_node_list_get_length(list), ==, 0);
- g_object_unref(list);
-
- /* Test insert_before */
-
- /* If refChild is null, insert newChild as last element of parent */
- div = webkit_dom_document_create_element(document, "DIV", NULL);
- webkit_dom_node_insert_before(WEBKIT_DOM_NODE(body), WEBKIT_DOM_NODE(div), NULL, NULL);
- g_assert(webkit_dom_node_has_child_nodes(WEBKIT_DOM_NODE(body)));
- list = webkit_dom_node_get_child_nodes(WEBKIT_DOM_NODE(body));
- g_assert_cmpint(webkit_dom_node_list_get_length(list), ==, 1);
- node = webkit_dom_node_list_item(list, 0);
- g_assert(node);
- g_assert(webkit_dom_node_is_same_node(WEBKIT_DOM_NODE(div), node));
- g_object_unref(list);
-
- /* Now insert a 'p' before 'div' */
- p = webkit_dom_document_create_element(document, "P", NULL);
- webkit_dom_node_insert_before(WEBKIT_DOM_NODE(body), WEBKIT_DOM_NODE(p), WEBKIT_DOM_NODE(div), NULL);
- g_assert(webkit_dom_node_has_child_nodes(WEBKIT_DOM_NODE(body)));
- list = webkit_dom_node_get_child_nodes(WEBKIT_DOM_NODE(body));
- g_assert_cmpint(webkit_dom_node_list_get_length(list), ==, 2);
- node = webkit_dom_node_list_item(list, 0);
- g_assert(node);
- g_assert(webkit_dom_node_is_same_node(WEBKIT_DOM_NODE(p), node));
- node = webkit_dom_node_list_item(list, 1);
- g_assert(node);
- g_assert(webkit_dom_node_is_same_node(WEBKIT_DOM_NODE(div), node));
- g_object_unref(list);
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
-
- g_test_add("/webkit/domnode/test_hierarchy_navigation",
- DomNodeFixture, HTML_DOCUMENT_HIERARCHY_NAVIGATION,
- dom_node_fixture_setup,
- test_dom_node_hierarchy_navigation,
- dom_node_fixture_teardown);
-
- g_test_add("/webkit/domnode/test_insertion",
- DomNodeFixture, HTML_DOCUMENT_NODE_INSERTION,
- dom_node_fixture_setup,
- test_dom_node_insertion,
- dom_node_fixture_teardown);
-
- return g_test_run();
-}
-
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testdownload.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testdownload.c
deleted file mode 100644
index e34d63230..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testdownload.c
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * Copyright (C) 2009 Christian Dywan <christian@twotoasts.de>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2,1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include <errno.h>
-#include <unistd.h>
-#include <glib/gstdio.h>
-#include <webkit/webkit.h>
-
-GMainLoop* loop;
-char* temporaryFilename = NULL;
-WebKitDownload* theDownload = NULL;
-
-static void
-test_webkit_download_create(void)
-{
- WebKitNetworkRequest* request;
- WebKitDownload* download;
- const gchar* uri = "http://example.com";
- gchar* tmpDir;
-
- request = webkit_network_request_new(uri);
- download = webkit_download_new(request);
- g_object_unref(request);
- g_assert_cmpstr(webkit_download_get_uri(download), ==, uri);
- g_assert(webkit_download_get_network_request(download) == request);
- g_assert(g_strrstr(uri, webkit_download_get_suggested_filename(download)));
- g_assert(webkit_download_get_status(download) == WEBKIT_DOWNLOAD_STATUS_CREATED);
- g_assert(!webkit_download_get_total_size(download));
- g_assert(!webkit_download_get_current_size(download));
- g_assert(!webkit_download_get_progress(download));
- g_assert(!webkit_download_get_elapsed_time(download));
- tmpDir = g_filename_to_uri(g_get_tmp_dir(), NULL, NULL);
- webkit_download_set_destination_uri(download, tmpDir);
- g_assert_cmpstr(tmpDir, ==, webkit_download_get_destination_uri(download));;
- g_free(tmpDir);
- g_object_unref(download);
-}
-
-static gboolean
-navigation_policy_decision_requested_cb(WebKitWebView* web_view,
- WebKitWebFrame* web_frame,
- WebKitNetworkRequest* request,
- WebKitWebNavigationAction* action,
- WebKitWebPolicyDecision* decision,
- gpointer data)
-{
- webkit_web_policy_decision_download(decision);
- return TRUE;
-}
-
-static void
-notify_status_cb(GObject* object, GParamSpec* pspec, gpointer data)
-{
- WebKitDownload* download = WEBKIT_DOWNLOAD(object);
- switch (webkit_download_get_status(download)) {
- case WEBKIT_DOWNLOAD_STATUS_FINISHED:
- case WEBKIT_DOWNLOAD_STATUS_ERROR:
- g_main_loop_quit(loop);
- break;
- case WEBKIT_DOWNLOAD_STATUS_CANCELLED:
- g_assert_not_reached();
- break;
- default:
- break;
- }
-}
-
-static gboolean
-set_filename(gchar* filename)
-{
- gchar *uri = g_filename_to_uri(filename, NULL, NULL);
-
- webkit_download_set_destination_uri(theDownload, uri);
- g_free(uri);
-
- webkit_download_start(theDownload);
- return FALSE;
-}
-
-static void
-handle_download_requested_cb(WebKitDownload* download,
- gboolean* beenThere,
- gboolean asynch)
-{
- theDownload = download;
- *beenThere = TRUE;
-
- if (temporaryFilename) {
- if (asynch) {
- g_idle_add((GSourceFunc)set_filename, temporaryFilename);
- } else {
- gchar *uri = g_filename_to_uri(temporaryFilename, NULL, NULL);
- if (uri)
- webkit_download_set_destination_uri(download, uri);
- g_free(uri);
- }
- }
-
- g_signal_connect(download, "notify::status",
- G_CALLBACK(notify_status_cb), NULL);
-}
-
-static gboolean
-download_requested_cb(WebKitWebView* web_view,
- WebKitDownload* download,
- gboolean* beenThere)
-{
- handle_download_requested_cb(download, beenThere, FALSE);
- return TRUE;
-}
-
-static gboolean
-download_requested_asynch_cb(WebKitWebView* web_view,
- WebKitDownload* download,
- gboolean* beenThere)
-{
- handle_download_requested_cb(download, beenThere, TRUE);
- return TRUE;
-}
-
-static void
-test_webkit_download_perform(gboolean asynch)
-{
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- GCallback downloadRequestCallback = NULL;
-
- g_object_ref_sink(G_OBJECT(webView));
-
- g_signal_connect(webView, "navigation-policy-decision-requested",
- G_CALLBACK(navigation_policy_decision_requested_cb),
- NULL);
-
- if (asynch)
- downloadRequestCallback = G_CALLBACK(download_requested_asynch_cb);
- else
- downloadRequestCallback = G_CALLBACK(download_requested_cb);
-
- gboolean beenThere = FALSE;
- g_signal_connect(webView, "download-requested",
- downloadRequestCallback, &beenThere);
-
- /* Preparation; FIXME: we should move this code to a test
- * utilities file, because we have a very similar one in
- * testwebframe.c */
- GError *error = NULL;
- gchar* filename;
- int fd = g_file_open_tmp("webkit-testwebdownload-XXXXXX", &filename, &error);
- close(fd);
-
- if (error)
- g_critical("Failed to open a temporary file for writing: %s.", error->message);
-
- if (g_unlink(filename) == -1)
- g_critical("Failed to delete the temporary file: %s.", g_strerror(errno));
-
- theDownload = NULL;
- temporaryFilename = filename;
-
- loop = g_main_loop_new(NULL, TRUE);
- webkit_web_view_load_uri(webView, "http://gnome.org/");
- g_main_loop_run(loop);
-
- g_assert_cmpint(beenThere, ==, TRUE);
-
- g_assert_cmpint(g_file_test(temporaryFilename, G_FILE_TEST_IS_REGULAR), ==, TRUE);
-
- g_unlink(temporaryFilename);
- g_free(temporaryFilename);
- temporaryFilename = NULL;
-
- g_main_loop_unref(loop);
- g_object_unref(webView);
-}
-
-static void
-test_webkit_download_synch(void)
-{
- test_webkit_download_perform(FALSE);
-}
-
-static void
-test_webkit_download_asynch(void)
-{
- test_webkit_download_perform(TRUE);
-}
-
-static gboolean mime_type_policy_decision_requested_cb(WebKitWebView* view, WebKitWebFrame* frame,
- WebKitNetworkRequest* request, const char* mime_type,
- WebKitWebPolicyDecision* decision, gpointer data)
-{
- webkit_web_policy_decision_download(decision);
- return TRUE;
-}
-
-static void idle_quit_loop_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
-{
- if (webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FINISHED ||
- webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FAILED)
- g_main_loop_quit(loop);
-}
-
-static void
-test_webkit_download_data(void)
-{
- gboolean beenThere = FALSE;
- WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
-
- g_signal_connect(webView, "download-requested",
- G_CALLBACK(download_requested_cb),
- &beenThere);
-
- g_signal_connect(webView, "notify::load-status",
- G_CALLBACK(idle_quit_loop_cb),
- NULL);
-
- g_signal_connect(webView, "mime-type-policy-decision-requested",
- G_CALLBACK(mime_type_policy_decision_requested_cb),
- NULL);
-
- loop = g_main_loop_new(NULL, TRUE);
-
- /* We're testing for a crash, so just not crashing is a pass */
- webkit_web_view_load_uri(webView, "data:application/octect-stream,");
- g_main_loop_run(loop);
-
- g_assert_cmpint(beenThere, ==, TRUE);
-
- g_main_loop_unref(loop);
- g_object_unref(webView);
-}
-
-static void notifyDownloadStatusCallback(GObject *object, GParamSpec *pspec, gpointer data)
-{
- WebKitDownload *download = WEBKIT_DOWNLOAD(object);
- WebKitNetworkResponse *response = webkit_download_get_network_response(download);
- SoupMessage *message = webkit_network_response_get_message(response);
-
- switch (webkit_download_get_status(download)) {
- case WEBKIT_DOWNLOAD_STATUS_ERROR:
- g_assert_cmpint(message->status_code, ==, 404);
- g_main_loop_quit(loop);
- break;
- case WEBKIT_DOWNLOAD_STATUS_FINISHED:
- case WEBKIT_DOWNLOAD_STATUS_CANCELLED:
- g_assert_not_reached();
- break;
- default:
- break;
- }
-}
-
-static void serverCallback(SoupServer *server, SoupMessage *message, const char *path, GHashTable *query, SoupClientContext *context, gpointer userData)
-{
- if (message->method != SOUP_METHOD_GET) {
- soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
- return;
- }
-
- soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
- soup_message_body_complete(message->response_body);
-}
-
-static void test_webkit_download_not_found(void)
-{
- SoupServer *server = soup_server_new(SOUP_SERVER_PORT, 0, NULL);
- soup_server_run_async(server);
- soup_server_add_handler(server, NULL, serverCallback, NULL, NULL);
- SoupURI *baseURI = soup_uri_new("http://127.0.0.1/");
- soup_uri_set_port(baseURI, soup_server_get_port(server));
-
- SoupURI *uri = soup_uri_new_with_base(baseURI, "/foo");
- char *uriString = soup_uri_to_string(uri, FALSE);
- soup_uri_free(uri);
-
- loop = g_main_loop_new(NULL, TRUE);
- WebKitNetworkRequest *request = webkit_network_request_new(uriString);
- g_free (uriString);
- WebKitDownload *download = webkit_download_new(request);
- g_object_unref(request);
-
- webkit_download_set_destination_uri(download, "file:///tmp/foo");
- g_signal_connect(download, "notify::status", G_CALLBACK(notifyDownloadStatusCallback), NULL);
-
- webkit_download_start(download);
- g_main_loop_run(loop);
-
- g_object_unref(download);
- g_main_loop_unref(loop);
- soup_uri_free(baseURI);
- g_object_unref(server);
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- // Get rid of runtime warnings about deprecated properties and signals, since they break the tests.
- g_setenv("G_ENABLE_DIAGNOSTIC", "0", TRUE);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_func("/webkit/download/create", test_webkit_download_create);
- g_test_add_func("/webkit/download/synch", test_webkit_download_synch);
- g_test_add_func("/webkit/download/asynch", test_webkit_download_asynch);
- g_test_add_func("/webkit/download/data", test_webkit_download_data);
- g_test_add_func("/webkit/download/not-found", test_webkit_download_not_found);
- return g_test_run ();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testfavicondatabase.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testfavicondatabase.c
deleted file mode 100644
index 393732b85..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testfavicondatabase.c
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Copyright (C) 2012 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include "test_utils.h"
-#include <glib/gstdio.h>
-#include <gtk/gtk.h>
-#include <string.h>
-#include <webkit/webkit.h>
-
-const int gIconSize = 16;
-
-GMainLoop *loop;
-char *baseURI;
-
-static void
-serverCallback(SoupServer *server, SoupMessage *message, const char *path, GHashTable *query, SoupClientContext *context, void *data)
-{
- if (message->method != SOUP_METHOD_GET) {
- soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
- return;
- }
-
- soup_message_set_status(message, SOUP_STATUS_OK);
-
- char *contents;
- gsize length;
- if (g_str_equal(path, "/favicon.ico")) {
- GError *error = NULL;
-
- g_file_get_contents("blank.ico", &contents, &length, &error);
- g_assert(!error);
- } else {
- contents = g_strdup("<html><body>test</body></html>");
- length = strlen(contents);
- }
-
- soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, contents, length);
- soup_message_body_complete(message->response_body);
-}
-
-static void deleteDatabaseFileIfExists(const char *databasePath)
-{
- if (!g_file_test(databasePath, G_FILE_TEST_IS_DIR))
- return;
-
- char *databaseFilename = g_build_filename(databasePath, "WebpageIcons.db", NULL);
- if (g_unlink(databaseFilename) == -1) {
- g_free(databaseFilename);
- return;
- }
-
- g_free(databaseFilename);
- g_rmdir(databasePath);
-}
-
-static void testWebKitFaviconDatabaseSetPath()
-{
- char *databasePath = g_build_filename(g_get_tmp_dir(), "webkit-testfavicondatabase", NULL);
- deleteDatabaseFileIfExists(databasePath);
-
- WebKitFaviconDatabase *database = webkit_get_favicon_database();
- webkit_favicon_database_set_path(database, databasePath);
-
- g_assert_cmpstr(databasePath, ==, webkit_favicon_database_get_path(database));
-
- g_free(databasePath);
-}
-
-// See the comment in main() function that goes with this same guard.
-#ifdef NDEBUG
-
-static void faviconDatabaseGetValidFaviconCallback(GObject *sourceObject, GAsyncResult *result, void *userData)
-{
- gboolean *beenHere = (gboolean*)userData;
- GError *error = NULL;
- GdkPixbuf *icon = webkit_favicon_database_get_favicon_pixbuf_finish(WEBKIT_FAVICON_DATABASE(sourceObject), result, &error);
- g_assert(icon);
- g_object_unref(icon);
-
- *beenHere = TRUE;
-
- g_main_loop_quit(loop);
-}
-
-static void faviconDatabaseGetInvalidFaviconCallback(GObject *sourceObject, GAsyncResult *result, void *userData)
-{
- gboolean *beenHere = (gboolean*)userData;
- GError *error = NULL;
- GdkPixbuf *icon = webkit_favicon_database_get_favicon_pixbuf_finish(WEBKIT_FAVICON_DATABASE(sourceObject), result, &error);
- g_assert(!icon);
-
- *beenHere = TRUE;
-
- g_main_loop_quit(loop);
-}
-
-static void faviconDatabaseGetFaviconCancelledCallback(GObject *sourceObject, GAsyncResult *result, void *userData)
-{
- gboolean *beenHere = (gboolean*)userData;
- GError *error = NULL;
- GdkPixbuf *icon = webkit_favicon_database_get_favicon_pixbuf_finish(WEBKIT_FAVICON_DATABASE(sourceObject), result, &error);
- g_assert(!icon);
- g_assert(error && g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED));
-
- *beenHere = TRUE;
-
- g_main_loop_quit(loop);
-}
-
-static inline void quitMainLoopIfLoadCompleted(gboolean *iconOrPageLoaded)
-{
- if (*iconOrPageLoaded)
- g_main_loop_quit(loop);
- else
- *iconOrPageLoaded = TRUE;
-}
-
-static void idleQuitLoopCallback(WebKitWebView *webView, GParamSpec *paramSpec, gboolean *iconOrPageLoaded)
-{
- WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
-
- if (status == WEBKIT_LOAD_FINISHED || status == WEBKIT_LOAD_FAILED)
- quitMainLoopIfLoadCompleted(iconOrPageLoaded);
-}
-
-static void webkitWebViewIconLoaded(WebKitFaviconDatabase *database, const char *frameURI, gboolean *iconOrPageLoaded)
-{
- quitMainLoopIfLoadCompleted(iconOrPageLoaded);
-}
-
-static void loadURI(const char *uri)
-{
- WebKitWebView *view = WEBKIT_WEB_VIEW(webkit_web_view_new());
- gboolean iconOrPageLoaded = FALSE;
-
- webkit_web_view_load_uri(view, uri);
-
- g_signal_connect(view, "notify::load-status", G_CALLBACK(idleQuitLoopCallback), &iconOrPageLoaded);
- g_signal_connect(view, "icon-loaded", G_CALLBACK(webkitWebViewIconLoaded), &iconOrPageLoaded);
-
- g_main_loop_run(loop);
-
- g_signal_handlers_disconnect_matched(view, G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, &iconOrPageLoaded);
-}
-
-static gboolean faviconDatabaseGetValidFaviconIdle(void *userData)
-{
- webkit_favicon_database_get_favicon_pixbuf(webkit_get_favicon_database(), baseURI,
- gIconSize, gIconSize, NULL,
- faviconDatabaseGetValidFaviconCallback, userData);
- return FALSE;
-}
-
-static gboolean faviconDatabaseGetInvalidFaviconIdle(void *userData)
-{
- webkit_favicon_database_get_favicon_pixbuf(webkit_get_favicon_database(), "http://www.webkitgtk.org/",
- gIconSize, gIconSize, NULL,
- faviconDatabaseGetInvalidFaviconCallback, userData);
- return FALSE;
-}
-
-static gboolean faviconDatabaseGetFaviconCancelledIdle(void *userData)
-{
- GCancellable *cancellable = g_cancellable_new();
- webkit_favicon_database_get_favicon_pixbuf(webkit_get_favicon_database(), baseURI,
- gIconSize, gIconSize, cancellable,
- faviconDatabaseGetFaviconCancelledCallback, userData);
- g_cancellable_cancel(cancellable);
- g_object_unref(cancellable);
- return FALSE;
-}
-
-static void testWebKitFaviconDatabaseGetFavicon()
-{
- gboolean beenToIconCallback;
-
- loop = g_main_loop_new(NULL, TRUE);
-
- /* Load uri to make sure favicon is added to database. */
- loadURI(baseURI);
-
- beenToIconCallback = FALSE;
- g_idle_add((GSourceFunc)faviconDatabaseGetValidFaviconIdle, &beenToIconCallback);
- g_main_loop_run(loop);
- g_assert(beenToIconCallback);
-
- beenToIconCallback = FALSE;
- g_idle_add((GSourceFunc)faviconDatabaseGetInvalidFaviconIdle, &beenToIconCallback);
- g_main_loop_run(loop);
- g_assert(beenToIconCallback);
-
- beenToIconCallback = FALSE;
- g_idle_add((GSourceFunc)faviconDatabaseGetFaviconCancelledIdle, &beenToIconCallback);
- g_main_loop_run(loop);
- g_assert(beenToIconCallback);
-}
-
-static void testWebKitFaviconDatabaseGetFaviconURI()
-{
- char *iconURI = webkit_favicon_database_get_favicon_uri(webkit_get_favicon_database(), baseURI);
- char *expectedURI = g_strdup_printf("%sfavicon.ico", baseURI);
- g_assert_cmpstr(iconURI, ==, expectedURI);
- g_free(expectedURI);
- g_free(iconURI);
-}
-
-#endif
-
-static void testWebKitFaviconDatabaseRemoveAll(void)
-{
- WebKitFaviconDatabase *database = webkit_get_favicon_database();
- webkit_favicon_database_clear(database);
- char *iconURI = webkit_favicon_database_get_favicon_uri(database, baseURI);
- g_assert(!iconURI);
- g_free(iconURI);
-}
-
-static void testWebKitFaviconDatabaseCloseDatabase(void)
-{
- WebKitFaviconDatabase *database = webkit_get_favicon_database();
- char *databasePath = g_strdup(webkit_favicon_database_get_path(database));
- webkit_favicon_database_set_path(database, 0);
- deleteDatabaseFileIfExists(databasePath);
- g_free(databasePath);
-}
-
-int main(int argc, char **argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- // Get rid of runtime warnings about deprecated properties and signals, since they break the tests.
- g_setenv("G_ENABLE_DIAGNOSTIC", "0", TRUE);
-
- /* This hopefully makes the test independent of the path it's called from. */
- testutils_relative_chdir("Tools/TestWebKitAPI/Tests/WebKitGtk/resources/test.html", argv[0]);
-
- SoupServer *server = soup_server_new(SOUP_SERVER_PORT, 0, NULL);
- soup_server_run_async(server);
-
- soup_server_add_handler(server, NULL, serverCallback, NULL, NULL);
-
- SoupURI *soupURI = soup_uri_new("http://127.0.0.1/");
- soup_uri_set_port(soupURI, soup_server_get_port(server));
-
- baseURI = soup_uri_to_string(soupURI, FALSE);
- soup_uri_free(soupURI);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_func("/webkit/favicondatabase/set-path", testWebKitFaviconDatabaseSetPath);
-
- // These two tests will trigger an ASSERTION on debug builds due
- // to http://webkit.org/b/67582. Remove the guards once the bug is fixed.
-#ifdef NDEBUG
- g_test_add_func("/webkit/favicondatabase/get-favicon", testWebKitFaviconDatabaseGetFavicon);
- g_test_add_func("/webkit/favicondatabase/get-favicon-uri", testWebKitFaviconDatabaseGetFaviconURI);
-#endif
-
- g_test_add_func("/webkit/favicondatabase/remove-all", testWebKitFaviconDatabaseRemoveAll);
- g_test_add_func("/webkit/favicondatabase/close-db", testWebKitFaviconDatabaseCloseDatabase);
-
- return g_test_run();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testglobals.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testglobals.c
deleted file mode 100644
index 4b9ec4fcf..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testglobals.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2010 Collabora Ltd.
- *
- * 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 <gtk/gtk.h>
-#include <libsoup/soup.h>
-#include <webkit/webkit.h>
-
-// Make sure the session is initialized properly when webkit_get_default_session() is called.
-static void test_globals_default_session()
-{
- g_test_bug("36754");
-
- SoupSession* session = webkit_get_default_session();
- soup_session_remove_feature_by_type(session, WEBKIT_TYPE_SOUP_AUTH_DIALOG);
-
- // This makes sure our initialization ran.
- g_assert(soup_session_get_feature(session, SOUP_TYPE_CONTENT_DECODER) != NULL);
-
- // Creating a WebView should make sure the session is
- // initialized, and not mess with our changes.
- WebKitWebView* web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(web_view);
- g_object_unref(web_view);
-
- // These makes sure our modification was kept.
- g_assert(soup_session_get_feature(session, SOUP_TYPE_CONTENT_DECODER) != NULL);
- g_assert(soup_session_get_feature(session, WEBKIT_TYPE_SOUP_AUTH_DIALOG) == NULL);
-}
-
-static void test_globals_security_policy()
-{
- // Check default policy for well known schemes.
- WebKitSecurityPolicy policy = webkit_get_security_policy_for_uri_scheme("http");
- guint mask = WEBKIT_SECURITY_POLICY_CORS_ENABLED;
- g_assert_cmpuint(policy & mask, ==, mask);
-
- policy = webkit_get_security_policy_for_uri_scheme("https");
- mask = WEBKIT_SECURITY_POLICY_SECURE | WEBKIT_SECURITY_POLICY_CORS_ENABLED;
- g_assert_cmpuint(policy & mask, ==, mask);
-
- policy = webkit_get_security_policy_for_uri_scheme("file");
- mask = WEBKIT_SECURITY_POLICY_LOCAL;
- g_assert_cmpuint(policy & mask, ==, mask);
-
- policy = webkit_get_security_policy_for_uri_scheme("data");
- mask = WEBKIT_SECURITY_POLICY_NO_ACCESS_TO_OTHER_SCHEME | WEBKIT_SECURITY_POLICY_SECURE;
- g_assert_cmpuint(policy & mask, ==, mask);
-
- policy = webkit_get_security_policy_for_uri_scheme("about");
- mask = WEBKIT_SECURITY_POLICY_NO_ACCESS_TO_OTHER_SCHEME | WEBKIT_SECURITY_POLICY_SECURE | WEBKIT_SECURITY_POLICY_EMPTY_DOCUMENT;
- g_assert_cmpuint(policy & mask, ==, mask);
-
- // Custom scheme.
- policy = webkit_get_security_policy_for_uri_scheme("foo");
- g_assert(!policy);
-
- policy |= WEBKIT_SECURITY_POLICY_LOCAL;
- webkit_set_security_policy_for_uri_scheme("foo", policy);
- g_assert_cmpuint(webkit_get_security_policy_for_uri_scheme("foo"), ==, policy);
-
- policy |= WEBKIT_SECURITY_POLICY_NO_ACCESS_TO_OTHER_SCHEME;
- webkit_set_security_policy_for_uri_scheme("foo", policy);
- g_assert_cmpuint(webkit_get_security_policy_for_uri_scheme("foo"), ==, policy);
-
- policy |= WEBKIT_SECURITY_POLICY_DISPLAY_ISOLATED;
- webkit_set_security_policy_for_uri_scheme("foo", policy);
- g_assert_cmpuint(webkit_get_security_policy_for_uri_scheme("foo"), ==, policy);
-
- policy |= WEBKIT_SECURITY_POLICY_SECURE;
- webkit_set_security_policy_for_uri_scheme("foo", policy);
- g_assert_cmpuint(webkit_get_security_policy_for_uri_scheme("foo"), ==, policy);
-
- policy |= WEBKIT_SECURITY_POLICY_CORS_ENABLED;
- webkit_set_security_policy_for_uri_scheme("foo", policy);
- g_assert_cmpuint(webkit_get_security_policy_for_uri_scheme("foo"), ==, policy);
-
- policy |= WEBKIT_SECURITY_POLICY_EMPTY_DOCUMENT;
- webkit_set_security_policy_for_uri_scheme("foo", policy);
- g_assert_cmpuint(webkit_get_security_policy_for_uri_scheme("foo"), ==, policy);
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_func("/webkit/globals/default_session",
- test_globals_default_session);
- g_test_add_func("/webkit/globals/security-policy",
- test_globals_security_policy);
- return g_test_run();
-}
-
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testhittestresult.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testhittestresult.c
deleted file mode 100644
index eac34c47b..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testhittestresult.c
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Copyright (C) 2009 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2,1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include <errno.h>
-#include <unistd.h>
-#include <glib/gstdio.h>
-#include <webkit/webkit.h>
-
-typedef struct {
- char* data;
- guint flag;
-} TestInfo;
-
-static GMainLoop* loop;
-
-typedef struct {
- WebKitWebView* webView;
- TestInfo* info;
-} HitTestResultFixture;
-
-TestInfo*
-test_info_new(const char* data, guint flag)
-{
- TestInfo* info;
-
- info = g_slice_new(TestInfo);
- info->data = g_strdup(data);
- info->flag = flag;
-
- return info;
-}
-
-void
-test_info_destroy(TestInfo* info)
-{
- g_free(info->data);
- g_slice_free(TestInfo, info);
-}
-
-static void hit_test_result_fixture_setup(HitTestResultFixture* fixture, gconstpointer data)
-{
- fixture->webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(fixture->webView);
- loop = g_main_loop_new(NULL, TRUE);
- fixture->info = (TestInfo*)data;
-}
-
-static void hit_test_result_fixture_teardown(HitTestResultFixture* fixture, gconstpointer data)
-{
- g_object_unref(fixture->webView);
- g_main_loop_unref(loop);
- test_info_destroy(fixture->info);
-}
-
-static void
-load_status_cb(WebKitWebView* webView,
- GParamSpec* spec,
- gpointer data)
-{
- WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
- TestInfo* info = (TestInfo*)data;
-
- if (status == WEBKIT_LOAD_FINISHED) {
- WebKitHitTestResult* result;
- guint context;
- GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS);
- WebKitDOMNode* node;
- gint x, y;
-
- /* Close enough to 0,0 */
- event->button.x = 5;
- event->button.y = 5;
-
- result = webkit_web_view_get_hit_test_result(webView, (GdkEventButton*) event);
- gdk_event_free(event);
- g_assert(result);
-
- g_object_get(result, "context", &context, NULL);
- g_assert(context & info->flag);
-
- g_object_get(result, "inner-node", &node, NULL);
- g_assert(node);
- g_assert(WEBKIT_DOM_IS_NODE(node));
-
- g_object_get(result, "x", &x, "y", &y, NULL);
- g_assert_cmpint(x, ==, 5);
- g_assert_cmpint(y, ==, 5);
-
- /* We can only test these node types at the moment. In the
- * input case there seems to be an extra layer with a DIV on
- * top of the input, which gets assigned to the inner-node.
- * tag */
- if (info->flag == WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT)
- g_assert(WEBKIT_DOM_IS_HTML_HTML_ELEMENT(node));
- else if (info->flag == WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE)
- g_assert(WEBKIT_DOM_IS_HTML_IMAGE_ELEMENT(node));
- else if (info->flag == WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK) {
- /* The hit test will give us the inner text node, we want
- * the A tag */
- WebKitDOMNode* parent = webkit_dom_node_get_parent_node(node);
- g_assert(WEBKIT_DOM_IS_HTML_ANCHOR_ELEMENT(parent));
- }
-
- g_object_unref(result);
- g_main_loop_quit(loop);
- }
-}
-
-static void
-test_webkit_hit_test_result(HitTestResultFixture* fixture, gconstpointer data)
-{
- TestInfo* info = (TestInfo*)data;
- GtkAllocation allocation = { 0, 0, 50, 50 };
-
- webkit_web_view_load_string(fixture->webView,
- info->data,
- "text/html",
- "utf-8",
- "file://");
- gtk_widget_size_allocate(GTK_WIDGET(fixture->webView), &allocation);
- g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_status_cb), info);
- g_main_loop_run(loop);
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
- // Get rid of runtime warnings about deprecated properties and signals, since they break the tests.
- g_setenv("G_ENABLE_DIAGNOSTIC", "0", TRUE);
-
- g_test_bug_base("https://bugs.webkit.org/");
-
- g_test_add("/webkit/hittestresult/document", HitTestResultFixture,
- test_info_new("<html><body><h1>WebKitGTK+!</h1></body></html>",
- WEBKIT_HIT_TEST_RESULT_CONTEXT_DOCUMENT),
- hit_test_result_fixture_setup, test_webkit_hit_test_result, hit_test_result_fixture_teardown);
- /* We hardcode all elements to be at 0,0 so that we know where to
- * generate the button events */
- g_test_add("/webkit/hittestresult/image", HitTestResultFixture,
- test_info_new("<html><body><img style='position:absolute; left:0; top:0'src='0xdeadbeef' width=50 height=50></img></body></html>",
- WEBKIT_HIT_TEST_RESULT_CONTEXT_IMAGE),
- hit_test_result_fixture_setup, test_webkit_hit_test_result, hit_test_result_fixture_teardown);
- g_test_add("/webkit/hittestresult/editable", HitTestResultFixture,
- test_info_new("<html><body><input style='position:absolute; left:0; top:0' size='35'></input>></body></html>",
- WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE),
- hit_test_result_fixture_setup, test_webkit_hit_test_result, hit_test_result_fixture_teardown);
- g_test_add("/webkit/hittestresult/link", HitTestResultFixture,
- test_info_new("<html><body><a style='position:absolute; left:0; top:0' href='http://www.example.com'>HELLO WORLD</a></body></html>",
- WEBKIT_HIT_TEST_RESULT_CONTEXT_LINK),
- hit_test_result_fixture_setup, test_webkit_hit_test_result, hit_test_result_fixture_teardown);
-
- return g_test_run ();
-}
-
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testhttpbackend.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testhttpbackend.c
deleted file mode 100644
index 93776879b..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testhttpbackend.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2009 Gustavo Noronha Silva
- *
- * 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 <errno.h>
-#include <unistd.h>
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-// Not yet public API
-SoupMessage* webkit_network_request_get_message(WebKitNetworkRequest* request);
-
-static gboolean navigation_policy_decision_requested_cb(WebKitWebView* web_view,
- WebKitWebFrame* web_frame,
- WebKitNetworkRequest* request,
- WebKitWebNavigationAction* action,
- WebKitWebPolicyDecision* decision,
- gpointer data)
-{
- SoupMessage* message = webkit_network_request_get_message(request);
-
- /* 1 -> webkit_network_request_with_core_request
- *
- * The SoupMessage is created exclusively for the emission of this
- * signal.
- */
- g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1);
-
- return FALSE;
-}
-
-static void test_soup_message_lifetime()
-{
- WebKitWebView* web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
-
- g_object_ref_sink(web_view);
-
- g_signal_connect(web_view, "navigation-policy-decision-requested",
- G_CALLBACK(navigation_policy_decision_requested_cb),
- NULL);
-
- /* load_uri will trigger the navigation-policy-decision-requested
- * signal emission;
- */
- webkit_web_view_load_uri(web_view, "http://127.0.0.1/");
-
- g_object_unref(web_view);
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_func("/webkit/soupmessage/lifetime", test_soup_message_lifetime);
- return g_test_run ();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testkeyevents.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testkeyevents.c
deleted file mode 100644
index acd01f35f..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testkeyevents.c
+++ /dev/null
@@ -1,390 +0,0 @@
-/*
- * Copyright (C) 2009, 2010 Martin Robinson <mrobinson@webkit.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2,1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-#include <glib/gstdio.h>
-#include <webkit/webkit.h>
-#include <JavaScriptCore/JSStringRef.h>
-#include <JavaScriptCore/JSContextRef.h>
-
-typedef struct {
- char* page;
- char* text;
- gboolean shouldBeHandled;
-} TestInfo;
-
-typedef struct {
- GtkWidget* window;
- WebKitWebView* webView;
- GMainLoop* loop;
- TestInfo* info;
-} KeyEventFixture;
-
-TestInfo*
-test_info_new(const char* page, gboolean shouldBeHandled)
-{
- TestInfo* info;
-
- info = g_slice_new(TestInfo);
- info->page = g_strdup(page);
- info->shouldBeHandled = shouldBeHandled;
- info->text = 0;
-
- return info;
-}
-
-void
-test_info_destroy(TestInfo* info)
-{
- g_free(info->page);
- g_free(info->text);
- g_slice_free(TestInfo, info);
-}
-
-static void key_event_fixture_setup(KeyEventFixture* fixture, gconstpointer data)
-{
- fixture->loop = g_main_loop_new(NULL, TRUE);
-
- fixture->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- fixture->webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
-
- gtk_container_add(GTK_CONTAINER(fixture->window), GTK_WIDGET(fixture->webView));
-}
-
-static void key_event_fixture_teardown(KeyEventFixture* fixture, gconstpointer data)
-{
- gtk_widget_destroy(fixture->window);
- g_main_loop_unref(fixture->loop);
- test_info_destroy(fixture->info);
-}
-
-static gboolean key_press_event_cb(WebKitWebView* webView, GdkEvent* event, gpointer data)
-{
- KeyEventFixture* fixture = (KeyEventFixture*)data;
- gboolean handled = GTK_WIDGET_GET_CLASS(fixture->webView)->key_press_event(GTK_WIDGET(fixture->webView), &event->key);
- g_assert_cmpint(handled, ==, fixture->info->shouldBeHandled);
-
- return FALSE;
-}
-
-static gboolean key_release_event_cb(WebKitWebView* webView, GdkEvent* event, gpointer data)
-{
- // WebCore never seems to mark keyup events as handled.
- KeyEventFixture* fixture = (KeyEventFixture*)data;
- gboolean handled = GTK_WIDGET_GET_CLASS(fixture->webView)->key_press_event(GTK_WIDGET(fixture->webView), &event->key);
- g_assert(!handled);
-
- g_main_loop_quit(fixture->loop);
-
- return FALSE;
-}
-
-static void test_keypress_events_load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data)
-{
- KeyEventFixture* fixture = (KeyEventFixture*)data;
- WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
- if (status == WEBKIT_LOAD_FINISHED) {
- g_signal_connect(fixture->webView, "key-press-event",
- G_CALLBACK(key_press_event_cb), fixture);
- g_signal_connect(fixture->webView, "key-release-event",
- G_CALLBACK(key_release_event_cb), fixture);
- if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
- gdk_unicode_to_keyval('a'), 0))
- g_assert_not_reached();
- }
-
-}
-
-gboolean map_event_cb(GtkWidget *widget, GdkEvent* event, gpointer data)
-{
- KeyEventFixture* fixture = (KeyEventFixture*)data;
- webkit_web_view_load_string(fixture->webView, fixture->info->page,
- "text/html", "utf-8", "file://");
- return FALSE;
-}
-
-static void setup_keyevent_test(KeyEventFixture* fixture, gconstpointer data, GCallback load_event_callback)
-{
- fixture->info = (TestInfo*)data;
- g_signal_connect(fixture->window, "map-event",
- G_CALLBACK(map_event_cb), fixture);
-
- gtk_widget_grab_focus(GTK_WIDGET(fixture->webView));
- gtk_widget_show(fixture->window);
- gtk_widget_show(GTK_WIDGET(fixture->webView));
- gtk_window_present(GTK_WINDOW(fixture->window));
-
- g_signal_connect(fixture->webView, "notify::load-status",
- load_event_callback, fixture);
-
- g_main_loop_run(fixture->loop);
-}
-
-static void test_keypress_events(KeyEventFixture* fixture, gconstpointer data)
-{
- setup_keyevent_test(fixture, data, G_CALLBACK(test_keypress_events_load_status_cb));
-}
-
-static gboolean element_text_equal_to(JSContextRef context, const gchar* text)
-{
- JSStringRef scriptString = JSStringCreateWithUTF8CString(
- "window.document.getElementById(\"in\").value;");
- JSValueRef value = JSEvaluateScript(context, scriptString, 0, 0, 0, 0);
- JSStringRelease(scriptString);
-
- // If the value isn't a string, the element is probably a div
- // so grab the innerText instead.
- if (!JSValueIsString(context, value)) {
- JSStringRef scriptString = JSStringCreateWithUTF8CString(
- "window.document.getElementById(\"in\").innerText;");
- value = JSEvaluateScript(context, scriptString, 0, 0, 0, 0);
- JSStringRelease(scriptString);
- }
-
- g_assert(JSValueIsString(context, value));
- JSStringRef inputString = JSValueToStringCopy(context, value, 0);
- g_assert(inputString);
-
- gint size = JSStringGetMaximumUTF8CStringSize(inputString);
- gchar* cString = g_malloc(size);
- JSStringGetUTF8CString(inputString, cString, size);
- JSStringRelease(inputString);
-
- gboolean result = g_utf8_collate(cString, text) == 0;
- g_free(cString);
- return result;
-}
-
-static void test_ime_load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data)
-{
- KeyEventFixture* fixture = (KeyEventFixture*)data;
- WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
- if (status != WEBKIT_LOAD_FINISHED)
- return;
-
- JSGlobalContextRef context = webkit_web_frame_get_global_context(
- webkit_web_view_get_main_frame(webView));
- g_assert(context);
-
- GtkIMContext* imContext = 0;
- g_object_get(webView, "im-context", &imContext, NULL);
- g_assert(imContext);
-
- // Test that commits that happen outside of key events
- // change the text field immediately. This closely replicates
- // the behavior of SCIM.
- g_assert(element_text_equal_to(context, ""));
- g_signal_emit_by_name(imContext, "commit", "a");
- g_assert(element_text_equal_to(context, "a"));
- g_signal_emit_by_name(imContext, "commit", "b");
- g_assert(element_text_equal_to(context, "ab"));
- g_signal_emit_by_name(imContext, "commit", "c");
- g_assert(element_text_equal_to(context, "abc"));
-
- g_object_unref(imContext);
- g_main_loop_quit(fixture->loop);
-}
-
-static void test_ime(KeyEventFixture* fixture, gconstpointer data)
-{
- setup_keyevent_test(fixture, data, G_CALLBACK(test_ime_load_status_cb));
-}
-
-static gboolean verify_contents(gpointer data)
-{
- KeyEventFixture* fixture = (KeyEventFixture*)data;
- JSGlobalContextRef context = webkit_web_frame_get_global_context(
- webkit_web_view_get_main_frame(fixture->webView));
- g_assert(context);
-
- g_assert(element_text_equal_to(context, fixture->info->text));
- g_main_loop_quit(fixture->loop);
- return FALSE;
-}
-
-static void test_blocking_load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data)
-{
- KeyEventFixture* fixture = (KeyEventFixture*)data;
- WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
- if (status != WEBKIT_LOAD_FINISHED)
- return;
-
- // The first keypress event should not modify the field.
- fixture->info->text = g_strdup("bc");
- if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
- gdk_unicode_to_keyval('a'), 0))
- g_assert_not_reached();
- if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
- gdk_unicode_to_keyval('b'), 0))
- g_assert_not_reached();
- if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
- gdk_unicode_to_keyval('c'), 0))
- g_assert_not_reached();
-
- g_idle_add(verify_contents, fixture);
-}
-
-static void test_blocking(KeyEventFixture* fixture, gconstpointer data)
-{
- setup_keyevent_test(fixture, data, G_CALLBACK(test_blocking_load_status_cb));
-}
-
-#if defined(GDK_WINDOWING_X11)
-static void test_xim_load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data)
-{
- KeyEventFixture* fixture = (KeyEventFixture*)data;
- WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
- if (status != WEBKIT_LOAD_FINISHED)
- return;
-
- GtkIMContext* imContext = 0;
- g_object_get(webView, "im-context", &imContext, NULL);
- g_assert(imContext);
-
- gchar* originalId = g_strdup(gtk_im_multicontext_get_context_id(GTK_IM_MULTICONTEXT(imContext)));
- gtk_im_multicontext_set_context_id(GTK_IM_MULTICONTEXT(imContext), "xim");
-
- // Test that commits that happen outside of key events
- // change the text field immediately. This closely replicates
- // the behavior of SCIM.
- fixture->info->text = g_strdup("debian");
- if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
- gdk_unicode_to_keyval('d'), 0))
- g_assert_not_reached();
- if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
- gdk_unicode_to_keyval('e'), 0))
- g_assert_not_reached();
- if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
- gdk_unicode_to_keyval('b'), 0))
- g_assert_not_reached();
- if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
- gdk_unicode_to_keyval('i'), 0))
- g_assert_not_reached();
- if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
- gdk_unicode_to_keyval('a'), 0))
- g_assert_not_reached();
- if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
- gdk_unicode_to_keyval('n'), 0))
- g_assert_not_reached();
-
- gtk_im_multicontext_set_context_id(GTK_IM_MULTICONTEXT(imContext), originalId);
- g_free(originalId);
- g_object_unref(imContext);
-
- g_idle_add(verify_contents, fixture);
-}
-
-static void test_xim(KeyEventFixture* fixture, gconstpointer data)
-{
- setup_keyevent_test(fixture, data, G_CALLBACK(test_xim_load_status_cb));
-}
-#endif
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
-
-
- // We'll test input on a slew of different node types. Key events to
- // text inputs and editable divs should be marked as handled. Key events
- // to buttons and links should not.
- const char* textinput_html = "<html><body><input id=\"in\" type=\"text\">"
- "<script>document.getElementById('in').focus();</script></body></html>";
- const char* button_html = "<html><body><input id=\"in\" type=\"button\">"
- "<script>document.getElementById('in').focus();</script></body></html>";
- const char* link_html = "<html><body><a href=\"http://www.gnome.org\" id=\"in\">"
- "LINKY MCLINKERSON</a><script>document.getElementById('in').focus();</script>"
- "</body></html>";
- const char* div_html = "<html><body><div id=\"in\" contenteditable=\"true\">"
- "<script>document.getElementById('in').focus();</script></body></html>";
-
- // These are similar to the blocks above, but they should block the first
- // keypress modifying the editable node.
- const char* textinput_html_blocking = "<html><body>"
- "<input id=\"in\" type=\"text\" "
- "onkeypress=\"if (first) {event.preventDefault();first=false;}\">"
- "<script>first = true;\ndocument.getElementById('in').focus();</script>\n"
- "</script></body></html>";
- const char* div_html_blocking = "<html><body>"
- "<div id=\"in\" contenteditable=\"true\" "
- "onkeypress=\"if (first) {event.preventDefault();first=false;}\">"
- "<script>first = true; document.getElementById('in').focus();</script>\n"
- "</script></body></html>";
-
- g_test_add("/webkit/keyevents/event-textinput", KeyEventFixture,
- test_info_new(textinput_html, TRUE),
- key_event_fixture_setup,
- test_keypress_events,
- key_event_fixture_teardown);
- g_test_add("/webkit/keyevents/event-buttons", KeyEventFixture,
- test_info_new(button_html, FALSE),
- key_event_fixture_setup,
- test_keypress_events,
- key_event_fixture_teardown);
- g_test_add("/webkit/keyevents/event-link", KeyEventFixture,
- test_info_new(link_html, FALSE),
- key_event_fixture_setup,
- test_keypress_events,
- key_event_fixture_teardown);
- g_test_add("/webkit/keyevent/event-div", KeyEventFixture,
- test_info_new(div_html, TRUE),
- key_event_fixture_setup,
- test_keypress_events,
- key_event_fixture_teardown);
- g_test_add("/webkit/keyevent/ime-textinput", KeyEventFixture,
- test_info_new(textinput_html, TRUE),
- key_event_fixture_setup,
- test_ime,
- key_event_fixture_teardown);
- g_test_add("/webkit/keyevent/ime-div", KeyEventFixture,
- test_info_new(div_html, TRUE),
- key_event_fixture_setup,
- test_ime,
- key_event_fixture_teardown);
- g_test_add("/webkit/keyevent/block-textinput", KeyEventFixture,
- test_info_new(textinput_html_blocking, TRUE),
- key_event_fixture_setup,
- test_blocking,
- key_event_fixture_teardown);
- g_test_add("/webkit/keyevent/block-div", KeyEventFixture,
- test_info_new(div_html_blocking, TRUE),
- key_event_fixture_setup,
- test_blocking,
- key_event_fixture_teardown);
-#if defined(GDK_WINDOWING_X11)
- g_test_add("/webkit/keyevent/xim-textinput", KeyEventFixture,
- test_info_new(textinput_html, TRUE),
- key_event_fixture_setup,
- test_xim,
- key_event_fixture_teardown);
- g_test_add("/webkit/keyevent/xim-div", KeyEventFixture,
- test_info_new(div_html, TRUE),
- key_event_fixture_setup,
- test_xim,
- key_event_fixture_teardown);
-#endif
-
- return g_test_run();
-}
-
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testloading.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testloading.c
deleted file mode 100644
index 95246ec28..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testloading.c
+++ /dev/null
@@ -1,437 +0,0 @@
-/*
- * Copyright (C) 2009, 2010 Gustavo Noronha Silva
- * Copyright (C) 2009 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include <gtk/gtk.h>
-#include <libsoup/soup.h>
-#include <string.h>
-#include <webkit/webkit.h>
-
-/* This string has to be rather big because of the cancelled test - it
- * looks like soup refuses to send or receive a too small chunk */
-#define HTML_STRING "<html><body>Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!Testing!</body></html>"
-
-SoupURI* base_uri;
-
-/* For real request testing */
-static void
-server_callback(SoupServer* server, SoupMessage* msg,
- const char* path, GHashTable* query,
- SoupClientContext* context, gpointer data)
-{
- if (msg->method != SOUP_METHOD_GET) {
- soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED);
- return;
- }
-
- soup_message_set_status(msg, SOUP_STATUS_OK);
-
- if (g_str_equal(path, "/test_loading_status") || g_str_equal(path, "/test_loading_status2"))
- soup_message_body_append(msg->response_body, SOUP_MEMORY_STATIC, HTML_STRING, strlen(HTML_STRING));
- else if (g_str_equal(path, "/test_load_error")) {
- soup_message_set_status(msg, SOUP_STATUS_CANT_CONNECT);
- } else if (g_str_equal(path, "/test_loading_cancelled")) {
- soup_message_headers_set_encoding(msg->response_headers, SOUP_ENCODING_CHUNKED);
- soup_message_body_append(msg->response_body, SOUP_MEMORY_STATIC, HTML_STRING, strlen(HTML_STRING));
- soup_server_unpause_message(server, msg);
- return;
- }
-
- soup_message_body_complete(msg->response_body);
-}
-
-typedef struct {
- WebKitWebView* webView;
- GMainLoop *loop;
- gboolean has_been_provisional;
- gboolean has_been_committed;
- gboolean has_been_first_visually_non_empty_layout;
- gboolean has_been_finished;
- gboolean has_been_failed;
- gboolean has_been_load_error;
-} WebLoadingFixture;
-
-static void web_loading_fixture_setup(WebLoadingFixture* fixture, gconstpointer data)
-{
- fixture->webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- fixture->loop = g_main_loop_new(NULL, TRUE);
- g_object_ref_sink(fixture->webView);
- fixture->has_been_provisional = FALSE;
- fixture->has_been_committed = FALSE;
- fixture->has_been_first_visually_non_empty_layout = FALSE;
- fixture->has_been_finished = FALSE;
- fixture->has_been_failed = FALSE;
- fixture->has_been_load_error = FALSE;
-}
-
-static void web_loading_fixture_teardown(WebLoadingFixture* fixture, gconstpointer data)
-{
- g_object_unref(fixture->webView);
- g_main_loop_unref(fixture->loop);
-}
-
-static char* get_uri_for_path(const char* path)
-{
- SoupURI* uri;
- char* uri_string;
-
- uri = soup_uri_new_with_base(base_uri, path);
- uri_string = soup_uri_to_string(uri, FALSE);
- soup_uri_free (uri);
-
- return uri_string;
-}
-
-static void load_finished_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, WebLoadingFixture* fixture)
-{
- g_assert(fixture->has_been_provisional);
- g_assert(fixture->has_been_committed);
- g_assert(fixture->has_been_first_visually_non_empty_layout);
-
- g_main_loop_quit(fixture->loop);
-}
-
-
-static void status_changed_cb(GObject* object, GParamSpec* pspec, WebLoadingFixture* fixture)
-{
- WebKitLoadStatus status = webkit_web_view_get_load_status(WEBKIT_WEB_VIEW(object));
-
- switch (status) {
- case WEBKIT_LOAD_PROVISIONAL:
- g_assert(!fixture->has_been_provisional);
- g_assert(!fixture->has_been_committed);
- g_assert(!fixture->has_been_first_visually_non_empty_layout);
- fixture->has_been_provisional = TRUE;
- break;
- case WEBKIT_LOAD_COMMITTED:
- g_assert(fixture->has_been_provisional);
- g_assert(!fixture->has_been_committed);
- g_assert(!fixture->has_been_first_visually_non_empty_layout);
- fixture->has_been_committed = TRUE;
- break;
- case WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT:
- g_assert(fixture->has_been_provisional);
- g_assert(fixture->has_been_committed);
- g_assert(!fixture->has_been_first_visually_non_empty_layout);
- fixture->has_been_first_visually_non_empty_layout = TRUE;
- break;
- case WEBKIT_LOAD_FINISHED:
- g_assert(fixture->has_been_provisional);
- g_assert(fixture->has_been_committed);
- g_assert(fixture->has_been_first_visually_non_empty_layout);
- break;
- default:
- g_assert_not_reached();
- }
-}
-
-static void test_loading_status(WebLoadingFixture* fixture, gconstpointer data)
-{
- char* uri_string;
-
- g_assert_cmpint(webkit_web_view_get_load_status(fixture->webView), ==, WEBKIT_LOAD_PROVISIONAL);
-
- g_object_connect(G_OBJECT(fixture->webView),
- "signal::notify::load-status", G_CALLBACK(status_changed_cb), fixture,
- "signal::load-finished", G_CALLBACK(load_finished_cb), fixture,
- NULL);
-
- uri_string = get_uri_for_path("/test_loading_status");
-
- /* load_uri will trigger the navigation-policy-decision-requested
- * signal emission;
- */
- webkit_web_view_load_uri(fixture->webView, uri_string);
- g_free(uri_string);
-
- g_main_loop_run(fixture->loop);
-}
-
-static void load_error_status_changed_cb(GObject* object, GParamSpec* pspec, WebLoadingFixture* fixture)
-{
- WebKitLoadStatus status = webkit_web_view_get_load_status(WEBKIT_WEB_VIEW(object));
-
- switch(status) {
- case WEBKIT_LOAD_PROVISIONAL:
- g_assert(!fixture->has_been_provisional);
- fixture->has_been_provisional = TRUE;
- break;
- case WEBKIT_LOAD_COMMITTED:
- g_assert(!fixture->has_been_committed);
- fixture->has_been_committed = TRUE;
- break;
- case WEBKIT_LOAD_FINISHED:
- g_assert(fixture->has_been_provisional);
- g_assert(fixture->has_been_load_error);
- g_assert(fixture->has_been_failed);
- g_assert(!fixture->has_been_finished);
- fixture->has_been_finished = TRUE;
- break;
- case WEBKIT_LOAD_FAILED:
- g_assert(!fixture->has_been_failed);
- fixture->has_been_failed = TRUE;
- g_main_loop_quit(fixture->loop);
- break;
- default:
- break;
- }
-}
-
-static gboolean load_error_cb(WebKitWebView* webView, WebKitWebFrame* frame, const char* uri, GError *error, WebLoadingFixture* fixture)
-{
- g_assert(fixture->has_been_provisional);
- g_assert(!fixture->has_been_load_error);
- fixture->has_been_load_error = TRUE;
-
- return FALSE;
-}
-
-static void test_loading_error(WebLoadingFixture* fixture, gconstpointer data)
-{
- char* uri_string;
-
- g_test_bug("28842");
-
- g_signal_connect(fixture->webView, "load-error", G_CALLBACK(load_error_cb), fixture);
- g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_error_status_changed_cb), fixture);
-
- uri_string = get_uri_for_path("/test_load_error");
- webkit_web_view_load_uri(fixture->webView, uri_string);
- g_free(uri_string);
-
- g_main_loop_run(fixture->loop);
-
- g_assert(fixture->has_been_provisional);
- g_assert(!fixture->has_been_committed);
- g_assert(fixture->has_been_load_error);
- g_assert(fixture->has_been_failed);
- g_assert(!fixture->has_been_finished);
-}
-
-/* Cancelled load */
-
-static gboolean load_cancelled_cb(WebKitWebView* webView, WebKitWebFrame* frame, const char* uri, GError *error, WebLoadingFixture* fixture)
-{
- g_assert(fixture->has_been_provisional);
- g_assert(fixture->has_been_failed);
- g_assert(!fixture->has_been_load_error);
- g_assert(error->code == WEBKIT_NETWORK_ERROR_CANCELLED);
- fixture->has_been_load_error = TRUE;
-
- return TRUE;
-}
-
-static gboolean stop_load (gpointer data)
-{
- webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(data));
- return FALSE;
-}
-
-static void load_cancelled_status_changed_cb(GObject* object, GParamSpec* pspec, WebLoadingFixture* fixture)
-{
- WebKitLoadStatus status = webkit_web_view_get_load_status(WEBKIT_WEB_VIEW(object));
-
- switch(status) {
- case WEBKIT_LOAD_PROVISIONAL:
- g_assert(!fixture->has_been_provisional);
- g_assert(!fixture->has_been_failed);
- fixture->has_been_provisional = TRUE;
- break;
- case WEBKIT_LOAD_COMMITTED:
- g_idle_add (stop_load, object);
- break;
- case WEBKIT_LOAD_FAILED:
- g_assert(fixture->has_been_provisional);
- g_assert(!fixture->has_been_failed);
- g_assert(!fixture->has_been_load_error);
- fixture->has_been_failed = TRUE;
- g_main_loop_quit(fixture->loop);
- break;
- case WEBKIT_LOAD_FINISHED:
- g_assert_not_reached();
- break;
- default:
- break;
- }
-}
-
-static void test_loading_cancelled(WebLoadingFixture* fixture, gconstpointer data)
-{
- char* uri_string;
-
- g_test_bug("29644");
-
- g_signal_connect(fixture->webView, "load-error", G_CALLBACK(load_cancelled_cb), fixture);
- g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_cancelled_status_changed_cb), fixture);
-
- uri_string = get_uri_for_path("/test_loading_cancelled");
- webkit_web_view_load_uri(fixture->webView, uri_string);
- g_free(uri_string);
-
- g_main_loop_run(fixture->loop);
-}
-
-static void load_goback_status_changed_cb(GObject* object, GParamSpec* pspec, WebLoadingFixture* fixture)
-{
- WebKitLoadStatus status = webkit_web_view_get_load_status(WEBKIT_WEB_VIEW(object));
-
- switch(status) {
- case WEBKIT_LOAD_PROVISIONAL:
- g_assert(!fixture->has_been_provisional);
- fixture->has_been_provisional = TRUE;
- break;
- case WEBKIT_LOAD_COMMITTED:
- g_assert(fixture->has_been_provisional);
- fixture->has_been_committed = TRUE;
- break;
- case WEBKIT_LOAD_FAILED:
- g_assert_not_reached();
- break;
- case WEBKIT_LOAD_FINISHED:
- g_assert(fixture->has_been_provisional);
- g_assert(fixture->has_been_committed);
- fixture->has_been_finished = TRUE;
- g_main_loop_quit(fixture->loop);
- break;
- default:
- break;
- }
-}
-
-static void load_wentback_status_changed_cb(GObject* object, GParamSpec* pspec, WebLoadingFixture* fixture)
-{
- WebKitLoadStatus status = webkit_web_view_get_load_status(WEBKIT_WEB_VIEW(object));
- char* uri_string;
- char* uri_string2;
-
- uri_string = get_uri_for_path("/test_loading_status");
- uri_string2 = get_uri_for_path("/test_loading_status2");
-
- switch(status) {
- case WEBKIT_LOAD_PROVISIONAL:
- g_assert_cmpstr(webkit_web_view_get_uri(fixture->webView), ==, uri_string2);
- break;
- case WEBKIT_LOAD_COMMITTED:
- g_assert_cmpstr(webkit_web_view_get_uri(fixture->webView), ==, uri_string);
- break;
- case WEBKIT_LOAD_FAILED:
- g_assert_not_reached();
- break;
- case WEBKIT_LOAD_FINISHED:
- g_assert_cmpstr(webkit_web_view_get_uri(fixture->webView), ==, uri_string);
- g_main_loop_quit(fixture->loop);
- break;
- default:
- break;
- }
-
- g_free(uri_string);
- g_free(uri_string2);
-}
-
-static void load_error_test(WebKitWebView* webview, WebKitWebFrame* frame, const char* uri, GError* error)
-{
- g_debug("Error: %s", error->message);
-}
-
-static void test_loading_goback(WebLoadingFixture* fixture, gconstpointer data)
-{
- char* uri_string;
-
- g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_goback_status_changed_cb), fixture);
-
- g_signal_connect(fixture->webView, "load-error", G_CALLBACK(load_error_test), fixture);
-
- uri_string = get_uri_for_path("/test_loading_status");
- webkit_web_view_load_uri(fixture->webView, uri_string);
- g_free(uri_string);
-
- g_main_loop_run(fixture->loop);
-
- fixture->has_been_provisional = FALSE;
- fixture->has_been_committed = FALSE;
- fixture->has_been_first_visually_non_empty_layout = FALSE;
- fixture->has_been_finished = FALSE;
- fixture->has_been_failed = FALSE;
- fixture->has_been_load_error = FALSE;
-
- uri_string = get_uri_for_path("/test_loading_status2");
- webkit_web_view_load_uri(fixture->webView, uri_string);
- g_free(uri_string);
-
- g_main_loop_run(fixture->loop);
-
- g_signal_handlers_disconnect_by_func(fixture->webView, load_goback_status_changed_cb, fixture);
-
- fixture->has_been_provisional = FALSE;
- fixture->has_been_committed = FALSE;
- fixture->has_been_first_visually_non_empty_layout = FALSE;
- fixture->has_been_finished = FALSE;
- fixture->has_been_failed = FALSE;
- fixture->has_been_load_error = FALSE;
-
- g_signal_connect(fixture->webView, "notify::load-status", G_CALLBACK(load_wentback_status_changed_cb), fixture);
- webkit_web_view_go_back(fixture->webView);
-
- g_main_loop_run(fixture->loop);
-
- g_signal_handlers_disconnect_by_func(fixture->webView, load_wentback_status_changed_cb, fixture);
-}
-
-int main(int argc, char** argv)
-{
- SoupServer* server;
-
- gtk_test_init(&argc, &argv, NULL);
- // Get rid of runtime warnings about deprecated properties and signals, since they break the tests.
- g_setenv("G_ENABLE_DIAGNOSTIC", "0", TRUE);
-
- server = soup_server_new(SOUP_SERVER_PORT, 0, NULL);
- soup_server_run_async(server);
-
- soup_server_add_handler(server, NULL, server_callback, NULL, NULL);
-
- base_uri = soup_uri_new("http://127.0.0.1/");
- soup_uri_set_port(base_uri, soup_server_get_port(server));
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add("/webkit/loading/status",
- WebLoadingFixture, NULL,
- web_loading_fixture_setup,
- test_loading_status,
- web_loading_fixture_teardown);
- g_test_add("/webkit/loading/error",
- WebLoadingFixture, NULL,
- web_loading_fixture_setup,
- test_loading_error,
- web_loading_fixture_teardown);
- g_test_add("/webkit/loading/cancelled",
- WebLoadingFixture, NULL,
- web_loading_fixture_setup,
- test_loading_cancelled,
- web_loading_fixture_teardown);
- g_test_add("/webkit/loading/goback",
- WebLoadingFixture, NULL,
- web_loading_fixture_setup,
- test_loading_goback,
- web_loading_fixture_teardown);
- return g_test_run();
-}
-
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testmimehandling.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testmimehandling.c
deleted file mode 100644
index 82568caf2..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testmimehandling.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (C) 2009 Jan Michael Alonzo
- * Copyright (C) 2009 Gustavo Noronha Silva
- *
- * 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 "test_utils.h"
-
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <libsoup/soup.h>
-#include <string.h>
-#include <webkit/webkit.h>
-#include <unistd.h>
-
-GMainLoop* loop;
-SoupSession *session;
-char* base_uri;
-
-/* For real request testing */
-static void
-server_callback(SoupServer *server, SoupMessage *msg,
- const char *path, GHashTable *query,
- SoupClientContext *context, gpointer data)
-{
- if (msg->method != SOUP_METHOD_GET) {
- soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED);
- return;
- }
-
- soup_message_set_status(msg, SOUP_STATUS_OK);
-
- /* PDF */
- if (g_str_equal(path, "/pdf")) {
- char* contents;
- gsize length;
- GError* error = NULL;
-
- g_file_get_contents("test.pdf", &contents, &length, &error);
- g_assert(!error);
-
- soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
- } else if (g_str_equal(path, "/html")) {
- char* contents;
- gsize length;
- GError* error = NULL;
-
- g_file_get_contents("test.html", &contents, &length, &error);
- g_assert(!error);
-
- soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
- } else if (g_str_equal(path, "/text")) {
- char* contents;
- gsize length;
- GError* error = NULL;
-
- soup_message_headers_append(msg->response_headers, "Content-Disposition", "attachment; filename=test.txt");
-
- g_file_get_contents("test.txt", &contents, &length, &error);
- g_assert(!error);
-
- soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
- }
-
- soup_message_body_complete(msg->response_body);
-}
-
-static void idle_quit_loop_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
-{
- if (webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FINISHED ||
- webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FAILED)
- g_main_loop_quit(loop);
-}
-
-static gboolean mime_type_policy_decision_requested_cb(WebKitWebView* view, WebKitWebFrame* frame,
- WebKitNetworkRequest* request, const char* mime_type,
- WebKitWebPolicyDecision* decision, gpointer data)
-{
- char* type = (char*)data;
-
- if (g_str_equal(type, "pdf")) {
- g_assert_cmpstr(mime_type, ==, "application/pdf");
- g_assert(!webkit_web_view_can_show_mime_type(view, mime_type));
- } else if (g_str_equal(type, "html")) {
- g_assert_cmpstr(mime_type, ==, "text/html");
- g_assert(webkit_web_view_can_show_mime_type(view, mime_type));
- } else if (g_str_equal(type, "text")) {
- WebKitNetworkResponse* response = webkit_web_frame_get_network_response(frame);
- SoupMessage* message = webkit_network_response_get_message(response);
- char* disposition;
-
- g_assert(message);
- soup_message_headers_get_content_disposition(message->response_headers,
- &disposition, NULL);
- g_object_unref(response);
-
- g_assert_cmpstr(disposition, ==, "attachment");
- g_free(disposition);
-
- g_assert_cmpstr(mime_type, ==, "text/plain");
- g_assert(webkit_web_view_can_show_mime_type(view, mime_type));
- }
-
- g_free(type);
-
- return FALSE;
-}
-
-static void testRemoteMimeType(const void* data)
-{
- const char* name = (const char*) data;
- WebKitWebView* view = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(G_OBJECT(view));
-
- loop = g_main_loop_new(NULL, TRUE);
-
- g_object_connect(G_OBJECT(view),
- "signal::notify::load-status", idle_quit_loop_cb, NULL,
- "signal::mime-type-policy-decision-requested", mime_type_policy_decision_requested_cb, g_strdup(name),
- NULL);
-
- char* effective_uri = g_strdup_printf("%s%s", base_uri, name);
- webkit_web_view_load_uri(view, effective_uri);
- g_free(effective_uri);
-
- g_main_loop_run(loop);
-
- g_object_unref(view);
-}
-
-static void testLocalMimeType(const void* data)
-{
- const char* typeName = (const char*) data;
- WebKitWebView* view = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(G_OBJECT(view));
-
- loop = g_main_loop_new(NULL, TRUE);
-
- g_object_connect(G_OBJECT(view),
- "signal::notify::load-status", idle_quit_loop_cb, NULL,
- "signal::mime-type-policy-decision-requested", mime_type_policy_decision_requested_cb, g_strdup(typeName),
- NULL);
-
- gchar* filename = g_strdup_printf("test.%s", typeName);
- GFile* file = g_file_new_for_path(filename);
- g_free(filename);
-
- gchar* fileURI = g_file_get_uri(file);
- g_object_unref(file);
-
- webkit_web_view_load_uri(view, fileURI);
- g_free(fileURI);
-
- g_main_loop_run(loop);
- g_object_unref(view);
-}
-
-int main(int argc, char** argv)
-{
- SoupServer* server;
- SoupURI* soup_uri;
-
- gtk_test_init(&argc, &argv, NULL);
-
- // Get rid of runtime warnings about deprecated properties and signals, since they break the tests.
- g_setenv("G_ENABLE_DIAGNOSTIC", "0", TRUE);
-
- /* Hopefully make test independent of the path it's called from. */
- testutils_relative_chdir("Tools/TestWebKitAPI/Tests/WebKitGtk/resources/test.html", argv[0]);
-
- server = soup_server_new(SOUP_SERVER_PORT, 0, NULL);
- soup_server_run_async(server);
-
- soup_server_add_handler(server, NULL, server_callback, NULL, NULL);
-
- soup_uri = soup_uri_new("http://127.0.0.1/");
- soup_uri_set_port(soup_uri, soup_server_get_port(server));
-
- base_uri = soup_uri_to_string(soup_uri, FALSE);
- soup_uri_free(soup_uri);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_data_func("/webkit/mime/remote-PDF", "pdf", testRemoteMimeType);
- g_test_add_data_func("/webkit/mime/remote-HTML", "html", testRemoteMimeType);
- g_test_add_data_func("/webkit/mime/remote-TEXT", "text", testRemoteMimeType);
- g_test_add_data_func("/webkit/mime/local-PDF", "pdf", testLocalMimeType);
- g_test_add_data_func("/webkit/mime/local-HTML", "html", testLocalMimeType);
- g_test_add_data_func("/webkit/mime/local-TEXT", "text", testLocalMimeType);
-
- return g_test_run();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testnetworkrequest.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testnetworkrequest.c
deleted file mode 100644
index 1b2c90f2d..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testnetworkrequest.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright (C) 2009 Gustavo Noronha Silva
- *
- * 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 <errno.h>
-#include <unistd.h>
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <gtk/gtk.h>
-#include <stdlib.h>
-#include <webkit/webkit.h>
-
-static void test_network_request_create_destroy()
-{
- WebKitNetworkRequest* request;
- SoupMessage* message;
-
- /* Test creation with URI */
- request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "uri", "http://debian.org/", NULL));
- g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
- message = webkit_network_request_get_message(request);
- g_assert(!message);
- g_object_unref(request);
-
- /* Test creation with SoupMessage */
- message = soup_message_new("GET", "http://debian.org/");
- request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, NULL));
- g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
- g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2);
- g_object_unref(request);
- g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1);
- g_object_unref(message);
-
- /* Test creation with both SoupMessage and URI */
- message = soup_message_new("GET", "http://debian.org/");
- request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, "uri", "http://gnome.org/", NULL));
- g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
- g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2);
- g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://gnome.org/");
- g_object_unref(request);
- g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1);
- g_object_unref(message);
-}
-
-static void test_network_request_properties()
-{
- WebKitNetworkRequest* request;
- SoupMessage* message;
- gchar* soupURI;
-
- /* Test URI is set correctly when creating with URI */
- request = webkit_network_request_new("http://debian.org/");
- g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
- g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://debian.org/");
- g_object_unref(request);
-
- /* Test URI is set correctly when creating with Message */
- message = soup_message_new("GET", "http://debian.org/");
- request = WEBKIT_NETWORK_REQUEST(g_object_new(WEBKIT_TYPE_NETWORK_REQUEST, "message", message, NULL));
- g_assert(WEBKIT_IS_NETWORK_REQUEST(request));
- g_object_unref(message);
-
- message = webkit_network_request_get_message(request);
- soupURI = soup_uri_to_string(soup_message_get_uri(message), FALSE);
- g_assert_cmpstr(soupURI, ==, "http://debian.org/");
- g_free(soupURI);
-
- g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://debian.org/");
- g_object_unref(request);
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_func("/webkit/networkrequest/createdestroy", test_network_request_create_destroy);
- g_test_add_func("/webkit/networkrequest/properties", test_network_request_properties);
- return g_test_run ();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testnetworkresponse.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testnetworkresponse.c
deleted file mode 100644
index b806aa111..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testnetworkresponse.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2009 Gustavo Noronha Silva
- * Copyright (C) 2009 Collabora Ltd.
- *
- * 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 <errno.h>
-#include <unistd.h>
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <gtk/gtk.h>
-#include <stdlib.h>
-#include <webkit/webkit.h>
-
-static void test_network_response_create_destroy()
-{
- WebKitNetworkResponse* response;
- SoupMessage* message;
-
- /* Test creation with URI */
- response = WEBKIT_NETWORK_RESPONSE(g_object_new(WEBKIT_TYPE_NETWORK_RESPONSE, "uri", "http://debian.org/", NULL));
- g_assert(WEBKIT_IS_NETWORK_RESPONSE(response));
- message = webkit_network_response_get_message(response);
- g_assert(!message);
- g_object_unref(response);
-
- /* Test creation with SoupMessage */
- message = soup_message_new("GET", "http://debian.org/");
- response = WEBKIT_NETWORK_RESPONSE(g_object_new(WEBKIT_TYPE_NETWORK_RESPONSE, "message", message, NULL));
- g_assert(WEBKIT_IS_NETWORK_RESPONSE(response));
- g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2);
- g_object_unref(response);
- g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1);
- g_object_unref(message);
-
- /* Test creation with both SoupMessage and URI */
- message = soup_message_new("GET", "http://debian.org/");
- response = WEBKIT_NETWORK_RESPONSE(g_object_new(WEBKIT_TYPE_NETWORK_RESPONSE, "message", message, "uri", "http://gnome.org/", NULL));
- g_assert(WEBKIT_IS_NETWORK_RESPONSE(response));
- g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 2);
- g_assert_cmpstr(webkit_network_response_get_uri(response), ==, "http://gnome.org/");
- g_object_unref(response);
- g_assert_cmpint(G_OBJECT(message)->ref_count, ==, 1);
- g_object_unref(message);
-}
-
-static void test_network_response_properties()
-{
- WebKitNetworkResponse* response;
- SoupMessage* message;
- gchar* soupURI;
-
- /* Test URI is set correctly when creating with URI */
- response = webkit_network_response_new("http://debian.org/");
- g_assert(WEBKIT_IS_NETWORK_RESPONSE(response));
- g_assert_cmpstr(webkit_network_response_get_uri(response), ==, "http://debian.org/");
- g_object_unref(response);
-
- /* Test URI is set correctly when creating with Message */
- message = soup_message_new("GET", "http://debian.org/");
- response = WEBKIT_NETWORK_RESPONSE(g_object_new(WEBKIT_TYPE_NETWORK_RESPONSE, "message", message, NULL));
- g_assert(WEBKIT_IS_NETWORK_RESPONSE(response));
- g_object_unref(message);
-
- message = webkit_network_response_get_message(response);
- soupURI = soup_uri_to_string(soup_message_get_uri(message), FALSE);
- g_assert_cmpstr(soupURI, ==, "http://debian.org/");
- g_free(soupURI);
-
- g_assert_cmpstr(webkit_network_response_get_uri(response), ==, "http://debian.org/");
- g_object_unref(response);
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_func("/webkit/networkresponse/createdestroy", test_network_response_create_destroy);
- g_test_add_func("/webkit/networkresponse/properties", test_network_response_properties);
- return g_test_run ();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebbackforwardlist.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebbackforwardlist.c
deleted file mode 100644
index 7782d4070..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebbackforwardlist.c
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * Copyright (C) 2008 Holger Hans Peter Freyther
- *
- * 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 <glib.h>
-#include <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-static void test_webkit_web_history_item_lifetime(void)
-{
- WebKitWebView* webView;
- WebKitWebBackForwardList* backForwardList;
- WebKitWebHistoryItem* currentItem;
- WebKitWebHistoryItem* forwardItem;
- WebKitWebHistoryItem* backItem;
- WebKitWebHistoryItem* nthItem;
- WebKitWebHistoryItem* item1;
- WebKitWebHistoryItem* item2;
- WebKitWebHistoryItem* item3;
- WebKitWebHistoryItem* item4;
- GList* backList = NULL;
- GList* forwardList = NULL;
- g_test_bug("19898");
-
- webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- backForwardList = webkit_web_view_get_back_forward_list(webView);
- g_assert_cmpint(G_OBJECT(backForwardList)->ref_count, ==, 1);
-
- /* add test items */
- item1 = webkit_web_history_item_new_with_data("http://example.com/1/", "Site 1");
- webkit_web_back_forward_list_add_item(backForwardList, item1);
- g_object_unref(item1);
-
- item2 = webkit_web_history_item_new_with_data("http://example.com/2/", "Site 2");
- webkit_web_back_forward_list_add_item(backForwardList, item2);
- g_object_unref(item2);
-
- item3 = webkit_web_history_item_new_with_data("http://example.com/3/", "Site 3");
- webkit_web_back_forward_list_add_item(backForwardList, item3);
- g_object_unref(item3);
-
- item4 = webkit_web_history_item_new_with_data("http://example.com/4/", "Site 4");
- webkit_web_back_forward_list_add_item(backForwardList, item4);
- g_object_unref(item4);
-
- /* make sure these functions don't add unnecessary ref to the history item */
- backItem = webkit_web_back_forward_list_get_back_item(backForwardList);
- g_object_ref(backItem);
- g_assert_cmpint(G_OBJECT(backItem)->ref_count, ==, 2);
- g_object_unref(backItem);
- g_assert_cmpint(G_OBJECT(backItem)->ref_count, ==, 1);
-
- currentItem = webkit_web_back_forward_list_get_current_item(backForwardList);
- g_object_ref(currentItem);
- g_assert_cmpint(G_OBJECT(currentItem)->ref_count, ==, 2);
- g_object_unref(currentItem);
- g_assert_cmpint(G_OBJECT(currentItem)->ref_count, ==, 1);
-
- webkit_web_back_forward_list_go_to_item(backForwardList, item2);
- forwardItem = webkit_web_back_forward_list_get_forward_item(backForwardList);
- g_object_ref(forwardItem);
- g_assert_cmpint(G_OBJECT(forwardItem)->ref_count, ==, 2);
- g_object_unref(forwardItem);
- g_assert_cmpint(G_OBJECT(forwardItem)->ref_count, ==, 1);
-
- nthItem = webkit_web_back_forward_list_get_nth_item(backForwardList, 1);
- g_object_ref(nthItem);
- g_assert_cmpint(G_OBJECT(nthItem)->ref_count, ==, 2);
- g_object_unref(nthItem);
- g_assert_cmpint(G_OBJECT(nthItem)->ref_count, ==, 1);
-
- backList = webkit_web_back_forward_list_get_back_list_with_limit(backForwardList, 5);
- for (; backList; backList = backList->next)
- g_assert_cmpint(G_OBJECT(backList->data)->ref_count, ==, 1);
-
- forwardList = webkit_web_back_forward_list_get_forward_list_with_limit(backForwardList, 5);
- for (; forwardList; forwardList = forwardList->next)
- g_assert_cmpint(G_OBJECT(forwardList->data)->ref_count, ==, 1);
-
- g_list_free(forwardList);
- g_list_free(backList);
- g_assert_cmpint(G_OBJECT(item1)->ref_count, ==, 1);
- g_assert_cmpint(G_OBJECT(item2)->ref_count, ==, 1);
- g_assert_cmpint(G_OBJECT(item3)->ref_count, ==, 1);
- g_assert_cmpint(G_OBJECT(item4)->ref_count, ==, 1);
- g_assert_cmpint(G_OBJECT(backForwardList)->ref_count, ==, 1);
- g_object_unref(webView);
-}
-
-static void test_webkit_web_back_forward_list_order(void)
-{
- WebKitWebView* webView;
- WebKitWebBackForwardList* webBackForwardList;
- WebKitWebHistoryItem* item1;
- WebKitWebHistoryItem* item2;
- WebKitWebHistoryItem* item3;
- WebKitWebHistoryItem* item4;
- WebKitWebHistoryItem* currentItem;
- GList* backList = NULL;
- GList* forwardList = NULL;
- g_test_bug("22694");
-
- webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
-
- webkit_web_view_set_maintains_back_forward_list(webView, TRUE);
- webBackForwardList = webkit_web_view_get_back_forward_list(webView);
- g_assert(webBackForwardList);
-
- // Check that there is no item.
- g_assert(!webkit_web_back_forward_list_get_current_item(webBackForwardList));
- g_assert_cmpint(webkit_web_back_forward_list_get_forward_length(webBackForwardList), ==, 0);
- g_assert_cmpint(webkit_web_back_forward_list_get_back_length(webBackForwardList), ==, 0);
- g_assert(!webkit_web_view_can_go_forward(webView));
- g_assert(!webkit_web_view_can_go_back(webView));
-
- // Add a new items
- item1 = webkit_web_history_item_new_with_data("http://example.com/1/", "Site 1");
- webkit_web_back_forward_list_add_item(webBackForwardList, item1);
- g_object_unref(item1);
- g_assert(webkit_web_back_forward_list_contains_item(webBackForwardList, item1));
-
- item2 = webkit_web_history_item_new_with_data("http://example.com/2/", "Site 2");
- webkit_web_back_forward_list_add_item(webBackForwardList, item2);
- g_object_unref(item2);
- g_assert(webkit_web_back_forward_list_contains_item(webBackForwardList, item2));
-
- item3 = webkit_web_history_item_new_with_data("http://example.com/3/", "Site 3");
- webkit_web_back_forward_list_add_item(webBackForwardList, item3);
- g_object_unref(item3);
- g_assert(webkit_web_back_forward_list_contains_item(webBackForwardList, item3));
-
- item4 = webkit_web_history_item_new_with_data("http://example.com/4/", "Site 4");
- webkit_web_back_forward_list_add_item(webBackForwardList, item4);
- g_object_unref(item4);
- g_assert(webkit_web_back_forward_list_contains_item(webBackForwardList, item4));
-
- // check the back list order
- backList = webkit_web_back_forward_list_get_back_list_with_limit(webBackForwardList, 5);
- g_assert(backList);
-
- currentItem = WEBKIT_WEB_HISTORY_ITEM(backList->data);
- g_assert_cmpstr(webkit_web_history_item_get_uri(currentItem), ==, "http://example.com/3/");
- g_assert_cmpstr(webkit_web_history_item_get_title(currentItem), ==, "Site 3");
- backList = backList->next;
-
- currentItem = WEBKIT_WEB_HISTORY_ITEM(backList->data);
- g_assert_cmpstr(webkit_web_history_item_get_uri(currentItem), ==, "http://example.com/2/");
- g_assert_cmpstr(webkit_web_history_item_get_title(currentItem), ==, "Site 2");
- backList = backList->next;
-
- currentItem = WEBKIT_WEB_HISTORY_ITEM(backList->data);
- g_assert_cmpstr(webkit_web_history_item_get_uri(currentItem), ==, "http://example.com/1/");
- g_assert_cmpstr(webkit_web_history_item_get_title(currentItem), ==, "Site 1");
- g_list_free(backList);
-
- // check the forward list order
- g_assert(webkit_web_view_go_to_back_forward_item(webView, item1));
- forwardList = webkit_web_back_forward_list_get_forward_list_with_limit(webBackForwardList,5);
- g_assert(forwardList);
-
- currentItem = WEBKIT_WEB_HISTORY_ITEM(forwardList->data);
- g_assert_cmpstr(webkit_web_history_item_get_uri(currentItem), ==, "http://example.com/4/");
- g_assert_cmpstr(webkit_web_history_item_get_title(currentItem), ==, "Site 4");
- forwardList = forwardList->next;
-
- currentItem = WEBKIT_WEB_HISTORY_ITEM(forwardList->data);
- g_assert_cmpstr(webkit_web_history_item_get_uri(currentItem), ==, "http://example.com/3/");
- g_assert_cmpstr(webkit_web_history_item_get_title(currentItem), ==, "Site 3");
- forwardList = forwardList->next;
-
- currentItem = WEBKIT_WEB_HISTORY_ITEM(forwardList->data);
- g_assert_cmpstr(webkit_web_history_item_get_uri(currentItem), ==, "http://example.com/2/");
- g_assert_cmpstr(webkit_web_history_item_get_title(currentItem), ==, "Site 2");
-
- g_list_free(forwardList);
- g_object_unref(webView);
-}
-
-static void test_webkit_web_back_forward_list_add_item(void)
-{
- WebKitWebView* webView;
- WebKitWebBackForwardList* webBackForwardList;
- WebKitWebHistoryItem* addItem1;
- WebKitWebHistoryItem* addItem2;
- WebKitWebHistoryItem* backItem;
- WebKitWebHistoryItem* currentItem;
- g_test_bug("22988");
-
- webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
-
- webkit_web_view_set_maintains_back_forward_list(webView, TRUE);
- webBackForwardList = webkit_web_view_get_back_forward_list(webView);
- g_assert(webBackForwardList);
-
- // Check that there is no item.
- g_assert(!webkit_web_back_forward_list_get_current_item(webBackForwardList));
- g_assert_cmpint(webkit_web_back_forward_list_get_forward_length(webBackForwardList), ==, 0);
- g_assert_cmpint(webkit_web_back_forward_list_get_back_length(webBackForwardList), ==, 0);
- g_assert(!webkit_web_view_can_go_forward(webView));
- g_assert(!webkit_web_view_can_go_back(webView));
-
- // Add a new item
- addItem1 = webkit_web_history_item_new_with_data("http://example.com/", "Added site");
- webkit_web_back_forward_list_add_item(webBackForwardList, addItem1);
- g_object_unref(addItem1);
- g_assert(webkit_web_back_forward_list_contains_item(webBackForwardList, addItem1));
-
- // Check that the added item is the current item.
- currentItem = webkit_web_back_forward_list_get_current_item(webBackForwardList);
- g_assert(currentItem);
- g_assert_cmpint(webkit_web_back_forward_list_get_forward_length(webBackForwardList), ==, 0);
- g_assert_cmpint(webkit_web_back_forward_list_get_back_length(webBackForwardList), ==, 0);
- g_assert(!webkit_web_view_can_go_forward(webView));
- g_assert(!webkit_web_view_can_go_back(webView));
- g_assert_cmpstr(webkit_web_history_item_get_uri(currentItem), ==, "http://example.com/");
- g_assert_cmpstr(webkit_web_history_item_get_title(currentItem), ==, "Added site");
-
- // Add another item.
- addItem2 = webkit_web_history_item_new_with_data("http://example.com/2/", "Added site 2");
- webkit_web_back_forward_list_add_item(webBackForwardList, addItem2);
- g_object_unref(addItem2);
- g_assert(webkit_web_back_forward_list_contains_item(webBackForwardList, addItem2));
-
- // Check that the added item is new current item.
- currentItem = webkit_web_back_forward_list_get_current_item(webBackForwardList);
- g_assert(currentItem);
- g_assert_cmpint(webkit_web_back_forward_list_get_forward_length(webBackForwardList), ==, 0);
- g_assert_cmpint(webkit_web_back_forward_list_get_back_length(webBackForwardList), ==, 1);
- g_assert(!webkit_web_view_can_go_forward(webView));
- g_assert(webkit_web_view_can_go_back(webView));
- g_assert_cmpstr(webkit_web_history_item_get_uri(currentItem), ==, "http://example.com/2/");
- g_assert_cmpstr(webkit_web_history_item_get_title(currentItem), ==, "Added site 2");
-
- backItem = webkit_web_back_forward_list_get_back_item(webBackForwardList);
- g_assert(backItem);
- g_assert_cmpstr(webkit_web_history_item_get_uri(backItem), ==, "http://example.com/");
- g_assert_cmpstr(webkit_web_history_item_get_title(backItem), ==, "Added site");
-
- // Go to the first added item.
- g_assert(webkit_web_view_go_to_back_forward_item(webView, addItem1));
- g_assert_cmpint(webkit_web_back_forward_list_get_forward_length(webBackForwardList), ==, 1);
- g_assert_cmpint(webkit_web_back_forward_list_get_back_length(webBackForwardList), ==, 0);
- g_assert(webkit_web_view_can_go_forward(webView));
- g_assert(!webkit_web_view_can_go_back(webView));
-
- g_object_unref(webView);
-}
-
-static void test_webkit_web_back_forward_list_clear(void)
-{
- WebKitWebView* webView;
- WebKitWebBackForwardList* webBackForwardList;
- WebKitWebHistoryItem* addItem;
- g_test_bug("36173");
-
- webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
-
- webBackForwardList = webkit_web_view_get_back_forward_list(webView);
- g_assert(webBackForwardList);
-
- // Check that there is no item.
- g_assert_cmpint(webkit_web_back_forward_list_get_forward_length(webBackForwardList), ==, 0);
- g_assert_cmpint(webkit_web_back_forward_list_get_back_length(webBackForwardList), ==, 0);
- g_assert(!webkit_web_back_forward_list_get_current_item(webBackForwardList));
- g_assert(!webkit_web_view_can_go_forward(webView));
- g_assert(!webkit_web_view_can_go_back(webView));
-
- // Check that clearing the empty list does not modify counters
- webkit_web_back_forward_list_clear(webBackForwardList);
- g_assert_cmpint(webkit_web_back_forward_list_get_forward_length(webBackForwardList), ==, 0);
- g_assert_cmpint(webkit_web_back_forward_list_get_back_length(webBackForwardList), ==, 0);
- g_assert(!webkit_web_back_forward_list_get_current_item(webBackForwardList));
- g_assert(!webkit_web_view_can_go_forward(webView));
- g_assert(!webkit_web_view_can_go_back(webView));
-
- // Add a new item
- addItem = webkit_web_history_item_new_with_data("http://example.com/", "Added site");
- webkit_web_back_forward_list_add_item(webBackForwardList, addItem);
- g_object_unref(addItem);
- g_assert(webkit_web_back_forward_list_contains_item(webBackForwardList, addItem));
-
- // Check that after clearing the list the added item is no longer in the list
- webkit_web_back_forward_list_clear(webBackForwardList);
- g_assert(!webkit_web_back_forward_list_contains_item(webBackForwardList, addItem));
-
- // Check that after clearing it, the list is empty
- g_assert_cmpint(webkit_web_back_forward_list_get_forward_length(webBackForwardList), ==, 0);
- g_assert_cmpint(webkit_web_back_forward_list_get_back_length(webBackForwardList), ==, 0);
- g_assert(!webkit_web_back_forward_list_get_current_item(webBackForwardList));
- g_assert(!webkit_web_view_can_go_forward(webView));
- g_assert(!webkit_web_view_can_go_back(webView));
-
- g_object_unref(webView);
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_func("/webkit/webbackforwardlist/add_item", test_webkit_web_back_forward_list_add_item);
- g_test_add_func("/webkit/webbackforwardlist/list_order", test_webkit_web_back_forward_list_order);
- g_test_add_func("/webkit/webhistoryitem/lifetime", test_webkit_web_history_item_lifetime);
- g_test_add_func("/webkit/webbackforwardlist/clear", test_webkit_web_back_forward_list_clear);
- return g_test_run ();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebdatasource.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebdatasource.c
deleted file mode 100644
index 056625744..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebdatasource.c
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * Copyright (C) 2009 Jan Michael Alonzo
- *
- * 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 <glib.h>
-#include <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-static const gshort defaultTimeout = 10;
-guint waitTimer;
-gboolean shouldWait;
-
-typedef struct {
- WebKitWebView* webView;
- WebKitWebFrame* mainFrame;
-} WebDataSourceFixture;
-
-static void test_webkit_web_data_source_get_initial_request()
-{
- WebKitWebView* view;
- WebKitWebFrame* frame;
- WebKitWebDataSource* dataSource;
- WebKitNetworkRequest* initialRequest;
-
- view = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(view);
- frame = webkit_web_view_get_main_frame(view);
-
- WebKitNetworkRequest* request = webkit_network_request_new("http://www.google.com");
- webkit_web_frame_load_request(frame, request);
- g_object_unref(request);
-
- dataSource = webkit_web_frame_get_provisional_data_source(frame);
- g_assert(dataSource);
- initialRequest = webkit_web_data_source_get_initial_request(dataSource);
- g_assert_cmpstr(webkit_network_request_get_uri(initialRequest), ==, "http://www.google.com/");
-
- g_object_unref(view);
-}
-
-static void notify_load_status_unreachable_cb(WebKitWebView* view, GParamSpec* pspec, GMainLoop* loop)
-{
- WebKitLoadStatus status = webkit_web_view_get_load_status (view);
- WebKitWebFrame* frame = webkit_web_view_get_main_frame(view);
-
- g_assert(status != WEBKIT_LOAD_FINISHED);
-
- if (status != WEBKIT_LOAD_FAILED)
- return;
-
- WebKitWebDataSource* datasource = webkit_web_frame_get_data_source(frame);
-
- g_assert_cmpstr("http://this.host.does.not.exist/doireallyexist.html", ==,
- webkit_web_data_source_get_unreachable_uri(datasource));
-
- g_main_loop_quit(loop);
-}
-
-static void notify_load_status_cb(WebKitWebView* view, GParamSpec* pspec, GMainLoop* loop)
-{
- WebKitLoadStatus status = webkit_web_view_get_load_status (view);
- WebKitWebFrame* frame = webkit_web_view_get_main_frame(view);
- WebKitWebDataSource* dataSource = webkit_web_frame_get_data_source(frame);
-
- if (status == WEBKIT_LOAD_COMMITTED) {
- g_assert(webkit_web_data_source_is_loading(dataSource));
- return;
- }
- else if (status != WEBKIT_LOAD_FINISHED)
- return;
-
- /* Test get_request */
- g_test_message("Testing webkit_web_data_source_get_request");
- WebKitNetworkRequest* request = webkit_web_data_source_get_request(dataSource);
- g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://www.webkit.org/");
-
- /* Test get_main_resource */
- g_test_message("Testing webkit_web_data_source_get_main_resource");
- WebKitWebResource* resource = webkit_web_data_source_get_main_resource(dataSource);
- g_assert_cmpstr("text/html", ==, webkit_web_resource_get_mime_type(resource));
- g_assert_cmpstr("http://www.webkit.org/", ==, webkit_web_resource_get_uri(resource));
-
- /* Test get_data. We just test if data has certain size for the mean time */
- g_test_message("Testing webkit_web_data_source_get_data has certain size");
- GString* data = webkit_web_data_source_get_data(dataSource);
- g_assert(data->len > 100);
-
- /* FIXME: Add test for get_encoding */
-
- g_main_loop_quit(loop);
-}
-
-static gboolean wait_timer_fired(GMainLoop* loop)
-{
- waitTimer = 0;
- g_main_loop_quit(loop);
-
- return FALSE;
-}
-
-static void test_webkit_web_data_source()
-{
- WebKitWebView* view;
- GMainLoop* loop;
-
- view = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(view);
- loop = g_main_loop_new(NULL, TRUE);
- g_signal_connect(view, "notify::load-status", G_CALLBACK(notify_load_status_cb), loop);
- webkit_web_view_load_uri(view, "http://www.webkit.org");
-
- waitTimer = g_timeout_add_seconds(defaultTimeout, (GSourceFunc)wait_timer_fired, loop);
-
- g_main_loop_run(loop);
-
- if (waitTimer)
- g_source_remove(waitTimer);
-
- waitTimer = 0;
-
- g_main_loop_unref(loop);
- g_object_unref(view);
-}
-
-static void notify_load_status_lifetime_cb(WebKitWebView* view, GParamSpec* pspec, GMainLoop* loop)
-{
- WebKitLoadStatus status = webkit_web_view_get_load_status (view);
- WebKitWebFrame* frame = webkit_web_view_get_main_frame(view);
- WebKitWebDataSource* dataSource = webkit_web_frame_get_data_source(frame);
-
- if (status == WEBKIT_LOAD_COMMITTED) {
- g_assert(webkit_web_data_source_is_loading(dataSource));
- return;
- } else if (status != WEBKIT_LOAD_FINISHED)
- return;
-
- g_main_loop_quit(loop);
-}
-
-static void test_webkit_web_data_source_lifetime()
-{
- WebKitWebView* view;
- GMainLoop* loop;
-
- view = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(view);
- loop = g_main_loop_new(NULL, TRUE);
- g_signal_connect(view, "notify::load-status", G_CALLBACK(notify_load_status_lifetime_cb), loop);
- webkit_web_view_load_uri(view, "http://www.webkit.org");
-
- waitTimer = g_timeout_add_seconds(defaultTimeout, (GSourceFunc)wait_timer_fired, loop);
-
- g_main_loop_run(loop);
-
- WebKitWebDataSource* dataSource = webkit_web_frame_get_data_source(webkit_web_view_get_main_frame(view));
- GList* subResources = webkit_web_data_source_get_subresources(dataSource);
- gint numberOfResources = g_list_length(subResources);
- g_list_free(subResources);
-
- g_assert_cmpint(webkit_web_view_get_load_status(view), ==, WEBKIT_LOAD_FINISHED);
-
- webkit_web_view_load_uri(view, "http://gnome.org");
-
- g_assert_cmpint(webkit_web_view_get_load_status(view), ==, WEBKIT_LOAD_PROVISIONAL);
-
- webkit_web_view_stop_loading(view);
-
- g_assert_cmpint(webkit_web_view_get_load_status(view), ==, WEBKIT_LOAD_FAILED);
-
- subResources = webkit_web_data_source_get_subresources(dataSource);
- g_assert_cmpint(numberOfResources, ==, g_list_length(subResources));
- g_list_free(subResources);
-
- if (waitTimer)
- g_source_remove(waitTimer);
-
- waitTimer = 0;
-
- g_main_loop_unref(loop);
- g_object_unref(view);
-}
-
-static void test_webkit_web_data_source_unreachable_uri()
-{
- /* FIXME: this test fails currently. */
- return;
-
- WebKitWebView* view;
- GMainLoop* loop;
-
- view = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(view);
- loop = g_main_loop_new(NULL, TRUE);
- g_signal_connect(view, "notify::load-status", G_CALLBACK(notify_load_status_unreachable_cb), loop);
- webkit_web_view_load_uri(view, "http://this.host.does.not.exist/doireallyexist.html");
-
- waitTimer = g_timeout_add_seconds(defaultTimeout, (GSourceFunc)wait_timer_fired, loop);
-
- g_main_loop_run(loop);
-
- if (waitTimer)
- g_source_remove(waitTimer);
-
- waitTimer = 0;
-
- g_main_loop_unref(loop);
- g_object_unref(view);
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_bug("24758");
- g_test_add_func("/webkit/webdatasource/get_initial_request",
- test_webkit_web_data_source_get_initial_request);
- g_test_add_func("/webkit/webdatasource/api",
- test_webkit_web_data_source);
- g_test_add_func("/webkit/webdatasource/unreachable_uri",
- test_webkit_web_data_source_unreachable_uri);
- g_test_add_func("/webkit/webdatasource/lifetime",
- test_webkit_web_data_source_lifetime);
-
- return g_test_run ();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebframe.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebframe.c
deleted file mode 100644
index 1131873d4..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebframe.c
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright (C) 2008 Holger Hans Peter Freyther
- * Copyright (C) 2009 Collabora Ltd.
- *
- * 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 <errno.h>
-#include <unistd.h>
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-static int numberOfFramesCreated = 0;
-
-static void createFrameSignalTestFrameCreatedCallback(WebKitWebView* webView, WebKitWebFrame* frame, gpointer data)
-{
- numberOfFramesCreated++;
-}
-
-static gboolean createFrameSignalTestTimeout(gpointer data)
-{
- g_assert_cmpint(numberOfFramesCreated, ==, 2);
- g_main_loop_quit((GMainLoop*) data);
- return FALSE;
-}
-
-static void test_webkit_web_frame_created_signal(void)
-{
- GtkWidget* webView;
- GtkWidget* window;
- GMainLoop* loop = g_main_loop_new(NULL, TRUE);
-
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-
- webView = webkit_web_view_new();
- g_signal_connect(webView, "frame-created", G_CALLBACK(createFrameSignalTestFrameCreatedCallback), loop);
-
- // We want to ensure that exactly two create-frame signals are
- // fired and no more, so we set a timeout here. There does not appear
- // to be a simple way via the API to figure out when all frames have
- // loaded.
- g_timeout_add(500, createFrameSignalTestTimeout, loop);
-
- gtk_container_add(GTK_CONTAINER(window), webView);
- gtk_widget_show(window);
- gtk_widget_show(webView);
-
- webkit_web_view_load_string(WEBKIT_WEB_VIEW(webView),
- "<html><body>Frames!"
- "<iframe></iframe>"
- "<iframe></iframe>"
- "</body></html>",
- "text/html", "utf-8", "file://");
- g_main_loop_run(loop);
-}
-
-static void test_webkit_web_frame_create_destroy(void)
-{
- GtkWidget *webView;
- GtkWidget *window;
-
- g_test_bug("21837");
- webView = webkit_web_view_new();
- g_object_ref_sink(webView);
- g_assert_cmpint(G_OBJECT(webView)->ref_count, ==, 1);
- // This crashed with the original version
- g_object_unref(webView);
-
- g_test_bug("25042");
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- webView = webkit_web_view_new();
- gtk_container_add(GTK_CONTAINER(window), webView);
- gtk_widget_show(window);
- gtk_widget_show(webView);
- gtk_widget_destroy(webView);
-}
-
-static void test_webkit_web_frame_lifetime(void)
-{
- WebKitWebView* webView;
- WebKitWebFrame* webFrame;
- g_test_bug("21837");
-
- webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- g_assert_cmpint(G_OBJECT(webView)->ref_count, ==, 1);
- webFrame = webkit_web_view_get_main_frame(webView);
- g_assert_cmpint(G_OBJECT(webFrame)->ref_count, ==, 1);
-
- // Add dummy reference on the WebKitWebFrame to keep it alive
- g_object_ref(webFrame);
- g_assert_cmpint(G_OBJECT(webFrame)->ref_count, ==, 2);
-
- // This crashed with the original version
- g_object_unref(webView);
-
- // Make sure that the frame got deleted as well. We did this
- // by adding an extra ref on the WebKitWebFrame and we should
- // be the one holding the last reference.
- g_assert_cmpint(G_OBJECT(webFrame)->ref_count, ==, 1);
- g_object_unref(webFrame);
-}
-
-static gboolean print_requested_cb(WebKitWebView* webView, WebKitWebFrame* webFrame, GMainLoop* loop)
-{
- g_object_set_data(G_OBJECT(webView), "signal-handled", GINT_TO_POINTER(TRUE));
- g_main_loop_quit(loop);
- return TRUE;
-}
-
-static void print_timeout(GMainLoop* loop)
-{
- if (g_main_loop_is_running(loop))
- g_main_loop_quit(loop);
-}
-
-static void test_webkit_web_frame_printing(void)
-{
- WebKitWebView* webView;
-
- webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(webView);
- g_assert_cmpint(G_OBJECT(webView)->ref_count, ==, 1);
-
- webkit_web_view_load_string(webView,
- "<html><body><h1>WebKitGTK+!</h1></body></html>",
- "text/html",
- "utf-8",
- "file://");
-
- GMainLoop* loop = g_main_loop_new(NULL, TRUE);
-
- // Does javascript print() work correctly?
- g_signal_connect(webView, "print-requested",
- G_CALLBACK(print_requested_cb),
- loop);
-
- g_object_set_data(G_OBJECT(webView), "signal-handled", GINT_TO_POINTER(FALSE));
- webkit_web_view_execute_script (webView, "print();");
-
- // Give javascriptcore some time to process the print request, but
- // prepare a timeout to avoid it running forever in case the signal is
- // never emitted.
- g_timeout_add(1000, (GSourceFunc)print_timeout, loop);
- g_main_loop_run(loop);
-
- g_assert_cmpint(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(webView), "signal-handled")), ==, TRUE);
-
- // Does printing directly to a file?
- GError *error = NULL;
- gchar* temporaryFilename = NULL;
- gint fd = g_file_open_tmp ("webkit-testwebframe-XXXXXX", &temporaryFilename, &error);
- close(fd);
-
- if (error) {
- g_critical("Failed to open a temporary file for writing: %s.", error->message);
- g_error_free(error);
- goto cleanup;
- }
-
- // We delete the file, so that we can easily figure out that the
- // file got printed;
- if (g_unlink(temporaryFilename) == -1) {
- g_warning("Failed to delete the temporary file: %s.\nThis may cause the test to be bogus.", g_strerror(errno));
- }
-
- WebKitWebFrame* webFrame = webkit_web_view_get_main_frame(webView);
- GtkPrintOperation* operation = gtk_print_operation_new();
- GtkPrintOperationAction action = GTK_PRINT_OPERATION_ACTION_EXPORT;
- GtkPrintOperationResult result;
-
- gtk_print_operation_set_export_filename(operation, temporaryFilename);
- result = webkit_web_frame_print_full (webFrame, operation, action, NULL);
-
- g_assert_cmpint(result, ==, GTK_PRINT_OPERATION_RESULT_APPLY);
- g_assert_cmpint(g_file_test(temporaryFilename, G_FILE_TEST_IS_REGULAR), ==, TRUE);
-
- g_unlink(temporaryFilename);
- g_object_unref(operation);
-cleanup:
- g_object_unref(webView);
- g_free(temporaryFilename);
-}
-
-static void test_webkit_web_frame_response()
-{
- WebKitWebFrame* frame = g_object_new(WEBKIT_TYPE_WEB_FRAME, NULL);
- WebKitNetworkResponse* response = webkit_web_frame_get_network_response(frame);
- g_assert(!response);
- g_object_unref(frame);
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_func("/webkit/webview/create_destroy", test_webkit_web_frame_create_destroy);
- g_test_add_func("/webkit/webview/frame-created_signal", test_webkit_web_frame_created_signal);
- g_test_add_func("/webkit/webframe/lifetime", test_webkit_web_frame_lifetime);
- g_test_add_func("/webkit/webview/printing", test_webkit_web_frame_printing);
- g_test_add_func("/webkit/webview/response", test_webkit_web_frame_response);
- return g_test_run ();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebhistoryitem.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebhistoryitem.c
deleted file mode 100644
index 82e191c20..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebhistoryitem.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2009 Jan Michael Alonzo
- *
- * 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 <glib.h>
-#include <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-typedef struct {
- WebKitWebHistoryItem* item;
-} WebHistoryItemFixture;
-
-static void web_history_item_fixture_setup(WebHistoryItemFixture* fixture,
- gconstpointer data)
-{
- fixture->item = webkit_web_history_item_new_with_data("http://example.com/", "Example1");
- g_assert_cmpint(G_OBJECT(fixture->item)->ref_count, == , 1);
- g_assert(fixture->item != NULL);
-}
-
-static void web_history_item_fixture_teardown(WebHistoryItemFixture* fixture,
- gconstpointer data)
-{
- g_assert(fixture->item != NULL);
- g_assert_cmpint(G_OBJECT(fixture->item)->ref_count, ==, 1);
-}
-
-static void test_webkit_web_history_item_get_data(WebHistoryItemFixture* fixture,
- gconstpointer data)
-{
- g_assert_cmpstr(webkit_web_history_item_get_title(fixture->item), ==, "Example1");
- g_assert_cmpstr(webkit_web_history_item_get_uri(fixture->item), ==, "http://example.com/");
-}
-
-static void test_webkit_web_history_item_alternate_title(WebHistoryItemFixture* fixture,
- gconstpointer data)
-{
- webkit_web_history_item_set_alternate_title(fixture->item, "Alternate title");
- g_assert_cmpstr(webkit_web_history_item_get_alternate_title(fixture->item), ==, "Alternate title");
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add("/webkit/webhistoryitem/get_data",
- WebHistoryItemFixture, 0, web_history_item_fixture_setup,
- test_webkit_web_history_item_get_data, web_history_item_fixture_teardown);
- g_test_add("/webkit/webhistoryitem/alternate_title",
- WebHistoryItemFixture, 0, web_history_item_fixture_setup,
- test_webkit_web_history_item_alternate_title, web_history_item_fixture_teardown);
- return g_test_run ();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebinspector.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebinspector.c
deleted file mode 100644
index a74382ff3..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebinspector.c
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright (C) 2012 Gustavo Noronha Silva <gns@gnome.org>
- *
- * 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 "test_utils.h"
-
-#include <string.h>
-#include <glib.h>
-#include <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-GMainLoop *loop;
-GtkWidget *window;
-
-static gboolean quitLoop(gpointer data)
-{
- g_main_loop_quit(loop);
- return TRUE;
-}
-
-/* Ignore simple translation-related messages and upgrade other
- * messages to warnings.
- */
-static gboolean consoleMessageCallback(WebKitWebView* webView, const char* message, unsigned int line, const char* sourceId)
-{
- if (strstr(message, "Localized string") || strstr(message, "Protocol Error: the message is for non-existing domain 'Profiler'") ||
- strstr(message, "Didn't find a TreeElement for a representedObject"))
- return TRUE;
-
- g_warning("Console: %s @%d: %s\n", sourceId, line, message);
- return TRUE;
-}
-
-static WebKitWebView* inspectElementCallback(WebKitWebInspector *inspector, WebKitWebView *inspectedWebView, int *timesElementInspected)
-{
- *timesElementInspected = *timesElementInspected + 1;
-
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-
- GtkWidget *newWebView = webkit_web_view_new();
- gtk_container_add(GTK_CONTAINER(window), newWebView);
-
- g_signal_connect(newWebView, "console-message",
- G_CALLBACK(consoleMessageCallback), NULL);
-
- return WEBKIT_WEB_VIEW(newWebView);
-}
-
-static gboolean closeInspector(WebKitWebInspector *inspector, int *timesClosed)
-{
- *timesClosed = *timesClosed + 1;
-
- gtk_widget_destroy(window);
- return TRUE;
-}
-
-static gboolean showInspector(WebKitWebInspector *inspector, gpointer data)
-{
- g_idle_add(quitLoop, NULL);
- return TRUE;
-}
-
-static void loadFinished(WebKitWebView *webView, WebKitWebFrame *frame, gboolean *isLoadFinished)
-{
- *isLoadFinished = TRUE;
- if (g_main_loop_is_running(loop))
- g_main_loop_quit(loop);
-}
-
-static void test_webkit_web_inspector_close_and_inspect()
-{
- WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- loop = g_main_loop_new(NULL, TRUE);
-
- gboolean isLoadFinished = FALSE;
- g_signal_connect(webView, "load-finished", G_CALLBACK(loadFinished), &isLoadFinished);
- webkit_web_view_load_string(webView,
- "<html><body><p>woohoo</p></body></html>",
- "text/html", "UTF-8", "file://");
- if (!isLoadFinished)
- g_main_loop_run(loop);
-
- g_object_set(webkit_web_view_get_settings(webView), "enable-developer-extras", TRUE, NULL);
- WebKitWebInspector *inspector = webkit_web_view_get_inspector(webView);
-
- int timesElementInspected = 0;
- int timesClosed = 0;
- g_object_connect(inspector,
- "signal::inspect-web-view", G_CALLBACK(inspectElementCallback), &timesElementInspected,
- "signal::show-window", G_CALLBACK(showInspector), NULL,
- "signal::close-window", G_CALLBACK(closeInspector), &timesClosed,
- NULL);
-
- webkit_web_inspector_inspect_coordinates(inspector, 0.0, 0.0);
- g_assert_cmpint(timesElementInspected, ==, 1);
-
- g_main_loop_run(loop);
-
- webkit_web_inspector_close(inspector);
- g_assert_cmpint(timesClosed, ==, 1);
-
- webkit_web_inspector_inspect_coordinates(inspector, 0.0, 0.0);
- g_assert_cmpint(timesElementInspected, ==, 2);
-
- g_main_loop_run(loop);
-
- gtk_widget_destroy(GTK_WIDGET(webView));
- g_assert_cmpint(timesClosed, ==, 2);
-
- g_main_loop_unref(loop);
-}
-
-static void test_webkit_web_inspector_destroy_inspected_web_view()
-{
- WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- loop = g_main_loop_new(NULL, TRUE);
-
- gboolean isLoadFinished = FALSE;
- g_signal_connect(webView, "load-finished", G_CALLBACK(loadFinished), &isLoadFinished);
- webkit_web_view_load_string(webView,
- "<html><body><p>woohoo</p></body></html>",
- "text/html", "UTF-8", "file://");
- if (!isLoadFinished)
- g_main_loop_run(loop);
-
- g_object_set(webkit_web_view_get_settings(webView), "enable-developer-extras", TRUE, NULL);
- WebKitWebInspector *inspector = webkit_web_view_get_inspector(webView);
-
- int timesElementInspected = 0;
- int timesClosed = 0;
- g_object_connect(inspector,
- "signal::inspect-web-view", G_CALLBACK(inspectElementCallback), &timesElementInspected,
- "signal::show-window", G_CALLBACK(showInspector), NULL,
- "signal::close-window", G_CALLBACK(closeInspector), &timesClosed,
- NULL);
-
- webkit_web_inspector_inspect_coordinates(inspector, 0.0, 0.0);
- g_assert_cmpint(timesElementInspected, ==, 1);
-
- g_main_loop_run(loop);
-
- gtk_widget_destroy(GTK_WIDGET(webView));
- g_assert_cmpint(timesClosed, ==, 1);
-
- g_main_loop_unref(loop);
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_func("/webkit/webinspector/destroy-inspected-web-view", test_webkit_web_inspector_destroy_inspected_web_view);
- g_test_add_func("/webkit/webinspector/close-and-inspect", test_webkit_web_inspector_close_and_inspect);
-
- return g_test_run();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebplugindatabase.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebplugindatabase.c
deleted file mode 100644
index 652811b13..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebplugindatabase.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2010 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include <errno.h>
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-/* This function is not public, so we need an extern declaration */
-extern void webkit_web_settings_add_extra_plugin_directory(WebKitWebView* view, const gchar* directory);
-
-static void test_webkit_web_plugin_database_get_plugins()
-{
- WebKitWebView* view = WEBKIT_WEB_VIEW(webkit_web_view_new());
- WebKitWebPluginDatabase* database;
- GSList* pluginList, *p;
- gboolean found = FALSE;
- gboolean enabled = FALSE;
-
- webkit_web_settings_add_extra_plugin_directory(view, TEST_PLUGIN_DIR);
- g_object_ref_sink(G_OBJECT(view));
-
- database = webkit_get_web_plugin_database();
- pluginList = webkit_web_plugin_database_get_plugins(database);
- for (p = pluginList; p; p = p->next) {
- WebKitWebPlugin* plugin = (WebKitWebPlugin*)p->data;
- if (!g_strcmp0(webkit_web_plugin_get_name(plugin), "WebKit Test PlugIn") &&
- !g_strcmp0(webkit_web_plugin_get_description(plugin), "Simple Netscape® plug-in that handles test content for WebKit")) {
- found = TRUE;
- enabled = webkit_web_plugin_get_enabled(plugin);
- webkit_web_plugin_set_enabled(plugin, FALSE);
- }
- }
- webkit_web_plugin_database_plugins_list_free(pluginList);
- g_assert(found);
- g_assert(enabled);
-
- webkit_web_plugin_database_refresh(database);
- pluginList = webkit_web_plugin_database_get_plugins(database);
-
- for (p = pluginList; p; p = p->next) {
- WebKitWebPlugin* plugin = (WebKitWebPlugin*)p->data;
- if (!g_strcmp0(webkit_web_plugin_get_name(plugin), "WebKit Test PlugIn") &&
- !g_strcmp0(webkit_web_plugin_get_description(plugin), "Simple Netscape® plug-in that handles test content for WebKit"))
- enabled = webkit_web_plugin_get_enabled(plugin);
- }
- webkit_web_plugin_database_plugins_list_free(pluginList);
- g_assert(!enabled);
-
- g_object_unref(view);
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_func("/webkit/webplugindatabase/getplugins", test_webkit_web_plugin_database_get_plugins);
- return g_test_run ();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebresource.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebresource.c
deleted file mode 100644
index 35d09476d..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebresource.c
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * Copyright (C) 2009 Jan Michael Alonzo
- *
- * 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 <glib.h>
-#include <gtk/gtk.h>
-#include <libsoup/soup.h>
-#include <string.h>
-#include <webkit/webkit.h>
-
-#define INDEX_HTML "<html></html>"
-#define MAIN_HTML "<html><head><script language=\"javascript\" src=\"/javascript.js\"></script></head><body><h1>hah</h1></html>"
-#define JAVASCRIPT "function blah () { var a = 1; }"
-
-GMainLoop* loop;
-SoupSession *session;
-char *base_uri;
-WebKitWebResource* main_resource;
-WebKitWebResource* sub_resource;
-
-typedef struct {
- WebKitWebResource* webResource;
- WebKitWebView* webView;
-} WebResourceFixture;
-
-/* For real request testing */
-static void
-server_callback (SoupServer *server, SoupMessage *msg,
- const char *path, GHashTable *query,
- SoupClientContext *context, gpointer data)
-{
- if (msg->method != SOUP_METHOD_GET) {
- soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);
- return;
- }
-
- soup_message_set_status (msg, SOUP_STATUS_OK);
-
- /* Redirect */
- if (g_str_equal (path, "/")) {
- soup_message_set_status (msg, SOUP_STATUS_MOVED_PERMANENTLY);
-
- soup_message_headers_append (msg->response_headers,
- "Location", "/index.html");
- } else if (g_str_equal (path, "/index.html")) {
- soup_message_body_append (msg->response_body,
- SOUP_MEMORY_COPY,
- INDEX_HTML,
- strlen (INDEX_HTML));
- } else if (g_str_equal (path, "/main.html")) {
- soup_message_body_append (msg->response_body,
- SOUP_MEMORY_COPY,
- MAIN_HTML,
- strlen (MAIN_HTML));
- } else if (g_str_equal (path, "/javascript.js")) {
- soup_message_body_append (msg->response_body,
- SOUP_MEMORY_COPY,
- JAVASCRIPT,
- strlen (JAVASCRIPT));
- }
-
-
- soup_message_body_complete (msg->response_body);
-}
-
-static void web_resource_fixture_setup(WebResourceFixture* fixture, gconstpointer data)
-{
- fixture->webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(fixture->webView);
- const gchar* webData = "<html></html>";
- fixture->webResource = webkit_web_resource_new(webData, strlen(webData), "http://example.com/", "text/html", "utf8", "Example.com");
- g_assert(fixture->webResource);
-}
-
-static void web_resource_fixture_teardown(WebResourceFixture* fixture, gconstpointer data)
-{
- g_assert(fixture->webResource);
- g_object_unref(fixture->webResource);
- g_object_unref(fixture->webView);
-}
-
-static void test_webkit_web_resource_get_url(WebResourceFixture* fixture, gconstpointer data)
-{
- gchar* url;
- g_object_get(G_OBJECT(fixture->webResource), "uri", &url, NULL);
- g_assert_cmpstr(url, ==, "http://example.com/");
- g_assert_cmpstr(webkit_web_resource_get_uri(fixture->webResource) ,==,"http://example.com/");
- g_free(url);
-}
-
-static void test_webkit_web_resource_get_data(WebResourceFixture* fixture, gconstpointer data)
-{
- GString* charData = webkit_web_resource_get_data(fixture->webResource);
- g_assert_cmpstr(charData->str, ==, "<html></html>");
-}
-
-static void test_webkit_web_resource_get_mime_type(WebResourceFixture* fixture, gconstpointer data)
-{
- gchar* mime_type;
- g_object_get(G_OBJECT(fixture->webResource), "mime-type", &mime_type, NULL);
- g_assert_cmpstr(mime_type, ==, "text/html");
- g_assert_cmpstr(webkit_web_resource_get_mime_type(fixture->webResource),==,"text/html");
- g_free(mime_type);
-}
-
-static void test_webkit_web_resource_get_encoding(WebResourceFixture* fixture, gconstpointer data)
-{
- gchar* text_encoding;
- g_object_get(G_OBJECT(fixture->webResource), "encoding", &text_encoding, NULL);
- g_assert_cmpstr(text_encoding, ==, "utf8");
- g_assert_cmpstr(webkit_web_resource_get_encoding(fixture->webResource),==,"utf8");
- g_free(text_encoding);
-}
-
-static void test_webkit_web_resource_get_frame_name(WebResourceFixture* fixture, gconstpointer data)
-{
- gchar* frame_name;
- g_object_get(G_OBJECT(fixture->webResource), "frame-name", &frame_name, NULL);
- g_assert_cmpstr(frame_name, ==, "Example.com");
- g_assert_cmpstr(webkit_web_resource_get_frame_name(fixture->webResource),==,"Example.com");
- g_free(frame_name);
-}
-
-static void resource_request_starting_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, WebKitWebResource* web_resource, WebKitNetworkRequest* request, WebKitNetworkResponse* response, gpointer data)
-{
- gint* been_there = data;
- *been_there = *been_there + 1;
-
- if (*been_there == 1) {
- g_assert(!main_resource);
- main_resource = g_object_ref(web_resource);
-
- g_assert_cmpstr(webkit_web_resource_get_uri(web_resource), ==, base_uri);
-
- /* This should be a redirect, so the response must be NULL */
- g_assert(!response);
- } else if (*been_there == 2) {
- char* uri = g_strdup_printf("%sindex.html", base_uri);
-
- g_assert_cmpstr(webkit_web_resource_get_uri(web_resource), ==, uri);
-
- /* Cancel the request. */
- webkit_network_request_set_uri(request, "about:blank");
-
- g_free(uri);
- }
-}
-
-static void notify_load_status_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
-{
- if (webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FINISHED) {
- gboolean* been_there = data;
- *been_there = TRUE;
-
- g_assert_cmpstr(webkit_web_view_get_uri(web_view), ==, "about:blank");
-
- g_main_loop_quit(loop);
- }
-}
-
-static void test_web_resource_loading()
-{
- WebKitWebView* web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
- gint been_to_resource_request_starting = 0;
- gboolean been_to_load_finished = FALSE;
- WebKitWebFrame* web_frame;
- WebKitWebDataSource* data_source;
-
- loop = g_main_loop_new(NULL, TRUE);
-
- g_object_ref_sink(web_view);
-
- g_signal_connect(web_view, "resource-request-starting",
- G_CALLBACK(resource_request_starting_cb),
- &been_to_resource_request_starting);
-
- g_signal_connect(web_view, "notify::load-status",
- G_CALLBACK(notify_load_status_cb),
- &been_to_load_finished);
-
- webkit_web_view_load_uri(web_view, base_uri);
-
- /* We won't get finished immediately, because of the redirect */
- g_main_loop_run(loop);
-
- web_frame = webkit_web_view_get_main_frame(web_view);
- data_source = webkit_web_frame_get_data_source(web_frame);
-
- g_assert(main_resource);
- g_assert(webkit_web_data_source_get_main_resource(data_source) == main_resource);
- g_object_unref(main_resource);
-
- g_assert_cmpint(been_to_resource_request_starting, ==, 2);
- g_assert_cmpint(been_to_load_finished, ==, TRUE);
-
- g_object_unref(web_view);
- g_main_loop_unref(loop);
-}
-
-static void resource_request_starting_sub_cb(WebKitWebView* web_view, WebKitWebFrame* web_frame, WebKitWebResource* web_resource, WebKitNetworkRequest* request, WebKitNetworkResponse* response, gpointer data)
-{
- if (!main_resource)
- main_resource = g_object_ref(web_resource);
- else if (!sub_resource)
- sub_resource = g_object_ref(web_resource);
-}
-
-static void notify_load_status_sub_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
-{
- if (webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FINISHED)
- g_main_loop_quit(loop);
-}
-
-static gboolean idle_quit_loop_cb(gpointer data)
-{
- g_main_loop_quit(loop);
- return FALSE;
-}
-
-static void test_web_resource_sub_resource_loading()
-{
- WebKitWebView* web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
- WebKitWebFrame* web_frame;
- WebKitWebDataSource* data_source;
- GList* sub_resources;
- char* uri = g_strdup_printf("%smain.html", base_uri);
-
- main_resource = NULL;
-
- loop = g_main_loop_new(NULL, TRUE);
-
- g_object_ref_sink(web_view);
-
- g_signal_connect(web_view, "resource-request-starting",
- G_CALLBACK(resource_request_starting_sub_cb),
- NULL);
-
- g_signal_connect(web_view, "notify::load-status",
- G_CALLBACK(notify_load_status_sub_cb),
- NULL);
-
- webkit_web_view_load_uri(web_view, uri);
-
- g_main_loop_run(loop);
-
- /* The main resource should be loaded; now let's wait for the sub-resource to load */
- g_idle_add(idle_quit_loop_cb, NULL);
- g_main_loop_run(loop);
-
- g_assert(main_resource && sub_resource);
- g_assert(main_resource != sub_resource);
-
- web_frame = webkit_web_view_get_main_frame(web_view);
- data_source = webkit_web_frame_get_data_source(web_frame);
-
- g_assert(webkit_web_data_source_get_main_resource(data_source) == main_resource);
- g_object_unref(main_resource);
-
- sub_resources = webkit_web_data_source_get_subresources(data_source);
- // Expected resources: javascripts.js, favicon.ico
- g_assert(sub_resources);
- g_assert(sub_resources->next);
- g_assert(!sub_resources->next->next);
-
- // Test that the object we got from the data source is the same
- // that went through resource-request-starting. Note that the order is
- // not important (and not guaranteed since the resources are stored in a
- // hashtable).
- g_assert(WEBKIT_WEB_RESOURCE(sub_resources->data) == sub_resource
- || WEBKIT_WEB_RESOURCE(sub_resources->next->data) == sub_resource);
-
- g_object_unref(web_view);
- g_main_loop_unref(loop);
-}
-
-int main(int argc, char** argv)
-{
- SoupServer* server;
- SoupURI* soup_uri;
-
- gtk_test_init(&argc, &argv, NULL);
-
- // Get rid of runtime warnings about deprecated properties and signals, since they break the tests.
- g_setenv("G_ENABLE_DIAGNOSTIC", "0", TRUE);
-
- server = soup_server_new(SOUP_SERVER_PORT, 0, NULL);
- soup_server_run_async(server);
-
- soup_server_add_handler(server, NULL, server_callback, NULL, NULL);
-
- soup_uri = soup_uri_new("http://127.0.0.1/");
- soup_uri_set_port(soup_uri, soup_server_get_port(server));
-
- base_uri = soup_uri_to_string(soup_uri, FALSE);
- soup_uri_free(soup_uri);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add("/webkit/webresource/get_url",
- WebResourceFixture, 0, web_resource_fixture_setup,
- test_webkit_web_resource_get_url, web_resource_fixture_teardown);
- g_test_add("/webkit/webresource/get_mime_type",
- WebResourceFixture, 0, web_resource_fixture_setup,
- test_webkit_web_resource_get_mime_type, web_resource_fixture_teardown);
- g_test_add("/webkit/webresource/get_text_encoding_name",
- WebResourceFixture, 0, web_resource_fixture_setup,
- test_webkit_web_resource_get_encoding, web_resource_fixture_teardown);
- g_test_add("/webkit/webresource/get_frame_name",
- WebResourceFixture, 0, web_resource_fixture_setup,
- test_webkit_web_resource_get_frame_name, web_resource_fixture_teardown);
- g_test_add("/webkit/webresource/get_data",
- WebResourceFixture, 0, web_resource_fixture_setup,
- test_webkit_web_resource_get_data, web_resource_fixture_teardown);
-
- g_test_add_func("/webkit/webresource/loading", test_web_resource_loading);
- g_test_add_func("/webkit/webresource/sub_resource_loading", test_web_resource_sub_resource_loading);
-
- return g_test_run ();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebsettings.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebsettings.c
deleted file mode 100644
index e557e133c..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebsettings.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2009 Jan Michael Alonzo
- *
- * 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 <glib.h>
-#include <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-static void test_webkit_web_settings_copy(void)
-{
- WebKitWebSettings *settings = webkit_web_settings_new();
-
- // Set some non-default settings to verify that settings are properly copied.
- g_object_set(settings,
- "enable-webgl", TRUE,
- "enable-fullscreen", TRUE,
- "auto-load-images", FALSE,
- "default-encoding", "utf-8",
- "enable-mediasource", TRUE,
- NULL);
-
- WebKitWebSettings *copy = webkit_web_settings_copy(settings);
-
- gboolean enableWebGL = FALSE;
- gboolean enableFullscreen = FALSE;
- gboolean autoLoadImages = FALSE;
- gboolean enableMediaSource = FALSE;
- char *defaultEncoding = 0;
- g_object_get(copy,
- "enable-fullscreen", &enableFullscreen,
- "enable-webgl", &enableWebGL,
- "auto-load-images", &autoLoadImages,
- "default-encoding", &defaultEncoding,
- "enable-mediasource", &enableMediaSource,
- NULL);
-
- g_assert(enableWebGL);
- g_assert(enableFullscreen);
- g_assert(!autoLoadImages);
- g_assert_cmpstr(defaultEncoding, ==, "utf-8");
- g_assert(enableMediaSource);
- g_free(defaultEncoding);
-}
-
-static void test_webkit_web_settings_user_agent(void)
-{
- WebKitWebSettings *settings;
- GtkWidget *webView;
- char *defaultUserAgent;
- char *userAgent = 0;
- g_test_bug("17375");
-
- webView = webkit_web_view_new();
- g_object_ref_sink(webView);
-
- settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webView));
- defaultUserAgent = g_strdup(webkit_web_settings_get_user_agent(settings));
-
- g_assert(g_strstr_len(defaultUserAgent, -1, "Version/8.0 Safari/"));
- g_assert(g_strstr_len(defaultUserAgent, -1, "Version/8.0") < g_strstr_len(defaultUserAgent, -1, "Safari/"));
-
- // test a custom UA string
- userAgent = 0;
- g_object_set(settings, "user-agent", "testwebsettings/0.1", NULL);
- g_object_get(settings,"user-agent", &userAgent, NULL);
- g_assert_cmpstr(userAgent, ==, "testwebsettings/0.1");
- g_free(userAgent);
-
- // setting it to NULL or an empty value should give us the default UA string
- userAgent = 0;
- g_object_set(settings, "user-agent", 0, NULL);
- g_object_get(settings,"user-agent", &userAgent, NULL);
- g_assert_cmpstr(userAgent, ==, defaultUserAgent);
- g_free(userAgent);
-
- userAgent = 0;
- g_object_set(settings, "user-agent", "", NULL);
- g_object_get(settings,"user-agent", &userAgent, NULL);
- g_assert_cmpstr(userAgent, ==, defaultUserAgent);
- g_free(userAgent);
-
- g_free(defaultUserAgent);
- g_object_unref(webView);
-}
-
-int main(int argc, char **argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_func("/webkit/websettings/user_agent", test_webkit_web_settings_user_agent);
- g_test_add_func("/webkit/websettings/copy", test_webkit_web_settings_copy);
- return g_test_run ();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebview.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebview.c
deleted file mode 100644
index 86057867c..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwebview.c
+++ /dev/null
@@ -1,749 +0,0 @@
-/*
- * Copyright (C) 2008 Holger Hans Peter Freyther
- * Copyright (C) 2009, 2010 Collabora Ltd.
- * Copyright (C) 2012 Igalia S.L.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include "test_utils.h"
-
-#include <errno.h>
-#include <unistd.h>
-#include <string.h>
-
-#include <glib.h>
-#include <glib/gstdio.h>
-#include <gdk/gdk.h>
-#include <gdk/gdkkeysyms.h>
-#include <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-GMainLoop* loop;
-SoupSession *session;
-char* base_uri;
-
-/* For real request testing */
-static void
-server_callback(SoupServer* server, SoupMessage* msg,
- const char* path, GHashTable* query,
- SoupClientContext* context, gpointer data)
-{
- if (msg->method != SOUP_METHOD_GET) {
- soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED);
- return;
- }
-
- soup_message_set_status(msg, SOUP_STATUS_OK);
-
- if (g_str_equal(path, "/favicon.ico")) {
- char* contents;
- gsize length;
- GError* error = NULL;
-
- g_file_get_contents("blank.ico", &contents, &length, &error);
- g_assert(!error);
-
- soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, length);
- } else if (g_str_equal(path, "/bigdiv.html")) {
- char* contents = g_strdup("<html><body><a id=\"link\" href=\"http://abc.def\">test</a><div style=\"background-color: green; height: 1200px;\"></div></body></html>");
- soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, strlen(contents));
- } else if (g_str_equal(path, "/iframe.html")) {
- char* contents = g_strdup("<html><body id=\"some-content\"><div style=\"background-color: green; height: 50px;\"></div><iframe src=\"bigdiv.html\"></iframe></body></html>");
- soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, strlen(contents));
- } else {
- char* contents = g_strdup("<html><body>test</body></html>");
- soup_message_body_append(msg->response_body, SOUP_MEMORY_TAKE, contents, strlen(contents));
- }
-
- soup_message_body_complete(msg->response_body);
-}
-
-static void idle_quit_loop_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
-{
- if (webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FINISHED ||
- webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FAILED)
- g_main_loop_quit(loop);
-}
-
-static gboolean timeout_cb(gpointer data)
-{
- g_error("Didn't get icon-uri before timing out.");
- return FALSE;
-}
-
-static void icon_uri_changed_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
-{
- char* expected_uri;
-
- g_assert_cmpstr(g_param_spec_get_name(pspec), ==, "icon-uri");
-
- expected_uri = g_strdup_printf("%sfavicon.ico", base_uri);
- g_assert_cmpstr(webkit_web_view_get_icon_uri(web_view), ==, expected_uri);
- g_free(expected_uri);
-
- g_main_loop_quit(loop);
-}
-
-static void icon_loaded_cb(WebKitWebView* web_view, char* icon_uri, gpointer data)
-{
- gboolean* been_here = (gboolean*)data;
- char* expected_uri = g_strdup_printf("%sfavicon.ico", base_uri);
- g_assert_cmpstr(icon_uri, ==, expected_uri);
- g_free(expected_uri);
-
- g_assert_cmpstr(icon_uri, ==, webkit_web_view_get_icon_uri(web_view));
-
- *been_here = TRUE;
-}
-
-static void test_webkit_web_view_icon_uri()
-{
- gboolean been_to_icon_loaded = FALSE;
- WebKitWebView* view = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_object_ref_sink(G_OBJECT(view));
-
- loop = g_main_loop_new(NULL, TRUE);
-
- g_object_connect(G_OBJECT(view),
- "signal::notify::icon-uri", icon_uri_changed_cb, NULL,
- "signal::icon-loaded", icon_loaded_cb, &been_to_icon_loaded,
- NULL);
-
- webkit_web_view_load_uri(view, base_uri);
-
- guint timeout_id = g_timeout_add(500, timeout_cb, 0);
-
- g_main_loop_run(loop);
-
- g_source_remove(timeout_id);
-
- g_assert(been_to_icon_loaded);
-
- g_object_unref(view);
-}
-
-static gboolean map_event_cb(GtkWidget *widget, GdkEvent* event, gpointer data)
-{
- GMainLoop* loop = (GMainLoop*)data;
- g_main_loop_quit(loop);
-
- return FALSE;
-}
-
-static gboolean quit_after_short_delay_cb(gpointer data)
-{
- g_main_loop_quit((GMainLoop*)data);
- return FALSE;
-}
-
-static void test_webkit_web_view_grab_focus()
-{
- char* uri = g_strconcat(base_uri, "iframe.html", NULL);
- GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP);
- GtkWidget* scrolled_window = gtk_scrolled_window_new(NULL, NULL);
- WebKitWebView* view = WEBKIT_WEB_VIEW(webkit_web_view_new());
- GtkAdjustment* adjustment;
-
- gtk_window_set_default_size(GTK_WINDOW(window), 400, 200);
-
- gtk_container_add(GTK_CONTAINER(window), scrolled_window);
- gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(view));
-
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-
- loop = g_main_loop_new(NULL, TRUE);
-
- g_signal_connect(view, "notify::load-status", G_CALLBACK(idle_quit_loop_cb), NULL);
-
- /* Wait for window to show up */
- gtk_widget_show_all(window);
- g_signal_connect(window, "map-event",
- G_CALLBACK(map_event_cb), loop);
- g_main_loop_run(loop);
-
- /* Load a page with a big div that will cause scrollbars to appear */
- webkit_web_view_load_uri(view, uri);
- g_main_loop_run(loop);
-
- adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolled_window));
- g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), ==, 0.0);
-
- /* Since webkit_web_view_execute_script does not return a value,
- it is impossible to know if an inner document has focus after
- a node of it was focused via .focus() method.
- The code below is an workaround: if the node has focus, a scroll
- action is performed and afterward it is checked if the adjustment
- has to be different from 0.
- */
- char script[] = "var innerDoc = document.defaultView.frames[0].document; \
- innerDoc.getElementById(\"link\").focus(); \
- if (innerDoc.hasFocus()) \
- window.scrollBy(0, 100);";
-
- /* Focus an element using JavaScript */
- webkit_web_view_execute_script(view, script);
-
- /* Adjustments update asynchronously, so we must wait a bit. */
- g_timeout_add(100, quit_after_short_delay_cb, loop);
- g_main_loop_run(loop);
-
- /* Make sure the ScrolledWindow noticed the scroll */
- g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), !=, 0.0);
-
- g_free(uri);
- gtk_widget_destroy(window);
-}
-
-static void do_test_webkit_web_view_adjustments(gboolean with_page_cache)
-{
- char* effective_uri = g_strconcat(base_uri, "bigdiv.html", NULL);
- char* second_uri = g_strconcat(base_uri, "iframe.html", NULL);
- GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- GtkWidget* scrolled_window = gtk_scrolled_window_new(NULL, NULL);
- WebKitWebView* view = WEBKIT_WEB_VIEW(webkit_web_view_new());
- GtkAdjustment* adjustment;
- double lower;
- double upper;
-
- if (with_page_cache) {
- WebKitWebSettings* settings = webkit_web_view_get_settings(view);
- g_object_set(settings, "enable-page-cache", TRUE, NULL);
- }
-
- gtk_window_set_default_size(GTK_WINDOW(window), 400, 200);
-
- gtk_container_add(GTK_CONTAINER(window), scrolled_window);
- gtk_container_add(GTK_CONTAINER(scrolled_window), GTK_WIDGET(view));
-
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-
- loop = g_main_loop_new(NULL, TRUE);
-
- g_object_connect(G_OBJECT(view),
- "signal::notify::load-status", idle_quit_loop_cb, NULL,
- NULL);
-
- /* Wait for window to show up */
- gtk_widget_show_all(window);
- g_signal_connect(window, "map-event",
- G_CALLBACK(map_event_cb), loop);
- g_main_loop_run(loop);
-
- /* Load a page with a big div that will cause scrollbars to appear */
- webkit_web_view_load_uri(view, effective_uri);
- g_main_loop_run(loop);
-
- /* Adjustments update asynchronously, so we must wait a bit. */
- g_timeout_add(100, quit_after_short_delay_cb, loop);
- g_main_loop_run(loop);
-
- adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolled_window));
- g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), ==, 0.0);
-
- lower = gtk_adjustment_get_lower(adjustment);
- upper = gtk_adjustment_get_upper(adjustment);
-
- /* Scroll the view using JavaScript */
- webkit_web_view_execute_script(view, "window.scrollBy(0, 100)");
-
- /* Adjustments update asynchronously, so we must wait a bit. */
- g_timeout_add(100, quit_after_short_delay_cb, loop);
- g_main_loop_run(loop);
-
- /* Make sure the ScrolledWindow noticed the scroll */
- g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), ==, 100.0);
-
- /* Load a second URI */
- webkit_web_view_load_uri(view, second_uri);
- g_main_loop_run(loop);
-
- /* The page loaded but the adjustments may not be updated yet. Wait a bit. */
- g_timeout_add(100, quit_after_short_delay_cb, loop);
- g_main_loop_run(loop);
-
- /* Make sure the scrollbar has been reset */
- g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), ==, 0.0);
-
- /* Go back */
- webkit_web_view_go_back(view);
-
- /* When using page cache, go_back will return syncronously */
- if (!with_page_cache)
- g_main_loop_run(loop);
-
- /* Make sure GTK+ has time to process the changes in size, for the adjusments */
- while (gtk_events_pending())
- gtk_main_iteration();
-
- /* Make sure upper and lower bounds have been restored correctly */
- g_assert_cmpfloat(lower, ==, gtk_adjustment_get_lower(adjustment));
- g_assert_cmpfloat(upper, ==, gtk_adjustment_get_upper(adjustment));
- g_assert_cmpfloat(gtk_adjustment_get_value(adjustment), ==, 100.0);
-
- g_free(effective_uri);
- g_free(second_uri);
-
- gtk_widget_destroy(window);
-}
-
-static void test_webkit_web_view_adjustments()
-{
- /* Test this with page cache disabled, and enabled. */
- do_test_webkit_web_view_adjustments(FALSE);
- do_test_webkit_web_view_adjustments(TRUE);
-}
-
-gboolean delayed_destroy(gpointer data)
-{
- gtk_widget_destroy(GTK_WIDGET(data));
- g_main_loop_quit(loop);
- return FALSE;
-}
-
-static void test_webkit_web_view_destroy()
-{
- GtkWidget* window;
- GtkWidget* web_view;
-
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- web_view = webkit_web_view_new();
-
- gtk_container_add(GTK_CONTAINER(window), web_view);
-
- gtk_widget_show_all(window);
-
- loop = g_main_loop_new(NULL, TRUE);
-
- g_signal_connect(window, "map-event",
- G_CALLBACK(map_event_cb), loop);
- g_main_loop_run(loop);
-
- g_idle_add(delayed_destroy, web_view);
- g_main_loop_run(loop);
-
- gtk_widget_destroy(window);
-}
-
-static void test_webkit_web_view_window_features()
-{
- GtkWidget* window;
- GtkWidget* web_view;
-
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- web_view = webkit_web_view_new();
-
- gtk_container_add(GTK_CONTAINER(window), web_view);
-
- gtk_widget_show_all(window);
-
- loop = g_main_loop_new(NULL, TRUE);
-
- g_signal_connect(window, "map-event",
- G_CALLBACK(map_event_cb), loop);
- g_main_loop_run(loop);
-
- /* Bug #36144 */
- g_object_set(G_OBJECT(web_view), "window-features", NULL, NULL);
-
- gtk_widget_destroy(window);
-}
-
-static void test_webkit_web_view_in_offscreen_window_does_not_crash()
-{
- loop = g_main_loop_new(NULL, TRUE);
-
- GtkWidget *window = gtk_offscreen_window_new();
- GtkWidget *web_view = webkit_web_view_new();
-
- gtk_container_add(GTK_CONTAINER(window), web_view);
- gtk_widget_show_all(window);
- g_signal_connect(web_view, "notify::load-status", G_CALLBACK(idle_quit_loop_cb), NULL);
- webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view), base_uri);
-
- g_main_loop_run(loop);
-
- gtk_widget_destroy(window);
- g_main_loop_unref(loop);
-}
-
-static void test_webkit_web_view_does_not_steal_focus()
-{
- loop = g_main_loop_new(NULL, TRUE);
-
- GtkWidget *window = gtk_offscreen_window_new();
- GtkWidget *webView = webkit_web_view_new();
- GtkWidget *entry = gtk_entry_new();
-
-#ifdef GTK_API_VERSION_2
- GtkWidget *box = gtk_hbox_new(FALSE, 0);
-#else
- GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
-#endif
-
- gtk_container_add(GTK_CONTAINER(box), webView);
- gtk_container_add(GTK_CONTAINER(box), entry);
- gtk_container_add(GTK_CONTAINER(window), box);
- gtk_widget_show_all(window);
-
- gtk_widget_grab_focus(entry);
- g_assert(gtk_widget_is_focus(entry));
-
- g_signal_connect(webView, "notify::load-status", G_CALLBACK(idle_quit_loop_cb), NULL);
- webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(webView),
- "<html><body>"
- " <input id=\"entry\" type=\"text\"/>"
- " <script>"
- " document.getElementById(\"entry\").focus();"
- " </script>"
- "</body></html>", "file://");
-
- g_main_loop_run(loop);
-
- g_assert(gtk_widget_is_focus(entry));
-
- gtk_widget_destroy(window);
- g_main_loop_unref(loop);
-}
-
-static gboolean emitKeyStroke(WebKitWebView* webView)
-{
- GdkEvent* pressEvent = gdk_event_new(GDK_KEY_PRESS);
- pressEvent->key.keyval = GDK_KEY_f;
- GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(webView));
- pressEvent->key.window = window;
- g_object_ref(pressEvent->key.window);
-
-#ifndef GTK_API_VERSION_2
- GdkDeviceManager* manager = gdk_display_get_device_manager(gdk_window_get_display(window));
- gdk_event_set_device(pressEvent, gdk_device_manager_get_client_pointer(manager));
-#endif
-
- // When synthesizing an event, an invalid hardware_keycode value
- // can cause it to be badly processed by Gtk+.
- GdkKeymapKey* keys;
- gint n_keys;
- if (gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), GDK_KEY_f, &keys, &n_keys)) {
- pressEvent->key.hardware_keycode = keys[0].keycode;
- g_free(keys);
- }
-
- GdkEvent* releaseEvent = gdk_event_copy(pressEvent);
- gtk_main_do_event(pressEvent);
- gdk_event_free(pressEvent);
- releaseEvent->key.type = GDK_KEY_RELEASE;
- gtk_main_do_event(releaseEvent);
- gdk_event_free(releaseEvent);
-
- return FALSE;
-}
-
-static gboolean entering_fullscreen_cb(WebKitWebView* webView, GObject* element, gboolean blocked)
-{
- if (blocked)
- g_main_loop_quit(loop);
- else
- g_timeout_add(200, (GSourceFunc) emitKeyStroke, webView);
- return blocked;
-}
-
-static gboolean leaving_fullscreen_cb(WebKitWebView* webView, GObject* element, gpointer data)
-{
- g_main_loop_quit(loop);
- return FALSE;
-}
-
-static void test_webkit_web_view_fullscreen(gconstpointer blocked)
-{
- GtkWidget* window;
- GtkWidget* web_view;
- WebKitWebSettings *settings;
-
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- web_view = webkit_web_view_new();
-
- settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(web_view));
- g_object_set(settings, "enable-fullscreen", TRUE, NULL);
- webkit_web_view_set_settings(WEBKIT_WEB_VIEW(web_view), settings);
-
- gtk_container_add(GTK_CONTAINER(window), web_view);
-
- gtk_widget_show_all(window);
-
- loop = g_main_loop_new(NULL, TRUE);
-
- g_signal_connect(web_view, "entering-fullscreen", G_CALLBACK(entering_fullscreen_cb), (gpointer) blocked);
- g_signal_connect(web_view, "leaving-fullscreen", G_CALLBACK(leaving_fullscreen_cb), NULL);
-
- webkit_web_view_load_string(WEBKIT_WEB_VIEW(web_view), "<html><body>"
- "<script>"
- "var eventName = 'keypress';"
- "document.addEventListener(eventName, function () {"
- " document.documentElement.webkitRequestFullScreen();"
- "}, false);"
- "</script></body></html>", NULL, NULL, NULL);
-
- g_timeout_add(100, (GSourceFunc) emitKeyStroke, WEBKIT_WEB_VIEW(web_view));
- g_main_loop_run(loop);
-
- gtk_widget_destroy(window);
-}
-
-static gboolean checkMimeTypeForFilter(GtkFileFilter* filter, const gchar* mimeType)
-{
- GtkFileFilterInfo filter_info;
- filter_info.contains = GTK_FILE_FILTER_MIME_TYPE;
- filter_info.mime_type = mimeType;
- return gtk_file_filter_filter(filter, &filter_info);
-}
-
-static gboolean runFileChooserCbNoMultiselNoMime(WebKitWebView* webview, WebKitFileChooserRequest* request, gpointer data)
-{
- g_assert(!webkit_file_chooser_request_get_select_multiple(request));
-
- const gchar* const* mimeTypes = webkit_file_chooser_request_get_mime_types(request);
- g_assert(!mimeTypes);
- GtkFileFilter* filter = webkit_file_chooser_request_get_mime_types_filter(request);
- g_assert(!filter);
-
- const gchar* const* selectedFiles = webkit_file_chooser_request_get_selected_files(request);
- g_assert(!selectedFiles);
-
- g_main_loop_quit(loop);
- return TRUE;
-}
-
-static gboolean runFileChooserCbMultiselNoMime(WebKitWebView* webview, WebKitFileChooserRequest* request, gpointer data)
-{
- g_assert(webkit_file_chooser_request_get_select_multiple(request));
-
- const gchar* const* mimeTypes = webkit_file_chooser_request_get_mime_types(request);
- g_assert(!mimeTypes);
- GtkFileFilter* filter = webkit_file_chooser_request_get_mime_types_filter(request);
- g_assert(!filter);
- const gchar* const* selectedFiles = webkit_file_chooser_request_get_selected_files(request);
- g_assert(!selectedFiles);
-
- // Select some files.
- const gchar* filesToSelect[4] = { "/foo", "/foo/bar", "/foo/bar/baz", 0 };
- webkit_file_chooser_request_select_files(request, filesToSelect);
-
- // Check the files that have been just selected.
- selectedFiles = webkit_file_chooser_request_get_selected_files(request);
- g_assert(selectedFiles);
- g_assert_cmpstr(selectedFiles[0], ==, "/foo");
- g_assert_cmpstr(selectedFiles[1], ==, "/foo/bar");
- g_assert_cmpstr(selectedFiles[2], ==, "/foo/bar/baz");
- g_assert(!selectedFiles[3]);
-
- g_main_loop_quit(loop);
- return TRUE;
-}
-
-static gboolean runFileChooserCbSelectionRetained(WebKitWebView* webview, WebKitFileChooserRequest* request, gpointer data)
-{
- const gchar* const* selectedFiles = webkit_file_chooser_request_get_selected_files(request);
- g_assert(selectedFiles);
- g_assert_cmpstr(selectedFiles[0], ==, "/foo");
- g_assert_cmpstr(selectedFiles[1], ==, "/foo/bar");
- g_assert_cmpstr(selectedFiles[2], ==, "/foo/bar/baz");
- g_assert(!selectedFiles[3]);
-
- g_main_loop_quit(loop);
- return TRUE;
-}
-
-static gboolean runFileChooserCbNoMultiselAcceptTypes(WebKitWebView* webview, WebKitFileChooserRequest* request, gpointer data)
-{
- g_assert(!webkit_file_chooser_request_get_select_multiple(request));
-
- const gchar* const* mimeTypes = webkit_file_chooser_request_get_mime_types(request);
- g_assert(mimeTypes);
- g_assert_cmpstr(mimeTypes[0], ==, "audio/*");
- g_assert_cmpstr(mimeTypes[1], ==, "video/*");
- g_assert_cmpstr(mimeTypes[2], ==, "image/*");
- g_assert(!mimeTypes[3]);
-
- GtkFileFilter* filter = webkit_file_chooser_request_get_mime_types_filter(request);
- g_assert(GTK_IS_FILE_FILTER(filter));
- g_assert(checkMimeTypeForFilter(filter, "audio/*"));
- g_assert(checkMimeTypeForFilter(filter, "video/*"));
- g_assert(checkMimeTypeForFilter(filter, "image/*"));
-
- const gchar* const* selectedFiles = webkit_file_chooser_request_get_selected_files(request);
- g_assert(!selectedFiles);
-
- g_main_loop_quit(loop);
- return TRUE;
-}
-
-void doMouseButtonEvent(GtkWidget* widget, GdkEventType eventType, int x, int y, unsigned int button, unsigned int modifiers)
-{
- g_assert(gtk_widget_get_realized(widget));
-
- GdkEvent* event = gdk_event_new(eventType);
- event->button.window = gtk_widget_get_window(widget);
- g_object_ref(event->button.window);
-
- event->button.time = GDK_CURRENT_TIME;
- event->button.x = x;
- event->button.y = y;
- event->button.axes = 0;
- event->button.state = modifiers;
- event->button.button = button;
-
-#ifndef GTK_API_VERSION_2
- event->button.device = gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gtk_widget_get_display(widget)));
-#endif
-
- int xRoot, yRoot;
- gdk_window_get_root_coords(gtk_widget_get_window(widget), x, y, &xRoot, &yRoot);
- event->button.x_root = xRoot;
- event->button.y_root = yRoot;
- gtk_main_do_event(event);
-}
-
-static void clickMouseButton(GtkWidget* widget, int x, int y, unsigned int button, unsigned int modifiers)
-{
- doMouseButtonEvent(widget, GDK_BUTTON_PRESS, x, y, button, modifiers);
- doMouseButtonEvent(widget, GDK_BUTTON_RELEASE, x, y, button, modifiers);
-}
-
-static gboolean clickMouseButtonAndWaitForFileChooserRequest(WebKitWebView* webView)
-{
- clickMouseButton(GTK_WIDGET(webView), 5, 5, 1, 0);
- return TRUE;
-}
-
-static void test_webkit_web_view_file_chooser()
-{
- const gchar* htmlFormatBase = "<html><body>"
- "<input style='position:absolute;left:0;top:0;margin:0;padding:0' type='file' %s/>"
- "</body></html>";
-
- GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- GtkWidget* webView = webkit_web_view_new();
- gtk_container_add(GTK_CONTAINER(window), webView);
- gtk_widget_show_all(window);
-
- loop = g_main_loop_new(NULL, TRUE);
-
- // Multiple selections not allowed, no MIME filtering.
- gulong handler = g_signal_connect(webView, "run-file-chooser", G_CALLBACK(runFileChooserCbNoMultiselNoMime), NULL);
- gchar* htmlFormat = g_strdup_printf(htmlFormatBase, "");
- webkit_web_view_load_string(WEBKIT_WEB_VIEW(webView), htmlFormat, NULL, NULL, NULL);
- g_free(htmlFormat);
-
- g_timeout_add(100, (GSourceFunc) clickMouseButtonAndWaitForFileChooserRequest, WEBKIT_WEB_VIEW(webView));
- g_main_loop_run(loop);
-
- g_signal_handler_disconnect(webView, handler);
-
- // Multiple selections allowed, no MIME filtering, some pre-selected files.
- handler = g_signal_connect(webView, "run-file-chooser", G_CALLBACK(runFileChooserCbMultiselNoMime), NULL);
- htmlFormat = g_strdup_printf(htmlFormatBase, "multiple");
- webkit_web_view_load_string(WEBKIT_WEB_VIEW(webView), htmlFormat, NULL, NULL, NULL);
- g_free(htmlFormat);
-
- g_timeout_add(100, (GSourceFunc) clickMouseButtonAndWaitForFileChooserRequest, WEBKIT_WEB_VIEW(webView));
- g_main_loop_run(loop);
-
- g_signal_handler_disconnect(webView, handler);
-
- // Perform another request to check if the list of files selected
- // in the previous step appears now as part of the new request.
- handler = g_signal_connect(webView, "run-file-chooser", G_CALLBACK(runFileChooserCbSelectionRetained), NULL);
- g_timeout_add(100, (GSourceFunc) clickMouseButtonAndWaitForFileChooserRequest, WEBKIT_WEB_VIEW(webView));
- g_main_loop_run(loop);
-
- g_signal_handler_disconnect(webView, handler);
-
- // Multiple selections not allowed, only accept images, audio and video files.
- handler = g_signal_connect(webView, "run-file-chooser", G_CALLBACK(runFileChooserCbNoMultiselAcceptTypes), NULL);
- htmlFormat = g_strdup_printf(htmlFormatBase, "accept='audio/*,video/*,image/*'");
- webkit_web_view_load_string(WEBKIT_WEB_VIEW(webView), htmlFormat, NULL, NULL, NULL);
- g_free(htmlFormat);
-
- g_timeout_add(100, (GSourceFunc) clickMouseButtonAndWaitForFileChooserRequest, WEBKIT_WEB_VIEW(webView));
- g_main_loop_run(loop);
-
- g_signal_handler_disconnect(webView, handler);
- gtk_widget_destroy(window);
-}
-
-static void test_webkit_web_view_source_mode()
-{
- GtkWidget* web_view;
-
- web_view = webkit_web_view_new();
-
- webkit_web_view_load_string(WEBKIT_WEB_VIEW(web_view), "<html><body></body></html>", NULL, NULL, NULL);
-
- g_assert(!webkit_web_view_get_view_source_mode(WEBKIT_WEB_VIEW(web_view)));
-
- webkit_web_view_set_view_source_mode(WEBKIT_WEB_VIEW(web_view), TRUE);
-
- g_assert(webkit_web_view_get_view_source_mode(WEBKIT_WEB_VIEW(web_view)));
-
- webkit_web_view_set_view_source_mode(WEBKIT_WEB_VIEW(web_view), FALSE);
-
- g_assert(!webkit_web_view_get_view_source_mode(WEBKIT_WEB_VIEW(web_view)));
-
- gtk_widget_destroy(web_view);
-}
-
-int main(int argc, char** argv)
-{
- SoupServer* server;
- SoupURI* soup_uri;
-
- gtk_test_init(&argc, &argv, NULL);
-
- // Get rid of runtime warnings about deprecated properties and signals, since they break the tests.
- g_setenv("G_ENABLE_DIAGNOSTIC", "0", TRUE);
-
- /* Hopefully make test independent of the path it's called from. */
- testutils_relative_chdir("Tools/TestWebKitAPI/Tests/WebKitGtk/resources/test.html", argv[0]);
-
- server = soup_server_new(SOUP_SERVER_PORT, 0, NULL);
- soup_server_run_async(server);
-
- soup_server_add_handler(server, NULL, server_callback, NULL, NULL);
-
- soup_uri = soup_uri_new("http://127.0.0.1/");
- soup_uri_set_port(soup_uri, soup_server_get_port(server));
-
- base_uri = soup_uri_to_string(soup_uri, FALSE);
- soup_uri_free(soup_uri);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_func("/webkit/webview/icon-uri", test_webkit_web_view_icon_uri);
- g_test_add_func("/webkit/webview/adjustments", test_webkit_web_view_adjustments);
- g_test_add_func("/webkit/webview/destroy", test_webkit_web_view_destroy);
- g_test_add_func("/webkit/webview/grab_focus", test_webkit_web_view_grab_focus);
- g_test_add_func("/webkit/webview/window-features", test_webkit_web_view_window_features);
- g_test_add_func("/webkit/webview/webview-in-offscreen-window-does-not-crash", test_webkit_web_view_in_offscreen_window_does_not_crash);
- g_test_add_func("/webkit/webview/webview-does-not-steal-focus", test_webkit_web_view_does_not_steal_focus);
- g_test_add_data_func("/webkit/webview/fullscreen", GINT_TO_POINTER(FALSE), test_webkit_web_view_fullscreen);
- g_test_add_data_func("/webkit/webview/fullscreen-blocked", GINT_TO_POINTER(TRUE), test_webkit_web_view_fullscreen);
- g_test_add_func("/webkit/webview/file-chooser", test_webkit_web_view_file_chooser);
- g_test_add_func("/webkit/webview/source-mode", test_webkit_web_view_source_mode);
-
- return g_test_run ();
-}
diff --git a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwindow.c b/Tools/TestWebKitAPI/Tests/WebKitGtk/testwindow.c
deleted file mode 100644
index 5eda47b12..000000000
--- a/Tools/TestWebKitAPI/Tests/WebKitGtk/testwindow.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (C) 2009 Collabora Ltd.
- *
- * 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 <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-static void notify_load_status_cb(WebKitWebView* web_view, GParamSpec* pspec, gpointer data)
-{
- if (webkit_web_view_get_load_status(web_view) == WEBKIT_LOAD_FINISHED) {
- GMainLoop* loop = (GMainLoop*)data;
-
- g_main_loop_quit(loop);
- }
-}
-
-static void test_webkit_window_scrollbar_policy(void)
-{
- GMainLoop* loop;
- GtkWidget* scrolledWindow;
- GtkWidget* webView;
- WebKitWebFrame* mainFrame;
- GtkPolicyType horizontalPolicy;
- GtkPolicyType verticalPolicy;
-
- loop = g_main_loop_new(NULL, TRUE);
-
- scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
-
- webView = webkit_web_view_new();
- g_object_ref_sink(webView);
-
- g_signal_connect(webView, "notify::load-status",
- G_CALLBACK(notify_load_status_cb), loop);
-
- gtk_container_add(GTK_CONTAINER(scrolledWindow), webView);
-
- mainFrame = webkit_web_view_get_main_frame(WEBKIT_WEB_VIEW(webView));
-
- /* Test we correctly apply policy for not having scrollbars; This
- * case is special, because we turn the policy from NEVER to
- * AUTOMATIC, since we cannot easily represent the same thing
- * using GtkScrolledWindow */
- webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(webView),
- "<html><body>WebKit!</body><script>document.getElementsByTagName('body')[0].style.overflow = 'hidden';</script></html>",
- "file://");
-
- g_main_loop_run(loop);
-
- gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
- &horizontalPolicy, &verticalPolicy);
-
- g_assert(horizontalPolicy == GTK_POLICY_AUTOMATIC);
- g_assert(verticalPolicy == GTK_POLICY_AUTOMATIC);
-
- g_assert(GTK_POLICY_NEVER == webkit_web_frame_get_horizontal_scrollbar_policy(mainFrame));
- g_assert(GTK_POLICY_NEVER == webkit_web_frame_get_vertical_scrollbar_policy(mainFrame));
-
- /* Test we correctly apply policy for always having scrollbars */
- webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(webView),
- "<html><body>WebKit!</body><script>document.getElementsByTagName('body')[0].style.overflow = 'scroll';</script></html>",
- "file://");
-
- g_main_loop_run(loop);
-
- gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
- &horizontalPolicy, &verticalPolicy);
-
- g_assert(horizontalPolicy == GTK_POLICY_ALWAYS);
- g_assert(verticalPolicy == GTK_POLICY_ALWAYS);
-
- g_assert(horizontalPolicy == webkit_web_frame_get_horizontal_scrollbar_policy(mainFrame));
- g_assert(verticalPolicy == webkit_web_frame_get_vertical_scrollbar_policy(mainFrame));
-
- /* Test we correctly apply policy for having scrollbars when needed */
- webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(webView),
- "<html><body>WebKit!</body><script>document.getElementsByTagName('body')[0].style.overflow = 'auto';</script></html>",
- "file://");
-
- g_main_loop_run(loop);
-
- gtk_scrolled_window_get_policy(GTK_SCROLLED_WINDOW(scrolledWindow),
- &horizontalPolicy, &verticalPolicy);
-
- g_assert(horizontalPolicy == GTK_POLICY_AUTOMATIC);
- g_assert(verticalPolicy == GTK_POLICY_AUTOMATIC);
-
- g_assert(horizontalPolicy == webkit_web_frame_get_horizontal_scrollbar_policy(mainFrame));
- g_assert(verticalPolicy == webkit_web_frame_get_vertical_scrollbar_policy(mainFrame));
-
- g_object_unref(webView);
-}
-
-int main(int argc, char** argv)
-{
- gtk_test_init(&argc, &argv, NULL);
-
- g_test_bug_base("https://bugs.webkit.org/");
- g_test_add_func("/webkit/window/scrollbar_policy", test_webkit_window_scrollbar_policy);
- return g_test_run ();
-}