Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #import "chrome/browser/ui/cocoa/autofill/autofill_layout_view.h" | |
| 6 | |
| 7 #include "base/memory/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" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 class AutofillLayoutViewTest : public ui::CocoaTest { | |
| 16 public: | |
| 17 virtual void SetUp() { | |
| 18 CocoaTest::SetUp(); | |
| 19 view_.reset([[AutofillLayoutView alloc] initWithFrame:NSZeroRect]); | |
| 20 layout_ = new SimpleGridLayout(view_); | |
| 21 [view_ setLayoutManager:layout_]; | |
| 22 | |
| 23 [[test_window() contentView] addSubview:view_]; | |
| 24 } | |
| 25 | |
| 26 protected: | |
| 27 scoped_nsobject<AutofillLayoutView> view_; | |
| 28 SimpleGridLayout* layout_; // weak, owned by view_. | |
|
sail
2013/05/01 17:12:36
how about adding an accessor in AutofillLayoutView
groby-ooo-7-16
2013/05/01 20:37:44
Added accessor. Still keeping the pointer for conv
| |
| 29 }; | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 TEST_VIEW(AutofillLayoutViewTest, view_) | |
| 34 | |
| 35 TEST_F(AutofillLayoutViewTest, setFrameInvokesLayout) { | |
| 36 EXPECT_FLOAT_EQ(0, NSWidth([view_ frame])); | |
| 37 EXPECT_FLOAT_EQ(0, NSHeight([view_ frame])); | |
| 38 | |
| 39 ColumnSet* cs = layout_->AddColumnSet(0); | |
| 40 cs->AddColumn(0.4); | |
| 41 cs->AddColumn(0.6); | |
| 42 layout_->StartRow(0, 0); | |
| 43 scoped_nsobject<NSView> childView1( | |
| 44 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 0, 45)]); | |
| 45 scoped_nsobject<NSView> childView2( | |
| 46 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 20, 55)]); | |
| 47 layout_->AddView(childView1); | |
| 48 layout_->AddView(childView2); | |
| 49 | |
| 50 ASSERT_EQ(2U, [[view_ subviews] count]); | |
| 51 EXPECT_FLOAT_EQ(0, NSWidth([view_ frame])); | |
| 52 EXPECT_FLOAT_EQ(0, NSHeight([view_ frame])); | |
| 53 | |
| 54 [view_ setFrame:NSMakeRect(0, 0, 40, 60)]; | |
| 55 EXPECT_FLOAT_EQ(40, NSWidth([view_ frame])); | |
| 56 EXPECT_FLOAT_EQ(60, NSHeight([view_ frame])); | |
| 57 | |
| 58 NSView* subview = [[view_ subviews] objectAtIndex:0]; | |
| 59 EXPECT_FLOAT_EQ(16, NSWidth([subview frame])); | |
| 60 EXPECT_FLOAT_EQ(55, NSHeight([subview frame])); | |
| 61 | |
| 62 subview = [[view_ subviews] objectAtIndex:1]; | |
| 63 EXPECT_FLOAT_EQ(24, NSWidth([subview frame])); | |
| 64 EXPECT_FLOAT_EQ(55, NSHeight([subview frame])); | |
| 65 } | |
| OLD | NEW |