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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #if defined(OS_MACOSX) | |
11 #include "base/mac/mac_util.h" | |
12 #endif | |
13 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
14 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
15 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
16 #include "chrome/browser/command_updater.h" | 13 #include "chrome/browser/command_updater.h" |
17 #include "chrome/browser/content_settings/host_content_settings_map.h" | 14 #include "chrome/browser/content_settings/host_content_settings_map.h" |
18 #include "chrome/browser/defaults.h" | 15 #include "chrome/browser/defaults.h" |
19 #include "chrome/browser/extensions/extension_browsertest.h" | 16 #include "chrome/browser/extensions/extension_browsertest.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/extensions/tab_helper.h" | 18 #include "chrome/browser/extensions/tab_helper.h" |
22 #include "chrome/browser/first_run/first_run.h" | 19 #include "chrome/browser/first_run/first_run.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 #include "content/public/common/page_transition_types.h" | 59 #include "content/public/common/page_transition_types.h" |
63 #include "content/public/common/renderer_preferences.h" | 60 #include "content/public/common/renderer_preferences.h" |
64 #include "content/public/common/url_constants.h" | 61 #include "content/public/common/url_constants.h" |
65 #include "content/public/test/browser_test_utils.h" | 62 #include "content/public/test/browser_test_utils.h" |
66 #include "grit/chromium_strings.h" | 63 #include "grit/chromium_strings.h" |
67 #include "grit/generated_resources.h" | 64 #include "grit/generated_resources.h" |
68 #include "net/base/mock_host_resolver.h" | 65 #include "net/base/mock_host_resolver.h" |
69 #include "net/test/test_server.h" | 66 #include "net/test/test_server.h" |
70 #include "ui/base/l10n/l10n_util.h" | 67 #include "ui/base/l10n/l10n_util.h" |
71 | 68 |
| 69 #if defined(OS_MACOSX) |
| 70 #include "base/mac/mac_util.h" |
| 71 #include "base/mac/scoped_nsautorelease_pool.h" |
| 72 #include "chrome/browser/ui/cocoa/run_loop_testing.h" |
| 73 #endif |
| 74 |
72 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
73 #include "base/i18n/rtl.h" | 76 #include "base/i18n/rtl.h" |
74 #include "chrome/browser/browser_process.h" | 77 #include "chrome/browser/browser_process.h" |
75 #endif | 78 #endif |
76 | 79 |
77 using content::InterstitialPage; | 80 using content::InterstitialPage; |
78 using content::NavigationController; | 81 using content::NavigationController; |
79 using content::NavigationEntry; | 82 using content::NavigationEntry; |
80 using content::OpenURLParams; | 83 using content::OpenURLParams; |
81 using content::Referrer; | 84 using content::Referrer; |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 browser()->OpenURL(OpenURLParams( | 425 browser()->OpenURL(OpenURLParams( |
423 url2, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | 426 url2, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); |
424 | 427 |
425 alert = ui_test_utils::WaitForAppModalDialog(); | 428 alert = ui_test_utils::WaitForAppModalDialog(); |
426 EXPECT_FALSE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); | 429 EXPECT_FALSE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); |
427 | 430 |
428 // Accept the navigation so we end up on a page without a beforeunload hook. | 431 // Accept the navigation so we end up on a page without a beforeunload hook. |
429 alert->native_dialog()->AcceptAppModalDialog(); | 432 alert->native_dialog()->AcceptAppModalDialog(); |
430 } | 433 } |
431 | 434 |
| 435 // BeforeUnloadAtQuitWithTwoWindows is a regression test for |
| 436 // http://crbug.com/11842. It opens two windows, one of which has a |
| 437 // beforeunload handler and attempts to exit cleanly. |
| 438 class BeforeUnloadAtQuitWithTwoWindows : public InProcessBrowserTest { |
| 439 public: |
| 440 // This test is for testing a specific shutdown behavior. This mimics what |
| 441 // happens in InProcessBrowserTest::RunTestOnMainThread and QuitBrowsers, but |
| 442 // ensures that it happens through the single IDC_EXIT of the test. |
| 443 virtual void CleanUpOnMainThread() OVERRIDE { |
| 444 // Cycle both the MessageLoop and the Cocoa runloop twice to flush out any |
| 445 // Chrome work that generates Cocoa work. Do this twice since there are two |
| 446 // Browsers that must be closed. |
| 447 CycleRunLoops(); |
| 448 CycleRunLoops(); |
| 449 |
| 450 // Run the application event loop to completion, which will cycle the |
| 451 // native MessagePump on all platforms. |
| 452 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 453 MessageLoop::current()->Run(); |
| 454 |
| 455 // Take care of any remaining Cocoa work. |
| 456 CycleRunLoops(); |
| 457 |
| 458 // At this point, quit should be for real now. |
| 459 ASSERT_EQ(0u, BrowserList::size()); |
| 460 } |
| 461 |
| 462 // A helper function that cycles the MessageLoop, and on Mac, the Cocoa run |
| 463 // loop. It also drains the NSAutoreleasePool. |
| 464 void CycleRunLoops() { |
| 465 content::RunAllPendingInMessageLoop(); |
| 466 #if defined(OS_MACOSX) |
| 467 chrome::testing::NSRunLoopRunAllPending(); |
| 468 AutoreleasePool()->Recycle(); |
| 469 #endif |
| 470 } |
| 471 }; |
| 472 |
| 473 IN_PROC_BROWSER_TEST_F(BeforeUnloadAtQuitWithTwoWindows, |
| 474 IfThisTestTimesOutItIndicatesFAILURE) { |
| 475 // In the first browser, set up a page that has a beforeunload handler. |
| 476 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); |
| 477 ui_test_utils::NavigateToURL(browser(), url); |
| 478 |
| 479 // Open a second browser window at about:blank. |
| 480 ui_test_utils::BrowserAddedObserver browser_added_observer; |
| 481 chrome::NewEmptyWindow(browser()->profile()); |
| 482 Browser* second_window = browser_added_observer.WaitForSingleNewBrowser(); |
| 483 ui_test_utils::NavigateToURL(second_window, GURL("about:blank")); |
| 484 |
| 485 // Tell the application to quit. IDC_EXIT calls AttemptUserExit, which on |
| 486 // everything but ChromeOS allows unload handlers to block exit. On that |
| 487 // platform, though, it exits unconditionally. See the comment and bug ID |
| 488 // in AttemptUserExit() in application_lifetime.cc. |
| 489 #if defined(OS_CHROMEOS) |
| 490 browser::AttemptExit(); |
| 491 #else |
| 492 chrome::ExecuteCommand(second_window, IDC_EXIT); |
| 493 #endif |
| 494 |
| 495 // The beforeunload handler will run at exit, ensure it does, and then accept |
| 496 // it to allow shutdown to proceed. |
| 497 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| 498 ASSERT_TRUE(alert); |
| 499 EXPECT_TRUE( |
| 500 static_cast<JavaScriptAppModalDialog*>(alert)->is_before_unload_dialog()); |
| 501 alert->native_dialog()->AcceptAppModalDialog(); |
| 502 |
| 503 // But wait there's more! If this test times out, it likely means that the |
| 504 // browser has not been able to quit correctly, indicating there's a |
| 505 // regression of the bug noted above. |
| 506 } |
| 507 |
432 // Test that scripts can fork a new renderer process for a cross-site popup, | 508 // Test that scripts can fork a new renderer process for a cross-site popup, |
433 // based on http://www.google.com/chrome/intl/en/webmasters-faq.html#newtab. | 509 // based on http://www.google.com/chrome/intl/en/webmasters-faq.html#newtab. |
434 // The script must open a new tab, set its window.opener to null, and navigate | 510 // The script must open a new tab, set its window.opener to null, and navigate |
435 // it to a cross-site URL. It should also work for meta-refreshes. | 511 // it to a cross-site URL. It should also work for meta-refreshes. |
436 // See http://crbug.com/93517. | 512 // See http://crbug.com/93517. |
437 IN_PROC_BROWSER_TEST_F(BrowserTest, NullOpenerRedirectForksProcess) { | 513 IN_PROC_BROWSER_TEST_F(BrowserTest, NullOpenerRedirectForksProcess) { |
438 CommandLine::ForCurrentProcess()->AppendSwitch( | 514 CommandLine::ForCurrentProcess()->AppendSwitch( |
439 switches::kDisablePopupBlocking); | 515 switches::kDisablePopupBlocking); |
440 | 516 |
441 // Create http and https servers for a cross-site transition. | 517 // Create http and https servers for a cross-site transition. |
(...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1613 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("WebKit"), true, true, | 1689 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("WebKit"), true, true, |
1614 NULL, NULL), | 1690 NULL, NULL), |
1615 0); | 1691 0); |
1616 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("OS"), true, true, | 1692 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("OS"), true, true, |
1617 NULL, NULL), | 1693 NULL, NULL), |
1618 0); | 1694 0); |
1619 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("JavaScript"), true, | 1695 ASSERT_GT(ui_test_utils::FindInPage(tab, ASCIIToUTF16("JavaScript"), true, |
1620 true, NULL, NULL), | 1696 true, NULL, NULL), |
1621 0); | 1697 0); |
1622 } | 1698 } |
OLD | NEW |