1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/macros.h"
6 #include "chrome/browser/extensions/extension_browsertest.h"
7 #include "chrome/browser/extensions/extension_toolbar_model.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/test/base/in_process_browser_test.h"
12 namespace extensions
{
14 // An InProcessBrowserTest for testing the ExtensionToolbarModel.
15 // TODO(erikkay) It's unfortunate that this needs to be an in-proc browser test.
16 // It would be nice to refactor things so that ExtensionService could run
17 // without so much of the browser in place.
18 class ExtensionToolbarModelTest
: public ExtensionBrowserTest
,
19 public ExtensionToolbarModel::Observer
{
21 virtual void SetUp() {
25 highlight_mode_count_
= 0;
27 ExtensionBrowserTest::SetUp();
30 virtual void SetUpOnMainThread() OVERRIDE
{
31 model_
= ExtensionToolbarModel::Get(browser()->profile());
32 model_
->AddObserver(this);
35 virtual void CleanUpOnMainThread() OVERRIDE
{
36 model_
->RemoveObserver(this);
39 virtual void BrowserActionAdded(const Extension
* extension
,
44 virtual void BrowserActionRemoved(const Extension
* extension
) OVERRIDE
{
48 virtual void BrowserActionMoved(const Extension
* extension
,
53 virtual void HighlightModeChanged(bool is_highlighting
) OVERRIDE
{
54 // Add one if highlighting, subtract one if not.
55 highlight_mode_count_
+= is_highlighting
? 1 : -1;
58 const Extension
* ExtensionAt(int index
) {
59 const ExtensionList
& toolbar_items
= model_
->toolbar_items();
60 for (ExtensionList::const_iterator i
= toolbar_items
.begin();
61 i
< toolbar_items
.end(); ++i
) {
69 ExtensionToolbarModel
* model_
;
74 int highlight_mode_count_
;
77 IN_PROC_BROWSER_TEST_F(ExtensionToolbarModelTest
, Basic
) {
78 // Load an extension with no browser action.
79 ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII("api_test")
80 .AppendASCII("browser_action")
81 .AppendASCII("none")));
83 // This extension should not be in the model (has no browser action).
84 EXPECT_EQ(0, inserted_count_
);
85 EXPECT_EQ(0u, model_
->toolbar_items().size());
86 ASSERT_EQ(NULL
, ExtensionAt(0));
88 // Load an extension with a browser action.
89 ASSERT_TRUE(LoadExtension(test_data_dir_
.AppendASCII("api_test")
90 .AppendASCII("browser_action")
91 .AppendASCII("basics")));
93 // We should now find our extension in the model.
94 EXPECT_EQ(1, inserted_count_
);
95 EXPECT_EQ(1u, model_
->toolbar_items().size());
96 const Extension
* extension
= ExtensionAt(0);
97 ASSERT_TRUE(NULL
!= extension
);
98 EXPECT_STREQ("A browser action with no icon that makes the page red",
99 extension
->name().c_str());
101 // Should be a no-op, but still fires the events.
102 model_
->MoveBrowserAction(extension
, 0);
103 EXPECT_EQ(1, moved_count_
);
104 EXPECT_EQ(1u, model_
->toolbar_items().size());
105 const Extension
* extension2
= ExtensionAt(0);
106 EXPECT_EQ(extension
, extension2
);
108 UnloadExtension(extension
->id());
109 EXPECT_EQ(1, removed_count_
);
110 EXPECT_EQ(0u, model_
->toolbar_items().size());
111 EXPECT_EQ(NULL
, ExtensionAt(0));
114 #if defined(OS_MACOSX)
115 // Flaky on Mac 10.8 Blink canary bots: http://crbug.com/166580
116 #define MAYBE_ReorderAndReinsert DISABLED_ReorderAndReinsert
118 #define MAYBE_ReorderAndReinsert ReorderAndReinsert
120 IN_PROC_BROWSER_TEST_F(ExtensionToolbarModelTest
, MAYBE_ReorderAndReinsert
) {
121 // Load an extension with a browser action.
122 base::FilePath
extension_a_path(test_data_dir_
.AppendASCII("api_test")
123 .AppendASCII("browser_action")
124 .AppendASCII("basics"));
125 ASSERT_TRUE(LoadExtension(extension_a_path
));
127 // First extension loaded.
128 EXPECT_EQ(1, inserted_count_
);
129 EXPECT_EQ(1u, model_
->toolbar_items().size());
130 const Extension
* extensionA
= ExtensionAt(0);
131 ASSERT_TRUE(NULL
!= extensionA
);
132 EXPECT_STREQ("A browser action with no icon that makes the page red",
133 extensionA
->name().c_str());
135 // Load another extension with a browser action.
136 base::FilePath
extension_b_path(test_data_dir_
.AppendASCII("api_test")
137 .AppendASCII("browser_action")
138 .AppendASCII("popup"));
139 ASSERT_TRUE(LoadExtension(extension_b_path
));
141 // Second extension loaded.
142 EXPECT_EQ(2, inserted_count_
);
143 EXPECT_EQ(2u, model_
->toolbar_items().size());
144 const Extension
* extensionB
= ExtensionAt(1);
145 ASSERT_TRUE(NULL
!= extensionB
);
146 EXPECT_STREQ("Popup tester", extensionB
->name().c_str());
148 // Load yet another extension with a browser action.
149 base::FilePath
extension_c_path(test_data_dir_
.AppendASCII("api_test")
150 .AppendASCII("browser_action")
151 .AppendASCII("remove_popup"));
152 ASSERT_TRUE(LoadExtension(extension_c_path
));
154 // Third extension loaded.
155 EXPECT_EQ(3, inserted_count_
);
156 EXPECT_EQ(3u, model_
->toolbar_items().size());
157 const Extension
* extensionC
= ExtensionAt(2);
158 ASSERT_TRUE(NULL
!= extensionC
);
159 EXPECT_STREQ("A page action which removes a popup.",
160 extensionC
->name().c_str());
162 // Order is now A, B, C. Let's put C first.
163 model_
->MoveBrowserAction(extensionC
, 0);
164 EXPECT_EQ(1, moved_count_
);
165 EXPECT_EQ(3u, model_
->toolbar_items().size());
166 EXPECT_EQ(extensionC
, ExtensionAt(0));
167 EXPECT_EQ(extensionA
, ExtensionAt(1));
168 EXPECT_EQ(extensionB
, ExtensionAt(2));
169 EXPECT_EQ(NULL
, ExtensionAt(3));
171 // Order is now C, A, B. Let's put A last.
172 model_
->MoveBrowserAction(extensionA
, 2);
173 EXPECT_EQ(2, moved_count_
);
174 EXPECT_EQ(3u, model_
->toolbar_items().size());
175 EXPECT_EQ(extensionC
, ExtensionAt(0));
176 EXPECT_EQ(extensionB
, ExtensionAt(1));
177 EXPECT_EQ(extensionA
, ExtensionAt(2));
178 EXPECT_EQ(NULL
, ExtensionAt(3));
180 // Order is now C, B, A. Let's remove B.
181 std::string idB
= extensionB
->id();
182 UnloadExtension(idB
);
183 EXPECT_EQ(1, removed_count_
);
184 EXPECT_EQ(2u, model_
->toolbar_items().size());
185 EXPECT_EQ(extensionC
, ExtensionAt(0));
186 EXPECT_EQ(extensionA
, ExtensionAt(1));
187 EXPECT_EQ(NULL
, ExtensionAt(2));
189 // Load extension B again.
190 ASSERT_TRUE(LoadExtension(extension_b_path
));
192 // Extension B loaded again.
193 EXPECT_EQ(4, inserted_count_
);
194 EXPECT_EQ(3u, model_
->toolbar_items().size());
195 // Make sure it gets its old spot in the list. We should get the same
196 // extension again, otherwise the order has changed.
197 ASSERT_STREQ(idB
.c_str(), ExtensionAt(1)->id().c_str());
200 UnloadExtension(idB
);
201 EXPECT_EQ(2, removed_count_
);
202 EXPECT_EQ(2u, model_
->toolbar_items().size());
203 EXPECT_EQ(extensionC
, ExtensionAt(0));
204 EXPECT_EQ(extensionA
, ExtensionAt(1));
205 EXPECT_EQ(NULL
, ExtensionAt(2));
207 // Order is now C, A. Flip it.
208 model_
->MoveBrowserAction(extensionA
, 0);
209 EXPECT_EQ(3, moved_count_
);
210 EXPECT_EQ(2u, model_
->toolbar_items().size());
211 EXPECT_EQ(extensionA
, ExtensionAt(0));
212 EXPECT_EQ(extensionC
, ExtensionAt(1));
213 EXPECT_EQ(NULL
, ExtensionAt(2));
215 // Move A to the location it already occupies.
216 model_
->MoveBrowserAction(extensionA
, 0);
217 EXPECT_EQ(4, moved_count_
);
218 EXPECT_EQ(2u, model_
->toolbar_items().size());
219 EXPECT_EQ(extensionA
, ExtensionAt(0));
220 EXPECT_EQ(extensionC
, ExtensionAt(1));
221 EXPECT_EQ(NULL
, ExtensionAt(2));
223 // Order is now A, C. Remove C.
224 std::string idC
= extensionC
->id();
225 UnloadExtension(idC
);
226 EXPECT_EQ(3, removed_count_
);
227 EXPECT_EQ(1u, model_
->toolbar_items().size());
228 EXPECT_EQ(extensionA
, ExtensionAt(0));
229 EXPECT_EQ(NULL
, ExtensionAt(1));
231 // Load extension C again.
232 ASSERT_TRUE(LoadExtension(extension_c_path
));
234 // Extension C loaded again.
235 EXPECT_EQ(5, inserted_count_
);
236 EXPECT_EQ(2u, model_
->toolbar_items().size());
237 // Make sure it gets its old spot in the list (at the very end).
238 ASSERT_STREQ(idC
.c_str(), ExtensionAt(1)->id().c_str());
241 IN_PROC_BROWSER_TEST_F(ExtensionToolbarModelTest
, UnloadAndDisableMultiple
) {
242 // Load three extensions with browser action.
243 base::FilePath
extension_a_path(test_data_dir_
.AppendASCII("api_test")
244 .AppendASCII("browser_action")
245 .AppendASCII("basics"));
246 ASSERT_TRUE(LoadExtension(extension_a_path
));
247 base::FilePath
extension_b_path(test_data_dir_
.AppendASCII("api_test")
248 .AppendASCII("browser_action")
249 .AppendASCII("popup"));
250 ASSERT_TRUE(LoadExtension(extension_b_path
));
251 base::FilePath
extension_c_path(test_data_dir_
.AppendASCII("api_test")
252 .AppendASCII("browser_action")
253 .AppendASCII("remove_popup"));
254 ASSERT_TRUE(LoadExtension(extension_c_path
));
256 // Verify we got the three we asked for and that they are ordered as: A, B, C.
257 const Extension
* extensionA
= ExtensionAt(0);
258 const Extension
* extensionB
= ExtensionAt(1);
259 const Extension
* extensionC
= ExtensionAt(2);
260 std::string idA
= extensionA
->id();
261 std::string idB
= extensionB
->id();
262 std::string idC
= extensionC
->id();
263 EXPECT_STREQ("A browser action with no icon that makes the page red",
264 extensionA
->name().c_str());
265 EXPECT_STREQ("Popup tester", extensionB
->name().c_str());
266 EXPECT_STREQ("A page action which removes a popup.",
267 extensionC
->name().c_str());
269 // Unload B, then C, then A.
270 UnloadExtension(idB
);
271 UnloadExtension(idC
);
272 UnloadExtension(idA
);
274 // Load C, then A, then B.
275 ASSERT_TRUE(LoadExtension(extension_c_path
));
276 ASSERT_TRUE(LoadExtension(extension_a_path
));
277 ASSERT_TRUE(LoadExtension(extension_b_path
));
278 EXPECT_EQ(0, moved_count_
);
280 extensionA
= ExtensionAt(0);
281 extensionB
= ExtensionAt(1);
282 extensionC
= ExtensionAt(2);
284 // Make sure we get the order we started with (A, B, C).
285 EXPECT_STREQ(idA
.c_str(), extensionA
->id().c_str());
286 EXPECT_STREQ(idB
.c_str(), extensionB
->id().c_str());
287 EXPECT_STREQ(idC
.c_str(), extensionC
->id().c_str());
289 // Put C in the middle and A to the end.
290 model_
->MoveBrowserAction(extensionC
, 1);
291 model_
->MoveBrowserAction(extensionA
, 2);
293 // Make sure we get this order (C, B, A).
294 EXPECT_STREQ(idC
.c_str(), ExtensionAt(0)->id().c_str());
295 EXPECT_STREQ(idB
.c_str(), ExtensionAt(1)->id().c_str());
296 EXPECT_STREQ(idA
.c_str(), ExtensionAt(2)->id().c_str());
298 // Disable B, then C, then A.
299 DisableExtension(idB
);
300 DisableExtension(idC
);
301 DisableExtension(idA
);
303 // Enable C, then A, then B.
304 EnableExtension(idA
);
305 EnableExtension(idB
);
306 EnableExtension(idC
);
308 // Make sure we get the order we started with.
309 EXPECT_STREQ(idC
.c_str(), ExtensionAt(0)->id().c_str());
310 EXPECT_STREQ(idB
.c_str(), ExtensionAt(1)->id().c_str());
311 EXPECT_STREQ(idA
.c_str(), ExtensionAt(2)->id().c_str());
314 IN_PROC_BROWSER_TEST_F(ExtensionToolbarModelTest
, Uninstall
) {
315 // Load two extensions with browser action.
316 base::FilePath
extension_a_path(test_data_dir_
.AppendASCII("api_test")
317 .AppendASCII("browser_action")
318 .AppendASCII("basics"));
319 ASSERT_TRUE(LoadExtension(extension_a_path
));
320 base::FilePath
extension_b_path(test_data_dir_
.AppendASCII("api_test")
321 .AppendASCII("browser_action")
322 .AppendASCII("popup"));
323 ASSERT_TRUE(LoadExtension(extension_b_path
));
325 // Verify we got what we came for.
326 const Extension
* extensionA
= ExtensionAt(0);
327 const Extension
* extensionB
= ExtensionAt(1);
328 std::string idA
= extensionA
->id();
329 std::string idB
= extensionB
->id();
330 EXPECT_STREQ("A browser action with no icon that makes the page red",
331 extensionA
->name().c_str());
332 EXPECT_STREQ("Popup tester", extensionB
->name().c_str());
334 // Order is now A, B. Make B first.
335 model_
->MoveBrowserAction(extensionB
, 0);
337 // Order is now B, A. Uninstall Extension B.
338 UninstallExtension(idB
);
340 // List contains only A now. Validate that.
341 EXPECT_STREQ(idA
.c_str(), ExtensionAt(0)->id().c_str());
342 EXPECT_EQ(1u, model_
->toolbar_items().size());
344 // Load Extension B again.
345 ASSERT_TRUE(LoadExtension(extension_b_path
));
346 EXPECT_EQ(2u, model_
->toolbar_items().size());
348 // Make sure Extension B is _not_ first (should have been forgotten at
350 EXPECT_STREQ(idA
.c_str(), ExtensionAt(0)->id().c_str());
351 EXPECT_STREQ(idB
.c_str(), ExtensionAt(1)->id().c_str());
354 IN_PROC_BROWSER_TEST_F(ExtensionToolbarModelTest
, ReorderOnPrefChange
) {
355 // Load three extensions with browser action.
356 base::FilePath
extension_a_path(test_data_dir_
.AppendASCII("api_test")
357 .AppendASCII("browser_action")
358 .AppendASCII("basics"));
359 ASSERT_TRUE(LoadExtension(extension_a_path
));
360 base::FilePath
extension_b_path(test_data_dir_
.AppendASCII("api_test")
361 .AppendASCII("browser_action")
362 .AppendASCII("popup"));
363 ASSERT_TRUE(LoadExtension(extension_b_path
));
364 base::FilePath
extension_c_path(test_data_dir_
.AppendASCII("api_test")
365 .AppendASCII("browser_action")
366 .AppendASCII("remove_popup"));
367 ASSERT_TRUE(LoadExtension(extension_c_path
));
368 std::string id_a
= ExtensionAt(0)->id();
369 std::string id_b
= ExtensionAt(1)->id();
370 std::string id_c
= ExtensionAt(2)->id();
372 // Change value of toolbar preference.
373 ExtensionIdList new_order
;
374 new_order
.push_back(id_c
);
375 new_order
.push_back(id_b
);
376 ExtensionPrefs::Get(browser()->profile())->SetToolbarOrder(new_order
);
378 // Verify order is changed.
379 EXPECT_EQ(id_c
, ExtensionAt(0)->id());
380 EXPECT_EQ(id_b
, ExtensionAt(1)->id());
381 EXPECT_EQ(id_a
, ExtensionAt(2)->id());
384 IN_PROC_BROWSER_TEST_F(ExtensionToolbarModelTest
, HighlightMode
) {
385 EXPECT_FALSE(model_
->HighlightExtensions(ExtensionIdList()));
386 EXPECT_EQ(0, highlight_mode_count_
);
388 // Load three extensions with browser action.
389 base::FilePath
extension_a_path(test_data_dir_
.AppendASCII("api_test")
390 .AppendASCII("browser_action")
391 .AppendASCII("basics"));
392 ASSERT_TRUE(LoadExtension(extension_a_path
));
393 base::FilePath
extension_b_path(test_data_dir_
.AppendASCII("api_test")
394 .AppendASCII("browser_action")
395 .AppendASCII("popup"));
396 ASSERT_TRUE(LoadExtension(extension_b_path
));
397 base::FilePath
extension_c_path(test_data_dir_
.AppendASCII("api_test")
398 .AppendASCII("browser_action")
399 .AppendASCII("remove_popup"));
400 ASSERT_TRUE(LoadExtension(extension_c_path
));
401 std::string id_a
= ExtensionAt(0)->id();
402 std::string id_b
= ExtensionAt(1)->id();
403 std::string id_c
= ExtensionAt(2)->id();
405 // Highlight one extension.
406 ExtensionIdList extension_ids
;
407 extension_ids
.push_back(id_b
);
408 model_
->HighlightExtensions(extension_ids
);
409 EXPECT_EQ(1, highlight_mode_count_
);
410 EXPECT_TRUE(model_
->is_highlighting());
412 EXPECT_EQ(1u, model_
->toolbar_items().size());
413 EXPECT_EQ(id_b
, ExtensionAt(0)->id());
415 // Stop highlighting.
416 model_
->StopHighlighting();
417 EXPECT_EQ(0, highlight_mode_count_
);
418 EXPECT_FALSE(model_
->is_highlighting());
420 // Verify that the extensions are back to normal.
421 EXPECT_EQ(3u, model_
->toolbar_items().size());
422 EXPECT_EQ(id_a
, ExtensionAt(0)->id());
423 EXPECT_EQ(id_b
, ExtensionAt(1)->id());
424 EXPECT_EQ(id_c
, ExtensionAt(2)->id());
426 // Call stop highlighting a second time (shouldn't be notified).
427 model_
->StopHighlighting();
428 EXPECT_EQ(0, highlight_mode_count_
);
429 EXPECT_FALSE(model_
->is_highlighting());
431 // Highlight all extensions.
432 extension_ids
.clear();
433 extension_ids
.push_back(id_a
);
434 extension_ids
.push_back(id_b
);
435 extension_ids
.push_back(id_c
);
436 model_
->HighlightExtensions(extension_ids
);
437 EXPECT_EQ(1, highlight_mode_count_
);
438 EXPECT_EQ(3u, model_
->toolbar_items().size());
439 EXPECT_EQ(id_a
, ExtensionAt(0)->id());
440 EXPECT_EQ(id_b
, ExtensionAt(1)->id());
441 EXPECT_EQ(id_c
, ExtensionAt(2)->id());
443 // Highlight only extension b (shrink the highlight list).
444 extension_ids
.clear();
445 extension_ids
.push_back(id_b
);
446 model_
->HighlightExtensions(extension_ids
);
447 EXPECT_EQ(2, highlight_mode_count_
);
448 EXPECT_EQ(1u, model_
->toolbar_items().size());
449 EXPECT_EQ(id_b
, ExtensionAt(0)->id());
451 // Highlight extensions a and b (grow the highlight list).
452 extension_ids
.clear();
453 extension_ids
.push_back(id_a
);
454 extension_ids
.push_back(id_b
);
455 model_
->HighlightExtensions(extension_ids
);
456 EXPECT_EQ(3, highlight_mode_count_
);
457 EXPECT_EQ(2u, model_
->toolbar_items().size());
458 EXPECT_EQ(id_a
, ExtensionAt(0)->id());
459 EXPECT_EQ(id_b
, ExtensionAt(1)->id());
461 // Highlight no extensions (empty the highlight list).
462 extension_ids
.clear();
463 model_
->HighlightExtensions(extension_ids
);
464 EXPECT_EQ(2, highlight_mode_count_
);
465 EXPECT_FALSE(model_
->is_highlighting());
466 EXPECT_EQ(id_a
, ExtensionAt(0)->id());
467 EXPECT_EQ(id_b
, ExtensionAt(1)->id());
468 EXPECT_EQ(id_c
, ExtensionAt(2)->id());
471 #if defined(OS_MACOSX)
472 // Flaky on Mac bots: http://crbug.com/358752
473 #define MAYBE_HighlightModeRemove DISABLED_HighlightModeRemove
475 #define MAYBE_HighlightModeRemove HighlightModeRemove
478 IN_PROC_BROWSER_TEST_F(ExtensionToolbarModelTest
, MAYBE_HighlightModeRemove
) {
479 // Load three extensions with browser action.
480 base::FilePath
extension_a_path(test_data_dir_
.AppendASCII("api_test")
481 .AppendASCII("browser_action")
482 .AppendASCII("basics"));
483 ASSERT_TRUE(LoadExtension(extension_a_path
));
484 base::FilePath
extension_b_path(test_data_dir_
.AppendASCII("api_test")
485 .AppendASCII("browser_action")
486 .AppendASCII("popup"));
487 ASSERT_TRUE(LoadExtension(extension_b_path
));
488 base::FilePath
extension_c_path(test_data_dir_
.AppendASCII("api_test")
489 .AppendASCII("browser_action")
490 .AppendASCII("remove_popup"));
491 ASSERT_TRUE(LoadExtension(extension_c_path
));
492 std::string id_a
= ExtensionAt(0)->id();
493 std::string id_b
= ExtensionAt(1)->id();
494 std::string id_c
= ExtensionAt(2)->id();
496 // Highlight two of the extensions.
497 ExtensionIdList extension_ids
;
498 extension_ids
.push_back(id_a
);
499 extension_ids
.push_back(id_b
);
500 model_
->HighlightExtensions(extension_ids
);
501 EXPECT_TRUE(model_
->is_highlighting());
502 EXPECT_EQ(1, highlight_mode_count_
);
503 EXPECT_EQ(2u, model_
->toolbar_items().size());
505 // Disable one of them - only one should remain highlighted.
506 DisableExtension(id_a
);
507 EXPECT_TRUE(model_
->is_highlighting());
508 EXPECT_EQ(1u, model_
->toolbar_items().size());
509 EXPECT_EQ(id_b
, ExtensionAt(0)->id());
511 // Uninstall the remaining highlighted extension. This should result in
512 // highlight mode exiting.
513 UninstallExtension(id_b
);
514 EXPECT_FALSE(model_
->is_highlighting());
515 EXPECT_EQ(0, highlight_mode_count_
);
516 EXPECT_EQ(1u, model_
->toolbar_items().size());
517 EXPECT_EQ(id_c
, ExtensionAt(0)->id());
519 // Test that removing an unhighlighted extension still works.
520 // Reinstall extension b, and then highlight extension c.
521 ASSERT_TRUE(LoadExtension(extension_b_path
));
522 EXPECT_EQ(id_b
, ExtensionAt(1)->id());
523 extension_ids
.clear();
524 extension_ids
.push_back(id_c
);
525 model_
->HighlightExtensions(extension_ids
);
526 EXPECT_EQ(1, highlight_mode_count_
);
527 EXPECT_TRUE(model_
->is_highlighting());
528 EXPECT_EQ(1u, model_
->toolbar_items().size());
529 EXPECT_EQ(id_c
, ExtensionAt(0)->id());
531 // Uninstalling b should not have visible impact.
532 UninstallExtension(id_b
);
533 EXPECT_TRUE(model_
->is_highlighting());
534 EXPECT_EQ(1, highlight_mode_count_
);
535 EXPECT_EQ(1u, model_
->toolbar_items().size());
536 EXPECT_EQ(id_c
, ExtensionAt(0)->id());
538 // When we stop, only extension c should remain.
539 model_
->StopHighlighting();
540 EXPECT_FALSE(model_
->is_highlighting());
541 EXPECT_EQ(0, highlight_mode_count_
);
542 EXPECT_EQ(1u, model_
->toolbar_items().size());
543 EXPECT_EQ(id_c
, ExtensionAt(0)->id());
546 IN_PROC_BROWSER_TEST_F(ExtensionToolbarModelTest
, HighlightModeAdd
) {
547 // Load two extensions with browser action.
548 base::FilePath
extension_a_path(test_data_dir_
.AppendASCII("api_test")
549 .AppendASCII("browser_action")
550 .AppendASCII("basics"));
551 ASSERT_TRUE(LoadExtension(extension_a_path
));
552 base::FilePath
extension_b_path(test_data_dir_
.AppendASCII("api_test")
553 .AppendASCII("browser_action")
554 .AppendASCII("popup"));
555 ASSERT_TRUE(LoadExtension(extension_b_path
));
556 std::string id_a
= ExtensionAt(0)->id();
557 std::string id_b
= ExtensionAt(1)->id();
559 // Highlight one of the extensions.
560 ExtensionIdList extension_ids
;
561 extension_ids
.push_back(id_a
);
562 model_
->HighlightExtensions(extension_ids
);
563 EXPECT_TRUE(model_
->is_highlighting());
564 EXPECT_EQ(1u, model_
->toolbar_items().size());
565 EXPECT_EQ(id_a
, ExtensionAt(0)->id());
567 // Adding the new extension should have no visible effect.
568 base::FilePath
extension_c_path(test_data_dir_
.AppendASCII("api_test")
569 .AppendASCII("browser_action")
570 .AppendASCII("remove_popup"));
571 const Extension
* extension_c
= LoadExtension(extension_c_path
);
572 ASSERT_TRUE(extension_c
);
573 std::string id_c
= extension_c
->id();
574 EXPECT_TRUE(model_
->is_highlighting());
575 EXPECT_EQ(1u, model_
->toolbar_items().size());
576 EXPECT_EQ(id_a
, ExtensionAt(0)->id());
578 // When we stop highlighting, we should see the new extension show up.
579 model_
->StopHighlighting();
580 EXPECT_FALSE(model_
->is_highlighting());
581 EXPECT_EQ(3u, model_
->toolbar_items().size());
582 EXPECT_EQ(id_a
, ExtensionAt(0)->id());
583 EXPECT_EQ(id_b
, ExtensionAt(1)->id());
584 EXPECT_EQ(id_c
, ExtensionAt(2)->id());
587 IN_PROC_BROWSER_TEST_F(ExtensionToolbarModelTest
, SizeAfterPrefChange
) {
588 // Load two extensions with browser action.
589 base::FilePath
extension_a_path(test_data_dir_
.AppendASCII("api_test")
590 .AppendASCII("browser_action")
591 .AppendASCII("basics"));
592 ASSERT_TRUE(LoadExtension(extension_a_path
));
593 base::FilePath
extension_b_path(test_data_dir_
.AppendASCII("api_test")
594 .AppendASCII("browser_action")
595 .AppendASCII("popup"));
596 ASSERT_TRUE(LoadExtension(extension_b_path
));
597 std::string id_a
= ExtensionAt(0)->id();
598 std::string id_b
= ExtensionAt(1)->id();
600 // Should be at max size (-1).
601 EXPECT_EQ(-1, model_
->GetVisibleIconCount());
603 model_
->OnExtensionToolbarPrefChange();
605 // Should still be at max size.
606 EXPECT_EQ(-1, model_
->GetVisibleIconCount());
609 } // namespace extensions