From 68513a70bcd92384395513322f1b801e7bf9c729 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Wed, 29 Sep 2010 17:32:26 +0100 Subject: Merge WebKit at r67908: Initial merge by Git Change-Id: I43a553e7b3299b28cb6ee8aa035ed70fe342b972 --- WebKit/gtk/tests/testatk.c | 146 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 132 insertions(+), 14 deletions(-) (limited to 'WebKit/gtk/tests') diff --git a/WebKit/gtk/tests/testatk.c b/WebKit/gtk/tests/testatk.c index 9930bc2..9ca7c05 100644 --- a/WebKit/gtk/tests/testatk.c +++ b/WebKit/gtk/tests/testatk.c @@ -44,10 +44,12 @@ static const char* contentsInTable = "
foobar static const char* contentsInTableWithHeaders = "
foobarbaz
qux123
quux456
678
corge91011
12
34
"; -static const char* textWithAttributes = "

This is the first sentence of this text.

This sentence should have an style applied and this part should have another one.

x12=x23

This sentence is the last one.

"; - static const char* listsOfItems = "
  1. text only
  2. link only
  3. text and a link
"; +static const char* textForSelections = "

A paragraph with plain text

A paragraph with a link in the middle

"; + +static const char* textWithAttributes = "

This is the first sentence of this text.

This sentence should have an style applied and this part should have another one.

x12=x23

This sentence is the last one.

"; + static gboolean bail_out(GMainLoop* loop) { if (g_main_loop_is_running(loop)) @@ -742,6 +744,121 @@ static void testWebkitAtkTextAttributes(void) atk_attribute_set_free(set3); } +static void testWekitAtkTextSelections(void) +{ + WebKitWebView* webView; + AtkObject* obj; + GMainLoop* loop; + gchar* selectedText; + gint startOffset; + gint endOffset; + gboolean result; + + webView = WEBKIT_WEB_VIEW(webkit_web_view_new()); + g_object_ref_sink(webView); + GtkAllocation alloc = { 0, 0, 800, 600 }; + gtk_widget_size_allocate(GTK_WIDGET(webView), &alloc); + webkit_web_view_load_string(webView, textForSelections, NULL, NULL, NULL); + loop = g_main_loop_new(NULL, TRUE); + + g_timeout_add(100, (GSourceFunc)bail_out, loop); + g_main_loop_run(loop); + + obj = gtk_widget_get_accessible(GTK_WIDGET(webView)); + g_assert(obj); + + AtkText* paragraph1 = ATK_TEXT(atk_object_ref_accessible_child(obj, 0)); + g_assert(ATK_IS_TEXT(paragraph1)); + AtkText* paragraph2 = ATK_TEXT(atk_object_ref_accessible_child(obj, 1)); + g_assert(ATK_IS_TEXT(paragraph2)); + AtkText* link = ATK_TEXT(atk_object_ref_accessible_child(ATK_OBJECT(paragraph2), 0)); + g_assert(ATK_IS_TEXT(link)); + + // First paragraph (simple text) + + // Basic initial checks + g_assert_cmpint(atk_text_get_n_selections(paragraph1), ==, 0); + selectedText = atk_text_get_selection(paragraph1, 0, &startOffset, &endOffset); + g_assert_cmpint(startOffset, ==, 0); + g_assert_cmpint(endOffset, ==, 0); + g_assert_cmpstr(selectedText, ==, NULL); + g_free (selectedText); + // Try removing a non existing (yet) selection + 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); + 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, ==, NULL); + 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); + + // 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, ==, NULL); + 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, ==, NULL); + g_free (selectedText); + + g_object_unref(paragraph1); + g_object_unref(paragraph2); + g_object_unref(webView); +} + static void test_webkit_atk_get_extents(void) { WebKitWebView* webView; @@ -876,17 +993,17 @@ static void testWebkitAtkListsOfItems(void) g_assert(atk_object_get_role(uList) == ATK_ROLE_LIST); g_assert_cmpint(atk_object_get_n_accessible_children(uList), ==, 3); - item1 = ATK_TEXT(atk_object_ref_accessible_child(uList, 0)); - item2 = ATK_TEXT(atk_object_ref_accessible_child(uList, 1)); - item3 = ATK_TEXT(atk_object_ref_accessible_child(uList, 2)); + item1 = atk_object_ref_accessible_child(uList, 0); + item2 = atk_object_ref_accessible_child(uList, 1); + 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_assert_cmpstr(atk_text_get_text(item1, 0, -1), ==, "\342\200\242 text only"); - g_assert_cmpstr(atk_text_get_text(item2, 0, -1), ==, "\342\200\242 link only"); - g_assert_cmpstr(atk_text_get_text(item3, 0, -1), ==, "\342\200\242 text and a link"); + g_assert_cmpstr(atk_text_get_text(ATK_TEXT(item1), 0, -1), ==, "\342\200\242 text only"); + g_assert_cmpstr(atk_text_get_text(ATK_TEXT(item2), 0, -1), ==, "\342\200\242 link only"); + g_assert_cmpstr(atk_text_get_text(ATK_TEXT(item3), 0, -1), ==, "\342\200\242 text and a link"); g_object_unref(item1); g_object_unref(item2); @@ -899,13 +1016,13 @@ static void testWebkitAtkListsOfItems(void) g_assert(atk_object_get_role(oList) == ATK_ROLE_LIST); g_assert_cmpint(atk_object_get_n_accessible_children(oList), ==, 3); - item1 = ATK_TEXT(atk_object_ref_accessible_child(oList, 0)); - item2 = ATK_TEXT(atk_object_ref_accessible_child(oList, 1)); - item3 = ATK_TEXT(atk_object_ref_accessible_child(oList, 2)); + 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_cmpstr(atk_text_get_text(item1, 0, -1), ==, "1 text only"); - g_assert_cmpstr(atk_text_get_text(item2, 0, -1), ==, "2 link only"); - g_assert_cmpstr(atk_text_get_text(item3, 0, -1), ==, "3 text and a link"); + g_assert_cmpstr(atk_text_get_text(ATK_TEXT(item1), 0, -1), ==, "1 text only"); + g_assert_cmpstr(atk_text_get_text(ATK_TEXT(item2), 0, -1), ==, "2 link only"); + g_assert_cmpstr(atk_text_get_text(ATK_TEXT(item3), 0, -1), ==, "3 text and a link"); g_assert_cmpint(atk_object_get_n_accessible_children(item1), ==, 0); g_assert_cmpint(atk_object_get_n_accessible_children(item2), ==, 1); @@ -936,6 +1053,7 @@ int main(int argc, char** argv) g_test_add_func("/webkit/atk/getTextInTable", testWebkitAtkGetTextInTable); g_test_add_func("/webkit/atk/getHeadersInTable", testWebkitAtkGetHeadersInTable); g_test_add_func("/webkit/atk/textAttributes", testWebkitAtkTextAttributes); + g_test_add_func("/webkit/atk/textSelections", testWekitAtkTextSelections); g_test_add_func("/webkit/atk/get_extents", test_webkit_atk_get_extents); g_test_add_func("/webkit/atk/listsOfItems", testWebkitAtkListsOfItems); return g_test_run (); -- cgit v1.1