[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 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 | |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 5 | #include "ash/magnifier/magnification_controller.h" |
[email protected] | 3dff2ef | 2014-02-09 22:50:39 | [diff] [blame] | 6 | |
jamescook | 2741744 | 2016-06-20 21:37:05 | [diff] [blame] | 7 | #include "ash/common/accessibility_types.h" |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 8 | #include "ash/shell.h" |
| 9 | #include "ash/test/ash_test_base.h" |
[email protected] | 0836da0 | 2013-06-10 19:33:35 | [diff] [blame] | 10 | #include "base/strings/stringprintf.h" |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 11 | #include "ui/aura/env.h" |
[email protected] | dc645d5 | 2014-04-28 14:42:55 | [diff] [blame] | 12 | #include "ui/aura/test/aura_test_utils.h" |
[email protected] | 7a60cd3a | 2014-03-20 20:54:57 | [diff] [blame] | 13 | #include "ui/aura/window_tree_host.h" |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 14 | #include "ui/base/ime/input_method.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 15 | #include "ui/display/manager/display_manager.h" |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 16 | #include "ui/display/screen.h" |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 17 | #include "ui/events/test/event_generator.h" |
Avi Drissman | fefc2f8 | 2014-12-22 19:25:29 | [diff] [blame] | 18 | #include "ui/gfx/geometry/rect_conversions.h" |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 19 | #include "ui/views/controls/textfield/textfield.h" |
| 20 | #include "ui/views/layout/fill_layout.h" |
| 21 | #include "ui/views/widget/widget.h" |
| 22 | #include "ui/views/widget/widget_delegate.h" |
| 23 | #include "ui/wm/core/coordinate_conversion.h" |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 24 | |
| 25 | namespace ash { |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 26 | namespace { |
| 27 | |
| 28 | const int kRootHeight = 600; |
| 29 | const int kRootWidth = 800; |
| 30 | |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 31 | const int kTextInputWindowWidth = 50; |
| 32 | const int kTextInputWindowHeight = 50; |
| 33 | |
| 34 | class TextInputView : public views::WidgetDelegateView { |
| 35 | public: |
| 36 | TextInputView() : text_field_(new views::Textfield) { |
| 37 | text_field_->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT); |
| 38 | AddChildView(text_field_); |
| 39 | SetLayoutManager(new views::FillLayout); |
| 40 | } |
| 41 | |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [diff] [blame] | 42 | ~TextInputView() override {} |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 43 | |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [diff] [blame] | 44 | gfx::Size GetPreferredSize() const override { |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 45 | return gfx::Size(kTextInputWindowWidth, kTextInputWindowHeight); |
| 46 | } |
| 47 | |
| 48 | // Overridden from views::WidgetDelegate: |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 49 | void FocusOnTextInput() { GetFocusManager()->SetFocusedView(text_field_); } |
| 50 | |
| 51 | private: |
| 52 | views::Textfield* text_field_; // owned by views hierarchy |
| 53 | |
| 54 | DISALLOW_COPY_AND_ASSIGN(TextInputView); |
| 55 | }; |
| 56 | |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 57 | } // namespace |
| 58 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 59 | class MagnificationControllerTest : public test::AshTestBase { |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 60 | public: |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 61 | MagnificationControllerTest() : text_input_view_(NULL) {} |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [diff] [blame] | 62 | ~MagnificationControllerTest() override {} |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 63 | |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [diff] [blame] | 64 | void SetUp() override { |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 65 | AshTestBase::SetUp(); |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 66 | UpdateDisplay(base::StringPrintf("%dx%d", kRootWidth, kRootHeight)); |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 67 | |
jennyz | b894b6d | 2015-06-01 20:12:18 | [diff] [blame] | 68 | GetMagnificationController()->DisableMoveMagnifierDelayForTesting(); |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 69 | } |
| 70 | |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [diff] [blame] | 71 | void TearDown() override { AshTestBase::TearDown(); } |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 72 | |
| 73 | protected: |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 74 | aura::Window* GetRootWindow() const { return Shell::GetPrimaryRootWindow(); } |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 75 | |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 76 | std::string GetHostMouseLocation() { |
[email protected] | dc645d5 | 2014-04-28 14:42:55 | [diff] [blame] | 77 | const gfx::Point& location = |
| 78 | aura::test::QueryLatestMousePositionRequestInHost( |
| 79 | GetRootWindow()->GetHost()); |
| 80 | return location.ToString(); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | ash::MagnificationController* GetMagnificationController() const { |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 84 | return ash::Shell::GetInstance()->magnification_controller(); |
| 85 | } |
| 86 | |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 87 | gfx::Rect GetViewport() const { |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 88 | gfx::RectF bounds(0, 0, kRootWidth, kRootHeight); |
| 89 | GetRootWindow()->layer()->transform().TransformRectReverse(&bounds); |
| 90 | return gfx::ToEnclosingRect(bounds); |
| 91 | } |
| 92 | |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 93 | std::string CurrentPointOfInterest() const { |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 94 | return GetMagnificationController() |
| 95 | ->GetPointOfInterestForTesting() |
| 96 | .ToString(); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 97 | } |
| 98 | |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 99 | void CreateAndShowTextInputView(const gfx::Rect& bounds) { |
| 100 | text_input_view_ = new TextInputView; |
| 101 | views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 102 | text_input_view_, GetRootWindow(), bounds); |
| 103 | widget->Show(); |
| 104 | } |
| 105 | |
| 106 | // Returns the text input view's bounds in root window coordinates. |
| 107 | gfx::Rect GetTextInputViewBounds() { |
| 108 | DCHECK(text_input_view_); |
| 109 | gfx::Rect bounds = text_input_view_->bounds(); |
| 110 | gfx::Point origin = bounds.origin(); |
| 111 | // Convert origin to screen coordinates. |
| 112 | views::View::ConvertPointToScreen(text_input_view_, &origin); |
| 113 | // Convert origin to root_window_ coordinates. |
sky | 984c189 | 2016-04-20 00:00:34 | [diff] [blame] | 114 | ::wm::ConvertPointFromScreen(GetRootWindow(), &origin); |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 115 | return gfx::Rect(origin.x(), origin.y(), bounds.width(), bounds.height()); |
| 116 | } |
| 117 | |
| 118 | // Returns the caret bounds in root window coordinates. |
| 119 | gfx::Rect GetCaretBounds() { |
| 120 | gfx::Rect caret_bounds = |
| 121 | GetInputMethod()->GetTextInputClient()->GetCaretBounds(); |
| 122 | gfx::Point origin = caret_bounds.origin(); |
sky | 984c189 | 2016-04-20 00:00:34 | [diff] [blame] | 123 | ::wm::ConvertPointFromScreen(GetRootWindow(), &origin); |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 124 | return gfx::Rect(origin.x(), origin.y(), caret_bounds.width(), |
| 125 | caret_bounds.height()); |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | void FocusOnTextInputView() { |
| 129 | DCHECK(text_input_view_); |
| 130 | text_input_view_->FocusOnTextInput(); |
| 131 | } |
| 132 | |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 133 | private: |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 134 | TextInputView* text_input_view_; |
| 135 | |
| 136 | ui::InputMethod* GetInputMethod() { |
| 137 | DCHECK(text_input_view_); |
shuchen | 12f77cb | 2015-07-02 02:11:14 | [diff] [blame] | 138 | return text_input_view_->GetWidget()->GetInputMethod(); |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 139 | } |
| 140 | |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 141 | DISALLOW_COPY_AND_ASSIGN(MagnificationControllerTest); |
| 142 | }; |
| 143 | |
| 144 | TEST_F(MagnificationControllerTest, EnableAndDisable) { |
| 145 | // Confirms the magnifier is disabled. |
| 146 | EXPECT_TRUE(GetRootWindow()->layer()->transform().IsIdentity()); |
| 147 | EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 148 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 149 | |
| 150 | // Enables magnifier. |
| 151 | GetMagnificationController()->SetEnabled(true); |
| 152 | EXPECT_FALSE(GetRootWindow()->layer()->transform().IsIdentity()); |
| 153 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 154 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 155 | |
| 156 | // Disables magnifier. |
| 157 | GetMagnificationController()->SetEnabled(false); |
| 158 | EXPECT_TRUE(GetRootWindow()->layer()->transform().IsIdentity()); |
| 159 | EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 160 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 161 | |
| 162 | // Confirms the the scale can't be changed. |
| 163 | GetMagnificationController()->SetScale(4.0f, false); |
| 164 | EXPECT_TRUE(GetRootWindow()->layer()->transform().IsIdentity()); |
| 165 | EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 166 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 167 | } |
| 168 | |
| 169 | TEST_F(MagnificationControllerTest, MagnifyAndUnmagnify) { |
| 170 | // Enables magnifier and confirms the default scale is 2.0x. |
| 171 | GetMagnificationController()->SetEnabled(true); |
| 172 | EXPECT_FALSE(GetRootWindow()->layer()->transform().IsIdentity()); |
| 173 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 174 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 175 | EXPECT_EQ("400,300", CurrentPointOfInterest()); |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 176 | |
| 177 | // Changes the scale. |
| 178 | GetMagnificationController()->SetScale(4.0f, false); |
| 179 | EXPECT_EQ(4.0f, GetMagnificationController()->GetScale()); |
| 180 | EXPECT_EQ("300,225 200x150", GetViewport().ToString()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 181 | EXPECT_EQ("400,300", CurrentPointOfInterest()); |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 182 | |
| 183 | GetMagnificationController()->SetScale(1.0f, false); |
| 184 | EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 185 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 186 | EXPECT_EQ("400,300", CurrentPointOfInterest()); |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 187 | |
| 188 | GetMagnificationController()->SetScale(3.0f, false); |
| 189 | EXPECT_EQ(3.0f, GetMagnificationController()->GetScale()); |
[email protected] | 0ec5834 | 2013-04-24 07:39:36 | [diff] [blame] | 190 | EXPECT_EQ("266,200 267x200", GetViewport().ToString()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 191 | EXPECT_EQ("400,300", CurrentPointOfInterest()); |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | TEST_F(MagnificationControllerTest, MoveWindow) { |
| 195 | // Enables magnifier and confirm the viewport is at center. |
| 196 | GetMagnificationController()->SetEnabled(true); |
| 197 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 198 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 199 | |
| 200 | // Move the viewport. |
| 201 | GetMagnificationController()->MoveWindow(0, 0, false); |
| 202 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 203 | |
| 204 | GetMagnificationController()->MoveWindow(200, 300, false); |
| 205 | EXPECT_EQ("200,300 400x300", GetViewport().ToString()); |
| 206 | |
| 207 | GetMagnificationController()->MoveWindow(400, 0, false); |
| 208 | EXPECT_EQ("400,0 400x300", GetViewport().ToString()); |
| 209 | |
| 210 | GetMagnificationController()->MoveWindow(400, 300, false); |
| 211 | EXPECT_EQ("400,300 400x300", GetViewport().ToString()); |
| 212 | |
| 213 | // Confirms that the viewport can't across the top-left border. |
| 214 | GetMagnificationController()->MoveWindow(-100, 0, false); |
| 215 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 216 | |
| 217 | GetMagnificationController()->MoveWindow(0, -100, false); |
| 218 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 219 | |
| 220 | GetMagnificationController()->MoveWindow(-100, -100, false); |
| 221 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 222 | |
| 223 | // Confirms that the viewport can't across the bittom-right border. |
| 224 | GetMagnificationController()->MoveWindow(800, 0, false); |
| 225 | EXPECT_EQ("400,0 400x300", GetViewport().ToString()); |
| 226 | |
| 227 | GetMagnificationController()->MoveWindow(0, 400, false); |
| 228 | EXPECT_EQ("0,300 400x300", GetViewport().ToString()); |
| 229 | |
| 230 | GetMagnificationController()->MoveWindow(200, 400, false); |
| 231 | EXPECT_EQ("200,300 400x300", GetViewport().ToString()); |
| 232 | |
| 233 | GetMagnificationController()->MoveWindow(1000, 1000, false); |
| 234 | EXPECT_EQ("400,300 400x300", GetViewport().ToString()); |
| 235 | } |
| 236 | |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 237 | TEST_F(MagnificationControllerTest, PointOfInterest) { |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 238 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 0)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 239 | EXPECT_EQ("0,0", CurrentPointOfInterest()); |
| 240 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 241 | GetEventGenerator().MoveMouseToInHost(gfx::Point(799, 599)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 242 | EXPECT_EQ("799,599", CurrentPointOfInterest()); |
| 243 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 244 | GetEventGenerator().MoveMouseToInHost(gfx::Point(400, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 245 | EXPECT_EQ("400,300", CurrentPointOfInterest()); |
| 246 | |
| 247 | GetMagnificationController()->SetEnabled(true); |
| 248 | EXPECT_EQ("400,300", CurrentPointOfInterest()); |
| 249 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 250 | GetEventGenerator().MoveMouseToInHost(gfx::Point(500, 400)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 251 | EXPECT_EQ("450,350", CurrentPointOfInterest()); |
| 252 | } |
| 253 | |
glevin | 0043bf4 | 2016-01-08 22:05:13 | [diff] [blame] | 254 | TEST_F(MagnificationControllerTest, FollowFocusChanged) { |
| 255 | // Enables magnifier and confirm the viewport is at center. |
| 256 | GetMagnificationController()->SetEnabled(true); |
| 257 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 258 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 259 | |
| 260 | // Don't move viewport when focusing edit box. |
| 261 | GetMagnificationController()->HandleFocusedNodeChanged( |
| 262 | true, gfx::Rect(0, 0, 10, 10)); |
| 263 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 264 | |
| 265 | // Move viewport to element in upper left. |
| 266 | GetMagnificationController()->HandleFocusedNodeChanged( |
| 267 | false, gfx::Rect(0, 0, 10, 10)); |
| 268 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 269 | |
| 270 | // Move viewport to element in lower right. |
| 271 | GetMagnificationController()->HandleFocusedNodeChanged( |
| 272 | false, gfx::Rect(790, 590, 10, 10)); |
| 273 | EXPECT_EQ("400,300 400x300", GetViewport().ToString()); |
| 274 | |
| 275 | // Don't follow focus onto empty rectangle. |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 276 | GetMagnificationController()->HandleFocusedNodeChanged(false, |
| 277 | gfx::Rect(0, 0, 0, 0)); |
glevin | 0043bf4 | 2016-01-08 22:05:13 | [diff] [blame] | 278 | EXPECT_EQ("400,300 400x300", GetViewport().ToString()); |
| 279 | } |
| 280 | |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 281 | TEST_F(MagnificationControllerTest, PanWindow2xLeftToRight) { |
| 282 | const aura::Env* env = aura::Env::GetInstance(); |
| 283 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 284 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 0)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 285 | EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); |
| 286 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 287 | EXPECT_EQ("0,0", env->last_mouse_location().ToString()); |
| 288 | |
| 289 | // Enables magnifier and confirm the viewport is at center. |
| 290 | GetMagnificationController()->SetEnabled(true); |
| 291 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 292 | |
| 293 | GetMagnificationController()->MoveWindow(0, 0, false); |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 294 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 0)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 295 | EXPECT_EQ("0,0", env->last_mouse_location().ToString()); |
| 296 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 297 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 298 | GetEventGenerator().MoveMouseToInHost(gfx::Point(300, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 299 | EXPECT_EQ("150,75", env->last_mouse_location().ToString()); |
| 300 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 301 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 302 | GetEventGenerator().MoveMouseToInHost(gfx::Point(700, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 303 | EXPECT_EQ("350,75", env->last_mouse_location().ToString()); |
| 304 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 305 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 306 | GetEventGenerator().MoveMouseToInHost(gfx::Point(701, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 307 | EXPECT_EQ("350,75", env->last_mouse_location().ToString()); |
| 308 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 309 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 310 | GetEventGenerator().MoveMouseToInHost(gfx::Point(702, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 311 | EXPECT_EQ("351,75", env->last_mouse_location().ToString()); |
| 312 | EXPECT_EQ("1,0 400x300", GetViewport().ToString()); |
| 313 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 314 | GetEventGenerator().MoveMouseToInHost(gfx::Point(703, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 315 | EXPECT_EQ("352,75", env->last_mouse_location().ToString()); |
| 316 | EXPECT_EQ("2,0 400x300", GetViewport().ToString()); |
| 317 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 318 | GetEventGenerator().MoveMouseToInHost(gfx::Point(704, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 319 | EXPECT_EQ("354,75", env->last_mouse_location().ToString()); |
| 320 | EXPECT_EQ("4,0 400x300", GetViewport().ToString()); |
| 321 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 322 | GetEventGenerator().MoveMouseToInHost(gfx::Point(712, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 323 | EXPECT_EQ("360,75", env->last_mouse_location().ToString()); |
| 324 | EXPECT_EQ("10,0 400x300", GetViewport().ToString()); |
| 325 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 326 | GetEventGenerator().MoveMouseToInHost(gfx::Point(600, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 327 | EXPECT_EQ("310,75", env->last_mouse_location().ToString()); |
| 328 | EXPECT_EQ("10,0 400x300", GetViewport().ToString()); |
| 329 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 330 | GetEventGenerator().MoveMouseToInHost(gfx::Point(720, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 331 | EXPECT_EQ("370,75", env->last_mouse_location().ToString()); |
| 332 | EXPECT_EQ("20,0 400x300", GetViewport().ToString()); |
| 333 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 334 | GetEventGenerator().MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 335 | EXPECT_EQ("410,75", env->last_mouse_location().ToString()); |
| 336 | EXPECT_EQ("410,75", CurrentPointOfInterest()); |
| 337 | EXPECT_EQ("60,0 400x300", GetViewport().ToString()); |
| 338 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 339 | GetEventGenerator().MoveMouseToInHost(gfx::Point(799, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 340 | EXPECT_EQ("459,75", env->last_mouse_location().ToString()); |
| 341 | EXPECT_EQ("109,0 400x300", GetViewport().ToString()); |
| 342 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 343 | GetEventGenerator().MoveMouseToInHost(gfx::Point(702, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 344 | EXPECT_EQ("460,75", env->last_mouse_location().ToString()); |
| 345 | EXPECT_EQ("110,0 400x300", GetViewport().ToString()); |
| 346 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 347 | GetEventGenerator().MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 348 | EXPECT_EQ("500,75", env->last_mouse_location().ToString()); |
| 349 | EXPECT_EQ("150,0 400x300", GetViewport().ToString()); |
| 350 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 351 | GetEventGenerator().MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 352 | EXPECT_EQ("540,75", env->last_mouse_location().ToString()); |
| 353 | EXPECT_EQ("190,0 400x300", GetViewport().ToString()); |
| 354 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 355 | GetEventGenerator().MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 356 | EXPECT_EQ("580,75", env->last_mouse_location().ToString()); |
| 357 | EXPECT_EQ("230,0 400x300", GetViewport().ToString()); |
| 358 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 359 | GetEventGenerator().MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 360 | EXPECT_EQ("620,75", env->last_mouse_location().ToString()); |
| 361 | EXPECT_EQ("270,0 400x300", GetViewport().ToString()); |
| 362 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 363 | GetEventGenerator().MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 364 | EXPECT_EQ("660,75", env->last_mouse_location().ToString()); |
| 365 | EXPECT_EQ("310,0 400x300", GetViewport().ToString()); |
| 366 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 367 | GetEventGenerator().MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 368 | EXPECT_EQ("700,75", env->last_mouse_location().ToString()); |
| 369 | EXPECT_EQ("350,0 400x300", GetViewport().ToString()); |
| 370 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 371 | GetEventGenerator().MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 372 | EXPECT_EQ("740,75", env->last_mouse_location().ToString()); |
| 373 | EXPECT_EQ("390,0 400x300", GetViewport().ToString()); |
| 374 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 375 | GetEventGenerator().MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 376 | EXPECT_EQ("780,75", env->last_mouse_location().ToString()); |
| 377 | EXPECT_EQ("400,0 400x300", GetViewport().ToString()); |
| 378 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 379 | GetEventGenerator().MoveMouseToInHost(gfx::Point(799, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 380 | EXPECT_EQ("799,75", env->last_mouse_location().ToString()); |
| 381 | EXPECT_EQ("400,0 400x300", GetViewport().ToString()); |
| 382 | } |
| 383 | |
| 384 | TEST_F(MagnificationControllerTest, PanWindow2xRightToLeft) { |
| 385 | const aura::Env* env = aura::Env::GetInstance(); |
| 386 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 387 | GetEventGenerator().MoveMouseToInHost(gfx::Point(799, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 388 | EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); |
| 389 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 390 | EXPECT_EQ("799,300", env->last_mouse_location().ToString()); |
| 391 | |
| 392 | // Enables magnifier and confirm the viewport is at center. |
| 393 | GetMagnificationController()->SetEnabled(true); |
| 394 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 395 | GetEventGenerator().MoveMouseToInHost(gfx::Point(799, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 396 | EXPECT_EQ("798,300", env->last_mouse_location().ToString()); |
| 397 | EXPECT_EQ("400,150 400x300", GetViewport().ToString()); |
| 398 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 399 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 400 | EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
| 401 | EXPECT_EQ("350,150 400x300", GetViewport().ToString()); |
| 402 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 403 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 404 | EXPECT_EQ("350,300", env->last_mouse_location().ToString()); |
| 405 | EXPECT_EQ("300,150 400x300", GetViewport().ToString()); |
| 406 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 407 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 408 | EXPECT_EQ("300,300", env->last_mouse_location().ToString()); |
| 409 | EXPECT_EQ("250,150 400x300", GetViewport().ToString()); |
| 410 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 411 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 412 | EXPECT_EQ("250,300", env->last_mouse_location().ToString()); |
| 413 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 414 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 415 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 416 | EXPECT_EQ("200,300", env->last_mouse_location().ToString()); |
| 417 | EXPECT_EQ("150,150 400x300", GetViewport().ToString()); |
| 418 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 419 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 420 | EXPECT_EQ("150,300", env->last_mouse_location().ToString()); |
| 421 | EXPECT_EQ("100,150 400x300", GetViewport().ToString()); |
| 422 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 423 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 424 | EXPECT_EQ("100,300", env->last_mouse_location().ToString()); |
| 425 | EXPECT_EQ("50,150 400x300", GetViewport().ToString()); |
| 426 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 427 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 428 | EXPECT_EQ("50,300", env->last_mouse_location().ToString()); |
| 429 | EXPECT_EQ("0,150 400x300", GetViewport().ToString()); |
| 430 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 431 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 432 | EXPECT_EQ("0,300", env->last_mouse_location().ToString()); |
| 433 | EXPECT_EQ("0,150 400x300", GetViewport().ToString()); |
| 434 | } |
| 435 | |
| 436 | TEST_F(MagnificationControllerTest, PanWindowToRight) { |
| 437 | const aura::Env* env = aura::Env::GetInstance(); |
| 438 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 439 | GetEventGenerator().MoveMouseToInHost(gfx::Point(400, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 440 | EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); |
| 441 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 442 | EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
| 443 | |
| 444 | float scale = 2.f; |
| 445 | |
| 446 | // Enables magnifier and confirm the viewport is at center. |
| 447 | GetMagnificationController()->SetEnabled(true); |
| 448 | EXPECT_FLOAT_EQ(2.f, GetMagnificationController()->GetScale()); |
| 449 | |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 450 | scale *= kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 451 | GetMagnificationController()->SetScale(scale, false); |
| 452 | EXPECT_FLOAT_EQ(2.3784142, GetMagnificationController()->GetScale()); |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 453 | GetEventGenerator().MoveMouseToInHost(gfx::Point(400, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 454 | EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 455 | GetEventGenerator().MoveMouseToInHost(gfx::Point(799, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 456 | EXPECT_EQ("566,299", env->last_mouse_location().ToString()); |
| 457 | EXPECT_EQ("705,300", GetHostMouseLocation()); |
| 458 | |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 459 | scale *= kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 460 | GetMagnificationController()->SetScale(scale, false); |
| 461 | EXPECT_FLOAT_EQ(2.8284268, GetMagnificationController()->GetScale()); |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 462 | GetEventGenerator().MoveMouseToInHost(gfx::Point(799, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 463 | EXPECT_EQ("599,299", env->last_mouse_location().ToString()); |
| 464 | EXPECT_EQ("702,300", GetHostMouseLocation()); |
| 465 | |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 466 | scale *= kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 467 | GetMagnificationController()->SetScale(scale, false); |
| 468 | EXPECT_FLOAT_EQ(3.3635852, GetMagnificationController()->GetScale()); |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 469 | GetEventGenerator().MoveMouseToInHost(gfx::Point(799, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 470 | EXPECT_EQ("627,298", env->last_mouse_location().ToString()); |
| 471 | EXPECT_EQ("707,300", GetHostMouseLocation()); |
| 472 | |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 473 | scale *= kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 474 | GetMagnificationController()->SetScale(scale, false); |
| 475 | EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale()); |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 476 | GetEventGenerator().MoveMouseToInHost(gfx::Point(799, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 477 | EXPECT_EQ("649,298", env->last_mouse_location().ToString()); |
| 478 | EXPECT_EQ("704,300", GetHostMouseLocation()); |
| 479 | } |
| 480 | |
| 481 | TEST_F(MagnificationControllerTest, PanWindowToLeft) { |
| 482 | const aura::Env* env = aura::Env::GetInstance(); |
| 483 | |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 484 | GetEventGenerator().MoveMouseToInHost(gfx::Point(400, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 485 | EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); |
| 486 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 487 | EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
| 488 | |
| 489 | float scale = 2.f; |
| 490 | |
| 491 | // Enables magnifier and confirm the viewport is at center. |
| 492 | GetMagnificationController()->SetEnabled(true); |
| 493 | EXPECT_FLOAT_EQ(2.f, GetMagnificationController()->GetScale()); |
| 494 | |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 495 | scale *= kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 496 | GetMagnificationController()->SetScale(scale, false); |
| 497 | EXPECT_FLOAT_EQ(2.3784142, GetMagnificationController()->GetScale()); |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 498 | GetEventGenerator().MoveMouseToInHost(gfx::Point(400, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 499 | EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 500 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 501 | EXPECT_EQ("231,299", env->last_mouse_location().ToString()); |
| 502 | EXPECT_EQ("100,300", GetHostMouseLocation()); |
| 503 | |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 504 | scale *= kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 505 | GetMagnificationController()->SetScale(scale, false); |
| 506 | EXPECT_FLOAT_EQ(2.8284268, GetMagnificationController()->GetScale()); |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 507 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | a1532827 | 2013-10-02 22:52:03 | [diff] [blame] | 508 | EXPECT_EQ("194,299", env->last_mouse_location().ToString()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 509 | EXPECT_EQ("99,300", GetHostMouseLocation()); |
| 510 | |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 511 | scale *= kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 512 | GetMagnificationController()->SetScale(scale, false); |
| 513 | EXPECT_FLOAT_EQ(3.3635852, GetMagnificationController()->GetScale()); |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 514 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | a1532827 | 2013-10-02 22:52:03 | [diff] [blame] | 515 | EXPECT_EQ("164,298", env->last_mouse_location().ToString()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 516 | EXPECT_EQ("98,300", GetHostMouseLocation()); |
| 517 | |
jamescook | a7f8dab | 2016-06-21 01:44:03 | [diff] [blame] | 518 | scale *= kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 519 | GetMagnificationController()->SetScale(scale, false); |
| 520 | EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale()); |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 521 | GetEventGenerator().MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | a1532827 | 2013-10-02 22:52:03 | [diff] [blame] | 522 | EXPECT_EQ("139,298", env->last_mouse_location().ToString()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 523 | EXPECT_EQ("100,300", GetHostMouseLocation()); |
| 524 | } |
| 525 | |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 526 | TEST_F(MagnificationControllerTest, FollowTextInputFieldFocus) { |
| 527 | CreateAndShowTextInputView(gfx::Rect(500, 300, 80, 80)); |
| 528 | gfx::Rect text_input_bounds = GetTextInputViewBounds(); |
| 529 | |
| 530 | // Enables magnifier and confirm the viewport is at center. |
| 531 | GetMagnificationController()->SetEnabled(true); |
| 532 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 533 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
jennyz | b894b6d | 2015-06-01 20:12:18 | [diff] [blame] | 534 | EXPECT_FALSE(GetMagnificationController()->KeepFocusCentered()); |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 535 | |
| 536 | // Move the viewport to (0, 0), so that text input field will be out of |
| 537 | // the viewport region. |
| 538 | GetMagnificationController()->MoveWindow(0, 0, false); |
| 539 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 540 | EXPECT_FALSE(GetViewport().Intersects(text_input_bounds)); |
| 541 | |
| 542 | // Focus on the text input field. |
| 543 | FocusOnTextInputView(); |
| 544 | |
| 545 | // Verify the view port has been moved to the place where the text field is |
| 546 | // contained in the view port and the caret is at the center of the view port. |
| 547 | gfx::Rect view_port = GetViewport(); |
| 548 | EXPECT_TRUE(view_port.Contains(text_input_bounds)); |
| 549 | gfx::Rect caret_bounds = GetCaretBounds(); |
| 550 | EXPECT_TRUE(text_input_bounds.Contains(caret_bounds)); |
jennyz | b894b6d | 2015-06-01 20:12:18 | [diff] [blame] | 551 | EXPECT_EQ(caret_bounds.CenterPoint(), view_port.CenterPoint()); |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 552 | } |
| 553 | |
jennyz | b894b6d | 2015-06-01 20:12:18 | [diff] [blame] | 554 | // Tests the following case. First the text input field intersects on the right |
| 555 | // edge with the view port, with focus caret sitting just a little left to the |
| 556 | // caret panning margin, so that when it gets focus, the view port won't move. |
| 557 | // Then when user types a character, the caret moves beyond the right panning |
| 558 | // edge, the view port will be moved to center the caret horizontally. |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 559 | TEST_F(MagnificationControllerTest, FollowTextInputFieldKeyPress) { |
jennyz | b894b6d | 2015-06-01 20:12:18 | [diff] [blame] | 560 | const int kCaretPanningMargin = 50; |
| 561 | const int kScale = 2.0f; |
| 562 | const int kViewportWidth = 400; |
| 563 | // Add some extra distance horizontally from text caret to to left edge of |
| 564 | // the text input view. |
| 565 | int x = kViewportWidth - (kCaretPanningMargin + 20) / kScale; |
| 566 | CreateAndShowTextInputView(gfx::Rect(x, 200, 80, 80)); |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 567 | gfx::Rect text_input_bounds = GetTextInputViewBounds(); |
| 568 | |
| 569 | // Enables magnifier and confirm the viewport is at center. |
| 570 | GetMagnificationController()->SetEnabled(true); |
| 571 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 572 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
jennyz | b894b6d | 2015-06-01 20:12:18 | [diff] [blame] | 573 | EXPECT_FALSE(GetMagnificationController()->KeepFocusCentered()); |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 574 | |
| 575 | // Move the viewport to (0, 0), so that text input field intersects the |
| 576 | // view port at the right edge. |
| 577 | GetMagnificationController()->MoveWindow(0, 0, false); |
| 578 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 579 | EXPECT_TRUE(GetViewport().Intersects(text_input_bounds)); |
| 580 | |
| 581 | // Focus on the text input field. |
| 582 | FocusOnTextInputView(); |
| 583 | |
jennyz | b894b6d | 2015-06-01 20:12:18 | [diff] [blame] | 584 | // Verify the view port is not moved, and the caret is inside the view port |
| 585 | // and not beyond the caret right panning margin. |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 586 | gfx::Rect view_port = GetViewport(); |
| 587 | EXPECT_EQ("0,0 400x300", view_port.ToString()); |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 588 | EXPECT_TRUE(text_input_bounds.Contains(GetCaretBounds())); |
jennyz | b894b6d | 2015-06-01 20:12:18 | [diff] [blame] | 589 | EXPECT_GT(view_port.right() - kCaretPanningMargin / kScale, |
| 590 | GetCaretBounds().x()); |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 591 | |
| 592 | // Press keys on text input simulate typing on text field and the caret |
jennyz | b894b6d | 2015-06-01 20:12:18 | [diff] [blame] | 593 | // moves beyond the caret right panning margin. The view port is moved to the |
| 594 | // place where caret's x coordinate is centered at the new view port. |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 595 | GetEventGenerator().PressKey(ui::VKEY_A, 0); |
| 596 | GetEventGenerator().ReleaseKey(ui::VKEY_A, 0); |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 597 | gfx::Rect caret_bounds = GetCaretBounds(); |
jennyz | b894b6d | 2015-06-01 20:12:18 | [diff] [blame] | 598 | EXPECT_LT(view_port.right() - kCaretPanningMargin / kScale, |
| 599 | GetCaretBounds().x()); |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 600 | |
| 601 | gfx::Rect new_view_port = GetViewport(); |
jennyz | b894b6d | 2015-06-01 20:12:18 | [diff] [blame] | 602 | EXPECT_EQ(caret_bounds.CenterPoint().x(), new_view_port.CenterPoint().x()); |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 603 | } |
| 604 | |
jennyz | b894b6d | 2015-06-01 20:12:18 | [diff] [blame] | 605 | TEST_F(MagnificationControllerTest, CenterTextCaretNotInsideViewport) { |
| 606 | CreateAndShowTextInputView(gfx::Rect(500, 300, 50, 30)); |
| 607 | gfx::Rect text_input_bounds = GetTextInputViewBounds(); |
| 608 | |
| 609 | // Enables magnifier and confirm the viewport is at center. |
| 610 | GetMagnificationController()->SetKeepFocusCentered(true); |
| 611 | GetMagnificationController()->SetEnabled(true); |
| 612 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 613 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 614 | EXPECT_TRUE(GetMagnificationController()->KeepFocusCentered()); |
| 615 | |
| 616 | // Move the viewport to (0, 0), so that text input field will be out of |
| 617 | // the viewport region. |
| 618 | GetMagnificationController()->MoveWindow(0, 0, false); |
| 619 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 620 | EXPECT_FALSE(GetViewport().Contains(text_input_bounds)); |
| 621 | |
| 622 | // Focus on the text input field. |
| 623 | FocusOnTextInputView(); |
| 624 | RunAllPendingInMessageLoop(); |
| 625 | // Verify the view port has been moved to the place where the text field is |
| 626 | // contained in the view port and the caret is at the center of the view port. |
| 627 | gfx::Rect view_port = GetViewport(); |
| 628 | EXPECT_TRUE(view_port.Contains(text_input_bounds)); |
| 629 | gfx::Rect caret_bounds = GetCaretBounds(); |
| 630 | EXPECT_EQ(caret_bounds.CenterPoint(), view_port.CenterPoint()); |
| 631 | |
| 632 | // Press keys on text input simulate typing on text field and the view port |
| 633 | // should be moved to keep the caret centered. |
kinaba | 5d46c35 | 2016-03-31 01:04:46 | [diff] [blame] | 634 | GetEventGenerator().PressKey(ui::VKEY_A, 0); |
| 635 | GetEventGenerator().ReleaseKey(ui::VKEY_A, 0); |
jennyz | b894b6d | 2015-06-01 20:12:18 | [diff] [blame] | 636 | RunAllPendingInMessageLoop(); |
| 637 | gfx::Rect new_caret_bounds = GetCaretBounds(); |
| 638 | EXPECT_NE(caret_bounds, new_caret_bounds); |
| 639 | |
| 640 | gfx::Rect new_view_port = GetViewport(); |
| 641 | EXPECT_NE(view_port, new_view_port); |
| 642 | EXPECT_TRUE(new_view_port.Contains(new_caret_bounds)); |
| 643 | EXPECT_EQ(new_caret_bounds.CenterPoint(), new_view_port.CenterPoint()); |
| 644 | } |
| 645 | |
| 646 | TEST_F(MagnificationControllerTest, CenterTextCaretInViewport) { |
| 647 | CreateAndShowTextInputView(gfx::Rect(250, 200, 50, 30)); |
| 648 | gfx::Rect text_input_bounds = GetTextInputViewBounds(); |
| 649 | |
| 650 | // Enables magnifier and confirm the viewport is at center. |
| 651 | GetMagnificationController()->SetKeepFocusCentered(true); |
| 652 | GetMagnificationController()->SetEnabled(true); |
| 653 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 654 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 655 | EXPECT_TRUE(GetMagnificationController()->KeepFocusCentered()); |
| 656 | |
| 657 | // Verify the text input field is inside the view port. |
| 658 | gfx::Rect view_port = GetViewport(); |
| 659 | EXPECT_TRUE(view_port.Contains(text_input_bounds)); |
| 660 | |
| 661 | // Focus on the text input field. |
| 662 | FocusOnTextInputView(); |
| 663 | RunAllPendingInMessageLoop(); |
| 664 | |
| 665 | // Verify the view port has been moved to the place where the text field is |
| 666 | // contained in the view port and the caret is at the center of the view port. |
| 667 | gfx::Rect new_view_port = GetViewport(); |
| 668 | EXPECT_NE(view_port, new_view_port); |
| 669 | EXPECT_TRUE(new_view_port.Contains(text_input_bounds)); |
| 670 | gfx::Rect caret_bounds = GetCaretBounds(); |
| 671 | EXPECT_EQ(caret_bounds.CenterPoint(), new_view_port.CenterPoint()); |
| 672 | } |
| 673 | |
oshima | 38dffad | 2015-05-05 17:22:56 | [diff] [blame] | 674 | // Make sure that unified desktop can enter magnified mode. |
| 675 | TEST_F(MagnificationControllerTest, EnableMagnifierInUnifiedDesktop) { |
| 676 | if (!SupportsMultipleDisplays()) |
| 677 | return; |
oshima | 628a617 | 2015-08-01 01:33:14 | [diff] [blame] | 678 | Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled(true); |
oshima | 38dffad | 2015-05-05 17:22:56 | [diff] [blame] | 679 | |
oshima | 38dffad | 2015-05-05 17:22:56 | [diff] [blame] | 680 | EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 681 | |
| 682 | GetMagnificationController()->SetEnabled(true); |
| 683 | |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 684 | display::Screen* screen = display::Screen::GetScreen(); |
oshima | 38dffad | 2015-05-05 17:22:56 | [diff] [blame] | 685 | |
| 686 | UpdateDisplay("500x500, 500x500"); |
| 687 | EXPECT_EQ("0,0 1000x500", screen->GetPrimaryDisplay().bounds().ToString()); |
| 688 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 689 | |
| 690 | GetMagnificationController()->SetEnabled(false); |
| 691 | |
| 692 | EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 693 | |
| 694 | GetMagnificationController()->SetEnabled(true); |
| 695 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 696 | |
| 697 | UpdateDisplay("500x500"); |
| 698 | EXPECT_EQ("0,0 500x500", screen->GetPrimaryDisplay().bounds().ToString()); |
| 699 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 700 | |
| 701 | GetMagnificationController()->SetEnabled(false); |
| 702 | EXPECT_EQ("0,0 500x500", screen->GetPrimaryDisplay().bounds().ToString()); |
| 703 | EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 704 | } |
| 705 | |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 706 | } // namespace ash |