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

Side by Side Diff: Source/core/platform/graphics/chromium/Canvas2DLayerBridgeTestHelper.h

Issue 21858004: Refactoring Canvas2DLayerBridge to make it easier to write unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 10 matching lines...) Expand all
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #ifndef Canvas2DLayerBridgeTestHelper_h
32 #define Canvas2DLayerBridgeTestHelper_h
32 33
33 #include "core/platform/graphics/gpu/DrawingBuffer.h" 34 #include "SkSurface.h"
34
35 #include "core/platform/graphics/GraphicsContext3D.h" 35 #include "core/platform/graphics/GraphicsContext3D.h"
36 #include "core/platform/graphics/chromium/Canvas2DLayerBridge.h"
36 #include "core/tests/FakeWebGraphicsContext3D.h" 37 #include "core/tests/FakeWebGraphicsContext3D.h"
37 #include "public/platform/Platform.h"
38 #include "wtf/RefPtr.h"
39 38
40 #include <gmock/gmock.h> 39 #include <gmock/gmock.h>
41 #include <gtest/gtest.h>
42 40
43 using namespace WebCore; 41 class MockCanvasContext : public WebKit::FakeWebGraphicsContext3D {
44 using namespace WebKit; 42 public:
45 using testing::Test; 43 MOCK_METHOD0(flush, void(void));
46 using testing::_;
47 44
48 namespace { 45 virtual GrGLInterface* onCreateGrGLInterface() OVERRIDE { return 0; }
49
50 class FakeContextEvictionManager : public ContextEvictionManager {
51 public:
52 void forciblyLoseOldestContext(const String& reason) { }
53 IntSize oldestContextSize() { return IntSize(); }
54 }; 46 };
55 47
56 } // namespace 48 class Canvas2DLayerBridgeTestHelper : public WebCore::Canvas2DLayerBridge::Helpe r {
49 public:
50 Canvas2DLayerBridgeTestHelper() : m_context(WebCore::GraphicsContext3D::crea teGraphicsContextFromWebContext(adoptPtr(new MockCanvasContext)))
51 { }
57 52
58 class DrawingBufferTest : public Test { 53 virtual WTF::PassRefPtr<WebCore::GraphicsContext3D> getContext() OVERRIDE
jamesr 2013/08/05 22:56:36 You don't need WTF:: here (you basically never do,
59 protected:
60 virtual void SetUp()
61 { 54 {
62 RefPtr<FakeContextEvictionManager> contextEvictionManager = adoptRef(new FakeContextEvictionManager()); 55 return m_context;
63 RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsCon textFromWebContext(adoptPtr(new FakeWebGraphicsContext3D));
64 const IntSize size(100, 100);
65 m_drawingBuffer = DrawingBuffer::create(context.get(), size, DrawingBuff er::Discard, contextEvictionManager.release());
66 } 56 }
67 57
68 RefPtr<DrawingBuffer> m_drawingBuffer; 58 virtual SkSurface* createSurface(WebCore::GraphicsContext3D* context3D, cons t WebCore::IntSize& size) OVERRIDE
59 {
60 SkImage::Info info;
61 info.fWidth = size.width();
62 info.fHeight = size.height();
63 info.fColorType = SkImage::kPMColor_ColorType;
64 info.fAlphaType = SkImage::kPremul_AlphaType;
65 return SkSurface::NewRaster(info);
66 }
67
68 void regenerateContext()
69 {
70 m_context = WebCore::GraphicsContext3D::createGraphicsContextFromWebCont ext(adoptPtr(new MockCanvasContext));
71 }
72
73 MockCanvasContext& mock()
74 {
75 return *static_cast<MockCanvasContext*>(m_context->webContext());
76 }
77
78 private:
79 RefPtr<WebCore::GraphicsContext3D> m_context;
69 }; 80 };
70 81
71 namespace { 82 #endif
72
73 TEST_F(DrawingBufferTest, verifyNoNewBuffersAfterContextLostWithMailboxes)
74 {
75 // Tell the buffer its contents changed and context was lost.
76 m_drawingBuffer->markContentsChanged();
77 m_drawingBuffer->releaseResources();
78
79 WebKit::WebExternalTextureMailbox mailbox;
80 EXPECT_FALSE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
81 }
82
83 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698