Modified: trunk/Source/WebKit2/ChangeLog (152152 => 152153)
--- trunk/Source/WebKit2/ChangeLog 2013-06-28 05:47:19 UTC (rev 152152)
+++ trunk/Source/WebKit2/ChangeLog 2013-06-28 07:34:43 UTC (rev 152153)
@@ -1,3 +1,22 @@
+2013-06-28 Dariusz Frankiewicz <[email protected]>
+
+ [EFL][WK2] Add spellcheck API tests in unit tests.
+ https://bugs.webkit.org/show_bug.cgi?id=118123
+
+ Reviewed by Christophe Dumez.
+
+ According to discussion in bug https://bugs.webkit.org/show_bug.cgi?id=113742
+ we're moving spelling tests from layout tests to unit tests.
+
+ * UIProcess/API/efl/tests/resources/spelling_selection_tests.html: Added.
+ New file is needed to make tests, with and without spellcheck attribute.
+ File contains basic site with content editable fields and buttons which select
+ different parts of misspelled words.
+
+ * UIProcess/API/efl/tests/test_ewk2_text_checker.cpp:
+ (countContextMenuItems):
+ Added method used to count number of items in context menu.
+
2013-06-27 Kangil Han <[email protected]>
Adopt is/toHTMLInputElement for code cleanup
Added: trunk/Source/WebKit2/UIProcess/API/efl/tests/resources/spelling_selection_tests.html (0 => 152153)
--- trunk/Source/WebKit2/UIProcess/API/efl/tests/resources/spelling_selection_tests.html (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/resources/spelling_selection_tests.html 2013-06-28 07:34:43 UTC (rev 152153)
@@ -0,0 +1,46 @@
+<!--
+ The page contains elements used to check context menu spelling suggestions.
+ There are also available functions which select specific part of misspelled word/sentence.
+-->
+<html>
+<head>
+ <title>Testing selection for Spelling</title>
+ <script>
+ // Select all text inside element.
+ function selectText(element)
+ {
+ var text = document.getElementById(element);
+ var selection = window.getSelection();
+ var range = document.createRange();
+ range.selectNodeContents(text);
+ selection.removeAllRanges();
+ selection.addRange(range);
+ }
+
+ // Select part of text inside element.
+ function selectSubText(element)
+ {
+ var text = document.getElementById(element);
+ var startNode = text.firstChild;
+ var endNode = text.firstChild;
+ var range = document.createRange();
+ range.setStart(startNode, 2);
+ range.setEnd(endNode, 6);
+ // Select "llco" from Wellcome word.
+ var selection = window.getSelection();
+ selection.removeAllRanges();
+ selection.addRange(range);
+ }
+ </script>
+</head>
+
+<body>
+ <!-- element used to count context menu items, without spellcheck suggestions -->
+ <div contenteditable="true" id="elementWithoutSpellcheck" spellcheck="false">Wellcome home</div>
+ <div contenteditable="true" id="elementWithSpellcheck" spellcheck="true">Wellcome home</div>
+
+ <button _onclick_="selectText('elementWithSpellcheck')">Select all words</button>
+ <button _onclick_="selectSubText('elementWithSpellcheck')">Select sub word</button>
+ <button _onclick_="selectText('elementWithoutSpellcheck')">Select all words in field without spellcheck</button>
+</body>
+</html>
Modified: trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_text_checker.cpp (152152 => 152153)
--- trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_text_checker.cpp 2013-06-28 05:47:19 UTC (rev 152152)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_text_checker.cpp 2013-06-28 07:34:43 UTC (rev 152153)
@@ -51,6 +51,7 @@
static const char learnSpellingString[] = "Learn Spelling";
static const char* clientSuggestionsForWord[] = { "clientSuggestion1", "clientSuggestion2", "clientSuggestion3" };
+static unsigned contextMenuItemsNumber = 0;
/**
* Structure keeps information which callbacks were called.
@@ -305,6 +306,127 @@
}
/**
+ * Count number of elements in context menu.
+ */
+static Eina_Bool countContextMenuItems(Ewk_View_Smart_Data*, Evas_Coord, Evas_Coord, Ewk_Context_Menu* contextMenu)
+{
+ contextMenuItemsNumber = eina_list_count(ewk_context_menu_items_get(contextMenu));
+ wasContextMenuShown = true;
+ return true;
+}
+
+/**
+ * Test whether there are spelling suggestions when misspelled word is directly context clicked.
+ */
+TEST_F(EWK2UnitTestBase, spelling_suggestion_for_context_click)
+{
+ wasContextMenuShown = false;
+
+ // Checking number of context menu items when element has no spellcheck suggestions.
+ ewkViewClass()->context_menu_show = countContextMenuItems;
+ ASSERT_TRUE(loadUrlSync(environment->urlForResource("spelling_selection_tests.html").data()));
+ mouseClick(10, 20, 3 /* Right button - invoke context menu */);
+
+ ASSERT_TRUE(waitUntilTrue(wasContextMenuShown));
+ unsigned numberItemsWithoutSpellCheck = contextMenuItemsNumber;
+
+ wasContextMenuShown = false;
+
+ // Testing how many items are in context menu when spellcheck is enabled.
+ ASSERT_TRUE(loadUrlSync(environment->urlForResource("spelling_selection_tests.html").data()));
+ mouseClick(35, 35, 3 /* Right button - invoke context menu */);
+
+ ASSERT_TRUE(waitUntilTrue(wasContextMenuShown));
+
+ EXPECT_LT(numberItemsWithoutSpellCheck, contextMenuItemsNumber);
+}
+
+/**
+ * Test whether there are no spelling suggestions when multiple words are selected (that are not a single misspelling).
+ */
+TEST_F(EWK2UnitTestBase, no_spelling_suggestion_for_multiword_selection)
+{
+ wasContextMenuShown = false;
+
+ // Checking number of context menu items when element has no spellcheck suggestions.
+ ewkViewClass()->context_menu_show = countContextMenuItems;
+ ASSERT_TRUE(loadUrlSync(environment->urlForResource("spelling_selection_tests.html").data()));
+ mouseClick(500, 60, 1 /* Left button - select all words in field without spellcheck */);
+ mouseClick(10, 20, 3 /* Right button - invoke context menu */);
+
+ ASSERT_TRUE(waitUntilTrue(wasContextMenuShown));
+ unsigned numberItemsWithoutSpellCheck = contextMenuItemsNumber;
+
+ wasContextMenuShown = false;
+
+ // Testing how many items are in context menu when multiple words are selected.
+ ASSERT_TRUE(loadUrlSync(environment->urlForResource("spelling_selection_tests.html").data()));
+ mouseClick(60, 60, 1 /* Left button - select all words in field with spellcheck */);
+ mouseClick(35, 35, 3 /* Right button - invoke context menu */);
+
+ ASSERT_TRUE(waitUntilTrue(wasContextMenuShown));
+
+ EXPECT_EQ(numberItemsWithoutSpellCheck, contextMenuItemsNumber);
+}
+
+/**
+ * Test whether there are no spelling suggestions when part of misspelled word are selected.
+ */
+TEST_F(EWK2UnitTestBase, no_spelling_suggestion_for_subword_selection)
+{
+ wasContextMenuShown = false;
+
+ // Checking number of context menu items when element has no spellcheck suggestions.
+ ewkViewClass()->context_menu_show = countContextMenuItems;
+ ASSERT_TRUE(loadUrlSync(environment->urlForResource("spelling_selection_tests.html").data()));
+ mouseClick(500, 60, 1 /* Left button - select all words in field without spellcheck */);
+ mouseClick(10, 20, 3 /* Right button - invoke context menu */);
+
+ ASSERT_TRUE(waitUntilTrue(wasContextMenuShown));
+ unsigned numberItemsWithoutSpellCheck = contextMenuItemsNumber;
+
+ wasContextMenuShown = false;
+
+ // Testing how many items are in context menu when part of word is selected.
+ ASSERT_TRUE(loadUrlSync(environment->urlForResource("spelling_selection_tests.html").data()));
+ mouseClick(200, 60, 1 /* Left button - select part of word in field with spellcheck */);
+ mouseClick(35, 35, 3 /* Right button - invoke context menu */);
+
+ ASSERT_TRUE(waitUntilTrue(wasContextMenuShown));
+
+ EXPECT_EQ(numberItemsWithoutSpellCheck, contextMenuItemsNumber);
+}
+
+/**
+ * Test whether context menu spelling items are available when misspelled word has selection as the double click.
+ */
+TEST_F(EWK2UnitTestBase, spelling_suggestion_for_double_clicked_word)
+{
+ wasContextMenuShown = false;
+
+ // Checking number of context menu items when element has no spell check suggestions.
+ ewkViewClass()->context_menu_show = countContextMenuItems;
+ ASSERT_TRUE(loadUrlSync(environment->urlForResource("spelling_selection_tests.html").data()));
+ mouseClick(500, 60, 1 /* Left button - select all words in field without spellcheck */);
+ mouseClick(10, 20, 3 /* Right button - invoke context menu */);
+
+ ASSERT_TRUE(waitUntilTrue(wasContextMenuShown));
+ unsigned numberItemsWithoutSpellCheck = contextMenuItemsNumber;
+
+ wasContextMenuShown = false;
+
+ // Making double click on misspelled word to select it, and checking are there context menu spell check suggestions.
+ ASSERT_TRUE(loadUrlSync(environment->urlForResource("spelling_selection_tests.html").data()));
+ mouseClick(35, 35, 1 /* Left button - 1st click of doubleclick */);
+ mouseClick(35, 35, 1 /* Left button - 2nd click of doubleclick */);
+ mouseClick(35, 35, 3 /* Right button - invoke context menu */);
+
+ ASSERT_TRUE(waitUntilTrue(wasContextMenuShown));
+
+ EXPECT_LT(numberItemsWithoutSpellCheck, contextMenuItemsNumber);
+}
+
+/**
* Test whether the default language is loaded independently of
* continuous spell checking setting.
*/