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

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: Minor Fix on OwnPtr on CanvasSurfaceLayerBridgeTest 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.get(); }
55
56 protected:
57 void SetUp() override;
58 void TearDown() override;
59
60 private:
61 OwnPtr<CanvasSurfaceLayerBridge> m_surfaceLayerBridge;
62 OwnPtr<FakeOffscreenCanvasSurfaceServiceImpl> m_surfaceService;
danakj 2016/06/17 00:33:28 Since the m_surfaceLayerBridge has a pointer to th
xlai (Olivia) 2016/06/17 16:04:07 Actually m_surfaceLayerBridge itself doesn't conta
danakj 2016/06/17 17:53:03 Sorry, what I mean is that on line 111-112 we have
xlai (Olivia) 2016/06/17 20:47:02 Done. Thanks! I've reversed the order of OwnPtr in
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 = cc::SurfaceId(10, 15, 0);
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 = adoptPtr(new FakeOffscreenCanvasSurfaceServiceImpl());
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698