Commit 11efe4f5 authored by Ghazale Hosseinabadi's avatar Ghazale Hosseinabadi Committed by Commit Bot

Add BROWSERACTION API test coverage

This cl adds BROWSERACTION_ENABLE and BROWSERACTION_DISABLE API test
coverages.

Bug: 1093066
Change-Id: I7f7006725f9633d6aae6f09e6facefe0270638ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2453149Reviewed-by: default avatarDavid Bertoni <dbertoni@chromium.org>
Commit-Queue: Ghazale Hosseinabadi <ghazale@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814954}
parent 07ec49c1
......@@ -207,6 +207,34 @@ class BrowserActionApiLazyTest
action->GetBadgeBackgroundColor(ExtensionAction::kDefaultTabId));
}
void RunEnableTest(base::StringPiece path, bool start_enabled) {
ExtensionTestMessageListener ready_listener("ready", true);
const Extension* extension =
LoadExtensionWithParamFlags(test_data_dir_.AppendASCII(path));
ASSERT_TRUE(extension) << message_;
// Test that there is a browser action in the toolbar.
ASSERT_EQ(1, GetBrowserActionsBar()->NumberOfBrowserActions());
ASSERT_TRUE(ready_listener.WaitUntilSatisfied());
ExtensionAction* action = GetBrowserAction(browser(), *extension);
// Tell the extension to enable/disable the browser action state and then
// catch the result.
ResultCatcher catcher;
if (start_enabled) {
action->SetIsVisible(ExtensionAction::kDefaultTabId, true);
ready_listener.Reply("start enabled");
} else {
action->SetIsVisible(ExtensionAction::kDefaultTabId, false);
ready_listener.Reply("start disabled");
}
EXPECT_TRUE(catcher.GetNextResult());
// Test that changes were applied.
EXPECT_EQ(!start_enabled,
action->GetIsVisible(ExtensionAction::kDefaultTabId));
}
private:
base::test::ScopedFeatureList feature_list_;
std::unique_ptr<extensions::ScopedWorkerBasedExtensionsChannel>
......@@ -237,6 +265,14 @@ IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, Basic) {
EXPECT_TRUE(catcher.GetNextResult());
}
IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, Disable) {
ASSERT_NO_FATAL_FAILURE(RunEnableTest("browser_action/enable", true));
}
IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, Enable) {
ASSERT_NO_FATAL_FAILURE(RunEnableTest("browser_action/enable", false));
}
IN_PROC_BROWSER_TEST_P(BrowserActionApiLazyTest, Update) {
ASSERT_NO_FATAL_FAILURE(RunUpdateTest("browser_action/update", false));
}
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function enableBrowserAction(message) {
if(message == 'start enabled') {
chrome.browserAction.disable(function() {
chrome.test.notifyPass();
});
} else {
chrome.browserAction.enable(function() {
chrome.test.notifyPass();
});
}
}
chrome.test.sendMessage('ready', function(message) {
enableBrowserAction(message);
});
{
"name": "A browser action test to verify tab enabling/disabling.",
"version": "1.0",
"manifest_version": 2,
"background": {
"persistent": false,
"scripts": ["background.js"]
},
"browser_action": {
"default_title": "This is the default title."
}
}
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