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.
6 #include "ash/test/ash_test_base.h"
7 #include "ash/test/test_shelf_delegate.h"
8 #include "ash/wm/mru_window_tracker.h"
9 #include "ash/wm/window_state.h"
10 #include "ash/wm/window_util.h"
11 #include "base/compiler_specific.h"
12 #include "ui/aura/test/test_window_delegate.h"
13 #include "ui/aura/window.h"
14 #include "ui/views/widget/widget.h"
18 class MruWindowTrackerTest
: public test::AshTestBase
{
20 MruWindowTrackerTest() {}
21 ~MruWindowTrackerTest() override
{}
23 aura::Window
* CreateWindow() {
24 return CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 400, 400));
27 ash::MruWindowTracker
* mru_window_tracker() {
28 return Shell::GetInstance()->mru_window_tracker();
32 DISALLOW_COPY_AND_ASSIGN(MruWindowTrackerTest
);
35 // Basic test that the activation order is tracked.
36 TEST_F(MruWindowTrackerTest
, Basic
) {
37 scoped_ptr
<aura::Window
> w1(CreateWindow());
38 scoped_ptr
<aura::Window
> w2(CreateWindow());
39 scoped_ptr
<aura::Window
> w3(CreateWindow());
40 wm::ActivateWindow(w3
.get());
41 wm::ActivateWindow(w2
.get());
42 wm::ActivateWindow(w1
.get());
44 MruWindowTracker::WindowList window_list
=
45 mru_window_tracker()->BuildMruWindowList();
46 EXPECT_EQ(w1
.get(), window_list
[0]);
47 EXPECT_EQ(w2
.get(), window_list
[1]);
48 EXPECT_EQ(w3
.get(), window_list
[2]);
51 // Test that minimized windows are considered least recently used (but kept in
52 // correct relative order).
53 TEST_F(MruWindowTrackerTest
, MinimizedWindowsAreLru
) {
54 scoped_ptr
<aura::Window
> w1(CreateWindow());
55 scoped_ptr
<aura::Window
> w2(CreateWindow());
56 scoped_ptr
<aura::Window
> w3(CreateWindow());
57 scoped_ptr
<aura::Window
> w4(CreateWindow());
58 scoped_ptr
<aura::Window
> w5(CreateWindow());
59 scoped_ptr
<aura::Window
> w6(CreateWindow());
60 wm::ActivateWindow(w6
.get());
61 wm::ActivateWindow(w5
.get());
62 wm::ActivateWindow(w4
.get());
63 wm::ActivateWindow(w3
.get());
64 wm::ActivateWindow(w2
.get());
65 wm::ActivateWindow(w1
.get());
67 wm::GetWindowState(w1
.get())->Minimize();
68 wm::GetWindowState(w4
.get())->Minimize();
69 wm::GetWindowState(w5
.get())->Minimize();
71 // Expect the relative order of minimized windows to remain the same, but all
72 // minimized windows to be at the end of the list.
73 MruWindowTracker::WindowList window_list
=
74 mru_window_tracker()->BuildMruWindowList();
75 EXPECT_EQ(w2
.get(), window_list
[0]);
76 EXPECT_EQ(w3
.get(), window_list
[1]);
77 EXPECT_EQ(w6
.get(), window_list
[2]);
78 EXPECT_EQ(w1
.get(), window_list
[3]);
79 EXPECT_EQ(w4
.get(), window_list
[4]);
80 EXPECT_EQ(w5
.get(), window_list
[5]);