| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/graphics/CanvasSurfaceLayerBridge.h" | 5 #include "platform/graphics/CanvasSurfaceLayerBridge.h" |
| 6 | 6 |
| 7 #include "cc/surfaces/surface_id.h" | 7 #include "cc/surfaces/surface_id.h" |
| 8 #include "cc/surfaces/surface_sequence.h" | 8 #include "cc/surfaces/surface_sequence.h" |
| 9 #include "platform/graphics/CanvasSurfaceLayerBridgeClient.h" | 9 #include "mojo/public/cpp/bindings/binding.h" |
| 10 #include "mojo/public/cpp/bindings/interface_request.h" |
| 11 #include "public/platform/modules/offscreencanvas/offscreen_canvas_surface.mojom
-blink.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "wtf/PtrUtil.h" | 14 #include "wtf/PtrUtil.h" |
| 13 #include <memory> | 15 #include <memory> |
| 14 | 16 |
| 15 namespace blink { | 17 namespace blink { |
| 16 | 18 |
| 17 class FakeOffscreenCanvasSurfaceImpl { | |
| 18 public: | |
| 19 FakeOffscreenCanvasSurfaceImpl() {} | |
| 20 ~FakeOffscreenCanvasSurfaceImpl() {} | |
| 21 | |
| 22 bool GetSurfaceId(cc::SurfaceId*); | |
| 23 }; | |
| 24 | |
| 25 //----------------------------------------------------------------------------- | 19 //----------------------------------------------------------------------------- |
| 26 | 20 |
| 27 class MockCanvasSurfaceLayerBridgeClient final : public CanvasSurfaceLayerBridge
Client { | 21 class MockOffscreenCanvasSurface final : public mojom::blink::OffscreenCanvasSur
face { |
| 28 public: | 22 public: |
| 29 explicit MockCanvasSurfaceLayerBridgeClient(FakeOffscreenCanvasSurfaceImpl*)
; | 23 MockOffscreenCanvasSurface(); |
| 30 ~MockCanvasSurfaceLayerBridgeClient() override; | 24 ~MockOffscreenCanvasSurface() override; |
| 31 | 25 |
| 32 bool syncGetSurfaceId(cc::SurfaceId*) override; | 26 mojom::blink::OffscreenCanvasSurfacePtr GetProxy(); |
| 33 void asyncRequire(const cc::SurfaceId&, const cc::SurfaceSequence&) override
{} | 27 |
| 34 void asyncSatisfy(const cc::SurfaceSequence&) override {} | 28 void GetSurfaceId(const GetSurfaceIdCallback&) override; |
| 29 void Require(const cc::SurfaceId&, const cc::SurfaceSequence&) override {} |
| 30 void Satisfy(const cc::SurfaceSequence&) override {} |
| 35 | 31 |
| 36 private: | 32 private: |
| 37 FakeOffscreenCanvasSurfaceImpl* m_service; | 33 mojo::Binding<mojom::blink::OffscreenCanvasSurface> m_binding; |
| 38 cc::SurfaceId m_surfaceId; | 34 cc::SurfaceId m_surfaceId; |
| 39 }; | 35 }; |
| 40 | 36 |
| 41 //----------------------------------------------------------------------------- | 37 //----------------------------------------------------------------------------- |
| 42 | 38 |
| 43 class CanvasSurfaceLayerBridgeTest : public testing::Test { | 39 class CanvasSurfaceLayerBridgeTest : public testing::Test { |
| 44 public: | 40 public: |
| 45 CanvasSurfaceLayerBridge* surfaceLayerBridge() const { return m_surfaceLayer
Bridge.get(); } | 41 CanvasSurfaceLayerBridge* surfaceLayerBridge() const { return m_surfaceLayer
Bridge.get(); } |
| 46 FakeOffscreenCanvasSurfaceImpl* surfaceService() const { return m_surfaceSer
vice.get(); } | |
| 47 | 42 |
| 48 protected: | 43 protected: |
| 49 void SetUp() override; | 44 void SetUp() override; |
| 50 | 45 |
| 51 private: | 46 private: |
| 52 std::unique_ptr<FakeOffscreenCanvasSurfaceImpl> m_surfaceService; | 47 MockOffscreenCanvasSurface m_service; |
| 53 std::unique_ptr<CanvasSurfaceLayerBridge> m_surfaceLayerBridge; | 48 std::unique_ptr<CanvasSurfaceLayerBridge> m_surfaceLayerBridge; |
| 54 }; | 49 }; |
| 55 | 50 |
| 56 //----------------------------------------------------------------------------- | 51 //----------------------------------------------------------------------------- |
| 57 | 52 |
| 58 MockCanvasSurfaceLayerBridgeClient::MockCanvasSurfaceLayerBridgeClient(FakeOffsc
reenCanvasSurfaceImpl* surfaceService) | 53 MockOffscreenCanvasSurface::MockOffscreenCanvasSurface() |
| 59 { | 54 : m_binding(this) |
| 60 m_service = surfaceService; | |
| 61 } | |
| 62 | |
| 63 MockCanvasSurfaceLayerBridgeClient::~MockCanvasSurfaceLayerBridgeClient() | |
| 64 { | 55 { |
| 65 } | 56 } |
| 66 | 57 |
| 67 bool MockCanvasSurfaceLayerBridgeClient::syncGetSurfaceId(cc::SurfaceId* surface
IdPtr) | 58 MockOffscreenCanvasSurface::~MockOffscreenCanvasSurface() |
| 68 { | 59 { |
| 69 return m_service->GetSurfaceId(surfaceIdPtr); | |
| 70 } | 60 } |
| 71 | 61 |
| 72 bool FakeOffscreenCanvasSurfaceImpl::GetSurfaceId(cc::SurfaceId* surfaceId) | 62 mojom::blink::OffscreenCanvasSurfacePtr MockOffscreenCanvasSurface::GetProxy() |
| 73 { | 63 { |
| 74 *surfaceId = cc::SurfaceId(10, 15, 0); | 64 return m_binding.CreateInterfacePtrAndBind(); |
| 75 return true; | 65 } |
| 66 |
| 67 void MockOffscreenCanvasSurface::GetSurfaceId(const GetSurfaceIdCallback& callba
ck) |
| 68 { |
| 69 callback.Run(cc::SurfaceId(10, 15, 0)); |
| 76 } | 70 } |
| 77 | 71 |
| 78 void CanvasSurfaceLayerBridgeTest::SetUp() | 72 void CanvasSurfaceLayerBridgeTest::SetUp() |
| 79 { | 73 { |
| 80 m_surfaceService = wrapUnique(new FakeOffscreenCanvasSurfaceImpl()); | 74 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(m_service.Get
Proxy())); |
| 81 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne
w MockCanvasSurfaceLayerBridgeClient(m_surfaceService.get())); | |
| 82 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri
dgeClient))); | |
| 83 } | 75 } |
| 84 | 76 |
| 85 TEST_F(CanvasSurfaceLayerBridgeTest, SurfaceLayerCreation) | 77 TEST_F(CanvasSurfaceLayerBridgeTest, SurfaceLayerCreation) |
| 86 { | 78 { |
| 87 bool success = this->surfaceLayerBridge()->createSurfaceLayer(50, 50); | 79 bool success = this->surfaceLayerBridge()->createSurfaceLayer(50, 50); |
| 88 EXPECT_TRUE(success); | 80 EXPECT_TRUE(success); |
| 89 } | 81 } |
| 90 | 82 |
| 91 } // namespace blink | 83 } // namespace blink |
| OLD | NEW |