| 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, thus causing the bubble to lose focus and dismiss itself. |
| 109 // This works because bubbles on Mac are always toplevel. |
| 110 EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
| 111 #else |
| 112 // Elsewhere, click on the omnibox. Note that with aura, the browser may be |
| 113 // "active" the entire time when the popup is not a toplevel window. It's |
| 114 // aura::Window::Focus() that determines where key events go in this case. |
| 115 ui_test_utils::ClickOnView(browser(), VIEW_ID_OMNIBOX); |
| 116 #endif |
| 117 |
| 118 // The window disappears immediately. |
| 119 EXPECT_FALSE(BrowserActionTestUtil(browser()).HasPopup()); |
| 120 |
| 121 // Wait for the notification to achieve a consistent state and verify that |
| 122 // the popup was properly torn down. |
| 123 observer.Wait(); |
| 124 base::RunLoop().RunUntilIdle(); |
| 76 } | 125 } |
| 77 }; | 126 }; |
| 78 | 127 |
| 79 // Tests opening a popup using the chrome.browserAction.openPopup API. This test | 128 // 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 | 129 // 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. | 130 // and opens a popup in the new window. Both popups should succeed in opening. |
| 82 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TestOpenPopup) { | 131 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TestOpenPopup) { |
| 83 if (!ShouldRunPopupTest()) | 132 if (!ShouldRunPopupTest()) |
| 84 return; | 133 return; |
| 85 | 134 |
| 86 BrowserActionTestUtil browserActionBar(browser()); | 135 BrowserActionTestUtil browserActionBar(browser()); |
| 87 // Setup extension message listener to wait for javascript to finish running. | 136 // Setup extension message listener to wait for javascript to finish running. |
| 88 ExtensionTestMessageListener listener("ready", true); | 137 ExtensionTestMessageListener listener("ready", true); |
| 89 { | 138 { |
| 90 OpenExtensionPopupViaAPI(); | 139 OpenPopupViaAPI(); |
| 91 EXPECT_TRUE(browserActionBar.HasPopup()); | 140 EXPECT_TRUE(browserActionBar.HasPopup()); |
| 92 browserActionBar.HidePopup(); | 141 browserActionBar.HidePopup(); |
| 93 } | 142 } |
| 94 | 143 |
| 95 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 144 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 96 Browser* new_browser = NULL; | 145 Browser* new_browser = NULL; |
| 97 { | 146 { |
| 98 content::WindowedNotificationObserver frame_observer( | 147 content::WindowedNotificationObserver frame_observer( |
| 99 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 148 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 100 content::NotificationService::AllSources()); | 149 content::NotificationService::AllSources()); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 "browser_action/popup"))); | 247 "browser_action/popup"))); |
| 199 const Extension* extension = GetSingleLoadedExtension(); | 248 const Extension* extension = GetSingleLoadedExtension(); |
| 200 ASSERT_TRUE(extension) << message_; | 249 ASSERT_TRUE(extension) << message_; |
| 201 | 250 |
| 202 ExtensionTestMessageListener listener("ready", true); | 251 ExtensionTestMessageListener listener("ready", true); |
| 203 // Load the test extension which will do nothing except notifyPass() to | 252 // Load the test extension which will do nothing except notifyPass() to |
| 204 // return control here. | 253 // return control here. |
| 205 ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup", | 254 ASSERT_TRUE(RunExtensionSubtest("browser_action/open_popup", |
| 206 "open_popup_fails.html")) << message_; | 255 "open_popup_fails.html")) << message_; |
| 207 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 256 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 208 | 257 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; | 258 ResultCatcher catcher; |
| 218 // Return control to javascript to validate that opening a popup fails now. | 259 // Return control to javascript to validate that opening a popup fails now. |
| 219 listener.Reply("show another"); | 260 listener.Reply("show another"); |
| 220 ASSERT_TRUE(catcher.GetNextResult()) << message_; | 261 ASSERT_TRUE(catcher.GetNextResult()) << message_; |
| 221 } | 262 } |
| 222 | 263 |
| 223 // Test that openPopup does not grant tab permissions like for browser action | 264 // Test that openPopup does not grant tab permissions like for browser action |
| 224 // clicks if the activeTab permission is set. | 265 // clicks if the activeTab permission is set. |
| 225 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, | 266 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, |
| 226 TestOpenPopupDoesNotGrantTabPermissions) { | 267 TestOpenPopupDoesNotGrantTabPermissions) { |
| 227 if (!ShouldRunPopupTest()) | 268 if (!ShouldRunPopupTest()) |
| 228 return; | 269 return; |
| 229 | 270 |
| 230 OpenExtensionPopupViaAPI(); | 271 OpenPopupViaAPI(); |
| 231 ExtensionService* service = extensions::ExtensionSystem::Get( | 272 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 232 browser()->profile())->extension_service(); | 273 browser()->profile())->extension_service(); |
| 233 ASSERT_FALSE( | 274 ASSERT_FALSE( |
| 234 service->GetExtensionById(last_loaded_extension_id(), false) | 275 service->GetExtensionById(last_loaded_extension_id(), false) |
| 235 ->permissions_data() | 276 ->permissions_data() |
| 236 ->HasAPIPermissionForTab( | 277 ->HasAPIPermissionForTab( |
| 237 SessionTabHelper::IdForTab( | 278 SessionTabHelper::IdForTab( |
| 238 browser()->tab_strip_model()->GetActiveWebContents()), | 279 browser()->tab_strip_model()->GetActiveWebContents()), |
| 239 APIPermission::kTab)); | 280 APIPermission::kTab)); |
| 240 } | 281 } |
| 241 | 282 |
| 242 // Test that the extension popup is closed when the browser window is clicked. | 283 // Test that the extension popup is closed when the browser window is focused. |
| 243 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, BrowserClickClosesPopup1) { | 284 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, FocusLossClosesPopup1) { |
| 285 if (!ShouldRunPopupTest()) |
| 286 return; |
| 287 OpenPopupViaAPI(); |
| 288 ClosePopupViaFocusLoss(); |
| 289 } |
| 290 |
| 291 // Test that the extension popup is closed when the browser window is focused. |
| 292 #if defined(OS_WIN) |
| 293 // Flaky on Windows: http://crbug.com/639130 |
| 294 #define MAYBE_FocusLossClosesPopup2 DISABLED_FocusLossClosesPopup2 |
| 295 #else |
| 296 #define MAYBE_FocusLossClosesPopup2 FocusLossClosesPopup2 |
| 297 #endif |
| 298 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, |
| 299 MAYBE_FocusLossClosesPopup2) { |
| 244 if (!ShouldRunPopupTest()) | 300 if (!ShouldRunPopupTest()) |
| 245 return; | 301 return; |
| 246 | 302 |
| 247 // Open an extension popup via the chrome.browserAction.openPopup API. | |
| 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 } | |
| 260 | |
| 261 // Test that the extension popup is closed when the browser window is clicked. | |
| 262 #if defined(OS_WIN) | |
| 263 // Flaky on Windows: http://crbug.com/639130 | |
| 264 #define MAYBE_BrowserClickClosesPopup2 DISABLED_BrowserClickClosesPopup2 | |
| 265 #else | |
| 266 #define MAYBE_BrowserClickClosesPopup2 BrowserClickClosesPopup2 | |
| 267 #endif | |
| 268 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, | |
| 269 MAYBE_BrowserClickClosesPopup2) { | |
| 270 if (!ShouldRunPopupTest()) | |
| 271 return; | |
| 272 | |
| 273 // Load a first extension that can open a popup. | 303 // Load a first extension that can open a popup. |
| 274 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | 304 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
| 275 "browser_action/popup"))); | 305 "browser_action/popup"))); |
| 276 const Extension* extension = GetSingleLoadedExtension(); | 306 const Extension* extension = GetSingleLoadedExtension(); |
| 277 ASSERT_TRUE(extension) << message_; | 307 ASSERT_TRUE(extension) << message_; |
| 278 | 308 OpenPopupViaToolbar(); |
| 279 // Open an extension popup by clicking the browser action button. | 309 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 } | 310 } |
| 291 | 311 |
| 292 // Test that the extension popup is closed on browser tab switches. | 312 // Test that the extension popup is closed on browser tab switches. |
| 293 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TabSwitchClosesPopup) { | 313 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, TabSwitchClosesPopup) { |
| 294 if (!ShouldRunPopupTest()) | 314 if (!ShouldRunPopupTest()) |
| 295 return; | 315 return; |
| 296 | 316 |
| 297 // Add a second tab to the browser and open an extension popup. | 317 // Add a second tab to the browser and open an extension popup. |
| 298 chrome::NewTab(browser()); | 318 chrome::NewTab(browser()); |
| 299 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 319 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
| 300 EXPECT_EQ(browser()->tab_strip_model()->GetWebContentsAt(1), | 320 EXPECT_EQ(browser()->tab_strip_model()->GetWebContentsAt(1), |
| 301 browser()->tab_strip_model()->GetActiveWebContents()); | 321 browser()->tab_strip_model()->GetActiveWebContents()); |
| 302 OpenExtensionPopupViaAPI(); | 322 OpenPopupViaAPI(); |
| 303 | 323 |
| 304 content::WindowedNotificationObserver observer( | 324 content::WindowedNotificationObserver observer( |
| 305 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 325 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 306 content::NotificationService::AllSources()); | 326 content::NotificationService::AllSources()); |
| 307 // Change active tabs, the extension popup should close. | 327 // Change active tabs, the extension popup should close. |
| 308 browser()->tab_strip_model()->ActivateTabAt(0, true); | 328 browser()->tab_strip_model()->ActivateTabAt(0, true); |
| 309 observer.Wait(); | 329 observer.Wait(); |
| 310 | 330 |
| 311 EXPECT_FALSE(BrowserActionTestUtil(browser()).HasPopup()); | 331 EXPECT_FALSE(BrowserActionTestUtil(browser()).HasPopup()); |
| 312 } | 332 } |
| 313 | 333 |
| 314 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, | 334 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, |
| 315 DeleteBrowserActionWithPopupOpen) { | 335 DeleteBrowserActionWithPopupOpen) { |
| 316 if (!ShouldRunPopupTest()) | 336 if (!ShouldRunPopupTest()) |
| 317 return; | 337 return; |
| 318 | 338 |
| 319 // First, we open a popup. | 339 // First, we open a popup. |
| 320 OpenExtensionPopupViaAPI(); | 340 OpenPopupViaAPI(); |
| 321 BrowserActionTestUtil browser_action_test_util(browser()); | 341 BrowserActionTestUtil browser_action_test_util(browser()); |
| 322 EXPECT_TRUE(browser_action_test_util.HasPopup()); | 342 EXPECT_TRUE(browser_action_test_util.HasPopup()); |
| 323 | 343 |
| 324 // Then, find the extension that created it. | 344 // Then, find the extension that created it. |
| 325 content::WebContents* active_web_contents = | 345 content::WebContents* active_web_contents = |
| 326 browser()->tab_strip_model()->GetActiveWebContents(); | 346 browser()->tab_strip_model()->GetActiveWebContents(); |
| 327 ASSERT_TRUE(active_web_contents); | 347 ASSERT_TRUE(active_web_contents); |
| 328 GURL url = active_web_contents->GetLastCommittedURL(); | 348 GURL url = active_web_contents->GetLastCommittedURL(); |
| 329 const Extension* extension = ExtensionRegistry::Get(browser()->profile())-> | 349 const Extension* extension = ExtensionRegistry::Get(browser()->profile())-> |
| 330 enabled_extensions().GetExtensionOrAppByURL(url); | 350 enabled_extensions().GetExtensionOrAppByURL(url); |
| 331 ASSERT_TRUE(extension); | 351 ASSERT_TRUE(extension); |
| 332 | 352 |
| 333 // Finally, uninstall the extension, which causes the view to be deleted and | 353 // Finally, uninstall the extension, which causes the view to be deleted and |
| 334 // the popup to go away. This should not crash. | 354 // the popup to go away. This should not crash. |
| 335 UninstallExtension(extension->id()); | 355 UninstallExtension(extension->id()); |
| 336 EXPECT_FALSE(browser_action_test_util.HasPopup()); | 356 EXPECT_FALSE(browser_action_test_util.HasPopup()); |
| 337 } | 357 } |
| 338 | 358 |
| 339 #if defined(TOOLKIT_VIEWS) | 359 // BrowserActionTestUtil::InspectPopup() is not implemented for a Cocoa browser. |
| 360 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) |
| 361 #define MAYBE_CloseBrowserWithDevTools CloseBrowserWithDevTools |
| 362 #else |
| 363 #define MAYBE_CloseBrowserWithDevTools DISABLED_CloseBrowserWithDevTools |
| 364 #endif |
| 340 // Test closing the browser while inspecting an extension popup with dev tools. | 365 // Test closing the browser while inspecting an extension popup with dev tools. |
| 341 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, CloseBrowserWithDevTools) { | 366 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, |
| 367 MAYBE_CloseBrowserWithDevTools) { |
| 342 if (!ShouldRunPopupTest()) | 368 if (!ShouldRunPopupTest()) |
| 343 return; | 369 return; |
| 344 | 370 |
| 345 // Load a first extension that can open a popup. | 371 // Load a first extension that can open a popup. |
| 346 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( | 372 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII( |
| 347 "browser_action/popup"))); | 373 "browser_action/popup"))); |
| 348 const Extension* extension = GetSingleLoadedExtension(); | 374 const Extension* extension = GetSingleLoadedExtension(); |
| 349 ASSERT_TRUE(extension) << message_; | 375 ASSERT_TRUE(extension) << message_; |
| 350 | 376 |
| 351 // Open an extension popup by clicking the browser action button. | 377 // Open an extension popup by clicking the browser action button. |
| 352 content::WindowedNotificationObserver frame_observer( | 378 content::WindowedNotificationObserver frame_observer( |
| 353 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 379 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 354 content::NotificationService::AllSources()); | 380 content::NotificationService::AllSources()); |
| 355 BrowserActionTestUtil(browser()).InspectPopup(0); | 381 BrowserActionTestUtil(browser()).InspectPopup(0); |
| 356 frame_observer.Wait(); | 382 frame_observer.Wait(); |
| 357 EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup()); | 383 EXPECT_TRUE(BrowserActionTestUtil(browser()).HasPopup()); |
| 358 | 384 |
| 359 // Close the browser window, this should not cause a crash. | 385 // Close the browser window, this should not cause a crash. |
| 360 chrome::CloseWindow(browser()); | 386 chrome::CloseWindow(browser()); |
| 361 } | 387 } |
| 362 #endif // TOOLKIT_VIEWS | |
| 363 | 388 |
| 364 #if defined(OS_WIN) | 389 #if defined(OS_WIN) |
| 365 // Test that forcibly closing the browser and popup HWND does not cause a crash. | 390 // Test that forcibly closing the browser and popup HWND does not cause a crash. |
| 366 // http://crbug.com/400646 | 391 // http://crbug.com/400646 |
| 367 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, | 392 IN_PROC_BROWSER_TEST_F(BrowserActionInteractiveTest, |
| 368 DISABLED_DestroyHWNDDoesNotCrash) { | 393 DISABLED_DestroyHWNDDoesNotCrash) { |
| 369 if (!ShouldRunPopupTest()) | 394 if (!ShouldRunPopupTest()) |
| 370 return; | 395 return; |
| 371 | 396 |
| 372 OpenExtensionPopupViaAPI(); | 397 OpenPopupViaAPI(); |
| 373 BrowserActionTestUtil test_util(browser()); | 398 BrowserActionTestUtil test_util(browser()); |
| 374 const gfx::NativeView view = test_util.GetPopupNativeView(); | 399 const gfx::NativeView view = test_util.GetPopupNativeView(); |
| 375 EXPECT_NE(static_cast<gfx::NativeView>(NULL), view); | 400 EXPECT_NE(static_cast<gfx::NativeView>(NULL), view); |
| 376 const HWND hwnd = views::HWNDForNativeView(view); | 401 const HWND hwnd = views::HWNDForNativeView(view); |
| 377 EXPECT_EQ(hwnd, | 402 EXPECT_EQ(hwnd, |
| 378 views::HWNDForNativeView(browser()->window()->GetNativeWindow())); | 403 views::HWNDForNativeView(browser()->window()->GetNativeWindow())); |
| 379 EXPECT_EQ(TRUE, ::IsWindow(hwnd)); | 404 EXPECT_EQ(TRUE, ::IsWindow(hwnd)); |
| 380 | 405 |
| 381 // Create a new browser window to prevent the message loop from terminating. | 406 // Create a new browser window to prevent the message loop from terminating. |
| 382 browser()->OpenURL(content::OpenURLParams(GURL("about:"), content::Referrer(), | 407 browser()->OpenURL(content::OpenURLParams(GURL("about:"), content::Referrer(), |
| 383 WindowOpenDisposition::NEW_WINDOW, | 408 WindowOpenDisposition::NEW_WINDOW, |
| 384 ui::PAGE_TRANSITION_TYPED, false)); | 409 ui::PAGE_TRANSITION_TYPED, false)); |
| 385 | 410 |
| 386 // Forcibly closing the browser HWND should not cause a crash. | 411 // Forcibly closing the browser HWND should not cause a crash. |
| 387 EXPECT_EQ(TRUE, ::CloseWindow(hwnd)); | 412 EXPECT_EQ(TRUE, ::CloseWindow(hwnd)); |
| 388 EXPECT_EQ(TRUE, ::DestroyWindow(hwnd)); | 413 EXPECT_EQ(TRUE, ::DestroyWindow(hwnd)); |
| 389 EXPECT_EQ(FALSE, ::IsWindow(hwnd)); | 414 EXPECT_EQ(FALSE, ::IsWindow(hwnd)); |
| 390 } | 415 } |
| 391 #endif // OS_WIN | 416 #endif // OS_WIN |
| 392 | 417 |
| 393 } // namespace | 418 } // namespace |
| 394 } // namespace extensions | 419 } // namespace extensions |
| OLD | NEW |