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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/toolbar/browser_actions_bar_browsertest.h"
7 #include "base/run_loop.h"
8 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
9 #include "chrome/browser/extensions/browser_action_test_util.h"
10 #include "chrome/browser/extensions/extension_action.h"
11 #include "chrome/browser/extensions/extension_action_manager.h"
12 #include "chrome/browser/extensions/extension_action_test_util.h"
13 #include "chrome/browser/extensions/extension_browsertest.h"
14 #include "chrome/browser/extensions/extension_service.h"
15 #include "chrome/browser/sessions/session_tab_helper.h"
16 #include "chrome/browser/ui/extensions/extension_action_view_controller.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
19 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
20 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h"
21 #include "components/crx_file/id_util.h"
22 #include "content/public/browser/notification_service.h"
23 #include "content/public/test/test_utils.h"
24 #include "extensions/browser/extension_prefs.h"
25 #include "extensions/browser/extension_registry.h"
26 #include "extensions/browser/notification_types.h"
27 #include "extensions/common/extension.h"
28 #include "extensions/common/extension_builder.h"
29 #include "extensions/common/value_builder.h"
30 #include "extensions/test/extension_test_message_listener.h"
34 scoped_refptr
<const extensions::Extension
> CreateExtension(
35 const std::string
& name
,
36 bool has_browser_action
) {
37 extensions::DictionaryBuilder manifest
;
38 manifest
.Set("name", name
).
39 Set("description", "an extension").
40 Set("manifest_version", 2).
41 Set("version", "1.0");
42 if (has_browser_action
)
43 manifest
.Set("browser_action", extensions::DictionaryBuilder().Pass());
44 return extensions::ExtensionBuilder().
45 SetManifest(manifest
.Pass()).
46 SetID(crx_file::id_util::GenerateId(name
)).
52 // BrowserActionsBarBrowserTest:
54 BrowserActionsBarBrowserTest::BrowserActionsBarBrowserTest()
55 : toolbar_model_(nullptr) {
58 BrowserActionsBarBrowserTest::~BrowserActionsBarBrowserTest() {
61 void BrowserActionsBarBrowserTest::SetUpCommandLine(
62 base::CommandLine
* command_line
) {
63 ToolbarActionsBar::disable_animations_for_testing_
= true;
64 ExtensionBrowserTest::SetUpCommandLine(command_line
);
67 void BrowserActionsBarBrowserTest::SetUpOnMainThread() {
68 ExtensionBrowserTest::SetUpOnMainThread();
69 browser_actions_bar_
.reset(new BrowserActionTestUtil(browser()));
70 toolbar_model_
= ToolbarActionsModel::Get(profile());
73 void BrowserActionsBarBrowserTest::TearDownOnMainThread() {
74 ToolbarActionsBar::disable_animations_for_testing_
= false;
75 ExtensionBrowserTest::TearDownOnMainThread();
78 void BrowserActionsBarBrowserTest::LoadExtensions() {
79 // Create three extensions with browser actions.
80 extension_a_
= CreateExtension("alpha", true);
81 extension_b_
= CreateExtension("beta", true);
82 extension_c_
= CreateExtension("gamma", true);
84 const extensions::Extension
* extensions
[] =
85 { extension_a(), extension_b(), extension_c() };
86 extensions::ExtensionRegistry
* registry
=
87 extensions::ExtensionRegistry::Get(profile());
88 // Add each, and verify that it is both correctly added to the extension
89 // registry and to the browser actions container.
90 for (size_t i
= 0; i
< arraysize(extensions
); ++i
) {
91 extension_service()->AddExtension(extensions
[i
]);
92 EXPECT_TRUE(registry
->enabled_extensions().GetByID(extensions
[i
]->id())) <<
93 extensions
[i
]->name();
94 EXPECT_EQ(static_cast<int>(i
+ 1),
95 browser_actions_bar_
->NumberOfBrowserActions());
96 EXPECT_TRUE(browser_actions_bar_
->HasIcon(i
));
97 EXPECT_EQ(static_cast<int>(i
+ 1),
98 browser_actions_bar()->VisibleBrowserActions());
102 // BrowserActionsBarRedesignBrowserTest:
104 BrowserActionsBarRedesignBrowserTest::BrowserActionsBarRedesignBrowserTest() {
107 BrowserActionsBarRedesignBrowserTest::~BrowserActionsBarRedesignBrowserTest() {
110 void BrowserActionsBarRedesignBrowserTest::SetUpCommandLine(
111 base::CommandLine
* command_line
) {
112 BrowserActionsBarBrowserTest::SetUpCommandLine(command_line
);
113 enable_redesign_
.reset(new extensions::FeatureSwitch::ScopedOverride(
114 extensions::FeatureSwitch::extension_action_redesign(),
118 // Test the basic functionality.
119 IN_PROC_BROWSER_TEST_F(BrowserActionsBarBrowserTest
, Basic
) {
120 // Load an extension with no browser action.
121 extension_service()->AddExtension(CreateExtension("alpha", false).get());
122 // This extension should not be in the model (has no browser action).
123 EXPECT_EQ(0, browser_actions_bar()->NumberOfBrowserActions());
125 // Load an extension with a browser action.
126 extension_service()->AddExtension(CreateExtension("beta", true).get());
127 EXPECT_EQ(1, browser_actions_bar()->NumberOfBrowserActions());
128 EXPECT_TRUE(browser_actions_bar()->HasIcon(0));
130 // Unload the extension.
131 std::string id
= browser_actions_bar()->GetExtensionId(0);
133 EXPECT_EQ(0, browser_actions_bar()->NumberOfBrowserActions());
136 // Test moving various browser actions. This is not to check the logic of the
137 // move (that's in the toolbar model tests), but just to check our ui.
138 IN_PROC_BROWSER_TEST_F(BrowserActionsBarBrowserTest
, MoveBrowserActions
) {
141 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
142 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
144 // Order is now A B C.
145 EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0));
146 EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(1));
147 EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(2));
149 // Move C to first position. Order is C A B.
150 toolbar_model()->MoveActionIcon(extension_c()->id(), 0);
151 EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(0));
152 EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(1));
153 EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(2));
155 // Move B to third position. Order is still C A B.
156 toolbar_model()->MoveActionIcon(extension_b()->id(), 2);
157 EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(0));
158 EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(1));
159 EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(2));
161 // Move B to middle position. Order is C B A.
162 toolbar_model()->MoveActionIcon(extension_b()->id(), 1);
163 EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(0));
164 EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(1));
165 EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(2));
168 // Test that explicitly hiding an extension action results in it disappearing
169 // from the browser actions bar.
170 IN_PROC_BROWSER_TEST_F(BrowserActionsBarBrowserTest
, ForceHide
) {
173 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
174 EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0));
175 // Force hide one of the extensions' browser action.
176 extensions::ExtensionActionAPI::Get(browser()->profile())->
177 SetBrowserActionVisibility(extension_a()->id(), false);
178 // The browser action for Extension A should be removed.
179 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
180 EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(0));
183 IN_PROC_BROWSER_TEST_F(BrowserActionsBarBrowserTest
, Visibility
) {
186 // Change container to show only one action, rest in overflow: A, [B, C].
187 toolbar_model()->SetVisibleIconCount(1);
188 EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
190 // Disable extension A (should disappear). State becomes: B [C].
191 DisableExtension(extension_a()->id());
192 EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions());
193 EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
194 EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(0));
196 // Enable A again. A should get its spot in the same location and the bar
197 // should not grow (chevron is showing). For details: http://crbug.com/35349.
198 // State becomes: A, [B, C].
199 EnableExtension(extension_a()->id());
200 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
201 EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
202 EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0));
204 // Disable C (in overflow). State becomes: A, [B].
205 DisableExtension(extension_c()->id());
206 EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions());
207 EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
208 EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0));
210 // Enable C again. State becomes: A, [B, C].
211 EnableExtension(extension_c()->id());
212 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
213 EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
214 EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0));
216 // Now we have 3 extensions. Make sure they are all visible. State: A, B, C.
217 toolbar_model()->SetVisibleIconCount(3);
218 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
220 // Disable extension A (should disappear). State becomes: B, C.
221 DisableExtension(extension_a()->id());
222 EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions());
223 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
224 EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(0));
226 // Disable extension B (should disappear). State becomes: C.
227 DisableExtension(extension_b()->id());
228 EXPECT_EQ(1, browser_actions_bar()->NumberOfBrowserActions());
229 EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
230 EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(0));
232 // Enable B. State becomes: B, C.
233 EnableExtension(extension_b()->id());
234 EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions());
235 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
236 EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(0));
238 // Enable A. State becomes: A, B, C.
239 EnableExtension(extension_a()->id());
240 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
241 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
242 EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0));
244 // Shrink the browser actions bar to zero visible icons.
245 // No icons should be visible, but we *should* show the chevron and have a
247 toolbar_model()->SetVisibleIconCount(0);
248 EXPECT_EQ(0, browser_actions_bar()->VisibleBrowserActions());
249 EXPECT_TRUE(browser_actions_bar()->IsChevronShowing());
251 // Reset visibility count to 2. State should be A, B, [C], and the chevron
252 // should be visible.
253 toolbar_model()->SetVisibleIconCount(2);
254 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
255 EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0));
256 EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(1));
257 EXPECT_TRUE(browser_actions_bar()->IsChevronShowing());
259 // Disable C (the overflowed extension). State should now be A, B, and the
260 // chevron should be hidden.
261 DisableExtension(extension_c()->id());
262 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
263 EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0));
264 EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(1));
265 EXPECT_FALSE(browser_actions_bar()->IsChevronShowing());
267 // Re-enable C. We should still only have 2 visible icons, and the chevron
268 // should be visible.
269 EnableExtension(extension_c()->id());
270 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
271 EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0));
272 EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(1));
273 EXPECT_TRUE(browser_actions_bar()->IsChevronShowing());
276 // Test that, with the toolbar action redesign, actions that want to run have
277 // the proper appearance.
278 IN_PROC_BROWSER_TEST_F(BrowserActionsBarRedesignBrowserTest
,
279 TestUiForActionsWantToRun
) {
281 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
283 // Load an extension with a page action.
284 scoped_refptr
<const extensions::Extension
> page_action_extension
=
285 extensions::extension_action_test_util::CreateActionExtension(
286 "page action", extensions::extension_action_test_util::PAGE_ACTION
);
287 extension_service()->AddExtension(page_action_extension
.get());
289 // Verify that the extension was added at the last index.
290 EXPECT_EQ(4, browser_actions_bar()->VisibleBrowserActions());
291 EXPECT_EQ(page_action_extension
->id(),
292 browser_actions_bar()->GetExtensionId(3));
293 EXPECT_FALSE(browser_actions_bar()->ActionButtonWantsToRun(3));
295 // Make the extension want to run on the current page.
296 ExtensionAction
* action
= extensions::ExtensionActionManager::Get(profile())->
297 GetExtensionAction(*page_action_extension
);
299 content::WebContents
* web_contents
=
300 browser()->tab_strip_model()->GetActiveWebContents();
301 int tab_id
= SessionTabHelper::IdForTab(web_contents
);
302 action
->SetIsVisible(tab_id
, true);
303 extensions::ExtensionActionAPI
* extension_action_api
=
304 extensions::ExtensionActionAPI::Get(profile());
305 extension_action_api
->NotifyChange(action
, web_contents
, profile());
306 // Verify that the extension's button has the proper UI.
307 EXPECT_TRUE(browser_actions_bar()->ActionButtonWantsToRun(3));
309 // Make the extension not want to run, and check that the special UI goes
311 action
->SetIsVisible(tab_id
, false);
312 extension_action_api
->NotifyChange(action
, web_contents
, profile());
313 EXPECT_FALSE(browser_actions_bar()->ActionButtonWantsToRun(3));
315 // Reduce the visible icon count so that the extension is hidden.
316 toolbar_model()->SetVisibleIconCount(3);
317 EXPECT_FALSE(browser_actions_bar()->OverflowedActionButtonWantsToRun());
319 // Make the extension want to run, and verify that the overflow button (the
320 // wrench) has the correct UI. Then, make the extension not want to run and
321 // verify it goes away.
322 action
->SetIsVisible(tab_id
, true);
323 extension_action_api
->NotifyChange(action
, web_contents
, profile());
324 EXPECT_TRUE(browser_actions_bar()->OverflowedActionButtonWantsToRun());
325 action
->SetIsVisible(tab_id
, false);
326 extension_action_api
->NotifyChange(action
, web_contents
, profile());
327 EXPECT_FALSE(browser_actions_bar()->OverflowedActionButtonWantsToRun());
329 // Make the extension want to run again, and then move it out of the overflow
330 // menu. This should stop the wrench menu from having the special UI.
331 action
->SetIsVisible(tab_id
, true);
332 extension_action_api
->NotifyChange(action
, web_contents
, profile());
333 EXPECT_TRUE(browser_actions_bar()->OverflowedActionButtonWantsToRun());
334 toolbar_model()->SetVisibleIconCount(4);
335 EXPECT_FALSE(browser_actions_bar()->OverflowedActionButtonWantsToRun());
337 // Adjusting the visible count down should mean an overflowed action wants
338 // to run again. Removing the action that wants to run should result in
339 // no overflowed action wanting to run.
340 toolbar_model()->SetVisibleIconCount(3);
341 EXPECT_TRUE(browser_actions_bar()->OverflowedActionButtonWantsToRun());
342 extension_service()->DisableExtension(page_action_extension
->id(),
343 extensions::Extension::DISABLE_NONE
);
344 EXPECT_FALSE(browser_actions_bar()->OverflowedActionButtonWantsToRun());
347 IN_PROC_BROWSER_TEST_F(BrowserActionsBarBrowserTest
,
348 BrowserActionPopupTest
) {
349 // Load up two extensions that have browser action popups.
350 base::FilePath data_dir
=
351 test_data_dir_
.AppendASCII("api_test").AppendASCII("browser_action");
352 const extensions::Extension
* first_extension
=
353 LoadExtension(data_dir
.AppendASCII("open_popup"));
354 ASSERT_TRUE(first_extension
);
355 const extensions::Extension
* second_extension
=
356 LoadExtension(data_dir
.AppendASCII("remove_popup"));
357 ASSERT_TRUE(second_extension
);
359 // Verify state: two actions, in the order of [first, second].
360 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
361 EXPECT_EQ(first_extension
->id(), browser_actions_bar()->GetExtensionId(0));
362 EXPECT_EQ(second_extension
->id(), browser_actions_bar()->GetExtensionId(1));
364 // Do a little piping to get at the underlying ExtensionActionViewControllers.
365 ToolbarActionsBar
* toolbar_actions_bar
=
366 browser_actions_bar()->GetToolbarActionsBar();
367 const std::vector
<ToolbarActionViewController
*>& toolbar_actions
=
368 toolbar_actions_bar
->GetActions();
369 ASSERT_EQ(2u, toolbar_actions
.size());
370 EXPECT_EQ(first_extension
->id(), toolbar_actions
[0]->GetId());
371 EXPECT_EQ(second_extension
->id(), toolbar_actions
[1]->GetId());
372 ExtensionActionViewController
* first_controller
=
373 static_cast<ExtensionActionViewController
*>(toolbar_actions
[0]);
374 ExtensionActionViewController
* second_controller
=
375 static_cast<ExtensionActionViewController
*>(toolbar_actions
[1]);
377 // Neither should yet be showing a popup.
378 EXPECT_FALSE(browser_actions_bar()->HasPopup());
379 EXPECT_FALSE(first_controller
->is_showing_popup());
380 EXPECT_FALSE(second_controller
->is_showing_popup());
382 // Click on the first extension's browser action. This should open a popup.
383 browser_actions_bar()->Press(0);
384 EXPECT_TRUE(browser_actions_bar()->HasPopup());
385 EXPECT_TRUE(first_controller
->is_showing_popup());
386 EXPECT_FALSE(second_controller
->is_showing_popup());
389 content::WindowedNotificationObserver
observer(
390 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED
,
391 content::NotificationService::AllSources());
392 // Clicking on the second extension's browser action should open the
393 // second's popup. Since we only allow one extension popup at a time, this
394 // should also close the first popup.
395 browser_actions_bar()->Press(1);
396 // Closing an extension popup isn't always synchronous; wait for a
399 EXPECT_TRUE(browser_actions_bar()->HasPopup());
400 EXPECT_FALSE(first_controller
->is_showing_popup());
401 EXPECT_TRUE(second_controller
->is_showing_popup());
405 // Clicking on the second extension's browser action a second time should
406 // result in closing the popup.
407 content::WindowedNotificationObserver
observer(
408 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED
,
409 content::NotificationService::AllSources());
410 browser_actions_bar()->Press(1);
412 EXPECT_FALSE(browser_actions_bar()->HasPopup());
413 EXPECT_FALSE(first_controller
->is_showing_popup());
414 EXPECT_FALSE(second_controller
->is_showing_popup());
418 IN_PROC_BROWSER_TEST_F(BrowserActionsBarRedesignBrowserTest
,
419 OverflowedBrowserActionPopupTest
) {
420 scoped_ptr
<BrowserActionTestUtil
> overflow_bar
=
421 browser_actions_bar()->CreateOverflowBar();
423 // Load up two extensions that have browser action popups.
424 base::FilePath data_dir
=
425 test_data_dir_
.AppendASCII("api_test").AppendASCII("browser_action");
426 const extensions::Extension
* first_extension
=
427 LoadExtension(data_dir
.AppendASCII("open_popup"));
428 ASSERT_TRUE(first_extension
);
429 const extensions::Extension
* second_extension
=
430 LoadExtension(data_dir
.AppendASCII("remove_popup"));
431 ASSERT_TRUE(second_extension
);
433 // Verify state: two actions, in the order of [first, second].
434 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
435 EXPECT_EQ(first_extension
->id(), browser_actions_bar()->GetExtensionId(0));
436 EXPECT_EQ(second_extension
->id(), browser_actions_bar()->GetExtensionId(1));
438 // Do a little piping to get at the underlying ExtensionActionViewControllers.
439 ToolbarActionsBar
* main_tab
= browser_actions_bar()->GetToolbarActionsBar();
440 std::vector
<ToolbarActionViewController
*> toolbar_actions
=
441 main_tab
->GetActions();
442 ASSERT_EQ(2u, toolbar_actions
.size());
443 EXPECT_EQ(first_extension
->id(), toolbar_actions
[0]->GetId());
444 EXPECT_EQ(second_extension
->id(), toolbar_actions
[1]->GetId());
445 ExtensionActionViewController
* first_controller_main
=
446 static_cast<ExtensionActionViewController
*>(toolbar_actions
[0]);
447 ExtensionActionViewController
* second_controller_main
=
448 static_cast<ExtensionActionViewController
*>(toolbar_actions
[1]);
450 ToolbarActionsBar
* overflow_tab
= overflow_bar
->GetToolbarActionsBar();
451 toolbar_actions
= overflow_tab
->GetActions();
452 ExtensionActionViewController
* second_controller_overflow
=
453 static_cast<ExtensionActionViewController
*>(toolbar_actions
[1]);
455 toolbar_model()->SetVisibleIconCount(0);
457 EXPECT_EQ(0, browser_actions_bar()->VisibleBrowserActions());
458 EXPECT_EQ(2, overflow_bar
->VisibleBrowserActions());
460 // Neither should yet be showing a popup.
461 EXPECT_FALSE(browser_actions_bar()->HasPopup());
462 EXPECT_FALSE(second_controller_main
->is_showing_popup());
463 EXPECT_FALSE(second_controller_overflow
->is_showing_popup());
465 // Click on the first extension's browser action. This should open a popup.
466 overflow_bar
->Press(1);
467 base::RunLoop().RunUntilIdle();
468 EXPECT_TRUE(browser_actions_bar()->HasPopup());
469 EXPECT_FALSE(overflow_bar
->HasPopup());
470 EXPECT_TRUE(second_controller_main
->is_showing_popup());
471 EXPECT_FALSE(second_controller_overflow
->is_showing_popup());
473 EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
474 EXPECT_EQ(1u, main_tab
->GetIconCount());
475 EXPECT_EQ(second_controller_main
->GetId(),
476 browser_actions_bar()->GetExtensionId(0));
477 EXPECT_EQ(2, overflow_bar
->VisibleBrowserActions());
478 EXPECT_EQ(2u, overflow_tab
->GetIconCount());
479 EXPECT_EQ(first_controller_main
->GetId(),
480 overflow_bar
->GetExtensionId(0));
483 content::WindowedNotificationObserver
observer(
484 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED
,
485 content::NotificationService::AllSources());
486 second_controller_main
->HidePopup();
490 EXPECT_FALSE(browser_actions_bar()->HasPopup());
491 EXPECT_FALSE(overflow_bar
->HasPopup());
492 EXPECT_FALSE(second_controller_main
->is_showing_popup());
493 EXPECT_FALSE(second_controller_overflow
->is_showing_popup());
494 EXPECT_EQ(0, browser_actions_bar()->VisibleBrowserActions());
495 EXPECT_EQ(2, overflow_bar
->VisibleBrowserActions());
496 base::RunLoop().RunUntilIdle();
497 EXPECT_EQ(first_controller_main
->GetId(),
498 browser_actions_bar()->GetExtensionId(0));
499 EXPECT_EQ(second_controller_main
->GetId(),
500 browser_actions_bar()->GetExtensionId(1));
503 // Test that page action popups work with the toolbar redesign.
504 IN_PROC_BROWSER_TEST_F(BrowserActionsBarRedesignBrowserTest
,
505 PageActionPopupsTest
) {
506 ExtensionTestMessageListener
listener("ready", false);
507 const extensions::Extension
* page_action_extension
=
508 LoadExtension(test_data_dir_
.AppendASCII("trigger_actions").
509 AppendASCII("page_action_popup"));
510 ASSERT_TRUE(page_action_extension
);
511 listener
.WaitUntilSatisfied();
512 EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
513 EXPECT_EQ(page_action_extension
->id(),
514 browser_actions_bar()->GetExtensionId(0));
515 browser_actions_bar()->Press(0);
516 base::RunLoop().RunUntilIdle();
517 EXPECT_TRUE(browser_actions_bar()->HasPopup());
518 // Cleanup the popup (to avoid having windows open at tear down).
519 browser_actions_bar()->HidePopup();
520 content::RunAllBlockingPoolTasksUntilIdle();
521 EXPECT_FALSE(browser_actions_bar()->HasPopup());