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

Side by Side Diff: ui/compositor/layer_owner_unittest.cc

Issue 2383263002: Generalize layer mirroring for phantom windows (Closed)
Patch Set: Address nit Created 4 years, 2 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
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 "ui/compositor/layer_owner.h" 5 #include "ui/compositor/layer_owner.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/test/null_task_runner.h" 8 #include "base/test/null_task_runner.h"
9 #include "cc/animation/animation_player.h" 9 #include "cc/animation/animation_player.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 80
81 void LayerOwnerTestWithCompositor::TearDown() { 81 void LayerOwnerTestWithCompositor::TearDown() {
82 compositor_.reset(); 82 compositor_.reset();
83 ui::TerminateContextFactoryForTests(); 83 ui::TerminateContextFactoryForTests();
84 } 84 }
85 85
86 } // namespace 86 } // namespace
87 87
88 TEST(LayerOwnerTest, RecreateLayerHonorsAnimationTargets) { 88 TEST(LayerOwnerTest, RecreateLayerHonorsAnimationTargets) {
89 LayerOwner owner; 89 LayerOwner owner;
90 Layer* layer = new Layer(LAYER_SOLID_COLOR); 90 owner.SetLayer(base::MakeUnique<Layer>(LAYER_SOLID_COLOR));
91
92 Layer* layer = owner.layer();
91 layer->SetVisible(true); 93 layer->SetVisible(true);
92 layer->SetOpacity(1.0f); 94 layer->SetOpacity(1.0f);
93 layer->SetColor(SK_ColorRED); 95 layer->SetColor(SK_ColorRED);
94 96
95 owner.SetLayer(layer);
96
97 ScopedLayerAnimationSettings settings(layer->GetAnimator()); 97 ScopedLayerAnimationSettings settings(layer->GetAnimator());
98 layer->SetVisible(false); 98 layer->SetVisible(false);
99 layer->SetOpacity(0.0f); 99 layer->SetOpacity(0.0f);
100 layer->SetColor(SK_ColorGREEN); 100 layer->SetColor(SK_ColorGREEN);
101 EXPECT_TRUE(layer->visible()); 101 EXPECT_TRUE(layer->visible());
102 EXPECT_EQ(1.0f, layer->opacity()); 102 EXPECT_EQ(1.0f, layer->opacity());
103 EXPECT_EQ(SK_ColorRED, layer->background_color()); 103 EXPECT_EQ(SK_ColorRED, layer->background_color());
104 104
105 std::unique_ptr<Layer> old_layer(owner.RecreateLayer()); 105 std::unique_ptr<Layer> old_layer(owner.RecreateLayer());
106 EXPECT_FALSE(owner.layer()->visible()); 106 EXPECT_FALSE(owner.layer()->visible());
107 EXPECT_EQ(0.0f, owner.layer()->opacity()); 107 EXPECT_EQ(0.0f, owner.layer()->opacity());
108 EXPECT_EQ(SK_ColorGREEN, owner.layer()->background_color()); 108 EXPECT_EQ(SK_ColorGREEN, owner.layer()->background_color());
109 } 109 }
110 110
111 // Tests that when a LAYER_SOLID_COLOR which is not backed by a SolidColorLayer 111 // Tests that when a LAYER_SOLID_COLOR which is not backed by a SolidColorLayer
112 // that opaqueness and color targets are maintained when the 112 // that opaqueness and color targets are maintained when the
113 // LayerOwner::RecreateLayers is called. 113 // LayerOwner::RecreateLayers is called.
114 TEST(LayerOwnerTest, RecreateLayerSolidColorWithChangedCCLayerHonorsTargets) { 114 TEST(LayerOwnerTest, RecreateLayerSolidColorWithChangedCCLayerHonorsTargets) {
115 SkColor transparent = SK_ColorTRANSPARENT; 115 SkColor transparent = SK_ColorTRANSPARENT;
116 LayerOwner owner; 116 LayerOwner owner;
117 Layer* layer = new Layer(LAYER_SOLID_COLOR); 117 owner.SetLayer(base::MakeUnique<Layer>(LAYER_SOLID_COLOR));
118 owner.SetLayer(layer); 118 Layer* layer = owner.layer();
119 layer->SetFillsBoundsOpaquely(false); 119 layer->SetFillsBoundsOpaquely(false);
120 layer->SetColor(transparent); 120 layer->SetColor(transparent);
121 // Changing the backing layer takes LAYER_SOLID_COLOR off of the normal layer 121 // Changing the backing layer takes LAYER_SOLID_COLOR off of the normal layer
122 // flow, need to ensure that set values are maintained. 122 // flow, need to ensure that set values are maintained.
123 layer->SwitchCCLayerForTest(); 123 layer->SwitchCCLayerForTest();
124 124
125 EXPECT_FALSE(layer->fills_bounds_opaquely()); 125 EXPECT_FALSE(layer->fills_bounds_opaquely());
126 EXPECT_EQ(transparent, layer->background_color()); 126 EXPECT_EQ(transparent, layer->background_color());
127 EXPECT_EQ(transparent, layer->GetTargetColor()); 127 EXPECT_EQ(transparent, layer->GetTargetColor());
128 128
129 std::unique_ptr<Layer> old_layer(owner.RecreateLayer()); 129 std::unique_ptr<Layer> old_layer(owner.RecreateLayer());
130 EXPECT_FALSE(owner.layer()->fills_bounds_opaquely()); 130 EXPECT_FALSE(owner.layer()->fills_bounds_opaquely());
131 EXPECT_EQ(transparent, owner.layer()->background_color()); 131 EXPECT_EQ(transparent, owner.layer()->background_color());
132 EXPECT_EQ(transparent, owner.layer()->GetTargetColor()); 132 EXPECT_EQ(transparent, owner.layer()->GetTargetColor());
133 } 133 }
134 134
135 TEST(LayerOwnerTest, RecreateRootLayerWithNullCompositor) { 135 TEST(LayerOwnerTest, RecreateRootLayerWithNullCompositor) {
136 LayerOwner owner; 136 LayerOwner owner;
137 Layer* layer = new Layer; 137 owner.SetLayer(base::MakeUnique<Layer>());
138 owner.SetLayer(layer);
139 138
140 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer(); 139 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer();
141 140
142 EXPECT_EQ(nullptr, owner.layer()->GetCompositor()); 141 EXPECT_EQ(nullptr, owner.layer()->GetCompositor());
143 EXPECT_EQ(nullptr, layer_copy->GetCompositor()); 142 EXPECT_EQ(nullptr, layer_copy->GetCompositor());
144 } 143 }
145 144
146 TEST(LayerOwnerTest, InvertPropertyRemainSameWithRecreateLayer) { 145 TEST(LayerOwnerTest, InvertPropertyRemainSameWithRecreateLayer) {
147 LayerOwner owner; 146 LayerOwner owner;
148 Layer* layer = new Layer; 147 owner.SetLayer(base::MakeUnique<Layer>());
149 owner.SetLayer(layer); 148 Layer* layer = owner.layer();
150 149
151 layer->SetLayerInverted(true); 150 layer->SetLayerInverted(true);
152 std::unique_ptr<Layer> old_layer1 = owner.RecreateLayer(); 151 std::unique_ptr<Layer> old_layer1 = owner.RecreateLayer();
153 EXPECT_EQ(old_layer1->layer_inverted(), owner.layer()->layer_inverted()); 152 EXPECT_EQ(old_layer1->layer_inverted(), owner.layer()->layer_inverted());
154 153
155 old_layer1->SetLayerInverted(false); 154 old_layer1->SetLayerInverted(false);
156 std::unique_ptr<Layer> old_layer2 = owner.RecreateLayer(); 155 std::unique_ptr<Layer> old_layer2 = owner.RecreateLayer();
157 EXPECT_EQ(old_layer2->layer_inverted(), owner.layer()->layer_inverted()); 156 EXPECT_EQ(old_layer2->layer_inverted(), owner.layer()->layer_inverted());
158 } 157 }
159 158
160 TEST(LayerOwnerTest, RecreateLayerWithTransform) { 159 TEST(LayerOwnerTest, RecreateLayerWithTransform) {
161 LayerOwner owner; 160 LayerOwner owner;
162 Layer* layer = new Layer; 161 owner.SetLayer(base::MakeUnique<Layer>());
163 owner.SetLayer(layer); 162 Layer* layer = owner.layer();
164 163
165 gfx::Transform transform; 164 gfx::Transform transform;
166 transform.Scale(2, 1); 165 transform.Scale(2, 1);
167 transform.Translate(10, 5); 166 transform.Translate(10, 5);
168 167
169 layer->SetTransform(transform); 168 layer->SetTransform(transform);
170 169
171 std::unique_ptr<Layer> old_layer1 = owner.RecreateLayer(); 170 std::unique_ptr<Layer> old_layer1 = owner.RecreateLayer();
172 // Both new layer and original layer have the same transform. 171 // Both new layer and original layer have the same transform.
173 EXPECT_EQ(transform, old_layer1->GetTargetTransform()); 172 EXPECT_EQ(transform, old_layer1->GetTargetTransform());
174 EXPECT_EQ(transform, owner.layer()->GetTargetTransform()); 173 EXPECT_EQ(transform, owner.layer()->GetTargetTransform());
175 174
176 // But they're now separated, so changing the old layer's transform 175 // But they're now separated, so changing the old layer's transform
177 // should not affect the owner's. 176 // should not affect the owner's.
178 owner.layer()->SetTransform(gfx::Transform()); 177 owner.layer()->SetTransform(gfx::Transform());
179 EXPECT_EQ(transform, old_layer1->GetTargetTransform()); 178 EXPECT_EQ(transform, old_layer1->GetTargetTransform());
180 std::unique_ptr<Layer> old_layer2 = owner.RecreateLayer(); 179 std::unique_ptr<Layer> old_layer2 = owner.RecreateLayer();
181 EXPECT_TRUE(old_layer2->GetTargetTransform().IsIdentity()); 180 EXPECT_TRUE(old_layer2->GetTargetTransform().IsIdentity());
182 EXPECT_TRUE(owner.layer()->GetTargetTransform().IsIdentity()); 181 EXPECT_TRUE(owner.layer()->GetTargetTransform().IsIdentity());
183 } 182 }
184 183
185 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerWithCompositor) { 184 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerWithCompositor) {
186 LayerOwner owner; 185 LayerOwner owner;
187 Layer* layer = new Layer; 186 owner.SetLayer(base::MakeUnique<Layer>());
188 owner.SetLayer(layer); 187 Layer* layer = owner.layer();
189
190 compositor()->SetRootLayer(layer); 188 compositor()->SetRootLayer(layer);
191 189
192 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer(); 190 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer();
193 191
194 EXPECT_EQ(compositor(), owner.layer()->GetCompositor()); 192 EXPECT_EQ(compositor(), owner.layer()->GetCompositor());
195 EXPECT_EQ(owner.layer(), compositor()->root_layer()); 193 EXPECT_EQ(owner.layer(), compositor()->root_layer());
196 EXPECT_EQ(nullptr, layer_copy->GetCompositor()); 194 EXPECT_EQ(nullptr, layer_copy->GetCompositor());
197 } 195 }
198 196
199 // Tests that recreating the root layer, while one of its children is animating, 197 // Tests that recreating the root layer, while one of its children is animating,
200 // properly updates the compositor. So that compositor is not null for observers 198 // properly updates the compositor. So that compositor is not null for observers
201 // of animations being cancelled. 199 // of animations being cancelled.
202 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerDuringAnimation) { 200 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerDuringAnimation) {
203 LayerOwner owner; 201 LayerOwner owner;
204 Layer* layer = new Layer; 202 owner.SetLayer(base::MakeUnique<Layer>());
205 owner.SetLayer(layer); 203 Layer* layer = owner.layer();
206 compositor()->SetRootLayer(layer); 204 compositor()->SetRootLayer(layer);
207 205
208 std::unique_ptr<Layer> child(new Layer); 206 std::unique_ptr<Layer> child(new Layer);
209 child->SetBounds(gfx::Rect(0, 0, 100, 100)); 207 child->SetBounds(gfx::Rect(0, 0, 100, 100));
210 layer->Add(child.get()); 208 layer->Add(child.get());
211 209
212 // This observer checks that the compositor of |child| is not null upon 210 // This observer checks that the compositor of |child| is not null upon
213 // animation completion. 211 // animation completion.
214 std::unique_ptr<TestLayerAnimationObserver> observer( 212 std::unique_ptr<TestLayerAnimationObserver> observer(
215 new TestLayerAnimationObserver(child.get())); 213 new TestLayerAnimationObserver(child.get()));
(...skipping 13 matching lines...) Expand all
229 } 227 }
230 228
231 // Tests that recreating a non-root layer, while one of its children is 229 // Tests that recreating a non-root layer, while one of its children is
232 // animating, properly updates the compositor. So that compositor is not null 230 // animating, properly updates the compositor. So that compositor is not null
233 // for observers of animations being cancelled. 231 // for observers of animations being cancelled.
234 TEST_F(LayerOwnerTestWithCompositor, RecreateNonRootLayerDuringAnimation) { 232 TEST_F(LayerOwnerTestWithCompositor, RecreateNonRootLayerDuringAnimation) {
235 std::unique_ptr<Layer> root_layer(new Layer); 233 std::unique_ptr<Layer> root_layer(new Layer);
236 compositor()->SetRootLayer(root_layer.get()); 234 compositor()->SetRootLayer(root_layer.get());
237 235
238 LayerOwner owner; 236 LayerOwner owner;
239 Layer* layer = new Layer; 237 owner.SetLayer(base::MakeUnique<Layer>());
240 owner.SetLayer(layer); 238 Layer* layer = owner.layer();
241 root_layer->Add(layer); 239 root_layer->Add(layer);
242 240
243 std::unique_ptr<Layer> child(new Layer); 241 std::unique_ptr<Layer> child(new Layer);
244 child->SetBounds(gfx::Rect(0, 0, 100, 100)); 242 child->SetBounds(gfx::Rect(0, 0, 100, 100));
245 layer->Add(child.get()); 243 layer->Add(child.get());
246 244
247 // This observer checks that the compositor of |child| is not null upon 245 // This observer checks that the compositor of |child| is not null upon
248 // animation completion. 246 // animation completion.
249 std::unique_ptr<TestLayerAnimationObserver> observer( 247 std::unique_ptr<TestLayerAnimationObserver> observer(
250 new TestLayerAnimationObserver(child.get())); 248 new TestLayerAnimationObserver(child.get()));
(...skipping 12 matching lines...) Expand all
263 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer(); 261 std::unique_ptr<Layer> layer_copy = owner.RecreateLayer();
264 } 262 }
265 263
266 // Tests that if LayerOwner-derived class destroys layer, then 264 // Tests that if LayerOwner-derived class destroys layer, then
267 // LayerAnimator's player becomes detached from compositor timeline. 265 // LayerAnimator's player becomes detached from compositor timeline.
268 TEST_F(LayerOwnerTestWithCompositor, DetachTimelineOnAnimatorDeletion) { 266 TEST_F(LayerOwnerTestWithCompositor, DetachTimelineOnAnimatorDeletion) {
269 std::unique_ptr<Layer> root_layer(new Layer); 267 std::unique_ptr<Layer> root_layer(new Layer);
270 compositor()->SetRootLayer(root_layer.get()); 268 compositor()->SetRootLayer(root_layer.get());
271 269
272 LayerOwnerForTesting owner; 270 LayerOwnerForTesting owner;
273 Layer* layer = new Layer; 271 owner.SetLayer(base::MakeUnique<Layer>());
274 owner.SetLayer(layer); 272 Layer* layer = owner.layer();
275 layer->SetOpacity(0.5f); 273 layer->SetOpacity(0.5f);
276 root_layer->Add(layer); 274 root_layer->Add(layer);
277 275
278 scoped_refptr<cc::AnimationPlayer> player = 276 scoped_refptr<cc::AnimationPlayer> player =
279 layer->GetAnimator()->GetAnimationPlayerForTesting(); 277 layer->GetAnimator()->GetAnimationPlayerForTesting();
280 EXPECT_TRUE(player); 278 EXPECT_TRUE(player);
281 EXPECT_TRUE(player->animation_timeline()); 279 EXPECT_TRUE(player->animation_timeline());
282 280
283 // Destroying layer/animator must detach animator's player from timeline. 281 // Destroying layer/animator must detach animator's player from timeline.
284 owner.DestroyLayerForTesting(); 282 owner.DestroyLayerForTesting();
285 EXPECT_FALSE(player->animation_timeline()); 283 EXPECT_FALSE(player->animation_timeline());
286 } 284 }
287 285
288 // Tests that if we run threaded opacity animation on already added layer 286 // Tests that if we run threaded opacity animation on already added layer
289 // then LayerAnimator's player becomes attached to timeline. 287 // then LayerAnimator's player becomes attached to timeline.
290 TEST_F(LayerOwnerTestWithCompositor, 288 TEST_F(LayerOwnerTestWithCompositor,
291 AttachTimelineIfAnimatorCreatedAfterSetCompositor) { 289 AttachTimelineIfAnimatorCreatedAfterSetCompositor) {
292 std::unique_ptr<Layer> root_layer(new Layer); 290 std::unique_ptr<Layer> root_layer(new Layer);
293 compositor()->SetRootLayer(root_layer.get()); 291 compositor()->SetRootLayer(root_layer.get());
294 292
295 LayerOwner owner; 293 LayerOwner owner;
296 Layer* layer = new Layer; 294 owner.SetLayer(base::MakeUnique<Layer>());
297 owner.SetLayer(layer); 295 Layer* layer = owner.layer();
298 root_layer->Add(layer); 296 root_layer->Add(layer);
299 297
300 layer->SetOpacity(0.5f); 298 layer->SetOpacity(0.5f);
301 299
302 scoped_refptr<cc::AnimationPlayer> player = 300 scoped_refptr<cc::AnimationPlayer> player =
303 layer->GetAnimator()->GetAnimationPlayerForTesting(); 301 layer->GetAnimator()->GetAnimationPlayerForTesting();
304 EXPECT_TRUE(player); 302 EXPECT_TRUE(player);
305 EXPECT_TRUE(player->animation_timeline()); 303 EXPECT_TRUE(player->animation_timeline());
306 } 304 }
307 305
308 } // namespace ui 306 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698