Chromium Code Reviews| 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 static CGFloat LeftMargin(NSRect superFrame, NSRect subFrame); | |
|
viettrungluu
2010/12/14 00:19:50
|static|s aren't necessary in an anonymous namespa
sail
2010/12/14 01:59:53
Cool! Didn't know that.
Done.
| |
| 66 static CGFloat RightMargin(NSRect superFrame, NSRect subFrame); | |
| 67 | |
| 65 // The dragging code in TabView makes heavy use of autorelease pools so | 68 // The dragging code in TabView makes heavy use of autorelease pools so |
| 66 // inherit from CocoaTest to have one created for us. | 69 // inherit from CocoaTest to have one created for us. |
| 67 class TabControllerTest : public CocoaTest { | 70 class TabControllerTest : public CocoaTest { |
| 68 public: | 71 public: |
| 69 TabControllerTest() { } | 72 TabControllerTest() { } |
| 70 }; | 73 }; |
| 71 | 74 |
| 72 // Tests creating the controller, sticking it in a window, and removing it. | 75 // Tests creating the controller, sticking it in a window, and removing it. |
| 73 TEST_F(TabControllerTest, Creation) { | 76 TEST_F(TabControllerTest, Creation) { |
| 74 NSWindow* window = test_window(); | 77 NSWindow* window = test_window(); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 [[window contentView] addSubview:[controller view]]; | 261 [[window contentView] addSubview:[controller view]]; |
| 259 int cap = [controller iconCapacity]; | 262 int cap = [controller iconCapacity]; |
| 260 EXPECT_GT(cap, 0); | 263 EXPECT_GT(cap, 0); |
| 261 | 264 |
| 262 // Asking the view for its menu should yield a valid menu. | 265 // Asking the view for its menu should yield a valid menu. |
| 263 NSMenu* menu = [[controller view] menu]; | 266 NSMenu* menu = [[controller view] menu]; |
| 264 EXPECT_TRUE(menu); | 267 EXPECT_TRUE(menu); |
| 265 EXPECT_GT([menu numberOfItems], 0); | 268 EXPECT_GT([menu numberOfItems], 0); |
| 266 } | 269 } |
| 267 | 270 |
| 271 // Tests that the title field is correctly positioned and sized when the | |
| 272 // view is resized. | |
| 273 TEST_F(TabControllerTest, TitleViewLayout) { | |
| 274 NSWindow* window = test_window(); | |
| 275 | |
| 276 scoped_nsobject<TabController> controller([[TabController alloc] init]); | |
| 277 [[window contentView] addSubview:[controller view]]; | |
| 278 NSRect tabFrame = [[controller view] frame]; | |
| 279 tabFrame.size.width = [TabController maxTabWidth]; | |
| 280 [[controller view] setFrame:tabFrame]; | |
| 281 | |
| 282 const NSRect originalTabFrame = [[controller view] frame]; | |
| 283 const NSRect originalIconFrame = [[controller iconView] frame]; | |
| 284 const NSRect originalCloseFrame = [[controller closeButton] frame]; | |
| 285 const NSRect originalTitleFrame = [[controller titleView] frame]; | |
| 286 | |
| 287 // Sanity check the start state. | |
| 288 EXPECT_FALSE([[controller iconView] isHidden]); | |
| 289 EXPECT_FALSE([[controller closeButton] isHidden]); | |
| 290 EXPECT_GT(NSWidth([[controller view] frame]), | |
| 291 NSWidth([[controller titleView] frame])); | |
| 292 | |
| 293 // Resize the tab so that that the it shrinks. | |
| 294 tabFrame.size.width = [TabController minTabWidth]; | |
| 295 [[controller view] setFrame:tabFrame]; | |
| 296 | |
| 297 // The icon view and close button should be hidden and the title view should | |
| 298 // be resize to take up their space. | |
| 299 EXPECT_TRUE([[controller iconView] isHidden]); | |
| 300 EXPECT_TRUE([[controller closeButton] isHidden]); | |
| 301 EXPECT_GT(NSWidth([[controller view] frame]), | |
| 302 NSWidth([[controller titleView] frame])); | |
| 303 EXPECT_EQ(LeftMargin(originalTabFrame, originalIconFrame), | |
| 304 LeftMargin([[controller view] frame], | |
| 305 [[controller titleView] frame])); | |
| 306 EXPECT_EQ(RightMargin(originalTabFrame, originalCloseFrame), | |
| 307 RightMargin([[controller view] frame], | |
| 308 [[controller titleView] frame])); | |
| 309 | |
| 310 // Resize the tab so that that the it grows. | |
| 311 tabFrame.size.width = [TabController maxTabWidth] * 0.75; | |
| 312 [[controller view] setFrame:tabFrame]; | |
| 313 | |
| 314 // The icon view and close button should be visible again and the title view | |
| 315 // should be resized to make room for them. | |
| 316 EXPECT_FALSE([[controller iconView] isHidden]); | |
| 317 EXPECT_FALSE([[controller closeButton] isHidden]); | |
| 318 EXPECT_GT(NSWidth([[controller view] frame]), | |
| 319 NSWidth([[controller titleView] frame])); | |
| 320 EXPECT_EQ(LeftMargin(originalTabFrame, originalTitleFrame), | |
| 321 LeftMargin([[controller view] frame], | |
| 322 [[controller titleView] frame])); | |
| 323 EXPECT_EQ(RightMargin(originalTabFrame, originalTitleFrame), | |
| 324 RightMargin([[controller view] frame], | |
| 325 [[controller titleView] frame])); | |
| 326 } | |
| 327 | |
| 328 static CGFloat LeftMargin(NSRect superFrame, NSRect subFrame) { | |
|
viettrungluu
2010/12/14 00:19:50
Just define these directly at the top.
sail
2010/12/14 01:59:53
Done.
| |
| 329 return NSMinX(subFrame) - NSMinX(superFrame); | |
| 330 } | |
| 331 | |
| 332 static CGFloat RightMargin(NSRect superFrame, NSRect subFrame) { | |
| 333 return NSMaxX(superFrame) - NSMaxX(subFrame); | |
| 334 } | |
| 335 | |
| 268 } // namespace | 336 } // namespace |
| OLD | NEW |