| 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 <ctime> | 5 #include <ctime> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/process/launch.h" | 10 #include "base/process/launch.h" |
| 11 #include "base/scoped_native_library.h" | 11 #include "base/scoped_native_library.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
| 14 #include "chrome/browser/media/webrtc_browsertest_base.h" | 14 #include "chrome/browser/media/webrtc_browsertest_base.h" |
| 15 #include "chrome/browser/media/webrtc_browsertest_common.h" | 15 #include "chrome/browser/media/webrtc_browsertest_common.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_tabstrip.h" | 18 #include "chrome/browser/ui/browser_tabstrip.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| 23 #include "content/public/test/browser_test_utils.h" | 23 #include "content/public/test/browser_test_utils.h" |
| 24 #include "net/test/embedded_test_server/embedded_test_server.h" | 24 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 25 #include "testing/perf/perf_test.h" | 25 #include "testing/perf/perf_test.h" |
| 26 | 26 |
| 27 // These are relative to the reference file dir defined by |
| 28 // webrtc_browsertest_common.h (i.e. chrome/test/data/webrtc/resources). |
| 27 static const base::FilePath::CharType kReferenceFile[] = | 29 static const base::FilePath::CharType kReferenceFile[] = |
| 28 #if defined (OS_WIN) | 30 #if defined (OS_WIN) |
| 29 FILE_PATH_LITERAL("pyauto_private/webrtc/human-voice-win.wav"); | 31 FILE_PATH_LITERAL("human-voice-win.wav"); |
| 30 #else | 32 #else |
| 31 FILE_PATH_LITERAL("pyauto_private/webrtc/human-voice-linux.wav"); | 33 FILE_PATH_LITERAL("human-voice-linux.wav"); |
| 32 #endif | 34 #endif |
| 33 | 35 |
| 34 // The javascript will load the reference file relative to its location, | 36 // The javascript will load the reference file relative to its location, |
| 35 // which is in /webrtc on the web server. Therefore, prepend a '..' traversal. | 37 // which is in /webrtc on the web server. The files we are looking for are in |
| 38 // webrtc/resources in the chrome/test/data folder. |
| 36 static const char kReferenceFileRelativeUrl[] = | 39 static const char kReferenceFileRelativeUrl[] = |
| 37 #if defined (OS_WIN) | 40 #if defined (OS_WIN) |
| 38 "../pyauto_private/webrtc/human-voice-win.wav"; | 41 "resources/human-voice-win.wav"; |
| 39 #else | 42 #else |
| 40 "../pyauto_private/webrtc/human-voice-linux.wav"; | 43 "resources/human-voice-linux.wav"; |
| 41 #endif | 44 #endif |
| 42 | 45 |
| 43 static const base::FilePath::CharType kToolsPath[] = | |
| 44 FILE_PATH_LITERAL("pyauto_private/media/tools"); | |
| 45 | |
| 46 static const char kMainWebrtcTestHtmlPage[] = | 46 static const char kMainWebrtcTestHtmlPage[] = |
| 47 "/webrtc/webrtc_audio_quality_test.html"; | 47 "/webrtc/webrtc_audio_quality_test.html"; |
| 48 | 48 |
| 49 static base::FilePath GetTestDataDir() { | |
| 50 base::FilePath source_dir; | |
| 51 PathService::Get(chrome::DIR_TEST_DATA, &source_dir); | |
| 52 return source_dir; | |
| 53 } | |
| 54 | |
| 55 // Test we can set up a WebRTC call and play audio through it. | 49 // Test we can set up a WebRTC call and play audio through it. |
| 56 // | 50 // |
| 57 // You must have the src-internal solution in your .gclient to put the required | 51 // You must have the src-internal solution in your .gclient to put the required |
| 58 // pyauto_private directory into chrome/test/data/. | 52 // pyauto_private directory into chrome/test/data/. |
| 59 // | 53 // |
| 60 // This test will only work on machines that have been configured to record | 54 // This test will only work on machines that have been configured to record |
| 61 // their own input. | 55 // their own input. |
| 62 // | 56 // |
| 63 // On Linux: | 57 // On Linux: |
| 64 // 1. # sudo apt-get install pavucontrol | 58 // 1. # sudo apt-get install pavucontrol |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 EXPECT_FALSE(command_line->HasSwitch( | 97 EXPECT_FALSE(command_line->HasSwitch( |
| 104 switches::kUseFakeDeviceForMediaStream)); | 98 switches::kUseFakeDeviceForMediaStream)); |
| 105 EXPECT_FALSE(command_line->HasSwitch( | 99 EXPECT_FALSE(command_line->HasSwitch( |
| 106 switches::kUseFakeUIForMediaStream)); | 100 switches::kUseFakeUIForMediaStream)); |
| 107 | 101 |
| 108 bool enable_audio_track_processing = GetParam(); | 102 bool enable_audio_track_processing = GetParam(); |
| 109 if (enable_audio_track_processing) | 103 if (enable_audio_track_processing) |
| 110 command_line->AppendSwitch(switches::kEnableAudioTrackProcessing); | 104 command_line->AppendSwitch(switches::kEnableAudioTrackProcessing); |
| 111 } | 105 } |
| 112 | 106 |
| 113 bool HasAllRequiredResources() { | |
| 114 base::FilePath reference_file = GetTestDataDir().Append(kReferenceFile); | |
| 115 if (!base::PathExists(reference_file)) { | |
| 116 LOG(ERROR) << "Cannot find the reference file to be used for audio " | |
| 117 << "quality comparison: " << reference_file.value(); | |
| 118 return false; | |
| 119 } | |
| 120 return true; | |
| 121 } | |
| 122 | |
| 123 void AddAudioFile(const std::string& input_file_relative_url, | 107 void AddAudioFile(const std::string& input_file_relative_url, |
| 124 content::WebContents* tab_contents) { | 108 content::WebContents* tab_contents) { |
| 125 EXPECT_EQ("ok-added", ExecuteJavascript( | 109 EXPECT_EQ("ok-added", ExecuteJavascript( |
| 126 "addAudioFile('" + input_file_relative_url + "')", tab_contents)); | 110 "addAudioFile('" + input_file_relative_url + "')", tab_contents)); |
| 127 } | 111 } |
| 128 | 112 |
| 129 void PlayAudioFile(content::WebContents* tab_contents) { | 113 void PlayAudioFile(content::WebContents* tab_contents) { |
| 130 EXPECT_EQ("ok-playing", ExecuteJavascript("playAudioFile()", tab_contents)); | 114 EXPECT_EQ("ok-playing", ExecuteJavascript("playAudioFile()", tab_contents)); |
| 131 } | 115 } |
| 132 | 116 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 int exit_code = -1; | 204 int exit_code = -1; |
| 221 base::WaitForExitCode(recording_application_, &exit_code); | 205 base::WaitForExitCode(recording_application_, &exit_code); |
| 222 return exit_code == 0; | 206 return exit_code == 0; |
| 223 } | 207 } |
| 224 private: | 208 private: |
| 225 base::ProcessHandle recording_application_; | 209 base::ProcessHandle recording_application_; |
| 226 }; | 210 }; |
| 227 | 211 |
| 228 bool ForceMicrophoneVolumeTo100Percent() { | 212 bool ForceMicrophoneVolumeTo100Percent() { |
| 229 #if defined(OS_WIN) | 213 #if defined(OS_WIN) |
| 230 CommandLine command_line(GetTestDataDir().Append(kToolsPath).Append( | 214 CommandLine command_line(test::GetReferenceFilesDir().Append( |
| 231 FILE_PATH_LITERAL("force_mic_volume_max.exe"))); | 215 FILE_PATH_LITERAL("force_mic_volume_max.exe"))); |
| 232 VLOG(0) << "Running " << command_line.GetCommandLineString(); | 216 VLOG(0) << "Running " << command_line.GetCommandLineString(); |
| 233 std::string result; | 217 std::string result; |
| 234 if (!base::GetAppOutput(command_line, &result)) { | 218 if (!base::GetAppOutput(command_line, &result)) { |
| 235 LOG(ERROR) << "Failed to set source volume: output was " << result; | 219 LOG(ERROR) << "Failed to set source volume: output was " << result; |
| 236 return false; | 220 return false; |
| 237 } | 221 } |
| 238 #else | 222 #else |
| 239 // Just force the volume of, say the first 5 devices. A machine will rarely | 223 // Just force the volume of, say the first 5 devices. A machine will rarely |
| 240 // have more input sources than that. This is way easier than finding the | 224 // have more input sources than that. This is way easier than finding the |
| (...skipping 27 matching lines...) Expand all Loading... |
| 268 // ABOVE_PERIODS: The period for which silence occurs. Value 1 is used for | 252 // ABOVE_PERIODS: The period for which silence occurs. Value 1 is used for |
| 269 // silence at beginning of audio. | 253 // silence at beginning of audio. |
| 270 // DURATION: the amount of time in seconds that non-silence must be detected | 254 // DURATION: the amount of time in seconds that non-silence must be detected |
| 271 // before sox stops trimming audio. | 255 // before sox stops trimming audio. |
| 272 // THRESHOLD: value used to indicate what sample value is treates as silence. | 256 // THRESHOLD: value used to indicate what sample value is treates as silence. |
| 273 const char* kAbovePeriods = "1"; | 257 const char* kAbovePeriods = "1"; |
| 274 const char* kDuration = "2"; | 258 const char* kDuration = "2"; |
| 275 const char* kTreshold = "5%"; | 259 const char* kTreshold = "5%"; |
| 276 | 260 |
| 277 #if defined(OS_WIN) | 261 #if defined(OS_WIN) |
| 278 CommandLine command_line(GetTestDataDir().Append(kToolsPath).Append( | 262 CommandLine command_line(test::GetReferenceFilesDir().Append( |
| 279 FILE_PATH_LITERAL("sox.exe"))); | 263 FILE_PATH_LITERAL("sox.exe"))); |
| 280 #else | 264 #else |
| 281 CommandLine command_line(base::FilePath(FILE_PATH_LITERAL("sox"))); | 265 CommandLine command_line(base::FilePath(FILE_PATH_LITERAL("sox"))); |
| 282 #endif | 266 #endif |
| 283 command_line.AppendArgPath(input_file); | 267 command_line.AppendArgPath(input_file); |
| 284 command_line.AppendArgPath(output_file); | 268 command_line.AppendArgPath(output_file); |
| 285 command_line.AppendArg("silence"); | 269 command_line.AppendArg("silence"); |
| 286 command_line.AppendArg(kAbovePeriods); | 270 command_line.AppendArg(kAbovePeriods); |
| 287 command_line.AppendArg(kDuration); | 271 command_line.AppendArg(kDuration); |
| 288 command_line.AppendArg(kTreshold); | 272 command_line.AppendArg(kTreshold); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 317 // "3.145", etc). Returns true on success. | 301 // "3.145", etc). Returns true on success. |
| 318 bool RunPesq(const base::FilePath& reference_file, | 302 bool RunPesq(const base::FilePath& reference_file, |
| 319 const base::FilePath& actual_file, | 303 const base::FilePath& actual_file, |
| 320 int sample_rate, std::string* raw_mos, std::string* mos_lqo) { | 304 int sample_rate, std::string* raw_mos, std::string* mos_lqo) { |
| 321 // PESQ will break if the paths are too long (!). | 305 // PESQ will break if the paths are too long (!). |
| 322 EXPECT_LT(reference_file.value().length(), 128u); | 306 EXPECT_LT(reference_file.value().length(), 128u); |
| 323 EXPECT_LT(actual_file.value().length(), 128u); | 307 EXPECT_LT(actual_file.value().length(), 128u); |
| 324 | 308 |
| 325 #if defined(OS_WIN) | 309 #if defined(OS_WIN) |
| 326 base::FilePath pesq_path = | 310 base::FilePath pesq_path = |
| 327 GetTestDataDir().Append(kToolsPath).Append(FILE_PATH_LITERAL("pesq.exe")); | 311 test::GetReferenceFilesDir().Append(FILE_PATH_LITERAL("pesq.exe")); |
| 328 #else | 312 #else |
| 329 base::FilePath pesq_path = | 313 base::FilePath pesq_path = |
| 330 GetTestDataDir().Append(kToolsPath).Append(FILE_PATH_LITERAL("pesq")); | 314 test::GetReferenceFilesDir().Append(FILE_PATH_LITERAL("pesq")); |
| 331 #endif | 315 #endif |
| 332 | 316 |
| 333 if (!base::PathExists(pesq_path)) { | 317 if (!base::PathExists(pesq_path)) { |
| 334 LOG(ERROR) << "Missing PESQ binary in " << pesq_path.value(); | 318 LOG(ERROR) << "Missing PESQ binary in " << pesq_path.value(); |
| 335 return false; | 319 return false; |
| 336 } | 320 } |
| 337 | 321 |
| 338 CommandLine command_line(pesq_path); | 322 CommandLine command_line(pesq_path); |
| 339 command_line.AppendArg(base::StringPrintf("+%d", sample_rate)); | 323 command_line.AppendArg(base::StringPrintf("+%d", sample_rate)); |
| 340 command_line.AppendArgPath(reference_file); | 324 command_line.AppendArgPath(reference_file); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 371 WebRtcAudioQualityBrowserTest, | 355 WebRtcAudioQualityBrowserTest, |
| 372 testing::ValuesIn(kRunTestsWithFlag)); | 356 testing::ValuesIn(kRunTestsWithFlag)); |
| 373 | 357 |
| 374 #if defined(OS_LINUX) || defined(OS_WIN) | 358 #if defined(OS_LINUX) || defined(OS_WIN) |
| 375 // Only implemented on Linux and Windows for now. | 359 // Only implemented on Linux and Windows for now. |
| 376 #define MAYBE_MANUAL_TestAudioQuality MANUAL_TestAudioQuality | 360 #define MAYBE_MANUAL_TestAudioQuality MANUAL_TestAudioQuality |
| 377 #else | 361 #else |
| 378 #define MAYBE_MANUAL_TestAudioQuality DISABLED_MANUAL_TestAudioQuality | 362 #define MAYBE_MANUAL_TestAudioQuality DISABLED_MANUAL_TestAudioQuality |
| 379 #endif | 363 #endif |
| 380 | 364 |
| 381 // Disabled due to crbug.com/359579. | |
| 382 IN_PROC_BROWSER_TEST_P(WebRtcAudioQualityBrowserTest, | 365 IN_PROC_BROWSER_TEST_P(WebRtcAudioQualityBrowserTest, |
| 383 DISABLED_MANUAL_TestAudioQuality) { | 366 MANUAL_TestAudioQuality) { |
| 384 #if defined(OS_WIN) | 367 #if defined(OS_WIN) |
| 385 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 368 if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
| 386 // It would take work to implement this on XP; not prioritized right now. | 369 // It would take work to implement this on XP; not prioritized right now. |
| 387 LOG(ERROR) << "This test is not implemented for Windows XP."; | 370 LOG(ERROR) << "This test is not implemented for Windows XP."; |
| 388 return; | 371 return; |
| 389 } | 372 } |
| 390 #endif | 373 #endif |
| 391 ASSERT_TRUE(HasAllRequiredResources()); | 374 ASSERT_TRUE(test::HasReferenceFilesInCheckout()); |
| 392 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 375 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 393 ASSERT_TRUE(peerconnection_server_.Start()); | 376 ASSERT_TRUE(peerconnection_server_.Start()); |
| 394 | 377 |
| 395 ASSERT_TRUE(ForceMicrophoneVolumeTo100Percent()); | 378 ASSERT_TRUE(ForceMicrophoneVolumeTo100Percent()); |
| 396 | 379 |
| 397 ui_test_utils::NavigateToURL( | 380 ui_test_utils::NavigateToURL( |
| 398 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); | 381 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); |
| 399 content::WebContents* left_tab = | 382 content::WebContents* left_tab = |
| 400 browser()->tab_strip_model()->GetActiveWebContents(); | 383 browser()->tab_strip_model()->GetActiveWebContents(); |
| 401 | 384 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 WaitUntilHangupVerified(right_tab); | 422 WaitUntilHangupVerified(right_tab); |
| 440 | 423 |
| 441 base::FilePath trimmed_recording = CreateTemporaryWaveFile(); | 424 base::FilePath trimmed_recording = CreateTemporaryWaveFile(); |
| 442 | 425 |
| 443 ASSERT_TRUE(RemoveSilence(recording, trimmed_recording)); | 426 ASSERT_TRUE(RemoveSilence(recording, trimmed_recording)); |
| 444 VLOG(0) << "Trimmed silence: " << trimmed_recording.value() << std::endl; | 427 VLOG(0) << "Trimmed silence: " << trimmed_recording.value() << std::endl; |
| 445 | 428 |
| 446 std::string raw_mos; | 429 std::string raw_mos; |
| 447 std::string mos_lqo; | 430 std::string mos_lqo; |
| 448 base::FilePath reference_file_in_test_dir = | 431 base::FilePath reference_file_in_test_dir = |
| 449 GetTestDataDir().Append(kReferenceFile); | 432 test::GetReferenceFilesDir().Append(kReferenceFile); |
| 450 ASSERT_TRUE(RunPesq(reference_file_in_test_dir, trimmed_recording, 16000, | 433 ASSERT_TRUE(RunPesq(reference_file_in_test_dir, trimmed_recording, 16000, |
| 451 &raw_mos, &mos_lqo)); | 434 &raw_mos, &mos_lqo)); |
| 452 | 435 |
| 453 perf_test::PrintResult("audio_pesq", "", "raw_mos", raw_mos, "score", true); | 436 perf_test::PrintResult("audio_pesq", "", "raw_mos", raw_mos, "score", true); |
| 454 perf_test::PrintResult("audio_pesq", "", "mos_lqo", mos_lqo, "score", true); | 437 perf_test::PrintResult("audio_pesq", "", "mos_lqo", mos_lqo, "score", true); |
| 455 | 438 |
| 456 EXPECT_TRUE(base::DeleteFile(recording, false)); | 439 EXPECT_TRUE(base::DeleteFile(recording, false)); |
| 457 EXPECT_TRUE(base::DeleteFile(trimmed_recording, false)); | 440 EXPECT_TRUE(base::DeleteFile(trimmed_recording, false)); |
| 458 | 441 |
| 459 ASSERT_TRUE(peerconnection_server_.Stop()); | 442 ASSERT_TRUE(peerconnection_server_.Stop()); |
| 460 } | 443 } |
| OLD | NEW |