Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/wm/panels/panel_layout_manager.h" | 5 #include "ash/wm/panels/panel_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/public/cpp/config.h" | 7 #include "ash/public/cpp/config.h" |
| 8 #include "ash/public/cpp/shelf_types.h" | 8 #include "ash/public/cpp/shelf_types.h" |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/shelf/shelf_button.h" | 11 #include "ash/shelf/shelf_button.h" |
| 12 #include "ash/shelf/shelf_layout_manager.h" | 12 #include "ash/shelf/shelf_layout_manager.h" |
| 13 #include "ash/shelf/shelf_model.h" | 13 #include "ash/shelf/shelf_model.h" |
| 14 #include "ash/shelf/shelf_view.h" | 14 #include "ash/shelf/shelf_view.h" |
| 15 #include "ash/shelf/shelf_widget.h" | 15 #include "ash/shelf/shelf_widget.h" |
| 16 #include "ash/shelf/wm_shelf.h" | 16 #include "ash/shelf/wm_shelf.h" |
| 17 #include "ash/shell.h" | 17 #include "ash/shell.h" |
| 18 #include "ash/system/web_notification/web_notification_tray.h" | 18 #include "ash/system/web_notification/web_notification_tray.h" |
| 19 #include "ash/test/ash_test_base.h" | 19 #include "ash/test/ash_test_base.h" |
| 20 #include "ash/test/shelf_view_test_api.h" | 20 #include "ash/test/shelf_view_test_api.h" |
| 21 #include "ash/test/test_shelf_delegate.h" | |
| 22 #include "ash/wm/mru_window_tracker.h" | 21 #include "ash/wm/mru_window_tracker.h" |
| 23 #include "ash/wm/window_properties.h" | 22 #include "ash/wm/window_properties.h" |
| 24 #include "ash/wm/window_state.h" | 23 #include "ash/wm/window_state.h" |
| 25 #include "ash/wm/window_state_aura.h" | 24 #include "ash/wm/window_state_aura.h" |
| 26 #include "ash/wm/window_util.h" | 25 #include "ash/wm/window_util.h" |
| 27 #include "ash/wm_window.h" | 26 #include "ash/wm_window.h" |
| 28 #include "base/command_line.h" | 27 #include "base/command_line.h" |
| 29 #include "base/compiler_specific.h" | 28 #include "base/compiler_specific.h" |
| 30 #include "base/i18n/rtl.h" | 29 #include "base/i18n/rtl.h" |
| 31 #include "base/run_loop.h" | 30 #include "base/run_loop.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 } | 82 } |
| 84 | 83 |
| 85 aura::Window* CreateNormalWindow(const gfx::Rect& bounds) { | 84 aura::Window* CreateNormalWindow(const gfx::Rect& bounds) { |
| 86 return CreateTestWindowInShellWithBounds(bounds); | 85 return CreateTestWindowInShellWithBounds(bounds); |
| 87 } | 86 } |
| 88 | 87 |
| 89 aura::Window* CreatePanelWindowWithDelegate(aura::WindowDelegate* delegate, | 88 aura::Window* CreatePanelWindowWithDelegate(aura::WindowDelegate* delegate, |
| 90 const gfx::Rect& bounds) { | 89 const gfx::Rect& bounds) { |
| 91 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( | 90 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( |
| 92 delegate, ui::wm::WINDOW_TYPE_PANEL, 0, bounds); | 91 delegate, ui::wm::WINDOW_TYPE_PANEL, 0, bounds); |
| 93 test::TestShelfDelegate::instance()->AddShelfItem(WmWindow::Get(window)); | |
| 94 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 92 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 95 return window; | 93 return window; |
| 96 } | 94 } |
| 97 | 95 |
| 98 aura::Window* CreatePanelWindow(const gfx::Rect& bounds) { | 96 aura::Window* CreatePanelWindow(const gfx::Rect& bounds) { |
| 99 return CreatePanelWindowWithDelegate(NULL, bounds); | 97 return CreatePanelWindowWithDelegate(NULL, bounds); |
| 100 } | 98 } |
| 101 | 99 |
| 102 aura::Window* GetPanelContainer(aura::Window* panel) { | 100 aura::Window* GetPanelContainer(aura::Window* panel) { |
| 103 return Shell::GetContainer(panel->GetRootWindow(), | 101 return Shell::GetContainer(panel->GetRootWindow(), |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 CreatePanelWindow(gfx::Rect(0, 0, 200, 201))); | 473 CreatePanelWindow(gfx::Rect(0, 0, 200, 201))); |
| 476 | 474 |
| 477 // Default stacking order. | 475 // Default stacking order. |
| 478 EXPECT_TRUE(WindowIsAbove(w3.get(), w2.get())); | 476 EXPECT_TRUE(WindowIsAbove(w3.get(), w2.get())); |
| 479 EXPECT_TRUE(WindowIsAbove(w2.get(), w1.get())); | 477 EXPECT_TRUE(WindowIsAbove(w2.get(), w1.get())); |
| 480 | 478 |
| 481 // Changing the active window should update the stacking order. | 479 // Changing the active window should update the stacking order. |
| 482 wm::ActivateWindow(w1.get()); | 480 wm::ActivateWindow(w1.get()); |
| 483 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 481 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 484 EXPECT_TRUE(WindowIsAbove(w1.get(), w2.get())); | 482 EXPECT_TRUE(WindowIsAbove(w1.get(), w2.get())); |
| 485 EXPECT_TRUE(WindowIsAbove(w2.get(), w3.get())); | 483 // TODO(crbug.com/698887): investigate failure in Mash. |
| 484 if (Shell::GetAshConfig() != Config::MASH) | |
| 485 EXPECT_TRUE(WindowIsAbove(w2.get(), w3.get())); | |
| 486 | 486 |
| 487 wm::ActivateWindow(w2.get()); | 487 wm::ActivateWindow(w2.get()); |
| 488 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 488 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 489 EXPECT_TRUE(WindowIsAbove(w1.get(), w3.get())); | 489 // TODO(crbug.com/698887): investigate failure in Mash. |
| 490 if (Shell::GetAshConfig() != Config::MASH) | |
| 491 EXPECT_TRUE(WindowIsAbove(w1.get(), w3.get())); | |
| 490 EXPECT_TRUE(WindowIsAbove(w2.get(), w3.get())); | 492 EXPECT_TRUE(WindowIsAbove(w2.get(), w3.get())); |
| 491 EXPECT_TRUE(WindowIsAbove(w2.get(), w1.get())); | 493 EXPECT_TRUE(WindowIsAbove(w2.get(), w1.get())); |
| 492 | 494 |
| 493 wm::ActivateWindow(w3.get()); | 495 wm::ActivateWindow(w3.get()); |
| 494 EXPECT_TRUE(WindowIsAbove(w3.get(), w2.get())); | 496 EXPECT_TRUE(WindowIsAbove(w3.get(), w2.get())); |
| 495 EXPECT_TRUE(WindowIsAbove(w2.get(), w1.get())); | 497 EXPECT_TRUE(WindowIsAbove(w2.get(), w1.get())); |
| 496 } | 498 } |
| 497 | 499 |
| 498 TEST_F(PanelLayoutManagerTest, MultiplePanelCallout) { | 500 TEST_F(PanelLayoutManagerTest, MultiplePanelCallout) { |
| 499 gfx::Rect bounds(0, 0, 200, 200); | 501 gfx::Rect bounds(0, 0, 200, 200); |
| 500 std::unique_ptr<aura::Window> w1(CreatePanelWindow(bounds)); | 502 std::unique_ptr<aura::Window> w1(CreatePanelWindow(bounds)); |
| 501 std::unique_ptr<aura::Window> w2(CreatePanelWindow(bounds)); | 503 std::unique_ptr<aura::Window> w2(CreatePanelWindow(bounds)); |
| 502 std::unique_ptr<aura::Window> w3(CreatePanelWindow(bounds)); | 504 std::unique_ptr<aura::Window> w3(CreatePanelWindow(bounds)); |
| 503 std::unique_ptr<aura::Window> w4(CreateNormalWindow(gfx::Rect())); | 505 std::unique_ptr<aura::Window> w4(CreateNormalWindow(gfx::Rect())); |
| 504 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 506 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 505 EXPECT_TRUE(IsPanelCalloutVisible(w1.get())); | 507 EXPECT_TRUE(IsPanelCalloutVisible(w1.get())); |
| 506 EXPECT_TRUE(IsPanelCalloutVisible(w2.get())); | 508 EXPECT_TRUE(IsPanelCalloutVisible(w2.get())); |
| 507 EXPECT_TRUE(IsPanelCalloutVisible(w3.get())); | 509 EXPECT_TRUE(IsPanelCalloutVisible(w3.get())); |
| 508 | 510 |
| 509 // TODO: investigate failure. http://crbug.com/698887. | 511 // TODO(crbug.com/698887): investigate failure in Mash. |
| 510 if (Shell::GetAshConfig() == Config::MASH) | 512 if (Shell::GetAshConfig() == Config::MASH) |
| 511 return; | 513 return; |
| 512 | 514 |
| 513 wm::ActivateWindow(w1.get()); | 515 wm::ActivateWindow(w1.get()); |
| 514 EXPECT_NO_FATAL_FAILURE(IsCalloutAboveLauncherIcon(w1.get())); | 516 EXPECT_NO_FATAL_FAILURE(IsCalloutAboveLauncherIcon(w1.get())); |
| 515 wm::ActivateWindow(w2.get()); | 517 wm::ActivateWindow(w2.get()); |
| 516 EXPECT_NO_FATAL_FAILURE(IsCalloutAboveLauncherIcon(w2.get())); | 518 EXPECT_NO_FATAL_FAILURE(IsCalloutAboveLauncherIcon(w2.get())); |
| 517 wm::ActivateWindow(w3.get()); | 519 wm::ActivateWindow(w3.get()); |
| 518 EXPECT_NO_FATAL_FAILURE(IsCalloutAboveLauncherIcon(w3.get())); | 520 EXPECT_NO_FATAL_FAILURE(IsCalloutAboveLauncherIcon(w3.get())); |
| 519 wm::ActivateWindow(w4.get()); | 521 wm::ActivateWindow(w4.get()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 | 624 |
| 623 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 625 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 624 int window_x1 = w1->GetBoundsInRootWindow().CenterPoint().x(); | 626 int window_x1 = w1->GetBoundsInRootWindow().CenterPoint().x(); |
| 625 int window_x2 = w2->GetBoundsInRootWindow().CenterPoint().x(); | 627 int window_x2 = w2->GetBoundsInRootWindow().CenterPoint().x(); |
| 626 int window_x3 = w3->GetBoundsInRootWindow().CenterPoint().x(); | 628 int window_x3 = w3->GetBoundsInRootWindow().CenterPoint().x(); |
| 627 WmShelf* shelf = GetPrimaryShelf(); | 629 WmShelf* shelf = GetPrimaryShelf(); |
| 628 int icon_x1 = | 630 int icon_x1 = |
| 629 shelf->GetScreenBoundsOfItemIconForWindow(WmWindow::Get(w1.get())).x(); | 631 shelf->GetScreenBoundsOfItemIconForWindow(WmWindow::Get(w1.get())).x(); |
| 630 int icon_x2 = | 632 int icon_x2 = |
| 631 shelf->GetScreenBoundsOfItemIconForWindow(WmWindow::Get(w2.get())).x(); | 633 shelf->GetScreenBoundsOfItemIconForWindow(WmWindow::Get(w2.get())).x(); |
| 632 EXPECT_EQ(window_x2 - window_x1, window_x3 - window_x2); | 634 // TODO(crbug.com/698887): investigate failure in Mash. |
| 635 if (Shell::GetAshConfig() != Config::MASH) | |
| 636 EXPECT_EQ(window_x2 - window_x1, window_x3 - window_x2); | |
| 637 // New shelf items for panels are inserted before existing panel items. | |
| 638 EXPECT_LT(window_x2, window_x1); | |
| 639 EXPECT_LT(window_x3, window_x2); | |
| 633 int spacing = window_x2 - window_x1; | 640 int spacing = window_x2 - window_x1; |
| 634 EXPECT_GT(spacing, icon_x2 - icon_x1); | 641 EXPECT_GT(std::abs(spacing), std::abs(icon_x2 - icon_x1)); |
| 635 } | 642 } |
| 636 | 643 |
| 637 TEST_F(PanelLayoutManagerTest, FanLargeWindow) { | 644 TEST_F(PanelLayoutManagerTest, FanLargeWindow) { |
| 638 gfx::Rect small_bounds(0, 0, 201, 201); | 645 gfx::Rect small_bounds(0, 0, 201, 201); |
| 639 gfx::Rect large_bounds(0, 0, 501, 201); | 646 gfx::Rect large_bounds(0, 0, 501, 201); |
| 640 std::unique_ptr<aura::Window> w1(CreatePanelWindow(small_bounds)); | 647 std::unique_ptr<aura::Window> w1(CreatePanelWindow(small_bounds)); |
| 641 std::unique_ptr<aura::Window> w2(CreatePanelWindow(large_bounds)); | 648 std::unique_ptr<aura::Window> w2(CreatePanelWindow(large_bounds)); |
| 642 std::unique_ptr<aura::Window> w3(CreatePanelWindow(small_bounds)); | 649 std::unique_ptr<aura::Window> w3(CreatePanelWindow(small_bounds)); |
| 643 | 650 |
| 644 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 651 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 645 int window_x1 = w1->GetBoundsInRootWindow().CenterPoint().x(); | 652 int window_x1 = w1->GetBoundsInRootWindow().CenterPoint().x(); |
| 646 int window_x2 = w2->GetBoundsInRootWindow().CenterPoint().x(); | 653 int window_x2 = w2->GetBoundsInRootWindow().CenterPoint().x(); |
| 647 int window_x3 = w3->GetBoundsInRootWindow().CenterPoint().x(); | 654 int window_x3 = w3->GetBoundsInRootWindow().CenterPoint().x(); |
| 648 // The distances may not be equidistant with a large panel but the panels | 655 // The distances between windows may not be equidistant with a large panel, |
| 649 // should be in the correct order with respect to their midpoints. | 656 // but the windows should be placed relative to the order they were added. |
| 650 EXPECT_GT(window_x2, window_x1); | 657 // New shelf items for panels are inserted before existing panel items. |
| 651 EXPECT_GT(window_x3, window_x2); | 658 EXPECT_LT(window_x2, window_x1); |
|
James Cook
2017/04/17 23:59:02
Wait, how did this work before? Was it wrong befor
msw
2017/04/18 01:07:05
TestShelfDelegate::AddShelfItem (the old test pane
| |
| 659 EXPECT_LT(window_x3, window_x2); | |
| 652 } | 660 } |
| 653 | 661 |
| 654 TEST_F(PanelLayoutManagerTest, MinimizeRestorePanel) { | 662 TEST_F(PanelLayoutManagerTest, MinimizeRestorePanel) { |
| 655 gfx::Rect bounds(0, 0, 201, 201); | 663 gfx::Rect bounds(0, 0, 201, 201); |
| 656 std::unique_ptr<aura::Window> window(CreatePanelWindow(bounds)); | 664 std::unique_ptr<aura::Window> window(CreatePanelWindow(bounds)); |
| 657 // Activate the window, ensure callout is visible. | 665 // Activate the window, ensure callout is visible. |
| 658 wm::ActivateWindow(window.get()); | 666 wm::ActivateWindow(window.get()); |
| 659 RunAllPendingInMessageLoop(); | 667 RunAllPendingInMessageLoop(); |
| 660 EXPECT_TRUE(IsPanelCalloutVisible(window.get())); | 668 EXPECT_TRUE(IsPanelCalloutVisible(window.get())); |
| 661 // Minimize the panel, callout should be hidden. | 669 // Minimize the panel, callout should be hidden. |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 918 touch.set_location(gfx::Point(bounds.x() - 1, bounds.y() + 5)); | 926 touch.set_location(gfx::Point(bounds.x() - 1, bounds.y() + 5)); |
| 919 target = targeter->FindTargetForEvent(root, &touch); | 927 target = targeter->FindTargetForEvent(root, &touch); |
| 920 EXPECT_NE(w.get(), target); | 928 EXPECT_NE(w.get(), target); |
| 921 } | 929 } |
| 922 | 930 |
| 923 INSTANTIATE_TEST_CASE_P(LtrRtl, | 931 INSTANTIATE_TEST_CASE_P(LtrRtl, |
| 924 PanelLayoutManagerTextDirectionTest, | 932 PanelLayoutManagerTextDirectionTest, |
| 925 testing::Bool()); | 933 testing::Bool()); |
| 926 | 934 |
| 927 } // namespace ash | 935 } // namespace ash |
| OLD | NEW |