Commit c13a5967 authored by Devlin Cronin's avatar Devlin Cronin Committed by Commit Bot

[Extensions] Update declarativeContent tests for "action" key

Update the parameterized declarativeContent tests to exercise the
behavior with the "action" manifest key, in addition to the page and
browser action keys.

Bug: 893373
Change-Id: I407be25d6dd8a9e567806d756d2c185bb37f4ce5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1613735Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Commit-Queue: Devlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662956}
parent 11270790
......@@ -484,11 +484,8 @@ void ParameterizedShowActionDeclarativeContentApiTest::TestShowAction(
// (for visibility reasons).
ASSERT_TRUE(action);
// Ensure browser actions are hidden (so that the ShowAction() rule has an
// effect).
bool has_browser_action =
action_type && *action_type == ActionInfo::TYPE_BROWSER;
if (has_browser_action)
// Ensure actions are hidden (so that the ShowAction() rule has an effect).
if (action->default_state() == ActionInfo::STATE_DISABLED)
action->SetIsVisible(ExtensionAction::kDefaultTabId, false);
const char kScript[] =
......@@ -514,12 +511,11 @@ void ParameterizedShowActionDeclarativeContentApiTest::TestShowAction(
const int tab_id = SessionTabHelper::IdForTab(tab).id();
EXPECT_TRUE(action->GetIsVisible(tab_id));
// Even an extension with no specified action with have a (synthesized) page
// action. Only browser action extensions are expected to not have a page
// action.
bool expect_page_action = !has_browser_action;
EXPECT_EQ(expect_page_action, action->action_type() == ActionInfo::TYPE_PAGE);
EXPECT_EQ(expect_page_action ? 1u : 0u,
// If an extension had no action specified in the manifest, it will get a
// synthesized page action.
ActionInfo::Type expected_type = action_type.value_or(ActionInfo::TYPE_PAGE);
EXPECT_EQ(expected_type, action->action_type());
EXPECT_EQ(expected_type == ActionInfo::TYPE_PAGE ? 1u : 0u,
extension_action_test_util::GetVisiblePageActionCount(tab));
}
......@@ -538,12 +534,10 @@ IN_PROC_BROWSER_TEST_P(ParameterizedShowActionDeclarativeContentApiTest,
TestShowAction(ActionInfo::TYPE_BROWSER);
}
// TODO(https://crbug.com/893373): Enable this when ExtensionActionManager knows
// about ActionInfo::Type::TYPE_ACTION.
// IN_PROC_BROWSER_TEST_P(ParameterizedShowActionDeclarativeContentApiTest,
// ActionInManifest) {
// TestShowAction(ActionInfo::TYPE_ACTION);
// }
IN_PROC_BROWSER_TEST_P(ParameterizedShowActionDeclarativeContentApiTest,
ActionInManifest) {
TestShowAction(ActionInfo::TYPE_ACTION);
}
// Tests that rules from manifest are added and evaluated properly.
IN_PROC_BROWSER_TEST_P(ParameterizedShowActionDeclarativeContentApiTest,
......
......@@ -88,9 +88,10 @@ ExtensionAction::ExtensionAction(const extensions::Extension& extension,
const extensions::ActionInfo& manifest_data)
: extension_id_(extension.id()),
extension_name_(extension.name()),
action_type_(manifest_data.type) {
SetIsVisible(kDefaultTabId, manifest_data.default_state ==
extensions::ActionInfo::STATE_ENABLED);
action_type_(manifest_data.type),
default_state_(manifest_data.default_state) {
SetIsVisible(kDefaultTabId,
default_state_ == extensions::ActionInfo::STATE_ENABLED);
Populate(extension, manifest_data);
}
......
......@@ -64,6 +64,10 @@ class ExtensionAction {
return action_type_;
}
extensions::ActionInfo::DefaultState default_state() const {
return default_state_;
}
// Set the url which the popup will load when the user clicks this action's
// icon. Setting an empty URL will disable the popup for a given tab.
void SetPopupUrl(int tab_id, const GURL& url);
......@@ -251,6 +255,8 @@ class ExtensionAction {
const std::string extension_name_;
const extensions::ActionInfo::Type action_type_;
// The default state of the action.
const extensions::ActionInfo::DefaultState default_state_;
// Each of these data items can have both a global state (stored with the key
// kDefaultTabId), or tab-specific state (stored with the tab_id as the key).
......
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