Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/RecordingImageBufferSurfaceTest.cpp

Issue 1456873003: More regular Platform implementations in unit tests (reland.) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: have GN disable c4267 also Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
12 #include "public/platform/Platform.h" 13 #include "public/platform/Platform.h"
13 #include "public/platform/WebTaskRunner.h" 14 #include "public/platform/WebTaskRunner.h"
14 #include "public/platform/WebThread.h" 15 #include "public/platform/WebThread.h"
15 #include "public/platform/WebTraceLocation.h" 16 #include "public/platform/WebTraceLocation.h"
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/skia/include/core/SkCanvas.h" 19 #include "third_party/skia/include/core/SkCanvas.h"
19 #include "third_party/skia/include/core/SkPictureRecorder.h" 20 #include "third_party/skia/include/core/SkPictureRecorder.h"
20 #include "wtf/OwnPtr.h" 21 #include "wtf/OwnPtr.h"
21 #include "wtf/PassOwnPtr.h" 22 #include "wtf/PassOwnPtr.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 OwnPtr<FakeImageBufferClient> m_fakeImageBufferClient; 230 OwnPtr<FakeImageBufferClient> m_fakeImageBufferClient;
230 OwnPtr<ImageBuffer> m_imageBuffer; 231 OwnPtr<ImageBuffer> m_imageBuffer;
231 }; 232 };
232 233
233 namespace { 234 namespace {
234 235
235 // The following test helper class installs a mock platform that provides a mock WebThread 236 // The following test helper class installs a mock platform that provides a mock WebThread
236 // for the current thread. The Mock thread is capable of queuing a single non-de layed task 237 // for the current thread. The Mock thread is capable of queuing a single non-de layed task
237 // and registering a single task observer. The run loop exits immediately after running 238 // and registering a single task observer. The run loop exits immediately after running
238 // the single task. 239 // the single task.
239 class AutoInstallCurrentThreadPlatformMock { 240
241 class CurrentThreadPlatformMock : public TestingPlatformSupport {
240 public: 242 public:
241 AutoInstallCurrentThreadPlatformMock() 243 CurrentThreadPlatformMock() { }
242 { 244 WebThread* currentThread() override { return &m_currentThread; }
243 m_oldPlatform = Platform::current();
244 Platform::initialize(&m_mockPlatform);
245 }
246 245
247 ~AutoInstallCurrentThreadPlatformMock() 246 void enterRunLoop() { m_currentThread.enterRunLoop(); }
248 {
249 Platform::initialize(m_oldPlatform);
250 }
251
252 void enterRunLoop()
253 {
254 m_mockPlatform.enterRunLoop();
255 }
256
257 private: 247 private:
258 class MockWebTaskRunner : public WebTaskRunner { 248 class MockWebTaskRunner : public WebTaskRunner {
259 public: 249 public:
260 MockWebTaskRunner() : m_task(0) { } 250 MockWebTaskRunner() : m_task(0) { }
261 ~MockWebTaskRunner() override { } 251 ~MockWebTaskRunner() override { }
262 252
263 void postTask(const WebTraceLocation&, Task* task) override 253 void postTask(const WebTraceLocation&, Task* task) override
264 { 254 {
265 EXPECT_EQ((Task*)0, m_task); 255 EXPECT_EQ((Task*)0, m_task);
266 m_task = task; 256 m_task = task;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 } 318 }
329 if (m_taskObserver) 319 if (m_taskObserver)
330 m_taskObserver->didProcessTask(); 320 m_taskObserver->didProcessTask();
331 } 321 }
332 322
333 private: 323 private:
334 MockWebTaskRunner m_taskRunner; 324 MockWebTaskRunner m_taskRunner;
335 TaskObserver* m_taskObserver; 325 TaskObserver* m_taskObserver;
336 }; 326 };
337 327
338 class CurrentThreadPlatformMock : public Platform { 328 CurrentThreadMock m_currentThread;
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;
354 }; 329 };
355 330
356 } // anonymous namespace 331 } // anonymous namespace
357 332
358 #define DEFINE_TEST_TASK_WRAPPER_CLASS(TEST_METHOD) \ 333 #define DEFINE_TEST_TASK_WRAPPER_CLASS(TEST_METHOD) \
359 class TestWrapperTask_ ## TEST_METHOD : public WebTaskRunner::Task { \ 334 class TestWrapperTask_ ## TEST_METHOD : public WebTaskRunner::Task { \
360 public: \ 335 public: \
361 TestWrapperTask_ ## TEST_METHOD(RecordingImageBufferSurfaceTest* test) : m_test(test) { } \ 336 TestWrapperTask_ ## TEST_METHOD(RecordingImageBufferSurfaceTest* test) : m_test(test) { } \
362 void run() override { m_test->TEST_METHOD(); } \ 337 void run() override { m_test->TEST_METHOD(); } \
363 private: \ 338 private: \
364 RecordingImageBufferSurfaceTest* m_test; \ 339 RecordingImageBufferSurfaceTest* m_test; \
365 }; 340 };
366 341
367 #define CALL_TEST_TASK_WRAPPER(TEST_METHOD) \ 342 #define CALL_TEST_TASK_WRAPPER(TEST_METHOD) \
368 { \ 343 { \
369 AutoInstallCurrentThreadPlatformMock ctpm; \ 344 CurrentThreadPlatformMock ctpm; \
370 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_ HERE, new TestWrapperTask_ ## TEST_METHOD(this)); \ 345 Platform::current()->currentThread()->taskRunner()->postTask(BLINK_FROM_ HERE, new TestWrapperTask_ ## TEST_METHOD(this)); \
371 ctpm.enterRunLoop(); \ 346 ctpm.enterRunLoop(); \
372 } 347 }
373 348
374 TEST_F(RecordingImageBufferSurfaceTest, testEmptyPicture) 349 TEST_F(RecordingImageBufferSurfaceTest, testEmptyPicture)
375 { 350 {
376 testEmptyPicture(); 351 testEmptyPicture();
377 } 352 }
378 353
379 TEST_F(RecordingImageBufferSurfaceTest, testNoFallbackWithClear) 354 TEST_F(RecordingImageBufferSurfaceTest, testNoFallbackWithClear)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 } 388 }
414 389
415 DEFINE_TEST_TASK_WRAPPER_CLASS(testClearRect) 390 DEFINE_TEST_TASK_WRAPPER_CLASS(testClearRect)
416 TEST_F(RecordingImageBufferSurfaceTest, testClearRect) 391 TEST_F(RecordingImageBufferSurfaceTest, testClearRect)
417 { 392 {
418 CALL_TEST_TASK_WRAPPER(testClearRect); 393 CALL_TEST_TASK_WRAPPER(testClearRect);
419 expectDisplayListEnabled(true); 394 expectDisplayListEnabled(true);
420 } 395 }
421 396
422 } // namespace blink 397 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698