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.
5 #include "cc/layers/contents_scaling_layer.h"
9 #include "cc/test/fake_layer_tree_host.h"
10 #include "cc/test/geometry_test_utils.h"
11 #include "testing/gtest/include/gtest/gtest.h"
16 class MockContentsScalingLayer
: public ContentsScalingLayer
{
18 MockContentsScalingLayer()
19 : ContentsScalingLayer() {}
21 virtual void SetNeedsDisplayRect(const gfx::RectF
& dirty_rect
) OVERRIDE
{
22 last_needs_display_rect_
= dirty_rect
;
23 ContentsScalingLayer::SetNeedsDisplayRect(dirty_rect
);
26 const gfx::RectF
& LastNeedsDisplayRect() const {
27 return last_needs_display_rect_
;
31 virtual ~MockContentsScalingLayer() {}
33 gfx::RectF last_needs_display_rect_
;
36 static void CalcDrawProps(FakeLayerTreeHost
* host
, float device_scale_factor
) {
37 RenderSurfaceLayerList render_surface_layer_list
;
38 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting
inputs(
39 host
->root_layer(), gfx::Size(500, 500), &render_surface_layer_list
);
40 inputs
.device_scale_factor
= device_scale_factor
;
41 LayerTreeHostCommon::CalculateDrawProperties(&inputs
);
44 TEST(ContentsScalingLayerTest
, CheckContentsBounds
) {
45 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
47 scoped_refptr
<MockContentsScalingLayer
> test_layer
=
48 make_scoped_refptr(new MockContentsScalingLayer());
50 scoped_refptr
<Layer
> root
= Layer::Create();
51 root
->AddChild(test_layer
);
52 host
->SetRootLayer(root
);
54 test_layer
->SetBounds(gfx::Size(320, 240));
56 CalcDrawProps(host
.get(), 1.f
);
57 EXPECT_FLOAT_EQ(1.f
, test_layer
->contents_scale_x());
58 EXPECT_FLOAT_EQ(1.f
, test_layer
->contents_scale_y());
59 EXPECT_EQ(320, test_layer
->content_bounds().width());
60 EXPECT_EQ(240, test_layer
->content_bounds().height());
62 CalcDrawProps(host
.get(), 2.f
);
63 EXPECT_EQ(640, test_layer
->content_bounds().width());
64 EXPECT_EQ(480, test_layer
->content_bounds().height());
66 test_layer
->SetBounds(gfx::Size(10, 20));
67 CalcDrawProps(host
.get(), 2.f
);
68 EXPECT_EQ(20, test_layer
->content_bounds().width());
69 EXPECT_EQ(40, test_layer
->content_bounds().height());
71 CalcDrawProps(host
.get(), 1.33f
);
72 EXPECT_EQ(14, test_layer
->content_bounds().width());
73 EXPECT_EQ(27, test_layer
->content_bounds().height());