Index: chrome/browser/ui/panels/panel_browser_view_browsertest.cc |
=================================================================== |
--- chrome/browser/ui/panels/panel_browser_view_browsertest.cc (revision 94932) |
+++ chrome/browser/ui/panels/panel_browser_view_browsertest.cc (working copy) |
@@ -13,11 +13,14 @@ |
#include "chrome/browser/ui/panels/panel_browser_view.h" |
#include "chrome/browser/ui/panels/panel_manager.h" |
#include "chrome/browser/ui/panels/panel_mouse_watcher_win.h" |
+#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
#include "chrome/browser/web_applications/web_app.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/extensions/extension.h" |
#include "chrome/test/base/in_process_browser_test.h" |
+#include "chrome/test/base/ui_test_utils.h" |
#include "grit/generated_resources.h" |
+#include "net/base/net_util.h" |
#include "ui/base/l10n/l10n_util.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "ui/base/animation/slide_animation.h" |
@@ -28,11 +31,15 @@ |
#include "views/controls/link.h" |
#include "views/controls/textfield/textfield.h" |
+const FilePath::CharType* kUpdateSizeTestFile = |
+ FILE_PATH_LITERAL("update-preferred-size.html"); |
+ |
class PanelBrowserViewTest : public InProcessBrowserTest { |
public: |
PanelBrowserViewTest() : InProcessBrowserTest() { } |
virtual void SetUpCommandLine(CommandLine* command_line) { |
+ EnableDOMAutomation(); |
command_line->AppendSwitch(switches::kEnablePanels); |
} |
@@ -443,6 +450,63 @@ |
panel->Close(); |
} |
+ |
+ void TestUpdatePreferredSize() { |
+ // Create a test panel with tab contents loaded. |
+ Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, |
+ "PanelTest", |
+ gfx::Rect(0, 0, 100, 100), |
+ browser()->profile()); |
+ |
+ panel_browser->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), |
+ PageTransition::START_PAGE); |
+ ui_test_utils::WaitForNavigation( |
+ &panel_browser->GetSelectedTabContents()->controller()); |
+ |
+ Panel* panel = static_cast<Panel*>(panel_browser->window()); |
+ panel->Show(); |
+ |
+ // Load the test page. |
+ ui_test_utils::NavigateToURL(panel_browser, |
+ ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), |
+ FilePath(kUpdateSizeTestFile))); |
+ gfx::Rect initial_bounds = panel->GetBounds(); |
+ EXPECT_EQ(100, initial_bounds.width()); |
+ EXPECT_EQ(100, initial_bounds.height()); |
+ |
+ // Expand the test page. |
+ EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
+ panel_browser->GetSelectedTabContents()->render_view_host(), |
+ std::wstring(), |
+ L"changeSize(50);")); |
+ |
+ // Wait till the bounds get changed. |
+ gfx::Rect bounds_on_grow; |
+ while ((bounds_on_grow = panel->GetBounds()) == initial_bounds) { |
+ MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
+ MessageLoop::current()->RunAllPending(); |
+ } |
+ EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); |
+ EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height()); |
+ |
+ // Shrink the test page. |
+ EXPECT_TRUE(ui_test_utils::ExecuteJavaScript( |
+ panel_browser->GetSelectedTabContents()->render_view_host(), |
+ std::wstring(), |
+ L"changeSize(-30);")); |
+ |
+ // Wait till the bounds get changed. |
+ gfx::Rect bounds_on_shrink; |
+ while ((bounds_on_shrink = panel->GetBounds()) == bounds_on_grow) { |
+ MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
+ MessageLoop::current()->RunAllPending(); |
+ } |
+ EXPECT_LT(bounds_on_shrink.width(), bounds_on_grow.width()); |
+ EXPECT_GT(bounds_on_shrink.width(), initial_bounds.width()); |
+ EXPECT_EQ(bounds_on_shrink.height(), initial_bounds.height()); |
+ |
+ panel->Close(); |
+ } |
}; |
// Panel is not supported for Linux view yet. |
@@ -758,4 +822,8 @@ |
IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, DrawAttention) { |
TestDrawAttention(); |
} |
+ |
+IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, UpdatePreferredSize) { |
+ TestUpdatePreferredSize(); |
+} |
#endif |