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

Side by Side Diff: content/browser/renderer_host/input/web_input_event_builders_gtk_unittest.cc

Issue 19776016: Add files. Does not compile yet! (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: builders Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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.
4
5 #include "content/browser/renderer_host/input/web_input_event_builders_gtk.h"
6
7 #include <gdk/gdk.h>
8 #include <gdk/gdkkeysyms.h>
9
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/WebKit/public/web/WebInputEvent.h"
12
13 using WebKit::WebInputEvent;
14 using WebKit::WebKeyboardEvent;
15 using WebKit::WebMouseEvent;
16 using content::WebMouseEventBuilder;
17 using content::WebKeyboardEventBuilder;
18
19 namespace {
20
21 TEST(WebMouseEventBuilderTest, DoubleClick) {
22 GdkEventButton first_click;
23 first_click.type = GDK_BUTTON_PRESS;
24 first_click.window = static_cast<GdkWindow*>(GINT_TO_POINTER(1));
25 first_click.x = first_click.y = first_click.x_root = first_click.y_root = 100;
26 first_click.state = 0;
27 first_click.time = 0;
28 first_click.button = 1;
29
30 // Single click works.
31 WebMouseEvent first_click_events =
32 WebMouseEventBuilder::Build(&first_click);
33 EXPECT_EQ(1, first_click_events.clickCount);
34
35 // Make sure double click works.
36 GdkEventButton second_click = first_click;
37 second_click.time = first_click.time + 100;
38 WebMouseEvent second_click_events =
39 WebMouseEventBuilder::Build(&second_click);
40 EXPECT_EQ(2, second_click_events.clickCount);
41
42 // Reset the click count.
43 first_click.time += 10000;
44 first_click_events = WebMouseEventBuilder::Build(&first_click);
45 EXPECT_EQ(1, first_click_events.clickCount);
46
47 // Two clicks with a long gap in between aren't counted as a double click.
48 second_click = first_click;
49 second_click.time = first_click.time + 1000;
50 second_click_events = WebMouseEventBuilder::Build(&second_click);
51 EXPECT_EQ(1, second_click_events.clickCount);
52
53 // Reset the click count.
54 first_click.time += 10000;
55 first_click_events = WebMouseEventBuilder::Build(&first_click);
56 EXPECT_EQ(1, first_click_events.clickCount);
57
58 // Two clicks far apart (horizontally) aren't counted as a double click.
59 second_click = first_click;
60 second_click.time = first_click.time + 1;
61 second_click.x = first_click.x + 100;
62 second_click_events = WebMouseEventBuilder::Build(&second_click);
63 EXPECT_EQ(1, second_click_events.clickCount);
64
65 // Reset the click count.
66 first_click.time += 10000;
67 first_click_events = WebMouseEventBuilder::Build(&first_click);
68 EXPECT_EQ(1, first_click_events.clickCount);
69
70 // Two clicks far apart (vertically) aren't counted as a double click.
71 second_click = first_click;
72 second_click.time = first_click.time + 1;
73 second_click.x = first_click.y + 100;
74 second_click_events = WebMouseEventBuilder::Build(&second_click);
75 EXPECT_EQ(1, second_click_events.clickCount);
76
77 // Reset the click count.
78 first_click.time += 10000;
79 first_click_events = WebMouseEventBuilder::Build(&first_click);
80 EXPECT_EQ(1, first_click_events.clickCount);
81
82 // Two clicks on different windows aren't a double click.
83 second_click = first_click;
84 second_click.time = first_click.time + 1;
85 second_click.window = static_cast<GdkWindow*>(GINT_TO_POINTER(2));
86 second_click_events = WebMouseEventBuilder::Build(&second_click);
87 EXPECT_EQ(1, second_click_events.clickCount);
88 }
89
90 TEST(WebMouseEventBuilderTest, MouseUpClickCount) {
91 GdkEventButton mouse_down;
92 memset(&mouse_down, 0, sizeof(mouse_down));
93 mouse_down.type = GDK_BUTTON_PRESS;
94 mouse_down.window = static_cast<GdkWindow*>(GINT_TO_POINTER(1));
95 mouse_down.x = mouse_down.y = mouse_down.x_root = mouse_down.y_root = 100;
96 mouse_down.time = 0;
97 mouse_down.button = 1;
98
99 // Properly set the last click time, so that the internal state won't be
100 // affected by previous tests.
101 WebMouseEventBuilder::Build(&mouse_down);
102
103 mouse_down.time += 10000;
104 GdkEventButton mouse_up = mouse_down;
105 mouse_up.type = GDK_BUTTON_RELEASE;
106 WebMouseEvent mouse_down_event;
107 WebMouseEvent mouse_up_event;
108
109 // Click for three times.
110 for (int i = 1; i < 4; ++i) {
111 mouse_down.time += 100;
112 mouse_down_event = WebMouseEventBuilder::Build(&mouse_down);
113 EXPECT_EQ(i, mouse_down_event.clickCount);
114
115 mouse_up.time = mouse_down.time + 50;
116 mouse_up_event = WebMouseEventBuilder::Build(&mouse_up);
117 EXPECT_EQ(i, mouse_up_event.clickCount);
118 }
119
120 // Reset the click count.
121 mouse_down.time += 10000;
122 mouse_down_event = WebMouseEventBuilder::Build(&mouse_down);
123 EXPECT_EQ(1, mouse_down_event.clickCount);
124
125 // Moving the cursor for a significant distance will reset the click count to
126 // 0.
127 GdkEventMotion mouse_move;
128 memset(&mouse_move, 0, sizeof(mouse_move));
129 mouse_move.type = GDK_MOTION_NOTIFY;
130 mouse_move.window = mouse_down.window;
131 mouse_move.time = mouse_down.time;
132 mouse_move.x = mouse_move.y = mouse_move.x_root = mouse_move.y_root =
133 mouse_down.x + 100;
134 WebMouseEventBuilder::Build(&mouse_move);
135
136 mouse_up.time = mouse_down.time + 50;
137 mouse_up_event = WebMouseEventBuilder::Build(&mouse_up);
138 EXPECT_EQ(0, mouse_up_event.clickCount);
139
140 // Reset the click count.
141 mouse_down.time += 10000;
142 mouse_down_event = WebMouseEventBuilder::Build(&mouse_down);
143 EXPECT_EQ(1, mouse_down_event.clickCount);
144
145 // Moving the cursor with a significant delay will reset the click count to 0.
146 mouse_move.time = mouse_down.time + 1000;
147 mouse_move.x = mouse_move.y = mouse_move.x_root = mouse_move.y_root =
148 mouse_down.x;
149 WebMouseEventBuilder::Build(&mouse_move);
150
151 mouse_up.time = mouse_move.time + 50;
152 mouse_up_event = WebMouseEventBuilder::Build(&mouse_up);
153 EXPECT_EQ(0, mouse_up_event.clickCount);
154 }
155
156 TEST(WebKeyboardEventBuilderTest, NumPadConversion) {
157 // Construct a GDK input event for the numpad "5" key.
158 char five[] = "5";
159 GdkEventKey gdk_event;
160 memset(&gdk_event, 0, sizeof(GdkEventKey));
161 gdk_event.type = GDK_KEY_PRESS;
162 gdk_event.keyval = GDK_KP_5;
163 gdk_event.string = five;
164
165 // Numpad flag should be set on the WebKeyboardEvent.
166 WebKeyboardEvent web_event = WebKeyboardEventBuilder::Build(&gdk_event);
167 EXPECT_TRUE(web_event.modifiers & WebInputEvent::IsKeyPad);
168 }
169
170 } // anonymous namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698