| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/input/touch_emulator.h" | 5 #include "content/browser/renderer_host/input/touch_emulator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/test/scoped_task_environment.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "content/browser/renderer_host/input/touch_emulator_client.h" | 14 #include "content/browser/renderer_host/input/touch_emulator_client.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/WebKit/public/platform/WebKeyboardEvent.h" | 16 #include "third_party/WebKit/public/platform/WebKeyboardEvent.h" |
| 17 #include "third_party/WebKit/public/platform/WebMouseWheelEvent.h" | 17 #include "third_party/WebKit/public/platform/WebMouseWheelEvent.h" |
| 18 #include "ui/events/blink/web_input_event_traits.h" | 18 #include "ui/events/blink/web_input_event_traits.h" |
| 19 | 19 |
| 20 using blink::WebGestureEvent; | 20 using blink::WebGestureEvent; |
| 21 using blink::WebInputEvent; | 21 using blink::WebInputEvent; |
| 22 using blink::WebKeyboardEvent; | 22 using blink::WebKeyboardEvent; |
| 23 using blink::WebMouseEvent; | 23 using blink::WebMouseEvent; |
| 24 using blink::WebMouseWheelEvent; | 24 using blink::WebMouseWheelEvent; |
| 25 using blink::WebTouchEvent; | 25 using blink::WebTouchEvent; |
| 26 using blink::WebTouchPoint; | 26 using blink::WebTouchPoint; |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 | 29 |
| 30 class TouchEmulatorTest : public testing::Test, | 30 class TouchEmulatorTest : public testing::Test, |
| 31 public TouchEmulatorClient { | 31 public TouchEmulatorClient { |
| 32 public: | 32 public: |
| 33 TouchEmulatorTest() | 33 TouchEmulatorTest() |
| 34 : shift_pressed_(false), | 34 : scoped_task_environment_( |
| 35 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 36 shift_pressed_(false), |
| 35 mouse_pressed_(false), | 37 mouse_pressed_(false), |
| 36 ack_touches_synchronously_(true), | 38 ack_touches_synchronously_(true), |
| 37 last_mouse_x_(-1), | 39 last_mouse_x_(-1), |
| 38 last_mouse_y_(-1) { | 40 last_mouse_y_(-1) { |
| 39 last_event_time_seconds_ = | 41 last_event_time_seconds_ = |
| 40 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); | 42 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); |
| 41 event_time_delta_seconds_ = 0.1; | 43 event_time_delta_seconds_ = 0.1; |
| 42 } | 44 } |
| 43 | 45 |
| 44 ~TouchEmulatorTest() override {} | 46 ~TouchEmulatorTest() override {} |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 240 |
| 239 void DisableSynchronousTouchAck() { ack_touches_synchronously_ = false; } | 241 void DisableSynchronousTouchAck() { ack_touches_synchronously_ = false; } |
| 240 | 242 |
| 241 float GetCursorScaleFactor() { | 243 float GetCursorScaleFactor() { |
| 242 CursorInfo info; | 244 CursorInfo info; |
| 243 cursor_.GetCursorInfo(&info); | 245 cursor_.GetCursorInfo(&info); |
| 244 return info.image_scale_factor; | 246 return info.image_scale_factor; |
| 245 } | 247 } |
| 246 | 248 |
| 247 private: | 249 private: |
| 250 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 248 std::unique_ptr<TouchEmulator> emulator_; | 251 std::unique_ptr<TouchEmulator> emulator_; |
| 249 std::vector<WebInputEvent::Type> forwarded_events_; | 252 std::vector<WebInputEvent::Type> forwarded_events_; |
| 250 double last_event_time_seconds_; | 253 double last_event_time_seconds_; |
| 251 double event_time_delta_seconds_; | 254 double event_time_delta_seconds_; |
| 252 bool shift_pressed_; | 255 bool shift_pressed_; |
| 253 bool mouse_pressed_; | 256 bool mouse_pressed_; |
| 254 bool ack_touches_synchronously_; | 257 bool ack_touches_synchronously_; |
| 255 int last_mouse_x_; | 258 int last_mouse_x_; |
| 256 int last_mouse_y_; | 259 int last_mouse_y_; |
| 257 std::vector<WebTouchEvent> touch_events_to_ack_; | 260 std::vector<WebTouchEvent> touch_events_to_ack_; |
| 258 base::MessageLoopForUI message_loop_; | |
| 259 WebCursor cursor_; | 261 WebCursor cursor_; |
| 260 }; | 262 }; |
| 261 | 263 |
| 262 | 264 |
| 263 TEST_F(TouchEmulatorTest, NoTouches) { | 265 TEST_F(TouchEmulatorTest, NoTouches) { |
| 264 MouseMove(100, 200); | 266 MouseMove(100, 200); |
| 265 MouseMove(300, 300); | 267 MouseMove(300, 300); |
| 266 EXPECT_EQ("", ExpectedEvents()); | 268 EXPECT_EQ("", ExpectedEvents()); |
| 267 } | 269 } |
| 268 | 270 |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 emulator()->SetDeviceScaleFactor(1.0f); | 590 emulator()->SetDeviceScaleFactor(1.0f); |
| 589 EXPECT_EQ(1.0f, GetCursorScaleFactor()); | 591 EXPECT_EQ(1.0f, GetCursorScaleFactor()); |
| 590 | 592 |
| 591 TouchEmulator another(this, 4.0f); | 593 TouchEmulator another(this, 4.0f); |
| 592 EXPECT_EQ(1.0f, GetCursorScaleFactor()); | 594 EXPECT_EQ(1.0f, GetCursorScaleFactor()); |
| 593 another.Enable(ui::GestureProviderConfigType::GENERIC_MOBILE); | 595 another.Enable(ui::GestureProviderConfigType::GENERIC_MOBILE); |
| 594 EXPECT_EQ(2.0f, GetCursorScaleFactor()); | 596 EXPECT_EQ(2.0f, GetCursorScaleFactor()); |
| 595 } | 597 } |
| 596 | 598 |
| 597 } // namespace content | 599 } // namespace content |
| OLD | NEW |