contents_scaling_layer_unittest.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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/layers/contents_scaling_layer.h"
6
7#include <vector>
8
9#include "cc/test/geometry_test_utils.h"
10#include "testing/gtest/include/gtest/gtest.h"
11
12namespace cc {
13namespace {
14
15class MockContentsScalingLayer : public ContentsScalingLayer {
16 public:
17  MockContentsScalingLayer()
18      : ContentsScalingLayer() {}
19
20  virtual void SetNeedsDisplayRect(const gfx::RectF& dirty_rect) OVERRIDE {
21    last_needs_display_rect_ = dirty_rect;
22    ContentsScalingLayer::SetNeedsDisplayRect(dirty_rect);
23  }
24
25  void ResetNeedsDisplay() {
26    needs_display_ = false;
27  }
28
29  const gfx::RectF& LastNeedsDisplayRect() const {
30    return last_needs_display_rect_;
31  }
32
33 private:
34  virtual ~MockContentsScalingLayer() {}
35
36  gfx::RectF last_needs_display_rect_;
37};
38
39void CalcDrawProps(Layer* root, float device_scale) {
40  LayerList render_surface_layer_list;
41  LayerTreeHostCommon::CalculateDrawProperties(
42      root,
43      gfx::Size(500, 500),
44      gfx::Transform(),
45      device_scale,
46      1.f,
47      NULL,
48      1024,
49      false,
50      false,
51      &render_surface_layer_list);
52}
53
54TEST(ContentsScalingLayerTest, CheckContentsBounds) {
55  scoped_refptr<MockContentsScalingLayer> test_layer =
56      make_scoped_refptr(new MockContentsScalingLayer());
57
58  scoped_refptr<Layer> root = Layer::Create();
59  root->AddChild(test_layer);
60
61  test_layer->SetBounds(gfx::Size(320, 240));
62  CalcDrawProps(root.get(), 1.f);
63  EXPECT_FLOAT_EQ(1.f, test_layer->contents_scale_x());
64  EXPECT_FLOAT_EQ(1.f, test_layer->contents_scale_y());
65  EXPECT_EQ(320, test_layer->content_bounds().width());
66  EXPECT_EQ(240, test_layer->content_bounds().height());
67
68  CalcDrawProps(root.get(), 2.f);
69  EXPECT_EQ(640, test_layer->content_bounds().width());
70  EXPECT_EQ(480, test_layer->content_bounds().height());
71
72  test_layer->SetBounds(gfx::Size(10, 20));
73  CalcDrawProps(root.get(), 2.f);
74  EXPECT_EQ(20, test_layer->content_bounds().width());
75  EXPECT_EQ(40, test_layer->content_bounds().height());
76
77  CalcDrawProps(root.get(), 1.33f);
78  EXPECT_EQ(14, test_layer->content_bounds().width());
79  EXPECT_EQ(27, test_layer->content_bounds().height());
80}
81
82}  // namespace
83}  // namespace cc
84