OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/contents_scaling_layer.h" | 7 #include "cc/contents_scaling_layer.h" |
8 | 8 |
9 #include "cc/test/geometry_test_utils.h" | 9 #include "cc/test/geometry_test_utils.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 using namespace cc; | 12 using namespace cc; |
13 | 13 |
14 class MockContentsScalingLayer : public ContentsScalingLayer { | 14 class MockContentsScalingLayer : public ContentsScalingLayer { |
15 public: | 15 public: |
16 MockContentsScalingLayer() | 16 MockContentsScalingLayer() |
17 : ContentsScalingLayer() { | 17 : ContentsScalingLayer() { |
18 } | 18 } |
19 | 19 |
20 virtual void setNeedsDisplayRect(const FloatRect& dirtyRect) OVERRIDE { | 20 virtual void setNeedsDisplayRect(const gfx::RectF& dirtyRect) OVERRIDE { |
21 m_lastNeedsDisplayRect = dirtyRect; | 21 m_lastNeedsDisplayRect = dirtyRect; |
22 ContentsScalingLayer::setNeedsDisplayRect(dirtyRect); | 22 ContentsScalingLayer::setNeedsDisplayRect(dirtyRect); |
23 } | 23 } |
24 | 24 |
25 void resetNeedsDisplay() { | 25 void resetNeedsDisplay() { |
26 m_needsDisplay = false; | 26 m_needsDisplay = false; |
27 } | 27 } |
28 | 28 |
29 const FloatRect& lastNeedsDisplayRect() const { | 29 const gfx::RectF& lastNeedsDisplayRect() const { |
30 return m_lastNeedsDisplayRect; | 30 return m_lastNeedsDisplayRect; |
31 } | 31 } |
32 | 32 |
33 private: | 33 private: |
34 virtual ~MockContentsScalingLayer() { | 34 virtual ~MockContentsScalingLayer() { |
35 } | 35 } |
36 | 36 |
37 FloatRect m_lastNeedsDisplayRect; | 37 gfx::RectF m_lastNeedsDisplayRect; |
38 }; | 38 }; |
39 | 39 |
40 TEST(ContentsScalingLayerTest, checkContentsBounds) { | 40 TEST(ContentsScalingLayerTest, checkContentsBounds) { |
41 scoped_refptr<MockContentsScalingLayer> testLayer = | 41 scoped_refptr<MockContentsScalingLayer> testLayer = |
42 make_scoped_refptr(new MockContentsScalingLayer()); | 42 make_scoped_refptr(new MockContentsScalingLayer()); |
43 | 43 |
44 testLayer->setBounds(IntSize(320, 240)); | 44 testLayer->setBounds(gfx::Size(320, 240)); |
45 EXPECT_FLOAT_EQ(1.0, testLayer->contentsScaleX()); | 45 EXPECT_FLOAT_EQ(1.0, testLayer->contentsScaleX()); |
46 EXPECT_FLOAT_EQ(1.0, testLayer->contentsScaleY()); | 46 EXPECT_FLOAT_EQ(1.0, testLayer->contentsScaleY()); |
47 EXPECT_EQ(320, testLayer->contentBounds().width()); | 47 EXPECT_EQ(320, testLayer->contentBounds().width()); |
48 EXPECT_EQ(240, testLayer->contentBounds().height()); | 48 EXPECT_EQ(240, testLayer->contentBounds().height()); |
49 | 49 |
50 testLayer->setContentsScale(2.0f); | 50 testLayer->setContentsScale(2.0f); |
51 EXPECT_EQ(640, testLayer->contentBounds().width()); | 51 EXPECT_EQ(640, testLayer->contentBounds().width()); |
52 EXPECT_EQ(480, testLayer->contentBounds().height()); | 52 EXPECT_EQ(480, testLayer->contentBounds().height()); |
53 | 53 |
54 testLayer->setBounds(IntSize(10, 20)); | 54 testLayer->setBounds(gfx::Size(10, 20)); |
55 EXPECT_EQ(20, testLayer->contentBounds().width()); | 55 EXPECT_EQ(20, testLayer->contentBounds().width()); |
56 EXPECT_EQ(40, testLayer->contentBounds().height()); | 56 EXPECT_EQ(40, testLayer->contentBounds().height()); |
57 | 57 |
58 testLayer->setContentsScale(1.33f); | 58 testLayer->setContentsScale(1.33f); |
59 EXPECT_EQ(14, testLayer->contentBounds().width()); | 59 EXPECT_EQ(14, testLayer->contentBounds().width()); |
60 EXPECT_EQ(27, testLayer->contentBounds().height()); | 60 EXPECT_EQ(27, testLayer->contentBounds().height()); |
61 } | 61 } |
62 | 62 |
63 TEST(ContentsScalingLayerTest, checkContentsScaleChangeTriggersNeedsDisplay) { | 63 TEST(ContentsScalingLayerTest, checkContentsScaleChangeTriggersNeedsDisplay) { |
64 scoped_refptr<MockContentsScalingLayer> testLayer = | 64 scoped_refptr<MockContentsScalingLayer> testLayer = |
65 make_scoped_refptr(new MockContentsScalingLayer()); | 65 make_scoped_refptr(new MockContentsScalingLayer()); |
66 | 66 |
67 testLayer->setBounds(IntSize(320, 240)); | 67 testLayer->setBounds(gfx::Size(320, 240)); |
68 | 68 |
69 testLayer->resetNeedsDisplay(); | 69 testLayer->resetNeedsDisplay(); |
70 EXPECT_FALSE(testLayer->needsDisplay()); | 70 EXPECT_FALSE(testLayer->needsDisplay()); |
71 | 71 |
72 testLayer->setContentsScale(testLayer->contentsScaleX() + 1.f); | 72 testLayer->setContentsScale(testLayer->contentsScaleX() + 1.f); |
73 EXPECT_TRUE(testLayer->needsDisplay()); | 73 EXPECT_TRUE(testLayer->needsDisplay()); |
74 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 320, 240), | 74 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 320, 240), |
75 testLayer->lastNeedsDisplayRect()); | 75 testLayer->lastNeedsDisplayRect()); |
76 } | 76 } |
OLD | NEW |