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

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

Issue 1446623003: [Reland] Enable AutoResize for Constrained Web Dialogs for Mac. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix browser tests. Created 4 years, 10 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/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 // OSX windows are initially created with non-empty dimensions. The
174 // autoresizeable dialog's window dimensions are determined after initial
175 // creation.
Nico 2016/02/04 22:28:29 is there any harm in setting this to 1, 1 on all p
apacible 2016/02/05 03:46:00 The initial dialog size for views is empty since t
176 #if defined(OS_MACOSX)
177 initial_dialog_size = gfx::Size(1, 1);
178 #endif
176 delegate->GetDialogSize(&initial_dialog_size); 179 delegate->GetDialogSize(&initial_dialog_size);
177 180
178 ConstrainedWebDialogDelegate* dialog_delegate = 181 ConstrainedWebDialogDelegate* dialog_delegate =
179 ShowConstrainedWebDialogWithAutoResize(browser()->profile(), delegate, 182 ShowConstrainedWebDialogWithAutoResize(browser()->profile(), delegate,
180 web_contents, min_size, 183 web_contents, min_size,
181 max_size); 184 max_size);
182 ASSERT_TRUE(dialog_delegate); 185 ASSERT_TRUE(dialog_delegate);
183 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); 186 EXPECT_TRUE(dialog_delegate->GetNativeDialog());
184 ASSERT_FALSE(IsShowingWebContentsModalDialog(web_contents)); 187 ASSERT_FALSE(IsShowingWebContentsModalDialog(web_contents));
185 EXPECT_EQ(min_size, dialog_delegate->GetMinimumSize()); 188 EXPECT_EQ(min_size, dialog_delegate->GetMinimumSize());
186 EXPECT_EQ(max_size, dialog_delegate->GetMaximumSize()); 189 EXPECT_EQ(max_size, dialog_delegate->GetMaximumSize());
187 190
188 // Check for initial sizing. Dialog was created as a 400x400 dialog. 191 // 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()); 192 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize());
191 193
192 observer.Wait(); 194 observer.Wait();
193 195
194 // Wait until the entire WebContents has loaded. 196 // Wait until the entire WebContents has loaded.
195 WaitForLoadStop(dialog_delegate->GetWebContents()); 197 WaitForLoadStop(dialog_delegate->GetWebContents());
196 198
197 ASSERT_TRUE(IsShowingWebContentsModalDialog(web_contents)); 199 ASSERT_TRUE(IsShowingWebContentsModalDialog(web_contents));
198 200
199 // Resize to content's originally set dimensions. 201 // 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()); 245 EXPECT_TRUE(dialog_delegate->GetNativeDialog());
244 EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents)); 246 EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents));
245 247
246 // Wait until the entire WebContents has loaded. 248 // Wait until the entire WebContents has loaded.
247 WaitForLoadStop(dialog_delegate->GetWebContents()); 249 WaitForLoadStop(dialog_delegate->GetWebContents());
248 250
249 gfx::Size initial_dialog_size; 251 gfx::Size initial_dialog_size;
250 delegate->GetDialogSize(&initial_dialog_size); 252 delegate->GetDialogSize(&initial_dialog_size);
251 253
252 // Check for initial sizing. Dialog was created as a 400x400 dialog. 254 // 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()); 255 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize());
255 256
256 // Resize <body> to dimension smaller than dialog. 257 // Resize <body> to dimension smaller than dialog.
257 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), 258 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(),
258 GetChangeDimensionsScript(100))); 259 GetChangeDimensionsScript(100)));
259 ASSERT_TRUE(RunLoopUntil(base::Bind( 260 ASSERT_TRUE(RunLoopUntil(base::Bind(
260 &IsEqualSizes, 261 &IsEqualSizes,
261 initial_dialog_size, 262 initial_dialog_size,
262 dialog_delegate))); 263 dialog_delegate)));
263 264
264 // Resize <body> to dimension larger than dialog. 265 // Resize <body> to dimension larger than dialog.
265 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), 266 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(),
266 GetChangeDimensionsScript(500))); 267 GetChangeDimensionsScript(500)));
267 ASSERT_TRUE(RunLoopUntil(base::Bind( 268 ASSERT_TRUE(RunLoopUntil(base::Bind(
268 &IsEqualSizes, 269 &IsEqualSizes,
269 initial_dialog_size, 270 initial_dialog_size,
270 dialog_delegate))); 271 dialog_delegate)));
271 } 272 }
272 #endif // !OS_MACOSX
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698