| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "ui/events/event.h" | 7 #include "ui/events/event.h" |
| 8 #include "ui/events/event_utils.h" | 8 #include "ui/events/event_utils.h" |
| 9 #include "ui/events/keycodes/dom4/keycode_converter.h" | 9 #include "ui/events/keycodes/dom4/keycode_converter.h" |
| 10 #include "ui/events/test/events_test_utils.h" | 10 #include "ui/events/test/events_test_utils.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 EXPECT_FALSE(MouseEvent::IsRepeatedClickEvent(mouse_ev1, mouse_ev2)); | 91 EXPECT_FALSE(MouseEvent::IsRepeatedClickEvent(mouse_ev1, mouse_ev2)); |
| 92 | 92 |
| 93 // Too long a time between clicks. | 93 // Too long a time between clicks. |
| 94 test_ev1.set_location(gfx::Point(0, 0)); | 94 test_ev1.set_location(gfx::Point(0, 0)); |
| 95 test_ev2.set_location(gfx::Point(0, 0)); | 95 test_ev2.set_location(gfx::Point(0, 0)); |
| 96 test_ev1.set_time_stamp(start); | 96 test_ev1.set_time_stamp(start); |
| 97 test_ev2.set_time_stamp(later); | 97 test_ev2.set_time_stamp(later); |
| 98 EXPECT_FALSE(MouseEvent::IsRepeatedClickEvent(mouse_ev1, mouse_ev2)); | 98 EXPECT_FALSE(MouseEvent::IsRepeatedClickEvent(mouse_ev1, mouse_ev2)); |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Tests that an event only increases the click count and gets marked as a |
| 102 // double click if a release event was seen for the previous click. This |
| 103 // prevents the same PRESSED event from being processed twice: |
| 104 // http://crbug.com/389162 |
| 105 TEST(EventTest, DoubleClickRequiresRelease) { |
| 106 const gfx::Point origin1(0, 0); |
| 107 const gfx::Point origin2(100, 0); |
| 108 scoped_ptr<MouseEvent> ev; |
| 109 base::TimeDelta start = base::TimeDelta::FromMilliseconds(0); |
| 110 |
| 111 ev.reset(new MouseEvent(ET_MOUSE_PRESSED, origin1, origin1, 0, 0)); |
| 112 ev->set_time_stamp(start); |
| 113 EXPECT_EQ(1, MouseEvent::GetRepeatCount(*ev)); |
| 114 ev.reset(new MouseEvent(ET_MOUSE_PRESSED, origin1, origin1, 0, 0)); |
| 115 ev->set_time_stamp(start); |
| 116 EXPECT_EQ(1, MouseEvent::GetRepeatCount(*ev)); |
| 117 |
| 118 ev.reset(new MouseEvent(ET_MOUSE_PRESSED, origin2, origin2, 0, 0)); |
| 119 ev->set_time_stamp(start); |
| 120 EXPECT_EQ(1, MouseEvent::GetRepeatCount(*ev)); |
| 121 ev.reset(new MouseEvent(ET_MOUSE_RELEASED, origin2, origin2, 0, 0)); |
| 122 ev->set_time_stamp(start); |
| 123 EXPECT_EQ(1, MouseEvent::GetRepeatCount(*ev)); |
| 124 ev.reset(new MouseEvent(ET_MOUSE_PRESSED, origin2, origin2, 0, 0)); |
| 125 ev->set_time_stamp(start); |
| 126 EXPECT_EQ(2, MouseEvent::GetRepeatCount(*ev)); |
| 127 ev.reset(new MouseEvent(ET_MOUSE_RELEASED, origin2, origin2, 0, 0)); |
| 128 ev->set_time_stamp(start); |
| 129 EXPECT_EQ(2, MouseEvent::GetRepeatCount(*ev)); |
| 130 MouseEvent::ResetLastClickForTest(); |
| 131 } |
| 132 |
| 133 // Tests that clicking right and then left clicking does not generate a double |
| 134 // click. |
| 135 TEST(EventTest, SingleClickRightLeft) { |
| 136 const gfx::Point origin(0, 0); |
| 137 scoped_ptr<MouseEvent> ev; |
| 138 base::TimeDelta start = base::TimeDelta::FromMilliseconds(0); |
| 139 |
| 140 ev.reset(new MouseEvent(ET_MOUSE_PRESSED, origin, origin, |
| 141 ui::EF_RIGHT_MOUSE_BUTTON, |
| 142 ui::EF_RIGHT_MOUSE_BUTTON)); |
| 143 ev->set_time_stamp(start); |
| 144 EXPECT_EQ(1, MouseEvent::GetRepeatCount(*ev)); |
| 145 ev.reset(new MouseEvent(ET_MOUSE_PRESSED, origin, origin, |
| 146 ui::EF_LEFT_MOUSE_BUTTON, |
| 147 ui::EF_LEFT_MOUSE_BUTTON)); |
| 148 ev->set_time_stamp(start); |
| 149 EXPECT_EQ(1, MouseEvent::GetRepeatCount(*ev)); |
| 150 ev.reset(new MouseEvent(ET_MOUSE_RELEASED, origin, origin, |
| 151 ui::EF_LEFT_MOUSE_BUTTON, |
| 152 ui::EF_LEFT_MOUSE_BUTTON)); |
| 153 ev->set_time_stamp(start); |
| 154 EXPECT_EQ(1, MouseEvent::GetRepeatCount(*ev)); |
| 155 ev.reset(new MouseEvent(ET_MOUSE_PRESSED, origin, origin, |
| 156 ui::EF_LEFT_MOUSE_BUTTON, |
| 157 ui::EF_LEFT_MOUSE_BUTTON)); |
| 158 ev->set_time_stamp(start); |
| 159 EXPECT_EQ(2, MouseEvent::GetRepeatCount(*ev)); |
| 160 MouseEvent::ResetLastClickForTest(); |
| 161 } |
| 162 |
| 101 TEST(EventTest, KeyEvent) { | 163 TEST(EventTest, KeyEvent) { |
| 102 static const struct { | 164 static const struct { |
| 103 KeyboardCode key_code; | 165 KeyboardCode key_code; |
| 104 int flags; | 166 int flags; |
| 105 uint16 character; | 167 uint16 character; |
| 106 } kTestData[] = { | 168 } kTestData[] = { |
| 107 { VKEY_A, 0, 'a' }, | 169 { VKEY_A, 0, 'a' }, |
| 108 { VKEY_A, EF_SHIFT_DOWN, 'A' }, | 170 { VKEY_A, EF_SHIFT_DOWN, 'A' }, |
| 109 { VKEY_A, EF_CAPS_LOCK_DOWN, 'A' }, | 171 { VKEY_A, EF_CAPS_LOCK_DOWN, 'A' }, |
| 110 { VKEY_A, EF_SHIFT_DOWN | EF_CAPS_LOCK_DOWN, 'a' }, | 172 { VKEY_A, EF_SHIFT_DOWN | EF_CAPS_LOCK_DOWN, 'a' }, |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 EXPECT_FALSE(key_a4_pressed.IsRepeat()); | 449 EXPECT_FALSE(key_a4_pressed.IsRepeat()); |
| 388 | 450 |
| 389 KeyEvent key_a4_pressed_nonstandard_state( | 451 KeyEvent key_a4_pressed_nonstandard_state( |
| 390 native_event_a_pressed_nonstandard_state, false); | 452 native_event_a_pressed_nonstandard_state, false); |
| 391 EXPECT_FALSE(key_a4_pressed_nonstandard_state.IsRepeat()); | 453 EXPECT_FALSE(key_a4_pressed_nonstandard_state.IsRepeat()); |
| 392 #endif | 454 #endif |
| 393 } | 455 } |
| 394 #endif // USE_X11 || OS_WIN | 456 #endif // USE_X11 || OS_WIN |
| 395 | 457 |
| 396 } // namespace ui | 458 } // namespace ui |
| OLD | NEW |