Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Yang Guo | b7a4426 | 2019-11-05 15:25:23 +0100 | [diff] [blame] | 5 | const childProcess = require('child_process'); |
| 6 | const fs = require('fs'); |
| 7 | const path = require('path'); |
Yang Guo | b7a4426 | 2019-11-05 15:25:23 +0100 | [diff] [blame] | 8 | const utils = require('./utils'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 9 | |
Yang Guo | b7a4426 | 2019-11-05 15:25:23 +0100 | [diff] [blame] | 10 | const Flags = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 11 | DEBUG_DEVTOOLS: '--debug-devtools', |
| 12 | DEBUG_DEVTOOLS_SHORTHAND: '-d', |
| 13 | FETCH_CONTENT_SHELL: '--fetch-content-shell', |
| 14 | CHROMIUM_PATH: '--chromium-path', // useful for bisecting |
| 15 | TARGET: '--target', // build sub-directory (e.g. Release, Default) |
| 16 | }; |
| 17 | |
Yang Guo | b7a4426 | 2019-11-05 15:25:23 +0100 | [diff] [blame] | 18 | const IS_DEBUG_ENABLED = |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 19 | utils.includes(process.argv, Flags.DEBUG_DEVTOOLS) || utils.includes(process.argv, Flags.DEBUG_DEVTOOLS_SHORTHAND); |
Yang Guo | b7a4426 | 2019-11-05 15:25:23 +0100 | [diff] [blame] | 20 | const CUSTOM_CHROMIUM_PATH = utils.parseArgs(process.argv)[Flags.CHROMIUM_PATH]; |
Yang Guo | b7a4426 | 2019-11-05 15:25:23 +0100 | [diff] [blame] | 21 | const TARGET = utils.parseArgs(process.argv)[Flags.TARGET] || 'Release'; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 22 | |
Yang Guo | b7a4426 | 2019-11-05 15:25:23 +0100 | [diff] [blame] | 23 | const PYTHON = process.platform === 'win32' ? 'python.bat' : 'python'; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 24 | |
Paul Lewis | 4d806b9 | 2020-03-13 14:51:06 +0000 | [diff] [blame] | 25 | const CURRENT_PATH = process.env.PWD || process.cwd(); // Using env.PWD to account for symlinks. |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 26 | const isThirdParty = CURRENT_PATH.includes('third_party'); |
| 27 | const CHROMIUM_SRC_PATH = CUSTOM_CHROMIUM_PATH || getChromiumSrcPath(isThirdParty); |
Yang Guo | b7a4426 | 2019-11-05 15:25:23 +0100 | [diff] [blame] | 28 | const RELEASE_PATH = path.resolve(CHROMIUM_SRC_PATH, 'out', TARGET); |
| 29 | const BLINK_TEST_PATH = path.resolve(CHROMIUM_SRC_PATH, 'third_party', 'blink', 'tools', 'run_web_tests.py'); |
| 30 | const DEVTOOLS_PATH = path.resolve(CHROMIUM_SRC_PATH, 'third_party', 'devtools-frontend', 'src'); |
| 31 | const CACHE_PATH = path.resolve(DEVTOOLS_PATH, '.test_cache'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 32 | |
| 33 | function main() { |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 34 | if (!utils.isDir(CACHE_PATH)) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 35 | fs.mkdirSync(CACHE_PATH); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 36 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 37 | |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 38 | const hasUserCompiledContentShell = utils.isFile(getContentShellBinaryPath(RELEASE_PATH)); |
Tim van der Lippe | 26bb5ad | 2020-06-01 11:54:14 +0100 | [diff] [blame] | 39 | if (!hasUserCompiledContentShell) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 40 | return; |
| 41 | } |
Tim van der Lippe | 26bb5ad | 2020-06-01 11:54:14 +0100 | [diff] [blame] | 42 | const outDir = path.resolve(RELEASE_PATH, '..'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 43 | |
Tim van der Lippe | 26bb5ad | 2020-06-01 11:54:14 +0100 | [diff] [blame] | 44 | runTests(outDir, IS_DEBUG_ENABLED); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 45 | } |
| 46 | main(); |
| 47 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 48 | |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 49 | function getChromiumSrcPath(isThirdParty) { |
| 50 | if (isThirdParty) |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 51 | // Assume we're in `chromium/src/third_party/devtools-frontend/src`. |
| 52 | { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 53 | return path.resolve(CURRENT_PATH, '..', '..', '..'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 54 | } |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 55 | // Assume we're in `devtools/devtools-frontend`, where `devtools` is |
| 56 | // on the same level as `chromium`. |
| 57 | const srcPath = path.resolve(CURRENT_PATH, '..', '..', 'chromium', 'src'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 58 | if (!utils.isDir(srcPath)) { |
| 59 | throw new Error( |
| 60 | `Chromium source directory not found at \`${srcPath}\`. ` + |
| 61 | 'Either move your standalone `devtools/devtools-frontend` checkout ' + |
| 62 | 'so that `devtools` is at the same level as `chromium` in ' + |
| 63 | '`chromium/src`, or use `--chromium-path`.'); |
| 64 | } |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 65 | return srcPath; |
| 66 | } |
| 67 | |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 68 | function getContentShellBinaryPath(dirPath) { |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 69 | if (process.platform === 'linux') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 70 | return path.resolve(dirPath, 'content_shell'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 71 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 72 | |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 73 | if (process.platform === 'win32') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 74 | return path.resolve(dirPath, 'content_shell.exe'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 75 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 76 | |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 77 | if (process.platform === 'darwin') { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 78 | return path.resolve(dirPath, 'Content Shell.app', 'Contents', 'MacOS', 'Content Shell'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 79 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | function runTests(buildDirectoryPath, useDebugDevtools) { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 83 | const testArgs = getInspectorTests().concat([ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 84 | '--build-directory', |
| 85 | buildDirectoryPath, |
| 86 | '--target', |
| 87 | TARGET, |
| 88 | ]); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 89 | if (useDebugDevtools) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 90 | testArgs.push('--additional-driver-flag=--debug-devtools'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 91 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 92 | console.log('TIP: You can debug a test using: npm run debug-test inspector/test-name.html'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 93 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 94 | |
| 95 | if (IS_DEBUG_ENABLED) { |
| 96 | testArgs.push('--additional-driver-flag=--remote-debugging-port=9222'); |
| 97 | testArgs.push('--time-out-ms=6000000'); |
| 98 | console.log('\n============================================='); |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 99 | const unitTest = testArgs.find(arg => arg.includes('http/tests/devtools/unit/')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 100 | if (unitTest) { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 101 | const unitTestPath = `http://localhost:8080/${unitTest.slice('http/tests/'.length)}`; |
| 102 | const link = |
Yang Guo | 49346f1 | 2020-02-06 10:52:02 +0100 | [diff] [blame] | 103 | `http://localhost:8080/inspector-sources/debug/integration_test_runner.html?test=${unitTestPath}`; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 104 | console.log('1) Go to: ', link); |
| 105 | console.log('2) Go to: http://localhost:9222/, click on "inspected-page.html", and copy the ws query parameter'); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 106 | console.log('3) Open DevTools on DevTools and you can refresh to re-run the test'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 107 | } else { |
| 108 | console.log('Go to: http://localhost:9222/'); |
| 109 | console.log('Click on link and in console execute: test()'); |
| 110 | } |
| 111 | console.log('=============================================\n'); |
| 112 | } |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 113 | const args = [BLINK_TEST_PATH].concat(testArgs).concat(getTestFlags()); |
Mathias Bynens | b0693f2 | 2020-01-23 13:17:15 +0100 | [diff] [blame] | 114 | console.log(`Running web tests with args: ${args.join(' ')}`); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 115 | childProcess.spawn(PYTHON, args, {stdio: 'inherit'}); |
| 116 | } |
| 117 | |
| 118 | function getTestFlags() { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 119 | const flagValues = Object.keys(Flags).map(key => Flags[key]); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 120 | return process.argv.slice(2).filter(arg => { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 121 | const flagName = utils.includes(arg, '=') ? arg.slice(0, arg.indexOf('=')) : arg; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 122 | return !utils.includes(flagValues, flagName) && !utils.includes(arg, 'inspector') && |
| 123 | !utils.includes(arg, 'http/tests/devtools'); |
| 124 | }); |
| 125 | } |
| 126 | |
| 127 | function getInspectorTests() { |
Mathias Bynens | 9866999 | 2019-11-28 08:50:08 +0100 | [diff] [blame] | 128 | const specificTests = |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 129 | process.argv.filter(arg => utils.includes(arg, 'inspector') || utils.includes(arg, 'http/tests/devtools')); |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 130 | if (specificTests.length) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 131 | return specificTests; |
Tim van der Lippe | ba26b2b | 2020-03-11 14:40:00 +0000 | [diff] [blame] | 132 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 133 | return [ |
| 134 | 'inspector*', |
| 135 | 'http/tests/inspector*', |
| 136 | 'http/tests/devtools', |
| 137 | ]; |
Kent Tamura | d3d3f04 | 2018-12-12 02:45:28 +0000 | [diff] [blame] | 138 | } |