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