| OLD | NEW |
| 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/test/scoped_class_swizzler_mac.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 Loading... |
| 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::ScopedClassSwizzler swizzler([NSEvent class], [TestEvent class], |
| 43 @selector(modifierFlags)); | 44 @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 |
| OLD | NEW |