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 "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" | 12 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h" |
13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
14 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
15 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 15 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
18 #include "content/public/test/browser_test_utils.h" | 18 #include "content/public/test/browser_test_utils.h" |
19 #include "content/public/test/test_navigation_observer.h" | 19 #include "content/public/test/test_navigation_observer.h" |
20 #include "ui/web_dialogs/test/test_web_dialog_delegate.h" | 20 #include "ui/web_dialogs/test/test_web_dialog_delegate.h" |
21 | 21 |
22 using content::WebContents; | 22 using content::WebContents; |
23 using ui::WebDialogDelegate; | 23 using ui::WebDialogDelegate; |
24 using web_modal::WebContentsModalDialogManager; | 24 using web_modal::WebContentsModalDialogManager; |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 #if !defined(OS_MACOSX) | |
29 static const char kTestDataURL[] = "data:text/html,<!doctype html>" | 28 static const char kTestDataURL[] = "data:text/html,<!doctype html>" |
30 "<body></body>" | 29 "<body></body>" |
31 "<style>" | 30 "<style>" |
32 "body { height: 150px; width: 150px; }" | 31 "body { height: 150px; width: 150px; }" |
33 "</style>"; | 32 "</style>"; |
34 | 33 |
35 bool IsEqualSizes(gfx::Size expected, | 34 bool IsEqualSizes(gfx::Size expected, |
36 ConstrainedWebDialogDelegate* dialog_delegate) { | 35 ConstrainedWebDialogDelegate* dialog_delegate) { |
37 return expected == dialog_delegate->GetPreferredSize(); | 36 return expected == dialog_delegate->GetPreferredSize(); |
38 } | 37 } |
39 | 38 |
40 std::string GetChangeDimensionsScript(int dimension) { | 39 std::string GetChangeDimensionsScript(int dimension) { |
41 return base::StringPrintf("window.document.body.style.width = %d + 'px';" | 40 return base::StringPrintf("window.document.body.style.width = %d + 'px';" |
42 "window.document.body.style.height = %d + 'px';", dimension, dimension); | 41 "window.document.body.style.height = %d + 'px';", dimension, dimension); |
43 } | 42 } |
44 #endif | |
45 | 43 |
46 class ConstrainedWebDialogBrowserTestObserver | 44 class ConstrainedWebDialogBrowserTestObserver |
47 : public content::WebContentsObserver { | 45 : public content::WebContentsObserver { |
48 public: | 46 public: |
49 explicit ConstrainedWebDialogBrowserTestObserver(WebContents* contents) | 47 explicit ConstrainedWebDialogBrowserTestObserver(WebContents* contents) |
50 : content::WebContentsObserver(contents), | 48 : content::WebContentsObserver(contents), |
51 contents_destroyed_(false) { | 49 contents_destroyed_(false) { |
52 } | 50 } |
53 ~ConstrainedWebDialogBrowserTestObserver() override {} | 51 ~ConstrainedWebDialogBrowserTestObserver() override {} |
54 | 52 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 ConstrainedWebDialogBrowserTestObserver observer(new_tab.get()); | 126 ConstrainedWebDialogBrowserTestObserver observer(new_tab.get()); |
129 dialog_delegate->ReleaseWebContentsOnDialogClose(); | 127 dialog_delegate->ReleaseWebContentsOnDialogClose(); |
130 dialog_delegate->OnDialogCloseFromWebUI(); | 128 dialog_delegate->OnDialogCloseFromWebUI(); |
131 | 129 |
132 ASSERT_FALSE(observer.contents_destroyed()); | 130 ASSERT_FALSE(observer.contents_destroyed()); |
133 EXPECT_FALSE(IsShowingWebContentsModalDialog(web_contents)); | 131 EXPECT_FALSE(IsShowingWebContentsModalDialog(web_contents)); |
134 new_tab.reset(); | 132 new_tab.reset(); |
135 EXPECT_TRUE(observer.contents_destroyed()); | 133 EXPECT_TRUE(observer.contents_destroyed()); |
136 } | 134 } |
137 | 135 |
138 #if !defined(OS_MACOSX) | |
139 // Tests that dialog autoresizes based on web contents when autoresizing | 136 // Tests that dialog autoresizes based on web contents when autoresizing |
140 // is enabled. | 137 // is enabled. |
141 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, | 138 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, |
142 ContentResizeInAutoResizingDialog) { | 139 ContentResizeInAutoResizingDialog) { |
143 // During auto-resizing, dialogs size to (WebContents size) + 16. | 140 // During auto-resizing, dialogs size to (WebContents size) + 16. |
144 const int dialog_border_space = 16; | 141 const int dialog_border_space = 16; |
145 | 142 |
146 // Expected dialog sizes after auto-resizing. | 143 // Expected dialog sizes after auto-resizing. |
147 const int initial_size = 150 + dialog_border_space; | 144 const int initial_size = 150 + dialog_border_space; |
148 const int new_size = 175 + dialog_border_space; | 145 const int new_size = 175 + dialog_border_space; |
(...skipping 18 matching lines...) Expand all Loading... | |
167 ShowConstrainedWebDialogWithAutoResize(browser()->profile(), delegate, | 164 ShowConstrainedWebDialogWithAutoResize(browser()->profile(), delegate, |
168 web_contents, min_size, | 165 web_contents, min_size, |
169 max_size); | 166 max_size); |
170 ASSERT_TRUE(dialog_delegate); | 167 ASSERT_TRUE(dialog_delegate); |
171 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); | 168 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); |
172 ASSERT_FALSE(IsShowingWebContentsModalDialog(web_contents)); | 169 ASSERT_FALSE(IsShowingWebContentsModalDialog(web_contents)); |
173 EXPECT_EQ(min_size, dialog_delegate->GetMinimumSize()); | 170 EXPECT_EQ(min_size, dialog_delegate->GetMinimumSize()); |
174 EXPECT_EQ(max_size, dialog_delegate->GetMaximumSize()); | 171 EXPECT_EQ(max_size, dialog_delegate->GetMaximumSize()); |
175 | 172 |
176 // Check for initial sizing. Dialog was created as a 400x400 dialog. | 173 // Check for initial sizing. Dialog was created as a 400x400 dialog. |
177 EXPECT_EQ(gfx::Size(), web_contents->GetPreferredSize()); | |
erikchen
2015/11/11 21:22:30
Why did you remove this expectation? At the very l
apacible
2015/11/12 02:02:24
Oops, returned.
apacible
2015/11/12 18:21:49
I remember why I'd removed it initially. In views,
| |
178 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize()); | 174 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize()); |
179 | 175 |
180 observer.Wait(); | 176 observer.Wait(); |
181 | 177 |
182 // Wait until the entire WebContents has loaded. | 178 // Wait until the entire WebContents has loaded. |
183 WaitForLoadStop(dialog_delegate->GetWebContents()); | 179 WaitForLoadStop(dialog_delegate->GetWebContents()); |
184 | 180 |
185 ASSERT_TRUE(IsShowingWebContentsModalDialog(web_contents)); | 181 ASSERT_TRUE(IsShowingWebContentsModalDialog(web_contents)); |
186 | 182 |
187 // Resize to content's originally set dimensions. | 183 // Resize to content's originally set dimensions. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); | 227 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); |
232 EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents)); | 228 EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents)); |
233 | 229 |
234 // Wait until the entire WebContents has loaded. | 230 // Wait until the entire WebContents has loaded. |
235 WaitForLoadStop(dialog_delegate->GetWebContents()); | 231 WaitForLoadStop(dialog_delegate->GetWebContents()); |
236 | 232 |
237 gfx::Size initial_dialog_size; | 233 gfx::Size initial_dialog_size; |
238 delegate->GetDialogSize(&initial_dialog_size); | 234 delegate->GetDialogSize(&initial_dialog_size); |
239 | 235 |
240 // Check for initial sizing. Dialog was created as a 400x400 dialog. | 236 // Check for initial sizing. Dialog was created as a 400x400 dialog. |
241 EXPECT_EQ(gfx::Size(), web_contents->GetPreferredSize()); | |
242 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize()); | 237 ASSERT_EQ(initial_dialog_size, dialog_delegate->GetPreferredSize()); |
243 | 238 |
244 // Resize <body> to dimension smaller than dialog. | 239 // Resize <body> to dimension smaller than dialog. |
245 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), | 240 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), |
246 GetChangeDimensionsScript(100))); | 241 GetChangeDimensionsScript(100))); |
247 ASSERT_TRUE(RunLoopUntil(base::Bind( | 242 ASSERT_TRUE(RunLoopUntil(base::Bind( |
248 &IsEqualSizes, | 243 &IsEqualSizes, |
249 initial_dialog_size, | 244 initial_dialog_size, |
250 dialog_delegate))); | 245 dialog_delegate))); |
251 | 246 |
252 // Resize <body> to dimension larger than dialog. | 247 // Resize <body> to dimension larger than dialog. |
253 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), | 248 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), |
254 GetChangeDimensionsScript(500))); | 249 GetChangeDimensionsScript(500))); |
255 ASSERT_TRUE(RunLoopUntil(base::Bind( | 250 ASSERT_TRUE(RunLoopUntil(base::Bind( |
256 &IsEqualSizes, | 251 &IsEqualSizes, |
257 initial_dialog_size, | 252 initial_dialog_size, |
258 dialog_delegate))); | 253 dialog_delegate))); |
259 } | 254 } |
260 #endif // !OS_MACOSX | |
OLD | NEW |