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

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: Fix GN build in android_dbg_recipe 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/OwnPtr.h"
13 #include "wtf/PassOwnPtr.h"
14 #include "wtf/Vector.h"
15
16 namespace blink {
17
18 class FakeOffscreenCanvasSurfaceServiceImpl {
19 public:
20 FakeOffscreenCanvasSurfaceServiceImpl() {}
21 ~FakeOffscreenCanvasSurfaceServiceImpl();
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(FakeOffscreenCanvasSurfaceServic eImpl*);
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 FakeOffscreenCanvasSurfaceServiceImpl* 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 FakeOffscreenCanvasSurfaceServiceImpl* surfaceService() const { return m_sur faceService; }
55
56 protected:
57 void SetUp() override;
58 void TearDown() override;
59
60 private:
61 OwnPtr<CanvasSurfaceLayerBridge> m_surfaceLayerBridge;
62 FakeOffscreenCanvasSurfaceServiceImpl* m_surfaceService;
jbroman 2016/06/16 21:11:48 This seems to be an owning pointer, too. std::uni
xlai (Olivia) 2016/06/16 23:16:21 OwnPtr is not suitable in this case. Due to the st
danakj 2016/06/16 23:19:23 Only one of the two owns it tho, right? So one wou
63 };
64
65 //-----------------------------------------------------------------------------
66
67 MockCanvasSurfaceLayerBridgeClient::MockCanvasSurfaceLayerBridgeClient(FakeOffsc reenCanvasSurfaceServiceImpl* 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 FakeOffscreenCanvasSurfaceServiceImpl::~FakeOffscreenCanvasSurfaceServiceImpl()
88 {
89 m_fakeSurfaceMap.clear();
90 }
91
92 bool FakeOffscreenCanvasSurfaceServiceImpl::GetSurfaceId(cc::SurfaceId* surfaceI d)
93 {
94 surfaceId = new cc::SurfaceId(10, 15, 0);
jbroman 2016/06/16 21:11:48 This doesn't set the out parameter; it just rewrit
xlai (Olivia) 2016/06/16 23:16:21 Done.
95 return true;
96 }
97
98 void FakeOffscreenCanvasSurfaceServiceImpl::RequestSurfaceCreation(const cc::Sur faceId& surfaceId)
99 {
100 m_fakeSurfaceMap.append(surfaceId);
101 }
102
103 bool FakeOffscreenCanvasSurfaceServiceImpl::isSurfaceInSurfaceMap(const cc::Surf aceId& surfaceId)
104 {
105 return m_fakeSurfaceMap.contains(surfaceId);
106 }
107
108 void CanvasSurfaceLayerBridgeTest::SetUp()
109 {
110 m_surfaceService = new FakeOffscreenCanvasSurfaceServiceImpl();
111 OwnPtr<CanvasSurfaceLayerBridgeClient> bridgeClient = adoptPtr(new MockCanva sSurfaceLayerBridgeClient(m_surfaceService));
112 m_surfaceLayerBridge = adoptPtr(new CanvasSurfaceLayerBridge(std::move(bridg eClient)));
113 }
114
115 void CanvasSurfaceLayerBridgeTest::TearDown()
116 {
117 delete m_surfaceService;
118 m_surfaceService = nullptr;
119 }
120
121 TEST_F(CanvasSurfaceLayerBridgeTest, SurfaceLayerCreation)
122 {
123 bool success = this->surfaceLayerBridge()->createSurfaceLayer(50, 50);
124 EXPECT_TRUE(this->surfaceService()->isSurfaceInSurfaceMap(this->surfaceLayer Bridge()->getSurfaceId()));
125 EXPECT_TRUE(success);
126 }
127
128 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698