| OLD | NEW |
| 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 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #import "testing/gtest_mac.h" | 14 #import "testing/gtest_mac.h" |
| 14 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
| 15 | 16 |
| 16 // 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 |
| 17 // 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. |
| 18 @interface TabControllerTestTarget : NSObject<TabControllerTarget> { | 19 @interface TabControllerTestTarget : NSObject<TabControllerTarget> { |
| 19 @private | 20 @private |
| 20 bool selected_; | 21 bool selected_; |
| 21 bool closed_; | 22 bool closed_; |
| 23 scoped_nsobject<TabStripDragController> dragController_; |
| 22 } | 24 } |
| 23 - (bool)selected; | 25 - (bool)selected; |
| 24 - (bool)closed; | 26 - (bool)closed; |
| 25 @end | 27 @end |
| 26 | 28 |
| 27 @implementation TabControllerTestTarget | 29 @implementation TabControllerTestTarget |
| 30 - (id)init { |
| 31 if ((self = [super init])) { |
| 32 dragController_.reset( |
| 33 [[TabStripDragController alloc] initWithTabStripController:nil]); |
| 34 } |
| 35 return self; |
| 36 } |
| 28 - (bool)selected { | 37 - (bool)selected { |
| 29 return selected_; | 38 return selected_; |
| 30 } | 39 } |
| 31 - (bool)closed { | 40 - (bool)closed { |
| 32 return closed_; | 41 return closed_; |
| 33 } | 42 } |
| 34 - (void)selectTab:(id)sender { | 43 - (void)selectTab:(id)sender { |
| 35 selected_ = true; | 44 selected_ = true; |
| 36 } | 45 } |
| 37 - (void)closeTab:(id)sender { | 46 - (void)closeTab:(id)sender { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 60 return NO; | 69 return NO; |
| 61 } | 70 } |
| 62 - (ui::SimpleMenuModel*)contextMenuModelForController:(TabController*)controller | 71 - (ui::SimpleMenuModel*)contextMenuModelForController:(TabController*)controller |
| 63 menuDelegate:(ui::SimpleMenuModel::Delegate*)delegate { | 72 menuDelegate:(ui::SimpleMenuModel::Delegate*)delegate { |
| 64 ui::SimpleMenuModel* model = new ui::SimpleMenuModel(delegate); | 73 ui::SimpleMenuModel* model = new ui::SimpleMenuModel(delegate); |
| 65 model->AddItem(1, ASCIIToUTF16("Hello World")); | 74 model->AddItem(1, ASCIIToUTF16("Hello World")); |
| 66 model->AddItem(2, ASCIIToUTF16("Allays")); | 75 model->AddItem(2, ASCIIToUTF16("Allays")); |
| 67 model->AddItem(3, ASCIIToUTF16("Chromium")); | 76 model->AddItem(3, ASCIIToUTF16("Chromium")); |
| 68 return model; | 77 return model; |
| 69 } | 78 } |
| 79 - (id<TabDraggingEventTarget>)dragController { |
| 80 return dragController_.get(); |
| 81 } |
| 70 @end | 82 @end |
| 71 | 83 |
| 72 namespace { | 84 namespace { |
| 73 | 85 |
| 74 CGFloat LeftMargin(NSRect superFrame, NSRect subFrame) { | 86 CGFloat LeftMargin(NSRect superFrame, NSRect subFrame) { |
| 75 return NSMinX(subFrame) - NSMinX(superFrame); | 87 return NSMinX(subFrame) - NSMinX(superFrame); |
| 76 } | 88 } |
| 77 | 89 |
| 78 CGFloat RightMargin(NSRect superFrame, NSRect subFrame) { | 90 CGFloat RightMargin(NSRect superFrame, NSRect subFrame) { |
| 79 return NSMaxX(superFrame) - NSMaxX(subFrame); | 91 return NSMaxX(superFrame) - NSMaxX(subFrame); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 NSWidth([[controller titleView] frame])); | 349 NSWidth([[controller titleView] frame])); |
| 338 EXPECT_EQ(LeftMargin(originalTabFrame, originalTitleFrame), | 350 EXPECT_EQ(LeftMargin(originalTabFrame, originalTitleFrame), |
| 339 LeftMargin([[controller view] frame], | 351 LeftMargin([[controller view] frame], |
| 340 [[controller titleView] frame])); | 352 [[controller titleView] frame])); |
| 341 EXPECT_EQ(RightMargin(originalTabFrame, originalTitleFrame), | 353 EXPECT_EQ(RightMargin(originalTabFrame, originalTitleFrame), |
| 342 RightMargin([[controller view] frame], | 354 RightMargin([[controller view] frame], |
| 343 [[controller titleView] frame])); | 355 [[controller titleView] frame])); |
| 344 } | 356 } |
| 345 | 357 |
| 346 } // namespace | 358 } // namespace |
| OLD | NEW |