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

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 implicit cast to bool. 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
« no previous file with comments | « ash/wm/window_selector_delegate.h ('k') | chrome/app/generated_resources.grd » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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/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 = ash::Shell::GetInstance()->
99 mru_window_tracker()->BuildMruWindowList();
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 overview mode is exited if the last remaining window is destroyed.
155 TEST_F(WindowSelectorTest, LastWindowDestroyed) {
156 gfx::Rect bounds(0, 0, 400, 400);
157 scoped_ptr<aura::Window> window1(CreateWindow(bounds));
158 scoped_ptr<aura::Window> window2(CreateWindow(bounds));
159 ToggleOverview();
160
161 window1.reset();
162 window2.reset();
163 EXPECT_FALSE(ash::Shell::GetInstance()->window_selector_controller()->
164 IsSelecting());
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
OLDNEW
« no previous file with comments | « ash/wm/window_selector_delegate.h ('k') | chrome/app/generated_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698