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

Side by Side Diff: Source/core/animation/AnimationTest.cpp

Issue 1120003002: [Oilpan] Migrate most classes under core/animations to Oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 5 years, 4 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 | « Source/core/animation/AnimationStackTest.cpp ('k') | Source/core/animation/AnimationTimeline.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013, Google Inc. All rights reserved. 2 * Copyright (c) 2013, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 startTimeline(); 51 startTimeline();
52 } 52 }
53 53
54 void setUpWithoutStartingTimeline() 54 void setUpWithoutStartingTimeline()
55 { 55 {
56 document = Document::create(); 56 document = Document::create();
57 document->animationClock().resetTimeForTesting(); 57 document->animationClock().resetTimeForTesting();
58 timeline = AnimationTimeline::create(document.get()); 58 timeline = AnimationTimeline::create(document.get());
59 animation = timeline->play(0); 59 animation = timeline->play(0);
60 animation->setStartTime(0); 60 animation->setStartTime(0);
61 animation->setEffect(makeAnimation().get()); 61 animation->setEffect(makeAnimation());
62 } 62 }
63 63
64 void startTimeline() 64 void startTimeline()
65 { 65 {
66 simulateFrame(0); 66 simulateFrame(0);
67 } 67 }
68 68
69 PassRefPtrWillBeRawPtr<KeyframeEffect> makeAnimation(double duration = 30, d ouble playbackRate = 1) 69 KeyframeEffect* makeAnimation(double duration = 30, double playbackRate = 1)
70 { 70 {
71 Timing timing; 71 Timing timing;
72 timing.iterationDuration = duration; 72 timing.iterationDuration = duration;
73 timing.playbackRate = playbackRate; 73 timing.playbackRate = playbackRate;
74 return KeyframeEffect::create(0, nullptr, timing); 74 return KeyframeEffect::create(0, nullptr, timing);
75 } 75 }
76 76
77 bool simulateFrame(double time) 77 bool simulateFrame(double time)
78 { 78 {
79 document->animationClock().updateTime(time); 79 document->animationClock().updateTime(time);
80 document->compositorPendingAnimations().update(false); 80 document->compositorPendingAnimations().update(false);
81 // The timeline does not know about our animation, so we have to explici tly call update(). 81 // The timeline does not know about our animation, so we have to explici tly call update().
82 return animation->update(TimingUpdateForAnimationFrame); 82 return animation->update(TimingUpdateForAnimationFrame);
83 } 83 }
84 84
85 RefPtrWillBePersistent<Document> document; 85 RefPtrWillBePersistent<Document> document;
86 RefPtrWillBePersistent<AnimationTimeline> timeline; 86 Persistent<AnimationTimeline> timeline;
87 RefPtrWillBePersistent<Animation> animation; 87 Persistent<Animation> animation;
88 TrackExceptionState exceptionState; 88 TrackExceptionState exceptionState;
89 }; 89 };
90 90
91 TEST_F(AnimationAnimationTest, InitialState) 91 TEST_F(AnimationAnimationTest, InitialState)
92 { 92 {
93 setUpWithoutStartingTimeline(); 93 setUpWithoutStartingTimeline();
94 animation = timeline->play(0); 94 animation = timeline->play(0);
95 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); 95 EXPECT_EQ(Animation::Pending, animation->playStateInternal());
96 EXPECT_EQ(0, animation->currentTimeInternal()); 96 EXPECT_EQ(0, animation->currentTimeInternal());
97 EXPECT_FALSE(animation->paused()); 97 EXPECT_FALSE(animation->paused());
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 animation->setPlaybackRate(0); 497 animation->setPlaybackRate(0);
498 animation->finish(exceptionState); 498 animation->finish(exceptionState);
499 EXPECT_EQ(10, animation->currentTimeInternal()); 499 EXPECT_EQ(10, animation->currentTimeInternal());
500 } 500 }
501 501
502 TEST_F(AnimationAnimationTest, FinishRaisesException) 502 TEST_F(AnimationAnimationTest, FinishRaisesException)
503 { 503 {
504 Timing timing; 504 Timing timing;
505 timing.iterationDuration = 1; 505 timing.iterationDuration = 1;
506 timing.iterationCount = std::numeric_limits<double>::infinity(); 506 timing.iterationCount = std::numeric_limits<double>::infinity();
507 animation->setEffect(KeyframeEffect::create(0, nullptr, timing).get()); 507 animation->setEffect(KeyframeEffect::create(0, nullptr, timing));
508 animation->setCurrentTimeInternal(10); 508 animation->setCurrentTimeInternal(10);
509 509
510 animation->finish(exceptionState); 510 animation->finish(exceptionState);
511 EXPECT_EQ(10, animation->currentTimeInternal()); 511 EXPECT_EQ(10, animation->currentTimeInternal());
512 EXPECT_TRUE(exceptionState.hadException()); 512 EXPECT_TRUE(exceptionState.hadException());
513 EXPECT_EQ(InvalidStateError, exceptionState.code()); 513 EXPECT_EQ(InvalidStateError, exceptionState.code());
514 } 514 }
515 515
516 TEST_F(AnimationAnimationTest, LimitingAtEffectEnd) 516 TEST_F(AnimationAnimationTest, LimitingAtEffectEnd)
517 { 517 {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 EXPECT_EQ(0, animation->currentTimeInternal()); 614 EXPECT_EQ(0, animation->currentTimeInternal());
615 simulateFrame(1); 615 simulateFrame(1);
616 EXPECT_EQ(30, animation->currentTimeInternal()); 616 EXPECT_EQ(30, animation->currentTimeInternal());
617 } 617 }
618 618
619 619
620 TEST_F(AnimationAnimationTest, SetEffect) 620 TEST_F(AnimationAnimationTest, SetEffect)
621 { 621 {
622 animation = timeline->play(0); 622 animation = timeline->play(0);
623 animation->setStartTime(0); 623 animation->setStartTime(0);
624 RefPtrWillBeRawPtr<AnimationEffect> effect1 = makeAnimation(); 624 AnimationEffect* effect1 = makeAnimation();
625 RefPtrWillBeRawPtr<AnimationEffect> effect2 = makeAnimation(); 625 AnimationEffect* effect2 = makeAnimation();
626 animation->setEffect(effect1.get()); 626 animation->setEffect(effect1);
627 EXPECT_EQ(effect1, animation->effect()); 627 EXPECT_EQ(effect1, animation->effect());
628 EXPECT_EQ(0, animation->currentTimeInternal()); 628 EXPECT_EQ(0, animation->currentTimeInternal());
629 animation->setCurrentTimeInternal(15); 629 animation->setCurrentTimeInternal(15);
630 animation->setEffect(effect2.get()); 630 animation->setEffect(effect2);
631 EXPECT_EQ(15, animation->currentTimeInternal()); 631 EXPECT_EQ(15, animation->currentTimeInternal());
632 EXPECT_EQ(0, effect1->animation()); 632 EXPECT_EQ(0, effect1->animation());
633 EXPECT_EQ(animation.get(), effect2->animation()); 633 EXPECT_EQ(animation.get(), effect2->animation());
634 EXPECT_EQ(effect2, animation->effect()); 634 EXPECT_EQ(effect2, animation->effect());
635 } 635 }
636 636
637 TEST_F(AnimationAnimationTest, SetEffectLimitsAnimation) 637 TEST_F(AnimationAnimationTest, SetEffectLimitsAnimation)
638 { 638 {
639 animation->setCurrentTimeInternal(20); 639 animation->setCurrentTimeInternal(20);
640 animation->setEffect(makeAnimation(10).get()); 640 animation->setEffect(makeAnimation(10));
641 EXPECT_EQ(20, animation->currentTimeInternal()); 641 EXPECT_EQ(20, animation->currentTimeInternal());
642 EXPECT_TRUE(animation->limited()); 642 EXPECT_TRUE(animation->limited());
643 simulateFrame(10); 643 simulateFrame(10);
644 EXPECT_EQ(20, animation->currentTimeInternal()); 644 EXPECT_EQ(20, animation->currentTimeInternal());
645 } 645 }
646 646
647 TEST_F(AnimationAnimationTest, SetEffectUnlimitsAnimation) 647 TEST_F(AnimationAnimationTest, SetEffectUnlimitsAnimation)
648 { 648 {
649 animation->setCurrentTimeInternal(40); 649 animation->setCurrentTimeInternal(40);
650 animation->setEffect(makeAnimation(60).get()); 650 animation->setEffect(makeAnimation(60));
651 EXPECT_FALSE(animation->limited()); 651 EXPECT_FALSE(animation->limited());
652 EXPECT_EQ(40, animation->currentTimeInternal()); 652 EXPECT_EQ(40, animation->currentTimeInternal());
653 simulateFrame(10); 653 simulateFrame(10);
654 EXPECT_EQ(50, animation->currentTimeInternal()); 654 EXPECT_EQ(50, animation->currentTimeInternal());
655 } 655 }
656 656
657 657
658 TEST_F(AnimationAnimationTest, EmptyAnimationsDontUpdateEffects) 658 TEST_F(AnimationAnimationTest, EmptyAnimationsDontUpdateEffects)
659 { 659 {
660 animation = timeline->play(0); 660 animation = timeline->play(0);
(...skipping 12 matching lines...) Expand all
673 animation->setEffect(animationNode); 673 animation->setEffect(animationNode);
674 EXPECT_EQ(0, animation2->effect()); 674 EXPECT_EQ(0, animation2->effect());
675 } 675 }
676 676
677 TEST_F(AnimationAnimationTest, AnimationsReturnTimeToNextEffect) 677 TEST_F(AnimationAnimationTest, AnimationsReturnTimeToNextEffect)
678 { 678 {
679 Timing timing; 679 Timing timing;
680 timing.startDelay = 1; 680 timing.startDelay = 1;
681 timing.iterationDuration = 1; 681 timing.iterationDuration = 1;
682 timing.endDelay = 1; 682 timing.endDelay = 1;
683 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(0 , nullptr, timing); 683 KeyframeEffect* keyframeEffect = KeyframeEffect::create(0, nullptr, timing);
684 animation = timeline->play(keyframeEffect.get()); 684 animation = timeline->play(keyframeEffect);
685 animation->setStartTime(0); 685 animation->setStartTime(0);
686 686
687 simulateFrame(0); 687 simulateFrame(0);
688 EXPECT_EQ(1, animation->timeToEffectChange()); 688 EXPECT_EQ(1, animation->timeToEffectChange());
689 689
690 simulateFrame(0.5); 690 simulateFrame(0.5);
691 EXPECT_EQ(0.5, animation->timeToEffectChange()); 691 EXPECT_EQ(0.5, animation->timeToEffectChange());
692 692
693 simulateFrame(1); 693 simulateFrame(1);
694 EXPECT_EQ(0, animation->timeToEffectChange()); 694 EXPECT_EQ(0, animation->timeToEffectChange());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 // received from the compositor yet, as cancel() nukes start times. 774 // received from the compositor yet, as cancel() nukes start times.
775 simulateFrame(0); 775 simulateFrame(0);
776 EXPECT_EQ(std::numeric_limits<double>::infinity(), animation->timeToEffectCh ange()); 776 EXPECT_EQ(std::numeric_limits<double>::infinity(), animation->timeToEffectCh ange());
777 } 777 }
778 778
779 TEST_F(AnimationAnimationTest, AttachedAnimations) 779 TEST_F(AnimationAnimationTest, AttachedAnimations)
780 { 780 {
781 RefPtrWillBePersistent<Element> element = document->createElement("foo", ASS ERT_NO_EXCEPTION); 781 RefPtrWillBePersistent<Element> element = document->createElement("foo", ASS ERT_NO_EXCEPTION);
782 782
783 Timing timing; 783 Timing timing;
784 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(e lement.get(), nullptr, timing); 784 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), nullp tr, timing);
785 RefPtrWillBeRawPtr<Animation> animation = timeline->play(keyframeEffect.get( )); 785 Animation* anim = timeline->play(keyframeEffect);
786 simulateFrame(0); 786 simulateFrame(0);
787 timeline->serviceAnimations(TimingUpdateForAnimationFrame); 787 timeline->serviceAnimations(TimingUpdateForAnimationFrame);
788 EXPECT_EQ(1U, element->elementAnimations()->animations().find(animation.get( ))->value); 788 EXPECT_EQ(1U, element->elementAnimations()->animations().find(anim)->value);
789 789
790 animation.release();
791 Heap::collectAllGarbage(); 790 Heap::collectAllGarbage();
792 EXPECT_TRUE(element->elementAnimations()->animations().isEmpty()); 791 EXPECT_TRUE(element->elementAnimations()->animations().isEmpty());
793 } 792 }
794 793
795 TEST_F(AnimationAnimationTest, HasLowerPriority) 794 TEST_F(AnimationAnimationTest, HasLowerPriority)
796 { 795 {
797 RefPtrWillBeRawPtr<Animation> animation1 = timeline->play(0); 796 Animation* animation1 = timeline->play(nullptr);
798 RefPtrWillBeRawPtr<Animation> animation2 = timeline->play(0); 797 Animation* animation2 = timeline->play(nullptr);
799 EXPECT_TRUE(Animation::hasLowerPriority(animation1.get(), animation2.get())) ; 798 EXPECT_TRUE(Animation::hasLowerPriority(animation1, animation2));
800 } 799 }
801 800
802 TEST_F(AnimationAnimationTest, PlayAfterCancel) 801 TEST_F(AnimationAnimationTest, PlayAfterCancel)
803 { 802 {
804 animation->cancel(); 803 animation->cancel();
805 EXPECT_EQ(Animation::Idle, animation->playStateInternal()); 804 EXPECT_EQ(Animation::Idle, animation->playStateInternal());
806 EXPECT_TRUE(std::isnan(animation->currentTime())); 805 EXPECT_TRUE(std::isnan(animation->currentTime()));
807 EXPECT_TRUE(std::isnan(animation->startTime())); 806 EXPECT_TRUE(std::isnan(animation->startTime()));
808 animation->play(); 807 animation->play();
809 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); 808 EXPECT_EQ(Animation::Pending, animation->playStateInternal());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 EXPECT_EQ(Animation::Idle, animation->playStateInternal()); 867 EXPECT_EQ(Animation::Idle, animation->playStateInternal());
869 EXPECT_TRUE(std::isnan(animation->currentTime())); 868 EXPECT_TRUE(std::isnan(animation->currentTime()));
870 EXPECT_TRUE(std::isnan(animation->startTime())); 869 EXPECT_TRUE(std::isnan(animation->startTime()));
871 animation->pause(); 870 animation->pause();
872 EXPECT_EQ(Animation::Idle, animation->playStateInternal()); 871 EXPECT_EQ(Animation::Idle, animation->playStateInternal());
873 EXPECT_TRUE(std::isnan(animation->currentTime())); 872 EXPECT_TRUE(std::isnan(animation->currentTime()));
874 EXPECT_TRUE(std::isnan(animation->startTime())); 873 EXPECT_TRUE(std::isnan(animation->startTime()));
875 } 874 }
876 875
877 } // namespace blink 876 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/animation/AnimationStackTest.cpp ('k') | Source/core/animation/AnimationTimeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698