Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: ash/wm/mru_window_tracker_unittest.cc

Issue 2411913003: Converts ash/wm/mru_window_tracker_unittest.cc to use AshTest (Closed)
Patch Set: comment Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/mus/wm/mru_window_tracker_unittest.cc ('k') | services/ui/public/cpp/window.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/common/wm/mru_window_tracker.h" 5 #include "ash/common/wm/mru_window_tracker.h"
6 6
7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/shell_window_ids.h" 7 #include "ash/common/shell_window_ids.h"
8 #include "ash/common/test/ash_test.h"
9 #include "ash/common/wm/window_state.h" 9 #include "ash/common/wm/window_state.h"
10 #include "ash/common/wm_shell.h" 10 #include "ash/common/wm_shell.h"
11 #include "ash/shell.h" 11 #include "ash/common/wm_window.h"
12 #include "ash/test/ash_test_base.h"
13 #include "ash/wm/window_state_aura.h"
14 #include "ash/wm/window_util.h"
15 #include "ui/aura/window.h"
16 #include "ui/base/hit_test.h" 12 #include "ui/base/hit_test.h"
17 #include "ui/views/widget/widget.h"
18 13
19 namespace ash { 14 namespace ash {
20 15
21 class MruWindowTrackerTest : public test::AshTestBase { 16 class MruWindowTrackerTest : public AshTest {
22 public: 17 public:
23 MruWindowTrackerTest() {} 18 MruWindowTrackerTest() {}
24 ~MruWindowTrackerTest() override {} 19 ~MruWindowTrackerTest() override {}
25 20
26 aura::Window* CreateWindow() { 21 std::unique_ptr<WindowOwner> CreateTestWindow() {
27 return CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 400, 400)); 22 return AshTest::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
28 } 23 }
29 24
30 ash::MruWindowTracker* mru_window_tracker() { 25 MruWindowTracker* mru_window_tracker() {
31 return WmShell::Get()->mru_window_tracker(); 26 return WmShell::Get()->mru_window_tracker();
32 } 27 }
33 28
34 private: 29 private:
35 DISALLOW_COPY_AND_ASSIGN(MruWindowTrackerTest); 30 DISALLOW_COPY_AND_ASSIGN(MruWindowTrackerTest);
36 }; 31 };
37 32
38 // Basic test that the activation order is tracked. 33 // Basic test that the activation order is tracked.
39 TEST_F(MruWindowTrackerTest, Basic) { 34 TEST_F(MruWindowTrackerTest, Basic) {
40 std::unique_ptr<aura::Window> w1(CreateWindow()); 35 std::unique_ptr<WindowOwner> w1_owner(CreateTestWindow());
41 std::unique_ptr<aura::Window> w2(CreateWindow()); 36 WmWindow* w1 = w1_owner->window();
42 std::unique_ptr<aura::Window> w3(CreateWindow()); 37 std::unique_ptr<WindowOwner> w2_owner(CreateTestWindow());
43 wm::ActivateWindow(w3.get()); 38 WmWindow* w2 = w2_owner->window();
44 wm::ActivateWindow(w2.get()); 39 std::unique_ptr<WindowOwner> w3_owner(CreateTestWindow());
45 wm::ActivateWindow(w1.get()); 40 WmWindow* w3 = w3_owner->window();
41 w3->Activate();
42 w2->Activate();
43 w1->Activate();
46 44
47 aura::Window::Windows window_list = 45 WmWindow::Windows window_list = mru_window_tracker()->BuildMruWindowList();
48 WmWindowAura::ToAuraWindows(mru_window_tracker()->BuildMruWindowList()); 46 EXPECT_EQ(w1, window_list[0]);
49 EXPECT_EQ(w1.get(), window_list[0]); 47 EXPECT_EQ(w2, window_list[1]);
50 EXPECT_EQ(w2.get(), window_list[1]); 48 EXPECT_EQ(w3, window_list[2]);
51 EXPECT_EQ(w3.get(), window_list[2]);
52 } 49 }
53 50
54 // Test that minimized windows are not treated specially. 51 // Test that minimized windows are not treated specially.
55 TEST_F(MruWindowTrackerTest, MinimizedWindowsAreLru) { 52 TEST_F(MruWindowTrackerTest, MinimizedWindowsAreLru) {
56 std::unique_ptr<aura::Window> w1(CreateWindow()); 53 // TODO(sky): fix me. Fails in mash because of http://crbug.com/654887.
57 std::unique_ptr<aura::Window> w2(CreateWindow()); 54 if (WmShell::Get()->IsRunningInMash())
58 std::unique_ptr<aura::Window> w3(CreateWindow()); 55 return;
59 std::unique_ptr<aura::Window> w4(CreateWindow());
60 std::unique_ptr<aura::Window> w5(CreateWindow());
61 std::unique_ptr<aura::Window> w6(CreateWindow());
62 wm::ActivateWindow(w6.get());
63 wm::ActivateWindow(w5.get());
64 wm::ActivateWindow(w4.get());
65 wm::ActivateWindow(w3.get());
66 wm::ActivateWindow(w2.get());
67 wm::ActivateWindow(w1.get());
68 56
69 wm::GetWindowState(w1.get())->Minimize(); 57 std::unique_ptr<WindowOwner> w1_owner(CreateTestWindow());
70 wm::GetWindowState(w4.get())->Minimize(); 58 WmWindow* w1 = w1_owner->window();
71 wm::GetWindowState(w5.get())->Minimize(); 59 std::unique_ptr<WindowOwner> w2_owner(CreateTestWindow());
60 WmWindow* w2 = w2_owner->window();
61 std::unique_ptr<WindowOwner> w3_owner(CreateTestWindow());
62 WmWindow* w3 = w3_owner->window();
63 std::unique_ptr<WindowOwner> w4_owner(CreateTestWindow());
64 WmWindow* w4 = w4_owner->window();
65 std::unique_ptr<WindowOwner> w5_owner(CreateTestWindow());
66 WmWindow* w5 = w5_owner->window();
67 std::unique_ptr<WindowOwner> w6_owner(CreateTestWindow());
68 WmWindow* w6 = w6_owner->window();
69 w6->Activate();
70 w5->Activate();
71 w4->Activate();
72 w3->Activate();
73 w2->Activate();
74 w1->Activate();
75
76 w1->GetWindowState()->Minimize();
77 w4->GetWindowState()->Minimize();
78 w5->GetWindowState()->Minimize();
72 79
73 // By minimizing the first window, we activate w2 which will move it to the 80 // By minimizing the first window, we activate w2 which will move it to the
74 // front of the MRU queue. 81 // front of the MRU queue.
75 EXPECT_TRUE(wm::GetWindowState(w2.get())->IsActive()); 82 EXPECT_TRUE(w2->IsActive());
76 83
77 aura::Window::Windows window_list = 84 WmWindow::Windows window_list = mru_window_tracker()->BuildMruWindowList();
78 WmWindowAura::ToAuraWindows(mru_window_tracker()->BuildMruWindowList()); 85 EXPECT_EQ(w2, window_list[0]);
79 EXPECT_EQ(w2.get(), window_list[0]); 86 EXPECT_EQ(w1, window_list[1]);
80 EXPECT_EQ(w1.get(), window_list[1]); 87 EXPECT_EQ(w3, window_list[2]);
81 EXPECT_EQ(w3.get(), window_list[2]); 88 EXPECT_EQ(w4, window_list[3]);
82 EXPECT_EQ(w4.get(), window_list[3]); 89 EXPECT_EQ(w5, window_list[4]);
83 EXPECT_EQ(w5.get(), window_list[4]); 90 EXPECT_EQ(w6, window_list[5]);
84 EXPECT_EQ(w6.get(), window_list[5]);
85 } 91 }
86 92
87 // Tests that windows being dragged are only in the WindowList once. 93 // Tests that windows being dragged are only in the WindowList once.
88 TEST_F(MruWindowTrackerTest, DraggedWindowsInListOnlyOnce) { 94 TEST_F(MruWindowTrackerTest, DraggedWindowsInListOnlyOnce) {
89 std::unique_ptr<aura::Window> w1(CreateWindow()); 95 std::unique_ptr<WindowOwner> w1_owner(CreateTestWindow());
90 wm::ActivateWindow(w1.get()); 96 WmWindow* w1 = w1_owner->window();
97 w1->Activate();
91 98
92 // Start dragging the window. 99 // Start dragging the window.
93 wm::GetWindowState(w1.get())->CreateDragDetails( 100 w1->GetWindowState()->CreateDragDetails(
94 gfx::Point(), HTRIGHT, aura::client::WINDOW_MOVE_SOURCE_TOUCH); 101 gfx::Point(), HTRIGHT, aura::client::WINDOW_MOVE_SOURCE_TOUCH);
95 102
96 // During a drag the window is reparented by the Docked container. 103 // During a drag the window is reparented by the Docked container.
97 aura::Window* drag_container = Shell::GetContainer( 104 WmWindow* drag_container = w1->GetRootWindow()->GetChildByShellWindowId(
98 Shell::GetTargetRootWindow(), kShellWindowId_DockedContainer); 105 kShellWindowId_DockedContainer);
99 drag_container->AddChild(w1.get()); 106 drag_container->AddChild(w1);
100 EXPECT_TRUE(wm::GetWindowState(w1.get())->is_dragged()); 107 EXPECT_TRUE(w1->GetWindowState()->is_dragged());
101 108
102 // The dragged window should only be in the list once. 109 // The dragged window should only be in the list once.
103 aura::Window::Windows window_list = WmWindowAura::ToAuraWindows( 110 WmWindow::Windows window_list =
104 mru_window_tracker()->BuildWindowListIgnoreModal()); 111 mru_window_tracker()->BuildWindowListIgnoreModal();
105 EXPECT_EQ(1, std::count(window_list.begin(), window_list.end(), w1.get())); 112 EXPECT_EQ(1, std::count(window_list.begin(), window_list.end(), w1));
106 } 113 }
107 114
108 // Tests that windows with propery of |kExcludeFromMruKey|==true are not in the 115 // Tests that windows with propery of |kExcludeFromMruKey|==true are not in the
109 // window list. 116 // window list.
110 TEST_F(MruWindowTrackerTest, ExcludedFormMru) { 117 TEST_F(MruWindowTrackerTest, ExcludedFromMru) {
111 std::unique_ptr<aura::Window> w1(CreateWindow()); 118 std::unique_ptr<WindowOwner> w1_owner(CreateTestWindow());
112 std::unique_ptr<aura::Window> w2(CreateWindow()); 119 WmWindow* w1 = w1_owner->window();
113 std::unique_ptr<aura::Window> w3(CreateWindow()); 120 std::unique_ptr<WindowOwner> w2_owner(CreateTestWindow());
121 WmWindow* w2 = w2_owner->window();
122 std::unique_ptr<WindowOwner> w3_owner(CreateTestWindow());
123 WmWindow* w3 = w3_owner->window();
114 124
115 wm::GetWindowState(w1.get())->SetExcludedFromMru(true); 125 w1->GetWindowState()->SetExcludedFromMru(true);
116 wm::GetWindowState(w3.get())->SetExcludedFromMru(true); 126 w3->GetWindowState()->SetExcludedFromMru(true);
117 127
118 wm::ActivateWindow(w3.get()); 128 w3->Activate();
119 wm::ActivateWindow(w2.get()); 129 w2->Activate();
120 wm::ActivateWindow(w1.get()); 130 w1->Activate();
121 131
122 // Expect the windows with |kExcludeFromMruKey| property being true are not 132 // Expect the windows with |kExcludeFromMruKey| property being true are not
123 // in the list. 133 // in the list.
124 aura::Window::Windows window_list = 134 WmWindow::Windows window_list = mru_window_tracker()->BuildMruWindowList();
125 WmWindowAura::ToAuraWindows(mru_window_tracker()->BuildMruWindowList());
126 135
127 EXPECT_EQ(window_list.end(), 136 // As |w1| and |w3| are excluded from the list, only |w2| should be present.
128 std::find(window_list.begin(), window_list.end(), w1.get())); 137 ASSERT_EQ(1u, window_list.size());
129 EXPECT_EQ(window_list.end(), 138 EXPECT_EQ(w2, window_list[0]);
130 std::find(window_list.begin(), window_list.end(), w3.get()));
131 EXPECT_EQ(1u, window_list.size());
132 } 139 }
133 140
134 } // namespace ash 141 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/wm/mru_window_tracker_unittest.cc ('k') | services/ui/public/cpp/window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698