Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/i18n/time_formatting.h" | 6 #include "base/i18n/time_formatting.h" |
| 7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/browser/ui/panels/panel.h" | 11 #include "chrome/browser/ui/panels/panel.h" |
| 12 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" | 12 #include "chrome/browser/ui/panels/panel_browser_frame_view.h" |
| 13 #include "chrome/browser/ui/panels/panel_browser_view.h" | 13 #include "chrome/browser/ui/panels/panel_browser_view.h" |
| 14 #include "chrome/browser/ui/panels/panel_manager.h" | |
| 14 #include "chrome/browser/web_applications/web_app.h" | 15 #include "chrome/browser/web_applications/web_app.h" |
| 15 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/extensions/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 17 #include "chrome/test/in_process_browser_test.h" | 18 #include "chrome/test/in_process_browser_test.h" |
| 18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/base/animation/slide_animation.h" | 22 #include "ui/base/animation/slide_animation.h" |
| 22 #include "views/controls/button/image_button.h" | 23 #include "views/controls/button/image_button.h" |
| 23 #include "views/controls/button/menu_button.h" | 24 #include "views/controls/button/menu_button.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 PanelBrowserView* browser_view2 = CreatePanelBrowserView("PanelTest2", | 271 PanelBrowserView* browser_view2 = CreatePanelBrowserView("PanelTest2", |
| 271 SHOW_AS_INACTIVE); | 272 SHOW_AS_INACTIVE); |
| 272 PanelBrowserFrameView* frame_view2 = browser_view2->GetFrameView(); | 273 PanelBrowserFrameView* frame_view2 = browser_view2->GetFrameView(); |
| 273 EXPECT_FALSE(browser_view2->panel()->IsActive()); | 274 EXPECT_FALSE(browser_view2->panel()->IsActive()); |
| 274 EXPECT_EQ(PanelBrowserFrameView::PAINT_AS_INACTIVE, | 275 EXPECT_EQ(PanelBrowserFrameView::PAINT_AS_INACTIVE, |
| 275 frame_view2->paint_state_); | 276 frame_view2->paint_state_); |
| 276 | 277 |
| 277 browser_view1->panel()->Close(); | 278 browser_view1->panel()->Close(); |
| 278 browser_view2->panel()->Close(); | 279 browser_view2->panel()->Close(); |
| 279 } | 280 } |
| 281 | |
| 282 // We put all the testing logic in this class instead of the test so that | |
| 283 // we do not need to declare each new test as a friend of PanelBrowserView | |
| 284 // for the purpose of accessing its private members. | |
| 285 void TestMinimizeAndRestore() { | |
| 286 PanelBrowserView* browser_view1 = CreatePanelBrowserView("PanelTest1", | |
| 287 SHOW_AS_ACTIVE); | |
| 288 Panel* panel1 = browser_view1->panel_.get(); | |
| 289 | |
| 290 // Test minimizing/restoring an individual panel. | |
| 291 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); | |
| 292 int initial_height = panel1->GetBounds().height(); | |
| 293 int titlebar_height = | |
| 294 browser_view1->GetFrameView()->NonClientTopBorderHeight(); | |
| 295 | |
| 296 panel1->SetExpansionState(Panel::MINIMIZED); | |
|
jennb
2011/06/30 17:33:31
Also check mouse watcher started?
jianli
2011/06/30 18:22:36
Done.
| |
| 297 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); | |
| 298 EXPECT_LT(panel1->GetBounds().height(), titlebar_height); | |
| 299 EXPECT_GT(panel1->GetBounds().height(), 0); | |
| 300 | |
| 301 panel1->SetExpansionState(Panel::TITLE_ONLY); | |
| 302 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | |
| 303 EXPECT_EQ(titlebar_height, panel1->GetBounds().height()); | |
| 304 | |
| 305 panel1->SetExpansionState(Panel::EXPANDED); | |
| 306 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); | |
| 307 EXPECT_EQ(initial_height, panel1->GetBounds().height()); | |
| 308 | |
| 309 panel1->SetExpansionState(Panel::TITLE_ONLY); | |
| 310 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | |
| 311 EXPECT_EQ(titlebar_height, panel1->GetBounds().height()); | |
| 312 | |
| 313 panel1->SetExpansionState(Panel::MINIMIZED); | |
| 314 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); | |
| 315 EXPECT_LT(panel1->GetBounds().height(), titlebar_height); | |
| 316 EXPECT_GT(panel1->GetBounds().height(), 0); | |
| 317 | |
| 318 // Create 2 more panels for more testing. | |
| 319 PanelBrowserView* browser_view2 = CreatePanelBrowserView("PanelTest2", | |
| 320 SHOW_AS_ACTIVE); | |
| 321 Panel* panel2 = browser_view2->panel_.get(); | |
| 322 | |
| 323 PanelBrowserView* browser_view3 = CreatePanelBrowserView("PanelTest3", | |
| 324 SHOW_AS_ACTIVE); | |
| 325 Panel* panel3 = browser_view3->panel_.get(); | |
| 326 | |
| 327 // Test bringing up or down the title-bar of all minimized panels. | |
| 328 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); | |
| 329 panel3->SetExpansionState(Panel::MINIMIZED); | |
| 330 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); | |
| 331 | |
| 332 PanelManager* panel_manager = PanelManager::GetInstance(); | |
| 333 | |
| 334 panel_manager->BringUpOrDownTitleBarForAllMinimizedPanels(true); | |
| 335 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); | |
| 336 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); | |
| 337 EXPECT_EQ(Panel::TITLE_ONLY, panel3->expansion_state()); | |
| 338 | |
| 339 panel_manager->BringUpOrDownTitleBarForAllMinimizedPanels(false); | |
| 340 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); | |
| 341 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); | |
| 342 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); | |
| 343 | |
| 344 // Test if it is OK to bring up title-bar given the mouse position. | |
| 345 EXPECT_TRUE(panel_manager->ShouldBringUpTitleBarForAllMinimizedPanels( | |
| 346 panel1->GetBounds().x(), panel1->GetBounds().y())); | |
| 347 EXPECT_FALSE(panel_manager->ShouldBringUpTitleBarForAllMinimizedPanels( | |
| 348 panel2->GetBounds().x(), panel2->GetBounds().y())); | |
| 349 EXPECT_TRUE(panel_manager->ShouldBringUpTitleBarForAllMinimizedPanels( | |
| 350 panel3->GetBounds().right() - 1, panel3->GetBounds().bottom() - 1)); | |
| 351 EXPECT_TRUE(panel_manager->ShouldBringUpTitleBarForAllMinimizedPanels( | |
| 352 panel3->GetBounds().right() - 1, panel3->GetBounds().bottom() + 10)); | |
| 353 EXPECT_FALSE(panel_manager->ShouldBringUpTitleBarForAllMinimizedPanels( | |
| 354 0, 0)); | |
| 355 | |
| 356 panel1->Close(); | |
|
jennb
2011/06/30 17:33:31
Also check mouse watcher still active after each c
jianli
2011/06/30 18:22:36
Done.
| |
| 357 panel2->Close(); | |
| 358 panel3->Close(); | |
| 359 } | |
| 280 }; | 360 }; |
| 281 | 361 |
| 282 // Panel is not supported for Linux view yet. | 362 // Panel is not supported for Linux view yet. |
| 283 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) | 363 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) |
| 284 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { | 364 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { |
| 285 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", | 365 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", |
| 286 SHOW_AS_ACTIVE); | 366 SHOW_AS_ACTIVE); |
| 287 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); | 367 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); |
| 288 | 368 |
| 289 // The bounds animation should not be triggered when the panel is up for the | 369 // The bounds animation should not be triggered when the panel is up for the |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 } | 660 } |
| 581 | 661 |
| 582 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreateSettingsMenu) { | 662 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreateSettingsMenu) { |
| 583 TestCreateSettingsMenuForExtension( | 663 TestCreateSettingsMenuForExtension( |
| 584 FILE_PATH_LITERAL("extension1"), Extension::EXTERNAL_POLICY_DOWNLOAD, | 664 FILE_PATH_LITERAL("extension1"), Extension::EXTERNAL_POLICY_DOWNLOAD, |
| 585 "", ""); | 665 "", ""); |
| 586 TestCreateSettingsMenuForExtension( | 666 TestCreateSettingsMenuForExtension( |
| 587 FILE_PATH_LITERAL("extension2"), Extension::INVALID, | 667 FILE_PATH_LITERAL("extension2"), Extension::INVALID, |
| 588 "http://home", "options.html"); | 668 "http://home", "options.html"); |
| 589 } | 669 } |
| 670 | |
| 671 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, MinimizeAndRestore) { | |
| 672 TestMinimizeAndRestore(); | |
| 673 } | |
| 590 #endif | 674 #endif |
| OLD | NEW |