Internals should have a method to reutrn the max sequence number of spellcheck reqeust.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Dec 2011 12:34:02 +0000 (12:34 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 7 Dec 2011 12:34:02 +0000 (12:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=73511

Patch by Shinya Kawanaka <shinyak@google.com> on 2011-12-07
Reviewed by Hajime Morita.

Source/WebCore:

Internal state of SpellChecker should be able to be exposed for testing SpellChecker.
This patch will enable us to know asynchronous spellcheck has finished or not.

Test: editing/spelling/spellcheck-sequencenum.html

* editing/SpellChecker.cpp:
(WebCore::SpellChecker::SpellChecker):
(WebCore::SpellChecker::createRequest):
(WebCore::SpellChecker::didCheck):
* editing/SpellChecker.h:
(WebCore::SpellChecker::lastRequestSequence):
  Interface to take SpellCheck sequence numbers.
(WebCore::SpellChecker::lastProcessedSequence): ditto.
* testing/Internals.cpp:
(WebCore::spellchecker):
(WebCore::Internals::lastSpellCheckRequestSequence):
(WebCore::Internals::lastSpellCheckProcessedSequence):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

Added tests to check internals.lastSpellCheckRequestSequence and internals.lastSpellCheckProcessedSequence.

* editing/spelling/spellcheck-sequencenum-expected.txt: Added.
* editing/spelling/spellcheck-sequencenum.html: Added.
* platform/gtk/Skipped:
* platform/qt/Skipped:

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

LayoutTests/ChangeLog
LayoutTests/editing/spelling/spellcheck-sequencenum-expected.txt [new file with mode: 0644]
LayoutTests/editing/spelling/spellcheck-sequencenum.html [new file with mode: 0644]
LayoutTests/platform/gtk/Skipped
LayoutTests/platform/qt/Skipped
Source/WebCore/ChangeLog
Source/WebCore/editing/SpellChecker.cpp
Source/WebCore/editing/SpellChecker.h
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl

index 8d45fd6..2588b0f 100644 (file)
@@ -1,3 +1,17 @@
+2011-12-07  Shinya Kawanaka  <shinyak@google.com>
+
+        Internals should have a method to reutrn the max sequence number of spellcheck reqeust.
+        https://bugs.webkit.org/show_bug.cgi?id=73511
+
+        Reviewed by Hajime Morita.
+
+        Added tests to check internals.lastSpellCheckRequestSequence and internals.lastSpellCheckProcessedSequence.
+
+        * editing/spelling/spellcheck-sequencenum-expected.txt: Added.
+        * editing/spelling/spellcheck-sequencenum.html: Added.
+        * platform/gtk/Skipped:
+        * platform/qt/Skipped:
+
 2011-12-07  Vsevolod Vlasov  <vsevik@chromium.org>
 
         Unreviewed chromium test expectations update.
diff --git a/LayoutTests/editing/spelling/spellcheck-sequencenum-expected.txt b/LayoutTests/editing/spelling/spellcheck-sequencenum-expected.txt
new file mode 100644 (file)
index 0000000..dc962ec
--- /dev/null
@@ -0,0 +1,12 @@
+For Bug 73511: Internals should have a method to return the max sequence number of spellcheck request.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS SpellCheck sequence seems working correctly.
+PASS SpellCheck sequence seems working correctly.
+PASS SpellCheck sequence seems working correctly.
+
diff --git a/LayoutTests/editing/spelling/spellcheck-sequencenum.html b/LayoutTests/editing/spelling/spellcheck-sequencenum.html
new file mode 100644 (file)
index 0000000..072acd5
--- /dev/null
@@ -0,0 +1,136 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/js-test-selection-shared.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script>
+description('For Bug 73511: Internals should have a method to return the max sequence number of spellcheck request.');
+
+if (window.layoutTestController) {
+    layoutTestController.waitUntilDone();
+    layoutTestController.setAsynchronousSpellCheckingEnabled(true);
+}
+
+var testRoot = document.createElement("div");
+document.body.insertBefore(testRoot, document.body.firstChild);
+
+var source = document.createElement("div");
+source.innerHTML = "foo bar";
+testRoot.appendChild(source);
+
+function createInput(testRoot) {
+    var e = document.createElement('input');
+    e.setAttribute("type", "text");
+    testRoot.appendChild(e);
+
+    return e;
+}
+
+function createTextArea(testRoot) {
+    var e = document.createElement("textarea");
+    testRoot.appendChild(e);
+
+    return e;
+}
+
+function createContentEditable(testRoot) {
+    var e = document.createElement("div");
+    e.setAttribute("contentEditable", "true");
+    testRoot.appendChild(e);
+
+    return e;
+}
+
+var destinations = [
+    createInput(testRoot),
+    createTextArea(testRoot),
+    createContentEditable(testRoot),
+];
+
+var sel = window.getSelection();
+
+var tests = [];
+for (var i = 0; i < destinations.length; ++i) {
+    var t = function(i) {
+        return function() {
+            if (!window.internals)
+                 return;
+            var sequence = internals.lastSpellCheckRequestSequence(document);
+            var processed = internals.lastSpellCheckProcessedSequence(document);
+            copyAndPaste(source, destinations[i]);
+            verify(sequence, processed);
+        }
+    }(i);
+    tests.push(t);
+}
+
+function verifyIfAny()
+{
+    var next = tests.shift();
+    if (next) {
+        next();
+        return;
+    }
+
+    testRoot.style.display = "none";
+    if (window.layoutTestController) {
+        layoutTestController.setAsynchronousSpellCheckingEnabled(false);
+        layoutTestController.notifyDone();
+    }
+}
+
+function copyAndPaste(source, dest)
+{
+    sel.selectAllChildren(source);
+    document.execCommand("Copy");
+
+    if (dest instanceof HTMLInputElement || dest instanceof HTMLTextAreaElement) {
+        dest.value = "";
+        dest.focus();
+    } else {
+        dest.innerHTML = "";
+        sel.selectAllChildren(dest);
+    }
+    document.execCommand("Paste");
+}
+
+function verify(sequence, processed)
+{
+    var nretry = 10;
+    var nsleep = 1;
+    function trial() {
+        var newSequence = internals.lastSpellCheckRequestSequence(document);
+        var newProcessed = internals.lastSpellCheckProcessedSequence(document);
+
+        var verified = newSequence >= sequence && newProcessed >= processed && newSequence == newProcessed;
+        if (verified) {
+            testPassed("SpellCheck sequence seems working correctly.");
+            verifyIfAny();
+            return;
+        }
+
+        nretry--;
+        if (0 == nretry) {
+            testFailed("SpellCheck sequence didn't increase.");
+            verifyIfAny();
+            return;
+        }
+
+        nsleep *= 2;
+        window.setTimeout(trial, nsleep);
+    };
+    trial();
+}
+
+verifyIfAny();
+
+var successfullyParsed = true;
+
+</script>
+<script src="../../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
index 53a18e9..b33848e 100644 (file)
@@ -1220,6 +1220,7 @@ media/event-attributes.html
 editing/spelling/spelling-backspace-between-lines.html
 editing/spelling/spellcheck-paste.html
 editing/spelling/spellcheck-queue.html
+editing/spelling/spellcheck-sequencenum.html
 
 # For https://bugs.webkit.org/show_bug.cgi?id=50758
 # These require DRT setSerializeHTTPLoads implementation to be reliable.
index 9605f20..03e5f39 100644 (file)
@@ -1010,6 +1010,7 @@ editing/spelling/spelling-attribute-at-child.html
 # EditorClient::requestCheckingOfString() is not implemented
 editing/spelling/spellcheck-paste.html
 editing/spelling/spellcheck-queue.html
+editing/spelling/spellcheck-sequencenum.html
 
 # [Qt][GTK] editing/spelling/spellcheck-async.html fails
 # https://bugs.webkit.org/show_bug.cgi?id=73003
index 4b074d4..95ef992 100644 (file)
@@ -1,3 +1,30 @@
+2011-12-07  Shinya Kawanaka  <shinyak@google.com>
+
+        Internals should have a method to reutrn the max sequence number of spellcheck reqeust.
+        https://bugs.webkit.org/show_bug.cgi?id=73511
+
+        Reviewed by Hajime Morita.
+
+        Internal state of SpellChecker should be able to be exposed for testing SpellChecker.
+        This patch will enable us to know asynchronous spellcheck has finished or not.
+
+        Test: editing/spelling/spellcheck-sequencenum.html
+
+        * editing/SpellChecker.cpp:
+        (WebCore::SpellChecker::SpellChecker):
+        (WebCore::SpellChecker::createRequest):
+        (WebCore::SpellChecker::didCheck):
+        * editing/SpellChecker.h:
+        (WebCore::SpellChecker::lastRequestSequence):
+          Interface to take SpellCheck sequence numbers.
+        (WebCore::SpellChecker::lastProcessedSequence): ditto.
+        * testing/Internals.cpp:
+        (WebCore::spellchecker):
+        (WebCore::Internals::lastSpellCheckRequestSequence):
+        (WebCore::Internals::lastSpellCheckProcessedSequence):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2011-12-07  Ryosuke Niwa  <rniwa@webkit.org>
 
         TypingCommand duplicates code to obtain the last typing command
index 8ff5742..aac69a0 100644 (file)
@@ -72,7 +72,8 @@ private:
 
 SpellChecker::SpellChecker(Frame* frame)
     : m_frame(frame)
-    , m_lastRequestedSequence(0)
+    , m_lastRequestSequence(0)
+    , m_lastProcessedSequence(0)
     , m_timerToProcessQueuedRequest(this, &SpellChecker::timerFiredToProcessQueuedRequest)
 {
 }
@@ -97,7 +98,7 @@ PassRefPtr<SpellChecker::SpellCheckRequest> SpellChecker::createRequest(TextChec
     if (!text.length())
         return PassRefPtr<SpellCheckRequest>();
 
-    return adoptRef(new SpellCheckRequest(++m_lastRequestedSequence, range, text, mask));
+    return adoptRef(new SpellCheckRequest(++m_lastRequestSequence, range, text, mask));
 }
 
 void SpellChecker::timerFiredToProcessQueuedRequest(Timer<SpellChecker>*)
@@ -198,7 +199,6 @@ static DocumentMarker::MarkerType toMarkerType(TextCheckingType type)
 void SpellChecker::didCheck(int sequence, const Vector<TextCheckingResult>& results)
 {
     ASSERT(m_processingRequest);
-
     ASSERT(m_processingRequest->sequence() == sequence);
     if (m_processingRequest->sequence() != sequence) {
         m_requestQueue.clear();
@@ -234,6 +234,9 @@ void SpellChecker::didCheck(int sequence, const Vector<TextCheckingResult>& resu
         startOffset = results[i].location;
     }
 
+    if (m_lastProcessedSequence < sequence)
+        m_lastProcessedSequence = sequence;
+
     m_processingRequest.clear();
     if (!m_requestQueue.isEmpty())
         m_timerToProcessQueuedRequest.startOneShot(0);
index 702f369..b45e4bc 100644 (file)
@@ -53,6 +53,16 @@ public:
     void requestCheckingFor(TextCheckingTypeMask, PassRefPtr<Range>);
     void didCheck(int sequence, const Vector<TextCheckingResult>&);
 
+    int lastRequestSequence() const
+    {
+        return m_lastRequestSequence;
+    }
+
+    int lastProcessedSequence() const
+    {
+        return m_lastProcessedSequence;
+    }
+
 private:
     class SpellCheckRequest;
     typedef Deque<RefPtr<SpellCheckRequest> > RequestQueue;
@@ -65,7 +75,8 @@ private:
     void enqueueRequest(PassRefPtr<SpellCheckRequest>);
 
     Frame* m_frame;
-    int m_lastRequestedSequence;
+    int m_lastRequestSequence;
+    int m_lastProcessedSequence;
 
     Timer<SpellChecker> m_timerToProcessQueuedRequest;
 
index ae97243..3f0606f 100644 (file)
@@ -48,6 +48,7 @@
 #include "Settings.h"
 #include "ShadowContentElement.h"
 #include "ShadowRoot.h"
+#include "SpellChecker.h"
 #include "TextIterator.h"
 
 #if ENABLE(GESTURE_EVENTS)
@@ -92,6 +93,14 @@ static bool markerTypesFrom(const String& markerType, DocumentMarker::MarkerType
     return true;
 }
 
+static SpellChecker* spellchecker(Document* document)
+{
+    if (!document || !document->frame() || !document->frame()->editor())
+        return 0;
+
+    return document->frame()->editor()->spellChecker();
+}
+
 const char* Internals::internalsId = "internals";
 
 PassRefPtr<Internals> Internals::create()
@@ -618,4 +627,28 @@ bool Internals::unifiedTextCheckingEnabled(Document* document, ExceptionCode& ec
     return document->frame()->settings()->unifiedTextCheckerEnabled();
 }
 
+int Internals::lastSpellCheckRequestSequence(Document* document, ExceptionCode& ec)
+{
+    SpellChecker* checker = spellchecker(document);
+
+    if (!checker) {
+        ec = INVALID_ACCESS_ERR;
+        return -1;
+    }
+
+    return checker->lastRequestSequence();
+}
+
+int Internals::lastSpellCheckProcessedSequence(Document* document, ExceptionCode& ec)
+{
+    SpellChecker* checker = spellchecker(document);
+
+    if (!checker) {
+        ec = INVALID_ACCESS_ERR;
+        return -1;
+    }
+
+    return checker->lastProcessedSequence();
+}
+
 }
index a68fe94..14d9dfd 100644 (file)
@@ -110,6 +110,9 @@ public:
     void setUnifiedTextCheckingEnabled(Document*, bool, ExceptionCode&);
     bool unifiedTextCheckingEnabled(Document*, ExceptionCode&);
 
+    int lastSpellCheckRequestSequence(Document*, ExceptionCode&);
+    int lastSpellCheckProcessedSequence(Document*, ExceptionCode&);
+
     static const char* internalsId;
 
 private:
index 889cda2..d622260 100644 (file)
@@ -81,6 +81,9 @@ module window {
         void setShouldLayoutFixedElementsRelativeToFrame(in Document document, in boolean enabled) raises(DOMException);
         void setUnifiedTextCheckingEnabled(in Document document, in boolean enabled) raises (DOMException);
         boolean unifiedTextCheckingEnabled(in Document document) raises (DOMException);
+
+        long lastSpellCheckRequestSequence(in Document document) raises (DOMException);
+        long lastSpellCheckProcessedSequence(in Document document) raises (DOMException);
     };
 }