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

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

Issue 28263002: Plumb timeToNextEffect through players and animation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Moved location of timeToEffectChange calculation Created 7 years, 2 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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/animation/Player.h" 32 #include "core/animation/Player.h"
33 33
34 #include "core/animation/Animation.h"
34 #include "core/animation/DocumentTimeline.h" 35 #include "core/animation/DocumentTimeline.h"
35 #include "core/dom/Document.h" 36 #include "core/dom/Document.h"
36 #include "core/dom/QualifiedName.h" 37 #include "core/dom/QualifiedName.h"
37 #include "weborigin/KURL.h" 38 #include "weborigin/KURL.h"
38 #include <gtest/gtest.h> 39 #include <gtest/gtest.h>
39 40
40 using namespace WebCore; 41 using namespace WebCore;
41 42
42 namespace { 43 namespace {
43 44
44 class CoreAnimationPlayerTest : public ::testing::Test { 45 class CoreAnimationPlayerTest : public ::testing::Test {
45 protected: 46 protected:
46 virtual void SetUp() 47 virtual void SetUp()
47 { 48 {
48 document = Document::create(); 49 document = Document::create();
49 timeline = DocumentTimeline::create(document.get()); 50 timeline = DocumentTimeline::create(document.get());
50 player = Player::create(timeline.get(), 0); 51 player = Player::create(timeline.get(), 0);
51 timeline->setZeroTimeAsPerfTime(0); 52 timeline->setZeroTimeAsPerfTime(0);
52 } 53 }
53 54
54 bool updateTimeline(double time) 55 bool updateTimeline(double time, double* timeToEffectChange = 0)
55 { 56 {
56 timeline->serviceAnimations(time); 57 timeline->serviceAnimations(time);
57 // The timeline does not know about our player, so we have to explicitly call update(). 58 // The timeline does not know about our player, so we have to explicitly call update().
58 return player->update(); 59 return player->update(timeToEffectChange);
59 } 60 }
60 61
61 RefPtr<Document> document; 62 RefPtr<Document> document;
62 RefPtr<DocumentTimeline> timeline; 63 RefPtr<DocumentTimeline> timeline;
63 RefPtr<Player> player; 64 RefPtr<Player> player;
64 }; 65 };
65 66
66 TEST_F(CoreAnimationPlayerTest, InitialState) 67 TEST_F(CoreAnimationPlayerTest, InitialState)
67 { 68 {
68 EXPECT_EQ(0, timeline->currentTime()); 69 EXPECT_EQ(0, timeline->currentTime());
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 updateTimeline(0); 252 updateTimeline(0);
252 player->setCurrentTime(std::numeric_limits<double>::max()); 253 player->setCurrentTime(std::numeric_limits<double>::max());
253 EXPECT_EQ(std::numeric_limits<double>::max(), player->currentTime()); 254 EXPECT_EQ(std::numeric_limits<double>::max(), player->currentTime());
254 EXPECT_EQ(-std::numeric_limits<double>::max(), player->timeDrift()); 255 EXPECT_EQ(-std::numeric_limits<double>::max(), player->timeDrift());
255 256
256 updateTimeline(100); 257 updateTimeline(100);
257 EXPECT_EQ(std::numeric_limits<double>::max(), player->currentTime()); 258 EXPECT_EQ(std::numeric_limits<double>::max(), player->currentTime());
258 EXPECT_EQ(-std::numeric_limits<double>::max(), player->timeDrift()); 259 EXPECT_EQ(-std::numeric_limits<double>::max(), player->timeDrift());
259 } 260 }
260 261
262 TEST_F(CoreAnimationPlayerTest, EmptyPlayersDontUpdateEffects)
263 {
264 double timeToNextEffect;
265 updateTimeline(0, &timeToNextEffect);
266 EXPECT_EQ(std::numeric_limits<double>::infinity(), timeToNextEffect);
267
268 timeToNextEffect = 0;
269 updateTimeline(1234, &timeToNextEffect);
270 EXPECT_EQ(std::numeric_limits<double>::infinity(), timeToNextEffect);
261 } 271 }
272
273 TEST_F(CoreAnimationPlayerTest, PlayersReturnTimeToNextEffect)
274 {
275 Timing timing;
276 timing.startDelay = 1;
277 timing.iterationDuration = 1;
278 timing.hasIterationDuration = true;
279 RefPtr<Animation> animation = Animation::create(0, 0, timing);
280 player = Player::create(timeline.get(), animation.get());
281
282 double timeToNextEffect;
283 updateTimeline(0, &timeToNextEffect);
284 EXPECT_EQ(1, timeToNextEffect);
285
286 updateTimeline(0.5, &timeToNextEffect);
287 EXPECT_EQ(0.5, timeToNextEffect);
288
289 updateTimeline(1, &timeToNextEffect);
290 EXPECT_EQ(0, timeToNextEffect);
291
292 updateTimeline(1.5, &timeToNextEffect);
293 EXPECT_EQ(0, timeToNextEffect);
294
295 updateTimeline(2, &timeToNextEffect);
296 EXPECT_EQ(std::numeric_limits<double>::infinity(), timeToNextEffect);
297
298 updateTimeline(3, &timeToNextEffect);
299 EXPECT_EQ(std::numeric_limits<double>::infinity(), timeToNextEffect);
300 }
301
302 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698