Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: ash/wm/window_selector_unittest.cc

Issue 20415002: Add window overview mode behind --ash-enable-overview-mode flag to F5 key. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove MRU window tracking refactoring from CL. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 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/window_cycle_controller.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/layer_animator.h"
24 #include "ui/gfx/rect_conversions.h"
25 #include "ui/gfx/transform.h"
26
27 namespace ash {
28 namespace internal {
29
30 namespace {
31
32 class LayerAnimationObserver : public ui::LayerAnimationObserver {
33 public:
34 LayerAnimationObserver(ui::Layer* layer)
35 : layer_(layer), animating_(false), message_loop_running_(false) {
36 layer_->GetAnimator()->AddObserver(this);
37 }
38
39 virtual ~LayerAnimationObserver() {
40 layer_->GetAnimator()->RemoveObserver(this);
41 }
42
43 virtual void OnLayerAnimationEnded(
44 ui::LayerAnimationSequence* sequence) OVERRIDE {
45 AnimationDone();
46 }
47
48 virtual void OnLayerAnimationScheduled(
49 ui::LayerAnimationSequence* sequence) OVERRIDE {
50 animating_ = true;
51 }
52
53 virtual void OnLayerAnimationAborted(
54 ui::LayerAnimationSequence* sequence) OVERRIDE {
55 AnimationDone();
56 }
57
58 void WaitUntilDone() {
59 while (animating_) {
60 message_loop_running_ = true;
61 base::MessageLoop::current()->Run();
62 message_loop_running_ = false;
63 }
64 }
65
66 private:
67 void AnimationDone() {
68 animating_ = false;
69 if (message_loop_running_)
70 base::MessageLoop::current()->Quit();
71 }
72
73 ui::Layer* layer_;
74 bool animating_;
75 bool message_loop_running_;
76
77 DISALLOW_COPY_AND_ASSIGN(LayerAnimationObserver);
78 };
79
80 } // namespace
81
82 class WindowSelectorTest : public test::AshTestBase {
83 public:
84 WindowSelectorTest() {}
85 virtual ~WindowSelectorTest() {}
86
87 aura::Window* CreateWindow(const gfx::Rect& bounds) {
88 return CreateTestWindowInShellWithDelegate(&wd, -1, bounds);
89 }
90
91 bool WindowsOverlapping(aura::Window* window1, aura::Window* window2) {
92 gfx::RectF window1_bounds = GetTransformedTargetBounds(window1);
93 gfx::RectF window2_bounds = GetTransformedTargetBounds(window2);
94 return window1_bounds.Intersects(window2_bounds);
95 }
96
97 void ToggleOverview() {
98 std::vector<aura::Window*> windows =
99 WindowCycleController::BuildWindowList(NULL, false);
100 ScopedVector<LayerAnimationObserver> animations;
101 for (size_t i = 0; i < windows.size(); ++i) {
102 animations.push_back(new LayerAnimationObserver(windows[i]->layer()));
103 }
104 ash::Shell::GetInstance()->window_selector_controller()->ToggleOverview();
105 for (size_t i = 0; i < animations.size(); ++i) {
106 animations[i]->WaitUntilDone();
107 }
108 }
109
110 gfx::RectF GetTransformedBounds(aura::Window* window) {
111 gfx::RectF bounds(window->layer()->bounds());
112 window->layer()->transform().TransformRect(&bounds);
113 return bounds;
114 }
115
116 gfx::RectF GetTransformedTargetBounds(aura::Window* window) {
117 gfx::RectF bounds(window->layer()->GetTargetBounds());
118 window->layer()->GetTargetTransform().TransformRect(&bounds);
119 return bounds;
120 }
121
122 void ClickWindow(aura::Window* window) {
123 aura::test::EventGenerator event_generator(window->GetRootWindow(), window);
124 gfx::RectF target = GetTransformedBounds(window);
125 event_generator.ClickLeftButton();
126 }
127
128 private:
129 aura::test::TestWindowDelegate wd;
130
131 DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest);
132 };
133
134 // Tests entering overview mode with two windows and selecting one.
135 TEST_F(WindowSelectorTest, Basic) {
136 gfx::Rect bounds(0, 0, 400, 400);
137 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
138 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
139 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get()));
140 wm::ActivateWindow(window2.get());
141 EXPECT_FALSE(wm::IsActiveWindow(window1.get()));
142 EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
143
144 // In overview mode the windows should no longer overlap.
145 ToggleOverview();
146 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get()));
147
148 // Clicking window 1 should activate it.
149 ClickWindow(window1.get());
150 EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
151 EXPECT_FALSE(wm::IsActiveWindow(window2.get()));
152 }
153
154 // Tests that windows remain on the display they are currently on in overview
155 // mode.
156 TEST_F(WindowSelectorTest, MultipleDisplays) {
157 if (!SupportsMultipleDisplays())
158 return;
159
160 UpdateDisplay("400x400,400x400");
161 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
162
163 scoped_ptr<aura::Window> window1(CreateWindow(gfx::Rect(0, 0, 100, 100)));
164 scoped_ptr<aura::Window> window2(CreateWindow(gfx::Rect(0, 0, 100, 100)));
165 scoped_ptr<aura::Window> window3(CreateWindow(gfx::Rect(450, 0, 100, 100)));
166 scoped_ptr<aura::Window> window4(CreateWindow(gfx::Rect(450, 0, 100, 100)));
167 EXPECT_EQ(root_windows[0], window1->GetRootWindow());
168 EXPECT_EQ(root_windows[0], window2->GetRootWindow());
169 EXPECT_EQ(root_windows[1], window3->GetRootWindow());
170 EXPECT_EQ(root_windows[1], window4->GetRootWindow());
171
172 // In overview mode, each window remains in the same root window.
173 ToggleOverview();
174 EXPECT_EQ(root_windows[0], window1->GetRootWindow());
175 EXPECT_EQ(root_windows[0], window2->GetRootWindow());
176 EXPECT_EQ(root_windows[1], window3->GetRootWindow());
177 EXPECT_EQ(root_windows[1], window4->GetRootWindow());
178 root_windows[0]->bounds().Contains(
179 ToEnclosingRect(GetTransformedBounds(window1.get())));
180 root_windows[0]->bounds().Contains(
181 ToEnclosingRect(GetTransformedBounds(window2.get())));
182 root_windows[1]->bounds().Contains(
183 ToEnclosingRect(GetTransformedBounds(window3.get())));
184 root_windows[1]->bounds().Contains(
185 ToEnclosingRect(GetTransformedBounds(window4.get())));
186 }
187
188 } // namespace internal
189 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698