OLD | NEW |
(Empty) | |
| 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 <algorithm> |
| 6 |
| 7 #include "gfx/canvas.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/views/rendering/border.h" |
| 10 #include "ui/views/view.h" |
| 11 |
| 12 namespace ui { |
| 13 |
| 14 class BorderTest : public testing::Test { |
| 15 public: |
| 16 BorderTest() {} |
| 17 virtual ~BorderTest() {} |
| 18 |
| 19 private: |
| 20 DISALLOW_COPY_AND_ASSIGN(BorderTest); |
| 21 }; |
| 22 |
| 23 class TestBorder : public Border { |
| 24 public: |
| 25 TestBorder() : painted_(false) {} |
| 26 |
| 27 bool painted() const { return painted_; } |
| 28 |
| 29 // Overridden from Border: |
| 30 virtual void Paint(const View* view, gfx::Canvas* canvas) const { |
| 31 painted_ = true; |
| 32 } |
| 33 |
| 34 private: |
| 35 mutable bool painted_; |
| 36 |
| 37 DISALLOW_COPY_AND_ASSIGN(TestBorder); |
| 38 }; |
| 39 |
| 40 TEST_F(BorderTest, Basic) { |
| 41 const int kViewSize = 100; |
| 42 View v; |
| 43 v.SetBounds(10, 10, kViewSize, kViewSize); |
| 44 |
| 45 // With no border, the content size is the view size. |
| 46 EXPECT_EQ(gfx::Rect(0, 0, kViewSize, kViewSize), v.GetContentsBounds()); |
| 47 |
| 48 const int kViewInset = 10; |
| 49 v.SetBorder(Border::CreateTransparentBorder( |
| 50 gfx::Insets(kViewInset, kViewInset, kViewInset, kViewInset))); |
| 51 |
| 52 // With the border, the content bounds are inset by the border's insets. |
| 53 EXPECT_EQ(gfx::Rect(kViewInset, kViewInset, kViewSize - 2 * kViewInset, |
| 54 kViewSize - 2 * kViewInset), |
| 55 v.GetContentsBounds()); |
| 56 |
| 57 TestBorder* border = new TestBorder; |
| 58 v.SetBorder(border); |
| 59 v.OnPaint(NULL); |
| 60 EXPECT_TRUE(border->painted()); |
| 61 } |
| 62 |
| 63 } // namespace ui |
OLD | NEW |