Fix flaky PDFExtensionTest
[chromium-blink-merge.git] / cc / layers / contents_scaling_layer_unittest.cc
blobefad2649ec16aaf6f26bb82e36343adf40aad03b
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"
7 #include <vector>
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"
13 namespace cc {
14 namespace {
16 class MockContentsScalingLayer : public ContentsScalingLayer {
17 public:
18 explicit MockContentsScalingLayer(const LayerSettings& settings)
19 : ContentsScalingLayer(settings) {}
21 void SetNeedsDisplayRect(const gfx::Rect& dirty_rect) override {
22 last_needs_display_rect_ = dirty_rect;
23 ContentsScalingLayer::SetNeedsDisplayRect(dirty_rect);
26 const gfx::Rect& LastNeedsDisplayRect() const {
27 return last_needs_display_rect_;
30 private:
31 ~MockContentsScalingLayer() override {}
33 gfx::Rect 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 LayerSettings layer_settings;
47 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
48 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
50 scoped_refptr<MockContentsScalingLayer> test_layer =
51 make_scoped_refptr(new MockContentsScalingLayer(layer_settings));
53 scoped_refptr<Layer> root = Layer::Create(layer_settings);
54 root->AddChild(test_layer);
55 host->SetRootLayer(root);
57 test_layer->SetBounds(gfx::Size(320, 240));
59 CalcDrawProps(host.get(), 1.f);
60 EXPECT_FLOAT_EQ(1.f, test_layer->contents_scale_x());
61 EXPECT_FLOAT_EQ(1.f, test_layer->contents_scale_y());
62 EXPECT_EQ(320, test_layer->content_bounds().width());
63 EXPECT_EQ(240, test_layer->content_bounds().height());
65 CalcDrawProps(host.get(), 2.f);
66 EXPECT_EQ(640, test_layer->content_bounds().width());
67 EXPECT_EQ(480, test_layer->content_bounds().height());
69 test_layer->SetBounds(gfx::Size(10, 20));
70 CalcDrawProps(host.get(), 2.f);
71 EXPECT_EQ(20, test_layer->content_bounds().width());
72 EXPECT_EQ(40, test_layer->content_bounds().height());
74 CalcDrawProps(host.get(), 1.33f);
75 EXPECT_EQ(14, test_layer->content_bounds().width());
76 EXPECT_EQ(27, test_layer->content_bounds().height());
79 } // namespace
80 } // namespace cc