| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/ui/browser.h" | 5 #include "chrome/browser/ui/browser.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 ui_test_utils::NavigateToURL(browser(), ntp_url); | 513 ui_test_utils::NavigateToURL(browser(), ntp_url); |
| 514 | 514 |
| 515 // Navigate to a 204 URL (aborts with no content) on the NTP and make sure it | 515 // Navigate to a 204 URL (aborts with no content) on the NTP and make sure it |
| 516 // sticks around so that the user can edit it. | 516 // sticks around so that the user can edit it. |
| 517 GURL abort_url(embedded_test_server()->GetURL("/nocontent")); | 517 GURL abort_url(embedded_test_server()->GetURL("/nocontent")); |
| 518 { | 518 { |
| 519 content::WindowedNotificationObserver stop_observer( | 519 content::WindowedNotificationObserver stop_observer( |
| 520 content::NOTIFICATION_LOAD_STOP, | 520 content::NOTIFICATION_LOAD_STOP, |
| 521 content::Source<NavigationController>( | 521 content::Source<NavigationController>( |
| 522 &web_contents->GetController())); | 522 &web_contents->GetController())); |
| 523 browser()->OpenURL(OpenURLParams(abort_url, Referrer(), CURRENT_TAB, | 523 browser()->OpenURL(OpenURLParams(abort_url, Referrer(), |
| 524 WindowOpenDisposition::CURRENT_TAB, |
| 524 ui::PAGE_TRANSITION_TYPED, false)); | 525 ui::PAGE_TRANSITION_TYPED, false)); |
| 525 stop_observer.Wait(); | 526 stop_observer.Wait(); |
| 526 EXPECT_TRUE(web_contents->GetController().GetPendingEntry()); | 527 EXPECT_TRUE(web_contents->GetController().GetPendingEntry()); |
| 527 EXPECT_EQ(abort_url, web_contents->GetVisibleURL()); | 528 EXPECT_EQ(abort_url, web_contents->GetVisibleURL()); |
| 528 } | 529 } |
| 529 | 530 |
| 530 // Navigate to a real URL. | 531 // Navigate to a real URL. |
| 531 GURL real_url(embedded_test_server()->GetURL("/title1.html")); | 532 GURL real_url(embedded_test_server()->GetURL("/title1.html")); |
| 532 ui_test_utils::NavigateToURL(browser(), real_url); | 533 ui_test_utils::NavigateToURL(browser(), real_url); |
| 533 EXPECT_EQ(real_url, web_contents->GetVisibleURL()); | 534 EXPECT_EQ(real_url, web_contents->GetVisibleURL()); |
| 534 | 535 |
| 535 // Now navigating to a 204 URL should clear the pending entry. | 536 // Now navigating to a 204 URL should clear the pending entry. |
| 536 { | 537 { |
| 537 content::WindowedNotificationObserver stop_observer( | 538 content::WindowedNotificationObserver stop_observer( |
| 538 content::NOTIFICATION_LOAD_STOP, | 539 content::NOTIFICATION_LOAD_STOP, |
| 539 content::Source<NavigationController>( | 540 content::Source<NavigationController>( |
| 540 &web_contents->GetController())); | 541 &web_contents->GetController())); |
| 541 browser()->OpenURL(OpenURLParams(abort_url, Referrer(), CURRENT_TAB, | 542 browser()->OpenURL(OpenURLParams(abort_url, Referrer(), |
| 543 WindowOpenDisposition::CURRENT_TAB, |
| 542 ui::PAGE_TRANSITION_TYPED, false)); | 544 ui::PAGE_TRANSITION_TYPED, false)); |
| 543 stop_observer.Wait(); | 545 stop_observer.Wait(); |
| 544 EXPECT_FALSE(web_contents->GetController().GetPendingEntry()); | 546 EXPECT_FALSE(web_contents->GetController().GetPendingEntry()); |
| 545 EXPECT_EQ(real_url, web_contents->GetVisibleURL()); | 547 EXPECT_EQ(real_url, web_contents->GetVisibleURL()); |
| 546 } | 548 } |
| 547 } | 549 } |
| 548 | 550 |
| 549 // Test for crbug.com/297289. Ensure that modal dialogs are closed when a | 551 // Test for crbug.com/297289. Ensure that modal dialogs are closed when a |
| 550 // cross-process navigation is ready to commit. | 552 // cross-process navigation is ready to commit. |
| 551 // Flaky test, see https://crbug.com/445155. | 553 // Flaky test, see https://crbug.com/445155. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 } | 662 } |
| 661 | 663 |
| 662 // Test for crbug.com/22004. Reloading a page with a before unload handler and | 664 // Test for crbug.com/22004. Reloading a page with a before unload handler and |
| 663 // then canceling the dialog should not leave the throbber spinning. | 665 // then canceling the dialog should not leave the throbber spinning. |
| 664 IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) { | 666 IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) { |
| 665 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); | 667 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); |
| 666 ui_test_utils::NavigateToURL(browser(), url); | 668 ui_test_utils::NavigateToURL(browser(), url); |
| 667 | 669 |
| 668 // Navigate to another page, but click cancel in the dialog. Make sure that | 670 // Navigate to another page, but click cancel in the dialog. Make sure that |
| 669 // the throbber stops spinning. | 671 // the throbber stops spinning. |
| 670 chrome::Reload(browser(), CURRENT_TAB); | 672 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 671 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 673 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| 672 alert->CloseModalDialog(); | 674 alert->CloseModalDialog(); |
| 673 EXPECT_FALSE( | 675 EXPECT_FALSE( |
| 674 browser()->tab_strip_model()->GetActiveWebContents()->IsLoading()); | 676 browser()->tab_strip_model()->GetActiveWebContents()->IsLoading()); |
| 675 | 677 |
| 676 // Clear the beforeunload handler so the test can easily exit. | 678 // Clear the beforeunload handler so the test can easily exit. |
| 677 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()-> | 679 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()-> |
| 678 ExecuteJavaScriptForTests(ASCIIToUTF16("onbeforeunload=null;")); | 680 ExecuteJavaScriptForTests(ASCIIToUTF16("onbeforeunload=null;")); |
| 679 } | 681 } |
| 680 | 682 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 ui_test_utils::NavigateToURL(browser(), url); | 783 ui_test_utils::NavigateToURL(browser(), url); |
| 782 | 784 |
| 783 // Navigate to a URL that redirects to another process and approve the | 785 // Navigate to a URL that redirects to another process and approve the |
| 784 // beforeunload dialog that pops up. | 786 // beforeunload dialog that pops up. |
| 785 content::WindowedNotificationObserver nav_observer( | 787 content::WindowedNotificationObserver nav_observer( |
| 786 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 788 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 787 content::NotificationService::AllSources()); | 789 content::NotificationService::AllSources()); |
| 788 GURL https_url(https_test_server.GetURL("/title1.html")); | 790 GURL https_url(https_test_server.GetURL("/title1.html")); |
| 789 GURL redirect_url( | 791 GURL redirect_url( |
| 790 embedded_test_server()->GetURL("/server-redirect?" + https_url.spec())); | 792 embedded_test_server()->GetURL("/server-redirect?" + https_url.spec())); |
| 791 browser()->OpenURL(OpenURLParams(redirect_url, Referrer(), CURRENT_TAB, | 793 browser()->OpenURL(OpenURLParams(redirect_url, Referrer(), |
| 794 WindowOpenDisposition::CURRENT_TAB, |
| 792 ui::PAGE_TRANSITION_TYPED, false)); | 795 ui::PAGE_TRANSITION_TYPED, false)); |
| 793 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 796 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| 794 EXPECT_TRUE( | 797 EXPECT_TRUE( |
| 795 static_cast<JavaScriptAppModalDialog*>(alert)->is_before_unload_dialog()); | 798 static_cast<JavaScriptAppModalDialog*>(alert)->is_before_unload_dialog()); |
| 796 alert->native_dialog()->AcceptAppModalDialog(); | 799 alert->native_dialog()->AcceptAppModalDialog(); |
| 797 nav_observer.Wait(); | 800 nav_observer.Wait(); |
| 798 | 801 |
| 799 // Restore previous browser client. | 802 // Restore previous browser client. |
| 800 SetBrowserClientForTesting(old_client); | 803 SetBrowserClientForTesting(old_client); |
| 801 } | 804 } |
| 802 | 805 |
| 803 // Test for crbug.com/80401. Canceling a before unload dialog should reset | 806 // Test for crbug.com/80401. Canceling a before unload dialog should reset |
| 804 // the URL to the previous page's URL. | 807 // the URL to the previous page's URL. |
| 805 IN_PROC_BROWSER_TEST_F(BrowserTest, CancelBeforeUnloadResetsURL) { | 808 IN_PROC_BROWSER_TEST_F(BrowserTest, CancelBeforeUnloadResetsURL) { |
| 806 GURL url(ui_test_utils::GetTestUrl(base::FilePath( | 809 GURL url(ui_test_utils::GetTestUrl(base::FilePath( |
| 807 base::FilePath::kCurrentDirectory), base::FilePath(kBeforeUnloadFile))); | 810 base::FilePath::kCurrentDirectory), base::FilePath(kBeforeUnloadFile))); |
| 808 ui_test_utils::NavigateToURL(browser(), url); | 811 ui_test_utils::NavigateToURL(browser(), url); |
| 809 | 812 |
| 810 // Navigate to a page that triggers a cross-site transition. | 813 // Navigate to a page that triggers a cross-site transition. |
| 811 ASSERT_TRUE(embedded_test_server()->Start()); | 814 ASSERT_TRUE(embedded_test_server()->Start()); |
| 812 GURL url2(embedded_test_server()->GetURL("/title1.html")); | 815 GURL url2(embedded_test_server()->GetURL("/title1.html")); |
| 813 browser()->OpenURL(OpenURLParams( | 816 browser()->OpenURL(OpenURLParams(url2, Referrer(), |
| 814 url2, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); | 817 WindowOpenDisposition::CURRENT_TAB, |
| 818 ui::PAGE_TRANSITION_TYPED, false)); |
| 815 | 819 |
| 816 content::WindowedNotificationObserver host_destroyed_observer( | 820 content::WindowedNotificationObserver host_destroyed_observer( |
| 817 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 821 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 818 content::NotificationService::AllSources()); | 822 content::NotificationService::AllSources()); |
| 819 | 823 |
| 820 // Cancel the dialog. | 824 // Cancel the dialog. |
| 821 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 825 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| 822 alert->CloseModalDialog(); | 826 alert->CloseModalDialog(); |
| 823 EXPECT_FALSE( | 827 EXPECT_FALSE( |
| 824 browser()->tab_strip_model()->GetActiveWebContents()->IsLoading()); | 828 browser()->tab_strip_model()->GetActiveWebContents()->IsLoading()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 #define MAYBE_BeforeUnloadVsBeforeReload BeforeUnloadVsBeforeReload | 881 #define MAYBE_BeforeUnloadVsBeforeReload BeforeUnloadVsBeforeReload |
| 878 #endif | 882 #endif |
| 879 | 883 |
| 880 // Test that when a page has an onunload handler, reloading a page shows a | 884 // Test that when a page has an onunload handler, reloading a page shows a |
| 881 // different dialog than navigating to a different page. | 885 // different dialog than navigating to a different page. |
| 882 IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_BeforeUnloadVsBeforeReload) { | 886 IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_BeforeUnloadVsBeforeReload) { |
| 883 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); | 887 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); |
| 884 ui_test_utils::NavigateToURL(browser(), url); | 888 ui_test_utils::NavigateToURL(browser(), url); |
| 885 | 889 |
| 886 // Reload the page, and check that we get a "before reload" dialog. | 890 // Reload the page, and check that we get a "before reload" dialog. |
| 887 chrome::Reload(browser(), CURRENT_TAB); | 891 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 888 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 892 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
| 889 EXPECT_TRUE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); | 893 EXPECT_TRUE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); |
| 890 | 894 |
| 891 // Cancel the reload. | 895 // Cancel the reload. |
| 892 alert->native_dialog()->CancelAppModalDialog(); | 896 alert->native_dialog()->CancelAppModalDialog(); |
| 893 | 897 |
| 894 // Navigate to another url, and check that we get a "before unload" dialog. | 898 // Navigate to another url, and check that we get a "before unload" dialog. |
| 895 GURL url2(url::kAboutBlankURL); | 899 GURL url2(url::kAboutBlankURL); |
| 896 browser()->OpenURL(OpenURLParams( | 900 browser()->OpenURL(OpenURLParams(url2, Referrer(), |
| 897 url2, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); | 901 WindowOpenDisposition::CURRENT_TAB, |
| 902 ui::PAGE_TRANSITION_TYPED, false)); |
| 898 | 903 |
| 899 alert = ui_test_utils::WaitForAppModalDialog(); | 904 alert = ui_test_utils::WaitForAppModalDialog(); |
| 900 EXPECT_FALSE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); | 905 EXPECT_FALSE(static_cast<JavaScriptAppModalDialog*>(alert)->is_reload()); |
| 901 | 906 |
| 902 // Accept the navigation so we end up on a page without a beforeunload hook. | 907 // Accept the navigation so we end up on a page without a beforeunload hook. |
| 903 alert->native_dialog()->AcceptAppModalDialog(); | 908 alert->native_dialog()->AcceptAppModalDialog(); |
| 904 } | 909 } |
| 905 | 910 |
| 906 // BeforeUnloadAtQuitWithTwoWindows is a regression test for | 911 // BeforeUnloadAtQuitWithTwoWindows is a regression test for |
| 907 // http://crbug.com/11842. It opens two windows, one of which has a | 912 // http://crbug.com/11842. It opens two windows, one of which has a |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1419 ASSERT_TRUE(embedded_test_server()->Start()); | 1424 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1420 | 1425 |
| 1421 // Load an app. | 1426 // Load an app. |
| 1422 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 1427 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 1423 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); | 1428 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); |
| 1424 const Extension* extension_app = GetExtension(); | 1429 const Extension* extension_app = GetExtension(); |
| 1425 | 1430 |
| 1426 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would. | 1431 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would. |
| 1427 WebContents* app_window = OpenApplication(AppLaunchParams( | 1432 WebContents* app_window = OpenApplication(AppLaunchParams( |
| 1428 browser()->profile(), extension_app, extensions::LAUNCH_CONTAINER_WINDOW, | 1433 browser()->profile(), extension_app, extensions::LAUNCH_CONTAINER_WINDOW, |
| 1429 NEW_WINDOW, extensions::SOURCE_TEST)); | 1434 WindowOpenDisposition::NEW_WINDOW, extensions::SOURCE_TEST)); |
| 1430 ASSERT_TRUE(app_window); | 1435 ASSERT_TRUE(app_window); |
| 1431 | 1436 |
| 1432 DevToolsWindow* devtools_window = | 1437 DevToolsWindow* devtools_window = |
| 1433 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false); | 1438 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), false); |
| 1434 | 1439 |
| 1435 // The launch should have created a new app browser and a dev tools browser. | 1440 // The launch should have created a new app browser and a dev tools browser. |
| 1436 ASSERT_EQ(3u, chrome::GetBrowserCount(browser()->profile())); | 1441 ASSERT_EQ(3u, chrome::GetBrowserCount(browser()->profile())); |
| 1437 | 1442 |
| 1438 // Find the new browsers. | 1443 // Find the new browsers. |
| 1439 Browser* app_browser = NULL; | 1444 Browser* app_browser = NULL; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1539 ASSERT_TRUE(embedded_test_server()->Start()); | 1544 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1540 | 1545 |
| 1541 // Load an app | 1546 // Load an app |
| 1542 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 1547 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
| 1543 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); | 1548 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app/"))); |
| 1544 const Extension* extension_app = GetExtension(); | 1549 const Extension* extension_app = GetExtension(); |
| 1545 | 1550 |
| 1546 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would. | 1551 // Launch it in a window, as AppLauncherHandler::HandleLaunchApp() would. |
| 1547 WebContents* app_window = OpenApplication(AppLaunchParams( | 1552 WebContents* app_window = OpenApplication(AppLaunchParams( |
| 1548 browser()->profile(), extension_app, extensions::LAUNCH_CONTAINER_WINDOW, | 1553 browser()->profile(), extension_app, extensions::LAUNCH_CONTAINER_WINDOW, |
| 1549 NEW_WINDOW, extensions::SOURCE_TEST)); | 1554 WindowOpenDisposition::NEW_WINDOW, extensions::SOURCE_TEST)); |
| 1550 ASSERT_TRUE(app_window); | 1555 ASSERT_TRUE(app_window); |
| 1551 | 1556 |
| 1552 // Apps launched in a window from the NTP have an extensions tab helper but | 1557 // Apps launched in a window from the NTP have an extensions tab helper but |
| 1553 // do not have extension_app set in it. | 1558 // do not have extension_app set in it. |
| 1554 ASSERT_TRUE(extensions::TabHelper::FromWebContents(app_window)); | 1559 ASSERT_TRUE(extensions::TabHelper::FromWebContents(app_window)); |
| 1555 EXPECT_FALSE( | 1560 EXPECT_FALSE( |
| 1556 extensions::TabHelper::FromWebContents(app_window)->extension_app()); | 1561 extensions::TabHelper::FromWebContents(app_window)->extension_app()); |
| 1557 EXPECT_EQ(extensions::AppLaunchInfo::GetFullLaunchURL(extension_app), | 1562 EXPECT_EQ(extensions::AppLaunchInfo::GetFullLaunchURL(extension_app), |
| 1558 app_window->GetURL()); | 1563 app_window->GetURL()); |
| 1559 | 1564 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1615 ui_test_utils::NavigateToURL( | 1620 ui_test_utils::NavigateToURL( |
| 1616 browser(), ui_test_utils::GetTestUrl( | 1621 browser(), ui_test_utils::GetTestUrl( |
| 1617 base::FilePath(base::FilePath::kCurrentDirectory), | 1622 base::FilePath(base::FilePath::kCurrentDirectory), |
| 1618 base::FilePath(kTitle1File))); | 1623 base::FilePath(kTitle1File))); |
| 1619 | 1624 |
| 1620 content::WindowedNotificationObserver back_nav_load_observer( | 1625 content::WindowedNotificationObserver back_nav_load_observer( |
| 1621 content::NOTIFICATION_LOAD_STOP, | 1626 content::NOTIFICATION_LOAD_STOP, |
| 1622 content::Source<NavigationController>( | 1627 content::Source<NavigationController>( |
| 1623 &browser()->tab_strip_model()->GetActiveWebContents()-> | 1628 &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 1624 GetController())); | 1629 GetController())); |
| 1625 chrome::GoBack(browser(), CURRENT_TAB); | 1630 chrome::GoBack(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 1626 back_nav_load_observer.Wait(); | 1631 back_nav_load_observer.Wait(); |
| 1627 CommandUpdater* command_updater = | 1632 CommandUpdater* command_updater = |
| 1628 browser()->command_controller()->command_updater(); | 1633 browser()->command_controller()->command_updater(); |
| 1629 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_FORWARD)); | 1634 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_FORWARD)); |
| 1630 | 1635 |
| 1631 content::WindowedNotificationObserver forward_nav_load_observer( | 1636 content::WindowedNotificationObserver forward_nav_load_observer( |
| 1632 content::NOTIFICATION_LOAD_STOP, | 1637 content::NOTIFICATION_LOAD_STOP, |
| 1633 content::Source<NavigationController>( | 1638 content::Source<NavigationController>( |
| 1634 &browser()->tab_strip_model()->GetActiveWebContents()-> | 1639 &browser()->tab_strip_model()->GetActiveWebContents()-> |
| 1635 GetController())); | 1640 GetController())); |
| 1636 chrome::GoForward(browser(), CURRENT_TAB); | 1641 chrome::GoForward(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 1637 // This check will happen before the navigation completes, since the browser | 1642 // This check will happen before the navigation completes, since the browser |
| 1638 // won't process the renderer's response until the Wait() call below. | 1643 // won't process the renderer's response until the Wait() call below. |
| 1639 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_FORWARD)); | 1644 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_FORWARD)); |
| 1640 forward_nav_load_observer.Wait(); | 1645 forward_nav_load_observer.Wait(); |
| 1641 } | 1646 } |
| 1642 | 1647 |
| 1643 // Makes sure certain commands are disabled when Incognito mode is forced. | 1648 // Makes sure certain commands are disabled when Incognito mode is forced. |
| 1644 IN_PROC_BROWSER_TEST_F(BrowserTest, DisableMenuItemsWhenIncognitoIsForced) { | 1649 IN_PROC_BROWSER_TEST_F(BrowserTest, DisableMenuItemsWhenIncognitoIsForced) { |
| 1645 CommandUpdater* command_updater = | 1650 CommandUpdater* command_updater = |
| 1646 browser()->command_controller()->command_updater(); | 1651 browser()->command_controller()->command_updater(); |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 browser()->tab_strip_model()->GetActiveWebContents(); | 1984 browser()->tab_strip_model()->GetActiveWebContents(); |
| 1980 MockWebContentsObserver mock_observer(web_contents); | 1985 MockWebContentsObserver mock_observer(web_contents); |
| 1981 | 1986 |
| 1982 ASSERT_TRUE(embedded_test_server()->Start()); | 1987 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1983 GURL url(embedded_test_server()->GetURL("/empty.html")); | 1988 GURL url(embedded_test_server()->GetURL("/empty.html")); |
| 1984 | 1989 |
| 1985 ui_test_utils::NavigateToURL(browser(), url); | 1990 ui_test_utils::NavigateToURL(browser(), url); |
| 1986 EXPECT_TRUE(mock_observer.got_user_gesture()); | 1991 EXPECT_TRUE(mock_observer.got_user_gesture()); |
| 1987 | 1992 |
| 1988 mock_observer.set_got_user_gesture(false); | 1993 mock_observer.set_got_user_gesture(false); |
| 1989 chrome::Reload(browser(), CURRENT_TAB); | 1994 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 1990 EXPECT_TRUE(mock_observer.got_user_gesture()); | 1995 EXPECT_TRUE(mock_observer.got_user_gesture()); |
| 1991 } | 1996 } |
| 1992 | 1997 |
| 1993 // TODO(ben): this test was never enabled. It has bit-rotted since being added. | 1998 // TODO(ben): this test was never enabled. It has bit-rotted since being added. |
| 1994 // It originally lived in browser_unittest.cc, but has been moved here to make | 1999 // It originally lived in browser_unittest.cc, but has been moved here to make |
| 1995 // room for real browser unit tests. | 2000 // room for real browser unit tests. |
| 1996 #if 0 | 2001 #if 0 |
| 1997 class BrowserTest2 : public InProcessBrowserTest { | 2002 class BrowserTest2 : public InProcessBrowserTest { |
| 1998 public: | 2003 public: |
| 1999 BrowserTest2() { | 2004 BrowserTest2() { |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2364 int modifiers, | 2369 int modifiers, |
| 2365 blink::WebMouseEvent::Button button, | 2370 blink::WebMouseEvent::Button button, |
| 2366 WindowOpenDisposition disposition) { | 2371 WindowOpenDisposition disposition) { |
| 2367 ui_test_utils::NavigateToURL(browser, url); | 2372 ui_test_utils::NavigateToURL(browser, url); |
| 2368 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); | 2373 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); |
| 2369 EXPECT_EQ(1, browser->tab_strip_model()->count()); | 2374 EXPECT_EQ(1, browser->tab_strip_model()->count()); |
| 2370 content::WebContents* web_contents = | 2375 content::WebContents* web_contents = |
| 2371 browser->tab_strip_model()->GetActiveWebContents(); | 2376 browser->tab_strip_model()->GetActiveWebContents(); |
| 2372 EXPECT_EQ(url, web_contents->GetURL()); | 2377 EXPECT_EQ(url, web_contents->GetURL()); |
| 2373 | 2378 |
| 2374 if (disposition == CURRENT_TAB) { | 2379 if (disposition == WindowOpenDisposition::CURRENT_TAB) { |
| 2375 content::WebContents* web_contents = | 2380 content::WebContents* web_contents = |
| 2376 browser->tab_strip_model()->GetActiveWebContents(); | 2381 browser->tab_strip_model()->GetActiveWebContents(); |
| 2377 content::TestNavigationObserver same_tab_observer(web_contents); | 2382 content::TestNavigationObserver same_tab_observer(web_contents); |
| 2378 SimulateMouseClick(web_contents, modifiers, button); | 2383 SimulateMouseClick(web_contents, modifiers, button); |
| 2379 same_tab_observer.Wait(); | 2384 same_tab_observer.Wait(); |
| 2380 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); | 2385 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); |
| 2381 EXPECT_EQ(1, browser->tab_strip_model()->count()); | 2386 EXPECT_EQ(1, browser->tab_strip_model()->count()); |
| 2382 EXPECT_EQ(getSecondPageTitle(), web_contents->GetTitle()); | 2387 EXPECT_EQ(getSecondPageTitle(), web_contents->GetTitle()); |
| 2383 return; | 2388 return; |
| 2384 } | 2389 } |
| 2385 | 2390 |
| 2386 content::WindowedNotificationObserver observer( | 2391 content::WindowedNotificationObserver observer( |
| 2387 chrome::NOTIFICATION_TAB_ADDED, | 2392 chrome::NOTIFICATION_TAB_ADDED, |
| 2388 content::NotificationService::AllSources()); | 2393 content::NotificationService::AllSources()); |
| 2389 SimulateMouseClick(web_contents, modifiers, button); | 2394 SimulateMouseClick(web_contents, modifiers, button); |
| 2390 observer.Wait(); | 2395 observer.Wait(); |
| 2391 | 2396 |
| 2392 if (disposition == NEW_WINDOW) { | 2397 if (disposition == WindowOpenDisposition::NEW_WINDOW) { |
| 2393 EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile())); | 2398 EXPECT_EQ(2u, chrome::GetBrowserCount(browser->profile())); |
| 2394 return; | 2399 return; |
| 2395 } | 2400 } |
| 2396 | 2401 |
| 2397 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); | 2402 EXPECT_EQ(1u, chrome::GetBrowserCount(browser->profile())); |
| 2398 EXPECT_EQ(2, browser->tab_strip_model()->count()); | 2403 EXPECT_EQ(2, browser->tab_strip_model()->count()); |
| 2399 web_contents = browser->tab_strip_model()->GetActiveWebContents(); | 2404 web_contents = browser->tab_strip_model()->GetActiveWebContents(); |
| 2400 WaitForLoadStop(web_contents); | 2405 WaitForLoadStop(web_contents); |
| 2401 if (disposition == NEW_FOREGROUND_TAB) { | 2406 if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) { |
| 2402 EXPECT_EQ(getSecondPageTitle(), web_contents->GetTitle()); | 2407 EXPECT_EQ(getSecondPageTitle(), web_contents->GetTitle()); |
| 2403 } else { | 2408 } else { |
| 2404 ASSERT_EQ(NEW_BACKGROUND_TAB, disposition); | 2409 ASSERT_EQ(WindowOpenDisposition::NEW_BACKGROUND_TAB, disposition); |
| 2405 EXPECT_EQ(getFirstPageTitle(), web_contents->GetTitle()); | 2410 EXPECT_EQ(getFirstPageTitle(), web_contents->GetTitle()); |
| 2406 } | 2411 } |
| 2407 } | 2412 } |
| 2408 | 2413 |
| 2409 private: | 2414 private: |
| 2410 DISALLOW_COPY_AND_ASSIGN(ClickModifierTest); | 2415 DISALLOW_COPY_AND_ASSIGN(ClickModifierTest); |
| 2411 }; | 2416 }; |
| 2412 | 2417 |
| 2413 // Tests for clicking on elements with handlers that run window.open. | 2418 // Tests for clicking on elements with handlers that run window.open. |
| 2414 | 2419 |
| 2415 IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenBasicClickTest) { | 2420 IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenBasicClickTest) { |
| 2416 int modifiers = 0; | 2421 int modifiers = 0; |
| 2417 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; | 2422 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; |
| 2418 WindowOpenDisposition disposition = NEW_FOREGROUND_TAB; | 2423 WindowOpenDisposition disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
| 2419 RunTest(browser(), GetWindowOpenURL(), modifiers, button, disposition); | 2424 RunTest(browser(), GetWindowOpenURL(), modifiers, button, disposition); |
| 2420 } | 2425 } |
| 2421 | 2426 |
| 2422 // TODO(ericu): Alt-click behavior on window.open is platform-dependent and not | 2427 // TODO(ericu): Alt-click behavior on window.open is platform-dependent and not |
| 2423 // well defined. Should we add tests so we know if it changes? | 2428 // well defined. Should we add tests so we know if it changes? |
| 2424 | 2429 |
| 2425 // Shift-clicks open in a new window. | 2430 // Shift-clicks open in a new window. |
| 2426 IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenShiftClickTest) { | 2431 IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenShiftClickTest) { |
| 2427 int modifiers = blink::WebInputEvent::ShiftKey; | 2432 int modifiers = blink::WebInputEvent::ShiftKey; |
| 2428 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; | 2433 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; |
| 2429 WindowOpenDisposition disposition = NEW_WINDOW; | 2434 WindowOpenDisposition disposition = WindowOpenDisposition::NEW_WINDOW; |
| 2430 RunTest(browser(), GetWindowOpenURL(), modifiers, button, disposition); | 2435 RunTest(browser(), GetWindowOpenURL(), modifiers, button, disposition); |
| 2431 } | 2436 } |
| 2432 | 2437 |
| 2433 // Control-clicks open in a background tab. | 2438 // Control-clicks open in a background tab. |
| 2434 // On OSX meta [the command key] takes the place of control. | 2439 // On OSX meta [the command key] takes the place of control. |
| 2435 IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenControlClickTest) { | 2440 IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenControlClickTest) { |
| 2436 #if defined(OS_MACOSX) | 2441 #if defined(OS_MACOSX) |
| 2437 int modifiers = blink::WebInputEvent::MetaKey; | 2442 int modifiers = blink::WebInputEvent::MetaKey; |
| 2438 #else | 2443 #else |
| 2439 int modifiers = blink::WebInputEvent::ControlKey; | 2444 int modifiers = blink::WebInputEvent::ControlKey; |
| 2440 #endif | 2445 #endif |
| 2441 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; | 2446 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; |
| 2442 WindowOpenDisposition disposition = NEW_BACKGROUND_TAB; | 2447 WindowOpenDisposition disposition = WindowOpenDisposition::NEW_BACKGROUND_TAB; |
| 2443 RunTest(browser(), GetWindowOpenURL(), modifiers, button, disposition); | 2448 RunTest(browser(), GetWindowOpenURL(), modifiers, button, disposition); |
| 2444 } | 2449 } |
| 2445 | 2450 |
| 2446 // Control-shift-clicks open in a foreground tab. | 2451 // Control-shift-clicks open in a foreground tab. |
| 2447 // On OSX meta [the command key] takes the place of control. | 2452 // On OSX meta [the command key] takes the place of control. |
| 2448 IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenControlShiftClickTest) { | 2453 IN_PROC_BROWSER_TEST_F(ClickModifierTest, WindowOpenControlShiftClickTest) { |
| 2449 #if defined(OS_MACOSX) | 2454 #if defined(OS_MACOSX) |
| 2450 int modifiers = blink::WebInputEvent::MetaKey; | 2455 int modifiers = blink::WebInputEvent::MetaKey; |
| 2451 #else | 2456 #else |
| 2452 int modifiers = blink::WebInputEvent::ControlKey; | 2457 int modifiers = blink::WebInputEvent::ControlKey; |
| 2453 #endif | 2458 #endif |
| 2454 modifiers |= blink::WebInputEvent::ShiftKey; | 2459 modifiers |= blink::WebInputEvent::ShiftKey; |
| 2455 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; | 2460 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; |
| 2456 WindowOpenDisposition disposition = NEW_FOREGROUND_TAB; | 2461 WindowOpenDisposition disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
| 2457 RunTest(browser(), GetWindowOpenURL(), modifiers, button, disposition); | 2462 RunTest(browser(), GetWindowOpenURL(), modifiers, button, disposition); |
| 2458 } | 2463 } |
| 2459 | 2464 |
| 2460 // Tests for clicking on normal links. | 2465 // Tests for clicking on normal links. |
| 2461 | 2466 |
| 2462 IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefBasicClickTest) { | 2467 IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefBasicClickTest) { |
| 2463 int modifiers = 0; | 2468 int modifiers = 0; |
| 2464 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; | 2469 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; |
| 2465 WindowOpenDisposition disposition = CURRENT_TAB; | 2470 WindowOpenDisposition disposition = WindowOpenDisposition::CURRENT_TAB; |
| 2466 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); | 2471 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); |
| 2467 } | 2472 } |
| 2468 | 2473 |
| 2469 // TODO(ericu): Alt-click behavior on links is platform-dependent and not well | 2474 // TODO(ericu): Alt-click behavior on links is platform-dependent and not well |
| 2470 // defined. Should we add tests so we know if it changes? | 2475 // defined. Should we add tests so we know if it changes? |
| 2471 | 2476 |
| 2472 // Shift-clicks open in a new window. | 2477 // Shift-clicks open in a new window. |
| 2473 IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefShiftClickTest) { | 2478 IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefShiftClickTest) { |
| 2474 int modifiers = blink::WebInputEvent::ShiftKey; | 2479 int modifiers = blink::WebInputEvent::ShiftKey; |
| 2475 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; | 2480 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; |
| 2476 WindowOpenDisposition disposition = NEW_WINDOW; | 2481 WindowOpenDisposition disposition = WindowOpenDisposition::NEW_WINDOW; |
| 2477 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); | 2482 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); |
| 2478 } | 2483 } |
| 2479 | 2484 |
| 2480 // Control-clicks open in a background tab. | 2485 // Control-clicks open in a background tab. |
| 2481 // On OSX meta [the command key] takes the place of control. | 2486 // On OSX meta [the command key] takes the place of control. |
| 2482 IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefControlClickTest) { | 2487 IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefControlClickTest) { |
| 2483 #if defined(OS_MACOSX) | 2488 #if defined(OS_MACOSX) |
| 2484 int modifiers = blink::WebInputEvent::MetaKey; | 2489 int modifiers = blink::WebInputEvent::MetaKey; |
| 2485 #else | 2490 #else |
| 2486 int modifiers = blink::WebInputEvent::ControlKey; | 2491 int modifiers = blink::WebInputEvent::ControlKey; |
| 2487 #endif | 2492 #endif |
| 2488 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; | 2493 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; |
| 2489 WindowOpenDisposition disposition = NEW_BACKGROUND_TAB; | 2494 WindowOpenDisposition disposition = WindowOpenDisposition::NEW_BACKGROUND_TAB; |
| 2490 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); | 2495 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); |
| 2491 } | 2496 } |
| 2492 | 2497 |
| 2493 // Control-shift-clicks open in a foreground tab. | 2498 // Control-shift-clicks open in a foreground tab. |
| 2494 // On OSX meta [the command key] takes the place of control. | 2499 // On OSX meta [the command key] takes the place of control. |
| 2495 // http://crbug.com/396347 | 2500 // http://crbug.com/396347 |
| 2496 IN_PROC_BROWSER_TEST_F(ClickModifierTest, DISABLED_HrefControlShiftClickTest) { | 2501 IN_PROC_BROWSER_TEST_F(ClickModifierTest, DISABLED_HrefControlShiftClickTest) { |
| 2497 #if defined(OS_MACOSX) | 2502 #if defined(OS_MACOSX) |
| 2498 int modifiers = blink::WebInputEvent::MetaKey; | 2503 int modifiers = blink::WebInputEvent::MetaKey; |
| 2499 #else | 2504 #else |
| 2500 int modifiers = blink::WebInputEvent::ControlKey; | 2505 int modifiers = blink::WebInputEvent::ControlKey; |
| 2501 #endif | 2506 #endif |
| 2502 modifiers |= blink::WebInputEvent::ShiftKey; | 2507 modifiers |= blink::WebInputEvent::ShiftKey; |
| 2503 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; | 2508 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Left; |
| 2504 WindowOpenDisposition disposition = NEW_FOREGROUND_TAB; | 2509 WindowOpenDisposition disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
| 2505 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); | 2510 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); |
| 2506 } | 2511 } |
| 2507 | 2512 |
| 2508 // Middle-clicks open in a background tab. | 2513 // Middle-clicks open in a background tab. |
| 2509 IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefMiddleClickTest) { | 2514 IN_PROC_BROWSER_TEST_F(ClickModifierTest, HrefMiddleClickTest) { |
| 2510 int modifiers = 0; | 2515 int modifiers = 0; |
| 2511 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Middle; | 2516 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Middle; |
| 2512 WindowOpenDisposition disposition = NEW_BACKGROUND_TAB; | 2517 WindowOpenDisposition disposition = WindowOpenDisposition::NEW_BACKGROUND_TAB; |
| 2513 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); | 2518 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); |
| 2514 } | 2519 } |
| 2515 | 2520 |
| 2516 // Shift-middle-clicks open in a foreground tab. | 2521 // Shift-middle-clicks open in a foreground tab. |
| 2517 // http://crbug.com/396347 | 2522 // http://crbug.com/396347 |
| 2518 IN_PROC_BROWSER_TEST_F(ClickModifierTest, DISABLED_HrefShiftMiddleClickTest) { | 2523 IN_PROC_BROWSER_TEST_F(ClickModifierTest, DISABLED_HrefShiftMiddleClickTest) { |
| 2519 int modifiers = blink::WebInputEvent::ShiftKey; | 2524 int modifiers = blink::WebInputEvent::ShiftKey; |
| 2520 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Middle; | 2525 blink::WebMouseEvent::Button button = blink::WebMouseEvent::Button::Middle; |
| 2521 WindowOpenDisposition disposition = NEW_FOREGROUND_TAB; | 2526 WindowOpenDisposition disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB; |
| 2522 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); | 2527 RunTest(browser(), GetHrefURL(), modifiers, button, disposition); |
| 2523 } | 2528 } |
| 2524 | 2529 |
| 2525 IN_PROC_BROWSER_TEST_F(BrowserTest, GetSizeForNewRenderView) { | 2530 IN_PROC_BROWSER_TEST_F(BrowserTest, GetSizeForNewRenderView) { |
| 2526 // The instant extended NTP has javascript that does not work with | 2531 // The instant extended NTP has javascript that does not work with |
| 2527 // ui_test_utils::NavigateToURL. The NTP rvh reloads when the browser tries | 2532 // ui_test_utils::NavigateToURL. The NTP rvh reloads when the browser tries |
| 2528 // to navigate away from the page, which causes the WebContents to end up in | 2533 // to navigate away from the page, which causes the WebContents to end up in |
| 2529 // an inconsistent state. (is_loaded = true, last_commited_url=ntp, | 2534 // an inconsistent state. (is_loaded = true, last_commited_url=ntp, |
| 2530 // visible_url=title1.html) | 2535 // visible_url=title1.html) |
| 2531 browser()->profile()->GetPrefs()->SetBoolean(prefs::kWebKitJavascriptEnabled, | 2536 browser()->profile()->GetPrefs()->SetBoolean(prefs::kWebKitJavascriptEnabled, |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2842 Browser* browser = new Browser(params); | 2847 Browser* browser = new Browser(params); |
| 2843 gfx::Rect bounds = browser->window()->GetBounds(); | 2848 gfx::Rect bounds = browser->window()->GetBounds(); |
| 2844 | 2849 |
| 2845 // Should be EXPECT_EQ, but this width is inconsistent across platforms. | 2850 // Should be EXPECT_EQ, but this width is inconsistent across platforms. |
| 2846 // See https://crbug.com/567925. | 2851 // See https://crbug.com/567925. |
| 2847 EXPECT_GE(bounds.width(), 100); | 2852 EXPECT_GE(bounds.width(), 100); |
| 2848 EXPECT_EQ(122, bounds.height()); | 2853 EXPECT_EQ(122, bounds.height()); |
| 2849 browser->window()->Close(); | 2854 browser->window()->Close(); |
| 2850 } | 2855 } |
| 2851 } | 2856 } |
| OLD | NEW |