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

Side by Side Diff: cc/contents_scaling_layer_unittest.cc

Issue 12603013: Part 10 of cc/ directory shuffles: layers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months 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/debug/debug_rect_history.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "cc/contents_scaling_layer.h"
6
7 #include "cc/test/geometry_test_utils.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace cc {
11 namespace {
12
13 class MockContentsScalingLayer : public ContentsScalingLayer {
14 public:
15 MockContentsScalingLayer()
16 : ContentsScalingLayer() {}
17
18 virtual void SetNeedsDisplayRect(const gfx::RectF& dirty_rect) OVERRIDE {
19 last_needs_display_rect_ = dirty_rect;
20 ContentsScalingLayer::SetNeedsDisplayRect(dirty_rect);
21 }
22
23 void ResetNeedsDisplay() {
24 needs_display_ = false;
25 }
26
27 const gfx::RectF& LastNeedsDisplayRect() const {
28 return last_needs_display_rect_;
29 }
30
31 void UpdateContentsScale(float contents_scale) {
32 // Simulate CalcDrawProperties.
33 CalculateContentsScale(
34 contents_scale,
35 false, // animating_transform_to_screen
36 &draw_properties().contents_scale_x,
37 &draw_properties().contents_scale_y,
38 &draw_properties().content_bounds);
39 }
40
41 private:
42 virtual ~MockContentsScalingLayer() {}
43
44 gfx::RectF last_needs_display_rect_;
45 };
46
47 void CalcDrawProps(Layer* root, float device_scale) {
48 std::vector<scoped_refptr<Layer> > render_surface_layer_list;
49 LayerTreeHostCommon::calculateDrawProperties(
50 root,
51 gfx::Size(500, 500),
52 device_scale,
53 1.f,
54 1024,
55 false,
56 render_surface_layer_list);
57 }
58
59 TEST(ContentsScalingLayerTest, CheckContentsBounds) {
60 scoped_refptr<MockContentsScalingLayer> test_layer =
61 make_scoped_refptr(new MockContentsScalingLayer());
62
63 scoped_refptr<Layer> root = Layer::Create();
64 root->AddChild(test_layer);
65
66 test_layer->SetBounds(gfx::Size(320, 240));
67 CalcDrawProps(root, 1.f);
68 EXPECT_FLOAT_EQ(1.f, test_layer->contents_scale_x());
69 EXPECT_FLOAT_EQ(1.f, test_layer->contents_scale_y());
70 EXPECT_EQ(320, test_layer->content_bounds().width());
71 EXPECT_EQ(240, test_layer->content_bounds().height());
72
73 CalcDrawProps(root, 2.f);
74 EXPECT_EQ(640, test_layer->content_bounds().width());
75 EXPECT_EQ(480, test_layer->content_bounds().height());
76
77 test_layer->SetBounds(gfx::Size(10, 20));
78 CalcDrawProps(root, 2.f);
79 EXPECT_EQ(20, test_layer->content_bounds().width());
80 EXPECT_EQ(40, test_layer->content_bounds().height());
81
82 CalcDrawProps(root, 1.33f);
83 EXPECT_EQ(14, test_layer->content_bounds().width());
84 EXPECT_EQ(27, test_layer->content_bounds().height());
85 }
86
87 } // namespace
88 } // namespace cc
OLDNEW
« no previous file with comments | « cc/contents_scaling_layer.cc ('k') | cc/debug/debug_rect_history.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698