Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
|
oshima
2016/06/18 04:47:44
nit: 2016
hidehiko
2016/06/18 05:32:45
Done.
| |
| 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 test { | |
|
oshima
2016/06/18 04:47:45
we keep ash::test for test utility (at least in as
hidehiko
2016/06/18 05:32:45
Done.
| |
| 21 namespace { | |
| 22 | |
| 23 int FindIndex(const std::vector<aura::Window*>& windows, | |
| 24 const aura::Window* target) { | |
| 25 auto iter = std::find(windows.begin(), windows.end(), target); | |
| 26 return iter != windows.end() ? iter - windows.begin() : -1; | |
| 27 } | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 31 class ScreenPinningControllerTest : public test::AshTestBase { | |
| 32 public: | |
| 33 ScreenPinningControllerTest() = default; | |
| 34 ~ScreenPinningControllerTest() override = default; | |
| 35 }; | |
|
oshima
2016/06/18 04:47:44
using ScreenPinningControllerTest = test::AshTestB
hidehiko
2016/06/18 05:32:45
Done.
| |
| 36 | |
| 37 TEST_F(ScreenPinningControllerTest, IsPinned) { | |
| 38 aura::Window* w1 = CreateTestWindowInShellWithId(0); | |
| 39 wm::ActivateWindow(w1); | |
| 40 | |
| 41 wm::PinWindow(w1); | |
| 42 EXPECT_TRUE(WmShell::Get()->IsPinned()); | |
| 43 } | |
| 44 | |
| 45 TEST_F(ScreenPinningControllerTest, OnlyOnePinnedWindow) { | |
| 46 aura::Window* w1 = CreateTestWindowInShellWithId(0); | |
| 47 aura::Window* w2 = CreateTestWindowInShellWithId(1); | |
| 48 wm::ActivateWindow(w1); | |
| 49 | |
| 50 wm::PinWindow(w1); | |
| 51 EXPECT_TRUE(WmWindowAura::Get(w1)->GetWindowState()->IsPinned()); | |
| 52 EXPECT_FALSE(WmWindowAura::Get(w2)->GetWindowState()->IsPinned()); | |
| 53 | |
| 54 // Prohibit to pin two (or more) windows. | |
| 55 wm::PinWindow(w2); | |
| 56 EXPECT_TRUE(WmWindowAura::Get(w1)->GetWindowState()->IsPinned()); | |
| 57 EXPECT_FALSE(WmWindowAura::Get(w2)->GetWindowState()->IsPinned()); | |
| 58 } | |
| 59 | |
| 60 TEST_F(ScreenPinningControllerTest, FullscreenInPinnedMode) { | |
| 61 aura::Window* w1 = CreateTestWindowInShellWithId(0); | |
| 62 aura::Window* w2 = CreateTestWindowInShellWithId(1); | |
| 63 wm::ActivateWindow(w1); | |
| 64 | |
| 65 wm::PinWindow(w1); | |
| 66 { | |
| 67 // Window w1 should be in front of w2. | |
| 68 std::vector<aura::Window*> siblings = w1->parent()->children(); | |
| 69 int index1 = FindIndex(siblings, w1); | |
| 70 int index2 = FindIndex(siblings, w2); | |
| 71 EXPECT_NE(index1, -1); | |
|
oshima
2016/06/18 04:47:44
It should be:
EXPECTE_NE(expected_value, actual_v
hidehiko
2016/06/18 05:32:45
Done.
| |
| 72 EXPECT_NE(index2, -1); | |
| 73 EXPECT_GT(index1, index2); | |
| 74 } | |
| 75 | |
| 76 // Set w2 to fullscreen. | |
| 77 { | |
| 78 wm::ActivateWindow(w2); | |
| 79 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
| 80 WmWindowAura::Get(w2)->GetWindowState()->OnWMEvent(&event); | |
| 81 } | |
| 82 { | |
| 83 // Verify that w1 is still in front of w2. | |
| 84 std::vector<aura::Window*> siblings = w1->parent()->children(); | |
| 85 int index1 = FindIndex(siblings, w1); | |
| 86 int index2 = FindIndex(siblings, w2); | |
| 87 EXPECT_NE(index1, -1); | |
| 88 EXPECT_NE(index2, -1); | |
| 89 EXPECT_GT(index1, index2); | |
| 90 } | |
| 91 | |
| 92 // Unset w2's fullscreen. | |
| 93 { | |
| 94 wm::ActivateWindow(w2); | |
| 95 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
| 96 WmWindowAura::Get(w2)->GetWindowState()->OnWMEvent(&event); | |
| 97 } | |
| 98 { | |
| 99 // Verify that w1 is still in front of w2. | |
| 100 std::vector<aura::Window*> siblings = w1->parent()->children(); | |
| 101 int index1 = FindIndex(siblings, w1); | |
| 102 int index2 = FindIndex(siblings, w2); | |
| 103 EXPECT_NE(index1, -1); | |
| 104 EXPECT_NE(index2, -1); | |
| 105 EXPECT_GT(index1, index2); | |
| 106 } | |
| 107 | |
| 108 // Maximize w2. | |
| 109 { | |
| 110 wm::ActivateWindow(w2); | |
| 111 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE); | |
| 112 WmWindowAura::Get(w2)->GetWindowState()->OnWMEvent(&event); | |
| 113 } | |
| 114 { | |
| 115 // Verify that w1 is still in front of w2. | |
| 116 std::vector<aura::Window*> siblings = w1->parent()->children(); | |
| 117 int index1 = FindIndex(siblings, w1); | |
| 118 int index2 = FindIndex(siblings, w2); | |
| 119 EXPECT_NE(index1, -1); | |
| 120 EXPECT_NE(index2, -1); | |
| 121 EXPECT_GT(index1, index2); | |
| 122 } | |
| 123 | |
| 124 // Unset w2's maximize. | |
| 125 { | |
| 126 wm::ActivateWindow(w2); | |
| 127 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE); | |
| 128 WmWindowAura::Get(w2)->GetWindowState()->OnWMEvent(&event); | |
| 129 } | |
| 130 { | |
| 131 // Verify that w1 is still in front of w2. | |
| 132 std::vector<aura::Window*> siblings = w1->parent()->children(); | |
| 133 int index1 = FindIndex(siblings, w1); | |
| 134 int index2 = FindIndex(siblings, w2); | |
| 135 EXPECT_NE(index1, -1); | |
| 136 EXPECT_NE(index2, -1); | |
| 137 EXPECT_GT(index1, index2); | |
| 138 } | |
| 139 | |
| 140 // Restore w1. | |
| 141 WmWindowAura::Get(w1)->GetWindowState()->Restore(); | |
| 142 | |
| 143 // Now, fullscreen-ize w2 should put it in front of w1. | |
| 144 { | |
| 145 wm::ActivateWindow(w2); | |
| 146 const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | |
| 147 WmWindowAura::Get(w2)->GetWindowState()->OnWMEvent(&event); | |
| 148 } | |
| 149 { | |
| 150 // Verify that w1 is still in front of w2. | |
| 151 std::vector<aura::Window*> siblings = w1->parent()->children(); | |
| 152 int index1 = FindIndex(siblings, w1); | |
| 153 int index2 = FindIndex(siblings, w2); | |
| 154 EXPECT_NE(index1, -1); | |
| 155 EXPECT_NE(index2, -1); | |
| 156 EXPECT_GT(index2, index1); | |
| 157 } | |
| 158 } | |
| 159 | |
| 160 } // namespace test | |
| 161 } // namespace ash | |
| OLD | NEW |