Index: chrome/browser/ui/panels/panel_browser_view_browsertest.cc |
=================================================================== |
--- chrome/browser/ui/panels/panel_browser_view_browsertest.cc (revision 97392) |
+++ chrome/browser/ui/panels/panel_browser_view_browsertest.cc (working copy) |
@@ -2,11 +2,12 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "base/command_line.h" |
+#include "chrome/browser/ui/panels/base_panel_browser_test.h" |
+ |
#include "base/i18n/time_formatting.h" |
+#include "base/memory/scoped_ptr.h" |
#include "chrome/browser/extensions/extension_service.h" |
#include "chrome/browser/profiles/profile.h" |
-#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_window.h" |
#include "chrome/browser/ui/panels/panel.h" |
#include "chrome/browser/ui/panels/panel_browser_frame_view.h" |
@@ -16,7 +17,6 @@ |
#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 "grit/generated_resources.h" |
#include "ui/base/l10n/l10n_util.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -28,14 +28,10 @@ |
#include "views/controls/link.h" |
#include "views/controls/textfield/textfield.h" |
-class PanelBrowserViewTest : public InProcessBrowserTest { |
+class PanelBrowserViewTest : public BasePanelBrowserTest { |
public: |
- PanelBrowserViewTest() : InProcessBrowserTest() { } |
+ PanelBrowserViewTest() : BasePanelBrowserTest() { } |
- virtual void SetUpCommandLine(CommandLine* command_line) { |
- command_line->AppendSwitch(switches::kEnablePanels); |
- } |
- |
protected: |
struct MenuItem { |
int id; |
@@ -71,19 +67,9 @@ |
bool is_cursor_in_view_; |
}; |
- enum ShowFlag { SHOW_AS_ACTIVE, SHOW_AS_INACTIVE }; |
- |
PanelBrowserView* CreatePanelBrowserView(const std::string& panel_name, |
ShowFlag show_flag) { |
- Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, |
- panel_name, |
- gfx::Rect(), |
- browser()->profile()); |
- Panel* panel = static_cast<Panel*>(panel_browser->window()); |
- if (show_flag == SHOW_AS_ACTIVE) |
- panel->Show(); |
- else |
- panel->ShowInactive(); |
+ Panel* panel = CreatePanel(panel_name, gfx::Rect(), show_flag); |
return static_cast<PanelBrowserView*>(panel->native_panel()); |
} |
@@ -119,31 +105,17 @@ |
const std::string& homepage_url, |
const std::string& options_page) { |
// Creates a testing extension. |
-#if defined(OS_WIN) |
- FilePath full_path(FILE_PATH_LITERAL("c:\\")); |
-#else |
- FilePath full_path(FILE_PATH_LITERAL("/")); |
-#endif |
- full_path = full_path.Append(path); |
- DictionaryValue input_value; |
- input_value.SetString(extension_manifest_keys::kVersion, "1.0.0.0"); |
- input_value.SetString(extension_manifest_keys::kName, "Sample Extension"); |
+ DictionaryValue extra_value; |
if (!homepage_url.empty()) { |
- input_value.SetString(extension_manifest_keys::kHomepageURL, |
+ extra_value.SetString(extension_manifest_keys::kHomepageURL, |
homepage_url); |
} |
if (!options_page.empty()) { |
- input_value.SetString(extension_manifest_keys::kOptionsPage, |
+ extra_value.SetString(extension_manifest_keys::kOptionsPage, |
options_page); |
} |
- std::string error; |
- scoped_refptr<Extension> extension = Extension::Create( |
- full_path, location, input_value, Extension::STRICT_ERROR_CHECKS, |
- &error); |
- ASSERT_TRUE(extension.get()); |
- EXPECT_STREQ("", error.c_str()); |
- browser()->GetProfile()->GetExtensionService()->OnLoadSingleExtension( |
- extension.get(), false); |
+ scoped_refptr<Extension> extension = CreateExtension( |
+ path, location, extra_value); |
// Creates a panel with the app name that comes from the extension ID. |
PanelBrowserView* browser_view = CreatePanelBrowserView( |
@@ -200,7 +172,16 @@ |
// We put all the testing logic in this class instead of the test so that |
// we do not need to declare each new test as a friend of PanelBrowserView |
// for the purpose of accessing its private members. |
- void TestMinimizeAndRestore() { |
+ void TestMinimizeAndRestore(bool enable_auto_hide) { |
+ PanelManager* panel_manager = PanelManager::GetInstance(); |
+ |
+ // Setup the mock bottom bar. |
+ mock_auto_hide_bottom_bar()->enable_auto_hide(enable_auto_hide); |
+ int expected_bottom_on_unminimized = |
+ testing_work_area().height() - mock_auto_hide_bottom_bar()->GetHeight(); |
+ int expected_bottom_on_minimized = testing_work_area().height(); |
+ |
+ // Create and test one panel first. |
PanelBrowserView* browser_view1 = CreatePanelBrowserView("PanelTest1", |
SHOW_AS_ACTIVE); |
Panel* panel1 = browser_view1->panel_.get(); |
@@ -216,6 +197,7 @@ |
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
EXPECT_LT(panel1->GetBounds().height(), titlebar_height); |
EXPECT_GT(panel1->GetBounds().height(), 0); |
+ EXPECT_EQ(expected_bottom_on_minimized, panel1->GetBounds().bottom()); |
EXPECT_TRUE(IsMouseWatcherStarted()); |
EXPECT_FALSE(panel1->IsActive()); |
WaitTillBoundsAnimationFinished(browser_view1); |
@@ -223,6 +205,7 @@ |
panel1->SetExpansionState(Panel::TITLE_ONLY); |
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
EXPECT_EQ(titlebar_height, panel1->GetBounds().height()); |
+ EXPECT_EQ(expected_bottom_on_unminimized, panel1->GetBounds().bottom()); |
WaitTillBoundsAnimationFinished(browser_view1); |
EXPECT_TRUE(frame_view1->close_button_->IsVisible()); |
EXPECT_TRUE(frame_view1->title_icon_->IsVisible()); |
@@ -231,6 +214,7 @@ |
panel1->SetExpansionState(Panel::EXPANDED); |
EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); |
EXPECT_EQ(initial_height, panel1->GetBounds().height()); |
+ EXPECT_EQ(expected_bottom_on_unminimized, panel1->GetBounds().bottom()); |
WaitTillBoundsAnimationFinished(browser_view1); |
EXPECT_TRUE(frame_view1->close_button_->IsVisible()); |
EXPECT_TRUE(frame_view1->title_icon_->IsVisible()); |
@@ -239,11 +223,13 @@ |
panel1->SetExpansionState(Panel::TITLE_ONLY); |
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
EXPECT_EQ(titlebar_height, panel1->GetBounds().height()); |
+ EXPECT_EQ(expected_bottom_on_unminimized, panel1->GetBounds().bottom()); |
panel1->SetExpansionState(Panel::MINIMIZED); |
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
EXPECT_LT(panel1->GetBounds().height(), titlebar_height); |
EXPECT_GT(panel1->GetBounds().height(), 0); |
+ EXPECT_EQ(expected_bottom_on_minimized, panel1->GetBounds().bottom()); |
// Create 2 more panels for more testing. |
PanelBrowserView* browser_view2 = CreatePanelBrowserView("PanelTest2", |
@@ -259,39 +245,41 @@ |
panel3->SetExpansionState(Panel::MINIMIZED); |
EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); |
- PanelManager* panel_manager = PanelManager::GetInstance(); |
- |
- panel_manager->BringUpOrDownTitlebarForAllMinimizedPanels(true); |
+ mock_auto_hide_bottom_bar()->SetVisibility(AutoHideBottomBar::VISIBLE); |
+ panel_manager->BringUpOrDownTitlebars(true); |
+ MessageLoop::current()->RunAllPending(); |
EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); |
EXPECT_EQ(Panel::TITLE_ONLY, panel3->expansion_state()); |
- panel_manager->BringUpOrDownTitlebarForAllMinimizedPanels(false); |
+ mock_auto_hide_bottom_bar()->SetVisibility(AutoHideBottomBar::HIDDEN); |
+ panel_manager->BringUpOrDownTitlebars(false); |
+ MessageLoop::current()->RunAllPending(); |
EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); |
EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); |
// Test if it is OK to bring up title-bar given the mouse position. |
- EXPECT_TRUE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( |
+ EXPECT_TRUE(panel_manager->ShouldBringUpTitlebars( |
panel1->GetBounds().x(), panel1->GetBounds().y())); |
- EXPECT_FALSE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( |
+ EXPECT_FALSE(panel_manager->ShouldBringUpTitlebars( |
panel2->GetBounds().x(), panel2->GetBounds().y())); |
- EXPECT_TRUE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( |
+ EXPECT_TRUE(panel_manager->ShouldBringUpTitlebars( |
panel3->GetBounds().right() - 1, panel3->GetBounds().bottom() - 1)); |
- EXPECT_TRUE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( |
+ EXPECT_TRUE(panel_manager->ShouldBringUpTitlebars( |
panel3->GetBounds().right() - 1, panel3->GetBounds().bottom() + 10)); |
- EXPECT_FALSE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( |
+ EXPECT_FALSE(panel_manager->ShouldBringUpTitlebars( |
0, 0)); |
// Test that the panel in title-only state should not be minimized |
// regardless of the current mouse position when the panel is being dragged. |
panel1->SetExpansionState(Panel::TITLE_ONLY); |
- EXPECT_FALSE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( |
+ EXPECT_FALSE(panel_manager->ShouldBringUpTitlebars( |
0, 0)); |
browser_view1->OnTitlebarMousePressed(panel1->GetBounds().origin()); |
browser_view1->OnTitlebarMouseDragged( |
panel1->GetBounds().origin().Subtract(gfx::Point(5, 5))); |
- EXPECT_TRUE(panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( |
+ EXPECT_TRUE(panel_manager->ShouldBringUpTitlebars( |
0, 0)); |
browser_view1->OnTitlebarMouseReleased(); |
@@ -345,12 +333,10 @@ |
// Test that we cannot bring up other minimized panel if the mouse is over |
// the panel that draws attension. |
EXPECT_FALSE(PanelManager::GetInstance()-> |
- ShouldBringUpTitlebarForAllMinimizedPanels( |
- panel->GetBounds().x(), panel->GetBounds().y())); |
+ ShouldBringUpTitlebars(panel->GetBounds().x(), panel->GetBounds().y())); |
// Test that we cannot bring down the panel that is drawing the attention. |
- PanelManager::GetInstance()->BringUpOrDownTitlebarForAllMinimizedPanels( |
- false); |
+ PanelManager::GetInstance()->BringUpOrDownTitlebars(false); |
EXPECT_EQ(Panel::TITLE_ONLY, panel->expansion_state()); |
// Test that the attention is cleared. |
@@ -362,6 +348,38 @@ |
panel->Close(); |
} |
+ |
+ void TestChangeAutoHideTaskBarHeight() { |
+ mock_auto_hide_bottom_bar()->enable_auto_hide(true); |
+ int test_work_area_bottom = testing_work_area().height(); |
+ int mock_bar_height = mock_auto_hide_bottom_bar()->GetHeight(); |
+ |
+ PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", |
+ SHOW_AS_ACTIVE); |
+ Panel* panel = browser_view->panel_.get(); |
+ EXPECT_EQ(test_work_area_bottom - mock_bar_height, |
+ panel->GetBounds().bottom()); |
+ |
+ int new_mock_bar_height = mock_bar_height + 10; |
+ mock_auto_hide_bottom_bar()->SetHeight(new_mock_bar_height); |
+ MessageLoop::current()->RunAllPending(); |
+ EXPECT_EQ(test_work_area_bottom - new_mock_bar_height, |
+ panel->GetBounds().bottom()); |
+ |
+ new_mock_bar_height = 0; |
+ mock_auto_hide_bottom_bar()->SetHeight(new_mock_bar_height); |
+ MessageLoop::current()->RunAllPending(); |
+ EXPECT_EQ(test_work_area_bottom - new_mock_bar_height, |
+ panel->GetBounds().bottom()); |
+ |
+ new_mock_bar_height = mock_bar_height - 10; |
+ mock_auto_hide_bottom_bar()->SetHeight(new_mock_bar_height); |
+ MessageLoop::current()->RunAllPending(); |
+ EXPECT_EQ(test_work_area_bottom - new_mock_bar_height, |
+ panel->GetBounds().bottom()); |
+ |
+ panel->Close(); |
+ } |
}; |
// Panel is not supported for Linux view yet. |
@@ -494,11 +512,23 @@ |
"http://home", "options.html"); |
} |
-IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, MinimizeAndRestore) { |
- TestMinimizeAndRestore(); |
+IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, |
+ MinimizeAndRestoreOnNormalTaskBar) { |
+ // Test that the taskbar is always visible. |
+ TestMinimizeAndRestore(false); |
} |
+IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, |
+ MinimizeAndRestoreOnAutoHideTaskBar) { |
+ // Test that the taskbar is in auto-hide mode. |
+ TestMinimizeAndRestore(true); |
+} |
+ |
IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, DrawAttention) { |
TestDrawAttention(); |
} |
+ |
+IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, ChangeAutoHideTaskBarHeight) { |
+ TestChangeAutoHideTaskBarHeight(); |
+} |
#endif |