| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <memory> | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/files/file_util.h" | |
| 9 #include "base/json/json_reader.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "base/strings/string_split.h" | |
| 12 #include "base/strings/stringprintf.h" | |
| 13 #include "base/test/test_timeouts.h" | |
| 14 #include "base/time/time.h" | |
| 15 #include "chrome/browser/browser_process.h" | |
| 16 #include "chrome/browser/media/webrtc_browsertest_base.h" | |
| 17 #include "chrome/browser/media/webrtc_browsertest_common.h" | |
| 18 #include "chrome/browser/media/webrtc_browsertest_perf.h" | |
| 19 #include "chrome/browser/ui/browser.h" | |
| 20 #include "chrome/browser/ui/browser_tabstrip.h" | |
| 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 22 #include "chrome/common/chrome_switches.h" | |
| 23 #include "chrome/test/base/in_process_browser_test.h" | |
| 24 #include "chrome/test/base/ui_test_utils.h" | |
| 25 #include "content/public/common/content_switches.h" | |
| 26 #include "content/public/common/feature_h264_with_openh264_ffmpeg.h" | |
| 27 #include "content/public/common/features.h" | |
| 28 #include "content/public/test/browser_test_utils.h" | |
| 29 #include "media/base/media_switches.h" | |
| 30 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 31 #include "testing/perf/perf_test.h" | |
| 32 | |
| 33 static const char kMainWebrtcTestHtmlPage[] = | |
| 34 "/webrtc/webrtc_jsep01_test.html"; | |
| 35 | |
| 36 std::string MakePerfTestLabel(std::string base, bool opus_dtx) { | |
| 37 if (opus_dtx) { | |
| 38 return base + "_with_opus_dtx"; | |
| 39 } | |
| 40 return base; | |
| 41 } | |
| 42 | |
| 43 // Performance browsertest for WebRTC. This test is manual since it takes long | |
| 44 // to execute and requires the reference files provided by the webrtc.DEPS | |
| 45 // solution (which is only available on WebRTC internal bots). | |
| 46 class WebRtcPerfBrowserTest : public WebRtcTestBase { | |
| 47 public: | |
| 48 void SetUpInProcessBrowserTestFixture() override { | |
| 49 DetectErrorsInJavaScript(); // Look for errors in our rather complex js. | |
| 50 } | |
| 51 | |
| 52 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 53 // Ensure the infobar is enabled, since we expect that in this test. | |
| 54 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream)); | |
| 55 | |
| 56 // Play a suitable, somewhat realistic video file. | |
| 57 base::FilePath input_video = test::GetReferenceFilesDir() | |
| 58 .Append(test::kReferenceFileName360p) | |
| 59 .AddExtension(test::kY4mFileExtension); | |
| 60 command_line->AppendSwitchPath(switches::kUseFileForFakeVideoCapture, | |
| 61 input_video); | |
| 62 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); | |
| 63 } | |
| 64 | |
| 65 // Tries to extract data from peerConnectionDataStore in the webrtc-internals | |
| 66 // tab. The caller owns the parsed data. Returns NULL on failure. | |
| 67 base::DictionaryValue* GetWebrtcInternalsData( | |
| 68 content::WebContents* webrtc_internals_tab) { | |
| 69 std::string all_stats_json = ExecuteJavascript( | |
| 70 "window.domAutomationController.send(" | |
| 71 " JSON.stringify(peerConnectionDataStore));", | |
| 72 webrtc_internals_tab); | |
| 73 | |
| 74 std::unique_ptr<base::Value> parsed_json = | |
| 75 base::JSONReader::Read(all_stats_json); | |
| 76 base::DictionaryValue* result; | |
| 77 if (parsed_json.get() && parsed_json->GetAsDictionary(&result)) { | |
| 78 ignore_result(parsed_json.release()); | |
| 79 return result; | |
| 80 } | |
| 81 | |
| 82 return NULL; | |
| 83 } | |
| 84 | |
| 85 const base::DictionaryValue* GetDataOnPeerConnection( | |
| 86 const base::DictionaryValue* all_data, | |
| 87 int peer_connection_index) { | |
| 88 base::DictionaryValue::Iterator iterator(*all_data); | |
| 89 | |
| 90 for (int i = 0; i < peer_connection_index && !iterator.IsAtEnd(); | |
| 91 --peer_connection_index) { | |
| 92 iterator.Advance(); | |
| 93 } | |
| 94 | |
| 95 const base::DictionaryValue* result; | |
| 96 if (!iterator.IsAtEnd() && iterator.value().GetAsDictionary(&result)) | |
| 97 return result; | |
| 98 | |
| 99 return NULL; | |
| 100 } | |
| 101 | |
| 102 std::unique_ptr<base::DictionaryValue> MeasureWebRtcInternalsData( | |
| 103 int duration_msec) { | |
| 104 chrome::AddTabAt(browser(), GURL(), -1, true); | |
| 105 ui_test_utils::NavigateToURL(browser(), GURL("chrome://webrtc-internals")); | |
| 106 content::WebContents* webrtc_internals_tab = | |
| 107 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 108 | |
| 109 test::SleepInJavascript(webrtc_internals_tab, duration_msec); | |
| 110 | |
| 111 return std::unique_ptr<base::DictionaryValue>( | |
| 112 GetWebrtcInternalsData(webrtc_internals_tab)); | |
| 113 } | |
| 114 | |
| 115 void RunsAudioVideoCall60SecsAndLogsInternalMetrics( | |
| 116 const std::string& video_codec) { | |
| 117 ASSERT_TRUE(test::HasReferenceFilesInCheckout()); | |
| 118 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 119 | |
| 120 ASSERT_GE(TestTimeouts::action_max_timeout().InSeconds(), 100) | |
| 121 << "This is a long-running test; you must specify " | |
| 122 "--ui-test-action-max-timeout to have a value of at least 100000."; | |
| 123 | |
| 124 content::WebContents* left_tab = | |
| 125 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | |
| 126 content::WebContents* right_tab = | |
| 127 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | |
| 128 | |
| 129 SetupPeerconnectionWithLocalStream(left_tab); | |
| 130 SetupPeerconnectionWithLocalStream(right_tab); | |
| 131 | |
| 132 if (!video_codec.empty()) { | |
| 133 SetDefaultVideoCodec(left_tab, video_codec); | |
| 134 SetDefaultVideoCodec(right_tab, video_codec); | |
| 135 } | |
| 136 NegotiateCall(left_tab, right_tab); | |
| 137 | |
| 138 StartDetectingVideo(left_tab, "remote-view"); | |
| 139 StartDetectingVideo(right_tab, "remote-view"); | |
| 140 | |
| 141 WaitForVideoToPlay(left_tab); | |
| 142 WaitForVideoToPlay(right_tab); | |
| 143 | |
| 144 // Let values stabilize, bandwidth ramp up, etc. | |
| 145 test::SleepInJavascript(left_tab, 60000); | |
| 146 | |
| 147 // Start measurements. | |
| 148 std::unique_ptr<base::DictionaryValue> all_data = | |
| 149 MeasureWebRtcInternalsData(10000); | |
| 150 ASSERT_TRUE(all_data.get() != NULL); | |
| 151 | |
| 152 const base::DictionaryValue* first_pc_dict = | |
| 153 GetDataOnPeerConnection(all_data.get(), 0); | |
| 154 ASSERT_TRUE(first_pc_dict != NULL); | |
| 155 test::PrintBweForVideoMetrics(*first_pc_dict, "", video_codec); | |
| 156 test::PrintMetricsForAllStreams(*first_pc_dict, "", video_codec); | |
| 157 | |
| 158 HangUp(left_tab); | |
| 159 HangUp(right_tab); | |
| 160 } | |
| 161 | |
| 162 void RunsOneWayCall60SecsAndLogsInternalMetrics( | |
| 163 const std::string& video_codec, | |
| 164 bool opus_dtx) { | |
| 165 ASSERT_TRUE(test::HasReferenceFilesInCheckout()); | |
| 166 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 167 | |
| 168 ASSERT_GE(TestTimeouts::action_max_timeout().InSeconds(), 100) | |
| 169 << "This is a long-running test; you must specify " | |
| 170 "--ui-test-action-max-timeout to have a value of at least 100000."; | |
| 171 | |
| 172 content::WebContents* left_tab = | |
| 173 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | |
| 174 content::WebContents* right_tab = | |
| 175 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | |
| 176 | |
| 177 SetupPeerconnectionWithLocalStream(left_tab); | |
| 178 SetupPeerconnectionWithoutLocalStream(right_tab); | |
| 179 | |
| 180 if (!video_codec.empty()) { | |
| 181 SetDefaultVideoCodec(left_tab, video_codec); | |
| 182 SetDefaultVideoCodec(right_tab, video_codec); | |
| 183 } | |
| 184 if (opus_dtx) { | |
| 185 EnableOpusDtx(left_tab); | |
| 186 EnableOpusDtx(right_tab); | |
| 187 } | |
| 188 NegotiateCall(left_tab, right_tab); | |
| 189 | |
| 190 // Remote video will only play in one tab since the call is one-way. | |
| 191 StartDetectingVideo(right_tab, "remote-view"); | |
| 192 WaitForVideoToPlay(right_tab); | |
| 193 | |
| 194 // Let values stabilize, bandwidth ramp up, etc. | |
| 195 test::SleepInJavascript(left_tab, 60000); | |
| 196 | |
| 197 std::unique_ptr<base::DictionaryValue> all_data = | |
| 198 MeasureWebRtcInternalsData(10000); | |
| 199 ASSERT_TRUE(all_data.get() != NULL); | |
| 200 | |
| 201 // This assumes the sending peer connection is always listed first in the | |
| 202 // data store, and the receiving second. | |
| 203 const base::DictionaryValue* first_pc_dict = | |
| 204 GetDataOnPeerConnection(all_data.get(), 0); | |
| 205 ASSERT_TRUE(first_pc_dict != NULL); | |
| 206 test::PrintBweForVideoMetrics( | |
| 207 *first_pc_dict, MakePerfTestLabel("_sendonly", opus_dtx), video_codec); | |
| 208 test::PrintMetricsForSendStreams( | |
| 209 *first_pc_dict, MakePerfTestLabel("_sendonly", opus_dtx), video_codec); | |
| 210 | |
| 211 const base::DictionaryValue* second_pc_dict = | |
| 212 GetDataOnPeerConnection(all_data.get(), 1); | |
| 213 ASSERT_TRUE(second_pc_dict != NULL); | |
| 214 test::PrintBweForVideoMetrics( | |
| 215 *second_pc_dict, MakePerfTestLabel("_recvonly", opus_dtx), video_codec); | |
| 216 test::PrintMetricsForRecvStreams( | |
| 217 *second_pc_dict, MakePerfTestLabel("_recvonly", opus_dtx), video_codec); | |
| 218 | |
| 219 HangUp(left_tab); | |
| 220 HangUp(right_tab); | |
| 221 } | |
| 222 }; | |
| 223 | |
| 224 // This is manual for its long execution time. | |
| 225 | |
| 226 IN_PROC_BROWSER_TEST_F( | |
| 227 WebRtcPerfBrowserTest, | |
| 228 MANUAL_RunsAudioVideoCall60SecsAndLogsInternalMetricsVp8) { | |
| 229 RunsAudioVideoCall60SecsAndLogsInternalMetrics("VP8"); | |
| 230 } | |
| 231 | |
| 232 IN_PROC_BROWSER_TEST_F( | |
| 233 WebRtcPerfBrowserTest, | |
| 234 MANUAL_RunsAudioVideoCall60SecsAndLogsInternalMetricsVp9) { | |
| 235 RunsAudioVideoCall60SecsAndLogsInternalMetrics("VP9"); | |
| 236 } | |
| 237 | |
| 238 #if BUILDFLAG(RTC_USE_H264) | |
| 239 | |
| 240 IN_PROC_BROWSER_TEST_F( | |
| 241 WebRtcPerfBrowserTest, | |
| 242 MANUAL_RunsAudioVideoCall60SecsAndLogsInternalMetricsH264) { | |
| 243 // Only run test if run-time feature corresponding to |rtc_use_h264| is on. | |
| 244 if (!base::FeatureList::IsEnabled(content::kWebRtcH264WithOpenH264FFmpeg)) { | |
| 245 LOG(WARNING) << "Run-time feature WebRTC-H264WithOpenH264FFmpeg disabled. " | |
| 246 "Skipping WebRtcPerfBrowserTest.MANUAL_RunsAudioVideoCall60SecsAndLogs" | |
| 247 "InternalMetricsH264 (test \"OK\")"; | |
| 248 return; | |
| 249 } | |
| 250 RunsAudioVideoCall60SecsAndLogsInternalMetrics("H264"); | |
| 251 } | |
| 252 | |
| 253 #endif // BUILDFLAG(RTC_USE_H264) | |
| 254 | |
| 255 IN_PROC_BROWSER_TEST_F( | |
| 256 WebRtcPerfBrowserTest, | |
| 257 MANUAL_RunsOneWayCall60SecsAndLogsInternalMetricsDefault) { | |
| 258 RunsOneWayCall60SecsAndLogsInternalMetrics("", false); | |
| 259 } | |
| 260 | |
| 261 IN_PROC_BROWSER_TEST_F( | |
| 262 WebRtcPerfBrowserTest, | |
| 263 MANUAL_RunsOneWayCall60SecsAndLogsInternalMetricsWithOpusDtx) { | |
| 264 RunsOneWayCall60SecsAndLogsInternalMetrics("", true); | |
| 265 } | |
| OLD | NEW |