Commit 80ff1c6f authored by David Bertoni's avatar David Bertoni Committed by Commit Bot

[Extensions] Fixed flakiness with incognito update test.

The CL adds a synchronization point between the browser and the
renderer at the transition from incognito mode disabled to enabled.

Bug: 1015136
Change-Id: Id29f5dc115f318cd5a7e08beac85d50d4793aa01
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2039595
Commit-Queue: David Bertoni <dbertoni@chromium.org>
Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758320}
parent da5442f6
...@@ -688,14 +688,13 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, IncognitoBasic) { ...@@ -688,14 +688,13 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, IncognitoBasic) {
} }
IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, IncognitoUpdate) { IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, IncognitoUpdate) {
// TODO(crbug.com/1015136): Investigate flakiness WRT Service Workers and
// incognito mode.
if ((GetParam() & kUseServiceWorker) != 0)
return;
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
ExtensionTestMessageListener incognito_not_allowed_listener(
"incognito not allowed", false);
const Extension* extension = LoadExtensionWithParamFlags( const Extension* extension = LoadExtensionWithParamFlags(
test_data_dir_.AppendASCII("browser_action/update")); test_data_dir_.AppendASCII("browser_action/update"));
ASSERT_TRUE(extension) << message_; ASSERT_TRUE(extension) << message_;
ASSERT_TRUE(incognito_not_allowed_listener.WaitUntilSatisfied());
// Test that there is a browser action in the toolbar. // Test that there is a browser action in the toolbar.
ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions()); ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions());
...@@ -707,21 +706,27 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, IncognitoUpdate) { ...@@ -707,21 +706,27 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, IncognitoUpdate) {
->NumberOfBrowserActions()); ->NumberOfBrowserActions());
// Set up a listener so we can reply for the extension to do the update. // Set up a listener so we can reply for the extension to do the update.
ExtensionTestMessageListener incognito_ready_listener("incognito ready", // This listener also adds a sequence point between the browser and the
true); // renderer for the transition between incognito mode not being allowed
// and it's being allowed. This ensures the browser ignores the renderer's
// execution until the transition is completed, since the script will
// start and stop multiple times during the initial load of the extension
// and the enabling of incognito mode.
ExtensionTestMessageListener incognito_allowed_listener("incognito allowed",
true);
// Now enable the extension in incognito mode, and test that the browser // Now enable the extension in incognito mode, and test that the browser
// action shows up. // action shows up. SetIsIncognitoEnabled() requires a reload of the
// SetIsIncognitoEnabled() requires a reload of the extension, so we have to // extension, so we have to wait for it to finish.
// wait for it.
TestExtensionRegistryObserver registry_observer( TestExtensionRegistryObserver registry_observer(
ExtensionRegistry::Get(profile()), extension->id()); ExtensionRegistry::Get(profile()), extension->id());
extensions::util::SetIsIncognitoEnabled(extension->id(), browser()->profile(), extensions::util::SetIsIncognitoEnabled(extension->id(), browser()->profile(),
true); true);
extension = registry_observer.WaitForExtensionLoaded(); extension = registry_observer.WaitForExtensionLoaded();
ASSERT_TRUE(extension);
ASSERT_EQ(1, ExtensionActionTestHelper::Create(incognito_browser) ASSERT_EQ(1, ExtensionActionTestHelper::Create(incognito_browser)
->NumberOfBrowserActions()); ->NumberOfBrowserActions());
ASSERT_TRUE(incognito_ready_listener.WaitUntilSatisfied()); ASSERT_TRUE(incognito_allowed_listener.WaitUntilSatisfied());
ExtensionAction* action = GetBrowserAction(incognito_browser, *extension); ExtensionAction* action = GetBrowserAction(incognito_browser, *extension);
EXPECT_EQ("This is the default title.", EXPECT_EQ("This is the default title.",
action->GetTitle(ExtensionAction::kDefaultTabId)); action->GetTitle(ExtensionAction::kDefaultTabId));
...@@ -732,7 +737,7 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, IncognitoUpdate) { ...@@ -732,7 +737,7 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, IncognitoUpdate) {
// Tell the extension to update the browser action state and then // Tell the extension to update the browser action state and then
// catch the result. // catch the result.
ResultCatcher incognito_catcher; ResultCatcher incognito_catcher;
incognito_ready_listener.Reply("incognito update"); incognito_allowed_listener.Reply("incognito update");
ASSERT_TRUE(incognito_catcher.GetNextResult()); ASSERT_TRUE(incognito_catcher.GetNextResult());
// Test that we received the changes. // Test that we received the changes.
......
...@@ -16,12 +16,17 @@ function updateBrowserAction() { ...@@ -16,12 +16,17 @@ function updateBrowserAction() {
} }
chrome.extension.isAllowedIncognitoAccess(function(isAllowedAccess) { chrome.extension.isAllowedIncognitoAccess(function(isAllowedAccess) {
if (isAllowedAccess == true) { switch(isAllowedAccess) {
chrome.test.sendMessage('incognito ready', function(message) { case false:
if (message == 'incognito update') { chrome.test.sendMessage('incognito not allowed');
updateBrowserAction(); break;
} case true:
}); chrome.test.sendMessage('incognito allowed', function(message) {
if (message == 'incognito update') {
updateBrowserAction();
}
});
break;
} }
}); });
......
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