OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/scoped_nsobject.h" | 7 #import "base/scoped_nsobject.h" |
8 #import "chrome/browser/ui/cocoa/tab_controller.h" | 8 #import "chrome/browser/ui/cocoa/tab_controller.h" |
9 #import "chrome/browser/ui/cocoa/tab_controller_target.h" | 9 #import "chrome/browser/ui/cocoa/tab_controller_target.h" |
10 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 10 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 forController:(TabController*)controller { | 55 forController:(TabController*)controller { |
56 } | 56 } |
57 - (BOOL)isCommandEnabled:(TabStripModel::ContextMenuCommand)command | 57 - (BOOL)isCommandEnabled:(TabStripModel::ContextMenuCommand)command |
58 forController:(TabController*)controller { | 58 forController:(TabController*)controller { |
59 return NO; | 59 return NO; |
60 } | 60 } |
61 @end | 61 @end |
62 | 62 |
63 namespace { | 63 namespace { |
64 | 64 |
| 65 CGFloat LeftMargin(NSRect superFrame, NSRect subFrame) { |
| 66 return NSMinX(subFrame) - NSMinX(superFrame); |
| 67 } |
| 68 |
| 69 CGFloat RightMargin(NSRect superFrame, NSRect subFrame) { |
| 70 return NSMaxX(superFrame) - NSMaxX(subFrame); |
| 71 } |
| 72 |
65 // The dragging code in TabView makes heavy use of autorelease pools so | 73 // The dragging code in TabView makes heavy use of autorelease pools so |
66 // inherit from CocoaTest to have one created for us. | 74 // inherit from CocoaTest to have one created for us. |
67 class TabControllerTest : public CocoaTest { | 75 class TabControllerTest : public CocoaTest { |
68 public: | 76 public: |
69 TabControllerTest() { } | 77 TabControllerTest() { } |
70 }; | 78 }; |
71 | 79 |
72 // Tests creating the controller, sticking it in a window, and removing it. | 80 // Tests creating the controller, sticking it in a window, and removing it. |
73 TEST_F(TabControllerTest, Creation) { | 81 TEST_F(TabControllerTest, Creation) { |
74 NSWindow* window = test_window(); | 82 NSWindow* window = test_window(); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 [[window contentView] addSubview:[controller view]]; | 266 [[window contentView] addSubview:[controller view]]; |
259 int cap = [controller iconCapacity]; | 267 int cap = [controller iconCapacity]; |
260 EXPECT_GT(cap, 0); | 268 EXPECT_GT(cap, 0); |
261 | 269 |
262 // Asking the view for its menu should yield a valid menu. | 270 // Asking the view for its menu should yield a valid menu. |
263 NSMenu* menu = [[controller view] menu]; | 271 NSMenu* menu = [[controller view] menu]; |
264 EXPECT_TRUE(menu); | 272 EXPECT_TRUE(menu); |
265 EXPECT_GT([menu numberOfItems], 0); | 273 EXPECT_GT([menu numberOfItems], 0); |
266 } | 274 } |
267 | 275 |
| 276 // Tests that the title field is correctly positioned and sized when the |
| 277 // view is resized. |
| 278 TEST_F(TabControllerTest, TitleViewLayout) { |
| 279 NSWindow* window = test_window(); |
| 280 |
| 281 scoped_nsobject<TabController> controller([[TabController alloc] init]); |
| 282 [[window contentView] addSubview:[controller view]]; |
| 283 NSRect tabFrame = [[controller view] frame]; |
| 284 tabFrame.size.width = [TabController maxTabWidth]; |
| 285 [[controller view] setFrame:tabFrame]; |
| 286 |
| 287 const NSRect originalTabFrame = [[controller view] frame]; |
| 288 const NSRect originalIconFrame = [[controller iconView] frame]; |
| 289 const NSRect originalCloseFrame = [[controller closeButton] frame]; |
| 290 const NSRect originalTitleFrame = [[controller titleView] frame]; |
| 291 |
| 292 // Sanity check the start state. |
| 293 EXPECT_FALSE([[controller iconView] isHidden]); |
| 294 EXPECT_FALSE([[controller closeButton] isHidden]); |
| 295 EXPECT_GT(NSWidth([[controller view] frame]), |
| 296 NSWidth([[controller titleView] frame])); |
| 297 |
| 298 // Resize the tab so that that the it shrinks. |
| 299 tabFrame.size.width = [TabController minTabWidth]; |
| 300 [[controller view] setFrame:tabFrame]; |
| 301 |
| 302 // The icon view and close button should be hidden and the title view should |
| 303 // be resize to take up their space. |
| 304 EXPECT_TRUE([[controller iconView] isHidden]); |
| 305 EXPECT_TRUE([[controller closeButton] isHidden]); |
| 306 EXPECT_GT(NSWidth([[controller view] frame]), |
| 307 NSWidth([[controller titleView] frame])); |
| 308 EXPECT_EQ(LeftMargin(originalTabFrame, originalIconFrame), |
| 309 LeftMargin([[controller view] frame], |
| 310 [[controller titleView] frame])); |
| 311 EXPECT_EQ(RightMargin(originalTabFrame, originalCloseFrame), |
| 312 RightMargin([[controller view] frame], |
| 313 [[controller titleView] frame])); |
| 314 |
| 315 // Resize the tab so that that the it grows. |
| 316 tabFrame.size.width = [TabController maxTabWidth] * 0.75; |
| 317 [[controller view] setFrame:tabFrame]; |
| 318 |
| 319 // The icon view and close button should be visible again and the title view |
| 320 // should be resized to make room for them. |
| 321 EXPECT_FALSE([[controller iconView] isHidden]); |
| 322 EXPECT_FALSE([[controller closeButton] isHidden]); |
| 323 EXPECT_GT(NSWidth([[controller view] frame]), |
| 324 NSWidth([[controller titleView] frame])); |
| 325 EXPECT_EQ(LeftMargin(originalTabFrame, originalTitleFrame), |
| 326 LeftMargin([[controller view] frame], |
| 327 [[controller titleView] frame])); |
| 328 EXPECT_EQ(RightMargin(originalTabFrame, originalTitleFrame), |
| 329 RightMargin([[controller view] frame], |
| 330 [[controller titleView] frame])); |
| 331 } |
| 332 |
268 } // namespace | 333 } // namespace |
OLD | NEW |