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..2b7c126b4cb83d1f47fbaf8d808a0cf6bda9bab6 |
--- /dev/null |
+++ b/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridgeTest.cpp |
@@ -0,0 +1,128 @@ |
+// 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 "platform/graphics/CanvasSurfaceLayerBridgeClient.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 MockCanvasSurfaceLayerBridgeClient final : public CanvasSurfaceLayerBridgeClient { |
+public: |
+ explicit MockCanvasSurfaceLayerBridgeClient(FakeOffscreenCanvasSurfaceServiceImpl*); |
+ ~MockCanvasSurfaceLayerBridgeClient() override; |
+ |
+ bool syncGetSurfaceId(cc::SurfaceId*) override; |
+ void asyncRequestSurfaceCreation(const cc::SurfaceId&) override; |
+ void asyncRequire(cc::SurfaceId, cc::SurfaceSequence) override {} |
+ void asyncSatisfy(cc::SurfaceSequence) override {}; |
+ |
+private: |
+ FakeOffscreenCanvasSurfaceServiceImpl* m_service; |
+ cc::SurfaceId m_surfaceId; |
+}; |
+ |
+//----------------------------------------------------------------------------- |
+ |
+class CanvasSurfaceLayerBridgeTest : public testing::Test { |
+public: |
+ CanvasSurfaceLayerBridge* surfaceLayerBridge() const { return m_surfaceLayerBridge.get(); } |
+ FakeOffscreenCanvasSurfaceServiceImpl* surfaceService() const { return m_surfaceService; } |
+ |
+protected: |
+ void SetUp() override; |
+ void TearDown() override; |
+ |
+private: |
+ OwnPtr<CanvasSurfaceLayerBridge> m_surfaceLayerBridge; |
+ FakeOffscreenCanvasSurfaceServiceImpl* m_surfaceService; |
jbroman
2016/06/16 21:11:48
This seems to be an owning pointer, too.
std::uni
xlai (Olivia)
2016/06/16 23:16:21
OwnPtr is not suitable in this case. Due to the st
danakj
2016/06/16 23:19:23
Only one of the two owns it tho, right? So one wou
|
+}; |
+ |
+//----------------------------------------------------------------------------- |
+ |
+MockCanvasSurfaceLayerBridgeClient::MockCanvasSurfaceLayerBridgeClient(FakeOffscreenCanvasSurfaceServiceImpl* surfaceService) |
+{ |
+ m_service = surfaceService; |
+} |
+ |
+MockCanvasSurfaceLayerBridgeClient::~MockCanvasSurfaceLayerBridgeClient() |
+{ |
+ m_service = nullptr; |
+} |
+ |
+bool MockCanvasSurfaceLayerBridgeClient::syncGetSurfaceId(cc::SurfaceId* surfaceIdPtr) |
+{ |
+ return m_service->GetSurfaceId(surfaceIdPtr); |
+} |
+ |
+void MockCanvasSurfaceLayerBridgeClient::asyncRequestSurfaceCreation(const cc::SurfaceId& surfaceId) |
+{ |
+ m_service->RequestSurfaceCreation(surfaceId); |
+} |
+ |
+FakeOffscreenCanvasSurfaceServiceImpl::~FakeOffscreenCanvasSurfaceServiceImpl() |
+{ |
+ m_fakeSurfaceMap.clear(); |
+} |
+ |
+bool FakeOffscreenCanvasSurfaceServiceImpl::GetSurfaceId(cc::SurfaceId* surfaceId) |
+{ |
+ surfaceId = new cc::SurfaceId(10, 15, 0); |
jbroman
2016/06/16 21:11:48
This doesn't set the out parameter; it just rewrit
xlai (Olivia)
2016/06/16 23:16:21
Done.
|
+ 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); |
+} |
+ |
+void CanvasSurfaceLayerBridgeTest::SetUp() |
+{ |
+ m_surfaceService = new FakeOffscreenCanvasSurfaceServiceImpl(); |
+ OwnPtr<CanvasSurfaceLayerBridgeClient> bridgeClient = adoptPtr(new MockCanvasSurfaceLayerBridgeClient(m_surfaceService)); |
+ m_surfaceLayerBridge = adoptPtr(new CanvasSurfaceLayerBridge(std::move(bridgeClient))); |
+} |
+ |
+void CanvasSurfaceLayerBridgeTest::TearDown() |
+{ |
+ delete m_surfaceService; |
+ m_surfaceService = nullptr; |
+} |
+ |
+TEST_F(CanvasSurfaceLayerBridgeTest, SurfaceLayerCreation) |
+{ |
+ bool success = this->surfaceLayerBridge()->createSurfaceLayer(50, 50); |
+ EXPECT_TRUE(this->surfaceService()->isSurfaceInSurfaceMap(this->surfaceLayerBridge()->getSurfaceId())); |
+ EXPECT_TRUE(success); |
+} |
+ |
+} // namespace blink |