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