| 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 "config.h" | 5 #include "config.h" |
| 6 #include "platform/graphics/RecordingImageBufferSurface.h" | 6 #include "platform/graphics/RecordingImageBufferSurface.h" |
| 7 | 7 |
| 8 #include "platform/graphics/GraphicsContext.h" | 8 #include "platform/graphics/GraphicsContext.h" |
| 9 #include "platform/graphics/ImageBuffer.h" | 9 #include "platform/graphics/ImageBuffer.h" |
| 10 #include "platform/graphics/ImageBufferClient.h" | 10 #include "platform/graphics/ImageBufferClient.h" |
| 11 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 11 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
| 12 #include "platform/testing/TestingPlatformSupport.h" | |
| 13 #include "public/platform/Platform.h" | 12 #include "public/platform/Platform.h" |
| 14 #include "public/platform/WebTaskRunner.h" | 13 #include "public/platform/WebTaskRunner.h" |
| 15 #include "public/platform/WebThread.h" | 14 #include "public/platform/WebThread.h" |
| 16 #include "public/platform/WebTraceLocation.h" | 15 #include "public/platform/WebTraceLocation.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "third_party/skia/include/core/SkCanvas.h" | 18 #include "third_party/skia/include/core/SkCanvas.h" |
| 20 #include "third_party/skia/include/core/SkPictureRecorder.h" | 19 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 21 #include "wtf/OwnPtr.h" | 20 #include "wtf/OwnPtr.h" |
| 22 #include "wtf/PassOwnPtr.h" | 21 #include "wtf/PassOwnPtr.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 OwnPtr<FakeImageBufferClient> m_fakeImageBufferClient; | 229 OwnPtr<FakeImageBufferClient> m_fakeImageBufferClient; |
| 231 OwnPtr<ImageBuffer> m_imageBuffer; | 230 OwnPtr<ImageBuffer> m_imageBuffer; |
| 232 }; | 231 }; |
| 233 | 232 |
| 234 namespace { | 233 namespace { |
| 235 | 234 |
| 236 // The following test helper class installs a mock platform that provides a mock
WebThread | 235 // 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 | 236 // 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 | 237 // and registering a single task observer. The run loop exits immediately after
running |
| 239 // the single task. | 238 // the single task. |
| 239 class AutoInstallCurrentThreadPlatformMock { |
| 240 public: |
| 241 AutoInstallCurrentThreadPlatformMock() |
| 242 { |
| 243 m_oldPlatform = Platform::current(); |
| 244 Platform::initialize(&m_mockPlatform); |
| 245 } |
| 240 | 246 |
| 241 class CurrentThreadPlatformMock : public TestingPlatformSupport { | 247 ~AutoInstallCurrentThreadPlatformMock() |
| 242 public: | 248 { |
| 243 CurrentThreadPlatformMock() { } | 249 Platform::initialize(m_oldPlatform); |
| 244 WebThread* currentThread() override { return &m_currentThread; } | 250 } |
| 245 | 251 |
| 246 void enterRunLoop() { m_currentThread.enterRunLoop(); } | 252 void enterRunLoop() |
| 253 { |
| 254 m_mockPlatform.enterRunLoop(); |
| 255 } |
| 256 |
| 247 private: | 257 private: |
| 248 class MockWebTaskRunner : public WebTaskRunner { | 258 class MockWebTaskRunner : public WebTaskRunner { |
| 249 public: | 259 public: |
| 250 MockWebTaskRunner() : m_task(0) { } | 260 MockWebTaskRunner() : m_task(0) { } |
| 251 ~MockWebTaskRunner() override { } | 261 ~MockWebTaskRunner() override { } |
| 252 | 262 |
| 253 void postTask(const WebTraceLocation&, Task* task) override | 263 void postTask(const WebTraceLocation&, Task* task) override |
| 254 { | 264 { |
| 255 EXPECT_EQ((Task*)0, m_task); | 265 EXPECT_EQ((Task*)0, m_task); |
| 256 m_task = task; | 266 m_task = task; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 } | 328 } |
| 319 if (m_taskObserver) | 329 if (m_taskObserver) |
| 320 m_taskObserver->didProcessTask(); | 330 m_taskObserver->didProcessTask(); |
| 321 } | 331 } |
| 322 | 332 |
| 323 private: | 333 private: |
| 324 MockWebTaskRunner m_taskRunner; | 334 MockWebTaskRunner m_taskRunner; |
| 325 TaskObserver* m_taskObserver; | 335 TaskObserver* m_taskObserver; |
| 326 }; | 336 }; |
| 327 | 337 |
| 328 CurrentThreadMock m_currentThread; | 338 class CurrentThreadPlatformMock : public Platform { |
| 339 public: |
| 340 CurrentThreadPlatformMock() { } |
| 341 virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t
length) |
| 342 { |
| 343 RELEASE_ASSERT_NOT_REACHED(); |
| 344 } |
| 345 WebThread* currentThread() override { return &m_currentThread; } |
| 346 |
| 347 void enterRunLoop() { m_currentThread.enterRunLoop(); } |
| 348 private: |
| 349 CurrentThreadMock m_currentThread; |
| 350 }; |
| 351 |
| 352 CurrentThreadPlatformMock m_mockPlatform; |
| 353 Platform* m_oldPlatform; |
| 329 }; | 354 }; |
| 330 | 355 |
| 331 } // anonymous namespace | 356 } // anonymous namespace |
| 332 | 357 |
| 333 #define DEFINE_TEST_TASK_WRAPPER_CLASS(TEST_METHOD)
\ | 358 #define DEFINE_TEST_TASK_WRAPPER_CLASS(TEST_METHOD)
\ |
| 334 class TestWrapperTask_ ## TEST_METHOD : public WebTaskRunner::Task {
\ | 359 class TestWrapperTask_ ## TEST_METHOD : public WebTaskRunner::Task {
\ |
| 335 public:
\ | 360 public:
\ |
| 336 TestWrapperTask_ ## TEST_METHOD(RecordingImageBufferSurfaceTest* test) :
m_test(test) { } \ | 361 TestWrapperTask_ ## TEST_METHOD(RecordingImageBufferSurfaceTest* test) :
m_test(test) { } \ |
| 337 void run() override { m_test->TEST_METHOD(); }
\ | 362 void run() override { m_test->TEST_METHOD(); }
\ |
| 338 private:
\ | 363 private:
\ |
| 339 RecordingImageBufferSurfaceTest* m_test;
\ | 364 RecordingImageBufferSurfaceTest* m_test;
\ |
| 340 }; | 365 }; |
| 341 | 366 |
| 342 #define CALL_TEST_TASK_WRAPPER(TEST_METHOD)
\ | 367 #define CALL_TEST_TASK_WRAPPER(TEST_METHOD)
\ |
| 343 {
\ | 368 {
\ |
| 344 CurrentThreadPlatformMock ctpm;
\ | 369 AutoInstallCurrentThreadPlatformMock ctpm;
\ |
| 345 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_
HERE, new TestWrapperTask_ ## TEST_METHOD(this)); \ | 370 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_
HERE, new TestWrapperTask_ ## TEST_METHOD(this)); \ |
| 346 ctpm.enterRunLoop(); \ | 371 ctpm.enterRunLoop(); \ |
| 347 } | 372 } |
| 348 | 373 |
| 349 TEST_F(RecordingImageBufferSurfaceTest, testEmptyPicture) | 374 TEST_F(RecordingImageBufferSurfaceTest, testEmptyPicture) |
| 350 { | 375 { |
| 351 testEmptyPicture(); | 376 testEmptyPicture(); |
| 352 } | 377 } |
| 353 | 378 |
| 354 TEST_F(RecordingImageBufferSurfaceTest, testNoFallbackWithClear) | 379 TEST_F(RecordingImageBufferSurfaceTest, testNoFallbackWithClear) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 } | 413 } |
| 389 | 414 |
| 390 DEFINE_TEST_TASK_WRAPPER_CLASS(testClearRect) | 415 DEFINE_TEST_TASK_WRAPPER_CLASS(testClearRect) |
| 391 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) | 416 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) |
| 392 { | 417 { |
| 393 CALL_TEST_TASK_WRAPPER(testClearRect); | 418 CALL_TEST_TASK_WRAPPER(testClearRect); |
| 394 expectDisplayListEnabled(true); | 419 expectDisplayListEnabled(true); |
| 395 } | 420 } |
| 396 | 421 |
| 397 } // namespace blink | 422 } // namespace blink |
| OLD | NEW |