Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: cc/contents_scaling_layer_unittest.cc

Issue 11503005: cc: Refactor content scale/bounds into draw properties (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/contents_scaling_layer.cc ('k') | cc/draw_properties.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "cc/contents_scaling_layer.h" 5 #include "cc/contents_scaling_layer.h"
6 6
7 #include "cc/test/geometry_test_utils.h" 7 #include "cc/test/geometry_test_utils.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace cc { 10 namespace cc {
11 namespace { 11 namespace {
12 12
13 class MockContentsScalingLayer : public ContentsScalingLayer { 13 class MockContentsScalingLayer : public ContentsScalingLayer {
14 public: 14 public:
15 MockContentsScalingLayer() 15 MockContentsScalingLayer()
16 : ContentsScalingLayer() { 16 : ContentsScalingLayer() {
17 } 17 }
18 18
19 virtual void setNeedsDisplayRect(const gfx::RectF& dirtyRect) OVERRIDE { 19 virtual void setNeedsDisplayRect(const gfx::RectF& dirtyRect) OVERRIDE {
20 m_lastNeedsDisplayRect = dirtyRect; 20 m_lastNeedsDisplayRect = dirtyRect;
21 ContentsScalingLayer::setNeedsDisplayRect(dirtyRect); 21 ContentsScalingLayer::setNeedsDisplayRect(dirtyRect);
22 } 22 }
23 23
24 void resetNeedsDisplay() { 24 void resetNeedsDisplay() {
25 m_needsDisplay = false; 25 m_needsDisplay = false;
26 } 26 }
27 27
28 const gfx::RectF& lastNeedsDisplayRect() const { 28 const gfx::RectF& lastNeedsDisplayRect() const {
29 return m_lastNeedsDisplayRect; 29 return m_lastNeedsDisplayRect;
30 }
31
32 void updateContentsScale(float contentsScale) {
33 // Simulate calcDrawProperties.
34 calculateContentsScale(
35 contentsScale,
36 &drawProperties().contents_scale_x,
37 &drawProperties().contents_scale_y,
38 &drawProperties().content_bounds);
30 } 39 }
31 40
32 private: 41 private:
33 virtual ~MockContentsScalingLayer() { 42 virtual ~MockContentsScalingLayer() {
34 } 43 }
35 44
36 gfx::RectF m_lastNeedsDisplayRect; 45 gfx::RectF m_lastNeedsDisplayRect;
37 }; 46 };
38 47
39 TEST(ContentsScalingLayerTest, checkContentsBounds) { 48 TEST(ContentsScalingLayerTest, checkContentsBounds) {
40 scoped_refptr<MockContentsScalingLayer> testLayer = 49 scoped_refptr<MockContentsScalingLayer> testLayer =
41 make_scoped_refptr(new MockContentsScalingLayer()); 50 make_scoped_refptr(new MockContentsScalingLayer());
42 51
43 testLayer->setBounds(gfx::Size(320, 240)); 52 testLayer->setBounds(gfx::Size(320, 240));
44 EXPECT_FLOAT_EQ(1.0, testLayer->contentsScaleX()); 53 EXPECT_FLOAT_EQ(1.0, testLayer->contentsScaleX());
45 EXPECT_FLOAT_EQ(1.0, testLayer->contentsScaleY()); 54 EXPECT_FLOAT_EQ(1.0, testLayer->contentsScaleY());
46 EXPECT_EQ(320, testLayer->contentBounds().width()); 55 EXPECT_EQ(320, testLayer->contentBounds().width());
47 EXPECT_EQ(240, testLayer->contentBounds().height()); 56 EXPECT_EQ(240, testLayer->contentBounds().height());
48 57
49 testLayer->setContentsScale(2.0f); 58 testLayer->updateContentsScale(2.0f);
50 EXPECT_EQ(640, testLayer->contentBounds().width()); 59 EXPECT_EQ(640, testLayer->contentBounds().width());
51 EXPECT_EQ(480, testLayer->contentBounds().height()); 60 EXPECT_EQ(480, testLayer->contentBounds().height());
52 61
53 testLayer->setBounds(gfx::Size(10, 20)); 62 testLayer->setBounds(gfx::Size(10, 20));
54 EXPECT_EQ(20, testLayer->contentBounds().width()); 63 EXPECT_EQ(20, testLayer->contentBounds().width());
55 EXPECT_EQ(40, testLayer->contentBounds().height()); 64 EXPECT_EQ(40, testLayer->contentBounds().height());
56 65
57 testLayer->setContentsScale(1.33f); 66 testLayer->updateContentsScale(1.33f);
58 EXPECT_EQ(14, testLayer->contentBounds().width()); 67 EXPECT_EQ(14, testLayer->contentBounds().width());
59 EXPECT_EQ(27, testLayer->contentBounds().height()); 68 EXPECT_EQ(27, testLayer->contentBounds().height());
60 } 69 }
61 70
62 TEST(ContentsScalingLayerTest, checkContentsScaleChangeTriggersNeedsDisplay) {
63 scoped_refptr<MockContentsScalingLayer> testLayer =
64 make_scoped_refptr(new MockContentsScalingLayer());
65
66 testLayer->setBounds(gfx::Size(320, 240));
67
68 testLayer->resetNeedsDisplay();
69 EXPECT_FALSE(testLayer->needsDisplay());
70
71 testLayer->setContentsScale(testLayer->contentsScaleX() + 1.f);
72 EXPECT_TRUE(testLayer->needsDisplay());
73 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 320, 240),
74 testLayer->lastNeedsDisplayRect());
75 }
76
77 } // namespace 71 } // namespace
78 } // namespace cc 72 } // namespace cc
OLDNEW
« no previous file with comments | « cc/contents_scaling_layer.cc ('k') | cc/draw_properties.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698