base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / events / event_unittest.cc
blob1debef9a1e83bd51bede619c3181a90ea267eb35
1 // Copyright (c) 2012 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.
5 #include "base/memory/scoped_ptr.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/events/event.h"
8 #include "ui/events/event_utils.h"
9 #include "ui/events/keycodes/dom3/dom_code.h"
10 #include "ui/events/keycodes/dom4/keycode_converter.h"
11 #include "ui/events/test/events_test_utils.h"
13 #if defined(USE_X11)
14 #include <X11/Xlib.h>
15 #include "ui/events/test/events_test_utils_x11.h"
16 #include "ui/gfx/x/x11_types.h"
17 #endif
19 namespace ui {
21 TEST(EventTest, NoNativeEvent) {
22 KeyEvent keyev(ET_KEY_PRESSED, VKEY_SPACE, EF_NONE);
23 EXPECT_FALSE(keyev.HasNativeEvent());
26 TEST(EventTest, NativeEvent) {
27 #if defined(OS_WIN)
28 MSG native_event = { NULL, WM_KEYUP, VKEY_A, 0 };
29 KeyEvent keyev(native_event);
30 EXPECT_TRUE(keyev.HasNativeEvent());
31 #elif defined(USE_X11)
32 ScopedXI2Event event;
33 event.InitKeyEvent(ET_KEY_RELEASED, VKEY_A, EF_NONE);
34 KeyEvent keyev(event);
35 EXPECT_TRUE(keyev.HasNativeEvent());
36 #endif
39 TEST(EventTest, GetCharacter) {
40 // Check if Control+Enter returns 10.
41 KeyEvent keyev1(ET_KEY_PRESSED, VKEY_RETURN, EF_CONTROL_DOWN);
42 EXPECT_EQ(10, keyev1.GetCharacter());
43 // Check if Enter returns 13.
44 KeyEvent keyev2(ET_KEY_PRESSED, VKEY_RETURN, EF_NONE);
45 EXPECT_EQ(13, keyev2.GetCharacter());
47 #if defined(USE_X11)
48 // For X11, test the functions with native_event() as well. crbug.com/107837
49 ScopedXI2Event event;
50 event.InitKeyEvent(ET_KEY_PRESSED, VKEY_RETURN, EF_CONTROL_DOWN);
51 KeyEvent keyev3(event);
52 EXPECT_EQ(10, keyev3.GetCharacter());
54 event.InitKeyEvent(ET_KEY_PRESSED, VKEY_RETURN, EF_NONE);
55 KeyEvent keyev4(event);
56 EXPECT_EQ(13, keyev4.GetCharacter());
57 #endif
60 TEST(EventTest, ClickCount) {
61 const gfx::Point origin(0, 0);
62 MouseEvent mouseev(ET_MOUSE_PRESSED, origin, origin, 0, 0);
63 for (int i = 1; i <=3 ; ++i) {
64 mouseev.SetClickCount(i);
65 EXPECT_EQ(i, mouseev.GetClickCount());
69 TEST(EventTest, RepeatedClick) {
70 const gfx::Point origin(0, 0);
71 MouseEvent mouse_ev1(ET_MOUSE_PRESSED, origin, origin, 0, 0);
72 MouseEvent mouse_ev2(ET_MOUSE_PRESSED, origin, origin, 0, 0);
73 LocatedEventTestApi test_ev1(&mouse_ev1);
74 LocatedEventTestApi test_ev2(&mouse_ev2);
76 base::TimeDelta start = base::TimeDelta::FromMilliseconds(0);
77 base::TimeDelta soon = start + base::TimeDelta::FromMilliseconds(1);
78 base::TimeDelta later = start + base::TimeDelta::FromMilliseconds(1000);
80 // Close point.
81 test_ev1.set_location(gfx::Point(0, 0));
82 test_ev2.set_location(gfx::Point(1, 0));
83 test_ev1.set_time_stamp(start);
84 test_ev2.set_time_stamp(soon);
85 EXPECT_TRUE(MouseEvent::IsRepeatedClickEvent(mouse_ev1, mouse_ev2));
87 // Too far.
88 test_ev1.set_location(gfx::Point(0, 0));
89 test_ev2.set_location(gfx::Point(10, 0));
90 test_ev1.set_time_stamp(start);
91 test_ev2.set_time_stamp(soon);
92 EXPECT_FALSE(MouseEvent::IsRepeatedClickEvent(mouse_ev1, mouse_ev2));
94 // Too long a time between clicks.
95 test_ev1.set_location(gfx::Point(0, 0));
96 test_ev2.set_location(gfx::Point(0, 0));
97 test_ev1.set_time_stamp(start);
98 test_ev2.set_time_stamp(later);
99 EXPECT_FALSE(MouseEvent::IsRepeatedClickEvent(mouse_ev1, mouse_ev2));
102 // Tests that an event only increases the click count and gets marked as a
103 // double click if a release event was seen for the previous click. This
104 // prevents the same PRESSED event from being processed twice:
105 // http://crbug.com/389162
106 TEST(EventTest, DoubleClickRequiresRelease) {
107 const gfx::Point origin1(0, 0);
108 const gfx::Point origin2(100, 0);
109 scoped_ptr<MouseEvent> ev;
110 base::TimeDelta start = base::TimeDelta::FromMilliseconds(0);
112 ev.reset(new MouseEvent(ET_MOUSE_PRESSED, origin1, origin1, 0, 0));
113 ev->set_time_stamp(start);
114 EXPECT_EQ(1, MouseEvent::GetRepeatCount(*ev));
115 ev.reset(new MouseEvent(ET_MOUSE_PRESSED, origin1, origin1, 0, 0));
116 ev->set_time_stamp(start);
117 EXPECT_EQ(1, MouseEvent::GetRepeatCount(*ev));
119 ev.reset(new MouseEvent(ET_MOUSE_PRESSED, origin2, origin2, 0, 0));
120 ev->set_time_stamp(start);
121 EXPECT_EQ(1, MouseEvent::GetRepeatCount(*ev));
122 ev.reset(new MouseEvent(ET_MOUSE_RELEASED, origin2, origin2, 0, 0));
123 ev->set_time_stamp(start);
124 EXPECT_EQ(1, MouseEvent::GetRepeatCount(*ev));
125 ev.reset(new MouseEvent(ET_MOUSE_PRESSED, origin2, origin2, 0, 0));
126 ev->set_time_stamp(start);
127 EXPECT_EQ(2, MouseEvent::GetRepeatCount(*ev));
128 ev.reset(new MouseEvent(ET_MOUSE_RELEASED, origin2, origin2, 0, 0));
129 ev->set_time_stamp(start);
130 EXPECT_EQ(2, MouseEvent::GetRepeatCount(*ev));
131 MouseEvent::ResetLastClickForTest();
134 // Tests that clicking right and then left clicking does not generate a double
135 // click.
136 TEST(EventTest, SingleClickRightLeft) {
137 const gfx::Point origin(0, 0);
138 scoped_ptr<MouseEvent> ev;
139 base::TimeDelta start = base::TimeDelta::FromMilliseconds(0);
141 ev.reset(new MouseEvent(ET_MOUSE_PRESSED, origin, origin,
142 ui::EF_RIGHT_MOUSE_BUTTON,
143 ui::EF_RIGHT_MOUSE_BUTTON));
144 ev->set_time_stamp(start);
145 EXPECT_EQ(1, MouseEvent::GetRepeatCount(*ev));
146 ev.reset(new MouseEvent(ET_MOUSE_PRESSED, origin, origin,
147 ui::EF_LEFT_MOUSE_BUTTON,
148 ui::EF_LEFT_MOUSE_BUTTON));
149 ev->set_time_stamp(start);
150 EXPECT_EQ(1, MouseEvent::GetRepeatCount(*ev));
151 ev.reset(new MouseEvent(ET_MOUSE_RELEASED, origin, origin,
152 ui::EF_LEFT_MOUSE_BUTTON,
153 ui::EF_LEFT_MOUSE_BUTTON));
154 ev->set_time_stamp(start);
155 EXPECT_EQ(1, MouseEvent::GetRepeatCount(*ev));
156 ev.reset(new MouseEvent(ET_MOUSE_PRESSED, origin, origin,
157 ui::EF_LEFT_MOUSE_BUTTON,
158 ui::EF_LEFT_MOUSE_BUTTON));
159 ev->set_time_stamp(start);
160 EXPECT_EQ(2, MouseEvent::GetRepeatCount(*ev));
161 MouseEvent::ResetLastClickForTest();
164 TEST(EventTest, KeyEvent) {
165 static const struct {
166 KeyboardCode key_code;
167 int flags;
168 uint16 character;
169 } kTestData[] = {
170 { VKEY_A, 0, 'a' },
171 { VKEY_A, EF_SHIFT_DOWN, 'A' },
172 { VKEY_A, EF_CAPS_LOCK_DOWN, 'A' },
173 { VKEY_A, EF_SHIFT_DOWN | EF_CAPS_LOCK_DOWN, 'a' },
174 { VKEY_A, EF_CONTROL_DOWN, 0x01 },
175 { VKEY_A, EF_SHIFT_DOWN | EF_CONTROL_DOWN, '\x01' },
176 { VKEY_Z, 0, 'z' },
177 { VKEY_Z, EF_SHIFT_DOWN, 'Z' },
178 { VKEY_Z, EF_CAPS_LOCK_DOWN, 'Z' },
179 { VKEY_Z, EF_SHIFT_DOWN | EF_CAPS_LOCK_DOWN, 'z' },
180 { VKEY_Z, EF_CONTROL_DOWN, '\x1A' },
181 { VKEY_Z, EF_SHIFT_DOWN | EF_CONTROL_DOWN, '\x1A' },
183 { VKEY_2, EF_CONTROL_DOWN, '\0' },
184 { VKEY_2, EF_SHIFT_DOWN | EF_CONTROL_DOWN, '\0' },
185 { VKEY_6, EF_CONTROL_DOWN, '\0' },
186 { VKEY_6, EF_SHIFT_DOWN | EF_CONTROL_DOWN, '\x1E' },
187 { VKEY_OEM_MINUS, EF_CONTROL_DOWN, '\0' },
188 { VKEY_OEM_MINUS, EF_SHIFT_DOWN | EF_CONTROL_DOWN, '\x1F' },
189 { VKEY_OEM_4, EF_CONTROL_DOWN, '\x1B' },
190 { VKEY_OEM_4, EF_SHIFT_DOWN | EF_CONTROL_DOWN, '\0' },
191 { VKEY_OEM_5, EF_CONTROL_DOWN, '\x1C' },
192 { VKEY_OEM_5, EF_SHIFT_DOWN | EF_CONTROL_DOWN, '\0' },
193 { VKEY_OEM_6, EF_CONTROL_DOWN, '\x1D' },
194 { VKEY_OEM_6, EF_SHIFT_DOWN | EF_CONTROL_DOWN, '\0' },
195 { VKEY_RETURN, EF_CONTROL_DOWN, '\x0A' },
197 { VKEY_0, 0, '0' },
198 { VKEY_0, EF_SHIFT_DOWN, ')' },
199 { VKEY_0, EF_SHIFT_DOWN | EF_CAPS_LOCK_DOWN, ')' },
200 { VKEY_0, EF_SHIFT_DOWN | EF_CONTROL_DOWN, '\0' },
202 { VKEY_9, 0, '9' },
203 { VKEY_9, EF_SHIFT_DOWN, '(' },
204 { VKEY_9, EF_SHIFT_DOWN | EF_CAPS_LOCK_DOWN, '(' },
205 { VKEY_9, EF_SHIFT_DOWN | EF_CONTROL_DOWN, '\0' },
207 { VKEY_NUMPAD0, EF_CONTROL_DOWN, '\0' },
208 { VKEY_NUMPAD0, EF_SHIFT_DOWN, '0' },
210 { VKEY_NUMPAD9, EF_CONTROL_DOWN, '\0' },
211 { VKEY_NUMPAD9, EF_SHIFT_DOWN, '9' },
213 { VKEY_TAB, EF_CONTROL_DOWN, '\0' },
214 { VKEY_TAB, EF_SHIFT_DOWN, '\t' },
216 { VKEY_MULTIPLY, EF_CONTROL_DOWN, '\0' },
217 { VKEY_MULTIPLY, EF_SHIFT_DOWN, '*' },
218 { VKEY_ADD, EF_CONTROL_DOWN, '\0' },
219 { VKEY_ADD, EF_SHIFT_DOWN, '+' },
220 { VKEY_SUBTRACT, EF_CONTROL_DOWN, '\0' },
221 { VKEY_SUBTRACT, EF_SHIFT_DOWN, '-' },
222 { VKEY_DECIMAL, EF_CONTROL_DOWN, '\0' },
223 { VKEY_DECIMAL, EF_SHIFT_DOWN, '.' },
224 { VKEY_DIVIDE, EF_CONTROL_DOWN, '\0' },
225 { VKEY_DIVIDE, EF_SHIFT_DOWN, '/' },
227 { VKEY_OEM_1, EF_CONTROL_DOWN, '\0' },
228 { VKEY_OEM_1, EF_SHIFT_DOWN, ':' },
229 { VKEY_OEM_PLUS, EF_CONTROL_DOWN, '\0' },
230 { VKEY_OEM_PLUS, EF_SHIFT_DOWN, '+' },
231 { VKEY_OEM_COMMA, EF_CONTROL_DOWN, '\0' },
232 { VKEY_OEM_COMMA, EF_SHIFT_DOWN, '<' },
233 { VKEY_OEM_PERIOD, EF_CONTROL_DOWN, '\0' },
234 { VKEY_OEM_PERIOD, EF_SHIFT_DOWN, '>' },
235 { VKEY_OEM_3, EF_CONTROL_DOWN, '\0' },
236 { VKEY_OEM_3, EF_SHIFT_DOWN, '~' },
239 for (size_t i = 0; i < arraysize(kTestData); ++i) {
240 KeyEvent key(ET_KEY_PRESSED,
241 kTestData[i].key_code,
242 kTestData[i].flags);
243 EXPECT_EQ(kTestData[i].character, key.GetCharacter())
244 << " Index:" << i << " key_code:" << kTestData[i].key_code;
248 TEST(EventTest, KeyEventDirectUnicode) {
249 KeyEvent key(0x1234U, ui::VKEY_UNKNOWN, ui::EF_NONE);
250 EXPECT_EQ(0x1234U, key.GetCharacter());
251 EXPECT_EQ(ET_KEY_PRESSED, key.type());
252 EXPECT_TRUE(key.is_char());
255 TEST(EventTest, NormalizeKeyEventFlags) {
256 #if defined(USE_X11)
257 // Normalize flags when KeyEvent is created from XEvent.
258 ScopedXI2Event event;
260 event.InitKeyEvent(ET_KEY_PRESSED, VKEY_SHIFT, EF_SHIFT_DOWN);
261 KeyEvent keyev(event);
262 EXPECT_EQ(EF_SHIFT_DOWN, keyev.flags());
265 event.InitKeyEvent(ET_KEY_RELEASED, VKEY_SHIFT, EF_SHIFT_DOWN);
266 KeyEvent keyev(event);
267 EXPECT_EQ(EF_NONE, keyev.flags());
270 event.InitKeyEvent(ET_KEY_PRESSED, VKEY_CONTROL, EF_CONTROL_DOWN);
271 KeyEvent keyev(event);
272 EXPECT_EQ(EF_CONTROL_DOWN, keyev.flags());
275 event.InitKeyEvent(ET_KEY_RELEASED, VKEY_CONTROL, EF_CONTROL_DOWN);
276 KeyEvent keyev(event);
277 EXPECT_EQ(EF_NONE, keyev.flags());
280 event.InitKeyEvent(ET_KEY_PRESSED, VKEY_MENU, EF_ALT_DOWN);
281 KeyEvent keyev(event);
282 EXPECT_EQ(EF_ALT_DOWN, keyev.flags());
285 event.InitKeyEvent(ET_KEY_RELEASED, VKEY_MENU, EF_ALT_DOWN);
286 KeyEvent keyev(event);
287 EXPECT_EQ(EF_NONE, keyev.flags());
289 #endif
291 // Do not normalize flags for synthesized events without
292 // KeyEvent::NormalizeFlags called explicitly.
294 KeyEvent keyev(ET_KEY_PRESSED, VKEY_SHIFT, EF_SHIFT_DOWN);
295 EXPECT_EQ(EF_SHIFT_DOWN, keyev.flags());
298 KeyEvent keyev(ET_KEY_RELEASED, VKEY_SHIFT, EF_SHIFT_DOWN);
299 EXPECT_EQ(EF_SHIFT_DOWN, keyev.flags());
300 keyev.NormalizeFlags();
301 EXPECT_EQ(EF_NONE, keyev.flags());
304 KeyEvent keyev(ET_KEY_PRESSED, VKEY_CONTROL, EF_CONTROL_DOWN);
305 EXPECT_EQ(EF_CONTROL_DOWN, keyev.flags());
308 KeyEvent keyev(ET_KEY_RELEASED, VKEY_CONTROL, EF_CONTROL_DOWN);
309 EXPECT_EQ(EF_CONTROL_DOWN, keyev.flags());
310 keyev.NormalizeFlags();
311 EXPECT_EQ(EF_NONE, keyev.flags());
314 KeyEvent keyev(ET_KEY_PRESSED, VKEY_MENU, EF_ALT_DOWN);
315 EXPECT_EQ(EF_ALT_DOWN, keyev.flags());
318 KeyEvent keyev(ET_KEY_RELEASED, VKEY_MENU, EF_ALT_DOWN);
319 EXPECT_EQ(EF_ALT_DOWN, keyev.flags());
320 keyev.NormalizeFlags();
321 EXPECT_EQ(EF_NONE, keyev.flags());
325 TEST(EventTest, KeyEventCopy) {
326 KeyEvent key(ET_KEY_PRESSED, VKEY_A, EF_NONE);
327 scoped_ptr<KeyEvent> copied_key(new KeyEvent(key));
328 EXPECT_EQ(copied_key->type(), key.type());
329 EXPECT_EQ(copied_key->key_code(), key.key_code());
332 TEST(EventTest, KeyEventCode) {
333 const DomCode kDomCodeForSpace = DomCode::SPACE;
334 const char kCodeForSpace[] = "Space";
335 ASSERT_EQ(kDomCodeForSpace,
336 ui::KeycodeConverter::CodeStringToDomCode(kCodeForSpace));
337 const uint16 kNativeCodeSpace =
338 ui::KeycodeConverter::CodeToNativeKeycode(kCodeForSpace);
339 ASSERT_NE(ui::KeycodeConverter::InvalidNativeKeycode(), kNativeCodeSpace);
340 ASSERT_EQ(kNativeCodeSpace,
341 ui::KeycodeConverter::DomCodeToNativeKeycode(kDomCodeForSpace));
344 KeyEvent key(ET_KEY_PRESSED, VKEY_SPACE, kDomCodeForSpace, EF_NONE);
345 EXPECT_EQ(kCodeForSpace, key.GetCodeString());
348 // Regardless the KeyEvent.key_code (VKEY_RETURN), code should be
349 // the specified value.
350 KeyEvent key(ET_KEY_PRESSED, VKEY_RETURN, kDomCodeForSpace, EF_NONE);
351 EXPECT_EQ(kCodeForSpace, key.GetCodeString());
354 // If the synthetic event is initialized without code, it returns
355 // an empty string.
356 // TODO(komatsu): Fill a fallback value assuming the US keyboard layout.
357 KeyEvent key(ET_KEY_PRESSED, VKEY_SPACE, EF_NONE);
358 EXPECT_TRUE(key.GetCodeString().empty());
360 #if defined(USE_X11)
362 // KeyEvent converts from the native keycode (XKB) to the code.
363 ScopedXI2Event xevent;
364 xevent.InitKeyEvent(ET_KEY_PRESSED, VKEY_SPACE, kNativeCodeSpace);
365 KeyEvent key(xevent);
366 EXPECT_EQ(kCodeForSpace, key.GetCodeString());
368 #endif // USE_X11
369 #if defined(OS_WIN)
371 // Test a non extended key.
372 ASSERT_EQ((kNativeCodeSpace & 0xFF), kNativeCodeSpace);
374 const LPARAM lParam = GetLParamFromScanCode(kNativeCodeSpace);
375 MSG native_event = { NULL, WM_KEYUP, VKEY_SPACE, lParam };
376 KeyEvent key(native_event);
378 // KeyEvent converts from the native keycode (scan code) to the code.
379 EXPECT_EQ(kCodeForSpace, key.GetCodeString());
382 const char kCodeForHome[] = "Home";
383 const uint16 kNativeCodeHome = 0xe047;
385 // 'Home' is an extended key with 0xe000 bits.
386 ASSERT_NE((kNativeCodeHome & 0xFF), kNativeCodeHome);
387 const LPARAM lParam = GetLParamFromScanCode(kNativeCodeHome);
389 MSG native_event = { NULL, WM_KEYUP, VKEY_HOME, lParam };
390 KeyEvent key(native_event);
392 // KeyEvent converts from the native keycode (scan code) to the code.
393 EXPECT_EQ(kCodeForHome, key.GetCodeString());
395 #endif // OS_WIN
398 namespace {
399 #if defined(USE_X11)
400 void SetKeyEventTimestamp(XEvent* event, long time) {
401 event->xkey.time = time;
404 #elif defined(OS_WIN)
405 void SetKeyEventTimestamp(MSG& msg, long time) {
406 msg.time = time;
408 #endif
409 } // namespace
411 #if defined(USE_X11) || defined(OS_WIN)
412 TEST(EventTest, AutoRepeat) {
413 const uint16 kNativeCodeA = ui::KeycodeConverter::CodeToNativeKeycode("KeyA");
414 const uint16 kNativeCodeB = ui::KeycodeConverter::CodeToNativeKeycode("KeyB");
415 #if defined(USE_X11)
416 ScopedXI2Event native_event_a_pressed;
417 native_event_a_pressed.InitKeyEvent(ET_KEY_PRESSED, VKEY_A, kNativeCodeA);
418 ScopedXI2Event native_event_a_pressed_1500;
419 native_event_a_pressed_1500.InitKeyEvent(
420 ET_KEY_PRESSED, VKEY_A, kNativeCodeA);
421 ScopedXI2Event native_event_a_pressed_3000;
422 native_event_a_pressed_3000.InitKeyEvent(
423 ET_KEY_PRESSED, VKEY_A, kNativeCodeA);
425 ScopedXI2Event native_event_a_released;
426 native_event_a_released.InitKeyEvent(ET_KEY_RELEASED, VKEY_A, kNativeCodeA);
427 ScopedXI2Event native_event_b_pressed;
428 native_event_b_pressed.InitKeyEvent(ET_KEY_PRESSED, VKEY_B, kNativeCodeB);
429 ScopedXI2Event native_event_a_pressed_nonstandard_state;
430 native_event_a_pressed_nonstandard_state.InitKeyEvent(
431 ET_KEY_PRESSED, VKEY_A, kNativeCodeA);
432 // IBUS-GTK uses the mask (1 << 25) to detect reposted event.
433 static_cast<XEvent*>(native_event_a_pressed_nonstandard_state)->xkey.state |=
434 1 << 25;
435 #elif defined(OS_WIN)
436 const LPARAM lParam_a = GetLParamFromScanCode(kNativeCodeA);
437 const LPARAM lParam_b = GetLParamFromScanCode(kNativeCodeB);
438 MSG native_event_a_pressed = { NULL, WM_KEYDOWN, VKEY_A, lParam_a };
439 MSG native_event_a_pressed_1500 = { NULL, WM_KEYDOWN, VKEY_A, lParam_a };
440 MSG native_event_a_pressed_3000 = { NULL, WM_KEYDOWN, VKEY_A, lParam_a };
441 MSG native_event_a_released = { NULL, WM_KEYUP, VKEY_A, lParam_a };
442 MSG native_event_b_pressed = { NULL, WM_KEYUP, VKEY_B, lParam_b };
443 #endif
444 SetKeyEventTimestamp(native_event_a_pressed_1500, 1500);
445 SetKeyEventTimestamp(native_event_a_pressed_3000, 3000);
448 KeyEvent key_a1(native_event_a_pressed);
449 EXPECT_FALSE(key_a1.IsRepeat());
450 KeyEvent key_a1_released(native_event_a_released);
451 EXPECT_FALSE(key_a1_released.IsRepeat());
453 KeyEvent key_a2(native_event_a_pressed);
454 EXPECT_FALSE(key_a2.IsRepeat());
455 KeyEvent key_a2_repeated(native_event_a_pressed);
456 EXPECT_TRUE(key_a2_repeated.IsRepeat());
457 KeyEvent key_a2_released(native_event_a_released);
458 EXPECT_FALSE(key_a2_released.IsRepeat());
462 KeyEvent key_a3(native_event_a_pressed);
463 EXPECT_FALSE(key_a3.IsRepeat());
464 KeyEvent key_b(native_event_b_pressed);
465 EXPECT_FALSE(key_b.IsRepeat());
466 KeyEvent key_a3_again(native_event_a_pressed);
467 EXPECT_FALSE(key_a3_again.IsRepeat());
468 KeyEvent key_a3_repeated(native_event_a_pressed);
469 EXPECT_TRUE(key_a3_repeated.IsRepeat());
470 KeyEvent key_a3_repeated2(native_event_a_pressed);
471 EXPECT_TRUE(key_a3_repeated2.IsRepeat());
472 KeyEvent key_a3_released(native_event_a_released);
473 EXPECT_FALSE(key_a3_released.IsRepeat());
476 // Hold the key longer than max auto repeat timeout.
478 KeyEvent key_a4_0(native_event_a_pressed);
479 EXPECT_FALSE(key_a4_0.IsRepeat());
480 KeyEvent key_a4_1500(native_event_a_pressed_1500);
481 EXPECT_TRUE(key_a4_1500.IsRepeat());
482 KeyEvent key_a4_3000(native_event_a_pressed_3000);
483 EXPECT_TRUE(key_a4_3000.IsRepeat());
484 KeyEvent key_a4_released(native_event_a_released);
485 EXPECT_FALSE(key_a4_released.IsRepeat());
488 #if defined(USE_X11)
490 KeyEvent key_a4_pressed(native_event_a_pressed);
491 EXPECT_FALSE(key_a4_pressed.IsRepeat());
493 KeyEvent key_a4_pressed_nonstandard_state(
494 native_event_a_pressed_nonstandard_state);
495 EXPECT_FALSE(key_a4_pressed_nonstandard_state.IsRepeat());
497 #endif
499 #endif // USE_X11 || OS_WIN
501 } // namespace ui