[Extensions Click-to-Script] (Hopefully) de-flake action runner tests

ExtensionActionRunnerBrowserTest.ActiveScriptsAreDisplayedAndDelayExecution
has been flaky on Windows. Looking at the test, this could be caused by
not waiting a sufficient amount of time after loading the extension for
the extension background page to register a listener for the tab update.
This, in turn, would result in the extension not appearing to want to
run when it should.

Solve this potential issue by dispatching a "ready" message from the
extension once it has registered the listener, and waiting for that
message in the C++ before creating the new tab. Also explicitly wait
for the script to be injected in the case of automatic injection, and
wait for the blocked action to be added for the case of requiring
consent.

Additionally, break apart the test from being a single test that
exercised four different expectations to four tests, each managing a
single expectation. This eliminates the chance of any of the test steps
interfering with one another.

Bug: 867882

Change-Id: I2859bd35573415080e3c70a3e08bf2108430ee28
Reviewed-on: https://chromium-review.googlesource.com/1195844
Commit-Queue: Devlin <[email protected]>
Reviewed-by: Karan Bhatia <[email protected]>
Cr-Commit-Position: refs/heads/master@{#587822}
diff --git a/chrome/browser/extensions/extension_action_runner.cc b/chrome/browser/extensions/extension_action_runner.cc
index d650642..ab63e53 100644
--- a/chrome/browser/extensions/extension_action_runner.cc
+++ b/chrome/browser/extensions/extension_action_runner.cc
@@ -67,6 +67,7 @@
       browser_context_(web_contents->GetBrowserContext()),
       was_used_on_page_(false),
       ignore_active_tab_granted_(false),
+      test_observer_(nullptr),
       extension_registry_observer_(this),
       weak_factory_(this) {
   CHECK(web_contents);
@@ -152,6 +153,8 @@
 
 void ExtensionActionRunner::OnWebRequestBlocked(const Extension* extension) {
   web_request_blocked_.insert(extension->id());
+  if (test_observer_)
+    test_observer_->OnBlockedActionAdded();
 }
 
 int ExtensionActionRunner::GetBlockedActions(const Extension* extension) {
@@ -231,6 +234,9 @@
     NotifyChange(extension);
 
   was_used_on_page_ = true;
+
+  if (test_observer_)
+    test_observer_->OnBlockedActionAdded();
 }
 
 void ExtensionActionRunner::RunPendingScriptsForExtension(