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( ...@@ -484,11 +484,8 @@ void ParameterizedShowActionDeclarativeContentApiTest::TestShowAction(
// (for visibility reasons). // (for visibility reasons).
ASSERT_TRUE(action); ASSERT_TRUE(action);
// Ensure browser actions are hidden (so that the ShowAction() rule has an // Ensure actions are hidden (so that the ShowAction() rule has an effect).
// effect). if (action->default_state() == ActionInfo::STATE_DISABLED)
bool has_browser_action =
action_type && *action_type == ActionInfo::TYPE_BROWSER;
if (has_browser_action)
action->SetIsVisible(ExtensionAction::kDefaultTabId, false); action->SetIsVisible(ExtensionAction::kDefaultTabId, false);
const char kScript[] = const char kScript[] =
...@@ -514,12 +511,11 @@ void ParameterizedShowActionDeclarativeContentApiTest::TestShowAction( ...@@ -514,12 +511,11 @@ void ParameterizedShowActionDeclarativeContentApiTest::TestShowAction(
const int tab_id = SessionTabHelper::IdForTab(tab).id(); const int tab_id = SessionTabHelper::IdForTab(tab).id();
EXPECT_TRUE(action->GetIsVisible(tab_id)); EXPECT_TRUE(action->GetIsVisible(tab_id));
// Even an extension with no specified action with have a (synthesized) page // If an extension had no action specified in the manifest, it will get a
// action. Only browser action extensions are expected to not have a page // synthesized page action.
// action. ActionInfo::Type expected_type = action_type.value_or(ActionInfo::TYPE_PAGE);
bool expect_page_action = !has_browser_action; EXPECT_EQ(expected_type, action->action_type());
EXPECT_EQ(expect_page_action, action->action_type() == ActionInfo::TYPE_PAGE); EXPECT_EQ(expected_type == ActionInfo::TYPE_PAGE ? 1u : 0u,
EXPECT_EQ(expect_page_action ? 1u : 0u,
extension_action_test_util::GetVisiblePageActionCount(tab)); extension_action_test_util::GetVisiblePageActionCount(tab));
} }
...@@ -538,12 +534,10 @@ IN_PROC_BROWSER_TEST_P(ParameterizedShowActionDeclarativeContentApiTest, ...@@ -538,12 +534,10 @@ IN_PROC_BROWSER_TEST_P(ParameterizedShowActionDeclarativeContentApiTest,
TestShowAction(ActionInfo::TYPE_BROWSER); TestShowAction(ActionInfo::TYPE_BROWSER);
} }
// TODO(https://crbug.com/893373): Enable this when ExtensionActionManager knows IN_PROC_BROWSER_TEST_P(ParameterizedShowActionDeclarativeContentApiTest,
// about ActionInfo::Type::TYPE_ACTION. ActionInManifest) {
// IN_PROC_BROWSER_TEST_P(ParameterizedShowActionDeclarativeContentApiTest, TestShowAction(ActionInfo::TYPE_ACTION);
// ActionInManifest) { }
// TestShowAction(ActionInfo::TYPE_ACTION);
// }
// Tests that rules from manifest are added and evaluated properly. // Tests that rules from manifest are added and evaluated properly.
IN_PROC_BROWSER_TEST_P(ParameterizedShowActionDeclarativeContentApiTest, IN_PROC_BROWSER_TEST_P(ParameterizedShowActionDeclarativeContentApiTest,
......
...@@ -88,9 +88,10 @@ ExtensionAction::ExtensionAction(const extensions::Extension& extension, ...@@ -88,9 +88,10 @@ ExtensionAction::ExtensionAction(const extensions::Extension& extension,
const extensions::ActionInfo& manifest_data) const extensions::ActionInfo& manifest_data)
: extension_id_(extension.id()), : extension_id_(extension.id()),
extension_name_(extension.name()), extension_name_(extension.name()),
action_type_(manifest_data.type) { action_type_(manifest_data.type),
SetIsVisible(kDefaultTabId, manifest_data.default_state == default_state_(manifest_data.default_state) {
extensions::ActionInfo::STATE_ENABLED); SetIsVisible(kDefaultTabId,
default_state_ == extensions::ActionInfo::STATE_ENABLED);
Populate(extension, manifest_data); Populate(extension, manifest_data);
} }
......
...@@ -64,6 +64,10 @@ class ExtensionAction { ...@@ -64,6 +64,10 @@ class ExtensionAction {
return action_type_; 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 // 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. // icon. Setting an empty URL will disable the popup for a given tab.
void SetPopupUrl(int tab_id, const GURL& url); void SetPopupUrl(int tab_id, const GURL& url);
...@@ -251,6 +255,8 @@ class ExtensionAction { ...@@ -251,6 +255,8 @@ class ExtensionAction {
const std::string extension_name_; const std::string extension_name_;
const extensions::ActionInfo::Type action_type_; 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 // 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). // 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