Chromium Code Reviews| Index: chrome/browser/ui/panels/panel_browsertest.cc |
| diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc |
| index 382642ccdf36a36fb05c7138447480a3873d1047..5cedcdd1a9eca25d4f8158d224d5b3bf56cd716c 100644 |
| --- a/chrome/browser/ui/panels/panel_browsertest.cc |
| +++ b/chrome/browser/ui/panels/panel_browsertest.cc |
| @@ -9,6 +9,7 @@ |
| #include "chrome/browser/net/url_request_mock_util.h" |
| #include "chrome/browser/prefs/pref_service.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/tabs/tab_strip_model.h" |
| #include "chrome/browser/ui/browser_list.h" |
| #include "chrome/browser/ui/browser_window.h" |
| #include "chrome/browser/ui/find_bar/find_bar.h" |
| @@ -847,11 +848,12 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, AutoResize) { |
| L"changeSize(50);")); |
| // Wait until the bounds get changed. |
| - gfx::Rect bounds_on_grow; |
| - while ((bounds_on_grow = panel->GetBounds()) == initial_bounds) { |
| + while (panel->GetBounds() == initial_bounds) { |
| MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| MessageLoop::current()->RunAllPending(); |
| } |
| + WaitForBoundsAnimationFinished(panel); |
| + gfx::Rect bounds_on_grow = panel->GetBounds(); |
| EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); |
| EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height()); |
| @@ -862,11 +864,12 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, AutoResize) { |
| L"changeSize(-30);")); |
| // Wait until the bounds get changed. |
| - gfx::Rect bounds_on_shrink; |
| - while ((bounds_on_shrink = panel->GetBounds()) == bounds_on_grow) { |
| + while (panel->GetBounds() == bounds_on_grow) { |
| MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| MessageLoop::current()->RunAllPending(); |
| } |
| + WaitForBoundsAnimationFinished(panel); |
| + gfx::Rect bounds_on_shrink = panel->GetBounds(); |
| 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()); |
| @@ -1391,6 +1394,70 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, |
| panel_other->Close(); |
| } |
| +IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateWithExistingContents) { |
| + PanelManager::GetInstance()->enable_auto_sizing(true); |
| + |
| + // Load contents into regular tabbed browser. |
| + GURL url(ui_test_utils::GetTestUrl( |
| + FilePath(FilePath::kCurrentDirectory), |
| + FilePath(FILE_PATH_LITERAL("update-preferred-size.html")))); |
| + ui_test_utils::NavigateToURL(browser(), url); |
| + EXPECT_EQ(1, browser()->tab_count()); |
| + |
| + Profile* profile = browser()->profile(); |
| + Browser* panel_browser = Browser::CreateForApp( |
| + Browser::TYPE_PANEL, "SwapIntoMe", gfx::Rect(0, 0, 100, 100), profile); |
| + Panel* panel = static_cast<Panel*>(panel_browser->window()); |
| + EXPECT_EQ(2U, BrowserList::size()); |
| + |
| + // Swap tab contents over to the panel from the browser. |
|
jianli
2011/11/11 22:31:23
browser => tabbed browser
jennb
2011/11/11 22:42:50
Done.
|
| + TabContentsWrapper* contents = |
| + browser()->tabstrip_model()->DetachTabContentsAt(0); |
| + panel_browser->tabstrip_model()->InsertTabContentsAt( |
| + 0, contents, TabStripModel::ADD_NONE); |
| + panel_browser->SelectNumberedTab(0); |
| + MessageLoopForUI::current()->RunAllPending(); |
| + EXPECT_EQ(contents, panel_browser->GetSelectedTabContentsWrapper()); |
| + EXPECT_EQ(1, PanelManager::GetInstance()->num_panels()); |
| + |
| + panel->Show(); |
| + WaitForWindowSizeAvailable(panel); |
| + WaitForBoundsAnimationFinished(panel); |
| + |
| + // Ensure that the tab contents were noticed by the panel by |
| + // verifying that the panel auto resizes correctly. (Panel |
| + // enables auto resizing when tab contents are detected.) |
| + gfx::Rect initial_bounds = panel->GetBounds(); |
| + EXPECT_LE(100, initial_bounds.width()); |
| + EXPECT_LE(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);")); |
| + while (panel->GetBounds() == initial_bounds) { |
| + MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| + MessageLoop::current()->RunAllPending(); |
| + } |
| + WaitForBoundsAnimationFinished(panel); |
| + gfx::Rect bounds_on_grow = panel->GetBounds(); |
| + EXPECT_GT(bounds_on_grow.width(), initial_bounds.width()); |
| + EXPECT_EQ(bounds_on_grow.height(), initial_bounds.height()); |
| + |
| + // Swapping tab contents back to the browser should close the panel. |
| + ui_test_utils::WindowedNotificationObserver signal( |
| + chrome::NOTIFICATION_BROWSER_CLOSED, |
| + content::Source<Browser>(panel_browser)); |
| + panel_browser->ConvertPopupToTabbedBrowser(); |
| + signal.Wait(); |
| + EXPECT_EQ(0, PanelManager::GetInstance()->num_panels()); |
| + |
| + Browser* tabbed_browser = BrowserList::FindTabbedBrowser(profile, false); |
| + EXPECT_EQ(contents, tabbed_browser->GetSelectedTabContentsWrapper()); |
| + tabbed_browser->window()->Close(); |
| +} |
| + |
| class PanelDownloadTest : public PanelBrowserTest { |
| public: |
| PanelDownloadTest() : PanelBrowserTest() { } |