Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: cc/blink/web_layer_impl_fixed_bounds_unittest.cc

Issue 2347343002: cc_blink: Fix a leak in web layer impl fixed bounds test. (Closed)
Patch Set: update Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/blink/web_layer_impl_fixed_bounds.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 #include "cc/blink/web_layer_impl_fixed_bounds.h" 6 #include "cc/blink/web_layer_impl_fixed_bounds.h"
7 #include "cc/layers/picture_image_layer.h" 7 #include "cc/layers/picture_image_layer.h"
8 #include "cc/test/fake_layer_tree_host.h" 8 #include "cc/test/fake_layer_tree_host.h"
9 #include "cc/test/geometry_test_utils.h" 9 #include "cc/test/geometry_test_utils.h"
10 #include "cc/test/test_task_graph_runner.h" 10 #include "cc/test/test_task_graph_runner.h"
11 #include "cc/trees/layer_tree_host_common.h" 11 #include "cc/trees/layer_tree_host_common.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/WebKit/public/platform/WebFloatPoint.h" 13 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
14 #include "third_party/WebKit/public/platform/WebSize.h" 14 #include "third_party/WebKit/public/platform/WebSize.h"
15 #include "third_party/skia/include/core/SkMatrix44.h" 15 #include "third_party/skia/include/core/SkMatrix44.h"
16 #include "ui/gfx/geometry/point3_f.h" 16 #include "ui/gfx/geometry/point3_f.h"
17 17
18 using blink::WebFloatPoint; 18 using blink::WebFloatPoint;
19 using blink::WebSize; 19 using blink::WebSize;
20 20
21 namespace cc_blink { 21 namespace cc_blink {
22 namespace { 22 namespace {
23 23
24 TEST(WebLayerImplFixedBoundsTest, IdentityBounds) { 24 TEST(WebLayerImplFixedBoundsTest, IdentityBounds) {
25 std::unique_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds()); 25 WebLayerImplFixedBounds layer;
26 layer->SetFixedBounds(gfx::Size(100, 100)); 26 layer.SetFixedBounds(gfx::Size(100, 100));
27 layer->setBounds(WebSize(100, 100)); 27 layer.setBounds(WebSize(100, 100));
28 EXPECT_EQ(WebSize(100, 100), layer->bounds()); 28 EXPECT_EQ(WebSize(100, 100), layer.bounds());
29 EXPECT_EQ(gfx::Size(100, 100), layer->layer()->bounds()); 29 EXPECT_EQ(gfx::Size(100, 100), layer.layer()->bounds());
30 EXPECT_EQ(gfx::Transform(), layer->layer()->transform()); 30 EXPECT_EQ(gfx::Transform(), layer.layer()->transform());
31 } 31 }
32 32
33 gfx::Point3F TransformPoint(const gfx::Transform& transform, 33 gfx::Point3F TransformPoint(const gfx::Transform& transform,
34 const gfx::Point3F& point) { 34 const gfx::Point3F& point) {
35 gfx::Point3F result = point; 35 gfx::Point3F result = point;
36 transform.TransformPoint(&result); 36 transform.TransformPoint(&result);
37 return result; 37 return result;
38 } 38 }
39 39
40 void CheckBoundsScaleSimple(WebLayerImplFixedBounds* layer, 40 void CheckBoundsScaleSimple(WebLayerImplFixedBounds* layer,
(...skipping 11 matching lines...) Expand all
52 gfx::Point3F scaled_point( 52 gfx::Point3F scaled_point(
53 original_point.x() * bounds.width / fixed_bounds.width(), 53 original_point.x() * bounds.width / fixed_bounds.width(),
54 original_point.y() * bounds.height / fixed_bounds.height(), 54 original_point.y() * bounds.height / fixed_bounds.height(),
55 original_point.z()); 55 original_point.z());
56 // Test if the bounds scale is correctly applied in transform. 56 // Test if the bounds scale is correctly applied in transform.
57 EXPECT_POINT3F_EQ(scaled_point, TransformPoint(layer->layer()->transform(), 57 EXPECT_POINT3F_EQ(scaled_point, TransformPoint(layer->layer()->transform(),
58 original_point)); 58 original_point));
59 } 59 }
60 60
61 TEST(WebLayerImplFixedBoundsTest, BoundsScaleSimple) { 61 TEST(WebLayerImplFixedBoundsTest, BoundsScaleSimple) {
62 std::unique_ptr<WebLayerImplFixedBounds> layer(new WebLayerImplFixedBounds()); 62 WebLayerImplFixedBounds layer;
63 CheckBoundsScaleSimple(layer.get(), WebSize(100, 200), gfx::Size(150, 250)); 63 CheckBoundsScaleSimple(&layer, WebSize(100, 200), gfx::Size(150, 250));
64 // Change fixed_bounds. 64 // Change fixed_bounds.
65 CheckBoundsScaleSimple(layer.get(), WebSize(100, 200), gfx::Size(75, 100)); 65 CheckBoundsScaleSimple(&layer, WebSize(100, 200), gfx::Size(75, 100));
66 // Change bounds. 66 // Change bounds.
67 CheckBoundsScaleSimple(layer.get(), WebSize(300, 100), gfx::Size(75, 100)); 67 CheckBoundsScaleSimple(&layer, WebSize(300, 100), gfx::Size(75, 100));
68 } 68 }
69 69
70 void ExpectEqualLayerRectsInTarget(cc::Layer* layer1, cc::Layer* layer2) { 70 void ExpectEqualLayerRectsInTarget(cc::Layer* layer1, cc::Layer* layer2) {
71 gfx::RectF layer1_rect_in_target(gfx::SizeF(layer1->bounds())); 71 gfx::RectF layer1_rect_in_target(gfx::SizeF(layer1->bounds()));
72 layer1->screen_space_transform().TransformRect(&layer1_rect_in_target); 72 layer1->screen_space_transform().TransformRect(&layer1_rect_in_target);
73 73
74 gfx::RectF layer2_rect_in_target(gfx::SizeF(layer2->bounds())); 74 gfx::RectF layer2_rect_in_target(gfx::SizeF(layer2->bounds()));
75 layer2->screen_space_transform().TransformRect(&layer2_rect_in_target); 75 layer2->screen_space_transform().TransformRect(&layer2_rect_in_target);
76 76
77 EXPECT_FLOAT_RECT_EQ(layer1_rect_in_target, layer2_rect_in_target); 77 EXPECT_FLOAT_RECT_EQ(layer1_rect_in_target, layer2_rect_in_target);
78 } 78 }
79 79
80 void CompareFixedBoundsLayerAndNormalLayer(const WebFloatPoint& anchor_point, 80 void CompareFixedBoundsLayerAndNormalLayer(const WebFloatPoint& anchor_point,
81 const gfx::Transform& transform) { 81 const gfx::Transform& transform) {
82 const gfx::Size kDeviceViewportSize(800, 600); 82 const gfx::Size kDeviceViewportSize(800, 600);
83 const float kDeviceScaleFactor = 2.f; 83 const float kDeviceScaleFactor = 2.f;
84 const float kPageScaleFactor = 1.5f; 84 const float kPageScaleFactor = 1.5f;
85 85
86 WebSize bounds(150, 200); 86 WebSize bounds(150, 200);
87 WebFloatPoint position(20, 30); 87 WebFloatPoint position(20, 30);
88 gfx::Size fixed_bounds(160, 70); 88 gfx::Size fixed_bounds(160, 70);
89 89
90 std::unique_ptr<WebLayerImplFixedBounds> root_layer( 90 WebLayerImplFixedBounds root_layer;
91 new WebLayerImplFixedBounds());
92 91
93 WebLayerImplFixedBounds* fixed_bounds_layer = 92 WebLayerImplFixedBounds fixed_bounds_layer(cc::PictureImageLayer::Create());
94 new WebLayerImplFixedBounds(cc::PictureImageLayer::Create()); 93 fixed_bounds_layer.setBounds(bounds);
95 fixed_bounds_layer->setBounds(bounds); 94 fixed_bounds_layer.SetFixedBounds(fixed_bounds);
96 fixed_bounds_layer->SetFixedBounds(fixed_bounds); 95 fixed_bounds_layer.setTransform(transform.matrix());
97 fixed_bounds_layer->setTransform(transform.matrix()); 96 fixed_bounds_layer.setPosition(position);
98 fixed_bounds_layer->setPosition(position); 97 root_layer.addChild(&fixed_bounds_layer);
99 root_layer->addChild(fixed_bounds_layer);
100 98
101 WebLayerImpl* normal_layer(new WebLayerImpl(cc::PictureImageLayer::Create())); 99 WebLayerImpl normal_layer(cc::PictureImageLayer::Create());
102 100
103 normal_layer->setBounds(bounds); 101 normal_layer.setBounds(bounds);
104 normal_layer->setTransform(transform.matrix()); 102 normal_layer.setTransform(transform.matrix());
105 normal_layer->setPosition(position); 103 normal_layer.setPosition(position);
106 root_layer->addChild(normal_layer); 104 root_layer.addChild(&normal_layer);
107 105
108 cc::FakeLayerTreeHostClient client; 106 cc::FakeLayerTreeHostClient client;
109 cc::TestTaskGraphRunner task_graph_runner; 107 cc::TestTaskGraphRunner task_graph_runner;
110 std::unique_ptr<cc::FakeLayerTreeHost> host = 108 std::unique_ptr<cc::FakeLayerTreeHost> host =
111 cc::FakeLayerTreeHost::Create(&client, &task_graph_runner); 109 cc::FakeLayerTreeHost::Create(&client, &task_graph_runner);
112 host->SetRootLayer(root_layer->layer()); 110 host->SetRootLayer(root_layer.layer());
113 111
114 { 112 {
115 cc::LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( 113 cc::LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
116 root_layer->layer(), kDeviceViewportSize); 114 root_layer.layer(), kDeviceViewportSize);
117 inputs.device_scale_factor = kDeviceScaleFactor; 115 inputs.device_scale_factor = kDeviceScaleFactor;
118 inputs.page_scale_factor = kPageScaleFactor; 116 inputs.page_scale_factor = kPageScaleFactor;
119 inputs.page_scale_layer = root_layer->layer(), 117 inputs.page_scale_layer = root_layer.layer(),
120 cc::LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); 118 cc::LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
121 119
122 ExpectEqualLayerRectsInTarget(normal_layer->layer(), 120 ExpectEqualLayerRectsInTarget(normal_layer.layer(),
123 fixed_bounds_layer->layer()); 121 fixed_bounds_layer.layer());
124 } 122 }
125 123
126 // Change of fixed bounds should not affect the target geometries. 124 // Change of fixed bounds should not affect the target geometries.
127 fixed_bounds_layer->SetFixedBounds( 125 fixed_bounds_layer.SetFixedBounds(
128 gfx::Size(fixed_bounds.width() / 2, fixed_bounds.height() * 2)); 126 gfx::Size(fixed_bounds.width() / 2, fixed_bounds.height() * 2));
129 127
130 { 128 {
131 cc::LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs( 129 cc::LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
132 root_layer->layer(), kDeviceViewportSize); 130 root_layer.layer(), kDeviceViewportSize);
133 inputs.device_scale_factor = kDeviceScaleFactor; 131 inputs.device_scale_factor = kDeviceScaleFactor;
134 inputs.page_scale_factor = kPageScaleFactor; 132 inputs.page_scale_factor = kPageScaleFactor;
135 inputs.page_scale_layer = root_layer->layer(), 133 inputs.page_scale_layer = root_layer.layer(),
136 cc::LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); 134 cc::LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
137 135
138 ExpectEqualLayerRectsInTarget(normal_layer->layer(), 136 ExpectEqualLayerRectsInTarget(normal_layer.layer(),
139 fixed_bounds_layer->layer()); 137 fixed_bounds_layer.layer());
140 } 138 }
141 } 139 }
142 140
143 // TODO(perkj): CompareToWebLayerImplSimple disabled on LSAN due to crbug/386080 141 // TODO(perkj): CompareToWebLayerImplSimple disabled on LSAN due to crbug/386080
144 #if defined(LEAK_SANITIZER) 142 #if defined(LEAK_SANITIZER)
145 #define MAYBE_CompareToWebLayerImplSimple DISABLED_CompareToWebLayerImplSimple 143 #define MAYBE_CompareToWebLayerImplSimple DISABLED_CompareToWebLayerImplSimple
146 #else 144 #else
147 #define MAYBE_CompareToWebLayerImplSimple CompareToWebLayerImplSimple 145 #define MAYBE_CompareToWebLayerImplSimple CompareToWebLayerImplSimple
148 #endif 146 #endif
149 // A black box test that ensures WebLayerImplFixedBounds won't change target 147 // A black box test that ensures WebLayerImplFixedBounds won't change target
(...skipping 20 matching lines...) Expand all
170 168
171 CompareFixedBoundsLayerAndNormalLayer(WebFloatPoint(0, 0), transform); 169 CompareFixedBoundsLayerAndNormalLayer(WebFloatPoint(0, 0), transform);
172 170
173 // With non-zero anchor point, WebLayerImplFixedBounds will fall back to 171 // With non-zero anchor point, WebLayerImplFixedBounds will fall back to
174 // WebLayerImpl. 172 // WebLayerImpl.
175 CompareFixedBoundsLayerAndNormalLayer(WebFloatPoint(0.4f, 0.6f), transform); 173 CompareFixedBoundsLayerAndNormalLayer(WebFloatPoint(0.4f, 0.6f), transform);
176 } 174 }
177 175
178 } // namespace 176 } // namespace
179 } // namespace cc_blink 177 } // namespace cc_blink
OLDNEW
« no previous file with comments | « cc/blink/web_layer_impl_fixed_bounds.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698