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

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

Issue 345243007: Add ScopedObjCClassSwizzler in base/mac, absorbs objc_method_swizzle and ScopedClassSwizzler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase to master Created 6 years, 5 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
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 #include "ui/events/event_utils.h" 5 #include "ui/events/event_utils.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/mac/scoped_cftyperef.h" 9 #include "base/mac/scoped_cftyperef.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #import "base/test/scoped_class_swizzler_mac.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/events/event_constants.h" 13 #include "ui/events/event_constants.h"
13 #import "ui/events/test/cocoa_test_event_utils.h" 14 #import "ui/events/test/cocoa_test_event_utils.h"
14 #include "ui/gfx/point.h" 15 #include "ui/gfx/point.h"
15 #import "ui/gfx/test/ui_cocoa_test_helper.h" 16 #import "ui/gfx/test/ui_cocoa_test_helper.h"
16 17
17 namespace { 18 namespace {
18 19
19 NSWindow* g_test_window = nil; 20 NSWindow* g_test_window = nil;
20 21
(...skipping 29 matching lines...) Expand all
50 gfx::Point Flip(gfx::Point window_location) { 51 gfx::Point Flip(gfx::Point window_location) {
51 NSRect window_frame = [test_window() frame]; 52 NSRect window_frame = [test_window() frame];
52 CGFloat content_height = 53 CGFloat content_height =
53 NSHeight([test_window() contentRectForFrameRect:window_frame]); 54 NSHeight([test_window() contentRectForFrameRect:window_frame]);
54 window_location.set_y(content_height - window_location.y()); 55 window_location.set_y(content_height - window_location.y());
55 return window_location; 56 return window_location;
56 } 57 }
57 58
58 void SwizzleMiddleMouseButton() { 59 void SwizzleMiddleMouseButton() {
59 DCHECK(!swizzler_); 60 DCHECK(!swizzler_);
60 swizzler_.reset(new ScopedClassSwizzler( 61 swizzler_.reset(new base::ScopedClassSwizzler(
61 [NSEvent class], 62 [NSEvent class],
62 [MiddleMouseButtonNumberDonor class], 63 [MiddleMouseButtonNumberDonor class],
63 @selector(buttonNumber))); 64 @selector(buttonNumber)));
64 } 65 }
65 66
66 void SwizzleTestWindow() { 67 void SwizzleTestWindow() {
67 DCHECK(!g_test_window); 68 DCHECK(!g_test_window);
68 DCHECK(!swizzler_); 69 DCHECK(!swizzler_);
69 g_test_window = test_window(); 70 g_test_window = test_window();
70 swizzler_.reset(new ScopedClassSwizzler( 71 swizzler_.reset(new base::ScopedClassSwizzler(
71 [NSEvent class], 72 [NSEvent class],
72 [TestWindowDonor class], 73 [TestWindowDonor class],
73 @selector(window))); 74 @selector(window)));
74 } 75 }
75 76
76 void ClearSwizzle() { 77 void ClearSwizzle() {
77 swizzler_.reset(); 78 swizzler_.reset();
78 g_test_window = nil; 79 g_test_window = nil;
79 } 80 }
80 81
(...skipping 29 matching lines...) Expand all
110 NSPointFromCGPoint(Flip(window_location).ToCGPoint()); 111 NSPointFromCGPoint(Flip(window_location).ToCGPoint());
111 NSPoint screen_point = [test_window() convertBaseToScreen:window_point]; 112 NSPoint screen_point = [test_window() convertBaseToScreen:window_point];
112 CGFloat primary_screen_height = 113 CGFloat primary_screen_height =
113 NSHeight([[[NSScreen screens] objectAtIndex:0] frame]); 114 NSHeight([[[NSScreen screens] objectAtIndex:0] frame]);
114 screen_point.y = primary_screen_height - screen_point.y; 115 screen_point.y = primary_screen_height - screen_point.y;
115 CGEventSetLocation(scroll, NSPointToCGPoint(screen_point)); 116 CGEventSetLocation(scroll, NSPointToCGPoint(screen_point));
116 return [NSEvent eventWithCGEvent:scroll]; 117 return [NSEvent eventWithCGEvent:scroll];
117 } 118 }
118 119
119 private: 120 private:
120 scoped_ptr<ScopedClassSwizzler> swizzler_; 121 scoped_ptr<base::ScopedClassSwizzler> swizzler_;
121 122
122 DISALLOW_COPY_AND_ASSIGN(EventsMacTest); 123 DISALLOW_COPY_AND_ASSIGN(EventsMacTest);
123 }; 124 };
124 125
125 } // namespace 126 } // namespace
126 127
127 TEST_F(EventsMacTest, EventFlagsFromNative) { 128 TEST_F(EventsMacTest, EventFlagsFromNative) {
128 // Left click. 129 // Left click.
129 NSEvent* left = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 0); 130 NSEvent* left = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 0);
130 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, EventFlagsFromNative(left)); 131 EXPECT_EQ(EF_LEFT_MOUSE_BUTTON, EventFlagsFromNative(left));
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 event = cocoa_test_event_utils::MouseEventWithType(NSMouseMoved, 0); 307 event = cocoa_test_event_utils::MouseEventWithType(NSMouseMoved, 0);
307 EXPECT_EQ(ui::ET_MOUSE_MOVED, ui::EventTypeFromNative(event)); 308 EXPECT_EQ(ui::ET_MOUSE_MOVED, ui::EventTypeFromNative(event));
308 309
309 event = cocoa_test_event_utils::EnterExitEventWithType(NSMouseEntered); 310 event = cocoa_test_event_utils::EnterExitEventWithType(NSMouseEntered);
310 EXPECT_EQ(ui::ET_MOUSE_ENTERED, ui::EventTypeFromNative(event)); 311 EXPECT_EQ(ui::ET_MOUSE_ENTERED, ui::EventTypeFromNative(event));
311 event = cocoa_test_event_utils::EnterExitEventWithType(NSMouseExited); 312 event = cocoa_test_event_utils::EnterExitEventWithType(NSMouseExited);
312 EXPECT_EQ(ui::ET_MOUSE_EXITED, ui::EventTypeFromNative(event)); 313 EXPECT_EQ(ui::ET_MOUSE_EXITED, ui::EventTypeFromNative(event));
313 } 314 }
314 315
315 } // namespace ui 316 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698