Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 #include "chrome/browser/extensions/browser_action_test_util.h" | 6 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 7 #include "chrome/browser/extensions/extension_action.h" | 7 #include "chrome/browser/extensions/extension_action.h" |
| 8 #include "chrome/browser/extensions/extension_action_manager.h" | 8 #include "chrome/browser/extensions/extension_action_manager.h" |
| 9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 22 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
| 23 #include "extensions/browser/extension_registry.h" | 23 #include "extensions/browser/extension_registry.h" |
| 24 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
| 25 #include "extensions/browser/notification_types.h" | 25 #include "extensions/browser/notification_types.h" |
| 26 #include "extensions/common/extension.h" | 26 #include "extensions/common/extension.h" |
| 27 #include "extensions/common/extension_set.h" | 27 #include "extensions/common/extension_set.h" |
| 28 #include "extensions/common/permissions/permissions_data.h" | 28 #include "extensions/common/permissions/permissions_data.h" |
| 29 #include "extensions/test/extension_test_message_listener.h" | 29 #include "extensions/test/extension_test_message_listener.h" |
| 30 #include "extensions/test/result_catcher.h" | 30 #include "extensions/test/result_catcher.h" |
| 31 #include "ui/base/ui_features.h" | |
| 31 | 32 |
| 32 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
| 33 #include "ui/views/win/hwnd_util.h" | 34 #include "ui/views/win/hwnd_util.h" |
| 34 #endif | 35 #endif |
| 35 | 36 |
| 36 namespace extensions { | 37 namespace extensions { |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 // chrome.browserAction API tests that interact with the UI in such a way that | 40 // chrome.browserAction API tests that interact with the UI in such a way that |
| 40 // they cannot be run concurrently (i.e. openPopup API tests that require the | 41 // they cannot be run concurrently (i.e. openPopup API tests that require the |
| 41 // window be focused/active). | 42 // window be focused/active). |
| 42 class BrowserActionInteractiveTest : public ExtensionApiTest { | 43 class BrowserActionInteractiveTest : public ExtensionApiTest { |
| 43 public: | 44 public: |
| 44 BrowserActionInteractiveTest() {} | 45 BrowserActionInteractiveTest() {} |
| 45 ~BrowserActionInteractiveTest() override {} | 46 ~BrowserActionInteractiveTest() override {} |
| 46 | 47 |
| 48 // BrowserTestBase: | |
| 49 void SetUpOnMainThread() override { | |
| 50 ExtensionApiTest::SetUpOnMainThread(); | |
| 51 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 52 } | |
| 53 | |
| 47 protected: | 54 protected: |
| 48 // Function to control whether to run popup tests for the current platform. | 55 // Function to control whether to run popup tests for the current platform. |
| 49 // These tests require RunExtensionSubtest to work as expected and the browser | 56 // These tests require RunExtensionSubtest to work as expected and the browser |
| 50 // window to able to be made active automatically. Returns false for platforms | 57 // window to able to be made active automatically. Returns false for platforms |
| 51 // where these conditions are not met. | 58 // where these conditions are not met. |
| 52 bool ShouldRunPopupTest() { | 59 bool ShouldRunPopupTest() { |
| 53 // TODO(justinlin): http://crbug.com/177163 | 60 // TODO(justinlin): http://crbug.com/177163 |
| 54 #if defined(OS_WIN) && !defined(NDEBUG) | 61 #if defined(OS_WIN) && !defined(NDEBUG) |
| 55 return false; | 62 return false; |
| 56 #elif defined(OS_MACOSX) | |
| 57 // TODO(justinlin): Browser window do not become active on Mac even when | |
| 58 // Activate() is called on them. Enable when/if it's possible to fix. | |
| 59 return false; | |
| 60 #else | 63 #else |
| 61 return true; | 64 return true; |
| 62 #endif | 65 #endif |
| 63 } | 66 } |
| 64 | 67 |
| 68 void EnsurePopupActive() { | |
| 69 BrowserActionTestUtil test_util(browser()); | |
| 70 EXPECT_TRUE(test_util.HasPopup()); | |
| 71 EXPECT_TRUE(test_util.WaitForPopup()); | |
| 72 EXPECT_TRUE(test_util.HasPopup()); | |
| 73 } | |
| 74 | |
| 65 // Open an extension popup via the chrome.browserAction.openPopup API. | 75 // Open an extension popup via the chrome.browserAction.openPopup API. |
| 66 void OpenExtensionPopupViaAPI() { | 76 void OpenPopupViaAPI() { |
| 67 // Setup the notification observer to wait for the popup to finish loading. | 77 // Setup the notification observer to wait for the popup to finish loading. |
| 68 content::WindowedNotificationObserver frame_observer( | 78 content::WindowedNotificationObserver frame_observer( |
| 69 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 79 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 70 content::NotificationService::AllSources()); | 80 content::NotificationService::AllSources()); |
| 71 // Show first popup in first window and expect it to have loaded. | 81 // Show first popup in first window and expect it to have loaded. |
| 72 ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup", | 82 ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup", |
| 73 "open_popup_succeeds.html")) << message_; | 83 "open_popup_succeeds.html")) << message_; |
| 74 frame_observer.Wait(); | 84 frame_observer.Wait(); |
| 85 EnsurePopupActive(); | |
| 86 } | |
| 87 | |
| 88 // Open an extension popup by clicking the browser action button. | |
| 89 void OpenPopupViaToolbar() { | |
| 90 content::WindowedNotificationObserver frame_observer( | |
| 91 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 92 content::NotificationService::AllSources()); | |
| 93 BrowserActionTestUtil(browser()).Press(0); | |
| 94 frame_observer.Wait(); | |
| 95 EnsurePopupActive(); | |
| 96 } | |
| 97 | |
| 98 // Trigger a focus loss to close the popup. | |
| 99 void ClosePopupViaFocusLoss() { | |
| 75 EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup()); | 100 EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup()); |
| 101 content::WindowedNotificationObserver observer( | |
| 102 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, | |
| 103 content::NotificationService::AllSources()); | |
| 104 | |
| 105 #if defined(OS_MACOSX) | |
| 106 // ClickOnView() in an inactive window is not robust on Mac. The click does | |
| 107 // not guarantee window activation on trybots. So activate the browser | |
| 108 // explicitly. This works because bubbles on Mac are always toplevel. | |
|
Devlin
2017/05/31 14:39:00
nit: I'd add something like "activating the browse
tapted
2017/06/01 05:23:37
Done.
| |
| 109 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | |
| 110 #else | |
| 111 // Elsewhere, click on the omnibox. Note that with aura, the browser may be | |
| 112 // "active" the entire time when the popup is not a toplevel window. It's | |
| 113 // aura::Window::Focus() that determines where key events go in this case. | |
| 114 ui_test_utils::ClickOnView(browser(), VIEW_ID_OMNIBOX); | |
| 115 #endif | |
| 116 | |
| 117 // The window disappears immediately. | |
| 118 EXPECT_FALSE(BrowserActionTestUtil(browser()).HasPopup()); | |
| 119 | |
| 120 // Wait for the notification to achieve a consistent state and verify that | |
| 121 // the popup was properly torn down. | |
| 122 observer.Wait(); | |
| 123 base::RunLoop().RunUntilIdle(); | |
| 76 } | 124 } |
| 77 }; | 125 }; |
| 78 | 126 |
| 79 // Tests opening a popup using the chrome.browserAction.openPopup API. This test | 127 // Tests opening a popup using the chrome.browserAction.openPopup API. This test |
| 80 // opens a popup in the starting window, closes the popup, creates a new window | 128 // opens a popup in the starting window, closes the popup, creates a new window |
| 81 // and opens a popup in the new window. Both popups should succeed in opening. | 129 // and opens a popup in the new window. Both popups should succeed in opening. |
| 82 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TestOpenPopup) { | 130 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TestOpenPopup) { |
| 83 if (!ShouldRunPopupTest()) | 131 if (!ShouldRunPopupTest()) |
| 84 return; | 132 return; |
| 85 | 133 |
| 86 BrowserActionTestUtil browserActionBar(browser()); | 134 BrowserActionTestUtil browserActionBar(browser()); |
| 87 // Setup extension message listener to wait for javascript to finish running. | 135 // Setup extension message listener to wait for javascript to finish running. |
| 88 ExtensionTestMessageListener listener("ready", true); | 136 ExtensionTestMessageListener listener("ready", true); |
| 89 { | 137 { |
| 90 OpenExtensionPopupViaAPI(); | 138 OpenPopupViaAPI(); |
| 91 EXPECT_TRUE(browserActionBar.HasPopup()); | 139 EXPECT_TRUE(browserActionBar.HasPopup()); |
| 92 browserActionBar.HidePopup(); | 140 browserActionBar.HidePopup(); |
| 93 } | 141 } |
| 94 | 142 |
| 95 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 143 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 96 Browser* new_browser = NULL; | 144 Browser* new_browser = NULL; |
| 97 { | 145 { |
| 98 content::WindowedNotificationObserver frame_observer( | 146 content::WindowedNotificationObserver frame_observer( |
| 99 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 147 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 100 content::NotificationService::AllSources()); | 148 content::NotificationService::AllSources()); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 "browser_action/popup"))); | 246 "browser_action/popup"))); |
| 199 const Extension* extension = GetSingleLoadedExtension(); | 247 const Extension* extension = GetSingleLoadedExtension(); |
| 200 ASSERT_TRUE(extension) << message_; | 248 ASSERT_TRUE(extension) << message_; |
| 201 | 249 |
| 202 ExtensionTestMessageListener listener("ready", true); | 250 ExtensionTestMessageListener listener("ready", true); |
| 203 // Load the test extension which will do nothing except notifyPass() to | 251 // Load the test extension which will do nothing except notifyPass() to |
| 204 // return control here. | 252 // return control here. |
| 205 ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup", | 253 ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup", |
| 206 "open_popup_fails.html")) << message_; | 254 "open_popup_fails.html")) << message_; |
| 207 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 255 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 208 | 256 OpenPopupViaToolbar(); |
| 209 content::WindowedNotificationObserver frame_observer( | |
| 210 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 211 content::NotificationService::AllSources()); | |
| 212 // Open popup in the first extension. | |
| 213 BrowserActionTestUtil(browser()).Press(0); | |
| 214 frame_observer.Wait(); | |
| 215 EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup()); | |
| 216 | |
| 217 ResultCatcher catcher; | 257 ResultCatcher catcher; |
| 218 // Return control to javascript to validate that opening a popup fails now. | 258 // Return control to javascript to validate that opening a popup fails now. |
| 219 listener.Reply("show another"); | 259 listener.Reply("show another"); |
| 220 ASSERT_TRUE(catcher.GetNextResult()) << message_; | 260 ASSERT_TRUE(catcher.GetNextResult()) << message_; |
| 221 } | 261 } |
| 222 | 262 |
| 223 // Test that openPopup does not grant tab permissions like for browser action | 263 // Test that openPopup does not grant tab permissions like for browser action |
| 224 // clicks if the activeTab permission is set. | 264 // clicks if the activeTab permission is set. |
| 225 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, | 265 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, |
| 226 TestOpenPopupDoesNotGrantTabPermissions) { | 266 TestOpenPopupDoesNotGrantTabPermissions) { |
| 227 if (!ShouldRunPopupTest()) | 267 if (!ShouldRunPopupTest()) |
| 228 return; | 268 return; |
| 229 | 269 |
| 230 OpenExtensionPopupViaAPI(); | 270 OpenPopupViaAPI(); |
| 231 ExtensionService* service = extensions::ExtensionSystem::Get( | 271 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 232 browser()->profile())->extension_service(); | 272 browser()->profile())->extension_service(); |
| 233 ASSERT_FALSE( | 273 ASSERT_FALSE( |
| 234 service->GetExtensionById(last_loaded_extension_id(), false) | 274 service->GetExtensionById(last_loaded_extension_id(), false) |
| 235 ->permissions_data() | 275 ->permissions_data() |
| 236 ->HasAPIPermissionForTab( | 276 ->HasAPIPermissionForTab( |
| 237 SessionTabHelper::IdForTab( | 277 SessionTabHelper::IdForTab( |
| 238 browser()->tab_strip_model()->GetActiveWebContents()), | 278 browser()->tab_strip_model()->GetActiveWebContents()), |
| 239 APIPermission::kTab)); | 279 APIPermission::kTab)); |
| 240 } | 280 } |
| 241 | 281 |
| 242 // Test that the extension popup is closed when the browser window is clicked. | 282 // Test that the extension popup is closed when the browser window is clicked. |
| 243 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, BrowserClickClosesPopup1) { | 283 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, BrowserClickClosesPopup1) { |
|
Devlin
2017/05/31 14:39:00
should we rename this test and update the comment?
tapted
2017/06/01 05:23:37
Yup - Done.
| |
| 244 if (!ShouldRunPopupTest()) | 284 if (!ShouldRunPopupTest()) |
| 245 return; | 285 return; |
| 246 | 286 OpenPopupViaAPI(); |
| 247 // Open an extension popup via the chrome.browserAction.openPopup API. | 287 ClosePopupViaFocusLoss(); |
| 248 content::WindowedNotificationObserver frame_observer( | |
| 249 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 250 content::NotificationService::AllSources()); | |
| 251 ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup", | |
| 252 "open_popup_succeeds.html")) << message_; | |
| 253 frame_observer.Wait(); | |
| 254 EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup()); | |
| 255 | |
| 256 // Click on the omnibox to close the extension popup. | |
| 257 ui_test_utils::ClickOnView(browser(), VIEW_ID_OMNIBOX); | |
| 258 EXPECT_FALSE(BrowserActionTestUtil(browser()).HasPopup()); | |
| 259 } | 288 } |
| 260 | 289 |
| 261 // Test that the extension popup is closed when the browser window is clicked. | 290 // Test that the extension popup is closed when the browser window is clicked. |
| 262 #if defined(OS_WIN) | 291 #if defined(OS_WIN) |
| 263 // Flaky on Windows: http://crbug.com/639130 | 292 // Flaky on Windows: http://crbug.com/639130 |
| 264 #define MAYBE_BrowserClickClosesPopup2 DISABLED_BrowserClickClosesPopup2 | 293 #define MAYBE_BrowserClickClosesPopup2 DISABLED_BrowserClickClosesPopup2 |
| 265 #else | 294 #else |
| 266 #define MAYBE_BrowserClickClosesPopup2 BrowserClickClosesPopup2 | 295 #define MAYBE_BrowserClickClosesPopup2 BrowserClickClosesPopup2 |
| 267 #endif | 296 #endif |
| 268 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, | 297 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, |
| 269 MAYBE_BrowserClickClosesPopup2) { | 298 MAYBE_BrowserClickClosesPopup2) { |
|
Devlin
2017/05/31 14:39:00
ditto
tapted
2017/06/01 05:23:37
Done.
| |
| 270 if (!ShouldRunPopupTest()) | 299 if (!ShouldRunPopupTest()) |
| 271 return; | 300 return; |
| 272 | 301 |
| 273 // Load a first extension that can open a popup. | 302 // Load a first extension that can open a popup. |
| 274 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | 303 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
| 275 "browser_action/popup"))); | 304 "browser_action/popup"))); |
| 276 const Extension* extension = GetSingleLoadedExtension(); | 305 const Extension* extension = GetSingleLoadedExtension(); |
| 277 ASSERT_TRUE(extension) << message_; | 306 ASSERT_TRUE(extension) << message_; |
| 278 | 307 OpenPopupViaToolbar(); |
| 279 // Open an extension popup by clicking the browser action button. | 308 ClosePopupViaFocusLoss(); |
| 280 content::WindowedNotificationObserver frame_observer( | |
| 281 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 282 content::NotificationService::AllSources()); | |
| 283 BrowserActionTestUtil(browser()).Press(0); | |
| 284 frame_observer.Wait(); | |
| 285 EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup()); | |
| 286 | |
| 287 // Click on the omnibox to close the extension popup. | |
| 288 ui_test_utils::ClickOnView(browser(), VIEW_ID_OMNIBOX); | |
| 289 EXPECT_FALSE(BrowserActionTestUtil(browser()).HasPopup()); | |
| 290 } | 309 } |
| 291 | 310 |
| 292 // Test that the extension popup is closed on browser tab switches. | 311 // Test that the extension popup is closed on browser tab switches. |
| 293 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TabSwitchClosesPopup) { | 312 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TabSwitchClosesPopup) { |
| 294 if (!ShouldRunPopupTest()) | 313 if (!ShouldRunPopupTest()) |
| 295 return; | 314 return; |
| 296 | 315 |
| 297 // Add a second tab to the browser and open an extension popup. | 316 // Add a second tab to the browser and open an extension popup. |
| 298 chrome::NewTab(browser()); | 317 chrome::NewTab(browser()); |
| 299 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 318 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 300 EXPECT_EQ(browser()->tab_strip_model()->GetWebContentsAt(1), | 319 EXPECT_EQ(browser()->tab_strip_model()->GetWebContentsAt(1), |
| 301 browser()->tab_strip_model()->GetActiveWebContents()); | 320 browser()->tab_strip_model()->GetActiveWebContents()); |
| 302 OpenExtensionPopupViaAPI(); | 321 OpenPopupViaAPI(); |
| 303 | 322 |
| 304 content::WindowedNotificationObserver observer( | 323 content::WindowedNotificationObserver observer( |
| 305 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 324 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 306 content::NotificationService::AllSources()); | 325 content::NotificationService::AllSources()); |
| 307 // Change active tabs, the extension popup should close. | 326 // Change active tabs, the extension popup should close. |
| 308 browser()->tab_strip_model()->ActivateTabAt(0, true); | 327 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 309 observer.Wait(); | 328 observer.Wait(); |
| 310 | 329 |
| 311 EXPECT_FALSE(BrowserActionTestUtil(browser()).HasPopup()); | 330 EXPECT_FALSE(BrowserActionTestUtil(browser()).HasPopup()); |
| 312 } | 331 } |
| 313 | 332 |
| 314 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, | 333 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, |
| 315 DeleteBrowserActionWithPopupOpen) { | 334 DeleteBrowserActionWithPopupOpen) { |
| 316 if (!ShouldRunPopupTest()) | 335 if (!ShouldRunPopupTest()) |
| 317 return; | 336 return; |
| 318 | 337 |
| 319 // First, we open a popup. | 338 // First, we open a popup. |
| 320 OpenExtensionPopupViaAPI(); | 339 OpenPopupViaAPI(); |
| 321 BrowserActionTestUtil browser_action_test_util(browser()); | 340 BrowserActionTestUtil browser_action_test_util(browser()); |
| 322 EXPECT_TRUE(browser_action_test_util.HasPopup()); | 341 EXPECT_TRUE(browser_action_test_util.HasPopup()); |
| 323 | 342 |
| 324 // Then, find the extension that created it. | 343 // Then, find the extension that created it. |
| 325 content::WebContents* active_web_contents = | 344 content::WebContents* active_web_contents = |
| 326 browser()->tab_strip_model()->GetActiveWebContents(); | 345 browser()->tab_strip_model()->GetActiveWebContents(); |
| 327 ASSERT_TRUE(active_web_contents); | 346 ASSERT_TRUE(active_web_contents); |
| 328 GURL url = active_web_contents->GetLastCommittedURL(); | 347 GURL url = active_web_contents->GetLastCommittedURL(); |
| 329 const Extension* extension = ExtensionRegistry::Get(browser()->profile())-> | 348 const Extension* extension = ExtensionRegistry::Get(browser()->profile())-> |
| 330 enabled_extensions().GetExtensionOrAppByURL(url); | 349 enabled_extensions().GetExtensionOrAppByURL(url); |
| 331 ASSERT_TRUE(extension); | 350 ASSERT_TRUE(extension); |
| 332 | 351 |
| 333 // Finally, uninstall the extension, which causes the view to be deleted and | 352 // Finally, uninstall the extension, which causes the view to be deleted and |
| 334 // the popup to go away. This should not crash. | 353 // the popup to go away. This should not crash. |
| 335 UninstallExtension(extension->id()); | 354 UninstallExtension(extension->id()); |
| 336 EXPECT_FALSE(browser_action_test_util.HasPopup()); | 355 EXPECT_FALSE(browser_action_test_util.HasPopup()); |
| 337 } | 356 } |
| 338 | 357 |
| 339 #if defined(TOOLKIT_VIEWS) | 358 // BrowserActionTestUtil::InspectPopup() is not implemented for a Cocoa browser. |
| 359 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
| 360 #define MAYBE_CloseBrowserWithDevTools CloseBrowserWithDevTools | |
| 361 #else | |
| 362 #define MAYBE_CloseBrowserWithDevTools DISABLED_CloseBrowserWithDevTools | |
| 363 #endif | |
| 340 // Test closing the browser while inspecting an extension popup with dev tools. | 364 // Test closing the browser while inspecting an extension popup with dev tools. |
| 341 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, CloseBrowserWithDevTools) { | 365 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, |
| 366 MAYBE_CloseBrowserWithDevTools) { | |
| 342 if (!ShouldRunPopupTest()) | 367 if (!ShouldRunPopupTest()) |
| 343 return; | 368 return; |
| 344 | 369 |
| 345 // Load a first extension that can open a popup. | 370 // Load a first extension that can open a popup. |
| 346 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | 371 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
| 347 "browser_action/popup"))); | 372 "browser_action/popup"))); |
| 348 const Extension* extension = GetSingleLoadedExtension(); | 373 const Extension* extension = GetSingleLoadedExtension(); |
| 349 ASSERT_TRUE(extension) << message_; | 374 ASSERT_TRUE(extension) << message_; |
| 350 | 375 |
| 351 // Open an extension popup by clicking the browser action button. | 376 // Open an extension popup by clicking the browser action button. |
| 352 content::WindowedNotificationObserver frame_observer( | 377 content::WindowedNotificationObserver frame_observer( |
| 353 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 378 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 354 content::NotificationService::AllSources()); | 379 content::NotificationService::AllSources()); |
| 355 BrowserActionTestUtil(browser()).InspectPopup(0); | 380 BrowserActionTestUtil(browser()).InspectPopup(0); |
| 356 frame_observer.Wait(); | 381 frame_observer.Wait(); |
| 357 EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup()); | 382 EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup()); |
| 358 | 383 |
| 359 // Close the browser window, this should not cause a crash. | 384 // Close the browser window, this should not cause a crash. |
| 360 chrome::CloseWindow(browser()); | 385 chrome::CloseWindow(browser()); |
| 361 } | 386 } |
| 362 #endif // TOOLKIT_VIEWS | |
| 363 | 387 |
| 364 #if defined(OS_WIN) | 388 #if defined(OS_WIN) |
| 365 // Test that forcibly closing the browser and popup HWND does not cause a crash. | 389 // Test that forcibly closing the browser and popup HWND does not cause a crash. |
| 366 // http://crbug.com/400646 | 390 // http://crbug.com/400646 |
| 367 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, | 391 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, |
| 368 DISABLED_DestroyHWNDDoesNotCrash) { | 392 DISABLED_DestroyHWNDDoesNotCrash) { |
| 369 if (!ShouldRunPopupTest()) | 393 if (!ShouldRunPopupTest()) |
| 370 return; | 394 return; |
| 371 | 395 |
| 372 OpenExtensionPopupViaAPI(); | 396 OpenPopupViaAPI(); |
| 373 BrowserActionTestUtil test_util(browser()); | 397 BrowserActionTestUtil test_util(browser()); |
| 374 const gfx::NativeView view = test_util.GetPopupNativeView(); | 398 const gfx::NativeView view = test_util.GetPopupNativeView(); |
| 375 EXPECT_NE(static_cast<gfx::NativeView>(NULL), view); | 399 EXPECT_NE(static_cast<gfx::NativeView>(NULL), view); |
| 376 const HWND hwnd = views::HWNDForNativeView(view); | 400 const HWND hwnd = views::HWNDForNativeView(view); |
| 377 EXPECT_EQ(hwnd, | 401 EXPECT_EQ(hwnd, |
| 378 views::HWNDForNativeView(browser()->window()->GetNativeWindow())); | 402 views::HWNDForNativeView(browser()->window()->GetNativeWindow())); |
| 379 EXPECT_EQ(TRUE, ::IsWindow(hwnd)); | 403 EXPECT_EQ(TRUE, ::IsWindow(hwnd)); |
| 380 | 404 |
| 381 // Create a new browser window to prevent the message loop from terminating. | 405 // Create a new browser window to prevent the message loop from terminating. |
| 382 browser()->OpenURL(content::OpenURLParams(GURL("about:"), content::Referrer(), | 406 browser()->OpenURL(content::OpenURLParams(GURL("about:"), content::Referrer(), |
| 383 WindowOpenDisposition::NEW_WINDOW, | 407 WindowOpenDisposition::NEW_WINDOW, |
| 384 ui::PAGE_TRANSITION_TYPED, false)); | 408 ui::PAGE_TRANSITION_TYPED, false)); |
| 385 | 409 |
| 386 // Forcibly closing the browser HWND should not cause a crash. | 410 // Forcibly closing the browser HWND should not cause a crash. |
| 387 EXPECT_EQ(TRUE, ::CloseWindow(hwnd)); | 411 EXPECT_EQ(TRUE, ::CloseWindow(hwnd)); |
| 388 EXPECT_EQ(TRUE, ::DestroyWindow(hwnd)); | 412 EXPECT_EQ(TRUE, ::DestroyWindow(hwnd)); |
| 389 EXPECT_EQ(FALSE, ::IsWindow(hwnd)); | 413 EXPECT_EQ(FALSE, ::IsWindow(hwnd)); |
| 390 } | 414 } |
| 391 #endif // OS_WIN | 415 #endif // OS_WIN |
| 392 | 416 |
| 393 } // namespace | 417 } // namespace |
| 394 } // namespace extensions | 418 } // namespace extensions |
| OLD | NEW |