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 3 // found in the LICENSE file. 4 5 #include "base/memory/scoped_nsobject.h" 6 #import "chrome/browser/ui/cocoa/fast_resize_view.h" 7 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 8 9 namespace { 10 11 class FastResizeViewTest : public CocoaTest { 12 public: 13 FastResizeViewTest() { 14 NSRect frame = NSMakeRect(0, 0, 100, 30); 15 scoped_nsobject<FastResizeView> view( 16 [[FastResizeView alloc] initWithFrame:frame]); 17 view_ = view.get(); 18 [[test_window() contentView] addSubview:view_]; 19 20 scoped_nsobject<NSView> childView([[NSView alloc] initWithFrame:frame]); 21 childView_ = childView.get(); 22 [view_ addSubview:childView_]; 23 } 24 25 FastResizeView* view_; 26 NSView* childView_; 27 }; 28 29 TEST_VIEW(FastResizeViewTest, view_); 30 31 TEST_F(FastResizeViewTest, TestResizingOfChildren) { 32 NSRect squareFrame = NSMakeRect(0, 0, 200, 200); 33 NSRect rectFrame = NSMakeRect(1, 1, 150, 300); 34 35 // Test that changing the view's frame also changes the child's frame. 36 [view_ setFrame:squareFrame]; 37 EXPECT_TRUE(NSEqualRects([view_ bounds], [childView_ frame])); 38 39 // Turn fast resize mode on and change the view's frame. This time, the child 40 // should not resize, but it should be anchored to the top left. 41 [view_ setFastResizeMode:YES]; 42 [view_ setFrame:NSMakeRect(15, 30, 250, 250)]; 43 EXPECT_TRUE(NSEqualSizes([childView_ frame].size, squareFrame.size)); 44 EXPECT_EQ(NSMinX([view_ bounds]), NSMinX([childView_ frame])); 45 EXPECT_EQ(NSMaxY([view_ bounds]), NSMaxY([childView_ frame])); 46 47 // Another resize with fast resize mode on. 48 [view_ setFrame:rectFrame]; 49 EXPECT_TRUE(NSEqualSizes([childView_ frame].size, squareFrame.size)); 50 EXPECT_EQ(NSMinX([view_ bounds]), NSMinX([childView_ frame])); 51 EXPECT_EQ(NSMaxY([view_ bounds]), NSMaxY([childView_ frame])); 52 53 // Turn fast resize mode off. This should initiate an immediate resize, even 54 // though we haven't called setFrame directly. 55 [view_ setFastResizeMode:NO]; 56 EXPECT_TRUE(NSEqualRects([view_ frame], rectFrame)); 57 EXPECT_TRUE(NSEqualRects([view_ bounds], [childView_ frame])); 58 } 59 60 } // namespace 61