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 "chrome/browser/ui/toolbar/browser_actions_bar_browsertest.h" | 5 #include "chrome/browser/ui/toolbar/browser_actions_bar_browsertest.h" |
6 | 6 |
| 7 #include "base/run_loop.h" |
7 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 8 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
8 #include "chrome/browser/extensions/browser_action_test_util.h" | 9 #include "chrome/browser/extensions/browser_action_test_util.h" |
9 #include "chrome/browser/extensions/extension_action.h" | 10 #include "chrome/browser/extensions/extension_action.h" |
10 #include "chrome/browser/extensions/extension_action_manager.h" | 11 #include "chrome/browser/extensions/extension_action_manager.h" |
11 #include "chrome/browser/extensions/extension_action_test_util.h" | 12 #include "chrome/browser/extensions/extension_action_test_util.h" |
12 #include "chrome/browser/extensions/extension_browsertest.h" | 13 #include "chrome/browser/extensions/extension_browsertest.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_toolbar_model.h" | 15 #include "chrome/browser/extensions/extension_toolbar_model.h" |
15 #include "chrome/browser/sessions/session_tab_helper.h" | 16 #include "chrome/browser/sessions/session_tab_helper.h" |
| 17 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 19 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
17 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 20 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
18 #include "components/crx_file/id_util.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" |
19 #include "extensions/browser/extension_prefs.h" | 24 #include "extensions/browser/extension_prefs.h" |
20 #include "extensions/browser/extension_registry.h" | 25 #include "extensions/browser/extension_registry.h" |
| 26 #include "extensions/browser/notification_types.h" |
21 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
22 #include "extensions/common/extension_builder.h" | 28 #include "extensions/common/extension_builder.h" |
23 #include "extensions/common/value_builder.h" | 29 #include "extensions/common/value_builder.h" |
24 | 30 |
25 namespace { | 31 namespace { |
26 | 32 |
27 scoped_refptr<const extensions::Extension> CreateExtension( | 33 scoped_refptr<const extensions::Extension> CreateExtension( |
28 const std::string& name, | 34 const std::string& name, |
29 bool has_browser_action) { | 35 bool has_browser_action) { |
30 extensions::DictionaryBuilder manifest; | 36 extensions::DictionaryBuilder manifest; |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 EXPECT_FALSE(browser_actions_bar()->OverflowedActionButtonWantsToRun()); | 328 EXPECT_FALSE(browser_actions_bar()->OverflowedActionButtonWantsToRun()); |
323 | 329 |
324 // Make the extension want to run again, and then move it out of the overflow | 330 // Make the extension want to run again, and then move it out of the overflow |
325 // menu. This should stop the wrench menu from having the special UI. | 331 // menu. This should stop the wrench menu from having the special UI. |
326 action->SetIsVisible(tab_id, true); | 332 action->SetIsVisible(tab_id, true); |
327 extension_action_api->NotifyChange(action, web_contents, profile()); | 333 extension_action_api->NotifyChange(action, web_contents, profile()); |
328 EXPECT_TRUE(browser_actions_bar()->OverflowedActionButtonWantsToRun()); | 334 EXPECT_TRUE(browser_actions_bar()->OverflowedActionButtonWantsToRun()); |
329 toolbar_model()->SetVisibleIconCount(4); | 335 toolbar_model()->SetVisibleIconCount(4); |
330 EXPECT_FALSE(browser_actions_bar()->OverflowedActionButtonWantsToRun()); | 336 EXPECT_FALSE(browser_actions_bar()->OverflowedActionButtonWantsToRun()); |
331 } | 337 } |
| 338 |
| 339 IN_PROC_BROWSER_TEST_F(BrowserActionsBarBrowserTest, BrowserActionPopupTest) { |
| 340 // Load up two extensions that have browser action popups. |
| 341 base::FilePath data_dir = |
| 342 test_data_dir_.AppendASCII("api_test").AppendASCII("browser_action"); |
| 343 const extensions::Extension* first_extension = |
| 344 LoadExtension(data_dir.AppendASCII("open_popup")); |
| 345 ASSERT_TRUE(first_extension); |
| 346 const extensions::Extension* second_extension = |
| 347 LoadExtension(data_dir.AppendASCII("remove_popup")); |
| 348 ASSERT_TRUE(second_extension); |
| 349 |
| 350 // Verify state: two actions, in the order of [first, second]. |
| 351 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions()); |
| 352 EXPECT_EQ(first_extension->id(), browser_actions_bar()->GetExtensionId(0)); |
| 353 EXPECT_EQ(second_extension->id(), browser_actions_bar()->GetExtensionId(1)); |
| 354 |
| 355 // Do a little piping to get at the underlying ExtensionActionViewControllers. |
| 356 ToolbarActionsBar* toolbar_actions_bar = |
| 357 browser_actions_bar()->GetToolbarActionsBar(); |
| 358 const std::vector<ToolbarActionViewController*>& toolbar_actions = |
| 359 toolbar_actions_bar->toolbar_actions(); |
| 360 ASSERT_EQ(2u, toolbar_actions.size()); |
| 361 EXPECT_EQ(first_extension->id(), toolbar_actions[0]->GetId()); |
| 362 EXPECT_EQ(second_extension->id(), toolbar_actions[1]->GetId()); |
| 363 ExtensionActionViewController* first_controller = |
| 364 static_cast<ExtensionActionViewController*>(toolbar_actions[0]); |
| 365 ExtensionActionViewController* second_controller = |
| 366 static_cast<ExtensionActionViewController*>(toolbar_actions[1]); |
| 367 |
| 368 // Neither should yet be showing a popup. |
| 369 EXPECT_FALSE(browser_actions_bar()->HasPopup()); |
| 370 EXPECT_FALSE(first_controller->is_showing_popup()); |
| 371 EXPECT_FALSE(second_controller->is_showing_popup()); |
| 372 |
| 373 // Click on the first extension's browser action. This should open a popup. |
| 374 browser_actions_bar()->Press(0); |
| 375 EXPECT_TRUE(browser_actions_bar()->HasPopup()); |
| 376 EXPECT_TRUE(first_controller->is_showing_popup()); |
| 377 EXPECT_FALSE(second_controller->is_showing_popup()); |
| 378 |
| 379 { |
| 380 content::WindowedNotificationObserver observer( |
| 381 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 382 content::NotificationService::AllSources()); |
| 383 // Clicking on the second extension's browser action should open the |
| 384 // second's popup. Since we only allow one extension popup at a time, this |
| 385 // should also close the first popup. |
| 386 browser_actions_bar()->Press(1); |
| 387 // Closing an extension popup isn't always synchronous; wait for a |
| 388 // notification. |
| 389 observer.Wait(); |
| 390 EXPECT_TRUE(browser_actions_bar()->HasPopup()); |
| 391 EXPECT_FALSE(first_controller->is_showing_popup()); |
| 392 EXPECT_TRUE(second_controller->is_showing_popup()); |
| 393 } |
| 394 |
| 395 { |
| 396 // Clicking on the second extension's browser action a second time should |
| 397 // result in closing the popup. |
| 398 content::WindowedNotificationObserver observer( |
| 399 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 400 content::NotificationService::AllSources()); |
| 401 browser_actions_bar()->Press(1); |
| 402 observer.Wait(); |
| 403 EXPECT_FALSE(browser_actions_bar()->HasPopup()); |
| 404 EXPECT_FALSE(first_controller->is_showing_popup()); |
| 405 EXPECT_FALSE(second_controller->is_showing_popup()); |
| 406 } |
| 407 } |
OLD | NEW |