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