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

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_actions_model_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698