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

Side by Side Diff: chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm

Issue 7709023: Revert 97828 - Clicking tab close with option key close the other tabs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "base/memory/scoped_nsobject.h" 7 #import "base/memory/scoped_nsobject.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" 9 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
10 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" 10 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h"
11 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" 11 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h"
12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" 12 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #import "testing/gtest_mac.h" 14 #import "testing/gtest_mac.h"
15 #include "testing/platform_test.h" 15 #include "testing/platform_test.h"
16 #import "third_party/ocmock/OCMock/OCMock.h"
17 16
18 // Implements the target interface for the tab, which gets sent messages when 17 // Implements the target interface for the tab, which gets sent messages when
19 // the tab is clicked on by the user and when its close box is clicked. 18 // the tab is clicked on by the user and when its close box is clicked.
20 @interface TabControllerTestTarget : NSObject<TabControllerTarget> { 19 @interface TabControllerTestTarget : NSObject<TabControllerTarget> {
21 @private 20 @private
22 bool selected_; 21 bool selected_;
23 bool closed_; 22 bool closed_;
24 bool closedOtherTabs_;
25 scoped_nsobject<TabStripDragController> dragController_; 23 scoped_nsobject<TabStripDragController> dragController_;
26 } 24 }
27 - (bool)selected; 25 - (bool)selected;
28 - (bool)closed; 26 - (bool)closed;
29 - (bool)closedOtherTabs;
30 @end 27 @end
31 28
32 @implementation TabControllerTestTarget 29 @implementation TabControllerTestTarget
33 - (id)init { 30 - (id)init {
34 if ((self = [super init])) { 31 if ((self = [super init])) {
35 dragController_.reset( 32 dragController_.reset(
36 [[TabStripDragController alloc] initWithTabStripController:nil]); 33 [[TabStripDragController alloc] initWithTabStripController:nil]);
37 } 34 }
38 return self; 35 return self;
39 } 36 }
40 - (bool)selected { 37 - (bool)selected {
41 return selected_; 38 return selected_;
42 } 39 }
43 - (bool)closed { 40 - (bool)closed {
44 return closed_; 41 return closed_;
45 } 42 }
46 - (bool)closedOtherTabs {
47 return closedOtherTabs_;
48 }
49 - (void)selectTab:(id)sender { 43 - (void)selectTab:(id)sender {
50 selected_ = true; 44 selected_ = true;
51 } 45 }
52 - (void)closeTab:(id)sender { 46 - (void)closeTab:(id)sender {
53 closed_ = true; 47 closed_ = true;
54 } 48 }
55 - (void)closeOtherTabs:(id)sender {
56 closedOtherTabs_ = true;
57 }
58 - (void)mouseTimer:(NSTimer*)timer { 49 - (void)mouseTimer:(NSTimer*)timer {
59 // Fire the mouseUp to break the TabView drag loop. 50 // Fire the mouseUp to break the TabView drag loop.
60 NSEvent* current = [NSApp currentEvent]; 51 NSEvent* current = [NSApp currentEvent];
61 NSWindow* window = [timer userInfo]; 52 NSWindow* window = [timer userInfo];
62 NSEvent* up = [NSEvent mouseEventWithType:NSLeftMouseUp 53 NSEvent* up = [NSEvent mouseEventWithType:NSLeftMouseUp
63 location:[current locationInWindow] 54 location:[current locationInWindow]
64 modifierFlags:[current modifierFlags] 55 modifierFlags:0
65 timestamp:[current timestamp] 56 timestamp:[current timestamp]
66 windowNumber:[window windowNumber] 57 windowNumber:[window windowNumber]
67 context:nil 58 context:nil
68 eventNumber:0 59 eventNumber:0
69 clickCount:1 60 clickCount:1
70 pressure:1.0]; 61 pressure:1.0];
71 [window postEvent:up atStart:YES]; 62 [window postEvent:up atStart:YES];
72 } 63 }
73 - (void)commandDispatch:(TabStripModel::ContextMenuCommand)command 64 - (void)commandDispatch:(TabStripModel::ContextMenuCommand)command
74 forController:(TabController*)controller { 65 forController:(TabController*)controller {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 EXPECT_FALSE([target closed]); 121 EXPECT_FALSE([target closed]);
131 [controller setTarget:target]; 122 [controller setTarget:target];
132 EXPECT_EQ(target.get(), [controller target]); 123 EXPECT_EQ(target.get(), [controller target]);
133 124
134 [controller closeTab:nil]; 125 [controller closeTab:nil];
135 EXPECT_TRUE([target closed]); 126 EXPECT_TRUE([target closed]);
136 127
137 [[controller view] removeFromSuperview]; 128 [[controller view] removeFromSuperview];
138 } 129 }
139 130
140 // Tests sending it a closeTab message with a mousedown event and ensuring
141 // that the target/action get called. closeOtherTabs message should be called
142 // when the tab is clicked with option key.
143 TEST_F(TabControllerTest, CloseOtherTabs) {
144 NSWindow* window = test_window();
145 scoped_nsobject<TabController> controller([[TabController alloc] init]);
146 [[window contentView] addSubview:[controller view]];
147
148 scoped_nsobject<TabControllerTestTarget> target(
149 [[TabControllerTestTarget alloc] init]);
150 EXPECT_FALSE([target closedOtherTabs]);
151 [controller setTarget:target];
152 [controller setAction:@selector(closeTab:)];
153 EXPECT_EQ(target.get(), [controller target]);
154 EXPECT_EQ(@selector(closeTab:), [controller action]);
155
156 // Create a mouse event with |NSAlternateKeyMask| and mock NSApp so that
157 // [NSApp currentEvent] returns the event.
158 NSEvent* current = [NSApp currentEvent];
159 NSEvent* down = [NSEvent mouseEventWithType:NSLeftMouseDown
160 location:[current locationInWindow]
161 modifierFlags:NSAlternateKeyMask
162 timestamp:[current timestamp]
163 windowNumber:[window windowNumber]
164 context:nil
165 eventNumber:0
166 clickCount:1
167 pressure:1.0];
168 // OCMock will swap NSApp internally and will restore it when the mock gets
169 // deallocated. This happens when the autorelease pool drains at the end of
170 // the test.
171 id fakeApp = [OCMockObject partialMockForObject:NSApp];
172 [[[fakeApp stub] andReturn:down] currentEvent];
173
174 [controller closeTab:nil];
175 EXPECT_TRUE([target closedOtherTabs]);
176 EXPECT_FALSE([target closed]);
177 [[controller view] removeFromSuperview];
178 }
179
180 // Tests setting the |selected| property via code. 131 // Tests setting the |selected| property via code.
181 TEST_F(TabControllerTest, APISelection) { 132 TEST_F(TabControllerTest, APISelection) {
182 NSWindow* window = test_window(); 133 NSWindow* window = test_window();
183 scoped_nsobject<TabController> controller([[TabController alloc] init]); 134 scoped_nsobject<TabController> controller([[TabController alloc] init]);
184 [[window contentView] addSubview:[controller view]]; 135 [[window contentView] addSubview:[controller view]];
185 136
186 EXPECT_FALSE([controller selected]); 137 EXPECT_FALSE([controller selected]);
187 [controller setSelected:YES]; 138 [controller setSelected:YES];
188 EXPECT_TRUE([controller selected]); 139 EXPECT_TRUE([controller selected]);
189 140
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 NSWidth([[controller titleView] frame])); 349 NSWidth([[controller titleView] frame]));
399 EXPECT_EQ(LeftMargin(originalTabFrame, originalTitleFrame), 350 EXPECT_EQ(LeftMargin(originalTabFrame, originalTitleFrame),
400 LeftMargin([[controller view] frame], 351 LeftMargin([[controller view] frame],
401 [[controller titleView] frame])); 352 [[controller titleView] frame]));
402 EXPECT_EQ(RightMargin(originalTabFrame, originalTitleFrame), 353 EXPECT_EQ(RightMargin(originalTabFrame, originalTitleFrame),
403 RightMargin([[controller view] frame], 354 RightMargin([[controller view] frame],
404 [[controller titleView] frame])); 355 [[controller titleView] frame]));
405 } 356 }
406 357
407 } // namespace 358 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/tabs/tab_controller_target.h ('k') | chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698