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" |
| 15 #include "chrome/browser/ui/panels/panel_mouse_watcher_win.h" |
14 #include "chrome/browser/web_applications/web_app.h" | 16 #include "chrome/browser/web_applications/web_app.h" |
15 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
17 #include "chrome/test/in_process_browser_test.h" | 19 #include "chrome/test/in_process_browser_test.h" |
18 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
19 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "ui/base/animation/slide_animation.h" | 23 #include "ui/base/animation/slide_animation.h" |
22 #include "views/controls/button/image_button.h" | 24 #include "views/controls/button/image_button.h" |
23 #include "views/controls/button/menu_button.h" | 25 #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", | 272 PanelBrowserView* browser_view2 = CreatePanelBrowserView("PanelTest2", |
271 SHOW_AS_INACTIVE); | 273 SHOW_AS_INACTIVE); |
272 PanelBrowserFrameView* frame_view2 = browser_view2->GetFrameView(); | 274 PanelBrowserFrameView* frame_view2 = browser_view2->GetFrameView(); |
273 EXPECT_FALSE(browser_view2->panel()->IsActive()); | 275 EXPECT_FALSE(browser_view2->panel()->IsActive()); |
274 EXPECT_EQ(PanelBrowserFrameView::PAINT_AS_INACTIVE, | 276 EXPECT_EQ(PanelBrowserFrameView::PAINT_AS_INACTIVE, |
275 frame_view2->paint_state_); | 277 frame_view2->paint_state_); |
276 | 278 |
277 browser_view1->panel()->Close(); | 279 browser_view1->panel()->Close(); |
278 browser_view2->panel()->Close(); | 280 browser_view2->panel()->Close(); |
279 } | 281 } |
| 282 |
| 283 // We put all the testing logic in this class instead of the test so that |
| 284 // we do not need to declare each new test as a friend of PanelBrowserView |
| 285 // for the purpose of accessing its private members. |
| 286 void TestMinimizeAndRestore() { |
| 287 PanelBrowserView* browser_view1 = CreatePanelBrowserView("PanelTest1", |
| 288 SHOW_AS_ACTIVE); |
| 289 Panel* panel1 = browser_view1->panel_.get(); |
| 290 |
| 291 // Test minimizing/restoring an individual panel. |
| 292 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); |
| 293 int initial_height = panel1->GetBounds().height(); |
| 294 int titlebar_height = |
| 295 browser_view1->GetFrameView()->NonClientTopBorderHeight(); |
| 296 |
| 297 panel1->SetExpansionState(Panel::MINIMIZED); |
| 298 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
| 299 EXPECT_LT(panel1->GetBounds().height(), titlebar_height); |
| 300 EXPECT_GT(panel1->GetBounds().height(), 0); |
| 301 EXPECT_TRUE(IsMouseWatcherStarted()); |
| 302 |
| 303 panel1->SetExpansionState(Panel::TITLE_ONLY); |
| 304 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
| 305 EXPECT_EQ(titlebar_height, panel1->GetBounds().height()); |
| 306 |
| 307 panel1->SetExpansionState(Panel::EXPANDED); |
| 308 EXPECT_EQ(Panel::EXPANDED, panel1->expansion_state()); |
| 309 EXPECT_EQ(initial_height, panel1->GetBounds().height()); |
| 310 |
| 311 panel1->SetExpansionState(Panel::TITLE_ONLY); |
| 312 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
| 313 EXPECT_EQ(titlebar_height, panel1->GetBounds().height()); |
| 314 |
| 315 panel1->SetExpansionState(Panel::MINIMIZED); |
| 316 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
| 317 EXPECT_LT(panel1->GetBounds().height(), titlebar_height); |
| 318 EXPECT_GT(panel1->GetBounds().height(), 0); |
| 319 |
| 320 // Create 2 more panels for more testing. |
| 321 PanelBrowserView* browser_view2 = CreatePanelBrowserView("PanelTest2", |
| 322 SHOW_AS_ACTIVE); |
| 323 Panel* panel2 = browser_view2->panel_.get(); |
| 324 |
| 325 PanelBrowserView* browser_view3 = CreatePanelBrowserView("PanelTest3", |
| 326 SHOW_AS_ACTIVE); |
| 327 Panel* panel3 = browser_view3->panel_.get(); |
| 328 |
| 329 // Test bringing up or down the title-bar of all minimized panels. |
| 330 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); |
| 331 panel3->SetExpansionState(Panel::MINIMIZED); |
| 332 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); |
| 333 |
| 334 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 335 |
| 336 panel_manager->BringUpOrDownTitleBarForAllMinimizedPanels(true); |
| 337 EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); |
| 338 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); |
| 339 EXPECT_EQ(Panel::TITLE_ONLY, panel3->expansion_state()); |
| 340 |
| 341 panel_manager->BringUpOrDownTitleBarForAllMinimizedPanels(false); |
| 342 EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); |
| 343 EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); |
| 344 EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); |
| 345 |
| 346 // Test if it is OK to bring up title-bar given the mouse position. |
| 347 EXPECT_TRUE(panel_manager->ShouldBringUpTitleBarForAllMinimizedPanels( |
| 348 panel1->GetBounds().x(), panel1->GetBounds().y())); |
| 349 EXPECT_FALSE(panel_manager->ShouldBringUpTitleBarForAllMinimizedPanels( |
| 350 panel2->GetBounds().x(), panel2->GetBounds().y())); |
| 351 EXPECT_TRUE(panel_manager->ShouldBringUpTitleBarForAllMinimizedPanels( |
| 352 panel3->GetBounds().right() - 1, panel3->GetBounds().bottom() - 1)); |
| 353 EXPECT_TRUE(panel_manager->ShouldBringUpTitleBarForAllMinimizedPanels( |
| 354 panel3->GetBounds().right() - 1, panel3->GetBounds().bottom() + 10)); |
| 355 EXPECT_FALSE(panel_manager->ShouldBringUpTitleBarForAllMinimizedPanels( |
| 356 0, 0)); |
| 357 |
| 358 panel1->Close(); |
| 359 EXPECT_TRUE(IsMouseWatcherStarted()); |
| 360 panel2->Close(); |
| 361 EXPECT_TRUE(IsMouseWatcherStarted()); |
| 362 panel3->Close(); |
| 363 EXPECT_FALSE(IsMouseWatcherStarted()); |
| 364 } |
280 }; | 365 }; |
281 | 366 |
282 // Panel is not supported for Linux view yet. | 367 // Panel is not supported for Linux view yet. |
283 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) | 368 #if !defined(OS_LINUX) || !defined(TOOLKIT_VIEWS) |
284 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { | 369 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreatePanel) { |
285 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", | 370 PanelBrowserView* browser_view = CreatePanelBrowserView("PanelTest", |
286 SHOW_AS_ACTIVE); | 371 SHOW_AS_ACTIVE); |
287 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); | 372 PanelBrowserFrameView* frame_view = browser_view->GetFrameView(); |
288 | 373 |
289 // The bounds animation should not be triggered when the panel is up for the | 374 // 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 } | 665 } |
581 | 666 |
582 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreateSettingsMenu) { | 667 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, CreateSettingsMenu) { |
583 TestCreateSettingsMenuForExtension( | 668 TestCreateSettingsMenuForExtension( |
584 FILE_PATH_LITERAL("extension1"), Extension::EXTERNAL_POLICY_DOWNLOAD, | 669 FILE_PATH_LITERAL("extension1"), Extension::EXTERNAL_POLICY_DOWNLOAD, |
585 "", ""); | 670 "", ""); |
586 TestCreateSettingsMenuForExtension( | 671 TestCreateSettingsMenuForExtension( |
587 FILE_PATH_LITERAL("extension2"), Extension::INVALID, | 672 FILE_PATH_LITERAL("extension2"), Extension::INVALID, |
588 "http://home", "options.html"); | 673 "http://home", "options.html"); |
589 } | 674 } |
| 675 |
| 676 IN_PROC_BROWSER_TEST_F(PanelBrowserViewTest, MinimizeAndRestore) { |
| 677 TestMinimizeAndRestore(); |
| 678 } |
590 #endif | 679 #endif |
OLD | NEW |