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

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: Intentional nullptr access 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 RefPtrWillBePersistent<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());
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 animation->setPlaybackRate(0); 501 animation->setPlaybackRate(0);
502 animation->finish(exceptionState); 502 animation->finish(exceptionState);
503 EXPECT_EQ(10, animation->currentTimeInternal()); 503 EXPECT_EQ(10, animation->currentTimeInternal());
504 } 504 }
505 505
506 TEST_F(AnimationAnimationTest, FinishRaisesException) 506 TEST_F(AnimationAnimationTest, FinishRaisesException)
507 { 507 {
508 Timing timing; 508 Timing timing;
509 timing.iterationDuration = 1; 509 timing.iterationDuration = 1;
510 timing.iterationCount = std::numeric_limits<double>::infinity(); 510 timing.iterationCount = std::numeric_limits<double>::infinity();
511 animation->setSource(KeyframeEffect::create(0, nullptr, timing).get()); 511 animation->setSource(KeyframeEffect::create(0, nullptr, timing));
512 animation->setCurrentTimeInternal(10); 512 animation->setCurrentTimeInternal(10);
513 513
514 animation->finish(exceptionState); 514 animation->finish(exceptionState);
515 EXPECT_EQ(10, animation->currentTimeInternal()); 515 EXPECT_EQ(10, animation->currentTimeInternal());
516 EXPECT_TRUE(exceptionState.hadException()); 516 EXPECT_TRUE(exceptionState.hadException());
517 EXPECT_EQ(InvalidStateError, exceptionState.code()); 517 EXPECT_EQ(InvalidStateError, exceptionState.code());
518 } 518 }
519 519
520 520
521 TEST_F(AnimationAnimationTest, LimitingAtSourceEnd) 521 TEST_F(AnimationAnimationTest, LimitingAtSourceEnd)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 EXPECT_EQ(0, animation->currentTimeInternal()); 619 EXPECT_EQ(0, animation->currentTimeInternal());
620 simulateFrame(1); 620 simulateFrame(1);
621 EXPECT_EQ(30, animation->currentTimeInternal()); 621 EXPECT_EQ(30, animation->currentTimeInternal());
622 } 622 }
623 623
624 624
625 TEST_F(AnimationAnimationTest, SetSource) 625 TEST_F(AnimationAnimationTest, SetSource)
626 { 626 {
627 animation = timeline->play(0); 627 animation = timeline->play(0);
628 animation->setStartTime(0); 628 animation->setStartTime(0);
629 RefPtrWillBeRawPtr<AnimationEffect> source1 = makeAnimation(); 629 AnimationEffect* source1 = makeAnimation();
630 RefPtrWillBeRawPtr<AnimationEffect> source2 = makeAnimation(); 630 AnimationEffect* source2 = makeAnimation();
631 animation->setSource(source1.get()); 631 animation->setSource(source1);
632 EXPECT_EQ(source1, animation->source()); 632 EXPECT_EQ(source1, animation->source());
633 EXPECT_EQ(0, animation->currentTimeInternal()); 633 EXPECT_EQ(0, animation->currentTimeInternal());
634 animation->setCurrentTimeInternal(15); 634 animation->setCurrentTimeInternal(15);
635 animation->setSource(source2.get()); 635 animation->setSource(source2);
636 EXPECT_EQ(15, animation->currentTimeInternal()); 636 EXPECT_EQ(15, animation->currentTimeInternal());
637 EXPECT_EQ(0, source1->animation()); 637 EXPECT_EQ(0, source1->animation());
638 EXPECT_EQ(animation.get(), source2->animation()); 638 EXPECT_EQ(animation.get(), source2->animation());
639 EXPECT_EQ(source2, animation->source()); 639 EXPECT_EQ(source2, animation->source());
640 } 640 }
641 641
642 TEST_F(AnimationAnimationTest, SetSourceLimitsAnimation) 642 TEST_F(AnimationAnimationTest, SetSourceLimitsAnimation)
643 { 643 {
644 animation->setCurrentTimeInternal(20); 644 animation->setCurrentTimeInternal(20);
645 animation->setSource(makeAnimation(10).get()); 645 animation->setSource(makeAnimation(10));
646 EXPECT_EQ(20, animation->currentTimeInternal()); 646 EXPECT_EQ(20, animation->currentTimeInternal());
647 EXPECT_TRUE(animation->limited()); 647 EXPECT_TRUE(animation->limited());
648 simulateFrame(10); 648 simulateFrame(10);
649 EXPECT_EQ(20, animation->currentTimeInternal()); 649 EXPECT_EQ(20, animation->currentTimeInternal());
650 } 650 }
651 651
652 TEST_F(AnimationAnimationTest, SetSourceUnlimitsAnimation) 652 TEST_F(AnimationAnimationTest, SetSourceUnlimitsAnimation)
653 { 653 {
654 animation->setCurrentTimeInternal(40); 654 animation->setCurrentTimeInternal(40);
655 animation->setSource(makeAnimation(60).get()); 655 animation->setSource(makeAnimation(60));
656 EXPECT_FALSE(animation->limited()); 656 EXPECT_FALSE(animation->limited());
657 EXPECT_EQ(40, animation->currentTimeInternal()); 657 EXPECT_EQ(40, animation->currentTimeInternal());
658 simulateFrame(10); 658 simulateFrame(10);
659 EXPECT_EQ(50, animation->currentTimeInternal()); 659 EXPECT_EQ(50, animation->currentTimeInternal());
660 } 660 }
661 661
662 662
663 TEST_F(AnimationAnimationTest, EmptyAnimationsDontUpdateEffects) 663 TEST_F(AnimationAnimationTest, EmptyAnimationsDontUpdateEffects)
664 { 664 {
665 animation = timeline->play(0); 665 animation = timeline->play(0);
(...skipping 12 matching lines...) Expand all
678 animation->setSource(animationNode); 678 animation->setSource(animationNode);
679 EXPECT_EQ(0, animation2->source()); 679 EXPECT_EQ(0, animation2->source());
680 } 680 }
681 681
682 TEST_F(AnimationAnimationTest, AnimationsReturnTimeToNextEffect) 682 TEST_F(AnimationAnimationTest, AnimationsReturnTimeToNextEffect)
683 { 683 {
684 Timing timing; 684 Timing timing;
685 timing.startDelay = 1; 685 timing.startDelay = 1;
686 timing.iterationDuration = 1; 686 timing.iterationDuration = 1;
687 timing.endDelay = 1; 687 timing.endDelay = 1;
688 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(0 , nullptr, timing); 688 KeyframeEffect* keyframeEffect = KeyframeEffect::create(0, nullptr, timing);
689 animation = timeline->play(keyframeEffect.get()); 689 animation = timeline->play(keyframeEffect);
690 animation->setStartTime(0); 690 animation->setStartTime(0);
691 691
692 simulateFrame(0); 692 simulateFrame(0);
693 EXPECT_EQ(1, animation->timeToEffectChange()); 693 EXPECT_EQ(1, animation->timeToEffectChange());
694 694
695 simulateFrame(0.5); 695 simulateFrame(0.5);
696 EXPECT_EQ(0.5, animation->timeToEffectChange()); 696 EXPECT_EQ(0.5, animation->timeToEffectChange());
697 697
698 simulateFrame(1); 698 simulateFrame(1);
699 EXPECT_EQ(0, animation->timeToEffectChange()); 699 EXPECT_EQ(0, animation->timeToEffectChange());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 // received from the compositor yet, as cancel() nukes start times. 779 // received from the compositor yet, as cancel() nukes start times.
780 simulateFrame(0); 780 simulateFrame(0);
781 EXPECT_EQ(std::numeric_limits<double>::infinity(), animation->timeToEffectCh ange()); 781 EXPECT_EQ(std::numeric_limits<double>::infinity(), animation->timeToEffectCh ange());
782 } 782 }
783 783
784 TEST_F(AnimationAnimationTest, AttachedAnimations) 784 TEST_F(AnimationAnimationTest, AttachedAnimations)
785 { 785 {
786 RefPtrWillBePersistent<Element> element = document->createElement("foo", ASS ERT_NO_EXCEPTION); 786 RefPtrWillBePersistent<Element> element = document->createElement("foo", ASS ERT_NO_EXCEPTION);
787 787
788 Timing timing; 788 Timing timing;
789 RefPtrWillBeRawPtr<KeyframeEffect> keyframeEffect = KeyframeEffect::create(e lement.get(), nullptr, timing); 789 KeyframeEffect* keyframeEffect = KeyframeEffect::create(element.get(), nullp tr, timing);
790 RefPtrWillBeRawPtr<Animation> animation = timeline->play(keyframeEffect.get( )); 790 RefPtrWillBeRawPtr<Animation> animation = timeline->play(keyframeEffect);
791 simulateFrame(0); 791 simulateFrame(0);
792 timeline->serviceAnimations(TimingUpdateForAnimationFrame); 792 timeline->serviceAnimations(TimingUpdateForAnimationFrame);
793 EXPECT_EQ(1U, element->elementAnimations()->animations().find(animation.get( ))->value); 793 EXPECT_EQ(1U, element->elementAnimations()->animations().find(animation.get( ))->value);
794 794
795 animation.release(); 795 animation.release();
796 Heap::collectAllGarbage(); 796 Heap::collectAllGarbage();
797 EXPECT_TRUE(element->elementAnimations()->animations().isEmpty()); 797 EXPECT_TRUE(element->elementAnimations()->animations().isEmpty());
798 } 798 }
799 799
800 TEST_F(AnimationAnimationTest, HasLowerPriority) 800 TEST_F(AnimationAnimationTest, HasLowerPriority)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 EXPECT_EQ(Animation::Idle, animation->playStateInternal()); 873 EXPECT_EQ(Animation::Idle, animation->playStateInternal());
874 EXPECT_TRUE(std::isnan(animation->currentTime())); 874 EXPECT_TRUE(std::isnan(animation->currentTime()));
875 EXPECT_TRUE(std::isnan(animation->startTime())); 875 EXPECT_TRUE(std::isnan(animation->startTime()));
876 animation->pause(); 876 animation->pause();
877 EXPECT_EQ(Animation::Idle, animation->playStateInternal()); 877 EXPECT_EQ(Animation::Idle, animation->playStateInternal());
878 EXPECT_TRUE(std::isnan(animation->currentTime())); 878 EXPECT_TRUE(std::isnan(animation->currentTime()));
879 EXPECT_TRUE(std::isnan(animation->startTime())); 879 EXPECT_TRUE(std::isnan(animation->startTime()));
880 } 880 }
881 881
882 } 882 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698