Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(963)

Unified Diff: chrome/browser/ui/toolbar/toolbar_actions_model_unittest.cc

Issue 1241063003: Support Component Actions in the toolbar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes per mfoltz@'s comments. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/toolbar/toolbar_actions_model_unittest.cc
diff --git a/chrome/browser/extensions/extension_toolbar_model_unittest.cc b/chrome/browser/ui/toolbar/toolbar_actions_model_unittest.cc
similarity index 43%
rename from chrome/browser/extensions/extension_toolbar_model_unittest.cc
rename to chrome/browser/ui/toolbar/toolbar_actions_model_unittest.cc
index fe14f85b974d9e53afa123edc25f633d61b4c9a7..74c01527b9f8c1f08763a56b7981bc82531a0a9c 100644
--- a/chrome/browser/extensions/extension_toolbar_model_unittest.cc
+++ b/chrome/browser/ui/toolbar/toolbar_actions_model_unittest.cc
@@ -12,7 +12,6 @@
#include "chrome/browser/extensions/extension_action_test_util.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_test_base.h"
-#include "chrome/browser/extensions/extension_toolbar_model.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/test_extension_dir.h"
#include "chrome/browser/extensions/test_extension_system.h"
@@ -20,6 +19,10 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_delegate.h"
+#include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h"
+#include "chrome/browser/ui/toolbar/mock_component_toolbar_actions_factory.h"
+#include "chrome/browser/ui/toolbar/test_toolbar_action_view_controller.h"
+#include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
#include "chrome/common/extensions/api/extension_action/action_info.h"
#include "components/crx_file/id_util.h"
#include "content/public/test/test_renderer_host.h"
@@ -38,16 +41,14 @@
#include "ui/aura/env.h"
#endif
-namespace extensions {
-
namespace {
// A simple observer that tracks the number of times certain events occur.
-class ExtensionToolbarModelTestObserver
- : public ExtensionToolbarModel::Observer {
+class ToolbarActionsModelTestObserver
+ : public ToolbarActionsModel::Observer {
public:
- explicit ExtensionToolbarModelTestObserver(ExtensionToolbarModel* model);
- ~ExtensionToolbarModelTestObserver() override;
+ explicit ToolbarActionsModelTestObserver(ToolbarActionsModel* model);
+ ~ToolbarActionsModelTestObserver() override;
size_t inserted_count() const { return inserted_count_; }
size_t removed_count() const { return removed_count_; }
@@ -56,23 +57,23 @@ class ExtensionToolbarModelTestObserver
size_t initialized_count() const { return initialized_count_; }
private:
- // ExtensionToolbarModel::Observer:
- void OnToolbarExtensionAdded(const Extension* extension, int index) override {
+ // ToolbarActionsModel::Observer:
+ void OnToolbarActionAdded(const std::string& id, int index) override {
++inserted_count_;
}
- void OnToolbarExtensionRemoved(const Extension* extension) override {
+ void OnToolbarActionRemoved(const std::string& id) override {
++removed_count_;
}
- void OnToolbarExtensionMoved(const Extension* extension, int index) override {
+ void OnToolbarActionMoved(const std::string& id, int index) override {
++moved_count_;
}
- void OnToolbarExtensionUpdated(const Extension* extension) override {}
+ void OnToolbarActionUpdated(const std::string& id) override {}
- bool ShowExtensionActionPopup(const Extension* extension,
- bool grant_active_tab) override {
+ bool ShowToolbarActionPopup(const std::string& id,
+ bool grant_active_tab) override {
return false;
}
@@ -87,7 +88,7 @@ class ExtensionToolbarModelTestObserver
Browser* GetBrowser() override { return NULL; }
- ExtensionToolbarModel* model_;
+ ToolbarActionsModel* model_;
size_t inserted_count_;
size_t removed_count_;
@@ -97,25 +98,26 @@ class ExtensionToolbarModelTestObserver
size_t initialized_count_;
};
-ExtensionToolbarModelTestObserver::ExtensionToolbarModelTestObserver(
- ExtensionToolbarModel* model) : model_(model),
- inserted_count_(0),
- removed_count_(0),
- moved_count_(0),
- highlight_mode_count_(0),
- initialized_count_(0) {
+ToolbarActionsModelTestObserver::ToolbarActionsModelTestObserver(
+ ToolbarActionsModel* model) : model_(model),
+ inserted_count_(0),
+ removed_count_(0),
+ moved_count_(0),
+ highlight_mode_count_(0),
+ initialized_count_(0) {
model_->AddObserver(this);
}
-ExtensionToolbarModelTestObserver::~ExtensionToolbarModelTestObserver() {
+ToolbarActionsModelTestObserver::~ToolbarActionsModelTestObserver() {
model_->RemoveObserver(this);
}
} // namespace
-class ExtensionToolbarModelUnitTest : public ExtensionServiceTestBase {
+class ToolbarActionsModelUnitTest :
+ public extensions::ExtensionServiceTestBase {
protected:
- // Initialize the ExtensionService, ExtensionToolbarModel, and
+ // Initialize the ExtensionService, ToolbarActionsModel, and
// ExtensionSystem.
void Init();
@@ -123,9 +125,11 @@ class ExtensionToolbarModelUnitTest : public ExtensionServiceTestBase {
// Adds or removes the given |extension| and verify success.
testing::AssertionResult AddExtension(
- const scoped_refptr<const Extension>& extension) WARN_UNUSED_RESULT;
+ const scoped_refptr<const extensions::Extension>& extension)
+ WARN_UNUSED_RESULT;
testing::AssertionResult RemoveExtension(
- const scoped_refptr<const Extension>& extension) WARN_UNUSED_RESULT;
+ const scoped_refptr<const extensions::Extension>& extension)
+ WARN_UNUSED_RESULT;
// Adds three extensions, all with browser actions.
testing::AssertionResult AddBrowserActionExtensions() WARN_UNUSED_RESULT;
@@ -134,68 +138,90 @@ class ExtensionToolbarModelUnitTest : public ExtensionServiceTestBase {
// action, and are added in that order.
testing::AssertionResult AddActionExtensions() WARN_UNUSED_RESULT;
- // Returns the extension at the given index in the toolbar model, or NULL
- // if one does not exist.
+ // Returns the action at the given index in the toolbar model, or NULL if one
+ // does not exist.
// If |model| is specified, it is used. Otherwise, this defaults to
// |toolbar_model_|.
- const Extension* GetExtensionAtIndex(
- size_t index, const ExtensionToolbarModel* model) const;
- const Extension* GetExtensionAtIndex(size_t index) const;
+ const std::string GetActionIdAtIndex(size_t index,
+ const ToolbarActionsModel* model) const;
+ const std::string GetActionIdAtIndex(size_t index) const;
- ExtensionToolbarModel* toolbar_model() { return toolbar_model_; }
+ ToolbarActionsModel* toolbar_model() { return toolbar_model_; }
- const ExtensionToolbarModelTestObserver* observer() const {
+ const ToolbarActionsModelTestObserver* observer() const {
return model_observer_.get();
}
size_t num_toolbar_items() const {
return toolbar_model_->toolbar_items().size();
}
- const Extension* browser_action_a() const { return browser_action_a_.get(); }
- const Extension* browser_action_b() const { return browser_action_b_.get(); }
- const Extension* browser_action_c() const { return browser_action_c_.get(); }
- const Extension* browser_action() const {
+ const extensions::Extension* browser_action_a() const {
+ return browser_action_a_.get();
+ }
+ const extensions::Extension* browser_action_b() const {
+ return browser_action_b_.get();
+ }
+ const extensions::Extension* browser_action_c() const {
+ return browser_action_c_.get();
+ }
+ const extensions::Extension* browser_action() const {
return browser_action_extension_.get();
}
- const Extension* page_action() const { return page_action_extension_.get(); }
- const Extension* no_action() const { return no_action_extension_.get(); }
+ const extensions::Extension* page_action() const {
+ return page_action_extension_.get();
+ }
+ const extensions::Extension* no_action() const {
+ return no_action_extension_.get();
+ }
+
+ // The mock component action will be referred to as "MCA" below.
+ const std::string& component_action_id() {
+ return mock_action_id_;
+ }
private:
// Verifies that all extensions in |extensions| are added successfully.
testing::AssertionResult AddAndVerifyExtensions(
- const ExtensionList& extensions);
+ const extensions::ExtensionList& extensions);
// The toolbar model associated with the testing profile.
- ExtensionToolbarModel* toolbar_model_;
+ ToolbarActionsModel* toolbar_model_;
+
+ std::string mock_action_id_;
// The test observer to track events. Must come after toolbar_model_ so that
// it is destroyed and removes itself as an observer first.
- scoped_ptr<ExtensionToolbarModelTestObserver> model_observer_;
+ scoped_ptr<ToolbarActionsModelTestObserver> model_observer_;
// Sample extensions with only browser actions.
- scoped_refptr<const Extension> browser_action_a_;
- scoped_refptr<const Extension> browser_action_b_;
- scoped_refptr<const Extension> browser_action_c_;
+ scoped_refptr<const extensions::Extension> browser_action_a_;
+ scoped_refptr<const extensions::Extension> browser_action_b_;
+ scoped_refptr<const extensions::Extension> browser_action_c_;
// Sample extensions with different kinds of actions.
- scoped_refptr<const Extension> browser_action_extension_;
- scoped_refptr<const Extension> page_action_extension_;
- scoped_refptr<const Extension> no_action_extension_;
+ scoped_refptr<const extensions::Extension> browser_action_extension_;
+ scoped_refptr<const extensions::Extension> page_action_extension_;
+ scoped_refptr<const extensions::Extension> no_action_extension_;
+
+ scoped_ptr<MockComponentToolbarActionsFactory> mock_actions_factory_;
};
-void ExtensionToolbarModelUnitTest::Init() {
+void ToolbarActionsModelUnitTest::Init() {
InitializeEmptyExtensionService();
+ mock_actions_factory_.reset(new MockComponentToolbarActionsFactory(NULL));
toolbar_model_ =
- extension_action_test_util::CreateToolbarModelForProfile(profile());
- model_observer_.reset(new ExtensionToolbarModelTestObserver(toolbar_model_));
+ extensions::extension_action_test_util::CreateToolbarModelForProfile(
+ profile());
+ model_observer_.reset(new ToolbarActionsModelTestObserver(toolbar_model_));
+ mock_action_id_ = ComponentToolbarActionsFactory::kActionIdForTest;
}
-void ExtensionToolbarModelUnitTest::TearDown() {
+void ToolbarActionsModelUnitTest::TearDown() {
model_observer_.reset();
- ExtensionServiceTestBase::TearDown();
+ extensions::ExtensionServiceTestBase::TearDown();
}
-testing::AssertionResult ExtensionToolbarModelUnitTest::AddExtension(
- const scoped_refptr<const Extension>& extension) {
+testing::AssertionResult ToolbarActionsModelUnitTest::AddExtension(
+ const scoped_refptr<const extensions::Extension>& extension) {
if (registry()->enabled_extensions().GetByID(extension->id())) {
return testing::AssertionFailure() << "Extension " << extension->name() <<
" already installed!";
@@ -208,14 +234,14 @@ testing::AssertionResult ExtensionToolbarModelUnitTest::AddExtension(
return testing::AssertionSuccess();
}
-testing::AssertionResult ExtensionToolbarModelUnitTest::RemoveExtension(
- const scoped_refptr<const Extension>& extension) {
+testing::AssertionResult ToolbarActionsModelUnitTest::RemoveExtension(
+ const scoped_refptr<const extensions::Extension>& extension) {
if (!registry()->enabled_extensions().GetByID(extension->id())) {
return testing::AssertionFailure() << "Extension " << extension->name() <<
" not installed!";
}
service()->UnloadExtension(extension->id(),
- UnloadedExtensionInfo::REASON_DISABLE);
+ extensions::UnloadedExtensionInfo::REASON_DISABLE);
if (registry()->enabled_extensions().GetByID(extension->id())) {
return testing::AssertionFailure() << "Failed to unload extension: " <<
extension->name();
@@ -223,15 +249,21 @@ testing::AssertionResult ExtensionToolbarModelUnitTest::RemoveExtension(
return testing::AssertionSuccess();
}
-testing::AssertionResult ExtensionToolbarModelUnitTest::AddActionExtensions() {
- browser_action_extension_ = extension_action_test_util::CreateActionExtension(
- "browser_action", extension_action_test_util::BROWSER_ACTION);
- page_action_extension_ = extension_action_test_util::CreateActionExtension(
- "page_action", extension_action_test_util::PAGE_ACTION);
- no_action_extension_ = extension_action_test_util::CreateActionExtension(
- "no_action", extension_action_test_util::NO_ACTION);
-
- ExtensionList extensions;
+testing::AssertionResult ToolbarActionsModelUnitTest::AddActionExtensions() {
+ browser_action_extension_ =
+ extensions::extension_action_test_util::CreateActionExtension(
+ "browser_action",
+ extensions::extension_action_test_util::BROWSER_ACTION);
+ page_action_extension_ =
+ extensions::extension_action_test_util::CreateActionExtension(
+ "page_action",
+ extensions::extension_action_test_util::PAGE_ACTION);
+ no_action_extension_ =
+ extensions::extension_action_test_util::CreateActionExtension(
+ "no_action",
+ extensions::extension_action_test_util::NO_ACTION);
+
+ extensions::ExtensionList extensions;
extensions.push_back(browser_action_extension_);
extensions.push_back(page_action_extension_);
extensions.push_back(no_action_extension_);
@@ -240,15 +272,21 @@ testing::AssertionResult ExtensionToolbarModelUnitTest::AddActionExtensions() {
}
testing::AssertionResult
-ExtensionToolbarModelUnitTest::AddBrowserActionExtensions() {
- browser_action_a_ = extension_action_test_util::CreateActionExtension(
- "browser_actionA", extension_action_test_util::BROWSER_ACTION);
- browser_action_b_ = extension_action_test_util::CreateActionExtension(
- "browser_actionB", extension_action_test_util::BROWSER_ACTION);
- browser_action_c_ = extension_action_test_util::CreateActionExtension(
- "browser_actionC", extension_action_test_util::BROWSER_ACTION);
-
- ExtensionList extensions;
+ToolbarActionsModelUnitTest::AddBrowserActionExtensions() {
+ browser_action_a_ =
+ extensions::extension_action_test_util::CreateActionExtension(
+ "browser_actionA",
+ extensions::extension_action_test_util::BROWSER_ACTION);
+ browser_action_b_ =
+ extensions::extension_action_test_util::CreateActionExtension(
+ "browser_actionB",
+ extensions::extension_action_test_util::BROWSER_ACTION);
+ browser_action_c_ =
+ extensions::extension_action_test_util::CreateActionExtension(
+ "browser_actionC",
+ extensions::extension_action_test_util::BROWSER_ACTION);
+
+ extensions::ExtensionList extensions;
extensions.push_back(browser_action_a_);
extensions.push_back(browser_action_b_);
extensions.push_back(browser_action_c_);
@@ -256,21 +294,21 @@ ExtensionToolbarModelUnitTest::AddBrowserActionExtensions() {
return AddAndVerifyExtensions(extensions);
}
-const Extension* ExtensionToolbarModelUnitTest::GetExtensionAtIndex(
- size_t index, const ExtensionToolbarModel* model) const {
+const std::string ToolbarActionsModelUnitTest::GetActionIdAtIndex(
+ size_t index, const ToolbarActionsModel* model) const {
return index < model->toolbar_items().size()
- ? model->toolbar_items()[index].get()
- : NULL;
+ ? model->toolbar_items()[index]
+ : std::string();
}
-const Extension* ExtensionToolbarModelUnitTest::GetExtensionAtIndex(
+const std::string ToolbarActionsModelUnitTest::GetActionIdAtIndex(
size_t index) const {
- return GetExtensionAtIndex(index, toolbar_model_);
+ return GetActionIdAtIndex(index, toolbar_model_);
}
-testing::AssertionResult ExtensionToolbarModelUnitTest::AddAndVerifyExtensions(
- const ExtensionList& extensions) {
- for (ExtensionList::const_iterator iter = extensions.begin();
+testing::AssertionResult ToolbarActionsModelUnitTest::AddAndVerifyExtensions(
+ const extensions::ExtensionList& extensions) {
+ for (extensions::ExtensionList::const_iterator iter = extensions.begin();
iter != extensions.end(); ++iter) {
if (!AddExtension(*iter)) {
return testing::AssertionFailure() << "Failed to install extension: " <<
@@ -280,112 +318,146 @@ testing::AssertionResult ExtensionToolbarModelUnitTest::AddAndVerifyExtensions(
return testing::AssertionSuccess();
}
-// A basic test for extensions with browser actions showing up in the toolbar.
-TEST_F(ExtensionToolbarModelUnitTest, BasicExtensionToolbarModelTest) {
+// A basic test for component actions and extensions with browser actions
+// showing up in the toolbar.
+TEST_F(ToolbarActionsModelUnitTest, BasicToolbarActionsModelTest) {
Init();
+ // One component action was added when the model was initialized.
+ EXPECT_EQ(0u, observer()->inserted_count());
+ EXPECT_EQ(1u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+
// Load an extension with no browser action.
- scoped_refptr<const Extension> extension1 =
- extension_action_test_util::CreateActionExtension(
- "no_action", extension_action_test_util::NO_ACTION);
+ scoped_refptr<const extensions::Extension> extension1 =
+ extensions::extension_action_test_util::CreateActionExtension(
+ "no_action", extensions::extension_action_test_util::NO_ACTION);
ASSERT_TRUE(AddExtension(extension1));
// This extension should not be in the model (has no browser action).
EXPECT_EQ(0u, observer()->inserted_count());
- EXPECT_EQ(0u, num_toolbar_items());
- EXPECT_EQ(NULL, GetExtensionAtIndex(0u));
+ EXPECT_EQ(1u, num_toolbar_items());
+ EXPECT_EQ("", GetActionIdAtIndex(1u));
// Load an extension with a browser action.
- scoped_refptr<const Extension> extension2 =
- extension_action_test_util::CreateActionExtension(
- "browser_action", extension_action_test_util::BROWSER_ACTION);
+ scoped_refptr<const extensions::Extension> extension2 =
+ extensions::extension_action_test_util::CreateActionExtension(
+ "browser_action",
+ extensions::extension_action_test_util::BROWSER_ACTION);
ASSERT_TRUE(AddExtension(extension2));
// We should now find our extension in the model.
EXPECT_EQ(1u, observer()->inserted_count());
- EXPECT_EQ(1u, num_toolbar_items());
- EXPECT_EQ(extension2.get(), GetExtensionAtIndex(0u));
+ EXPECT_EQ(2u, num_toolbar_items());
+ EXPECT_EQ(extension2->id(), GetActionIdAtIndex(1u));
// Should be a no-op, but still fires the events.
- toolbar_model()->MoveExtensionIcon(extension2->id(), 0);
+ toolbar_model()->MoveActionIcon(extension2->id(), 1);
EXPECT_EQ(1u, observer()->moved_count());
- EXPECT_EQ(1u, num_toolbar_items());
- EXPECT_EQ(extension2.get(), GetExtensionAtIndex(0u));
+ EXPECT_EQ(2u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(extension2->id(), GetActionIdAtIndex(1u));
// Remove the extension and verify.
ASSERT_TRUE(RemoveExtension(extension2));
EXPECT_EQ(1u, observer()->removed_count());
- EXPECT_EQ(0u, num_toolbar_items());
- EXPECT_EQ(NULL, GetExtensionAtIndex(0u));
+ EXPECT_EQ(1u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ("", GetActionIdAtIndex(1u));
}
// Test various different reorderings, removals, and reinsertions.
-TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarReorderAndReinsert) {
+TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarReorderAndReinsert) {
Init();
+ // One component action was added when the model was initialized.
+ EXPECT_EQ(1u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(),
+ GetActionIdAtIndex(0u));
+
// Add the three browser action extensions.
ASSERT_TRUE(AddBrowserActionExtensions());
- // Verify the three extensions are in the model in the proper order.
- EXPECT_EQ(3u, num_toolbar_items());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u));
+ // Verify the four actions are in the model in the proper order.
+ EXPECT_EQ(4u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
- // Order is now A, B, C. Let's put C first.
- toolbar_model()->MoveExtensionIcon(browser_action_c()->id(), 0);
+ // Order is now MCA, A, B, C. Let's put C first.
+ toolbar_model()->MoveActionIcon(browser_action_c()->id(), 0);
EXPECT_EQ(1u, observer()->moved_count());
- EXPECT_EQ(3u, num_toolbar_items());
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(1u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(2u));
+ EXPECT_EQ(4u, num_toolbar_items());
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(3u));
- // Order is now C, A, B. Let's put A last.
- toolbar_model()->MoveExtensionIcon(browser_action_a()->id(), 2);
+ // Order is now C, MCAn, A, B. Let's put A last.
+ toolbar_model()->MoveActionIcon(browser_action_a()->id(), 2);
EXPECT_EQ(2u, observer()->moved_count());
- EXPECT_EQ(3u, num_toolbar_items());
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u));
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(2u));
+ EXPECT_EQ(4u, num_toolbar_items());
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(3u));
- // Order is now C, B, A. Let's remove B.
+ // Order is now C, MCA, B, A. Let's remove B.
ASSERT_TRUE(RemoveExtension(browser_action_b()));
EXPECT_EQ(1u, observer()->removed_count());
- EXPECT_EQ(2u, num_toolbar_items());
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(1u));
+ EXPECT_EQ(3u, num_toolbar_items());
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(2u));
// Load extension B again.
ASSERT_TRUE(AddExtension(browser_action_b()));
// Extension B loaded again.
EXPECT_EQ(4u, observer()->inserted_count());
- EXPECT_EQ(3u, num_toolbar_items());
+ EXPECT_EQ(4u, num_toolbar_items());
// Make sure it gets its old spot in the list.
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(3u));
// Unload B again.
ASSERT_TRUE(RemoveExtension(browser_action_b()));
EXPECT_EQ(2u, observer()->removed_count());
- EXPECT_EQ(2u, num_toolbar_items());
+ EXPECT_EQ(3u, num_toolbar_items());
- // Order is now C, A. Flip it.
- toolbar_model()->MoveExtensionIcon(browser_action_a()->id(), 0);
+ // Order is now C, MCA, A. Let's put A first.
+ toolbar_model()->MoveActionIcon(browser_action_a()->id(), 0);
EXPECT_EQ(3u, observer()->moved_count());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(2u));
// Move A to the location it already occupies.
- toolbar_model()->MoveExtensionIcon(browser_action_a()->id(), 0);
+ toolbar_model()->MoveActionIcon(browser_action_a()->id(), 0);
EXPECT_EQ(4u, observer()->moved_count());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u));
-
- // Order is now A, C. Remove C.
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(2u));
+
+ // Order is now A, C, MCA. Let's put MCA first.
+ toolbar_model()->MoveActionIcon(component_action_id(), 0);
+ EXPECT_EQ(5u, observer()->moved_count());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u));
+
+ // Order is now MCA, A, C. Remove C.
ASSERT_TRUE(RemoveExtension(browser_action_c()));
EXPECT_EQ(3u, observer()->removed_count());
+ EXPECT_EQ(2u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
+
+ // Order is now A, MCA. Remove A.
+ ASSERT_TRUE(RemoveExtension(browser_action_a()));
+ EXPECT_EQ(4u, observer()->removed_count());
EXPECT_EQ(1u, num_toolbar_items());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
// Load extension C again.
ASSERT_TRUE(AddExtension(browser_action_c()));
@@ -393,197 +465,221 @@ TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarReorderAndReinsert) {
// Extension C loaded again.
EXPECT_EQ(5u, observer()->inserted_count());
EXPECT_EQ(2u, num_toolbar_items());
- // Make sure it gets its old spot in the list (at the very end).
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u));
+ // Make sure it gets its old spot in the list (at the end).
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(1u));
}
// Test that order persists after unloading and disabling, but not across
// uninstallation.
-TEST_F(ExtensionToolbarModelUnitTest,
- ExtensionToolbarUnloadDisableAndUninstall) {
+TEST_F(ToolbarActionsModelUnitTest,
+ ActionsToolbarUnloadDisableAndUninstall) {
Init();
+ // One component action was added when the model was initialized.
+ EXPECT_EQ(1u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+
// Add the three browser action extensions.
ASSERT_TRUE(AddBrowserActionExtensions());
- // Verify the three extensions are in the model in the proper order: A, B, C.
- EXPECT_EQ(3u, num_toolbar_items());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u));
+ // Verify the four actions are in the model in the proper order:
+ // MCA, A, B, C.
+ EXPECT_EQ(4u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
// Unload B, then C, then A, and then reload C, then A, then B.
ASSERT_TRUE(RemoveExtension(browser_action_b()));
ASSERT_TRUE(RemoveExtension(browser_action_c()));
ASSERT_TRUE(RemoveExtension(browser_action_a()));
- EXPECT_EQ(0u, num_toolbar_items()); // Sanity check: all gone?
+ // Sanity check: all gone except the component action (MCA)?
+ EXPECT_EQ(1u, num_toolbar_items());
ASSERT_TRUE(AddExtension(browser_action_c()));
ASSERT_TRUE(AddExtension(browser_action_a()));
ASSERT_TRUE(AddExtension(browser_action_b()));
- EXPECT_EQ(3u, num_toolbar_items()); // Sanity check: all back?
+ EXPECT_EQ(4u, num_toolbar_items()); // Sanity check: all back?
EXPECT_EQ(0u, observer()->moved_count());
// Even though we unloaded and reloaded in a different order, the original
- // order (A, B, C) should be preserved.
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u));
+ // order (MCA, A, B, C) should be preserved.
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
// Disabling extensions should also preserve order.
service()->DisableExtension(browser_action_b()->id(),
- Extension::DISABLE_USER_ACTION);
+ extensions::Extension::DISABLE_USER_ACTION);
service()->DisableExtension(browser_action_c()->id(),
- Extension::DISABLE_USER_ACTION);
+ extensions::Extension::DISABLE_USER_ACTION);
service()->DisableExtension(browser_action_a()->id(),
- Extension::DISABLE_USER_ACTION);
+ extensions::Extension::DISABLE_USER_ACTION);
service()->EnableExtension(browser_action_c()->id());
service()->EnableExtension(browser_action_a()->id());
service()->EnableExtension(browser_action_b()->id());
- // Make sure we still get the original A, B, C order.
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u));
+ // Make sure we still get the original MCA, A, B, C order.
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
// Move browser_action_b() to be first.
- toolbar_model()->MoveExtensionIcon(browser_action_b()->id(), 0);
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(0u));
+ toolbar_model()->MoveActionIcon(browser_action_b()->id(), 0);
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(0u));
// Uninstall Extension B.
service()->UninstallExtension(browser_action_b()->id(),
- UNINSTALL_REASON_FOR_TESTING,
+ extensions::UNINSTALL_REASON_FOR_TESTING,
base::Bind(&base::DoNothing),
NULL); // Ignore error.
- // List contains only A and C now. Validate that.
- EXPECT_EQ(2u, num_toolbar_items());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u));
+ // List contains only MCA, A, and C now. Validate that.
+ EXPECT_EQ(3u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u));
ASSERT_TRUE(AddExtension(browser_action_b()));
// Make sure Extension B is _not_ first (its old position should have been
- // forgotten at uninstall time). Order should be A, C, B.
- EXPECT_EQ(3u, num_toolbar_items());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(2u));
+ // forgotten at uninstall time). Order should be MCA, A, C, B.
+ EXPECT_EQ(4u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(3u));
}
-TEST_F(ExtensionToolbarModelUnitTest, ReorderOnPrefChange) {
+TEST_F(ToolbarActionsModelUnitTest, ReorderOnPrefChange) {
Init();
+ // One component action was added when the model was initialized.
+ EXPECT_EQ(1u, num_toolbar_items());
+
// Add the three browser action extensions.
ASSERT_TRUE(AddBrowserActionExtensions());
- EXPECT_EQ(3u, num_toolbar_items());
+ EXPECT_EQ(4u, num_toolbar_items());
// Change the value of the toolbar preference.
- ExtensionIdList new_order;
+ ActionIdList new_order;
new_order.push_back(browser_action_c()->id());
new_order.push_back(browser_action_b()->id());
- ExtensionPrefs::Get(profile())->SetToolbarOrder(new_order);
+ extensions::ExtensionPrefs::Get(profile())->SetToolbarOrder(new_order);
// Verify order is changed.
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u));
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(2u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(3u));
}
-// Test that new extensions are always visible on installation and inserted at
-// the "end" of the visible section.
-TEST_F(ExtensionToolbarModelUnitTest, NewToolbarExtensionsAreVisible) {
+// Test that new extension actions are always visible on installation and
+// inserted at the "end" of the visible section.
+TEST_F(ToolbarActionsModelUnitTest, NewToolbarExtensionsAreVisible) {
Init();
// Three extensions with actions.
- scoped_refptr<const Extension> extension_a =
- extension_action_test_util::CreateActionExtension(
- "a", extension_action_test_util::BROWSER_ACTION);
- scoped_refptr<const Extension> extension_b =
- extension_action_test_util::CreateActionExtension(
- "b", extension_action_test_util::BROWSER_ACTION);
- scoped_refptr<const Extension> extension_c =
- extension_action_test_util::CreateActionExtension(
- "c", extension_action_test_util::BROWSER_ACTION);
- scoped_refptr<const Extension> extension_d =
- extension_action_test_util::CreateActionExtension(
- "d", extension_action_test_util::BROWSER_ACTION);
-
- // We should start off without any extensions.
- EXPECT_EQ(0u, num_toolbar_items());
- EXPECT_EQ(0u, toolbar_model()->visible_icon_count());
+ scoped_refptr<const extensions::Extension> extension_a =
+ extensions::extension_action_test_util::CreateActionExtension(
+ "a", extensions::extension_action_test_util::BROWSER_ACTION);
+ scoped_refptr<const extensions::Extension> extension_b =
+ extensions::extension_action_test_util::CreateActionExtension(
+ "b", extensions::extension_action_test_util::BROWSER_ACTION);
+ scoped_refptr<const extensions::Extension> extension_c =
+ extensions::extension_action_test_util::CreateActionExtension(
+ "c", extensions::extension_action_test_util::BROWSER_ACTION);
+ scoped_refptr<const extensions::Extension> extension_d =
+ extensions::extension_action_test_util::CreateActionExtension(
+ "d", extensions::extension_action_test_util::BROWSER_ACTION);
+
+ // One component action was added when the model was initialized.
+ EXPECT_EQ(1u, num_toolbar_items());
- // Add one extension. It should be visible.
- service()->AddExtension(extension_a.get());
+ // We should start off without any action, but one component action.
EXPECT_EQ(1u, num_toolbar_items());
EXPECT_EQ(1u, toolbar_model()->visible_icon_count());
- EXPECT_EQ(extension_a.get(), GetExtensionAtIndex(0u));
- // Hide all extensions.
+ // Add one action. It should be visible.
+ service()->AddExtension(extension_a.get());
+ EXPECT_EQ(2u, num_toolbar_items());
+ EXPECT_EQ(2u, toolbar_model()->visible_icon_count());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(extension_a.get()->id(), GetActionIdAtIndex(1u));
+
+ // Hide all action.
toolbar_model()->SetVisibleIconCount(0);
EXPECT_EQ(0u, toolbar_model()->visible_icon_count());
- // Add a new extension - it should be visible, so it should be in the first
- // index. The other extension should remain hidden.
+ // Add a new action - it should be visible, so it should be in the first
+ // index. The other action should remain hidden.
service()->AddExtension(extension_b.get());
- EXPECT_EQ(2u, num_toolbar_items());
+ EXPECT_EQ(3u, num_toolbar_items());
EXPECT_EQ(1u, toolbar_model()->visible_icon_count());
- EXPECT_EQ(extension_b.get(), GetExtensionAtIndex(0u));
- EXPECT_EQ(extension_a.get(), GetExtensionAtIndex(1u));
+ EXPECT_EQ(extension_b.get()->id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(extension_a.get()->id(), GetActionIdAtIndex(2u));
- // Show all extensions.
- toolbar_model()->SetVisibleIconCount(2);
- EXPECT_EQ(2u, toolbar_model()->visible_icon_count());
+ // Show all action.
+ toolbar_model()->SetVisibleIconCount(3);
+ EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
EXPECT_TRUE(toolbar_model()->all_icons_visible());
- // Add the third extension. Since all extensions are visible, it should go in
- // the last index.
+ // Add the fourth action. Since all action are visible, it should go in the
+ // last index.
service()->AddExtension(extension_c.get());
- EXPECT_EQ(3u, num_toolbar_items());
- EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
+ EXPECT_EQ(4u, num_toolbar_items());
+ EXPECT_EQ(4u, toolbar_model()->visible_icon_count());
EXPECT_TRUE(toolbar_model()->all_icons_visible());
- EXPECT_EQ(extension_b.get(), GetExtensionAtIndex(0u));
- EXPECT_EQ(extension_a.get(), GetExtensionAtIndex(1u));
- EXPECT_EQ(extension_c.get(), GetExtensionAtIndex(2u));
+ EXPECT_EQ(extension_b.get()->id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(extension_a.get()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(extension_c.get()->id(), GetActionIdAtIndex(3u));
- // Hide one extension (two remaining visible).
- toolbar_model()->SetVisibleIconCount(2);
- EXPECT_EQ(2u, toolbar_model()->visible_icon_count());
+ // Hide one action (three remaining visible).
+ toolbar_model()->SetVisibleIconCount(3);
+ EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
- // Add a fourth extension. It should go at the end of the visible section and
- // be visible, so it increases visible count by 1, and goes into the third
- // index. The hidden extension should remain hidden.
+ // Add a fifth action. It should go at the end of the visible section and
+ // be visible, so it increases visible count by 1, and goes into the fourth
+ // index. The hidden action should remain hidden.
service()->AddExtension(extension_d.get());
- EXPECT_EQ(4u, num_toolbar_items());
- EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
- EXPECT_EQ(extension_b.get(), GetExtensionAtIndex(0u));
- EXPECT_EQ(extension_a.get(), GetExtensionAtIndex(1u));
- EXPECT_EQ(extension_d.get(), GetExtensionAtIndex(2u));
- EXPECT_EQ(extension_c.get(), GetExtensionAtIndex(3u));
+ EXPECT_EQ(5u, num_toolbar_items());
+ EXPECT_EQ(4u, toolbar_model()->visible_icon_count());
+ EXPECT_EQ(extension_b.get()->id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(extension_a.get()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(extension_d.get()->id(), GetActionIdAtIndex(3u));
+ EXPECT_EQ(extension_c.get()->id(), GetActionIdAtIndex(4u));
}
-TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarHighlightMode) {
+TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarHighlightMode) {
Init();
- EXPECT_FALSE(toolbar_model()->HighlightExtensions(
- ExtensionIdList(), ExtensionToolbarModel::HIGHLIGHT_WARNING));
+ // One component action was added when the model was initialized.
+ EXPECT_EQ(1u, num_toolbar_items());
+
+ EXPECT_FALSE(toolbar_model()->HighlightActions(
+ ActionIdList(), ToolbarActionsModel::HIGHLIGHT_WARNING));
EXPECT_EQ(0, observer()->highlight_mode_count());
// Add the three browser action extensions.
ASSERT_TRUE(AddBrowserActionExtensions());
- EXPECT_EQ(3u, num_toolbar_items());
+ EXPECT_EQ(4u, num_toolbar_items());
// Start with a visible count of 2 (non-zero, and not all).
toolbar_model()->SetVisibleIconCount(2u);
// Highlight one extension.
- ExtensionIdList extension_ids;
- extension_ids.push_back(browser_action_b()->id());
- toolbar_model()->HighlightExtensions(
- extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING);
+ ActionIdList action_ids;
+ action_ids.push_back(browser_action_b()->id());
+ toolbar_model()->HighlightActions(
+ action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
EXPECT_EQ(1, observer()->highlight_mode_count());
EXPECT_TRUE(toolbar_model()->is_highlighting());
-
EXPECT_EQ(1u, num_toolbar_items());
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(0u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(0u));
EXPECT_EQ(1u, toolbar_model()->visible_icon_count());
// Stop highlighting.
@@ -592,10 +688,11 @@ TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarHighlightMode) {
EXPECT_FALSE(toolbar_model()->is_highlighting());
// Verify that the extensions are back to normal.
- EXPECT_EQ(3u, num_toolbar_items());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u));
+ EXPECT_EQ(4u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
EXPECT_EQ(2u, toolbar_model()->visible_icon_count());
// Call stop highlighting a second time (shouldn't be notified).
@@ -604,216 +701,245 @@ TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarHighlightMode) {
EXPECT_FALSE(toolbar_model()->is_highlighting());
// Highlight all extensions.
- extension_ids.clear();
- extension_ids.push_back(browser_action_a()->id());
- extension_ids.push_back(browser_action_b()->id());
- extension_ids.push_back(browser_action_c()->id());
- toolbar_model()->HighlightExtensions(
- extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING);
+ action_ids.clear();
+ action_ids.push_back(browser_action_a()->id());
+ action_ids.push_back(browser_action_b()->id());
+ action_ids.push_back(browser_action_c()->id());
+ toolbar_model()->HighlightActions(
+ action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
EXPECT_EQ(1, observer()->highlight_mode_count());
EXPECT_EQ(3u, num_toolbar_items());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u));
EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
// Even though the visible count is 3, we shouldn't adjust the stored
// preference.
- EXPECT_EQ(2, profile()->GetPrefs()->GetInteger(pref_names::kToolbarSize));
-
- // Highlight only extension b (shrink the highlight list).
- extension_ids.clear();
- extension_ids.push_back(browser_action_b()->id());
- toolbar_model()->HighlightExtensions(
- extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING);
+ EXPECT_EQ(2, profile()->GetPrefs()->GetInteger(
+ extensions::pref_names::kToolbarSize));
+
+ // Highlight only extension B (shrink the highlight list).
+ action_ids.clear();
+ action_ids.push_back(browser_action_b()->id());
+ toolbar_model()->HighlightActions(
+ action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
EXPECT_EQ(2, observer()->highlight_mode_count());
EXPECT_EQ(1u, num_toolbar_items());
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(0u));
-
- // Highlight extensions a and b (grow the highlight list).
- extension_ids.clear();
- extension_ids.push_back(browser_action_a()->id());
- extension_ids.push_back(browser_action_b()->id());
- toolbar_model()->HighlightExtensions(
- extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING);
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(0u));
+
+ // Highlight extensions A and B (grow the highlight list).
+ action_ids.clear();
+ action_ids.push_back(browser_action_a()->id());
+ action_ids.push_back(browser_action_b()->id());
+ toolbar_model()->HighlightActions(
+ action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
EXPECT_EQ(3, observer()->highlight_mode_count());
EXPECT_EQ(2u, num_toolbar_items());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(1u));
// Highlight no extensions (empty the highlight list).
- extension_ids.clear();
- toolbar_model()->HighlightExtensions(
- extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING);
+ action_ids.clear();
+ toolbar_model()->HighlightActions(
+ action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
EXPECT_EQ(2, observer()->highlight_mode_count());
EXPECT_FALSE(toolbar_model()->is_highlighting());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u));
-
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
// Our toolbar size should be back to normal.
EXPECT_EQ(2u, toolbar_model()->visible_icon_count());
- EXPECT_EQ(2, profile()->GetPrefs()->GetInteger(pref_names::kToolbarSize));
+ EXPECT_EQ(2, profile()->GetPrefs()->GetInteger(
+ extensions::pref_names::kToolbarSize));
}
-TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarHighlightModeRemove) {
+TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarHighlightModeRemove) {
Init();
+ // One component action was added when the model was initialized.
+ EXPECT_EQ(1u, num_toolbar_items());
+
// Add the three browser action extensions.
ASSERT_TRUE(AddBrowserActionExtensions());
- EXPECT_EQ(3u, num_toolbar_items());
+ EXPECT_EQ(4u, num_toolbar_items());
// Highlight two of the extensions.
- ExtensionIdList extension_ids;
- extension_ids.push_back(browser_action_a()->id());
- extension_ids.push_back(browser_action_b()->id());
- toolbar_model()->HighlightExtensions(
- extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING);
+ ActionIdList action_ids;
+ action_ids.push_back(browser_action_a()->id());
+ action_ids.push_back(browser_action_b()->id());
+ toolbar_model()->HighlightActions(
+ action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
EXPECT_TRUE(toolbar_model()->is_highlighting());
EXPECT_EQ(1, observer()->highlight_mode_count());
EXPECT_EQ(2u, num_toolbar_items());
// Disable one of them - only one should remain highlighted.
service()->DisableExtension(browser_action_a()->id(),
- Extension::DISABLE_USER_ACTION);
+ extensions::Extension::DISABLE_USER_ACTION);
EXPECT_TRUE(toolbar_model()->is_highlighting());
EXPECT_EQ(1u, num_toolbar_items());
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(0u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(0u));
// Uninstall the remaining highlighted extension. This should result in
// highlight mode exiting.
service()->UninstallExtension(browser_action_b()->id(),
- UNINSTALL_REASON_FOR_TESTING,
+ extensions::UNINSTALL_REASON_FOR_TESTING,
base::Bind(&base::DoNothing),
NULL); // Ignore error.
EXPECT_FALSE(toolbar_model()->is_highlighting());
EXPECT_EQ(0, observer()->highlight_mode_count());
- EXPECT_EQ(1u, num_toolbar_items());
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u));
+ EXPECT_EQ(2u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(1u));
// Test that removing an unhighlighted extension still works.
- // Reinstall extension b, and then highlight extension c.
+ // Reinstall extension B, and then highlight extension C.
ASSERT_TRUE(AddExtension(browser_action_b()));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u));
- extension_ids.clear();
- extension_ids.push_back(browser_action_c()->id());
- toolbar_model()->HighlightExtensions(
- extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING);
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
+ action_ids.clear();
+ action_ids.push_back(browser_action_c()->id());
+ toolbar_model()->HighlightActions(
+ action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
EXPECT_EQ(1, observer()->highlight_mode_count());
EXPECT_TRUE(toolbar_model()->is_highlighting());
EXPECT_EQ(1u, num_toolbar_items());
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(0u));
- // Uninstalling b should not have visible impact.
+ // Uninstalling B should not have visible impact.
service()->UninstallExtension(browser_action_b()->id(),
- UNINSTALL_REASON_FOR_TESTING,
+ extensions::UNINSTALL_REASON_FOR_TESTING,
base::Bind(&base::DoNothing),
NULL); // Ignore error.
EXPECT_TRUE(toolbar_model()->is_highlighting());
EXPECT_EQ(1, observer()->highlight_mode_count());
EXPECT_EQ(1u, num_toolbar_items());
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(0u));
- // When we stop, only extension c should remain.
+ // When we stop, only MCA and C should remain.
toolbar_model()->StopHighlighting();
EXPECT_FALSE(toolbar_model()->is_highlighting());
EXPECT_EQ(0, observer()->highlight_mode_count());
- EXPECT_EQ(1u, num_toolbar_items());
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u));
+ EXPECT_EQ(2u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(1u));
}
-TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarHighlightModeAdd) {
+TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarHighlightModeAdd) {
Init();
+ // One component action was added when the model was initialized.
+ EXPECT_EQ(1u, num_toolbar_items());
+
// Add the three browser action extensions.
ASSERT_TRUE(AddBrowserActionExtensions());
- EXPECT_EQ(3u, num_toolbar_items());
+ EXPECT_EQ(4u, num_toolbar_items());
- // Remove one (down to two).
+ // Remove one (down to three).
ASSERT_TRUE(RemoveExtension(browser_action_c()));
- // Highlight one of the two extensions.
- ExtensionIdList extension_ids;
- extension_ids.push_back(browser_action_a()->id());
- toolbar_model()->HighlightExtensions(
- extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING);
+ // Highlight one of the three actions (one of the two extensinos).
+ ActionIdList action_ids;
+ action_ids.push_back(browser_action_a()->id());
+ toolbar_model()->HighlightActions(
+ action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
EXPECT_TRUE(toolbar_model()->is_highlighting());
EXPECT_EQ(1u, num_toolbar_items());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u));
// Adding a new extension should have no visible effect.
ASSERT_TRUE(AddExtension(browser_action_c()));
EXPECT_TRUE(toolbar_model()->is_highlighting());
EXPECT_EQ(1u, num_toolbar_items());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u));
// When we stop highlighting, we should see the new extension show up.
toolbar_model()->StopHighlighting();
EXPECT_FALSE(toolbar_model()->is_highlighting());
- EXPECT_EQ(3u, num_toolbar_items());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u));
+ EXPECT_EQ(4u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
}
-// Test that the extension toolbar maintains the proper size, even after a pref
+// Test that the action toolbar maintains the proper size, even after a pref
// change.
-TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarSizeAfterPrefChange) {
+TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarSizeAfterPrefChange) {
Init();
+ // One component action was added when the model was initialized.
+ EXPECT_EQ(1u, num_toolbar_items());
+
// Add the three browser action extensions.
ASSERT_TRUE(AddBrowserActionExtensions());
- EXPECT_EQ(3u, num_toolbar_items());
+ EXPECT_EQ(4u, num_toolbar_items());
// Should be at max size.
EXPECT_TRUE(toolbar_model()->all_icons_visible());
EXPECT_EQ(num_toolbar_items(), toolbar_model()->visible_icon_count());
- toolbar_model()->OnExtensionToolbarPrefChange();
+ toolbar_model()->OnActionToolbarPrefChange();
// Should still be at max size.
EXPECT_TRUE(toolbar_model()->all_icons_visible());
EXPECT_EQ(num_toolbar_items(), toolbar_model()->visible_icon_count());
}
// Test that, in the absence of the extension-action-redesign switch, the
-// model only contains extensions with browser actions.
-TEST_F(ExtensionToolbarModelUnitTest, TestToolbarExtensionTypesNoSwitch) {
+// model only contains extensions with browser actions and component actions.
+TEST_F(ToolbarActionsModelUnitTest, TestToolbarExtensionTypesNoSwitch) {
Init();
- ASSERT_TRUE(AddActionExtensions());
+ // One component action was added when the model was initialized.
EXPECT_EQ(1u, num_toolbar_items());
- EXPECT_EQ(browser_action(), GetExtensionAtIndex(0u));
+
+ ASSERT_TRUE(AddActionExtensions());
+
+ EXPECT_EQ(2u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action()->id(), GetActionIdAtIndex(1u));
}
// Test that, with the extension-action-redesign switch, the model contains
// all types of extensions, except those which should not be displayed on the
// toolbar (like component extensions).
-TEST_F(ExtensionToolbarModelUnitTest, TestToolbarExtensionTypesSwitch) {
- FeatureSwitch::ScopedOverride enable_redesign(
- FeatureSwitch::extension_action_redesign(), true);
+TEST_F(ToolbarActionsModelUnitTest, TestToolbarExtensionTypesSwitch) {
+ extensions::FeatureSwitch::ScopedOverride enable_redesign(
+ extensions::FeatureSwitch::extension_action_redesign(), true);
Init();
+
+ // One component action was added when the model was initialized.
+ EXPECT_EQ(1u, num_toolbar_items());
+
ASSERT_TRUE(AddActionExtensions());
// With the switch on, extensions with page actions and no action should also
// be displayed in the toolbar.
- EXPECT_EQ(3u, num_toolbar_items());
- EXPECT_EQ(browser_action(), GetExtensionAtIndex(0u));
- EXPECT_EQ(page_action(), GetExtensionAtIndex(1u));
- EXPECT_EQ(no_action(), GetExtensionAtIndex(2u));
+ EXPECT_EQ(4u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(page_action()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(no_action()->id(), GetActionIdAtIndex(3u));
}
// Test that hiding actions on the toolbar results in their removal from the
// model when the redesign switch is not enabled.
-TEST_F(ExtensionToolbarModelUnitTest,
- ExtensionToolbarActionsVisibilityNoSwitch) {
+TEST_F(ToolbarActionsModelUnitTest,
+ ActionsToolbarActionsVisibilityNoSwitch) {
Init();
- ExtensionActionAPI* action_api = ExtensionActionAPI::Get(profile());
+ // One component action was added when the model was initialized.
+ EXPECT_EQ(1u, num_toolbar_items());
+
+ extensions::ExtensionActionAPI* action_api =
+ extensions::ExtensionActionAPI::Get(profile());
ASSERT_TRUE(AddBrowserActionExtensions());
- // Sanity check: Order should start as A B C.
- EXPECT_EQ(3u, num_toolbar_items());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u));
+ // Sanity check: Order should start as MCA, A , B, C.
+ EXPECT_EQ(4u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
// By default, all actions should be visible.
EXPECT_TRUE(action_api->GetBrowserActionVisibility(browser_action_a()->id()));
@@ -824,24 +950,27 @@ TEST_F(ExtensionToolbarModelUnitTest,
action_api->SetBrowserActionVisibility(browser_action_b()->id(), false);
EXPECT_FALSE(action_api->GetBrowserActionVisibility(
browser_action_b()->id()));
- // Thus, there should now only be two items on the toolbar - A and C.
- EXPECT_EQ(2u, num_toolbar_items());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u));
+ // Thus, there should now only be three items on the toolbar: MCA, A, C.
+ EXPECT_EQ(3u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u));
// Resetting the visibility to 'true' should result in the extension being
// added back at its original position.
action_api->SetBrowserActionVisibility(browser_action_b()->id(), true);
EXPECT_TRUE(action_api->GetBrowserActionVisibility(browser_action_b()->id()));
- // So the toolbar order should be A B C.
- EXPECT_EQ(3u, num_toolbar_items());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u));
+ // So the toolbar order should be MCA, A, B, C.
+ EXPECT_EQ(4u, num_toolbar_items());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
}
-TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarIncognitoModeTest) {
+TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarIncognitoModeTest) {
Init();
+
ASSERT_TRUE(AddBrowserActionExtensions());
// Give two extensions incognito access.
@@ -849,61 +978,67 @@ TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarIncognitoModeTest) {
// util::SetIsIncognitoEnabled because the latter tries to reload the
// extension, which requries a filepath associated with the extension (and,
// for this test, reloading the extension is irrelevant to us).
- ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile());
+ extensions::ExtensionPrefs* extension_prefs =
+ extensions::ExtensionPrefs::Get(profile());
extension_prefs->SetIsIncognitoEnabled(browser_action_b()->id(), true);
extension_prefs->SetIsIncognitoEnabled(browser_action_c()->id(), true);
- util::SetIsIncognitoEnabled(browser_action_b()->id(), profile(), true);
- util::SetIsIncognitoEnabled(browser_action_c()->id(), profile(), true);
+ extensions::util::SetIsIncognitoEnabled(browser_action_b()->id(),
+ profile(), true);
+ extensions::util::SetIsIncognitoEnabled(browser_action_c()->id(),
+ profile(), true);
// Move C to the second index.
- toolbar_model()->MoveExtensionIcon(browser_action_c()->id(), 1u);
- // Set visible count to 2 so that c is overflowed. State is A C [B].
- toolbar_model()->SetVisibleIconCount(2);
+ toolbar_model()->MoveActionIcon(browser_action_c()->id(), 2u);
+ // Set visible count to 3 so that C is overflowed. State is MCA, A, C, [B].
+ toolbar_model()->SetVisibleIconCount(3);
EXPECT_EQ(1u, observer()->moved_count());
// Get an incognito profile and toolbar.
- ExtensionToolbarModel* incognito_model =
- extension_action_test_util::CreateToolbarModelForProfile(
+ ToolbarActionsModel* incognito_model =
+ extensions::extension_action_test_util::CreateToolbarModelForProfile(
profile()->GetOffTheRecordProfile());
- ExtensionToolbarModelTestObserver incognito_observer(incognito_model);
+ ToolbarActionsModelTestObserver incognito_observer(incognito_model);
EXPECT_EQ(0u, incognito_observer.moved_count());
- // We should have two items, C and B, and the order should be preserved from
- // the original model.
- EXPECT_EQ(2u, incognito_model->toolbar_items().size());
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u, incognito_model));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u, incognito_model));
+ // We should have three items: MCA, C, B, and the order should be preserved
+ // from the original model.
+ EXPECT_EQ(3u, incognito_model->toolbar_items().size());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u, incognito_model));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(1u, incognito_model));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u, incognito_model));
- // Extensions in the overflow menu in the regular toolbar should remain in
- // overflow in the incognito toolbar. So, we should have C [B].
- EXPECT_EQ(1u, incognito_model->visible_icon_count());
- // The regular model should still have two icons visible.
- EXPECT_EQ(2u, toolbar_model()->visible_icon_count());
+ // Actions in the overflow menu in the regular toolbar should remain in
+ // overflow in the incognito toolbar. So, we should have MCA, C, [B].
+ EXPECT_EQ(2u, incognito_model->visible_icon_count());
+ // The regular model should still have three icons visible.
+ EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
// Changing the incognito model size should not affect the regular model.
incognito_model->SetVisibleIconCount(0);
EXPECT_EQ(0u, incognito_model->visible_icon_count());
- EXPECT_EQ(2u, toolbar_model()->visible_icon_count());
+ EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
- // Expanding the incognito model to 2 should register as "all icons"
+ // Expanding the incognito model to 3 should register as "all icons"
// since it is all of the incognito-enabled extensions.
- incognito_model->SetVisibleIconCount(2u);
- EXPECT_EQ(2u, incognito_model->visible_icon_count());
+ incognito_model->SetVisibleIconCount(3u);
+ EXPECT_EQ(3u, incognito_model->visible_icon_count());
EXPECT_TRUE(incognito_model->all_icons_visible());
// Moving icons in the incognito toolbar should not affect the regular
- // toolbar. Incognito currently has C B...
- incognito_model->MoveExtensionIcon(browser_action_b()->id(), 0u);
- // So now it should be B C...
+ // toolbar. Incognito currently has MCA, C, B...
+ incognito_model->MoveActionIcon(browser_action_b()->id(), 0u);
+ // So now it should be B, MCA, C...
EXPECT_EQ(1u, incognito_observer.moved_count());
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(0u, incognito_model));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u, incognito_model));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(0u, incognito_model));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u, incognito_model));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u, incognito_model));
// ... and the regular toolbar should be unaffected.
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(2u));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(3u));
// Similarly, the observer for the regular model should not have received
// any updates.
@@ -911,15 +1046,14 @@ TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarIncognitoModeTest) {
// And performing moves on the regular model should have no effect on the
// incognito model or its observers.
- toolbar_model()->MoveExtensionIcon(browser_action_c()->id(), 2u);
+ toolbar_model()->MoveActionIcon(browser_action_c()->id(), 2u);
EXPECT_EQ(2u, observer()->moved_count());
EXPECT_EQ(1u, incognito_observer.moved_count());
}
// Test that enabling extensions incognito with an active incognito profile
// works.
-TEST_F(ExtensionToolbarModelUnitTest,
- ExtensionToolbarIncognitoEnableExtension) {
+TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarIncognitoEnableExtension) {
Init();
const char* kManifest =
@@ -935,21 +1069,22 @@ TEST_F(ExtensionToolbarModelUnitTest,
// needs to be notified of the reload, we need it this time (as opposed to
// above, where we simply set the prefs before the incognito bar was
// created.
- TestExtensionDir dir1;
+ extensions::TestExtensionDir dir1;
dir1.WriteManifest(base::StringPrintf(kManifest, "incognito1"));
- TestExtensionDir dir2;
+ extensions::TestExtensionDir dir2;
dir2.WriteManifest(base::StringPrintf(kManifest, "incognito2"));
- TestExtensionDir* dirs[] = { &dir1, &dir2 };
- const Extension* extensions[] = { nullptr, nullptr };
+ extensions::TestExtensionDir* dirs[] = { &dir1, &dir2 };
+ const extensions::Extension* extensions[] = { nullptr, nullptr };
for (size_t i = 0; i < arraysize(dirs); ++i) {
// The extension id will be calculated from the file path; we need this to
// wait for the extension to load.
base::FilePath path_for_id =
base::MakeAbsoluteFilePath(dirs[i]->unpacked_path());
std::string id = crx_file::id_util::GenerateIdForPath(path_for_id);
- TestExtensionRegistryObserver observer(registry(), id);
- UnpackedInstaller::Create(service())->Load(dirs[i]->unpacked_path());
+ extensions::TestExtensionRegistryObserver observer(registry(), id);
+ extensions::UnpackedInstaller::Create(service())->Load(
+ dirs[i]->unpacked_path());
observer.WaitForExtensionLoaded();
extensions[i] = registry()->enabled_extensions().GetByID(id);
ASSERT_TRUE(extensions[i]);
@@ -961,58 +1096,62 @@ TEST_F(ExtensionToolbarModelUnitTest,
std::string extension_b = extensions[1]->id();
// The first model should have both extensions visible.
- EXPECT_EQ(2u, toolbar_model()->toolbar_items().size());
- EXPECT_EQ(extension_a, GetExtensionAtIndex(0)->id());
- EXPECT_EQ(extension_b, GetExtensionAtIndex(1)->id());
+ EXPECT_EQ(3u, toolbar_model()->toolbar_items().size());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(extension_a, GetActionIdAtIndex(1u));
+ EXPECT_EQ(extension_b, GetActionIdAtIndex(2u));
- // Set the model to only show one extension, so the order is A [B].
+ // Set the model to only show one extension, so the order is MCA, A, [B].
toolbar_model()->SetVisibleIconCount(1u);
// Get an incognito profile and toolbar.
- ExtensionToolbarModel* incognito_model =
- extension_action_test_util::CreateToolbarModelForProfile(
+ ToolbarActionsModel* incognito_model =
+ extensions::extension_action_test_util::CreateToolbarModelForProfile(
profile()->GetOffTheRecordProfile());
- ExtensionToolbarModelTestObserver incognito_observer(incognito_model);
+ ToolbarActionsModelTestObserver incognito_observer(incognito_model);
- // Right now, no extensions are enabled in incognito mode.
- EXPECT_EQ(0u, incognito_model->toolbar_items().size());
+ // Right now, only the component action is enabled in incognito mode.
+ EXPECT_EQ(1u, incognito_model->toolbar_items().size());
- // Set extension b (which is overflowed) to be enabled in incognito. This
+ // Set extension B (which is overflowed) to be enabled in incognito. This
// results in b reloading, so wait for it.
{
- TestExtensionRegistryObserver observer(registry(), extension_b);
- util::SetIsIncognitoEnabled(extension_b, profile(), true);
+ extensions::TestExtensionRegistryObserver observer(registry(), extension_b);
+ extensions::util::SetIsIncognitoEnabled(extension_b, profile(), true);
observer.WaitForExtensionLoaded();
}
- // Now, we should have one icon in the incognito bar. But, since B is
+ // Now, we should have two icons in the incognito bar. But, since B is
// overflowed in the main bar, it shouldn't be visible.
- EXPECT_EQ(1u, incognito_model->toolbar_items().size());
- EXPECT_EQ(extension_b, GetExtensionAtIndex(0u, incognito_model)->id());
- EXPECT_EQ(0u, incognito_model->visible_icon_count());
+ EXPECT_EQ(2u, incognito_model->toolbar_items().size());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u, incognito_model));
+ EXPECT_EQ(extension_b, GetActionIdAtIndex(1u, incognito_model));
+ EXPECT_EQ(1u, incognito_model->visible_icon_count());
// Also enable extension a for incognito (again, wait for the reload).
{
- TestExtensionRegistryObserver observer(registry(), extension_a);
- util::SetIsIncognitoEnabled(extension_a, profile(), true);
+ extensions::TestExtensionRegistryObserver observer(registry(), extension_a);
+ extensions::util::SetIsIncognitoEnabled(extension_a, profile(), true);
observer.WaitForExtensionLoaded();
}
// Now, both extensions should be enabled in incognito mode. In addition, the
- // incognito toolbar should have expanded to show extension a (since it isn't
+ // incognito toolbar should have expanded to show extension A (since it isn't
// overflowed in the main bar).
- EXPECT_EQ(2u, incognito_model->toolbar_items().size());
- EXPECT_EQ(extension_a, GetExtensionAtIndex(0u, incognito_model)->id());
- EXPECT_EQ(extension_b, GetExtensionAtIndex(1u, incognito_model)->id());
+ EXPECT_EQ(3u, incognito_model->toolbar_items().size());
+ EXPECT_EQ(component_action_id(),
+ GetActionIdAtIndex(0u, incognito_model));
+ EXPECT_EQ(extension_a, GetActionIdAtIndex(1u, incognito_model));
+ EXPECT_EQ(extension_b, GetActionIdAtIndex(2u, incognito_model));
EXPECT_EQ(1u, incognito_model->visible_icon_count());
}
// Test that hiding actions on the toolbar results in sending them to the
// overflow menu when the redesign switch is enabled.
-TEST_F(ExtensionToolbarModelUnitTest,
- ExtensionToolbarActionsVisibilityWithSwitch) {
- FeatureSwitch::ScopedOverride enable_redesign(
- FeatureSwitch::extension_action_redesign(), true);
+TEST_F(ToolbarActionsModelUnitTest,
+ ActionsToolbarActionsVisibilityWithSwitch) {
+ extensions::FeatureSwitch::ScopedOverride enable_redesign(
+ extensions::FeatureSwitch::extension_action_redesign(), true);
Init();
// We choose to use all types of extensions here, since the misnamed
@@ -1020,18 +1159,20 @@ TEST_F(ExtensionToolbarModelUnitTest,
ASSERT_TRUE(AddActionExtensions());
// For readability, alias extensions A B C.
- const Extension* extension_a = browser_action();
- const Extension* extension_b = page_action();
- const Extension* extension_c = no_action();
+ const extensions::Extension* extension_a = browser_action();
+ const extensions::Extension* extension_b = page_action();
+ const extensions::Extension* extension_c = no_action();
- // Sanity check: Order should start as A B C, with all three visible.
- EXPECT_EQ(3u, num_toolbar_items());
+ // Sanity check: Order should start as MCA, A, B, C, with all four visible.
+ EXPECT_EQ(4u, num_toolbar_items());
EXPECT_TRUE(toolbar_model()->all_icons_visible());
- EXPECT_EQ(extension_a, GetExtensionAtIndex(0u));
- EXPECT_EQ(extension_b, GetExtensionAtIndex(1u));
- EXPECT_EQ(extension_c, GetExtensionAtIndex(2u));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(extension_a->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(extension_b->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(extension_c->id(), GetActionIdAtIndex(3u));
- ExtensionActionAPI* action_api = ExtensionActionAPI::Get(profile());
+ extensions::ExtensionActionAPI* action_api =
+ extensions::ExtensionActionAPI::Get(profile());
// By default, all actions should be visible.
EXPECT_TRUE(action_api->GetBrowserActionVisibility(extension_a->id()));
@@ -1041,151 +1182,163 @@ TEST_F(ExtensionToolbarModelUnitTest,
// Hiding an action should result in it being sent to the overflow menu.
action_api->SetBrowserActionVisibility(extension_b->id(), false);
- // Thus, the order should be A C B, with B in the overflow.
- EXPECT_EQ(3u, num_toolbar_items());
- EXPECT_EQ(2u, toolbar_model()->visible_icon_count());
- EXPECT_EQ(extension_a, GetExtensionAtIndex(0u));
- EXPECT_EQ(extension_c, GetExtensionAtIndex(1u));
- EXPECT_EQ(extension_b, GetExtensionAtIndex(2u));
+ // Thus, the order should be MCA, A, C, B, with B in the overflow.
+ EXPECT_EQ(4u, num_toolbar_items());
+ EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(extension_a->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(extension_c->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(extension_b->id(), GetActionIdAtIndex(3u));
// Hiding an extension's action should result in it being sent to the overflow
// as well, but as the _first_ extension in the overflow.
action_api->SetBrowserActionVisibility(extension_a->id(), false);
- // Thus, the order should be C A B, with A and B in the overflow.
- EXPECT_EQ(3u, num_toolbar_items());
- EXPECT_EQ(1u, toolbar_model()->visible_icon_count());
- EXPECT_EQ(extension_c, GetExtensionAtIndex(0u));
- EXPECT_EQ(extension_a, GetExtensionAtIndex(1u));
- EXPECT_EQ(extension_b, GetExtensionAtIndex(2u));
+ // Thus, the order should be MCA, C, A, B, with A and B in the overflow.
+ EXPECT_EQ(4u, num_toolbar_items());
+ EXPECT_EQ(2u, toolbar_model()->visible_icon_count());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(extension_c->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(extension_a->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(extension_b->id(), GetActionIdAtIndex(3u));
// Resetting A's visibility to true should send it back to the visible icons
// (and should grow visible icons by 1), but it should be added to the end of
// the visible icon list (not to its original position).
action_api->SetBrowserActionVisibility(extension_a->id(), true);
- // So order is C A B, with only B in the overflow.
- EXPECT_EQ(3u, num_toolbar_items());
- EXPECT_EQ(2u, toolbar_model()->visible_icon_count());
- EXPECT_EQ(extension_c, GetExtensionAtIndex(0u));
- EXPECT_EQ(extension_a, GetExtensionAtIndex(1u));
- EXPECT_EQ(extension_b, GetExtensionAtIndex(2u));
+ // So order is MCA, C, A, B, with only B in the overflow.
+ EXPECT_EQ(4u, num_toolbar_items());
+ EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(extension_c->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(extension_a->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(extension_b->id(), GetActionIdAtIndex(3u));
- // Resetting B to be visible should make the order C A B, with no overflow.
+ // Resetting B to be visible should make the order MCA, C, A, B, with no
+ // overflow.
action_api->SetBrowserActionVisibility(extension_b->id(), true);
- EXPECT_EQ(3u, num_toolbar_items());
+ EXPECT_EQ(4u, num_toolbar_items());
EXPECT_TRUE(toolbar_model()->all_icons_visible());
- EXPECT_EQ(extension_c, GetExtensionAtIndex(0u));
- EXPECT_EQ(extension_a, GetExtensionAtIndex(1u));
- EXPECT_EQ(extension_b, GetExtensionAtIndex(2u));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
+ EXPECT_EQ(extension_c->id(), GetActionIdAtIndex(1u));
+ EXPECT_EQ(extension_a->id(), GetActionIdAtIndex(2u));
+ EXPECT_EQ(extension_b->id(), GetActionIdAtIndex(3u));
}
// Test that observers receive no Added notifications until after the
// ExtensionSystem has initialized.
-TEST_F(ExtensionToolbarModelUnitTest, ModelWaitsForExtensionSystemReady) {
+TEST_F(ToolbarActionsModelUnitTest, ModelWaitsForExtensionSystemReady) {
InitializeEmptyExtensionService();
- ExtensionToolbarModel* toolbar_model =
- extension_action_test_util::
+ ToolbarActionsModel* toolbar_model =
+ extensions::extension_action_test_util::
CreateToolbarModelForProfileWithoutWaitingForReady(profile());
- ExtensionToolbarModelTestObserver model_observer(toolbar_model);
+ ToolbarActionsModelTestObserver model_observer(toolbar_model);
+
EXPECT_TRUE(AddBrowserActionExtensions());
// Since the model hasn't been initialized (the ExtensionSystem::ready task
// hasn't been run), there should be no insertion notifications.
EXPECT_EQ(0u, model_observer.inserted_count());
EXPECT_EQ(0u, model_observer.initialized_count());
- EXPECT_FALSE(toolbar_model->extensions_initialized());
+ EXPECT_FALSE(toolbar_model->actions_initialized());
// Run the ready task.
- static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile()))->
- SetReady();
+ static_cast<extensions::TestExtensionSystem*>(
+ extensions::ExtensionSystem::Get(profile()))->SetReady();
// Run tasks posted to TestExtensionSystem.
base::RunLoop().RunUntilIdle();
// We should still have no insertions, but should have an initialized count.
- EXPECT_TRUE(toolbar_model->extensions_initialized());
+ EXPECT_TRUE(toolbar_model->actions_initialized());
EXPECT_EQ(0u, model_observer.inserted_count());
EXPECT_EQ(1u, model_observer.initialized_count());
}
// Check that the toolbar model correctly clears and reorders when it detects
// a preference change.
-TEST_F(ExtensionToolbarModelUnitTest, ToolbarModelPrefChange) {
+TEST_F(ToolbarActionsModelUnitTest, ToolbarModelPrefChange) {
Init();
ASSERT_TRUE(AddBrowserActionExtensions());
- // We should start in the basic A B C order.
+ // We should start in the basic MCA, A, B, C order.
ASSERT_TRUE(browser_action_a());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3));
// Record the difference between the inserted and removed counts. The actual
// value of the counts is not important, but we need to be sure that if we
// call to remove any, we also add them back.
size_t inserted_and_removed_difference =
observer()->inserted_count() - observer()->removed_count();
- // Assign a new order, B C A, and write it in the prefs.
- ExtensionIdList new_order;
+ // Assign a new order, B, C, MCA, A, and write it in the prefs.
+ ActionIdList new_order;
new_order.push_back(browser_action_b()->id());
new_order.push_back(browser_action_c()->id());
+ new_order.push_back(component_action_id());
new_order.push_back(browser_action_a()->id());
- ExtensionPrefs::Get(profile())->SetToolbarOrder(new_order);
+ extensions::ExtensionPrefs::Get(profile())->SetToolbarOrder(new_order);
// Ensure everything has time to run.
base::RunLoop().RunUntilIdle();
// The new order should be reflected in the model.
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(0));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1));
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(2));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(0));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(1));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(2));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(3));
EXPECT_EQ(inserted_and_removed_difference,
observer()->inserted_count() - observer()->removed_count());
}
-TEST_F(ExtensionToolbarModelUnitTest, ComponentExtesionsAddedToEnd) {
+TEST_F(ToolbarActionsModelUnitTest, ComponentExtensionsAddedToEnd) {
Init();
ASSERT_TRUE(AddBrowserActionExtensions());
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3));
const char kName[] = "component";
- DictionaryBuilder manifest;
+ extensions::DictionaryBuilder manifest;
manifest.Set("name", kName)
.Set("description", "An extension")
.Set("manifest_version", 2)
.Set("version", "1.0.0")
- .Set("browser_action", DictionaryBuilder().Pass());
- scoped_refptr<const Extension> component_extension =
- ExtensionBuilder().SetManifest(manifest.Pass())
+ .Set("browser_action", extensions::DictionaryBuilder().Pass());
+ scoped_refptr<const extensions::Extension> component_extension =
+ extensions::ExtensionBuilder().SetManifest(manifest.Pass())
.SetID(crx_file::id_util::GenerateId(kName))
- .SetLocation(Manifest::COMPONENT)
+ .SetLocation(extensions::Manifest::COMPONENT)
.Build();
service()->AddExtension(component_extension.get());
- EXPECT_EQ(component_extension.get(), GetExtensionAtIndex(0));
- EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(1));
- EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(2));
- EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(3));
+ EXPECT_EQ(component_extension.get()->id(), GetActionIdAtIndex(0));
+ EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1));
+ EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(2));
+ EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(3));
+ EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(4));
}
-TEST_F(ExtensionToolbarModelUnitTest,
+TEST_F(ToolbarActionsModelUnitTest,
ToolbarModelHighlightsForToolbarRedesign) {
- FeatureSwitch::ScopedOverride enable_redesign(
- FeatureSwitch::extension_action_redesign(), true);
+ extensions::FeatureSwitch::ScopedOverride enable_redesign(
+ extensions::FeatureSwitch::extension_action_redesign(), true);
InitializeEmptyExtensionService();
EXPECT_TRUE(AddActionExtensions());
- ExtensionToolbarModel* toolbar_model =
- extension_action_test_util::CreateToolbarModelForProfile(profile());
+ ToolbarActionsModel* toolbar_model =
+ extensions::extension_action_test_util::CreateToolbarModelForProfile(
+ profile());
EXPECT_TRUE(toolbar_model);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(ExtensionToolbarIconSurfacingBubbleDelegate::ShouldShowForProfile(
profile()));
EXPECT_TRUE(toolbar_model->is_highlighting());
- EXPECT_EQ(ExtensionToolbarModel::HIGHLIGHT_INFO,
+ EXPECT_EQ(ToolbarActionsModel::HIGHLIGHT_INFO,
toolbar_model->highlight_type());
EXPECT_EQ(3u, toolbar_model->visible_icon_count());
EXPECT_EQ(3u, toolbar_model->toolbar_items().size());
@@ -1195,8 +1348,6 @@ TEST_F(ExtensionToolbarModelUnitTest,
bubble->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS);
EXPECT_FALSE(toolbar_model->is_highlighting());
- EXPECT_EQ(ExtensionToolbarModel::HIGHLIGHT_NONE,
+ EXPECT_EQ(ToolbarActionsModel::HIGHLIGHT_NONE,
toolbar_model->highlight_type());
}
-
-} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698