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

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

Issue 1796273004: [Reland] Enable AutoResize for Constrained Web Dialogs for Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2661
Patch Set: Created 4 years, 9 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 | « chrome/browser/ui/webui/constrained_web_dialog_ui.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" 13 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
14 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
15 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "components/web_modal/web_contents_modal_dialog_manager.h" 16 #include "components/web_modal/web_contents_modal_dialog_manager.h"
17 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
18 #include "content/public/browser/web_contents_observer.h" 18 #include "content/public/browser/web_contents_observer.h"
19 #include "content/public/test/browser_test_utils.h" 19 #include "content/public/test/browser_test_utils.h"
20 #include "content/public/test/test_navigation_observer.h" 20 #include "content/public/test/test_navigation_observer.h"
21 #include "ui/web_dialogs/test/test_web_dialog_delegate.h" 21 #include "ui/web_dialogs/test/test_web_dialog_delegate.h"
22 22
23 using content::WebContents; 23 using content::WebContents;
24 using ui::WebDialogDelegate; 24 using ui::WebDialogDelegate;
25 using web_modal::WebContentsModalDialogManager; 25 using web_modal::WebContentsModalDialogManager;
26 26
27 namespace { 27 namespace {
28 28
29 #if !defined(OS_MACOSX)
30 static const char kTestDataURL[] = "data:text/html,<!doctype html>" 29 static const char kTestDataURL[] = "data:text/html,<!doctype html>"
31 "<body></body>" 30 "<body></body>"
32 "<style>" 31 "<style>"
33 "body { height: 150px; width: 150px; }" 32 "body { height: 150px; width: 150px; }"
34 "</style>"; 33 "</style>";
35 34
36 bool IsEqualSizes(gfx::Size expected, 35 bool IsEqualSizes(gfx::Size expected,
37 ConstrainedWebDialogDelegate* dialog_delegate) { 36 ConstrainedWebDialogDelegate* dialog_delegate) {
38 return expected == dialog_delegate->GetPreferredSize(); 37 return expected == dialog_delegate->GetPreferredSize();
39 } 38 }
40 39
41 std::string GetChangeDimensionsScript(int dimension) { 40 std::string GetChangeDimensionsScript(int dimension) {
42 return base::StringPrintf("window.document.body.style.width = %d + 'px';" 41 return base::StringPrintf("window.document.body.style.width = %d + 'px';"
43 "window.document.body.style.height = %d + 'px';", dimension, dimension); 42 "window.document.body.style.height = %d + 'px';", dimension, dimension);
44 } 43 }
45 #endif
46 44
47 class ConstrainedWebDialogBrowserTestObserver 45 class ConstrainedWebDialogBrowserTestObserver
48 : public content::WebContentsObserver { 46 : public content::WebContentsObserver {
49 public: 47 public:
50 explicit ConstrainedWebDialogBrowserTestObserver(WebContents* contents) 48 explicit ConstrainedWebDialogBrowserTestObserver(WebContents* contents)
51 : content::WebContentsObserver(contents), 49 : content::WebContentsObserver(contents),
52 contents_destroyed_(false) { 50 contents_destroyed_(false) {
53 } 51 }
54 ~ConstrainedWebDialogBrowserTestObserver() override {} 52 ~ConstrainedWebDialogBrowserTestObserver() override {}
55 53
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 ConstrainedWebDialogBrowserTestObserver observer(new_tab.get()); 138 ConstrainedWebDialogBrowserTestObserver observer(new_tab.get());
141 dialog_delegate->ReleaseWebContentsOnDialogClose(); 139 dialog_delegate->ReleaseWebContentsOnDialogClose();
142 dialog_delegate->OnDialogCloseFromWebUI(); 140 dialog_delegate->OnDialogCloseFromWebUI();
143 141
144 ASSERT_FALSE(observer.contents_destroyed()); 142 ASSERT_FALSE(observer.contents_destroyed());
145 EXPECT_FALSE(IsShowingWebContentsModalDialog(web_contents)); 143 EXPECT_FALSE(IsShowingWebContentsModalDialog(web_contents));
146 new_tab.reset(); 144 new_tab.reset();
147 EXPECT_TRUE(observer.contents_destroyed()); 145 EXPECT_TRUE(observer.contents_destroyed());
148 } 146 }
149 147
150 #if !defined(OS_MACOSX)
151 // Tests that dialog autoresizes based on web contents when autoresizing 148 // Tests that dialog autoresizes based on web contents when autoresizing
152 // is enabled. 149 // is enabled.
153 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, 150 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest,
154 ContentResizeInAutoResizingDialog) { 151 ContentResizeInAutoResizingDialog) {
155 // During auto-resizing, dialogs size to (WebContents size) + 16. 152 // During auto-resizing, dialogs size to (WebContents size) + 16.
156 const int dialog_border_space = 16; 153 const int dialog_border_space = 16;
157 154
158 // Expected dialog sizes after auto-resizing. 155 // Expected dialog sizes after auto-resizing.
159 const int initial_size = 150 + dialog_border_space; 156 const int initial_size = 150 + dialog_border_space;
160 const int new_size = 175 + dialog_border_space; 157 const int new_size = 175 + dialog_border_space;
161 158
162 // The delegate deletes itself. 159 // The delegate deletes itself.
163 WebDialogDelegate* delegate = 160 WebDialogDelegate* delegate =
164 new AutoResizingTestWebDialogDelegate(GURL(kTestDataURL)); 161 new AutoResizingTestWebDialogDelegate(GURL(kTestDataURL));
165 WebContents* web_contents = 162 WebContents* web_contents =
166 browser()->tab_strip_model()->GetActiveWebContents(); 163 browser()->tab_strip_model()->GetActiveWebContents();
167 ASSERT_TRUE(web_contents); 164 ASSERT_TRUE(web_contents);
168 165
169 // Observes the next created WebContents. 166 // Observes the next created WebContents.
170 content::TestNavigationObserver observer(NULL); 167 content::TestNavigationObserver observer(NULL);
171 observer.StartWatchingNewWebContents(); 168 observer.StartWatchingNewWebContents();
172 169
173 gfx::Size min_size = gfx::Size(100, 100); 170 gfx::Size min_size = gfx::Size(100, 100);
174 gfx::Size max_size = gfx::Size(200, 200); 171 gfx::Size max_size = gfx::Size(200, 200);
175 gfx::Size initial_dialog_size; 172 gfx::Size initial_dialog_size;
173
174 // OSX windows must be initially created with non-empty dimensions. The
175 // autoresizeable dialog's window dimensions are determined after initial
176 // creation.
177 #if defined(OS_MACOSX)
178 initial_dialog_size = gfx::Size(1, 1);
179 #endif
176 delegate->GetDialogSize(&initial_dialog_size); 180 delegate->GetDialogSize(&initial_dialog_size);
177 181
178 ConstrainedWebDialogDelegate* dialog_delegate = 182 ConstrainedWebDialogDelegate* dialog_delegate =
179 ShowConstrainedWebDialogWithAutoResize(browser()->profile(), delegate, 183 ShowConstrainedWebDialogWithAutoResize(browser()->profile(), delegate,
180 web_contents, min_size, 184 web_contents, min_size,
181 max_size); 185 max_size);
182 ASSERT_TRUE(dialog_delegate); 186 ASSERT_TRUE(dialog_delegate);
183 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); 187 EXPECT_TRUE(dialog_delegate->GetNativeDialog());
184 ASSERT_FALSE(IsShowingWebContentsModalDialog(web_contents)); 188 ASSERT_FALSE(IsShowingWebContentsModalDialog(web_contents));
185 EXPECT_EQ(min_size, dialog_delegate->GetMinimumSize()); 189 EXPECT_EQ(min_size, dialog_delegate->GetMinimumSize());
186 EXPECT_EQ(max_size, dialog_delegate->GetMaximumSize()); 190 EXPECT_EQ(max_size, dialog_delegate->GetMaximumSize());
187 191
188 // Check for initial sizing. Dialog was created as a 400x400 dialog. 192 // Check for initial sizing. Dialog was created as a 400x400 dialog.
189 EXPECT_EQ(gfx::Size(), web_contents->GetPreferredSize());
190 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize()); 193 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize());
191 194
192 observer.Wait(); 195 observer.Wait();
193 196
194 // Wait until the entire WebContents has loaded. 197 // Wait until the entire WebContents has loaded.
195 WaitForLoadStop(dialog_delegate->GetWebContents()); 198 WaitForLoadStop(dialog_delegate->GetWebContents());
196 199
197 ASSERT_TRUE(IsShowingWebContentsModalDialog(web_contents)); 200 ASSERT_TRUE(IsShowingWebContentsModalDialog(web_contents));
198 201
199 // Resize to content's originally set dimensions. 202 // Resize to content's originally set dimensions.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); 246 EXPECT_TRUE(dialog_delegate->GetNativeDialog());
244 EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents)); 247 EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents));
245 248
246 // Wait until the entire WebContents has loaded. 249 // Wait until the entire WebContents has loaded.
247 WaitForLoadStop(dialog_delegate->GetWebContents()); 250 WaitForLoadStop(dialog_delegate->GetWebContents());
248 251
249 gfx::Size initial_dialog_size; 252 gfx::Size initial_dialog_size;
250 delegate->GetDialogSize(&initial_dialog_size); 253 delegate->GetDialogSize(&initial_dialog_size);
251 254
252 // Check for initial sizing. Dialog was created as a 400x400 dialog. 255 // Check for initial sizing. Dialog was created as a 400x400 dialog.
253 EXPECT_EQ(gfx::Size(), web_contents->GetPreferredSize());
254 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize()); 256 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize());
255 257
256 // Resize <body> to dimension smaller than dialog. 258 // Resize <body> to dimension smaller than dialog.
257 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), 259 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(),
258 GetChangeDimensionsScript(100))); 260 GetChangeDimensionsScript(100)));
259 ASSERT_TRUE(RunLoopUntil(base::Bind( 261 ASSERT_TRUE(RunLoopUntil(base::Bind(
260 &IsEqualSizes, 262 &IsEqualSizes,
261 initial_dialog_size, 263 initial_dialog_size,
262 dialog_delegate))); 264 dialog_delegate)));
263 265
264 // Resize <body> to dimension larger than dialog. 266 // Resize <body> to dimension larger than dialog.
265 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), 267 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(),
266 GetChangeDimensionsScript(500))); 268 GetChangeDimensionsScript(500)));
267 ASSERT_TRUE(RunLoopUntil(base::Bind( 269 ASSERT_TRUE(RunLoopUntil(base::Bind(
268 &IsEqualSizes, 270 &IsEqualSizes,
269 initial_dialog_size, 271 initial_dialog_size,
270 dialog_delegate))); 272 dialog_delegate)));
271 } 273 }
272 #endif // !OS_MACOSX
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/constrained_web_dialog_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698