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

Side by Side Diff: cc/animation/layer_animation_controller_unittest.cc

Issue 68503014: cc: Alow animations to be aborted from either thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo in MarkAnimationsForDeletion Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « cc/animation/layer_animation_controller.cc ('k') | cc/trees/layer_tree_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 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 "cc/animation/layer_animation_controller.h" 5 #include "cc/animation/layer_animation_controller.h"
6 6
7 #include "cc/animation/animation.h" 7 #include "cc/animation/animation.h"
8 #include "cc/animation/animation_curve.h" 8 #include "cc/animation/animation_curve.h"
9 #include "cc/animation/animation_delegate.h" 9 #include "cc/animation/animation_delegate.h"
10 #include "cc/animation/keyframed_animation_curve.h" 10 #include "cc/animation/keyframed_animation_curve.h"
(...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1266 0.0, operations3, scoped_ptr<TimingFunction>())); 1266 0.0, operations3, scoped_ptr<TimingFunction>()));
1267 operations3.AppendMatrix(transform3); 1267 operations3.AppendMatrix(transform3);
1268 curve3->AddKeyframe(TransformKeyframe::Create( 1268 curve3->AddKeyframe(TransformKeyframe::Create(
1269 1.0, operations3, scoped_ptr<TimingFunction>())); 1269 1.0, operations3, scoped_ptr<TimingFunction>()));
1270 animation = Animation::Create( 1270 animation = Animation::Create(
1271 curve3.PassAs<AnimationCurve>(), 3, 3, Animation::Transform); 1271 curve3.PassAs<AnimationCurve>(), 3, 3, Animation::Transform);
1272 controller_impl->AddAnimation(animation.Pass()); 1272 controller_impl->AddAnimation(animation.Pass());
1273 EXPECT_FALSE(controller_impl->AnimatedBoundsForBox(box, &bounds)); 1273 EXPECT_FALSE(controller_impl->AnimatedBoundsForBox(box, &bounds));
1274 } 1274 }
1275 1275
1276 // Tests that AbortAnimations aborts all animations targeting the specified
1277 // property.
1278 TEST(LayerAnimationControllerTest, AbortAnimations) {
1279 FakeLayerAnimationValueObserver dummy;
1280 scoped_refptr<LayerAnimationController> controller(
1281 LayerAnimationController::Create(0));
1282 controller->AddValueObserver(&dummy);
1283
1284 // Start with several animations, and allow some of them to reach the finished
1285 // state.
1286 controller->AddAnimation(CreateAnimation(
1287 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(),
1288 1,
1289 Animation::Transform));
1290 controller->AddAnimation(CreateAnimation(
1291 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1292 2,
1293 Animation::Opacity));
1294 controller->AddAnimation(CreateAnimation(
1295 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(),
1296 3,
1297 Animation::Transform));
1298 controller->AddAnimation(CreateAnimation(
1299 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(),
1300 4,
1301 Animation::Transform));
1302 controller->AddAnimation(CreateAnimation(
1303 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1304 5,
1305 Animation::Opacity));
1306
1307 controller->Animate(1.0);
1308 controller->UpdateState(true, NULL);
1309 controller->Animate(2.0);
1310 controller->UpdateState(true, NULL);
1311
1312 EXPECT_EQ(Animation::Finished,
1313 controller->GetAnimation(1, Animation::Transform)->run_state());
1314 EXPECT_EQ(Animation::Finished,
1315 controller->GetAnimation(2, Animation::Opacity)->run_state());
1316 EXPECT_EQ(Animation::Running,
1317 controller->GetAnimation(3, Animation::Transform)->run_state());
1318 EXPECT_EQ(Animation::WaitingForTargetAvailability,
1319 controller->GetAnimation(4, Animation::Transform)->run_state());
1320 EXPECT_EQ(Animation::Running,
1321 controller->GetAnimation(5, Animation::Opacity)->run_state());
1322
1323 controller->AbortAnimations(Animation::Transform);
1324
1325 // Only un-finished Transform animations should have been aborted.
1326 EXPECT_EQ(Animation::Finished,
1327 controller->GetAnimation(1, Animation::Transform)->run_state());
1328 EXPECT_EQ(Animation::Finished,
1329 controller->GetAnimation(2, Animation::Opacity)->run_state());
1330 EXPECT_EQ(Animation::Aborted,
1331 controller->GetAnimation(3, Animation::Transform)->run_state());
1332 EXPECT_EQ(Animation::Aborted,
1333 controller->GetAnimation(4, Animation::Transform)->run_state());
1334 EXPECT_EQ(Animation::Running,
1335 controller->GetAnimation(5, Animation::Opacity)->run_state());
1336 }
1337
1338 // An animation aborted on the main thread should get deleted on both threads.
1339 TEST(LayerAnimationControllerTest, MainThreadAbortedAnimationGetsDeleted) {
1340 FakeLayerAnimationValueObserver dummy_impl;
1341 scoped_refptr<LayerAnimationController> controller_impl(
1342 LayerAnimationController::Create(0));
1343 controller_impl->AddValueObserver(&dummy_impl);
1344 FakeLayerAnimationValueObserver dummy;
1345 scoped_refptr<LayerAnimationController> controller(
1346 LayerAnimationController::Create(0));
1347 controller->AddValueObserver(&dummy);
1348
1349 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false);
1350 int group_id = controller->GetAnimation(Animation::Opacity)->group();
1351
1352 controller->PushAnimationUpdatesTo(controller_impl.get());
1353 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1354
1355 controller->AbortAnimations(Animation::Opacity);
1356 EXPECT_EQ(Animation::Aborted,
1357 controller->GetAnimation(Animation::Opacity)->run_state());
1358
1359 controller->Animate(1.0);
1360 controller->UpdateState(true, NULL);
1361 EXPECT_EQ(Animation::WaitingForDeletion,
1362 controller->GetAnimation(Animation::Opacity)->run_state());
1363
1364 controller->PushAnimationUpdatesTo(controller_impl.get());
1365 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity));
1366 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1367 }
1368
1369 // An animation aborted on the impl thread should get deleted on both threads.
1370 TEST(LayerAnimationControllerTest, ImplThreadAbortedAnimationGetsDeleted) {
1371 FakeLayerAnimationValueObserver dummy_impl;
1372 scoped_refptr<LayerAnimationController> controller_impl(
1373 LayerAnimationController::Create(0));
1374 controller_impl->AddValueObserver(&dummy_impl);
1375 FakeLayerAnimationValueObserver dummy;
1376 scoped_refptr<LayerAnimationController> controller(
1377 LayerAnimationController::Create(0));
1378 controller->AddValueObserver(&dummy);
1379
1380 AddOpacityTransitionToController(controller.get(), 1.0, 0.f, 1.f, false);
1381 int group_id = controller->GetAnimation(Animation::Opacity)->group();
1382
1383 controller->PushAnimationUpdatesTo(controller_impl.get());
1384 EXPECT_TRUE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1385
1386 controller_impl->AbortAnimations(Animation::Opacity);
1387 EXPECT_EQ(Animation::Aborted,
1388 controller_impl->GetAnimation(Animation::Opacity)->run_state());
1389
1390 AnimationEventsVector events;
1391 controller_impl->Animate(1.0);
1392 controller_impl->UpdateState(true, &events);
1393 EXPECT_EQ(1u, events.size());
1394 EXPECT_EQ(AnimationEvent::Aborted, events[0].type);
1395 EXPECT_EQ(Animation::WaitingForDeletion,
1396 controller_impl->GetAnimation(Animation::Opacity)->run_state());
1397
1398 controller->NotifyAnimationAborted(events[0]);
1399 EXPECT_EQ(Animation::Aborted,
1400 controller->GetAnimation(Animation::Opacity)->run_state());
1401
1402 controller->Animate(1.5);
1403 controller->UpdateState(true, NULL);
1404 EXPECT_EQ(Animation::WaitingForDeletion,
1405 controller->GetAnimation(Animation::Opacity)->run_state());
1406
1407 controller->PushAnimationUpdatesTo(controller_impl.get());
1408 EXPECT_FALSE(controller->GetAnimation(group_id, Animation::Opacity));
1409 EXPECT_FALSE(controller_impl->GetAnimation(group_id, Animation::Opacity));
1410 }
1411
1412 // Ensure that we only generate Finished events for animations in a group
1413 // once all animations in that group are finished.
1414 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) {
1415 scoped_ptr<AnimationEventsVector> events(
1416 make_scoped_ptr(new AnimationEventsVector));
1417 FakeLayerAnimationValueObserver dummy_impl;
1418 scoped_refptr<LayerAnimationController> controller_impl(
1419 LayerAnimationController::Create(0));
1420 controller_impl->AddValueObserver(&dummy_impl);
1421
1422 // Add two animations with the same group id but different durations.
1423 controller_impl->AddAnimation(CreateAnimation(
1424 scoped_ptr<AnimationCurve>(new FakeTransformTransition(2.0)).Pass(),
1425 1,
1426 Animation::Transform));
1427 controller_impl->AddAnimation(CreateAnimation(
1428 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1429 1,
1430 Animation::Opacity));
1431
1432 controller_impl->Animate(1.0);
1433 controller_impl->UpdateState(true, events.get());
1434
1435 // Both animations should have started.
1436 EXPECT_EQ(2u, events->size());
1437 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type);
1438 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type);
1439
1440 events.reset(new AnimationEventsVector);
1441 controller_impl->Animate(2.0);
1442 controller_impl->UpdateState(true, events.get());
1443
1444 // The opacity animation should be finished, but should not have generated
1445 // a Finished event yet.
1446 EXPECT_EQ(0u, events->size());
1447 EXPECT_EQ(Animation::Finished,
1448 controller_impl->GetAnimation(1, Animation::Opacity)->run_state());
1449 EXPECT_EQ(Animation::Running,
1450 controller_impl->GetAnimation(1,
1451 Animation::Transform)->run_state());
1452
1453 controller_impl->Animate(3.0);
1454 controller_impl->UpdateState(true, events.get());
1455
1456 // Both animations should have generated Finished events.
1457 EXPECT_EQ(2u, events->size());
1458 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type);
1459 EXPECT_EQ(AnimationEvent::Finished, (*events)[1].type);
1460 }
1461
1462 // Ensure that when a group has a mix of aborted and finished animations,
1463 // we generate a Finished event for the finished animation and an Aborted
1464 // event for the aborted animation.
1465 TEST(LayerAnimationControllerTest, FinishedAndAbortedEventsForGroup) {
1466 scoped_ptr<AnimationEventsVector> events(
1467 make_scoped_ptr(new AnimationEventsVector));
1468 FakeLayerAnimationValueObserver dummy_impl;
1469 scoped_refptr<LayerAnimationController> controller_impl(
1470 LayerAnimationController::Create(0));
1471 controller_impl->AddValueObserver(&dummy_impl);
1472
1473 // Add two animations with the same group id.
1474 controller_impl->AddAnimation(CreateAnimation(
1475 scoped_ptr<AnimationCurve>(new FakeTransformTransition(1.0)).Pass(),
1476 1,
1477 Animation::Transform));
1478 controller_impl->AddAnimation(CreateAnimation(
1479 scoped_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)).Pass(),
1480 1,
1481 Animation::Opacity));
1482
1483 controller_impl->Animate(1.0);
1484 controller_impl->UpdateState(true, events.get());
1485
1486 // Both animations should have started.
1487 EXPECT_EQ(2u, events->size());
1488 EXPECT_EQ(AnimationEvent::Started, (*events)[0].type);
1489 EXPECT_EQ(AnimationEvent::Started, (*events)[1].type);
1490
1491 controller_impl->AbortAnimations(Animation::Opacity);
1492
1493 events.reset(new AnimationEventsVector);
1494 controller_impl->Animate(2.0);
1495 controller_impl->UpdateState(true, events.get());
1496
1497 // We should have exactly 2 events: a Finished event for the tranform
1498 // animation, and an Aborted event for the opacity animation.
1499 EXPECT_EQ(2u, events->size());
1500 EXPECT_EQ(AnimationEvent::Finished, (*events)[0].type);
1501 EXPECT_EQ(Animation::Transform, (*events)[0].target_property);
1502 EXPECT_EQ(AnimationEvent::Aborted, (*events)[1].type);
1503 EXPECT_EQ(Animation::Opacity, (*events)[1].target_property);
1504 }
1505
1276 } // namespace 1506 } // namespace
1277 } // namespace cc 1507 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/layer_animation_controller.cc ('k') | cc/trees/layer_tree_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698