Commit 5c5abd24 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[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 <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587822}
parent 7f98222a
...@@ -67,6 +67,7 @@ ExtensionActionRunner::ExtensionActionRunner(content::WebContents* web_contents) ...@@ -67,6 +67,7 @@ ExtensionActionRunner::ExtensionActionRunner(content::WebContents* web_contents)
browser_context_(web_contents->GetBrowserContext()), browser_context_(web_contents->GetBrowserContext()),
was_used_on_page_(false), was_used_on_page_(false),
ignore_active_tab_granted_(false), ignore_active_tab_granted_(false),
test_observer_(nullptr),
extension_registry_observer_(this), extension_registry_observer_(this),
weak_factory_(this) { weak_factory_(this) {
CHECK(web_contents); CHECK(web_contents);
...@@ -152,6 +153,8 @@ void ExtensionActionRunner::OnActiveTabPermissionGranted( ...@@ -152,6 +153,8 @@ void ExtensionActionRunner::OnActiveTabPermissionGranted(
void ExtensionActionRunner::OnWebRequestBlocked(const Extension* extension) { void ExtensionActionRunner::OnWebRequestBlocked(const Extension* extension) {
web_request_blocked_.insert(extension->id()); web_request_blocked_.insert(extension->id());
if (test_observer_)
test_observer_->OnBlockedActionAdded();
} }
int ExtensionActionRunner::GetBlockedActions(const Extension* extension) { int ExtensionActionRunner::GetBlockedActions(const Extension* extension) {
...@@ -231,6 +234,9 @@ void ExtensionActionRunner::RequestScriptInjection( ...@@ -231,6 +234,9 @@ void ExtensionActionRunner::RequestScriptInjection(
NotifyChange(extension); NotifyChange(extension);
was_used_on_page_ = true; was_used_on_page_ = true;
if (test_observer_)
test_observer_->OnBlockedActionAdded();
} }
void ExtensionActionRunner::RunPendingScriptsForExtension( void ExtensionActionRunner::RunPendingScriptsForExtension(
......
...@@ -43,6 +43,11 @@ class ExtensionRegistry; ...@@ -43,6 +43,11 @@ class ExtensionRegistry;
class ExtensionActionRunner : public content::WebContentsObserver, class ExtensionActionRunner : public content::WebContentsObserver,
public ExtensionRegistryObserver { public ExtensionRegistryObserver {
public: public:
class TestObserver {
public:
virtual void OnBlockedActionAdded() = 0;
};
explicit ExtensionActionRunner(content::WebContents* web_contents); explicit ExtensionActionRunner(content::WebContents* web_contents);
~ExtensionActionRunner() override; ~ExtensionActionRunner() override;
...@@ -88,6 +93,9 @@ class ExtensionActionRunner : public content::WebContentsObserver, ...@@ -88,6 +93,9 @@ class ExtensionActionRunner : public content::WebContentsObserver,
std::unique_ptr<ToolbarActionsBarBubbleDelegate::CloseAction> action) { std::unique_ptr<ToolbarActionsBarBubbleDelegate::CloseAction> action) {
default_bubble_close_action_for_testing_ = std::move(action); default_bubble_close_action_for_testing_ = std::move(action);
} }
void set_observer_for_testing(TestObserver* observer) {
test_observer_ = observer;
}
#if defined(UNIT_TEST) #if defined(UNIT_TEST)
// Only used in tests. // Only used in tests.
...@@ -208,6 +216,8 @@ class ExtensionActionRunner : public content::WebContentsObserver, ...@@ -208,6 +216,8 @@ class ExtensionActionRunner : public content::WebContentsObserver,
std::unique_ptr<ToolbarActionsBarBubbleDelegate::CloseAction> std::unique_ptr<ToolbarActionsBarBubbleDelegate::CloseAction>
default_bubble_close_action_for_testing_; default_bubble_close_action_for_testing_;
TestObserver* test_observer_;
ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
extension_registry_observer_; extension_registry_observer_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment