| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 dialog_delegate))); | 247 dialog_delegate))); |
| 251 | 248 |
| 252 // Resize <body> to dimension larger than dialog. | 249 // Resize <body> to dimension larger than dialog. |
| 253 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), | 250 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), |
| 254 GetChangeDimensionsScript(500))); | 251 GetChangeDimensionsScript(500))); |
| 255 ASSERT_TRUE(RunLoopUntil(base::Bind( | 252 ASSERT_TRUE(RunLoopUntil(base::Bind( |
| 256 &IsEqualSizes, | 253 &IsEqualSizes, |
| 257 initial_dialog_size, | 254 initial_dialog_size, |
| 258 dialog_delegate))); | 255 dialog_delegate))); |
| 259 } | 256 } |
| 260 #endif // !OS_MACOSX | |
| OLD | NEW |