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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 | 537 |
538 IN_PROC_BROWSER_TEST_F(BrowserTest, JavascriptAlertActivatesTab) { | 538 IN_PROC_BROWSER_TEST_F(BrowserTest, JavascriptAlertActivatesTab) { |
539 GURL url(ui_test_utils::GetTestUrl(base::FilePath( | 539 GURL url(ui_test_utils::GetTestUrl(base::FilePath( |
540 base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File))); | 540 base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File))); |
541 ui_test_utils::NavigateToURL(browser(), url); | 541 ui_test_utils::NavigateToURL(browser(), url); |
542 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); | 542 AddTabAtIndex(0, url, ui::PAGE_TRANSITION_TYPED); |
543 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 543 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
544 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); | 544 EXPECT_EQ(0, browser()->tab_strip_model()->active_index()); |
545 WebContents* second_tab = browser()->tab_strip_model()->GetWebContentsAt(1); | 545 WebContents* second_tab = browser()->tab_strip_model()->GetWebContentsAt(1); |
546 ASSERT_TRUE(second_tab); | 546 ASSERT_TRUE(second_tab); |
547 second_tab->GetMainFrame()->ExecuteJavaScript( | 547 second_tab->GetMainFrame()->ExecuteJavaScriptForTests( |
548 ASCIIToUTF16("alert('Activate!');")); | 548 ASCIIToUTF16("alert('Activate!');")); |
549 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 549 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
550 alert->CloseModalDialog(); | 550 alert->CloseModalDialog(); |
551 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 551 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
552 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); | 552 EXPECT_EQ(1, browser()->tab_strip_model()->active_index()); |
553 } | 553 } |
554 | 554 |
555 | 555 |
556 #if defined(OS_WIN) && !defined(NDEBUG) | 556 #if defined(OS_WIN) && !defined(NDEBUG) |
557 // http://crbug.com/114859. Times out frequently on Windows. | 557 // http://crbug.com/114859. Times out frequently on Windows. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 IN_PROC_BROWSER_TEST_F(BrowserTest, DISABLED_CrossProcessNavCancelsDialogs) { | 644 IN_PROC_BROWSER_TEST_F(BrowserTest, DISABLED_CrossProcessNavCancelsDialogs) { |
645 ASSERT_TRUE(test_server()->Start()); | 645 ASSERT_TRUE(test_server()->Start()); |
646 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 646 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
647 GURL url(test_server()->GetURL("empty.html")); | 647 GURL url(test_server()->GetURL("empty.html")); |
648 ui_test_utils::NavigateToURL(browser(), url); | 648 ui_test_utils::NavigateToURL(browser(), url); |
649 | 649 |
650 // Test this with multiple alert dialogs to ensure that we can navigate away | 650 // Test this with multiple alert dialogs to ensure that we can navigate away |
651 // even if the renderer tries to synchronously create more. | 651 // even if the renderer tries to synchronously create more. |
652 // See http://crbug.com/312490. | 652 // See http://crbug.com/312490. |
653 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | 653 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
654 contents->GetMainFrame()->ExecuteJavaScript( | 654 contents->GetMainFrame()->ExecuteJavaScriptForTests( |
655 ASCIIToUTF16("alert('one'); alert('two');")); | 655 ASCIIToUTF16("alert('one'); alert('two');")); |
656 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 656 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
657 EXPECT_TRUE(alert->IsValid()); | 657 EXPECT_TRUE(alert->IsValid()); |
658 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); | 658 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); |
659 EXPECT_TRUE(dialog_queue->HasActiveDialog()); | 659 EXPECT_TRUE(dialog_queue->HasActiveDialog()); |
660 | 660 |
661 // A cross-site navigation should force the dialog to close. | 661 // A cross-site navigation should force the dialog to close. |
662 GURL url2("http://www.example.com/empty.html"); | 662 GURL url2("http://www.example.com/empty.html"); |
663 ui_test_utils::NavigateToURL(browser(), url2); | 663 ui_test_utils::NavigateToURL(browser(), url2); |
664 EXPECT_FALSE(dialog_queue->HasActiveDialog()); | 664 EXPECT_FALSE(dialog_queue->HasActiveDialog()); |
665 | 665 |
666 // Make sure input events still work in the renderer process. | 666 // Make sure input events still work in the renderer process. |
667 EXPECT_FALSE(contents->GetRenderProcessHost()->IgnoreInputEvents()); | 667 EXPECT_FALSE(contents->GetRenderProcessHost()->IgnoreInputEvents()); |
668 } | 668 } |
669 | 669 |
670 // Make sure that dialogs are closed after a renderer process dies, and that | 670 // Make sure that dialogs are closed after a renderer process dies, and that |
671 // subsequent navigations work. See http://crbug/com/343265. | 671 // subsequent navigations work. See http://crbug/com/343265. |
672 IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsDialogs) { | 672 IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsDialogs) { |
673 ASSERT_TRUE(test_server()->Start()); | 673 ASSERT_TRUE(test_server()->Start()); |
674 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 674 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
675 GURL beforeunload_url(test_server()->GetURL("files/beforeunload.html")); | 675 GURL beforeunload_url(test_server()->GetURL("files/beforeunload.html")); |
676 ui_test_utils::NavigateToURL(browser(), beforeunload_url); | 676 ui_test_utils::NavigateToURL(browser(), beforeunload_url); |
677 | 677 |
678 // Start a navigation to trigger the beforeunload dialog. | 678 // Start a navigation to trigger the beforeunload dialog. |
679 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | 679 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
680 contents->GetMainFrame()->ExecuteJavaScript( | 680 contents->GetMainFrame()->ExecuteJavaScriptForTests( |
681 ASCIIToUTF16("window.location.href = 'data:text/html,foo'")); | 681 ASCIIToUTF16("window.location.href = 'data:text/html,foo'")); |
682 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 682 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
683 EXPECT_TRUE(alert->IsValid()); | 683 EXPECT_TRUE(alert->IsValid()); |
684 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); | 684 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); |
685 EXPECT_TRUE(dialog_queue->HasActiveDialog()); | 685 EXPECT_TRUE(dialog_queue->HasActiveDialog()); |
686 | 686 |
687 // Crash the renderer process and ensure the dialog is gone. | 687 // Crash the renderer process and ensure the dialog is gone. |
688 content::RenderProcessHost* child_process = contents->GetRenderProcessHost(); | 688 content::RenderProcessHost* child_process = contents->GetRenderProcessHost(); |
689 content::RenderProcessHostWatcher crash_observer( | 689 content::RenderProcessHostWatcher crash_observer( |
690 child_process, | 690 child_process, |
691 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); | 691 content::RenderProcessHostWatcher::WATCH_FOR_PROCESS_EXIT); |
692 child_process->Shutdown(0, false); | 692 child_process->Shutdown(0, false); |
693 crash_observer.Wait(); | 693 crash_observer.Wait(); |
694 EXPECT_FALSE(dialog_queue->HasActiveDialog()); | 694 EXPECT_FALSE(dialog_queue->HasActiveDialog()); |
695 | 695 |
696 // Make sure subsequent navigations work. | 696 // Make sure subsequent navigations work. |
697 GURL url2("http://www.example.com/files/empty.html"); | 697 GURL url2("http://www.example.com/files/empty.html"); |
698 ui_test_utils::NavigateToURL(browser(), url2); | 698 ui_test_utils::NavigateToURL(browser(), url2); |
699 } | 699 } |
700 | 700 |
701 // Make sure that dialogs opened by subframes are closed when the process dies. | 701 // Make sure that dialogs opened by subframes are closed when the process dies. |
702 // See http://crbug.com/366510. | 702 // See http://crbug.com/366510. |
703 IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsSubframeDialogs) { | 703 IN_PROC_BROWSER_TEST_F(BrowserTest, SadTabCancelsSubframeDialogs) { |
704 // Navigate to an iframe that opens an alert dialog. | 704 // Navigate to an iframe that opens an alert dialog. |
705 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | 705 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
706 contents->GetMainFrame()->ExecuteJavaScript( | 706 contents->GetMainFrame()->ExecuteJavaScriptForTests( |
707 ASCIIToUTF16("window.location.href = 'data:text/html," | 707 ASCIIToUTF16("window.location.href = 'data:text/html," |
708 "<iframe srcdoc=\"<script>alert(1)</script>\">'")); | 708 "<iframe srcdoc=\"<script>alert(1)</script>\">'")); |
709 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 709 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
710 EXPECT_TRUE(alert->IsValid()); | 710 EXPECT_TRUE(alert->IsValid()); |
711 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); | 711 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); |
712 EXPECT_TRUE(dialog_queue->HasActiveDialog()); | 712 EXPECT_TRUE(dialog_queue->HasActiveDialog()); |
713 | 713 |
714 // Crash the renderer process and ensure the dialog is gone. | 714 // Crash the renderer process and ensure the dialog is gone. |
715 content::RenderProcessHost* child_process = contents->GetRenderProcessHost(); | 715 content::RenderProcessHost* child_process = contents->GetRenderProcessHost(); |
716 content::RenderProcessHostWatcher crash_observer( | 716 content::RenderProcessHostWatcher crash_observer( |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 // Navigate to another page, but click cancel in the dialog. Make sure that | 760 // Navigate to another page, but click cancel in the dialog. Make sure that |
761 // the throbber stops spinning. | 761 // the throbber stops spinning. |
762 chrome::Reload(browser(), CURRENT_TAB); | 762 chrome::Reload(browser(), CURRENT_TAB); |
763 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 763 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
764 alert->CloseModalDialog(); | 764 alert->CloseModalDialog(); |
765 EXPECT_FALSE( | 765 EXPECT_FALSE( |
766 browser()->tab_strip_model()->GetActiveWebContents()->IsLoading()); | 766 browser()->tab_strip_model()->GetActiveWebContents()->IsLoading()); |
767 | 767 |
768 // Clear the beforeunload handler so the test can easily exit. | 768 // Clear the beforeunload handler so the test can easily exit. |
769 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()-> | 769 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()-> |
770 ExecuteJavaScript(ASCIIToUTF16("onbeforeunload=null;")); | 770 ExecuteJavaScriptForTests(ASCIIToUTF16("onbeforeunload=null;")); |
771 } | 771 } |
772 | 772 |
773 class RedirectObserver : public content::WebContentsObserver { | 773 class RedirectObserver : public content::WebContentsObserver { |
774 public: | 774 public: |
775 explicit RedirectObserver(content::WebContents* web_contents) | 775 explicit RedirectObserver(content::WebContents* web_contents) |
776 : WebContentsObserver(web_contents) { | 776 : WebContentsObserver(web_contents) { |
777 } | 777 } |
778 | 778 |
779 void DidNavigateAnyFrame( | 779 void DidNavigateAnyFrame( |
780 content::RenderFrameHost* render_frame_host, | 780 content::RenderFrameHost* render_frame_host, |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 GetActiveWebContents()->GetController().GetPendingEntry(); | 921 GetActiveWebContents()->GetController().GetPendingEntry(); |
922 EXPECT_EQ(NULL, entry); | 922 EXPECT_EQ(NULL, entry); |
923 | 923 |
924 // Wait for the ShouldClose_ACK to arrive. We can detect it by waiting for | 924 // Wait for the ShouldClose_ACK to arrive. We can detect it by waiting for |
925 // the pending RVH to be destroyed. | 925 // the pending RVH to be destroyed. |
926 host_destroyed_observer.Wait(); | 926 host_destroyed_observer.Wait(); |
927 EXPECT_EQ(url, browser()->toolbar_model()->GetURL()); | 927 EXPECT_EQ(url, browser()->toolbar_model()->GetURL()); |
928 | 928 |
929 // Clear the beforeunload handler so the test can easily exit. | 929 // Clear the beforeunload handler so the test can easily exit. |
930 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()-> | 930 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame()-> |
931 ExecuteJavaScript(ASCIIToUTF16("onbeforeunload=null;")); | 931 ExecuteJavaScriptForTests(ASCIIToUTF16("onbeforeunload=null;")); |
932 } | 932 } |
933 | 933 |
934 // Test for crbug.com/11647. A page closed with window.close() should not have | 934 // Test for crbug.com/11647. A page closed with window.close() should not have |
935 // two beforeunload dialogs shown. | 935 // two beforeunload dialogs shown. |
936 // http://crbug.com/410891 | 936 // http://crbug.com/410891 |
937 IN_PROC_BROWSER_TEST_F(BrowserTest, | 937 IN_PROC_BROWSER_TEST_F(BrowserTest, |
938 DISABLED_SingleBeforeUnloadAfterWindowClose) { | 938 DISABLED_SingleBeforeUnloadAfterWindowClose) { |
939 browser() | 939 browser() |
940 ->tab_strip_model() | 940 ->tab_strip_model() |
941 ->GetActiveWebContents() | 941 ->GetActiveWebContents() |
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2061 | 2061 |
2062 // Ensure that creating an interstitial page closes any JavaScript dialogs | 2062 // Ensure that creating an interstitial page closes any JavaScript dialogs |
2063 // that were present on the previous page. See http://crbug.com/295695. | 2063 // that were present on the previous page. See http://crbug.com/295695. |
2064 IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialClosesDialogs) { | 2064 IN_PROC_BROWSER_TEST_F(BrowserTest, InterstitialClosesDialogs) { |
2065 ASSERT_TRUE(test_server()->Start()); | 2065 ASSERT_TRUE(test_server()->Start()); |
2066 host_resolver()->AddRule("www.example.com", "127.0.0.1"); | 2066 host_resolver()->AddRule("www.example.com", "127.0.0.1"); |
2067 GURL url(test_server()->GetURL("empty.html")); | 2067 GURL url(test_server()->GetURL("empty.html")); |
2068 ui_test_utils::NavigateToURL(browser(), url); | 2068 ui_test_utils::NavigateToURL(browser(), url); |
2069 | 2069 |
2070 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); | 2070 WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); |
2071 contents->GetMainFrame()->ExecuteJavaScript( | 2071 contents->GetMainFrame()->ExecuteJavaScriptForTests( |
2072 ASCIIToUTF16("alert('Dialog showing!');")); | 2072 ASCIIToUTF16("alert('Dialog showing!');")); |
2073 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); | 2073 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); |
2074 EXPECT_TRUE(alert->IsValid()); | 2074 EXPECT_TRUE(alert->IsValid()); |
2075 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); | 2075 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); |
2076 EXPECT_TRUE(dialog_queue->HasActiveDialog()); | 2076 EXPECT_TRUE(dialog_queue->HasActiveDialog()); |
2077 | 2077 |
2078 TestInterstitialPage* interstitial = | 2078 TestInterstitialPage* interstitial = |
2079 new TestInterstitialPage(contents, false, GURL()); | 2079 new TestInterstitialPage(contents, false, GURL()); |
2080 content::WaitForInterstitialAttach(contents); | 2080 content::WaitForInterstitialAttach(contents); |
2081 | 2081 |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2998 // the observer (to make sure that the event fires twice and we don't | 2998 // the observer (to make sure that the event fires twice and we don't |
2999 // just see the previous event's style). | 2999 // just see the previous event's style). |
3000 observer.ClearLatestSecurityStyleAndExplanations(); | 3000 observer.ClearLatestSecurityStyleAndExplanations(); |
3001 | 3001 |
3002 // Other conditions cannot be tested after clicking through because | 3002 // Other conditions cannot be tested after clicking through because |
3003 // once the interstitial is clicked through, all URLs for this host | 3003 // once the interstitial is clicked through, all URLs for this host |
3004 // will remain in a broken state. | 3004 // will remain in a broken state. |
3005 ProceedThroughInterstitial(web_contents); | 3005 ProceedThroughInterstitial(web_contents); |
3006 CheckExpiredSecurityStyle(observer); | 3006 CheckExpiredSecurityStyle(observer); |
3007 } | 3007 } |
OLD | NEW |