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

Side by Side Diff: chrome/browser/ui/webui/constrained_web_dialog_ui_browsertest.cc

Issue 2798583002: WebUI: prevent WebContent to hold invalid pointer. (Closed)
Patch Set: Fix compilation on mac Created 3 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "base/callback.h" 5 #include "base/callback.h"
6 #include "base/location.h" 6 #include "base/location.h"
7 #include "base/single_thread_task_runner.h" 7 #include "base/single_thread_task_runner.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 browser()->tab_strip_model()->GetActiveWebContents(); 113 browser()->tab_strip_model()->GetActiveWebContents();
114 ASSERT_TRUE(web_contents); 114 ASSERT_TRUE(web_contents);
115 115
116 ConstrainedWebDialogDelegate* dialog_delegate = 116 ConstrainedWebDialogDelegate* dialog_delegate =
117 ShowConstrainedWebDialog(browser()->profile(), delegate, web_contents); 117 ShowConstrainedWebDialog(browser()->profile(), delegate, web_contents);
118 ASSERT_TRUE(dialog_delegate); 118 ASSERT_TRUE(dialog_delegate);
119 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); 119 EXPECT_TRUE(dialog_delegate->GetNativeDialog());
120 EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents)); 120 EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents));
121 } 121 }
122 122
123 // Tests that ReleaseWebContentsOnDialogClose() works. 123 // Tests that ReleaseWebContents() works.
124 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, 124 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, ReleaseWebContents) {
125 ReleaseWebContentsOnDialogClose) {
126 // The delegate deletes itself. 125 // The delegate deletes itself.
127 WebDialogDelegate* delegate = new ui::test::TestWebDialogDelegate( 126 WebDialogDelegate* delegate = new ui::test::TestWebDialogDelegate(
128 GURL(chrome::kChromeUIConstrainedHTMLTestURL)); 127 GURL(chrome::kChromeUIConstrainedHTMLTestURL));
129 WebContents* web_contents = 128 WebContents* web_contents =
130 browser()->tab_strip_model()->GetActiveWebContents(); 129 browser()->tab_strip_model()->GetActiveWebContents();
131 ASSERT_TRUE(web_contents); 130 ASSERT_TRUE(web_contents);
132 131
133 ConstrainedWebDialogDelegate* dialog_delegate = 132 ConstrainedWebDialogDelegate* dialog_delegate =
134 ShowConstrainedWebDialog(browser()->profile(), delegate, web_contents); 133 ShowConstrainedWebDialog(browser()->profile(), delegate, web_contents);
135 ASSERT_TRUE(dialog_delegate); 134 ASSERT_TRUE(dialog_delegate);
136 std::unique_ptr<WebContents> new_tab(dialog_delegate->GetWebContents()); 135 WebContents* dialog_contents = dialog_delegate->GetWebContents();
137 ASSERT_TRUE(new_tab.get()); 136 ASSERT_TRUE(dialog_contents);
138 ASSERT_TRUE(IsShowingWebContentsModalDialog(web_contents)); 137 ASSERT_TRUE(IsShowingWebContentsModalDialog(web_contents));
139 138
140 ConstrainedWebDialogBrowserTestObserver observer(new_tab.get()); 139 ConstrainedWebDialogBrowserTestObserver observer(dialog_contents);
141 dialog_delegate->ReleaseWebContentsOnDialogClose(); 140 std::unique_ptr<WebContents> dialog_contents_holder =
141 dialog_delegate->ReleaseWebContents();
142 dialog_delegate->OnDialogCloseFromWebUI(); 142 dialog_delegate->OnDialogCloseFromWebUI();
143 143
144 ASSERT_FALSE(observer.contents_destroyed()); 144 ASSERT_FALSE(observer.contents_destroyed());
145 EXPECT_FALSE(IsShowingWebContentsModalDialog(web_contents)); 145 EXPECT_FALSE(IsShowingWebContentsModalDialog(web_contents));
146 new_tab.reset(); 146 dialog_contents_holder.reset();
147 EXPECT_TRUE(observer.contents_destroyed()); 147 EXPECT_TRUE(observer.contents_destroyed());
148 } 148 }
149 149
150 // Tests that dialog autoresizes based on web contents when autoresizing 150 // Tests that dialog autoresizes based on web contents when autoresizing
151 // is enabled. 151 // is enabled.
152 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, 152 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest,
153 ContentResizeInAutoResizingDialog) { 153 ContentResizeInAutoResizingDialog) {
154 // During auto-resizing, dialogs size to (WebContents size) + 16. 154 // During auto-resizing, dialogs size to (WebContents size) + 16.
155 const int dialog_border_space = 16; 155 const int dialog_border_space = 16;
156 156
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 dialog_delegate))); 266 dialog_delegate)));
267 267
268 // Resize <body> to dimension larger than dialog. 268 // Resize <body> to dimension larger than dialog.
269 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), 269 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(),
270 GetChangeDimensionsScript(500))); 270 GetChangeDimensionsScript(500)));
271 ASSERT_TRUE(RunLoopUntil(base::Bind( 271 ASSERT_TRUE(RunLoopUntil(base::Bind(
272 &IsEqualSizes, 272 &IsEqualSizes,
273 initial_dialog_size, 273 initial_dialog_size,
274 dialog_delegate))); 274 dialog_delegate)));
275 } 275 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698