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

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

Issue 7565007: Clicking tab close with option key close the other tabs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed rsesek's comments. 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 16
17 // 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
18 // 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.
19 @interface TabControllerTestTarget : NSObject<TabControllerTarget> { 19 @interface TabControllerTestTarget : NSObject<TabControllerTarget> {
20 @private 20 @private
21 bool selected_; 21 bool selected_;
22 bool closed_; 22 bool closed_;
23 bool closedOtherTabs_;
23 scoped_nsobject<TabStripDragController> dragController_; 24 scoped_nsobject<TabStripDragController> dragController_;
24 } 25 }
25 - (bool)selected; 26 - (bool)selected;
26 - (bool)closed; 27 - (bool)closed;
28 - (bool)closedOtherTabs;
27 @end 29 @end
28 30
29 @implementation TabControllerTestTarget 31 @implementation TabControllerTestTarget
30 - (id)init { 32 - (id)init {
31 if ((self = [super init])) { 33 if ((self = [super init])) {
32 dragController_.reset( 34 dragController_.reset(
33 [[TabStripDragController alloc] initWithTabStripController:nil]); 35 [[TabStripDragController alloc] initWithTabStripController:nil]);
34 } 36 }
35 return self; 37 return self;
36 } 38 }
37 - (bool)selected { 39 - (bool)selected {
38 return selected_; 40 return selected_;
39 } 41 }
40 - (bool)closed { 42 - (bool)closed {
41 return closed_; 43 return closed_;
42 } 44 }
45 - (bool)closedOtherTabs {
46 return closedOtherTabs_;
47 }
43 - (void)selectTab:(id)sender { 48 - (void)selectTab:(id)sender {
44 selected_ = true; 49 selected_ = true;
45 } 50 }
46 - (void)closeTab:(id)sender { 51 - (void)closeTab:(id)sender {
47 closed_ = true; 52 closed_ = true;
48 } 53 }
54 - (void)closeOtherTabs:(id)sender {
55 closedOtherTabs_ = true;
56 }
49 - (void)mouseTimer:(NSTimer*)timer { 57 - (void)mouseTimer:(NSTimer*)timer {
50 // Fire the mouseUp to break the TabView drag loop. 58 // Fire the mouseUp to break the TabView drag loop.
51 NSEvent* current = [NSApp currentEvent]; 59 NSEvent* current = [NSApp currentEvent];
52 NSWindow* window = [timer userInfo]; 60 NSWindow* window = [timer userInfo];
53 NSEvent* up = [NSEvent mouseEventWithType:NSLeftMouseUp 61 NSEvent* up = [NSEvent mouseEventWithType:NSLeftMouseUp
54 location:[current locationInWindow] 62 location:[current locationInWindow]
55 modifierFlags:0 63 modifierFlags:0
56 timestamp:[current timestamp] 64 timestamp:[current timestamp]
57 windowNumber:[window windowNumber] 65 windowNumber:[window windowNumber]
58 context:nil 66 context:nil
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 EXPECT_FALSE([target closed]); 129 EXPECT_FALSE([target closed]);
122 [controller setTarget:target]; 130 [controller setTarget:target];
123 EXPECT_EQ(target.get(), [controller target]); 131 EXPECT_EQ(target.get(), [controller target]);
124 132
125 [controller closeTab:nil]; 133 [controller closeTab:nil];
126 EXPECT_TRUE([target closed]); 134 EXPECT_TRUE([target closed]);
127 135
128 [[controller view] removeFromSuperview]; 136 [[controller view] removeFromSuperview];
129 } 137 }
130 138
139 // Tests sending it a closeOtherTabs message and ensuring that the
140 // target/action get called.
141 TEST_F(TabControllerTest, CloseOtherTabs) {
142 NSWindow* window = test_window();
143 scoped_nsobject<TabController> controller([[TabController alloc] init]);
144 [[window contentView] addSubview:[controller view]];
145 NSRect frame = [[controller view] frame];
146 frame.size.width = [TabController minTabWidth];
147 frame.origin = NSMakePoint(0, 0);
148 [[controller view] setFrame:frame];
149
150 scoped_nsobject<TabControllerTestTarget> target(
151 [[TabControllerTestTarget alloc] init]);
152 EXPECT_FALSE([target closedOtherTabs]);
153 [controller setTarget:target];
154 [controller setAction:@selector(closeOtherTabs:)];
Robert Sesek 2011/08/10 16:00:34 I think this should really be testing that the Tab
155 EXPECT_EQ(target.get(), [controller target]);
156 EXPECT_EQ(@selector(closeOtherTabs:), [controller action]);
157
158 // In order to track a click, we have to fake a mouse down and a mouse up.
159 [NSTimer scheduledTimerWithTimeInterval:0.1
160 target:target.get()
161 selector:@selector(mouseTimer:)
162 userInfo:window
163 repeats:NO];
164 NSEvent* current = [NSApp currentEvent];
165 NSPoint click_point = NSMakePoint(frame.size.width / 2,
166 frame.size.height / 2);
167 NSEvent* down = [NSEvent mouseEventWithType:NSLeftMouseDown
168 location:[current locationInWindow]
169 modifierFlags:0
170 timestamp:[current timestamp]
171 windowNumber:[window windowNumber]
172 context:nil
173 eventNumber:0
174 clickCount:1
175 pressure:1.0];
176 [[controller view] mouseDown:down];
177
178 EXPECT_TRUE([target closedOtherTabs]);
179 [[controller view] removeFromSuperview];
180 }
181
131 // Tests setting the |selected| property via code. 182 // Tests setting the |selected| property via code.
132 TEST_F(TabControllerTest, APISelection) { 183 TEST_F(TabControllerTest, APISelection) {
133 NSWindow* window = test_window(); 184 NSWindow* window = test_window();
134 scoped_nsobject<TabController> controller([[TabController alloc] init]); 185 scoped_nsobject<TabController> controller([[TabController alloc] init]);
135 [[window contentView] addSubview:[controller view]]; 186 [[window contentView] addSubview:[controller view]];
136 187
137 EXPECT_FALSE([controller selected]); 188 EXPECT_FALSE([controller selected]);
138 [controller setSelected:YES]; 189 [controller setSelected:YES];
139 EXPECT_TRUE([controller selected]); 190 EXPECT_TRUE([controller selected]);
140 191
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 NSWidth([[controller titleView] frame])); 400 NSWidth([[controller titleView] frame]));
350 EXPECT_EQ(LeftMargin(originalTabFrame, originalTitleFrame), 401 EXPECT_EQ(LeftMargin(originalTabFrame, originalTitleFrame),
351 LeftMargin([[controller view] frame], 402 LeftMargin([[controller view] frame],
352 [[controller titleView] frame])); 403 [[controller titleView] frame]));
353 EXPECT_EQ(RightMargin(originalTabFrame, originalTitleFrame), 404 EXPECT_EQ(RightMargin(originalTabFrame, originalTitleFrame),
354 RightMargin([[controller view] frame], 405 RightMargin([[controller view] frame],
355 [[controller titleView] frame])); 406 [[controller titleView] frame]));
356 } 407 }
357 408
358 } // namespace 409 } // 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