OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "base/test/scoped_command_line.h" | 7 #include "base/test/scoped_command_line.h" |
8 #include "base/test/scoped_feature_list.h" | |
9 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h" | 9 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/common/chrome_features.h" | |
13 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
15 #include "content/public/browser/render_frame_host.h" | 13 #include "content/public/browser/render_frame_host.h" |
16 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
17 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
18 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
19 | 17 |
20 using JavaScriptDialogTest = InProcessBrowserTest; | 18 using JavaScriptDialogTest = InProcessBrowserTest; |
21 | 19 |
22 IN_PROC_BROWSER_TEST_F(JavaScriptDialogTest, ReloadDoesntHang) { | 20 IN_PROC_BROWSER_TEST_F(JavaScriptDialogTest, ReloadDoesntHang) { |
23 base::test::ScopedFeatureList feature_list; | |
24 feature_list.InitAndEnableFeature(features::kAutoDismissingDialogs); | |
25 | |
26 content::WebContents* tab = | 21 content::WebContents* tab = |
27 browser()->tab_strip_model()->GetActiveWebContents(); | 22 browser()->tab_strip_model()->GetActiveWebContents(); |
28 JavaScriptDialogTabHelper* js_helper = | 23 JavaScriptDialogTabHelper* js_helper = |
29 JavaScriptDialogTabHelper::FromWebContents(tab); | 24 JavaScriptDialogTabHelper::FromWebContents(tab); |
30 | 25 |
31 // Show a dialog. | 26 // Show a dialog. |
32 scoped_refptr<content::MessageLoopRunner> runner = | 27 scoped_refptr<content::MessageLoopRunner> runner = |
33 new content::MessageLoopRunner; | 28 new content::MessageLoopRunner; |
34 js_helper->SetDialogShownCallbackForTesting(runner->QuitClosure()); | 29 js_helper->SetDialogShownCallbackForTesting(runner->QuitClosure()); |
35 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); | 30 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); |
36 runner->Run(); | 31 runner->Run(); |
37 | 32 |
38 // Try reloading. | 33 // Try reloading. |
39 tab->GetController().Reload(content::ReloadType::NORMAL, false); | 34 tab->GetController().Reload(content::ReloadType::NORMAL, false); |
40 content::WaitForLoadStop(tab); | 35 content::WaitForLoadStop(tab); |
41 | 36 |
42 // If the WaitForLoadStop doesn't hang forever, we've passed. | 37 // If the WaitForLoadStop doesn't hang forever, we've passed. |
43 } | 38 } |
44 | 39 |
45 IN_PROC_BROWSER_TEST_F(JavaScriptDialogTest, | 40 IN_PROC_BROWSER_TEST_F(JavaScriptDialogTest, |
46 ClosingPageSharingRendererDoesntHang) { | 41 ClosingPageSharingRendererDoesntHang) { |
47 base::test::ScopedFeatureList feature_list; | |
48 feature_list.InitAndEnableFeature(features::kAutoDismissingDialogs); | |
49 | |
50 // Turn off popup blocking. | 42 // Turn off popup blocking. |
51 base::test::ScopedCommandLine scoped_command_line; | 43 base::test::ScopedCommandLine scoped_command_line; |
52 scoped_command_line.GetProcessCommandLine()->AppendSwitch( | 44 scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
53 switches::kDisablePopupBlocking); | 45 switches::kDisablePopupBlocking); |
54 | 46 |
55 // Two tabs, one render process. | 47 // Two tabs, one render process. |
56 content::WebContents* tab1 = | 48 content::WebContents* tab1 = |
57 browser()->tab_strip_model()->GetActiveWebContents(); | 49 browser()->tab_strip_model()->GetActiveWebContents(); |
58 content::WebContentsAddedObserver new_wc_observer; | 50 content::WebContentsAddedObserver new_wc_observer; |
59 tab1->GetMainFrame()->ExecuteJavaScriptForTests( | 51 tab1->GetMainFrame()->ExecuteJavaScriptForTests( |
(...skipping 18 matching lines...) Expand all Loading... |
78 | 70 |
79 // Try reloading tab one. | 71 // Try reloading tab one. |
80 tab1->GetController().Reload(content::ReloadType::NORMAL, false); | 72 tab1->GetController().Reload(content::ReloadType::NORMAL, false); |
81 content::WaitForLoadStop(tab1); | 73 content::WaitForLoadStop(tab1); |
82 | 74 |
83 // If the WaitForLoadStop doesn't hang forever, we've passed. | 75 // If the WaitForLoadStop doesn't hang forever, we've passed. |
84 } | 76 } |
85 | 77 |
86 IN_PROC_BROWSER_TEST_F(JavaScriptDialogTest, | 78 IN_PROC_BROWSER_TEST_F(JavaScriptDialogTest, |
87 ClosingPageWithSubframeAlertingDoesntCrash) { | 79 ClosingPageWithSubframeAlertingDoesntCrash) { |
88 base::test::ScopedFeatureList feature_list; | |
89 feature_list.InitAndEnableFeature(features::kAutoDismissingDialogs); | |
90 | |
91 content::WebContents* tab = | 80 content::WebContents* tab = |
92 browser()->tab_strip_model()->GetActiveWebContents(); | 81 browser()->tab_strip_model()->GetActiveWebContents(); |
93 JavaScriptDialogTabHelper* js_helper = | 82 JavaScriptDialogTabHelper* js_helper = |
94 JavaScriptDialogTabHelper::FromWebContents(tab); | 83 JavaScriptDialogTabHelper::FromWebContents(tab); |
95 | 84 |
96 // A subframe shows a dialog. | 85 // A subframe shows a dialog. |
97 std::string dialog_url = "data:text/html,<script>alert(\"hi\");</script>"; | 86 std::string dialog_url = "data:text/html,<script>alert(\"hi\");</script>"; |
98 std::string script = "var iframe = document.createElement('iframe');" | 87 std::string script = "var iframe = document.createElement('iframe');" |
99 "iframe.src = '" + dialog_url + "';" | 88 "iframe.src = '" + dialog_url + "';" |
100 "document.body.appendChild(iframe);"; | 89 "document.body.appendChild(iframe);"; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // prompt, ok + no override | 181 // prompt, ok + no override |
193 js_helper->RunJavaScriptDialog( | 182 js_helper->RunJavaScriptDialog( |
194 tab, GURL(), content::JAVASCRIPT_DIALOG_TYPE_PROMPT, base::string16(), | 183 tab, GURL(), content::JAVASCRIPT_DIALOG_TYPE_PROMPT, base::string16(), |
195 value1, callback, &did_suppress); | 184 value1, callback, &did_suppress); |
196 ASSERT_TRUE(js_helper->IsShowingDialogForTesting()); | 185 ASSERT_TRUE(js_helper->IsShowingDialogForTesting()); |
197 js_helper->HandleJavaScriptDialog(tab, true, nullptr); | 186 js_helper->HandleJavaScriptDialog(tab, true, nullptr); |
198 ASSERT_FALSE(js_helper->IsShowingDialogForTesting()); | 187 ASSERT_FALSE(js_helper->IsShowingDialogForTesting()); |
199 ASSERT_TRUE(callback_helper.last_success()); | 188 ASSERT_TRUE(callback_helper.last_success()); |
200 ASSERT_EQ(value1, callback_helper.last_input()); | 189 ASSERT_EQ(value1, callback_helper.last_input()); |
201 } | 190 } |
OLD | NEW |