diff options
| author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-09 14:16:12 +0100 |
|---|---|---|
| committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-09 14:16:12 +0100 |
| commit | 03e12282df9aa1e1fb05a8b90f1cfc2e08764cec (patch) | |
| tree | 52599cd0ab782b1768e23ad176f7618f98333cb6 /Source/WebKit/gtk/tests | |
| parent | cd44dc59cdfc39534aef4d417e9f3c412e3be139 (diff) | |
| download | qtwebkit-03e12282df9aa1e1fb05a8b90f1cfc2e08764cec.tar.gz | |
Imported WebKit commit e09a82039aa4273ab318b71122e92d8e5f233525 (http://svn.webkit.org/repository/webkit/trunk@107223)
Diffstat (limited to 'Source/WebKit/gtk/tests')
| -rw-r--r-- | Source/WebKit/gtk/tests/test_utils.c | 4 | ||||
| -rw-r--r-- | Source/WebKit/gtk/tests/testatk.c | 39 | ||||
| -rw-r--r-- | Source/WebKit/gtk/tests/testwebinspector.c | 177 |
3 files changed, 208 insertions, 12 deletions
diff --git a/Source/WebKit/gtk/tests/test_utils.c b/Source/WebKit/gtk/tests/test_utils.c index 360a15b2a..6bb645d0d 100644 --- a/Source/WebKit/gtk/tests/test_utils.c +++ b/Source/WebKit/gtk/tests/test_utils.c @@ -29,10 +29,8 @@ int testutils_relative_chdir(const gchar *targetFilename, const gchar *executabl if (repoPath) { if (g_chdir(repoPath)) return -1; - } else if (g_path_is_absolute(executablePath)) { - if (g_chdir(g_path_get_dirname(executablePath))) + } else if (g_chdir(g_path_get_dirname(executablePath))) return -1; - } while (!g_file_test(targetFilename, G_FILE_TEST_EXISTS)) { gchar *pathName; diff --git a/Source/WebKit/gtk/tests/testatk.c b/Source/WebKit/gtk/tests/testatk.c index a79010175..60c27942b 100644 --- a/Source/WebKit/gtk/tests/testatk.c +++ b/Source/WebKit/gtk/tests/testatk.c @@ -35,7 +35,7 @@ static const char* contentsWithNewlines = "<html><body><p>This is a test. \n\nTh static const char* contentsWithPreformattedText = "<html><body><pre>\n\t\n\tfirst line\n\tsecond line\n</pre></body></html>"; -static const char* contentsWithSpecialChars = "<html><body><p>« This is a paragraph with “special” characters inside. »</p></body></html>"; +static const char* contentsWithSpecialChars = "<html><body><p>« This is a paragraph with “special” characters inside. »</p><ul><li style='max-width:100px;'>List item with some text that wraps across different lines.</li></ul></body></html>"; static const char* contentsInTextarea = "<html><body><textarea cols='80'>This is a test. This is the second sentence. And this the third.</textarea></body></html>"; @@ -810,23 +810,44 @@ static void testWebkitAtkGetTextAtOffsetWithSpecialCharacters() /* 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)); + AtkObject* paragraph = atk_object_ref_accessible_child(object, 0); + g_assert(ATK_IS_TEXT(paragraph)); - const gchar* expectedText = "\302\253\302\240This is a paragraph with \342\200\234special\342\200\235 characters inside.\302\240\302\273"; - char* text = atk_text_get_text(textObject, 0, -1); + gchar* expectedText = g_strdup("\302\253\302\240This is a paragraph with \342\200\234special\342\200\235 characters inside.\302\240\302\273"); + char* text = atk_text_get_text(ATK_TEXT(paragraph), 0, -1); g_assert_cmpstr(text, ==, expectedText); g_free(text); /* Check that getting the text with ATK_TEXT_BOUNDARY_LINE_START and ATK_TEXT_BOUNDARY_LINE_END does not crash because of not properly handling characters inside the UTF-8 string. */ - testGetTextFunction(textObject, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_START, 0, expectedText, 0, 57); - testGetTextFunction(textObject, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END, 0, expectedText, 0, 57); + testGetTextFunction(ATK_TEXT(paragraph), atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_START, 0, expectedText, 0, 57); + testGetTextFunction(ATK_TEXT(paragraph), atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END, 0, expectedText, 0, 57); + g_free(expectedText); + + AtkObject* list = atk_object_ref_accessible_child(object, 1); + g_assert(ATK_OBJECT(list)); + + AtkText* listItem = ATK_TEXT(atk_object_ref_accessible_child(list, 0)); + g_assert(ATK_IS_TEXT(listItem)); + + text = atk_text_get_text(ATK_TEXT(listItem), 0, -1); + g_assert_cmpstr(text, ==, "\342\200\242 List item with some text that wraps across different lines."); + g_free(text); + /* Check that getting the text with ATK_TEXT_BOUNDARY_LINE_START + and ATK_TEXT_BOUNDARY_LINE_END for line items with bullets + (special character) and wrapped text always return the right + piece of text for each line. */ + testGetTextFunction(ATK_TEXT(listItem), atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_START, 3, "\342\200\242 List item ", 0, 12); + testGetTextFunction(ATK_TEXT(listItem), atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_START, 13, "with some ", 12, 22); + testGetTextFunction(ATK_TEXT(listItem), atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END, 0, "\342\200\242 List item", 0, 11); + testGetTextFunction(ATK_TEXT(listItem), atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END, 12, " with some", 11, 21); + + g_object_unref(list); + g_object_unref(listItem); + g_object_unref(paragraph); g_object_unref(webView); } diff --git a/Source/WebKit/gtk/tests/testwebinspector.c b/Source/WebKit/gtk/tests/testwebinspector.c new file mode 100644 index 000000000..40aa55334 --- /dev/null +++ b/Source/WebKit/gtk/tests/testwebinspector.c @@ -0,0 +1,177 @@ +/* + * 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 "test_utils.h" + +#include <string.h> +#include <glib.h> +#include <gtk/gtk.h> +#include <webkit/webkit.h> + +#if GTK_CHECK_VERSION(2, 14, 0) + +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'")) + 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 test_webkit_web_inspector_close_and_inspect() +{ + WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + + WebKitWebSettings *settings = webkit_web_view_get_settings(webView); + g_object_set(settings, "enable-developer-extras", TRUE, NULL); + + webkit_web_view_load_string (webView, + "<html><body><p>woohoo</p></body></html>", + "text/html", "UTF-8", "file://"); + + 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), ×ElementInspected, + "signal::show-window", G_CALLBACK(showInspector), NULL, + "signal::close-window", G_CALLBACK(closeInspector), ×Closed, + NULL); + + webkit_web_inspector_inspect_coordinates(inspector, 0.0, 0.0); + g_assert_cmpint(timesElementInspected, ==, 1); + + loop = g_main_loop_new(NULL, TRUE); + 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()); + + WebKitWebSettings *settings = webkit_web_view_get_settings(webView); + g_object_set(settings, "enable-developer-extras", TRUE, NULL); + + webkit_web_view_load_string (webView, + "<html><body><p>woohoo</p></body></html>", + "text/html", "UTF-8", "file://"); + + 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), ×ElementInspected, + "signal::show-window", G_CALLBACK(showInspector), NULL, + "signal::close-window", G_CALLBACK(closeInspector), ×Closed, + NULL); + + webkit_web_inspector_inspect_coordinates(inspector, 0.0, 0.0); + g_assert_cmpint(timesElementInspected, ==, 1); + + loop = g_main_loop_new(NULL, TRUE); + 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); + + testutils_relative_chdir("Programs/resources/inspector/inspector.html", argv[0]); + + char *currentDir = g_get_current_dir(); + g_setenv("WEBKIT_INSPECTOR_PATH", currentDir, TRUE); + g_free(currentDir); + + 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 (); +} + +#else +int main(int argc, char** argv) +{ + g_critical("You will need gtk-2.14.0 to run the unit tests. Doing nothing now."); + return 0; +} + +#endif |
