Index: third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridgeTest.cpp |
diff --git a/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridgeTest.cpp b/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridgeTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..17aa005648c54d5d463904259800f54c0e8773ed |
--- /dev/null |
+++ b/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridgeTest.cpp |
@@ -0,0 +1,119 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "platform/graphics/CanvasSurfaceLayerBridge.h" |
+ |
+#include "cc/surfaces/surface_id.h" |
+#include "cc/surfaces/surface_sequence.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "wtf/OwnPtr.h" |
+#include "wtf/PassOwnPtr.h" |
+#include "wtf/Vector.h" |
+ |
+namespace blink { |
+ |
+class FakeOffscreenCanvasSurfaceServiceImpl { |
+public: |
+ FakeOffscreenCanvasSurfaceServiceImpl() {} |
+ ~FakeOffscreenCanvasSurfaceServiceImpl(); |
+ |
+ bool GetSurfaceId(cc::SurfaceId*); |
+ void RequestSurfaceCreation(const cc::SurfaceId&); |
+ |
+ bool isSurfaceInSurfaceMap(const cc::SurfaceId&); |
+ |
+private: |
+ Vector<cc::SurfaceId> m_fakeSurfaceMap; |
+}; |
+ |
+//----------------------------------------------------------------------------- |
+ |
+class MockCanvasSurfaceLayerBridge : public CanvasSurfaceLayerBridge { |
+public: |
+ explicit MockCanvasSurfaceLayerBridge(); |
+ ~MockCanvasSurfaceLayerBridge() override; |
+ |
+ // Implement virtual functions |
+ bool syncGetServiceId() override; |
+ void asyncRequestSurfaceCreation() override; |
+ |
+ FakeOffscreenCanvasSurfaceServiceImpl* service() const { return m_mockService.get(); } |
+ cc::SurfaceId surfaceId() { return m_surfaceId; } |
+ |
+private: |
+ OwnPtr<FakeOffscreenCanvasSurfaceServiceImpl> m_mockService; |
+}; |
+ |
+//----------------------------------------------------------------------------- |
+ |
+class CanvasSurfaceLayerBridgeTest : public testing::Test { |
+public: |
+ CanvasSurfaceLayerBridgeTest(); |
+ MockCanvasSurfaceLayerBridge* surfaceLayerBridge() const { return m_surfaceLayerBridge.get(); } |
+ |
+private: |
+ OwnPtr<MockCanvasSurfaceLayerBridge> m_surfaceLayerBridge; |
+}; |
+ |
+//----------------------------------------------------------------------------- |
+ |
+FakeOffscreenCanvasSurfaceServiceImpl::~FakeOffscreenCanvasSurfaceServiceImpl() |
+{ |
+ m_fakeSurfaceMap.clear(); |
+} |
+ |
+bool FakeOffscreenCanvasSurfaceServiceImpl::GetSurfaceId(cc::SurfaceId* surfaceId) |
+{ |
+ surfaceId = new cc::SurfaceId(10, 15, 0); |
+ return true; |
+} |
+ |
+void FakeOffscreenCanvasSurfaceServiceImpl::RequestSurfaceCreation(const cc::SurfaceId& surfaceId) |
+{ |
+ m_fakeSurfaceMap.append(surfaceId); |
+} |
+ |
+bool FakeOffscreenCanvasSurfaceServiceImpl::isSurfaceInSurfaceMap(const cc::SurfaceId& surfaceId) |
+{ |
+ return m_fakeSurfaceMap.contains(surfaceId); |
+} |
+ |
+MockCanvasSurfaceLayerBridge::MockCanvasSurfaceLayerBridge() |
+{ |
+ // The constructor of CanvasSurfaceLayerBridge connects to remote mojo |
+ // service and sets m_mockService as a connection end. Here, we fake the |
+ // m_service that acts similar to OffscreenCanvasSurfaceServiceImpl on the |
+ // browser side. |
+ m_mockService = adoptPtr(new FakeOffscreenCanvasSurfaceServiceImpl()); |
+} |
+ |
+MockCanvasSurfaceLayerBridge::~MockCanvasSurfaceLayerBridge() |
+{ |
+} |
+ |
+bool MockCanvasSurfaceLayerBridge::syncGetServiceId() |
+{ |
+ return m_mockService->GetSurfaceId(&m_surfaceId); |
+} |
+ |
+void MockCanvasSurfaceLayerBridge::asyncRequestSurfaceCreation() |
+{ |
+ m_mockService->RequestSurfaceCreation(m_surfaceId); |
+} |
+ |
+CanvasSurfaceLayerBridgeTest::CanvasSurfaceLayerBridgeTest() |
+{ |
+ m_surfaceLayerBridge = adoptPtr(new MockCanvasSurfaceLayerBridge()); |
+} |
+ |
+TEST_F(CanvasSurfaceLayerBridgeTest, SurfaceLayerCreation) |
+{ |
+ bool success = this->surfaceLayerBridge()->createSurfaceLayer(50, 50); |
+ |
+ EXPECT_TRUE(this->surfaceLayerBridge()->service()->isSurfaceInSurfaceMap(this->surfaceLayerBridge()->surfaceId())); |
+ EXPECT_TRUE(success); |
+} |
+ |
+} // namespace blink |