Chromium Code Reviews| 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..ec4d0890609bad91abc65a8bcb38816332c3c0b9 100644 |
| --- a/chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm |
| +++ b/chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm |
| @@ -13,6 +13,7 @@ |
| #include "testing/gtest/include/gtest/gtest.h" |
| #import "testing/gtest_mac.h" |
| #include "testing/platform_test.h" |
| +#import "third_party/ocmock/OCMock/OCMock.h" |
| // Implements the target interface for the tab, which gets sent messages when |
| // the tab is clicked on by the user and when its close box is clicked. |
| @@ -20,10 +21,12 @@ |
| @private |
| bool selected_; |
| bool closed_; |
| + bool closedOtherTabs_; |
| scoped_nsobject<TabStripDragController> dragController_; |
| } |
| - (bool)selected; |
| - (bool)closed; |
| +- (bool)closedOtherTabs; |
| @end |
| @implementation TabControllerTestTarget |
| @@ -40,19 +43,25 @@ |
| - (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]; |
| NSWindow* window = [timer userInfo]; |
| NSEvent* up = [NSEvent mouseEventWithType:NSLeftMouseUp |
| location:[current locationInWindow] |
| - modifierFlags:0 |
| + modifierFlags:[current modifierFlags] |
| timestamp:[current timestamp] |
| windowNumber:[window windowNumber] |
| context:nil |
| @@ -128,6 +137,43 @@ TEST_F(TabControllerTest, Close) { |
| [[controller view] removeFromSuperview]; |
| } |
| +// Tests sending it a closeTab message with a mousedown event and ensuring |
| +// that the target/action get called. closeOtherTabs message should be called |
| +// when the tab is clicked with option key. |
| +TEST_F(TabControllerTest, CloseOtherTabs) { |
| + NSWindow* window = test_window(); |
| + scoped_nsobject<TabController> controller([[TabController alloc] init]); |
| + [[window contentView] addSubview:[controller view]]; |
| + |
| + scoped_nsobject<TabControllerTestTarget> target( |
| + [[TabControllerTestTarget alloc] init]); |
| + EXPECT_FALSE([target closedOtherTabs]); |
| + [controller setTarget:target]; |
| + [controller setAction:@selector(closeTab:)]; |
| + EXPECT_EQ(target.get(), [controller target]); |
| + EXPECT_EQ(@selector(closeTab:), [controller action]); |
| + |
| + // Create a mouse event with |NSAlternateKeyMask| and mock NSApp so that |
| + // [NSApp currentEvent] returns the event. |
| + NSEvent* current = [NSApp currentEvent]; |
| + NSEvent* down = [NSEvent mouseEventWithType:NSLeftMouseDown |
| + location:[current locationInWindow] |
| + modifierFlags:NSAlternateKeyMask |
| + timestamp:[current timestamp] |
| + windowNumber:[window windowNumber] |
| + context:nil |
| + eventNumber:0 |
| + clickCount:1 |
| + pressure:1.0]; |
| + id fakeApp = [OCMockObject partialMockForObject:NSApp]; |
|
Robert Sesek
2011/08/19 15:36:25
I had to figure out how this worked. Add a comment
bashi
2011/08/22 06:43:48
Done.
|
| + [[[fakeApp stub] andReturn:down] currentEvent]; |
| + |
| + [controller closeTab:nil]; |
| + EXPECT_TRUE([target closedOtherTabs]); |
| + EXPECT_FALSE([target closed]); |
| + [[controller view] removeFromSuperview]; |
| +} |
| + |
| // Tests setting the |selected| property via code. |
| TEST_F(TabControllerTest, APISelection) { |
| NSWindow* window = test_window(); |