Title: [179792] trunk
Revision
179792
Author
[email protected]
Date
2015-02-07 18:43:40 -0800 (Sat, 07 Feb 2015)

Log Message

Add some dictionary lookup tests
https://bugs.webkit.org/show_bug.cgi?id=141355

Reviewed by Darin Adler.

Tests: platform/mac/editing/dictionary-lookup/dictionary-lookup-input.html
       platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection.html
       platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection.html
       platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl.html
       platform/mac/editing/dictionary-lookup/dictionary-lookup.html

* WebCore.exp.in:
Remove an unneeded export.

* editing/mac/DictionaryLookup.h:
Use OBJC_CLASS instead of @class so that this can be included in pure-C++ files.

* testing/Internals.cpp:
(WebCore::Internals::rangeForDictionaryLookupAtLocation):
* testing/Internals.h:
* testing/Internals.idl:
Expose rangeForDictionaryLookupAtHitTestResult fairly directly to _javascript_.

* platform/mac/editing/dictionary-lookup/dictionary-lookup-expected.txt: Added.
* platform/mac/editing/dictionary-lookup/dictionary-lookup-input-expected.txt: Added.
* platform/mac/editing/dictionary-lookup/dictionary-lookup-input.html: Added.
* platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection-expected.txt: Added.
* platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection.html: Added.
* platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection-expected.txt: Added.
* platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection.html: Added.
* platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl-expected.txt: Added.
* platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl.html: Added.
* platform/mac/editing/dictionary-lookup/dictionary-lookup.html: Added.
* platform/mac/editing/dictionary-lookup/lookup-test.js: Added.
(runTest):
Add tests for various cases that we've had trouble with in the past.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (179791 => 179792)


--- trunk/LayoutTests/ChangeLog	2015-02-08 02:28:48 UTC (rev 179791)
+++ trunk/LayoutTests/ChangeLog	2015-02-08 02:43:40 UTC (rev 179792)
@@ -1,3 +1,24 @@
+2015-02-07  Tim Horton  <[email protected]>
+
+        Add some dictionary lookup tests
+        https://bugs.webkit.org/show_bug.cgi?id=141355
+
+        Reviewed by Darin Adler.
+
+        * platform/mac/editing/dictionary-lookup/dictionary-lookup-expected.txt: Added.
+        * platform/mac/editing/dictionary-lookup/dictionary-lookup-input-expected.txt: Added.
+        * platform/mac/editing/dictionary-lookup/dictionary-lookup-input.html: Added.
+        * platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection-expected.txt: Added.
+        * platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection.html: Added.
+        * platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection-expected.txt: Added.
+        * platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection.html: Added.
+        * platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl-expected.txt: Added.
+        * platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl.html: Added.
+        * platform/mac/editing/dictionary-lookup/dictionary-lookup.html: Added.
+        * platform/mac/editing/dictionary-lookup/lookup-test.js: Added.
+        (runTest):
+        Add tests for various cases that we've had trouble with in the past.
+
 2015-02-07  Zalan Bujtas  <[email protected]>
 
         Unreviewed gardening.

Added: trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-expected.txt (0 => 179792)


--- trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-expected.txt	2015-02-08 02:43:40 UTC (rev 179792)
@@ -0,0 +1,7 @@
+Some text to look up.
+I love New York.
+Some text to look up.
+
+Lookup string for normal text: 'look'.
+Lookup string for title-case phrase: 'New York'.
+Lookup string for unselectable text: 'null'.

Added: trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-input-expected.txt (0 => 179792)


--- trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-input-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-input-expected.txt	2015-02-08 02:43:40 UTC (rev 179792)
@@ -0,0 +1,7 @@
+
+
+Some text to look up.
+
+Lookup string for input type=text field: 'withaverylongwordinthemiddle'.
+Lookup string for password field: 'null'.
+Lookup string for contentEditable div: 'look'.

Added: trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-input.html (0 => 179792)


--- trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-input.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-input.html	2015-02-08 02:43:40 UTC (rev 179792)
@@ -0,0 +1,11 @@
+<html>
+<head><script type="text/_javascript_" src=""
+<body _onload_="runTest()">
+<!-- Text input fields should be available to look up as usual. -->
+<input type="text" class="lookupInCenter" data-name="input type=text field" value="Text withaverylongwordinthemiddle to hit."></input><br/>
+<!-- Password fields should not be available to look up. -->
+<input type="password" class="lookupInCenter" data-name="password field" value="some very long password string"></input><br/>
+<!-- contentEditable areas should be available to look up as usual. -->
+<div contenteditable>Some text to <span class="lookupInCenter" data-name="contentEditable div">look</span> up.</div>
+</body>
+</html>

Added: trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection-expected.txt (0 => 179792)


--- trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection-expected.txt	2015-02-08 02:43:40 UTC (rev 179792)
@@ -0,0 +1,3 @@
+Some text to not look up. This part is all selected, and should be taken as a unit when looked up.
+
+Lookup string for inside selected text: 'This part is all selected, and should be taken as a unit when looked up.'.

Added: trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection.html (0 => 179792)


--- trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection.html	2015-02-08 02:43:40 UTC (rev 179792)
@@ -0,0 +1,19 @@
+<html>
+<head>
+    <script type="text/_javascript_" src=""
+    <script>
+window._onload_ = function () {
+    var selection = window.getSelection();
+    var range = document.createRange();
+    range.selectNode(document.getElementById("select"));
+    selection.addRange(range);
+
+    runTest();
+}
+    </script>
+</head>
+<body>
+<!-- The hit word is inside the selection, so the whole selection should be looked up. -->
+<div>Some text to not look up. <span id="select">This part is all selected, and should be taken as a <span class="lookupInCenter" data-name="inside selected text">unit</span> when looked up.</span></div>
+</body>
+</html>

Added: trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection-expected.txt (0 => 179792)


--- trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection-expected.txt	2015-02-08 02:43:40 UTC (rev 179792)
@@ -0,0 +1,3 @@
+Some text to look up. This part is all selected, but the hit word is elsewhere so that doesn't matter.
+
+Lookup string for outside selected text: 'text'.

Added: trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection.html (0 => 179792)


--- trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection.html	2015-02-08 02:43:40 UTC (rev 179792)
@@ -0,0 +1,19 @@
+<html>
+<head>
+    <script type="text/_javascript_" src=""
+    <script>
+window._onload_ = function () {
+    var selection = window.getSelection();
+    var range = document.createRange();
+    range.selectNode(document.getElementById("select"));
+    selection.addRange(range);
+
+    runTest();
+}
+    </script>
+</head>
+<body>
+<!-- The hit word is outside the selection, so the selection should be ignored. -->
+<div>Some <span class="lookupInCenter" data-name="outside selected text">text</span> to look up. <span id="select">This part is all selected, but the hit word is elsewhere so that doesn't matter.</span></div>
+</body>
+</html>

Added: trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl-expected.txt (0 => 179792)


--- trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl-expected.txt	2015-02-08 02:43:40 UTC (rev 179792)
@@ -0,0 +1,3 @@
+عذراً الصفحة المطلوبة غير موجودة.
+
+Lookup string for right-to-left text: 'المطلوبة'.

Added: trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl.html (0 => 179792)


--- trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl.html	2015-02-08 02:43:40 UTC (rev 179792)
@@ -0,0 +1,9 @@
+<html>
+<head>
+    <script type="text/_javascript_" src=""
+    <meta charset="UTF-8">
+</head>
+<body _onload_="runTest()">
+<div dir="RTL">عذراً الصفحة <span class="lookupInCenter" data-name="right-to-left text">المطلوبة</span> غير موجودة.</div>
+</body>
+</html>

Added: trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup.html (0 => 179792)


--- trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup.html	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup.html	2015-02-08 02:43:40 UTC (rev 179792)
@@ -0,0 +1,11 @@
+<html>
+<head><script type="text/_javascript_" src=""
+<body _onload_="runTest()">
+<!-- Plain text should be available to look up. -->
+<div>Some text to <span class="lookupInCenter" data-name="normal text">look</span> up.</div>
+<!-- Title-case phrases should be looked up as a unit. -->
+<div>I love <span class="lookupInCenter" data-name="title-case phrase">New</span> York.</div>
+<!-- Unselectable text should not be looked up. -->
+<div style="-webkit-user-select: none;">Some text to <span class="lookupInCenter" data-name="unselectable text">look</span> up.</div>
+</body>
+</html>

Added: trunk/LayoutTests/platform/mac/editing/dictionary-lookup/lookup-test.js (0 => 179792)


--- trunk/LayoutTests/platform/mac/editing/dictionary-lookup/lookup-test.js	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/editing/dictionary-lookup/lookup-test.js	2015-02-08 02:43:40 UTC (rev 179792)
@@ -0,0 +1,26 @@
+function runTest() {
+    if (!window.testRunner || !internals) {
+        document.body.innerHTML += "<br/>ERROR: This test cannot be run interactively.";
+        return;
+    }
+
+    testRunner.dumpAsText();
+
+    var targets = document.getElementsByClassName("lookupInCenter");
+    Array.prototype.forEach.call(targets, function(target) {
+        var spanRects = target.getClientRects();
+
+        if (spanRects.count > 1) {
+            document.body.innerHTML += "<br/>ERROR: More than one rect for hit word."
+            return;
+        }
+
+        var rect = spanRects[0];
+        var x = rect.left + rect.width / 2;
+        var y = rect.top + rect.height / 2;
+
+        var lookupRange = internals.rangeForDictionaryLookupAtLocation(x, y);
+        
+        document.body.innerHTML += "<br/>Lookup string for " + target.dataset["name"] + ": '" + lookupRange + "'.";
+    });
+}
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (179791 => 179792)


--- trunk/Source/WebCore/ChangeLog	2015-02-08 02:28:48 UTC (rev 179791)
+++ trunk/Source/WebCore/ChangeLog	2015-02-08 02:43:40 UTC (rev 179792)
@@ -1,3 +1,28 @@
+2015-02-07  Tim Horton  <[email protected]>
+
+        Add some dictionary lookup tests
+        https://bugs.webkit.org/show_bug.cgi?id=141355
+
+        Reviewed by Darin Adler.
+
+        Tests: platform/mac/editing/dictionary-lookup/dictionary-lookup-input.html
+               platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection.html
+               platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection.html
+               platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl.html
+               platform/mac/editing/dictionary-lookup/dictionary-lookup.html
+
+        * WebCore.exp.in:
+        Remove an unneeded export.
+
+        * editing/mac/DictionaryLookup.h:
+        Use OBJC_CLASS instead of @class so that this can be included in pure-C++ files.
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::rangeForDictionaryLookupAtLocation):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+        Expose rangeForDictionaryLookupAtHitTestResult fairly directly to _javascript_.
+
 2015-02-07  Chris Dumez  <[email protected]>
 
         Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda functions

Modified: trunk/Source/WebCore/WebCore.exp.in (179791 => 179792)


--- trunk/Source/WebCore/WebCore.exp.in	2015-02-08 02:28:48 UTC (rev 179791)
+++ trunk/Source/WebCore/WebCore.exp.in	2015-02-08 02:43:40 UTC (rev 179792)
@@ -2454,7 +2454,6 @@
 __ZN7WebCore36rangeForDictionaryLookupForSelectionERKNS_16VisibleSelectionEPP12NSDictionary
 __ZN7WebCore37contextMenuItemTagTransformationsMenuEv
 __ZN7WebCore38contextMenuItemTagWritingDirectionMenuEv
-__ZN7WebCore39rangeExpandedAroundPositionByCharactersERKNS_15VisiblePositionEi
 __ZN7WebCore39rangeForDictionaryLookupAtHitTestResultERKNS_13HitTestResultEPP12NSDictionary
 __ZN7WebCore42contextMenuItemTagCheckGrammarWithSpellingEv
 __ZN7WebCore42contextMenuItemTagCheckSpellingWhileTypingEv

