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