| 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/aura/wm_window_aura.h" | 9 #include "ash/aura/wm_window_aura.h" |
| 10 #include "ash/common/accelerators/accelerator_controller.h" |
| 10 #include "ash/common/wm/window_state.h" | 11 #include "ash/common/wm/window_state.h" |
| 11 #include "ash/common/wm/wm_event.h" | 12 #include "ash/common/wm/wm_event.h" |
| 12 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
| 13 #include "ash/common/wm_window.h" | 14 #include "ash/common/wm_window.h" |
| 14 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
| 15 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
| 16 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 17 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 18 | 19 |
| 19 namespace ash { | 20 namespace ash { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 int FindIndex(const std::vector<aura::Window*>& windows, | 23 int FindIndex(const std::vector<aura::Window*>& windows, |
| 23 const aura::Window* target) { | 24 const aura::Window* target) { |
| 24 auto iter = std::find(windows.begin(), windows.end(), target); | 25 auto iter = std::find(windows.begin(), windows.end(), target); |
| 25 return iter != windows.end() ? iter - windows.begin() : -1; | 26 return iter != windows.end() ? iter - windows.begin() : -1; |
| 26 } | 27 } |
| 27 | 28 |
| 28 } // namespace | 29 } // namespace |
| 29 | 30 |
| 30 using ScreenPinningControllerTest = test::AshTestBase; | 31 using ScreenPinningControllerTest = test::AshTestBase; |
| 31 | 32 |
| 32 TEST_F(ScreenPinningControllerTest, IsPinned) { | 33 TEST_F(ScreenPinningControllerTest, IsPinned) { |
| 33 aura::Window* w1 = CreateTestWindowInShellWithId(0); | 34 aura::Window* w1 = CreateTestWindowInShellWithId(0); |
| 34 wm::ActivateWindow(w1); | 35 wm::ActivateWindow(w1); |
| 35 | 36 |
| 36 wm::PinWindow(w1); | 37 wm::PinWindow(w1, /* trusted */ false); |
| 37 EXPECT_TRUE(WmShell::Get()->IsPinned()); | 38 EXPECT_TRUE(WmShell::Get()->IsPinned()); |
| 38 } | 39 } |
| 39 | 40 |
| 40 TEST_F(ScreenPinningControllerTest, OnlyOnePinnedWindow) { | 41 TEST_F(ScreenPinningControllerTest, OnlyOnePinnedWindow) { |
| 41 aura::Window* w1 = CreateTestWindowInShellWithId(0); | 42 aura::Window* w1 = CreateTestWindowInShellWithId(0); |
| 42 aura::Window* w2 = CreateTestWindowInShellWithId(1); | 43 aura::Window* w2 = CreateTestWindowInShellWithId(1); |
| 43 wm::ActivateWindow(w1); | 44 wm::ActivateWindow(w1); |
| 44 | 45 |
| 45 wm::PinWindow(w1); | 46 wm::PinWindow(w1, /* trusted */ false); |
| 46 EXPECT_TRUE(WmWindowAura::Get(w1)->GetWindowState()->IsPinned()); | 47 EXPECT_TRUE(WmWindowAura::Get(w1)->GetWindowState()->IsPinned()); |
| 47 EXPECT_FALSE(WmWindowAura::Get(w2)->GetWindowState()->IsPinned()); | 48 EXPECT_FALSE(WmWindowAura::Get(w2)->GetWindowState()->IsPinned()); |
| 48 | 49 |
| 49 // Prohibit to pin two (or more) windows. | 50 // Prohibit to pin two (or more) windows. |
| 50 wm::PinWindow(w2); | 51 wm::PinWindow(w2, /* trusted */ false); |
| 51 EXPECT_TRUE(WmWindowAura::Get(w1)->GetWindowState()->IsPinned()); | 52 EXPECT_TRUE(WmWindowAura::Get(w1)->GetWindowState()->IsPinned()); |
| 52 EXPECT_FALSE(WmWindowAura::Get(w2)->GetWindowState()->IsPinned()); | 53 EXPECT_FALSE(WmWindowAura::Get(w2)->GetWindowState()->IsPinned()); |
| 53 } | 54 } |
| 54 | 55 |
| 55 TEST_F(ScreenPinningControllerTest, FullscreenInPinnedMode) { | 56 TEST_F(ScreenPinningControllerTest, FullscreenInPinnedMode) { |
| 56 aura::Window* w1 = CreateTestWindowInShellWithId(0); | 57 aura::Window* w1 = CreateTestWindowInShellWithId(0); |
| 57 aura::Window* w2 = CreateTestWindowInShellWithId(1); | 58 aura::Window* w2 = CreateTestWindowInShellWithId(1); |
| 58 wm::ActivateWindow(w1); | 59 wm::ActivateWindow(w1); |
| 59 | 60 |
| 60 wm::PinWindow(w1); | 61 wm::PinWindow(w1, /* trusted */ false); |
| 61 { | 62 { |
| 62 // Window w1 should be in front of w2. | 63 // Window w1 should be in front of w2. |
| 63 std::vector<aura::Window*> siblings = w1->parent()->children(); | 64 std::vector<aura::Window*> siblings = w1->parent()->children(); |
| 64 int index1 = FindIndex(siblings, w1); | 65 int index1 = FindIndex(siblings, w1); |
| 65 int index2 = FindIndex(siblings, w2); | 66 int index2 = FindIndex(siblings, w2); |
| 66 EXPECT_NE(-1, index1); | 67 EXPECT_NE(-1, index1); |
| 67 EXPECT_NE(-1, index2); | 68 EXPECT_NE(-1, index2); |
| 68 EXPECT_GT(index1, index2); | 69 EXPECT_GT(index1, index2); |
| 69 } | 70 } |
| 70 | 71 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // Verify that w1 is still in front of w2. | 146 // Verify that w1 is still in front of w2. |
| 146 std::vector<aura::Window*> siblings = w1->parent()->children(); | 147 std::vector<aura::Window*> siblings = w1->parent()->children(); |
| 147 int index1 = FindIndex(siblings, w1); | 148 int index1 = FindIndex(siblings, w1); |
| 148 int index2 = FindIndex(siblings, w2); | 149 int index2 = FindIndex(siblings, w2); |
| 149 EXPECT_NE(-1, index1); | 150 EXPECT_NE(-1, index1); |
| 150 EXPECT_NE(-1, index2); | 151 EXPECT_NE(-1, index2); |
| 151 EXPECT_GT(index2, index1); | 152 EXPECT_GT(index2, index1); |
| 152 } | 153 } |
| 153 } | 154 } |
| 154 | 155 |
| 156 TEST_F(ScreenPinningControllerTest, TrustedPinnedWithAccelerator) { |
| 157 aura::Window* w1 = CreateTestWindowInShellWithId(0); |
| 158 wm::ActivateWindow(w1); |
| 159 |
| 160 wm::PinWindow(w1, /* trusted */ true); |
| 161 EXPECT_TRUE(WmShell::Get()->IsPinned()); |
| 162 |
| 163 WmShell::Get()->accelerator_controller()->PerformActionIfEnabled(UNPIN); |
| 164 EXPECT_TRUE(WmShell::Get()->IsPinned()); |
| 165 } |
| 166 |
| 155 } // namespace ash | 167 } // namespace ash |
| OLD | NEW |