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

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

Powered by Google App Engine
This is Rietveld 408576698