Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / renderer / media / webrtc_audio_capturer_unittest.cc
index 11a017c..ded95d6 100644 (file)
@@ -84,9 +84,9 @@ class WebRtcAudioCapturerTest : public testing::Test {
 #endif
   }
 
-  void EnableAudioTrackProcessing() {
+  void DisableAudioTrackProcessing() {
     CommandLine::ForCurrentProcess()->AppendSwitch(
-        switches::kEnableAudioTrackProcessing);
+        switches::kDisableAudioTrackProcessing);
   }
 
   void VerifyAudioParams(const blink::WebMediaConstraints& constraints,
@@ -96,18 +96,16 @@ class WebRtcAudioCapturerTest : public testing::Test {
                              "", "", params_.sample_rate(),
                              params_.channel_layout(),
                              params_.frames_per_buffer()),
-        constraints, NULL);
+        constraints, NULL, NULL);
     capturer_source_ = new MockCapturerSource();
     EXPECT_CALL(*capturer_source_.get(), Initialize(_, capturer_.get(), -1));
-    capturer_->SetCapturerSourceForTesting(capturer_source_, params_);
-
     EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
     EXPECT_CALL(*capturer_source_.get(), Start());
+    capturer_->SetCapturerSourceForTesting(capturer_source_, params_);
+
     scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
         WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
-    track_.reset(new WebRtcLocalAudioTrack(adapter, capturer_, NULL));
-    static_cast<WebRtcLocalAudioSourceProvider*>(
-        track_->audio_source_provider())->SetSinkParamsForTesting(params_);
+    track_.reset(new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL));
     track_->Start();
 
     // Connect a mock sink to the track.
@@ -126,13 +124,15 @@ class WebRtcAudioCapturerTest : public testing::Test {
     audio_bus->Zero();
 
     media::AudioCapturerSource::CaptureCallback* callback =
-        static_cast<media::AudioCapturerSource::CaptureCallback*>(capturer_);
+        static_cast<media::AudioCapturerSource::CaptureCallback*>(
+            capturer_.get());
 
     // Verify the sink is getting the correct values.
     EXPECT_CALL(*sink, FormatIsSet());
     EXPECT_CALL(*sink,
                 OnDataCallback(_, _, delay_ms, expected_volume_value,
-                               need_audio_processing, key_pressed));
+                               need_audio_processing, key_pressed))
+        .Times(AtLeast(1));
     callback->Capture(audio_bus.get(), delay_ms, volume, key_pressed);
 
     // Verify the cached values in the capturer fits what we expect.
@@ -158,14 +158,14 @@ class WebRtcAudioCapturerTest : public testing::Test {
 
 // Pass the delay value, volume and key_pressed info via capture callback, and
 // those values should be correctly stored and passed to the track.
-TEST_F(WebRtcAudioCapturerTest, VerifyAudioParams) {
+TEST_F(WebRtcAudioCapturerTest, VerifyAudioParamsWithoutAudioProcessing) {
+  DisableAudioTrackProcessing();
   // Use constraints with default settings.
-  blink::WebMediaConstraints constraints;
-  VerifyAudioParams(constraints, true);
+  MockMediaConstraintFactory constraint_factory;
+  VerifyAudioParams(constraint_factory.CreateWebMediaConstraints(), true);
 }
 
 TEST_F(WebRtcAudioCapturerTest, VerifyAudioParamsWithAudioProcessing) {
-  EnableAudioTrackProcessing();
   // Turn off the default constraints to verify that the sink will get packets
   // with a buffer size smaller than 10ms.
   MockMediaConstraintFactory constraint_factory;
@@ -173,4 +173,21 @@ TEST_F(WebRtcAudioCapturerTest, VerifyAudioParamsWithAudioProcessing) {
   VerifyAudioParams(constraint_factory.CreateWebMediaConstraints(), false);
 }
 
+TEST_F(WebRtcAudioCapturerTest, FailToCreateCapturerWithWrongConstraints) {
+  MockMediaConstraintFactory constraint_factory;
+  const std::string dummy_constraint = "dummy";
+  constraint_factory.AddMandatory(dummy_constraint, true);
+
+  scoped_refptr<WebRtcAudioCapturer> capturer(
+      WebRtcAudioCapturer::CreateCapturer(
+          0, StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE,
+                               "", "", params_.sample_rate(),
+                               params_.channel_layout(),
+                               params_.frames_per_buffer()),
+          constraint_factory.CreateWebMediaConstraints(), NULL, NULL)
+  );
+  EXPECT_TRUE(capturer.get() == NULL);
+}
+
+
 }  // namespace content