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..61e9d599ba9a2b27da5093cd7c78170fffe5f5f3 |
--- /dev/null |
+++ b/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridgeTest.cpp |
@@ -0,0 +1,126 @@ |
+// 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.get(); } |
+ |
+protected: |
+ void SetUp() override; |
+ void TearDown() override; |
+ |
+private: |
+ OwnPtr<CanvasSurfaceLayerBridge> m_surfaceLayerBridge; |
+ OwnPtr<FakeOffscreenCanvasSurfaceServiceImpl> m_surfaceService; |
danakj
2016/06/17 00:33:28
Since the m_surfaceLayerBridge has a pointer to th
xlai (Olivia)
2016/06/17 16:04:07
Actually m_surfaceLayerBridge itself doesn't conta
danakj
2016/06/17 17:53:03
Sorry, what I mean is that on line 111-112 we have
xlai (Olivia)
2016/06/17 20:47:02
Done. Thanks! I've reversed the order of OwnPtr in
|
+}; |
+ |
+//----------------------------------------------------------------------------- |
+ |
+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 = 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); |
+} |
+ |
+void CanvasSurfaceLayerBridgeTest::SetUp() |
+{ |
+ m_surfaceService = adoptPtr(new FakeOffscreenCanvasSurfaceServiceImpl()); |
+ OwnPtr<CanvasSurfaceLayerBridgeClient> bridgeClient = adoptPtr(new MockCanvasSurfaceLayerBridgeClient(m_surfaceService.get())); |
+ m_surfaceLayerBridge = adoptPtr(new CanvasSurfaceLayerBridge(std::move(bridgeClient))); |
+} |
+ |
+void CanvasSurfaceLayerBridgeTest::TearDown() |
+{ |
+} |
+ |
+TEST_F(CanvasSurfaceLayerBridgeTest, SurfaceLayerCreation) |
+{ |
+ bool success = this->surfaceLayerBridge()->createSurfaceLayer(50, 50); |
+ EXPECT_TRUE(this->surfaceService()->isSurfaceInSurfaceMap(this->surfaceLayerBridge()->getSurfaceId())); |
+ EXPECT_TRUE(success); |
+} |
+ |
+} // namespace blink |