Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Unified Diff: ui/events/test/event_generator.cc

Issue 1017323002: make IsRepeated work even when a KeyEvent is created from the same native event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ui/events/event_unittest.cc ('K') | « ui/events/event_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/test/event_generator.cc
diff --git a/ui/events/test/event_generator.cc b/ui/events/test/event_generator.cc
index f743ba18408f9b98626ff2859a806d2a53225577..26df7b43877c69ec3110d2093f971320f117f4ea 100644
--- a/ui/events/test/event_generator.cc
+++ b/ui/events/test/event_generator.cc
@@ -10,6 +10,7 @@
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
#include "base/time/default_tick_clock.h"
+#include "base/time/tick_clock.h"
#include "ui/events/event.h"
#include "ui/events/event_source.h"
#include "ui/events/event_utils.h"
@@ -32,6 +33,21 @@ namespace {
void DummyCallback(EventType, const gfx::Vector2dF&) {
}
+class TestTickClock : public base::TickClock {
+ public:
+ // Starts off with a clock set to TimeTicks().
+ TestTickClock() {}
+
+ base::TimeTicks NowTicks() override {
+ return base::TimeTicks::FromInternalValue(ticks_++ * 1000);
+ }
+
+ private:
+ int64 ticks_ = 1;
+
+ DISALLOW_COPY_AND_ASSIGN(TestTickClock);
+};
+
class TestKeyEvent : public ui::KeyEvent {
public:
TestKeyEvent(const base::NativeEvent& native_event, int flags)
@@ -518,6 +534,9 @@ void EventGenerator::Init(gfx::NativeWindow root_window,
if (window_context)
current_location_ = delegate()->CenterOfWindow(window_context);
current_target_ = delegate()->GetTargetAt(current_location_);
+
+ scoped_ptr<base::TickClock> clock(new TestTickClock);
+ SetTickClock(clock.Pass());
}
void EventGenerator::DispatchKeyEvent(bool is_press,
@@ -537,12 +556,14 @@ void EventGenerator::DispatchKeyEvent(bool is_press,
}
MSG native_event =
{ NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 };
+ native_event.time = Now().InMicroseconds();
TestKeyEvent keyev(native_event, flags);
#elif defined(USE_X11)
ui::ScopedXI2Event xevent;
xevent.InitKeyEvent(is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED,
key_code,
flags);
+ static_cast<XEvent*>(xevent)->xkey.time = Now().InMicroseconds();
ui::KeyEvent keyev(xevent);
#else
ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED;
« ui/events/event_unittest.cc ('K') | « ui/events/event_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698