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

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

Issue 251183006: Web Animations: Timeline should not advance during task execution (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Deflake element-animate-position-crash. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/animation/AnimationClock.cpp ('k') | Source/core/animation/DocumentAnimations.cpp » ('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 21 matching lines...) Expand all
32 #include "core/animation/AnimationClock.h" 32 #include "core/animation/AnimationClock.h"
33 33
34 #include "wtf/OwnPtr.h" 34 #include "wtf/OwnPtr.h"
35 #include <gtest/gtest.h> 35 #include <gtest/gtest.h>
36 36
37 using namespace WebCore; 37 using namespace WebCore;
38 38
39 namespace { 39 namespace {
40 40
41 class AnimationAnimationClockTest : public ::testing::Test { 41 class AnimationAnimationClockTest : public ::testing::Test {
42 public:
43 AnimationAnimationClockTest()
44 : animationClock(mockTimeFunction)
45 {}
42 protected: 46 protected:
43 virtual void SetUp() 47 virtual void SetUp()
44 { 48 {
45 animationClock = AnimationClock::create(mockTimeFunction); 49 mockTime = 0;
46 mockTime = 200; 50 animationClock.resetTimeForTesting();
47 } 51 }
48 52
49 static double mockTimeFunction() 53 static double mockTimeFunction()
50 { 54 {
51 return mockTime; 55 return mockTime;
52 } 56 }
53 57
54 static double mockTime; 58 static double mockTime;
55 OwnPtr<AnimationClock> animationClock; 59 AnimationClock animationClock;
56 }; 60 };
57 61
58 double AnimationAnimationClockTest::mockTime; 62 double AnimationAnimationClockTest::mockTime;
59 63
60 TEST_F(AnimationAnimationClockTest, CurrentTime) 64 TEST_F(AnimationAnimationClockTest, TimeDoesNotChange)
61 { 65 {
62 // Current time should not advance until minTimeBeforeUnsynchronizedTick has elapsed 66 animationClock.updateTime(100);
63 EXPECT_EQ(200, animationClock->currentTime()); 67 EXPECT_EQ(100, animationClock.currentTime());
64 mockTime = 200 + minTimeBeforeUnsynchronizedAnimationClockTick / 2.0; 68 EXPECT_EQ(100, animationClock.currentTime());
65 EXPECT_EQ(200, animationClock->currentTime());
66
67 mockTime = 200 + minTimeBeforeUnsynchronizedAnimationClockTick;
68 EXPECT_EQ(mockTime, animationClock->currentTime());
69 } 69 }
70 70
71 TEST_F(AnimationAnimationClockTest, UpdateTime) 71 TEST_F(AnimationAnimationClockTest, TimeAdvancesWhenUpdated)
72 { 72 {
73 animationClock->updateTime(100); 73 animationClock.updateTime(100);
74 EXPECT_EQ(100, animationClock->currentTime()); 74 EXPECT_EQ(100, animationClock.currentTime());
75 mockTime = 200;
76 EXPECT_EQ(100, animationClock->currentTime());
77 75
78 animationClock->unfreeze(); 76 animationClock.updateTime(200);
79 EXPECT_EQ(200, animationClock->currentTime()); 77 EXPECT_EQ(200, animationClock.currentTime());
78 }
80 79
81 animationClock->updateTime(300); 80 TEST_F(AnimationAnimationClockTest, TimeAdvancesToTaskTime)
82 EXPECT_EQ(300, animationClock->currentTime()); 81 {
83 mockTime = 400; 82 animationClock.updateTime(100);
84 EXPECT_EQ(300, animationClock->currentTime()); 83 EXPECT_EQ(100, animationClock.currentTime());
84
85 mockTime = 150;
86 AnimationClock::notifyTaskStart();
87 EXPECT_GE(mockTime, animationClock.currentTime());
88 }
89
90 TEST_F(AnimationAnimationClockTest, TimeAdvancesToTaskTimeOnlyWhenRequired)
91 {
92 animationClock.updateTime(100);
93 EXPECT_EQ(100, animationClock.currentTime());
94
95 AnimationClock::notifyTaskStart();
96 animationClock.updateTime(125);
97 EXPECT_EQ(125, animationClock.currentTime());
98 }
99
100 TEST_F(AnimationAnimationClockTest, UpdateTimeIsMonotonic)
101 {
102 animationClock.updateTime(100);
103 EXPECT_EQ(100, animationClock.currentTime());
104
105 // Update can't go backwards.
106 animationClock.updateTime(50);
107 EXPECT_EQ(100, animationClock.currentTime());
108
109 mockTime = 50;
110 AnimationClock::notifyTaskStart();
111 EXPECT_EQ(100, animationClock.currentTime());
112
113 mockTime = 150;
114 AnimationClock::notifyTaskStart();
115 EXPECT_GE(150, animationClock.currentTime());
116
117 // Update can't go backwards after advance to estimate.
118 animationClock.updateTime(100);
119 EXPECT_GE(150, animationClock.currentTime());
85 } 120 }
86 121
87 } 122 }
OLDNEW
« no previous file with comments | « Source/core/animation/AnimationClock.cpp ('k') | Source/core/animation/DocumentAnimations.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698