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

Side by Side Diff: ash/magnifier/magnification_controller_unittest.cc

Issue 13947045: Magnifier: Move the cursor directly to the root window host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/display/display_controller.h" 5 #include "ash/display/display_controller.h"
6 #include "ash/magnifier/magnification_controller.h" 6 #include "ash/magnifier/magnification_controller.h"
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "ui/aura/client/aura_constants.h" 10 #include "ui/aura/client/aura_constants.h"
11 #include "ui/aura/env.h"
11 #include "ui/aura/root_window.h" 12 #include "ui/aura/root_window.h"
13 #include "ui/aura/test/event_generator.h"
12 #include "ui/gfx/rect_conversions.h" 14 #include "ui/gfx/rect_conversions.h"
13 #include "ui/gfx/screen.h" 15 #include "ui/gfx/screen.h"
14 16
15 namespace ash { 17 namespace ash {
16 namespace internal { 18 namespace internal {
17 namespace { 19 namespace {
18 20
19 const int kRootHeight = 600; 21 const int kRootHeight = 600;
20 const int kRootWidth = 800; 22 const int kRootWidth = 800;
21 23
(...skipping 17 matching lines...) Expand all
39 EXPECT_EQ(kRootHeight, root_bounds.height()); 41 EXPECT_EQ(kRootHeight, root_bounds.height());
40 EXPECT_EQ(kRootWidth, root_bounds.width()); 42 EXPECT_EQ(kRootWidth, root_bounds.width());
41 #endif 43 #endif
42 } 44 }
43 45
44 virtual void TearDown() OVERRIDE { 46 virtual void TearDown() OVERRIDE {
45 AshTestBase::TearDown(); 47 AshTestBase::TearDown();
46 } 48 }
47 49
48 protected: 50 protected:
49 aura::RootWindow* GetRootWindow() { 51 aura::RootWindow* GetRootWindow() const {
50 return Shell::GetPrimaryRootWindow(); 52 return Shell::GetPrimaryRootWindow();
51 } 53 }
52 54
53 ash::MagnificationController* GetMagnificationController() { 55
56 void MoveCursorWithEvent(gfx::Point point) {
57 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
58 generator.MoveMouseTo(point.x(), point.y());
59 }
60
61 std::string GetHostMouseLocation() {
62 gfx::Point point;
63 GetRootWindow()->QueryMouseLocationForTest(&point);
64 return point.ToString();
65 }
66
67 ash::MagnificationController* GetMagnificationController() const {
54 return ash::Shell::GetInstance()->magnification_controller(); 68 return ash::Shell::GetInstance()->magnification_controller();
55 } 69 }
56 70
57 gfx::Rect GetViewport() { 71 gfx::Rect GetViewport() const {
58 gfx::RectF bounds(0, 0, kRootWidth, kRootHeight); 72 gfx::RectF bounds(0, 0, kRootWidth, kRootHeight);
59 GetRootWindow()->layer()->transform().TransformRectReverse(&bounds); 73 GetRootWindow()->layer()->transform().TransformRectReverse(&bounds);
60 return gfx::ToEnclosingRect(bounds); 74 return gfx::ToEnclosingRect(bounds);
61 } 75 }
62 76
77 std::string CurrentPointOfInterest() const {
78 return GetMagnificationController()->
79 GetPointOfInterestForTesting().ToString();
80 }
81
63 private: 82 private:
64 DISALLOW_COPY_AND_ASSIGN(MagnificationControllerTest); 83 DISALLOW_COPY_AND_ASSIGN(MagnificationControllerTest);
65 }; 84 };
66 85
67 TEST_F(MagnificationControllerTest, EnableAndDisable) { 86 TEST_F(MagnificationControllerTest, EnableAndDisable) {
68 // Confirms the magnifier is disabled. 87 // Confirms the magnifier is disabled.
69 EXPECT_TRUE(GetRootWindow()->layer()->transform().IsIdentity()); 88 EXPECT_TRUE(GetRootWindow()->layer()->transform().IsIdentity());
70 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); 89 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale());
71 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); 90 EXPECT_EQ("0,0 800x600", GetViewport().ToString());
72 91
(...skipping 15 matching lines...) Expand all
88 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); 107 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale());
89 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); 108 EXPECT_EQ("0,0 800x600", GetViewport().ToString());
90 } 109 }
91 110
92 TEST_F(MagnificationControllerTest, MagnifyAndUnmagnify) { 111 TEST_F(MagnificationControllerTest, MagnifyAndUnmagnify) {
93 // Enables magnifier and confirms the default scale is 2.0x. 112 // Enables magnifier and confirms the default scale is 2.0x.
94 GetMagnificationController()->SetEnabled(true); 113 GetMagnificationController()->SetEnabled(true);
95 EXPECT_FALSE(GetRootWindow()->layer()->transform().IsIdentity()); 114 EXPECT_FALSE(GetRootWindow()->layer()->transform().IsIdentity());
96 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); 115 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale());
97 EXPECT_EQ("200,150 400x300", GetViewport().ToString()); 116 EXPECT_EQ("200,150 400x300", GetViewport().ToString());
117 EXPECT_EQ("400,300", CurrentPointOfInterest());
98 118
99 // Changes the scale. 119 // Changes the scale.
100 GetMagnificationController()->SetScale(4.0f, false); 120 GetMagnificationController()->SetScale(4.0f, false);
101 EXPECT_EQ(4.0f, GetMagnificationController()->GetScale()); 121 EXPECT_EQ(4.0f, GetMagnificationController()->GetScale());
102 EXPECT_EQ("300,225 200x150", GetViewport().ToString()); 122 EXPECT_EQ("300,225 200x150", GetViewport().ToString());
123 EXPECT_EQ("400,300", CurrentPointOfInterest());
103 124
104 GetMagnificationController()->SetScale(1.0f, false); 125 GetMagnificationController()->SetScale(1.0f, false);
105 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); 126 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale());
106 EXPECT_EQ("0,0 800x600", GetViewport().ToString()); 127 EXPECT_EQ("0,0 800x600", GetViewport().ToString());
128 EXPECT_EQ("400,300", CurrentPointOfInterest());
107 129
108 GetMagnificationController()->SetScale(3.0f, false); 130 GetMagnificationController()->SetScale(3.0f, false);
109 EXPECT_EQ(3.0f, GetMagnificationController()->GetScale()); 131 EXPECT_EQ(3.0f, GetMagnificationController()->GetScale());
110 EXPECT_EQ("266,200 268x200", GetViewport().ToString()); 132 EXPECT_EQ("266,200 268x200", GetViewport().ToString());
133 EXPECT_EQ("400,300", CurrentPointOfInterest());
111 } 134 }
112 135
113 TEST_F(MagnificationControllerTest, MoveWindow) { 136 TEST_F(MagnificationControllerTest, MoveWindow) {
114 // Enables magnifier and confirm the viewport is at center. 137 // Enables magnifier and confirm the viewport is at center.
115 GetMagnificationController()->SetEnabled(true); 138 GetMagnificationController()->SetEnabled(true);
116 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); 139 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale());
117 EXPECT_EQ("200,150 400x300", GetViewport().ToString()); 140 EXPECT_EQ("200,150 400x300", GetViewport().ToString());
118 141
119 // Move the viewport. 142 // Move the viewport.
120 GetMagnificationController()->MoveWindow(0, 0, false); 143 GetMagnificationController()->MoveWindow(0, 0, false);
(...skipping 25 matching lines...) Expand all
146 GetMagnificationController()->MoveWindow(0, 400, false); 169 GetMagnificationController()->MoveWindow(0, 400, false);
147 EXPECT_EQ("0,300 400x300", GetViewport().ToString()); 170 EXPECT_EQ("0,300 400x300", GetViewport().ToString());
148 171
149 GetMagnificationController()->MoveWindow(200, 400, false); 172 GetMagnificationController()->MoveWindow(200, 400, false);
150 EXPECT_EQ("200,300 400x300", GetViewport().ToString()); 173 EXPECT_EQ("200,300 400x300", GetViewport().ToString());
151 174
152 GetMagnificationController()->MoveWindow(1000, 1000, false); 175 GetMagnificationController()->MoveWindow(1000, 1000, false);
153 EXPECT_EQ("400,300 400x300", GetViewport().ToString()); 176 EXPECT_EQ("400,300 400x300", GetViewport().ToString());
154 } 177 }
155 178
179 TEST_F(MagnificationControllerTest, PointOfInterest) {
180 MoveCursorWithEvent(gfx::Point(0, 0));
181 EXPECT_EQ("0,0", CurrentPointOfInterest());
182
183 MoveCursorWithEvent(gfx::Point(799, 599));
184 EXPECT_EQ("799,599", CurrentPointOfInterest());
185
186 MoveCursorWithEvent(gfx::Point(400, 300));
187 EXPECT_EQ("400,300", CurrentPointOfInterest());
188
189 GetMagnificationController()->SetEnabled(true);
190 EXPECT_EQ("400,300", CurrentPointOfInterest());
191
192 MoveCursorWithEvent(gfx::Point(500, 400));
193 EXPECT_EQ("450,350", CurrentPointOfInterest());
194 }
195
196 TEST_F(MagnificationControllerTest, PanWindow2xLeftToRight) {
197 const aura::Env* env = aura::Env::GetInstance();
198
199 MoveCursorWithEvent(gfx::Point(0, 0));
200 EXPECT_EQ(1.f, GetMagnificationController()->GetScale());
201 EXPECT_EQ("0,0 800x600", GetViewport().ToString());
202 EXPECT_EQ("0,0", env->last_mouse_location().ToString());
203
204 // Enables magnifier and confirm the viewport is at center.
205 GetMagnificationController()->SetEnabled(true);
206 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale());
207
208 GetMagnificationController()->MoveWindow(0, 0, false);
209 MoveCursorWithEvent(gfx::Point(0, 0));
210 EXPECT_EQ("0,0", env->last_mouse_location().ToString());
211 EXPECT_EQ("0,0 400x300", GetViewport().ToString());
212
213 MoveCursorWithEvent(gfx::Point(300, 150));
214 EXPECT_EQ("150,75", env->last_mouse_location().ToString());
215 EXPECT_EQ("0,0 400x300", GetViewport().ToString());
216
217 MoveCursorWithEvent(gfx::Point(700, 150));
218 EXPECT_EQ("350,75", env->last_mouse_location().ToString());
219 EXPECT_EQ("0,0 400x300", GetViewport().ToString());
220
221 MoveCursorWithEvent(gfx::Point(701, 150));
222 EXPECT_EQ("350,75", env->last_mouse_location().ToString());
223 EXPECT_EQ("0,0 400x300", GetViewport().ToString());
224
225 MoveCursorWithEvent(gfx::Point(702, 150));
226 EXPECT_EQ("351,75", env->last_mouse_location().ToString());
227 EXPECT_EQ("1,0 400x300", GetViewport().ToString());
228
229 MoveCursorWithEvent(gfx::Point(703, 150));
230 EXPECT_EQ("352,75", env->last_mouse_location().ToString());
231 EXPECT_EQ("2,0 400x300", GetViewport().ToString());
232
233 MoveCursorWithEvent(gfx::Point(704, 150));
234 EXPECT_EQ("354,75", env->last_mouse_location().ToString());
235 EXPECT_EQ("4,0 400x300", GetViewport().ToString());
236
237 MoveCursorWithEvent(gfx::Point(712, 150));
238 EXPECT_EQ("360,75", env->last_mouse_location().ToString());
239 EXPECT_EQ("10,0 400x300", GetViewport().ToString());
240
241 MoveCursorWithEvent(gfx::Point(600, 150));
242 EXPECT_EQ("310,75", env->last_mouse_location().ToString());
243 EXPECT_EQ("10,0 400x300", GetViewport().ToString());
244
245 MoveCursorWithEvent(gfx::Point(720, 150));
246 EXPECT_EQ("370,75", env->last_mouse_location().ToString());
247 EXPECT_EQ("20,0 400x300", GetViewport().ToString());
248
249 MoveCursorWithEvent(gfx::Point(780, 150));
250 EXPECT_EQ("410,75", env->last_mouse_location().ToString());
251 EXPECT_EQ("410,75", CurrentPointOfInterest());
252 EXPECT_EQ("60,0 400x300", GetViewport().ToString());
253
254 MoveCursorWithEvent(gfx::Point(799, 150));
255 EXPECT_EQ("459,75", env->last_mouse_location().ToString());
256 EXPECT_EQ("109,0 400x300", GetViewport().ToString());
257
258 MoveCursorWithEvent(gfx::Point(702, 150));
259 EXPECT_EQ("460,75", env->last_mouse_location().ToString());
260 EXPECT_EQ("110,0 400x300", GetViewport().ToString());
261
262 MoveCursorWithEvent(gfx::Point(780, 150));
263 EXPECT_EQ("500,75", env->last_mouse_location().ToString());
264 EXPECT_EQ("150,0 400x300", GetViewport().ToString());
265
266 MoveCursorWithEvent(gfx::Point(780, 150));
267 EXPECT_EQ("540,75", env->last_mouse_location().ToString());
268 EXPECT_EQ("190,0 400x300", GetViewport().ToString());
269
270 MoveCursorWithEvent(gfx::Point(780, 150));
271 EXPECT_EQ("580,75", env->last_mouse_location().ToString());
272 EXPECT_EQ("230,0 400x300", GetViewport().ToString());
273
274 MoveCursorWithEvent(gfx::Point(780, 150));
275 EXPECT_EQ("620,75", env->last_mouse_location().ToString());
276 EXPECT_EQ("270,0 400x300", GetViewport().ToString());
277
278 MoveCursorWithEvent(gfx::Point(780, 150));
279 EXPECT_EQ("660,75", env->last_mouse_location().ToString());
280 EXPECT_EQ("310,0 400x300", GetViewport().ToString());
281
282 MoveCursorWithEvent(gfx::Point(780, 150));
283 EXPECT_EQ("700,75", env->last_mouse_location().ToString());
284 EXPECT_EQ("350,0 400x300", GetViewport().ToString());
285
286 MoveCursorWithEvent(gfx::Point(780, 150));
287 EXPECT_EQ("740,75", env->last_mouse_location().ToString());
288 EXPECT_EQ("390,0 400x300", GetViewport().ToString());
289
290 MoveCursorWithEvent(gfx::Point(780, 150));
291 EXPECT_EQ("780,75", env->last_mouse_location().ToString());
292 EXPECT_EQ("400,0 400x300", GetViewport().ToString());
293
294 MoveCursorWithEvent(gfx::Point(799, 150));
295 EXPECT_EQ("799,75", env->last_mouse_location().ToString());
296 EXPECT_EQ("400,0 400x300", GetViewport().ToString());
297 }
298
299 TEST_F(MagnificationControllerTest, PanWindow2xRightToLeft) {
300 const aura::Env* env = aura::Env::GetInstance();
301
302 MoveCursorWithEvent(gfx::Point(799, 300));
303 EXPECT_EQ(1.f, GetMagnificationController()->GetScale());
304 EXPECT_EQ("0,0 800x600", GetViewport().ToString());
305 EXPECT_EQ("799,300", env->last_mouse_location().ToString());
306
307 // Enables magnifier and confirm the viewport is at center.
308 GetMagnificationController()->SetEnabled(true);
309
310 MoveCursorWithEvent(gfx::Point(799, 300));
311 EXPECT_EQ("798,300", env->last_mouse_location().ToString());
312 EXPECT_EQ("400,150 400x300", GetViewport().ToString());
313
314 MoveCursorWithEvent(gfx::Point(0, 300));
315 EXPECT_EQ("400,300", env->last_mouse_location().ToString());
316 EXPECT_EQ("350,150 400x300", GetViewport().ToString());
317
318 MoveCursorWithEvent(gfx::Point(0, 300));
319 EXPECT_EQ("350,300", env->last_mouse_location().ToString());
320 EXPECT_EQ("300,150 400x300", GetViewport().ToString());
321
322 MoveCursorWithEvent(gfx::Point(0, 300));
323 EXPECT_EQ("300,300", env->last_mouse_location().ToString());
324 EXPECT_EQ("250,150 400x300", GetViewport().ToString());
325
326 MoveCursorWithEvent(gfx::Point(0, 300));
327 EXPECT_EQ("250,300", env->last_mouse_location().ToString());
328 EXPECT_EQ("200,150 400x300", GetViewport().ToString());
329
330 MoveCursorWithEvent(gfx::Point(0, 300));
331 EXPECT_EQ("200,300", env->last_mouse_location().ToString());
332 EXPECT_EQ("150,150 400x300", GetViewport().ToString());
333
334 MoveCursorWithEvent(gfx::Point(0, 300));
335 EXPECT_EQ("150,300", env->last_mouse_location().ToString());
336 EXPECT_EQ("100,150 400x300", GetViewport().ToString());
337
338 MoveCursorWithEvent(gfx::Point(0, 300));
339 EXPECT_EQ("100,300", env->last_mouse_location().ToString());
340 EXPECT_EQ("50,150 400x300", GetViewport().ToString());
341
342 MoveCursorWithEvent(gfx::Point(0, 300));
343 EXPECT_EQ("50,300", env->last_mouse_location().ToString());
344 EXPECT_EQ("0,150 400x300", GetViewport().ToString());
345
346 MoveCursorWithEvent(gfx::Point(0, 300));
347 EXPECT_EQ("0,300", env->last_mouse_location().ToString());
348 EXPECT_EQ("0,150 400x300", GetViewport().ToString());
349 }
350
351 TEST_F(MagnificationControllerTest, PanWindowToRight) {
352 const aura::Env* env = aura::Env::GetInstance();
353
354 MoveCursorWithEvent(gfx::Point(400, 300));
355 EXPECT_EQ(1.f, GetMagnificationController()->GetScale());
356 EXPECT_EQ("0,0 800x600", GetViewport().ToString());
357 EXPECT_EQ("400,300", env->last_mouse_location().ToString());
358
359 float scale = 2.f;
360
361 // Enables magnifier and confirm the viewport is at center.
362 GetMagnificationController()->SetEnabled(true);
363 EXPECT_FLOAT_EQ(2.f, GetMagnificationController()->GetScale());
364
365 scale *= kMagnificationScaleFactor;
366 GetMagnificationController()->SetScale(scale, false);
367 EXPECT_FLOAT_EQ(2.3784142, GetMagnificationController()->GetScale());
368 MoveCursorWithEvent(gfx::Point(400, 300));
369 EXPECT_EQ("400,300", env->last_mouse_location().ToString());
370 MoveCursorWithEvent(gfx::Point(799, 300));
371 EXPECT_EQ("566,299", env->last_mouse_location().ToString());
372 EXPECT_EQ("705,300", GetHostMouseLocation());
373
374 scale *= kMagnificationScaleFactor;
375 GetMagnificationController()->SetScale(scale, false);
376 EXPECT_FLOAT_EQ(2.8284268, GetMagnificationController()->GetScale());
377 MoveCursorWithEvent(gfx::Point(799, 300));
378 EXPECT_EQ("599,299", env->last_mouse_location().ToString());
379 EXPECT_EQ("702,300", GetHostMouseLocation());
380
381 scale *= kMagnificationScaleFactor;
382 GetMagnificationController()->SetScale(scale, false);
383 EXPECT_FLOAT_EQ(3.3635852, GetMagnificationController()->GetScale());
384 MoveCursorWithEvent(gfx::Point(799, 300));
385 EXPECT_EQ("627,298", env->last_mouse_location().ToString());
386 EXPECT_EQ("707,300", GetHostMouseLocation());
387
388 scale *= kMagnificationScaleFactor;
389 GetMagnificationController()->SetScale(scale, false);
390 EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale());
391 MoveCursorWithEvent(gfx::Point(799, 300));
392 EXPECT_EQ("649,298", env->last_mouse_location().ToString());
393 EXPECT_EQ("704,300", GetHostMouseLocation());
394 }
395
396 TEST_F(MagnificationControllerTest, PanWindowToLeft) {
397 const aura::Env* env = aura::Env::GetInstance();
398
399 MoveCursorWithEvent(gfx::Point(400, 300));
400 EXPECT_EQ(1.f, GetMagnificationController()->GetScale());
401 EXPECT_EQ("0,0 800x600", GetViewport().ToString());
402 EXPECT_EQ("400,300", env->last_mouse_location().ToString());
403
404 float scale = 2.f;
405
406 // Enables magnifier and confirm the viewport is at center.
407 GetMagnificationController()->SetEnabled(true);
408 EXPECT_FLOAT_EQ(2.f, GetMagnificationController()->GetScale());
409
410 scale *= kMagnificationScaleFactor;
411 GetMagnificationController()->SetScale(scale, false);
412 EXPECT_FLOAT_EQ(2.3784142, GetMagnificationController()->GetScale());
413 MoveCursorWithEvent(gfx::Point(400, 300));
414 EXPECT_EQ("400,300", env->last_mouse_location().ToString());
415 MoveCursorWithEvent(gfx::Point(0, 300));
416 EXPECT_EQ("231,299", env->last_mouse_location().ToString());
417 EXPECT_EQ("100,300", GetHostMouseLocation());
418
419 scale *= kMagnificationScaleFactor;
420 GetMagnificationController()->SetScale(scale, false);
421 EXPECT_FLOAT_EQ(2.8284268, GetMagnificationController()->GetScale());
422 MoveCursorWithEvent(gfx::Point(0, 300));
423 EXPECT_EQ("195,299", env->last_mouse_location().ToString());
424 EXPECT_EQ("99,300", GetHostMouseLocation());
425
426 scale *= kMagnificationScaleFactor;
427 GetMagnificationController()->SetScale(scale, false);
428 EXPECT_FLOAT_EQ(3.3635852, GetMagnificationController()->GetScale());
429 MoveCursorWithEvent(gfx::Point(0, 300));
430 EXPECT_EQ("165,298", env->last_mouse_location().ToString());
431 EXPECT_EQ("98,300", GetHostMouseLocation());
432
433 scale *= kMagnificationScaleFactor;
434 GetMagnificationController()->SetScale(scale, false);
435 EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale());
436 MoveCursorWithEvent(gfx::Point(0, 300));
437 EXPECT_EQ("140,298", env->last_mouse_location().ToString());
438 EXPECT_EQ("100,300", GetHostMouseLocation());
439 }
440
156 } // namespace internal 441 } // namespace internal
157 } // namespace ash 442 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698