[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 | |
oshima | 38dffad | 2015-05-05 17:22:56 | [diff] [blame^] | 7 | #include "ash/display/display_manager.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] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 11 | #include "ui/aura/client/aura_constants.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" |
pkotwicz | 0991c82 | 2014-10-31 04:21:03 | [diff] [blame] | 16 | #include "ui/chromeos/accessibility_types.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" |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 19 | #include "ui/gfx/screen.h" |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 20 | #include "ui/views/controls/textfield/textfield.h" |
| 21 | #include "ui/views/layout/fill_layout.h" |
| 22 | #include "ui/views/widget/widget.h" |
| 23 | #include "ui/views/widget/widget_delegate.h" |
| 24 | #include "ui/wm/core/coordinate_conversion.h" |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 25 | |
| 26 | namespace ash { |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 27 | namespace { |
| 28 | |
| 29 | const int kRootHeight = 600; |
| 30 | const int kRootWidth = 800; |
| 31 | |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 32 | const int kTextInputWindowWidth = 50; |
| 33 | const int kTextInputWindowHeight = 50; |
| 34 | |
| 35 | class TextInputView : public views::WidgetDelegateView { |
| 36 | public: |
| 37 | TextInputView() : text_field_(new views::Textfield) { |
| 38 | text_field_->SetTextInputType(ui::TEXT_INPUT_TYPE_TEXT); |
| 39 | AddChildView(text_field_); |
| 40 | SetLayoutManager(new views::FillLayout); |
| 41 | } |
| 42 | |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [diff] [blame] | 43 | ~TextInputView() override {} |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 44 | |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [diff] [blame] | 45 | gfx::Size GetPreferredSize() const override { |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 46 | return gfx::Size(kTextInputWindowWidth, kTextInputWindowHeight); |
| 47 | } |
| 48 | |
| 49 | // Overridden from views::WidgetDelegate: |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [diff] [blame] | 50 | views::View* GetContentsView() override { return this; } |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 51 | |
| 52 | void FocusOnTextInput() { GetFocusManager()->SetFocusedView(text_field_); } |
| 53 | |
| 54 | private: |
| 55 | views::Textfield* text_field_; // owned by views hierarchy |
| 56 | |
| 57 | DISALLOW_COPY_AND_ASSIGN(TextInputView); |
| 58 | }; |
| 59 | |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 60 | } // namespace |
| 61 | |
| 62 | class MagnificationControllerTest: public test::AshTestBase { |
| 63 | public: |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 64 | MagnificationControllerTest() : text_input_view_(NULL) {} |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [diff] [blame] | 65 | ~MagnificationControllerTest() override {} |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 66 | |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [diff] [blame] | 67 | void SetUp() override { |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 68 | AshTestBase::SetUp(); |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 69 | UpdateDisplay(base::StringPrintf("%dx%d", kRootWidth, kRootHeight)); |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 70 | |
[email protected] | bf9cdb36 | 2013-10-25 19:22:45 | [diff] [blame] | 71 | aura::Window* root = GetRootWindow(); |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 72 | gfx::Rect root_bounds(root->bounds()); |
| 73 | |
| 74 | #if defined(OS_WIN) |
| 75 | // RootWindow and Display can't resize on Windows Ash. |
| 76 | // http://crbug.com/165962 |
| 77 | EXPECT_EQ(kRootHeight, root_bounds.height()); |
| 78 | EXPECT_EQ(kRootWidth, root_bounds.width()); |
| 79 | #endif |
| 80 | } |
| 81 | |
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. |
| 126 | wm::ConvertPointFromScreen(GetRootWindow(), &origin); |
| 127 | return gfx::Rect(origin.x(), origin.y(), bounds.width(), bounds.height()); |
| 128 | } |
| 129 | |
| 130 | // Returns the caret bounds in root window coordinates. |
| 131 | gfx::Rect GetCaretBounds() { |
| 132 | gfx::Rect caret_bounds = |
| 133 | GetInputMethod()->GetTextInputClient()->GetCaretBounds(); |
| 134 | gfx::Point origin = caret_bounds.origin(); |
| 135 | wm::ConvertPointFromScreen(GetRootWindow(), &origin); |
| 136 | return gfx::Rect( |
| 137 | origin.x(), origin.y(), caret_bounds.width(), caret_bounds.height()); |
| 138 | } |
| 139 | |
| 140 | void FocusOnTextInputView() { |
| 141 | DCHECK(text_input_view_); |
| 142 | text_input_view_->FocusOnTextInput(); |
| 143 | } |
| 144 | |
[email protected] | 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_); |
| 150 | return text_input_view_->GetWidget() |
| 151 | ->GetNativeWindow() |
| 152 | ->GetRootWindow() |
| 153 | ->GetProperty(aura::client::kRootWindowInputMethodKey); |
| 154 | } |
| 155 | |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 156 | DISALLOW_COPY_AND_ASSIGN(MagnificationControllerTest); |
| 157 | }; |
| 158 | |
| 159 | TEST_F(MagnificationControllerTest, EnableAndDisable) { |
| 160 | // Confirms the magnifier is disabled. |
| 161 | EXPECT_TRUE(GetRootWindow()->layer()->transform().IsIdentity()); |
| 162 | EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 163 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 164 | |
| 165 | // Enables magnifier. |
| 166 | GetMagnificationController()->SetEnabled(true); |
| 167 | EXPECT_FALSE(GetRootWindow()->layer()->transform().IsIdentity()); |
| 168 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 169 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 170 | |
| 171 | // Disables magnifier. |
| 172 | GetMagnificationController()->SetEnabled(false); |
| 173 | EXPECT_TRUE(GetRootWindow()->layer()->transform().IsIdentity()); |
| 174 | EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 175 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 176 | |
| 177 | // Confirms the the scale can't be changed. |
| 178 | GetMagnificationController()->SetScale(4.0f, false); |
| 179 | EXPECT_TRUE(GetRootWindow()->layer()->transform().IsIdentity()); |
| 180 | EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 181 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 182 | } |
| 183 | |
| 184 | TEST_F(MagnificationControllerTest, MagnifyAndUnmagnify) { |
| 185 | // Enables magnifier and confirms the default scale is 2.0x. |
| 186 | GetMagnificationController()->SetEnabled(true); |
| 187 | EXPECT_FALSE(GetRootWindow()->layer()->transform().IsIdentity()); |
| 188 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 189 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 190 | EXPECT_EQ("400,300", CurrentPointOfInterest()); |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 191 | |
| 192 | // Changes the scale. |
| 193 | GetMagnificationController()->SetScale(4.0f, false); |
| 194 | EXPECT_EQ(4.0f, GetMagnificationController()->GetScale()); |
| 195 | EXPECT_EQ("300,225 200x150", GetViewport().ToString()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 196 | EXPECT_EQ("400,300", CurrentPointOfInterest()); |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 197 | |
| 198 | GetMagnificationController()->SetScale(1.0f, false); |
| 199 | EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 200 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 201 | EXPECT_EQ("400,300", CurrentPointOfInterest()); |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 202 | |
| 203 | GetMagnificationController()->SetScale(3.0f, false); |
| 204 | EXPECT_EQ(3.0f, GetMagnificationController()->GetScale()); |
[email protected] | 0ec5834 | 2013-04-24 07:39:36 | [diff] [blame] | 205 | EXPECT_EQ("266,200 267x200", GetViewport().ToString()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 206 | EXPECT_EQ("400,300", CurrentPointOfInterest()); |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | TEST_F(MagnificationControllerTest, MoveWindow) { |
| 210 | // Enables magnifier and confirm the viewport is at center. |
| 211 | GetMagnificationController()->SetEnabled(true); |
| 212 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 213 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 214 | |
| 215 | // Move the viewport. |
| 216 | GetMagnificationController()->MoveWindow(0, 0, false); |
| 217 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 218 | |
| 219 | GetMagnificationController()->MoveWindow(200, 300, false); |
| 220 | EXPECT_EQ("200,300 400x300", GetViewport().ToString()); |
| 221 | |
| 222 | GetMagnificationController()->MoveWindow(400, 0, false); |
| 223 | EXPECT_EQ("400,0 400x300", GetViewport().ToString()); |
| 224 | |
| 225 | GetMagnificationController()->MoveWindow(400, 300, false); |
| 226 | EXPECT_EQ("400,300 400x300", GetViewport().ToString()); |
| 227 | |
| 228 | // Confirms that the viewport can't across the top-left border. |
| 229 | GetMagnificationController()->MoveWindow(-100, 0, false); |
| 230 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 231 | |
| 232 | GetMagnificationController()->MoveWindow(0, -100, false); |
| 233 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 234 | |
| 235 | GetMagnificationController()->MoveWindow(-100, -100, false); |
| 236 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 237 | |
| 238 | // Confirms that the viewport can't across the bittom-right border. |
| 239 | GetMagnificationController()->MoveWindow(800, 0, false); |
| 240 | EXPECT_EQ("400,0 400x300", GetViewport().ToString()); |
| 241 | |
| 242 | GetMagnificationController()->MoveWindow(0, 400, false); |
| 243 | EXPECT_EQ("0,300 400x300", GetViewport().ToString()); |
| 244 | |
| 245 | GetMagnificationController()->MoveWindow(200, 400, false); |
| 246 | EXPECT_EQ("200,300 400x300", GetViewport().ToString()); |
| 247 | |
| 248 | GetMagnificationController()->MoveWindow(1000, 1000, false); |
| 249 | EXPECT_EQ("400,300 400x300", GetViewport().ToString()); |
| 250 | } |
| 251 | |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 252 | TEST_F(MagnificationControllerTest, PointOfInterest) { |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 253 | ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 254 | |
| 255 | generator.MoveMouseToInHost(gfx::Point(0, 0)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 256 | EXPECT_EQ("0,0", CurrentPointOfInterest()); |
| 257 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 258 | generator.MoveMouseToInHost(gfx::Point(799, 599)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 259 | EXPECT_EQ("799,599", CurrentPointOfInterest()); |
| 260 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 261 | generator.MoveMouseToInHost(gfx::Point(400, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 262 | EXPECT_EQ("400,300", CurrentPointOfInterest()); |
| 263 | |
| 264 | GetMagnificationController()->SetEnabled(true); |
| 265 | EXPECT_EQ("400,300", CurrentPointOfInterest()); |
| 266 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 267 | generator.MoveMouseToInHost(gfx::Point(500, 400)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 268 | EXPECT_EQ("450,350", CurrentPointOfInterest()); |
| 269 | } |
| 270 | |
| 271 | TEST_F(MagnificationControllerTest, PanWindow2xLeftToRight) { |
| 272 | const aura::Env* env = aura::Env::GetInstance(); |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 273 | ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 274 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 275 | generator.MoveMouseToInHost(gfx::Point(0, 0)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 276 | EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); |
| 277 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 278 | EXPECT_EQ("0,0", env->last_mouse_location().ToString()); |
| 279 | |
| 280 | // Enables magnifier and confirm the viewport is at center. |
| 281 | GetMagnificationController()->SetEnabled(true); |
| 282 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 283 | |
| 284 | GetMagnificationController()->MoveWindow(0, 0, false); |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 285 | generator.MoveMouseToInHost(gfx::Point(0, 0)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 286 | EXPECT_EQ("0,0", env->last_mouse_location().ToString()); |
| 287 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 288 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 289 | generator.MoveMouseToInHost(gfx::Point(300, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 290 | EXPECT_EQ("150,75", env->last_mouse_location().ToString()); |
| 291 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 292 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 293 | generator.MoveMouseToInHost(gfx::Point(700, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 294 | EXPECT_EQ("350,75", env->last_mouse_location().ToString()); |
| 295 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 296 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 297 | generator.MoveMouseToInHost(gfx::Point(701, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 298 | EXPECT_EQ("350,75", env->last_mouse_location().ToString()); |
| 299 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 300 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 301 | generator.MoveMouseToInHost(gfx::Point(702, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 302 | EXPECT_EQ("351,75", env->last_mouse_location().ToString()); |
| 303 | EXPECT_EQ("1,0 400x300", GetViewport().ToString()); |
| 304 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 305 | generator.MoveMouseToInHost(gfx::Point(703, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 306 | EXPECT_EQ("352,75", env->last_mouse_location().ToString()); |
| 307 | EXPECT_EQ("2,0 400x300", GetViewport().ToString()); |
| 308 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 309 | generator.MoveMouseToInHost(gfx::Point(704, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 310 | EXPECT_EQ("354,75", env->last_mouse_location().ToString()); |
| 311 | EXPECT_EQ("4,0 400x300", GetViewport().ToString()); |
| 312 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 313 | generator.MoveMouseToInHost(gfx::Point(712, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 314 | EXPECT_EQ("360,75", env->last_mouse_location().ToString()); |
| 315 | EXPECT_EQ("10,0 400x300", GetViewport().ToString()); |
| 316 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 317 | generator.MoveMouseToInHost(gfx::Point(600, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 318 | EXPECT_EQ("310,75", env->last_mouse_location().ToString()); |
| 319 | EXPECT_EQ("10,0 400x300", GetViewport().ToString()); |
| 320 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 321 | generator.MoveMouseToInHost(gfx::Point(720, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 322 | EXPECT_EQ("370,75", env->last_mouse_location().ToString()); |
| 323 | EXPECT_EQ("20,0 400x300", GetViewport().ToString()); |
| 324 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 325 | generator.MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 326 | EXPECT_EQ("410,75", env->last_mouse_location().ToString()); |
| 327 | EXPECT_EQ("410,75", CurrentPointOfInterest()); |
| 328 | EXPECT_EQ("60,0 400x300", GetViewport().ToString()); |
| 329 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 330 | generator.MoveMouseToInHost(gfx::Point(799, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 331 | EXPECT_EQ("459,75", env->last_mouse_location().ToString()); |
| 332 | EXPECT_EQ("109,0 400x300", GetViewport().ToString()); |
| 333 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 334 | generator.MoveMouseToInHost(gfx::Point(702, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 335 | EXPECT_EQ("460,75", env->last_mouse_location().ToString()); |
| 336 | EXPECT_EQ("110,0 400x300", GetViewport().ToString()); |
| 337 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 338 | generator.MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 339 | EXPECT_EQ("500,75", env->last_mouse_location().ToString()); |
| 340 | EXPECT_EQ("150,0 400x300", GetViewport().ToString()); |
| 341 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 342 | generator.MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 343 | EXPECT_EQ("540,75", env->last_mouse_location().ToString()); |
| 344 | EXPECT_EQ("190,0 400x300", GetViewport().ToString()); |
| 345 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 346 | generator.MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 347 | EXPECT_EQ("580,75", env->last_mouse_location().ToString()); |
| 348 | EXPECT_EQ("230,0 400x300", GetViewport().ToString()); |
| 349 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 350 | generator.MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 351 | EXPECT_EQ("620,75", env->last_mouse_location().ToString()); |
| 352 | EXPECT_EQ("270,0 400x300", GetViewport().ToString()); |
| 353 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 354 | generator.MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 355 | EXPECT_EQ("660,75", env->last_mouse_location().ToString()); |
| 356 | EXPECT_EQ("310,0 400x300", GetViewport().ToString()); |
| 357 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 358 | generator.MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 359 | EXPECT_EQ("700,75", env->last_mouse_location().ToString()); |
| 360 | EXPECT_EQ("350,0 400x300", GetViewport().ToString()); |
| 361 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 362 | generator.MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 363 | EXPECT_EQ("740,75", env->last_mouse_location().ToString()); |
| 364 | EXPECT_EQ("390,0 400x300", GetViewport().ToString()); |
| 365 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 366 | generator.MoveMouseToInHost(gfx::Point(780, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 367 | EXPECT_EQ("780,75", env->last_mouse_location().ToString()); |
| 368 | EXPECT_EQ("400,0 400x300", GetViewport().ToString()); |
| 369 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 370 | generator.MoveMouseToInHost(gfx::Point(799, 150)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 371 | EXPECT_EQ("799,75", env->last_mouse_location().ToString()); |
| 372 | EXPECT_EQ("400,0 400x300", GetViewport().ToString()); |
| 373 | } |
| 374 | |
| 375 | TEST_F(MagnificationControllerTest, PanWindow2xRightToLeft) { |
| 376 | const aura::Env* env = aura::Env::GetInstance(); |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 377 | ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 378 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 379 | generator.MoveMouseToInHost(gfx::Point(799, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 380 | EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); |
| 381 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 382 | EXPECT_EQ("799,300", env->last_mouse_location().ToString()); |
| 383 | |
| 384 | // Enables magnifier and confirm the viewport is at center. |
| 385 | GetMagnificationController()->SetEnabled(true); |
| 386 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 387 | generator.MoveMouseToInHost(gfx::Point(799, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 388 | EXPECT_EQ("798,300", env->last_mouse_location().ToString()); |
| 389 | EXPECT_EQ("400,150 400x300", GetViewport().ToString()); |
| 390 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 391 | generator.MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 392 | EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
| 393 | EXPECT_EQ("350,150 400x300", GetViewport().ToString()); |
| 394 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 395 | generator.MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 396 | EXPECT_EQ("350,300", env->last_mouse_location().ToString()); |
| 397 | EXPECT_EQ("300,150 400x300", GetViewport().ToString()); |
| 398 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 399 | generator.MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 400 | EXPECT_EQ("300,300", env->last_mouse_location().ToString()); |
| 401 | EXPECT_EQ("250,150 400x300", GetViewport().ToString()); |
| 402 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 403 | generator.MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 404 | EXPECT_EQ("250,300", env->last_mouse_location().ToString()); |
| 405 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 406 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 407 | generator.MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 408 | EXPECT_EQ("200,300", env->last_mouse_location().ToString()); |
| 409 | EXPECT_EQ("150,150 400x300", GetViewport().ToString()); |
| 410 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 411 | generator.MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 412 | EXPECT_EQ("150,300", env->last_mouse_location().ToString()); |
| 413 | EXPECT_EQ("100,150 400x300", GetViewport().ToString()); |
| 414 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 415 | generator.MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 416 | EXPECT_EQ("100,300", env->last_mouse_location().ToString()); |
| 417 | EXPECT_EQ("50,150 400x300", GetViewport().ToString()); |
| 418 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 419 | generator.MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 420 | EXPECT_EQ("50,300", env->last_mouse_location().ToString()); |
| 421 | EXPECT_EQ("0,150 400x300", GetViewport().ToString()); |
| 422 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 423 | generator.MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 424 | EXPECT_EQ("0,300", env->last_mouse_location().ToString()); |
| 425 | EXPECT_EQ("0,150 400x300", GetViewport().ToString()); |
| 426 | } |
| 427 | |
| 428 | TEST_F(MagnificationControllerTest, PanWindowToRight) { |
| 429 | const aura::Env* env = aura::Env::GetInstance(); |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 430 | ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 431 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 432 | generator.MoveMouseToInHost(gfx::Point(400, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 433 | EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); |
| 434 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 435 | EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
| 436 | |
| 437 | float scale = 2.f; |
| 438 | |
| 439 | // Enables magnifier and confirm the viewport is at center. |
| 440 | GetMagnificationController()->SetEnabled(true); |
| 441 | EXPECT_FLOAT_EQ(2.f, GetMagnificationController()->GetScale()); |
| 442 | |
pkotwicz | 0991c82 | 2014-10-31 04:21:03 | [diff] [blame] | 443 | scale *= ui::kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 444 | GetMagnificationController()->SetScale(scale, false); |
| 445 | EXPECT_FLOAT_EQ(2.3784142, GetMagnificationController()->GetScale()); |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 446 | generator.MoveMouseToInHost(gfx::Point(400, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 447 | EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 448 | generator.MoveMouseToInHost(gfx::Point(799, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 449 | EXPECT_EQ("566,299", env->last_mouse_location().ToString()); |
| 450 | EXPECT_EQ("705,300", GetHostMouseLocation()); |
| 451 | |
pkotwicz | 0991c82 | 2014-10-31 04:21:03 | [diff] [blame] | 452 | scale *= ui::kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 453 | GetMagnificationController()->SetScale(scale, false); |
| 454 | EXPECT_FLOAT_EQ(2.8284268, GetMagnificationController()->GetScale()); |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 455 | generator.MoveMouseToInHost(gfx::Point(799, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 456 | EXPECT_EQ("599,299", env->last_mouse_location().ToString()); |
| 457 | EXPECT_EQ("702,300", GetHostMouseLocation()); |
| 458 | |
pkotwicz | 0991c82 | 2014-10-31 04:21:03 | [diff] [blame] | 459 | scale *= ui::kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 460 | GetMagnificationController()->SetScale(scale, false); |
| 461 | EXPECT_FLOAT_EQ(3.3635852, GetMagnificationController()->GetScale()); |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 462 | generator.MoveMouseToInHost(gfx::Point(799, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 463 | EXPECT_EQ("627,298", env->last_mouse_location().ToString()); |
| 464 | EXPECT_EQ("707,300", GetHostMouseLocation()); |
| 465 | |
pkotwicz | 0991c82 | 2014-10-31 04:21:03 | [diff] [blame] | 466 | scale *= ui::kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 467 | GetMagnificationController()->SetScale(scale, false); |
| 468 | EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale()); |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 469 | generator.MoveMouseToInHost(gfx::Point(799, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 470 | EXPECT_EQ("649,298", env->last_mouse_location().ToString()); |
| 471 | EXPECT_EQ("704,300", GetHostMouseLocation()); |
| 472 | } |
| 473 | |
| 474 | TEST_F(MagnificationControllerTest, PanWindowToLeft) { |
| 475 | const aura::Env* env = aura::Env::GetInstance(); |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 476 | ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 477 | |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 478 | generator.MoveMouseToInHost(gfx::Point(400, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 479 | EXPECT_EQ(1.f, GetMagnificationController()->GetScale()); |
| 480 | EXPECT_EQ("0,0 800x600", GetViewport().ToString()); |
| 481 | EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
| 482 | |
| 483 | float scale = 2.f; |
| 484 | |
| 485 | // Enables magnifier and confirm the viewport is at center. |
| 486 | GetMagnificationController()->SetEnabled(true); |
| 487 | EXPECT_FLOAT_EQ(2.f, GetMagnificationController()->GetScale()); |
| 488 | |
pkotwicz | 0991c82 | 2014-10-31 04:21:03 | [diff] [blame] | 489 | scale *= ui::kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 490 | GetMagnificationController()->SetScale(scale, false); |
| 491 | EXPECT_FLOAT_EQ(2.3784142, GetMagnificationController()->GetScale()); |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 492 | generator.MoveMouseToInHost(gfx::Point(400, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 493 | EXPECT_EQ("400,300", env->last_mouse_location().ToString()); |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 494 | generator.MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 495 | EXPECT_EQ("231,299", env->last_mouse_location().ToString()); |
| 496 | EXPECT_EQ("100,300", GetHostMouseLocation()); |
| 497 | |
pkotwicz | 0991c82 | 2014-10-31 04:21:03 | [diff] [blame] | 498 | scale *= ui::kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 499 | GetMagnificationController()->SetScale(scale, false); |
| 500 | EXPECT_FLOAT_EQ(2.8284268, GetMagnificationController()->GetScale()); |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 501 | generator.MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | a1532827 | 2013-10-02 22:52:03 | [diff] [blame] | 502 | EXPECT_EQ("194,299", env->last_mouse_location().ToString()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 503 | EXPECT_EQ("99,300", GetHostMouseLocation()); |
| 504 | |
pkotwicz | 0991c82 | 2014-10-31 04:21:03 | [diff] [blame] | 505 | scale *= ui::kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 506 | GetMagnificationController()->SetScale(scale, false); |
| 507 | EXPECT_FLOAT_EQ(3.3635852, GetMagnificationController()->GetScale()); |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 508 | generator.MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | a1532827 | 2013-10-02 22:52:03 | [diff] [blame] | 509 | EXPECT_EQ("164,298", env->last_mouse_location().ToString()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 510 | EXPECT_EQ("98,300", GetHostMouseLocation()); |
| 511 | |
pkotwicz | 0991c82 | 2014-10-31 04:21:03 | [diff] [blame] | 512 | scale *= ui::kMagnificationScaleFactor; |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 513 | GetMagnificationController()->SetScale(scale, false); |
| 514 | EXPECT_FLOAT_EQ(4.f, GetMagnificationController()->GetScale()); |
[email protected] | 2549dbc | 2013-05-09 18:48:12 | [diff] [blame] | 515 | generator.MoveMouseToInHost(gfx::Point(0, 300)); |
[email protected] | a1532827 | 2013-10-02 22:52:03 | [diff] [blame] | 516 | EXPECT_EQ("139,298", env->last_mouse_location().ToString()); |
[email protected] | 6f16249 | 2013-04-26 09:02:09 | [diff] [blame] | 517 | EXPECT_EQ("100,300", GetHostMouseLocation()); |
| 518 | } |
| 519 | |
jennyz | 91b6ed0c | 2014-10-23 21:52:41 | [diff] [blame] | 520 | TEST_F(MagnificationControllerTest, FollowTextInputFieldFocus) { |
| 521 | CreateAndShowTextInputView(gfx::Rect(500, 300, 80, 80)); |
| 522 | gfx::Rect text_input_bounds = GetTextInputViewBounds(); |
| 523 | |
| 524 | // Enables magnifier and confirm the viewport is at center. |
| 525 | GetMagnificationController()->SetEnabled(true); |
| 526 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 527 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 528 | |
| 529 | // Move the viewport to (0, 0), so that text input field will be out of |
| 530 | // the viewport region. |
| 531 | GetMagnificationController()->MoveWindow(0, 0, false); |
| 532 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 533 | EXPECT_FALSE(GetViewport().Intersects(text_input_bounds)); |
| 534 | |
| 535 | // Focus on the text input field. |
| 536 | FocusOnTextInputView(); |
| 537 | |
| 538 | // Verify the view port has been moved to the place where the text field is |
| 539 | // contained in the view port and the caret is at the center of the view port. |
| 540 | gfx::Rect view_port = GetViewport(); |
| 541 | EXPECT_TRUE(view_port.Contains(text_input_bounds)); |
| 542 | gfx::Rect caret_bounds = GetCaretBounds(); |
| 543 | EXPECT_TRUE(text_input_bounds.Contains(caret_bounds)); |
| 544 | EXPECT_EQ(caret_bounds.origin(), view_port.CenterPoint()); |
| 545 | } |
| 546 | |
| 547 | TEST_F(MagnificationControllerTest, FollowTextInputFieldKeyPress) { |
| 548 | CreateAndShowTextInputView(gfx::Rect(385, 200, 80, 80)); |
| 549 | gfx::Rect text_input_bounds = GetTextInputViewBounds(); |
| 550 | |
| 551 | // Enables magnifier and confirm the viewport is at center. |
| 552 | GetMagnificationController()->SetEnabled(true); |
| 553 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 554 | EXPECT_EQ("200,150 400x300", GetViewport().ToString()); |
| 555 | |
| 556 | // Move the viewport to (0, 0), so that text input field intersects the |
| 557 | // view port at the right edge. |
| 558 | GetMagnificationController()->MoveWindow(0, 0, false); |
| 559 | EXPECT_EQ("0,0 400x300", GetViewport().ToString()); |
| 560 | EXPECT_TRUE(GetViewport().Intersects(text_input_bounds)); |
| 561 | |
| 562 | // Focus on the text input field. |
| 563 | FocusOnTextInputView(); |
| 564 | |
| 565 | // Verify the view port is not moved, and the caret is inside the view port. |
| 566 | gfx::Rect view_port = GetViewport(); |
| 567 | EXPECT_EQ("0,0 400x300", view_port.ToString()); |
| 568 | EXPECT_TRUE(view_port.Intersects(text_input_bounds)); |
| 569 | EXPECT_TRUE(text_input_bounds.Contains(GetCaretBounds())); |
| 570 | |
| 571 | // Press keys on text input simulate typing on text field and the caret |
| 572 | // moves out of the old view port region. The view port is moved to the place |
| 573 | // where caret's x coordinate is centered at the new view port. |
| 574 | ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
| 575 | generator.PressKey(ui::VKEY_A, 0); |
| 576 | generator.ReleaseKey(ui::VKEY_A, 0); |
| 577 | gfx::Rect caret_bounds = GetCaretBounds(); |
| 578 | EXPECT_FALSE(view_port.Intersects(caret_bounds)); |
| 579 | |
| 580 | gfx::Rect new_view_port = GetViewport(); |
| 581 | EXPECT_TRUE(new_view_port.Contains(caret_bounds)); |
| 582 | EXPECT_EQ(caret_bounds.x(), new_view_port.CenterPoint().x()); |
| 583 | EXPECT_EQ(view_port.y(), new_view_port.y()); |
| 584 | } |
| 585 | |
oshima | 38dffad | 2015-05-05 17:22:56 | [diff] [blame^] | 586 | // Make sure that unified desktop can enter magnified mode. |
| 587 | TEST_F(MagnificationControllerTest, EnableMagnifierInUnifiedDesktop) { |
| 588 | if (!SupportsMultipleDisplays()) |
| 589 | return; |
| 590 | |
| 591 | DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 592 | display_manager->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED); |
| 593 | display_manager->SetMultiDisplayMode(DisplayManager::UNIFIED); |
| 594 | |
| 595 | EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 596 | |
| 597 | GetMagnificationController()->SetEnabled(true); |
| 598 | |
| 599 | gfx::Screen* screen = |
| 600 | gfx::Screen::GetScreenFor(Shell::GetPrimaryRootWindow()); |
| 601 | |
| 602 | UpdateDisplay("500x500, 500x500"); |
| 603 | EXPECT_EQ("0,0 1000x500", screen->GetPrimaryDisplay().bounds().ToString()); |
| 604 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 605 | |
| 606 | GetMagnificationController()->SetEnabled(false); |
| 607 | |
| 608 | EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 609 | |
| 610 | GetMagnificationController()->SetEnabled(true); |
| 611 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 612 | |
| 613 | UpdateDisplay("500x500"); |
| 614 | EXPECT_EQ("0,0 500x500", screen->GetPrimaryDisplay().bounds().ToString()); |
| 615 | EXPECT_EQ(2.0f, GetMagnificationController()->GetScale()); |
| 616 | |
| 617 | GetMagnificationController()->SetEnabled(false); |
| 618 | EXPECT_EQ("0,0 500x500", screen->GetPrimaryDisplay().bounds().ToString()); |
| 619 | EXPECT_EQ(1.0f, GetMagnificationController()->GetScale()); |
| 620 | } |
| 621 | |
[email protected] | 7e36873 | 2013-01-16 13:31:23 | [diff] [blame] | 622 | } // namespace ash |