OLD | NEW |
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) |
29 static const char kTestDataURL[] = "data:text/html,<!doctype html>" | 30 static const char kTestDataURL[] = "data:text/html,<!doctype html>" |
30 "<body></body>" | 31 "<body></body>" |
31 "<style>" | 32 "<style>" |
32 "body { height: 150px; width: 150px; }" | 33 "body { height: 150px; width: 150px; }" |
33 "</style>"; | 34 "</style>"; |
34 | 35 |
35 bool IsEqualSizes(gfx::Size expected, | 36 bool IsEqualSizes(gfx::Size expected, |
36 ConstrainedWebDialogDelegate* dialog_delegate) { | 37 ConstrainedWebDialogDelegate* dialog_delegate) { |
37 return expected == dialog_delegate->GetPreferredSize(); | 38 return expected == dialog_delegate->GetPreferredSize(); |
38 } | 39 } |
39 | 40 |
40 std::string GetChangeDimensionsScript(int dimension) { | 41 std::string GetChangeDimensionsScript(int dimension) { |
41 return base::StringPrintf("window.document.body.style.width = %d + 'px';" | 42 return base::StringPrintf("window.document.body.style.width = %d + 'px';" |
42 "window.document.body.style.height = %d + 'px';", dimension, dimension); | 43 "window.document.body.style.height = %d + 'px';", dimension, dimension); |
43 } | 44 } |
| 45 #endif |
44 | 46 |
45 class ConstrainedWebDialogBrowserTestObserver | 47 class ConstrainedWebDialogBrowserTestObserver |
46 : public content::WebContentsObserver { | 48 : public content::WebContentsObserver { |
47 public: | 49 public: |
48 explicit ConstrainedWebDialogBrowserTestObserver(WebContents* contents) | 50 explicit ConstrainedWebDialogBrowserTestObserver(WebContents* contents) |
49 : content::WebContentsObserver(contents), | 51 : content::WebContentsObserver(contents), |
50 contents_destroyed_(false) { | 52 contents_destroyed_(false) { |
51 } | 53 } |
52 ~ConstrainedWebDialogBrowserTestObserver() override {} | 54 ~ConstrainedWebDialogBrowserTestObserver() override {} |
53 | 55 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 ConstrainedWebDialogBrowserTestObserver observer(new_tab.get()); | 140 ConstrainedWebDialogBrowserTestObserver observer(new_tab.get()); |
139 dialog_delegate->ReleaseWebContentsOnDialogClose(); | 141 dialog_delegate->ReleaseWebContentsOnDialogClose(); |
140 dialog_delegate->OnDialogCloseFromWebUI(); | 142 dialog_delegate->OnDialogCloseFromWebUI(); |
141 | 143 |
142 ASSERT_FALSE(observer.contents_destroyed()); | 144 ASSERT_FALSE(observer.contents_destroyed()); |
143 EXPECT_FALSE(IsShowingWebContentsModalDialog(web_contents)); | 145 EXPECT_FALSE(IsShowingWebContentsModalDialog(web_contents)); |
144 new_tab.reset(); | 146 new_tab.reset(); |
145 EXPECT_TRUE(observer.contents_destroyed()); | 147 EXPECT_TRUE(observer.contents_destroyed()); |
146 } | 148 } |
147 | 149 |
| 150 #if !defined(OS_MACOSX) |
148 // Tests that dialog autoresizes based on web contents when autoresizing | 151 // Tests that dialog autoresizes based on web contents when autoresizing |
149 // is enabled. | 152 // is enabled. |
150 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, | 153 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, |
151 ContentResizeInAutoResizingDialog) { | 154 ContentResizeInAutoResizingDialog) { |
152 // During auto-resizing, dialogs size to (WebContents size) + 16. | 155 // During auto-resizing, dialogs size to (WebContents size) + 16. |
153 const int dialog_border_space = 16; | 156 const int dialog_border_space = 16; |
154 | 157 |
155 // Expected dialog sizes after auto-resizing. | 158 // Expected dialog sizes after auto-resizing. |
156 const int initial_size = 150 + dialog_border_space; | 159 const int initial_size = 150 + dialog_border_space; |
157 const int new_size = 175 + dialog_border_space; | 160 const int new_size = 175 + dialog_border_space; |
158 | 161 |
159 // The delegate deletes itself. | 162 // The delegate deletes itself. |
160 WebDialogDelegate* delegate = | 163 WebDialogDelegate* delegate = |
161 new AutoResizingTestWebDialogDelegate(GURL(kTestDataURL)); | 164 new AutoResizingTestWebDialogDelegate(GURL(kTestDataURL)); |
162 WebContents* web_contents = | 165 WebContents* web_contents = |
163 browser()->tab_strip_model()->GetActiveWebContents(); | 166 browser()->tab_strip_model()->GetActiveWebContents(); |
164 ASSERT_TRUE(web_contents); | 167 ASSERT_TRUE(web_contents); |
165 | 168 |
166 // Observes the next created WebContents. | 169 // Observes the next created WebContents. |
167 content::TestNavigationObserver observer(NULL); | 170 content::TestNavigationObserver observer(NULL); |
168 observer.StartWatchingNewWebContents(); | 171 observer.StartWatchingNewWebContents(); |
169 | 172 |
170 gfx::Size min_size = gfx::Size(100, 100); | 173 gfx::Size min_size = gfx::Size(100, 100); |
171 gfx::Size max_size = gfx::Size(200, 200); | 174 gfx::Size max_size = gfx::Size(200, 200); |
172 gfx::Size initial_dialog_size; | 175 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. | |
176 #if defined(OS_MACOSX) | |
177 initial_dialog_size = gfx::Size(1, 1); | |
178 #endif | |
179 delegate->GetDialogSize(&initial_dialog_size); | 176 delegate->GetDialogSize(&initial_dialog_size); |
180 | 177 |
181 ConstrainedWebDialogDelegate* dialog_delegate = | 178 ConstrainedWebDialogDelegate* dialog_delegate = |
182 ShowConstrainedWebDialogWithAutoResize(browser()->profile(), delegate, | 179 ShowConstrainedWebDialogWithAutoResize(browser()->profile(), delegate, |
183 web_contents, min_size, | 180 web_contents, min_size, |
184 max_size); | 181 max_size); |
185 ASSERT_TRUE(dialog_delegate); | 182 ASSERT_TRUE(dialog_delegate); |
186 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); | 183 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); |
187 ASSERT_FALSE(IsShowingWebContentsModalDialog(web_contents)); | 184 ASSERT_FALSE(IsShowingWebContentsModalDialog(web_contents)); |
188 EXPECT_EQ(min_size, dialog_delegate->GetMinimumSize()); | 185 EXPECT_EQ(min_size, dialog_delegate->GetMinimumSize()); |
189 EXPECT_EQ(max_size, dialog_delegate->GetMaximumSize()); | 186 EXPECT_EQ(max_size, dialog_delegate->GetMaximumSize()); |
190 | 187 |
191 // Check for initial sizing. Dialog was created as a 400x400 dialog. | 188 // Check for initial sizing. Dialog was created as a 400x400 dialog. |
| 189 EXPECT_EQ(gfx::Size(), web_contents->GetPreferredSize()); |
192 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize()); | 190 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize()); |
193 | 191 |
194 observer.Wait(); | 192 observer.Wait(); |
195 | 193 |
196 // Wait until the entire WebContents has loaded. | 194 // Wait until the entire WebContents has loaded. |
197 WaitForLoadStop(dialog_delegate->GetWebContents()); | 195 WaitForLoadStop(dialog_delegate->GetWebContents()); |
198 | 196 |
199 ASSERT_TRUE(IsShowingWebContentsModalDialog(web_contents)); | 197 ASSERT_TRUE(IsShowingWebContentsModalDialog(web_contents)); |
200 | 198 |
201 // Resize to content's originally set dimensions. | 199 // Resize to content's originally set dimensions. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); | 243 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); |
246 EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents)); | 244 EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents)); |
247 | 245 |
248 // Wait until the entire WebContents has loaded. | 246 // Wait until the entire WebContents has loaded. |
249 WaitForLoadStop(dialog_delegate->GetWebContents()); | 247 WaitForLoadStop(dialog_delegate->GetWebContents()); |
250 | 248 |
251 gfx::Size initial_dialog_size; | 249 gfx::Size initial_dialog_size; |
252 delegate->GetDialogSize(&initial_dialog_size); | 250 delegate->GetDialogSize(&initial_dialog_size); |
253 | 251 |
254 // Check for initial sizing. Dialog was created as a 400x400 dialog. | 252 // Check for initial sizing. Dialog was created as a 400x400 dialog. |
| 253 EXPECT_EQ(gfx::Size(), web_contents->GetPreferredSize()); |
255 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize()); | 254 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize()); |
256 | 255 |
257 // Resize <body> to dimension smaller than dialog. | 256 // Resize <body> to dimension smaller than dialog. |
258 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), | 257 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), |
259 GetChangeDimensionsScript(100))); | 258 GetChangeDimensionsScript(100))); |
260 ASSERT_TRUE(RunLoopUntil(base::Bind( | 259 ASSERT_TRUE(RunLoopUntil(base::Bind( |
261 &IsEqualSizes, | 260 &IsEqualSizes, |
262 initial_dialog_size, | 261 initial_dialog_size, |
263 dialog_delegate))); | 262 dialog_delegate))); |
264 | 263 |
265 // Resize <body> to dimension larger than dialog. | 264 // Resize <body> to dimension larger than dialog. |
266 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), | 265 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), |
267 GetChangeDimensionsScript(500))); | 266 GetChangeDimensionsScript(500))); |
268 ASSERT_TRUE(RunLoopUntil(base::Bind( | 267 ASSERT_TRUE(RunLoopUntil(base::Bind( |
269 &IsEqualSizes, | 268 &IsEqualSizes, |
270 initial_dialog_size, | 269 initial_dialog_size, |
271 dialog_delegate))); | 270 dialog_delegate))); |
272 } | 271 } |
| 272 #endif // !OS_MACOSX |
OLD | NEW |