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

Side by Side Diff: media/mojo/clients/mojo_android_overlay_unittest.cc

Issue 2864603002: Provide callback to create mojo AndroidOverlays to AVDA. (Closed)
Patch Set: rebased Created 3 years, 7 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
« no previous file with comments | « media/mojo/clients/mojo_android_overlay.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 OverlayCreated(); 60 OverlayCreated();
61 } 61 }
62 62
63 MOCK_METHOD0(OverlayCreated, void(void)); 63 MOCK_METHOD0(OverlayCreated, void(void));
64 64
65 mojom::AndroidOverlayRequest overlay_request_; 65 mojom::AndroidOverlayRequest overlay_request_;
66 mojom::AndroidOverlayClientPtr client_; 66 mojom::AndroidOverlayClientPtr client_;
67 mojom::AndroidOverlayConfigPtr config_; 67 mojom::AndroidOverlayConfigPtr config_;
68 }; 68 };
69 69
70 // When the overlay client needs the provider interface, it'll ask us.
71 class MockInterfaceProvider
72 : public StrictMock<service_manager::mojom::InterfaceProvider> {
73 public:
74 // |provider| is the provider that we'll provide, provided that we're only
75 // asked to provide it once. Savvy?
76 MockInterfaceProvider(mojom::AndroidOverlayProvider& provider)
77 : provider_binding_(&provider) {}
78
79 // We can't mock GetInterface directly because of |handle|'s deleted ctor.
80 MOCK_METHOD1(InterfaceGotten, void(const std::string&));
81
82 void GetInterface(const std::string& name,
83 mojo::ScopedMessagePipeHandle handle) override {
84 // Let the mock know.
85 InterfaceGotten(name);
86
87 // Actually do the work.
88 provider_binding_.Bind(
89 mojom::AndroidOverlayProviderRequest(std::move(handle)));
90 }
91
92 mojo::Binding<mojom::AndroidOverlayProvider> provider_binding_;
93 };
94
95 public: 70 public:
96 MojoAndroidOverlayTest() 71 MojoAndroidOverlayTest()
97 : overlay_binding_(&mock_overlay_), interface_provider_(mock_provider_) {} 72 : provider_binding_(&mock_provider_), overlay_binding_(&mock_overlay_) {}
98 73
99 ~MojoAndroidOverlayTest() override {} 74 ~MojoAndroidOverlayTest() override {}
100 75
101 void SetUp() override { 76 void SetUp() override {
102 // Set up default config. 77 // Set up default config.
103 config_.rect = gfx::Rect(100, 200, 300, 400); 78 config_.rect = gfx::Rect(100, 200, 300, 400);
104 config_.ready_cb = base::Bind(&MockClientCallbacks::OnReady, 79 config_.ready_cb = base::Bind(&MockClientCallbacks::OnReady,
105 base::Unretained(&callbacks_)); 80 base::Unretained(&callbacks_));
106 config_.failed_cb = base::Bind(&MockClientCallbacks::OnFailed, 81 config_.failed_cb = base::Bind(&MockClientCallbacks::OnFailed,
107 base::Unretained(&callbacks_)); 82 base::Unretained(&callbacks_));
(...skipping 13 matching lines...) Expand all
121 // Drop the surface before the surface texture. 96 // Drop the surface before the surface texture.
122 surface_ = gl::ScopedJavaSurface(); 97 surface_ = gl::ScopedJavaSurface();
123 } 98 }
124 99
125 base::RunLoop().RunUntilIdle(); 100 base::RunLoop().RunUntilIdle();
126 } 101 }
127 102
128 // Create an overlay in |overlay_client_| using the current config, but do 103 // Create an overlay in |overlay_client_| using the current config, but do
129 // not bind anything to |overlay_request_| yet. 104 // not bind anything to |overlay_request_| yet.
130 void CreateOverlay() { 105 void CreateOverlay() {
131 EXPECT_CALL(interface_provider_,
132 InterfaceGotten(mojom::AndroidOverlayProvider::Name_))
133 .Times(1);
134 EXPECT_CALL(mock_provider_, OverlayCreated()); 106 EXPECT_CALL(mock_provider_, OverlayCreated());
135 107
136 base::UnguessableToken routing_token = base::UnguessableToken::Create(); 108 base::UnguessableToken routing_token = base::UnguessableToken::Create();
109 mojom::AndroidOverlayProviderPtr provider_ptr;
110 provider_binding_.Bind(mojo::MakeRequest(&provider_ptr));
111
137 overlay_client_.reset(new MojoAndroidOverlay( 112 overlay_client_.reset(new MojoAndroidOverlay(
138 &interface_provider_, std::move(config_), routing_token)); 113 std::move(provider_ptr), std::move(config_), routing_token));
139 base::RunLoop().RunUntilIdle(); 114 base::RunLoop().RunUntilIdle();
140 } 115 }
141 116
142 // Create an overlay, then provide it with |mock_overlay_|. 117 // Create an overlay, then provide it with |mock_overlay_|.
143 void CreateAndInitializeOverlay() { 118 void CreateAndInitializeOverlay() {
144 CreateOverlay(); 119 CreateOverlay();
145 120
146 // Bind an overlay to the request. 121 // Bind an overlay to the request.
147 overlay_binding_.Bind(std::move(mock_provider_.overlay_request_)); 122 overlay_binding_.Bind(std::move(mock_provider_.overlay_request_));
148 base::RunLoop().RunUntilIdle(); 123 base::RunLoop().RunUntilIdle();
(...skipping 26 matching lines...) Expand all
175 base::RunLoop().RunUntilIdle(); 150 base::RunLoop().RunUntilIdle();
176 } 151 }
177 152
178 // Mojo stuff. 153 // Mojo stuff.
179 base::MessageLoop loop; 154 base::MessageLoop loop;
180 155
181 // The mock provider that |overlay_client_| will talk to. 156 // The mock provider that |overlay_client_| will talk to.
182 // |interface_provider_| will bind it. 157 // |interface_provider_| will bind it.
183 MockAndroidOverlayProvider mock_provider_; 158 MockAndroidOverlayProvider mock_provider_;
184 159
160 // Binding for |mock_provider_|.
161 mojo::Binding<mojom::AndroidOverlayProvider> provider_binding_;
162
185 // The mock overlay impl that |mock_provider_| will provide. 163 // The mock overlay impl that |mock_provider_| will provide.
186 MockAndroidOverlay mock_overlay_; 164 MockAndroidOverlay mock_overlay_;
187 mojo::Binding<mojom::AndroidOverlay> overlay_binding_; 165 mojo::Binding<mojom::AndroidOverlay> overlay_binding_;
188 166
189 // The InterfaceProvider impl that will provide |mock_provider_| to the
190 // overlay client |overlay_client_|.
191 MockInterfaceProvider interface_provider_;
192
193 // The client under test. 167 // The client under test.
194 std::unique_ptr<AndroidOverlay> overlay_client_; 168 std::unique_ptr<AndroidOverlay> overlay_client_;
195 169
196 // If we create a surface, then these are the SurfaceTexture that owns it, 170 // If we create a surface, then these are the SurfaceTexture that owns it,
197 // the surface itself, and the key that we registered with GpuSurfaceLookup, 171 // the surface itself, and the key that we registered with GpuSurfaceLookup,
198 // respectively. We could probably mock out GpuSurfaceLookup, but we'd still 172 // respectively. We could probably mock out GpuSurfaceLookup, but we'd still
199 // have to provide a (mock) ScopedJavaSurface, which isn't easy. 173 // have to provide a (mock) ScopedJavaSurface, which isn't easy.
200 scoped_refptr<gl::SurfaceTexture> surface_texture_; 174 scoped_refptr<gl::SurfaceTexture> surface_texture_;
201 gl::ScopedJavaSurface surface_; 175 gl::ScopedJavaSurface surface_;
202 int surface_key_ = 0; 176 int surface_key_ = 0;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 } 230 }
257 231
258 // Test |secure| makes it to the mojo config when it is false 232 // Test |secure| makes it to the mojo config when it is false
259 TEST_F(MojoAndroidOverlayTest, SecureFlagIsSentViaMojoWhenFalse) { 233 TEST_F(MojoAndroidOverlayTest, SecureFlagIsSentViaMojoWhenFalse) {
260 config_.secure = false; 234 config_.secure = false;
261 CreateOverlay(); 235 CreateOverlay();
262 ASSERT_FALSE(mock_provider_.config_->secure); 236 ASSERT_FALSE(mock_provider_.config_->secure);
263 } 237 }
264 238
265 } // namespace media 239 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/clients/mojo_android_overlay.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698