OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/screen_pinning_controller.h" | 5 #include "ash/wm/screen_pinning_controller.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/accelerators/accelerator_controller.h" | 9 #include "ash/accelerators/accelerator_controller.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
12 #include "ash/wm/screen_pinning_controller.h" | 12 #include "ash/wm/screen_pinning_controller.h" |
13 #include "ash/wm/window_state.h" | 13 #include "ash/wm/window_state.h" |
14 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
15 #include "ash/wm/wm_event.h" | 15 #include "ash/wm/wm_event.h" |
16 #include "ash/wm_window.h" | |
17 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
18 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
19 | 18 |
20 namespace ash { | 19 namespace ash { |
21 namespace { | 20 namespace { |
22 | 21 |
23 int FindIndex(const std::vector<aura::Window*>& windows, | 22 int FindIndex(const std::vector<aura::Window*>& windows, |
24 const aura::Window* target) { | 23 const aura::Window* target) { |
25 auto iter = std::find(windows.begin(), windows.end(), target); | 24 auto iter = std::find(windows.begin(), windows.end(), target); |
26 return iter != windows.end() ? iter - windows.begin() : -1; | 25 return iter != windows.end() ? iter - windows.begin() : -1; |
(...skipping 10 matching lines...) Expand all Loading... |
37 wm::PinWindow(w1, /* trusted */ false); | 36 wm::PinWindow(w1, /* trusted */ false); |
38 EXPECT_TRUE(Shell::Get()->screen_pinning_controller()->IsPinned()); | 37 EXPECT_TRUE(Shell::Get()->screen_pinning_controller()->IsPinned()); |
39 } | 38 } |
40 | 39 |
41 TEST_F(ScreenPinningControllerTest, OnlyOnePinnedWindow) { | 40 TEST_F(ScreenPinningControllerTest, OnlyOnePinnedWindow) { |
42 aura::Window* w1 = CreateTestWindowInShellWithId(0); | 41 aura::Window* w1 = CreateTestWindowInShellWithId(0); |
43 aura::Window* w2 = CreateTestWindowInShellWithId(1); | 42 aura::Window* w2 = CreateTestWindowInShellWithId(1); |
44 wm::ActivateWindow(w1); | 43 wm::ActivateWindow(w1); |
45 | 44 |
46 wm::PinWindow(w1, /* trusted */ false); | 45 wm::PinWindow(w1, /* trusted */ false); |
47 EXPECT_TRUE(WmWindow::Get(w1)->GetWindowState()->IsPinned()); | 46 EXPECT_TRUE(wm::GetWindowState(w1)->IsPinned()); |
48 EXPECT_FALSE(WmWindow::Get(w2)->GetWindowState()->IsPinned()); | 47 EXPECT_FALSE(wm::GetWindowState(w2)->IsPinned()); |
49 | 48 |
50 // Prohibit to pin two (or more) windows. | 49 // Prohibit to pin two (or more) windows. |
51 wm::PinWindow(w2, /* trusted */ false); | 50 wm::PinWindow(w2, /* trusted */ false); |
52 EXPECT_TRUE(WmWindow::Get(w1)->GetWindowState()->IsPinned()); | 51 EXPECT_TRUE(wm::GetWindowState(w1)->IsPinned()); |
53 EXPECT_FALSE(WmWindow::Get(w2)->GetWindowState()->IsPinned()); | 52 EXPECT_FALSE(wm::GetWindowState(w2)->IsPinned()); |
54 } | 53 } |
55 | 54 |
56 TEST_F(ScreenPinningControllerTest, FullscreenInPinnedMode) { | 55 TEST_F(ScreenPinningControllerTest, FullscreenInPinnedMode) { |
57 aura::Window* w1 = CreateTestWindowInShellWithId(0); | 56 aura::Window* w1 = CreateTestWindowInShellWithId(0); |
58 aura::Window* w2 = CreateTestWindowInShellWithId(1); | 57 aura::Window* w2 = CreateTestWindowInShellWithId(1); |
59 wm::ActivateWindow(w1); | 58 wm::ActivateWindow(w1); |
60 | 59 |
61 wm::PinWindow(w1, /* trusted */ false); | 60 wm::PinWindow(w1, /* trusted */ false); |
62 { | 61 { |
63 // Window w1 should be in front of w2. | 62 // Window w1 should be in front of w2. |
64 std::vector<aura::Window*> siblings = w1->parent()->children(); | 63 std::vector<aura::Window*> siblings = w1->parent()->children(); |
65 int index1 = FindIndex(siblings, w1); | 64 int index1 = FindIndex(siblings, w1); |
66 int index2 = FindIndex(siblings, w2); | 65 int index2 = FindIndex(siblings, w2); |
67 EXPECT_NE(-1, index1); | 66 EXPECT_NE(-1, index1); |
68 EXPECT_NE(-1, index2); | 67 EXPECT_NE(-1, index2); |
69 EXPECT_GT(index1, index2); | 68 EXPECT_GT(index1, index2); |
70 } | 69 } |
71 | 70 |
72 // Set w2 to fullscreen. | 71 // Set w2 to fullscreen. |
73 { | 72 { |
74 wm::ActivateWindow(w2); | 73 wm::ActivateWindow(w2); |
75 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | 74 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
76 WmWindow::Get(w2)->GetWindowState()->OnWMEvent(&event); | 75 wm::GetWindowState(w2)->OnWMEvent(&event); |
77 } | 76 } |
78 { | 77 { |
79 // Verify that w1 is still in front of w2. | 78 // Verify that w1 is still in front of w2. |
80 std::vector<aura::Window*> siblings = w1->parent()->children(); | 79 std::vector<aura::Window*> siblings = w1->parent()->children(); |
81 int index1 = FindIndex(siblings, w1); | 80 int index1 = FindIndex(siblings, w1); |
82 int index2 = FindIndex(siblings, w2); | 81 int index2 = FindIndex(siblings, w2); |
83 EXPECT_NE(-1, index1); | 82 EXPECT_NE(-1, index1); |
84 EXPECT_NE(-1, index2); | 83 EXPECT_NE(-1, index2); |
85 EXPECT_GT(index1, index2); | 84 EXPECT_GT(index1, index2); |
86 } | 85 } |
87 | 86 |
88 // Unset w2's fullscreen. | 87 // Unset w2's fullscreen. |
89 { | 88 { |
90 wm::ActivateWindow(w2); | 89 wm::ActivateWindow(w2); |
91 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | 90 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
92 WmWindow::Get(w2)->GetWindowState()->OnWMEvent(&event); | 91 wm::GetWindowState(w2)->OnWMEvent(&event); |
93 } | 92 } |
94 { | 93 { |
95 // Verify that w1 is still in front of w2. | 94 // Verify that w1 is still in front of w2. |
96 std::vector<aura::Window*> siblings = w1->parent()->children(); | 95 std::vector<aura::Window*> siblings = w1->parent()->children(); |
97 int index1 = FindIndex(siblings, w1); | 96 int index1 = FindIndex(siblings, w1); |
98 int index2 = FindIndex(siblings, w2); | 97 int index2 = FindIndex(siblings, w2); |
99 EXPECT_NE(-1, index1); | 98 EXPECT_NE(-1, index1); |
100 EXPECT_NE(-1, index2); | 99 EXPECT_NE(-1, index2); |
101 EXPECT_GT(index1, index2); | 100 EXPECT_GT(index1, index2); |
102 } | 101 } |
103 | 102 |
104 // Maximize w2. | 103 // Maximize w2. |
105 { | 104 { |
106 wm::ActivateWindow(w2); | 105 wm::ActivateWindow(w2); |
107 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE); | 106 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE); |
108 WmWindow::Get(w2)->GetWindowState()->OnWMEvent(&event); | 107 wm::GetWindowState(w2)->OnWMEvent(&event); |
109 } | 108 } |
110 { | 109 { |
111 // Verify that w1 is still in front of w2. | 110 // Verify that w1 is still in front of w2. |
112 std::vector<aura::Window*> siblings = w1->parent()->children(); | 111 std::vector<aura::Window*> siblings = w1->parent()->children(); |
113 int index1 = FindIndex(siblings, w1); | 112 int index1 = FindIndex(siblings, w1); |
114 int index2 = FindIndex(siblings, w2); | 113 int index2 = FindIndex(siblings, w2); |
115 EXPECT_NE(-1, index1); | 114 EXPECT_NE(-1, index1); |
116 EXPECT_NE(-1, index2); | 115 EXPECT_NE(-1, index2); |
117 EXPECT_GT(index1, index2); | 116 EXPECT_GT(index1, index2); |
118 } | 117 } |
119 | 118 |
120 // Unset w2's maximize. | 119 // Unset w2's maximize. |
121 { | 120 { |
122 wm::ActivateWindow(w2); | 121 wm::ActivateWindow(w2); |
123 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE); | 122 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE); |
124 WmWindow::Get(w2)->GetWindowState()->OnWMEvent(&event); | 123 wm::GetWindowState(w2)->OnWMEvent(&event); |
125 } | 124 } |
126 { | 125 { |
127 // Verify that w1 is still in front of w2. | 126 // Verify that w1 is still in front of w2. |
128 std::vector<aura::Window*> siblings = w1->parent()->children(); | 127 std::vector<aura::Window*> siblings = w1->parent()->children(); |
129 int index1 = FindIndex(siblings, w1); | 128 int index1 = FindIndex(siblings, w1); |
130 int index2 = FindIndex(siblings, w2); | 129 int index2 = FindIndex(siblings, w2); |
131 EXPECT_NE(-1, index1); | 130 EXPECT_NE(-1, index1); |
132 EXPECT_NE(-1, index2); | 131 EXPECT_NE(-1, index2); |
133 EXPECT_GT(index1, index2); | 132 EXPECT_GT(index1, index2); |
134 } | 133 } |
135 | 134 |
136 // Restore w1. | 135 // Restore w1. |
137 WmWindow::Get(w1)->GetWindowState()->Restore(); | 136 wm::GetWindowState(w1)->Restore(); |
138 | 137 |
139 // Now, fullscreen-ize w2 should put it in front of w1. | 138 // Now, fullscreen-ize w2 should put it in front of w1. |
140 { | 139 { |
141 wm::ActivateWindow(w2); | 140 wm::ActivateWindow(w2); |
142 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | 141 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
143 WmWindow::Get(w2)->GetWindowState()->OnWMEvent(&event); | 142 wm::GetWindowState(w2)->OnWMEvent(&event); |
144 } | 143 } |
145 { | 144 { |
146 // Verify that w1 is still in front of w2. | 145 // Verify that w1 is still in front of w2. |
147 std::vector<aura::Window*> siblings = w1->parent()->children(); | 146 std::vector<aura::Window*> siblings = w1->parent()->children(); |
148 int index1 = FindIndex(siblings, w1); | 147 int index1 = FindIndex(siblings, w1); |
149 int index2 = FindIndex(siblings, w2); | 148 int index2 = FindIndex(siblings, w2); |
150 EXPECT_NE(-1, index1); | 149 EXPECT_NE(-1, index1); |
151 EXPECT_NE(-1, index2); | 150 EXPECT_NE(-1, index2); |
152 EXPECT_GT(index2, index1); | 151 EXPECT_GT(index2, index1); |
153 } | 152 } |
154 } | 153 } |
155 | 154 |
156 TEST_F(ScreenPinningControllerTest, TrustedPinnedWithAccelerator) { | 155 TEST_F(ScreenPinningControllerTest, TrustedPinnedWithAccelerator) { |
157 aura::Window* w1 = CreateTestWindowInShellWithId(0); | 156 aura::Window* w1 = CreateTestWindowInShellWithId(0); |
158 wm::ActivateWindow(w1); | 157 wm::ActivateWindow(w1); |
159 | 158 |
160 wm::PinWindow(w1, /* trusted */ true); | 159 wm::PinWindow(w1, /* trusted */ true); |
161 EXPECT_TRUE(Shell::Get()->screen_pinning_controller()->IsPinned()); | 160 EXPECT_TRUE(Shell::Get()->screen_pinning_controller()->IsPinned()); |
162 | 161 |
163 Shell::Get()->accelerator_controller()->PerformActionIfEnabled(UNPIN); | 162 Shell::Get()->accelerator_controller()->PerformActionIfEnabled(UNPIN); |
164 // The UNPIN accelerator key is disabled for trusted pinned and the window | 163 // The UNPIN accelerator key is disabled for trusted pinned and the window |
165 // must be still pinned. | 164 // must be still pinned. |
166 EXPECT_TRUE(Shell::Get()->screen_pinning_controller()->IsPinned()); | 165 EXPECT_TRUE(Shell::Get()->screen_pinning_controller()->IsPinned()); |
167 } | 166 } |
168 | 167 |
169 } // namespace ash | 168 } // namespace ash |
OLD | NEW |