Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: chrome/browser/ui/browser_browsertest.cc

Issue 2784533002: Turn on auto-dismissing dialogs for trunk builds. (Closed)
Patch Set: chromeos Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "chrome/browser/ui/browser_commands.h" 49 #include "chrome/browser/ui/browser_commands.h"
50 #include "chrome/browser/ui/browser_finder.h" 50 #include "chrome/browser/ui/browser_finder.h"
51 #include "chrome/browser/ui/browser_list.h" 51 #include "chrome/browser/ui/browser_list.h"
52 #include "chrome/browser/ui/browser_tabstrip.h" 52 #include "chrome/browser/ui/browser_tabstrip.h"
53 #include "chrome/browser/ui/browser_ui_prefs.h" 53 #include "chrome/browser/ui/browser_ui_prefs.h"
54 #include "chrome/browser/ui/browser_window.h" 54 #include "chrome/browser/ui/browser_window.h"
55 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" 55 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
56 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" 56 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
57 #include "chrome/browser/ui/extensions/app_launch_params.h" 57 #include "chrome/browser/ui/extensions/app_launch_params.h"
58 #include "chrome/browser/ui/extensions/application_launch.h" 58 #include "chrome/browser/ui/extensions/application_launch.h"
59 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h"
59 #include "chrome/browser/ui/search/search_tab_helper.h" 60 #include "chrome/browser/ui/search/search_tab_helper.h"
60 #include "chrome/browser/ui/startup/startup_browser_creator.h" 61 #include "chrome/browser/ui/startup/startup_browser_creator.h"
61 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" 62 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
62 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" 63 #include "chrome/browser/ui/tabs/pinned_tab_codec.h"
63 #include "chrome/browser/ui/tabs/tab_strip_model.h" 64 #include "chrome/browser/ui/tabs/tab_strip_model.h"
64 #include "chrome/common/chrome_paths.h" 65 #include "chrome/common/chrome_paths.h"
65 #include "chrome/common/chrome_switches.h" 66 #include "chrome/common/chrome_switches.h"
66 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 67 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
67 #include "chrome/common/pref_names.h" 68 #include "chrome/common/pref_names.h"
68 #include "chrome/common/url_constants.h" 69 #include "chrome/common/url_constants.h"
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 481
481 IN_PROC_BROWSER_TEST_F(BrowserTest, JavascriptAlertActivatesTab) { 482 IN_PROC_BROWSER_TEST_F(BrowserTest, JavascriptAlertActivatesTab) {
482 GURL url(ui_test_utils::GetTestUrl(base::FilePath( 483 GURL url(ui_test_utils::GetTestUrl(base::FilePath(
483 base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File))); 484 base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File)));
484 ui_test_utils::NavigateToURL(browser(), url); 485 ui_test_utils::NavigateToURL(browser(), url);
485 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); 486 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED);
486 EXPECT_EQ(2, browser()->tab_strip_model()->count()); 487 EXPECT_EQ(2, browser()->tab_strip_model()->count());
487 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); 488 EXPECT_EQ(0, browser()->tab_strip_model()->active_index());
488 WebContents* second_tab = browser()->tab_strip_model()->GetWebContentsAt(1); 489 WebContents* second_tab = browser()->tab_strip_model()->GetWebContentsAt(1);
489 ASSERT_TRUE(second_tab); 490 ASSERT_TRUE(second_tab);
491 JavaScriptDialogTabHelper* js_helper =
492 JavaScriptDialogTabHelper::FromWebContents(second_tab);
493 base::RunLoop dialog_wait;
494 js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
490 second_tab->GetMainFrame()->ExecuteJavaScriptForTests( 495 second_tab->GetMainFrame()->ExecuteJavaScriptForTests(
491 ASCIIToUTF16("alert('Activate!');")); 496 ASCIIToUTF16("alert('Activate!');"));
492 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 497 dialog_wait.Run();
493 alert->CloseModalDialog(); 498 js_helper->HandleJavaScriptDialog(second_tab, true, nullptr);
494 EXPECT_EQ(2, browser()->tab_strip_model()->count()); 499 EXPECT_EQ(2, browser()->tab_strip_model()->count());
495 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); 500 EXPECT_EQ(1, browser()->tab_strip_model()->active_index());
496 } 501 }
497 502
498 503
499 #if defined(OS_WIN) && !defined(NDEBUG) 504 #if defined(OS_WIN) && !defined(NDEBUG)
500 // http://crbug.com/114859. Times out frequently on Windows. 505 // http://crbug.com/114859. Times out frequently on Windows.
501 #define MAYBE_ThirtyFourTabs DISABLED_ThirtyFourTabs 506 #define MAYBE_ThirtyFourTabs DISABLED_ThirtyFourTabs
502 #else 507 #else
503 #define MAYBE_ThirtyFourTabs ThirtyFourTabs 508 #define MAYBE_ThirtyFourTabs ThirtyFourTabs
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 IN_PROC_BROWSER_TEST_F(BrowserTest, DISABLED_CrossProcessNavCancelsDialogs) { 594 IN_PROC_BROWSER_TEST_F(BrowserTest, DISABLED_CrossProcessNavCancelsDialogs) {
590 ASSERT_TRUE(embedded_test_server()->Start()); 595 ASSERT_TRUE(embedded_test_server()->Start());
591 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 596 host_resolver()->AddRule("www.example.com", "127.0.0.1");
592 GURL url(embedded_test_server()->GetURL("/empty.html")); 597 GURL url(embedded_test_server()->GetURL("/empty.html"));
593 ui_test_utils::NavigateToURL(browser(), url); 598 ui_test_utils::NavigateToURL(browser(), url);
594 599
595 // Test this with multiple alert dialogs to ensure that we can navigate away 600 // Test this with multiple alert dialogs to ensure that we can navigate away
596 // even if the renderer tries to synchronously create more. 601 // even if the renderer tries to synchronously create more.
597 // See http://crbug.com/312490. 602 // See http://crbug.com/312490.
598 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); 603 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
604 JavaScriptDialogTabHelper* js_helper =
605 JavaScriptDialogTabHelper::FromWebContents(contents);
606 base::RunLoop dialog_wait;
607 js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
599 contents->GetMainFrame()->ExecuteJavaScriptForTests( 608 contents->GetMainFrame()->ExecuteJavaScriptForTests(
600 ASCIIToUTF16("alert('one'); alert('two');")); 609 ASCIIToUTF16("alert('one'); alert('two');"));
601 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 610 dialog_wait.Run();
602 EXPECT_TRUE(alert->IsValid()); 611 EXPECT_TRUE(js_helper->IsShowingDialogForTesting());
603 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance();
604 EXPECT_TRUE(dialog_queue->HasActiveDialog());
605 612
606 // A cross-site navigation should force the dialog to close. 613 // A cross-site navigation should force the dialog to close.
607 GURL url2("http://www.example.com/empty.html"); 614 GURL url2("http://www.example.com/empty.html");
608 ui_test_utils::NavigateToURL(browser(), url2); 615 ui_test_utils::NavigateToURL(browser(), url2);
609 EXPECT_FALSE(dialog_queue->HasActiveDialog()); 616 EXPECT_FALSE(js_helper->IsShowingDialogForTesting());
610 617
611 // Make sure input events still work in the renderer process. 618 // Make sure input events still work in the renderer process.
612 EXPECT_FALSE(contents->GetRenderProcessHost()->IgnoreInputEvents()); 619 EXPECT_FALSE(contents->GetRenderProcessHost()->IgnoreInputEvents());
613 } 620 }
614 621
615 // Make sure that dialogs are closed after a renderer process dies, and that 622 // Make sure that dialogs are closed after a renderer process dies, and that
616 // subsequent navigations work. See http://crbug/com/343265. 623 // subsequent navigations work. See http://crbug/com/343265.
617 IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsDialogs) { 624 IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsDialogs) {
618 ASSERT_TRUE(embedded_test_server()->Start()); 625 ASSERT_TRUE(embedded_test_server()->Start());
619 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 626 host_resolver()->AddRule("www.example.com", "127.0.0.1");
(...skipping 27 matching lines...) Expand all
647 } 654 }
648 655
649 // Make sure that dialogs opened by subframes are closed when the process dies. 656 // Make sure that dialogs opened by subframes are closed when the process dies.
650 // See http://crbug.com/366510. 657 // See http://crbug.com/366510.
651 IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsSubframeDialogs) { 658 IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsSubframeDialogs) {
652 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); 659 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
653 ui_test_utils::NavigateToURL( 660 ui_test_utils::NavigateToURL(
654 browser(), GURL("data:text/html, <html><body></body></html>")); 661 browser(), GURL("data:text/html, <html><body></body></html>"));
655 662
656 // Create an iframe that opens an alert dialog. 663 // Create an iframe that opens an alert dialog.
664 JavaScriptDialogTabHelper* js_helper =
665 JavaScriptDialogTabHelper::FromWebContents(contents);
666 base::RunLoop dialog_wait;
667 js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
657 contents->GetMainFrame()->ExecuteJavaScriptForTests( 668 contents->GetMainFrame()->ExecuteJavaScriptForTests(
658 ASCIIToUTF16("f = document.createElement('iframe');" 669 ASCIIToUTF16("f = document.createElement('iframe');"
659 "f.srcdoc = '<script>alert(1)</script>';" 670 "f.srcdoc = '<script>alert(1)</script>';"
660 "document.body.appendChild(f);")); 671 "document.body.appendChild(f);"));
661 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 672 dialog_wait.Run();
662 EXPECT_TRUE(alert->IsValid()); 673 EXPECT_TRUE(js_helper->IsShowingDialogForTesting());
663 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance();
664 EXPECT_TRUE(dialog_queue->HasActiveDialog());
665 674
666 // Crash the renderer process and ensure the dialog is gone. 675 // Crash the renderer process and ensure the dialog is gone.
667 content::RenderProcessHost* child_process = contents->GetRenderProcessHost(); 676 content::RenderProcessHost* child_process = contents->GetRenderProcessHost();
668 content::RenderProcessHostWatcher crash_observer( 677 content::RenderProcessHostWatcher crash_observer(
669 child_process, 678 child_process,
670 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); 679 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT);
671 child_process->Shutdown(0, false); 680 child_process->Shutdown(0, false);
672 crash_observer.Wait(); 681 crash_observer.Wait();
673 EXPECT_FALSE(dialog_queue->HasActiveDialog()); 682 EXPECT_FALSE(js_helper->IsShowingDialogForTesting());
674 683
675 // Make sure subsequent navigations work. 684 // Make sure subsequent navigations work.
676 GURL url2("data:text/html,foo"); 685 GURL url2("data:text/html,foo");
677 ui_test_utils::NavigateToURL(browser(), url2); 686 ui_test_utils::NavigateToURL(browser(), url2);
678 } 687 }
679 688
680 // Make sure modal dialogs within a guestview are closed when an interstitial 689 // Make sure modal dialogs within a guestview are closed when an interstitial
681 // page is showing. See crbug.com/482380. 690 // page is showing. See crbug.com/482380.
682 IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialCancelsGuestViewDialogs) { 691 IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialCancelsGuestViewDialogs) {
692 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
693 JavaScriptDialogTabHelper* js_helper =
694 JavaScriptDialogTabHelper::FromWebContents(contents);
695 base::RunLoop dialog_wait;
696 js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
697
683 // Navigate to a PDF, which is loaded within a guestview. 698 // Navigate to a PDF, which is loaded within a guestview.
684 ASSERT_TRUE(embedded_test_server()->Start()); 699 ASSERT_TRUE(embedded_test_server()->Start());
685 GURL pdf_with_dialog(embedded_test_server()->GetURL("/alert_dialog.pdf")); 700 GURL pdf_with_dialog(embedded_test_server()->GetURL("/alert_dialog.pdf"));
686 ui_test_utils::NavigateToURL(browser(), pdf_with_dialog); 701 ui_test_utils::NavigateToURL(browser(), pdf_with_dialog);
687 702
688 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 703 dialog_wait.Run();
689 EXPECT_TRUE(alert->IsValid()); 704 EXPECT_TRUE(js_helper->IsShowingDialogForTesting());
690 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance();
691 EXPECT_TRUE(dialog_queue->HasActiveDialog());
692
693 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
694 705
695 TestInterstitialPage* interstitial = 706 TestInterstitialPage* interstitial =
696 new TestInterstitialPage(contents, false, GURL()); 707 new TestInterstitialPage(contents, false, GURL());
697 content::WaitForInterstitialAttach(contents); 708 content::WaitForInterstitialAttach(contents);
698 709
699 // The interstitial should have closed the dialog. 710 // The interstitial should have closed the dialog.
700 EXPECT_TRUE(contents->ShowingInterstitialPage()); 711 EXPECT_TRUE(contents->ShowingInterstitialPage());
701 EXPECT_FALSE(dialog_queue->HasActiveDialog()); 712 EXPECT_FALSE(js_helper->IsShowingDialogForTesting());
702 713
703 interstitial->DontProceed(); 714 interstitial->DontProceed();
704 } 715 }
705 716
706 // Test for crbug.com/22004. Reloading a page with a before unload handler and 717 // Test for crbug.com/22004. Reloading a page with a before unload handler and
707 // then canceling the dialog should not leave the throbber spinning. 718 // then canceling the dialog should not leave the throbber spinning.
708 IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) { 719 IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) {
709 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML); 720 GURL url(std::string("data:text/html,") + kBeforeUnloadHTML);
710 ui_test_utils::NavigateToURL(browser(), url); 721 ui_test_utils::NavigateToURL(browser(), url);
711 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); 722 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
(...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 1894
1884 // Ensure that creating an interstitial page closes any JavaScript dialogs 1895 // Ensure that creating an interstitial page closes any JavaScript dialogs
1885 // that were present on the previous page. See http://crbug.com/295695. 1896 // that were present on the previous page. See http://crbug.com/295695.
1886 IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialClosesDialogs) { 1897 IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialClosesDialogs) {
1887 ASSERT_TRUE(embedded_test_server()->Start()); 1898 ASSERT_TRUE(embedded_test_server()->Start());
1888 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 1899 host_resolver()->AddRule("www.example.com", "127.0.0.1");
1889 GURL url(embedded_test_server()->GetURL("/empty.html")); 1900 GURL url(embedded_test_server()->GetURL("/empty.html"));
1890 ui_test_utils::NavigateToURL(browser(), url); 1901 ui_test_utils::NavigateToURL(browser(), url);
1891 1902
1892 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); 1903 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents();
1904 JavaScriptDialogTabHelper* js_helper =
1905 JavaScriptDialogTabHelper::FromWebContents(contents);
1906 base::RunLoop dialog_wait;
1907 js_helper->SetDialogShownCallbackForTesting(dialog_wait.QuitClosure());
1893 contents->GetMainFrame()->ExecuteJavaScriptForTests( 1908 contents->GetMainFrame()->ExecuteJavaScriptForTests(
1894 ASCIIToUTF16("alert('Dialog showing!');")); 1909 ASCIIToUTF16("alert('Dialog showing!');"));
1895 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 1910 dialog_wait.Run();
1896 EXPECT_TRUE(alert->IsValid()); 1911 EXPECT_TRUE(js_helper->IsShowingDialogForTesting());
1897 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance();
1898 EXPECT_TRUE(dialog_queue->HasActiveDialog());
1899 1912
1900 TestInterstitialPage* interstitial = 1913 TestInterstitialPage* interstitial =
1901 new TestInterstitialPage(contents, false, GURL()); 1914 new TestInterstitialPage(contents, false, GURL());
1902 content::WaitForInterstitialAttach(contents); 1915 content::WaitForInterstitialAttach(contents);
1903 1916
1904 // The interstitial should have closed the dialog. 1917 // The interstitial should have closed the dialog.
1905 EXPECT_TRUE(contents->ShowingInterstitialPage()); 1918 EXPECT_TRUE(contents->ShowingInterstitialPage());
1906 EXPECT_FALSE(dialog_queue->HasActiveDialog()); 1919 EXPECT_FALSE(js_helper->IsShowingDialogForTesting());
1907 1920
1908 // Don't proceed and wait for interstitial to detach. This doesn't destroy 1921 // Don't proceed and wait for interstitial to detach. This doesn't destroy
1909 // |contents|. 1922 // |contents|.
1910 interstitial->DontProceed(); 1923 interstitial->DontProceed();
1911 content::WaitForInterstitialDetach(contents); 1924 content::WaitForInterstitialDetach(contents);
1912 // interstitial is deleted now. 1925 // interstitial is deleted now.
1913 1926
1914 // Make sure input events still work in the renderer process. 1927 // Make sure input events still work in the renderer process.
1915 EXPECT_FALSE(contents->GetRenderProcessHost()->IgnoreInputEvents()); 1928 EXPECT_FALSE(contents->GetRenderProcessHost()->IgnoreInputEvents());
1916 } 1929 }
(...skipping 957 matching lines...) Expand 10 before | Expand all | Expand 10 after
2874 Browser* browser = new Browser(params); 2887 Browser* browser = new Browser(params);
2875 gfx::Rect bounds = browser->window()->GetBounds(); 2888 gfx::Rect bounds = browser->window()->GetBounds();
2876 2889
2877 // Should be EXPECT_EQ, but this width is inconsistent across platforms. 2890 // Should be EXPECT_EQ, but this width is inconsistent across platforms.
2878 // See https://crbug.com/567925. 2891 // See https://crbug.com/567925.
2879 EXPECT_GE(bounds.width(), 100); 2892 EXPECT_GE(bounds.width(), 100);
2880 EXPECT_EQ(122, bounds.height()); 2893 EXPECT_EQ(122, bounds.height());
2881 browser->window()->Close(); 2894 browser->window()->Close();
2882 } 2895 }
2883 } 2896 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698