blob: 8ee7557873f17d9fdf52b61a3c943868e2f634d9 [file] [log] [blame]
James Cookb0bf8e82017-04-09 17:01:441// 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"
skye87cbf962017-04-28 01:46:059#include "ash/test/ash_test_base.h"
James Cookb0bf8e82017-04-09 17:01:4410#include "ash/wm/window_state.h"
skye87cbf962017-04-28 01:46:0511#include "ash/wm/window_util.h"
James Cookb0bf8e82017-04-09 17:01:4412#include "ui/base/hit_test.h"
13
14namespace ash {
15
James Cook317781a2017-07-18 02:08:0616class MruWindowTrackerTest : public AshTestBase {
James Cookb0bf8e82017-04-09 17:01:4417 public:
Chris Watkinsc24daf62017-11-28 03:43:0918 MruWindowTrackerTest() = default;
19 ~MruWindowTrackerTest() override = default;
James Cookb0bf8e82017-04-09 17:01:4420
skye87cbf962017-04-28 01:46:0521 std::unique_ptr<aura::Window> CreateTestWindow() {
22 return AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
James Cookb0bf8e82017-04-09 17:01:4423 }
24
25 MruWindowTracker* mru_window_tracker() {
26 return Shell::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.
34TEST_F(MruWindowTrackerTest, Basic) {
skye87cbf962017-04-28 01:46:0535 std::unique_ptr<aura::Window> w1(CreateTestWindow());
36 std::unique_ptr<aura::Window> w2(CreateTestWindow());
37 std::unique_ptr<aura::Window> w3(CreateTestWindow());
38 wm::ActivateWindow(w3.get());
39 wm::ActivateWindow(w2.get());
40 wm::ActivateWindow(w1.get());
James Cookb0bf8e82017-04-09 17:01:4441
varkha843aa522017-05-24 16:05:5942 MruWindowTracker::WindowList window_list =
43 mru_window_tracker()->BuildMruWindowList();
James Cookb0bf8e82017-04-09 17:01:4444 ASSERT_EQ(3u, window_list.size());
varkha843aa522017-05-24 16:05:5945 EXPECT_EQ(w1.get(), window_list[0]);
46 EXPECT_EQ(w2.get(), window_list[1]);
47 EXPECT_EQ(w3.get(), window_list[2]);
James Cookb0bf8e82017-04-09 17:01:4448}
49
50// Test that minimized windows are not treated specially.
51TEST_F(MruWindowTrackerTest, MinimizedWindowsAreLru) {
skye87cbf962017-04-28 01:46:0552 std::unique_ptr<aura::Window> w1(CreateTestWindow());
53 std::unique_ptr<aura::Window> w2(CreateTestWindow());
54 std::unique_ptr<aura::Window> w3(CreateTestWindow());
55 std::unique_ptr<aura::Window> w4(CreateTestWindow());
56 std::unique_ptr<aura::Window> w5(CreateTestWindow());
57 std::unique_ptr<aura::Window> w6(CreateTestWindow());
58 wm::ActivateWindow(w6.get());
59 wm::ActivateWindow(w5.get());
60 wm::ActivateWindow(w4.get());
61 wm::ActivateWindow(w3.get());
62 wm::ActivateWindow(w2.get());
63 wm::ActivateWindow(w1.get());
James Cookb0bf8e82017-04-09 17:01:4464
skye87cbf962017-04-28 01:46:0565 wm::GetWindowState(w1.get())->Minimize();
66 wm::GetWindowState(w4.get())->Minimize();
67 wm::GetWindowState(w5.get())->Minimize();
James Cookb0bf8e82017-04-09 17:01:4468
69 // By minimizing the first window, we activate w2 which will move it to the
70 // front of the MRU queue.
skye87cbf962017-04-28 01:46:0571 EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
James Cookb0bf8e82017-04-09 17:01:4472
varkha843aa522017-05-24 16:05:5973 MruWindowTracker::WindowList window_list =
74 mru_window_tracker()->BuildMruWindowList();
75 EXPECT_EQ(w2.get(), window_list[0]);
76 EXPECT_EQ(w1.get(), window_list[1]);
77 EXPECT_EQ(w3.get(), window_list[2]);
78 EXPECT_EQ(w4.get(), window_list[3]);
79 EXPECT_EQ(w5.get(), window_list[4]);
80 EXPECT_EQ(w6.get(), window_list[5]);
James Cookb0bf8e82017-04-09 17:01:4481}
82
83// Tests that windows being dragged are only in the WindowList once.
84TEST_F(MruWindowTrackerTest, DraggedWindowsInListOnlyOnce) {
skye87cbf962017-04-28 01:46:0585 std::unique_ptr<aura::Window> w1(CreateTestWindow());
86 wm::ActivateWindow(w1.get());
James Cookb0bf8e82017-04-09 17:01:4487
88 // Start dragging the window.
skye87cbf962017-04-28 01:46:0589 wm::GetWindowState(w1.get())->CreateDragDetails(
Thiago Farina3b086a02017-05-30 22:32:5090 gfx::Point(), HTRIGHT, ::wm::WINDOW_MOVE_SOURCE_TOUCH);
James Cookb0bf8e82017-04-09 17:01:4491
92 // The dragged window should only be in the list once.
varkha843aa522017-05-24 16:05:5993 MruWindowTracker::WindowList window_list =
James Cookb0bf8e82017-04-09 17:01:4494 mru_window_tracker()->BuildWindowListIgnoreModal();
varkha843aa522017-05-24 16:05:5995 EXPECT_EQ(1, std::count(window_list.begin(), window_list.end(), w1.get()));
James Cookb0bf8e82017-04-09 17:01:4496}
97
98} // namespace ash