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

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

Issue 2867633002: Fetch the surface from GpuSurfaceTracker for mojo AndroidOverlay. (Closed)
Patch Set: started checking surface obj 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/bind.h" 8 #include "base/bind.h"
8 #include "base/macros.h" 9 #include "base/macros.h"
9 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "gpu/ipc/common/gpu_surface_tracker.h"
12 #include "media/base/mock_filters.h" 14 #include "media/base/mock_filters.h"
13 #include "media/mojo/clients/mojo_android_overlay.h" 15 #include "media/mojo/clients/mojo_android_overlay.h"
14 #include "mojo/public/cpp/bindings/interface_request.h" 16 #include "mojo/public/cpp/bindings/interface_request.h"
15 #include "mojo/public/cpp/bindings/strong_binding.h" 17 #include "mojo/public/cpp/bindings/strong_binding.h"
16 #include "services/service_manager/public/interfaces/interface_provider.mojom.h" 18 #include "services/service_manager/public/interfaces/interface_provider.mojom.h"
17
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "ui/gl/android/scoped_java_surface.h"
21 #include "ui/gl/android/surface_texture.h"
19 22
20 using ::testing::_; 23 using ::testing::_;
21 using ::testing::StrictMock; 24 using ::testing::StrictMock;
22 25
23 namespace media { 26 namespace media {
24 27
25 class MojoAndroidOverlayTest : public ::testing::Test { 28 class MojoAndroidOverlayTest : public ::testing::Test {
26 public: 29 public:
27 class MockAndroidOverlay : public StrictMock<mojom::AndroidOverlay> { 30 class MockAndroidOverlay : public StrictMock<mojom::AndroidOverlay> {
28 public: 31 public:
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 100
98 void SetUp() override { 101 void SetUp() override {
99 // Set up default config. 102 // Set up default config.
100 config_.rect = gfx::Rect(100, 200, 300, 400); 103 config_.rect = gfx::Rect(100, 200, 300, 400);
101 config_.ready_cb = base::Bind(&MockClientCallbacks::OnReady, 104 config_.ready_cb = base::Bind(&MockClientCallbacks::OnReady,
102 base::Unretained(&callbacks_)); 105 base::Unretained(&callbacks_));
103 config_.failed_cb = base::Bind(&MockClientCallbacks::OnFailed, 106 config_.failed_cb = base::Bind(&MockClientCallbacks::OnFailed,
104 base::Unretained(&callbacks_)); 107 base::Unretained(&callbacks_));
105 config_.destroyed_cb = base::Bind(&MockClientCallbacks::OnDestroyed, 108 config_.destroyed_cb = base::Bind(&MockClientCallbacks::OnDestroyed,
106 base::Unretained(&callbacks_)); 109 base::Unretained(&callbacks_));
110
111 // Make sure that we have an implementation of GpuSurfaceLookup.
112 gpu::GpuSurfaceTracker::Get();
107 } 113 }
108 114
109 void TearDown() override { 115 void TearDown() override {
110 overlay_client_.reset(); 116 overlay_client_.reset();
117
118 // If we registered a surface, then unregister it.
119 if (surface_texture_) {
120 gpu::GpuSurfaceTracker::Get()->RemoveSurface(surface_key_);
121 // Drop the surface before the surface texture.
122 surface_ = gl::ScopedJavaSurface();
123 }
124
111 base::RunLoop().RunUntilIdle(); 125 base::RunLoop().RunUntilIdle();
112 } 126 }
113 127
114 // Create an overlay in |overlay_client_| using the current config, but do 128 // Create an overlay in |overlay_client_| using the current config, but do
115 // not bind anything to |overlay_request_| yet. 129 // not bind anything to |overlay_request_| yet.
116 void CreateOverlay() { 130 void CreateOverlay() {
117 EXPECT_CALL(interface_provider_, 131 EXPECT_CALL(interface_provider_,
118 InterfaceGotten(mojom::AndroidOverlayProvider::Name_)) 132 InterfaceGotten(mojom::AndroidOverlayProvider::Name_))
119 .Times(1); 133 .Times(1);
120 EXPECT_CALL(mock_provider_, OverlayCreated()); 134 EXPECT_CALL(mock_provider_, OverlayCreated());
121 135
122 base::UnguessableToken routing_token = base::UnguessableToken::Create(); 136 base::UnguessableToken routing_token = base::UnguessableToken::Create();
123 overlay_client_.reset(new MojoAndroidOverlay( 137 overlay_client_.reset(new MojoAndroidOverlay(
124 &interface_provider_, std::move(config_), routing_token)); 138 &interface_provider_, std::move(config_), routing_token));
125 base::RunLoop().RunUntilIdle(); 139 base::RunLoop().RunUntilIdle();
126 } 140 }
127 141
128 // Create an overlay, then provide it with |mock_overlay_|. 142 // Create an overlay, then provide it with |mock_overlay_|.
129 void CreateAndInitializeOverlay() { 143 void CreateAndInitializeOverlay() {
130 CreateOverlay(); 144 CreateOverlay();
131 145
132 // Bind an overlay to the request. 146 // Bind an overlay to the request.
133 overlay_binding_.Bind(std::move(mock_provider_.overlay_request_)); 147 overlay_binding_.Bind(std::move(mock_provider_.overlay_request_));
134 base::RunLoop().RunUntilIdle(); 148 base::RunLoop().RunUntilIdle();
135 } 149 }
136 150
137 // Notify |overlay_client_| that the surface is ready. 151 // Notify |overlay_client_| that the surface is ready.
138 void CreateSurface() { 152 void CreateSurface() {
139 EXPECT_CALL(callbacks_, OnReady(overlay_client_.get())); 153 EXPECT_CALL(callbacks_, OnReady(overlay_client_.get()));
140 const int surface_key = 123; 154
141 mock_provider_.client_->OnSurfaceReady(surface_key); 155 // We have to actually add a valid surface, else the client will get mad
156 // when it tries to retrieve it.
157 surface_texture_ = gl::SurfaceTexture::Create(0);
158 surface_ = gl::ScopedJavaSurface(surface_texture_.get());
159 surface_key_ = gpu::GpuSurfaceTracker::Get()->AddSurfaceForNativeWidget(
160 gpu::GpuSurfaceTracker::SurfaceRecord(gfx::kNullAcceleratedWidget,
161 surface_.j_surface().obj()));
162
163 mock_provider_.client_->OnSurfaceReady(surface_key_);
142 base::RunLoop().RunUntilIdle(); 164 base::RunLoop().RunUntilIdle();
165
166 // Verify that we actually got back the right surface.
167 JNIEnv* env = base::android::AttachCurrentThread();
168 ASSERT_TRUE(env->IsSameObject(surface_.j_surface().obj(),
169 overlay_client_->GetJavaSurface().obj()));
143 } 170 }
144 171
145 // Destroy the overlay. This includes onSurfaceDestroyed cases. 172 // Destroy the overlay. This includes onSurfaceDestroyed cases.
146 void DestroyOverlay() { 173 void DestroyOverlay() {
147 mock_provider_.client_->OnDestroyed(); 174 mock_provider_.client_->OnDestroyed();
148 base::RunLoop().RunUntilIdle(); 175 base::RunLoop().RunUntilIdle();
149 } 176 }
150 177
151 // Mojo stuff. 178 // Mojo stuff.
152 base::MessageLoop loop; 179 base::MessageLoop loop;
153 180
154 // The mock provider that |overlay_client_| will talk to. 181 // The mock provider that |overlay_client_| will talk to.
155 // |interface_provider_| will bind it. 182 // |interface_provider_| will bind it.
156 MockAndroidOverlayProvider mock_provider_; 183 MockAndroidOverlayProvider mock_provider_;
157 184
158 // The mock overlay impl that |mock_provider_| will provide. 185 // The mock overlay impl that |mock_provider_| will provide.
159 MockAndroidOverlay mock_overlay_; 186 MockAndroidOverlay mock_overlay_;
160 mojo::Binding<mojom::AndroidOverlay> overlay_binding_; 187 mojo::Binding<mojom::AndroidOverlay> overlay_binding_;
161 188
162 // The InterfaceProvider impl that will provide |mock_provider_| to the 189 // The InterfaceProvider impl that will provide |mock_provider_| to the
163 // overlay client |overlay_client_|. 190 // overlay client |overlay_client_|.
164 MockInterfaceProvider interface_provider_; 191 MockInterfaceProvider interface_provider_;
165 192
166 // The client under test. 193 // The client under test.
167 std::unique_ptr<AndroidOverlay> overlay_client_; 194 std::unique_ptr<AndroidOverlay> overlay_client_;
168 195
196 // 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,
198 // respectively. We could probably mock out GpuSurfaceLookup, but we'd still
199 // have to provide a (mock) ScopedJavaSurface, which isn't easy.
200 scoped_refptr<gl::SurfaceTexture> surface_texture_;
201 gl::ScopedJavaSurface surface_;
202 int surface_key_ = 0;
203
169 // Inital config for |CreateOverlay|. 204 // Inital config for |CreateOverlay|.
170 // Set to sane values, but feel free to modify before CreateOverlay(). 205 // Set to sane values, but feel free to modify before CreateOverlay().
171 AndroidOverlayConfig config_; 206 AndroidOverlayConfig config_;
172 MockClientCallbacks callbacks_; 207 MockClientCallbacks callbacks_;
173 }; 208 };
174 209
175 // Verify basic create => init => ready => destroyed. 210 // Verify basic create => init => ready => destroyed.
176 TEST_F(MojoAndroidOverlayTest, CreateInitReadyDestroy) { 211 TEST_F(MojoAndroidOverlayTest, CreateInitReadyDestroy) {
177 CreateAndInitializeOverlay(); 212 CreateAndInitializeOverlay();
178 CreateSurface(); 213 CreateSurface();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 256 }
222 257
223 // Test |secure| makes it to the mojo config when it is false 258 // Test |secure| makes it to the mojo config when it is false
224 TEST_F(MojoAndroidOverlayTest, SecureFlagIsSentViaMojoWhenFalse) { 259 TEST_F(MojoAndroidOverlayTest, SecureFlagIsSentViaMojoWhenFalse) {
225 config_.secure = false; 260 config_.secure = false;
226 CreateOverlay(); 261 CreateOverlay();
227 ASSERT_FALSE(mock_provider_.config_->secure); 262 ASSERT_FALSE(mock_provider_.config_->secure);
228 } 263 }
229 264
230 } // namespace media 265 } // 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