James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame^] | 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/wm/mru_window_tracker.h" |
| 6 | |
| 7 | #include "ash/public/cpp/shell_window_ids.h" |
| 8 | #include "ash/shell.h" |
| 9 | #include "ash/test/ash_test.h" |
| 10 | #include "ash/wm/window_state.h" |
| 11 | #include "ash/wm_shell.h" |
| 12 | #include "ash/wm_window.h" |
| 13 | #include "ui/base/hit_test.h" |
| 14 | |
| 15 | namespace ash { |
| 16 | |
| 17 | class MruWindowTrackerTest : public AshTest { |
| 18 | public: |
| 19 | MruWindowTrackerTest() {} |
| 20 | ~MruWindowTrackerTest() override {} |
| 21 | |
| 22 | std::unique_ptr<WindowOwner> CreateTestWindow() { |
| 23 | return AshTest::CreateTestWindow(gfx::Rect(0, 0, 400, 400)); |
| 24 | } |
| 25 | |
| 26 | MruWindowTracker* mru_window_tracker() { |
| 27 | return Shell::Get()->mru_window_tracker(); |
| 28 | } |
| 29 | |
| 30 | private: |
| 31 | DISALLOW_COPY_AND_ASSIGN(MruWindowTrackerTest); |
| 32 | }; |
| 33 | |
| 34 | // Basic test that the activation order is tracked. |
| 35 | TEST_F(MruWindowTrackerTest, Basic) { |
| 36 | std::unique_ptr<WindowOwner> w1_owner(CreateTestWindow()); |
| 37 | WmWindow* w1 = w1_owner->window(); |
| 38 | std::unique_ptr<WindowOwner> w2_owner(CreateTestWindow()); |
| 39 | WmWindow* w2 = w2_owner->window(); |
| 40 | std::unique_ptr<WindowOwner> w3_owner(CreateTestWindow()); |
| 41 | WmWindow* w3 = w3_owner->window(); |
| 42 | w3->Activate(); |
| 43 | w2->Activate(); |
| 44 | w1->Activate(); |
| 45 | |
| 46 | WmWindow::Windows window_list = mru_window_tracker()->BuildMruWindowList(); |
| 47 | ASSERT_EQ(3u, window_list.size()); |
| 48 | EXPECT_EQ(w1, window_list[0]); |
| 49 | EXPECT_EQ(w2, window_list[1]); |
| 50 | EXPECT_EQ(w3, window_list[2]); |
| 51 | } |
| 52 | |
| 53 | // Test that minimized windows are not treated specially. |
| 54 | TEST_F(MruWindowTrackerTest, MinimizedWindowsAreLru) { |
| 55 | std::unique_ptr<WindowOwner> w1_owner(CreateTestWindow()); |
| 56 | WmWindow* w1 = w1_owner->window(); |
| 57 | std::unique_ptr<WindowOwner> w2_owner(CreateTestWindow()); |
| 58 | WmWindow* w2 = w2_owner->window(); |
| 59 | std::unique_ptr<WindowOwner> w3_owner(CreateTestWindow()); |
| 60 | WmWindow* w3 = w3_owner->window(); |
| 61 | std::unique_ptr<WindowOwner> w4_owner(CreateTestWindow()); |
| 62 | WmWindow* w4 = w4_owner->window(); |
| 63 | std::unique_ptr<WindowOwner> w5_owner(CreateTestWindow()); |
| 64 | WmWindow* w5 = w5_owner->window(); |
| 65 | std::unique_ptr<WindowOwner> w6_owner(CreateTestWindow()); |
| 66 | WmWindow* w6 = w6_owner->window(); |
| 67 | w6->Activate(); |
| 68 | w5->Activate(); |
| 69 | w4->Activate(); |
| 70 | w3->Activate(); |
| 71 | w2->Activate(); |
| 72 | w1->Activate(); |
| 73 | |
| 74 | w1->GetWindowState()->Minimize(); |
| 75 | w4->GetWindowState()->Minimize(); |
| 76 | w5->GetWindowState()->Minimize(); |
| 77 | |
| 78 | // By minimizing the first window, we activate w2 which will move it to the |
| 79 | // front of the MRU queue. |
| 80 | EXPECT_TRUE(w2->IsActive()); |
| 81 | |
| 82 | WmWindow::Windows window_list = mru_window_tracker()->BuildMruWindowList(); |
| 83 | EXPECT_EQ(w2, window_list[0]); |
| 84 | EXPECT_EQ(w1, window_list[1]); |
| 85 | EXPECT_EQ(w3, window_list[2]); |
| 86 | EXPECT_EQ(w4, window_list[3]); |
| 87 | EXPECT_EQ(w5, window_list[4]); |
| 88 | EXPECT_EQ(w6, window_list[5]); |
| 89 | } |
| 90 | |
| 91 | // Tests that windows being dragged are only in the WindowList once. |
| 92 | TEST_F(MruWindowTrackerTest, DraggedWindowsInListOnlyOnce) { |
| 93 | std::unique_ptr<WindowOwner> w1_owner(CreateTestWindow()); |
| 94 | WmWindow* w1 = w1_owner->window(); |
| 95 | w1->Activate(); |
| 96 | |
| 97 | // Start dragging the window. |
| 98 | w1->GetWindowState()->CreateDragDetails( |
| 99 | gfx::Point(), HTRIGHT, aura::client::WINDOW_MOVE_SOURCE_TOUCH); |
| 100 | |
| 101 | // The dragged window should only be in the list once. |
| 102 | WmWindow::Windows window_list = |
| 103 | mru_window_tracker()->BuildWindowListIgnoreModal(); |
| 104 | EXPECT_EQ(1, std::count(window_list.begin(), window_list.end(), w1)); |
| 105 | } |
| 106 | |
| 107 | } // namespace ash |