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

Side by Side Diff: third_party/WebKit/Source/devtools/scripts/npm_test.js

Issue 2648633002: DevTools: enable backwards-compatibility testing (Closed)
Patch Set: Created 3 years, 11 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 var childProcess = require("child_process"); 5 var childProcess = require("child_process");
6 var fs = require("fs"); 6 var fs = require("fs");
7 var path = require("path"); 7 var path = require("path");
8 var shell = require("child_process").execSync; 8 var shell = require("child_process").execSync;
9 9
10 var utils = require("./utils"); 10 var utils = require("./utils");
11 11
12 var Flags = { 12 var Flags = {
13 DEBUG_DEVTOOLS: "--debug-devtools", 13 DEBUG_DEVTOOLS: "--debug-devtools",
14 DEBUG_DEVTOOLS_SHORTHAND: "-d", 14 DEBUG_DEVTOOLS_SHORTHAND: "-d",
15 FETCH_CONTENT_SHELL: "--fetch-content-shell", 15 FETCH_CONTENT_SHELL: "--fetch-content-shell",
16 COMPAT_PROTOCOL: "--compat-protocol",
17 };
18
19 var COMPAT_URL_MAPPING = {
20 "1.2": "https://storage.googleapis.com/content-shell-devtools-compat/content _shell_417361.zip",
16 }; 21 };
17 22
18 var IS_DEBUG_ENABLED = utils.includes(process.argv, Flags.DEBUG_DEVTOOLS) || 23 var IS_DEBUG_ENABLED = utils.includes(process.argv, Flags.DEBUG_DEVTOOLS) ||
19 utils.includes(process.argv, Flags.DEBUG_DEVTOOLS_SHORTHAND); 24 utils.includes(process.argv, Flags.DEBUG_DEVTOOLS_SHORTHAND);
25 var COMPAT_PROTOCOL = utils.parseArgs(process.argv)[Flags.COMPAT_PROTOCOL];
20 var IS_FETCH_CONTENT_SHELL = utils.includes(process.argv, Flags.FETCH_CONTENT_SH ELL); 26 var IS_FETCH_CONTENT_SHELL = utils.includes(process.argv, Flags.FETCH_CONTENT_SH ELL);
21 27
22 var CONTENT_SHELL_ZIP = "content-shell.zip"; 28 var CONTENT_SHELL_ZIP = "content-shell.zip";
23 var MAX_CONTENT_SHELLS = 10; 29 var MAX_CONTENT_SHELLS = 10;
24 var PLATFORM = getPlatform(); 30 var PLATFORM = getPlatform();
25 var PYTHON = process.platform === "win32" ? "python.bat" : "python"; 31 var PYTHON = process.platform === "win32" ? "python.bat" : "python";
26 32
27 var CHROMIUM_SRC_PATH = path.resolve(__dirname, "..", "..", "..", "..", ".."); 33 var CHROMIUM_SRC_PATH = path.resolve(__dirname, "..", "..", "..", "..", "..");
28 var RELEASE_PATH = path.resolve(CHROMIUM_SRC_PATH, "out", "Release"); 34 var RELEASE_PATH = path.resolve(CHROMIUM_SRC_PATH, "out", "Release");
29 var BLINK_TEST_PATH = path.resolve(CHROMIUM_SRC_PATH, "blink", "tools", "run_lay out_tests.py"); 35 var BLINK_TEST_PATH = path.resolve(CHROMIUM_SRC_PATH, "blink", "tools", "run_lay out_tests.py");
30 var CACHE_PATH = path.resolve(__dirname, "..", ".test_cache"); 36 var CACHE_PATH = path.resolve(__dirname, "..", ".test_cache");
31 var SOURCE_PATH = path.resolve(__dirname, "..", "front_end"); 37 var SOURCE_PATH = path.resolve(__dirname, "..", "front_end");
32 38
33 function main(){ 39 function main(){
40 if (!utils.isDir(CACHE_PATH))
41 fs.mkdirSync(CACHE_PATH);
42 deleteOldContentShells();
43
44 if (COMPAT_PROTOCOL) {
45 runCompatibilityTests();
46 return;
47 }
34 var hasUserCompiledContentShell = utils.isFile(getContentShellBinaryPath(REL EASE_PATH)); 48 var hasUserCompiledContentShell = utils.isFile(getContentShellBinaryPath(REL EASE_PATH));
35 if (!IS_FETCH_CONTENT_SHELL && hasUserCompiledContentShell) { 49 if (!IS_FETCH_CONTENT_SHELL && hasUserCompiledContentShell) {
36 var outDir = path.resolve(RELEASE_PATH, ".."); 50 var outDir = path.resolve(RELEASE_PATH, "..");
37 if (!IS_DEBUG_ENABLED) { 51 if (!IS_DEBUG_ENABLED) {
38 compileFrontend(); 52 compileFrontend();
39 } 53 }
40 runTests(outDir, IS_DEBUG_ENABLED); 54 runTests(outDir, IS_DEBUG_ENABLED);
41 return; 55 return;
42 } 56 }
43 if (!utils.isDir(CACHE_PATH)) 57
44 fs.mkdirSync(CACHE_PATH);
45 deleteOldContentShells();
46 findPreviousUploadedPosition(findMostRecentChromiumCommit()) 58 findPreviousUploadedPosition(findMostRecentChromiumCommit())
47 .then(onUploadedCommitPosition) 59 .then(onUploadedCommitPosition)
48 .catch(onError); 60 .catch(onError);
49 61
50 function onError(error) { 62 function onError(error) {
51 console.log("Unable to run tests because of error:", error); 63 console.log("Unable to run tests because of error:", error);
52 console.log(`Try removing the .test_cache folder [${CACHE_PATH}] and ret rying`); 64 console.log(`Try removing the .test_cache folder [${CACHE_PATH}] and ret rying`);
53 } 65 }
54 } 66 }
55 main(); 67 main();
56 68
69 function runCompatibilityTests()
70 {
71 const folder = `compat-protocol-${COMPAT_PROTOCOL}`;
72 compileFrontend();
73 var outPath = path.resolve(CACHE_PATH, folder, "out");
74 var contentShellDirPath = path.resolve(outPath, "Release");
75 var hasCachedContentShell = utils.isFile(getContentShellBinaryPath(contentSh ellDirPath));
76 if (hasCachedContentShell) {
77 console.log(`Using cached content shell at: ${outPath}`);
78 copyFrontendToCompatBuildPath(contentShellDirPath, RELEASE_PATH);
79 runTests(outPath, IS_DEBUG_ENABLED);
80 return;
81 }
82 prepareContentShellDirectory(folder)
83 .then(() => downloadContentShell(COMPAT_URL_MAPPING[COMPAT_PROTOCOL], fo lder))
84 .then(extractContentShell)
85 .then(() => copyFrontendToCompatBuildPath(contentShellDirPath, RELEASE_P ATH))
86 .then(() => runTests(outPath, IS_DEBUG_ENABLED));
87 }
88
57 function compileFrontend() 89 function compileFrontend()
58 { 90 {
59 console.log("Compiling devtools frontend"); 91 console.log("Compiling devtools frontend");
60 try { 92 try {
61 shell(`ninja -C ${RELEASE_PATH} devtools_frontend_resources`); 93 shell(`ninja -C ${RELEASE_PATH} devtools_frontend_resources`);
62 } catch (err) { 94 } catch (err) {
63 console.log(err.stdout.toString()); 95 console.log(err.stdout.toString());
64 console.log('ERROR: Cannot compile frontend\n' + err); 96 console.log('ERROR: Cannot compile frontend\n' + err);
65 process.exit(1); 97 process.exit(1);
66 } 98 }
67 } 99 }
68 100
69 function onUploadedCommitPosition(commitPosition) 101 function onUploadedCommitPosition(commitPosition)
70 { 102 {
71 var contentShellDirPath = path.resolve(CACHE_PATH, commitPosition, "out", "R elease"); 103 var contentShellDirPath = path.resolve(CACHE_PATH, commitPosition, "out", "R elease");
72 var contentShellResourcesPath = path.resolve(contentShellDirPath, "resources "); 104 var contentShellResourcesPath = path.resolve(contentShellDirPath, "resources ");
73 var contentShellPath = path.resolve(CACHE_PATH, commitPosition, "out"); 105 var contentShellPath = path.resolve(CACHE_PATH, commitPosition, "out");
74 106
75 var hasCachedContentShell = utils.isFile(getContentShellBinaryPath(contentSh ellDirPath)); 107 var hasCachedContentShell = utils.isFile(getContentShellBinaryPath(contentSh ellDirPath));
76 if (hasCachedContentShell) { 108 if (hasCachedContentShell) {
77 console.log(`Using cached content shell at: ${contentShellPath}`); 109 console.log(`Using cached content shell at: ${contentShellPath}`);
78 copyFrontend(contentShellResourcesPath); 110 copyFrontend(contentShellResourcesPath);
79 return runTests(contentShellPath, true); 111 return runTests(contentShellPath, true);
80 } 112 }
113 var url = `http://commondatastorage.googleapis.com/chromium-browser-snapshot s/${PLATFORM}/${commitPosition}/${CONTENT_SHELL_ZIP}`;
81 return prepareContentShellDirectory(commitPosition) 114 return prepareContentShellDirectory(commitPosition)
82 .then(downloadContentShell) 115 .then(() => downloadContentShell(url, commitPosition))
83 .then(extractContentShell) 116 .then(extractContentShell)
84 .then(() => copyFrontend(contentShellResourcesPath)) 117 .then(() => copyFrontend(contentShellResourcesPath))
85 .then(() => runTests(contentShellPath, true)); 118 .then(() => runTests(contentShellPath, true));
86 } 119 }
87 120
121 function copyFrontendToCompatBuildPath(compatBuildPath, latestBuildPath)
122 {
123 var customDevtoolsResourcesPath = path.resolve(compatBuildPath, "resources") ;
124 var latestDevtoolsInspectorPath = path.resolve(latestBuildPath, "resources" , "inspector");
125 var copiedFrontendPath = path.resolve(customDevtoolsResourcesPath, "inspecto r");
126 if (utils.isDir(copiedFrontendPath))
127 utils.removeRecursive(copiedFrontendPath);
128 utils.copyRecursive(latestDevtoolsInspectorPath, customDevtoolsResourcesPath );
129 }
130
88 function copyFrontend(contentShellResourcesPath) 131 function copyFrontend(contentShellResourcesPath)
89 { 132 {
90 var devtoolsResourcesPath = path.resolve(contentShellResourcesPath, "inspect or"); 133 var devtoolsResourcesPath = path.resolve(contentShellResourcesPath, "inspect or");
91 var copiedFrontendPath = path.resolve(devtoolsResourcesPath, "front_end"); 134 var copiedFrontendPath = path.resolve(devtoolsResourcesPath, "front_end");
92 var debugFrontendPath = path.resolve(devtoolsResourcesPath, "debug"); 135 var debugFrontendPath = path.resolve(devtoolsResourcesPath, "debug");
93 var inspectorBackendCommandsPath = path.resolve(devtoolsResourcesPath, "Insp ectorBackendCommands.js"); 136 var inspectorBackendCommandsPath = path.resolve(devtoolsResourcesPath, "Insp ectorBackendCommands.js");
94 var supportedCSSPropertiesPath = path.resolve(devtoolsResourcesPath, "Suppor tedCSSProperties.js"); 137 var supportedCSSPropertiesPath = path.resolve(devtoolsResourcesPath, "Suppor tedCSSProperties.js");
95 utils.removeRecursive(copiedFrontendPath); 138 utils.removeRecursive(copiedFrontendPath);
96 utils.removeRecursive(debugFrontendPath); 139 utils.removeRecursive(debugFrontendPath);
97 utils.copyRecursive(SOURCE_PATH, devtoolsResourcesPath); 140 utils.copyRecursive(SOURCE_PATH, devtoolsResourcesPath);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 } 206 }
164 207
165 function onError(error) 208 function onError(error)
166 { 209 {
167 if (error) 210 if (error)
168 console.log(`Received error: ${error} trying to fetch positions list from url: ${positionsListURL}`); 211 console.log(`Received error: ${error} trying to fetch positions list from url: ${positionsListURL}`);
169 throw new Error(`Unable to find a previous upload position for commit po sition: ${commitPosition}`); 212 throw new Error(`Unable to find a previous upload position for commit po sition: ${commitPosition}`);
170 } 213 }
171 } 214 }
172 215
173 function prepareContentShellDirectory(contentShellCommitPosition) 216 function prepareContentShellDirectory(folder)
174 { 217 {
175 var contentShellPath = path.join(CACHE_PATH, contentShellCommitPosition); 218 var contentShellPath = path.join(CACHE_PATH, folder);
176 if (utils.isDir(contentShellPath)) 219 if (utils.isDir(contentShellPath))
177 utils.removeRecursive(contentShellPath); 220 utils.removeRecursive(contentShellPath);
178 fs.mkdirSync(contentShellPath); 221 fs.mkdirSync(contentShellPath);
179 return Promise.resolve(contentShellCommitPosition); 222 return Promise.resolve(folder);
180 } 223 }
181 224
182 function downloadContentShell(commitPosition) 225 function downloadContentShell(url, folder)
183 { 226 {
184 var url = `http://commondatastorage.googleapis.com/chromium-browser-snapshot s/${PLATFORM}/${commitPosition}/${CONTENT_SHELL_ZIP}`;
185 console.log("Downloading content shell from:", url); 227 console.log("Downloading content shell from:", url);
186 console.log("NOTE: Download is ~35-65 MB depending on OS"); 228 console.log("NOTE: Download is ~35-65 MB depending on OS");
187 return utils.fetch(url) 229 return utils.fetch(url)
188 .then(writeZip) 230 .then(writeZip)
189 .catch(onError); 231 .catch(onError);
190 232
191 function writeZip(buffer) 233 function writeZip(buffer)
192 { 234 {
193 console.log("Completed download of content shell"); 235 console.log("Completed download of content shell");
194 var contentShellZipPath = path.join(CACHE_PATH, commitPosition, CONTENT_ SHELL_ZIP); 236 var contentShellZipPath = path.join(CACHE_PATH, folder, CONTENT_SHELL_ZI P);
195 fs.writeFileSync(contentShellZipPath, buffer); 237 fs.writeFileSync(contentShellZipPath, buffer);
196 return contentShellZipPath; 238 return contentShellZipPath;
197 } 239 }
198 240
199 function onError(error) 241 function onError(error)
200 { 242 {
201 console.log(`Received error: ${error} trying to download content shell f rom url: ${url}`); 243 console.log(`Received error: ${error} trying to download content shell f rom url: ${url}`);
202 throw new Error("Unable to download content shell"); 244 throw new Error("Unable to download content shell");
203 } 245 }
204 } 246 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 var testArgs = getInspectorTests().concat([ 282 var testArgs = getInspectorTests().concat([
241 "--no-pixel-tests", 283 "--no-pixel-tests",
242 "--build-directory", 284 "--build-directory",
243 buildDirectoryPath, 285 buildDirectoryPath,
244 ]); 286 ]);
245 if (useDebugDevtools) { 287 if (useDebugDevtools) {
246 testArgs.push("--additional-driver-flag=--debug-devtools"); 288 testArgs.push("--additional-driver-flag=--debug-devtools");
247 } else { 289 } else {
248 console.log("TIP: You can debug a test using: npm run debug-test inspect or/test-name.html") 290 console.log("TIP: You can debug a test using: npm run debug-test inspect or/test-name.html")
249 } 291 }
292 if (COMPAT_PROTOCOL) {
293 testArgs.push(`--platform=linux-devtools-${COMPAT_PROTOCOL}`);
294 }
250 if (IS_DEBUG_ENABLED) { 295 if (IS_DEBUG_ENABLED) {
251 testArgs.push("--additional-driver-flag=--remote-debugging-port=9222"); 296 testArgs.push("--additional-driver-flag=--remote-debugging-port=9222");
252 testArgs.push("--time-out-ms=6000000"); 297 testArgs.push("--time-out-ms=6000000");
253 console.log("\n============================================="); 298 console.log("\n=============================================");
254 console.log("Go to: http://localhost:9222/"); 299 console.log("Go to: http://localhost:9222/");
255 console.log("Click on link and in console execute: test()"); 300 console.log("Click on link and in console execute: test()");
256 console.log("=============================================\n"); 301 console.log("=============================================\n");
257 } 302 }
258 var args = [BLINK_TEST_PATH].concat(testArgs).concat(getTestFlags()); 303 var args = [BLINK_TEST_PATH].concat(testArgs).concat(getTestFlags());
259 console.log(`Running layout tests with args: ${args}`); 304 console.log(`Running layout tests with args: ${args}`);
260 childProcess.spawn(PYTHON, args, {stdio: "inherit"}); 305 childProcess.spawn(PYTHON, args, {stdio: "inherit"});
261 } 306 }
262 307
263 function getTestFlags() 308 function getTestFlags()
264 { 309 {
265 var flagValues = Object.keys(Flags).map(key => Flags[key]); 310 var flagValues = Object.keys(Flags).map(key => Flags[key]);
266 return process.argv 311 return process.argv
267 .slice(2) 312 .slice(2)
268 .filter(arg => !utils.includes(flagValues, arg) && !utils.includes(arg, "inspector")); 313 .filter(arg => {
314 var flagName = utils.includes(arg, "=") ? arg.slice(0, arg.indexOf(' =')) : arg;
315 return !utils.includes(flagValues, flagName) && !utils.includes(arg, "inspector")
316 });
269 } 317 }
270 318
271 function getInspectorTests() 319 function getInspectorTests()
272 { 320 {
273 var specificTests = process.argv.filter(arg => utils.includes(arg, "inspecto r")); 321 var specificTests = process.argv.filter(arg => utils.includes(arg, "inspecto r"));
274 if (specificTests.length) 322 if (specificTests.length)
275 return specificTests; 323 return specificTests;
276 return [ 324 return [
277 "inspector*", 325 "inspector*",
278 "http/tests/inspector*", 326 "http/tests/inspector*",
279 ]; 327 ];
280 } 328 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698