| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/extensions/extension_host.h" |
| 10 #include "chrome/browser/extensions/extension_process_manager.h" |
| 9 #include "chrome/browser/extensions/extension_test_message_listener.h" | 11 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 10 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
| 12 #include "chrome/browser/ui/browser_list.h" | 14 #include "chrome/browser/ui/browser_list.h" |
| 13 #include "chrome/browser/ui/browser_tabstrip.h" | 15 #include "chrome/browser/ui/browser_tabstrip.h" |
| 14 #include "chrome/browser/ui/panels/panel_manager.h" | 16 #include "chrome/browser/ui/panels/panel_manager.h" |
| 15 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "content/public/browser/render_process_host.h" |
| 18 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/common/result_codes.h" |
| 19 #include "content/public/test/browser_test_utils.h" | 23 #include "content/public/test/browser_test_utils.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "net/base/mock_host_resolver.h" | 25 #include "net/base/mock_host_resolver.h" |
| 22 | 26 |
| 23 using content::OpenURLParams; | 27 using content::OpenURLParams; |
| 24 using content::Referrer; | 28 using content::Referrer; |
| 25 using content::WebContents; | 29 using content::WebContents; |
| 26 | 30 |
| 27 // Disabled, http://crbug.com/64899. | 31 // Disabled, http://crbug.com/64899. |
| 28 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) { | 32 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) { |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 #if defined(USE_ASH) | 279 #if defined(USE_ASH) |
| 276 // On Ash, new panel windows open as popup windows instead, so there are 2 | 280 // On Ash, new panel windows open as popup windows instead, so there are 2 |
| 277 // extension domain popups that will close (instead of 1 popup on non-Ash). | 281 // extension domain popups that will close (instead of 1 popup on non-Ash). |
| 278 num_popups -= 2; | 282 num_popups -= 2; |
| 279 #else | 283 #else |
| 280 num_popups -= 1; | 284 num_popups -= 1; |
| 281 #endif | 285 #endif |
| 282 WaitForTabsAndPopups(browser(), 1, num_popups, 0); | 286 WaitForTabsAndPopups(browser(), 1, num_popups, 0); |
| 283 } | 287 } |
| 284 | 288 |
| 289 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, ClosePanelsOnExtensionCrash) { |
| 290 #if defined(USE_ASH) |
| 291 // On Ash, new panel windows open as popup windows instead. |
| 292 int num_popups = 4; |
| 293 int num_panels = 0; |
| 294 #else |
| 295 int num_popups = 2; |
| 296 int num_panels = 2; |
| 297 #endif |
| 298 ASSERT_TRUE(StartTestServer()); |
| 299 |
| 300 // Setup listeners to wait on strings we expect the extension pages to send. |
| 301 std::vector<std::string> test_strings; |
| 302 test_strings.push_back("content_tab"); |
| 303 if (num_panels) |
| 304 test_strings.push_back("content_panel"); |
| 305 test_strings.push_back("content_popup"); |
| 306 |
| 307 ScopedVector<ExtensionTestMessageListener> listeners; |
| 308 for (size_t i = 0; i < test_strings.size(); ++i) { |
| 309 listeners.push_back( |
| 310 new ExtensionTestMessageListener(test_strings[i], false)); |
| 311 } |
| 312 |
| 313 const extensions::Extension* extension = LoadExtension( |
| 314 test_data_dir_.AppendASCII("window_open").AppendASCII( |
| 315 "close_panels_on_uninstall")); |
| 316 ASSERT_TRUE(extension); |
| 317 |
| 318 // Two tabs. One in extension domain and one in non-extension domain. |
| 319 // Two popups - one in extension domain and one in non-extension domain. |
| 320 // Two panels - one in extension domain and one in non-extension domain. |
| 321 WaitForTabsAndPopups(browser(), 2, num_popups, num_panels); |
| 322 |
| 323 // Wait on test messages to make sure the pages loaded. |
| 324 for (size_t i = 0; i < listeners.size(); ++i) |
| 325 ASSERT_TRUE(listeners[i]->WaitUntilSatisfied()); |
| 326 |
| 327 // Crash the extension. |
| 328 extensions::ExtensionHost* extension_host = |
| 329 browser()->profile()->GetExtensionProcessManager()-> |
| 330 GetBackgroundHostForExtension(extension->id()); |
| 331 ASSERT_TRUE(extension_host); |
| 332 base::KillProcess(extension_host->render_process_host()->GetHandle(), |
| 333 content::RESULT_CODE_KILLED, false); |
| 334 WaitForExtensionCrash(extension->id()); |
| 335 |
| 336 // Only expect panels to close. The rest stay open to show a sad-tab. |
| 337 WaitForTabsAndPopups(browser(), 2, num_popups, 0); |
| 338 } |
| 339 |
| 285 #if defined(USE_ASH) | 340 #if defined(USE_ASH) |
| 286 // This test is not applicable on Ash. Ash opens panel windows as popup | 341 // This test is not applicable on Ash. Ash opens panel windows as popup |
| 287 // windows. The modified window.open behavior only applies to panel windows. | 342 // windows. The modified window.open behavior only applies to panel windows. |
| 288 #define MAYBE_WindowOpenFromPanel DISABLED_WindowOpenFromPanel | 343 #define MAYBE_WindowOpenFromPanel DISABLED_WindowOpenFromPanel |
| 289 #else | 344 #else |
| 290 #define MAYBE_WindowOpenFromPanel WindowOpenFromPanel | 345 #define MAYBE_WindowOpenFromPanel WindowOpenFromPanel |
| 291 #endif | 346 #endif |
| 292 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenFromPanel) { | 347 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenFromPanel) { |
| 293 ASSERT_TRUE(StartTestServer()); | 348 ASSERT_TRUE(StartTestServer()); |
| 294 | 349 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 ASSERT_NO_FATAL_FAILURE(OpenWindow(chrome::GetActiveWebContents(browser()), | 409 ASSERT_NO_FATAL_FAILURE(OpenWindow(chrome::GetActiveWebContents(browser()), |
| 355 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + | 410 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + |
| 356 "/newtab.html"), false, &newtab)); | 411 "/newtab.html"), false, &newtab)); |
| 357 | 412 |
| 358 // Extension API should succeed. | 413 // Extension API should succeed. |
| 359 bool result = false; | 414 bool result = false; |
| 360 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 415 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 361 newtab->GetRenderViewHost(), L"", L"testExtensionApi()", &result)); | 416 newtab->GetRenderViewHost(), L"", L"testExtensionApi()", &result)); |
| 362 EXPECT_TRUE(result); | 417 EXPECT_TRUE(result); |
| 363 } | 418 } |
| OLD | NEW |