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

Side by Side Diff: ppapi/tests/test_media_stream_audio_track.cc

Issue 175383003: [PPAPI][MediaStream] Add browser tests for MediaStreamAudioTrack (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@browser_test
Patch Set: Update Created 6 years, 10 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 | « ppapi/tests/test_media_stream_audio_track.h ('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
(Empty)
1 // Copyright (c) 2014 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 // Tests PPB_MediaStreamAudioTrack interface.
6
7 #include "ppapi/tests/test_media_stream_audio_track.h"
8
9 #include "ppapi/c/private/ppb_testing_private.h"
10 #include "ppapi/cpp/audio_buffer.h"
11 #include "ppapi/cpp/completion_callback.h"
12 #include "ppapi/cpp/instance.h"
13 #include "ppapi/cpp/var.h"
14 #include "ppapi/tests/test_utils.h"
15 #include "ppapi/tests/testing_instance.h"
16
17 REGISTER_TEST_CASE(MediaStreamAudioTrack);
18
19 namespace {
20
21 const int32_t kTimes = 3;
22 const char kJSCode[] =
23 "function gotStream(stream) {"
24 " test_stream = stream;"
25 " var track = stream.getAudioTracks()[0];"
26 " var plugin = document.getElementById('plugin');"
27 " plugin.postMessage(track);"
28 "}"
29 "var constraints = {"
30 " audio: true,"
31 " video: false,"
32 "};"
33 "navigator.getUserMedia = "
34 " navigator.getUserMedia || navigator.webkitGetUserMedia;"
35 "navigator.getUserMedia(constraints,"
36 " gotStream, function() {});";
37 }
38
39 TestMediaStreamAudioTrack::TestMediaStreamAudioTrack(TestingInstance* instance)
40 : TestCase(instance),
41 event_(instance_->pp_instance()) {
42 }
43
44 bool TestMediaStreamAudioTrack::Init() {
45 return true;
46 }
47
48 TestMediaStreamAudioTrack::~TestMediaStreamAudioTrack() {
49 }
50
51 void TestMediaStreamAudioTrack::RunTests(const std::string& filter) {
52 RUN_TEST(Create, filter);
53 RUN_TEST(GetBuffer, filter);
54 }
55
56 void TestMediaStreamAudioTrack::HandleMessage(const pp::Var& message) {
57 if (message.is_resource()) {
58 audio_track_ = pp::MediaStreamAudioTrack(message.AsResource());
59 }
60 event_.Signal();
61 }
62
63 std::string TestMediaStreamAudioTrack::TestCreate() {
64 // Create a track.
65 instance_->EvalScript(kJSCode);
66 event_.Wait();
67 event_.Reset();
68
69 ASSERT_FALSE(audio_track_.is_null());
70 ASSERT_FALSE(audio_track_.HasEnded());
71 ASSERT_FALSE(audio_track_.GetId().empty());
72
73 // Close the track.
74 audio_track_.Close();
75 ASSERT_TRUE(audio_track_.HasEnded());
76 audio_track_ = pp::MediaStreamAudioTrack();
77 PASS();
78 }
79
80 std::string TestMediaStreamAudioTrack::TestGetBuffer() {
81 // Create a track.
82 instance_->EvalScript(kJSCode);
83 event_.Wait();
84 event_.Reset();
85
86 ASSERT_FALSE(audio_track_.is_null());
87 ASSERT_FALSE(audio_track_.HasEnded());
88 ASSERT_FALSE(audio_track_.GetId().empty());
89
90 PP_TimeDelta timestamp = 0.0;
91
92 // Get |kTimes| buffers.
93 for (int i = 0; i < kTimes; ++i) {
94 TestCompletionCallbackWithOutput<pp::AudioBuffer> cc(
95 instance_->pp_instance(), false);
96 cc.WaitForResult(audio_track_.GetBuffer(cc.GetCallback()));
97 ASSERT_EQ(PP_OK, cc.result());
98 pp::AudioBuffer buffer = cc.output();
99 ASSERT_FALSE(buffer.is_null());
100 ASSERT_EQ(buffer.GetSampleRate(), PP_AUDIOBUFFER_SAMPLERATE_44100);
101 ASSERT_EQ(buffer.GetSampleSize(), PP_AUDIOBUFFER_SAMPLESIZE_16_BITS);
102
103 ASSERT_GE(buffer.GetTimestamp(), timestamp);
104 timestamp = buffer.GetTimestamp();
105
106 ASSERT_GT(buffer.GetDataBufferSize(), 0U);
107 ASSERT_TRUE(buffer.GetDataBuffer() != NULL);
108
109 audio_track_.RecycleBuffer(buffer);
110
111 // A recycled buffer should be invalidated.
112 ASSERT_EQ(buffer.GetSampleRate(), PP_AUDIOBUFFER_SAMPLERATE_UNKNOWN);
113 ASSERT_EQ(buffer.GetSampleSize(), PP_AUDIOBUFFER_SAMPLESIZE_UNKNOWN);
114 ASSERT_EQ(buffer.GetDataBufferSize(), 0U);
115 ASSERT_TRUE(buffer.GetDataBuffer() == NULL);
116 }
117
118 // Close the track.
119 audio_track_.Close();
120 ASSERT_TRUE(audio_track_.HasEnded());
121 audio_track_ = pp::MediaStreamAudioTrack();
122 PASS();
123 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_media_stream_audio_track.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698