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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ppapi/tests/test_media_stream_audio_track.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/tests/test_media_stream_audio_track.cc
diff --git a/ppapi/tests/test_media_stream_audio_track.cc b/ppapi/tests/test_media_stream_audio_track.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f0734a0ff2025bb30e28d1fd27e015703b701090
--- /dev/null
+++ b/ppapi/tests/test_media_stream_audio_track.cc
@@ -0,0 +1,123 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+//
+// Tests PPB_MediaStreamAudioTrack interface.
+
+#include "ppapi/tests/test_media_stream_audio_track.h"
+
+#include "ppapi/c/private/ppb_testing_private.h"
+#include "ppapi/cpp/audio_buffer.h"
+#include "ppapi/cpp/completion_callback.h"
+#include "ppapi/cpp/instance.h"
+#include "ppapi/cpp/var.h"
+#include "ppapi/tests/test_utils.h"
+#include "ppapi/tests/testing_instance.h"
+
+REGISTER_TEST_CASE(MediaStreamAudioTrack);
+
+namespace {
+
+const int32_t kTimes = 3;
+const char kJSCode[] =
+ "function gotStream(stream) {"
+ " test_stream = stream;"
+ " var track = stream.getAudioTracks()[0];"
+ " var plugin = document.getElementById('plugin');"
+ " plugin.postMessage({track: track});"
dmichael (off chromium) 2014/02/21 19:30:57 nit: It might be clearer to use a different name f
Peng 2014/02/21 20:28:24 Done.
+ "}"
+ "var constraints = {"
+ " audio: true,"
+ " video: false,"
+ "};"
+ "navigator.webkitGetUserMedia(constraints,"
dmichael (off chromium) 2014/02/21 19:30:57 Would it be worthwhile to do something like: getUs
Peng 2014/02/21 20:28:24 getUserMedia = ... does not work, have to use navi
+ " gotStream, function() {});";
+}
+
+TestMediaStreamAudioTrack::TestMediaStreamAudioTrack(TestingInstance* instance)
+ : TestCase(instance),
+ event_(instance_->pp_instance()) {
+}
+
+bool TestMediaStreamAudioTrack::Init() {
+ return true;
+}
+
+TestMediaStreamAudioTrack::~TestMediaStreamAudioTrack() {
+}
+
+void TestMediaStreamAudioTrack::RunTests(const std::string& filter) {
+ RUN_TEST(Create, filter);
+ RUN_TEST(GetBuffer, filter);
+}
+
+void TestMediaStreamAudioTrack::HandleMessage(const pp::Var& message) {
+ if (message.is_dictionary()) {
+ pp::Var var_track = pp::VarDictionary(message).Get("track");
+ if (var_track.is_resource()) {
+ audio_track_ = pp::MediaStreamAudioTrack(var_track.AsResource());
+ }
+ }
+ event_.Signal();
+}
+
+std::string TestMediaStreamAudioTrack::TestCreate() {
+ // Create a track.
+ instance_->EvalScript(kJSCode);
+ event_.Wait();
+ event_.Reset();
+
+ ASSERT_FALSE(audio_track_.is_null());
+ ASSERT_FALSE(audio_track_.HasEnded());
+ ASSERT_FALSE(audio_track_.GetId().empty());
+
+ // Close the track.
+ audio_track_.Close();
+ ASSERT_TRUE(audio_track_.HasEnded());
+ audio_track_ = pp::MediaStreamAudioTrack();
+ PASS();
+}
+
+std::string TestMediaStreamAudioTrack::TestGetBuffer() {
+ // Create a track.
+ instance_->EvalScript(kJSCode);
+ event_.Wait();
+ event_.Reset();
+
+ ASSERT_FALSE(audio_track_.is_null());
+ ASSERT_FALSE(audio_track_.HasEnded());
+ ASSERT_FALSE(audio_track_.GetId().empty());
+
+ PP_TimeDelta timestamp = 0.0;
+
+ // Get |kTimes| buffers.
+ for (int i = 0; i < kTimes; ++i) {
+ TestCompletionCallbackWithOutput<pp::AudioBuffer> cc(
+ instance_->pp_instance(), false);
+ cc.WaitForResult(audio_track_.GetBuffer(cc.GetCallback()));
+ ASSERT_EQ(PP_OK, cc.result());
+ pp::AudioBuffer buffer = cc.output();
+ ASSERT_FALSE(buffer.is_null());
+ ASSERT_EQ(buffer.GetSampleRate(), PP_AUDIOBUFFER_SAMPLERATE_44100);
+ ASSERT_EQ(buffer.GetSampleSize(), PP_AUDIOBUFFER_SAMPLESIZE_16_BITS);
+
+ ASSERT_GE(buffer.GetTimestamp(), timestamp);
+ timestamp = buffer.GetTimestamp();
+
+ ASSERT_GT(buffer.GetDataBufferSize(), 0U);
+ ASSERT_TRUE(buffer.GetDataBuffer() != NULL);
+
+ audio_track_.RecycleBuffer(buffer);
+
+ ASSERT_EQ(buffer.GetSampleRate(), PP_AUDIOBUFFER_SAMPLERATE_UNKNOWN);
dmichael (off chromium) 2014/02/21 19:30:57 A short comment above this might help. E.g.: "A re
Peng 2014/02/21 20:28:24 Done.
+ ASSERT_EQ(buffer.GetSampleSize(), PP_AUDIOBUFFER_SAMPLESIZE_UNKNOWN);
+ ASSERT_EQ(buffer.GetDataBufferSize(), 0U);
+ ASSERT_TRUE(buffer.GetDataBuffer() == NULL);
+ }
+
+ // Close the track.
+ audio_track_.Close();
+ ASSERT_TRUE(audio_track_.HasEnded());
+ audio_track_ = pp::MediaStreamAudioTrack();
+ PASS();
+}
« 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