| 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 "chrome/browser/media/webrtc_browsertest_common.h" | 5 #include "chrome/browser/media/webrtc_browsertest_common.h" |
| 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/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser_tabstrip.h" | 15 #include "chrome/browser/ui/browser_tabstrip.h" |
| 16 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
| 17 | 17 |
| 18 namespace test { | |
| 19 | |
| 20 const base::FilePath::CharType kReferenceVideosDirName[] = | |
| 21 FILE_PATH_LITERAL("webrtc.DEPS/webrtc_videos"); | |
| 22 const base::FilePath::CharType kReferenceFileName360p[] = | |
| 23 FILE_PATH_LITERAL("reference_video_640x360_30fps"); | |
| 24 const base::FilePath::CharType kYuvFileExtension[] = FILE_PATH_LITERAL("yuv"); | |
| 25 const base::FilePath::CharType kY4mFileExtension[] = FILE_PATH_LITERAL("y4m"); | |
| 26 | |
| 27 // This message describes how to modify your .gclient to get the reference | |
| 28 // video files downloaded for you. | |
| 29 static const char kAdviseOnGclientSolution[] = | |
| 30 "You need to add this solution to your .gclient to run this test:\n" | |
| 31 "{\n" | |
| 32 " \"name\" : \"webrtc.DEPS\",\n" | |
| 33 " \"url\" : \"svn://svn.chromium.org/chrome/trunk/deps/" | |
| 34 "third_party/webrtc/webrtc.DEPS\",\n" | |
| 35 "}"; | |
| 36 | |
| 37 const int kDefaultPollIntervalMsec = 250; | 18 const int kDefaultPollIntervalMsec = 250; |
| 38 | 19 |
| 39 base::FilePath GetReferenceVideosDir() { | |
| 40 // FilePath does not tolerate relative paths, and we want to hang the | |
| 41 // kReferenceVideosDirName at the same level as Chromium codebase, so we | |
| 42 // need to subtract the trailing .../src manually from the path. | |
| 43 const size_t src_token_length = 3u; | |
| 44 const base::FilePath::StringType src_token(FILE_PATH_LITERAL("src")); | |
| 45 | |
| 46 base::FilePath source_dir; | |
| 47 PathService::Get(base::DIR_SOURCE_ROOT, &source_dir); | |
| 48 | |
| 49 base::FilePath::StringType path = source_dir.value(); | |
| 50 DCHECK_GT(path.size(), src_token_length); | |
| 51 std::size_t found = path.rfind(src_token); | |
| 52 if (found != std::string::npos) | |
| 53 path.erase(found, src_token_length); | |
| 54 return base::FilePath(path).Append(kReferenceVideosDirName); | |
| 55 } | |
| 56 | |
| 57 bool HasReferenceFilesInCheckout() { | |
| 58 if (!base::PathExists(GetReferenceVideosDir())) { | |
| 59 LOG(ERROR) | |
| 60 << "Cannot find the working directory for the reference video " | |
| 61 << "files, expected at " << GetReferenceVideosDir().value() << ". " << | |
| 62 kAdviseOnGclientSolution; | |
| 63 return false; | |
| 64 } | |
| 65 base::FilePath webrtc_reference_video_yuv = GetReferenceVideosDir() | |
| 66 .Append(kReferenceFileName360p).AddExtension(kYuvFileExtension); | |
| 67 if (!base::PathExists(webrtc_reference_video_yuv)) { | |
| 68 LOG(ERROR) | |
| 69 << "Missing YUV reference video to be used for quality" | |
| 70 << " comparison, expected at " << webrtc_reference_video_yuv.value() | |
| 71 << ". " << kAdviseOnGclientSolution; | |
| 72 return false; | |
| 73 } | |
| 74 | |
| 75 base::FilePath webrtc_reference_video_y4m = GetReferenceVideosDir() | |
| 76 .Append(kReferenceFileName360p).AddExtension(kY4mFileExtension); | |
| 77 if (!base::PathExists(webrtc_reference_video_y4m)) { | |
| 78 LOG(ERROR) | |
| 79 << "Missing Y4M reference video to be used for quality" | |
| 80 << " comparison, expected at "<< webrtc_reference_video_y4m.value() | |
| 81 << ". " << kAdviseOnGclientSolution; | |
| 82 return false; | |
| 83 } | |
| 84 return true; | |
| 85 } | |
| 86 | |
| 87 bool SleepInJavascript(content::WebContents* tab_contents, int timeout_msec) { | 20 bool SleepInJavascript(content::WebContents* tab_contents, int timeout_msec) { |
| 88 const std::string javascript = base::StringPrintf( | 21 const std::string javascript = base::StringPrintf( |
| 89 "setTimeout(function() {" | 22 "setTimeout(function() {" |
| 90 " window.domAutomationController.send('sleep-ok');" | 23 " window.domAutomationController.send('sleep-ok');" |
| 91 "}, %d)", timeout_msec); | 24 "}, %d)", timeout_msec); |
| 92 | 25 |
| 93 std::string result; | 26 std::string result; |
| 94 bool ok = content::ExecuteScriptAndExtractString( | 27 bool ok = content::ExecuteScriptAndExtractString( |
| 95 tab_contents, javascript, &result); | 28 tab_contents, javascript, &result); |
| 96 return ok && result == "sleep-ok"; | 29 return ok && result == "sleep-ok"; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 122 if (evaluates_to == result) | 55 if (evaluates_to == result) |
| 123 return true; | 56 return true; |
| 124 | 57 |
| 125 // Sleep a bit here to keep this loop from spinlocking too badly. | 58 // Sleep a bit here to keep this loop from spinlocking too badly. |
| 126 if (!SleepInJavascript(tab_contents, poll_interval_msec)) { | 59 if (!SleepInJavascript(tab_contents, poll_interval_msec)) { |
| 127 // TODO(phoglund): Figure out why this fails every now and then. | 60 // TODO(phoglund): Figure out why this fails every now and then. |
| 128 // It's not a huge deal if it does though. | 61 // It's not a huge deal if it does though. |
| 129 LOG(ERROR) << "Failed to sleep."; | 62 LOG(ERROR) << "Failed to sleep."; |
| 130 } | 63 } |
| 131 } | 64 } |
| 132 LOG(ERROR) | 65 LOG(ERROR) << "Timed out while waiting for " << javascript << |
| 133 << "Timed out while waiting for " << javascript | 66 " to evaluate to " << evaluates_to << "; last result was '" << result << |
| 134 << " to evaluate to " << evaluates_to << "; last result was '" << result | 67 "'"; |
| 135 << "'"; | |
| 136 return false; | 68 return false; |
| 137 } | 69 } |
| 138 | 70 |
| 139 static base::FilePath::CharType kServerExecutable[] = | 71 static base::FilePath::CharType kServerExecutable[] = |
| 140 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
| 141 FILE_PATH_LITERAL("peerconnection_server.exe"); | 73 FILE_PATH_LITERAL("peerconnection_server.exe"); |
| 142 #else | 74 #else |
| 143 FILE_PATH_LITERAL("peerconnection_server"); | 75 FILE_PATH_LITERAL("peerconnection_server"); |
| 144 #endif | 76 #endif |
| 145 | 77 |
| 146 const char PeerConnectionServerRunner::kDefaultPort[] = "7778"; | 78 const char PeerConnectionServerRunner::kDefaultPort[] = "7778"; |
| 147 | 79 |
| 148 bool PeerConnectionServerRunner::Start() { | 80 bool PeerConnectionServerRunner::Start() { |
| 149 base::FilePath peerconnection_server; | 81 base::FilePath peerconnection_server; |
| 150 if (!PathService::Get(base::DIR_MODULE, &peerconnection_server)) { | 82 if (!PathService::Get(base::DIR_MODULE, &peerconnection_server)) { |
| 151 LOG(ERROR) << "Failed retrieving base::DIR_MODULE!"; | 83 LOG(ERROR) << "Failed retrieving base::DIR_MODULE!"; |
| 152 return false; | 84 return false; |
| 153 } | 85 } |
| 154 peerconnection_server = peerconnection_server.Append(kServerExecutable); | 86 peerconnection_server = peerconnection_server.Append(kServerExecutable); |
| 155 | 87 |
| 156 if (!base::PathExists(peerconnection_server)) { | 88 if (!base::PathExists(peerconnection_server)) { |
| 157 LOG(ERROR) | 89 LOG(ERROR) << "Missing " << kServerExecutable << ". You must build " |
| 158 << "Missing " << kServerExecutable << ". You must build " | 90 "it so it ends up next to the browser test binary."; |
| 159 << "it so it ends up next to the browser test binary."; | |
| 160 return false; | 91 return false; |
| 161 } | 92 } |
| 162 | 93 |
| 163 CommandLine command_line(peerconnection_server); | 94 CommandLine command_line(peerconnection_server); |
| 164 command_line.AppendSwitchASCII("port", kDefaultPort); | 95 command_line.AppendSwitchASCII("port", kDefaultPort); |
| 165 VLOG(0) << "Running " << command_line.GetCommandLineString(); | 96 VLOG(0) << "Running " << command_line.GetCommandLineString(); |
| 166 return base::LaunchProcess(command_line, | 97 return base::LaunchProcess(command_line, |
| 167 base::LaunchOptions(), | 98 base::LaunchOptions(), |
| 168 &server_pid_); | 99 &server_pid_); |
| 169 } | 100 } |
| 170 | 101 |
| 171 bool PeerConnectionServerRunner::Stop() { | 102 bool PeerConnectionServerRunner::Stop() { |
| 172 return base::KillProcess(server_pid_, 0, false); | 103 return base::KillProcess(server_pid_, 0, false); |
| 173 } | 104 } |
| 174 | 105 |
| 175 void PeerConnectionServerRunner::KillAllPeerConnectionServers() { | 106 void PeerConnectionServerRunner::KillAllPeerConnectionServersOnCurrentSystem() { |
| 176 if (!base::KillProcesses(kServerExecutable, -1, NULL)) { | 107 if (!base::KillProcesses(kServerExecutable, -1, NULL)) { |
| 177 LOG(ERROR) << "Failed to kill instances of " << kServerExecutable << "."; | 108 LOG(ERROR) << "Failed to kill instances of " << kServerExecutable << "."; |
| 178 return; | 109 return; |
| 179 } | 110 } |
| 180 base::WaitForProcessesToExit(kServerExecutable, | 111 base::WaitForProcessesToExit(kServerExecutable, |
| 181 base::TimeDelta::FromSeconds(5), NULL); | 112 base::TimeDelta::FromSeconds(5), NULL); |
| 182 } | 113 } |
| 183 | |
| 184 } // namespace test | |
| OLD | NEW |