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

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

Issue 2809543002: bindings: Pass is_null flag to attribute setters when they are nullable (Closed)
Patch Set: Created 3 years, 8 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 page_holder = DummyPageHolder::Create(); 57 page_holder = DummyPageHolder::Create();
58 document = &page_holder->GetDocument(); 58 document = &page_holder->GetDocument();
59 document->GetAnimationClock().ResetTimeForTesting(); 59 document->GetAnimationClock().ResetTimeForTesting();
60 timeline = AnimationTimeline::Create(document.Get()); 60 timeline = AnimationTimeline::Create(document.Get());
61 timeline->ResetForTesting(); 61 timeline->ResetForTesting();
62 animation = timeline->Play(0); 62 animation = timeline->Play(0);
63 animation->setStartTime(0); 63 animation->setStartTime(0, false);
64 animation->setEffect(MakeAnimation()); 64 animation->setEffect(MakeAnimation());
65 } 65 }
66 66
67 void StartTimeline() { SimulateFrame(0); } 67 void StartTimeline() { SimulateFrame(0); }
68 68
69 KeyframeEffect* MakeAnimation(double duration = 30, 69 KeyframeEffect* MakeAnimation(double duration = 30,
70 double playback_rate = 1) { 70 double playback_rate = 1) {
71 Timing timing; 71 Timing timing;
72 timing.iteration_duration = duration; 72 timing.iteration_duration = duration;
73 timing.playback_rate = playback_rate; 73 timing.playback_rate = playback_rate;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 TEST_F(AnimationAnimationTest, 152 TEST_F(AnimationAnimationTest,
153 SetCurrentTimeNegativeWithoutSimultaneousPlaybackRateChange) { 153 SetCurrentTimeNegativeWithoutSimultaneousPlaybackRateChange) {
154 SimulateFrame(20); 154 SimulateFrame(20);
155 EXPECT_EQ(20, animation->CurrentTimeInternal()); 155 EXPECT_EQ(20, animation->CurrentTimeInternal());
156 EXPECT_EQ(Animation::kRunning, animation->PlayStateInternal()); 156 EXPECT_EQ(Animation::kRunning, animation->PlayStateInternal());
157 animation->setPlaybackRate(-1); 157 animation->setPlaybackRate(-1);
158 EXPECT_EQ(Animation::kPending, animation->PlayStateInternal()); 158 EXPECT_EQ(Animation::kPending, animation->PlayStateInternal());
159 SimulateFrame(30); 159 SimulateFrame(30);
160 EXPECT_EQ(20, animation->CurrentTimeInternal()); 160 EXPECT_EQ(20, animation->CurrentTimeInternal());
161 EXPECT_EQ(Animation::kRunning, animation->PlayStateInternal()); 161 EXPECT_EQ(Animation::kRunning, animation->PlayStateInternal());
162 animation->setCurrentTime(-10 * 1000); 162 animation->setCurrentTime(-10 * 1000, false);
163 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal()); 163 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal());
164 } 164 }
165 165
166 TEST_F(AnimationAnimationTest, SetCurrentTimePastContentEnd) { 166 TEST_F(AnimationAnimationTest, SetCurrentTimePastContentEnd) {
167 animation->setCurrentTime(50 * 1000); 167 animation->setCurrentTime(50 * 1000, false);
168 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal()); 168 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal());
169 EXPECT_EQ(50, animation->CurrentTimeInternal()); 169 EXPECT_EQ(50, animation->CurrentTimeInternal());
170 SimulateFrame(20); 170 SimulateFrame(20);
171 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal()); 171 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal());
172 EXPECT_EQ(50, animation->CurrentTimeInternal()); 172 EXPECT_EQ(50, animation->CurrentTimeInternal());
173 173
174 animation->setPlaybackRate(-2); 174 animation->setPlaybackRate(-2);
175 animation->setCurrentTime(50 * 1000); 175 animation->setCurrentTime(50 * 1000, false);
176 EXPECT_EQ(Animation::kPending, animation->PlayStateInternal()); 176 EXPECT_EQ(Animation::kPending, animation->PlayStateInternal());
177 EXPECT_EQ(50, animation->CurrentTimeInternal()); 177 EXPECT_EQ(50, animation->CurrentTimeInternal());
178 SimulateFrame(20); 178 SimulateFrame(20);
179 EXPECT_EQ(Animation::kRunning, animation->PlayStateInternal()); 179 EXPECT_EQ(Animation::kRunning, animation->PlayStateInternal());
180 SimulateFrame(40); 180 SimulateFrame(40);
181 EXPECT_EQ(10, animation->CurrentTimeInternal()); 181 EXPECT_EQ(10, animation->CurrentTimeInternal());
182 } 182 }
183 183
184 TEST_F(AnimationAnimationTest, SetCurrentTimeMax) { 184 TEST_F(AnimationAnimationTest, SetCurrentTimeMax) {
185 animation->SetCurrentTimeInternal(std::numeric_limits<double>::max()); 185 animation->SetCurrentTimeInternal(std::numeric_limits<double>::max());
186 EXPECT_EQ(std::numeric_limits<double>::max(), 186 EXPECT_EQ(std::numeric_limits<double>::max(),
187 animation->CurrentTimeInternal()); 187 animation->CurrentTimeInternal());
188 SimulateFrame(100); 188 SimulateFrame(100);
189 EXPECT_EQ(std::numeric_limits<double>::max(), 189 EXPECT_EQ(std::numeric_limits<double>::max(),
190 animation->CurrentTimeInternal()); 190 animation->CurrentTimeInternal());
191 } 191 }
192 192
193 TEST_F(AnimationAnimationTest, SetCurrentTimeSetsStartTime) { 193 TEST_F(AnimationAnimationTest, SetCurrentTimeSetsStartTime) {
194 EXPECT_EQ(0, animation->startTime()); 194 EXPECT_EQ(0, animation->startTime());
195 animation->setCurrentTime(1000); 195 animation->setCurrentTime(1000, false);
196 EXPECT_EQ(-1000, animation->startTime()); 196 EXPECT_EQ(-1000, animation->startTime());
197 SimulateFrame(1); 197 SimulateFrame(1);
198 EXPECT_EQ(-1000, animation->startTime()); 198 EXPECT_EQ(-1000, animation->startTime());
199 EXPECT_EQ(2000, animation->currentTime()); 199 EXPECT_EQ(2000, animation->currentTime());
200 } 200 }
201 201
202 TEST_F(AnimationAnimationTest, SetStartTime) { 202 TEST_F(AnimationAnimationTest, SetStartTime) {
203 SimulateFrame(20); 203 SimulateFrame(20);
204 EXPECT_EQ(Animation::kRunning, animation->PlayStateInternal()); 204 EXPECT_EQ(Animation::kRunning, animation->PlayStateInternal());
205 EXPECT_EQ(0, animation->StartTimeInternal()); 205 EXPECT_EQ(0, animation->StartTimeInternal());
206 EXPECT_EQ(20 * 1000, animation->currentTime()); 206 EXPECT_EQ(20 * 1000, animation->currentTime());
207 animation->setStartTime(10 * 1000); 207 animation->setStartTime(10 * 1000, false);
208 EXPECT_EQ(Animation::kRunning, animation->PlayStateInternal()); 208 EXPECT_EQ(Animation::kRunning, animation->PlayStateInternal());
209 EXPECT_EQ(10, animation->StartTimeInternal()); 209 EXPECT_EQ(10, animation->StartTimeInternal());
210 EXPECT_EQ(10 * 1000, animation->currentTime()); 210 EXPECT_EQ(10 * 1000, animation->currentTime());
211 SimulateFrame(30); 211 SimulateFrame(30);
212 EXPECT_EQ(10, animation->StartTimeInternal()); 212 EXPECT_EQ(10, animation->StartTimeInternal());
213 EXPECT_EQ(20 * 1000, animation->currentTime()); 213 EXPECT_EQ(20 * 1000, animation->currentTime());
214 animation->setStartTime(-20 * 1000); 214 animation->setStartTime(-20 * 1000, false);
215 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal()); 215 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal());
216 } 216 }
217 217
218 TEST_F(AnimationAnimationTest, SetStartTimeLimitsAnimation) { 218 TEST_F(AnimationAnimationTest, SetStartTimeLimitsAnimation) {
219 animation->setStartTime(-50 * 1000); 219 animation->setStartTime(-50 * 1000, false);
220 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal()); 220 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal());
221 EXPECT_EQ(30, animation->CurrentTimeInternal()); 221 EXPECT_EQ(30, animation->CurrentTimeInternal());
222 animation->setPlaybackRate(-1); 222 animation->setPlaybackRate(-1);
223 EXPECT_EQ(Animation::kPending, animation->PlayStateInternal()); 223 EXPECT_EQ(Animation::kPending, animation->PlayStateInternal());
224 animation->setStartTime(-100 * 1000); 224 animation->setStartTime(-100 * 1000, false);
225 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal()); 225 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal());
226 EXPECT_EQ(0, animation->CurrentTimeInternal()); 226 EXPECT_EQ(0, animation->CurrentTimeInternal());
227 EXPECT_TRUE(animation->Limited()); 227 EXPECT_TRUE(animation->Limited());
228 } 228 }
229 229
230 TEST_F(AnimationAnimationTest, SetStartTimeOnLimitedAnimation) { 230 TEST_F(AnimationAnimationTest, SetStartTimeOnLimitedAnimation) {
231 SimulateFrame(30); 231 SimulateFrame(30);
232 animation->setStartTime(-10 * 1000); 232 animation->setStartTime(-10 * 1000, false);
233 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal()); 233 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal());
234 EXPECT_EQ(30, animation->CurrentTimeInternal()); 234 EXPECT_EQ(30, animation->CurrentTimeInternal());
235 animation->SetCurrentTimeInternal(50); 235 animation->SetCurrentTimeInternal(50);
236 animation->setStartTime(-40 * 1000); 236 animation->setStartTime(-40 * 1000, false);
237 EXPECT_EQ(30, animation->CurrentTimeInternal()); 237 EXPECT_EQ(30, animation->CurrentTimeInternal());
238 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal()); 238 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal());
239 EXPECT_TRUE(animation->Limited()); 239 EXPECT_TRUE(animation->Limited());
240 } 240 }
241 241
242 TEST_F(AnimationAnimationTest, StartTimePauseFinish) { 242 TEST_F(AnimationAnimationTest, StartTimePauseFinish) {
243 NonThrowableExceptionState exception_state; 243 NonThrowableExceptionState exception_state;
244 animation->pause(); 244 animation->pause();
245 EXPECT_EQ(Animation::kPending, animation->PlayStateInternal()); 245 EXPECT_EQ(Animation::kPending, animation->PlayStateInternal());
246 EXPECT_TRUE(std::isnan(animation->startTime())); 246 EXPECT_TRUE(std::isnan(animation->startTime()));
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 } 379 }
380 380
381 TEST_F(AnimationAnimationTest, ReverseSeeksToStart) { 381 TEST_F(AnimationAnimationTest, ReverseSeeksToStart) {
382 animation->SetCurrentTimeInternal(-10); 382 animation->SetCurrentTimeInternal(-10);
383 animation->setPlaybackRate(-1); 383 animation->setPlaybackRate(-1);
384 animation->reverse(); 384 animation->reverse();
385 EXPECT_EQ(0, animation->CurrentTimeInternal()); 385 EXPECT_EQ(0, animation->CurrentTimeInternal());
386 } 386 }
387 387
388 TEST_F(AnimationAnimationTest, ReverseSeeksToEnd) { 388 TEST_F(AnimationAnimationTest, ReverseSeeksToEnd) {
389 animation->setCurrentTime(40 * 1000); 389 animation->setCurrentTime(40 * 1000, false);
390 animation->reverse(); 390 animation->reverse();
391 EXPECT_EQ(30, animation->CurrentTimeInternal()); 391 EXPECT_EQ(30, animation->CurrentTimeInternal());
392 } 392 }
393 393
394 TEST_F(AnimationAnimationTest, ReverseBeyondLimit) { 394 TEST_F(AnimationAnimationTest, ReverseBeyondLimit) {
395 animation->SetCurrentTimeInternal(40); 395 animation->SetCurrentTimeInternal(40);
396 animation->setPlaybackRate(-1); 396 animation->setPlaybackRate(-1);
397 animation->reverse(); 397 animation->reverse();
398 EXPECT_EQ(Animation::kPending, animation->PlayStateInternal()); 398 EXPECT_EQ(Animation::kPending, animation->PlayStateInternal());
399 EXPECT_EQ(0, animation->CurrentTimeInternal()); 399 EXPECT_EQ(0, animation->CurrentTimeInternal());
(...skipping 11 matching lines...) Expand all
411 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal()); 411 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal());
412 412
413 animation->setPlaybackRate(-1); 413 animation->setPlaybackRate(-1);
414 animation->finish(exception_state); 414 animation->finish(exception_state);
415 EXPECT_EQ(0, animation->CurrentTimeInternal()); 415 EXPECT_EQ(0, animation->CurrentTimeInternal());
416 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal()); 416 EXPECT_EQ(Animation::kFinished, animation->PlayStateInternal());
417 } 417 }
418 418
419 TEST_F(AnimationAnimationTest, FinishAfterEffectEnd) { 419 TEST_F(AnimationAnimationTest, FinishAfterEffectEnd) {
420 NonThrowableExceptionState exception_state; 420 NonThrowableExceptionState exception_state;
421 animation->setCurrentTime(40 * 1000); 421 animation->setCurrentTime(40 * 1000, false);
422 animation->finish(exception_state); 422 animation->finish(exception_state);
423 EXPECT_EQ(40, animation->CurrentTimeInternal()); 423 EXPECT_EQ(40, animation->CurrentTimeInternal());
424 } 424 }
425 425
426 TEST_F(AnimationAnimationTest, FinishBeforeStart) { 426 TEST_F(AnimationAnimationTest, FinishBeforeStart) {
427 NonThrowableExceptionState exception_state; 427 NonThrowableExceptionState exception_state;
428 animation->SetCurrentTimeInternal(-10); 428 animation->SetCurrentTimeInternal(-10);
429 animation->setPlaybackRate(-1); 429 animation->setPlaybackRate(-1);
430 animation->finish(exception_state); 430 animation->finish(exception_state);
431 EXPECT_EQ(0, animation->CurrentTimeInternal()); 431 EXPECT_EQ(0, animation->CurrentTimeInternal());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 animation->setPlaybackRate(std::numeric_limits<double>::max()); 532 animation->setPlaybackRate(std::numeric_limits<double>::max());
533 SimulateFrame(0); 533 SimulateFrame(0);
534 EXPECT_EQ(std::numeric_limits<double>::max(), animation->playbackRate()); 534 EXPECT_EQ(std::numeric_limits<double>::max(), animation->playbackRate());
535 EXPECT_EQ(0, animation->CurrentTimeInternal()); 535 EXPECT_EQ(0, animation->CurrentTimeInternal());
536 SimulateFrame(1); 536 SimulateFrame(1);
537 EXPECT_EQ(30, animation->CurrentTimeInternal()); 537 EXPECT_EQ(30, animation->CurrentTimeInternal());
538 } 538 }
539 539
540 TEST_F(AnimationAnimationTest, SetEffect) { 540 TEST_F(AnimationAnimationTest, SetEffect) {
541 animation = timeline->Play(0); 541 animation = timeline->Play(0);
542 animation->setStartTime(0); 542 animation->setStartTime(0, false);
543 AnimationEffectReadOnly* effect1 = MakeAnimation(); 543 AnimationEffectReadOnly* effect1 = MakeAnimation();
544 AnimationEffectReadOnly* effect2 = MakeAnimation(); 544 AnimationEffectReadOnly* effect2 = MakeAnimation();
545 animation->setEffect(effect1); 545 animation->setEffect(effect1);
546 EXPECT_EQ(effect1, animation->effect()); 546 EXPECT_EQ(effect1, animation->effect());
547 EXPECT_EQ(0, animation->CurrentTimeInternal()); 547 EXPECT_EQ(0, animation->CurrentTimeInternal());
548 animation->SetCurrentTimeInternal(15); 548 animation->SetCurrentTimeInternal(15);
549 animation->setEffect(effect2); 549 animation->setEffect(effect2);
550 EXPECT_EQ(15, animation->CurrentTimeInternal()); 550 EXPECT_EQ(15, animation->CurrentTimeInternal());
551 EXPECT_EQ(0, effect1->GetAnimation()); 551 EXPECT_EQ(0, effect1->GetAnimation());
552 EXPECT_EQ(animation, effect2->GetAnimation()); 552 EXPECT_EQ(animation, effect2->GetAnimation());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 EXPECT_EQ(0, animation2->effect()); 590 EXPECT_EQ(0, animation2->effect());
591 } 591 }
592 592
593 TEST_F(AnimationAnimationTest, AnimationsReturnTimeToNextEffect) { 593 TEST_F(AnimationAnimationTest, AnimationsReturnTimeToNextEffect) {
594 Timing timing; 594 Timing timing;
595 timing.start_delay = 1; 595 timing.start_delay = 1;
596 timing.iteration_duration = 1; 596 timing.iteration_duration = 1;
597 timing.end_delay = 1; 597 timing.end_delay = 1;
598 KeyframeEffect* keyframe_effect = KeyframeEffect::Create(0, nullptr, timing); 598 KeyframeEffect* keyframe_effect = KeyframeEffect::Create(0, nullptr, timing);
599 animation = timeline->Play(keyframe_effect); 599 animation = timeline->Play(keyframe_effect);
600 animation->setStartTime(0); 600 animation->setStartTime(0, false);
601 601
602 SimulateFrame(0); 602 SimulateFrame(0);
603 EXPECT_EQ(1, animation->TimeToEffectChange()); 603 EXPECT_EQ(1, animation->TimeToEffectChange());
604 604
605 SimulateFrame(0.5); 605 SimulateFrame(0.5);
606 EXPECT_EQ(0.5, animation->TimeToEffectChange()); 606 EXPECT_EQ(0.5, animation->TimeToEffectChange());
607 607
608 SimulateFrame(1); 608 SimulateFrame(1);
609 EXPECT_EQ(0, animation->TimeToEffectChange()); 609 EXPECT_EQ(0, animation->TimeToEffectChange());
610 610
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 EXPECT_EQ(0, animation->currentTime()); 727 EXPECT_EQ(0, animation->currentTime());
728 EXPECT_TRUE(std::isnan(animation->startTime())); 728 EXPECT_TRUE(std::isnan(animation->startTime()));
729 SimulateFrame(10); 729 SimulateFrame(10);
730 EXPECT_EQ(Animation::kRunning, animation->PlayStateInternal()); 730 EXPECT_EQ(Animation::kRunning, animation->PlayStateInternal());
731 EXPECT_EQ(0, animation->currentTime()); 731 EXPECT_EQ(0, animation->currentTime());
732 EXPECT_EQ(10 * 1000, animation->startTime()); 732 EXPECT_EQ(10 * 1000, animation->startTime());
733 } 733 }
734 734
735 TEST_F(AnimationAnimationTest, PlayBackwardsAfterCancel) { 735 TEST_F(AnimationAnimationTest, PlayBackwardsAfterCancel) {
736 animation->setPlaybackRate(-1); 736 animation->setPlaybackRate(-1);
737 animation->setCurrentTime(15 * 1000); 737 animation->setCurrentTime(15 * 1000, false);
738 SimulateFrame(0); 738 SimulateFrame(0);
739 animation->cancel(); 739 animation->cancel();
740 EXPECT_EQ(Animation::kIdle, animation->PlayStateInternal()); 740 EXPECT_EQ(Animation::kIdle, animation->PlayStateInternal());
741 EXPECT_TRUE(std::isnan(animation->currentTime())); 741 EXPECT_TRUE(std::isnan(animation->currentTime()));
742 EXPECT_TRUE(std::isnan(animation->startTime())); 742 EXPECT_TRUE(std::isnan(animation->startTime()));
743 animation->play(); 743 animation->play();
744 EXPECT_EQ(Animation::kPending, animation->PlayStateInternal()); 744 EXPECT_EQ(Animation::kPending, animation->PlayStateInternal());
745 EXPECT_EQ(30 * 1000, animation->currentTime()); 745 EXPECT_EQ(30 * 1000, animation->currentTime());
746 EXPECT_TRUE(std::isnan(animation->startTime())); 746 EXPECT_TRUE(std::isnan(animation->startTime()));
747 SimulateFrame(10); 747 SimulateFrame(10);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 timeline->Play(keyframe_effect_not_composited); 813 timeline->Play(keyframe_effect_not_composited);
814 814
815 SimulateFrame(0, composited_element_ids); 815 SimulateFrame(0, composited_element_ids);
816 EXPECT_TRUE(animation_composited->CanStartAnimationOnCompositor( 816 EXPECT_TRUE(animation_composited->CanStartAnimationOnCompositor(
817 composited_element_ids)); 817 composited_element_ids));
818 EXPECT_FALSE(animation_not_composited->CanStartAnimationOnCompositor( 818 EXPECT_FALSE(animation_not_composited->CanStartAnimationOnCompositor(
819 composited_element_ids)); 819 composited_element_ids));
820 } 820 }
821 821
822 } // namespace blink 822 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/animation/Animation.cpp ('k') | third_party/WebKit/Source/core/animation/AnimationTimeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698