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

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

Issue 2042913002: Converts MruWindowTracker to work with common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tweaks Created 4 years, 6 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
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/wm/mru_window_tracker.h"
James Cook 2016/06/07 01:21:05 Thanks for moving this up. It's one of my pet peev
6
7 #include "ash/aura/wm_window_aura.h"
5 #include "ash/common/shell_window_ids.h" 8 #include "ash/common/shell_window_ids.h"
6 #include "ash/common/wm/window_state.h" 9 #include "ash/common/wm/window_state.h"
7 #include "ash/shell.h" 10 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 11 #include "ash/test/ash_test_base.h"
9 #include "ash/test/test_shelf_delegate.h" 12 #include "ash/test/test_shelf_delegate.h"
James Cook 2016/06/07 01:21:05 While you're here, I don't think this is needed.
sky 2016/06/07 02:46:21 Done.
10 #include "ash/wm/mru_window_tracker.h"
11 #include "ash/wm/window_state_aura.h" 13 #include "ash/wm/window_state_aura.h"
12 #include "ash/wm/window_util.h" 14 #include "ash/wm/window_util.h"
13 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
James Cook 2016/06/07 01:21:05 or this
sky 2016/06/07 02:46:21 Done.
14 #include "ui/aura/test/test_window_delegate.h" 16 #include "ui/aura/test/test_window_delegate.h"
James Cook 2016/06/07 01:21:05 or this
sky 2016/06/07 02:46:21 Done.
15 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
16 #include "ui/base/hit_test.h" 18 #include "ui/base/hit_test.h"
17 #include "ui/views/widget/widget.h" 19 #include "ui/views/widget/widget.h"
18 20
19 namespace ash { 21 namespace ash {
20 22
21 class MruWindowTrackerTest : public test::AshTestBase { 23 class MruWindowTrackerTest : public test::AshTestBase {
22 public: 24 public:
23 MruWindowTrackerTest() {} 25 MruWindowTrackerTest() {}
24 ~MruWindowTrackerTest() override {} 26 ~MruWindowTrackerTest() override {}
25 27
26 aura::Window* CreateWindow() { 28 aura::Window* CreateWindow() {
27 return CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 400, 400)); 29 return CreateTestWindowInShellWithBounds(gfx::Rect(0, 0, 400, 400));
28 } 30 }
29 31
30 ash::MruWindowTracker* mru_window_tracker() { 32 ash::MruWindowTracker* mru_window_tracker() {
31 return Shell::GetInstance()->mru_window_tracker(); 33 return Shell::GetInstance()->mru_window_tracker();
32 } 34 }
33 35
34 private: 36 private:
35 DISALLOW_COPY_AND_ASSIGN(MruWindowTrackerTest); 37 DISALLOW_COPY_AND_ASSIGN(MruWindowTrackerTest);
36 }; 38 };
37 39
38 // Basic test that the activation order is tracked. 40 // Basic test that the activation order is tracked.
39 TEST_F(MruWindowTrackerTest, Basic) { 41 TEST_F(MruWindowTrackerTest, Basic) {
40 std::unique_ptr<aura::Window> w1(CreateWindow()); 42 std::unique_ptr<aura::Window> w1(CreateWindow());
James Cook 2016/06/07 01:21:05 It seems like this test could be converted to crea
sky 2016/06/07 02:46:21 I will convert the test separately.
James Cook 2016/06/07 14:05:38 Acknowledged.
41 std::unique_ptr<aura::Window> w2(CreateWindow()); 43 std::unique_ptr<aura::Window> w2(CreateWindow());
42 std::unique_ptr<aura::Window> w3(CreateWindow()); 44 std::unique_ptr<aura::Window> w3(CreateWindow());
43 wm::ActivateWindow(w3.get()); 45 wm::ActivateWindow(w3.get());
44 wm::ActivateWindow(w2.get()); 46 wm::ActivateWindow(w2.get());
45 wm::ActivateWindow(w1.get()); 47 wm::ActivateWindow(w1.get());
46 48
47 MruWindowTracker::WindowList window_list = 49 aura::Window::Windows window_list =
48 mru_window_tracker()->BuildMruWindowList(); 50 WmWindowAura::ToAuraWindows(mru_window_tracker()->BuildMruWindowList());
49 EXPECT_EQ(w1.get(), window_list[0]); 51 EXPECT_EQ(w1.get(), window_list[0]);
50 EXPECT_EQ(w2.get(), window_list[1]); 52 EXPECT_EQ(w2.get(), window_list[1]);
51 EXPECT_EQ(w3.get(), window_list[2]); 53 EXPECT_EQ(w3.get(), window_list[2]);
52 } 54 }
53 55
54 // Test that minimized windows are considered least recently used (but kept in 56 // Test that minimized windows are considered least recently used (but kept in
55 // correct relative order). 57 // correct relative order).
56 TEST_F(MruWindowTrackerTest, MinimizedWindowsAreLru) { 58 TEST_F(MruWindowTrackerTest, MinimizedWindowsAreLru) {
57 std::unique_ptr<aura::Window> w1(CreateWindow()); 59 std::unique_ptr<aura::Window> w1(CreateWindow());
58 std::unique_ptr<aura::Window> w2(CreateWindow()); 60 std::unique_ptr<aura::Window> w2(CreateWindow());
59 std::unique_ptr<aura::Window> w3(CreateWindow()); 61 std::unique_ptr<aura::Window> w3(CreateWindow());
60 std::unique_ptr<aura::Window> w4(CreateWindow()); 62 std::unique_ptr<aura::Window> w4(CreateWindow());
61 std::unique_ptr<aura::Window> w5(CreateWindow()); 63 std::unique_ptr<aura::Window> w5(CreateWindow());
62 std::unique_ptr<aura::Window> w6(CreateWindow()); 64 std::unique_ptr<aura::Window> w6(CreateWindow());
63 wm::ActivateWindow(w6.get()); 65 wm::ActivateWindow(w6.get());
64 wm::ActivateWindow(w5.get()); 66 wm::ActivateWindow(w5.get());
65 wm::ActivateWindow(w4.get()); 67 wm::ActivateWindow(w4.get());
66 wm::ActivateWindow(w3.get()); 68 wm::ActivateWindow(w3.get());
67 wm::ActivateWindow(w2.get()); 69 wm::ActivateWindow(w2.get());
68 wm::ActivateWindow(w1.get()); 70 wm::ActivateWindow(w1.get());
69 71
70 wm::GetWindowState(w1.get())->Minimize(); 72 wm::GetWindowState(w1.get())->Minimize();
71 wm::GetWindowState(w4.get())->Minimize(); 73 wm::GetWindowState(w4.get())->Minimize();
72 wm::GetWindowState(w5.get())->Minimize(); 74 wm::GetWindowState(w5.get())->Minimize();
73 75
74 // Expect the relative order of minimized windows to remain the same, but all 76 // Expect the relative order of minimized windows to remain the same, but all
75 // minimized windows to be at the end of the list. 77 // minimized windows to be at the end of the list.
76 MruWindowTracker::WindowList window_list = 78 aura::Window::Windows window_list =
77 mru_window_tracker()->BuildMruWindowList(); 79 WmWindowAura::ToAuraWindows(mru_window_tracker()->BuildMruWindowList());
78 EXPECT_EQ(w2.get(), window_list[0]); 80 EXPECT_EQ(w2.get(), window_list[0]);
79 EXPECT_EQ(w3.get(), window_list[1]); 81 EXPECT_EQ(w3.get(), window_list[1]);
80 EXPECT_EQ(w6.get(), window_list[2]); 82 EXPECT_EQ(w6.get(), window_list[2]);
81 EXPECT_EQ(w1.get(), window_list[3]); 83 EXPECT_EQ(w1.get(), window_list[3]);
82 EXPECT_EQ(w4.get(), window_list[4]); 84 EXPECT_EQ(w4.get(), window_list[4]);
83 EXPECT_EQ(w5.get(), window_list[5]); 85 EXPECT_EQ(w5.get(), window_list[5]);
84 } 86 }
85 87
86 // Tests that windows being dragged are only in the WindowList once. 88 // Tests that windows being dragged are only in the WindowList once.
87 TEST_F(MruWindowTrackerTest, DraggedWindowsInListOnlyOnce) { 89 TEST_F(MruWindowTrackerTest, DraggedWindowsInListOnlyOnce) {
88 std::unique_ptr<aura::Window> w1(CreateWindow()); 90 std::unique_ptr<aura::Window> w1(CreateWindow());
89 wm::ActivateWindow(w1.get()); 91 wm::ActivateWindow(w1.get());
90 92
91 // Start dragging the window. 93 // Start dragging the window.
92 wm::GetWindowState(w1.get())->CreateDragDetails( 94 wm::GetWindowState(w1.get())->CreateDragDetails(
93 gfx::Point(), HTRIGHT, aura::client::WINDOW_MOVE_SOURCE_TOUCH); 95 gfx::Point(), HTRIGHT, aura::client::WINDOW_MOVE_SOURCE_TOUCH);
94 96
95 // During a drag the window is reparented by the Docked container. 97 // During a drag the window is reparented by the Docked container.
96 aura::Window* drag_container = Shell::GetContainer( 98 aura::Window* drag_container = Shell::GetContainer(
97 Shell::GetTargetRootWindow(), kShellWindowId_DockedContainer); 99 Shell::GetTargetRootWindow(), kShellWindowId_DockedContainer);
98 drag_container->AddChild(w1.get()); 100 drag_container->AddChild(w1.get());
99 EXPECT_TRUE(wm::GetWindowState(w1.get())->is_dragged()); 101 EXPECT_TRUE(wm::GetWindowState(w1.get())->is_dragged());
100 102
101 // The dragged window should only be in the list once. 103 // The dragged window should only be in the list once.
102 MruWindowTracker::WindowList window_list = 104 aura::Window::Windows window_list = WmWindowAura::ToAuraWindows(
103 mru_window_tracker()->BuildWindowListIgnoreModal(); 105 mru_window_tracker()->BuildWindowListIgnoreModal());
104 EXPECT_EQ(1, std::count(window_list.begin(), window_list.end(), w1.get())); 106 EXPECT_EQ(1, std::count(window_list.begin(), window_list.end(), w1.get()));
105 } 107 }
106 108
107 } // namespace ash 109 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698