1 // Copyright (c) 2013 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 #import "chrome/browser/ui/cocoa/autofill/layout_view.h"
7 #include "base/mac/scoped_nsobject.h"
8 #include "chrome/browser/ui/cocoa/autofill/simple_grid_layout.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/platform_test.h"
11 #import "ui/base/test/ui_cocoa_test_helper.h"
15 class LayoutViewTest : public ui::CocoaTest {
19 view_.reset([[LayoutView alloc] initWithFrame:NSZeroRect]);
20 [view_ setLayoutManager:
21 scoped_ptr<SimpleGridLayout>(new SimpleGridLayout(view_))];
22 layout_ = [view_ layoutManager];
23 [[test_window() contentView] addSubview:view_];
27 base::scoped_nsobject<LayoutView> view_;
28 SimpleGridLayout* layout_; // weak, owned by view_.
33 TEST_VIEW(LayoutViewTest, view_)
35 TEST_F(LayoutViewTest, setFrameInvokesLayout) {
36 EXPECT_FLOAT_EQ(0, NSWidth([view_ frame]));
37 EXPECT_FLOAT_EQ(0, NSHeight([view_ frame]));
39 ColumnSet* cs = layout_->AddColumnSet(0);
42 layout_->StartRow(0, 0);
43 base::scoped_nsobject<NSView> childView1(
44 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 0, 45)]);
45 base::scoped_nsobject<NSView> childView2(
46 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 20, 55)]);
47 layout_->AddView(childView1);
48 layout_->AddView(childView2);
50 ASSERT_EQ(2U, [[view_ subviews] count]);
51 EXPECT_FLOAT_EQ(0, NSWidth([view_ frame]));
52 EXPECT_FLOAT_EQ(0, NSHeight([view_ frame]));
54 [view_ setFrame:NSMakeRect(0, 0, 40, 60)];
55 EXPECT_FLOAT_EQ(40, NSWidth([view_ frame]));
56 EXPECT_FLOAT_EQ(60, NSHeight([view_ frame]));
58 NSView* subview = [[view_ subviews] objectAtIndex:0];
59 EXPECT_FLOAT_EQ(16, NSWidth([subview frame]));
60 EXPECT_FLOAT_EQ(55, NSHeight([subview frame]));
62 subview = [[view_ subviews] objectAtIndex:1];
63 EXPECT_FLOAT_EQ(24, NSWidth([subview frame]));
64 EXPECT_FLOAT_EQ(55, NSHeight([subview frame]));