OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "platform/graphics/CanvasSurfaceLayerBridge.h" |
| 6 |
| 7 #include "cc/surfaces/surface_id.h" |
| 8 #include "cc/surfaces/surface_sequence.h" |
| 9 #include "platform/graphics/CanvasSurfaceLayerBridgeClient.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "wtf/OwnPtr.h" |
| 13 #include "wtf/PassOwnPtr.h" |
| 14 #include "wtf/Vector.h" |
| 15 |
| 16 namespace blink { |
| 17 |
| 18 class FakeOffscreenCanvasSurfaceImpl { |
| 19 public: |
| 20 FakeOffscreenCanvasSurfaceImpl() {} |
| 21 ~FakeOffscreenCanvasSurfaceImpl(); |
| 22 |
| 23 bool GetSurfaceId(cc::SurfaceId*); |
| 24 void RequestSurfaceCreation(const cc::SurfaceId&); |
| 25 |
| 26 bool isSurfaceInSurfaceMap(const cc::SurfaceId&); |
| 27 |
| 28 private: |
| 29 Vector<cc::SurfaceId> m_fakeSurfaceMap; |
| 30 }; |
| 31 |
| 32 //----------------------------------------------------------------------------- |
| 33 |
| 34 class MockCanvasSurfaceLayerBridgeClient final : public CanvasSurfaceLayerBridge
Client { |
| 35 public: |
| 36 explicit MockCanvasSurfaceLayerBridgeClient(FakeOffscreenCanvasSurfaceImpl*)
; |
| 37 ~MockCanvasSurfaceLayerBridgeClient() override; |
| 38 |
| 39 bool syncGetSurfaceId(cc::SurfaceId*) override; |
| 40 void asyncRequestSurfaceCreation(const cc::SurfaceId&) override; |
| 41 void asyncRequire(cc::SurfaceId, cc::SurfaceSequence) override {} |
| 42 void asyncSatisfy(cc::SurfaceSequence) override {}; |
| 43 |
| 44 private: |
| 45 FakeOffscreenCanvasSurfaceImpl* m_service; |
| 46 cc::SurfaceId m_surfaceId; |
| 47 }; |
| 48 |
| 49 //----------------------------------------------------------------------------- |
| 50 |
| 51 class CanvasSurfaceLayerBridgeTest : public testing::Test { |
| 52 public: |
| 53 CanvasSurfaceLayerBridge* surfaceLayerBridge() const { return m_surfaceLayer
Bridge.get(); } |
| 54 FakeOffscreenCanvasSurfaceImpl* surfaceService() const { return m_surfaceSer
vice.get(); } |
| 55 |
| 56 protected: |
| 57 void SetUp() override; |
| 58 void TearDown() override; |
| 59 |
| 60 private: |
| 61 OwnPtr<CanvasSurfaceLayerBridge> m_surfaceLayerBridge; |
| 62 OwnPtr<FakeOffscreenCanvasSurfaceImpl> m_surfaceService; |
| 63 }; |
| 64 |
| 65 //----------------------------------------------------------------------------- |
| 66 |
| 67 MockCanvasSurfaceLayerBridgeClient::MockCanvasSurfaceLayerBridgeClient(FakeOffsc
reenCanvasSurfaceImpl* surfaceService) |
| 68 { |
| 69 m_service = surfaceService; |
| 70 } |
| 71 |
| 72 MockCanvasSurfaceLayerBridgeClient::~MockCanvasSurfaceLayerBridgeClient() |
| 73 { |
| 74 m_service = nullptr; |
| 75 } |
| 76 |
| 77 bool MockCanvasSurfaceLayerBridgeClient::syncGetSurfaceId(cc::SurfaceId* surface
IdPtr) |
| 78 { |
| 79 return m_service->GetSurfaceId(surfaceIdPtr); |
| 80 } |
| 81 |
| 82 void MockCanvasSurfaceLayerBridgeClient::asyncRequestSurfaceCreation(const cc::S
urfaceId& surfaceId) |
| 83 { |
| 84 m_service->RequestSurfaceCreation(surfaceId); |
| 85 } |
| 86 |
| 87 FakeOffscreenCanvasSurfaceImpl::~FakeOffscreenCanvasSurfaceImpl() |
| 88 { |
| 89 m_fakeSurfaceMap.clear(); |
| 90 } |
| 91 |
| 92 bool FakeOffscreenCanvasSurfaceImpl::GetSurfaceId(cc::SurfaceId* surfaceId) |
| 93 { |
| 94 *surfaceId = cc::SurfaceId(10, 15, 0); |
| 95 return true; |
| 96 } |
| 97 |
| 98 void FakeOffscreenCanvasSurfaceImpl::RequestSurfaceCreation(const cc::SurfaceId&
surfaceId) |
| 99 { |
| 100 m_fakeSurfaceMap.append(surfaceId); |
| 101 } |
| 102 |
| 103 bool FakeOffscreenCanvasSurfaceImpl::isSurfaceInSurfaceMap(const cc::SurfaceId&
surfaceId) |
| 104 { |
| 105 return m_fakeSurfaceMap.contains(surfaceId); |
| 106 } |
| 107 |
| 108 void CanvasSurfaceLayerBridgeTest::SetUp() |
| 109 { |
| 110 m_surfaceService = adoptPtr(new FakeOffscreenCanvasSurfaceImpl()); |
| 111 OwnPtr<CanvasSurfaceLayerBridgeClient> bridgeClient = adoptPtr(new MockCanva
sSurfaceLayerBridgeClient(m_surfaceService.get())); |
| 112 m_surfaceLayerBridge = adoptPtr(new CanvasSurfaceLayerBridge(std::move(bridg
eClient))); |
| 113 } |
| 114 |
| 115 void CanvasSurfaceLayerBridgeTest::TearDown() |
| 116 { |
| 117 } |
| 118 |
| 119 TEST_F(CanvasSurfaceLayerBridgeTest, SurfaceLayerCreation) |
| 120 { |
| 121 bool success = this->surfaceLayerBridge()->createSurfaceLayer(50, 50); |
| 122 EXPECT_TRUE(this->surfaceService()->isSurfaceInSurfaceMap(this->surfaceLayer
Bridge()->getSurfaceId())); |
| 123 EXPECT_TRUE(success); |
| 124 } |
| 125 |
| 126 } // namespace blink |
OLD | NEW |