Add a switch to TestRunner to enable/disable mock spell checker

Most layout tests are not related to spell checker, and we do not want
to see failures due to appearance/disappearance of spelling markers in
their pixel results.

This patch adds a switch to TestRunner (more specifically, its
SpellCheckClient) so that the mock spell checker returns non-empty result
only when the switch is on. It is off by default, and hence, spelling
markers do not appear in unrelated tests. Spell checking tests are modified
to explicitly set this switch on so their results remain the same as before.

The following tests are rebaselined to remove the spelling markers from their
pixel results:
- compositing/overflow/do-not-paint-outline-into-composited-scrolling-contents.html
- editing/execCommand/5569741.html
- editing/inserting/5418891.html
- editing/inserting/insert-div-027.html
- editing/inserting/paragraph-separator-01.html
- editing/inserting/paragraph-separator-02.html
- editing/inserting/paragraph-separator-03.html
- editing/inserting/return-key-with-selection-003.html
- editing/pasteboard/cut-text-001.html
- editing/pasteboard/undoable-fragment-removes.html
- editing/selection/move-backwords-by-word-001.html
- editing/selection/move-by-word-001.html
- editing/style/block-styles-007.html
- fast/dom/blur-contenteditable.html
- fast/dom/focus-contenteditable.html
- fast/forms/text/input-double-click-selection-gap-bug.html
- fast/inline-block/14498-positionForCoordinates.html
- fast/repaint/inline-outline-repaint.html
- virtual/prefer_compositing_to_lcd_text/compositing/overflow/do-not-paint-outline-into-composited-scrolling-contents.html

BUG=639213

Review-Url: https://codereview.chromium.org/2270293003
Cr-Commit-Position: refs/heads/master@{#414042}
diff --git a/components/test_runner/spell_check_client.cc b/components/test_runner/spell_check_client.cc
index 94ad604..b7a929f 100644
--- a/components/test_runner/spell_check_client.cc
+++ b/components/test_runner/spell_check_client.cc
@@ -33,12 +33,22 @@
   delegate_ = delegate;
 }
 
+void SpellCheckClient::SetEnabled(bool enabled) {
+  enabled_ = enabled;
+}
+
 // blink::WebSpellCheckClient
 void SpellCheckClient::spellCheck(
     const blink::WebString& text,
     int& misspelled_offset,
     int& misspelled_length,
     blink::WebVector<blink::WebString>* optional_suggestions) {
+  if (!enabled_) {
+    misspelled_offset = 0;
+    misspelled_length = 0;
+    return;
+  }
+
   // Check the spelling of the given text.
   spell_check_.SpellCheckWord(text, &misspelled_offset, &misspelled_length);
 }
@@ -48,7 +58,7 @@
     const blink::WebVector<uint32_t>& markers,
     const blink::WebVector<unsigned>& marker_offsets,
     blink::WebTextCheckingCompletion* completion) {
-  if (text.isEmpty()) {
+  if (!enabled_ || text.isEmpty()) {
     if (completion)
       completion->didCancelCheckingText();
     return;
diff --git a/components/test_runner/spell_check_client.h b/components/test_runner/spell_check_client.h
index f9f23cb1..c7bb376d 100644
--- a/components/test_runner/spell_check_client.h
+++ b/components/test_runner/spell_check_client.h
@@ -30,6 +30,7 @@
   virtual ~SpellCheckClient();
 
   void SetDelegate(WebTestDelegate* delegate);
+  void SetEnabled(bool enabled);
 
   // blink::WebSpellCheckClient implementation.
   void spellCheck(
@@ -47,6 +48,10 @@
  private:
   void FinishLastTextCheck();
 
+  // Do not perform any checking when |enabled_ == false|.
+  // Tests related to spell checking should enable it manually.
+  bool enabled_ = false;
+
   // The mock spellchecker used in spellCheck().
   MockSpellCheck spell_check_;
 
diff --git a/components/test_runner/test_runner.cc b/components/test_runner/test_runner.cc
index f186060..d684316 100644
--- a/components/test_runner/test_runner.cc
+++ b/components/test_runner/test_runner.cc
@@ -214,6 +214,7 @@
   void SetDomainRelaxationForbiddenForURLScheme(bool forbidden,
                                                 const std::string& scheme);
   void SetDumpConsoleMessages(bool value);
+  void SetMockSpellCheckerEnabled(bool enabled);
   void SetImagesAllowed(bool allowed);
   void SetIsolatedWorldContentSecurityPolicy(int world_id,
                                              const std::string& policy);
@@ -514,6 +515,8 @@
                  &TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme)
       .SetMethod("setDumpConsoleMessages",
                  &TestRunnerBindings::SetDumpConsoleMessages)
+      .SetMethod("setMockSpellCheckerEnabled",
+                 &TestRunnerBindings::SetMockSpellCheckerEnabled)
       .SetMethod("setIconDatabaseEnabled", &TestRunnerBindings::NotImplemented)
       .SetMethod("setImagesAllowed", &TestRunnerBindings::SetImagesAllowed)
       .SetMethod("setIsolatedWorldContentSecurityPolicy",
@@ -705,6 +708,11 @@
     runner_->SetDumpConsoleMessages(enabled);
 }
 
+void TestRunnerBindings::SetMockSpellCheckerEnabled(bool enabled) {
+  if (runner_)
+    runner_->SetMockSpellCheckerEnabled(enabled);
+}
+
 v8::Local<v8::Value>
 TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue(
     int world_id, const std::string& script) {
@@ -1629,6 +1637,8 @@
     delegate_->CloseRemainingWindows();
   else
     close_remaining_windows_ = true;
+
+  spellcheck_->SetEnabled(false);
 }
 
 void TestRunner::SetTestIsRunning(bool running) {
@@ -2570,6 +2580,10 @@
   OnLayoutTestRuntimeFlagsChanged();
 }
 
+void TestRunner::SetMockSpellCheckerEnabled(bool enabled) {
+  spellcheck_->SetEnabled(enabled);
+}
+
 bool TestRunner::ShouldDumpConsoleMessages() const {
   return layout_test_runtime_flags_.dump_console_messages();
 }
diff --git a/components/test_runner/test_runner.h b/components/test_runner/test_runner.h
index 1abf848..b394f97 100644
--- a/components/test_runner/test_runner.h
+++ b/components/test_runner/test_runner.h
@@ -463,6 +463,9 @@
   // to test output.
   void SetDumpConsoleMessages(bool value);
 
+  // Controls whether the mock spell checker is enabled.
+  void SetMockSpellCheckerEnabled(bool enabled);
+
   ///////////////////////////////////////////////////////////////////////////
   // Methods interacting with the WebViewTestProxy