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

Side by Side Diff: Source/platform/graphics/Canvas2DLayerManagerTest.cpp

Issue 1184673003: Fix unit test style in Source/platform/, part 2. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26
27 #include "platform/graphics/Canvas2DLayerManager.h" 26 #include "platform/graphics/Canvas2DLayerManager.h"
28 27
29 #include "SkDevice.h" 28 #include "SkDevice.h"
30 #include "SkSurface.h" 29 #include "SkSurface.h"
31 #include "platform/graphics/test/MockWebGraphicsContext3D.h" 30 #include "platform/graphics/test/MockWebGraphicsContext3D.h"
32 #include "public/platform/Platform.h" 31 #include "public/platform/Platform.h"
33 #include "public/platform/WebGraphicsContext3DProvider.h" 32 #include "public/platform/WebGraphicsContext3DProvider.h"
34 #include "public/platform/WebThread.h" 33 #include "public/platform/WebThread.h"
35 #include "public/platform/WebTraceLocation.h" 34 #include "public/platform/WebTraceLocation.h"
36 #include "public/platform/WebUnitTestSupport.h" 35 #include "public/platform/WebUnitTestSupport.h"
37
38 #include <gmock/gmock.h> 36 #include <gmock/gmock.h>
39 #include <gtest/gtest.h> 37 #include <gtest/gtest.h>
40 38
41 using namespace blink;
42 using testing::InSequence; 39 using testing::InSequence;
43 using testing::Return; 40 using testing::Return;
44 using testing::Test; 41 using testing::Test;
45 42
43 namespace blink {
44
46 namespace { 45 namespace {
47 46
48 class MockWebGraphicsContext3DProvider : public WebGraphicsContext3DProvider { 47 class MockWebGraphicsContext3DProvider : public WebGraphicsContext3DProvider {
49 public: 48 public:
50 MockWebGraphicsContext3DProvider(WebGraphicsContext3D* context3d) 49 MockWebGraphicsContext3DProvider(WebGraphicsContext3D* context3d)
51 : m_context3d(context3d) { } 50 : m_context3d(context3d) { }
52 51
53 WebGraphicsContext3D* context3d() 52 WebGraphicsContext3D* context3d() override
54 { 53 {
55 return m_context3d; 54 return m_context3d;
56 } 55 }
57 56
58 GrContext* grContext() 57 GrContext* grContext() override
59 { 58 {
60 return 0; 59 return 0;
61 } 60 }
62 61
63 private: 62 private:
64 WebGraphicsContext3D* m_context3d; 63 WebGraphicsContext3D* m_context3d;
65 }; 64 };
66 65
67 class FakeCanvas2DLayerBridge : public Canvas2DLayerBridge { 66 class FakeCanvas2DLayerBridge : public Canvas2DLayerBridge {
68 public: 67 public:
69 FakeCanvas2DLayerBridge(WebGraphicsContext3D* context, PassOwnPtr<SkDeferred Canvas> canvas, PassRefPtr<SkSurface> surface) 68 FakeCanvas2DLayerBridge(WebGraphicsContext3D* context, PassOwnPtr<SkDeferred Canvas> canvas, PassRefPtr<SkSurface> surface)
70 : Canvas2DLayerBridge(adoptPtr(new MockWebGraphicsContext3DProvider(cont ext)), canvas, surface, 0, NonOpaque) 69 : Canvas2DLayerBridge(adoptPtr(new MockWebGraphicsContext3DProvider(cont ext)), canvas, surface, 0, NonOpaque)
71 , m_freeableBytes(0) 70 , m_freeableBytes(0)
72 , m_freeMemoryIfPossibleCount(0) 71 , m_freeMemoryIfPossibleCount(0)
73 , m_flushCount(0) 72 , m_flushCount(0)
74 { 73 {
75 } 74 }
76 75
77 virtual size_t storageAllocatedForRecording() override 76 size_t storageAllocatedForRecording() override
78 { 77 {
79 // Because the fake layer has no canvas to query, just 78 // Because the fake layer has no canvas to query, just
80 // return status quo. Allocation changes that would normally be 79 // return status quo. Allocation changes that would normally be
81 // initiated by the canvas can be faked by invoking 80 // initiated by the canvas can be faked by invoking
82 // storageAllocatedForRecordingChanged directly from the test code. 81 // storageAllocatedForRecordingChanged directly from the test code.
83 return m_bytesAllocated; 82 return m_bytesAllocated;
84 } 83 }
85 84
86 void fakeFreeableBytes(size_t size) 85 void fakeFreeableBytes(size_t size)
87 { 86 {
88 m_freeableBytes = size; 87 m_freeableBytes = size;
89 } 88 }
90 89
91 virtual size_t freeMemoryIfPossible(size_t size) override 90 size_t freeMemoryIfPossible(size_t size) override
92 { 91 {
93 m_freeMemoryIfPossibleCount++; 92 m_freeMemoryIfPossibleCount++;
94 size_t bytesFreed = size < m_freeableBytes ? size : m_freeableBytes; 93 size_t bytesFreed = size < m_freeableBytes ? size : m_freeableBytes;
95 m_freeableBytes -= bytesFreed; 94 m_freeableBytes -= bytesFreed;
96 if (bytesFreed) 95 if (bytesFreed)
97 storageAllocatedForRecordingChanged(m_bytesAllocated - bytesFreed); 96 storageAllocatedForRecordingChanged(m_bytesAllocated - bytesFreed);
98 return bytesFreed; 97 return bytesFreed;
99 } 98 }
100 99
101 virtual void flush() override 100 void flush() override
102 { 101 {
103 flushedDrawCommands(); 102 flushedDrawCommands();
104 m_freeableBytes = bytesAllocated(); 103 m_freeableBytes = bytesAllocated();
105 m_flushCount++; 104 m_flushCount++;
106 } 105 }
107 106
108 public: 107 public:
109 size_t m_freeableBytes; 108 size_t m_freeableBytes;
110 int m_freeMemoryIfPossibleCount; 109 int m_freeMemoryIfPossibleCount;
111 int m_flushCount; 110 int m_flushCount;
112 }; 111 };
113 112
114 class FakeCanvas2DLayerBridgePtr { 113 class FakeCanvas2DLayerBridgePtr {
115 public: 114 public:
116 FakeCanvas2DLayerBridgePtr(PassRefPtr<FakeCanvas2DLayerBridge> layerBridge) 115 FakeCanvas2DLayerBridgePtr(PassRefPtr<FakeCanvas2DLayerBridge> layerBridge)
117 : m_layerBridge(layerBridge) { } 116 : m_layerBridge(layerBridge) { }
118 117
119 ~FakeCanvas2DLayerBridgePtr() 118 ~FakeCanvas2DLayerBridgePtr()
120 { 119 {
121 m_layerBridge->beginDestruction(); 120 m_layerBridge->beginDestruction();
122 } 121 }
123 122
124 FakeCanvas2DLayerBridge* operator->() { return m_layerBridge.get(); } 123 FakeCanvas2DLayerBridge* operator->() { return m_layerBridge.get(); }
125 FakeCanvas2DLayerBridge* get() { return m_layerBridge.get(); } 124 FakeCanvas2DLayerBridge* get() { return m_layerBridge.get(); }
126 125
127 private: 126 private:
128 RefPtr<FakeCanvas2DLayerBridge> m_layerBridge; 127 RefPtr<FakeCanvas2DLayerBridge> m_layerBridge;
129 }; 128 };
130 129
131 } // unnamed namespace 130 } // anonymous namespace
132 131
133 class Canvas2DLayerManagerTest : public Test { 132 class Canvas2DLayerManagerTest : public Test {
134 protected: 133 protected:
135 void storageAllocationTrackingTest() 134 void storageAllocationTrackingTest()
136 { 135 {
137 Canvas2DLayerManager& manager = Canvas2DLayerManager::get(); 136 Canvas2DLayerManager& manager = Canvas2DLayerManager::get();
138 manager.init(10, 10); 137 manager.init(10, 10);
139 { 138 {
140 OwnPtr<MockWebGraphicsContext3D> webContext = adoptPtr(new MockWebGr aphicsContext3D); 139 OwnPtr<MockWebGraphicsContext3D> webContext = adoptPtr(new MockWebGr aphicsContext3D);
141 RefPtr<SkSurface> surface1 = adoptRef(SkSurface::NewRasterN32Premul( 1, 1)); 140 RefPtr<SkSurface> surface1 = adoptRef(SkSurface::NewRasterN32Premul( 1, 1));
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 252
254 class DeferredFrameTestTask : public WebThread::Task { 253 class DeferredFrameTestTask : public WebThread::Task {
255 public: 254 public:
256 DeferredFrameTestTask(Canvas2DLayerManagerTest* test, FakeCanvas2DLayerB ridge* layer, bool skipCommands) 255 DeferredFrameTestTask(Canvas2DLayerManagerTest* test, FakeCanvas2DLayerB ridge* layer, bool skipCommands)
257 { 256 {
258 m_test = test; 257 m_test = test;
259 m_layer = layer; 258 m_layer = layer;
260 m_skipCommands = skipCommands; 259 m_skipCommands = skipCommands;
261 } 260 }
262 261
263 virtual void run() override 262 void run() override
264 { 263 {
265 m_test->doDeferredFrameTestTask(m_layer, m_skipCommands); 264 m_test->doDeferredFrameTestTask(m_layer, m_skipCommands);
266 } 265 }
266
267 private: 267 private:
268 Canvas2DLayerManagerTest* m_test; 268 Canvas2DLayerManagerTest* m_test;
269 FakeCanvas2DLayerBridge* m_layer; 269 FakeCanvas2DLayerBridge* m_layer;
270 bool m_skipCommands; 270 bool m_skipCommands;
271 }; 271 };
272 272
273 void deferredFrameTest() 273 void deferredFrameTest()
274 { 274 {
275 OwnPtr<MockWebGraphicsContext3D> webContext = adoptPtr(new MockWebGraphi csContext3D); 275 OwnPtr<MockWebGraphicsContext3D> webContext = adoptPtr(new MockWebGraphi csContext3D);
276 Canvas2DLayerManager::get().init(10, 10); 276 Canvas2DLayerManager::get().init(10, 10);
(...skipping 24 matching lines...) Expand all
301 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); 301 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
302 EXPECT_EQ(1, layer->m_flushCount); 302 EXPECT_EQ(1, layer->m_flushCount);
303 303
304 Platform::current()->currentThread()->postTask(FROM_HERE, new DeferredFr ameTestTask(this, layer.get(), false)); 304 Platform::current()->currentThread()->postTask(FROM_HERE, new DeferredFr ameTestTask(this, layer.get(), false));
305 Platform::current()->unitTestSupport()->enterRunLoop(); 305 Platform::current()->unitTestSupport()->enterRunLoop();
306 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive); 306 EXPECT_FALSE(Canvas2DLayerManager::get().m_taskObserverActive);
307 EXPECT_EQ(2, layer->m_flushCount); 307 EXPECT_EQ(2, layer->m_flushCount);
308 } 308 }
309 }; 309 };
310 310
311 namespace {
312
313 TEST_F(Canvas2DLayerManagerTest, testStorageAllocationTracking) 311 TEST_F(Canvas2DLayerManagerTest, testStorageAllocationTracking)
314 { 312 {
315 storageAllocationTrackingTest(); 313 storageAllocationTrackingTest();
316 } 314 }
317 315
318 TEST_F(Canvas2DLayerManagerTest, testEviction) 316 TEST_F(Canvas2DLayerManagerTest, testEviction)
319 { 317 {
320 evictionTest(); 318 evictionTest();
321 } 319 }
322 320
(...skipping 10 matching lines...) Expand all
333 TEST_F(Canvas2DLayerManagerTest, testHiddenCanvas) 331 TEST_F(Canvas2DLayerManagerTest, testHiddenCanvas)
334 { 332 {
335 hiddenCanvasTest(); 333 hiddenCanvasTest();
336 } 334 }
337 335
338 TEST_F(Canvas2DLayerManagerTest, testAddRemoveLayer) 336 TEST_F(Canvas2DLayerManagerTest, testAddRemoveLayer)
339 { 337 {
340 addRemoveLayerTest(); 338 addRemoveLayerTest();
341 } 339 }
342 340
343 } // unnamed namespace 341 } // namespace blink
344
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698