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

Side by Side Diff: content/renderer/media/media_stream_constraints_util_audio_unittest.cc

Issue 2958543002: Update MediaStreamConstraintsAudioUtil unit tests. (Closed)
Patch Set: Created 3 years, 6 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 | « no previous file | 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #include "content/renderer/media/media_stream_constraints_util_audio.h" 5 #include "content/renderer/media/media_stream_constraints_util_audio.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*> 335 blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*>
336 kMainBoolConstraints = { 336 kMainBoolConstraints = {
337 &blink::WebMediaTrackConstraintSet::hotword_enabled, 337 &blink::WebMediaTrackConstraintSet::hotword_enabled,
338 &blink::WebMediaTrackConstraintSet::disable_local_echo, 338 &blink::WebMediaTrackConstraintSet::disable_local_echo,
339 &blink::WebMediaTrackConstraintSet::render_to_associated_sink}; 339 &blink::WebMediaTrackConstraintSet::render_to_associated_sink};
340 340
341 ASSERT_EQ(kMainSettings.size(), kMainBoolConstraints.size()); 341 ASSERT_EQ(kMainSettings.size(), kMainBoolConstraints.size());
342 for (auto set_function : kBoolSetFunctions) { 342 for (auto set_function : kBoolSetFunctions) {
343 for (auto accessor : kFactoryAccessors) { 343 for (auto accessor : kFactoryAccessors) {
344 // Ideal advanced is ignored by the SelectSettings algorithm. 344 // Ideal advanced is ignored by the SelectSettings algorithm.
345 if (set_function == &blink::BooleanConstraint::SetIdeal && 345 // Using array elements instead of pointer values due to the comparison
346 accessor == &MockConstraintFactory::AddAdvanced) { 346 // failing on some build configurations.
347 if (set_function == kBoolSetFunctions[1] &&
348 accessor == kFactoryAccessors[1]) {
347 continue; 349 continue;
348 } 350 }
349 for (size_t i = 0; i < kMainSettings.size(); ++i) { 351 for (size_t i = 0; i < kMainSettings.size(); ++i) {
350 for (bool value : kBoolValues) { 352 for (bool value : kBoolValues) {
351 ResetFactory(); 353 ResetFactory();
352 (((constraint_factory_.*accessor)().*kMainBoolConstraints[i]).* 354 (((constraint_factory_.*accessor)().*kMainBoolConstraints[i]).*
353 set_function)(value); 355 set_function)(value);
354 auto result = SelectSettings(); 356 auto result = SelectSettings();
355 EXPECT_TRUE(result.HasValue()); 357 EXPECT_TRUE(result.HasValue());
356 EXPECT_EQ(value, (result.*kMainSettings[i])()); 358 EXPECT_EQ(value, (result.*kMainSettings[i])());
(...skipping 30 matching lines...) Expand all
387 &blink::WebMediaTrackConstraintSet::goog_highpass_filter, 389 &blink::WebMediaTrackConstraintSet::goog_highpass_filter,
388 &blink::WebMediaTrackConstraintSet:: 390 &blink::WebMediaTrackConstraintSet::
389 goog_experimental_auto_gain_control, 391 goog_experimental_auto_gain_control,
390 }; 392 };
391 393
392 ASSERT_EQ(kAudioProcessingProperties.size(), 394 ASSERT_EQ(kAudioProcessingProperties.size(),
393 kAudioProcessingConstraints.size()); 395 kAudioProcessingConstraints.size());
394 for (auto set_function : kBoolSetFunctions) { 396 for (auto set_function : kBoolSetFunctions) {
395 for (auto accessor : kFactoryAccessors) { 397 for (auto accessor : kFactoryAccessors) {
396 // Ideal advanced is ignored by the SelectSettings algorithm. 398 // Ideal advanced is ignored by the SelectSettings algorithm.
397 if (set_function == &blink::BooleanConstraint::SetIdeal && 399 // Using array elements instead of pointer values due to the comparison
398 accessor == &MockConstraintFactory::AddAdvanced) { 400 // failing on some build configurations.
401 if (set_function == kBoolSetFunctions[1] &&
402 accessor == kFactoryAccessors[1]) {
399 continue; 403 continue;
400 } 404 }
401 for (size_t i = 0; i < kAudioProcessingProperties.size(); ++i) { 405 for (size_t i = 0; i < kAudioProcessingProperties.size(); ++i) {
402 for (bool value : kBoolValues) { 406 for (bool value : kBoolValues) {
403 ResetFactory(); 407 ResetFactory();
404 (((constraint_factory_.*accessor)().*kAudioProcessingConstraints[i]).* 408 (((constraint_factory_.*accessor)().*kAudioProcessingConstraints[i]).*
405 set_function)(value); 409 set_function)(value);
406 auto result = SelectSettings(); 410 auto result = SelectSettings();
407 EXPECT_TRUE(result.HasValue()); 411 EXPECT_TRUE(result.HasValue());
408 EXPECT_EQ(value, result.audio_processing_properties().* 412 EXPECT_EQ(value, result.audio_processing_properties().*
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 } 482 }
479 } 483 }
480 } 484 }
481 485
482 // Tests the echoCancellation constraint with a device without hardware echo 486 // Tests the echoCancellation constraint with a device without hardware echo
483 // cancellation. 487 // cancellation.
484 TEST_P(MediaStreamConstraintsUtilAudioTest, EchoCancellationWithSw) { 488 TEST_P(MediaStreamConstraintsUtilAudioTest, EchoCancellationWithSw) {
485 for (auto set_function : kBoolSetFunctions) { 489 for (auto set_function : kBoolSetFunctions) {
486 for (auto accessor : kFactoryAccessors) { 490 for (auto accessor : kFactoryAccessors) {
487 // Ideal advanced is ignored by the SelectSettings algorithm. 491 // Ideal advanced is ignored by the SelectSettings algorithm.
488 if (set_function == &blink::BooleanConstraint::SetIdeal && 492 // Using array elements instead of pointer values due to the comparison
489 accessor == &MockConstraintFactory::AddAdvanced) { 493 // failing on some build configurations.
494 if (set_function == kBoolSetFunctions[1] &&
495 accessor == kFactoryAccessors[1]) {
490 continue; 496 continue;
491 } 497 }
492 for (bool value : kBoolValues) { 498 for (bool value : kBoolValues) {
493 ResetFactory(); 499 ResetFactory();
494 ((constraint_factory_.*accessor)().echo_cancellation.* 500 ((constraint_factory_.*accessor)().echo_cancellation.*
495 set_function)(value); 501 set_function)(value);
496 auto result = SelectSettings(); 502 auto result = SelectSettings();
497 EXPECT_TRUE(result.HasValue()); 503 EXPECT_TRUE(result.HasValue());
498 const AudioProcessingProperties& properties = 504 const AudioProcessingProperties& properties =
499 result.audio_processing_properties(); 505 result.audio_processing_properties();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 // cancellation. 546 // cancellation.
541 TEST_P(MediaStreamConstraintsUtilAudioTest, EchoCancellationWithHw) { 547 TEST_P(MediaStreamConstraintsUtilAudioTest, EchoCancellationWithHw) {
542 // With content capture, there is no hardware echo cancellation, so 548 // With content capture, there is no hardware echo cancellation, so
543 // nothing to test. 549 // nothing to test.
544 if (!IsDeviceCapture()) 550 if (!IsDeviceCapture())
545 return; 551 return;
546 552
547 for (auto set_function : kBoolSetFunctions) { 553 for (auto set_function : kBoolSetFunctions) {
548 for (auto accessor : kFactoryAccessors) { 554 for (auto accessor : kFactoryAccessors) {
549 // Ideal advanced is ignored by the SelectSettings algorithm. 555 // Ideal advanced is ignored by the SelectSettings algorithm.
550 if (set_function == &blink::BooleanConstraint::SetIdeal && 556 // Using array elements instead of pointer values due to the comparison
551 accessor == &MockConstraintFactory::AddAdvanced) { 557 // failing on some build configurations.
558 if (set_function == kBoolSetFunctions[1] &&
559 accessor == kFactoryAccessors[1]) {
552 continue; 560 continue;
553 } 561 }
554 for (bool value : kBoolValues) { 562 for (bool value : kBoolValues) {
555 ResetFactory(); 563 ResetFactory();
556 constraint_factory_.basic().device_id.SetExact( 564 constraint_factory_.basic().device_id.SetExact(
557 blink::WebString::FromASCII(hw_echo_canceller_device_->device_id)); 565 blink::WebString::FromASCII(hw_echo_canceller_device_->device_id));
558 ((constraint_factory_.*accessor)().echo_cancellation.* 566 ((constraint_factory_.*accessor)().echo_cancellation.*
559 set_function)(value); 567 set_function)(value);
560 auto result = SelectSettings(); 568 auto result = SelectSettings();
561 EXPECT_TRUE(result.HasValue()); 569 EXPECT_TRUE(result.HasValue());
(...skipping 25 matching lines...) Expand all
587 } 595 }
588 } 596 }
589 } 597 }
590 598
591 // Tests the googEchoCancellation constraint with a device without hardware echo 599 // Tests the googEchoCancellation constraint with a device without hardware echo
592 // cancellation. 600 // cancellation.
593 TEST_P(MediaStreamConstraintsUtilAudioTest, GoogEchoCancellationWithSw) { 601 TEST_P(MediaStreamConstraintsUtilAudioTest, GoogEchoCancellationWithSw) {
594 for (auto set_function : kBoolSetFunctions) { 602 for (auto set_function : kBoolSetFunctions) {
595 for (auto accessor : kFactoryAccessors) { 603 for (auto accessor : kFactoryAccessors) {
596 // Ideal advanced is ignored by the SelectSettings algorithm. 604 // Ideal advanced is ignored by the SelectSettings algorithm.
597 if (set_function == &blink::BooleanConstraint::SetIdeal && 605 // Using array elements instead of pointers due to the comparison failing
598 accessor == &MockConstraintFactory::AddAdvanced) { 606 // on compilers.
607 if (set_function == kBoolSetFunctions[1] &&
608 accessor == kFactoryAccessors[1]) {
599 continue; 609 continue;
600 } 610 }
601 for (bool value : kBoolValues) { 611 for (bool value : kBoolValues) {
602 ResetFactory(); 612 ResetFactory();
603 ((constraint_factory_.*accessor)().goog_echo_cancellation.* 613 ((constraint_factory_.*accessor)().goog_echo_cancellation.*
604 set_function)(value); 614 set_function)(value);
605 auto result = SelectSettings(); 615 auto result = SelectSettings();
606 EXPECT_TRUE(result.HasValue()); 616 EXPECT_TRUE(result.HasValue());
607 const AudioProcessingProperties& properties = 617 const AudioProcessingProperties& properties =
608 result.audio_processing_properties(); 618 result.audio_processing_properties();
(...skipping 23 matching lines...) Expand all
632 // cancellation. 642 // cancellation.
633 TEST_P(MediaStreamConstraintsUtilAudioTest, GoogEchoCancellationWithHw) { 643 TEST_P(MediaStreamConstraintsUtilAudioTest, GoogEchoCancellationWithHw) {
634 // With content capture, there is no hardware echo cancellation, so 644 // With content capture, there is no hardware echo cancellation, so
635 // nothing to test. 645 // nothing to test.
636 if (!IsDeviceCapture()) 646 if (!IsDeviceCapture())
637 return; 647 return;
638 648
639 for (auto set_function : kBoolSetFunctions) { 649 for (auto set_function : kBoolSetFunctions) {
640 for (auto accessor : kFactoryAccessors) { 650 for (auto accessor : kFactoryAccessors) {
641 // Ideal advanced is ignored by the SelectSettings algorithm. 651 // Ideal advanced is ignored by the SelectSettings algorithm.
642 if (set_function == &blink::BooleanConstraint::SetIdeal && 652 // Using array elements instead of pointer values due to the comparison
643 accessor == &MockConstraintFactory::AddAdvanced) { 653 // failing on some build configurations.
654 if (set_function == kBoolSetFunctions[1] &&
655 accessor == kFactoryAccessors[1]) {
644 continue; 656 continue;
645 } 657 }
646 for (bool value : kBoolValues) { 658 for (bool value : kBoolValues) {
647 ResetFactory(); 659 ResetFactory();
648 constraint_factory_.basic().device_id.SetExact( 660 constraint_factory_.basic().device_id.SetExact(
649 blink::WebString::FromASCII(hw_echo_canceller_device_->device_id)); 661 blink::WebString::FromASCII(hw_echo_canceller_device_->device_id));
650 ((constraint_factory_.*accessor)().goog_echo_cancellation.* 662 ((constraint_factory_.*accessor)().goog_echo_cancellation.*
651 set_function)(value); 663 set_function)(value);
652 auto result = SelectSettings(); 664 auto result = SelectSettings();
653 EXPECT_TRUE(result.HasValue()); 665 EXPECT_TRUE(result.HasValue());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 &blink::WebMediaTrackConstraintSet::goog_highpass_filter, 726 &blink::WebMediaTrackConstraintSet::goog_highpass_filter,
715 &blink::WebMediaTrackConstraintSet:: 727 &blink::WebMediaTrackConstraintSet::
716 goog_experimental_auto_gain_control, 728 goog_experimental_auto_gain_control,
717 }; 729 };
718 730
719 ASSERT_EQ(kAudioProcessingProperties.size(), 731 ASSERT_EQ(kAudioProcessingProperties.size(),
720 kAudioProcessingConstraints.size()); 732 kAudioProcessingConstraints.size());
721 for (auto set_function : kBoolSetFunctions) { 733 for (auto set_function : kBoolSetFunctions) {
722 for (auto accessor : kFactoryAccessors) { 734 for (auto accessor : kFactoryAccessors) {
723 // Ideal advanced is ignored by the SelectSettings algorithm. 735 // Ideal advanced is ignored by the SelectSettings algorithm.
724 if (set_function == &blink::BooleanConstraint::SetIdeal && 736 // Using array elements instead of pointer values due to the comparison
725 accessor == &MockConstraintFactory::AddAdvanced) { 737 // failing on some build configurations.
738 if (set_function == kBoolSetFunctions[1] &&
739 accessor == kFactoryAccessors[1]) {
726 continue; 740 continue;
727 } 741 }
728 for (size_t i = 0; i < kAudioProcessingProperties.size(); ++i) { 742 for (size_t i = 0; i < kAudioProcessingProperties.size(); ++i) {
729 ResetFactory(); 743 ResetFactory();
730 ((constraint_factory_.*accessor)().echo_cancellation.* 744 ((constraint_factory_.*accessor)().echo_cancellation.*
731 set_function)(false); 745 set_function)(false);
732 (((constraint_factory_.*accessor)().*kAudioProcessingConstraints[i]).* 746 (((constraint_factory_.*accessor)().*kAudioProcessingConstraints[i]).*
733 set_function)(true); 747 set_function)(true);
734 auto result = SelectSettings(); 748 auto result = SelectSettings();
735 EXPECT_TRUE(result.HasValue()); 749 EXPECT_TRUE(result.HasValue());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 825
812 // Test that a valid geometry is interpreted correctly in all the ways it can 826 // Test that a valid geometry is interpreted correctly in all the ways it can
813 // be set. 827 // be set.
814 TEST_P(MediaStreamConstraintsUtilAudioTest, ValidGeometry) { 828 TEST_P(MediaStreamConstraintsUtilAudioTest, ValidGeometry) {
815 const blink::WebString kGeometry = 829 const blink::WebString kGeometry =
816 blink::WebString::FromASCII("-0.02 0 0 0.02 0 1.01"); 830 blink::WebString::FromASCII("-0.02 0 0 0.02 0 1.01");
817 831
818 for (auto set_function : kStringSetFunctions) { 832 for (auto set_function : kStringSetFunctions) {
819 for (auto accessor : kFactoryAccessors) { 833 for (auto accessor : kFactoryAccessors) {
820 // Ideal advanced is ignored by the SelectSettings algorithm. 834 // Ideal advanced is ignored by the SelectSettings algorithm.
821 // Using kStringSetFunctions[1] instead of 835 // Using array elements instead of pointer values due to the comparison
822 // static_cast<StringSetFunction>(&blink::StringConstraint::SetIdeal) 836 // failing on some build configurations.
823 // because the equality comparison provides the wrong result in the
824 // Windows Debug build, making the test fail.
825 if (set_function == kStringSetFunctions[1] && 837 if (set_function == kStringSetFunctions[1] &&
826 accessor == &MockConstraintFactory::AddAdvanced) { 838 accessor == kFactoryAccessors[1]) {
827 continue; 839 continue;
828 } 840 }
829 ResetFactory(); 841 ResetFactory();
830 ((constraint_factory_.*accessor)().goog_array_geometry.* 842 ((constraint_factory_.*accessor)().goog_array_geometry.*
831 set_function)(kGeometry); 843 set_function)(kGeometry);
832 auto result = SelectSettings(); 844 auto result = SelectSettings();
833 EXPECT_TRUE(result.HasValue()); 845 EXPECT_TRUE(result.HasValue());
834 CheckDeviceDefaults(result); 846 CheckDeviceDefaults(result);
835 CheckBoolDefaults(AudioSettingsBoolMembers(), 847 CheckBoolDefaults(AudioSettingsBoolMembers(),
836 AudioPropertiesBoolMembers(), result); 848 AudioPropertiesBoolMembers(), result);
837 const std::vector<media::Point>& geometry = 849 const std::vector<media::Point>& geometry =
838 result.audio_processing_properties().goog_array_geometry; 850 result.audio_processing_properties().goog_array_geometry;
839 EXPECT_EQ(2u, geometry.size()); 851 EXPECT_EQ(2u, geometry.size());
840 EXPECT_EQ(media::Point(-0.02, 0, 0), geometry[0]); 852 EXPECT_EQ(media::Point(-0.02, 0, 0), geometry[0]);
841 EXPECT_EQ(media::Point(0.02, 0, 1.01), geometry[1]); 853 EXPECT_EQ(media::Point(0.02, 0, 1.01), geometry[1]);
842 } 854 }
843 } 855 }
844 } 856 }
845 857
846 // Test that an invalid geometry is interpreted as empty in all the ways it can 858 // Test that an invalid geometry is interpreted as empty in all the ways it can
847 // be set. 859 // be set.
848 TEST_P(MediaStreamConstraintsUtilAudioTest, InvalidGeometry) { 860 TEST_P(MediaStreamConstraintsUtilAudioTest, InvalidGeometry) {
849 const blink::WebString kGeometry = 861 const blink::WebString kGeometry =
850 blink::WebString::FromASCII("1 1 1 invalid"); 862 blink::WebString::FromASCII("1 1 1 invalid");
851 863
852 for (auto set_function : kStringSetFunctions) { 864 for (auto set_function : kStringSetFunctions) {
853 for (auto accessor : kFactoryAccessors) { 865 for (auto accessor : kFactoryAccessors) {
854 // Ideal advanced is ignored by the SelectSettings algorithm. 866 // Ideal advanced is ignored by the SelectSettings algorithm.
855 if (set_function == static_cast<StringSetFunction>( 867 // Using array elements instead of pointer values due to the comparison
856 &blink::StringConstraint::SetIdeal) && 868 // failing on some build configurations.
857 accessor == &MockConstraintFactory::AddAdvanced) { 869 if (set_function == kStringSetFunctions[1] &&
870 accessor == kFactoryAccessors[1]) {
858 continue; 871 continue;
859 } 872 }
860 ResetFactory(); 873 ResetFactory();
861 ((constraint_factory_.*accessor)().goog_array_geometry.* 874 ((constraint_factory_.*accessor)().goog_array_geometry.*
862 set_function)(kGeometry); 875 set_function)(kGeometry);
863 auto result = SelectSettings(); 876 auto result = SelectSettings();
864 EXPECT_TRUE(result.HasValue()); 877 EXPECT_TRUE(result.HasValue());
865 CheckDeviceDefaults(result); 878 CheckDeviceDefaults(result);
866 CheckBoolDefaults(AudioSettingsBoolMembers(), 879 CheckBoolDefaults(AudioSettingsBoolMembers(),
867 AudioPropertiesBoolMembers(), result); 880 AudioPropertiesBoolMembers(), result);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 } 966 }
954 967
955 INSTANTIATE_TEST_CASE_P(, 968 INSTANTIATE_TEST_CASE_P(,
956 MediaStreamConstraintsUtilAudioTest, 969 MediaStreamConstraintsUtilAudioTest,
957 testing::Values("", 970 testing::Values("",
958 kMediaStreamSourceTab, 971 kMediaStreamSourceTab,
959 kMediaStreamSourceSystem, 972 kMediaStreamSourceSystem,
960 kMediaStreamSourceDesktop)); 973 kMediaStreamSourceDesktop));
961 974
962 } // namespace content 975 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698