Space out issuing of spellcheck requests to speed up layout test.

Avoid issuing all spellcheck requests (by focusing elements) in one go
as this queues up a number of tasks and timers that it will require going
back to the event loop many times to process and handle. As the actual
test also relies on timers and setTimeout() this delays the completion
of the test considerably.

Restructure the test, interleaving the element focusing (=> spellcheck
request) with asynchronously checking the spellcheck result. Test completes
earlier as a result.

R=haraken
BUG=356957
TEST=editing/spelling/spellcheck-editable-on-focus.html

Review URL: https://codereview.chromium.org/1781273009

Cr-Commit-Position: refs/heads/master@{#380895}
diff --git a/third_party/WebKit/LayoutTests/editing/spelling/spellcheck-editable-on-focus-expected.txt b/third_party/WebKit/LayoutTests/editing/spelling/spellcheck-editable-on-focus-expected.txt
index 26db3e4..c335f468 100644
--- a/third_party/WebKit/LayoutTests/editing/spelling/spellcheck-editable-on-focus-expected.txt
+++ b/third_party/WebKit/LayoutTests/editing/spelling/spellcheck-editable-on-focus-expected.txt
@@ -3,12 +3,12 @@
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS internals.markerCountForNode(findFirstTextNode(testEditable), "spelling") became expectedNumberOfMarkers
-PASS internals.markerCountForNode(findFirstTextNode(testTextArea), "spelling") became expectedNumberOfMarkers
-PASS internals.markerCountForNode(findFirstTextNode(testTextField), "spelling") became expectedNumberOfMarkers
-PASS internals.markerCountForNode(findFirstTextNode(testEditable), "spelling") became expectedNumberOfMarkers
-PASS internals.markerCountForNode(findFirstTextNode(testTextArea), "spelling") became expectedNumberOfMarkers
-PASS internals.markerCountForNode(findFirstTextNode(testTextField), "spelling") became expectedNumberOfMarkers
+PASS internals.markerCountForNode(findFirstTextNodeOf("test_editable"), "spelling") became 0
+PASS internals.markerCountForNode(findFirstTextNodeOf("test_textarea"), "spelling") became 0
+PASS internals.markerCountForNode(findFirstTextNodeOf("test_textfield"), "spelling") became 0
+PASS internals.markerCountForNode(findFirstTextNodeOf("test_editable"), "spelling") became 3
+PASS internals.markerCountForNode(findFirstTextNodeOf("test_textarea"), "spelling") became 3
+PASS internals.markerCountForNode(findFirstTextNodeOf("test_textfield"), "spelling") became 3
 PASS successfullyParsed is true
 
 TEST COMPLETE
diff --git a/third_party/WebKit/LayoutTests/editing/spelling/spellcheck-editable-on-focus.html b/third_party/WebKit/LayoutTests/editing/spelling/spellcheck-editable-on-focus.html
index d49f42c..c871e5b 100644
--- a/third_party/WebKit/LayoutTests/editing/spelling/spellcheck-editable-on-focus.html
+++ b/third_party/WebKit/LayoutTests/editing/spelling/spellcheck-editable-on-focus.html
@@ -5,7 +5,7 @@
 <script src="resources/util.js"></script>
 <script src="../../resources/js-test.js"></script>
 </head>
-<body onload="test();">
+<body>
 <div id="container">
   <div id="test_editable" contentEditable>zz zz zz.</div>
   <textarea id="test_textarea">zz zz zz.</textarea>
@@ -18,27 +18,27 @@
 
 jsTestIsAsync = true;
 
-var testEditable = document.getElementById('test_editable');
-var testTextArea = document.getElementById('test_textarea');
-var testTextField = document.getElementById('test_textfield');
-
-function triggerSpellingForEditables() {
-    testEditable.focus();
-    testTextArea.focus();
-    testTextField.focus();
+function findFirstTextNodeOf(id) {
+    return findFirstTextNode(document.getElementById(id));
 }
 
-var expectedNumberOfMarkers;
-var textNode;
-function verifySpellingMarkers(expectation, doneCallback) {
-    expectedNumberOfMarkers = expectation;
-    shouldBecomeEqual('internals.markerCountForNode(findFirstTextNode(testEditable), "spelling")', 'expectedNumberOfMarkers', function() {
-        shouldBecomeEqual('internals.markerCountForNode(findFirstTextNode(testTextArea), "spelling")', 'expectedNumberOfMarkers', function() {
-            shouldBecomeEqual('internals.markerCountForNode(findFirstTextNode(testTextField), "spelling")', 'expectedNumberOfMarkers', function() {
-                doneCallback();
+var expectedNumberOfMarkers = "0";
+function checkMarkersFor(elementID, doFocus, continuation) {
+    var element = document.getElementById(elementID);
+    if (doFocus)
+        element.focus();
+    shouldBecomeEqual('internals.markerCountForNode(findFirstTextNodeOf("' + elementID + '"), "spelling")', expectedNumberOfMarkers, continuation);
+}
+
+function verifySpellingMarkers(doFocus, doneCallback) {
+    checkMarkersFor('test_editable', doFocus, function () {
+        checkMarkersFor('test_textarea', doFocus, function () {
+            checkMarkersFor('test_textfield', doFocus, function () {
+                doneCallback && doneCallback();
                 // After focusing the editable elements, check whether they have spelling markers.
-                verifySpellingMarkers(3, finishJSTest);
-             });
+                expectedNumberOfMarkers = "3";
+                verifySpellingMarkers(true, finishJSTest);
+            });
         });
     });
 }
@@ -53,9 +53,9 @@
 
     // Check whether non-focused elements do not have spelling markers, then
     // verify them when they get focused.
-    verifySpellingMarkers(0, triggerSpellingForEditables);
+    verifySpellingMarkers(false);
 }
-
+test();
 </script>
 </body>
 </html>