Index: chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm |
diff --git a/chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm b/chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm |
index 62781982cad529404cf5f45d3a3c79122e059c9c..2f095011298c21520edcdf68b38d6112824eca42 100644 |
--- a/chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm |
+++ b/chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm |
@@ -20,10 +20,12 @@ |
@private |
bool selected_; |
bool closed_; |
+ bool closedOtherTabs_; |
scoped_nsobject<TabStripDragController> dragController_; |
} |
- (bool)selected; |
- (bool)closed; |
+- (bool)closedOtherTabs; |
@end |
@implementation TabControllerTestTarget |
@@ -40,12 +42,18 @@ |
- (bool)closed { |
return closed_; |
} |
+- (bool)closedOtherTabs { |
+ return closedOtherTabs_; |
+} |
- (void)selectTab:(id)sender { |
selected_ = true; |
} |
- (void)closeTab:(id)sender { |
closed_ = true; |
} |
+- (void)closeOtherTabs:(id)sender { |
+ closedOtherTabs_ = true; |
+} |
- (void)mouseTimer:(NSTimer*)timer { |
// Fire the mouseUp to break the TabView drag loop. |
NSEvent* current = [NSApp currentEvent]; |
@@ -128,6 +136,49 @@ TEST_F(TabControllerTest, Close) { |
[[controller view] removeFromSuperview]; |
} |
+// Tests sending it a closeOtherTabs message and ensuring that the |
+// target/action get called. |
+TEST_F(TabControllerTest, CloseOtherTabs) { |
+ NSWindow* window = test_window(); |
+ scoped_nsobject<TabController> controller([[TabController alloc] init]); |
+ [[window contentView] addSubview:[controller view]]; |
+ NSRect frame = [[controller view] frame]; |
+ frame.size.width = [TabController minTabWidth]; |
+ frame.origin = NSMakePoint(0, 0); |
+ [[controller view] setFrame:frame]; |
+ |
+ scoped_nsobject<TabControllerTestTarget> target( |
+ [[TabControllerTestTarget alloc] init]); |
+ EXPECT_FALSE([target closedOtherTabs]); |
+ [controller setTarget:target]; |
+ [controller setAction:@selector(closeOtherTabs:)]; |
Robert Sesek
2011/08/10 16:00:34
I think this should really be testing that the Tab
|
+ EXPECT_EQ(target.get(), [controller target]); |
+ EXPECT_EQ(@selector(closeOtherTabs:), [controller action]); |
+ |
+ // In order to track a click, we have to fake a mouse down and a mouse up. |
+ [NSTimer scheduledTimerWithTimeInterval:0.1 |
+ target:target.get() |
+ selector:@selector(mouseTimer:) |
+ userInfo:window |
+ repeats:NO]; |
+ NSEvent* current = [NSApp currentEvent]; |
+ NSPoint click_point = NSMakePoint(frame.size.width / 2, |
+ frame.size.height / 2); |
+ NSEvent* down = [NSEvent mouseEventWithType:NSLeftMouseDown |
+ location:[current locationInWindow] |
+ modifierFlags:0 |
+ timestamp:[current timestamp] |
+ windowNumber:[window windowNumber] |
+ context:nil |
+ eventNumber:0 |
+ clickCount:1 |
+ pressure:1.0]; |
+ [[controller view] mouseDown:down]; |
+ |
+ EXPECT_TRUE([target closedOtherTabs]); |
+ [[controller view] removeFromSuperview]; |
+} |
+ |
// Tests setting the |selected| property via code. |
TEST_F(TabControllerTest, APISelection) { |
NSWindow* window = test_window(); |