Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Side by Side Diff: chrome/browser/media/webrtc_browsertest_common.cc

Issue 216773002: Relanding Switched main WebRTC browser tests to use a more realistic video (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
18 const int kDefaultPollIntervalMsec = 250; 37 const int kDefaultPollIntervalMsec = 250;
19 38
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
20 bool SleepInJavascript(content::WebContents* tab_contents, int timeout_msec) { 87 bool SleepInJavascript(content::WebContents* tab_contents, int timeout_msec) {
21 const std::string javascript = base::StringPrintf( 88 const std::string javascript = base::StringPrintf(
22 "setTimeout(function() {" 89 "setTimeout(function() {"
23 " window.domAutomationController.send('sleep-ok');" 90 " window.domAutomationController.send('sleep-ok');"
24 "}, %d)", timeout_msec); 91 "}, %d)", timeout_msec);
25 92
26 std::string result; 93 std::string result;
27 bool ok = content::ExecuteScriptAndExtractString( 94 bool ok = content::ExecuteScriptAndExtractString(
28 tab_contents, javascript, &result); 95 tab_contents, javascript, &result);
29 return ok && result == "sleep-ok"; 96 return ok && result == "sleep-ok";
(...skipping 25 matching lines...) Expand all
55 if (evaluates_to == result) 122 if (evaluates_to == result)
56 return true; 123 return true;
57 124
58 // Sleep a bit here to keep this loop from spinlocking too badly. 125 // Sleep a bit here to keep this loop from spinlocking too badly.
59 if (!SleepInJavascript(tab_contents, poll_interval_msec)) { 126 if (!SleepInJavascript(tab_contents, poll_interval_msec)) {
60 // TODO(phoglund): Figure out why this fails every now and then. 127 // TODO(phoglund): Figure out why this fails every now and then.
61 // It's not a huge deal if it does though. 128 // It's not a huge deal if it does though.
62 LOG(ERROR) << "Failed to sleep."; 129 LOG(ERROR) << "Failed to sleep.";
63 } 130 }
64 } 131 }
65 LOG(ERROR) << "Timed out while waiting for " << javascript << 132 LOG(ERROR)
66 " to evaluate to " << evaluates_to << "; last result was '" << result << 133 << "Timed out while waiting for " << javascript
67 "'"; 134 << " to evaluate to " << evaluates_to << "; last result was '" << result
135 << "'";
68 return false; 136 return false;
69 } 137 }
70 138
71 static base::FilePath::CharType kServerExecutable[] = 139 static base::FilePath::CharType kServerExecutable[] =
72 #if defined(OS_WIN) 140 #if defined(OS_WIN)
73 FILE_PATH_LITERAL("peerconnection_server.exe"); 141 FILE_PATH_LITERAL("peerconnection_server.exe");
74 #else 142 #else
75 FILE_PATH_LITERAL("peerconnection_server"); 143 FILE_PATH_LITERAL("peerconnection_server");
76 #endif 144 #endif
77 145
78 const char PeerConnectionServerRunner::kDefaultPort[] = "7778"; 146 const char PeerConnectionServerRunner::kDefaultPort[] = "7778";
79 147
80 bool PeerConnectionServerRunner::Start() { 148 bool PeerConnectionServerRunner::Start() {
81 base::FilePath peerconnection_server; 149 base::FilePath peerconnection_server;
82 if (!PathService::Get(base::DIR_MODULE, &peerconnection_server)) { 150 if (!PathService::Get(base::DIR_MODULE, &peerconnection_server)) {
83 LOG(ERROR) << "Failed retrieving base::DIR_MODULE!"; 151 LOG(ERROR) << "Failed retrieving base::DIR_MODULE!";
84 return false; 152 return false;
85 } 153 }
86 peerconnection_server = peerconnection_server.Append(kServerExecutable); 154 peerconnection_server = peerconnection_server.Append(kServerExecutable);
87 155
88 if (!base::PathExists(peerconnection_server)) { 156 if (!base::PathExists(peerconnection_server)) {
89 LOG(ERROR) << "Missing " << kServerExecutable << ". You must build " 157 LOG(ERROR)
90 "it so it ends up next to the browser test binary."; 158 << "Missing " << kServerExecutable << ". You must build "
159 << "it so it ends up next to the browser test binary.";
91 return false; 160 return false;
92 } 161 }
93 162
94 CommandLine command_line(peerconnection_server); 163 CommandLine command_line(peerconnection_server);
95 command_line.AppendSwitchASCII("port", kDefaultPort); 164 command_line.AppendSwitchASCII("port", kDefaultPort);
96 VLOG(0) << "Running " << command_line.GetCommandLineString(); 165 VLOG(0) << "Running " << command_line.GetCommandLineString();
97 return base::LaunchProcess(command_line, 166 return base::LaunchProcess(command_line,
98 base::LaunchOptions(), 167 base::LaunchOptions(),
99 &server_pid_); 168 &server_pid_);
100 } 169 }
101 170
102 bool PeerConnectionServerRunner::Stop() { 171 bool PeerConnectionServerRunner::Stop() {
103 return base::KillProcess(server_pid_, 0, false); 172 return base::KillProcess(server_pid_, 0, false);
104 } 173 }
105 174
106 void PeerConnectionServerRunner::KillAllPeerConnectionServersOnCurrentSystem() { 175 void PeerConnectionServerRunner::KillAllPeerConnectionServers() {
107 if (!base::KillProcesses(kServerExecutable, -1, NULL)) { 176 if (!base::KillProcesses(kServerExecutable, -1, NULL)) {
108 LOG(ERROR) << "Failed to kill instances of " << kServerExecutable << "."; 177 LOG(ERROR) << "Failed to kill instances of " << kServerExecutable << ".";
109 return; 178 return;
110 } 179 }
111 base::WaitForProcessesToExit(kServerExecutable, 180 base::WaitForProcessesToExit(kServerExecutable,
112 base::TimeDelta::FromSeconds(5), NULL); 181 base::TimeDelta::FromSeconds(5), NULL);
113 } 182 }
183
184 } // namespace test
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc_browsertest_common.h ('k') | chrome/browser/media/webrtc_browsertest_perf.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698