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 "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "wtf/OwnPtr.h" |
| 12 #include "wtf/PassOwnPtr.h" |
| 13 #include "wtf/Vector.h" |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 class FakeOffscreenCanvasSurfaceServiceImpl { |
| 18 public: |
| 19 FakeOffscreenCanvasSurfaceServiceImpl() {} |
| 20 ~FakeOffscreenCanvasSurfaceServiceImpl(); |
| 21 |
| 22 bool GetSurfaceId(cc::SurfaceId*); |
| 23 void RequestSurfaceCreation(const cc::SurfaceId&); |
| 24 |
| 25 bool isSurfaceInSurfaceMap(const cc::SurfaceId&); |
| 26 |
| 27 private: |
| 28 Vector<cc::SurfaceId> m_fakeSurfaceMap; |
| 29 }; |
| 30 |
| 31 //----------------------------------------------------------------------------- |
| 32 |
| 33 class MockCanvasSurfaceLayerBridge : public CanvasSurfaceLayerBridge { |
| 34 public: |
| 35 explicit MockCanvasSurfaceLayerBridge(); |
| 36 ~MockCanvasSurfaceLayerBridge() override; |
| 37 |
| 38 // Implement virtual functions |
| 39 bool syncGetServiceId() override; |
| 40 void asyncRequestSurfaceCreation() override; |
| 41 |
| 42 FakeOffscreenCanvasSurfaceServiceImpl* service() const { return m_mockServic
e.get(); } |
| 43 cc::SurfaceId surfaceId() { return m_surfaceId; } |
| 44 |
| 45 private: |
| 46 OwnPtr<FakeOffscreenCanvasSurfaceServiceImpl> m_mockService; |
| 47 }; |
| 48 |
| 49 //----------------------------------------------------------------------------- |
| 50 |
| 51 class CanvasSurfaceLayerBridgeTest : public testing::Test { |
| 52 public: |
| 53 CanvasSurfaceLayerBridgeTest(); |
| 54 MockCanvasSurfaceLayerBridge* surfaceLayerBridge() const { return m_surfaceL
ayerBridge.get(); } |
| 55 |
| 56 private: |
| 57 OwnPtr<MockCanvasSurfaceLayerBridge> m_surfaceLayerBridge; |
| 58 }; |
| 59 |
| 60 //----------------------------------------------------------------------------- |
| 61 |
| 62 FakeOffscreenCanvasSurfaceServiceImpl::~FakeOffscreenCanvasSurfaceServiceImpl() |
| 63 { |
| 64 m_fakeSurfaceMap.clear(); |
| 65 } |
| 66 |
| 67 bool FakeOffscreenCanvasSurfaceServiceImpl::GetSurfaceId(cc::SurfaceId* surfaceI
d) |
| 68 { |
| 69 surfaceId = new cc::SurfaceId(10, 15, 0); |
| 70 return true; |
| 71 } |
| 72 |
| 73 void FakeOffscreenCanvasSurfaceServiceImpl::RequestSurfaceCreation(const cc::Sur
faceId& surfaceId) |
| 74 { |
| 75 m_fakeSurfaceMap.append(surfaceId); |
| 76 } |
| 77 |
| 78 bool FakeOffscreenCanvasSurfaceServiceImpl::isSurfaceInSurfaceMap(const cc::Surf
aceId& surfaceId) |
| 79 { |
| 80 return m_fakeSurfaceMap.contains(surfaceId); |
| 81 } |
| 82 |
| 83 MockCanvasSurfaceLayerBridge::MockCanvasSurfaceLayerBridge() |
| 84 { |
| 85 // The constructor of CanvasSurfaceLayerBridge connects to remote mojo |
| 86 // service and sets m_mockService as a connection end. Here, we fake the |
| 87 // m_service that acts similar to OffscreenCanvasSurfaceServiceImpl on the |
| 88 // browser side. |
| 89 m_mockService = adoptPtr(new FakeOffscreenCanvasSurfaceServiceImpl()); |
| 90 } |
| 91 |
| 92 MockCanvasSurfaceLayerBridge::~MockCanvasSurfaceLayerBridge() |
| 93 { |
| 94 } |
| 95 |
| 96 bool MockCanvasSurfaceLayerBridge::syncGetServiceId() |
| 97 { |
| 98 return m_mockService->GetSurfaceId(&m_surfaceId); |
| 99 } |
| 100 |
| 101 void MockCanvasSurfaceLayerBridge::asyncRequestSurfaceCreation() |
| 102 { |
| 103 m_mockService->RequestSurfaceCreation(m_surfaceId); |
| 104 } |
| 105 |
| 106 CanvasSurfaceLayerBridgeTest::CanvasSurfaceLayerBridgeTest() |
| 107 { |
| 108 m_surfaceLayerBridge = adoptPtr(new MockCanvasSurfaceLayerBridge()); |
| 109 } |
| 110 |
| 111 TEST_F(CanvasSurfaceLayerBridgeTest, SurfaceLayerCreation) |
| 112 { |
| 113 bool success = this->surfaceLayerBridge()->createSurfaceLayer(50, 50); |
| 114 |
| 115 EXPECT_TRUE(this->surfaceLayerBridge()->service()->isSurfaceInSurfaceMap(thi
s->surfaceLayerBridge()->surfaceId())); |
| 116 EXPECT_TRUE(success); |
| 117 } |
| 118 |
| 119 } // namespace blink |
OLD | NEW |