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

Unified Diff: Source/core/platform/graphics/chromium/Canvas2DLayerBridgeTest.cpp

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/Canvas2DLayerBridgeTest.cpp
diff --git a/Source/core/platform/graphics/chromium/Canvas2DLayerBridgeTest.cpp b/Source/core/platform/graphics/chromium/Canvas2DLayerBridgeTest.cpp
index b7c83c4b47cc62d1ddcde47f324355a98eb76c11..b08539b8320d30c5217cc6636b21f236915c9ddd 100644
--- a/Source/core/platform/graphics/chromium/Canvas2DLayerBridgeTest.cpp
+++ b/Source/core/platform/graphics/chromium/Canvas2DLayerBridgeTest.cpp
@@ -24,17 +24,15 @@
#include "config.h"
-#include "core/platform/graphics/chromium/Canvas2DLayerBridge.h"
-
#include "SkDeferredCanvas.h"
+#include "SkSurface.h"
#include "core/platform/graphics/ImageBuffer.h"
-#include "core/tests/FakeWebGraphicsContext3D.h"
+#include "core/platform/graphics/chromium/Canvas2DLayerBridgeTestHelper.h"
#include "public/platform/Platform.h"
#include "public/platform/WebThread.h"
#include "third_party/skia/include/core/SkDevice.h"
#include "wtf/RefPtr.h"
-#include <gmock/gmock.h>
#include <gtest/gtest.h>
using namespace WebCore;
@@ -45,63 +43,93 @@ using testing::Test;
namespace {
-class MockCanvasContext : public FakeWebGraphicsContext3D {
-public:
- MOCK_METHOD0(flush, void(void));
- MOCK_METHOD0(createTexture, unsigned(void));
- MOCK_METHOD1(deleteTexture, void(unsigned));
-
- virtual GrGLInterface* onCreateGrGLInterface() OVERRIDE { return 0; }
-};
-
class FakeCanvas2DLayerBridge : public Canvas2DLayerBridge {
public:
- static PassOwnPtr<FakeCanvas2DLayerBridge> create(PassRefPtr<GraphicsContext3D> context, SkDeferredCanvas* canvas, OpacityMode opacityMode)
+ static PassOwnPtr<FakeCanvas2DLayerBridge> create(PassOwnPtr<Helper> helper, const IntSize& size, OpacityMode opacityMode, bool* success)
{
- return adoptPtr(new FakeCanvas2DLayerBridge(context, canvas, opacityMode));
+ return adoptPtr(new FakeCanvas2DLayerBridge(helper, size, opacityMode, success));
}
protected:
- FakeCanvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, SkDeferredCanvas* canvas, OpacityMode opacityMode) :
- Canvas2DLayerBridge(context, canvas, opacityMode)
+ FakeCanvas2DLayerBridge(PassOwnPtr<Helper> helper, const WebCore::IntSize& size, OpacityMode opacityMode, bool* success) :
+ Canvas2DLayerBridge(helper, size, opacityMode, success)
{ }
};
-} // namespace
+}
class Canvas2DLayerBridgeTest : public Test {
protected:
void fullLifecycleTest()
{
- RefPtr<GraphicsContext3D> mainContext = GraphicsContext3D::createGraphicsContextFromWebContext(adoptPtr(new MockCanvasContext));
+ OwnPtr<Canvas2DLayerBridgeTestHelper> testHelper = adoptPtr(new Canvas2DLayerBridgeTestHelper);
- MockCanvasContext& mainMock = *static_cast<MockCanvasContext*>(mainContext->webContext());
+ MockCanvasContext* mockContext = &testHelper->mock();
+ ::testing::Mock::VerifyAndClearExpectations(mockContext);
- SkDevice device(SkBitmap::kARGB_8888_Config, 300, 150);
- SkDeferredCanvas canvas(&device);
+ IntSize size(300, 150);
+ bool success;
+ OwnPtr<Canvas2DLayerBridge> bridge = FakeCanvas2DLayerBridge::create(testHelper.release(), size, Canvas2DLayerBridge::NonOpaque, &success);
+ EXPECT_TRUE(success);
- ::testing::Mock::VerifyAndClearExpectations(&mainMock);
+ ::testing::Mock::VerifyAndClearExpectations(mockContext);
- OwnPtr<Canvas2DLayerBridge> bridge = FakeCanvas2DLayerBridge::create(mainContext.release(), &canvas, Canvas2DLayerBridge::NonOpaque);
-
- ::testing::Mock::VerifyAndClearExpectations(&mainMock);
-
- EXPECT_CALL(mainMock, flush());
+ EXPECT_CALL(*mockContext, flush());
unsigned textureId = bridge->backBufferTexture();
EXPECT_EQ(textureId, 0u);
- ::testing::Mock::VerifyAndClearExpectations(&mainMock);
+ ::testing::Mock::VerifyAndClearExpectations(mockContext);
bridge.clear();
- ::testing::Mock::VerifyAndClearExpectations(&mainMock);
+ ::testing::Mock::VerifyAndClearExpectations(mockContext);
+ }
+
+ void loseContextTest()
+ {
+ OwnPtr<Canvas2DLayerBridgeTestHelper> testHelper = adoptPtr(new Canvas2DLayerBridgeTestHelper);
+ MockCanvasContext* mockContext = &testHelper->mock();
+
+ IntSize size(300, 150);
+ bool success;
+ OwnPtr<Canvas2DLayerBridge> bridge = FakeCanvas2DLayerBridge::create(testHelper.release(), size, Canvas2DLayerBridge::NonOpaque, &success);
+ EXPECT_TRUE(success);
+
+ ::testing::Mock::VerifyAndClearExpectations(mockContext);
+ EXPECT_TRUE(bridge->isValid());
+
+ mockContext->fakeContextLoss();
+
+ ::testing::Mock::VerifyAndClearExpectations(mockContext);
+
+ EXPECT_FALSE(bridge->isValid());
+
+ ::testing::Mock::VerifyAndClearExpectations(mockContext);
+
+ static_cast<Canvas2DLayerBridgeTestHelper*>(bridge->helper())->regenerateContext();
+ mockContext = &static_cast<Canvas2DLayerBridgeTestHelper*>(bridge->helper())->mock();
+
+ ::testing::Mock::VerifyAndClearExpectations(mockContext);
+
+ EXPECT_TRUE(bridge->isValid());
+
+ ::testing::Mock::VerifyAndClearExpectations(mockContext);
+
+ EXPECT_FALSE(bridge->prepareMailbox(0, 0));
+
+ ::testing::Mock::VerifyAndClearExpectations(mockContext);
}
};
namespace {
-TEST_F(Canvas2DLayerBridgeTest, testFullLifecycleSingleThreaded)
+TEST_F(Canvas2DLayerBridgeTest, testFullLifecycle)
{
fullLifecycleTest();
}
+TEST_F(Canvas2DLayerBridgeTest, testLoseContext)
+{
+ loseContextTest();
+}
+
} // namespace

Powered by Google App Engine
This is Rietveld 408576698