Chromium Code Reviews| Index: ui/events/test/event_generator.cc |
| diff --git a/ui/events/test/event_generator.cc b/ui/events/test/event_generator.cc |
| index 05f8e683ebbfd2f39fbae1dc1ff60d8b01c82032..92eef76a5fc4d618939aab9e779ab9349cfbdefd 100644 |
| --- a/ui/events/test/event_generator.cc |
| +++ b/ui/events/test/event_generator.cc |
| @@ -41,41 +41,6 @@ namespace { |
| void DummyCallback(EventType, const gfx::Vector2dF&) { |
| } |
| -// A proxy for TickClock that allows passing the same underlying clock |
| -// to multiple consumers, each retaining a unique_ptr to their own |
| -// instance of TickClock proxy. |
| -class ClonableTickClock : public base::TickClock, |
| - public base::RefCounted<ClonableTickClock> { |
| - private: |
| - class TickClockProxy : public base::TickClock { |
| - public: |
| - explicit TickClockProxy(ClonableTickClock* tick_clock) |
| - : tick_clock_(tick_clock) {} |
| - |
| - private: |
| - base::TimeTicks NowTicks() override { return tick_clock_->NowTicks(); } |
| - |
| - scoped_refptr<ClonableTickClock> tick_clock_; |
| - DISALLOW_COPY_AND_ASSIGN(TickClockProxy); |
| - }; |
| - |
| - public: |
| - explicit ClonableTickClock(std::unique_ptr<base::TickClock> tick_clock) |
| - : tick_clock_(std::move(tick_clock)) {} |
| - |
| - base::TimeTicks NowTicks() override { return tick_clock_->NowTicks(); } |
| - std::unique_ptr<TickClock> Clone() { |
| - return WrapUnique(new TickClockProxy(this)); |
| - } |
| - |
| - private: |
| - friend class base::RefCounted<ClonableTickClock>; |
| - ~ClonableTickClock() override = default; |
| - std::unique_ptr<TickClock> tick_clock_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(ClonableTickClock); |
| -}; |
| - |
| class TestTickClock : public base::TickClock { |
| public: |
| // Starts off with a clock set to TimeTicks(). |
| @@ -214,20 +179,21 @@ void EventGenerator::MoveMouseToWithNative(const gfx::Point& point_in_host, |
| ui::ScopedXI2Event xevent; |
| xevent.InitMotionEvent(point_in_host, point_for_native, flags_); |
| static_cast<XEvent*>(xevent)->xmotion.time = |
| - (Now() - base::TimeTicks()).InMilliseconds() & UINT32_MAX; |
| + (ui::EventTimeForNow() - base::TimeTicks()).InMilliseconds() & UINT32_MAX; |
| ui::MouseEvent mouseev(xevent); |
| #elif defined(USE_OZONE) |
| // Ozone uses the location in native event as a system location. |
| // Create a fake event with the point in host, which will be passed |
| // to the non native event, then update the native event with the native |
| // (root) one. |
| - std::unique_ptr<ui::MouseEvent> native_event(new ui::MouseEvent( |
| - ui::ET_MOUSE_MOVED, point_in_host, point_in_host, Now(), flags_, 0)); |
| + std::unique_ptr<ui::MouseEvent> native_event( |
| + new ui::MouseEvent(ui::ET_MOUSE_MOVED, point_in_host, point_in_host, |
| + ui::EventTimeForNow(), flags_, 0)); |
| ui::MouseEvent mouseev(native_event.get()); |
| native_event->set_location(point_for_native); |
| #else |
| ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, point_in_host, point_for_native, |
| - Now(), flags_, 0); |
| + ui::EventTimeForNow(), flags_, 0); |
| LOG(FATAL) |
| << "Generating a native motion event is not supported on this platform"; |
| #endif |
| @@ -291,9 +257,8 @@ void EventGenerator::PressTouch() { |
| } |
| void EventGenerator::PressTouchId(int touch_id) { |
| - TestTouchEvent touchev( |
| - ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), touch_id, flags_, |
| - Now()); |
| + TestTouchEvent touchev(ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), |
| + touch_id, flags_, ui::EventTimeForNow()); |
| Dispatch(&touchev); |
| } |
| @@ -303,9 +268,8 @@ void EventGenerator::MoveTouch(const gfx::Point& point) { |
| void EventGenerator::MoveTouchId(const gfx::Point& point, int touch_id) { |
| current_location_ = point; |
| - TestTouchEvent touchev( |
| - ui::ET_TOUCH_MOVED, GetLocationInCurrentRoot(), touch_id, flags_, |
| - Now()); |
| + TestTouchEvent touchev(ui::ET_TOUCH_MOVED, GetLocationInCurrentRoot(), |
| + touch_id, flags_, ui::EventTimeForNow()); |
| Dispatch(&touchev); |
| if (!grab_) |
| @@ -317,9 +281,8 @@ void EventGenerator::ReleaseTouch() { |
| } |
| void EventGenerator::ReleaseTouchId(int touch_id) { |
| - TestTouchEvent touchev( |
| - ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), touch_id, flags_, |
| - Now()); |
| + TestTouchEvent touchev(ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), |
| + touch_id, flags_, ui::EventTimeForNow()); |
| Dispatch(&touchev); |
| } |
| @@ -336,16 +299,14 @@ void EventGenerator::PressMoveAndReleaseTouchToCenterOf(EventTarget* window) { |
| void EventGenerator::GestureEdgeSwipe() { |
| GestureEventDetails details(ET_GESTURE_WIN8_EDGE_SWIPE); |
| details.set_device_type(GestureDeviceType::DEVICE_TOUCHSCREEN); |
| - GestureEvent gesture(0, 0, 0, Now(), details); |
| + GestureEvent gesture(0, 0, 0, ui::EventTimeForNow(), details); |
| Dispatch(&gesture); |
| } |
| void EventGenerator::GestureTapAt(const gfx::Point& location) { |
| const int kTouchId = 2; |
| - ui::TouchEvent press(ui::ET_TOUCH_PRESSED, |
| - location, |
| - kTouchId, |
| - Now()); |
| + ui::TouchEvent press(ui::ET_TOUCH_PRESSED, location, kTouchId, |
| + ui::EventTimeForNow()); |
| Dispatch(&press); |
| ui::TouchEvent release( |
| @@ -356,10 +317,8 @@ void EventGenerator::GestureTapAt(const gfx::Point& location) { |
| void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) { |
| const int kTouchId = 3; |
| - ui::TouchEvent press(ui::ET_TOUCH_PRESSED, |
| - location, |
| - kTouchId, |
| - Now()); |
| + ui::TouchEvent press(ui::ET_TOUCH_PRESSED, location, kTouchId, |
| + ui::EventTimeForNow()); |
| Dispatch(&press); |
| ui::TouchEvent release( |
| @@ -393,7 +352,7 @@ void EventGenerator::GestureScrollSequenceWithCallback( |
| int steps, |
| const ScrollStepCallback& callback) { |
| const int kTouchId = 5; |
| - base::TimeTicks timestamp = Now(); |
| + base::TimeTicks timestamp = ui::EventTimeForNow(); |
| ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, 0, kTouchId, |
| timestamp, 5.0f, 5.0f, 0.0f, 1.0f); |
| Dispatch(&press); |
| @@ -453,7 +412,7 @@ void EventGenerator::GestureMultiFingerScrollWithDelays( |
| points[i] = start[i]; |
| } |
| - base::TimeTicks press_time_first = Now(); |
| + base::TimeTicks press_time_first = ui::EventTimeForNow(); |
| base::TimeTicks press_time[kMaxTouchPoints]; |
| bool pressed[kMaxTouchPoints]; |
| for (int i = 0; i < count; ++i) { |
| @@ -505,7 +464,7 @@ void EventGenerator::ScrollSequence(const gfx::Point& start, |
| float y_offset, |
| int steps, |
| int num_fingers) { |
| - base::TimeTicks timestamp = Now(); |
| + base::TimeTicks timestamp = ui::EventTimeForNow(); |
| ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, |
| start, |
| timestamp, |
| @@ -544,7 +503,7 @@ void EventGenerator::ScrollSequence(const gfx::Point& start, |
| const std::vector<gfx::PointF>& offsets, |
| int num_fingers) { |
| size_t steps = offsets.size(); |
| - base::TimeTicks timestamp = Now(); |
| + base::TimeTicks timestamp = ui::EventTimeForNow(); |
| ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, |
| start, |
| timestamp, |
| @@ -588,24 +547,9 @@ void EventGenerator::Dispatch(ui::Event* event) { |
| DoDispatchEvent(event, async_); |
| } |
| -void EventGenerator::SetTickClock(std::unique_ptr<base::TickClock> tick_clock) { |
| - scoped_refptr<ClonableTickClock> clonable = |
| - new ClonableTickClock(std::move(tick_clock)); |
| - ui::SetEventTickClockForTesting(clonable->Clone()); |
| - tick_clock_ = clonable->Clone(); |
| -} |
| - |
| -base::TimeTicks EventGenerator::Now() { |
| - // This is the same as what EventTimeForNow() does, but here we do it |
| - // with a tick clock that can be replaced with a simulated clock for tests. |
| - // TODO(majidvp): The tick clock used by |ui::EventTimeForNow()| is now |
| - // mockable so we no longer need this. |
| - return tick_clock_->NowTicks(); |
| -} |
| - |
| void EventGenerator::Init(gfx::NativeWindow root_window, |
| gfx::NativeWindow window_context) { |
| - SetTickClock(WrapUnique(new TestTickClock())); |
| + ui::SetEventTickClockForTesting(WrapUnique(new TestTickClock())); |
|
sadrul
2016/06/30 14:30:11
Should you unset it from the dtor? (see https://co
majidvp
2016/07/05 01:59:47
Yes it should be. It is actually unset from dtor i
|
| delegate()->SetContext(this, root_window, window_context); |
| if (window_context) |
| current_location_ = delegate()->CenterOfWindow(window_context); |
| @@ -630,7 +574,8 @@ void EventGenerator::DispatchKeyEvent(bool is_press, |
| } |
| MSG native_event = |
| { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 }; |
| - native_event.time = (Now() - base::TimeTicks()).InMicroseconds(); |
| + native_event.time = |
| + (ui::EventTimeForNow() - base::TimeTicks()).InMicroseconds(); |
| ui::KeyEvent keyev(native_event, flags); |
| #elif defined(USE_X11) |
| ui::ScopedXI2Event xevent; |
| @@ -638,7 +583,7 @@ void EventGenerator::DispatchKeyEvent(bool is_press, |
| key_code, |
| flags); |
| static_cast<XEvent*>(xevent)->xkey.time = |
| - (Now() - base::TimeTicks()).InMilliseconds() & UINT32_MAX; |
| + (ui::EventTimeForNow() - base::TimeTicks()).InMilliseconds() & UINT32_MAX; |
| ui::KeyEvent keyev(xevent); |
| #else |
| ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; |