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