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

Side by Side 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 rdevlin.cronin@'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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/files/file_util.h" 5 #include "base/files/file_util.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" 10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
11 #include "chrome/browser/extensions/extension_action_manager.h" 11 #include "chrome/browser/extensions/extension_action_manager.h"
12 #include "chrome/browser/extensions/extension_action_test_util.h" 12 #include "chrome/browser/extensions/extension_action_test_util.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/extension_service_test_base.h" 14 #include "chrome/browser/extensions/extension_service_test_base.h"
15 #include "chrome/browser/extensions/extension_toolbar_model.h"
16 #include "chrome/browser/extensions/extension_util.h" 15 #include "chrome/browser/extensions/extension_util.h"
17 #include "chrome/browser/extensions/test_extension_dir.h" 16 #include "chrome/browser/extensions/test_extension_dir.h"
18 #include "chrome/browser/extensions/test_extension_system.h" 17 #include "chrome/browser/extensions/test_extension_system.h"
19 #include "chrome/browser/extensions/unpacked_installer.h" 18 #include "chrome/browser/extensions/unpacked_installer.h"
20 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/sessions/session_tab_helper.h" 20 #include "chrome/browser/sessions/session_tab_helper.h"
22 #include "chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_d elegate.h" 21 #include "chrome/browser/ui/extensions/extension_toolbar_icon_surfacing_bubble_d elegate.h"
22 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h"
23 #include "chrome/browser/ui/toolbar/mock_component_toolbar_actions_factory.h"
24 #include "chrome/browser/ui/toolbar/test_toolbar_action_view_controller.h"
25 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
23 #include "chrome/common/extensions/api/extension_action/action_info.h" 26 #include "chrome/common/extensions/api/extension_action/action_info.h"
24 #include "components/crx_file/id_util.h" 27 #include "components/crx_file/id_util.h"
25 #include "content/public/test/test_renderer_host.h" 28 #include "content/public/test/test_renderer_host.h"
26 #include "content/public/test/web_contents_tester.h" 29 #include "content/public/test/web_contents_tester.h"
27 #include "extensions/browser/extension_prefs.h" 30 #include "extensions/browser/extension_prefs.h"
28 #include "extensions/browser/extension_registry.h" 31 #include "extensions/browser/extension_registry.h"
29 #include "extensions/browser/extension_system.h" 32 #include "extensions/browser/extension_system.h"
30 #include "extensions/browser/pref_names.h" 33 #include "extensions/browser/pref_names.h"
31 #include "extensions/browser/test_extension_registry_observer.h" 34 #include "extensions/browser/test_extension_registry_observer.h"
32 #include "extensions/common/extension.h" 35 #include "extensions/common/extension.h"
33 #include "extensions/common/extension_builder.h" 36 #include "extensions/common/extension_builder.h"
34 #include "extensions/common/feature_switch.h" 37 #include "extensions/common/feature_switch.h"
35 #include "extensions/common/value_builder.h" 38 #include "extensions/common/value_builder.h"
36 39
37 #if defined(USE_AURA) 40 #if defined(USE_AURA)
38 #include "ui/aura/env.h" 41 #include "ui/aura/env.h"
39 #endif 42 #endif
40 43
41 namespace extensions {
42
43 namespace { 44 namespace {
44 45
45 // A simple observer that tracks the number of times certain events occur. 46 // A simple observer that tracks the number of times certain events occur.
46 class ExtensionToolbarModelTestObserver 47 class ToolbarActionsModelTestObserver
47 : public ExtensionToolbarModel::Observer { 48 : public ToolbarActionsModel::Observer {
48 public: 49 public:
49 explicit ExtensionToolbarModelTestObserver(ExtensionToolbarModel* model); 50 explicit ToolbarActionsModelTestObserver(ToolbarActionsModel* model);
50 ~ExtensionToolbarModelTestObserver() override; 51 ~ToolbarActionsModelTestObserver() override;
51 52
52 size_t inserted_count() const { return inserted_count_; } 53 size_t inserted_count() const { return inserted_count_; }
53 size_t removed_count() const { return removed_count_; } 54 size_t removed_count() const { return removed_count_; }
54 size_t moved_count() const { return moved_count_; } 55 size_t moved_count() const { return moved_count_; }
55 int highlight_mode_count() const { return highlight_mode_count_; } 56 int highlight_mode_count() const { return highlight_mode_count_; }
56 size_t initialized_count() const { return initialized_count_; } 57 size_t initialized_count() const { return initialized_count_; }
57 58
58 private: 59 private:
59 // ExtensionToolbarModel::Observer: 60 // ToolbarActionsModel::Observer:
60 void OnToolbarExtensionAdded(const Extension* extension, int index) override { 61 void OnToolbarActionAdded(const std::string& id, int index) override {
61 ++inserted_count_; 62 ++inserted_count_;
62 } 63 }
63 64
64 void OnToolbarExtensionRemoved(const Extension* extension) override { 65 void OnToolbarActionRemoved(const std::string& id) override {
65 ++removed_count_; 66 ++removed_count_;
66 } 67 }
67 68
68 void OnToolbarExtensionMoved(const Extension* extension, int index) override { 69 void OnToolbarActionMoved(const std::string& id, int index) override {
69 ++moved_count_; 70 ++moved_count_;
70 } 71 }
71 72
72 void OnToolbarExtensionUpdated(const Extension* extension) override {} 73 void OnToolbarActionUpdated(const std::string& id) override {}
73 74
74 bool ShowExtensionActionPopup(const Extension* extension, 75 bool ShowToolbarActionPopup(const std::string& id,
75 bool grant_active_tab) override { 76 bool grant_active_tab) override {
76 return false; 77 return false;
77 } 78 }
78 79
79 void OnToolbarVisibleCountChanged() override {} 80 void OnToolbarVisibleCountChanged() override {}
80 81
81 void OnToolbarHighlightModeChanged(bool is_highlighting) override { 82 void OnToolbarHighlightModeChanged(bool is_highlighting) override {
82 // Add one if highlighting, subtract one if not. 83 // Add one if highlighting, subtract one if not.
83 highlight_mode_count_ += is_highlighting ? 1 : -1; 84 highlight_mode_count_ += is_highlighting ? 1 : -1;
84 } 85 }
85 86
86 void OnToolbarModelInitialized() override { ++initialized_count_; } 87 void OnToolbarModelInitialized() override { ++initialized_count_; }
87 88
88 Browser* GetBrowser() override { return NULL; } 89 Browser* GetBrowser() override { return NULL; }
89 90
90 ExtensionToolbarModel* model_; 91 ToolbarActionsModel* model_;
91 92
92 size_t inserted_count_; 93 size_t inserted_count_;
93 size_t removed_count_; 94 size_t removed_count_;
94 size_t moved_count_; 95 size_t moved_count_;
95 // Int because it could become negative (if something goes wrong). 96 // Int because it could become negative (if something goes wrong).
96 int highlight_mode_count_; 97 int highlight_mode_count_;
97 size_t initialized_count_; 98 size_t initialized_count_;
98 }; 99 };
99 100
100 ExtensionToolbarModelTestObserver::ExtensionToolbarModelTestObserver( 101 ToolbarActionsModelTestObserver::ToolbarActionsModelTestObserver(
101 ExtensionToolbarModel* model) : model_(model), 102 ToolbarActionsModel* model) : model_(model),
102 inserted_count_(0), 103 inserted_count_(0),
103 removed_count_(0), 104 removed_count_(0),
104 moved_count_(0), 105 moved_count_(0),
105 highlight_mode_count_(0), 106 highlight_mode_count_(0),
106 initialized_count_(0) { 107 initialized_count_(0) {
107 model_->AddObserver(this); 108 model_->AddObserver(this);
108 } 109 }
109 110
110 ExtensionToolbarModelTestObserver::~ExtensionToolbarModelTestObserver() { 111 ToolbarActionsModelTestObserver::~ToolbarActionsModelTestObserver() {
111 model_->RemoveObserver(this); 112 model_->RemoveObserver(this);
112 } 113 }
113 114
114 } // namespace 115 } // namespace
115 116
116 class ExtensionToolbarModelUnitTest : public ExtensionServiceTestBase { 117 class ToolbarActionsModelUnitTest :
118 public extensions::ExtensionServiceTestBase {
117 protected: 119 protected:
118 // Initialize the ExtensionService, ExtensionToolbarModel, and 120 // Initialize the ExtensionService, ToolbarActionsModel, and
119 // ExtensionSystem. 121 // ExtensionSystem.
120 void Init(); 122 void Init();
121 123
122 void TearDown() override; 124 void TearDown() override;
123 125
124 // Adds or removes the given |extension| and verify success. 126 // Adds or removes the given |extension| and verify success.
125 testing::AssertionResult AddExtension( 127 testing::AssertionResult AddExtension(
126 const scoped_refptr<const Extension>& extension) WARN_UNUSED_RESULT; 128 const scoped_refptr<const extensions::Extension>& extension)
129 WARN_UNUSED_RESULT;
127 testing::AssertionResult RemoveExtension( 130 testing::AssertionResult RemoveExtension(
128 const scoped_refptr<const Extension>& extension) WARN_UNUSED_RESULT; 131 const scoped_refptr<const extensions::Extension>& extension)
132 WARN_UNUSED_RESULT;
129 133
130 // Adds three extensions, all with browser actions. 134 // Adds three extensions, all with browser actions.
131 testing::AssertionResult AddBrowserActionExtensions() WARN_UNUSED_RESULT; 135 testing::AssertionResult AddBrowserActionExtensions() WARN_UNUSED_RESULT;
132 136
133 // Adds three extensions, one each for browser action, page action, and no 137 // Adds three extensions, one each for browser action, page action, and no
134 // action, and are added in that order. 138 // action, and are added in that order.
135 testing::AssertionResult AddActionExtensions() WARN_UNUSED_RESULT; 139 testing::AssertionResult AddActionExtensions() WARN_UNUSED_RESULT;
136 140
137 // Returns the extension at the given index in the toolbar model, or NULL 141 // Returns the action at the given index in the toolbar model, or NULL if one
138 // if one does not exist. 142 // does not exist.
139 // If |model| is specified, it is used. Otherwise, this defaults to 143 // If |model| is specified, it is used. Otherwise, this defaults to
140 // |toolbar_model_|. 144 // |toolbar_model_|.
141 const Extension* GetExtensionAtIndex( 145 const std::string GetActionIdAtIndex(size_t index,
142 size_t index, const ExtensionToolbarModel* model) const; 146 const ToolbarActionsModel* model) const;
143 const Extension* GetExtensionAtIndex(size_t index) const; 147 const std::string GetActionIdAtIndex(size_t index) const;
144 148
145 ExtensionToolbarModel* toolbar_model() { return toolbar_model_; } 149 ToolbarActionsModel* toolbar_model() { return toolbar_model_; }
146 150
147 const ExtensionToolbarModelTestObserver* observer() const { 151 const ToolbarActionsModelTestObserver* observer() const {
148 return model_observer_.get(); 152 return model_observer_.get();
149 } 153 }
150 size_t num_toolbar_items() const { 154 size_t num_toolbar_items() const {
151 return toolbar_model_->toolbar_items().size(); 155 return toolbar_model_->toolbar_items().size();
152 } 156 }
153 const Extension* browser_action_a() const { return browser_action_a_.get(); } 157 const extensions::Extension* browser_action_a() const {
154 const Extension* browser_action_b() const { return browser_action_b_.get(); } 158 return browser_action_a_.get();
155 const Extension* browser_action_c() const { return browser_action_c_.get(); } 159 }
156 const Extension* browser_action() const { 160 const extensions::Extension* browser_action_b() const {
161 return browser_action_b_.get();
162 }
163 const extensions::Extension* browser_action_c() const {
164 return browser_action_c_.get();
165 }
166 const extensions::Extension* browser_action() const {
157 return browser_action_extension_.get(); 167 return browser_action_extension_.get();
158 } 168 }
159 const Extension* page_action() const { return page_action_extension_.get(); } 169 const extensions::Extension* page_action() const {
160 const Extension* no_action() const { return no_action_extension_.get(); } 170 return page_action_extension_.get();
171 }
172 const extensions::Extension* no_action() const {
173 return no_action_extension_.get();
174 }
175
176 // The mock component action will be referred to as "MCA" below.
177 const std::string& component_action_id() {
178 return ComponentToolbarActionsFactory::kMockActionId;
179 }
161 180
162 private: 181 private:
163 // Verifies that all extensions in |extensions| are added successfully. 182 // Verifies that all extensions in |extensions| are added successfully.
164 testing::AssertionResult AddAndVerifyExtensions( 183 testing::AssertionResult AddAndVerifyExtensions(
165 const ExtensionList& extensions); 184 const extensions::ExtensionList& extensions);
166 185
167 // The toolbar model associated with the testing profile. 186 // The toolbar model associated with the testing profile.
168 ExtensionToolbarModel* toolbar_model_; 187 ToolbarActionsModel* toolbar_model_;
169 188
170 // The test observer to track events. Must come after toolbar_model_ so that 189 // The test observer to track events. Must come after toolbar_model_ so that
171 // it is destroyed and removes itself as an observer first. 190 // it is destroyed and removes itself as an observer first.
172 scoped_ptr<ExtensionToolbarModelTestObserver> model_observer_; 191 scoped_ptr<ToolbarActionsModelTestObserver> model_observer_;
173 192
174 // Sample extensions with only browser actions. 193 // Sample extensions with only browser actions.
175 scoped_refptr<const Extension> browser_action_a_; 194 scoped_refptr<const extensions::Extension> browser_action_a_;
176 scoped_refptr<const Extension> browser_action_b_; 195 scoped_refptr<const extensions::Extension> browser_action_b_;
177 scoped_refptr<const Extension> browser_action_c_; 196 scoped_refptr<const extensions::Extension> browser_action_c_;
178 197
179 // Sample extensions with different kinds of actions. 198 // Sample extensions with different kinds of actions.
180 scoped_refptr<const Extension> browser_action_extension_; 199 scoped_refptr<const extensions::Extension> browser_action_extension_;
181 scoped_refptr<const Extension> page_action_extension_; 200 scoped_refptr<const extensions::Extension> page_action_extension_;
182 scoped_refptr<const Extension> no_action_extension_; 201 scoped_refptr<const extensions::Extension> no_action_extension_;
202
203 scoped_ptr<MockComponentToolbarActionsFactory> mock_actions_factory_;
183 }; 204 };
184 205
185 void ExtensionToolbarModelUnitTest::Init() { 206 void ToolbarActionsModelUnitTest::Init() {
186 InitializeEmptyExtensionService(); 207 InitializeEmptyExtensionService();
208 mock_actions_factory_.reset(new MockComponentToolbarActionsFactory(NULL));
187 toolbar_model_ = 209 toolbar_model_ =
188 extension_action_test_util::CreateToolbarModelForProfile(profile()); 210 extensions::extension_action_test_util::CreateToolbarModelForProfile(
189 model_observer_.reset(new ExtensionToolbarModelTestObserver(toolbar_model_)); 211 profile());
212 model_observer_.reset(new ToolbarActionsModelTestObserver(toolbar_model_));
190 } 213 }
191 214
192 void ExtensionToolbarModelUnitTest::TearDown() { 215 void ToolbarActionsModelUnitTest::TearDown() {
193 model_observer_.reset(); 216 model_observer_.reset();
194 ExtensionServiceTestBase::TearDown(); 217 extensions::ExtensionServiceTestBase::TearDown();
195 } 218 }
196 219
197 testing::AssertionResult ExtensionToolbarModelUnitTest::AddExtension( 220 testing::AssertionResult ToolbarActionsModelUnitTest::AddExtension(
198 const scoped_refptr<const Extension>& extension) { 221 const scoped_refptr<const extensions::Extension>& extension) {
199 if (registry()->enabled_extensions().GetByID(extension->id())) { 222 if (registry()->enabled_extensions().GetByID(extension->id())) {
200 return testing::AssertionFailure() << "Extension " << extension->name() << 223 return testing::AssertionFailure() << "Extension " << extension->name() <<
201 " already installed!"; 224 " already installed!";
202 } 225 }
203 service()->AddExtension(extension.get()); 226 service()->AddExtension(extension.get());
204 if (!registry()->enabled_extensions().GetByID(extension->id())) { 227 if (!registry()->enabled_extensions().GetByID(extension->id())) {
205 return testing::AssertionFailure() << "Failed to install extension: " << 228 return testing::AssertionFailure() << "Failed to install extension: " <<
206 extension->name(); 229 extension->name();
207 } 230 }
208 return testing::AssertionSuccess(); 231 return testing::AssertionSuccess();
209 } 232 }
210 233
211 testing::AssertionResult ExtensionToolbarModelUnitTest::RemoveExtension( 234 testing::AssertionResult ToolbarActionsModelUnitTest::RemoveExtension(
212 const scoped_refptr<const Extension>& extension) { 235 const scoped_refptr<const extensions::Extension>& extension) {
213 if (!registry()->enabled_extensions().GetByID(extension->id())) { 236 if (!registry()->enabled_extensions().GetByID(extension->id())) {
214 return testing::AssertionFailure() << "Extension " << extension->name() << 237 return testing::AssertionFailure() << "Extension " << extension->name() <<
215 " not installed!"; 238 " not installed!";
216 } 239 }
217 service()->UnloadExtension(extension->id(), 240 service()->UnloadExtension(extension->id(),
218 UnloadedExtensionInfo::REASON_DISABLE); 241 extensions::UnloadedExtensionInfo::REASON_DISABLE);
219 if (registry()->enabled_extensions().GetByID(extension->id())) { 242 if (registry()->enabled_extensions().GetByID(extension->id())) {
220 return testing::AssertionFailure() << "Failed to unload extension: " << 243 return testing::AssertionFailure() << "Failed to unload extension: " <<
221 extension->name(); 244 extension->name();
222 } 245 }
223 return testing::AssertionSuccess(); 246 return testing::AssertionSuccess();
224 } 247 }
225 248
226 testing::AssertionResult ExtensionToolbarModelUnitTest::AddActionExtensions() { 249 testing::AssertionResult ToolbarActionsModelUnitTest::AddActionExtensions() {
227 browser_action_extension_ = extension_action_test_util::CreateActionExtension( 250 browser_action_extension_ =
228 "browser_action", extension_action_test_util::BROWSER_ACTION); 251 extensions::extension_action_test_util::CreateActionExtension(
229 page_action_extension_ = extension_action_test_util::CreateActionExtension( 252 "browser_action",
230 "page_action", extension_action_test_util::PAGE_ACTION); 253 extensions::extension_action_test_util::BROWSER_ACTION);
231 no_action_extension_ = extension_action_test_util::CreateActionExtension( 254 page_action_extension_ =
232 "no_action", extension_action_test_util::NO_ACTION); 255 extensions::extension_action_test_util::CreateActionExtension(
256 "page_action",
257 extensions::extension_action_test_util::PAGE_ACTION);
258 no_action_extension_ =
259 extensions::extension_action_test_util::CreateActionExtension(
260 "no_action",
261 extensions::extension_action_test_util::NO_ACTION);
233 262
234 ExtensionList extensions; 263 extensions::ExtensionList extensions;
235 extensions.push_back(browser_action_extension_); 264 extensions.push_back(browser_action_extension_);
236 extensions.push_back(page_action_extension_); 265 extensions.push_back(page_action_extension_);
237 extensions.push_back(no_action_extension_); 266 extensions.push_back(no_action_extension_);
238 267
239 return AddAndVerifyExtensions(extensions); 268 return AddAndVerifyExtensions(extensions);
240 } 269 }
241 270
242 testing::AssertionResult 271 testing::AssertionResult
243 ExtensionToolbarModelUnitTest::AddBrowserActionExtensions() { 272 ToolbarActionsModelUnitTest::AddBrowserActionExtensions() {
244 browser_action_a_ = extension_action_test_util::CreateActionExtension( 273 browser_action_a_ =
245 "browser_actionA", extension_action_test_util::BROWSER_ACTION); 274 extensions::extension_action_test_util::CreateActionExtension(
246 browser_action_b_ = extension_action_test_util::CreateActionExtension( 275 "browser_actionA",
247 "browser_actionB", extension_action_test_util::BROWSER_ACTION); 276 extensions::extension_action_test_util::BROWSER_ACTION);
248 browser_action_c_ = extension_action_test_util::CreateActionExtension( 277 browser_action_b_ =
249 "browser_actionC", extension_action_test_util::BROWSER_ACTION); 278 extensions::extension_action_test_util::CreateActionExtension(
279 "browser_actionB",
280 extensions::extension_action_test_util::BROWSER_ACTION);
281 browser_action_c_ =
282 extensions::extension_action_test_util::CreateActionExtension(
283 "browser_actionC",
284 extensions::extension_action_test_util::BROWSER_ACTION);
250 285
251 ExtensionList extensions; 286 extensions::ExtensionList extensions;
252 extensions.push_back(browser_action_a_); 287 extensions.push_back(browser_action_a_);
253 extensions.push_back(browser_action_b_); 288 extensions.push_back(browser_action_b_);
254 extensions.push_back(browser_action_c_); 289 extensions.push_back(browser_action_c_);
255 290
256 return AddAndVerifyExtensions(extensions); 291 return AddAndVerifyExtensions(extensions);
257 } 292 }
258 293
259 const Extension* ExtensionToolbarModelUnitTest::GetExtensionAtIndex( 294 const std::string ToolbarActionsModelUnitTest::GetActionIdAtIndex(
260 size_t index, const ExtensionToolbarModel* model) const { 295 size_t index, const ToolbarActionsModel* model) const {
261 return index < model->toolbar_items().size() 296 return index < model->toolbar_items().size()
262 ? model->toolbar_items()[index].get() 297 ? model->toolbar_items()[index]
263 : NULL; 298 : "";
Devlin 2015/08/03 20:58:30 nitty nit: in this code, we typically prefer std::
apacible 2015/08/04 22:15:59 Done.
264 } 299 }
265 300
266 const Extension* ExtensionToolbarModelUnitTest::GetExtensionAtIndex( 301 const std::string ToolbarActionsModelUnitTest::GetActionIdAtIndex(
267 size_t index) const { 302 size_t index) const {
268 return GetExtensionAtIndex(index, toolbar_model_); 303 return GetActionIdAtIndex(index, toolbar_model_);
269 } 304 }
270 305
271 testing::AssertionResult ExtensionToolbarModelUnitTest::AddAndVerifyExtensions( 306 testing::AssertionResult ToolbarActionsModelUnitTest::AddAndVerifyExtensions(
272 const ExtensionList& extensions) { 307 const extensions::ExtensionList& extensions) {
273 for (ExtensionList::const_iterator iter = extensions.begin(); 308 for (extensions::ExtensionList::const_iterator iter = extensions.begin();
274 iter != extensions.end(); ++iter) { 309 iter != extensions.end(); ++iter) {
275 if (!AddExtension(*iter)) { 310 if (!AddExtension(*iter)) {
276 return testing::AssertionFailure() << "Failed to install extension: " << 311 return testing::AssertionFailure() << "Failed to install extension: " <<
277 (*iter)->name(); 312 (*iter)->name();
278 } 313 }
279 } 314 }
280 return testing::AssertionSuccess(); 315 return testing::AssertionSuccess();
281 } 316 }
282 317
283 // A basic test for extensions with browser actions showing up in the toolbar. 318 // A basic test for component actions and extensions with browser actions
284 TEST_F(ExtensionToolbarModelUnitTest, BasicExtensionToolbarModelTest) { 319 // showing up in the toolbar.
320 TEST_F(ToolbarActionsModelUnitTest, BasicToolbarActionsModelTest) {
285 Init(); 321 Init();
286 322
323 // One component action was added when the model was initialized.
324 EXPECT_EQ(0u, observer()->inserted_count());
325 EXPECT_EQ(1u, num_toolbar_items());
326 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
327
287 // Load an extension with no browser action. 328 // Load an extension with no browser action.
288 scoped_refptr<const Extension> extension1 = 329 scoped_refptr<const extensions::Extension> extension1 =
289 extension_action_test_util::CreateActionExtension( 330 extensions::extension_action_test_util::CreateActionExtension(
290 "no_action", extension_action_test_util::NO_ACTION); 331 "no_action", extensions::extension_action_test_util::NO_ACTION);
291 ASSERT_TRUE(AddExtension(extension1)); 332 ASSERT_TRUE(AddExtension(extension1));
292 333
293 // This extension should not be in the model (has no browser action). 334 // This extension should not be in the model (has no browser action).
294 EXPECT_EQ(0u, observer()->inserted_count()); 335 EXPECT_EQ(0u, observer()->inserted_count());
295 EXPECT_EQ(0u, num_toolbar_items()); 336 EXPECT_EQ(1u, num_toolbar_items());
296 EXPECT_EQ(NULL, GetExtensionAtIndex(0u)); 337 EXPECT_EQ("", GetActionIdAtIndex(1u));
297 338
298 // Load an extension with a browser action. 339 // Load an extension with a browser action.
299 scoped_refptr<const Extension> extension2 = 340 scoped_refptr<const extensions::Extension> extension2 =
300 extension_action_test_util::CreateActionExtension( 341 extensions::extension_action_test_util::CreateActionExtension(
301 "browser_action", extension_action_test_util::BROWSER_ACTION); 342 "browser_action",
343 extensions::extension_action_test_util::BROWSER_ACTION);
302 ASSERT_TRUE(AddExtension(extension2)); 344 ASSERT_TRUE(AddExtension(extension2));
303 345
304 // We should now find our extension in the model. 346 // We should now find our extension in the model.
305 EXPECT_EQ(1u, observer()->inserted_count()); 347 EXPECT_EQ(1u, observer()->inserted_count());
306 EXPECT_EQ(1u, num_toolbar_items()); 348 EXPECT_EQ(2u, num_toolbar_items());
307 EXPECT_EQ(extension2.get(), GetExtensionAtIndex(0u)); 349 EXPECT_EQ(extension2->id(), GetActionIdAtIndex(1u));
308 350
309 // Should be a no-op, but still fires the events. 351 // Should be a no-op, but still fires the events.
310 toolbar_model()->MoveExtensionIcon(extension2->id(), 0); 352 toolbar_model()->MoveActionIcon(extension2->id(), 1);
311 EXPECT_EQ(1u, observer()->moved_count()); 353 EXPECT_EQ(1u, observer()->moved_count());
312 EXPECT_EQ(1u, num_toolbar_items()); 354 EXPECT_EQ(2u, num_toolbar_items());
313 EXPECT_EQ(extension2.get(), GetExtensionAtIndex(0u)); 355 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
356 EXPECT_EQ(extension2->id(), GetActionIdAtIndex(1u));
314 357
315 // Remove the extension and verify. 358 // Remove the extension and verify.
316 ASSERT_TRUE(RemoveExtension(extension2)); 359 ASSERT_TRUE(RemoveExtension(extension2));
317 EXPECT_EQ(1u, observer()->removed_count()); 360 EXPECT_EQ(1u, observer()->removed_count());
318 EXPECT_EQ(0u, num_toolbar_items()); 361 EXPECT_EQ(1u, num_toolbar_items());
319 EXPECT_EQ(NULL, GetExtensionAtIndex(0u)); 362 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
363 EXPECT_EQ("", GetActionIdAtIndex(1u));
320 } 364 }
321 365
322 // Test various different reorderings, removals, and reinsertions. 366 // Test various different reorderings, removals, and reinsertions.
323 TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarReorderAndReinsert) { 367 TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarReorderAndReinsert) {
324 Init(); 368 Init();
325 369
370 // One component action was added when the model was initialized.
371 EXPECT_EQ(1u, num_toolbar_items());
372 EXPECT_EQ(component_action_id(),
373 GetActionIdAtIndex(0u));
374
326 // Add the three browser action extensions. 375 // Add the three browser action extensions.
327 ASSERT_TRUE(AddBrowserActionExtensions()); 376 ASSERT_TRUE(AddBrowserActionExtensions());
328 377
329 // Verify the three extensions are in the model in the proper order. 378 // Verify the four actions are in the model in the proper order.
330 EXPECT_EQ(3u, num_toolbar_items()); 379 EXPECT_EQ(4u, num_toolbar_items());
331 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 380 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
332 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u)); 381 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
333 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u)); 382 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
383 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
334 384
335 // Order is now A, B, C. Let's put C first. 385 // Order is now MCA, A, B, C. Let's put C first.
336 toolbar_model()->MoveExtensionIcon(browser_action_c()->id(), 0); 386 toolbar_model()->MoveActionIcon(browser_action_c()->id(), 0);
337 EXPECT_EQ(1u, observer()->moved_count()); 387 EXPECT_EQ(1u, observer()->moved_count());
338 EXPECT_EQ(3u, num_toolbar_items()); 388 EXPECT_EQ(4u, num_toolbar_items());
339 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u)); 389 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(0u));
340 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(1u)); 390 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u));
341 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(2u)); 391 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(2u));
392 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(3u));
342 393
343 // Order is now C, A, B. Let's put A last. 394 // Order is now C, MCAn, A, B. Let's put A last.
344 toolbar_model()->MoveExtensionIcon(browser_action_a()->id(), 2); 395 toolbar_model()->MoveActionIcon(browser_action_a()->id(), 2);
345 EXPECT_EQ(2u, observer()->moved_count()); 396 EXPECT_EQ(2u, observer()->moved_count());
346 EXPECT_EQ(3u, num_toolbar_items()); 397 EXPECT_EQ(4u, num_toolbar_items());
347 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u)); 398 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(0u));
348 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u)); 399 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u));
349 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(2u)); 400 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(2u));
401 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(3u));
350 402
351 // Order is now C, B, A. Let's remove B. 403 // Order is now C, MCA, B, A. Let's remove B.
352 ASSERT_TRUE(RemoveExtension(browser_action_b())); 404 ASSERT_TRUE(RemoveExtension(browser_action_b()));
353 EXPECT_EQ(1u, observer()->removed_count()); 405 EXPECT_EQ(1u, observer()->removed_count());
354 EXPECT_EQ(2u, num_toolbar_items()); 406 EXPECT_EQ(3u, num_toolbar_items());
355 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u)); 407 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(0u));
356 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(1u)); 408 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u));
409 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(2u));
357 410
358 // Load extension B again. 411 // Load extension B again.
359 ASSERT_TRUE(AddExtension(browser_action_b())); 412 ASSERT_TRUE(AddExtension(browser_action_b()));
360 413
361 // Extension B loaded again. 414 // Extension B loaded again.
362 EXPECT_EQ(4u, observer()->inserted_count()); 415 EXPECT_EQ(4u, observer()->inserted_count());
363 EXPECT_EQ(3u, num_toolbar_items()); 416 EXPECT_EQ(4u, num_toolbar_items());
364 // Make sure it gets its old spot in the list. 417 // Make sure it gets its old spot in the list.
365 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u)); 418 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(3u));
366 419
367 // Unload B again. 420 // Unload B again.
368 ASSERT_TRUE(RemoveExtension(browser_action_b())); 421 ASSERT_TRUE(RemoveExtension(browser_action_b()));
369 EXPECT_EQ(2u, observer()->removed_count()); 422 EXPECT_EQ(2u, observer()->removed_count());
370 EXPECT_EQ(2u, num_toolbar_items()); 423 EXPECT_EQ(3u, num_toolbar_items());
371 424
372 // Order is now C, A. Flip it. 425 // Order is now C, MCA, A. Let's put A first.
373 toolbar_model()->MoveExtensionIcon(browser_action_a()->id(), 0); 426 toolbar_model()->MoveActionIcon(browser_action_a()->id(), 0);
374 EXPECT_EQ(3u, observer()->moved_count()); 427 EXPECT_EQ(3u, observer()->moved_count());
375 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 428 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u));
376 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u)); 429 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(1u));
430 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(2u));
377 431
378 // Move A to the location it already occupies. 432 // Move A to the location it already occupies.
379 toolbar_model()->MoveExtensionIcon(browser_action_a()->id(), 0); 433 toolbar_model()->MoveActionIcon(browser_action_a()->id(), 0);
380 EXPECT_EQ(4u, observer()->moved_count()); 434 EXPECT_EQ(4u, observer()->moved_count());
381 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 435 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u));
382 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u)); 436 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(1u));
437 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(2u));
383 438
384 // Order is now A, C. Remove C. 439 // Order is now A, C, MCA. Let's put MCA first.
440 toolbar_model()->MoveActionIcon(component_action_id(), 0);
441 EXPECT_EQ(5u, observer()->moved_count());
442 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
443 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
444 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u));
445
446 // Order is now MCA, A, C. Remove C.
385 ASSERT_TRUE(RemoveExtension(browser_action_c())); 447 ASSERT_TRUE(RemoveExtension(browser_action_c()));
386 EXPECT_EQ(3u, observer()->removed_count()); 448 EXPECT_EQ(3u, observer()->removed_count());
449 EXPECT_EQ(2u, num_toolbar_items());
450 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
451 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
452
453 // Order is now A, MCA. Remove A.
454 ASSERT_TRUE(RemoveExtension(browser_action_a()));
455 EXPECT_EQ(4u, observer()->removed_count());
387 EXPECT_EQ(1u, num_toolbar_items()); 456 EXPECT_EQ(1u, num_toolbar_items());
388 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 457 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
389 458
390 // Load extension C again. 459 // Load extension C again.
391 ASSERT_TRUE(AddExtension(browser_action_c())); 460 ASSERT_TRUE(AddExtension(browser_action_c()));
392 461
393 // Extension C loaded again. 462 // Extension C loaded again.
394 EXPECT_EQ(5u, observer()->inserted_count()); 463 EXPECT_EQ(5u, observer()->inserted_count());
395 EXPECT_EQ(2u, num_toolbar_items()); 464 EXPECT_EQ(2u, num_toolbar_items());
396 // Make sure it gets its old spot in the list (at the very end). 465 // Make sure it gets its old spot in the list (at the end).
397 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u)); 466 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(1u));
398 } 467 }
399 468
400 // Test that order persists after unloading and disabling, but not across 469 // Test that order persists after unloading and disabling, but not across
401 // uninstallation. 470 // uninstallation.
402 TEST_F(ExtensionToolbarModelUnitTest, 471 TEST_F(ToolbarActionsModelUnitTest,
403 ExtensionToolbarUnloadDisableAndUninstall) { 472 ActionsToolbarUnloadDisableAndUninstall) {
404 Init(); 473 Init();
474
475 // One component action was added when the model was initialized.
476 EXPECT_EQ(1u, num_toolbar_items());
477 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
405 478
406 // Add the three browser action extensions. 479 // Add the three browser action extensions.
407 ASSERT_TRUE(AddBrowserActionExtensions()); 480 ASSERT_TRUE(AddBrowserActionExtensions());
408 481
409 // Verify the three extensions are in the model in the proper order: A, B, C. 482 // Verify the four actions are in the model in the proper order:
410 EXPECT_EQ(3u, num_toolbar_items()); 483 // MCA, A, B, C.
411 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 484 EXPECT_EQ(4u, num_toolbar_items());
412 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u)); 485 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
413 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u)); 486 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
487 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
488 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
414 489
415 // Unload B, then C, then A, and then reload C, then A, then B. 490 // Unload B, then C, then A, and then reload C, then A, then B.
416 ASSERT_TRUE(RemoveExtension(browser_action_b())); 491 ASSERT_TRUE(RemoveExtension(browser_action_b()));
417 ASSERT_TRUE(RemoveExtension(browser_action_c())); 492 ASSERT_TRUE(RemoveExtension(browser_action_c()));
418 ASSERT_TRUE(RemoveExtension(browser_action_a())); 493 ASSERT_TRUE(RemoveExtension(browser_action_a()));
419 EXPECT_EQ(0u, num_toolbar_items()); // Sanity check: all gone? 494 // Sanity check: all gone except the component action (MCA)?
495 EXPECT_EQ(1u, num_toolbar_items());
420 ASSERT_TRUE(AddExtension(browser_action_c())); 496 ASSERT_TRUE(AddExtension(browser_action_c()));
421 ASSERT_TRUE(AddExtension(browser_action_a())); 497 ASSERT_TRUE(AddExtension(browser_action_a()));
422 ASSERT_TRUE(AddExtension(browser_action_b())); 498 ASSERT_TRUE(AddExtension(browser_action_b()));
423 EXPECT_EQ(3u, num_toolbar_items()); // Sanity check: all back? 499 EXPECT_EQ(4u, num_toolbar_items()); // Sanity check: all back?
424 EXPECT_EQ(0u, observer()->moved_count()); 500 EXPECT_EQ(0u, observer()->moved_count());
425 501
426 // Even though we unloaded and reloaded in a different order, the original 502 // Even though we unloaded and reloaded in a different order, the original
427 // order (A, B, C) should be preserved. 503 // order (MCA, A, B, C) should be preserved.
428 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 504 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
429 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u)); 505 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
430 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u)); 506 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
507 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
431 508
432 // Disabling extensions should also preserve order. 509 // Disabling extensions should also preserve order.
433 service()->DisableExtension(browser_action_b()->id(), 510 service()->DisableExtension(browser_action_b()->id(),
434 Extension::DISABLE_USER_ACTION); 511 extensions::Extension::DISABLE_USER_ACTION);
435 service()->DisableExtension(browser_action_c()->id(), 512 service()->DisableExtension(browser_action_c()->id(),
436 Extension::DISABLE_USER_ACTION); 513 extensions::Extension::DISABLE_USER_ACTION);
437 service()->DisableExtension(browser_action_a()->id(), 514 service()->DisableExtension(browser_action_a()->id(),
438 Extension::DISABLE_USER_ACTION); 515 extensions::Extension::DISABLE_USER_ACTION);
439 service()->EnableExtension(browser_action_c()->id()); 516 service()->EnableExtension(browser_action_c()->id());
440 service()->EnableExtension(browser_action_a()->id()); 517 service()->EnableExtension(browser_action_a()->id());
441 service()->EnableExtension(browser_action_b()->id()); 518 service()->EnableExtension(browser_action_b()->id());
442 519
443 // Make sure we still get the original A, B, C order. 520 // Make sure we still get the original MCA, A, B, C order.
444 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 521 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
445 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u)); 522 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
446 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u)); 523 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
524 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
447 525
448 // Move browser_action_b() to be first. 526 // Move browser_action_b() to be first.
449 toolbar_model()->MoveExtensionIcon(browser_action_b()->id(), 0); 527 toolbar_model()->MoveActionIcon(browser_action_b()->id(), 0);
450 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(0u)); 528 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(0u));
451 529
452 // Uninstall Extension B. 530 // Uninstall Extension B.
453 service()->UninstallExtension(browser_action_b()->id(), 531 service()->UninstallExtension(browser_action_b()->id(),
454 UNINSTALL_REASON_FOR_TESTING, 532 extensions::UNINSTALL_REASON_FOR_TESTING,
455 base::Bind(&base::DoNothing), 533 base::Bind(&base::DoNothing),
456 NULL); // Ignore error. 534 NULL); // Ignore error.
457 // List contains only A and C now. Validate that. 535 // List contains only MCA, A, and C now. Validate that.
458 EXPECT_EQ(2u, num_toolbar_items()); 536 EXPECT_EQ(3u, num_toolbar_items());
459 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 537 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
460 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u)); 538 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
539 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u));
461 540
462 ASSERT_TRUE(AddExtension(browser_action_b())); 541 ASSERT_TRUE(AddExtension(browser_action_b()));
463 542
464 // Make sure Extension B is _not_ first (its old position should have been 543 // Make sure Extension B is _not_ first (its old position should have been
465 // forgotten at uninstall time). Order should be A, C, B. 544 // forgotten at uninstall time). Order should be MCA, A, C, B.
466 EXPECT_EQ(3u, num_toolbar_items()); 545 EXPECT_EQ(4u, num_toolbar_items());
467 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 546 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
468 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u)); 547 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
469 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(2u)); 548 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u));
470 } 549 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(3u));
471 550 }
472 TEST_F(ExtensionToolbarModelUnitTest, ReorderOnPrefChange) { 551
473 Init(); 552 TEST_F(ToolbarActionsModelUnitTest, ReorderOnPrefChange) {
553 Init();
554
555 // One component action was added when the model was initialized.
556 EXPECT_EQ(1u, num_toolbar_items());
474 557
475 // Add the three browser action extensions. 558 // Add the three browser action extensions.
476 ASSERT_TRUE(AddBrowserActionExtensions()); 559 ASSERT_TRUE(AddBrowserActionExtensions());
477 EXPECT_EQ(3u, num_toolbar_items()); 560 EXPECT_EQ(4u, num_toolbar_items());
478 561
479 // Change the value of the toolbar preference. 562 // Change the value of the toolbar preference.
480 ExtensionIdList new_order; 563 ActionIdList new_order;
481 new_order.push_back(browser_action_c()->id()); 564 new_order.push_back(browser_action_c()->id());
482 new_order.push_back(browser_action_b()->id()); 565 new_order.push_back(browser_action_b()->id());
483 ExtensionPrefs::Get(profile())->SetToolbarOrder(new_order); 566 extensions::ExtensionPrefs::Get(profile())->SetToolbarOrder(new_order);
484 567
485 // Verify order is changed. 568 // Verify order is changed.
486 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u)); 569 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(0u));
487 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u)); 570 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(1u));
488 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(2u)); 571 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(2u));
489 } 572 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(3u));
490 573 }
491 // Test that new extensions are always visible on installation and inserted at 574
492 // the "end" of the visible section. 575 // Test that new extension actions are always visible on installation and
493 TEST_F(ExtensionToolbarModelUnitTest, NewToolbarExtensionsAreVisible) { 576 // inserted at the "end" of the visible section.
577 TEST_F(ToolbarActionsModelUnitTest, NewToolbarExtensionsAreVisible) {
494 Init(); 578 Init();
495 579
496 // Three extensions with actions. 580 // Three extensions with actions.
497 scoped_refptr<const Extension> extension_a = 581 scoped_refptr<const extensions::Extension> extension_a =
498 extension_action_test_util::CreateActionExtension( 582 extensions::extension_action_test_util::CreateActionExtension(
499 "a", extension_action_test_util::BROWSER_ACTION); 583 "a", extensions::extension_action_test_util::BROWSER_ACTION);
500 scoped_refptr<const Extension> extension_b = 584 scoped_refptr<const extensions::Extension> extension_b =
501 extension_action_test_util::CreateActionExtension( 585 extensions::extension_action_test_util::CreateActionExtension(
502 "b", extension_action_test_util::BROWSER_ACTION); 586 "b", extensions::extension_action_test_util::BROWSER_ACTION);
503 scoped_refptr<const Extension> extension_c = 587 scoped_refptr<const extensions::Extension> extension_c =
504 extension_action_test_util::CreateActionExtension( 588 extensions::extension_action_test_util::CreateActionExtension(
505 "c", extension_action_test_util::BROWSER_ACTION); 589 "c", extensions::extension_action_test_util::BROWSER_ACTION);
506 scoped_refptr<const Extension> extension_d = 590 scoped_refptr<const extensions::Extension> extension_d =
507 extension_action_test_util::CreateActionExtension( 591 extensions::extension_action_test_util::CreateActionExtension(
508 "d", extension_action_test_util::BROWSER_ACTION); 592 "d", extensions::extension_action_test_util::BROWSER_ACTION);
509 593
510 // We should start off without any extensions. 594 // One component action was added when the model was initialized.
511 EXPECT_EQ(0u, num_toolbar_items()); 595 EXPECT_EQ(1u, num_toolbar_items());
512 EXPECT_EQ(0u, toolbar_model()->visible_icon_count()); 596
513 597 // We should start off without any action, but one component action.
514 // Add one extension. It should be visible. 598 EXPECT_EQ(1u, num_toolbar_items());
599 EXPECT_EQ(1u, toolbar_model()->visible_icon_count());
600
601 // Add one action. It should be visible.
515 service()->AddExtension(extension_a.get()); 602 service()->AddExtension(extension_a.get());
516 EXPECT_EQ(1u, num_toolbar_items()); 603 EXPECT_EQ(2u, num_toolbar_items());
517 EXPECT_EQ(1u, toolbar_model()->visible_icon_count()); 604 EXPECT_EQ(2u, toolbar_model()->visible_icon_count());
518 EXPECT_EQ(extension_a.get(), GetExtensionAtIndex(0u)); 605 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
519 606 EXPECT_EQ(extension_a.get()->id(), GetActionIdAtIndex(1u));
520 // Hide all extensions. 607
608 // Hide all action.
521 toolbar_model()->SetVisibleIconCount(0); 609 toolbar_model()->SetVisibleIconCount(0);
522 EXPECT_EQ(0u, toolbar_model()->visible_icon_count()); 610 EXPECT_EQ(0u, toolbar_model()->visible_icon_count());
523 611
524 // Add a new extension - it should be visible, so it should be in the first 612 // Add a new action - it should be visible, so it should be in the first
525 // index. The other extension should remain hidden. 613 // index. The other action should remain hidden.
526 service()->AddExtension(extension_b.get()); 614 service()->AddExtension(extension_b.get());
527 EXPECT_EQ(2u, num_toolbar_items()); 615 EXPECT_EQ(3u, num_toolbar_items());
528 EXPECT_EQ(1u, toolbar_model()->visible_icon_count()); 616 EXPECT_EQ(1u, toolbar_model()->visible_icon_count());
529 EXPECT_EQ(extension_b.get(), GetExtensionAtIndex(0u)); 617 EXPECT_EQ(extension_b.get()->id(), GetActionIdAtIndex(0u));
530 EXPECT_EQ(extension_a.get(), GetExtensionAtIndex(1u)); 618 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u));
531 619 EXPECT_EQ(extension_a.get()->id(), GetActionIdAtIndex(2u));
532 // Show all extensions. 620
533 toolbar_model()->SetVisibleIconCount(2); 621 // Show all action.
534 EXPECT_EQ(2u, toolbar_model()->visible_icon_count()); 622 toolbar_model()->SetVisibleIconCount(3);
535 EXPECT_TRUE(toolbar_model()->all_icons_visible());
536
537 // Add the third extension. Since all extensions are visible, it should go in
538 // the last index.
539 service()->AddExtension(extension_c.get());
540 EXPECT_EQ(3u, num_toolbar_items());
541 EXPECT_EQ(3u, toolbar_model()->visible_icon_count()); 623 EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
542 EXPECT_TRUE(toolbar_model()->all_icons_visible()); 624 EXPECT_TRUE(toolbar_model()->all_icons_visible());
543 EXPECT_EQ(extension_b.get(), GetExtensionAtIndex(0u)); 625
544 EXPECT_EQ(extension_a.get(), GetExtensionAtIndex(1u)); 626 // Add the fourth action. Since all action are visible, it should go in the
545 EXPECT_EQ(extension_c.get(), GetExtensionAtIndex(2u)); 627 // last index.
546 628 service()->AddExtension(extension_c.get());
547 // Hide one extension (two remaining visible). 629 EXPECT_EQ(4u, num_toolbar_items());
548 toolbar_model()->SetVisibleIconCount(2); 630 EXPECT_EQ(4u, toolbar_model()->visible_icon_count());
549 EXPECT_EQ(2u, toolbar_model()->visible_icon_count()); 631 EXPECT_TRUE(toolbar_model()->all_icons_visible());
550 632 EXPECT_EQ(extension_b.get()->id(), GetActionIdAtIndex(0u));
551 // Add a fourth extension. It should go at the end of the visible section and 633 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u));
552 // be visible, so it increases visible count by 1, and goes into the third 634 EXPECT_EQ(extension_a.get()->id(), GetActionIdAtIndex(2u));
553 // index. The hidden extension should remain hidden. 635 EXPECT_EQ(extension_c.get()->id(), GetActionIdAtIndex(3u));
636
637 // Hide one action (three remaining visible).
638 toolbar_model()->SetVisibleIconCount(3);
639 EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
640
641 // Add a fifth action. It should go at the end of the visible section and
642 // be visible, so it increases visible count by 1, and goes into the fourth
643 // index. The hidden action should remain hidden.
554 service()->AddExtension(extension_d.get()); 644 service()->AddExtension(extension_d.get());
555 EXPECT_EQ(4u, num_toolbar_items()); 645 EXPECT_EQ(5u, num_toolbar_items());
556 EXPECT_EQ(3u, toolbar_model()->visible_icon_count()); 646 EXPECT_EQ(4u, toolbar_model()->visible_icon_count());
557 EXPECT_EQ(extension_b.get(), GetExtensionAtIndex(0u)); 647 EXPECT_EQ(extension_b.get()->id(), GetActionIdAtIndex(0u));
558 EXPECT_EQ(extension_a.get(), GetExtensionAtIndex(1u)); 648 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u));
559 EXPECT_EQ(extension_d.get(), GetExtensionAtIndex(2u)); 649 EXPECT_EQ(extension_a.get()->id(), GetActionIdAtIndex(2u));
560 EXPECT_EQ(extension_c.get(), GetExtensionAtIndex(3u)); 650 EXPECT_EQ(extension_d.get()->id(), GetActionIdAtIndex(3u));
561 } 651 EXPECT_EQ(extension_c.get()->id(), GetActionIdAtIndex(4u));
562 652 }
563 TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarHighlightMode) { 653
564 Init(); 654 TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarHighlightMode) {
565 655 Init();
566 EXPECT_FALSE(toolbar_model()->HighlightExtensions( 656
567 ExtensionIdList(), ExtensionToolbarModel::HIGHLIGHT_WARNING)); 657 // One component action was added when the model was initialized.
658 EXPECT_EQ(1u, num_toolbar_items());
659
660 EXPECT_FALSE(toolbar_model()->HighlightActions(
661 ActionIdList(), ToolbarActionsModel::HIGHLIGHT_WARNING));
568 EXPECT_EQ(0, observer()->highlight_mode_count()); 662 EXPECT_EQ(0, observer()->highlight_mode_count());
569 663
570 // Add the three browser action extensions. 664 // Add the three browser action extensions.
571 ASSERT_TRUE(AddBrowserActionExtensions()); 665 ASSERT_TRUE(AddBrowserActionExtensions());
572 EXPECT_EQ(3u, num_toolbar_items()); 666 EXPECT_EQ(4u, num_toolbar_items());
573 667
574 // Start with a visible count of 2 (non-zero, and not all). 668 // Start with a visible count of 2 (non-zero, and not all).
575 toolbar_model()->SetVisibleIconCount(2u); 669 toolbar_model()->SetVisibleIconCount(2u);
576 670
577 // Highlight one extension. 671 // Highlight one extension.
578 ExtensionIdList extension_ids; 672 ActionIdList action_ids;
579 extension_ids.push_back(browser_action_b()->id()); 673 action_ids.push_back(browser_action_b()->id());
580 toolbar_model()->HighlightExtensions( 674 toolbar_model()->HighlightActions(
581 extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING); 675 action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
582 EXPECT_EQ(1, observer()->highlight_mode_count()); 676 EXPECT_EQ(1, observer()->highlight_mode_count());
583 EXPECT_TRUE(toolbar_model()->is_highlighting()); 677 EXPECT_TRUE(toolbar_model()->is_highlighting());
584 678 EXPECT_EQ(1u, num_toolbar_items());
585 EXPECT_EQ(1u, num_toolbar_items()); 679 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(0u));
586 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(0u));
587 EXPECT_EQ(1u, toolbar_model()->visible_icon_count()); 680 EXPECT_EQ(1u, toolbar_model()->visible_icon_count());
588 681
589 // Stop highlighting. 682 // Stop highlighting.
590 toolbar_model()->StopHighlighting(); 683 toolbar_model()->StopHighlighting();
591 EXPECT_EQ(0, observer()->highlight_mode_count()); 684 EXPECT_EQ(0, observer()->highlight_mode_count());
592 EXPECT_FALSE(toolbar_model()->is_highlighting()); 685 EXPECT_FALSE(toolbar_model()->is_highlighting());
593 686
594 // Verify that the extensions are back to normal. 687 // Verify that the extensions are back to normal.
595 EXPECT_EQ(3u, num_toolbar_items()); 688 EXPECT_EQ(4u, num_toolbar_items());
596 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 689 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
597 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u)); 690 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
598 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u)); 691 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
692 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
599 EXPECT_EQ(2u, toolbar_model()->visible_icon_count()); 693 EXPECT_EQ(2u, toolbar_model()->visible_icon_count());
600 694
601 // Call stop highlighting a second time (shouldn't be notified). 695 // Call stop highlighting a second time (shouldn't be notified).
602 toolbar_model()->StopHighlighting(); 696 toolbar_model()->StopHighlighting();
603 EXPECT_EQ(0, observer()->highlight_mode_count()); 697 EXPECT_EQ(0, observer()->highlight_mode_count());
604 EXPECT_FALSE(toolbar_model()->is_highlighting()); 698 EXPECT_FALSE(toolbar_model()->is_highlighting());
605 699
606 // Highlight all extensions. 700 // Highlight all extensions.
607 extension_ids.clear(); 701 action_ids.clear();
608 extension_ids.push_back(browser_action_a()->id()); 702 action_ids.push_back(browser_action_a()->id());
609 extension_ids.push_back(browser_action_b()->id()); 703 action_ids.push_back(browser_action_b()->id());
610 extension_ids.push_back(browser_action_c()->id()); 704 action_ids.push_back(browser_action_c()->id());
611 toolbar_model()->HighlightExtensions( 705 toolbar_model()->HighlightActions(
612 extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING); 706 action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
613 EXPECT_EQ(1, observer()->highlight_mode_count()); 707 EXPECT_EQ(1, observer()->highlight_mode_count());
614 EXPECT_EQ(3u, num_toolbar_items()); 708 EXPECT_EQ(3u, num_toolbar_items());
615 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 709 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u));
616 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u)); 710 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(1u));
617 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u)); 711 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u));
618 EXPECT_EQ(3u, toolbar_model()->visible_icon_count()); 712 EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
619 // Even though the visible count is 3, we shouldn't adjust the stored 713 // Even though the visible count is 3, we shouldn't adjust the stored
620 // preference. 714 // preference.
621 EXPECT_EQ(2, profile()->GetPrefs()->GetInteger(pref_names::kToolbarSize)); 715 EXPECT_EQ(2, profile()->GetPrefs()->GetInteger(
622 716 extensions::pref_names::kToolbarSize));
623 // Highlight only extension b (shrink the highlight list). 717
624 extension_ids.clear(); 718 // Highlight only extension B (shrink the highlight list).
625 extension_ids.push_back(browser_action_b()->id()); 719 action_ids.clear();
626 toolbar_model()->HighlightExtensions( 720 action_ids.push_back(browser_action_b()->id());
627 extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING); 721 toolbar_model()->HighlightActions(
722 action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
628 EXPECT_EQ(2, observer()->highlight_mode_count()); 723 EXPECT_EQ(2, observer()->highlight_mode_count());
629 EXPECT_EQ(1u, num_toolbar_items()); 724 EXPECT_EQ(1u, num_toolbar_items());
630 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(0u)); 725 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(0u));
631 726
632 // Highlight extensions a and b (grow the highlight list). 727 // Highlight extensions A and B (grow the highlight list).
633 extension_ids.clear(); 728 action_ids.clear();
634 extension_ids.push_back(browser_action_a()->id()); 729 action_ids.push_back(browser_action_a()->id());
635 extension_ids.push_back(browser_action_b()->id()); 730 action_ids.push_back(browser_action_b()->id());
636 toolbar_model()->HighlightExtensions( 731 toolbar_model()->HighlightActions(
637 extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING); 732 action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
638 EXPECT_EQ(3, observer()->highlight_mode_count()); 733 EXPECT_EQ(3, observer()->highlight_mode_count());
639 EXPECT_EQ(2u, num_toolbar_items()); 734 EXPECT_EQ(2u, num_toolbar_items());
640 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 735 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u));
641 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u)); 736 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(1u));
642 737
643 // Highlight no extensions (empty the highlight list). 738 // Highlight no extensions (empty the highlight list).
644 extension_ids.clear(); 739 action_ids.clear();
645 toolbar_model()->HighlightExtensions( 740 toolbar_model()->HighlightActions(
646 extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING); 741 action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
647 EXPECT_EQ(2, observer()->highlight_mode_count()); 742 EXPECT_EQ(2, observer()->highlight_mode_count());
648 EXPECT_FALSE(toolbar_model()->is_highlighting()); 743 EXPECT_FALSE(toolbar_model()->is_highlighting());
649 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 744 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
650 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u)); 745 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
651 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u)); 746 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
652 747 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
653 // Our toolbar size should be back to normal. 748 // Our toolbar size should be back to normal.
654 EXPECT_EQ(2u, toolbar_model()->visible_icon_count()); 749 EXPECT_EQ(2u, toolbar_model()->visible_icon_count());
655 EXPECT_EQ(2, profile()->GetPrefs()->GetInteger(pref_names::kToolbarSize)); 750 EXPECT_EQ(2, profile()->GetPrefs()->GetInteger(
656 } 751 extensions::pref_names::kToolbarSize));
657 752 }
658 TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarHighlightModeRemove) { 753
659 Init(); 754 TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarHighlightModeRemove) {
755 Init();
756
757 // One component action was added when the model was initialized.
758 EXPECT_EQ(1u, num_toolbar_items());
660 759
661 // Add the three browser action extensions. 760 // Add the three browser action extensions.
662 ASSERT_TRUE(AddBrowserActionExtensions()); 761 ASSERT_TRUE(AddBrowserActionExtensions());
663 EXPECT_EQ(3u, num_toolbar_items()); 762 EXPECT_EQ(4u, num_toolbar_items());
664 763
665 // Highlight two of the extensions. 764 // Highlight two of the extensions.
666 ExtensionIdList extension_ids; 765 ActionIdList action_ids;
667 extension_ids.push_back(browser_action_a()->id()); 766 action_ids.push_back(browser_action_a()->id());
668 extension_ids.push_back(browser_action_b()->id()); 767 action_ids.push_back(browser_action_b()->id());
669 toolbar_model()->HighlightExtensions( 768 toolbar_model()->HighlightActions(
670 extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING); 769 action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
671 EXPECT_TRUE(toolbar_model()->is_highlighting()); 770 EXPECT_TRUE(toolbar_model()->is_highlighting());
672 EXPECT_EQ(1, observer()->highlight_mode_count()); 771 EXPECT_EQ(1, observer()->highlight_mode_count());
673 EXPECT_EQ(2u, num_toolbar_items()); 772 EXPECT_EQ(2u, num_toolbar_items());
674 773
675 // Disable one of them - only one should remain highlighted. 774 // Disable one of them - only one should remain highlighted.
676 service()->DisableExtension(browser_action_a()->id(), 775 service()->DisableExtension(browser_action_a()->id(),
677 Extension::DISABLE_USER_ACTION); 776 extensions::Extension::DISABLE_USER_ACTION);
678 EXPECT_TRUE(toolbar_model()->is_highlighting()); 777 EXPECT_TRUE(toolbar_model()->is_highlighting());
679 EXPECT_EQ(1u, num_toolbar_items()); 778 EXPECT_EQ(1u, num_toolbar_items());
680 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(0u)); 779 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(0u));
681 780
682 // Uninstall the remaining highlighted extension. This should result in 781 // Uninstall the remaining highlighted extension. This should result in
683 // highlight mode exiting. 782 // highlight mode exiting.
684 service()->UninstallExtension(browser_action_b()->id(), 783 service()->UninstallExtension(browser_action_b()->id(),
685 UNINSTALL_REASON_FOR_TESTING, 784 extensions::UNINSTALL_REASON_FOR_TESTING,
686 base::Bind(&base::DoNothing), 785 base::Bind(&base::DoNothing),
687 NULL); // Ignore error. 786 NULL); // Ignore error.
688 EXPECT_FALSE(toolbar_model()->is_highlighting()); 787 EXPECT_FALSE(toolbar_model()->is_highlighting());
689 EXPECT_EQ(0, observer()->highlight_mode_count()); 788 EXPECT_EQ(0, observer()->highlight_mode_count());
690 EXPECT_EQ(1u, num_toolbar_items()); 789 EXPECT_EQ(2u, num_toolbar_items());
691 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u)); 790 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
791 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(1u));
692 792
693 // Test that removing an unhighlighted extension still works. 793 // Test that removing an unhighlighted extension still works.
694 // Reinstall extension b, and then highlight extension c. 794 // Reinstall extension B, and then highlight extension C.
695 ASSERT_TRUE(AddExtension(browser_action_b())); 795 ASSERT_TRUE(AddExtension(browser_action_b()));
696 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u)); 796 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
697 extension_ids.clear(); 797 action_ids.clear();
698 extension_ids.push_back(browser_action_c()->id()); 798 action_ids.push_back(browser_action_c()->id());
699 toolbar_model()->HighlightExtensions( 799 toolbar_model()->HighlightActions(
700 extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING); 800 action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
701 EXPECT_EQ(1, observer()->highlight_mode_count()); 801 EXPECT_EQ(1, observer()->highlight_mode_count());
702 EXPECT_TRUE(toolbar_model()->is_highlighting()); 802 EXPECT_TRUE(toolbar_model()->is_highlighting());
703 EXPECT_EQ(1u, num_toolbar_items()); 803 EXPECT_EQ(1u, num_toolbar_items());
704 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u)); 804 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(0u));
705 805
706 // Uninstalling b should not have visible impact. 806 // Uninstalling B should not have visible impact.
707 service()->UninstallExtension(browser_action_b()->id(), 807 service()->UninstallExtension(browser_action_b()->id(),
708 UNINSTALL_REASON_FOR_TESTING, 808 extensions::UNINSTALL_REASON_FOR_TESTING,
709 base::Bind(&base::DoNothing), 809 base::Bind(&base::DoNothing),
710 NULL); // Ignore error. 810 NULL); // Ignore error.
711 EXPECT_TRUE(toolbar_model()->is_highlighting()); 811 EXPECT_TRUE(toolbar_model()->is_highlighting());
712 EXPECT_EQ(1, observer()->highlight_mode_count()); 812 EXPECT_EQ(1, observer()->highlight_mode_count());
713 EXPECT_EQ(1u, num_toolbar_items()); 813 EXPECT_EQ(1u, num_toolbar_items());
714 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u)); 814 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(0u));
715 815
716 // When we stop, only extension c should remain. 816 // When we stop, only MCA and C should remain.
717 toolbar_model()->StopHighlighting(); 817 toolbar_model()->StopHighlighting();
718 EXPECT_FALSE(toolbar_model()->is_highlighting()); 818 EXPECT_FALSE(toolbar_model()->is_highlighting());
719 EXPECT_EQ(0, observer()->highlight_mode_count()); 819 EXPECT_EQ(0, observer()->highlight_mode_count());
720 EXPECT_EQ(1u, num_toolbar_items()); 820 EXPECT_EQ(2u, num_toolbar_items());
721 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u)); 821 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
722 } 822 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(1u));
723 823 }
724 TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarHighlightModeAdd) { 824
725 Init(); 825 TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarHighlightModeAdd) {
826 Init();
827
828 // One component action was added when the model was initialized.
829 EXPECT_EQ(1u, num_toolbar_items());
726 830
727 // Add the three browser action extensions. 831 // Add the three browser action extensions.
728 ASSERT_TRUE(AddBrowserActionExtensions()); 832 ASSERT_TRUE(AddBrowserActionExtensions());
729 EXPECT_EQ(3u, num_toolbar_items()); 833 EXPECT_EQ(4u, num_toolbar_items());
730 834
731 // Remove one (down to two). 835 // Remove one (down to three).
732 ASSERT_TRUE(RemoveExtension(browser_action_c())); 836 ASSERT_TRUE(RemoveExtension(browser_action_c()));
733 837
734 // Highlight one of the two extensions. 838 // Highlight one of the three actions (one of the two extensinos).
735 ExtensionIdList extension_ids; 839 ActionIdList action_ids;
736 extension_ids.push_back(browser_action_a()->id()); 840 action_ids.push_back(browser_action_a()->id());
737 toolbar_model()->HighlightExtensions( 841 toolbar_model()->HighlightActions(
738 extension_ids, ExtensionToolbarModel::HIGHLIGHT_WARNING); 842 action_ids, ToolbarActionsModel::HIGHLIGHT_WARNING);
739 EXPECT_TRUE(toolbar_model()->is_highlighting()); 843 EXPECT_TRUE(toolbar_model()->is_highlighting());
740 EXPECT_EQ(1u, num_toolbar_items()); 844 EXPECT_EQ(1u, num_toolbar_items());
741 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 845 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u));
742 846
743 // Adding a new extension should have no visible effect. 847 // Adding a new extension should have no visible effect.
744 ASSERT_TRUE(AddExtension(browser_action_c())); 848 ASSERT_TRUE(AddExtension(browser_action_c()));
745 EXPECT_TRUE(toolbar_model()->is_highlighting()); 849 EXPECT_TRUE(toolbar_model()->is_highlighting());
746 EXPECT_EQ(1u, num_toolbar_items()); 850 EXPECT_EQ(1u, num_toolbar_items());
747 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 851 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u));
748 852
749 // When we stop highlighting, we should see the new extension show up. 853 // When we stop highlighting, we should see the new extension show up.
750 toolbar_model()->StopHighlighting(); 854 toolbar_model()->StopHighlighting();
751 EXPECT_FALSE(toolbar_model()->is_highlighting()); 855 EXPECT_FALSE(toolbar_model()->is_highlighting());
752 EXPECT_EQ(3u, num_toolbar_items()); 856 EXPECT_EQ(4u, num_toolbar_items());
753 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 857 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
754 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u)); 858 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
755 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u)); 859 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
756 } 860 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
757 861 }
758 // Test that the extension toolbar maintains the proper size, even after a pref 862
863 // Test that the action toolbar maintains the proper size, even after a pref
759 // change. 864 // change.
760 TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarSizeAfterPrefChange) { 865 TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarSizeAfterPrefChange) {
761 Init(); 866 Init();
867
868 // One component action was added when the model was initialized.
869 EXPECT_EQ(1u, num_toolbar_items());
762 870
763 // Add the three browser action extensions. 871 // Add the three browser action extensions.
764 ASSERT_TRUE(AddBrowserActionExtensions()); 872 ASSERT_TRUE(AddBrowserActionExtensions());
765 EXPECT_EQ(3u, num_toolbar_items()); 873 EXPECT_EQ(4u, num_toolbar_items());
766 874
767 // Should be at max size. 875 // Should be at max size.
768 EXPECT_TRUE(toolbar_model()->all_icons_visible()); 876 EXPECT_TRUE(toolbar_model()->all_icons_visible());
769 EXPECT_EQ(num_toolbar_items(), toolbar_model()->visible_icon_count()); 877 EXPECT_EQ(num_toolbar_items(), toolbar_model()->visible_icon_count());
770 toolbar_model()->OnExtensionToolbarPrefChange(); 878 toolbar_model()->OnActionToolbarPrefChange();
771 // Should still be at max size. 879 // Should still be at max size.
772 EXPECT_TRUE(toolbar_model()->all_icons_visible()); 880 EXPECT_TRUE(toolbar_model()->all_icons_visible());
773 EXPECT_EQ(num_toolbar_items(), toolbar_model()->visible_icon_count()); 881 EXPECT_EQ(num_toolbar_items(), toolbar_model()->visible_icon_count());
774 } 882 }
775 883
776 // Test that, in the absence of the extension-action-redesign switch, the 884 // Test that, in the absence of the extension-action-redesign switch, the
777 // model only contains extensions with browser actions. 885 // model only contains extensions with browser actions and component actions.
778 TEST_F(ExtensionToolbarModelUnitTest, TestToolbarExtensionTypesNoSwitch) { 886 TEST_F(ToolbarActionsModelUnitTest, TestToolbarExtensionTypesNoSwitch) {
779 Init(); 887 Init();
888
889 // One component action was added when the model was initialized.
890 EXPECT_EQ(1u, num_toolbar_items());
891
780 ASSERT_TRUE(AddActionExtensions()); 892 ASSERT_TRUE(AddActionExtensions());
781 893
782 EXPECT_EQ(1u, num_toolbar_items()); 894 EXPECT_EQ(2u, num_toolbar_items());
783 EXPECT_EQ(browser_action(), GetExtensionAtIndex(0u)); 895 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
896 EXPECT_EQ(browser_action()->id(), GetActionIdAtIndex(1u));
784 } 897 }
785 898
786 // Test that, with the extension-action-redesign switch, the model contains 899 // Test that, with the extension-action-redesign switch, the model contains
787 // all types of extensions, except those which should not be displayed on the 900 // all types of extensions, except those which should not be displayed on the
788 // toolbar (like component extensions). 901 // toolbar (like component extensions).
789 TEST_F(ExtensionToolbarModelUnitTest, TestToolbarExtensionTypesSwitch) { 902 TEST_F(ToolbarActionsModelUnitTest, TestToolbarExtensionTypesSwitch) {
790 FeatureSwitch::ScopedOverride enable_redesign( 903 extensions::FeatureSwitch::ScopedOverride enable_redesign(
791 FeatureSwitch::extension_action_redesign(), true); 904 extensions::FeatureSwitch::extension_action_redesign(), true);
792 Init(); 905 Init();
906
907 // One component action was added when the model was initialized.
908 EXPECT_EQ(1u, num_toolbar_items());
909
793 ASSERT_TRUE(AddActionExtensions()); 910 ASSERT_TRUE(AddActionExtensions());
794 911
795 // With the switch on, extensions with page actions and no action should also 912 // With the switch on, extensions with page actions and no action should also
796 // be displayed in the toolbar. 913 // be displayed in the toolbar.
797 EXPECT_EQ(3u, num_toolbar_items()); 914 EXPECT_EQ(4u, num_toolbar_items());
798 EXPECT_EQ(browser_action(), GetExtensionAtIndex(0u)); 915 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
799 EXPECT_EQ(page_action(), GetExtensionAtIndex(1u)); 916 EXPECT_EQ(browser_action()->id(), GetActionIdAtIndex(1u));
800 EXPECT_EQ(no_action(), GetExtensionAtIndex(2u)); 917 EXPECT_EQ(page_action()->id(), GetActionIdAtIndex(2u));
918 EXPECT_EQ(no_action()->id(), GetActionIdAtIndex(3u));
801 } 919 }
802 920
803 // Test that hiding actions on the toolbar results in their removal from the 921 // Test that hiding actions on the toolbar results in their removal from the
804 // model when the redesign switch is not enabled. 922 // model when the redesign switch is not enabled.
805 TEST_F(ExtensionToolbarModelUnitTest, 923 TEST_F(ToolbarActionsModelUnitTest,
806 ExtensionToolbarActionsVisibilityNoSwitch) { 924 ActionsToolbarActionsVisibilityNoSwitch) {
807 Init(); 925 Init();
808 926
809 ExtensionActionAPI* action_api = ExtensionActionAPI::Get(profile()); 927 // One component action was added when the model was initialized.
810 928 EXPECT_EQ(1u, num_toolbar_items());
811 ASSERT_TRUE(AddBrowserActionExtensions()); 929
812 // Sanity check: Order should start as A B C. 930 extensions::ExtensionActionAPI* action_api =
813 EXPECT_EQ(3u, num_toolbar_items()); 931 extensions::ExtensionActionAPI::Get(profile());
814 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 932
815 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u)); 933 ASSERT_TRUE(AddBrowserActionExtensions());
816 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u)); 934 // Sanity check: Order should start as MCA, A , B, C.
935 EXPECT_EQ(4u, num_toolbar_items());
936 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
937 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
938 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
939 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
817 940
818 // By default, all actions should be visible. 941 // By default, all actions should be visible.
819 EXPECT_TRUE(action_api->GetBrowserActionVisibility(browser_action_a()->id())); 942 EXPECT_TRUE(action_api->GetBrowserActionVisibility(browser_action_a()->id()));
820 EXPECT_TRUE(action_api->GetBrowserActionVisibility(browser_action_b()->id())); 943 EXPECT_TRUE(action_api->GetBrowserActionVisibility(browser_action_b()->id()));
821 EXPECT_TRUE(action_api->GetBrowserActionVisibility(browser_action_c()->id())); 944 EXPECT_TRUE(action_api->GetBrowserActionVisibility(browser_action_c()->id()));
822 945
823 // Hiding an action should result in its removal from the toolbar. 946 // Hiding an action should result in its removal from the toolbar.
824 action_api->SetBrowserActionVisibility(browser_action_b()->id(), false); 947 action_api->SetBrowserActionVisibility(browser_action_b()->id(), false);
825 EXPECT_FALSE(action_api->GetBrowserActionVisibility( 948 EXPECT_FALSE(action_api->GetBrowserActionVisibility(
826 browser_action_b()->id())); 949 browser_action_b()->id()));
827 // Thus, there should now only be two items on the toolbar - A and C. 950 // Thus, there should now only be three items on the toolbar: MCA, A, C.
828 EXPECT_EQ(2u, num_toolbar_items()); 951 EXPECT_EQ(3u, num_toolbar_items());
829 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 952 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
830 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u)); 953 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
954 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u));
831 955
832 // Resetting the visibility to 'true' should result in the extension being 956 // Resetting the visibility to 'true' should result in the extension being
833 // added back at its original position. 957 // added back at its original position.
834 action_api->SetBrowserActionVisibility(browser_action_b()->id(), true); 958 action_api->SetBrowserActionVisibility(browser_action_b()->id(), true);
835 EXPECT_TRUE(action_api->GetBrowserActionVisibility(browser_action_b()->id())); 959 EXPECT_TRUE(action_api->GetBrowserActionVisibility(browser_action_b()->id()));
836 // So the toolbar order should be A B C. 960 // So the toolbar order should be MCA, A, B, C.
837 EXPECT_EQ(3u, num_toolbar_items()); 961 EXPECT_EQ(4u, num_toolbar_items());
838 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 962 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
839 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u)); 963 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
840 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2u)); 964 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u));
965 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u));
841 } 966 }
842 967
843 TEST_F(ExtensionToolbarModelUnitTest, ExtensionToolbarIncognitoModeTest) { 968 TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarIncognitoModeTest) {
844 Init(); 969 Init();
970
845 ASSERT_TRUE(AddBrowserActionExtensions()); 971 ASSERT_TRUE(AddBrowserActionExtensions());
846 972
847 // Give two extensions incognito access. 973 // Give two extensions incognito access.
848 // Note: We use ExtensionPrefs::SetIsIncognitoEnabled instead of 974 // Note: We use ExtensionPrefs::SetIsIncognitoEnabled instead of
849 // util::SetIsIncognitoEnabled because the latter tries to reload the 975 // util::SetIsIncognitoEnabled because the latter tries to reload the
850 // extension, which requries a filepath associated with the extension (and, 976 // extension, which requries a filepath associated with the extension (and,
851 // for this test, reloading the extension is irrelevant to us). 977 // for this test, reloading the extension is irrelevant to us).
852 ExtensionPrefs* extension_prefs = ExtensionPrefs::Get(profile()); 978 extensions::ExtensionPrefs* extension_prefs =
979 extensions::ExtensionPrefs::Get(profile());
853 extension_prefs->SetIsIncognitoEnabled(browser_action_b()->id(), true); 980 extension_prefs->SetIsIncognitoEnabled(browser_action_b()->id(), true);
854 extension_prefs->SetIsIncognitoEnabled(browser_action_c()->id(), true); 981 extension_prefs->SetIsIncognitoEnabled(browser_action_c()->id(), true);
855 982
856 util::SetIsIncognitoEnabled(browser_action_b()->id(), profile(), true); 983 extensions::util::SetIsIncognitoEnabled(browser_action_b()->id(),
857 util::SetIsIncognitoEnabled(browser_action_c()->id(), profile(), true); 984 profile(), true);
985 extensions::util::SetIsIncognitoEnabled(browser_action_c()->id(),
986 profile(), true);
858 987
859 // Move C to the second index. 988 // Move C to the second index.
860 toolbar_model()->MoveExtensionIcon(browser_action_c()->id(), 1u); 989 toolbar_model()->MoveActionIcon(browser_action_c()->id(), 2u);
861 // Set visible count to 2 so that c is overflowed. State is A C [B]. 990 // Set visible count to 3 so that C is overflowed. State is MCA, A, C, [B].
862 toolbar_model()->SetVisibleIconCount(2); 991 toolbar_model()->SetVisibleIconCount(3);
863 EXPECT_EQ(1u, observer()->moved_count()); 992 EXPECT_EQ(1u, observer()->moved_count());
864 993
865 // Get an incognito profile and toolbar. 994 // Get an incognito profile and toolbar.
866 ExtensionToolbarModel* incognito_model = 995 ToolbarActionsModel* incognito_model =
867 extension_action_test_util::CreateToolbarModelForProfile( 996 extensions::extension_action_test_util::CreateToolbarModelForProfile(
868 profile()->GetOffTheRecordProfile()); 997 profile()->GetOffTheRecordProfile());
869 998
870 ExtensionToolbarModelTestObserver incognito_observer(incognito_model); 999 ToolbarActionsModelTestObserver incognito_observer(incognito_model);
871 EXPECT_EQ(0u, incognito_observer.moved_count()); 1000 EXPECT_EQ(0u, incognito_observer.moved_count());
872 1001
873 // We should have two items, C and B, and the order should be preserved from 1002 // We should have three items: MCA, C, B, and the order should be preserved
874 // the original model. 1003 // from the original model.
875 EXPECT_EQ(2u, incognito_model->toolbar_items().size()); 1004 EXPECT_EQ(3u, incognito_model->toolbar_items().size());
876 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(0u, incognito_model)); 1005 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u, incognito_model));
877 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1u, incognito_model)); 1006 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(1u, incognito_model));
1007 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2u, incognito_model));
878 1008
879 // Extensions in the overflow menu in the regular toolbar should remain in 1009 // Actions in the overflow menu in the regular toolbar should remain in
880 // overflow in the incognito toolbar. So, we should have C [B]. 1010 // overflow in the incognito toolbar. So, we should have MCA, C, [B].
881 EXPECT_EQ(1u, incognito_model->visible_icon_count()); 1011 EXPECT_EQ(2u, incognito_model->visible_icon_count());
882 // The regular model should still have two icons visible. 1012 // The regular model should still have three icons visible.
883 EXPECT_EQ(2u, toolbar_model()->visible_icon_count()); 1013 EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
884 1014
885 // Changing the incognito model size should not affect the regular model. 1015 // Changing the incognito model size should not affect the regular model.
886 incognito_model->SetVisibleIconCount(0); 1016 incognito_model->SetVisibleIconCount(0);
887 EXPECT_EQ(0u, incognito_model->visible_icon_count()); 1017 EXPECT_EQ(0u, incognito_model->visible_icon_count());
888 EXPECT_EQ(2u, toolbar_model()->visible_icon_count()); 1018 EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
889 1019
890 // Expanding the incognito model to 2 should register as "all icons" 1020 // Expanding the incognito model to 3 should register as "all icons"
891 // since it is all of the incognito-enabled extensions. 1021 // since it is all of the incognito-enabled extensions.
892 incognito_model->SetVisibleIconCount(2u); 1022 incognito_model->SetVisibleIconCount(3u);
893 EXPECT_EQ(2u, incognito_model->visible_icon_count()); 1023 EXPECT_EQ(3u, incognito_model->visible_icon_count());
894 EXPECT_TRUE(incognito_model->all_icons_visible()); 1024 EXPECT_TRUE(incognito_model->all_icons_visible());
895 1025
896 // Moving icons in the incognito toolbar should not affect the regular 1026 // Moving icons in the incognito toolbar should not affect the regular
897 // toolbar. Incognito currently has C B... 1027 // toolbar. Incognito currently has MCA, C, B...
898 incognito_model->MoveExtensionIcon(browser_action_b()->id(), 0u); 1028 incognito_model->MoveActionIcon(browser_action_b()->id(), 0u);
899 // So now it should be B C... 1029 // So now it should be B, MCA, C...
900 EXPECT_EQ(1u, incognito_observer.moved_count()); 1030 EXPECT_EQ(1u, incognito_observer.moved_count());
901 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(0u, incognito_model)); 1031 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(0u, incognito_model));
902 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u, incognito_model)); 1032 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u, incognito_model));
1033 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u, incognito_model));
903 // ... and the regular toolbar should be unaffected. 1034 // ... and the regular toolbar should be unaffected.
904 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0u)); 1035 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
905 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1u)); 1036 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1u));
906 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(2u)); 1037 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u));
1038 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(3u));
907 1039
908 // Similarly, the observer for the regular model should not have received 1040 // Similarly, the observer for the regular model should not have received
909 // any updates. 1041 // any updates.
910 EXPECT_EQ(1u, observer()->moved_count()); 1042 EXPECT_EQ(1u, observer()->moved_count());
911 1043
912 // And performing moves on the regular model should have no effect on the 1044 // And performing moves on the regular model should have no effect on the
913 // incognito model or its observers. 1045 // incognito model or its observers.
914 toolbar_model()->MoveExtensionIcon(browser_action_c()->id(), 2u); 1046 toolbar_model()->MoveActionIcon(browser_action_c()->id(), 2u);
915 EXPECT_EQ(2u, observer()->moved_count()); 1047 EXPECT_EQ(2u, observer()->moved_count());
916 EXPECT_EQ(1u, incognito_observer.moved_count()); 1048 EXPECT_EQ(1u, incognito_observer.moved_count());
917 } 1049 }
918 1050
919 // Test that enabling extensions incognito with an active incognito profile 1051 // Test that enabling extensions incognito with an active incognito profile
920 // works. 1052 // works.
921 TEST_F(ExtensionToolbarModelUnitTest, 1053 TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarIncognitoEnableExtension) {
922 ExtensionToolbarIncognitoEnableExtension) {
923 Init(); 1054 Init();
924 1055
925 const char* kManifest = 1056 const char* kManifest =
926 "{" 1057 "{"
927 " \"name\": \"%s\"," 1058 " \"name\": \"%s\","
928 " \"version\": \"1.0\"," 1059 " \"version\": \"1.0\","
929 " \"manifest_version\": 2," 1060 " \"manifest_version\": 2,"
930 " \"browser_action\": {}" 1061 " \"browser_action\": {}"
931 "}"; 1062 "}";
932 1063
933 // For this test, we need to have "real" extension files, because we need to 1064 // For this test, we need to have "real" extension files, because we need to
934 // be able to reload them during the incognito process. Since the toolbar 1065 // be able to reload them during the incognito process. Since the toolbar
935 // needs to be notified of the reload, we need it this time (as opposed to 1066 // needs to be notified of the reload, we need it this time (as opposed to
936 // above, where we simply set the prefs before the incognito bar was 1067 // above, where we simply set the prefs before the incognito bar was
937 // created. 1068 // created.
938 TestExtensionDir dir1; 1069 extensions::TestExtensionDir dir1;
939 dir1.WriteManifest(base::StringPrintf(kManifest, "incognito1")); 1070 dir1.WriteManifest(base::StringPrintf(kManifest, "incognito1"));
940 TestExtensionDir dir2; 1071 extensions::TestExtensionDir dir2;
941 dir2.WriteManifest(base::StringPrintf(kManifest, "incognito2")); 1072 dir2.WriteManifest(base::StringPrintf(kManifest, "incognito2"));
942 1073
943 TestExtensionDir* dirs[] = { &dir1, &dir2 }; 1074 extensions::TestExtensionDir* dirs[] = { &dir1, &dir2 };
944 const Extension* extensions[] = { nullptr, nullptr }; 1075 const extensions::Extension* extensions[] = { nullptr, nullptr };
945 for (size_t i = 0; i < arraysize(dirs); ++i) { 1076 for (size_t i = 0; i < arraysize(dirs); ++i) {
946 // The extension id will be calculated from the file path; we need this to 1077 // The extension id will be calculated from the file path; we need this to
947 // wait for the extension to load. 1078 // wait for the extension to load.
948 base::FilePath path_for_id = 1079 base::FilePath path_for_id =
949 base::MakeAbsoluteFilePath(dirs[i]->unpacked_path()); 1080 base::MakeAbsoluteFilePath(dirs[i]->unpacked_path());
950 std::string id = crx_file::id_util::GenerateIdForPath(path_for_id); 1081 std::string id = crx_file::id_util::GenerateIdForPath(path_for_id);
951 TestExtensionRegistryObserver observer(registry(), id); 1082 extensions::TestExtensionRegistryObserver observer(registry(), id);
952 UnpackedInstaller::Create(service())->Load(dirs[i]->unpacked_path()); 1083 extensions::UnpackedInstaller::Create(service())->Load(
1084 dirs[i]->unpacked_path());
953 observer.WaitForExtensionLoaded(); 1085 observer.WaitForExtensionLoaded();
954 extensions[i] = registry()->enabled_extensions().GetByID(id); 1086 extensions[i] = registry()->enabled_extensions().GetByID(id);
955 ASSERT_TRUE(extensions[i]); 1087 ASSERT_TRUE(extensions[i]);
956 } 1088 }
957 1089
958 // For readability, alias to A and B. Since we'll be reloading these 1090 // For readability, alias to A and B. Since we'll be reloading these
959 // extensions, we also can't rely on pointers. 1091 // extensions, we also can't rely on pointers.
960 std::string extension_a = extensions[0]->id(); 1092 std::string extension_a = extensions[0]->id();
961 std::string extension_b = extensions[1]->id(); 1093 std::string extension_b = extensions[1]->id();
962 1094
963 // The first model should have both extensions visible. 1095 // The first model should have both extensions visible.
964 EXPECT_EQ(2u, toolbar_model()->toolbar_items().size()); 1096 EXPECT_EQ(3u, toolbar_model()->toolbar_items().size());
965 EXPECT_EQ(extension_a, GetExtensionAtIndex(0)->id()); 1097 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
966 EXPECT_EQ(extension_b, GetExtensionAtIndex(1)->id()); 1098 EXPECT_EQ(extension_a, GetActionIdAtIndex(1u));
1099 EXPECT_EQ(extension_b, GetActionIdAtIndex(2u));
967 1100
968 // Set the model to only show one extension, so the order is A [B]. 1101 // Set the model to only show one extension, so the order is MCA, A, [B].
969 toolbar_model()->SetVisibleIconCount(1u); 1102 toolbar_model()->SetVisibleIconCount(1u);
970 1103
971 // Get an incognito profile and toolbar. 1104 // Get an incognito profile and toolbar.
972 ExtensionToolbarModel* incognito_model = 1105 ToolbarActionsModel* incognito_model =
973 extension_action_test_util::CreateToolbarModelForProfile( 1106 extensions::extension_action_test_util::CreateToolbarModelForProfile(
974 profile()->GetOffTheRecordProfile()); 1107 profile()->GetOffTheRecordProfile());
975 ExtensionToolbarModelTestObserver incognito_observer(incognito_model); 1108 ToolbarActionsModelTestObserver incognito_observer(incognito_model);
976 1109
977 // Right now, no extensions are enabled in incognito mode. 1110 // Right now, only the component action is enabled in incognito mode.
978 EXPECT_EQ(0u, incognito_model->toolbar_items().size()); 1111 EXPECT_EQ(1u, incognito_model->toolbar_items().size());
979 1112
980 // Set extension b (which is overflowed) to be enabled in incognito. This 1113 // Set extension B (which is overflowed) to be enabled in incognito. This
981 // results in b reloading, so wait for it. 1114 // results in b reloading, so wait for it.
982 { 1115 {
983 TestExtensionRegistryObserver observer(registry(), extension_b); 1116 extensions::TestExtensionRegistryObserver observer(registry(), extension_b);
984 util::SetIsIncognitoEnabled(extension_b, profile(), true); 1117 extensions::util::SetIsIncognitoEnabled(extension_b, profile(), true);
985 observer.WaitForExtensionLoaded(); 1118 observer.WaitForExtensionLoaded();
986 } 1119 }
987 1120
988 // Now, we should have one icon in the incognito bar. But, since B is 1121 // Now, we should have two icons in the incognito bar. But, since B is
989 // overflowed in the main bar, it shouldn't be visible. 1122 // overflowed in the main bar, it shouldn't be visible.
990 EXPECT_EQ(1u, incognito_model->toolbar_items().size()); 1123 EXPECT_EQ(2u, incognito_model->toolbar_items().size());
991 EXPECT_EQ(extension_b, GetExtensionAtIndex(0u, incognito_model)->id()); 1124 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u, incognito_model));
992 EXPECT_EQ(0u, incognito_model->visible_icon_count()); 1125 EXPECT_EQ(extension_b, GetActionIdAtIndex(1u, incognito_model));
1126 EXPECT_EQ(1u, incognito_model->visible_icon_count());
993 1127
994 // Also enable extension a for incognito (again, wait for the reload). 1128 // Also enable extension a for incognito (again, wait for the reload).
995 { 1129 {
996 TestExtensionRegistryObserver observer(registry(), extension_a); 1130 extensions::TestExtensionRegistryObserver observer(registry(), extension_a);
997 util::SetIsIncognitoEnabled(extension_a, profile(), true); 1131 extensions::util::SetIsIncognitoEnabled(extension_a, profile(), true);
998 observer.WaitForExtensionLoaded(); 1132 observer.WaitForExtensionLoaded();
999 } 1133 }
1000 1134
1001 // Now, both extensions should be enabled in incognito mode. In addition, the 1135 // Now, both extensions should be enabled in incognito mode. In addition, the
1002 // incognito toolbar should have expanded to show extension a (since it isn't 1136 // incognito toolbar should have expanded to show extension A (since it isn't
1003 // overflowed in the main bar). 1137 // overflowed in the main bar).
1004 EXPECT_EQ(2u, incognito_model->toolbar_items().size()); 1138 EXPECT_EQ(3u, incognito_model->toolbar_items().size());
1005 EXPECT_EQ(extension_a, GetExtensionAtIndex(0u, incognito_model)->id()); 1139 EXPECT_EQ(component_action_id(),
1006 EXPECT_EQ(extension_b, GetExtensionAtIndex(1u, incognito_model)->id()); 1140 GetActionIdAtIndex(0u, incognito_model));
1141 EXPECT_EQ(extension_a, GetActionIdAtIndex(1u, incognito_model));
1142 EXPECT_EQ(extension_b, GetActionIdAtIndex(2u, incognito_model));
1007 EXPECT_EQ(1u, incognito_model->visible_icon_count()); 1143 EXPECT_EQ(1u, incognito_model->visible_icon_count());
1008 } 1144 }
1009 1145
1010 // Test that hiding actions on the toolbar results in sending them to the 1146 // Test that hiding actions on the toolbar results in sending them to the
1011 // overflow menu when the redesign switch is enabled. 1147 // overflow menu when the redesign switch is enabled.
1012 TEST_F(ExtensionToolbarModelUnitTest, 1148 TEST_F(ToolbarActionsModelUnitTest,
1013 ExtensionToolbarActionsVisibilityWithSwitch) { 1149 ActionsToolbarActionsVisibilityWithSwitch) {
1014 FeatureSwitch::ScopedOverride enable_redesign( 1150 extensions::FeatureSwitch::ScopedOverride enable_redesign(
1015 FeatureSwitch::extension_action_redesign(), true); 1151 extensions::FeatureSwitch::extension_action_redesign(), true);
1016 Init(); 1152 Init();
1017 1153
1018 // We choose to use all types of extensions here, since the misnamed 1154 // We choose to use all types of extensions here, since the misnamed
1019 // BrowserActionVisibility is now for toolbar visibility. 1155 // BrowserActionVisibility is now for toolbar visibility.
1020 ASSERT_TRUE(AddActionExtensions()); 1156 ASSERT_TRUE(AddActionExtensions());
1021 1157
1022 // For readability, alias extensions A B C. 1158 // For readability, alias extensions A B C.
1023 const Extension* extension_a = browser_action(); 1159 const extensions::Extension* extension_a = browser_action();
1024 const Extension* extension_b = page_action(); 1160 const extensions::Extension* extension_b = page_action();
1025 const Extension* extension_c = no_action(); 1161 const extensions::Extension* extension_c = no_action();
1026 1162
1027 // Sanity check: Order should start as A B C, with all three visible. 1163 // Sanity check: Order should start as MCA, A, B, C, with all four visible.
1028 EXPECT_EQ(3u, num_toolbar_items()); 1164 EXPECT_EQ(4u, num_toolbar_items());
1029 EXPECT_TRUE(toolbar_model()->all_icons_visible()); 1165 EXPECT_TRUE(toolbar_model()->all_icons_visible());
1030 EXPECT_EQ(extension_a, GetExtensionAtIndex(0u)); 1166 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
1031 EXPECT_EQ(extension_b, GetExtensionAtIndex(1u)); 1167 EXPECT_EQ(extension_a->id(), GetActionIdAtIndex(1u));
1032 EXPECT_EQ(extension_c, GetExtensionAtIndex(2u)); 1168 EXPECT_EQ(extension_b->id(), GetActionIdAtIndex(2u));
1169 EXPECT_EQ(extension_c->id(), GetActionIdAtIndex(3u));
1033 1170
1034 ExtensionActionAPI* action_api = ExtensionActionAPI::Get(profile()); 1171 extensions::ExtensionActionAPI* action_api =
1172 extensions::ExtensionActionAPI::Get(profile());
1035 1173
1036 // By default, all actions should be visible. 1174 // By default, all actions should be visible.
1037 EXPECT_TRUE(action_api->GetBrowserActionVisibility(extension_a->id())); 1175 EXPECT_TRUE(action_api->GetBrowserActionVisibility(extension_a->id()));
1038 EXPECT_TRUE(action_api->GetBrowserActionVisibility(extension_c->id())); 1176 EXPECT_TRUE(action_api->GetBrowserActionVisibility(extension_c->id()));
1039 EXPECT_TRUE(action_api->GetBrowserActionVisibility(extension_b->id())); 1177 EXPECT_TRUE(action_api->GetBrowserActionVisibility(extension_b->id()));
1040 1178
1041 // Hiding an action should result in it being sent to the overflow menu. 1179 // Hiding an action should result in it being sent to the overflow menu.
1042 action_api->SetBrowserActionVisibility(extension_b->id(), false); 1180 action_api->SetBrowserActionVisibility(extension_b->id(), false);
1043 1181
1044 // Thus, the order should be A C B, with B in the overflow. 1182 // Thus, the order should be MCA, A, C, B, with B in the overflow.
1045 EXPECT_EQ(3u, num_toolbar_items()); 1183 EXPECT_EQ(4u, num_toolbar_items());
1046 EXPECT_EQ(2u, toolbar_model()->visible_icon_count()); 1184 EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
1047 EXPECT_EQ(extension_a, GetExtensionAtIndex(0u)); 1185 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
1048 EXPECT_EQ(extension_c, GetExtensionAtIndex(1u)); 1186 EXPECT_EQ(extension_a->id(), GetActionIdAtIndex(1u));
1049 EXPECT_EQ(extension_b, GetExtensionAtIndex(2u)); 1187 EXPECT_EQ(extension_c->id(), GetActionIdAtIndex(2u));
1188 EXPECT_EQ(extension_b->id(), GetActionIdAtIndex(3u));
1050 1189
1051 // Hiding an extension's action should result in it being sent to the overflow 1190 // Hiding an extension's action should result in it being sent to the overflow
1052 // as well, but as the _first_ extension in the overflow. 1191 // as well, but as the _first_ extension in the overflow.
1053 action_api->SetBrowserActionVisibility(extension_a->id(), false); 1192 action_api->SetBrowserActionVisibility(extension_a->id(), false);
1054 // Thus, the order should be C A B, with A and B in the overflow. 1193 // Thus, the order should be MCA, C, A, B, with A and B in the overflow.
1055 EXPECT_EQ(3u, num_toolbar_items()); 1194 EXPECT_EQ(4u, num_toolbar_items());
1056 EXPECT_EQ(1u, toolbar_model()->visible_icon_count()); 1195 EXPECT_EQ(2u, toolbar_model()->visible_icon_count());
1057 EXPECT_EQ(extension_c, GetExtensionAtIndex(0u)); 1196 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
1058 EXPECT_EQ(extension_a, GetExtensionAtIndex(1u)); 1197 EXPECT_EQ(extension_c->id(), GetActionIdAtIndex(1u));
1059 EXPECT_EQ(extension_b, GetExtensionAtIndex(2u)); 1198 EXPECT_EQ(extension_a->id(), GetActionIdAtIndex(2u));
1199 EXPECT_EQ(extension_b->id(), GetActionIdAtIndex(3u));
1060 1200
1061 // Resetting A's visibility to true should send it back to the visible icons 1201 // Resetting A's visibility to true should send it back to the visible icons
1062 // (and should grow visible icons by 1), but it should be added to the end of 1202 // (and should grow visible icons by 1), but it should be added to the end of
1063 // the visible icon list (not to its original position). 1203 // the visible icon list (not to its original position).
1064 action_api->SetBrowserActionVisibility(extension_a->id(), true); 1204 action_api->SetBrowserActionVisibility(extension_a->id(), true);
1065 // So order is C A B, with only B in the overflow. 1205 // So order is MCA, C, A, B, with only B in the overflow.
1066 EXPECT_EQ(3u, num_toolbar_items()); 1206 EXPECT_EQ(4u, num_toolbar_items());
1067 EXPECT_EQ(2u, toolbar_model()->visible_icon_count()); 1207 EXPECT_EQ(3u, toolbar_model()->visible_icon_count());
1068 EXPECT_EQ(extension_c, GetExtensionAtIndex(0u)); 1208 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
1069 EXPECT_EQ(extension_a, GetExtensionAtIndex(1u)); 1209 EXPECT_EQ(extension_c->id(), GetActionIdAtIndex(1u));
1070 EXPECT_EQ(extension_b, GetExtensionAtIndex(2u)); 1210 EXPECT_EQ(extension_a->id(), GetActionIdAtIndex(2u));
1211 EXPECT_EQ(extension_b->id(), GetActionIdAtIndex(3u));
1071 1212
1072 // Resetting B to be visible should make the order C A B, with no overflow. 1213 // Resetting B to be visible should make the order MCA, C, A, B, with no
1214 // overflow.
1073 action_api->SetBrowserActionVisibility(extension_b->id(), true); 1215 action_api->SetBrowserActionVisibility(extension_b->id(), true);
1074 EXPECT_EQ(3u, num_toolbar_items()); 1216 EXPECT_EQ(4u, num_toolbar_items());
1075 EXPECT_TRUE(toolbar_model()->all_icons_visible()); 1217 EXPECT_TRUE(toolbar_model()->all_icons_visible());
1076 EXPECT_EQ(extension_c, GetExtensionAtIndex(0u)); 1218 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0u));
1077 EXPECT_EQ(extension_a, GetExtensionAtIndex(1u)); 1219 EXPECT_EQ(extension_c->id(), GetActionIdAtIndex(1u));
1078 EXPECT_EQ(extension_b, GetExtensionAtIndex(2u)); 1220 EXPECT_EQ(extension_a->id(), GetActionIdAtIndex(2u));
1221 EXPECT_EQ(extension_b->id(), GetActionIdAtIndex(3u));
1079 } 1222 }
1080 1223
1081 // Test that observers receive no Added notifications until after the 1224 // Test that observers receive no Added notifications until after the
1082 // ExtensionSystem has initialized. 1225 // ExtensionSystem has initialized.
1083 TEST_F(ExtensionToolbarModelUnitTest, ModelWaitsForExtensionSystemReady) { 1226 TEST_F(ToolbarActionsModelUnitTest, ModelWaitsForExtensionSystemReady) {
1084 InitializeEmptyExtensionService(); 1227 InitializeEmptyExtensionService();
1085 ExtensionToolbarModel* toolbar_model = 1228 ToolbarActionsModel* toolbar_model =
1086 extension_action_test_util:: 1229 extensions::extension_action_test_util::
1087 CreateToolbarModelForProfileWithoutWaitingForReady(profile()); 1230 CreateToolbarModelForProfileWithoutWaitingForReady(profile());
1088 ExtensionToolbarModelTestObserver model_observer(toolbar_model); 1231 ToolbarActionsModelTestObserver model_observer(toolbar_model);
1232
1089 EXPECT_TRUE(AddBrowserActionExtensions()); 1233 EXPECT_TRUE(AddBrowserActionExtensions());
1090 1234
1091 // Since the model hasn't been initialized (the ExtensionSystem::ready task 1235 // Since the model hasn't been initialized (the ExtensionSystem::ready task
1092 // hasn't been run), there should be no insertion notifications. 1236 // hasn't been run), there should be no insertion notifications.
1093 EXPECT_EQ(0u, model_observer.inserted_count()); 1237 EXPECT_EQ(0u, model_observer.inserted_count());
1094 EXPECT_EQ(0u, model_observer.initialized_count()); 1238 EXPECT_EQ(0u, model_observer.initialized_count());
1095 EXPECT_FALSE(toolbar_model->extensions_initialized()); 1239 EXPECT_FALSE(toolbar_model->actions_initialized());
1096 1240
1097 // Run the ready task. 1241 // Run the ready task.
1098 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile()))-> 1242 static_cast<extensions::TestExtensionSystem*>(
1099 SetReady(); 1243 extensions::ExtensionSystem::Get(profile()))->SetReady();
1100 // Run tasks posted to TestExtensionSystem. 1244 // Run tasks posted to TestExtensionSystem.
1101 base::RunLoop().RunUntilIdle(); 1245 base::RunLoop().RunUntilIdle();
1102 1246
1103 // We should still have no insertions, but should have an initialized count. 1247 // We should still have no insertions, but should have an initialized count.
1104 EXPECT_TRUE(toolbar_model->extensions_initialized()); 1248 EXPECT_TRUE(toolbar_model->actions_initialized());
1105 EXPECT_EQ(0u, model_observer.inserted_count()); 1249 EXPECT_EQ(0u, model_observer.inserted_count());
1106 EXPECT_EQ(1u, model_observer.initialized_count()); 1250 EXPECT_EQ(1u, model_observer.initialized_count());
1107 } 1251 }
1108 1252
1109 // Check that the toolbar model correctly clears and reorders when it detects 1253 // Check that the toolbar model correctly clears and reorders when it detects
1110 // a preference change. 1254 // a preference change.
1111 TEST_F(ExtensionToolbarModelUnitTest, ToolbarModelPrefChange) { 1255 TEST_F(ToolbarActionsModelUnitTest, ToolbarModelPrefChange) {
1112 Init(); 1256 Init();
1113 1257
1114 ASSERT_TRUE(AddBrowserActionExtensions()); 1258 ASSERT_TRUE(AddBrowserActionExtensions());
1115 1259
1116 // We should start in the basic A B C order. 1260 // We should start in the basic MCA, A, B, C order.
1117 ASSERT_TRUE(browser_action_a()); 1261 ASSERT_TRUE(browser_action_a());
1118 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0)); 1262 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0));
1119 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1)); 1263 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1));
1120 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2)); 1264 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2));
1265 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3));
1121 // Record the difference between the inserted and removed counts. The actual 1266 // Record the difference between the inserted and removed counts. The actual
1122 // value of the counts is not important, but we need to be sure that if we 1267 // value of the counts is not important, but we need to be sure that if we
1123 // call to remove any, we also add them back. 1268 // call to remove any, we also add them back.
1124 size_t inserted_and_removed_difference = 1269 size_t inserted_and_removed_difference =
1125 observer()->inserted_count() - observer()->removed_count(); 1270 observer()->inserted_count() - observer()->removed_count();
1126 1271
1127 // Assign a new order, B C A, and write it in the prefs. 1272 // Assign a new order, B, C, MCA, A, and write it in the prefs.
1128 ExtensionIdList new_order; 1273 ActionIdList new_order;
1129 new_order.push_back(browser_action_b()->id()); 1274 new_order.push_back(browser_action_b()->id());
1130 new_order.push_back(browser_action_c()->id()); 1275 new_order.push_back(browser_action_c()->id());
1276 new_order.push_back(component_action_id());
1131 new_order.push_back(browser_action_a()->id()); 1277 new_order.push_back(browser_action_a()->id());
1132 ExtensionPrefs::Get(profile())->SetToolbarOrder(new_order); 1278 extensions::ExtensionPrefs::Get(profile())->SetToolbarOrder(new_order);
1133 1279
1134 // Ensure everything has time to run. 1280 // Ensure everything has time to run.
1135 base::RunLoop().RunUntilIdle(); 1281 base::RunLoop().RunUntilIdle();
1136 1282
1137 // The new order should be reflected in the model. 1283 // The new order should be reflected in the model.
1138 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(0)); 1284 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(0));
1139 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1)); 1285 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(1));
1140 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(2)); 1286 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(2));
1287 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(3));
1141 EXPECT_EQ(inserted_and_removed_difference, 1288 EXPECT_EQ(inserted_and_removed_difference,
1142 observer()->inserted_count() - observer()->removed_count()); 1289 observer()->inserted_count() - observer()->removed_count());
1143 } 1290 }
1144 1291
1145 TEST_F(ExtensionToolbarModelUnitTest, ComponentExtesionsAddedToEnd) { 1292 TEST_F(ToolbarActionsModelUnitTest, ComponentExtensionsAddedToEnd) {
1146 Init(); 1293 Init();
1147 1294
1148 ASSERT_TRUE(AddBrowserActionExtensions()); 1295 ASSERT_TRUE(AddBrowserActionExtensions());
1149 1296
1150 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0)); 1297 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(0));
1151 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1)); 1298 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(1));
1152 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2)); 1299 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(2));
1300 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3));
1153 1301
1154 const char kName[] = "component"; 1302 const char kName[] = "component";
1155 DictionaryBuilder manifest; 1303 extensions::DictionaryBuilder manifest;
1156 manifest.Set("name", kName) 1304 manifest.Set("name", kName)
1157 .Set("description", "An extension") 1305 .Set("description", "An extension")
1158 .Set("manifest_version", 2) 1306 .Set("manifest_version", 2)
1159 .Set("version", "1.0.0") 1307 .Set("version", "1.0.0")
1160 .Set("browser_action", DictionaryBuilder().Pass()); 1308 .Set("browser_action", extensions::DictionaryBuilder().Pass());
1161 scoped_refptr<const Extension> component_extension = 1309 scoped_refptr<const extensions::Extension> component_extension =
1162 ExtensionBuilder().SetManifest(manifest.Pass()) 1310 extensions::ExtensionBuilder().SetManifest(manifest.Pass())
1163 .SetID(crx_file::id_util::GenerateId(kName)) 1311 .SetID(crx_file::id_util::GenerateId(kName))
1164 .SetLocation(Manifest::COMPONENT) 1312 .SetLocation(extensions::Manifest::COMPONENT)
1165 .Build(); 1313 .Build();
1166 service()->AddExtension(component_extension.get()); 1314 service()->AddExtension(component_extension.get());
1167 1315
1168 EXPECT_EQ(component_extension.get(), GetExtensionAtIndex(0)); 1316 EXPECT_EQ(component_extension.get()->id(), GetActionIdAtIndex(0));
1169 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(1)); 1317 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1));
1170 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(2)); 1318 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(2));
1171 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(3)); 1319 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(3));
1320 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(4));
1172 } 1321 }
1173 1322
1174 TEST_F(ExtensionToolbarModelUnitTest, 1323 TEST_F(ToolbarActionsModelUnitTest,
1175 ToolbarModelHighlightsForToolbarRedesign) { 1324 ToolbarModelHighlightsForToolbarRedesign) {
1176 FeatureSwitch::ScopedOverride enable_redesign( 1325 extensions::FeatureSwitch::ScopedOverride enable_redesign(
1177 FeatureSwitch::extension_action_redesign(), true); 1326 extensions::FeatureSwitch::extension_action_redesign(), true);
1178 InitializeEmptyExtensionService(); 1327 InitializeEmptyExtensionService();
1179 EXPECT_TRUE(AddActionExtensions()); 1328 EXPECT_TRUE(AddActionExtensions());
1180 ExtensionToolbarModel* toolbar_model = 1329 ToolbarActionsModel* toolbar_model =
1181 extension_action_test_util::CreateToolbarModelForProfile(profile()); 1330 extensions::extension_action_test_util::CreateToolbarModelForProfile(
1331 profile());
1182 EXPECT_TRUE(toolbar_model); 1332 EXPECT_TRUE(toolbar_model);
1183 base::RunLoop().RunUntilIdle(); 1333 base::RunLoop().RunUntilIdle();
1184 1334
1185 EXPECT_TRUE(ExtensionToolbarIconSurfacingBubbleDelegate::ShouldShowForProfile( 1335 EXPECT_TRUE(ExtensionToolbarIconSurfacingBubbleDelegate::ShouldShowForProfile(
1186 profile())); 1336 profile()));
1187 EXPECT_TRUE(toolbar_model->is_highlighting()); 1337 EXPECT_TRUE(toolbar_model->is_highlighting());
1188 EXPECT_EQ(ExtensionToolbarModel::HIGHLIGHT_INFO, 1338 EXPECT_EQ(ToolbarActionsModel::HIGHLIGHT_INFO,
1189 toolbar_model->highlight_type()); 1339 toolbar_model->highlight_type());
1190 EXPECT_EQ(3u, toolbar_model->visible_icon_count()); 1340 EXPECT_EQ(3u, toolbar_model->visible_icon_count());
1191 EXPECT_EQ(3u, toolbar_model->toolbar_items().size()); 1341 EXPECT_EQ(3u, toolbar_model->toolbar_items().size());
1192 1342
1193 scoped_ptr<ToolbarActionsBarBubbleDelegate> bubble( 1343 scoped_ptr<ToolbarActionsBarBubbleDelegate> bubble(
1194 new ExtensionToolbarIconSurfacingBubbleDelegate(profile())); 1344 new ExtensionToolbarIconSurfacingBubbleDelegate(profile()));
1195 bubble->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS); 1345 bubble->OnBubbleClosed(ToolbarActionsBarBubbleDelegate::CLOSE_DISMISS);
1196 1346
1197 EXPECT_FALSE(toolbar_model->is_highlighting()); 1347 EXPECT_FALSE(toolbar_model->is_highlighting());
1198 EXPECT_EQ(ExtensionToolbarModel::HIGHLIGHT_NONE, 1348 EXPECT_EQ(ToolbarActionsModel::HIGHLIGHT_NONE,
1199 toolbar_model->highlight_type()); 1349 toolbar_model->highlight_type());
1200 } 1350 }
1201
1202 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698