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 8b146beab6fe09858c1248c059d139b15f2a3554..becc8905cd3f6095841c642d1bf3bd31443d2095 100644 |
--- a/chrome/browser/ui/panels/panel_browsertest.cc |
+++ b/chrome/browser/ui/panels/panel_browsertest.cc |
@@ -16,6 +16,7 @@ |
#include "chrome/browser/prefs/browser_prefs.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" |
@@ -856,11 +857,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) { |
Paweł Hajdan Jr.
2011/11/14 12:24:33
Ouch, this is generally bad style (running Message
|
MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
Paweł Hajdan Jr.
2011/11/14 12:24:33
By the way, I think this QuitTask is redundant wit
|
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()); |
@@ -871,11 +873,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()); |
@@ -1400,6 +1403,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 tabbed browser. |
+ 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) { |
Paweł Hajdan Jr.
2011/11/14 12:24:33
Ah, and here the bad code is being repeated. This
|
+ 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() { } |
@@ -1724,14 +1791,12 @@ IN_PROC_BROWSER_TEST_F(PanelAndNotificationTest, NoOverlapping) { |
// Closing short panel should move the notification balloon down to the same |
// position when tall panel brings up its titlebar. |
- panel1->Close(); |
- WaitForBoundsAnimationFinished(panel1); |
+ CloseWindowAndWait(panel1->browser()); |
EXPECT_EQ(balloon_bottom_after_tall_panel_titlebar_up, |
GetBalloonBottomPosition(balloon)); |
// Closing the remaining tall panel should move the notification balloon back |
// to its original position. |
- panel2->Close(); |
- WaitForBoundsAnimationFinished(panel2); |
+ CloseWindowAndWait(panel2->browser()); |
EXPECT_EQ(original_balloon_bottom, GetBalloonBottomPosition(balloon)); |
} |