| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "platform/graphics/RecordingImageBufferSurface.h" | 5 #include "platform/graphics/RecordingImageBufferSurface.h" |
| 6 | 6 |
| 7 #include "platform/graphics/GraphicsContext.h" | 7 #include "platform/graphics/GraphicsContext.h" |
| 8 #include "platform/graphics/ImageBuffer.h" | 8 #include "platform/graphics/ImageBuffer.h" |
| 9 #include "platform/graphics/ImageBufferClient.h" | 9 #include "platform/graphics/ImageBufferClient.h" |
| 10 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 10 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 EXPECT_EQ(expectedSurfaceCreationCount, m_surfaceFactory->createSurfaceC
ount()); | 224 EXPECT_EQ(expectedSurfaceCreationCount, m_surfaceFactory->createSurfaceC
ount()); |
| 225 } | 225 } |
| 226 | 226 |
| 227 private: | 227 private: |
| 228 MockSurfaceFactory* m_surfaceFactory; | 228 MockSurfaceFactory* m_surfaceFactory; |
| 229 RecordingImageBufferSurface* m_testSurface; | 229 RecordingImageBufferSurface* m_testSurface; |
| 230 std::unique_ptr<FakeImageBufferClient> m_fakeImageBufferClient; | 230 std::unique_ptr<FakeImageBufferClient> m_fakeImageBufferClient; |
| 231 std::unique_ptr<ImageBuffer> m_imageBuffer; | 231 std::unique_ptr<ImageBuffer> m_imageBuffer; |
| 232 }; | 232 }; |
| 233 | 233 |
| 234 namespace { | |
| 235 | |
| 236 // The following test helper class installs a mock platform that provides a mock
WebThread | |
| 237 // for the current thread. The Mock thread is capable of queuing a single non-de
layed task | |
| 238 // and registering a single task observer. The run loop exits immediately after
running | |
| 239 // the single task. | |
| 240 | |
| 241 class CurrentThreadPlatformMock : public TestingPlatformSupport { | |
| 242 public: | |
| 243 CurrentThreadPlatformMock() { } | |
| 244 WebThread* currentThread() override { return &m_currentThread; } | |
| 245 | |
| 246 void enterRunLoop() { m_currentThread.enterRunLoop(); } | |
| 247 private: | |
| 248 class MockWebTaskRunner : public WebTaskRunner { | |
| 249 public: | |
| 250 MockWebTaskRunner() : m_task(0) { } | |
| 251 ~MockWebTaskRunner() override { } | |
| 252 | |
| 253 void postTask(const WebTraceLocation&, Task* task) override | |
| 254 { | |
| 255 EXPECT_EQ((Task*)0, m_task); | |
| 256 m_task = task; | |
| 257 } | |
| 258 | |
| 259 void postDelayedTask(const WebTraceLocation&, Task*, double delayMs) ove
rride { NOTREACHED(); }; | |
| 260 | |
| 261 bool runsTasksOnCurrentThread() override | |
| 262 { | |
| 263 NOTREACHED(); | |
| 264 return true; | |
| 265 } | |
| 266 | |
| 267 std::unique_ptr<WebTaskRunner> clone() override | |
| 268 { | |
| 269 NOTREACHED(); | |
| 270 return nullptr; | |
| 271 } | |
| 272 | |
| 273 double virtualTimeSeconds() const override | |
| 274 { | |
| 275 NOTREACHED(); | |
| 276 return 0.0; | |
| 277 } | |
| 278 | |
| 279 double monotonicallyIncreasingVirtualTimeSeconds() const override | |
| 280 { | |
| 281 NOTREACHED(); | |
| 282 return 0.0; | |
| 283 } | |
| 284 | |
| 285 base::SingleThreadTaskRunner* taskRunner() override | |
| 286 { | |
| 287 NOTREACHED(); | |
| 288 return nullptr; | |
| 289 } | |
| 290 | |
| 291 Task* m_task; | |
| 292 }; | |
| 293 | |
| 294 class CurrentThreadMock : public WebThread { | |
| 295 public: | |
| 296 CurrentThreadMock() : m_taskObserver(0) { } | |
| 297 | |
| 298 ~CurrentThreadMock() override | |
| 299 { | |
| 300 EXPECT_EQ((WebTaskRunner::Task*)0, m_taskRunner.m_task); | |
| 301 } | |
| 302 | |
| 303 WebTaskRunner* getWebTaskRunner() override | |
| 304 { | |
| 305 return &m_taskRunner; | |
| 306 } | |
| 307 | |
| 308 bool isCurrentThread() const override { return true; } | |
| 309 | |
| 310 PlatformThreadId threadId() const override | |
| 311 { | |
| 312 NOTREACHED(); | |
| 313 return 0; | |
| 314 } | |
| 315 | |
| 316 void addTaskObserver(TaskObserver* taskObserver) override | |
| 317 { | |
| 318 EXPECT_EQ(nullptr, m_taskObserver); | |
| 319 m_taskObserver = taskObserver; | |
| 320 } | |
| 321 | |
| 322 void removeTaskObserver(TaskObserver* taskObserver) override | |
| 323 { | |
| 324 EXPECT_EQ(m_taskObserver, taskObserver); | |
| 325 m_taskObserver = 0; | |
| 326 } | |
| 327 | |
| 328 WebScheduler* scheduler() const override | |
| 329 { | |
| 330 NOTREACHED(); | |
| 331 return nullptr; | |
| 332 } | |
| 333 | |
| 334 void enterRunLoop() | |
| 335 { | |
| 336 if (m_taskObserver) | |
| 337 m_taskObserver->willProcessTask(); | |
| 338 if (m_taskRunner.m_task) { | |
| 339 m_taskRunner.m_task->run(); | |
| 340 delete m_taskRunner.m_task; | |
| 341 m_taskRunner.m_task = 0; | |
| 342 } | |
| 343 if (m_taskObserver) | |
| 344 m_taskObserver->didProcessTask(); | |
| 345 } | |
| 346 | |
| 347 private: | |
| 348 MockWebTaskRunner m_taskRunner; | |
| 349 TaskObserver* m_taskObserver; | |
| 350 }; | |
| 351 | |
| 352 CurrentThreadMock m_currentThread; | |
| 353 }; | |
| 354 | |
| 355 } // anonymous namespace | |
| 356 | |
| 357 #define CALL_TEST_TASK_WRAPPER(TEST_METHOD)
\ | 234 #define CALL_TEST_TASK_WRAPPER(TEST_METHOD)
\ |
| 358 {
\ | 235 {
\ |
| 359 CurrentThreadPlatformMock ctpm;
\ | 236 TestingPlatformSupportWithMockScheduler testingPlatform;
\ |
| 360 Platform::current()->currentThread()->getWebTaskRunner()->postTask(BLINK
_FROM_HERE, WTF::bind(&RecordingImageBufferSurfaceTest::TEST_METHOD, WTF::unreta
ined(this))); \ | 237 Platform::current()->currentThread()->getWebTaskRunner()->postTask(BLINK
_FROM_HERE, WTF::bind(&RecordingImageBufferSurfaceTest::TEST_METHOD, WTF::unreta
ined(this))); \ |
| 361 ctpm.enterRunLoop(); \ | 238 testingPlatform.runUntilIdle(); \ |
| 362 } | 239 } |
| 363 | 240 |
| 364 TEST_F(RecordingImageBufferSurfaceTest, testEmptyPicture) | 241 TEST_F(RecordingImageBufferSurfaceTest, testEmptyPicture) |
| 365 { | 242 { |
| 366 testEmptyPicture(); | 243 testEmptyPicture(); |
| 367 } | 244 } |
| 368 | 245 |
| 369 TEST_F(RecordingImageBufferSurfaceTest, testNoFallbackWithClear) | 246 TEST_F(RecordingImageBufferSurfaceTest, testNoFallbackWithClear) |
| 370 { | 247 { |
| 371 testNoFallbackWithClear(); | 248 testNoFallbackWithClear(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 397 expectDisplayListEnabled(true); | 274 expectDisplayListEnabled(true); |
| 398 } | 275 } |
| 399 | 276 |
| 400 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) | 277 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) |
| 401 { | 278 { |
| 402 CALL_TEST_TASK_WRAPPER(testClearRect); | 279 CALL_TEST_TASK_WRAPPER(testClearRect); |
| 403 expectDisplayListEnabled(true); | 280 expectDisplayListEnabled(true); |
| 404 } | 281 } |
| 405 | 282 |
| 406 } // namespace blink | 283 } // namespace blink |
| OLD | NEW |