Modified: trunk/Source/WebCore/editing/mac/DictionaryLookup.h (179791 => 179792)


--- trunk/Source/WebCore/editing/mac/DictionaryLookup.h	2015-02-08 02:28:48 UTC (rev 179791)
+++ trunk/Source/WebCore/editing/mac/DictionaryLookup.h	2015-02-08 02:43:40 UTC (rev 179792)
@@ -30,7 +30,7 @@
 
 #include <wtf/PassRefPtr.h>
 
-@class NSDictionary;
+OBJC_CLASS NSDictionary;
 
 namespace WebCore {
 

Modified: trunk/Source/WebCore/testing/Internals.cpp (179791 => 179792)


--- trunk/Source/WebCore/testing/Internals.cpp	2015-02-08 02:28:48 UTC (rev 179791)
+++ trunk/Source/WebCore/testing/Internals.cpp	2015-02-08 02:43:40 UTC (rev 179792)
@@ -166,6 +166,10 @@
 #include "MockMediaPlayerMediaSource.h"
 #endif
 
+#if PLATFORM(MAC)
+#include "DictionaryLookup.h"
+#endif
+
 using JSC::CodeBlock;
 using JSC::FunctionExecutable;
 using JSC::JSFunction;
@@ -1086,6 +1090,28 @@
     return TextIterator::subrange(range, rangeLocation, rangeLength);
 }
 
+RefPtr<Range> Internals::rangeForDictionaryLookupAtLocation(int x, int y, ExceptionCode& ec)
+{
+#if PLATFORM(MAC)
+    Document* document = contextDocument();
+    if (!document || !document->frame()) {
+        ec = INVALID_ACCESS_ERR;
+        return nullptr;
+    }
+
+    document->updateLayoutIgnorePendingStylesheets();
+    
+    HitTestResult result = document->frame()->mainFrame().eventHandler().hitTestResultAtPoint(IntPoint(x, y));
+    NSDictionary *options = nullptr;
+    return rangeForDictionaryLookupAtHitTestResult(result, &options);
+#else
+    UNUSED_PARAM(x);
+    UNUSED_PARAM(y);
+    ec = INVALID_ACCESS_ERR;
+    return nullptr;
+#endif
+}
+
 void Internals::setDelegatesScrolling(bool enabled, ExceptionCode& ec)
 {
     Document* document = contextDocument();

Modified: trunk/Source/WebCore/testing/Internals.h (179791 => 179792)


--- trunk/Source/WebCore/testing/Internals.h	2015-02-08 02:28:48 UTC (rev 179791)
+++ trunk/Source/WebCore/testing/Internals.h	2015-02-08 02:43:40 UTC (rev 179792)
@@ -162,6 +162,7 @@
     unsigned lengthFromRange(Element* scope, const Range*, ExceptionCode&);
     String rangeAsText(const Range*, ExceptionCode&);
     PassRefPtr<Range> subrange(Range* range, int rangeLocation, int rangeLength, ExceptionCode&);
+    RefPtr<Range> rangeForDictionaryLookupAtLocation(int x, int y, ExceptionCode&);
 
     void setDelegatesScrolling(bool enabled, ExceptionCode&);
 

Modified: trunk/Source/WebCore/testing/Internals.idl (179791 => 179792)


--- trunk/Source/WebCore/testing/Internals.idl	2015-02-08 02:28:48 UTC (rev 179791)
+++ trunk/Source/WebCore/testing/Internals.idl	2015-02-08 02:43:40 UTC (rev 179792)
@@ -124,6 +124,7 @@
     [RaisesException] unsigned long lengthFromRange(Element scope, Range range);
     [RaisesException] DOMString rangeAsText(Range range);
     [RaisesException] Range subrange(Range range, long rangeLocation, long rangeLength);
+    [RaisesException] Range rangeForDictionaryLookupAtLocation(long x, long y);
 
     [RaisesException] void setDelegatesScrolling(boolean enabled);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to