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/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/process/launch.h" | 9 #include "base/process/launch.h" |
| 10 #include "base/process/process.h" |
10 #include "base/scoped_native_library.h" | 11 #include "base/scoped_native_library.h" |
11 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
12 #include "chrome/browser/media/webrtc_browsertest_base.h" | 13 #include "chrome/browser/media/webrtc_browsertest_base.h" |
13 #include "chrome/browser/media/webrtc_browsertest_common.h" | 14 #include "chrome/browser/media/webrtc_browsertest_common.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_tabstrip.h" | 17 #include "chrome/browser/ui/browser_tabstrip.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
19 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // Prepare the peer connections manually in this test since we don't add | 168 // Prepare the peer connections manually in this test since we don't add |
168 // getUserMedia-derived media streams in this test like the other tests. | 169 // getUserMedia-derived media streams in this test like the other tests. |
169 EXPECT_EQ("ok-peerconnection-created", | 170 EXPECT_EQ("ok-peerconnection-created", |
170 ExecuteJavascript("preparePeerConnection()", tab)); | 171 ExecuteJavascript("preparePeerConnection()", tab)); |
171 return tab; | 172 return tab; |
172 } | 173 } |
173 }; | 174 }; |
174 | 175 |
175 class AudioRecorder { | 176 class AudioRecorder { |
176 public: | 177 public: |
177 AudioRecorder(): recording_application_(base::kNullProcessHandle) {} | 178 AudioRecorder() {} |
178 ~AudioRecorder() {} | 179 ~AudioRecorder() {} |
179 | 180 |
180 // Starts the recording program for the specified duration. Returns true | 181 // Starts the recording program for the specified duration. Returns true |
181 // on success. | 182 // on success. |
182 bool StartRecording(int duration_sec, const base::FilePath& output_file, | 183 bool StartRecording(int duration_sec, const base::FilePath& output_file, |
183 bool mono) { | 184 bool mono) { |
184 EXPECT_EQ(base::kNullProcessHandle, recording_application_) | 185 EXPECT_FALSE(recording_application_.IsValid()) |
185 << "Tried to record, but is already recording."; | 186 << "Tried to record, but is already recording."; |
186 | 187 |
187 CommandLine command_line(CommandLine::NO_PROGRAM); | 188 CommandLine command_line(CommandLine::NO_PROGRAM); |
188 #if defined(OS_WIN) | 189 #if defined(OS_WIN) |
189 // This disable is required to run SoundRecorder.exe on 64-bit Windows | 190 // This disable is required to run SoundRecorder.exe on 64-bit Windows |
190 // from a 32-bit binary. We need to load the wow64 disable function from | 191 // from a 32-bit binary. We need to load the wow64 disable function from |
191 // the DLL since it doesn't exist on Windows XP. | 192 // the DLL since it doesn't exist on Windows XP. |
192 // TODO(phoglund): find some cleaner solution than using SoundRecorder.exe. | 193 // TODO(phoglund): find some cleaner solution than using SoundRecorder.exe. |
193 base::ScopedNativeLibrary kernel32_lib(base::FilePath(L"kernel32")); | 194 base::ScopedNativeLibrary kernel32_lib(base::FilePath(L"kernel32")); |
194 if (kernel32_lib.is_valid()) { | 195 if (kernel32_lib.is_valid()) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 command_line.AppendArg("-d"); | 238 command_line.AppendArg("-d"); |
238 command_line.AppendArg(base::StringPrintf("%d", duration_sec)); | 239 command_line.AppendArg(base::StringPrintf("%d", duration_sec)); |
239 command_line.AppendArg("-f"); | 240 command_line.AppendArg("-f"); |
240 command_line.AppendArg("dat"); | 241 command_line.AppendArg("dat"); |
241 command_line.AppendArg("-c"); | 242 command_line.AppendArg("-c"); |
242 command_line.AppendArg(base::StringPrintf("%d", num_channels)); | 243 command_line.AppendArg(base::StringPrintf("%d", num_channels)); |
243 command_line.AppendArgPath(output_file); | 244 command_line.AppendArgPath(output_file); |
244 #endif | 245 #endif |
245 | 246 |
246 DVLOG(0) << "Running " << command_line.GetCommandLineString(); | 247 DVLOG(0) << "Running " << command_line.GetCommandLineString(); |
247 return base::LaunchProcess(command_line, base::LaunchOptions(), | 248 recording_application_ = |
248 &recording_application_); | 249 base::LaunchProcess(command_line, base::LaunchOptions()); |
| 250 return recording_application_.IsValid(); |
249 } | 251 } |
250 | 252 |
251 // Joins the recording program. Returns true on success. | 253 // Joins the recording program. Returns true on success. |
252 bool WaitForRecordingToEnd() { | 254 bool WaitForRecordingToEnd() { |
253 int exit_code = -1; | 255 int exit_code = -1; |
254 base::WaitForExitCode(recording_application_, &exit_code); | 256 recording_application_.WaitForExit(&exit_code); |
255 return exit_code == 0; | 257 return exit_code == 0; |
256 } | 258 } |
257 private: | 259 private: |
258 base::ProcessHandle recording_application_; | 260 base::Process recording_application_; |
259 }; | 261 }; |
260 | 262 |
261 bool ForceMicrophoneVolumeTo100Percent() { | 263 bool ForceMicrophoneVolumeTo100Percent() { |
262 #if defined(OS_WIN) | 264 #if defined(OS_WIN) |
263 // Note: the force binary isn't in tools since it's one of our own. | 265 // Note: the force binary isn't in tools since it's one of our own. |
264 CommandLine command_line(test::GetReferenceFilesDir().Append( | 266 CommandLine command_line(test::GetReferenceFilesDir().Append( |
265 FILE_PATH_LITERAL("force_mic_volume_max.exe"))); | 267 FILE_PATH_LITERAL("force_mic_volume_max.exe"))); |
266 DVLOG(0) << "Running " << command_line.GetCommandLineString(); | 268 DVLOG(0) << "Running " << command_line.GetCommandLineString(); |
267 std::string result; | 269 std::string result; |
268 if (!base::GetAppOutput(command_line, &result)) { | 270 if (!base::GetAppOutput(command_line, &result)) { |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 | 534 |
533 ASSERT_TRUE(RemoveSilence(recording, trimmed_recording)); | 535 ASSERT_TRUE(RemoveSilence(recording, trimmed_recording)); |
534 DVLOG(0) << "Trimmed silence: " << trimmed_recording.value() << std::endl; | 536 DVLOG(0) << "Trimmed silence: " << trimmed_recording.value() << std::endl; |
535 | 537 |
536 // TODO(phoglund): invoke bjornv's audio energy analysis tool on the trimmed | 538 // TODO(phoglund): invoke bjornv's audio energy analysis tool on the trimmed |
537 // recording and log the result. | 539 // recording and log the result. |
538 | 540 |
539 EXPECT_TRUE(base::DeleteFile(recording, false)); | 541 EXPECT_TRUE(base::DeleteFile(recording, false)); |
540 EXPECT_TRUE(base::DeleteFile(trimmed_recording, false)); | 542 EXPECT_TRUE(base::DeleteFile(trimmed_recording, false)); |
541 } | 543 } |
OLD | NEW |