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

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

Powered by Google App Engine
This is Rietveld 408576698