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

Side by Side Diff: ui/events/cocoa/events_mac_unittest.mm

Issue 2654653002: Handle floating point coordinates from ozone to exosphere (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « ui/events/cocoa/events_mac.mm ('k') | ui/events/event.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import <Carbon/Carbon.h> 5 #import <Carbon/Carbon.h>
6 #import <Cocoa/Cocoa.h> 6 #import <Cocoa/Cocoa.h>
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // Tests mouse button presses and mouse wheel events. 209 // Tests mouse button presses and mouse wheel events.
210 TEST_F(EventsMacTest, ButtonEvents) { 210 TEST_F(EventsMacTest, ButtonEvents) {
211 gfx::Point location(5, 10); 211 gfx::Point location(5, 10);
212 gfx::Vector2d offset; 212 gfx::Vector2d offset;
213 213
214 NSEvent* event = 214 NSEvent* event =
215 TestMouseEvent(kCGEventLeftMouseDown, location, kNoEventFlags); 215 TestMouseEvent(kCGEventLeftMouseDown, location, kNoEventFlags);
216 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(event)); 216 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(event));
217 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, ui::EventFlagsFromNative(event)); 217 EXPECT_EQ(ui::EF_LEFT_MOUSE_BUTTON, ui::EventFlagsFromNative(event));
218 EXPECT_EQ(location, ui::EventLocationFromNative(event)); 218 EXPECT_EQ(location, ui::EventLocationFromNative(event));
219 EXPECT_EQ(ui::EventLocationFromNative(event),
220 gfx::ToFlooredPoint(ui::EventLocationFromNativeF(event)));
219 221
220 event = 222 event =
221 TestMouseEvent(kCGEventOtherMouseDown, location, kCGEventFlagMaskShift); 223 TestMouseEvent(kCGEventOtherMouseDown, location, kCGEventFlagMaskShift);
222 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(event)); 224 EXPECT_EQ(ui::ET_MOUSE_PRESSED, ui::EventTypeFromNative(event));
223 EXPECT_EQ(ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_SHIFT_DOWN, 225 EXPECT_EQ(ui::EF_MIDDLE_MOUSE_BUTTON | ui::EF_SHIFT_DOWN,
224 ui::EventFlagsFromNative(event)); 226 ui::EventFlagsFromNative(event));
225 EXPECT_EQ(location, ui::EventLocationFromNative(event)); 227 EXPECT_EQ(location, ui::EventLocationFromNative(event));
228 EXPECT_EQ(ui::EventLocationFromNative(event),
229 gfx::ToFlooredPoint(ui::EventLocationFromNativeF(event)));
226 230
227 event = TestMouseEvent(kCGEventRightMouseUp, location, kNoEventFlags); 231 event = TestMouseEvent(kCGEventRightMouseUp, location, kNoEventFlags);
228 EXPECT_EQ(ui::ET_MOUSE_RELEASED, ui::EventTypeFromNative(event)); 232 EXPECT_EQ(ui::ET_MOUSE_RELEASED, ui::EventTypeFromNative(event));
229 EXPECT_EQ(ui::EF_RIGHT_MOUSE_BUTTON, ui::EventFlagsFromNative(event)); 233 EXPECT_EQ(ui::EF_RIGHT_MOUSE_BUTTON, ui::EventFlagsFromNative(event));
230 EXPECT_EQ(location, ui::EventLocationFromNative(event)); 234 EXPECT_EQ(location, ui::EventLocationFromNative(event));
235 EXPECT_EQ(ui::EventLocationFromNative(event),
236 gfx::ToFlooredPoint(ui::EventLocationFromNativeF(event)));
231 237
232 // Scroll up. 238 // Scroll up.
233 event = TestScrollEvent(location, 0, 1); 239 event = TestScrollEvent(location, 0, 1);
234 EXPECT_EQ(ui::ET_SCROLL, ui::EventTypeFromNative(event)); 240 EXPECT_EQ(ui::ET_SCROLL, ui::EventTypeFromNative(event));
235 EXPECT_EQ(0, ui::EventFlagsFromNative(event)); 241 EXPECT_EQ(0, ui::EventFlagsFromNative(event));
236 EXPECT_EQ(location.ToString(), ui::EventLocationFromNative(event).ToString()); 242 EXPECT_EQ(location.ToString(), ui::EventLocationFromNative(event).ToString());
243 EXPECT_EQ(ui::EventLocationFromNative(event),
244 gfx::ToFlooredPoint(ui::EventLocationFromNativeF(event)));
237 offset = ui::GetMouseWheelOffset(event); 245 offset = ui::GetMouseWheelOffset(event);
238 EXPECT_GT(offset.y(), 0); 246 EXPECT_GT(offset.y(), 0);
239 EXPECT_EQ(0, offset.x()); 247 EXPECT_EQ(0, offset.x());
240 248
241 // Scroll down. 249 // Scroll down.
242 event = TestScrollEvent(location, 0, -1); 250 event = TestScrollEvent(location, 0, -1);
243 EXPECT_EQ(ui::ET_SCROLL, ui::EventTypeFromNative(event)); 251 EXPECT_EQ(ui::ET_SCROLL, ui::EventTypeFromNative(event));
244 EXPECT_EQ(0, ui::EventFlagsFromNative(event)); 252 EXPECT_EQ(0, ui::EventFlagsFromNative(event));
245 EXPECT_EQ(location, ui::EventLocationFromNative(event)); 253 EXPECT_EQ(location, ui::EventLocationFromNative(event));
254 EXPECT_EQ(ui::EventLocationFromNative(event),
255 gfx::ToFlooredPoint(ui::EventLocationFromNativeF(event)));
246 offset = ui::GetMouseWheelOffset(event); 256 offset = ui::GetMouseWheelOffset(event);
247 EXPECT_LT(offset.y(), 0); 257 EXPECT_LT(offset.y(), 0);
248 EXPECT_EQ(0, offset.x()); 258 EXPECT_EQ(0, offset.x());
249 259
250 // Scroll left. 260 // Scroll left.
251 event = TestScrollEvent(location, 1, 0); 261 event = TestScrollEvent(location, 1, 0);
252 EXPECT_EQ(ui::ET_SCROLL, ui::EventTypeFromNative(event)); 262 EXPECT_EQ(ui::ET_SCROLL, ui::EventTypeFromNative(event));
253 EXPECT_EQ(0, ui::EventFlagsFromNative(event)); 263 EXPECT_EQ(0, ui::EventFlagsFromNative(event));
254 EXPECT_EQ(location, ui::EventLocationFromNative(event)); 264 EXPECT_EQ(location, ui::EventLocationFromNative(event));
265 EXPECT_EQ(ui::EventLocationFromNative(event),
266 gfx::ToFlooredPoint(ui::EventLocationFromNativeF(event)));
255 offset = ui::GetMouseWheelOffset(event); 267 offset = ui::GetMouseWheelOffset(event);
256 EXPECT_EQ(0, offset.y()); 268 EXPECT_EQ(0, offset.y());
257 EXPECT_GT(offset.x(), 0); 269 EXPECT_GT(offset.x(), 0);
258 270
259 // Scroll right. 271 // Scroll right.
260 event = TestScrollEvent(location, -1, 0); 272 event = TestScrollEvent(location, -1, 0);
261 EXPECT_EQ(ui::ET_SCROLL, ui::EventTypeFromNative(event)); 273 EXPECT_EQ(ui::ET_SCROLL, ui::EventTypeFromNative(event));
262 EXPECT_EQ(0, ui::EventFlagsFromNative(event)); 274 EXPECT_EQ(0, ui::EventFlagsFromNative(event));
263 EXPECT_EQ(location, ui::EventLocationFromNative(event)); 275 EXPECT_EQ(location, ui::EventLocationFromNative(event));
276 EXPECT_EQ(ui::EventLocationFromNative(event),
277 gfx::ToFlooredPoint(ui::EventLocationFromNativeF(event)));
264 offset = ui::GetMouseWheelOffset(event); 278 offset = ui::GetMouseWheelOffset(event);
265 EXPECT_EQ(0, offset.y()); 279 EXPECT_EQ(0, offset.y());
266 EXPECT_LT(offset.x(), 0); 280 EXPECT_LT(offset.x(), 0);
267 } 281 }
268 282
269 // Test correct location when the window has a native titlebar. 283 // Test correct location when the window has a native titlebar.
270 TEST_F(EventsMacTest, NativeTitlebarEventLocation) { 284 TEST_F(EventsMacTest, NativeTitlebarEventLocation) {
271 gfx::Point location(5, 10); 285 gfx::Point location(5, 10);
272 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | 286 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask |
273 NSMiniaturizableWindowMask | NSResizableWindowMask; 287 NSMiniaturizableWindowMask | NSResizableWindowMask;
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 NSEvent* native_event = cocoa_test_event_utils::KeyEventWithModifierOnly( 547 NSEvent* native_event = cocoa_test_event_utils::KeyEventWithModifierOnly(
534 test_case.key_code, test_case.modifier_flags); 548 test_case.key_code, test_case.modifier_flags);
535 std::unique_ptr<ui::Event> event = EventFromNative(native_event); 549 std::unique_ptr<ui::Event> event = EventFromNative(native_event);
536 EXPECT_TRUE(event); 550 EXPECT_TRUE(event);
537 EXPECT_EQ(test_case.expected_type, event->type()); 551 EXPECT_EQ(test_case.expected_type, event->type());
538 EXPECT_EQ(test_case.expected_key_code, event->AsKeyEvent()->key_code()); 552 EXPECT_EQ(test_case.expected_key_code, event->AsKeyEvent()->key_code());
539 } 553 }
540 } 554 }
541 555
542 } // namespace ui 556 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/cocoa/events_mac.mm ('k') | ui/events/event.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698