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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/platform/graphics/chromium/Canvas2DLayerBridgeTestHelper.h
diff --git a/Source/core/platform/graphics/gpu/DrawingBufferTest.cpp b/Source/core/platform/graphics/chromium/Canvas2DLayerBridgeTestHelper.h
similarity index 54%
copy from Source/core/platform/graphics/gpu/DrawingBufferTest.cpp
copy to Source/core/platform/graphics/chromium/Canvas2DLayerBridgeTestHelper.h
index 7b393101989d5d5ce9aa0ec7e59a7c5d58330214..c748141111c54c16c44cc055a568dde357dc0255 100644
--- a/Source/core/platform/graphics/gpu/DrawingBufferTest.cpp
+++ b/Source/core/platform/graphics/chromium/Canvas2DLayerBridgeTestHelper.h
@@ -28,56 +28,55 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "config.h"
-
-#include "core/platform/graphics/gpu/DrawingBuffer.h"
+#ifndef Canvas2DLayerBridgeTestHelper_h
+#define Canvas2DLayerBridgeTestHelper_h
+#include "SkSurface.h"
#include "core/platform/graphics/GraphicsContext3D.h"
+#include "core/platform/graphics/chromium/Canvas2DLayerBridge.h"
#include "core/tests/FakeWebGraphicsContext3D.h"
-#include "public/platform/Platform.h"
-#include "wtf/RefPtr.h"
#include <gmock/gmock.h>
-#include <gtest/gtest.h>
-
-using namespace WebCore;
-using namespace WebKit;
-using testing::Test;
-using testing::_;
-namespace {
-
-class FakeContextEvictionManager : public ContextEvictionManager {
+class MockCanvasContext : public WebKit::FakeWebGraphicsContext3D {
public:
- void forciblyLoseOldestContext(const String& reason) { }
- IntSize oldestContextSize() { return IntSize(); }
+ MOCK_METHOD0(flush, void(void));
+
+ virtual GrGLInterface* onCreateGrGLInterface() OVERRIDE { return 0; }
};
-} // namespace
+class Canvas2DLayerBridgeTestHelper : public WebCore::Canvas2DLayerBridge::Helper {
+public:
+ Canvas2DLayerBridgeTestHelper() : m_context(WebCore::GraphicsContext3D::createGraphicsContextFromWebContext(adoptPtr(new MockCanvasContext)))
+ { }
-class DrawingBufferTest : public Test {
-protected:
- virtual void SetUp()
+ virtual WTF::PassRefPtr<WebCore::GraphicsContext3D> getContext() OVERRIDE
jamesr 2013/08/05 22:56:36 You don't need WTF:: here (you basically never do,
{
- RefPtr<FakeContextEvictionManager> contextEvictionManager = adoptRef(new FakeContextEvictionManager());
- RefPtr<GraphicsContext3D> context = GraphicsContext3D::createGraphicsContextFromWebContext(adoptPtr(new FakeWebGraphicsContext3D));
- const IntSize size(100, 100);
- m_drawingBuffer = DrawingBuffer::create(context.get(), size, DrawingBuffer::Discard, contextEvictionManager.release());
+ return m_context;
}
- RefPtr<DrawingBuffer> m_drawingBuffer;
-};
+ virtual SkSurface* createSurface(WebCore::GraphicsContext3D* context3D, const WebCore::IntSize& size) OVERRIDE
+ {
+ SkImage::Info info;
+ info.fWidth = size.width();
+ info.fHeight = size.height();
+ info.fColorType = SkImage::kPMColor_ColorType;
+ info.fAlphaType = SkImage::kPremul_AlphaType;
+ return SkSurface::NewRaster(info);
+ }
-namespace {
+ void regenerateContext()
+ {
+ m_context = WebCore::GraphicsContext3D::createGraphicsContextFromWebContext(adoptPtr(new MockCanvasContext));
+ }
-TEST_F(DrawingBufferTest, verifyNoNewBuffersAfterContextLostWithMailboxes)
-{
- // Tell the buffer its contents changed and context was lost.
- m_drawingBuffer->markContentsChanged();
- m_drawingBuffer->releaseResources();
+ MockCanvasContext& mock()
+ {
+ return *static_cast<MockCanvasContext*>(m_context->webContext());
+ }
- WebKit::WebExternalTextureMailbox mailbox;
- EXPECT_FALSE(m_drawingBuffer->prepareMailbox(&mailbox, 0));
-}
+private:
+ RefPtr<WebCore::GraphicsContext3D> m_context;
+};
-} // namespace
+#endif

Powered by Google App Engine
This is Rietveld 408576698