contents_scaling_layer_unittest.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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 void UpdateContentsScale(float contents_scale) { 34 // Simulate CalcDrawProperties. 35 CalculateContentsScale( 36 contents_scale, 37 false, // animating_transform_to_screen 38 &draw_properties().contents_scale_x, 39 &draw_properties().contents_scale_y, 40 &draw_properties().content_bounds); 41 } 42 43 private: 44 virtual ~MockContentsScalingLayer() {} 45 46 gfx::RectF last_needs_display_rect_; 47}; 48 49void CalcDrawProps(Layer* root, float device_scale) { 50 LayerList render_surface_layer_list; 51 LayerTreeHostCommon::CalculateDrawProperties( 52 root, 53 gfx::Size(500, 500), 54 device_scale, 55 1.f, 56 NULL, 57 1024, 58 false, 59 &render_surface_layer_list); 60} 61 62TEST(ContentsScalingLayerTest, CheckContentsBounds) { 63 scoped_refptr<MockContentsScalingLayer> test_layer = 64 make_scoped_refptr(new MockContentsScalingLayer()); 65 66 scoped_refptr<Layer> root = Layer::Create(); 67 root->AddChild(test_layer); 68 69 test_layer->SetBounds(gfx::Size(320, 240)); 70 CalcDrawProps(root, 1.f); 71 EXPECT_FLOAT_EQ(1.f, test_layer->contents_scale_x()); 72 EXPECT_FLOAT_EQ(1.f, test_layer->contents_scale_y()); 73 EXPECT_EQ(320, test_layer->content_bounds().width()); 74 EXPECT_EQ(240, test_layer->content_bounds().height()); 75 76 CalcDrawProps(root, 2.f); 77 EXPECT_EQ(640, test_layer->content_bounds().width()); 78 EXPECT_EQ(480, test_layer->content_bounds().height()); 79 80 test_layer->SetBounds(gfx::Size(10, 20)); 81 CalcDrawProps(root, 2.f); 82 EXPECT_EQ(20, test_layer->content_bounds().width()); 83 EXPECT_EQ(40, test_layer->content_bounds().height()); 84 85 CalcDrawProps(root, 1.33f); 86 EXPECT_EQ(14, test_layer->content_bounds().width()); 87 EXPECT_EQ(27, test_layer->content_bounds().height()); 88} 89 90} // namespace 91} // namespace cc 92