summaryrefslogtreecommitdiffstats
path: root/WebKit/gtk/tests
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/gtk/tests')
-rw-r--r--WebKit/gtk/tests/testatk.c146
1 files changed, 132 insertions, 14 deletions
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 = "<html><body><table><tr><td>foo</td><td>bar
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* 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 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* 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></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 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 ();