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/extensions/extension_toolbar_model.h"
16 #include "chrome/browser/sessions/session_tab_helper.h"
17 #include "chrome/browser/ui/extensions/extension_action_view_controller.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
20 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.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_
= extensions::ExtensionToolbarModel::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()->MoveExtensionIcon(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()->MoveExtensionIcon(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()->MoveExtensionIcon(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());
338 IN_PROC_BROWSER_TEST_F(BrowserActionsBarBrowserTest
, BrowserActionPopupTest
) {
339 // Load up two extensions that have browser action popups.
340 base::FilePath data_dir
=
341 test_data_dir_
.AppendASCII("api_test").AppendASCII("browser_action");
342 const extensions::Extension
* first_extension
=
343 LoadExtension(data_dir
.AppendASCII("open_popup"));
344 ASSERT_TRUE(first_extension
);
345 const extensions::Extension
* second_extension
=
346 LoadExtension(data_dir
.AppendASCII("remove_popup"));
347 ASSERT_TRUE(second_extension
);
349 // Verify state: two actions, in the order of [first, second].
350 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
351 EXPECT_EQ(first_extension
->id(), browser_actions_bar()->GetExtensionId(0));
352 EXPECT_EQ(second_extension
->id(), browser_actions_bar()->GetExtensionId(1));
354 // Do a little piping to get at the underlying ExtensionActionViewControllers.
355 ToolbarActionsBar
* toolbar_actions_bar
=
356 browser_actions_bar()->GetToolbarActionsBar();
357 const std::vector
<ToolbarActionViewController
*>& toolbar_actions
=
358 toolbar_actions_bar
->GetActions();
359 ASSERT_EQ(2u, toolbar_actions
.size());
360 EXPECT_EQ(first_extension
->id(), toolbar_actions
[0]->GetId());
361 EXPECT_EQ(second_extension
->id(), toolbar_actions
[1]->GetId());
362 ExtensionActionViewController
* first_controller
=
363 static_cast<ExtensionActionViewController
*>(toolbar_actions
[0]);
364 ExtensionActionViewController
* second_controller
=
365 static_cast<ExtensionActionViewController
*>(toolbar_actions
[1]);
367 // Neither should yet be showing a popup.
368 EXPECT_FALSE(browser_actions_bar()->HasPopup());
369 EXPECT_FALSE(first_controller
->is_showing_popup());
370 EXPECT_FALSE(second_controller
->is_showing_popup());
372 // Click on the first extension's browser action. This should open a popup.
373 browser_actions_bar()->Press(0);
374 EXPECT_TRUE(browser_actions_bar()->HasPopup());
375 EXPECT_TRUE(first_controller
->is_showing_popup());
376 EXPECT_FALSE(second_controller
->is_showing_popup());
379 content::WindowedNotificationObserver
observer(
380 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED
,
381 content::NotificationService::AllSources());
382 // Clicking on the second extension's browser action should open the
383 // second's popup. Since we only allow one extension popup at a time, this
384 // should also close the first popup.
385 browser_actions_bar()->Press(1);
386 // Closing an extension popup isn't always synchronous; wait for a
389 EXPECT_TRUE(browser_actions_bar()->HasPopup());
390 EXPECT_FALSE(first_controller
->is_showing_popup());
391 EXPECT_TRUE(second_controller
->is_showing_popup());
395 // Clicking on the second extension's browser action a second time should
396 // result in closing the popup.
397 content::WindowedNotificationObserver
observer(
398 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED
,
399 content::NotificationService::AllSources());
400 browser_actions_bar()->Press(1);
402 EXPECT_FALSE(browser_actions_bar()->HasPopup());
403 EXPECT_FALSE(first_controller
->is_showing_popup());
404 EXPECT_FALSE(second_controller
->is_showing_popup());
408 // Waiting for popup termination is flaky on mac; disabling while investigating.
409 #if defined(OS_MACOSX)
410 #define MAYBE_OverflowedBrowserActionPopupTest DISABLED_OverflowedBrowserActionPopupTest
412 #define MAYBE_OverflowedBrowserActionPopupTest OverflowedBrowserActionPopupTest
414 IN_PROC_BROWSER_TEST_F(BrowserActionsBarRedesignBrowserTest
,
415 MAYBE_OverflowedBrowserActionPopupTest
) {
416 scoped_ptr
<BrowserActionTestUtil
> overflow_bar
=
417 browser_actions_bar()->CreateOverflowBar();
419 // Load up two extensions that have browser action popups.
420 base::FilePath data_dir
=
421 test_data_dir_
.AppendASCII("api_test").AppendASCII("browser_action");
422 const extensions::Extension
* first_extension
=
423 LoadExtension(data_dir
.AppendASCII("open_popup"));
424 ASSERT_TRUE(first_extension
);
425 const extensions::Extension
* second_extension
=
426 LoadExtension(data_dir
.AppendASCII("remove_popup"));
427 ASSERT_TRUE(second_extension
);
429 // Verify state: two actions, in the order of [first, second].
430 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
431 EXPECT_EQ(first_extension
->id(), browser_actions_bar()->GetExtensionId(0));
432 EXPECT_EQ(second_extension
->id(), browser_actions_bar()->GetExtensionId(1));
434 // Do a little piping to get at the underlying ExtensionActionViewControllers.
435 ToolbarActionsBar
* main_tab
= browser_actions_bar()->GetToolbarActionsBar();
436 std::vector
<ToolbarActionViewController
*> toolbar_actions
=
437 main_tab
->GetActions();
438 ASSERT_EQ(2u, toolbar_actions
.size());
439 EXPECT_EQ(first_extension
->id(), toolbar_actions
[0]->GetId());
440 EXPECT_EQ(second_extension
->id(), toolbar_actions
[1]->GetId());
441 ExtensionActionViewController
* first_controller_main
=
442 static_cast<ExtensionActionViewController
*>(toolbar_actions
[0]);
443 ExtensionActionViewController
* second_controller_main
=
444 static_cast<ExtensionActionViewController
*>(toolbar_actions
[1]);
446 ToolbarActionsBar
* overflow_tab
= overflow_bar
->GetToolbarActionsBar();
447 toolbar_actions
= overflow_tab
->GetActions();
448 ExtensionActionViewController
* second_controller_overflow
=
449 static_cast<ExtensionActionViewController
*>(toolbar_actions
[1]);
451 toolbar_model()->SetVisibleIconCount(0);
453 EXPECT_EQ(0, browser_actions_bar()->VisibleBrowserActions());
454 EXPECT_EQ(2, overflow_bar
->VisibleBrowserActions());
456 // Neither should yet be showing a popup.
457 EXPECT_FALSE(browser_actions_bar()->HasPopup());
458 EXPECT_FALSE(second_controller_main
->is_showing_popup());
459 EXPECT_FALSE(second_controller_overflow
->is_showing_popup());
461 // Click on the first extension's browser action. This should open a popup.
462 overflow_bar
->Press(1);
463 base::RunLoop().RunUntilIdle();
464 EXPECT_TRUE(browser_actions_bar()->HasPopup());
465 EXPECT_FALSE(overflow_bar
->HasPopup());
466 EXPECT_TRUE(second_controller_main
->is_showing_popup());
467 EXPECT_FALSE(second_controller_overflow
->is_showing_popup());
469 EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
470 EXPECT_EQ(1u, main_tab
->GetIconCount());
471 EXPECT_EQ(second_controller_main
->GetId(),
472 browser_actions_bar()->GetExtensionId(0));
473 EXPECT_EQ(2, overflow_bar
->VisibleBrowserActions());
474 EXPECT_EQ(2u, overflow_tab
->GetIconCount());
475 EXPECT_EQ(first_controller_main
->GetId(),
476 overflow_bar
->GetExtensionId(0));
479 content::WindowedNotificationObserver
observer(
480 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED
,
481 content::NotificationService::AllSources());
482 second_controller_main
->HidePopup();
486 EXPECT_FALSE(browser_actions_bar()->HasPopup());
487 EXPECT_FALSE(overflow_bar
->HasPopup());
488 EXPECT_FALSE(second_controller_main
->is_showing_popup());
489 EXPECT_FALSE(second_controller_overflow
->is_showing_popup());
490 EXPECT_EQ(0, browser_actions_bar()->VisibleBrowserActions());
491 EXPECT_EQ(2, overflow_bar
->VisibleBrowserActions());
492 base::RunLoop().RunUntilIdle();
493 EXPECT_EQ(first_controller_main
->GetId(),
494 browser_actions_bar()->GetExtensionId(0));
495 EXPECT_EQ(second_controller_main
->GetId(),
496 browser_actions_bar()->GetExtensionId(1));
499 // Test that page action popups work with the toolbar redesign.
500 IN_PROC_BROWSER_TEST_F(BrowserActionsBarRedesignBrowserTest
,
501 PageActionPopupsTest
) {
502 ExtensionTestMessageListener
listener("ready", false);
503 const extensions::Extension
* page_action_extension
=
504 LoadExtension(test_data_dir_
.AppendASCII("trigger_actions").
505 AppendASCII("page_action_popup"));
506 ASSERT_TRUE(page_action_extension
);
507 listener
.WaitUntilSatisfied();
508 EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions());
509 EXPECT_EQ(page_action_extension
->id(),
510 browser_actions_bar()->GetExtensionId(0));
511 browser_actions_bar()->Press(0);
512 base::RunLoop().RunUntilIdle();
513 EXPECT_TRUE(browser_actions_bar()->HasPopup());