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

Unified Diff: content/renderer/media/webrtc_audio_device_unittest.cc

Issue 8427031: First unit tests for WebRTCAudioDevice. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 | « content/content_tests.gypi ('k') | content/test/webrtc_audio_device_test.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/webrtc_audio_device_unittest.cc
===================================================================
--- content/renderer/media/webrtc_audio_device_unittest.cc (revision 0)
+++ content/renderer/media/webrtc_audio_device_unittest.cc (working copy)
@@ -0,0 +1,120 @@
+// Copyright (c) 2011 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.
+
+#include "base/environment.h"
+#include "base/test/test_timeouts.h"
+#include "content/renderer/media/webrtc_audio_device_impl.h"
+#include "content/test/webrtc_audio_device_test.h"
+#include "media/audio/audio_util.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "third_party/webrtc/voice_engine/main/interface/voe_audio_processing.h"
+#include "third_party/webrtc/voice_engine/main/interface/voe_base.h"
+#include "third_party/webrtc/voice_engine/main/interface/voe_file.h"
+#include "third_party/webrtc/voice_engine/main/interface/voe_network.h"
+
+using testing::_;
+using testing::InvokeWithoutArgs;
+using testing::Return;
+using testing::StrEq;
+
+namespace {
+
+ACTION_P(QuitMessageLoop, loop_or_proxy) {
+ loop_or_proxy->PostTask(FROM_HERE, new MessageLoop::QuitTask());
+}
+
+class AudioUtil : public AudioUtilInterface {
+ public:
+ virtual double GetAudioHardwareSampleRate() OVERRIDE {
+ return media::GetAudioHardwareSampleRate();
+ }
+ virtual double GetAudioInputHardwareSampleRate() OVERRIDE {
+ return media::GetAudioInputHardwareSampleRate();
+ }
+};
+
+bool IsRunningHeadless() {
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ if (env->HasVar("CHROME_HEADLESS"))
+ return true;
+ return false;
+}
+
+} // end namespace
+
+// Basic test that instantiates and initializes an instance of
+// WebRtcAudioDeviceImpl.
+// TODO(tommi): Re-enable when the flakiness of CpuWindows in webrtc has
+// been fixed.
+TEST_F(WebRTCAudioDeviceTest, DISABLED_Construct) {
+ AudioUtil audio_util;
+ set_audio_util_callback(&audio_util);
+ scoped_refptr<WebRtcAudioDeviceImpl> audio_device(
+ new WebRtcAudioDeviceImpl());
+ audio_device->SetSessionId(1);
+
+ WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
+ ASSERT_TRUE(engine.valid());
+
+ ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
+ int err = base->Init(audio_device);
+ EXPECT_EQ(0, err);
+ EXPECT_EQ(0, base->Terminate());
+}
+
+// Uses WebRtcAudioDeviceImpl to play a local wave file.
+// Disabled when running headless since the bots don't have the required config.
+// TODO(tommi): Re-enable when the flakiness of CpuWindows in webrtc has
+// been fixed.
+TEST_F(WebRTCAudioDeviceTest, DISABLED_PlayLocalFile) {
+ if (IsRunningHeadless())
+ return;
+
+ std::string file_path(
+ GetTestDataPath(FILE_PATH_LITERAL("speechmusic_mono_16kHz.pcm")));
+
+ AudioUtil audio_util;
+ set_audio_util_callback(&audio_util);
+
+ EXPECT_CALL(media_observer(),
+ OnSetAudioStreamStatus(_, 1, StrEq("created"))).Times(1);
+ EXPECT_CALL(media_observer(),
+ OnSetAudioStreamPlaying(_, 1, true)).Times(1);
+ EXPECT_CALL(media_observer(),
+ OnSetAudioStreamStatus(_, 1, StrEq("closed"))).Times(1);
+ EXPECT_CALL(media_observer(),
+ OnDeleteAudioStream(_, 1)).Times(1);
+
+ scoped_refptr<WebRtcAudioDeviceImpl> audio_device(
+ new WebRtcAudioDeviceImpl());
+ audio_device->SetSessionId(1);
+
+ WebRTCAutoDelete<webrtc::VoiceEngine> engine(webrtc::VoiceEngine::Create());
+ ASSERT_TRUE(engine.valid());
+
+ ScopedWebRTCPtr<webrtc::VoEBase> base(engine.get());
+ ASSERT_TRUE(base.valid());
+ int err = base->Init(audio_device);
+ ASSERT_EQ(0, err);
+
+ int ch = base->CreateChannel();
+ EXPECT_NE(-1, ch);
+ EXPECT_EQ(0, base->StartPlayout(ch));
+
+ ScopedWebRTCPtr<webrtc::VoEFile> file(engine.get());
+ int duration = 0;
+ EXPECT_EQ(0, file->GetFileDuration(file_path.c_str(), duration,
+ webrtc::kFileFormatPcm16kHzFile));
+ EXPECT_NE(0, duration);
+
+ EXPECT_EQ(0, file->StartPlayingFileLocally(ch, file_path.c_str(), false,
+ webrtc::kFileFormatPcm16kHzFile));
+
+ message_loop_.PostDelayedTask(FROM_HERE,
+ new MessageLoop::QuitTask(),
+ TestTimeouts::action_timeout_ms());
+ message_loop_.Run();
+
+ EXPECT_EQ(0, base->Terminate());
+}
Property changes on: content/renderer/media/webrtc_audio_device_unittest.cc
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+LF
« no previous file with comments | « content/content_tests.gypi ('k') | content/test/webrtc_audio_device_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698