summaryrefslogtreecommitdiffstats
path: root/ui/views/rendering/border_unittest.cc
blob: 2b7740de07e0558647c98179e1213f3ea8f091d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <algorithm>

#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/canvas.h"
#include "ui/views/rendering/border.h"
#include "ui/views/view.h"

namespace ui {

class BorderTest : public testing::Test {
 public:
  BorderTest() {}
  virtual ~BorderTest() {}

 private:
  DISALLOW_COPY_AND_ASSIGN(BorderTest);
};

class TestBorder : public Border {
 public:
  TestBorder() : painted_(false) {}

  bool painted() const { return painted_; }

  // Overridden from Border:
  virtual void Paint(const View* view, gfx::Canvas* canvas) const {
    painted_ = true;
  }

 private:
  mutable bool painted_;

  DISALLOW_COPY_AND_ASSIGN(TestBorder);
};

class PaintableView : public View {
 public:
  PaintableView() {}
  virtual ~PaintableView() {}

  void CallOnPaintWithNULLCanvas() {
    OnPaint(NULL);
  }

 private:
  DISALLOW_COPY_AND_ASSIGN(PaintableView);
};

TEST_F(BorderTest, Basic) {
  const int kViewSize = 100;
  PaintableView v;
  v.SetBounds(10, 10, kViewSize, kViewSize);

  // With no border, the content size is the view size.
  EXPECT_EQ(gfx::Rect(0, 0, kViewSize, kViewSize), v.GetContentsBounds());

  const int kViewInset = 10;
  v.SetBorder(Border::CreateTransparentBorder(
      gfx::Insets(kViewInset, kViewInset, kViewInset, kViewInset)));

  // With the border, the content bounds are inset by the border's insets.
  EXPECT_EQ(gfx::Rect(kViewInset, kViewInset, kViewSize - 2 * kViewInset,
                      kViewSize - 2 * kViewInset),
            v.GetContentsBounds());

  TestBorder* border = new TestBorder;
  v.SetBorder(border);
  v.CallOnPaintWithNULLCanvas();
  EXPECT_TRUE(border->painted());
}

}  // namespace ui