• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3// found in the LICENSE file.
4
5#include "ui/base/cocoa/cocoa_base_utils.h"
6
7#import <objc/objc-class.h>
8
9#include "testing/gtest/include/gtest/gtest.h"
10#include "testing/platform_test.h"
11#include "ui/events/event_constants.h"
12#import "ui/events/test/cocoa_test_event_utils.h"
13#import "ui/gfx/test/ui_cocoa_test_helper.h"
14
15// 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// NSEvent that represents a middle click with modifiers.
18@interface TestEvent : NSObject
19@end
20@implementation TestEvent
21- (NSUInteger)modifierFlags { return NSShiftKeyMask; }
22@end
23
24namespace ui {
25
26namespace {
27
28class CocoaBaseUtilsTest : public CocoaTest {
29};
30
31TEST_F(CocoaBaseUtilsTest, WindowOpenDispositionFromNSEvent) {
32  // Left Click = same tab.
33  NSEvent* me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp, 0);
34  EXPECT_EQ(CURRENT_TAB, WindowOpenDispositionFromNSEvent(me));
35
36  // Middle Click = new background tab.
37  me = cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp, 0);
38  EXPECT_EQ(NEW_BACKGROUND_TAB, WindowOpenDispositionFromNSEvent(me));
39
40  // Shift+Middle Click = new foreground tab.
41  {
42    ScopedClassSwizzler swizzler([NSEvent class], [TestEvent class],
43                                 @selector(modifierFlags));
44    me = cocoa_test_event_utils::MouseEventWithType(NSOtherMouseUp,
45                                                    NSShiftKeyMask);
46    EXPECT_EQ(NEW_FOREGROUND_TAB, WindowOpenDispositionFromNSEvent(me));
47  }
48
49  // Cmd+Left Click = new background tab.
50  me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp,
51                                                  NSCommandKeyMask);
52  EXPECT_EQ(NEW_BACKGROUND_TAB, WindowOpenDispositionFromNSEvent(me));
53
54  // Cmd+Shift+Left Click = new foreground tab.
55  me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp,
56                                              NSCommandKeyMask |
57                                              NSShiftKeyMask);
58  EXPECT_EQ(NEW_FOREGROUND_TAB, WindowOpenDispositionFromNSEvent(me));
59
60  // Shift+Left Click = new window
61  me = cocoa_test_event_utils::MouseEventWithType(NSLeftMouseUp,
62                                                  NSShiftKeyMask);
63  EXPECT_EQ(NEW_WINDOW, WindowOpenDispositionFromNSEvent(me));
64}
65
66}  // namespace
67
68}  // namespace ui
69