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

Side by Side Diff: content/browser/webrtc/webrtc_getusermedia_browsertest.cc

Issue 2808463004: Fix race in WebRtcGetUserMediaBrowserTest (Closed)
Patch Set: Created 3 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/feature_list.h" 8 #include "base/feature_list.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 return expect_value == controls.disable_local_echo; 99 return expect_value == controls.disable_local_echo;
100 } 100 }
101 101
102 } // namespace 102 } // namespace
103 103
104 namespace content { 104 namespace content {
105 105
106 class WebRtcGetUserMediaBrowserTest : public WebRtcContentBrowserTestBase { 106 class WebRtcGetUserMediaBrowserTest : public WebRtcContentBrowserTestBase {
107 public: 107 public:
108 WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) { 108 WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) {
109 scoped_feature_list_.InitAndDisableFeature(
110 features::kMediaStreamOldVideoConstraints);
109 // Automatically grant device permission. 111 // Automatically grant device permission.
110 AppendUseFakeUIForMediaStreamFlag(); 112 AppendUseFakeUIForMediaStreamFlag();
111 } 113 }
112 ~WebRtcGetUserMediaBrowserTest() override {} 114 ~WebRtcGetUserMediaBrowserTest() override {}
113 115
114 void StartTracing() { 116 void StartTracing() {
115 CHECK(trace_log_ == NULL) << "Can only can start tracing once"; 117 CHECK(trace_log_ == NULL) << "Can only can start tracing once";
116 trace_log_ = base::trace_event::TraceLog::GetInstance(); 118 trace_log_ = base::trace_event::TraceLog::GetInstance();
117 base::trace_event::TraceConfig trace_config( 119 base::trace_event::TraceConfig trace_config(
118 "video", base::trace_event::RECORD_UNTIL_FULL); 120 "video", base::trace_event::RECORD_UNTIL_FULL);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 } 262 }
261 } 263 }
262 ASSERT_FALSE(audio_ids->empty()); 264 ASSERT_FALSE(audio_ids->empty());
263 ASSERT_FALSE(video_ids->empty()); 265 ASSERT_FALSE(video_ids->empty());
264 } 266 }
265 267
266 private: 268 private:
267 base::trace_event::TraceLog* trace_log_; 269 base::trace_event::TraceLog* trace_log_;
268 scoped_refptr<base::RefCountedString> recorded_trace_data_; 270 scoped_refptr<base::RefCountedString> recorded_trace_data_;
269 scoped_refptr<MessageLoopRunner> message_loop_runner_; 271 scoped_refptr<MessageLoopRunner> message_loop_runner_;
272 base::test::ScopedFeatureList scoped_feature_list_;
270 }; 273 };
271 274
272 // These tests will all make a getUserMedia call with different constraints and 275 // These tests will all make a getUserMedia call with different constraints and
273 // see that the success callback is called. If the error callback is called or 276 // see that the success callback is called. If the error callback is called or
274 // none of the callbacks are called the tests will simply time out and fail. 277 // none of the callbacks are called the tests will simply time out and fail.
275 278
276 // Test fails under MSan, http://crbug.com/445745 279 // Test fails under MSan, http://crbug.com/445745
277 #if defined(MEMORY_SANITIZER) 280 #if defined(MEMORY_SANITIZER)
278 #define MAYBE_GetVideoStreamAndStop DISABLED_GetVideoStreamAndStop 281 #define MAYBE_GetVideoStreamAndStop DISABLED_GetVideoStreamAndStop
279 #else 282 #else
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, 493 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
491 TwoGetUserMediaWithEqualConstraints) { 494 TwoGetUserMediaWithEqualConstraints) {
492 std::string constraints1 = "{video: true, audio: true}"; 495 std::string constraints1 = "{video: true, audio: true}";
493 const std::string& constraints2 = constraints1; 496 const std::string& constraints2 = constraints1;
494 std::string expected_result = "w=640:h=480-w=640:h=480"; 497 std::string expected_result = "w=640:h=480-w=640:h=480";
495 498
496 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2, 499 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
497 expected_result); 500 expected_result);
498 } 501 }
499 502
500 // TODO(guidou): Remove this test. http://crbug.com/706408
501 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
502 TwoGetUserMediaWithSecondVideoCroppedOldConstraints) {
503 base::test::ScopedFeatureList scoped_feature_list;
504 scoped_feature_list.InitAndEnableFeature(
505 features::kMediaStreamOldVideoConstraints);
506 std::string constraints1 = "{video: true}";
507 std::string constraints2 = "{video: {mandatory: {maxHeight: 360}}}";
508 std::string expected_result = "w=640:h=480-w=640:h=360";
509 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
510 expected_result);
511 }
512
513 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, 503 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
514 TwoGetUserMediaWithSecondVideoCropped) { 504 TwoGetUserMediaWithSecondVideoCropped) {
515 base::test::ScopedFeatureList scoped_feature_list;
516 scoped_feature_list.InitAndDisableFeature(
517 features::kMediaStreamOldVideoConstraints);
518 std::string constraints1 = "{video: true}"; 505 std::string constraints1 = "{video: true}";
519 std::string constraints2 = 506 std::string constraints2 =
520 "{video: {width: {exact: 640}, height: {exact: 360}}}"; 507 "{video: {width: {exact: 640}, height: {exact: 360}}}";
521 std::string expected_result = "w=640:h=480-w=640:h=360"; 508 std::string expected_result = "w=640:h=480-w=640:h=360";
522 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2, 509 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
523 expected_result); 510 expected_result);
524 } 511 }
525 512
526 // Test fails under MSan, http://crbug.com/445745 513 // Test fails under MSan, http://crbug.com/445745
527 // TODO(guidou): Remove this test. http://crbug.com/706408
528 #if defined(MEMORY_SANITIZER)
529 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVgaOldConstraints \
530 DISABLED_TwoGetUserMediaWithFirstHdSecondVgaOldConstraints
531 #else
532 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVgaOldConstraints \
533 TwoGetUserMediaWithFirstHdSecondVgaOldConstraints
534 #endif
535 IN_PROC_BROWSER_TEST_F(
536 WebRtcGetUserMediaBrowserTest,
537 MAYBE_TwoGetUserMediaWithFirstHdSecondVgaOldConstraints) {
538 base::test::ScopedFeatureList scoped_feature_list;
539 scoped_feature_list.InitAndEnableFeature(
540 features::kMediaStreamOldVideoConstraints);
541 std::string constraints1 =
542 "{video: {mandatory: {maxWidth:1280 , minWidth:1280 , maxHeight: 720, "
543 "minHeight: 720}}}";
544 std::string constraints2 =
545 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
546 std::string expected_result = "w=1280:h=720-w=640:h=480";
547 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
548 expected_result);
549 }
550
551 // Test fails under MSan, http://crbug.com/445745
552 #if defined(MEMORY_SANITIZER) 514 #if defined(MEMORY_SANITIZER)
553 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \ 515 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
554 DISABLED_TwoGetUserMediaWithFirstHdSecondVga 516 DISABLED_TwoGetUserMediaWithFirstHdSecondVga
555 #else 517 #else
556 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \ 518 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
557 TwoGetUserMediaWithFirstHdSecondVga 519 TwoGetUserMediaWithFirstHdSecondVga
558 #endif 520 #endif
559 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, 521 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest,
560 MAYBE_TwoGetUserMediaWithFirstHdSecondVga) { 522 MAYBE_TwoGetUserMediaWithFirstHdSecondVga) {
561 base::test::ScopedFeatureList scoped_feature_list;
562 scoped_feature_list.InitAndDisableFeature(
563 features::kMediaStreamOldVideoConstraints);
564 std::string constraints1 = 523 std::string constraints1 =
565 "{video: {width : {exact: 1280}, height: {exact: 720}}}"; 524 "{video: {width : {exact: 1280}, height: {exact: 720}}}";
566 std::string constraints2 = 525 std::string constraints2 =
567 "{video: {width : {exact: 640}, height: {exact: 480}}}"; 526 "{video: {width : {exact: 640}, height: {exact: 480}}}";
568 std::string expected_result = "w=1280:h=720-w=640:h=480"; 527 std::string expected_result = "w=1280:h=720-w=640:h=480";
569 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2, 528 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
570 expected_result); 529 expected_result);
571 } 530 }
572 531
573 // Timing out on Windows 7 bot: http://crbug.com/443294 532 // Timing out on Windows 7 bot: http://crbug.com/443294
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 640, 640, 480, 480, 10, 30); 631 640, 640, 480, 480, 10, 30);
673 632
674 ASSERT_EQ("ConstraintNotSatisfiedError", 633 ASSERT_EQ("ConstraintNotSatisfiedError",
675 ExecuteJavascriptAndReturnResult(gum_with_impossible_constraints)); 634 ExecuteJavascriptAndReturnResult(gum_with_impossible_constraints));
676 635
677 ASSERT_EQ("w=640:h=480", 636 ASSERT_EQ("w=640:h=480",
678 ExecuteJavascriptAndReturnResult(gum_with_vga_constraints)); 637 ExecuteJavascriptAndReturnResult(gum_with_vga_constraints));
679 } 638 }
680 639
681 #if defined(OS_ANDROID) && defined(NDEBUG) 640 #if defined(OS_ANDROID) && defined(NDEBUG)
682 #define MAYBE_TraceVideoCaptureControllerPerformanceDuringGetUserMedia DISABLED_ TraceVideoCaptureControllerPerformanceDuringGetUserMedia 641 #define MAYBE_TraceVideoCaptureControllerPerformanceDuringGetUserMedia \
642 DISABLED_TraceVideoCaptureControllerPerformanceDuringGetUserMedia
683 #else 643 #else
684 #define MAYBE_TraceVideoCaptureControllerPerformanceDuringGetUserMedia TraceVide oCaptureControllerPerformanceDuringGetUserMedia 644 #define MAYBE_TraceVideoCaptureControllerPerformanceDuringGetUserMedia \
645 TraceVideoCaptureControllerPerformanceDuringGetUserMedia
685 #endif 646 #endif
686 647
687 // This test will make a simple getUserMedia page, verify that video is playing 648 // This test will make a simple getUserMedia page, verify that video is playing
688 // in a simple local <video>, and for a couple of seconds, collect some 649 // in a simple local <video>, and for a couple of seconds, collect some
689 // performance traces from VideoCaptureController colorspace conversion and 650 // performance traces from VideoCaptureController colorspace conversion and
690 // potential resizing. 651 // potential resizing.
691 IN_PROC_BROWSER_TEST_F( 652 IN_PROC_BROWSER_TEST_F(
692 WebRtcGetUserMediaBrowserTest, 653 WebRtcGetUserMediaBrowserTest,
693 MAYBE_TraceVideoCaptureControllerPerformanceDuringGetUserMedia) { 654 MAYBE_TraceVideoCaptureControllerPerformanceDuringGetUserMedia) {
694 RunGetUserMediaAndCollectMeasures( 655 RunGetUserMediaAndCollectMeasures(
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 manager->SetGenerateStreamCallbackForTesting( 786 manager->SetGenerateStreamCallbackForTesting(
826 base::Bind(&VerifyDisableLocalEcho, true)); 787 base::Bind(&VerifyDisableLocalEcho, true));
827 call = GenerateGetUserMediaWithDisableLocalEcho( 788 call = GenerateGetUserMediaWithDisableLocalEcho(
828 "getUserMediaAndExpectSuccess", "true"); 789 "getUserMediaAndExpectSuccess", "true");
829 ExecuteJavascriptAndWaitForOk(call); 790 ExecuteJavascriptAndWaitForOk(call);
830 791
831 manager->SetGenerateStreamCallbackForTesting( 792 manager->SetGenerateStreamCallbackForTesting(
832 MediaStreamManager::GenerateStreamTestCallback()); 793 MediaStreamManager::GenerateStreamTestCallback());
833 } 794 }
834 795
796 // TODO(guidou): Remove this test. http://crbug.com/706408
797 class WebRtcGetUserMediaOldConstraintsBrowserTest
798 : public WebRtcContentBrowserTestBase {
799 public:
800 WebRtcGetUserMediaOldConstraintsBrowserTest() : trace_log_(NULL) {
801 scoped_feature_list_.InitAndEnableFeature(
802 features::kMediaStreamOldVideoConstraints);
803 // Automatically grant device permission.
804 AppendUseFakeUIForMediaStreamFlag();
805 }
806 ~WebRtcGetUserMediaOldConstraintsBrowserTest() override {}
807
808 void StartTracing() {
809 CHECK(trace_log_ == NULL) << "Can only can start tracing once";
810 trace_log_ = base::trace_event::TraceLog::GetInstance();
811 base::trace_event::TraceConfig trace_config(
812 "video", base::trace_event::RECORD_UNTIL_FULL);
813 trace_log_->SetEnabled(trace_config,
814 base::trace_event::TraceLog::RECORDING_MODE);
815 // Check that we are indeed recording.
816 EXPECT_EQ(trace_log_->GetNumTracesRecorded(), 1);
817 }
818
819 void StopTracing() {
820 CHECK(message_loop_runner_.get() == NULL)
821 << "Calling StopTracing more than once";
822
823 {
824 base::ThreadRestrictions::ScopedAllowIO allow_thread_join_caused_by_test;
825 trace_log_->SetDisabled();
826 }
827
828 message_loop_runner_ = new MessageLoopRunner;
829 trace_log_->Flush(base::Bind(
830 &WebRtcGetUserMediaOldConstraintsBrowserTest::OnTraceDataCollected,
831 base::Unretained(this)));
832 message_loop_runner_->Run();
833 }
834
835 void OnTraceDataCollected(
836 const scoped_refptr<base::RefCountedString>& events_str_ptr,
837 bool has_more_events) {
838 CHECK(!has_more_events);
839 recorded_trace_data_ = events_str_ptr;
840 message_loop_runner_->Quit();
841 }
842
843 TraceAnalyzer* CreateTraceAnalyzer() {
844 return TraceAnalyzer::Create("[" + recorded_trace_data_->data() + "]");
845 }
846
847 void RunGetUserMediaAndCollectMeasures(const int time_to_sample_secs,
848 const std::string& measure_filter,
849 const std::string& graph_name) {
850 ASSERT_TRUE(embedded_test_server()->Start());
851
852 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
853 NavigateToURL(shell(), url);
854
855 // Put getUserMedia to work and let it run for a couple of seconds.
856 DCHECK(time_to_sample_secs);
857 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
858 "%s({video: true}, 'myStreamName');", kGetUserMediaAndGetStreamUp));
859
860 // Now the stream is up and running, start collecting traces.
861 StartTracing();
862
863 ExecuteJavascriptAndWaitForOk(
864 base::StringPrintf("waitAndStopVideoTrack(window['myStreamName'], %d);",
865 time_to_sample_secs));
866
867 // Wait until the page title changes to "OK". Do not sleep() here since that
868 // would stop both this code and the browser underneath.
869 StopTracing();
870
871 std::unique_ptr<TraceAnalyzer> analyzer(CreateTraceAnalyzer());
872 analyzer->AssociateBeginEndEvents();
873 trace_analyzer::TraceEventVector events;
874 DCHECK(measure_filter.size());
875 analyzer->FindEvents(Query::EventNameIs(measure_filter), &events);
876 ASSERT_GT(events.size(), 0u)
877 << "Could not collect any samples during test, this is bad";
878
879 std::string duration_us;
880 std::string interarrival_us;
881 for (size_t i = 0; i != events.size(); ++i) {
882 duration_us.append(
883 base::StringPrintf("%d,", static_cast<int>(events[i]->duration)));
884 }
885
886 for (size_t i = 1; i < events.size(); ++i) {
887 // The event |timestamp| comes in ns, divide to get us like |duration|.
888 interarrival_us.append(base::StringPrintf(
889 "%d,",
890 static_cast<int>((events[i]->timestamp - events[i - 1]->timestamp) /
891 base::Time::kNanosecondsPerMicrosecond)));
892 }
893
894 perf_test::PrintResultList(graph_name, "", "sample_duration", duration_us,
895 "us", true);
896
897 perf_test::PrintResultList(graph_name, "", "interarrival_time",
898 interarrival_us, "us", true);
899 }
900
901 // Runs the JavaScript twoGetUserMedia with |constraints1| and |constraint2|.
902 void RunTwoGetTwoGetUserMediaWithDifferentContraints(
903 const std::string& constraints1,
904 const std::string& constraints2,
905 const std::string& expected_result) {
906 ASSERT_TRUE(embedded_test_server()->Start());
907
908 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
909 NavigateToURL(shell(), url);
910
911 std::string command =
912 "twoGetUserMedia(" + constraints1 + ',' + constraints2 + ')';
913
914 EXPECT_EQ(expected_result, ExecuteJavascriptAndReturnResult(command));
915 }
916
917 void GetInputDevices(std::vector<std::string>* audio_ids,
918 std::vector<std::string>* video_ids) {
919 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
920 NavigateToURL(shell(), url);
921
922 std::string devices_as_json =
923 ExecuteJavascriptAndReturnResult("getSources()");
924 EXPECT_FALSE(devices_as_json.empty());
925
926 int error_code;
927 std::string error_message;
928 std::unique_ptr<base::Value> value = base::JSONReader::ReadAndReturnError(
929 devices_as_json, base::JSON_ALLOW_TRAILING_COMMAS, &error_code,
930 &error_message);
931
932 ASSERT_TRUE(value.get() != NULL) << error_message;
933 EXPECT_EQ(value->GetType(), base::Value::Type::LIST);
934
935 base::ListValue* values;
936 ASSERT_TRUE(value->GetAsList(&values));
937
938 for (base::ListValue::iterator it = values->begin(); it != values->end();
939 ++it) {
940 const base::DictionaryValue* dict;
941 std::string kind;
942 std::string device_id;
943 ASSERT_TRUE((*it)->GetAsDictionary(&dict));
944 ASSERT_TRUE(dict->GetString("kind", &kind));
945 ASSERT_TRUE(dict->GetString("id", &device_id));
946 ASSERT_FALSE(device_id.empty());
947 EXPECT_TRUE(kind == "audio" || kind == "video");
948 if (kind == "audio") {
949 audio_ids->push_back(device_id);
950 } else if (kind == "video") {
951 video_ids->push_back(device_id);
952 }
953 }
954 ASSERT_FALSE(audio_ids->empty());
955 ASSERT_FALSE(video_ids->empty());
956 }
957
958 private:
959 base::trace_event::TraceLog* trace_log_;
960 scoped_refptr<base::RefCountedString> recorded_trace_data_;
961 scoped_refptr<MessageLoopRunner> message_loop_runner_;
962 base::test::ScopedFeatureList scoped_feature_list_;
963 };
964
965 // These tests will all make a getUserMedia call with different constraints and
966 // see that the success callback is called. If the error callback is called or
967 // none of the callbacks are called the tests will simply time out and fail.
968
969 // Test fails under MSan, http://crbug.com/445745
970 #if defined(MEMORY_SANITIZER)
971 #define MAYBE_GetVideoStreamAndStop DISABLED_GetVideoStreamAndStop
972 #else
973 #define MAYBE_GetVideoStreamAndStop GetVideoStreamAndStop
974 #endif
975 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
976 MAYBE_GetVideoStreamAndStop) {
977 ASSERT_TRUE(embedded_test_server()->Start());
978
979 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
980 NavigateToURL(shell(), url);
981
982 ExecuteJavascriptAndWaitForOk(
983 base::StringPrintf("%s({video: true});", kGetUserMediaAndStop));
984 }
985
986 // Test fails under MSan, http://crbug.com/445745
987 #if defined(MEMORY_SANITIZER)
988 #define MAYBE_RenderSameTrackMediastreamAndStop \
989 DISABLED_RenderSameTrackMediastreamAndStop
990 #else
991 #define MAYBE_RenderSameTrackMediastreamAndStop \
992 RenderSameTrackMediastreamAndStop
993 #endif
994 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
995 MAYBE_RenderSameTrackMediastreamAndStop) {
996 ASSERT_TRUE(embedded_test_server()->Start());
997
998 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
999 NavigateToURL(shell(), url);
1000
1001 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
1002 "%s({video: true});", kRenderSameTrackMediastreamAndStop));
1003 }
1004
1005 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1006 RenderClonedMediastreamAndStop) {
1007 ASSERT_TRUE(embedded_test_server()->Start());
1008
1009 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1010 NavigateToURL(shell(), url);
1011
1012 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
1013 "%s({video: true});", kRenderClonedMediastreamAndStop));
1014 }
1015
1016 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1017 kRenderClonedTrackMediastreamAndStop) {
1018 ASSERT_TRUE(embedded_test_server()->Start());
1019
1020 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1021 NavigateToURL(shell(), url);
1022
1023 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
1024 "%s({video: true});", kRenderClonedTrackMediastreamAndStop));
1025 }
1026
1027 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1028 kRenderDuplicatedMediastreamAndStop) {
1029 ASSERT_TRUE(embedded_test_server()->Start());
1030
1031 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1032 NavigateToURL(shell(), url);
1033
1034 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
1035 "%s({video: true});", kRenderDuplicatedMediastreamAndStop));
1036 }
1037
1038 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1039 GetAudioAndVideoStreamAndStop) {
1040 ASSERT_TRUE(embedded_test_server()->Start());
1041
1042 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1043 NavigateToURL(shell(), url);
1044
1045 ExecuteJavascriptAndWaitForOk(base::StringPrintf(
1046 "%s({video: true, audio: true});", kGetUserMediaAndStop));
1047 }
1048
1049 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1050 GetAudioAndVideoStreamAndClone) {
1051 ASSERT_TRUE(embedded_test_server()->Start());
1052
1053 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1054 NavigateToURL(shell(), url);
1055
1056 ExecuteJavascriptAndWaitForOk("getUserMediaAndClone();");
1057 }
1058
1059 // Test fails under Android, http://crbug.com/524388
1060 // Test fails under MSan
1061 // Flaky everywhere else: http://crbug.com/523152
1062 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1063 RenderVideoTrackInMultipleTagsAndPause) {
1064 ASSERT_TRUE(embedded_test_server()->Start());
1065
1066 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1067 NavigateToURL(shell(), url);
1068
1069 ExecuteJavascriptAndWaitForOk("getUserMediaAndRenderInSeveralVideoTags();");
1070 }
1071
1072 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1073 GetUserMediaWithMandatorySourceID) {
1074 ASSERT_TRUE(embedded_test_server()->Start());
1075
1076 std::vector<std::string> audio_ids;
1077 std::vector<std::string> video_ids;
1078 GetInputDevices(&audio_ids, &video_ids);
1079
1080 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1081 NavigateToURL(shell(), url);
1082
1083 // Test all combinations of mandatory sourceID;
1084 for (std::vector<std::string>::const_iterator video_it = video_ids.begin();
1085 video_it != video_ids.end(); ++video_it) {
1086 for (std::vector<std::string>::const_iterator audio_it = audio_ids.begin();
1087 audio_it != audio_ids.end(); ++audio_it) {
1088 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
1089 GenerateGetUserMediaWithMandatorySourceID(
1090 kGetUserMediaAndStop, *audio_it, *video_it)));
1091 }
1092 }
1093 }
1094
1095 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1096 GetUserMediaWithInvalidMandatorySourceID) {
1097 ASSERT_TRUE(embedded_test_server()->Start());
1098
1099 std::vector<std::string> audio_ids;
1100 std::vector<std::string> video_ids;
1101 GetInputDevices(&audio_ids, &video_ids);
1102
1103 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1104
1105 // Test with invalid mandatory audio sourceID.
1106 // TODO(guidou): Update error string when spec-compliant constraint resolution
1107 // for audio is implemented. See http://crbug.com/657733.
1108 NavigateToURL(shell(), url);
1109 EXPECT_EQ("DevicesNotFoundError",
1110 ExecuteJavascriptAndReturnResult(
1111 GenerateGetUserMediaWithMandatorySourceID(
1112 kGetUserMediaAndExpectFailure, "something invalid",
1113 video_ids[0])));
1114
1115 // Test with invalid mandatory video sourceID.
1116 EXPECT_EQ("ConstraintNotSatisfiedError",
1117 ExecuteJavascriptAndReturnResult(
1118 GenerateGetUserMediaWithMandatorySourceID(
1119 kGetUserMediaAndExpectFailure, audio_ids[0],
1120 "something invalid")));
1121
1122 // Test with empty mandatory audio sourceID.
1123 // TODO(guidou): Update error string when spec-compliant constraint resolution
1124 // for audio is implemented. See http://crbug.com/657733.
1125 EXPECT_EQ("DevicesNotFoundError",
1126 ExecuteJavascriptAndReturnResult(
1127 GenerateGetUserMediaWithMandatorySourceID(
1128 kGetUserMediaAndExpectFailure, "", video_ids[0])));
1129 }
1130
1131 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1132 GetUserMediaWithInvalidOptionalSourceID) {
1133 ASSERT_TRUE(embedded_test_server()->Start());
1134
1135 std::vector<std::string> audio_ids;
1136 std::vector<std::string> video_ids;
1137 GetInputDevices(&audio_ids, &video_ids);
1138
1139 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1140
1141 // Test with invalid optional audio sourceID.
1142 NavigateToURL(shell(), url);
1143 EXPECT_EQ(
1144 kOK,
1145 ExecuteJavascriptAndReturnResult(GenerateGetUserMediaWithOptionalSourceID(
1146 kGetUserMediaAndStop, "something invalid", video_ids[0])));
1147
1148 // Test with invalid optional video sourceID.
1149 EXPECT_EQ(
1150 kOK,
1151 ExecuteJavascriptAndReturnResult(GenerateGetUserMediaWithOptionalSourceID(
1152 kGetUserMediaAndStop, audio_ids[0], "something invalid")));
1153
1154 // Test with empty optional audio sourceID.
1155 EXPECT_EQ(kOK, ExecuteJavascriptAndReturnResult(
1156 GenerateGetUserMediaWithOptionalSourceID(
1157 kGetUserMediaAndStop, "", video_ids[0])));
1158 }
1159
1160 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1161 TwoGetUserMediaAndStop) {
1162 ASSERT_TRUE(embedded_test_server()->Start());
1163
1164 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1165 NavigateToURL(shell(), url);
1166
1167 ExecuteJavascriptAndWaitForOk(
1168 "twoGetUserMediaAndStop({video: true, audio: true});");
1169 }
1170
1171 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1172 TwoGetUserMediaWithEqualConstraints) {
1173 std::string constraints1 = "{video: true, audio: true}";
1174 const std::string& constraints2 = constraints1;
1175 std::string expected_result = "w=640:h=480-w=640:h=480";
1176
1177 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
1178 expected_result);
1179 }
1180
1181 // TODO(guidou): Remove this test. http://crbug.com/706408
1182 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1183 TwoGetUserMediaWithSecondVideoCropped) {
1184 std::string constraints1 = "{video: true}";
1185 std::string constraints2 = "{video: {mandatory: {maxHeight: 360}}}";
1186 std::string expected_result = "w=640:h=480-w=640:h=360";
1187 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
1188 expected_result);
1189 }
1190
1191 // Test fails under MSan, http://crbug.com/445745
1192 // TODO(guidou): Remove this test. http://crbug.com/706408
1193 #if defined(MEMORY_SANITIZER)
1194 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
1195 DISABLED_TwoGetUserMediaWithFirstHdSecondVga
1196 #else
1197 #define MAYBE_TwoGetUserMediaWithFirstHdSecondVga \
1198 TwoGetUserMediaWithFirstHdSecondVga
1199 #endif
1200 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1201 MAYBE_TwoGetUserMediaWithFirstHdSecondVga) {
1202 std::string constraints1 =
1203 "{video: {mandatory: {maxWidth:1280 , minWidth:1280 , maxHeight: 720, "
1204 "minHeight: 720}}}";
1205 std::string constraints2 =
1206 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
1207 std::string expected_result = "w=1280:h=720-w=640:h=480";
1208 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
1209 expected_result);
1210 }
1211
1212 // Timing out on Windows 7 bot: http://crbug.com/443294
1213 // Flaky: http://crbug.com/660656; possible the test is too perf sensitive.
1214 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1215 DISABLED_TwoGetUserMediaWithFirst1080pSecondVga) {
1216 std::string constraints1 =
1217 "{video: {mandatory: {maxWidth:1920 , minWidth:1920 , maxHeight: 1080, "
1218 "minHeight: 1080}}}";
1219 std::string constraints2 =
1220 "{video: {mandatory: {maxWidth:640 , maxHeight: 480}}}";
1221 std::string expected_result = "w=1920:h=1080-w=640:h=480";
1222 RunTwoGetTwoGetUserMediaWithDifferentContraints(constraints1, constraints2,
1223 expected_result);
1224 }
1225
1226 // Test fails under MSan, http://crbug.com/445745
1227 #if defined(MEMORY_SANITIZER)
1228 #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
1229 DISABLED_TwoGetUserMediaAndVerifyFrameRate
1230 #else
1231 #define MAYBE_TwoGetUserMediaAndVerifyFrameRate \
1232 TwoGetUserMediaAndVerifyFrameRate
1233 #endif
1234 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1235 MAYBE_TwoGetUserMediaAndVerifyFrameRate) {
1236 ASSERT_TRUE(embedded_test_server()->Start());
1237
1238 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1239 NavigateToURL(shell(), url);
1240
1241 std::string constraints1 =
1242 "{video: {mandatory: {minWidth:640 , minHeight: 480, "
1243 "minFrameRate : 15, maxFrameRate : 15}}}";
1244 std::string constraints2 =
1245 "{video: {mandatory: {maxWidth:320 , maxHeight: 240,"
1246 "minFrameRate : 7, maxFrameRate : 7}}}";
1247
1248 std::string command = "twoGetUserMediaAndVerifyFrameRate(" + constraints1 +
1249 ',' + constraints2 + ", 15, 7)";
1250 ExecuteJavascriptAndWaitForOk(command);
1251 }
1252
1253 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1254 GetUserMediaWithTooHighVideoConstraintsValues) {
1255 ASSERT_TRUE(embedded_test_server()->Start());
1256
1257 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1258
1259 int large_value = 99999;
1260 std::string call = GenerateGetUserMediaCall(
1261 kGetUserMediaAndExpectFailure, large_value, large_value, large_value,
1262 large_value, large_value, large_value);
1263 NavigateToURL(shell(), url);
1264
1265 EXPECT_EQ("ConstraintNotSatisfiedError",
1266 ExecuteJavascriptAndReturnResult(call));
1267 }
1268
1269 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1270 GetUserMediaFailToAccessAudioDevice) {
1271 ASSERT_TRUE(embedded_test_server()->Start());
1272
1273 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1274 NavigateToURL(shell(), url);
1275
1276 // Set the maximum allowed input and output streams to 0
1277 // so that the call to create a new audio input stream will fail.
1278 media::AudioManager::Get()->SetMaxStreamCountForTesting(0, 0);
1279
1280 const std::string call = base::StringPrintf(
1281 "%s({video: false, audio: true});", kGetUserMediaAndExpectFailure);
1282 EXPECT_EQ("TrackStartError", ExecuteJavascriptAndReturnResult(call));
1283 }
1284
1285 // This test makes two getUserMedia requests, one with impossible constraints
1286 // that should trigger an error, and one with valid constraints. The test
1287 // verifies getUserMedia can succeed after being given impossible constraints.
1288 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1289 TwoGetUserMediaAndCheckCallbackAfterFailure) {
1290 ASSERT_TRUE(embedded_test_server()->Start());
1291
1292 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1293 NavigateToURL(shell(), url);
1294
1295 int large_value = 99999;
1296 const std::string gum_with_impossible_constraints = GenerateGetUserMediaCall(
1297 kGetUserMediaAndExpectFailure, large_value, large_value, large_value,
1298 large_value, large_value, large_value);
1299 const std::string gum_with_vga_constraints = GenerateGetUserMediaCall(
1300 kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 10, 30);
1301
1302 ASSERT_EQ("ConstraintNotSatisfiedError",
1303 ExecuteJavascriptAndReturnResult(gum_with_impossible_constraints));
1304
1305 ASSERT_EQ("w=640:h=480",
1306 ExecuteJavascriptAndReturnResult(gum_with_vga_constraints));
1307 }
1308
1309 #if defined(OS_ANDROID) && defined(NDEBUG)
1310 #define MAYBE_TraceVideoCaptureControllerPerformanceDuringGetUserMedia \
1311 DISABLED_TraceVideoCaptureControllerPerformanceDuringGetUserMedia
1312 #else
1313 #define MAYBE_TraceVideoCaptureControllerPerformanceDuringGetUserMedia \
1314 TraceVideoCaptureControllerPerformanceDuringGetUserMedia
1315 #endif
1316
1317 // This test will make a simple getUserMedia page, verify that video is playing
1318 // in a simple local <video>, and for a couple of seconds, collect some
1319 // performance traces from VideoCaptureController colorspace conversion and
1320 // potential resizing.
1321 IN_PROC_BROWSER_TEST_F(
1322 WebRtcGetUserMediaOldConstraintsBrowserTest,
1323 MAYBE_TraceVideoCaptureControllerPerformanceDuringGetUserMedia) {
1324 RunGetUserMediaAndCollectMeasures(
1325 10, "VideoCaptureDeviceClient::OnIncomingCapturedData",
1326 "VideoCaptureDeviceClient");
1327 }
1328
1329 // This test calls getUserMedia and checks for aspect ratio behavior.
1330 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1331 TestGetUserMediaAspectRatio4To3) {
1332 ASSERT_TRUE(embedded_test_server()->Start());
1333
1334 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1335
1336 std::string constraints_4_3 = GenerateGetUserMediaCall(
1337 kGetUserMediaAndAnalyseAndStop, 640, 640, 480, 480, 10, 30);
1338
1339 NavigateToURL(shell(), url);
1340 ASSERT_EQ("w=640:h=480", ExecuteJavascriptAndReturnResult(constraints_4_3));
1341 }
1342
1343 // This test calls getUserMedia and checks for aspect ratio behavior.
1344 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1345 TestGetUserMediaAspectRatio16To9) {
1346 ASSERT_TRUE(embedded_test_server()->Start());
1347
1348 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1349
1350 std::string constraints_16_9 = GenerateGetUserMediaCall(
1351 kGetUserMediaAndAnalyseAndStop, 640, 640, 360, 360, 10, 30);
1352
1353 NavigateToURL(shell(), url);
1354 ASSERT_EQ("w=640:h=360", ExecuteJavascriptAndReturnResult(constraints_16_9));
1355 }
1356
1357 // This test calls getUserMedia and checks for aspect ratio behavior.
1358 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1359 TestGetUserMediaAspectRatio1To1) {
1360 ASSERT_TRUE(embedded_test_server()->Start());
1361
1362 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1363
1364 std::string constraints_1_1 = GenerateGetUserMediaCall(
1365 kGetUserMediaAndAnalyseAndStop, 320, 320, 320, 320, 10, 30);
1366
1367 NavigateToURL(shell(), url);
1368 ASSERT_EQ("w=320:h=320", ExecuteJavascriptAndReturnResult(constraints_1_1));
1369 }
1370
1371 // This test calls getUserMedia in an iframe and immediately close the iframe
1372 // in the scope of the success callback.
1373 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1374 AudioInIFrameAndCloseInSuccessCb) {
1375 ASSERT_TRUE(embedded_test_server()->Start());
1376
1377 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1378 NavigateToURL(shell(), url);
1379
1380 std::string call = "getUserMediaInIframeAndCloseInSuccessCb({audio: true});";
1381 ExecuteJavascriptAndWaitForOk(call);
1382 }
1383
1384 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1385 VideoInIFrameAndCloseInSuccessCb) {
1386 ASSERT_TRUE(embedded_test_server()->Start());
1387
1388 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1389 NavigateToURL(shell(), url);
1390
1391 std::string call = "getUserMediaInIframeAndCloseInSuccessCb({video: true});";
1392 ExecuteJavascriptAndWaitForOk(call);
1393 }
1394
1395 // This test calls getUserMedia in an iframe and immediately close the iframe
1396 // in the scope of the failure callback.
1397 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1398 VideoWithBadConstraintsInIFrameAndCloseInFailureCb) {
1399 ASSERT_TRUE(embedded_test_server()->Start());
1400
1401 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1402
1403 int large_value = 99999;
1404 std::string call = GenerateGetUserMediaCall(
1405 "getUserMediaInIframeAndCloseInFailureCb", large_value, large_value,
1406 large_value, large_value, large_value, large_value);
1407 NavigateToURL(shell(), url);
1408
1409 ExecuteJavascriptAndWaitForOk(call);
1410 }
1411
1412 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1413 InvalidSourceIdInIFrameAndCloseInFailureCb) {
1414 ASSERT_TRUE(embedded_test_server()->Start());
1415
1416 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1417
1418 std::string call = GenerateGetUserMediaWithMandatorySourceID(
1419 "getUserMediaInIframeAndCloseInFailureCb", "invalid", "invalid");
1420 NavigateToURL(shell(), url);
1421
1422 ExecuteJavascriptAndWaitForOk(call);
1423 }
1424
1425 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaOldConstraintsBrowserTest,
1426 DisableLocalEchoParameter) {
1427 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1428 switches::kEnableExperimentalWebPlatformFeatures);
1429 ASSERT_TRUE(embedded_test_server()->Start());
1430
1431 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html"));
1432 NavigateToURL(shell(), url);
1433
1434 MediaStreamManager* manager =
1435 BrowserMainLoop::GetInstance()->media_stream_manager();
1436
1437 manager->SetGenerateStreamCallbackForTesting(
1438 base::Bind(&VerifyDisableLocalEcho, false));
1439 std::string call = GenerateGetUserMediaWithDisableLocalEcho(
1440 "getUserMediaAndExpectSuccess", "false");
1441 ExecuteJavascriptAndWaitForOk(call);
1442
1443 manager->SetGenerateStreamCallbackForTesting(
1444 base::Bind(&VerifyDisableLocalEcho, true));
1445 call = GenerateGetUserMediaWithDisableLocalEcho(
1446 "getUserMediaAndExpectSuccess", "true");
1447 ExecuteJavascriptAndWaitForOk(call);
1448
1449 manager->SetGenerateStreamCallbackForTesting(
1450 MediaStreamManager::GenerateStreamTestCallback());
1451 }
1452
835 } // namespace content 1453 } // 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