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 "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 9 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
9 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 10 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
10 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" | 11 #import "chrome/browser/ui/cocoa/tabs/tab_controller_target.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 #import "testing/gtest_mac.h" | 13 #import "testing/gtest_mac.h" |
13 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
14 | 15 |
15 // Implements the target interface for the tab, which gets sent messages when | 16 // Implements the target interface for the tab, which gets sent messages when |
16 // the tab is clicked on by the user and when its close box is clicked. | 17 // the tab is clicked on by the user and when its close box is clicked. |
17 @interface TabControllerTestTarget : NSObject<TabControllerTarget> { | 18 @interface TabControllerTestTarget : NSObject<TabControllerTarget> { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 pressure:1.0]; | 52 pressure:1.0]; |
52 [window postEvent:up atStart:YES]; | 53 [window postEvent:up atStart:YES]; |
53 } | 54 } |
54 - (void)commandDispatch:(TabStripModel::ContextMenuCommand)command | 55 - (void)commandDispatch:(TabStripModel::ContextMenuCommand)command |
55 forController:(TabController*)controller { | 56 forController:(TabController*)controller { |
56 } | 57 } |
57 - (BOOL)isCommandEnabled:(TabStripModel::ContextMenuCommand)command | 58 - (BOOL)isCommandEnabled:(TabStripModel::ContextMenuCommand)command |
58 forController:(TabController*)controller { | 59 forController:(TabController*)controller { |
59 return NO; | 60 return NO; |
60 } | 61 } |
| 62 - (ui::SimpleMenuModel*)contextMenuModelForController:(TabController*)controller |
| 63 menuDelegate:(ui::SimpleMenuModel::Delegate*)delegate { |
| 64 ui::SimpleMenuModel* model = new ui::SimpleMenuModel(delegate); |
| 65 model->AddItem(1, ASCIIToUTF16("Hello World")); |
| 66 model->AddItem(2, ASCIIToUTF16("Allays")); |
| 67 model->AddItem(3, ASCIIToUTF16("Chromium")); |
| 68 return model; |
| 69 } |
61 @end | 70 @end |
62 | 71 |
63 namespace { | 72 namespace { |
64 | 73 |
65 CGFloat LeftMargin(NSRect superFrame, NSRect subFrame) { | 74 CGFloat LeftMargin(NSRect superFrame, NSRect subFrame) { |
66 return NSMinX(subFrame) - NSMinX(superFrame); | 75 return NSMinX(subFrame) - NSMinX(superFrame); |
67 } | 76 } |
68 | 77 |
69 CGFloat RightMargin(NSRect superFrame, NSRect subFrame) { | 78 CGFloat RightMargin(NSRect superFrame, NSRect subFrame) { |
70 return NSMaxX(superFrame) - NSMaxX(subFrame); | 79 return NSMaxX(superFrame) - NSMaxX(subFrame); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 EXPECT_TRUE([controller shouldShowIcon]); | 265 EXPECT_TRUE([controller shouldShowIcon]); |
257 EXPECT_TRUE([controller shouldShowCloseButton]); | 266 EXPECT_TRUE([controller shouldShowCloseButton]); |
258 | 267 |
259 cap = [controller iconCapacity]; | 268 cap = [controller iconCapacity]; |
260 EXPECT_GT(cap, 0); | 269 EXPECT_GT(cap, 0); |
261 } | 270 } |
262 | 271 |
263 TEST_F(TabControllerTest, Menu) { | 272 TEST_F(TabControllerTest, Menu) { |
264 NSWindow* window = test_window(); | 273 NSWindow* window = test_window(); |
265 scoped_nsobject<TabController> controller([[TabController alloc] init]); | 274 scoped_nsobject<TabController> controller([[TabController alloc] init]); |
| 275 scoped_nsobject<TabControllerTestTarget> target( |
| 276 [[TabControllerTestTarget alloc] init]); |
| 277 [controller setTarget:target]; |
| 278 |
266 [[window contentView] addSubview:[controller view]]; | 279 [[window contentView] addSubview:[controller view]]; |
267 int cap = [controller iconCapacity]; | 280 int cap = [controller iconCapacity]; |
268 EXPECT_GT(cap, 0); | 281 EXPECT_GT(cap, 0); |
269 | 282 |
270 // Asking the view for its menu should yield a valid menu. | 283 // Asking the view for its menu should yield a valid menu. |
271 NSMenu* menu = [[controller view] menu]; | 284 NSMenu* menu = [[controller view] menu]; |
272 EXPECT_TRUE(menu); | 285 EXPECT_TRUE(menu); |
273 EXPECT_GT([menu numberOfItems], 0); | 286 EXPECT_EQ(3, [menu numberOfItems]); |
274 } | 287 } |
275 | 288 |
276 // Tests that the title field is correctly positioned and sized when the | 289 // Tests that the title field is correctly positioned and sized when the |
277 // view is resized. | 290 // view is resized. |
278 TEST_F(TabControllerTest, TitleViewLayout) { | 291 TEST_F(TabControllerTest, TitleViewLayout) { |
279 NSWindow* window = test_window(); | 292 NSWindow* window = test_window(); |
280 | 293 |
281 scoped_nsobject<TabController> controller([[TabController alloc] init]); | 294 scoped_nsobject<TabController> controller([[TabController alloc] init]); |
282 [[window contentView] addSubview:[controller view]]; | 295 [[window contentView] addSubview:[controller view]]; |
283 NSRect tabFrame = [[controller view] frame]; | 296 NSRect tabFrame = [[controller view] frame]; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 NSWidth([[controller titleView] frame])); | 337 NSWidth([[controller titleView] frame])); |
325 EXPECT_EQ(LeftMargin(originalTabFrame, originalTitleFrame), | 338 EXPECT_EQ(LeftMargin(originalTabFrame, originalTitleFrame), |
326 LeftMargin([[controller view] frame], | 339 LeftMargin([[controller view] frame], |
327 [[controller titleView] frame])); | 340 [[controller titleView] frame])); |
328 EXPECT_EQ(RightMargin(originalTabFrame, originalTitleFrame), | 341 EXPECT_EQ(RightMargin(originalTabFrame, originalTitleFrame), |
329 RightMargin([[controller view] frame], | 342 RightMargin([[controller view] frame], |
330 [[controller titleView] frame])); | 343 [[controller titleView] frame])); |
331 } | 344 } |
332 | 345 |
333 } // namespace | 346 } // namespace |
OLD | NEW |