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

Side by Side Diff: chrome/browser/ui/javascript_dialogs/javascript_dialog_browsertest.cc

Issue 2641173004: Make the callback from JavaScript dialogs even when closing a WebContents. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
Charlie Reis 2017/01/19 21:51:00 Is this leftover from some earlier logging?
Avi (use Gerrit) 2017/01/19 22:03:38 Done.
5 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "base/test/scoped_command_line.h"
6 #include "base/test/scoped_feature_list.h" 8 #include "base/test/scoped_feature_list.h"
7 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h" 10 #include "chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/common/chrome_features.h" 12 #include "chrome/common/chrome_features.h"
13 #include "chrome/common/chrome_switches.h"
11 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
12 #include "content/public/browser/render_frame_host.h" 15 #include "content/public/browser/render_frame_host.h"
13 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
14 #include "content/public/test/browser_test_utils.h" 17 #include "content/public/test/browser_test_utils.h"
15 #include "content/public/test/test_utils.h" 18 #include "content/public/test/test_utils.h"
16 19
17 using JavaScriptDialogTest = InProcessBrowserTest; 20 using JavaScriptDialogTest = InProcessBrowserTest;
18 21
19 IN_PROC_BROWSER_TEST_F(JavaScriptDialogTest, ReloadDoesntHang) { 22 IN_PROC_BROWSER_TEST_F(JavaScriptDialogTest, ReloadDoesntHang) {
20 base::test::ScopedFeatureList feature_list; 23 base::test::ScopedFeatureList feature_list;
21 feature_list.InitAndEnableFeature(features::kAutoDismissingDialogs); 24 feature_list.InitAndEnableFeature(features::kAutoDismissingDialogs);
22 25
23 content::WebContents* tab = 26 content::WebContents* tab =
24 browser()->tab_strip_model()->GetActiveWebContents(); 27 browser()->tab_strip_model()->GetActiveWebContents();
25 JavaScriptDialogTabHelper* js_helper = 28 JavaScriptDialogTabHelper* js_helper =
26 JavaScriptDialogTabHelper::FromWebContents(tab); 29 JavaScriptDialogTabHelper::FromWebContents(tab);
27 30
28 // Show a dialog. 31 // Show a dialog.
29
30 scoped_refptr<content::MessageLoopRunner> runner = 32 scoped_refptr<content::MessageLoopRunner> runner =
31 new content::MessageLoopRunner; 33 new content::MessageLoopRunner;
32 js_helper->SetDialogShownCallbackForTesting(runner->QuitClosure()); 34 js_helper->SetDialogShownCallbackForTesting(runner->QuitClosure());
33 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()")); 35 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()"));
34 runner->Run(); 36 runner->Run();
35 37
36 // Try reloading. 38 // Try reloading.
37
38 tab->GetController().Reload(content::ReloadType::NORMAL, false); 39 tab->GetController().Reload(content::ReloadType::NORMAL, false);
39 content::WaitForLoadStop(tab); 40 content::WaitForLoadStop(tab);
40 41
41 // If the WaitForLoadStop doesn't hang forever, we've passed. 42 // If the WaitForLoadStop doesn't hang forever, we've passed.
42 } 43 }
44
45 IN_PROC_BROWSER_TEST_F(JavaScriptDialogTest,
46 ClosingPageSharingRendererDoesntHang) {
47 base::test::ScopedFeatureList feature_list;
48 feature_list.InitAndEnableFeature(features::kAutoDismissingDialogs);
49
50 // Turn off popup blocking.
51 base::test::ScopedCommandLine scoped_command_line;
52 scoped_command_line.GetProcessCommandLine()->AppendSwitch(
53 switches::kDisablePopupBlocking);
54
55 // Two tabs, one render process.
56 content::WebContents* tab1 =
57 browser()->tab_strip_model()->GetActiveWebContents();
58 content::WebContentsAddedObserver new_wc_observer;
59 tab1->GetMainFrame()->ExecuteJavaScriptForTests(
60 base::UTF8ToUTF16("window.open('about:blank');"));
61 content::WebContents* tab2 = new_wc_observer.GetWebContents();
62 ASSERT_NE(tab1, tab2);
63 ASSERT_EQ(tab1->GetRenderProcessHost(), tab2->GetRenderProcessHost());
64
65 // Tab two shows a dialog.
66 scoped_refptr<content::MessageLoopRunner> runner =
67 new content::MessageLoopRunner;
68 JavaScriptDialogTabHelper* js_helper2 =
69 JavaScriptDialogTabHelper::FromWebContents(tab2);
70 js_helper2->SetDialogShownCallbackForTesting(runner->QuitClosure());
71 tab2->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16("alert()"));
72 runner->Run();
73
74 // Tab two is closed while the dialog is up.
75 int tab2_index = browser()->tab_strip_model()->GetIndexOfWebContents(tab2);
76 browser()->tab_strip_model()->CloseWebContentsAt(tab2_index,
77 TabStripModel::CLOSE_NONE);
78
79 // Try reloading tab one.
80 tab1->GetController().Reload(content::ReloadType::NORMAL, false);
81 content::WaitForLoadStop(tab1);
82
83 // If the WaitForLoadStop doesn't hang forever, we've passed.
84 }
85
86 IN_PROC_BROWSER_TEST_F(JavaScriptDialogTest,
87 ClosingPageWithSubframeAlertingDoesntCrash) {
88 base::test::ScopedFeatureList feature_list;
89 feature_list.InitAndEnableFeature(features::kAutoDismissingDialogs);
90
91 content::WebContents* tab =
92 browser()->tab_strip_model()->GetActiveWebContents();
93 JavaScriptDialogTabHelper* js_helper =
94 JavaScriptDialogTabHelper::FromWebContents(tab);
95
96 // A subframe shows a dialog.
97 std::string dialog_url = "data:text/html,<script>alert(\"hi\");</script>";
98 std::string script = "var iframe = document.createElement('iframe');"
99 "iframe.src = '" + dialog_url + "';"
100 "document.body.appendChild(iframe);";
Charlie Reis 2017/01/19 21:51:00 Another test that might be useful (in a followup C
Avi (use Gerrit) 2017/01/19 22:03:38 That is sooo evil; I'm totally writing that one.
Charlie Reis 2017/01/19 22:08:32 Yep, exactly.
101 scoped_refptr<content::MessageLoopRunner> runner =
102 new content::MessageLoopRunner;
103 js_helper->SetDialogShownCallbackForTesting(runner->QuitClosure());
104 tab->GetMainFrame()->ExecuteJavaScriptForTests(base::UTF8ToUTF16(script));
105 runner->Run();
106
107 // The tab is closed while the dialog is up.
108 int tab_index = browser()->tab_strip_model()->GetIndexOfWebContents(tab);
109 browser()->tab_strip_model()->CloseWebContentsAt(tab_index,
110 TabStripModel::CLOSE_NONE);
111
112 // No crash is good news.
113 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/javascript_dialogs/javascript_dialog_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698