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

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: Resize expect size of Persistent Created 5 years, 7 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 /* 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 startTimeline(); 53 startTimeline();
54 } 54 }
55 55
56 void setUpWithoutStartingTimeline() 56 void setUpWithoutStartingTimeline()
57 { 57 {
58 document = Document::create(); 58 document = Document::create();
59 document->animationClock().resetTimeForTesting(); 59 document->animationClock().resetTimeForTesting();
60 timeline = AnimationTimeline::create(document.get()); 60 timeline = AnimationTimeline::create(document.get());
61 animation = timeline->play(0); 61 animation = timeline->play(0);
62 animation->setStartTime(0); 62 animation->setStartTime(0);
63 animation->setSource(makeAnimation().get()); 63 animation->setSource(makeAnimation());
64 } 64 }
65 65
66 void startTimeline() 66 void startTimeline()
67 { 67 {
68 simulateFrame(0); 68 simulateFrame(0);
69 } 69 }
70 70
71 PassRefPtrWillBeRawPtr<KeyframeEffect> makeAnimation(double duration = 30, d ouble playbackRate = 1) 71 KeyframeEffect* makeAnimation(double duration = 30, double playbackRate = 1)
72 { 72 {
73 Timing timing; 73 Timing timing;
74 timing.iterationDuration = duration; 74 timing.iterationDuration = duration;
75 timing.playbackRate = playbackRate; 75 timing.playbackRate = playbackRate;
76 return KeyframeEffect::create(0, nullptr, timing); 76 return KeyframeEffect::create(0, nullptr, timing);
77 } 77 }
78 78
79 bool simulateFrame(double time) 79 bool simulateFrame(double time)
80 { 80 {
81 document->animationClock().updateTime(time); 81 document->animationClock().updateTime(time);
82 document->compositorPendingAnimations().update(false); 82 document->compositorPendingAnimations().update(false);
83 // The timeline does not know about our animation, so we have to explici tly call update(). 83 // The timeline does not know about our animation, so we have to explici tly call update().
84 return animation->update(TimingUpdateForAnimationFrame); 84 return animation->update(TimingUpdateForAnimationFrame);
85 } 85 }
86 86
87 RefPtrWillBePersistent<Document> document; 87 RefPtrWillBePersistent<Document> document;
88 RefPtrWillBePersistent<AnimationTimeline> timeline; 88 Persistent<AnimationTimeline> timeline;
89 RefPtrWillBePersistent<Animation> animation; 89 Persistent<Animation> animation;
90 TrackExceptionState exceptionState; 90 TrackExceptionState exceptionState;
91 }; 91 };
92 92
93 TEST_F(AnimationAnimationTest, InitialState) 93 TEST_F(AnimationAnimationTest, InitialState)
94 { 94 {
95 setUpWithoutStartingTimeline(); 95 setUpWithoutStartingTimeline();
96 animation = timeline->play(0); 96 animation = timeline->play(0);
97 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); 97 EXPECT_EQ(Animation::Pending, animation->playStateInternal());
98 EXPECT_EQ(0, animation->currentTimeInternal()); 98 EXPECT_EQ(0, animation->currentTimeInternal());
99 EXPECT_FALSE(animation->paused()); 99 EXPECT_FALSE(animation->paused());
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 animation->setPlaybackRate(0); 499 animation->setPlaybackRate(0);
500 animation->finish(exceptionState); 500 animation->finish(exceptionState);
501 EXPECT_EQ(10, animation->currentTimeInternal()); 501 EXPECT_EQ(10, animation->currentTimeInternal());
502 } 502 }
503 503
504 TEST_F(AnimationAnimationTest, FinishRaisesException) 504 TEST_F(AnimationAnimationTest, FinishRaisesException)
505 { 505 {
506 Timing timing; 506 Timing timing;
507 timing.iterationDuration = 1; 507 timing.iterationDuration = 1;
508 timing.iterationCount = std::numeric_limits<double>::infinity(); 508 timing.iterationCount = std::numeric_limits<double>::infinity();
509 animation->setSource(KeyframeEffect::create(0, nullptr, timing).get()); 509 animation->setSource(KeyframeEffect::create(0, nullptr, timing));
510 animation->setCurrentTimeInternal(10); 510 animation->setCurrentTimeInternal(10);
511 511
512 animation->finish(exceptionState); 512 animation->finish(exceptionState);
513 EXPECT_EQ(10, animation->currentTimeInternal()); 513 EXPECT_EQ(10, animation->currentTimeInternal());
514 EXPECT_TRUE(exceptionState.hadException()); 514 EXPECT_TRUE(exceptionState.hadException());
515 EXPECT_EQ(InvalidStateError, exceptionState.code()); 515 EXPECT_EQ(InvalidStateError, exceptionState.code());
516 } 516 }
517 517
518 TEST_F(AnimationAnimationTest, LimitingAtSourceEnd) 518 TEST_F(AnimationAnimationTest, LimitingAtSourceEnd)
519 { 519 {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 EXPECT_EQ(0, animation->currentTimeInternal()); 616 EXPECT_EQ(0, animation->currentTimeInternal());
617 simulateFrame(1); 617 simulateFrame(1);
618 EXPECT_EQ(30, animation->currentTimeInternal()); 618 EXPECT_EQ(30, animation->currentTimeInternal());
619 } 619 }
620 620
621 621
622 TEST_F(AnimationAnimationTest, SetSource) 622 TEST_F(AnimationAnimationTest, SetSource)
623 { 623 {
624 animation = timeline->play(0); 624 animation = timeline->play(0);
625 animation->setStartTime(0); 625 animation->setStartTime(0);
626 RefPtrWillBeRawPtr<AnimationEffect> source1 = makeAnimation(); 626 AnimationEffect* source1 = makeAnimation();
627 RefPtrWillBeRawPtr<AnimationEffect> source2 = makeAnimation(); 627 AnimationEffect* source2 = makeAnimation();
628 animation->setSource(source1.get()); 628 animation->setSource(source1);
629 EXPECT_EQ(source1, animation->source()); 629 EXPECT_EQ(source1, animation->source());
630 EXPECT_EQ(0, animation->currentTimeInternal()); 630 EXPECT_EQ(0, animation->currentTimeInternal());
631 animation->setCurrentTimeInternal(15); 631 animation->setCurrentTimeInternal(15);
632 animation->setSource(source2.get()); 632 animation->setSource(source2);
633 EXPECT_EQ(15, animation->currentTimeInternal()); 633 EXPECT_EQ(15, animation->currentTimeInternal());
634 EXPECT_EQ(0, source1->animation()); 634 EXPECT_EQ(0, source1->animation());
635 EXPECT_EQ(animation.get(), source2->animation()); 635 EXPECT_EQ(animation.get(), source2->animation());
636 EXPECT_EQ(source2, animation->source()); 636 EXPECT_EQ(source2, animation->source());
637 } 637 }
638 638
639 TEST_F(AnimationAnimationTest, SetSourceLimitsAnimation) 639 TEST_F(AnimationAnimationTest, SetSourceLimitsAnimation)
640 { 640 {
641 animation->setCurrentTimeInternal(20); 641 animation->setCurrentTimeInternal(20);
642 animation->setSource(makeAnimation(10).get()); 642 animation->setSource(makeAnimation(10));
643 EXPECT_EQ(20, animation->currentTimeInternal()); 643 EXPECT_EQ(20, animation->currentTimeInternal());
644 EXPECT_TRUE(animation->limited()); 644 EXPECT_TRUE(animation->limited());
645 simulateFrame(10); 645 simulateFrame(10);
646 EXPECT_EQ(20, animation->currentTimeInternal()); 646 EXPECT_EQ(20, animation->currentTimeInternal());
647 } 647 }
648 648
649 TEST_F(AnimationAnimationTest, SetSourceUnlimitsAnimation) 649 TEST_F(AnimationAnimationTest, SetSourceUnlimitsAnimation)
650 { 650 {
651 animation->setCurrentTimeInternal(40); 651 animation->setCurrentTimeInternal(40);
652 animation->setSource(makeAnimation(60).get()); 652 animation->setSource(makeAnimation(60));
653 EXPECT_FALSE(animation->limited()); 653 EXPECT_FALSE(animation->limited());
654 EXPECT_EQ(40, animation->currentTimeInternal()); 654 EXPECT_EQ(40, animation->currentTimeInternal());
655 simulateFrame(10); 655 simulateFrame(10);
656 EXPECT_EQ(50, animation->currentTimeInternal()); 656 EXPECT_EQ(50, animation->currentTimeInternal());
657 } 657 }
658 658
659 659
660 TEST_F(AnimationAnimationTest, EmptyAnimationsDontUpdateEffects) 660 TEST_F(AnimationAnimationTest, EmptyAnimationsDontUpdateEffects)
661 { 661 {
662 animation = timeline->play(0); 662 animation = timeline->play(0);
(...skipping 12 matching lines...) Expand all
675 animation->setSource(animationNode); 675 animation->setSource(animationNode);
676 EXPECT_EQ(0, animation2->source()); 676 EXPECT_EQ(0, animation2->source());
677 } 677 }
678 678
679 TEST_F(AnimationAnimationTest, AnimationsReturnTimeToNextEffect) 679 TEST_F(AnimationAnimationTest, AnimationsReturnTimeToNextEffect)
680 { 680 {
681 Timing timing; 681 Timing timing;
682 timing.startDelay = 1; 682 timing.startDelay = 1;
683 timing.iterationDuration = 1; 683 timing.iterationDuration = 1;
684 timing.endDelay = 1; 684 timing.endDelay = 1;
685 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(0 , nullptr, timing); 685 KeyframeEffect* keyframeEffect = KeyframeEffect::create(0, nullptr, timing);
686 animation = timeline->play(keyframeEffect.get()); 686 animation = timeline->play(keyframeEffect);
687 animation->setStartTime(0); 687 animation->setStartTime(0);
688 688
689 simulateFrame(0); 689 simulateFrame(0);
690 EXPECT_EQ(1, animation->timeToEffectChange()); 690 EXPECT_EQ(1, animation->timeToEffectChange());
691 691
692 simulateFrame(0.5); 692 simulateFrame(0.5);
693 EXPECT_EQ(0.5, animation->timeToEffectChange()); 693 EXPECT_EQ(0.5, animation->timeToEffectChange());
694 694
695 simulateFrame(1); 695 simulateFrame(1);
696 EXPECT_EQ(0, animation->timeToEffectChange()); 696 EXPECT_EQ(0, animation->timeToEffectChange());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 // received from the compositor yet, as cancel() nukes start times. 776 // received from the compositor yet, as cancel() nukes start times.
777 simulateFrame(0); 777 simulateFrame(0);
778 EXPECT_EQ(std::numeric_limits<double>::infinity(), animation->timeToEffectCh ange()); 778 EXPECT_EQ(std::numeric_limits<double>::infinity(), animation->timeToEffectCh ange());
779 } 779 }
780 780
781 TEST_F(AnimationAnimationTest, AttachedAnimations) 781 TEST_F(AnimationAnimationTest, AttachedAnimations)
782 { 782 {
783 RefPtrWillBePersistent<Element> element = document->createElement("foo", ASS ERT_NO_EXCEPTION); 783 RefPtrWillBePersistent<Element> element = document->createElement("foo", ASS ERT_NO_EXCEPTION);
784 784
785 Timing timing; 785 Timing timing;
786 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(e lement.get(), nullptr, timing); 786 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), nullp tr, timing);
787 RefPtrWillBeRawPtr<Animation> animation = timeline->play(keyframeEffect.get( )); 787 Animation* anim = timeline->play(keyframeEffect);
788 simulateFrame(0); 788 simulateFrame(0);
789 timeline->serviceAnimations(TimingUpdateForAnimationFrame); 789 timeline->serviceAnimations(TimingUpdateForAnimationFrame);
790 EXPECT_EQ(1U, element->elementAnimations()->animations().find(animation.get( ))->value); 790 EXPECT_EQ(1U, element->elementAnimations()->animations().find(anim)->value);
791 791
792 animation.release();
793 Heap::collectAllGarbage(); 792 Heap::collectAllGarbage();
794 EXPECT_TRUE(element->elementAnimations()->animations().isEmpty()); 793 EXPECT_TRUE(element->elementAnimations()->animations().isEmpty());
795 } 794 }
796 795
797 TEST_F(AnimationAnimationTest, HasLowerPriority) 796 TEST_F(AnimationAnimationTest, HasLowerPriority)
798 { 797 {
799 RefPtrWillBeRawPtr<Animation> animation1 = timeline->play(0); 798 Animation* animation1 = timeline->play(nullptr);
800 RefPtrWillBeRawPtr<Animation> animation2 = timeline->play(0); 799 Animation* animation2 = timeline->play(nullptr);
801 EXPECT_TRUE(Animation::hasLowerPriority(animation1.get(), animation2.get())) ; 800 EXPECT_TRUE(Animation::hasLowerPriority(animation1, animation2));
802 } 801 }
803 802
804 TEST_F(AnimationAnimationTest, PlayAfterCancel) 803 TEST_F(AnimationAnimationTest, PlayAfterCancel)
805 { 804 {
806 animation->cancel(); 805 animation->cancel();
807 EXPECT_EQ(Animation::Idle, animation->playStateInternal()); 806 EXPECT_EQ(Animation::Idle, animation->playStateInternal());
808 EXPECT_TRUE(std::isnan(animation->currentTime())); 807 EXPECT_TRUE(std::isnan(animation->currentTime()));
809 EXPECT_TRUE(std::isnan(animation->startTime())); 808 EXPECT_TRUE(std::isnan(animation->startTime()));
810 animation->play(); 809 animation->play();
811 EXPECT_EQ(Animation::Pending, animation->playStateInternal()); 810 EXPECT_EQ(Animation::Pending, animation->playStateInternal());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 { 867 {
869 animation->cancel(); 868 animation->cancel();
870 EXPECT_EQ(Animation::Idle, animation->playStateInternal()); 869 EXPECT_EQ(Animation::Idle, animation->playStateInternal());
871 EXPECT_TRUE(std::isnan(animation->currentTime())); 870 EXPECT_TRUE(std::isnan(animation->currentTime()));
872 EXPECT_TRUE(std::isnan(animation->startTime())); 871 EXPECT_TRUE(std::isnan(animation->startTime()));
873 animation->pause(); 872 animation->pause();
874 EXPECT_EQ(Animation::Idle, animation->playStateInternal()); 873 EXPECT_EQ(Animation::Idle, animation->playStateInternal());
875 EXPECT_TRUE(std::isnan(animation->currentTime())); 874 EXPECT_TRUE(std::isnan(animation->currentTime()));
876 EXPECT_TRUE(std::isnan(animation->startTime())); 875 EXPECT_TRUE(std::isnan(animation->startTime()));
877 } 876 }
878
879 } 877 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698