Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/utf_string_conversions.h" | |
| 11 #include "base/test/trace_event_analyzer.h" | 12 #include "base/test/trace_event_analyzer.h" |
| 12 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
| 13 #include "base/trace_event/trace_event_impl.h" | 14 #include "base/trace_event/trace_event_impl.h" |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 16 #include "content/browser/browser_main_loop.h" | 17 #include "content/browser/browser_main_loop.h" |
| 17 #include "content/browser/renderer_host/media/media_stream_manager.h" | 18 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 18 #include "content/browser/web_contents/web_contents_impl.h" | 19 #include "content/browser/web_contents/web_contents_impl.h" |
| 19 #include "content/browser/webrtc/webrtc_content_browsertest_base.h" | 20 #include "content/browser/webrtc/webrtc_content_browsertest_base.h" |
| 20 #include "content/browser/webrtc/webrtc_internals.h" | 21 #include "content/browser/webrtc/webrtc_internals.h" |
| 21 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 22 #include "content/public/test/browser_test_utils.h" | 23 #include "content/public/test/browser_test_utils.h" |
| 23 #include "content/public/test/content_browser_test_utils.h" | 24 #include "content/public/test/content_browser_test_utils.h" |
| 24 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
| 25 #include "content/shell/browser/shell.h" | 26 #include "content/shell/browser/shell.h" |
| 27 #include "media/base/media_switches.h" | |
| 26 #include "net/test/embedded_test_server/embedded_test_server.h" | 28 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 27 #include "testing/perf/perf_test.h" | 29 #include "testing/perf/perf_test.h" |
| 28 | 30 |
| 29 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
| 30 #include "base/win/windows_version.h" | 32 #include "base/win/windows_version.h" |
| 31 #endif | 33 #endif |
| 32 | 34 |
| 33 using trace_analyzer::TraceAnalyzer; | 35 using trace_analyzer::TraceAnalyzer; |
| 34 using trace_analyzer::Query; | 36 using trace_analyzer::Query; |
| 35 using trace_analyzer::TraceEventVector; | 37 using trace_analyzer::TraceEventVector; |
| 36 | 38 |
| 37 namespace { | 39 namespace { |
| 38 | 40 |
| 39 static const char kGetUserMediaAndStop[] = "getUserMediaAndStop"; | 41 static const char kGetUserMediaAndStop[] = "getUserMediaAndStop"; |
| 40 static const char kGetUserMediaAndGetStreamUp[] = "getUserMediaAndGetStreamUp"; | 42 static const char kGetUserMediaAndGetStreamUp[] = "getUserMediaAndGetStreamUp"; |
| 41 static const char kGetUserMediaAndAnalyseAndStop[] = | 43 static const char kGetUserMediaAndAnalyseAndStop[] = |
| 42 "getUserMediaAndAnalyseAndStop"; | 44 "getUserMediaAndAnalyseAndStop"; |
| 43 static const char kGetUserMediaAndExpectFailure[] = | 45 static const char kGetUserMediaAndExpectFailure[] = |
| 44 "getUserMediaAndExpectFailure"; | 46 "getUserMediaAndExpectFailure"; |
| 45 static const char kRenderSameTrackMediastreamAndStop[] = | 47 static const char kRenderSameTrackMediastreamAndStop[] = |
| 46 "renderSameTrackMediastreamAndStop"; | 48 "renderSameTrackMediastreamAndStop"; |
| 47 static const char kRenderClonedMediastreamAndStop[] = | 49 static const char kRenderClonedMediastreamAndStop[] = |
| 48 "renderClonedMediastreamAndStop"; | 50 "renderClonedMediastreamAndStop"; |
| 49 static const char kRenderClonedTrackMediastreamAndStop[] = | 51 static const char kRenderClonedTrackMediastreamAndStop[] = |
| 50 "renderClonedTrackMediastreamAndStop"; | 52 "renderClonedTrackMediastreamAndStop"; |
| 51 static const char kRenderDuplicatedMediastreamAndStop[] = | 53 static const char kRenderDuplicatedMediastreamAndStop[] = |
| 52 "renderDuplicatedMediastreamAndStop"; | 54 "renderDuplicatedMediastreamAndStop"; |
| 55 static const char kGetDepthStreamAndCallCreateImageBitmap[] = | |
| 56 "getDepthStreamAndCallCreateImageBitmap"; | |
| 53 | 57 |
| 54 // Results returned by JS. | 58 // Results returned by JS. |
| 55 static const char kOK[] = "OK"; | 59 static const char kOK[] = "OK"; |
| 56 | 60 |
| 57 std::string GenerateGetUserMediaWithMandatorySourceID( | 61 std::string GenerateGetUserMediaWithMandatorySourceID( |
| 58 const std::string& function_name, | 62 const std::string& function_name, |
| 59 const std::string& audio_source_id, | 63 const std::string& audio_source_id, |
| 60 const std::string& video_source_id) { | 64 const std::string& video_source_id) { |
| 61 const std::string audio_constraint = | 65 const std::string audio_constraint = |
| 62 "audio: {mandatory: { sourceId:\"" + audio_source_id + "\"}}, "; | 66 "audio: {mandatory: { sourceId:\"" + audio_source_id + "\"}}, "; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 88 const std::string video_constraint = | 92 const std::string video_constraint = |
| 89 "video: { mandatory: { chromeMediaSource:'screen' }}"; | 93 "video: { mandatory: { chromeMediaSource:'screen' }}"; |
| 90 return function_name + "({" + audio_constraint + video_constraint + "});"; | 94 return function_name + "({" + audio_constraint + video_constraint + "});"; |
| 91 } | 95 } |
| 92 | 96 |
| 93 bool VerifyDisableLocalEcho(bool expect_value, | 97 bool VerifyDisableLocalEcho(bool expect_value, |
| 94 const content::StreamControls& controls) { | 98 const content::StreamControls& controls) { |
| 95 return expect_value == controls.disable_local_echo; | 99 return expect_value == controls.disable_local_echo; |
| 96 } | 100 } |
| 97 | 101 |
| 102 void RemoveSwitchFromCommandLine(base::CommandLine* command_line, | |
| 103 const std::string& switch_value) { | |
| 104 base::CommandLine::StringVector argv = command_line->argv(); | |
| 105 const base::CommandLine::StringType switch_string = | |
| 106 #if defined(OS_WIN) | |
| 107 base::ASCIIToUTF16(switch_value); | |
| 108 #else | |
| 109 switch_value; | |
| 110 #endif | |
| 111 argv.erase(std::remove_if( | |
| 112 argv.begin(), argv.end(), | |
| 113 [switch_string](const base::CommandLine::StringType& value) { | |
| 114 return value.find(switch_string) != std::string::npos; | |
| 115 }), | |
| 116 argv.end()); | |
| 117 command_line->InitFromArgv(argv); | |
| 118 } | |
| 119 | |
| 98 } // namespace | 120 } // namespace |
| 99 | 121 |
| 100 namespace content { | 122 namespace content { |
| 101 | 123 |
| 102 class WebRtcGetUserMediaBrowserTest : public WebRtcContentBrowserTestBase { | 124 class WebRtcGetUserMediaBrowserTest : public WebRtcContentBrowserTestBase { |
| 103 public: | 125 public: |
| 104 WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) { | 126 WebRtcGetUserMediaBrowserTest() : trace_log_(NULL) { |
| 105 // Automatically grant device permission. | 127 // Automatically grant device permission. |
| 106 AppendUseFakeUIForMediaStreamFlag(); | 128 AppendUseFakeUIForMediaStreamFlag(); |
| 107 } | 129 } |
| 108 ~WebRtcGetUserMediaBrowserTest() override {} | 130 ~WebRtcGetUserMediaBrowserTest() override {} |
| 109 | 131 |
| 132 void SetUpCommandLine(base::CommandLine* command_line) override { | |
|
aleksandar.stojiljkovic
2016/10/30 11:08:39
avi@chromium.org,
This change came after LGTM when
| |
| 133 // Test using two video capture devices - a color and a 16-bit depth device. | |
| 134 // By default, command line argument is present with no value. We need to | |
| 135 // remove it and then add the value defining two video capture devices. | |
| 136 const std::string fake_device_switch = | |
| 137 switches::kUseFakeDeviceForMediaStream; | |
|
phoglund_chromium
2016/11/02 10:56:57
Well, your new test does appear to use getUserMedi
aleksandar.stojiljkovic
2016/11/02 13:46:44
Done.
Good idea - there are more tests coming and
| |
| 138 ASSERT_TRUE(command_line->HasSwitch(fake_device_switch) && | |
| 139 command_line->GetSwitchValueASCII(fake_device_switch).empty()); | |
| 140 RemoveSwitchFromCommandLine(command_line, fake_device_switch); | |
| 141 command_line->AppendSwitchASCII(fake_device_switch, "device-count=2"); | |
| 142 WebRtcContentBrowserTestBase::SetUpCommandLine(command_line); | |
| 143 } | |
| 144 | |
| 110 void StartTracing() { | 145 void StartTracing() { |
| 111 CHECK(trace_log_ == NULL) << "Can only can start tracing once"; | 146 CHECK(trace_log_ == NULL) << "Can only can start tracing once"; |
| 112 trace_log_ = base::trace_event::TraceLog::GetInstance(); | 147 trace_log_ = base::trace_event::TraceLog::GetInstance(); |
| 113 base::trace_event::TraceConfig trace_config( | 148 base::trace_event::TraceConfig trace_config( |
| 114 "video", base::trace_event::RECORD_UNTIL_FULL); | 149 "video", base::trace_event::RECORD_UNTIL_FULL); |
| 115 trace_log_->SetEnabled(trace_config, | 150 trace_log_->SetEnabled(trace_config, |
| 116 base::trace_event::TraceLog::RECORDING_MODE); | 151 base::trace_event::TraceLog::RECORDING_MODE); |
| 117 // Check that we are indeed recording. | 152 // Check that we are indeed recording. |
| 118 EXPECT_EQ(trace_log_->GetNumTracesRecorded(), 1); | 153 EXPECT_EQ(trace_log_->GetNumTracesRecorded(), 1); |
| 119 } | 154 } |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 | 372 |
| 338 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); | 373 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 339 NavigateToURL(shell(), url); | 374 NavigateToURL(shell(), url); |
| 340 | 375 |
| 341 ExecuteJavascriptAndWaitForOk( | 376 ExecuteJavascriptAndWaitForOk( |
| 342 base::StringPrintf("%s({video: true});", | 377 base::StringPrintf("%s({video: true});", |
| 343 kRenderDuplicatedMediastreamAndStop)); | 378 kRenderDuplicatedMediastreamAndStop)); |
| 344 } | 379 } |
| 345 | 380 |
| 346 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, | 381 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, |
| 382 GetDepthStreamAndCallCreateImageBitmap) { | |
| 383 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 384 | |
| 385 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); | |
| 386 NavigateToURL(shell(), url); | |
| 387 | |
| 388 ExecuteJavascriptAndWaitForOk(base::StringPrintf( | |
| 389 "%s({video: true});", kGetDepthStreamAndCallCreateImageBitmap)); | |
| 390 } | |
| 391 | |
| 392 IN_PROC_BROWSER_TEST_F(WebRtcGetUserMediaBrowserTest, | |
| 347 GetAudioAndVideoStreamAndStop) { | 393 GetAudioAndVideoStreamAndStop) { |
| 348 ASSERT_TRUE(embedded_test_server()->Start()); | 394 ASSERT_TRUE(embedded_test_server()->Start()); |
| 349 | 395 |
| 350 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); | 396 GURL url(embedded_test_server()->GetURL("/media/getusermedia.html")); |
| 351 NavigateToURL(shell(), url); | 397 NavigateToURL(shell(), url); |
| 352 | 398 |
| 353 ExecuteJavascriptAndWaitForOk(base::StringPrintf( | 399 ExecuteJavascriptAndWaitForOk(base::StringPrintf( |
| 354 "%s({video: true, audio: true});", kGetUserMediaAndStop)); | 400 "%s({video: true, audio: true});", kGetUserMediaAndStop)); |
| 355 } | 401 } |
| 356 | 402 |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 base::Bind(&VerifyDisableLocalEcho, true)); | 810 base::Bind(&VerifyDisableLocalEcho, true)); |
| 765 call = GenerateGetUserMediaWithDisableLocalEcho( | 811 call = GenerateGetUserMediaWithDisableLocalEcho( |
| 766 "getUserMediaAndExpectSuccess", "true"); | 812 "getUserMediaAndExpectSuccess", "true"); |
| 767 ExecuteJavascriptAndWaitForOk(call); | 813 ExecuteJavascriptAndWaitForOk(call); |
| 768 | 814 |
| 769 manager->SetGenerateStreamCallbackForTesting( | 815 manager->SetGenerateStreamCallbackForTesting( |
| 770 MediaStreamManager::GenerateStreamTestCallback()); | 816 MediaStreamManager::GenerateStreamTestCallback()); |
| 771 } | 817 } |
| 772 | 818 |
| 773 } // namespace content | 819 } // namespace content |
| OLD | NEW |