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

Side by Side Diff: ui/base/cocoa/cocoa_base_utils_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: Inlude in shiny new gn base_unittests target Created 6 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
« no previous file with comments | « chrome/common/mac/objc_zombie.mm ('k') | ui/events/cocoa/events_mac_unittest.mm » ('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 #include "ui/base/cocoa/cocoa_base_utils.h" 5 #include "ui/base/cocoa/cocoa_base_utils.h"
6 6
7 #import <objc/objc-class.h> 7 #import <objc/objc-class.h>
8 8
9 #import "base/mac/scoped_objc_class_swizzler.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/platform_test.h" 11 #include "testing/platform_test.h"
11 #include "ui/events/event_constants.h" 12 #include "ui/events/event_constants.h"
12 #import "ui/events/test/cocoa_test_event_utils.h" 13 #import "ui/events/test/cocoa_test_event_utils.h"
13 #import "ui/gfx/test/ui_cocoa_test_helper.h" 14 #import "ui/gfx/test/ui_cocoa_test_helper.h"
14 15
15 // We provide a donor class with a specially modified |modifierFlags| 16 // We provide a donor class with a specially modified |modifierFlags|
16 // implementation that we swap with NSEvent's. This is because we can't create a 17 // implementation that we swap with NSEvent's. This is because we can't create a
17 // NSEvent that represents a middle click with modifiers. 18 // NSEvent that represents a middle click with modifiers.
18 @interface TestEvent : NSObject 19 @interface TestEvent : NSObject
(...skipping 13 matching lines...) Expand all
32 // Left Click = same tab. 33 // Left Click = same tab.
33 NSEvent* me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 0); 34 NSEvent* me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 0);
34 EXPECT_EQ(CURRENT_TAB, WindowOpenDispositionFromNSEvent(me)); 35 EXPECT_EQ(CURRENT_TAB, WindowOpenDispositionFromNSEvent(me));
35 36
36 // Middle Click = new background tab. 37 // Middle Click = new background tab.
37 me = cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0); 38 me = cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0);
38 EXPECT_EQ(NEW_BACKGROUND_TAB, WindowOpenDispositionFromNSEvent(me)); 39 EXPECT_EQ(NEW_BACKGROUND_TAB, WindowOpenDispositionFromNSEvent(me));
39 40
40 // Shift+Middle Click = new foreground tab. 41 // Shift+Middle Click = new foreground tab.
41 { 42 {
42 ScopedClassSwizzler swizzler([NSEvent class], [TestEvent class], 43 base::mac::ScopedObjCClassSwizzler swizzler(
43 @selector(modifierFlags)); 44 [NSEvent class], [TestEvent class], @selector(modifierFlags));
44 me = cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 45 me = cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp,
45 NSShiftKeyMask); 46 NSShiftKeyMask);
46 EXPECT_EQ(NEW_FOREGROUND_TAB, WindowOpenDispositionFromNSEvent(me)); 47 EXPECT_EQ(NEW_FOREGROUND_TAB, WindowOpenDispositionFromNSEvent(me));
47 } 48 }
48 49
49 // Cmd+Left Click = new background tab. 50 // Cmd+Left Click = new background tab.
50 me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 51 me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp,
51 NSCommandKeyMask); 52 NSCommandKeyMask);
52 EXPECT_EQ(NEW_BACKGROUND_TAB, WindowOpenDispositionFromNSEvent(me)); 53 EXPECT_EQ(NEW_BACKGROUND_TAB, WindowOpenDispositionFromNSEvent(me));
53 54
54 // Cmd+Shift+Left Click = new foreground tab. 55 // Cmd+Shift+Left Click = new foreground tab.
55 me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 56 me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp,
56 NSCommandKeyMask | 57 NSCommandKeyMask |
57 NSShiftKeyMask); 58 NSShiftKeyMask);
58 EXPECT_EQ(NEW_FOREGROUND_TAB, WindowOpenDispositionFromNSEvent(me)); 59 EXPECT_EQ(NEW_FOREGROUND_TAB, WindowOpenDispositionFromNSEvent(me));
59 60
60 // Shift+Left Click = new window 61 // Shift+Left Click = new window
61 me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 62 me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp,
62 NSShiftKeyMask); 63 NSShiftKeyMask);
63 EXPECT_EQ(NEW_WINDOW, WindowOpenDispositionFromNSEvent(me)); 64 EXPECT_EQ(NEW_WINDOW, WindowOpenDispositionFromNSEvent(me));
64 } 65 }
65 66
66 } // namespace 67 } // namespace
67 68
68 } // namespace ui 69 } // namespace ui
OLDNEW
« no previous file with comments | « chrome/common/mac/objc_zombie.mm ('k') | ui/events/cocoa/events_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698