| OLD | NEW |
| 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_s
hell_417361.zip', |
| 16 }; | 21 }; |
| 17 | 22 |
| 18 var IS_DEBUG_ENABLED = | 23 var IS_DEBUG_ENABLED = |
| 19 utils.includes(process.argv, Flags.DEBUG_DEVTOOLS) || utils.includes(process
.argv, Flags.DEBUG_DEVTOOLS_SHORTHAND); | 24 utils.includes(process.argv, Flags.DEBUG_DEVTOOLS) || 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 DEVTOOLS_PATH = path.resolve(__dirname, '..'); |
| 31 var SOURCE_PATH = path.resolve(__dirname, '..', 'front_end'); | 37 var CACHE_PATH = path.resolve(DEVTOOLS_PATH, '.test_cache'); |
| 38 var SOURCE_PATH = path.resolve(DEVTOOLS_PATH, 'front_end'); |
| 32 | 39 |
| 33 function main() { | 40 function main() { |
| 41 if (!utils.isDir(CACHE_PATH)) |
| 42 fs.mkdirSync(CACHE_PATH); |
| 43 deleteOldContentShells(); |
| 44 |
| 45 if (COMPAT_PROTOCOL) { |
| 46 runCompatibilityTests(); |
| 47 return; |
| 48 } |
| 34 var hasUserCompiledContentShell = utils.isFile(getContentShellBinaryPath(RELEA
SE_PATH)); | 49 var hasUserCompiledContentShell = utils.isFile(getContentShellBinaryPath(RELEA
SE_PATH)); |
| 35 if (!IS_FETCH_CONTENT_SHELL && hasUserCompiledContentShell) { | 50 if (!IS_FETCH_CONTENT_SHELL && hasUserCompiledContentShell) { |
| 36 var outDir = path.resolve(RELEASE_PATH, '..'); | 51 var outDir = path.resolve(RELEASE_PATH, '..'); |
| 37 if (!IS_DEBUG_ENABLED) | 52 if (!IS_DEBUG_ENABLED) |
| 38 compileFrontend(); | 53 compileFrontend(); |
| 39 | 54 |
| 40 runTests(outDir, IS_DEBUG_ENABLED); | 55 runTests(outDir, IS_DEBUG_ENABLED); |
| 41 return; | 56 return; |
| 42 } | 57 } |
| 43 if (!utils.isDir(CACHE_PATH)) | 58 |
| 44 fs.mkdirSync(CACHE_PATH); | |
| 45 deleteOldContentShells(); | |
| 46 findPreviousUploadedPosition(findMostRecentChromiumCommit()).then(onUploadedCo
mmitPosition).catch(onError); | 59 findPreviousUploadedPosition(findMostRecentChromiumCommit()).then(onUploadedCo
mmitPosition).catch(onError); |
| 47 | 60 |
| 48 function onError(error) { | 61 function onError(error) { |
| 49 console.log('Unable to run tests because of error:', error); | 62 console.log('Unable to run tests because of error:', error); |
| 50 console.log(`Try removing the .test_cache folder [${CACHE_PATH}] and retryin
g`); | 63 console.log(`Try removing the .test_cache folder [${CACHE_PATH}] and retryin
g`); |
| 51 } | 64 } |
| 52 } | 65 } |
| 53 main(); | 66 main(); |
| 54 | 67 |
| 68 function runCompatibilityTests() { |
| 69 const folder = `compat-protocol-${COMPAT_PROTOCOL}`; |
| 70 compileFrontend(); |
| 71 var outPath = path.resolve(CACHE_PATH, folder, 'out'); |
| 72 var contentShellDirPath = path.resolve(outPath, 'Release'); |
| 73 var hasCachedContentShell = utils.isFile(getContentShellBinaryPath(contentShel
lDirPath)); |
| 74 if (hasCachedContentShell) { |
| 75 console.log(`Using cached content shell at: ${outPath}`); |
| 76 copyFrontendToCompatBuildPath(contentShellDirPath, RELEASE_PATH); |
| 77 runTests(outPath, IS_DEBUG_ENABLED); |
| 78 return; |
| 79 } |
| 80 prepareContentShellDirectory(folder) |
| 81 .then(() => downloadContentShell(COMPAT_URL_MAPPING[COMPAT_PROTOCOL], fold
er)) |
| 82 .then(extractContentShell) |
| 83 .then(() => copyFrontendToCompatBuildPath(contentShellDirPath, RELEASE_PAT
H)) |
| 84 .then(() => runTests(outPath, IS_DEBUG_ENABLED)); |
| 85 } |
| 86 |
| 55 function compileFrontend() { | 87 function compileFrontend() { |
| 56 console.log('Compiling devtools frontend'); | 88 console.log('Compiling devtools frontend'); |
| 57 try { | 89 try { |
| 58 shell(`ninja -C ${RELEASE_PATH} devtools_frontend_resources`); | 90 shell(`ninja -C ${RELEASE_PATH} devtools_frontend_resources`); |
| 59 } catch (err) { | 91 } catch (err) { |
| 60 console.log(err.stdout.toString()); | 92 console.log(err.stdout.toString()); |
| 61 console.log('ERROR: Cannot compile frontend\n' + err); | 93 console.log('ERROR: Cannot compile frontend\n' + err); |
| 62 process.exit(1); | 94 process.exit(1); |
| 63 } | 95 } |
| 64 } | 96 } |
| 65 | 97 |
| 66 function onUploadedCommitPosition(commitPosition) { | 98 function onUploadedCommitPosition(commitPosition) { |
| 67 var contentShellDirPath = path.resolve(CACHE_PATH, commitPosition, 'out', 'Rel
ease'); | 99 var contentShellDirPath = path.resolve(CACHE_PATH, commitPosition, 'out', 'Rel
ease'); |
| 68 var contentShellResourcesPath = path.resolve(contentShellDirPath, 'resources')
; | 100 var contentShellResourcesPath = path.resolve(contentShellDirPath, 'resources')
; |
| 69 var contentShellPath = path.resolve(CACHE_PATH, commitPosition, 'out'); | 101 var contentShellPath = path.resolve(CACHE_PATH, commitPosition, 'out'); |
| 70 | 102 |
| 71 var hasCachedContentShell = utils.isFile(getContentShellBinaryPath(contentShel
lDirPath)); | 103 var hasCachedContentShell = utils.isFile(getContentShellBinaryPath(contentShel
lDirPath)); |
| 72 if (hasCachedContentShell) { | 104 if (hasCachedContentShell) { |
| 73 console.log(`Using cached content shell at: ${contentShellPath}`); | 105 console.log(`Using cached content shell at: ${contentShellPath}`); |
| 74 copyFrontend(contentShellResourcesPath); | 106 copyFrontend(contentShellResourcesPath); |
| 75 return runTests(contentShellPath, true); | 107 return runTests(contentShellPath, true); |
| 76 } | 108 } |
| 109 var url = `http://commondatastorage.googleapis.com/chromium-browser-snapshots/
${PLATFORM}/${commitPosition |
| 110 }/${CONTENT_SHELL_ZIP}`; |
| 77 return prepareContentShellDirectory(commitPosition) | 111 return prepareContentShellDirectory(commitPosition) |
| 78 .then(downloadContentShell) | 112 .then(() => downloadContentShell(url, commitPosition)) |
| 79 .then(extractContentShell) | 113 .then(extractContentShell) |
| 80 .then(() => copyFrontend(contentShellResourcesPath)) | 114 .then(() => copyFrontend(contentShellResourcesPath)) |
| 81 .then(() => runTests(contentShellPath, true)); | 115 .then(() => runTests(contentShellPath, true)); |
| 82 } | 116 } |
| 83 | 117 |
| 118 function copyFrontendToCompatBuildPath(compatBuildPath, latestBuildPath) { |
| 119 var customDevtoolsResourcesPath = path.resolve(compatBuildPath, 'resources'); |
| 120 var latestDevtoolsInspectorPath = path.resolve(latestBuildPath, 'resources', '
inspector'); |
| 121 var copiedFrontendPath = path.resolve(customDevtoolsResourcesPath, 'inspector'
); |
| 122 if (utils.isDir(copiedFrontendPath)) |
| 123 utils.removeRecursive(copiedFrontendPath); |
| 124 utils.copyRecursive(latestDevtoolsInspectorPath, customDevtoolsResourcesPath); |
| 125 } |
| 126 |
| 84 function copyFrontend(contentShellResourcesPath) { | 127 function copyFrontend(contentShellResourcesPath) { |
| 85 var devtoolsResourcesPath = path.resolve(contentShellResourcesPath, 'inspector
'); | 128 var devtoolsResourcesPath = path.resolve(contentShellResourcesPath, 'inspector
'); |
| 86 var copiedFrontendPath = path.resolve(devtoolsResourcesPath, 'front_end'); | 129 var copiedFrontendPath = path.resolve(devtoolsResourcesPath, 'front_end'); |
| 87 var debugFrontendPath = path.resolve(devtoolsResourcesPath, 'debug'); | 130 var debugFrontendPath = path.resolve(devtoolsResourcesPath, 'debug'); |
| 88 var inspectorBackendCommandsPath = path.resolve(devtoolsResourcesPath, 'Inspec
torBackendCommands.js'); | 131 var inspectorBackendCommandsPath = path.resolve(devtoolsResourcesPath, 'Inspec
torBackendCommands.js'); |
| 89 var supportedCSSPropertiesPath = path.resolve(devtoolsResourcesPath, 'Supporte
dCSSProperties.js'); | 132 var supportedCSSPropertiesPath = path.resolve(devtoolsResourcesPath, 'Supporte
dCSSProperties.js'); |
| 90 utils.removeRecursive(copiedFrontendPath); | 133 utils.removeRecursive(copiedFrontendPath); |
| 91 utils.removeRecursive(debugFrontendPath); | 134 utils.removeRecursive(debugFrontendPath); |
| 92 utils.copyRecursive(SOURCE_PATH, devtoolsResourcesPath); | 135 utils.copyRecursive(SOURCE_PATH, devtoolsResourcesPath); |
| 93 fs.renameSync(copiedFrontendPath, debugFrontendPath); | 136 fs.renameSync(copiedFrontendPath, debugFrontendPath); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 onError(); | 195 onError(); |
| 153 } | 196 } |
| 154 | 197 |
| 155 function onError(error) { | 198 function onError(error) { |
| 156 if (error) | 199 if (error) |
| 157 console.log(`Received error: ${error} trying to fetch positions list from
url: ${positionsListURL}`); | 200 console.log(`Received error: ${error} trying to fetch positions list from
url: ${positionsListURL}`); |
| 158 throw new Error(`Unable to find a previous upload position for commit positi
on: ${commitPosition}`); | 201 throw new Error(`Unable to find a previous upload position for commit positi
on: ${commitPosition}`); |
| 159 } | 202 } |
| 160 } | 203 } |
| 161 | 204 |
| 162 function prepareContentShellDirectory(contentShellCommitPosition) { | 205 function prepareContentShellDirectory(folder) { |
| 163 var contentShellPath = path.join(CACHE_PATH, contentShellCommitPosition); | 206 var contentShellPath = path.join(CACHE_PATH, folder); |
| 164 if (utils.isDir(contentShellPath)) | 207 if (utils.isDir(contentShellPath)) |
| 165 utils.removeRecursive(contentShellPath); | 208 utils.removeRecursive(contentShellPath); |
| 166 fs.mkdirSync(contentShellPath); | 209 fs.mkdirSync(contentShellPath); |
| 167 return Promise.resolve(contentShellCommitPosition); | 210 return Promise.resolve(folder); |
| 168 } | 211 } |
| 169 | 212 |
| 170 function downloadContentShell(commitPosition) { | 213 function downloadContentShell(url, folder) { |
| 171 var url = `http://commondatastorage.googleapis.com/chromium-browser-snapshots/
${PLATFORM}/${commitPosition | |
| 172 }/${CONTENT_SHELL_ZIP}`; | |
| 173 console.log('Downloading content shell from:', url); | 214 console.log('Downloading content shell from:', url); |
| 174 console.log('NOTE: Download is ~35-65 MB depending on OS'); | 215 console.log('NOTE: Download is ~35-65 MB depending on OS'); |
| 175 return utils.fetch(url).then(writeZip).catch(onError); | 216 return utils.fetch(url).then(writeZip).catch(onError); |
| 176 | 217 |
| 177 function writeZip(buffer) { | 218 function writeZip(buffer) { |
| 178 console.log('Completed download of content shell'); | 219 console.log('Completed download of content shell'); |
| 179 var contentShellZipPath = path.join(CACHE_PATH, commitPosition, CONTENT_SHEL
L_ZIP); | 220 var contentShellZipPath = path.join(CACHE_PATH, folder, CONTENT_SHELL_ZIP); |
| 180 fs.writeFileSync(contentShellZipPath, buffer); | 221 fs.writeFileSync(contentShellZipPath, buffer); |
| 181 return contentShellZipPath; | 222 return contentShellZipPath; |
| 182 } | 223 } |
| 183 | 224 |
| 184 function onError(error) { | 225 function onError(error) { |
| 185 console.log(`Received error: ${error} trying to download content shell from
url: ${url}`); | 226 console.log(`Received error: ${error} trying to download content shell from
url: ${url}`); |
| 186 throw new Error('Unable to download content shell'); | 227 throw new Error('Unable to download content shell'); |
| 187 } | 228 } |
| 188 } | 229 } |
| 189 | 230 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 var testArgs = getInspectorTests().concat([ | 263 var testArgs = getInspectorTests().concat([ |
| 223 '--no-pixel-tests', | 264 '--no-pixel-tests', |
| 224 '--build-directory', | 265 '--build-directory', |
| 225 buildDirectoryPath, | 266 buildDirectoryPath, |
| 226 ]); | 267 ]); |
| 227 if (useDebugDevtools) | 268 if (useDebugDevtools) |
| 228 testArgs.push('--additional-driver-flag=--debug-devtools'); | 269 testArgs.push('--additional-driver-flag=--debug-devtools'); |
| 229 else | 270 else |
| 230 console.log('TIP: You can debug a test using: npm run debug-test inspector/t
est-name.html'); | 271 console.log('TIP: You can debug a test using: npm run debug-test inspector/t
est-name.html'); |
| 231 | 272 |
| 273 if (COMPAT_PROTOCOL) { |
| 274 let platform = `protocol-${COMPAT_PROTOCOL}`; |
| 275 let compatBaselinePath = path.resolve(DEVTOOLS_PATH, 'tests', 'baseline', pl
atform); |
| 276 testArgs.push(`--additional-platform-directory=${compatBaselinePath}`); |
| 277 } |
| 232 if (IS_DEBUG_ENABLED) { | 278 if (IS_DEBUG_ENABLED) { |
| 233 testArgs.push('--additional-driver-flag=--remote-debugging-port=9222'); | 279 testArgs.push('--additional-driver-flag=--remote-debugging-port=9222'); |
| 234 testArgs.push('--time-out-ms=6000000'); | 280 testArgs.push('--time-out-ms=6000000'); |
| 235 console.log('\n============================================='); | 281 console.log('\n============================================='); |
| 236 console.log('Go to: http://localhost:9222/'); | 282 console.log('Go to: http://localhost:9222/'); |
| 237 console.log('Click on link and in console execute: test()'); | 283 console.log('Click on link and in console execute: test()'); |
| 238 console.log('=============================================\n'); | 284 console.log('=============================================\n'); |
| 239 } | 285 } |
| 240 var args = [BLINK_TEST_PATH].concat(testArgs).concat(getTestFlags()); | 286 var args = [BLINK_TEST_PATH].concat(testArgs).concat(getTestFlags()); |
| 241 console.log(`Running layout tests with args: ${args}`); | 287 console.log(`Running layout tests with args: ${args}`); |
| 242 childProcess.spawn(PYTHON, args, {stdio: 'inherit'}); | 288 childProcess.spawn(PYTHON, args, {stdio: 'inherit'}); |
| 243 } | 289 } |
| 244 | 290 |
| 245 function getTestFlags() { | 291 function getTestFlags() { |
| 246 var flagValues = Object.keys(Flags).map(key => Flags[key]); | 292 var flagValues = Object.keys(Flags).map(key => Flags[key]); |
| 247 return process.argv.slice(2).filter(arg => !utils.includes(flagValues, arg) &&
!utils.includes(arg, 'inspector')); | 293 return process.argv.slice(2).filter(arg => { |
| 294 var flagName = utils.includes(arg, '=') ? arg.slice(0, arg.indexOf('=')) : a
rg; |
| 295 return !utils.includes(flagValues, flagName) && !utils.includes(arg, 'inspec
tor'); |
| 296 }); |
| 248 } | 297 } |
| 249 | 298 |
| 250 function getInspectorTests() { | 299 function getInspectorTests() { |
| 251 var specificTests = process.argv.filter(arg => utils.includes(arg, 'inspector'
)); | 300 var specificTests = process.argv.filter(arg => utils.includes(arg, 'inspector'
)); |
| 252 if (specificTests.length) | 301 if (specificTests.length) |
| 253 return specificTests; | 302 return specificTests; |
| 254 return [ | 303 return [ |
| 255 'inspector*', | 304 'inspector*', |
| 256 'http/tests/inspector*', | 305 'http/tests/inspector*', |
| 257 ]; | 306 ]; |
| 258 } | 307 } |
| OLD | NEW |