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