| 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/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 class AutoResizingTestWebDialogDelegate | 64 class AutoResizingTestWebDialogDelegate |
| 65 : public ui::test::TestWebDialogDelegate { | 65 : public ui::test::TestWebDialogDelegate { |
| 66 public: | 66 public: |
| 67 explicit AutoResizingTestWebDialogDelegate(const GURL& url) | 67 explicit AutoResizingTestWebDialogDelegate(const GURL& url) |
| 68 : TestWebDialogDelegate(url) {} | 68 : TestWebDialogDelegate(url) {} |
| 69 ~AutoResizingTestWebDialogDelegate() override {} | 69 ~AutoResizingTestWebDialogDelegate() override {} |
| 70 | 70 |
| 71 // Dialog delegates for auto-resizing dialogs are expected not to set |size|. | 71 // Dialog delegates for auto-resizing dialogs are expected not to set |size|. |
| 72 void GetDialogSize(gfx::Size* size) const override {} | 72 void GetDialogSize(gfx::Size* size) const override {} |
| 73 |
| 74 ui::ModalType GetDialogModalType() const override { |
| 75 return ui::MODAL_TYPE_CHILD; |
| 76 } |
| 73 }; | 77 }; |
| 74 | 78 |
| 79 class ChildModalTestWebDialogDelegate |
| 80 : public ui::test::TestWebDialogDelegate { |
| 81 public: |
| 82 explicit ChildModalTestWebDialogDelegate(const GURL& url) |
| 83 : TestWebDialogDelegate(url) {} |
| 84 ~ChildModalTestWebDialogDelegate() override {} |
| 85 |
| 86 // Dialog is child modal |
| 87 ui::ModalType GetDialogModalType() const override { |
| 88 return ui::MODAL_TYPE_CHILD; |
| 89 } |
| 90 |
| 91 }; |
| 92 |
| 93 |
| 75 } // namespace | 94 } // namespace |
| 76 | 95 |
| 77 class ConstrainedWebDialogBrowserTest : public InProcessBrowserTest { | 96 class ConstrainedWebDialogBrowserTest : public InProcessBrowserTest { |
| 78 public: | 97 public: |
| 79 ConstrainedWebDialogBrowserTest() {} | 98 ConstrainedWebDialogBrowserTest() {} |
| 80 | 99 |
| 81 // Runs the current MessageLoop until |condition| is true or timeout. | 100 // Runs the current MessageLoop until |condition| is true or timeout. |
| 82 bool RunLoopUntil(const base::Callback<bool()>& condition) { | 101 bool RunLoopUntil(const base::Callback<bool()>& condition) { |
| 83 const base::TimeTicks start_time = base::TimeTicks::Now(); | 102 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 84 while (!condition.Run()) { | 103 while (!condition.Run()) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 100 bool IsShowingWebContentsModalDialog(WebContents* web_contents) const { | 119 bool IsShowingWebContentsModalDialog(WebContents* web_contents) const { |
| 101 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 120 WebContentsModalDialogManager* web_contents_modal_dialog_manager = |
| 102 WebContentsModalDialogManager::FromWebContents(web_contents); | 121 WebContentsModalDialogManager::FromWebContents(web_contents); |
| 103 return web_contents_modal_dialog_manager->IsDialogActive(); | 122 return web_contents_modal_dialog_manager->IsDialogActive(); |
| 104 } | 123 } |
| 105 }; | 124 }; |
| 106 | 125 |
| 107 // Tests that opening/closing the constrained window won't crash it. | 126 // Tests that opening/closing the constrained window won't crash it. |
| 108 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, BasicTest) { | 127 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, BasicTest) { |
| 109 // The delegate deletes itself. | 128 // The delegate deletes itself. |
| 110 WebDialogDelegate* delegate = new ui::test::TestWebDialogDelegate( | 129 WebDialogDelegate* delegate = new ChildModalTestWebDialogDelegate( |
| 111 GURL(chrome::kChromeUIConstrainedHTMLTestURL)); | 130 GURL(chrome::kChromeUIConstrainedHTMLTestURL)); |
| 112 WebContents* web_contents = | 131 WebContents* web_contents = |
| 113 browser()->tab_strip_model()->GetActiveWebContents(); | 132 browser()->tab_strip_model()->GetActiveWebContents(); |
| 114 ASSERT_TRUE(web_contents); | 133 ASSERT_TRUE(web_contents); |
| 115 | 134 |
| 116 ConstrainedWebDialogDelegate* dialog_delegate = | 135 ConstrainedWebDialogDelegate* dialog_delegate = |
| 117 ShowConstrainedWebDialog(browser()->profile(), delegate, web_contents); | 136 ShowConstrainedWebDialog(browser()->profile(), delegate, web_contents); |
| 118 ASSERT_TRUE(dialog_delegate); | 137 ASSERT_TRUE(dialog_delegate); |
| 119 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); | 138 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); |
| 120 EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents)); | 139 EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents)); |
| 121 } | 140 } |
| 122 | 141 |
| 123 // Tests that ReleaseWebContentsOnDialogClose() works. | 142 // Tests that ReleaseWebContentsOnDialogClose() works. |
| 124 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, | 143 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, |
| 125 ReleaseWebContentsOnDialogClose) { | 144 ReleaseWebContentsOnDialogClose) { |
| 126 // The delegate deletes itself. | 145 // The delegate deletes itself. |
| 127 WebDialogDelegate* delegate = new ui::test::TestWebDialogDelegate( | 146 WebDialogDelegate* delegate = new ChildModalTestWebDialogDelegate( |
| 128 GURL(chrome::kChromeUIConstrainedHTMLTestURL)); | 147 GURL(chrome::kChromeUIConstrainedHTMLTestURL)); |
| 129 WebContents* web_contents = | 148 WebContents* web_contents = |
| 130 browser()->tab_strip_model()->GetActiveWebContents(); | 149 browser()->tab_strip_model()->GetActiveWebContents(); |
| 131 ASSERT_TRUE(web_contents); | 150 ASSERT_TRUE(web_contents); |
| 132 | 151 |
| 133 ConstrainedWebDialogDelegate* dialog_delegate = | 152 ConstrainedWebDialogDelegate* dialog_delegate = |
| 134 ShowConstrainedWebDialog(browser()->profile(), delegate, web_contents); | 153 ShowConstrainedWebDialog(browser()->profile(), delegate, web_contents); |
| 135 ASSERT_TRUE(dialog_delegate); | 154 ASSERT_TRUE(dialog_delegate); |
| 136 std::unique_ptr<WebContents> new_tab(dialog_delegate->GetWebContents()); | 155 std::unique_ptr<WebContents> new_tab(dialog_delegate->GetWebContents()); |
| 137 ASSERT_TRUE(new_tab.get()); | 156 ASSERT_TRUE(new_tab.get()); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 &IsEqualSizes, | 249 &IsEqualSizes, |
| 231 max_size, | 250 max_size, |
| 232 dialog_delegate))); | 251 dialog_delegate))); |
| 233 } | 252 } |
| 234 | 253 |
| 235 // Tests that dialog does not autoresize when autoresizing is not enabled. | 254 // Tests that dialog does not autoresize when autoresizing is not enabled. |
| 236 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, | 255 IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, |
| 237 ContentResizeInNonAutoResizingDialog) { | 256 ContentResizeInNonAutoResizingDialog) { |
| 238 // The delegate deletes itself. | 257 // The delegate deletes itself. |
| 239 WebDialogDelegate* delegate = | 258 WebDialogDelegate* delegate = |
| 240 new ui::test::TestWebDialogDelegate(GURL(kTestDataURL)); | 259 new ChildModalTestWebDialogDelegate(GURL(kTestDataURL)); |
| 241 WebContents* web_contents = | 260 WebContents* web_contents = |
| 242 browser()->tab_strip_model()->GetActiveWebContents(); | 261 browser()->tab_strip_model()->GetActiveWebContents(); |
| 243 ASSERT_TRUE(web_contents); | 262 ASSERT_TRUE(web_contents); |
| 244 | 263 |
| 245 ConstrainedWebDialogDelegate* dialog_delegate = | 264 ConstrainedWebDialogDelegate* dialog_delegate = |
| 246 ShowConstrainedWebDialog(browser()->profile(), delegate, web_contents); | 265 ShowConstrainedWebDialog(browser()->profile(), delegate, web_contents); |
| 247 ASSERT_TRUE(dialog_delegate); | 266 ASSERT_TRUE(dialog_delegate); |
| 248 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); | 267 EXPECT_TRUE(dialog_delegate->GetNativeDialog()); |
| 249 EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents)); | 268 EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents)); |
| 250 | 269 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 266 dialog_delegate))); | 285 dialog_delegate))); |
| 267 | 286 |
| 268 // Resize <body> to dimension larger than dialog. | 287 // Resize <body> to dimension larger than dialog. |
| 269 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), | 288 EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(), |
| 270 GetChangeDimensionsScript(500))); | 289 GetChangeDimensionsScript(500))); |
| 271 ASSERT_TRUE(RunLoopUntil(base::Bind( | 290 ASSERT_TRUE(RunLoopUntil(base::Bind( |
| 272 &IsEqualSizes, | 291 &IsEqualSizes, |
| 273 initial_dialog_size, | 292 initial_dialog_size, |
| 274 dialog_delegate))); | 293 dialog_delegate))); |
| 275 } | 294 } |
| OLD | NEW |