| Index: chrome/browser/ui/webui/constrained_web_dialog_ui_browsertest.cc
|
| diff --git a/chrome/browser/ui/webui/constrained_web_dialog_ui_browsertest.cc b/chrome/browser/ui/webui/constrained_web_dialog_ui_browsertest.cc
|
| index 5570984094b8f76ba6d46db87a6e54f4e11814d3..521169043209706c668227a94a3ba2fdb0c97a19 100644
|
| --- a/chrome/browser/ui/webui/constrained_web_dialog_ui_browsertest.cc
|
| +++ b/chrome/browser/ui/webui/constrained_web_dialog_ui_browsertest.cc
|
| @@ -2,6 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "base/callback.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/ui/browser.h"
|
| @@ -12,6 +13,8 @@
|
| #include "components/web_modal/web_contents_modal_dialog_manager.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "content/public/browser/web_contents_observer.h"
|
| +#include "content/public/test/browser_test_utils.h"
|
| +#include "content/public/test/test_navigation_observer.h"
|
| #include "ui/web_dialogs/test/test_web_dialog_delegate.h"
|
|
|
| using content::WebContents;
|
| @@ -43,6 +46,30 @@ class ConstrainedWebDialogBrowserTest : public InProcessBrowserTest {
|
| public:
|
| ConstrainedWebDialogBrowserTest() {}
|
|
|
| + bool IsEqualSizes(gfx::Size expected,
|
| + ConstrainedWebDialogDelegate* dialog_delegate) {
|
| + return expected == dialog_delegate->GetPreferredSize();
|
| + }
|
| +
|
| + // Runs the current MessageLoop until |condition| is true or timeout.
|
| + bool RunLoopUntil(const base::Callback<bool()>& condition) {
|
| + const base::TimeTicks start_time = base::TimeTicks::Now();
|
| + while (!condition.Run()) {
|
| + const base::TimeTicks current_time = base::TimeTicks::Now();
|
| + if (current_time - start_time > base::TimeDelta::FromSeconds(5)) {
|
| + ADD_FAILURE() << "Condition not met within five seconds.";
|
| + return false;
|
| + }
|
| +
|
| + base::MessageLoop::current()->PostDelayedTask(
|
| + FROM_HERE,
|
| + base::MessageLoop::QuitClosure(),
|
| + base::TimeDelta::FromMilliseconds(20));
|
| + content::RunMessageLoop();
|
| + }
|
| + return true;
|
| + }
|
| +
|
| protected:
|
| bool IsShowingWebContentsModalDialog(WebContents* web_contents) const {
|
| WebContentsModalDialogManager* web_contents_modal_dialog_manager =
|
| @@ -61,7 +88,7 @@ IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest, BasicTest) {
|
| ASSERT_TRUE(web_contents);
|
|
|
| ConstrainedWebDialogDelegate* dialog_delegate =
|
| - CreateConstrainedWebDialog(browser()->profile(), delegate, web_contents);
|
| + ShowConstrainedWebDialog(browser()->profile(), delegate, web_contents);
|
| ASSERT_TRUE(dialog_delegate);
|
| EXPECT_TRUE(dialog_delegate->GetNativeDialog());
|
| EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents));
|
| @@ -78,7 +105,7 @@ IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest,
|
| ASSERT_TRUE(web_contents);
|
|
|
| ConstrainedWebDialogDelegate* dialog_delegate =
|
| - CreateConstrainedWebDialog(browser()->profile(), delegate, web_contents);
|
| + ShowConstrainedWebDialog(browser()->profile(), delegate, web_contents);
|
| ASSERT_TRUE(dialog_delegate);
|
| scoped_ptr<WebContents> new_tab(dialog_delegate->GetWebContents());
|
| ASSERT_TRUE(new_tab.get());
|
| @@ -93,3 +120,148 @@ IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest,
|
| new_tab.reset();
|
| EXPECT_TRUE(observer.contents_destroyed());
|
| }
|
| +
|
| +#if !defined(OS_MACOSX)
|
| +// Tests that dialog autoresizes based on web contents when autoresizing
|
| +// is enabled.
|
| +IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest,
|
| + ContentResizeInAutoResizingDialog) {
|
| + std::string url = "data:text/html,<!doctype html>"
|
| + "<body></body>"
|
| + "<style>"
|
| + "body { height: 150px; width: 150px; }"
|
| + "</style>"
|
| + "<script>"
|
| + " function changeDimensions(width, height) {"
|
| + " window.document.body.style.width = width + 'px';"
|
| + " window.document.body.style.height = height + 'px';"
|
| + " }"
|
| + " document.title='ready';"
|
| + "</script>";
|
| +
|
| + // The delegate deletes itself.
|
| + WebDialogDelegate* delegate = new ui::test::TestWebDialogDelegate(
|
| + GURL(url));
|
| + WebContents* web_contents =
|
| + browser()->tab_strip_model()->GetActiveWebContents();
|
| + ASSERT_TRUE(web_contents);
|
| +
|
| + // Observes the next created WebContents.
|
| + content::TestNavigationObserver observer(NULL);
|
| + observer.StartWatchingNewWebContents();
|
| +
|
| + gfx::Size min_size = gfx::Size(100, 100);
|
| + gfx::Size max_size = gfx::Size(200, 200);
|
| + ConstrainedWebDialogDelegate* dialog_delegate =
|
| + CreateConstrainedWebDialogWithAutoResize(browser()->profile(), delegate,
|
| + web_contents, min_size,
|
| + max_size);
|
| + ASSERT_TRUE(dialog_delegate);
|
| + EXPECT_TRUE(dialog_delegate->GetNativeDialog());
|
| + ASSERT_FALSE(IsShowingWebContentsModalDialog(web_contents));
|
| + EXPECT_EQ(min_size, dialog_delegate->GetMinimumSize());
|
| + EXPECT_EQ(max_size, dialog_delegate->GetMaximumSize());
|
| +
|
| + // Check for initial sizing. Dialog was created as a 400x400 dialog.
|
| + EXPECT_EQ(gfx::Size(), web_contents->GetPreferredSize());
|
| + ASSERT_EQ(gfx::Size(400, 400), dialog_delegate->GetPreferredSize());
|
| +
|
| + observer.Wait();
|
| +
|
| + // Wait until the entire WebContents has loaded.
|
| + base::string16 ready_title(base::ASCIIToUTF16("ready"));
|
| + content::TitleWatcher watcher(dialog_delegate->GetWebContents(),
|
| + ready_title);
|
| + ignore_result(watcher.WaitAndGetTitle());
|
| +
|
| + ASSERT_TRUE(IsShowingWebContentsModalDialog(web_contents));
|
| +
|
| + // Resize to content's originally set dimensions.
|
| + EXPECT_TRUE(RunLoopUntil(base::Bind(
|
| + &ConstrainedWebDialogBrowserTest::IsEqualSizes,
|
| + base::Unretained(this),
|
| + gfx::Size(166, 166),
|
| + dialog_delegate)));
|
| + ASSERT_EQ(gfx::Size(166, 166), dialog_delegate->GetPreferredSize());
|
| +
|
| + // Resize to dimensions within expected bounds.
|
| + EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(),
|
| + "changeDimensions(175, 175);"));
|
| + EXPECT_TRUE(RunLoopUntil(base::Bind(
|
| + &ConstrainedWebDialogBrowserTest::IsEqualSizes,
|
| + base::Unretained(this),
|
| + gfx::Size(191, 191),
|
| + dialog_delegate)));
|
| + ASSERT_EQ(gfx::Size(191, 191), dialog_delegate->GetPreferredSize());
|
| +
|
| + // Resize to dimensions smaller than the minimum bounds.
|
| + EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(),
|
| + "changeDimensions(50, 50);"));
|
| + EXPECT_TRUE(RunLoopUntil(base::Bind(
|
| + &ConstrainedWebDialogBrowserTest::IsEqualSizes,
|
| + base::Unretained(this),
|
| + gfx::Size(100, 100),
|
| + dialog_delegate)));
|
| + ASSERT_EQ(gfx::Size(100, 100), dialog_delegate->GetPreferredSize());
|
| +
|
| + // Resize to dimensions greater than the maximum bounds.
|
| + EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(),
|
| + "changeDimensions(250, 250);"));
|
| + EXPECT_TRUE(RunLoopUntil(base::Bind(
|
| + &ConstrainedWebDialogBrowserTest::IsEqualSizes,
|
| + base::Unretained(this),
|
| + gfx::Size(200, 200),
|
| + dialog_delegate)));
|
| + ASSERT_EQ(gfx::Size(200, 200), dialog_delegate->GetPreferredSize());
|
| +}
|
| +
|
| +// Tests that dialog does not autoresize when autoresizing is not enabled.
|
| +IN_PROC_BROWSER_TEST_F(ConstrainedWebDialogBrowserTest,
|
| + ContentResizeInNonAutoResizingDialog) {
|
| + std::string url = "data:text/html,<!doctype html>"
|
| + "<body></body>"
|
| + "<style>"
|
| + "body { height: 150px; width: 150px; }"
|
| + "</style>"
|
| + "<script>"
|
| + " function changeDimensions(width, height) {"
|
| + " window.document.body.style.width = width + 'px';"
|
| + " window.document.body.style.height = height + 'px';"
|
| + " }"
|
| + " document.title='ready';"
|
| + "</script>";
|
| +
|
| + // The delegate deletes itself.
|
| + WebDialogDelegate* delegate = new ui::test::TestWebDialogDelegate(
|
| + GURL(url));
|
| + WebContents* web_contents =
|
| + browser()->tab_strip_model()->GetActiveWebContents();
|
| + ASSERT_TRUE(web_contents);
|
| +
|
| + ConstrainedWebDialogDelegate* dialog_delegate =
|
| + ShowConstrainedWebDialog(browser()->profile(), delegate, web_contents);
|
| + ASSERT_TRUE(dialog_delegate);
|
| + EXPECT_TRUE(dialog_delegate->GetNativeDialog());
|
| + EXPECT_TRUE(IsShowingWebContentsModalDialog(web_contents));
|
| +
|
| + // Wait until the entire WebContents has loaded.
|
| + base::string16 ready_title(base::ASCIIToUTF16("ready"));
|
| + content::TitleWatcher watcher(dialog_delegate->GetWebContents(),
|
| + ready_title);
|
| + ignore_result(watcher.WaitAndGetTitle());
|
| +
|
| + // Check for initial sizing. Dialog was created as a 400x400 dialog.
|
| + EXPECT_EQ(gfx::Size(), web_contents->GetPreferredSize());
|
| + ASSERT_EQ(gfx::Size(400, 400), dialog_delegate->GetPreferredSize());
|
| +
|
| + // Resize <body> to dimension smaller than dialog.
|
| + EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(),
|
| + "changeDimensions(100, 100);"));
|
| + ASSERT_EQ(gfx::Size(400, 400), dialog_delegate->GetPreferredSize());
|
| +
|
| + // Resize <body> to dimension larger than dialog.
|
| + EXPECT_TRUE(ExecuteScript(dialog_delegate->GetWebContents(),
|
| + "changeDimensions(500, 500);"));
|
| + ASSERT_EQ(gfx::Size(400, 400), dialog_delegate->GetPreferredSize());
|
| +}
|
| +#endif
|
|
|