| 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" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 #include "third_party/skia/include/utils/SkNullCanvas.h" | 13 #include "third_party/skia/include/utils/SkNullCanvas.h" |
| 14 #include "wtf/PtrUtil.h" |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 class MockTaskRunner : public WebTaskRunner { | 19 class MockTaskRunner : public WebTaskRunner { |
| 19 public: | 20 public: |
| 20 void setTime(double newTime) { m_time = newTime; } | 21 void setTime(double newTime) { m_time = newTime; } |
| 21 | 22 |
| 22 MockTaskRunner() | 23 MockTaskRunner() |
| 23 : WebTaskRunner(), m_time(0.0), m_currentTask(nullptr) | 24 : WebTaskRunner(), m_time(0.0), m_currentTask(nullptr) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 40 } | 41 } |
| 41 bool runsTasksOnCurrentThread() override { return true; } | 42 bool runsTasksOnCurrentThread() override { return true; } |
| 42 std::unique_ptr<WebTaskRunner> clone() override { return nullptr; } | 43 std::unique_ptr<WebTaskRunner> clone() override { return nullptr; } |
| 43 double virtualTimeSeconds() const override { return 0.0; } | 44 double virtualTimeSeconds() const override { return 0.0; } |
| 44 double monotonicallyIncreasingVirtualTimeSeconds() const override { return m
_time; } | 45 double monotonicallyIncreasingVirtualTimeSeconds() const override { return m
_time; } |
| 45 | 46 |
| 46 double m_time; | 47 double m_time; |
| 47 Task* m_currentTask; | 48 Task* m_currentTask; |
| 48 }; | 49 }; |
| 49 | 50 |
| 50 class MockTimer : public Timer<SVGImageChromeClient> { | 51 class MockTimer : public TaskRunnerTimer<SVGImageChromeClient> { |
| 51 typedef void (SVGImageChromeClient::*TimerFiredFunction)(Timer*); | |
| 52 public: | 52 public: |
| 53 using TimerFiredFunction = typename TaskRunnerTimer<SVGImageChromeClient>::T
imerFiredFunction; |
| 54 |
| 53 MockTimer(SVGImageChromeClient* o, TimerFiredFunction f) | 55 MockTimer(SVGImageChromeClient* o, TimerFiredFunction f) |
| 54 : Timer<SVGImageChromeClient>(o, f, &m_taskRunner) | 56 : TaskRunnerTimer(&m_taskRunner, o, f) |
| 55 { | 57 { |
| 56 } | 58 } |
| 57 | 59 |
| 58 void fire() | 60 void fire() |
| 59 { | 61 { |
| 60 this->Timer<SVGImageChromeClient>::fired(); | 62 fired(); |
| 61 stop(); | 63 stop(); |
| 62 } | 64 } |
| 63 | 65 |
| 64 void setTime(double newTime) | 66 void setTime(double newTime) |
| 65 { | 67 { |
| 66 m_taskRunner.setTime(newTime); | 68 m_taskRunner.setTime(newTime); |
| 67 } | 69 } |
| 68 | 70 |
| 69 private: | 71 private: |
| 70 MockTaskRunner m_taskRunner; | 72 MockTaskRunner m_taskRunner; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 "</style>" | 136 "</style>" |
| 135 "<path class='spinner' fill='none' d='M 8,1.125 A 6.875,6.875 0 1 1 1.125,8'
stroke-width='2' stroke='blue'/>" | 137 "<path class='spinner' fill='none' d='M 8,1.125 A 6.875,6.875 0 1 1 1.125,8'
stroke-width='2' stroke='blue'/>" |
| 136 "</svg>"; | 138 "</svg>"; |
| 137 | 139 |
| 138 TEST_F(SVGImageTest, TimelineSuspendAndResume) | 140 TEST_F(SVGImageTest, TimelineSuspendAndResume) |
| 139 { | 141 { |
| 140 const bool shouldPause = true; | 142 const bool shouldPause = true; |
| 141 load(kAnimatedDocument, shouldPause); | 143 load(kAnimatedDocument, shouldPause); |
| 142 SVGImageChromeClient& chromeClient = image().chromeClientForTesting(); | 144 SVGImageChromeClient& chromeClient = image().chromeClientForTesting(); |
| 143 MockTimer* timer = new MockTimer(&chromeClient, &SVGImageChromeClient::anima
tionTimerFired); | 145 MockTimer* timer = new MockTimer(&chromeClient, &SVGImageChromeClient::anima
tionTimerFired); |
| 144 chromeClient.setTimer(timer); | 146 chromeClient.setTimer(wrapUnique(timer)); |
| 145 | 147 |
| 146 // Simulate a draw. Cause a frame (timer) to be scheduled. | 148 // Simulate a draw. Cause a frame (timer) to be scheduled. |
| 147 pumpFrame(); | 149 pumpFrame(); |
| 148 EXPECT_TRUE(image().hasAnimations()); | 150 EXPECT_TRUE(image().hasAnimations()); |
| 149 EXPECT_TRUE(timer->isActive()); | 151 EXPECT_TRUE(timer->isActive()); |
| 150 | 152 |
| 151 // Fire the timer/trigger a frame update. Since the observer always returns | 153 // Fire the timer/trigger a frame update. Since the observer always returns |
| 152 // true for shouldPauseAnimation, this will result in the timeline being | 154 // true for shouldPauseAnimation, this will result in the timeline being |
| 153 // suspended. | 155 // suspended. |
| 154 timer->fire(); | 156 timer->fire(); |
| 155 EXPECT_TRUE(chromeClient.isSuspended()); | 157 EXPECT_TRUE(chromeClient.isSuspended()); |
| 156 EXPECT_FALSE(timer->isActive()); | 158 EXPECT_FALSE(timer->isActive()); |
| 157 | 159 |
| 158 // Simulate a draw. This should resume the animation again. | 160 // Simulate a draw. This should resume the animation again. |
| 159 pumpFrame(); | 161 pumpFrame(); |
| 160 EXPECT_TRUE(timer->isActive()); | 162 EXPECT_TRUE(timer->isActive()); |
| 161 EXPECT_FALSE(chromeClient.isSuspended()); | 163 EXPECT_FALSE(chromeClient.isSuspended()); |
| 162 } | 164 } |
| 163 | 165 |
| 164 TEST_F(SVGImageTest, ResetAnimation) | 166 TEST_F(SVGImageTest, ResetAnimation) |
| 165 { | 167 { |
| 166 const bool shouldPause = false; | 168 const bool shouldPause = false; |
| 167 load(kAnimatedDocument, shouldPause); | 169 load(kAnimatedDocument, shouldPause); |
| 168 SVGImageChromeClient& chromeClient = image().chromeClientForTesting(); | 170 SVGImageChromeClient& chromeClient = image().chromeClientForTesting(); |
| 169 MockTimer* timer = new MockTimer(&chromeClient, &SVGImageChromeClient::anima
tionTimerFired); | 171 MockTimer* timer = new MockTimer(&chromeClient, &SVGImageChromeClient::anima
tionTimerFired); |
| 170 chromeClient.setTimer(timer); | 172 chromeClient.setTimer(wrapUnique(timer)); |
| 171 | 173 |
| 172 // Simulate a draw. Cause a frame (timer) to be scheduled. | 174 // Simulate a draw. Cause a frame (timer) to be scheduled. |
| 173 pumpFrame(); | 175 pumpFrame(); |
| 174 EXPECT_TRUE(image().hasAnimations()); | 176 EXPECT_TRUE(image().hasAnimations()); |
| 175 EXPECT_TRUE(timer->isActive()); | 177 EXPECT_TRUE(timer->isActive()); |
| 176 | 178 |
| 177 // Reset the animation. This will suspend the timeline but not cancel the | 179 // Reset the animation. This will suspend the timeline but not cancel the |
| 178 // timer. | 180 // timer. |
| 179 image().resetAnimation(); | 181 image().resetAnimation(); |
| 180 EXPECT_TRUE(chromeClient.isSuspended()); | 182 EXPECT_TRUE(chromeClient.isSuspended()); |
| 181 EXPECT_TRUE(timer->isActive()); | 183 EXPECT_TRUE(timer->isActive()); |
| 182 | 184 |
| 183 // Fire the timer/trigger a frame update. The timeline will remain | 185 // Fire the timer/trigger a frame update. The timeline will remain |
| 184 // suspended and no frame will be scheduled. | 186 // suspended and no frame will be scheduled. |
| 185 timer->fire(); | 187 timer->fire(); |
| 186 EXPECT_TRUE(chromeClient.isSuspended()); | 188 EXPECT_TRUE(chromeClient.isSuspended()); |
| 187 EXPECT_FALSE(timer->isActive()); | 189 EXPECT_FALSE(timer->isActive()); |
| 188 | 190 |
| 189 // Simulate a draw. This should resume the animation again. | 191 // Simulate a draw. This should resume the animation again. |
| 190 pumpFrame(); | 192 pumpFrame(); |
| 191 EXPECT_FALSE(chromeClient.isSuspended()); | 193 EXPECT_FALSE(chromeClient.isSuspended()); |
| 192 EXPECT_TRUE(timer->isActive()); | 194 EXPECT_TRUE(timer->isActive()); |
| 193 } | 195 } |
| 194 | 196 |
| 195 } // namespace blink | 197 } // namespace blink |
| OLD | NEW |