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

Side by Side Diff: chrome/browser/cocoa/event_utils_unittest.mm

Issue 173044: This changelist represents the necessary merger of two others:... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 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
OLDNEW
(Empty)
1 // Copyright (c) 2009 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 #import <objc/objc-class.h>
6
7 #import "chrome/browser/cocoa/cocoa_test_helper.h"
8 #include "chrome/browser/cocoa/event_utils.h"
9 #include "chrome/browser/cocoa/test_event_utils.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 // We provide a donor class with a specially modified |modifierFlags|
13 // implementation that we swap with NSEvent's. This is because we can't create a
14 // NSEvent that represents a middle click with modifiers.
15 @interface TestEvent : NSObject
16 @end
17 @implementation TestEvent
18 - (NSUInteger)modifierFlags { return NSShiftKeyMask; }
19 @end
20
21 namespace {
22
23 class EventUtilsTest : public testing::Test {
24 private:
25 CocoaTestHelper cocoa_helper_; // Inits Cocoa, creates window, etc...
26 };
27
28 TEST_F(EventUtilsTest, TestWindowOpenDispositionFromNSEvent) {
29 // Left Click = same tab.
30 NSEvent* me = test_event_utils::MakeMouseEvent(NSLeftMouseUp, 0);
31 EXPECT_EQ(CURRENT_TAB, event_utils::WindowOpenDispositionFromNSEvent(me));
32
33 // Middle Click = new background tab.
34 me = test_event_utils::MakeMouseEvent(NSOtherMouseUp, 0);
35 EXPECT_EQ(NEW_BACKGROUND_TAB,
36 event_utils::WindowOpenDispositionFromNSEvent(me));
37
38 // Shift+Middle Click = new foreground tab.
39 {
40 ScopedClassSwizzler swizzler([NSEvent class], [TestEvent class],
41 @selector(modifierFlags));
42 me = test_event_utils::MakeMouseEvent(NSOtherMouseUp, NSShiftKeyMask);
43 EXPECT_EQ(NEW_FOREGROUND_TAB,
44 event_utils::WindowOpenDispositionFromNSEvent(me));
45 }
46
47 // Cmd+Left Click = new background tab.
48 me = test_event_utils::MakeMouseEvent(NSLeftMouseUp, NSCommandKeyMask);
49 EXPECT_EQ(NEW_BACKGROUND_TAB,
50 event_utils::WindowOpenDispositionFromNSEvent(me));
51
52 // Cmd+Shift+Left Click = new foreground tab.
53 me = test_event_utils::MakeMouseEvent(NSLeftMouseUp, NSCommandKeyMask | NSShif tKeyMask);
54 EXPECT_EQ(NEW_FOREGROUND_TAB,
55 event_utils::WindowOpenDispositionFromNSEvent(me));
56
57 // Shift+Left Click = new window
58 me = test_event_utils::MakeMouseEvent(NSLeftMouseUp, NSShiftKeyMask);
59 EXPECT_EQ(NEW_WINDOW, event_utils::WindowOpenDispositionFromNSEvent(me));
60 }
61
62 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/event_utils.mm ('k') | chrome/browser/cocoa/history_menu_cocoa_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698