contents_scaling_layer_unittest.cc revision b2df76ea8fec9e32f6f3718986dba0d95315b29c
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      device_scale,
45      1.f,
46      NULL,
47      1024,
48      false,
49      false,
50      &render_surface_layer_list);
51}
52
53TEST(ContentsScalingLayerTest, CheckContentsBounds) {
54  scoped_refptr<MockContentsScalingLayer> test_layer =
55      make_scoped_refptr(new MockContentsScalingLayer());
56
57  scoped_refptr<Layer> root = Layer::Create();
58  root->AddChild(test_layer);
59
60  test_layer->SetBounds(gfx::Size(320, 240));
61  CalcDrawProps(root, 1.f);
62  EXPECT_FLOAT_EQ(1.f, test_layer->contents_scale_x());
63  EXPECT_FLOAT_EQ(1.f, test_layer->contents_scale_y());
64  EXPECT_EQ(320, test_layer->content_bounds().width());
65  EXPECT_EQ(240, test_layer->content_bounds().height());
66
67  CalcDrawProps(root, 2.f);
68  EXPECT_EQ(640, test_layer->content_bounds().width());
69  EXPECT_EQ(480, test_layer->content_bounds().height());
70
71  test_layer->SetBounds(gfx::Size(10, 20));
72  CalcDrawProps(root, 2.f);
73  EXPECT_EQ(20, test_layer->content_bounds().width());
74  EXPECT_EQ(40, test_layer->content_bounds().height());
75
76  CalcDrawProps(root, 1.33f);
77  EXPECT_EQ(14, test_layer->content_bounds().width());
78  EXPECT_EQ(27, test_layer->content_bounds().height());
79}
80
81}  // namespace
82}  // namespace cc
83