| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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/root_window_controller.h" | |
| 6 #include "ash/screen_ash.h" | |
| 7 #include "ash/shell.h" | |
| 8 #include "ash/test/ash_test_base.h" | |
| 9 #include "ash/test/shell_test_api.h" | |
| 10 #include "ash/wm/mru_window_tracker.h" | |
| 11 #include "ash/wm/window_selector_controller.h" | |
| 12 #include "ash/wm/window_util.h" | |
| 13 #include "base/basictypes.h" | |
| 14 #include "base/compiler_specific.h" | |
| 15 #include "base/memory/scoped_vector.h" | |
| 16 #include "base/run_loop.h" | |
| 17 #include "ui/aura/client/aura_constants.h" | |
| 18 #include "ui/aura/root_window.h" | |
| 19 #include "ui/aura/test/event_generator.h" | |
| 20 #include "ui/aura/test/test_window_delegate.h" | |
| 21 #include "ui/aura/test/test_windows.h" | |
| 22 #include "ui/aura/window.h" | |
| 23 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | |
| 24 #include "ui/gfx/rect_conversions.h" | |
| 25 #include "ui/gfx/transform.h" | |
| 26 | |
| 27 namespace ash { | |
| 28 namespace internal { | |
| 29 | |
| 30 class WindowSelectorTest : public test::AshTestBase { | |
| 31 public: | |
| 32 WindowSelectorTest() {} | |
| 33 virtual ~WindowSelectorTest() {} | |
| 34 | |
| 35 aura::Window* CreateWindow(const gfx::Rect& bounds) { | |
| 36 return CreateTestWindowInShellWithDelegate(&wd, -1, bounds); | |
| 37 } | |
| 38 | |
| 39 bool WindowsOverlapping(aura::Window* window1, aura::Window* window2) { | |
| 40 gfx::RectF window1_bounds = GetTransformedTargetBounds(window1); | |
| 41 gfx::RectF window2_bounds = GetTransformedTargetBounds(window2); | |
| 42 return window1_bounds.Intersects(window2_bounds); | |
| 43 } | |
| 44 | |
| 45 void ToggleOverview() { | |
| 46 ash::Shell::GetInstance()->window_selector_controller()->ToggleOverview(); | |
| 47 } | |
| 48 | |
| 49 void Cycle(WindowSelector::Direction direction) { | |
| 50 ash::Shell::GetInstance()->window_selector_controller()-> | |
| 51 HandleCycleWindow(direction); | |
| 52 } | |
| 53 | |
| 54 void StopCycling() { | |
| 55 ash::Shell::GetInstance()->window_selector_controller()->AltKeyReleased(); | |
| 56 } | |
| 57 | |
| 58 gfx::RectF GetTransformedBounds(aura::Window* window) { | |
| 59 gfx::RectF bounds(window->layer()->bounds()); | |
| 60 window->layer()->transform().TransformRect(&bounds); | |
| 61 return bounds; | |
| 62 } | |
| 63 | |
| 64 gfx::RectF GetTransformedTargetBounds(aura::Window* window) { | |
| 65 gfx::RectF bounds(window->layer()->GetTargetBounds()); | |
| 66 window->layer()->GetTargetTransform().TransformRect(&bounds); | |
| 67 return bounds; | |
| 68 } | |
| 69 | |
| 70 void ClickWindow(aura::Window* window) { | |
| 71 aura::test::EventGenerator event_generator(window->GetRootWindow(), window); | |
| 72 gfx::RectF target = GetTransformedBounds(window); | |
| 73 event_generator.ClickLeftButton(); | |
| 74 } | |
| 75 | |
| 76 bool IsSelecting() { | |
| 77 return ash::Shell::GetInstance()->window_selector_controller()-> | |
| 78 IsSelecting(); | |
| 79 } | |
| 80 | |
| 81 private: | |
| 82 aura::test::TestWindowDelegate wd; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest); | |
| 85 }; | |
| 86 | |
| 87 // Tests entering overview mode with two windows and selecting one. | |
| 88 TEST_F(WindowSelectorTest, Basic) { | |
| 89 gfx::Rect bounds(0, 0, 400, 400); | |
| 90 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | |
| 91 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | |
| 92 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get())); | |
| 93 wm::ActivateWindow(window2.get()); | |
| 94 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | |
| 95 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | |
| 96 | |
| 97 // In overview mode the windows should no longer overlap. | |
| 98 ToggleOverview(); | |
| 99 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get())); | |
| 100 | |
| 101 // Clicking window 1 should activate it. | |
| 102 ClickWindow(window1.get()); | |
| 103 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | |
| 104 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); | |
| 105 } | |
| 106 | |
| 107 // Tests entering overview mode with three windows and cycling through them. | |
| 108 TEST_F(WindowSelectorTest, BasicCycle) { | |
| 109 gfx::Rect bounds(0, 0, 400, 400); | |
| 110 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | |
| 111 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | |
| 112 scoped_ptr<aura::Window> window3(CreateWindow(bounds)); | |
| 113 wm::ActivateWindow(window3.get()); | |
| 114 wm::ActivateWindow(window2.get()); | |
| 115 wm::ActivateWindow(window1.get()); | |
| 116 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | |
| 117 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); | |
| 118 EXPECT_FALSE(wm::IsActiveWindow(window3.get())); | |
| 119 | |
| 120 Cycle(WindowSelector::FORWARD); | |
| 121 EXPECT_TRUE(IsSelecting()); | |
| 122 Cycle(WindowSelector::FORWARD); | |
| 123 StopCycling(); | |
| 124 EXPECT_FALSE(IsSelecting()); | |
| 125 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | |
| 126 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); | |
| 127 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); | |
| 128 } | |
| 129 | |
| 130 // Tests that overview mode is exited if the last remaining window is destroyed. | |
| 131 TEST_F(WindowSelectorTest, LastWindowDestroyed) { | |
| 132 gfx::Rect bounds(0, 0, 400, 400); | |
| 133 scoped_ptr<aura::Window> window1(CreateWindow(bounds)); | |
| 134 scoped_ptr<aura::Window> window2(CreateWindow(bounds)); | |
| 135 ToggleOverview(); | |
| 136 | |
| 137 window1.reset(); | |
| 138 window2.reset(); | |
| 139 EXPECT_FALSE(IsSelecting()); | |
| 140 } | |
| 141 | |
| 142 // Tests that entering overview mode restores a window to its original | |
| 143 // target location. | |
| 144 TEST_F(WindowSelectorTest, QuickReentryRestoresInitialTransform) { | |
| 145 gfx::Rect bounds(0, 0, 400, 400); | |
| 146 scoped_ptr<aura::Window> window(CreateWindow(bounds)); | |
| 147 gfx::Rect initial_bounds = ToEnclosingRect( | |
| 148 GetTransformedBounds(window.get())); | |
| 149 ToggleOverview(); | |
| 150 // Quickly exit and reenter overview mode. The window should still be | |
| 151 // animating when we reenter. We cannot short circuit animations for this but | |
| 152 // we also don't have to wait for them to complete. | |
| 153 { | |
| 154 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | |
| 155 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | |
| 156 ToggleOverview(); | |
| 157 ToggleOverview(); | |
| 158 } | |
| 159 EXPECT_NE(initial_bounds, ToEnclosingRect( | |
| 160 GetTransformedTargetBounds(window.get()))); | |
| 161 ToggleOverview(); | |
| 162 EXPECT_FALSE(IsSelecting()); | |
| 163 EXPECT_EQ(initial_bounds, ToEnclosingRect( | |
| 164 GetTransformedTargetBounds(window.get()))); | |
| 165 } | |
| 166 | |
| 167 // Tests that windows remain on the display they are currently on in overview | |
| 168 // mode. | |
| 169 TEST_F(WindowSelectorTest, MultipleDisplays) { | |
| 170 if (!SupportsMultipleDisplays()) | |
| 171 return; | |
| 172 | |
| 173 UpdateDisplay("400x400,400x400"); | |
| 174 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | |
| 175 | |
| 176 scoped_ptr<aura::Window> window1(CreateWindow(gfx::Rect(0, 0, 100, 100))); | |
| 177 scoped_ptr<aura::Window> window2(CreateWindow(gfx::Rect(0, 0, 100, 100))); | |
| 178 scoped_ptr<aura::Window> window3(CreateWindow(gfx::Rect(450, 0, 100, 100))); | |
| 179 scoped_ptr<aura::Window> window4(CreateWindow(gfx::Rect(450, 0, 100, 100))); | |
| 180 EXPECT_EQ(root_windows[0], window1->GetRootWindow()); | |
| 181 EXPECT_EQ(root_windows[0], window2->GetRootWindow()); | |
| 182 EXPECT_EQ(root_windows[1], window3->GetRootWindow()); | |
| 183 EXPECT_EQ(root_windows[1], window4->GetRootWindow()); | |
| 184 | |
| 185 // In overview mode, each window remains in the same root window. | |
| 186 ToggleOverview(); | |
| 187 EXPECT_EQ(root_windows[0], window1->GetRootWindow()); | |
| 188 EXPECT_EQ(root_windows[0], window2->GetRootWindow()); | |
| 189 EXPECT_EQ(root_windows[1], window3->GetRootWindow()); | |
| 190 EXPECT_EQ(root_windows[1], window4->GetRootWindow()); | |
| 191 root_windows[0]->bounds().Contains( | |
| 192 ToEnclosingRect(GetTransformedBounds(window1.get()))); | |
| 193 root_windows[0]->bounds().Contains( | |
| 194 ToEnclosingRect(GetTransformedBounds(window2.get()))); | |
| 195 root_windows[1]->bounds().Contains( | |
| 196 ToEnclosingRect(GetTransformedBounds(window3.get()))); | |
| 197 root_windows[1]->bounds().Contains( | |
| 198 ToEnclosingRect(GetTransformedBounds(window4.get()))); | |
| 199 } | |
| 200 | |
| 201 } // namespace internal | |
| 202 } // namespace ash | |
| OLD | NEW |