| Index: chrome/browser/extensions/api/extension_action/browser_action_interactive_test.cc
|
| diff --git a/chrome/browser/extensions/api/extension_action/browser_action_interactive_test.cc b/chrome/browser/extensions/api/extension_action/browser_action_interactive_test.cc
|
| index 1c0ffcdd78f937b7ee85456f64f3c8410731dd8b..5fd289df8c345e8331e4d0d5c5a0b8ed032be79b 100644
|
| --- a/chrome/browser/extensions/api/extension_action/browser_action_interactive_test.cc
|
| +++ b/chrome/browser/extensions/api/extension_action/browser_action_interactive_test.cc
|
| @@ -28,6 +28,7 @@
|
| #include "extensions/common/permissions/permissions_data.h"
|
| #include "extensions/test/extension_test_message_listener.h"
|
| #include "extensions/test/result_catcher.h"
|
| +#include "ui/base/ui_features.h"
|
|
|
| #if defined(OS_WIN)
|
| #include "ui/views/win/hwnd_util.h"
|
| @@ -44,6 +45,12 @@ class BrowserActionInteractiveTest : public ExtensionApiTest {
|
| BrowserActionInteractiveTest() {}
|
| ~BrowserActionInteractiveTest() override {}
|
|
|
| + // BrowserTestBase:
|
| + void SetUpOnMainThread() override {
|
| + ExtensionApiTest::SetUpOnMainThread();
|
| + EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
|
| + }
|
| +
|
| protected:
|
| // Function to control whether to run popup tests for the current platform.
|
| // These tests require RunExtensionSubtest to work as expected and the browser
|
| @@ -53,17 +60,20 @@ class BrowserActionInteractiveTest : public ExtensionApiTest {
|
| // TODO(justinlin): http://crbug.com/177163
|
| #if defined(OS_WIN) && !defined(NDEBUG)
|
| return false;
|
| -#elif defined(OS_MACOSX)
|
| - // TODO(justinlin): Browser window do not become active on Mac even when
|
| - // Activate() is called on them. Enable when/if it's possible to fix.
|
| - return false;
|
| #else
|
| return true;
|
| #endif
|
| }
|
|
|
| + void EnsurePopupActive() {
|
| + BrowserActionTestUtil test_util(browser());
|
| + EXPECT_TRUE(test_util.HasPopup());
|
| + EXPECT_TRUE(test_util.WaitForPopup());
|
| + EXPECT_TRUE(test_util.HasPopup());
|
| + }
|
| +
|
| // Open an extension popup via the chrome.browserAction.openPopup API.
|
| - void OpenExtensionPopupViaAPI() {
|
| + void OpenPopupViaAPI() {
|
| // Setup the notification observer to wait for the popup to finish loading.
|
| content::WindowedNotificationObserver frame_observer(
|
| content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
|
| @@ -72,7 +82,46 @@ class BrowserActionInteractiveTest : public ExtensionApiTest {
|
| ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup",
|
| "open_popup_succeeds.html")) << message_;
|
| frame_observer.Wait();
|
| + EnsurePopupActive();
|
| + }
|
| +
|
| + // Open an extension popup by clicking the browser action button.
|
| + void OpenPopupViaToolbar() {
|
| + content::WindowedNotificationObserver frame_observer(
|
| + content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
|
| + content::NotificationService::AllSources());
|
| + BrowserActionTestUtil(browser()).Press(0);
|
| + frame_observer.Wait();
|
| + EnsurePopupActive();
|
| + }
|
| +
|
| + // Trigger a focus loss to close the popup.
|
| + void ClosePopupViaFocusLoss() {
|
| EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup());
|
| + content::WindowedNotificationObserver observer(
|
| + extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
|
| + content::NotificationService::AllSources());
|
| +
|
| +#if defined(OS_MACOSX)
|
| + // ClickOnView() in an inactive window is not robust on Mac. The click does
|
| + // not guarantee window activation on trybots. So activate the browser
|
| + // explicitly, thus causing the bubble to lose focus and dismiss itself.
|
| + // This works because bubbles on Mac are always toplevel.
|
| + EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
|
| +#else
|
| + // Elsewhere, click on the omnibox. Note that with aura, the browser may be
|
| + // "active" the entire time when the popup is not a toplevel window. It's
|
| + // aura::Window::Focus() that determines where key events go in this case.
|
| + ui_test_utils::ClickOnView(browser(), VIEW_ID_OMNIBOX);
|
| +#endif
|
| +
|
| + // The window disappears immediately.
|
| + EXPECT_FALSE(BrowserActionTestUtil(browser()).HasPopup());
|
| +
|
| + // Wait for the notification to achieve a consistent state and verify that
|
| + // the popup was properly torn down.
|
| + observer.Wait();
|
| + base::RunLoop().RunUntilIdle();
|
| }
|
| };
|
|
|
| @@ -87,7 +136,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TestOpenPopup) {
|
| // Setup extension message listener to wait for javascript to finish running.
|
| ExtensionTestMessageListener listener("ready", true);
|
| {
|
| - OpenExtensionPopupViaAPI();
|
| + OpenPopupViaAPI();
|
| EXPECT_TRUE(browserActionBar.HasPopup());
|
| browserActionBar.HidePopup();
|
| }
|
| @@ -205,15 +254,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
|
| ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup",
|
| "open_popup_fails.html")) << message_;
|
| EXPECT_TRUE(listener.WaitUntilSatisfied());
|
| -
|
| - content::WindowedNotificationObserver frame_observer(
|
| - content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
|
| - content::NotificationService::AllSources());
|
| - // Open popup in the first extension.
|
| - BrowserActionTestUtil(browser()).Press(0);
|
| - frame_observer.Wait();
|
| - EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup());
|
| -
|
| + OpenPopupViaToolbar();
|
| ResultCatcher catcher;
|
| // Return control to javascript to validate that opening a popup fails now.
|
| listener.Reply("show another");
|
| @@ -227,7 +268,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
|
| if (!ShouldRunPopupTest())
|
| return;
|
|
|
| - OpenExtensionPopupViaAPI();
|
| + OpenPopupViaAPI();
|
| ExtensionService* service = extensions::ExtensionSystem::Get(
|
| browser()->profile())->extension_service();
|
| ASSERT_FALSE(
|
| @@ -239,34 +280,23 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
|
| APIPermission::kTab));
|
| }
|
|
|
| -// Test that the extension popup is closed when the browser window is clicked.
|
| -IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, BrowserClickClosesPopup1) {
|
| +// Test that the extension popup is closed when the browser window is focused.
|
| +IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, FocusLossClosesPopup1) {
|
| if (!ShouldRunPopupTest())
|
| return;
|
| -
|
| - // Open an extension popup via the chrome.browserAction.openPopup API.
|
| - content::WindowedNotificationObserver frame_observer(
|
| - content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
|
| - content::NotificationService::AllSources());
|
| - ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup",
|
| - "open_popup_succeeds.html")) << message_;
|
| - frame_observer.Wait();
|
| - EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup());
|
| -
|
| - // Click on the omnibox to close the extension popup.
|
| - ui_test_utils::ClickOnView(browser(), VIEW_ID_OMNIBOX);
|
| - EXPECT_FALSE(BrowserActionTestUtil(browser()).HasPopup());
|
| + OpenPopupViaAPI();
|
| + ClosePopupViaFocusLoss();
|
| }
|
|
|
| -// Test that the extension popup is closed when the browser window is clicked.
|
| +// Test that the extension popup is closed when the browser window is focused.
|
| #if defined(OS_WIN)
|
| // Flaky on Windows: http://crbug.com/639130
|
| -#define MAYBE_BrowserClickClosesPopup2 DISABLED_BrowserClickClosesPopup2
|
| +#define MAYBE_FocusLossClosesPopup2 DISABLED_FocusLossClosesPopup2
|
| #else
|
| -#define MAYBE_BrowserClickClosesPopup2 BrowserClickClosesPopup2
|
| +#define MAYBE_FocusLossClosesPopup2 FocusLossClosesPopup2
|
| #endif
|
| IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
|
| - MAYBE_BrowserClickClosesPopup2) {
|
| + MAYBE_FocusLossClosesPopup2) {
|
| if (!ShouldRunPopupTest())
|
| return;
|
|
|
| @@ -275,18 +305,8 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
|
| "browser_action/popup")));
|
| const Extension* extension = GetSingleLoadedExtension();
|
| ASSERT_TRUE(extension) << message_;
|
| -
|
| - // Open an extension popup by clicking the browser action button.
|
| - content::WindowedNotificationObserver frame_observer(
|
| - content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
|
| - content::NotificationService::AllSources());
|
| - BrowserActionTestUtil(browser()).Press(0);
|
| - frame_observer.Wait();
|
| - EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup());
|
| -
|
| - // Click on the omnibox to close the extension popup.
|
| - ui_test_utils::ClickOnView(browser(), VIEW_ID_OMNIBOX);
|
| - EXPECT_FALSE(BrowserActionTestUtil(browser()).HasPopup());
|
| + OpenPopupViaToolbar();
|
| + ClosePopupViaFocusLoss();
|
| }
|
|
|
| // Test that the extension popup is closed on browser tab switches.
|
| @@ -299,7 +319,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TabSwitchClosesPopup) {
|
| ASSERT_EQ(2, browser()->tab_strip_model()->count());
|
| EXPECT_EQ(browser()->tab_strip_model()->GetWebContentsAt(1),
|
| browser()->tab_strip_model()->GetActiveWebContents());
|
| - OpenExtensionPopupViaAPI();
|
| + OpenPopupViaAPI();
|
|
|
| content::WindowedNotificationObserver observer(
|
| extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
|
| @@ -317,7 +337,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
|
| return;
|
|
|
| // First, we open a popup.
|
| - OpenExtensionPopupViaAPI();
|
| + OpenPopupViaAPI();
|
| BrowserActionTestUtil browser_action_test_util(browser());
|
| EXPECT_TRUE(browser_action_test_util.HasPopup());
|
|
|
| @@ -336,9 +356,15 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
|
| EXPECT_FALSE(browser_action_test_util.HasPopup());
|
| }
|
|
|
| -#if defined(TOOLKIT_VIEWS)
|
| +// BrowserActionTestUtil::InspectPopup() is not implemented for a Cocoa browser.
|
| +#if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER)
|
| +#define MAYBE_CloseBrowserWithDevTools CloseBrowserWithDevTools
|
| +#else
|
| +#define MAYBE_CloseBrowserWithDevTools DISABLED_CloseBrowserWithDevTools
|
| +#endif
|
| // Test closing the browser while inspecting an extension popup with dev tools.
|
| -IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, CloseBrowserWithDevTools) {
|
| +IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
|
| + MAYBE_CloseBrowserWithDevTools) {
|
| if (!ShouldRunPopupTest())
|
| return;
|
|
|
| @@ -359,7 +385,6 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, CloseBrowserWithDevTools) {
|
| // Close the browser window, this should not cause a crash.
|
| chrome::CloseWindow(browser());
|
| }
|
| -#endif // TOOLKIT_VIEWS
|
|
|
| #if defined(OS_WIN)
|
| // Test that forcibly closing the browser and popup HWND does not cause a crash.
|
| @@ -369,7 +394,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest,
|
| if (!ShouldRunPopupTest())
|
| return;
|
|
|
| - OpenExtensionPopupViaAPI();
|
| + OpenPopupViaAPI();
|
| BrowserActionTestUtil test_util(browser());
|
| const gfx::NativeView view = test_util.GetPopupNativeView();
|
| EXPECT_NE(static_cast<gfx::NativeView>(NULL), view);
|
|
|