| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_util.h" | |
| 7 #include "base/json/json_reader.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/path_service.h" | |
| 10 #include "base/process/launch.h" | |
| 11 #include "base/process/process_metrics.h" | |
| 12 #include "base/strings/string_split.h" | |
| 13 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 14 #include "base/synchronization/waitable_event.h" | |
| 15 #include "base/test/test_timeouts.h" | |
| 16 #include "base/time/time.h" | |
| 17 #include "chrome/browser/browser_process.h" | |
| 18 #include "chrome/browser/media/webrtc_browsertest_base.h" | 7 #include "chrome/browser/media/webrtc_browsertest_base.h" |
| 19 #include "chrome/browser/media/webrtc_browsertest_common.h" | 8 #include "chrome/browser/media/webrtc_browsertest_common.h" |
| 20 #include "chrome/browser/media/webrtc_browsertest_perf.h" | |
| 21 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_tabstrip.h" | 10 #include "chrome/browser/ui/browser_tabstrip.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 24 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
| 26 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 27 #include "content/public/browser/notification_service.h" | |
| 28 #include "content/public/browser/render_process_host.h" | |
| 29 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
| 30 #include "media/base/media_switches.h" | 16 #include "media/base/media_switches.h" |
| 31 #include "net/test/embedded_test_server/embedded_test_server.h" | 17 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 32 #include "testing/perf/perf_test.h" | |
| 33 | |
| 34 // For fine-grained suppression. | |
| 35 #if defined(OS_WIN) | |
| 36 #include "base/win/windows_version.h" | |
| 37 #endif | |
| 38 | 18 |
| 39 static const char kMainWebrtcTestHtmlPage[] = | 19 static const char kMainWebrtcTestHtmlPage[] = |
| 40 "/webrtc/webrtc_jsep01_test.html"; | 20 "/webrtc/webrtc_jsep01_test.html"; |
| 41 | 21 |
| 42 // Top-level integration test for WebRTC. The test methods here must run | 22 // Top-level integration test for WebRTC. It always uses fake devices; see |
| 43 // sequentially since they use a server binary on the system (hence they are | 23 // WebRtcWebcamBrowserTest for a test that acquires any real webcam on the |
| 44 // tagged as MANUAL). In addition, they need the reference videos which require | 24 // system. |
| 45 // the webrtc.DEPS solution, which is not generally available on Chromium bots. | |
| 46 class WebRtcBrowserTest : public WebRtcTestBase, | 25 class WebRtcBrowserTest : public WebRtcTestBase, |
| 47 public testing::WithParamInterface<bool> { | 26 public testing::WithParamInterface<bool> { |
| 48 public: | 27 public: |
| 49 WebRtcBrowserTest() {} | |
| 50 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 28 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 51 DetectErrorsInJavaScript(); // Look for errors in our rather complex js. | 29 DetectErrorsInJavaScript(); // Look for errors in our rather complex js. |
| 52 } | 30 } |
| 53 | 31 |
| 54 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 32 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 55 // Ensure the infobar is enabled, since we expect that in this test. | 33 // Ensure the infobar is enabled, since we expect that in this test. |
| 56 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream)); | 34 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream)); |
| 57 | 35 |
| 58 // Play a suitable, somewhat realistic video file. | 36 // Always use fake devices. |
| 59 base::FilePath input_video = test::GetReferenceFilesDir() | |
| 60 .Append(test::kReferenceFileName360p) | |
| 61 .AddExtension(test::kY4mFileExtension); | |
| 62 command_line->AppendSwitchPath(switches::kUseFileForFakeVideoCapture, | |
| 63 input_video); | |
| 64 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); | 37 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); |
| 65 | 38 |
| 66 // Flag used by TestWebAudioMediaStream to force garbage collection. | 39 // Flag used by TestWebAudioMediaStream to force garbage collection. |
| 67 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); | 40 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); |
| 68 | |
| 69 bool enable_audio_track_processing = GetParam(); | |
| 70 if (enable_audio_track_processing) | |
| 71 command_line->AppendSwitch(switches::kEnableAudioTrackProcessing); | |
| 72 } | |
| 73 | |
| 74 void PrintProcessMetrics(base::ProcessMetrics* process_metrics, | |
| 75 const std::string& suffix) { | |
| 76 perf_test::PrintResult("cpu", "", "cpu" + suffix, | |
| 77 process_metrics->GetCPUUsage(), | |
| 78 "%", true); | |
| 79 perf_test::PrintResult("memory", "", "ws_peak" + suffix, | |
| 80 process_metrics->GetPeakWorkingSetSize(), | |
| 81 "bytes", true); | |
| 82 perf_test::PrintResult("memory", "", "ws_final" + suffix, | |
| 83 process_metrics->GetWorkingSetSize(), | |
| 84 "bytes", false); | |
| 85 | |
| 86 size_t private_mem; | |
| 87 size_t shared_mem; | |
| 88 if (process_metrics->GetMemoryBytes(&private_mem, &shared_mem)) { | |
| 89 perf_test::PrintResult("memory", "", "private_mem_final" + suffix, | |
| 90 private_mem, "bytes", false); | |
| 91 perf_test::PrintResult("memory", "", "shared_mem_final" + suffix, | |
| 92 shared_mem, "bytes", false); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 // Tries to extract data from peerConnectionDataStore in the webrtc-internals | |
| 97 // tab. The caller owns the parsed data. Returns NULL on failure. | |
| 98 base::DictionaryValue* GetWebrtcInternalsData( | |
| 99 content::WebContents* webrtc_internals_tab) { | |
| 100 std::string all_stats_json = ExecuteJavascript( | |
| 101 "window.domAutomationController.send(" | |
| 102 " JSON.stringify(peerConnectionDataStore));", | |
| 103 webrtc_internals_tab); | |
| 104 | |
| 105 base::Value* parsed_json = base::JSONReader::Read(all_stats_json); | |
| 106 base::DictionaryValue* result; | |
| 107 if (parsed_json && parsed_json->GetAsDictionary(&result)) | |
| 108 return result; | |
| 109 | |
| 110 return NULL; | |
| 111 } | |
| 112 | |
| 113 const base::DictionaryValue* GetDataOnFirstPeerConnection( | |
| 114 const base::DictionaryValue* all_data) { | |
| 115 base::DictionaryValue::Iterator iterator(*all_data); | |
| 116 | |
| 117 const base::DictionaryValue* result; | |
| 118 if (!iterator.IsAtEnd() && iterator.value().GetAsDictionary(&result)) | |
| 119 return result; | |
| 120 | |
| 121 return NULL; | |
| 122 } | |
| 123 | |
| 124 bool OnWinXp() { | |
| 125 #if defined(OS_WIN) | |
| 126 return base::win::GetVersion() <= base::win::VERSION_XP; | |
| 127 #else | |
| 128 return false; | |
| 129 #endif | |
| 130 } | 41 } |
| 131 }; | 42 }; |
| 132 | 43 |
| 133 static const bool kRunTestsWithFlag[] = { false, true }; | 44 static const bool kRunTestsWithFlag[] = { false, true }; |
| 134 INSTANTIATE_TEST_CASE_P(WebRtcBrowserTests, | 45 INSTANTIATE_TEST_CASE_P(WebRtcBrowserTests, |
| 135 WebRtcBrowserTest, | 46 WebRtcBrowserTest, |
| 136 testing::ValuesIn(kRunTestsWithFlag)); | 47 testing::ValuesIn(kRunTestsWithFlag)); |
| 137 | 48 |
| 138 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, | 49 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, |
| 139 MANUAL_RunsAudioVideoWebRTCCallInTwoTabs) { | 50 RunsAudioVideoWebRTCCallInTwoTabs) { |
| 140 if (OnWinXp()) return; | 51 if (OnWinXp()) return; |
| 141 | 52 |
| 142 ASSERT_TRUE(test::HasReferenceFilesInCheckout()); | 53 ASSERT_TRUE(test::HasReferenceFilesInCheckout()); |
| 143 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 54 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 144 | 55 |
| 145 content::WebContents* left_tab = | 56 content::WebContents* left_tab = |
| 146 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | 57 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); |
| 147 content::WebContents* right_tab = | 58 content::WebContents* right_tab = |
| 148 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | 59 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); |
| 149 | 60 |
| 150 SetupPeerconnectionWithLocalStream(left_tab); | 61 SetupPeerconnectionWithLocalStream(left_tab); |
| 151 SetupPeerconnectionWithLocalStream(right_tab); | 62 SetupPeerconnectionWithLocalStream(right_tab); |
| 152 | 63 |
| 153 NegotiateCall(left_tab, right_tab); | 64 NegotiateCall(left_tab, right_tab); |
| 154 | 65 |
| 155 StartDetectingVideo(left_tab, "remote-view"); | 66 StartDetectingVideo(left_tab, "remote-view"); |
| 156 StartDetectingVideo(right_tab, "remote-view"); | 67 StartDetectingVideo(right_tab, "remote-view"); |
| 157 | 68 |
| 158 WaitForVideoToPlay(left_tab); | 69 WaitForVideoToPlay(left_tab); |
| 159 WaitForVideoToPlay(right_tab); | 70 WaitForVideoToPlay(right_tab); |
| 160 | 71 |
| 161 HangUp(left_tab); | 72 HangUp(left_tab); |
| 73 HangUp(right_tab); |
| 162 } | 74 } |
| 163 | 75 |
| 164 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, MANUAL_CpuUsage15Seconds) { | 76 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, TestWebAudioMediaStream) { |
| 77 // This tests against crash regressions for the WebAudio-MediaStream |
| 78 // integration. |
| 165 if (OnWinXp()) return; | 79 if (OnWinXp()) return; |
| 166 | 80 |
| 167 ASSERT_TRUE(test::HasReferenceFilesInCheckout()); | 81 ASSERT_TRUE(test::HasReferenceFilesInCheckout()); |
| 168 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 169 | |
| 170 base::FilePath results_file; | |
| 171 ASSERT_TRUE(base::CreateTemporaryFile(&results_file)); | |
| 172 | |
| 173 content::WebContents* left_tab = | |
| 174 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | |
| 175 | |
| 176 #if defined(OS_MACOSX) | |
| 177 // Don't measure renderer CPU on mac: requires a mach broker we don't have | |
| 178 // access to from the browser test. | |
| 179 scoped_ptr<base::ProcessMetrics> browser_process_metrics( | |
| 180 base::ProcessMetrics::CreateProcessMetrics( | |
| 181 base::Process::Current().handle(), NULL)); | |
| 182 browser_process_metrics->GetCPUUsage(); | |
| 183 #else | |
| 184 // Measure rendering CPU on platforms that support it. | |
| 185 base::ProcessHandle renderer_pid = | |
| 186 left_tab->GetRenderProcessHost()->GetHandle(); | |
| 187 scoped_ptr<base::ProcessMetrics> renderer_process_metrics( | |
| 188 base::ProcessMetrics::CreateProcessMetrics(renderer_pid)); | |
| 189 renderer_process_metrics->GetCPUUsage(); | |
| 190 | |
| 191 scoped_ptr<base::ProcessMetrics> browser_process_metrics( | |
| 192 base::ProcessMetrics::CreateProcessMetrics( | |
| 193 base::Process::Current().handle())); | |
| 194 browser_process_metrics->GetCPUUsage(); | |
| 195 #endif | |
| 196 | |
| 197 content::WebContents* right_tab = | |
| 198 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | |
| 199 | |
| 200 SetupPeerconnectionWithLocalStream(left_tab); | |
| 201 SetupPeerconnectionWithLocalStream(right_tab); | |
| 202 | |
| 203 NegotiateCall(left_tab, right_tab); | |
| 204 | |
| 205 test::SleepInJavascript(left_tab, 15000); | |
| 206 | |
| 207 HangUp(left_tab); | |
| 208 | |
| 209 #if !defined(OS_MACOSX) | |
| 210 PrintProcessMetrics(renderer_process_metrics.get(), "_r"); | |
| 211 #endif | |
| 212 PrintProcessMetrics(browser_process_metrics.get(), "_b"); | |
| 213 } | |
| 214 | |
| 215 // This is manual for its long execution time. | |
| 216 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, | |
| 217 MANUAL_RunsAudioVideoCall60SecsAndLogsInternalMetrics) { | |
| 218 if (OnWinXp()) return; | |
| 219 | |
| 220 ASSERT_TRUE(test::HasReferenceFilesInCheckout()); | |
| 221 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 222 | |
| 223 ASSERT_GE(TestTimeouts::action_max_timeout().InSeconds(), 100) << | |
| 224 "This is a long-running test; you must specify " | |
| 225 "--ui-test-action-max-timeout to have a value of at least 100000."; | |
| 226 | |
| 227 content::WebContents* left_tab = | |
| 228 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | |
| 229 content::WebContents* right_tab = | |
| 230 OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | |
| 231 | |
| 232 SetupPeerconnectionWithLocalStream(left_tab); | |
| 233 SetupPeerconnectionWithLocalStream(right_tab); | |
| 234 | |
| 235 NegotiateCall(left_tab, right_tab); | |
| 236 | |
| 237 StartDetectingVideo(left_tab, "remote-view"); | |
| 238 StartDetectingVideo(right_tab, "remote-view"); | |
| 239 | |
| 240 WaitForVideoToPlay(left_tab); | |
| 241 WaitForVideoToPlay(right_tab); | |
| 242 | |
| 243 // Let values stabilize, bandwidth ramp up, etc. | |
| 244 test::SleepInJavascript(left_tab, 60000); | |
| 245 | |
| 246 // Start measurements. | |
| 247 chrome::AddTabAt(browser(), GURL(), -1, true); | |
| 248 ui_test_utils::NavigateToURL(browser(), GURL("chrome://webrtc-internals")); | |
| 249 content::WebContents* webrtc_internals_tab = | |
| 250 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 251 | |
| 252 test::SleepInJavascript(left_tab, 10000); | |
| 253 | |
| 254 scoped_ptr<base::DictionaryValue> all_data( | |
| 255 GetWebrtcInternalsData(webrtc_internals_tab)); | |
| 256 ASSERT_TRUE(all_data.get() != NULL); | |
| 257 | |
| 258 const base::DictionaryValue* first_pc_dict = | |
| 259 GetDataOnFirstPeerConnection(all_data.get()); | |
| 260 ASSERT_TRUE(first_pc_dict != NULL); | |
| 261 test::PrintBweForVideoMetrics(*first_pc_dict); | |
| 262 test::PrintMetricsForAllStreams(*first_pc_dict); | |
| 263 | |
| 264 HangUp(left_tab); | |
| 265 } | |
| 266 | |
| 267 IN_PROC_BROWSER_TEST_P(WebRtcBrowserTest, MANUAL_TestWebAudioMediaStream) { | |
| 268 if (OnWinXp()) return; | |
| 269 | |
| 270 ASSERT_TRUE(test::HasReferenceFilesInCheckout()); | |
| 271 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 82 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 272 GURL url(embedded_test_server()->GetURL("/webrtc/webaudio_crash.html")); | 83 GURL url(embedded_test_server()->GetURL("/webrtc/webaudio_crash.html")); |
| 273 ui_test_utils::NavigateToURL(browser(), url); | 84 ui_test_utils::NavigateToURL(browser(), url); |
| 274 content::WebContents* tab = | 85 content::WebContents* tab = |
| 275 browser()->tab_strip_model()->GetActiveWebContents(); | 86 browser()->tab_strip_model()->GetActiveWebContents(); |
| 276 | 87 |
| 277 // A sleep is necessary to be able to detect the crash. | 88 // A sleep is necessary to be able to detect the crash. |
| 278 test::SleepInJavascript(tab, 1000); | 89 test::SleepInJavascript(tab, 1000); |
| 279 | 90 |
| 280 ASSERT_FALSE(tab->IsCrashed()); | 91 ASSERT_FALSE(tab->IsCrashed()); |
| 281 } | 92 } |
| OLD | NEW |