OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/wm/screen_pinning_controller.h" |
| 6 |
| 7 #include <vector> |
| 8 |
| 9 #include "ash/aura/wm_window_aura.h" |
| 10 #include "ash/common/wm/window_state.h" |
| 11 #include "ash/common/wm/wm_event.h" |
| 12 #include "ash/common/wm_shell.h" |
| 13 #include "ash/common/wm_window.h" |
| 14 #include "ash/test/ash_test_base.h" |
| 15 #include "ash/wm/window_util.h" |
| 16 #include "base/stl_util.h" |
| 17 #include "ui/aura/window.h" |
| 18 |
| 19 namespace ash { |
| 20 namespace { |
| 21 |
| 22 int FindIndex(const std::vector<aura::Window*>& windows, |
| 23 const aura::Window* target) { |
| 24 auto iter = std::find(windows.begin(), windows.end(), target); |
| 25 return iter != windows.end() ? iter - windows.begin() : -1; |
| 26 } |
| 27 |
| 28 } // namespace |
| 29 |
| 30 using ScreenPinningControllerTest = test::AshTestBase; |
| 31 |
| 32 TEST_F(ScreenPinningControllerTest, IsPinned) { |
| 33 aura::Window* w1 = CreateTestWindowInShellWithId(0); |
| 34 wm::ActivateWindow(w1); |
| 35 |
| 36 wm::PinWindow(w1); |
| 37 EXPECT_TRUE(WmShell::Get()->IsPinned()); |
| 38 } |
| 39 |
| 40 TEST_F(ScreenPinningControllerTest, OnlyOnePinnedWindow) { |
| 41 aura::Window* w1 = CreateTestWindowInShellWithId(0); |
| 42 aura::Window* w2 = CreateTestWindowInShellWithId(1); |
| 43 wm::ActivateWindow(w1); |
| 44 |
| 45 wm::PinWindow(w1); |
| 46 EXPECT_TRUE(WmWindowAura::Get(w1)->GetWindowState()->IsPinned()); |
| 47 EXPECT_FALSE(WmWindowAura::Get(w2)->GetWindowState()->IsPinned()); |
| 48 |
| 49 // Prohibit to pin two (or more) windows. |
| 50 wm::PinWindow(w2); |
| 51 EXPECT_TRUE(WmWindowAura::Get(w1)->GetWindowState()->IsPinned()); |
| 52 EXPECT_FALSE(WmWindowAura::Get(w2)->GetWindowState()->IsPinned()); |
| 53 } |
| 54 |
| 55 TEST_F(ScreenPinningControllerTest, FullscreenInPinnedMode) { |
| 56 aura::Window* w1 = CreateTestWindowInShellWithId(0); |
| 57 aura::Window* w2 = CreateTestWindowInShellWithId(1); |
| 58 wm::ActivateWindow(w1); |
| 59 |
| 60 wm::PinWindow(w1); |
| 61 { |
| 62 // Window w1 should be in front of w2. |
| 63 std::vector<aura::Window*> siblings = w1->parent()->children(); |
| 64 int index1 = FindIndex(siblings, w1); |
| 65 int index2 = FindIndex(siblings, w2); |
| 66 EXPECT_NE(-1, index1); |
| 67 EXPECT_NE(-1, index2); |
| 68 EXPECT_GT(index1, index2); |
| 69 } |
| 70 |
| 71 // Set w2 to fullscreen. |
| 72 { |
| 73 wm::ActivateWindow(w2); |
| 74 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
| 75 WmWindowAura::Get(w2)->GetWindowState()->OnWMEvent(&event); |
| 76 } |
| 77 { |
| 78 // Verify that w1 is still in front of w2. |
| 79 std::vector<aura::Window*> siblings = w1->parent()->children(); |
| 80 int index1 = FindIndex(siblings, w1); |
| 81 int index2 = FindIndex(siblings, w2); |
| 82 EXPECT_NE(-1, index1); |
| 83 EXPECT_NE(-1, index2); |
| 84 EXPECT_GT(index1, index2); |
| 85 } |
| 86 |
| 87 // Unset w2's fullscreen. |
| 88 { |
| 89 wm::ActivateWindow(w2); |
| 90 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
| 91 WmWindowAura::Get(w2)->GetWindowState()->OnWMEvent(&event); |
| 92 } |
| 93 { |
| 94 // Verify that w1 is still in front of w2. |
| 95 std::vector<aura::Window*> siblings = w1->parent()->children(); |
| 96 int index1 = FindIndex(siblings, w1); |
| 97 int index2 = FindIndex(siblings, w2); |
| 98 EXPECT_NE(-1, index1); |
| 99 EXPECT_NE(-1, index2); |
| 100 EXPECT_GT(index1, index2); |
| 101 } |
| 102 |
| 103 // Maximize w2. |
| 104 { |
| 105 wm::ActivateWindow(w2); |
| 106 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE); |
| 107 WmWindowAura::Get(w2)->GetWindowState()->OnWMEvent(&event); |
| 108 } |
| 109 { |
| 110 // Verify that w1 is still in front of w2. |
| 111 std::vector<aura::Window*> siblings = w1->parent()->children(); |
| 112 int index1 = FindIndex(siblings, w1); |
| 113 int index2 = FindIndex(siblings, w2); |
| 114 EXPECT_NE(-1, index1); |
| 115 EXPECT_NE(-1, index2); |
| 116 EXPECT_GT(index1, index2); |
| 117 } |
| 118 |
| 119 // Unset w2's maximize. |
| 120 { |
| 121 wm::ActivateWindow(w2); |
| 122 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE); |
| 123 WmWindowAura::Get(w2)->GetWindowState()->OnWMEvent(&event); |
| 124 } |
| 125 { |
| 126 // Verify that w1 is still in front of w2. |
| 127 std::vector<aura::Window*> siblings = w1->parent()->children(); |
| 128 int index1 = FindIndex(siblings, w1); |
| 129 int index2 = FindIndex(siblings, w2); |
| 130 EXPECT_NE(-1, index1); |
| 131 EXPECT_NE(-1, index2); |
| 132 EXPECT_GT(index1, index2); |
| 133 } |
| 134 |
| 135 // Restore w1. |
| 136 WmWindowAura::Get(w1)->GetWindowState()->Restore(); |
| 137 |
| 138 // Now, fullscreen-ize w2 should put it in front of w1. |
| 139 { |
| 140 wm::ActivateWindow(w2); |
| 141 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
| 142 WmWindowAura::Get(w2)->GetWindowState()->OnWMEvent(&event); |
| 143 } |
| 144 { |
| 145 // Verify that w1 is still in front of w2. |
| 146 std::vector<aura::Window*> siblings = w1->parent()->children(); |
| 147 int index1 = FindIndex(siblings, w1); |
| 148 int index2 = FindIndex(siblings, w2); |
| 149 EXPECT_NE(-1, index1); |
| 150 EXPECT_NE(-1, index2); |
| 151 EXPECT_GT(index2, index1); |
| 152 } |
| 153 } |
| 154 |
| 155 } // namespace ash |
OLD | NEW |