OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Tests PPB_MediaStreamAudioTrack interface. | 5 // Tests PPB_MediaStreamAudioTrack interface. |
6 | 6 |
7 #include "ppapi/tests/test_media_stream_audio_track.h" | 7 #include "ppapi/tests/test_media_stream_audio_track.h" |
8 | 8 |
9 #include "ppapi/c/private/ppb_testing_private.h" | 9 #include "ppapi/c/private/ppb_testing_private.h" |
10 #include "ppapi/cpp/audio_buffer.h" | 10 #include "ppapi/cpp/audio_buffer.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 return true; | 69 return true; |
70 } | 70 } |
71 | 71 |
72 TestMediaStreamAudioTrack::~TestMediaStreamAudioTrack() { | 72 TestMediaStreamAudioTrack::~TestMediaStreamAudioTrack() { |
73 } | 73 } |
74 | 74 |
75 void TestMediaStreamAudioTrack::RunTests(const std::string& filter) { | 75 void TestMediaStreamAudioTrack::RunTests(const std::string& filter) { |
76 RUN_TEST(Create, filter); | 76 RUN_TEST(Create, filter); |
77 RUN_TEST(GetBuffer, filter); | 77 RUN_TEST(GetBuffer, filter); |
78 RUN_TEST(Configure, filter); | 78 RUN_TEST(Configure, filter); |
| 79 RUN_TEST(ConfigureClose, filter); |
79 } | 80 } |
80 | 81 |
81 void TestMediaStreamAudioTrack::HandleMessage(const pp::Var& message) { | 82 void TestMediaStreamAudioTrack::HandleMessage(const pp::Var& message) { |
82 if (message.is_resource()) { | 83 if (message.is_resource()) { |
83 audio_track_ = pp::MediaStreamAudioTrack(message.AsResource()); | 84 audio_track_ = pp::MediaStreamAudioTrack(message.AsResource()); |
84 } | 85 } |
85 event_.Signal(); | 86 event_.Signal(); |
86 } | 87 } |
87 | 88 |
88 std::string TestMediaStreamAudioTrack::TestCreate() { | 89 std::string TestMediaStreamAudioTrack::TestCreate() { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 std::string TestMediaStreamAudioTrack::TestConfigure() { | 198 std::string TestMediaStreamAudioTrack::TestConfigure() { |
198 // Create a track. | 199 // Create a track. |
199 instance_->EvalScript(kJSCode); | 200 instance_->EvalScript(kJSCode); |
200 event_.Wait(); | 201 event_.Wait(); |
201 event_.Reset(); | 202 event_.Reset(); |
202 | 203 |
203 ASSERT_FALSE(audio_track_.is_null()); | 204 ASSERT_FALSE(audio_track_.is_null()); |
204 ASSERT_FALSE(audio_track_.HasEnded()); | 205 ASSERT_FALSE(audio_track_.HasEnded()); |
205 ASSERT_FALSE(audio_track_.GetId().empty()); | 206 ASSERT_FALSE(audio_track_.GetId().empty()); |
206 | 207 |
| 208 // Perform a |Configure()| with no attributes. This ends up making an IPC |
| 209 // call, but the host implementation has a fast-path when there are no changes |
| 210 // to the configuration. This test is intended to hit that fast-path and make |
| 211 // sure it works correctly. |
| 212 { |
| 213 int32_t attrib_list[] = { |
| 214 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE, |
| 215 }; |
| 216 ASSERT_SUBTEST_SUCCESS(CheckConfigure(attrib_list, PP_OK)); |
| 217 } |
| 218 |
207 // Configure number of buffers. | 219 // Configure number of buffers. |
208 struct { | 220 struct { |
209 int32_t buffers; | 221 int32_t buffers; |
210 int32_t expect_result; | 222 int32_t expect_result; |
211 } buffers[] = { | 223 } buffers[] = { |
212 { 8, PP_OK }, | 224 { 8, PP_OK }, |
213 { 100, PP_OK }, | 225 { 100, PP_OK }, |
214 { kMaxNumberOfBuffers, PP_OK }, | 226 { kMaxNumberOfBuffers, PP_OK }, |
215 { -1, PP_ERROR_BADARGUMENT }, | 227 { -1, PP_ERROR_BADARGUMENT }, |
216 { kMaxNumberOfBuffers + 1, PP_OK }, // Clipped to max value. | 228 { kMaxNumberOfBuffers + 1, PP_OK }, // Clipped to max value. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 ASSERT_EQ(PP_ERROR_INPROGRESS, cc_configure.result()); | 298 ASSERT_EQ(PP_ERROR_INPROGRESS, cc_configure.result()); |
287 audio_track_.RecycleBuffer(buffer); | 299 audio_track_.RecycleBuffer(buffer); |
288 } | 300 } |
289 | 301 |
290 // Close the track. | 302 // Close the track. |
291 audio_track_.Close(); | 303 audio_track_.Close(); |
292 ASSERT_TRUE(audio_track_.HasEnded()); | 304 ASSERT_TRUE(audio_track_.HasEnded()); |
293 audio_track_ = pp::MediaStreamAudioTrack(); | 305 audio_track_ = pp::MediaStreamAudioTrack(); |
294 PASS(); | 306 PASS(); |
295 } | 307 } |
| 308 |
| 309 std::string TestMediaStreamAudioTrack::TestConfigureClose() { |
| 310 // Create a track. |
| 311 instance_->EvalScript(kJSCode); |
| 312 event_.Wait(); |
| 313 event_.Reset(); |
| 314 |
| 315 ASSERT_FALSE(audio_track_.is_null()); |
| 316 ASSERT_FALSE(audio_track_.HasEnded()); |
| 317 ASSERT_FALSE(audio_track_.GetId().empty()); |
| 318 |
| 319 // Configure the audio track and close it immediately. The Configure() call |
| 320 // should complete. |
| 321 int32_t attrib_list[] = { |
| 322 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_BUFFERS, 10, |
| 323 PP_MEDIASTREAMAUDIOTRACK_ATTRIB_NONE, |
| 324 }; |
| 325 TestCompletionCallback cc_configure(instance_->pp_instance(), false); |
| 326 int32_t result = audio_track_.Configure(attrib_list, |
| 327 cc_configure.GetCallback()); |
| 328 ASSERT_EQ(PP_OK_COMPLETIONPENDING, result); |
| 329 audio_track_.Close(); |
| 330 cc_configure.WaitForResult(result); |
| 331 result = cc_configure.result(); |
| 332 // Unfortunately, we can't control whether the configure succeeds or is |
| 333 // aborted. |
| 334 ASSERT_TRUE(result == PP_OK || result == PP_ERROR_ABORTED); |
| 335 |
| 336 PASS(); |
| 337 } |
OLD | NEW |