| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/svg/graphics/SVGImage.h" | 5 #include "core/svg/graphics/SVGImage.h" |
| 6 | 6 |
| 7 #include "core/svg/graphics/SVGImageChromeClient.h" | 7 #include "core/svg/graphics/SVGImageChromeClient.h" |
| 8 #include "platform/SharedBuffer.h" | 8 #include "platform/SharedBuffer.h" |
| 9 #include "platform/Timer.h" | 9 #include "platform/Timer.h" |
| 10 #include "platform/geometry/FloatRect.h" | 10 #include "platform/geometry/FloatRect.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 TEST_F(SVGImageTest, TimelineSuspendAndResume) { | 84 TEST_F(SVGImageTest, TimelineSuspendAndResume) { |
| 85 const bool shouldPause = true; | 85 const bool shouldPause = true; |
| 86 load(kAnimatedDocument, shouldPause); | 86 load(kAnimatedDocument, shouldPause); |
| 87 SVGImageChromeClient& chromeClient = image().chromeClientForTesting(); | 87 SVGImageChromeClient& chromeClient = image().chromeClientForTesting(); |
| 88 Timer<SVGImageChromeClient>* timer = new Timer<SVGImageChromeClient>( | 88 Timer<SVGImageChromeClient>* timer = new Timer<SVGImageChromeClient>( |
| 89 &chromeClient, &SVGImageChromeClient::animationTimerFired); | 89 &chromeClient, &SVGImageChromeClient::animationTimerFired); |
| 90 chromeClient.setTimer(WTF::wrapUnique(timer)); | 90 chromeClient.setTimer(WTF::wrapUnique(timer)); |
| 91 | 91 |
| 92 // Simulate a draw. Cause a frame (timer) to be scheduled. | 92 // Simulate a draw. Cause a frame (timer) to be scheduled. |
| 93 pumpFrame(); | 93 pumpFrame(); |
| 94 EXPECT_TRUE(image().hasAnimations()); | 94 EXPECT_TRUE(image().maybeAnimated()); |
| 95 EXPECT_TRUE(timer->isActive()); | 95 EXPECT_TRUE(timer->isActive()); |
| 96 | 96 |
| 97 // Fire the timer/trigger a frame update. Since the observer always returns | 97 // Fire the timer/trigger a frame update. Since the observer always returns |
| 98 // true for shouldPauseAnimation, this will result in the timeline being | 98 // true for shouldPauseAnimation, this will result in the timeline being |
| 99 // suspended. | 99 // suspended. |
| 100 // TODO(alexclarke): Move over to using base::TimeDelta and base::TimeTicks so | 100 // TODO(alexclarke): Move over to using base::TimeDelta and base::TimeTicks so |
| 101 // we can avoid computations like this. | 101 // we can avoid computations like this. |
| 102 testing::runDelayedTasks(1.0 + timer->nextFireInterval() * 1000.0); | 102 testing::runDelayedTasks(1.0 + timer->nextFireInterval() * 1000.0); |
| 103 EXPECT_TRUE(chromeClient.isSuspended()); | 103 EXPECT_TRUE(chromeClient.isSuspended()); |
| 104 EXPECT_FALSE(timer->isActive()); | 104 EXPECT_FALSE(timer->isActive()); |
| 105 | 105 |
| 106 // Simulate a draw. This should resume the animation again. | 106 // Simulate a draw. This should resume the animation again. |
| 107 pumpFrame(); | 107 pumpFrame(); |
| 108 EXPECT_TRUE(timer->isActive()); | 108 EXPECT_TRUE(timer->isActive()); |
| 109 EXPECT_FALSE(chromeClient.isSuspended()); | 109 EXPECT_FALSE(chromeClient.isSuspended()); |
| 110 } | 110 } |
| 111 | 111 |
| 112 TEST_F(SVGImageTest, ResetAnimation) { | 112 TEST_F(SVGImageTest, ResetAnimation) { |
| 113 const bool shouldPause = false; | 113 const bool shouldPause = false; |
| 114 load(kAnimatedDocument, shouldPause); | 114 load(kAnimatedDocument, shouldPause); |
| 115 SVGImageChromeClient& chromeClient = image().chromeClientForTesting(); | 115 SVGImageChromeClient& chromeClient = image().chromeClientForTesting(); |
| 116 Timer<SVGImageChromeClient>* timer = new Timer<SVGImageChromeClient>( | 116 Timer<SVGImageChromeClient>* timer = new Timer<SVGImageChromeClient>( |
| 117 &chromeClient, &SVGImageChromeClient::animationTimerFired); | 117 &chromeClient, &SVGImageChromeClient::animationTimerFired); |
| 118 chromeClient.setTimer(WTF::wrapUnique(timer)); | 118 chromeClient.setTimer(WTF::wrapUnique(timer)); |
| 119 | 119 |
| 120 // Simulate a draw. Cause a frame (timer) to be scheduled. | 120 // Simulate a draw. Cause a frame (timer) to be scheduled. |
| 121 pumpFrame(); | 121 pumpFrame(); |
| 122 EXPECT_TRUE(image().hasAnimations()); | 122 EXPECT_TRUE(image().maybeAnimated()); |
| 123 EXPECT_TRUE(timer->isActive()); | 123 EXPECT_TRUE(timer->isActive()); |
| 124 | 124 |
| 125 // Reset the animation. This will suspend the timeline but not cancel the | 125 // Reset the animation. This will suspend the timeline but not cancel the |
| 126 // timer. | 126 // timer. |
| 127 image().resetAnimation(); | 127 image().resetAnimation(); |
| 128 EXPECT_TRUE(chromeClient.isSuspended()); | 128 EXPECT_TRUE(chromeClient.isSuspended()); |
| 129 EXPECT_TRUE(timer->isActive()); | 129 EXPECT_TRUE(timer->isActive()); |
| 130 | 130 |
| 131 // Fire the timer/trigger a frame update. The timeline will remain | 131 // Fire the timer/trigger a frame update. The timeline will remain |
| 132 // suspended and no frame will be scheduled. | 132 // suspended and no frame will be scheduled. |
| 133 // TODO(alexclarke): Move over to using base::TimeDelta and base::TimeTicks so | 133 // TODO(alexclarke): Move over to using base::TimeDelta and base::TimeTicks so |
| 134 // we can avoid computations like this. | 134 // we can avoid computations like this. |
| 135 testing::runDelayedTasks(1.0 + timer->nextFireInterval() * 1000.0); | 135 testing::runDelayedTasks(1.0 + timer->nextFireInterval() * 1000.0); |
| 136 EXPECT_TRUE(chromeClient.isSuspended()); | 136 EXPECT_TRUE(chromeClient.isSuspended()); |
| 137 EXPECT_FALSE(timer->isActive()); | 137 EXPECT_FALSE(timer->isActive()); |
| 138 | 138 |
| 139 // Simulate a draw. This should resume the animation again. | 139 // Simulate a draw. This should resume the animation again. |
| 140 pumpFrame(); | 140 pumpFrame(); |
| 141 EXPECT_FALSE(chromeClient.isSuspended()); | 141 EXPECT_FALSE(chromeClient.isSuspended()); |
| 142 EXPECT_TRUE(timer->isActive()); | 142 EXPECT_TRUE(timer->isActive()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 } // namespace blink | 145 } // namespace blink |
| OLD | NEW |