summaryrefslogtreecommitdiffstats
path: root/cc/contents_scaling_layer_unittest.cc
blob: 1825641643e9ee57618efde9dcac8bd780a41c0d (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
77
78
// Copyright 2012 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 "cc/contents_scaling_layer.h"

#include "cc/test/geometry_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace cc {
namespace {

class MockContentsScalingLayer : public ContentsScalingLayer {
 public:
  MockContentsScalingLayer()
      : ContentsScalingLayer() {
  }

  virtual void setNeedsDisplayRect(const gfx::RectF& dirtyRect) OVERRIDE {
    m_lastNeedsDisplayRect = dirtyRect;
    ContentsScalingLayer::setNeedsDisplayRect(dirtyRect);
  }

  void resetNeedsDisplay() {
      m_needsDisplay = false;
  }

  const gfx::RectF& lastNeedsDisplayRect() const {
    return m_lastNeedsDisplayRect;
  }

 private:
  virtual ~MockContentsScalingLayer() {
  }

  gfx::RectF m_lastNeedsDisplayRect;
};

TEST(ContentsScalingLayerTest, checkContentsBounds) {
  scoped_refptr<MockContentsScalingLayer> testLayer =
      make_scoped_refptr(new MockContentsScalingLayer());

  testLayer->setBounds(gfx::Size(320, 240));
  EXPECT_FLOAT_EQ(1.0, testLayer->contentsScaleX());
  EXPECT_FLOAT_EQ(1.0, testLayer->contentsScaleY());
  EXPECT_EQ(320, testLayer->contentBounds().width());
  EXPECT_EQ(240, testLayer->contentBounds().height());

  testLayer->setContentsScale(2.0f);
  EXPECT_EQ(640, testLayer->contentBounds().width());
  EXPECT_EQ(480, testLayer->contentBounds().height());

  testLayer->setBounds(gfx::Size(10, 20));
  EXPECT_EQ(20, testLayer->contentBounds().width());
  EXPECT_EQ(40, testLayer->contentBounds().height());

  testLayer->setContentsScale(1.33f);
  EXPECT_EQ(14, testLayer->contentBounds().width());
  EXPECT_EQ(27, testLayer->contentBounds().height());
}

TEST(ContentsScalingLayerTest, checkContentsScaleChangeTriggersNeedsDisplay) {
  scoped_refptr<MockContentsScalingLayer> testLayer =
      make_scoped_refptr(new MockContentsScalingLayer());

  testLayer->setBounds(gfx::Size(320, 240));

  testLayer->resetNeedsDisplay();
  EXPECT_FALSE(testLayer->needsDisplay());

  testLayer->setContentsScale(testLayer->contentsScaleX() + 1.f);
  EXPECT_TRUE(testLayer->needsDisplay());
  EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 320, 240),
                       testLayer->lastNeedsDisplayRect());
}

}  // namespace
}  // namespace cc