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