| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/ui/cocoa/autofill/simple_grid_layout.h" | 5 #include "chrome/browser/ui/cocoa/autofill/simple_grid_layout.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 // Layout objects as multiple columns in a single row. | 13 // Layout objects as multiple columns in a single row. |
| 14 class ColumnLayout : public SimpleGridLayout { | 14 class ColumnLayout : public SimpleGridLayout { |
| 15 public: | 15 public: |
| 16 ColumnLayout(NSView* host) : SimpleGridLayout(host) { AddRow(); } | 16 ColumnLayout(NSView* host) : SimpleGridLayout(host) { AddRow(); } |
| 17 ~ColumnLayout() {} | 17 ~ColumnLayout() {} |
| 18 }; | 18 }; |
| 19 | 19 |
| 20 class LayoutTest : public testing::Test { | 20 class LayoutTest : public testing::Test { |
| 21 public: | 21 public: |
| 22 base::scoped_nsobject<NSView> CreateViewWithWidth(float width) { | 22 base::scoped_nsobject<NSView> CreateViewWithWidth(float width) { |
| 23 NSRect frame = NSMakeRect(0, 0, width, 0); | 23 // Height of 1, since empty rects become 0x0 when run by NSIntegralRect. |
| 24 NSRect frame = NSMakeRect(0, 0, width, 1); |
| 24 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:frame]); | 25 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:frame]); |
| 25 return view; | 26 return view; |
| 26 } | 27 } |
| 27 | 28 |
| 29 // Width of 1, since empty rects become 0x0 when run by NSIntegralRect. |
| 28 base::scoped_nsobject<NSView> CreateViewWithHeight(float height) { | 30 base::scoped_nsobject<NSView> CreateViewWithHeight(float height) { |
| 29 NSRect frame = NSMakeRect(0, 0, 0, height); | 31 NSRect frame = NSMakeRect(0, 0, 1, height); |
| 30 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:frame]); | 32 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:frame]); |
| 31 return view; | 33 return view; |
| 32 } | 34 } |
| 33 }; | 35 }; |
| 34 | 36 |
| 35 TEST_F(LayoutTest, GridLayoutAddGetColumnSet) { | 37 TEST_F(LayoutTest, GridLayoutAddGetColumnSet) { |
| 36 SimpleGridLayout layout(NULL); | 38 SimpleGridLayout layout(NULL); |
| 37 | 39 |
| 38 // Non-existing id's are not found. | 40 // Non-existing id's are not found. |
| 39 EXPECT_EQ(0L, layout.GetColumnSet(1)); | 41 EXPECT_EQ(0L, layout.GetColumnSet(1)); |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 EXPECT_FLOAT_EQ(20.0f, columns.GetColumnWidth(1)); | 390 EXPECT_FLOAT_EQ(20.0f, columns.GetColumnWidth(1)); |
| 389 EXPECT_FLOAT_EQ(32.0f, columns.GetColumnWidth(2)); | 391 EXPECT_FLOAT_EQ(32.0f, columns.GetColumnWidth(2)); |
| 390 | 392 |
| 391 columns.CalculateSize(200.0f); | 393 columns.CalculateSize(200.0f); |
| 392 EXPECT_FLOAT_EQ(108.0f, columns.GetColumnWidth(0)); | 394 EXPECT_FLOAT_EQ(108.0f, columns.GetColumnWidth(0)); |
| 393 EXPECT_FLOAT_EQ(20.0f, columns.GetColumnWidth(1)); | 395 EXPECT_FLOAT_EQ(20.0f, columns.GetColumnWidth(1)); |
| 394 EXPECT_FLOAT_EQ(72.0f, columns.GetColumnWidth(2)); | 396 EXPECT_FLOAT_EQ(72.0f, columns.GetColumnWidth(2)); |
| 395 } | 397 } |
| 396 | 398 |
| 397 } // namespace | 399 } // namespace |
| OLD | NEW |