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..4d042a1df45234d81a3f974b78ead4e10bc4eab1 |
--- /dev/null |
+++ b/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridgeTest.cpp |
@@ -0,0 +1,134 @@ |
+// 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 "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "third_party/WebKit/public/platform/modules/offscreencanvas/offscreen_canvas_surface_service.mojom-blink.h" |
+#include "wtf/OwnPtr.h" |
+#include "wtf/PassOwnPtr.h" |
+#include "wtf/Vector.h" |
+ |
+namespace blink { |
+ |
+class FakeOffscreenCanvasSurfaceServiceImpl { |
+public: |
+ FakeOffscreenCanvasSurfaceServiceImpl() {} |
+ ~FakeOffscreenCanvasSurfaceServiceImpl(); |
+ |
+ mojom::blink::SurfaceIdPtr GetSurfaceId(); |
+ 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; |
+ void asyncSatisfy(const cc::SurfaceSequence&) override; |
+ void asyncRequire(const cc::SurfaceId&, const cc::SurfaceSequence&) 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(); |
+} |
+ |
+mojom::blink::SurfaceIdPtr FakeOffscreenCanvasSurfaceServiceImpl::GetSurfaceId() |
+{ |
+ mojom::blink::SurfaceIdPtr tempSurfaceIdPtr = mojom::blink::SurfaceId::New(); |
+ tempSurfaceIdPtr->id_namespace = 10; |
+ tempSurfaceIdPtr->local_id = 15; |
+ tempSurfaceIdPtr->nonce = 0; |
+ return tempSurfaceIdPtr.Clone(); |
+} |
+ |
+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() |
+{ |
+ m_surfaceIdPtr = m_mockService->GetSurfaceId(); |
+ DCHECK(m_surfaceIdPtr); |
+ return true; |
+} |
+ |
+void MockCanvasSurfaceLayerBridge::asyncRequestSurfaceCreation() |
+{ |
+ cc::SurfaceId surfaceId(m_surfaceIdPtr->id_namespace, m_surfaceIdPtr->local_id, m_surfaceIdPtr->nonce); |
+ m_mockService->RequestSurfaceCreation(surfaceId); |
+} |
+ |
+void MockCanvasSurfaceLayerBridge::asyncSatisfy(const cc::SurfaceSequence& sequence) |
+{ |
+} |
+ |
+void MockCanvasSurfaceLayerBridge::asyncRequire(const cc::SurfaceId& surfaceId, const cc::SurfaceSequence& sequence) |
+{ |
+} |
+ |
+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 |