Add some dictionary lookup tests
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Feb 2015 02:43:40 +0000 (02:43 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Feb 2015 02:43:40 +0000 (02:43 +0000)
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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@179792 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-input-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-input.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/dictionary-lookup/lookup-test.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/editing/mac/DictionaryLookup.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl

index 9b3a72c..ff0b4c1 100644 (file)
@@ -1,3 +1,24 @@
+2015-02-07  Tim Horton  <timothy_horton@apple.com>
+
+        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  <zalan@apple.com>
 
         Unreviewed gardening.
diff --git a/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-expected.txt b/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-expected.txt
new file mode 100644 (file)
index 0000000..04d4b65
--- /dev/null
@@ -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'.
diff --git a/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-input-expected.txt b/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-input-expected.txt
new file mode 100644 (file)
index 0000000..a13ff94
--- /dev/null
@@ -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'.
diff --git a/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-input.html b/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-input.html
new file mode 100644 (file)
index 0000000..e17dc92
--- /dev/null
@@ -0,0 +1,11 @@
+<html>
+<head><script type="text/javascript" src="lookup-test.js"></script></head>
+<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>
diff --git a/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection-expected.txt b/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection-expected.txt
new file mode 100644 (file)
index 0000000..903725f
--- /dev/null
@@ -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.'.
diff --git a/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection.html b/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-inside-selection.html
new file mode 100644 (file)
index 0000000..2650b8c
--- /dev/null
@@ -0,0 +1,19 @@
+<html>
+<head>
+    <script type="text/javascript" src="lookup-test.js"></script>
+    <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>
diff --git a/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection-expected.txt b/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection-expected.txt
new file mode 100644 (file)
index 0000000..7108dab
--- /dev/null
@@ -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'.
diff --git a/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection.html b/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-outside-selection.html
new file mode 100644 (file)
index 0000000..3e87664
--- /dev/null
@@ -0,0 +1,19 @@
+<html>
+<head>
+    <script type="text/javascript" src="lookup-test.js"></script>
+    <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>
diff --git a/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl-expected.txt b/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl-expected.txt
new file mode 100644 (file)
index 0000000..5800e31
--- /dev/null
@@ -0,0 +1,3 @@
+عذراً الصفحة المطلوبة غير موجودة.
+
+Lookup string for right-to-left text: 'المطلوبة'.
diff --git a/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl.html b/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup-rtl.html
new file mode 100644 (file)
index 0000000..afaec68
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<head>
+    <script type="text/javascript" src="lookup-test.js"></script>
+    <meta charset="UTF-8">
+</head>
+<body onload="runTest()">
+<div dir="RTL">عذراً الصفحة <span class="lookupInCenter" data-name="right-to-left text">المطلوبة</span> غير موجودة.</div>
+</body>
+</html>
diff --git a/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup.html b/LayoutTests/platform/mac/editing/dictionary-lookup/dictionary-lookup.html
new file mode 100644 (file)
index 0000000..d702d38
--- /dev/null
@@ -0,0 +1,11 @@
+<html>
+<head><script type="text/javascript" src="lookup-test.js"></script></head>
+<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>
diff --git a/LayoutTests/platform/mac/editing/dictionary-lookup/lookup-test.js b/LayoutTests/platform/mac/editing/dictionary-lookup/lookup-test.js
new file mode 100644 (file)
index 0000000..fb9d6c4
--- /dev/null
@@ -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
index 37fbe50..5085387 100644 (file)
@@ -1,3 +1,28 @@
+2015-02-07  Tim Horton  <timothy_horton@apple.com>
+
+        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  <cdumez@apple.com>
 
         Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda functions
index fc7da8e..19a040a 100644 (file)
@@ -2454,7 +2454,6 @@ __ZN7WebCore35contextMenuItemTagSubstitutionsMenuEv
 __ZN7WebCore36rangeForDictionaryLookupForSelectionERKNS_16VisibleSelectionEPP12NSDictionary
 __ZN7WebCore37contextMenuItemTagTransformationsMenuEv
 __ZN7WebCore38contextMenuItemTagWritingDirectionMenuEv
-__ZN7WebCore39rangeExpandedAroundPositionByCharactersERKNS_15VisiblePositionEi
 __ZN7WebCore39rangeForDictionaryLookupAtHitTestResultERKNS_13HitTestResultEPP12NSDictionary
 __ZN7WebCore42contextMenuItemTagCheckGrammarWithSpellingEv
 __ZN7WebCore42contextMenuItemTagCheckSpellingWhileTypingEv
index ea937b2..01a287d 100644 (file)
@@ -30,7 +30,7 @@
 
 #include <wtf/PassRefPtr.h>
 
-@class NSDictionary;
+OBJC_CLASS NSDictionary;
 
 namespace WebCore {
 
index 40d1def..8646e06 100644 (file)
 #include "MockMediaPlayerMediaSource.h"
 #endif
 
+#if PLATFORM(MAC)
+#include "DictionaryLookup.h"
+#endif
+
 using JSC::CodeBlock;
 using JSC::FunctionExecutable;
 using JSC::JSFunction;
@@ -1086,6 +1090,28 @@ PassRefPtr<Range> Internals::subrange(Range* range, int rangeLocation, int range
     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();
index 761d5e4..09a449d 100644 (file)
@@ -162,6 +162,7 @@ public:
     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&);
 
index c3ad203..dc2ad59 100644 (file)
@@ -124,6 +124,7 @@ enum PageOverlayType {
     [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);