blob: 596884d2254a754791d698e1c97b912c20d15249 [file] [log] [blame]
[email protected]7e368732013-01-16 13:31:231// 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
[email protected]7e368732013-01-16 13:31:235#include "ash/magnifier/magnification_controller.h"
[email protected]3dff2ef2014-02-09 22:50:396
oshima38dffad2015-05-05 17:22:567#include "ash/display/display_manager.h"
[email protected]7e368732013-01-16 13:31:238#include "ash/shell.h"
9#include "ash/test/ash_test_base.h"
[email protected]0836da02013-06-10 19:33:3510#include "base/strings/stringprintf.h"
[email protected]7e368732013-01-16 13:31:2311#include "ui/aura/client/aura_constants.h"
[email protected]6f162492013-04-26 09:02:0912#include "ui/aura/env.h"
[email protected]dc645d52014-04-28 14:42:5513#include "ui/aura/test/aura_test_utils.h"
[email protected]7a60cd3a2014-03-20 20:54:5714#include "ui/aura/window_tree_host.h"
jennyz91b6ed0c2014-10-23 21:52:4115#include "ui/base/ime/input_method.h"
pkotwicz0991c822014-10-31 04:21:0316#include "ui/chromeos/accessibility_types.h"
[email protected]73c9fd02014-07-28 01:48:5217#include "ui/events/test/event_generator.h"
Avi Drissmanfefc2f82014-12-22 19:25:2918#include "ui/gfx/geometry/rect_conversions.h"
[email protected]7e368732013-01-16 13:31:2319#include "ui/gfx/screen.h"
jennyz91b6ed0c2014-10-23 21:52:4120#include "ui/views/controls/textfield/textfield.h"
21#include "ui/views/layout/fill_layout.h"
22#include "ui/views/widget/widget.h"
23#include "ui/views/widget/widget_delegate.h"
24#include "ui/wm/core/coordinate_conversion.h"
[email protected]7e368732013-01-16 13:31:2325
26namespace ash {
[email protected]7e368732013-01-16 13:31:2327namespace {
28
29const int kRootHeight = 600;
30const int kRootWidth = 800;
31
jennyz91b6ed0c2014-10-23 21:52:4132const int kTextInputWindowWidth = 50;
33const int kTextInputWindowHeight = 50;
34
35class TextInputView : public views::WidgetDelegateView {
36 public:
37 TextInputView() : text_field_(new views::Textfield) {
38 text_field_->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT);
39 AddChildView(text_field_);
40 SetLayoutManager(new views::FillLayout);
41 }
42
dcheng222b9c72015-01-16 00:48:0143 ~TextInputView() override {}
jennyz91b6ed0c2014-10-23 21:52:4144
dcheng222b9c72015-01-16 00:48:0145 gfx::Size GetPreferredSize() const override {
jennyz91b6ed0c2014-10-23 21:52:4146 return gfx::Size(kTextInputWindowWidth, kTextInputWindowHeight);
47 }
48
49 // Overridden from views::WidgetDelegate:
dcheng222b9c72015-01-16 00:48:0150 views::View* GetContentsView() override { return this; }
jennyz91b6ed0c2014-10-23 21:52:4151
52 void FocusOnTextInput() { GetFocusManager()->SetFocusedView(text_field_); }
53
54 private:
55 views::Textfield* text_field_; // owned by views hierarchy
56
57 DISALLOW_COPY_AND_ASSIGN(TextInputView);
58};
59
[email protected]7e368732013-01-16 13:31:2360} // namespace
61
62class MagnificationControllerTest: public test::AshTestBase {
63 public:
jennyz91b6ed0c2014-10-23 21:52:4164 MagnificationControllerTest() : text_input_view_(NULL) {}
dcheng222b9c72015-01-16 00:48:0165 ~MagnificationControllerTest() override {}
[email protected]7e368732013-01-16 13:31:2366
dcheng222b9c72015-01-16 00:48:0167 void SetUp() override {
[email protected]7e368732013-01-16 13:31:2368 AshTestBase::SetUp();
[email protected]7d3cbc92013-03-18 22:33:0469 UpdateDisplay(base::StringPrintf("%dx%d", kRootWidth, kRootHeight));
[email protected]7e368732013-01-16 13:31:2370
[email protected]bf9cdb362013-10-25 19:22:4571 aura::Window* root = GetRootWindow();
[email protected]7e368732013-01-16 13:31:2372 gfx::Rect root_bounds(root->bounds());
73
74#if defined(OS_WIN)
75 // RootWindow and Display can't resize on Windows Ash.
76 // http://crbug.com/165962
77 EXPECT_EQ(kRootHeight, root_bounds.height());
78 EXPECT_EQ(kRootWidth, root_bounds.width());
79#endif
80 }
81
dcheng222b9c72015-01-16 00:48:0182 void TearDown() override { AshTestBase::TearDown(); }
[email protected]7e368732013-01-16 13:31:2383
84 protected:
[email protected]bf9cdb362013-10-25 19:22:4585 aura::Window* GetRootWindow() const {
[email protected]7e368732013-01-16 13:31:2386 return Shell::GetPrimaryRootWindow();
87 }
88
[email protected]6f162492013-04-26 09:02:0989 std::string GetHostMouseLocation() {
[email protected]dc645d52014-04-28 14:42:5590 const gfx::Point& location =
91 aura::test::QueryLatestMousePositionRequestInHost(
92 GetRootWindow()->GetHost());
93 return location.ToString();
[email protected]6f162492013-04-26 09:02:0994 }
95
96 ash::MagnificationController* GetMagnificationController() const {
[email protected]7e368732013-01-16 13:31:2397 return ash::Shell::GetInstance()->magnification_controller();
98 }
99
[email protected]6f162492013-04-26 09:02:09100 gfx::Rect GetViewport() const {
[email protected]7e368732013-01-16 13:31:23101 gfx::RectF bounds(0, 0, kRootWidth, kRootHeight);
102 GetRootWindow()->layer()->transform().TransformRectReverse(&bounds);
103 return gfx::ToEnclosingRect(bounds);
104 }
105
[email protected]6f162492013-04-26 09:02:09106 std::string CurrentPointOfInterest() const {
107 return GetMagnificationController()->
108 GetPointOfInterestForTesting().ToString();
109 }
110
jennyz91b6ed0c2014-10-23 21:52:41111 void CreateAndShowTextInputView(const gfx::Rect& bounds) {
112 text_input_view_ = new TextInputView;
113 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
114 text_input_view_, GetRootWindow(), bounds);
115 widget->Show();
116 }
117
118 // Returns the text input view's bounds in root window coordinates.
119 gfx::Rect GetTextInputViewBounds() {
120 DCHECK(text_input_view_);
121 gfx::Rect bounds = text_input_view_->bounds();
122 gfx::Point origin = bounds.origin();
123 // Convert origin to screen coordinates.
124 views::View::ConvertPointToScreen(text_input_view_, &origin);
125 // Convert origin to root_window_ coordinates.
126 wm::ConvertPointFromScreen(GetRootWindow(), &origin);
127 return gfx::Rect(origin.x(), origin.y(), bounds.width(), bounds.height());
128 }
129
130 // Returns the caret bounds in root window coordinates.
131 gfx::Rect GetCaretBounds() {
132 gfx::Rect caret_bounds =
133 GetInputMethod()->GetTextInputClient()->GetCaretBounds();
134 gfx::Point origin = caret_bounds.origin();
135 wm::ConvertPointFromScreen(GetRootWindow(), &origin);
136 return gfx::Rect(
137 origin.x(), origin.y(), caret_bounds.width(), caret_bounds.height());
138 }
139
140 void FocusOnTextInputView() {
141 DCHECK(text_input_view_);
142 text_input_view_->FocusOnTextInput();
143 }
144
[email protected]7e368732013-01-16 13:31:23145 private:
jennyz91b6ed0c2014-10-23 21:52:41146 TextInputView* text_input_view_;
147
148 ui::InputMethod* GetInputMethod() {
149 DCHECK(text_input_view_);
150 return text_input_view_->GetWidget()
151 ->GetNativeWindow()
152 ->GetRootWindow()
153 ->GetProperty(aura::client::kRootWindowInputMethodKey);
154 }
155
[email protected]7e368732013-01-16 13:31:23156 DISALLOW_COPY_AND_ASSIGN(MagnificationControllerTest);
157};
158
159TEST_F(MagnificationControllerTest, EnableAndDisable) {
160 // Confirms the magnifier is disabled.
161 EXPECT_TRUE(GetRootWindow()->layer()->transform().IsIdentity());
162 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale());
163 EXPECT_EQ("0,0 800x600", GetViewport().ToString());
164
165 // Enables magnifier.
166 GetMagnificationController()->SetEnabled(true);
167 EXPECT_FALSE(GetRootWindow()->layer()->transform().IsIdentity());
168 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale());
169 EXPECT_EQ("200,150 400x300", GetViewport().ToString());
170
171 // Disables magnifier.
172 GetMagnificationController()->SetEnabled(false);
173 EXPECT_TRUE(GetRootWindow()->layer()->transform().IsIdentity());
174 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale());
175 EXPECT_EQ("0,0 800x600", GetViewport().ToString());
176
177 // Confirms the the scale can't be changed.
178 GetMagnificationController()->SetScale(4.0f, false);
179 EXPECT_TRUE(GetRootWindow()->layer()->transform().IsIdentity());
180 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale());
181 EXPECT_EQ("0,0 800x600", GetViewport().ToString());
182}
183
184TEST_F(MagnificationControllerTest, MagnifyAndUnmagnify) {
185 // Enables magnifier and confirms the default scale is 2.0x.
186 GetMagnificationController()->SetEnabled(true);
187 EXPECT_FALSE(GetRootWindow()->layer()->transform().IsIdentity());
188 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale());
189 EXPECT_EQ("200,150 400x300", GetViewport().ToString());
[email protected]6f162492013-04-26 09:02:09190 EXPECT_EQ("400,300", CurrentPointOfInterest());
[email protected]7e368732013-01-16 13:31:23191
192 // Changes the scale.
193 GetMagnificationController()->SetScale(4.0f, false);
194 EXPECT_EQ(4.0f, GetMagnificationController()->GetScale());
195 EXPECT_EQ("300,225 200x150", GetViewport().ToString());
[email protected]6f162492013-04-26 09:02:09196 EXPECT_EQ("400,300", CurrentPointOfInterest());
[email protected]7e368732013-01-16 13:31:23197
198 GetMagnificationController()->SetScale(1.0f, false);
199 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale());
200 EXPECT_EQ("0,0 800x600", GetViewport().ToString());
[email protected]6f162492013-04-26 09:02:09201 EXPECT_EQ("400,300", CurrentPointOfInterest());
[email protected]7e368732013-01-16 13:31:23202
203 GetMagnificationController()->SetScale(3.0f, false);
204 EXPECT_EQ(3.0f, GetMagnificationController()->GetScale());
[email protected]0ec58342013-04-24 07:39:36205 EXPECT_EQ("266,200 267x200", GetViewport().ToString());
[email protected]6f162492013-04-26 09:02:09206 EXPECT_EQ("400,300", CurrentPointOfInterest());
[email protected]7e368732013-01-16 13:31:23207}
208
209TEST_F(MagnificationControllerTest, MoveWindow) {
210 // Enables magnifier and confirm the viewport is at center.
211 GetMagnificationController()->SetEnabled(true);
212 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale());
213 EXPECT_EQ("200,150 400x300", GetViewport().ToString());
214
215 // Move the viewport.
216 GetMagnificationController()->MoveWindow(0, 0, false);
217 EXPECT_EQ("0,0 400x300", GetViewport().ToString());
218
219 GetMagnificationController()->MoveWindow(200, 300, false);
220 EXPECT_EQ("200,300 400x300", GetViewport().ToString());
221
222 GetMagnificationController()->MoveWindow(400, 0, false);
223 EXPECT_EQ("400,0 400x300", GetViewport().ToString());
224
225 GetMagnificationController()->MoveWindow(400, 300, false);
226 EXPECT_EQ("400,300 400x300", GetViewport().ToString());
227
228 // Confirms that the viewport can't across the top-left border.
229 GetMagnificationController()->MoveWindow(-100, 0, false);
230 EXPECT_EQ("0,0 400x300", GetViewport().ToString());
231
232 GetMagnificationController()->MoveWindow(0, -100, false);
233 EXPECT_EQ("0,0 400x300", GetViewport().ToString());
234
235 GetMagnificationController()->MoveWindow(-100, -100, false);
236 EXPECT_EQ("0,0 400x300", GetViewport().ToString());
237
238 // Confirms that the viewport can't across the bittom-right border.
239 GetMagnificationController()->MoveWindow(800, 0, false);
240 EXPECT_EQ("400,0 400x300", GetViewport().ToString());
241
242 GetMagnificationController()->MoveWindow(0, 400, false);
243 EXPECT_EQ("0,300 400x300", GetViewport().ToString());
244
245 GetMagnificationController()->MoveWindow(200, 400, false);
246 EXPECT_EQ("200,300 400x300", GetViewport().ToString());
247
248 GetMagnificationController()->MoveWindow(1000, 1000, false);
249 EXPECT_EQ("400,300 400x300", GetViewport().ToString());
250}
251
[email protected]6f162492013-04-26 09:02:09252TEST_F(MagnificationControllerTest, PointOfInterest) {
[email protected]73c9fd02014-07-28 01:48:52253 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
[email protected]2549dbc2013-05-09 18:48:12254
255 generator.MoveMouseToInHost(gfx::Point(0, 0));
[email protected]6f162492013-04-26 09:02:09256 EXPECT_EQ("0,0", CurrentPointOfInterest());
257
[email protected]2549dbc2013-05-09 18:48:12258 generator.MoveMouseToInHost(gfx::Point(799, 599));
[email protected]6f162492013-04-26 09:02:09259 EXPECT_EQ("799,599", CurrentPointOfInterest());
260
[email protected]2549dbc2013-05-09 18:48:12261 generator.MoveMouseToInHost(gfx::Point(400, 300));
[email protected]6f162492013-04-26 09:02:09262 EXPECT_EQ("400,300", CurrentPointOfInterest());
263
264 GetMagnificationController()->SetEnabled(true);
265 EXPECT_EQ("400,300", CurrentPointOfInterest());
266
[email protected]2549dbc2013-05-09 18:48:12267 generator.MoveMouseToInHost(gfx::Point(500, 400));
[email protected]6f162492013-04-26 09:02:09268 EXPECT_EQ("450,350", CurrentPointOfInterest());
269}
270
271TEST_F(MagnificationControllerTest, PanWindow2xLeftToRight) {
272 const aura::Env* env = aura::Env::GetInstance();
[email protected]73c9fd02014-07-28 01:48:52273 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
[email protected]6f162492013-04-26 09:02:09274
[email protected]2549dbc2013-05-09 18:48:12275 generator.MoveMouseToInHost(gfx::Point(0, 0));
[email protected]6f162492013-04-26 09:02:09276 EXPECT_EQ(1.f, GetMagnificationController()->GetScale());
277 EXPECT_EQ("0,0 800x600", GetViewport().ToString());
278 EXPECT_EQ("0,0", env->last_mouse_location().ToString());
279
280 // Enables magnifier and confirm the viewport is at center.
281 GetMagnificationController()->SetEnabled(true);
282 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale());
283
284 GetMagnificationController()->MoveWindow(0, 0, false);
[email protected]2549dbc2013-05-09 18:48:12285 generator.MoveMouseToInHost(gfx::Point(0, 0));
[email protected]6f162492013-04-26 09:02:09286 EXPECT_EQ("0,0", env->last_mouse_location().ToString());
287 EXPECT_EQ("0,0 400x300", GetViewport().ToString());
288
[email protected]2549dbc2013-05-09 18:48:12289 generator.MoveMouseToInHost(gfx::Point(300, 150));
[email protected]6f162492013-04-26 09:02:09290 EXPECT_EQ("150,75", env->last_mouse_location().ToString());
291 EXPECT_EQ("0,0 400x300", GetViewport().ToString());
292
[email protected]2549dbc2013-05-09 18:48:12293 generator.MoveMouseToInHost(gfx::Point(700, 150));
[email protected]6f162492013-04-26 09:02:09294 EXPECT_EQ("350,75", env->last_mouse_location().ToString());
295 EXPECT_EQ("0,0 400x300", GetViewport().ToString());
296
[email protected]2549dbc2013-05-09 18:48:12297 generator.MoveMouseToInHost(gfx::Point(701, 150));
[email protected]6f162492013-04-26 09:02:09298 EXPECT_EQ("350,75", env->last_mouse_location().ToString());
299 EXPECT_EQ("0,0 400x300", GetViewport().ToString());
300
[email protected]2549dbc2013-05-09 18:48:12301 generator.MoveMouseToInHost(gfx::Point(702, 150));
[email protected]6f162492013-04-26 09:02:09302 EXPECT_EQ("351,75", env->last_mouse_location().ToString());
303 EXPECT_EQ("1,0 400x300", GetViewport().ToString());
304
[email protected]2549dbc2013-05-09 18:48:12305 generator.MoveMouseToInHost(gfx::Point(703, 150));
[email protected]6f162492013-04-26 09:02:09306 EXPECT_EQ("352,75", env->last_mouse_location().ToString());
307 EXPECT_EQ("2,0 400x300", GetViewport().ToString());
308
[email protected]2549dbc2013-05-09 18:48:12309 generator.MoveMouseToInHost(gfx::Point(704, 150));
[email protected]6f162492013-04-26 09:02:09310 EXPECT_EQ("354,75", env->last_mouse_location().ToString());
311 EXPECT_EQ("4,0 400x300", GetViewport().ToString());
312
[email protected]2549dbc2013-05-09 18:48:12313 generator.MoveMouseToInHost(gfx::Point(712, 150));
[email protected]6f162492013-04-26 09:02:09314 EXPECT_EQ("360,75", env->last_mouse_location().ToString());
315 EXPECT_EQ("10,0 400x300", GetViewport().ToString());
316
[email protected]2549dbc2013-05-09 18:48:12317 generator.MoveMouseToInHost(gfx::Point(600, 150));
[email protected]6f162492013-04-26 09:02:09318 EXPECT_EQ("310,75", env->last_mouse_location().ToString());
319 EXPECT_EQ("10,0 400x300", GetViewport().ToString());
320
[email protected]2549dbc2013-05-09 18:48:12321 generator.MoveMouseToInHost(gfx::Point(720, 150));
[email protected]6f162492013-04-26 09:02:09322 EXPECT_EQ("370,75", env->last_mouse_location().ToString());
323 EXPECT_EQ("20,0 400x300", GetViewport().ToString());
324
[email protected]2549dbc2013-05-09 18:48:12325 generator.MoveMouseToInHost(gfx::Point(780, 150));
[email protected]6f162492013-04-26 09:02:09326 EXPECT_EQ("410,75", env->last_mouse_location().ToString());
327 EXPECT_EQ("410,75", CurrentPointOfInterest());
328 EXPECT_EQ("60,0 400x300", GetViewport().ToString());
329
[email protected]2549dbc2013-05-09 18:48:12330 generator.MoveMouseToInHost(gfx::Point(799, 150));
[email protected]6f162492013-04-26 09:02:09331 EXPECT_EQ("459,75", env->last_mouse_location().ToString());
332 EXPECT_EQ("109,0 400x300", GetViewport().ToString());
333
[email protected]2549dbc2013-05-09 18:48:12334 generator.MoveMouseToInHost(gfx::Point(702, 150));
[email protected]6f162492013-04-26 09:02:09335 EXPECT_EQ("460,75", env->last_mouse_location().ToString());
336 EXPECT_EQ("110,0 400x300", GetViewport().ToString());
337
[email protected]2549dbc2013-05-09 18:48:12338 generator.MoveMouseToInHost(gfx::Point(780, 150));
[email protected]6f162492013-04-26 09:02:09339 EXPECT_EQ("500,75", env->last_mouse_location().ToString());
340 EXPECT_EQ("150,0 400x300", GetViewport().ToString());
341
[email protected]2549dbc2013-05-09 18:48:12342 generator.MoveMouseToInHost(gfx::Point(780, 150));
[email protected]6f162492013-04-26 09:02:09343 EXPECT_EQ("540,75", env->last_mouse_location().ToString());
344 EXPECT_EQ("190,0 400x300", GetViewport().ToString());
345
[email protected]2549dbc2013-05-09 18:48:12346 generator.MoveMouseToInHost(gfx::Point(780, 150));
[email protected]6f162492013-04-26 09:02:09347 EXPECT_EQ("580,75", env->last_mouse_location().ToString());
348 EXPECT_EQ("230,0 400x300", GetViewport().ToString());
349
[email protected]2549dbc2013-05-09 18:48:12350 generator.MoveMouseToInHost(gfx::Point(780, 150));
[email protected]6f162492013-04-26 09:02:09351 EXPECT_EQ("620,75", env->last_mouse_location().ToString());
352 EXPECT_EQ("270,0 400x300", GetViewport().ToString());
353
[email protected]2549dbc2013-05-09 18:48:12354 generator.MoveMouseToInHost(gfx::Point(780, 150));
[email protected]6f162492013-04-26 09:02:09355 EXPECT_EQ("660,75", env->last_mouse_location().ToString());
356 EXPECT_EQ("310,0 400x300", GetViewport().ToString());
357
[email protected]2549dbc2013-05-09 18:48:12358 generator.MoveMouseToInHost(gfx::Point(780, 150));
[email protected]6f162492013-04-26 09:02:09359 EXPECT_EQ("700,75", env->last_mouse_location().ToString());
360 EXPECT_EQ("350,0 400x300", GetViewport().ToString());
361
[email protected]2549dbc2013-05-09 18:48:12362 generator.MoveMouseToInHost(gfx::Point(780, 150));
[email protected]6f162492013-04-26 09:02:09363 EXPECT_EQ("740,75", env->last_mouse_location().ToString());
364 EXPECT_EQ("390,0 400x300", GetViewport().ToString());
365
[email protected]2549dbc2013-05-09 18:48:12366 generator.MoveMouseToInHost(gfx::Point(780, 150));
[email protected]6f162492013-04-26 09:02:09367 EXPECT_EQ("780,75", env->last_mouse_location().ToString());
368 EXPECT_EQ("400,0 400x300", GetViewport().ToString());
369
[email protected]2549dbc2013-05-09 18:48:12370 generator.MoveMouseToInHost(gfx::Point(799, 150));
[email protected]6f162492013-04-26 09:02:09371 EXPECT_EQ("799,75", env->last_mouse_location().ToString());
372 EXPECT_EQ("400,0 400x300", GetViewport().ToString());
373}
374
375TEST_F(MagnificationControllerTest, PanWindow2xRightToLeft) {
376 const aura::Env* env = aura::Env::GetInstance();
[email protected]73c9fd02014-07-28 01:48:52377 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
[email protected]6f162492013-04-26 09:02:09378
[email protected]2549dbc2013-05-09 18:48:12379 generator.MoveMouseToInHost(gfx::Point(799, 300));
[email protected]6f162492013-04-26 09:02:09380 EXPECT_EQ(1.f, GetMagnificationController()->GetScale());
381 EXPECT_EQ("0,0 800x600", GetViewport().ToString());
382 EXPECT_EQ("799,300", env->last_mouse_location().ToString());
383
384 // Enables magnifier and confirm the viewport is at center.
385 GetMagnificationController()->SetEnabled(true);
386
[email protected]2549dbc2013-05-09 18:48:12387 generator.MoveMouseToInHost(gfx::Point(799, 300));
[email protected]6f162492013-04-26 09:02:09388 EXPECT_EQ("798,300", env->last_mouse_location().ToString());
389 EXPECT_EQ("400,150 400x300", GetViewport().ToString());
390
[email protected]2549dbc2013-05-09 18:48:12391 generator.MoveMouseToInHost(gfx::Point(0, 300));
[email protected]6f162492013-04-26 09:02:09392 EXPECT_EQ("400,300", env->last_mouse_location().ToString());
393 EXPECT_EQ("350,150 400x300", GetViewport().ToString());
394
[email protected]2549dbc2013-05-09 18:48:12395 generator.MoveMouseToInHost(gfx::Point(0, 300));
[email protected]6f162492013-04-26 09:02:09396 EXPECT_EQ("350,300", env->last_mouse_location().ToString());
397 EXPECT_EQ("300,150 400x300", GetViewport().ToString());
398
[email protected]2549dbc2013-05-09 18:48:12399 generator.MoveMouseToInHost(gfx::Point(0, 300));
[email protected]6f162492013-04-26 09:02:09400 EXPECT_EQ("300,300", env->last_mouse_location().ToString());
401 EXPECT_EQ("250,150 400x300", GetViewport().ToString());
402
[email protected]2549dbc2013-05-09 18:48:12403 generator.MoveMouseToInHost(gfx::Point(0, 300));
[email protected]6f162492013-04-26 09:02:09404 EXPECT_EQ("250,300", env->last_mouse_location().ToString());
405 EXPECT_EQ("200,150 400x300", GetViewport().ToString());
406
[email protected]2549dbc2013-05-09 18:48:12407 generator.MoveMouseToInHost(gfx::Point(0, 300));
[email protected]6f162492013-04-26 09:02:09408 EXPECT_EQ("200,300", env->last_mouse_location().ToString());
409 EXPECT_EQ("150,150 400x300", GetViewport().ToString());
410
[email protected]2549dbc2013-05-09 18:48:12411 generator.MoveMouseToInHost(gfx::Point(0, 300));
[email protected]6f162492013-04-26 09:02:09412 EXPECT_EQ("150,300", env->last_mouse_location().ToString());
413 EXPECT_EQ("100,150 400x300", GetViewport().ToString());
414
[email protected]2549dbc2013-05-09 18:48:12415 generator.MoveMouseToInHost(gfx::Point(0, 300));
[email protected]6f162492013-04-26 09:02:09416 EXPECT_EQ("100,300", env->last_mouse_location().ToString());
417 EXPECT_EQ("50,150 400x300", GetViewport().ToString());
418
[email protected]2549dbc2013-05-09 18:48:12419 generator.MoveMouseToInHost(gfx::Point(0, 300));
[email protected]6f162492013-04-26 09:02:09420 EXPECT_EQ("50,300", env->last_mouse_location().ToString());
421 EXPECT_EQ("0,150 400x300", GetViewport().ToString());
422
[email protected]2549dbc2013-05-09 18:48:12423 generator.MoveMouseToInHost(gfx::Point(0, 300));
[email protected]6f162492013-04-26 09:02:09424 EXPECT_EQ("0,300", env->last_mouse_location().ToString());
425 EXPECT_EQ("0,150 400x300", GetViewport().ToString());
426}
427
428TEST_F(MagnificationControllerTest, PanWindowToRight) {
429 const aura::Env* env = aura::Env::GetInstance();
[email protected]73c9fd02014-07-28 01:48:52430 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
[email protected]6f162492013-04-26 09:02:09431
[email protected]2549dbc2013-05-09 18:48:12432 generator.MoveMouseToInHost(gfx::Point(400, 300));
[email protected]6f162492013-04-26 09:02:09433 EXPECT_EQ(1.f, GetMagnificationController()->GetScale());
434 EXPECT_EQ("0,0 800x600", GetViewport().ToString());
435 EXPECT_EQ("400,300", env->last_mouse_location().ToString());
436
437 float scale = 2.f;
438
439 // Enables magnifier and confirm the viewport is at center.
440 GetMagnificationController()->SetEnabled(true);
441 EXPECT_FLOAT_EQ(2.f, GetMagnificationController()->GetScale());
442
pkotwicz0991c822014-10-31 04:21:03443 scale *= ui::kMagnificationScaleFactor;
[email protected]6f162492013-04-26 09:02:09444 GetMagnificationController()->SetScale(scale, false);
445 EXPECT_FLOAT_EQ(2.3784142, GetMagnificationController()->GetScale());
[email protected]2549dbc2013-05-09 18:48:12446 generator.MoveMouseToInHost(gfx::Point(400, 300));
[email protected]6f162492013-04-26 09:02:09447 EXPECT_EQ("400,300", env->last_mouse_location().ToString());
[email protected]2549dbc2013-05-09 18:48:12448 generator.MoveMouseToInHost(gfx::Point(799, 300));
[email protected]6f162492013-04-26 09:02:09449 EXPECT_EQ("566,299", env->last_mouse_location().ToString());
450 EXPECT_EQ("705,300", GetHostMouseLocation());
451
pkotwicz0991c822014-10-31 04:21:03452 scale *= ui::kMagnificationScaleFactor;
[email protected]6f162492013-04-26 09:02:09453 GetMagnificationController()->SetScale(scale, false);
454 EXPECT_FLOAT_EQ(2.8284268, GetMagnificationController()->GetScale());
[email protected]2549dbc2013-05-09 18:48:12455 generator.MoveMouseToInHost(gfx::Point(799, 300));
[email protected]6f162492013-04-26 09:02:09456 EXPECT_EQ("599,299", env->last_mouse_location().ToString());
457 EXPECT_EQ("702,300", GetHostMouseLocation());
458
pkotwicz0991c822014-10-31 04:21:03459 scale *= ui::kMagnificationScaleFactor;
[email protected]6f162492013-04-26 09:02:09460 GetMagnificationController()->SetScale(scale, false);
461 EXPECT_FLOAT_EQ(3.3635852, GetMagnificationController()->GetScale());
[email protected]2549dbc2013-05-09 18:48:12462 generator.MoveMouseToInHost(gfx::Point(799, 300));
[email protected]6f162492013-04-26 09:02:09463 EXPECT_EQ("627,298", env->last_mouse_location().ToString());
464 EXPECT_EQ("707,300", GetHostMouseLocation());
465
pkotwicz0991c822014-10-31 04:21:03466 scale *= ui::kMagnificationScaleFactor;
[email protected]6f162492013-04-26 09:02:09467 GetMagnificationController()->SetScale(scale, false);
468 EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale());
[email protected]2549dbc2013-05-09 18:48:12469 generator.MoveMouseToInHost(gfx::Point(799, 300));
[email protected]6f162492013-04-26 09:02:09470 EXPECT_EQ("649,298", env->last_mouse_location().ToString());
471 EXPECT_EQ("704,300", GetHostMouseLocation());
472}
473
474TEST_F(MagnificationControllerTest, PanWindowToLeft) {
475 const aura::Env* env = aura::Env::GetInstance();
[email protected]73c9fd02014-07-28 01:48:52476 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
[email protected]6f162492013-04-26 09:02:09477
[email protected]2549dbc2013-05-09 18:48:12478 generator.MoveMouseToInHost(gfx::Point(400, 300));
[email protected]6f162492013-04-26 09:02:09479 EXPECT_EQ(1.f, GetMagnificationController()->GetScale());
480 EXPECT_EQ("0,0 800x600", GetViewport().ToString());
481 EXPECT_EQ("400,300", env->last_mouse_location().ToString());
482
483 float scale = 2.f;
484
485 // Enables magnifier and confirm the viewport is at center.
486 GetMagnificationController()->SetEnabled(true);
487 EXPECT_FLOAT_EQ(2.f, GetMagnificationController()->GetScale());
488
pkotwicz0991c822014-10-31 04:21:03489 scale *= ui::kMagnificationScaleFactor;
[email protected]6f162492013-04-26 09:02:09490 GetMagnificationController()->SetScale(scale, false);
491 EXPECT_FLOAT_EQ(2.3784142, GetMagnificationController()->GetScale());
[email protected]2549dbc2013-05-09 18:48:12492 generator.MoveMouseToInHost(gfx::Point(400, 300));
[email protected]6f162492013-04-26 09:02:09493 EXPECT_EQ("400,300", env->last_mouse_location().ToString());
[email protected]2549dbc2013-05-09 18:48:12494 generator.MoveMouseToInHost(gfx::Point(0, 300));
[email protected]6f162492013-04-26 09:02:09495 EXPECT_EQ("231,299", env->last_mouse_location().ToString());
496 EXPECT_EQ("100,300", GetHostMouseLocation());
497
pkotwicz0991c822014-10-31 04:21:03498 scale *= ui::kMagnificationScaleFactor;
[email protected]6f162492013-04-26 09:02:09499 GetMagnificationController()->SetScale(scale, false);
500 EXPECT_FLOAT_EQ(2.8284268, GetMagnificationController()->GetScale());
[email protected]2549dbc2013-05-09 18:48:12501 generator.MoveMouseToInHost(gfx::Point(0, 300));
[email protected]a15328272013-10-02 22:52:03502 EXPECT_EQ("194,299", env->last_mouse_location().ToString());
[email protected]6f162492013-04-26 09:02:09503 EXPECT_EQ("99,300", GetHostMouseLocation());
504
pkotwicz0991c822014-10-31 04:21:03505 scale *= ui::kMagnificationScaleFactor;
[email protected]6f162492013-04-26 09:02:09506 GetMagnificationController()->SetScale(scale, false);
507 EXPECT_FLOAT_EQ(3.3635852, GetMagnificationController()->GetScale());
[email protected]2549dbc2013-05-09 18:48:12508 generator.MoveMouseToInHost(gfx::Point(0, 300));
[email protected]a15328272013-10-02 22:52:03509 EXPECT_EQ("164,298", env->last_mouse_location().ToString());
[email protected]6f162492013-04-26 09:02:09510 EXPECT_EQ("98,300", GetHostMouseLocation());
511
pkotwicz0991c822014-10-31 04:21:03512 scale *= ui::kMagnificationScaleFactor;
[email protected]6f162492013-04-26 09:02:09513 GetMagnificationController()->SetScale(scale, false);
514 EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale());
[email protected]2549dbc2013-05-09 18:48:12515 generator.MoveMouseToInHost(gfx::Point(0, 300));
[email protected]a15328272013-10-02 22:52:03516 EXPECT_EQ("139,298", env->last_mouse_location().ToString());
[email protected]6f162492013-04-26 09:02:09517 EXPECT_EQ("100,300", GetHostMouseLocation());
518}
519
jennyz91b6ed0c2014-10-23 21:52:41520TEST_F(MagnificationControllerTest, FollowTextInputFieldFocus) {
521 CreateAndShowTextInputView(gfx::Rect(500, 300, 80, 80));
522 gfx::Rect text_input_bounds = GetTextInputViewBounds();
523
524 // Enables magnifier and confirm the viewport is at center.
525 GetMagnificationController()->SetEnabled(true);
526 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale());
527 EXPECT_EQ("200,150 400x300", GetViewport().ToString());
528
529 // Move the viewport to (0, 0), so that text input field will be out of
530 // the viewport region.
531 GetMagnificationController()->MoveWindow(0, 0, false);
532 EXPECT_EQ("0,0 400x300", GetViewport().ToString());
533 EXPECT_FALSE(GetViewport().Intersects(text_input_bounds));
534
535 // Focus on the text input field.
536 FocusOnTextInputView();
537
538 // Verify the view port has been moved to the place where the text field is
539 // contained in the view port and the caret is at the center of the view port.
540 gfx::Rect view_port = GetViewport();
541 EXPECT_TRUE(view_port.Contains(text_input_bounds));
542 gfx::Rect caret_bounds = GetCaretBounds();
543 EXPECT_TRUE(text_input_bounds.Contains(caret_bounds));
544 EXPECT_EQ(caret_bounds.origin(), view_port.CenterPoint());
545}
546
547TEST_F(MagnificationControllerTest, FollowTextInputFieldKeyPress) {
548 CreateAndShowTextInputView(gfx::Rect(385, 200, 80, 80));
549 gfx::Rect text_input_bounds = GetTextInputViewBounds();
550
551 // Enables magnifier and confirm the viewport is at center.
552 GetMagnificationController()->SetEnabled(true);
553 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale());
554 EXPECT_EQ("200,150 400x300", GetViewport().ToString());
555
556 // Move the viewport to (0, 0), so that text input field intersects the
557 // view port at the right edge.
558 GetMagnificationController()->MoveWindow(0, 0, false);
559 EXPECT_EQ("0,0 400x300", GetViewport().ToString());
560 EXPECT_TRUE(GetViewport().Intersects(text_input_bounds));
561
562 // Focus on the text input field.
563 FocusOnTextInputView();
564
565 // Verify the view port is not moved, and the caret is inside the view port.
566 gfx::Rect view_port = GetViewport();
567 EXPECT_EQ("0,0 400x300", view_port.ToString());
568 EXPECT_TRUE(view_port.Intersects(text_input_bounds));
569 EXPECT_TRUE(text_input_bounds.Contains(GetCaretBounds()));
570
571 // Press keys on text input simulate typing on text field and the caret
572 // moves out of the old view port region. The view port is moved to the place
573 // where caret's x coordinate is centered at the new view port.
574 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
575 generator.PressKey(ui::VKEY_A, 0);
576 generator.ReleaseKey(ui::VKEY_A, 0);
577 gfx::Rect caret_bounds = GetCaretBounds();
578 EXPECT_FALSE(view_port.Intersects(caret_bounds));
579
580 gfx::Rect new_view_port = GetViewport();
581 EXPECT_TRUE(new_view_port.Contains(caret_bounds));
582 EXPECT_EQ(caret_bounds.x(), new_view_port.CenterPoint().x());
583 EXPECT_EQ(view_port.y(), new_view_port.y());
584}
585
oshima38dffad2015-05-05 17:22:56586// Make sure that unified desktop can enter magnified mode.
587TEST_F(MagnificationControllerTest, EnableMagnifierInUnifiedDesktop) {
588 if (!SupportsMultipleDisplays())
589 return;
590
591 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
592 display_manager->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED);
593 display_manager->SetMultiDisplayMode(DisplayManager::UNIFIED);
594
595 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale());
596
597 GetMagnificationController()->SetEnabled(true);
598
599 gfx::Screen* screen =
600 gfx::Screen::GetScreenFor(Shell::GetPrimaryRootWindow());
601
602 UpdateDisplay("500x500, 500x500");
603 EXPECT_EQ("0,0 1000x500", screen->GetPrimaryDisplay().bounds().ToString());
604 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale());
605
606 GetMagnificationController()->SetEnabled(false);
607
608 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale());
609
610 GetMagnificationController()->SetEnabled(true);
611 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale());
612
613 UpdateDisplay("500x500");
614 EXPECT_EQ("0,0 500x500", screen->GetPrimaryDisplay().bounds().ToString());
615 EXPECT_EQ(2.0f, GetMagnificationController()->GetScale());
616
617 GetMagnificationController()->SetEnabled(false);
618 EXPECT_EQ("0,0 500x500", screen->GetPrimaryDisplay().bounds().ToString());
619 EXPECT_EQ(1.0f, GetMagnificationController()->GetScale());
620}
621
[email protected]7e368732013-01-16 13:31:23622} // namespace ash