| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/common/wm/mru_window_tracker.h" | |
| 6 | |
| 7 #include "ash/common/test/ash_test.h" | |
| 8 #include "ash/common/wm/window_state.h" | |
| 9 #include "ash/common/wm_shell.h" | |
| 10 #include "ash/common/wm_window.h" | |
| 11 #include "ash/public/cpp/shell_window_ids.h" | |
| 12 #include "ui/base/hit_test.h" | |
| 13 | |
| 14 namespace ash { | |
| 15 | |
| 16 class MruWindowTrackerTest : public AshTest { | |
| 17 public: | |
| 18 MruWindowTrackerTest() {} | |
| 19 ~MruWindowTrackerTest() override {} | |
| 20 | |
| 21 std::unique_ptr<WindowOwner> CreateTestWindow() { | |
| 22 return AshTest::CreateTestWindow(gfx::Rect(0, 0, 400, 400)); | |
| 23 } | |
| 24 | |
| 25 MruWindowTracker* mru_window_tracker() { | |
| 26 return WmShell::Get()->mru_window_tracker(); | |
| 27 } | |
| 28 | |
| 29 private: | |
| 30 DISALLOW_COPY_AND_ASSIGN(MruWindowTrackerTest); | |
| 31 }; | |
| 32 | |
| 33 // Basic test that the activation order is tracked. | |
| 34 TEST_F(MruWindowTrackerTest, Basic) { | |
| 35 std::unique_ptr<WindowOwner> w1_owner(CreateTestWindow()); | |
| 36 WmWindow* w1 = w1_owner->window(); | |
| 37 std::unique_ptr<WindowOwner> w2_owner(CreateTestWindow()); | |
| 38 WmWindow* w2 = w2_owner->window(); | |
| 39 std::unique_ptr<WindowOwner> w3_owner(CreateTestWindow()); | |
| 40 WmWindow* w3 = w3_owner->window(); | |
| 41 w3->Activate(); | |
| 42 w2->Activate(); | |
| 43 w1->Activate(); | |
| 44 | |
| 45 WmWindow::Windows window_list = mru_window_tracker()->BuildMruWindowList(); | |
| 46 ASSERT_EQ(3u, window_list.size()); | |
| 47 EXPECT_EQ(w1, window_list[0]); | |
| 48 EXPECT_EQ(w2, window_list[1]); | |
| 49 EXPECT_EQ(w3, window_list[2]); | |
| 50 } | |
| 51 | |
| 52 // Test that minimized windows are not treated specially. | |
| 53 TEST_F(MruWindowTrackerTest, MinimizedWindowsAreLru) { | |
| 54 // TODO(sky): fix me. Fails in mash because of http://crbug.com/654887. | |
| 55 if (WmShell::Get()->IsRunningInMash()) | |
| 56 return; | |
| 57 | |
| 58 std::unique_ptr<WindowOwner> w1_owner(CreateTestWindow()); | |
| 59 WmWindow* w1 = w1_owner->window(); | |
| 60 std::unique_ptr<WindowOwner> w2_owner(CreateTestWindow()); | |
| 61 WmWindow* w2 = w2_owner->window(); | |
| 62 std::unique_ptr<WindowOwner> w3_owner(CreateTestWindow()); | |
| 63 WmWindow* w3 = w3_owner->window(); | |
| 64 std::unique_ptr<WindowOwner> w4_owner(CreateTestWindow()); | |
| 65 WmWindow* w4 = w4_owner->window(); | |
| 66 std::unique_ptr<WindowOwner> w5_owner(CreateTestWindow()); | |
| 67 WmWindow* w5 = w5_owner->window(); | |
| 68 std::unique_ptr<WindowOwner> w6_owner(CreateTestWindow()); | |
| 69 WmWindow* w6 = w6_owner->window(); | |
| 70 w6->Activate(); | |
| 71 w5->Activate(); | |
| 72 w4->Activate(); | |
| 73 w3->Activate(); | |
| 74 w2->Activate(); | |
| 75 w1->Activate(); | |
| 76 | |
| 77 w1->GetWindowState()->Minimize(); | |
| 78 w4->GetWindowState()->Minimize(); | |
| 79 w5->GetWindowState()->Minimize(); | |
| 80 | |
| 81 // By minimizing the first window, we activate w2 which will move it to the | |
| 82 // front of the MRU queue. | |
| 83 EXPECT_TRUE(w2->IsActive()); | |
| 84 | |
| 85 WmWindow::Windows window_list = mru_window_tracker()->BuildMruWindowList(); | |
| 86 EXPECT_EQ(w2, window_list[0]); | |
| 87 EXPECT_EQ(w1, window_list[1]); | |
| 88 EXPECT_EQ(w3, window_list[2]); | |
| 89 EXPECT_EQ(w4, window_list[3]); | |
| 90 EXPECT_EQ(w5, window_list[4]); | |
| 91 EXPECT_EQ(w6, window_list[5]); | |
| 92 } | |
| 93 | |
| 94 // Tests that windows being dragged are only in the WindowList once. | |
| 95 TEST_F(MruWindowTrackerTest, DraggedWindowsInListOnlyOnce) { | |
| 96 std::unique_ptr<WindowOwner> w1_owner(CreateTestWindow()); | |
| 97 WmWindow* w1 = w1_owner->window(); | |
| 98 w1->Activate(); | |
| 99 | |
| 100 // Start dragging the window. | |
| 101 w1->GetWindowState()->CreateDragDetails( | |
| 102 gfx::Point(), HTRIGHT, aura::client::WINDOW_MOVE_SOURCE_TOUCH); | |
| 103 | |
| 104 // During a drag the window is reparented by the Docked container. | |
| 105 WmWindow* drag_container = w1->GetRootWindow()->GetChildByShellWindowId( | |
| 106 kShellWindowId_DockedContainer); | |
| 107 drag_container->AddChild(w1); | |
| 108 EXPECT_TRUE(w1->GetWindowState()->is_dragged()); | |
| 109 | |
| 110 // The dragged window should only be in the list once. | |
| 111 WmWindow::Windows window_list = | |
| 112 mru_window_tracker()->BuildWindowListIgnoreModal(); | |
| 113 EXPECT_EQ(1, std::count(window_list.begin(), window_list.end(), w1)); | |
| 114 } | |
| 115 | |
| 116 } // namespace ash | |
| OLD | NEW |