| 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 "public/platform/Platform.h" | 12 #include "public/platform/Platform.h" |
| 13 #include "public/platform/WebTaskRunner.h" |
| 13 #include "public/platform/WebThread.h" | 14 #include "public/platform/WebThread.h" |
| 14 #include "public/platform/WebTraceLocation.h" | 15 #include "public/platform/WebTraceLocation.h" |
| 15 #include "third_party/skia/include/core/SkCanvas.h" | 16 #include "third_party/skia/include/core/SkCanvas.h" |
| 16 #include "third_party/skia/include/core/SkPictureRecorder.h" | 17 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 17 #include "wtf/OwnPtr.h" | 18 #include "wtf/OwnPtr.h" |
| 18 #include "wtf/PassOwnPtr.h" | 19 #include "wtf/PassOwnPtr.h" |
| 19 #include "wtf/RefPtr.h" | 20 #include "wtf/RefPtr.h" |
| 20 #include <gmock/gmock.h> | 21 #include <gmock/gmock.h> |
| 21 #include <gtest/gtest.h> | 22 #include <gtest/gtest.h> |
| 22 | 23 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 { | 248 { |
| 248 Platform::initialize(m_oldPlatform); | 249 Platform::initialize(m_oldPlatform); |
| 249 } | 250 } |
| 250 | 251 |
| 251 void enterRunLoop() | 252 void enterRunLoop() |
| 252 { | 253 { |
| 253 m_mockPlatform.enterRunLoop(); | 254 m_mockPlatform.enterRunLoop(); |
| 254 } | 255 } |
| 255 | 256 |
| 256 private: | 257 private: |
| 257 class CurrentThreadMock : public WebThread { | 258 class MockWebTaskRunner : public WebTaskRunner { |
| 258 public: | 259 public: |
| 259 CurrentThreadMock() : m_taskObserver(0), m_task(0) { } | 260 MockWebTaskRunner() : m_task(0) { } |
| 260 | 261 ~MockWebTaskRunner() override { } |
| 261 ~CurrentThreadMock() override | |
| 262 { | |
| 263 EXPECT_EQ((Task*)0, m_task); | |
| 264 } | |
| 265 | 262 |
| 266 virtual void postTask(const WebTraceLocation&, Task* task) | 263 virtual void postTask(const WebTraceLocation&, Task* task) |
| 267 { | 264 { |
| 268 EXPECT_EQ((Task*)0, m_task); | 265 EXPECT_EQ((Task*)0, m_task); |
| 269 m_task = task; | 266 m_task = task; |
| 270 } | 267 } |
| 271 | 268 |
| 272 void postDelayedTask(const WebTraceLocation&, Task*, long long delayMs)
override { ASSERT_NOT_REACHED(); }; | 269 void postDelayedTask(const WebTraceLocation&, Task*, long long delayMs)
override { ASSERT_NOT_REACHED(); }; |
| 273 | 270 |
| 271 Task* m_task; |
| 272 }; |
| 273 |
| 274 class CurrentThreadMock : public WebThread { |
| 275 public: |
| 276 CurrentThreadMock() : m_taskObserver(0) { } |
| 277 |
| 278 ~CurrentThreadMock() override |
| 279 { |
| 280 EXPECT_EQ((WebTaskRunner::Task*)0, m_taskRunner.m_task); |
| 281 } |
| 282 |
| 283 WebTaskRunner* taskRunner() override |
| 284 { |
| 285 return &m_taskRunner; |
| 286 } |
| 287 |
| 274 bool isCurrentThread() const override { return true; } | 288 bool isCurrentThread() const override { return true; } |
| 289 |
| 275 PlatformThreadId threadId() const override | 290 PlatformThreadId threadId() const override |
| 276 { | 291 { |
| 277 ASSERT_NOT_REACHED(); | 292 ASSERT_NOT_REACHED(); |
| 278 return 0; | 293 return 0; |
| 279 } | 294 } |
| 280 | 295 |
| 281 void addTaskObserver(TaskObserver* taskObserver) override | 296 void addTaskObserver(TaskObserver* taskObserver) override |
| 282 { | 297 { |
| 283 EXPECT_EQ((TaskObserver*)0, m_taskObserver); | 298 EXPECT_EQ(nullptr, m_taskObserver); |
| 284 m_taskObserver = taskObserver; | 299 m_taskObserver = taskObserver; |
| 285 } | 300 } |
| 286 | 301 |
| 287 void removeTaskObserver(TaskObserver* taskObserver) override | 302 void removeTaskObserver(TaskObserver* taskObserver) override |
| 288 { | 303 { |
| 289 EXPECT_EQ(m_taskObserver, taskObserver); | 304 EXPECT_EQ(m_taskObserver, taskObserver); |
| 290 m_taskObserver = 0; | 305 m_taskObserver = 0; |
| 291 } | 306 } |
| 292 | 307 |
| 293 WebScheduler* scheduler() const override | 308 WebScheduler* scheduler() const override |
| 294 { | 309 { |
| 295 ASSERT_NOT_REACHED(); | 310 ASSERT_NOT_REACHED(); |
| 296 return nullptr; | 311 return nullptr; |
| 297 } | 312 } |
| 298 | 313 |
| 299 void enterRunLoop() | 314 void enterRunLoop() |
| 300 { | 315 { |
| 301 if (m_taskObserver) | 316 if (m_taskObserver) |
| 302 m_taskObserver->willProcessTask(); | 317 m_taskObserver->willProcessTask(); |
| 303 if (m_task) { | 318 if (m_taskRunner.m_task) { |
| 304 m_task->run(); | 319 m_taskRunner.m_task->run(); |
| 305 delete m_task; | 320 delete m_taskRunner.m_task; |
| 306 m_task = 0; | 321 m_taskRunner.m_task = 0; |
| 307 } | 322 } |
| 308 if (m_taskObserver) | 323 if (m_taskObserver) |
| 309 m_taskObserver->didProcessTask(); | 324 m_taskObserver->didProcessTask(); |
| 310 } | 325 } |
| 311 | 326 |
| 312 private: | 327 private: |
| 328 MockWebTaskRunner m_taskRunner; |
| 313 TaskObserver* m_taskObserver; | 329 TaskObserver* m_taskObserver; |
| 314 Task* m_task; | |
| 315 }; | 330 }; |
| 316 | 331 |
| 317 class CurrentThreadPlatformMock : public Platform { | 332 class CurrentThreadPlatformMock : public Platform { |
| 318 public: | 333 public: |
| 319 CurrentThreadPlatformMock() { } | 334 CurrentThreadPlatformMock() { } |
| 320 virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t
length) { ASSERT_NOT_REACHED(); } | 335 virtual void cryptographicallyRandomValues(unsigned char* buffer, size_t
length) { ASSERT_NOT_REACHED(); } |
| 321 WebThread* currentThread() override { return &m_currentThread; } | 336 WebThread* currentThread() override { return &m_currentThread; } |
| 322 | 337 |
| 323 void enterRunLoop() { m_currentThread.enterRunLoop(); } | 338 void enterRunLoop() { m_currentThread.enterRunLoop(); } |
| 324 private: | 339 private: |
| 325 CurrentThreadMock m_currentThread; | 340 CurrentThreadMock m_currentThread; |
| 326 }; | 341 }; |
| 327 | 342 |
| 328 CurrentThreadPlatformMock m_mockPlatform; | 343 CurrentThreadPlatformMock m_mockPlatform; |
| 329 Platform* m_oldPlatform; | 344 Platform* m_oldPlatform; |
| 330 }; | 345 }; |
| 331 | 346 |
| 332 } // anonymous namespace | 347 } // anonymous namespace |
| 333 | 348 |
| 334 #define DEFINE_TEST_TASK_WRAPPER_CLASS(TEST_METHOD)
\ | 349 #define DEFINE_TEST_TASK_WRAPPER_CLASS(TEST_METHOD)
\ |
| 335 class TestWrapperTask_ ## TEST_METHOD : public WebThread::Task {
\ | 350 class TestWrapperTask_ ## TEST_METHOD : public WebTaskRunner::Task {
\ |
| 336 public:
\ | 351 public:
\ |
| 337 TestWrapperTask_ ## TEST_METHOD(RecordingImageBufferSurfaceTest* test) :
m_test(test) { } \ | 352 TestWrapperTask_ ## TEST_METHOD(RecordingImageBufferSurfaceTest* test) :
m_test(test) { } \ |
| 338 void run() override { m_test->TEST_METHOD(); }
\ | 353 void run() override { m_test->TEST_METHOD(); }
\ |
| 339 private:
\ | 354 private:
\ |
| 340 RecordingImageBufferSurfaceTest* m_test;
\ | 355 RecordingImageBufferSurfaceTest* m_test;
\ |
| 341 }; | 356 }; |
| 342 | 357 |
| 343 #define CALL_TEST_TASK_WRAPPER(TEST_METHOD)
\ | 358 #define CALL_TEST_TASK_WRAPPER(TEST_METHOD)
\ |
| 344 {
\ | 359 {
\ |
| 345 AutoInstallCurrentThreadPlatformMock ctpm;
\ | 360 AutoInstallCurrentThreadPlatformMock ctpm;
\ |
| 346 Platform::current()->currentThread()->postTask(FROM_HERE, new TestWrappe
rTask_ ## TEST_METHOD(this)); \ | 361 Platform::current()->currentThread()->taskRunner()->postTask(FROM_HERE,
new TestWrapperTask_ ## TEST_METHOD(this)); \ |
| 347 ctpm.enterRunLoop(); \ | 362 ctpm.enterRunLoop(); \ |
| 348 } | 363 } |
| 349 | 364 |
| 350 TEST_F(RecordingImageBufferSurfaceTest, testEmptyPicture) | 365 TEST_F(RecordingImageBufferSurfaceTest, testEmptyPicture) |
| 351 { | 366 { |
| 352 testEmptyPicture(); | 367 testEmptyPicture(); |
| 353 } | 368 } |
| 354 | 369 |
| 355 TEST_F(RecordingImageBufferSurfaceTest, testNoFallbackWithClear) | 370 TEST_F(RecordingImageBufferSurfaceTest, testNoFallbackWithClear) |
| 356 { | 371 { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 } | 404 } |
| 390 | 405 |
| 391 DEFINE_TEST_TASK_WRAPPER_CLASS(testClearRect) | 406 DEFINE_TEST_TASK_WRAPPER_CLASS(testClearRect) |
| 392 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) | 407 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) |
| 393 { | 408 { |
| 394 CALL_TEST_TASK_WRAPPER(testClearRect); | 409 CALL_TEST_TASK_WRAPPER(testClearRect); |
| 395 expectDisplayListEnabled(true); | 410 expectDisplayListEnabled(true); |
| 396 } | 411 } |
| 397 | 412 |
| 398 } // namespace blink | 413 } // namespace blink |
| OLD | NEW |