Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridgeTest.cpp

Issue 2036663003: Establish mojo service between Canvas (blink) and SurfaceManager (browser) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: OWNERS change on offscreencanvas folder Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/PtrUtil.h"
13 #include "wtf/Vector.h"
14 #include <memory>
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
59 private:
60 std::unique_ptr<FakeOffscreenCanvasSurfaceImpl> m_surfaceService;
61 std::unique_ptr<CanvasSurfaceLayerBridge> m_surfaceLayerBridge;
62 };
63
64 //-----------------------------------------------------------------------------
65
66 MockCanvasSurfaceLayerBridgeClient::MockCanvasSurfaceLayerBridgeClient(FakeOffsc reenCanvasSurfaceImpl* surfaceService)
67 {
68 m_service = surfaceService;
69 }
70
71 MockCanvasSurfaceLayerBridgeClient::~MockCanvasSurfaceLayerBridgeClient()
72 {
73 }
74
75 bool MockCanvasSurfaceLayerBridgeClient::syncGetSurfaceId(cc::SurfaceId* surface IdPtr)
76 {
77 return m_service->GetSurfaceId(surfaceIdPtr);
78 }
79
80 void MockCanvasSurfaceLayerBridgeClient::asyncRequestSurfaceCreation(const cc::S urfaceId& surfaceId)
81 {
82 m_service->RequestSurfaceCreation(surfaceId);
83 }
84
85 FakeOffscreenCanvasSurfaceImpl::~FakeOffscreenCanvasSurfaceImpl()
86 {
87 m_fakeSurfaceMap.clear();
88 }
89
90 bool FakeOffscreenCanvasSurfaceImpl::GetSurfaceId(cc::SurfaceId* surfaceId)
91 {
92 *surfaceId = cc::SurfaceId(10, 15, 0);
93 return true;
94 }
95
96 void FakeOffscreenCanvasSurfaceImpl::RequestSurfaceCreation(const cc::SurfaceId& surfaceId)
97 {
98 m_fakeSurfaceMap.append(surfaceId);
99 }
100
101 bool FakeOffscreenCanvasSurfaceImpl::isSurfaceInSurfaceMap(const cc::SurfaceId& surfaceId)
102 {
103 return m_fakeSurfaceMap.contains(surfaceId);
104 }
105
106 void CanvasSurfaceLayerBridgeTest::SetUp()
107 {
108 m_surfaceService = wrapUnique(new FakeOffscreenCanvasSurfaceImpl());
109 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne w MockCanvasSurfaceLayerBridgeClient(m_surfaceService.get()));
110 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri dgeClient)));
111 }
112
113 TEST_F(CanvasSurfaceLayerBridgeTest, SurfaceLayerCreation)
114 {
115 bool success = this->surfaceLayerBridge()->createSurfaceLayer(50, 50);
116 EXPECT_TRUE(this->surfaceService()->isSurfaceInSurfaceMap(this->surfaceLayer Bridge()->getSurfaceId()));
117 EXPECT_TRUE(success);
118 }
119
120 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698