blob: a0fcfd5261127d0c932cd8425af273969d55a523 [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:37 +00001// 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 Guob7a44262019-11-05 15:25:23 +01005const childProcess = require('child_process');
6const fs = require('fs');
7const path = require('path');
Yang Guob7a44262019-11-05 15:25:23 +01008const utils = require('./utils');
Blink Reformat4c46d092018-04-07 15:32:37 +00009
Yang Guob7a44262019-11-05 15:25:23 +010010const Flags = {
Blink Reformat4c46d092018-04-07 15:32:37 +000011 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 Guob7a44262019-11-05 15:25:23 +010018const IS_DEBUG_ENABLED =
Blink Reformat4c46d092018-04-07 15:32:37 +000019 utils.includes(process.argv, Flags.DEBUG_DEVTOOLS) || utils.includes(process.argv, Flags.DEBUG_DEVTOOLS_SHORTHAND);
Yang Guob7a44262019-11-05 15:25:23 +010020const CUSTOM_CHROMIUM_PATH = utils.parseArgs(process.argv)[Flags.CHROMIUM_PATH];
Yang Guob7a44262019-11-05 15:25:23 +010021const TARGET = utils.parseArgs(process.argv)[Flags.TARGET] || 'Release';
Blink Reformat4c46d092018-04-07 15:32:37 +000022
Paul Lewis4d806b92020-03-13 14:51:06 +000023const CURRENT_PATH = process.env.PWD || process.cwd(); // Using env.PWD to account for symlinks.
Mathias Bynens98669992019-11-28 08:50:08 +010024const isThirdParty = CURRENT_PATH.includes('third_party');
25const CHROMIUM_SRC_PATH = CUSTOM_CHROMIUM_PATH || getChromiumSrcPath(isThirdParty);
Yang Guob7a44262019-11-05 15:25:23 +010026const RELEASE_PATH = path.resolve(CHROMIUM_SRC_PATH, 'out', TARGET);
27const BLINK_TEST_PATH = path.resolve(CHROMIUM_SRC_PATH, 'third_party', 'blink', 'tools', 'run_web_tests.py');
28const DEVTOOLS_PATH = path.resolve(CHROMIUM_SRC_PATH, 'third_party', 'devtools-frontend', 'src');
29const CACHE_PATH = path.resolve(DEVTOOLS_PATH, '.test_cache');
Blink Reformat4c46d092018-04-07 15:32:37 +000030
31function main() {
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000032 if (!utils.isDir(CACHE_PATH)) {
Blink Reformat4c46d092018-04-07 15:32:37 +000033 fs.mkdirSync(CACHE_PATH);
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000034 }
Blink Reformat4c46d092018-04-07 15:32:37 +000035
Mathias Bynens98669992019-11-28 08:50:08 +010036 const hasUserCompiledContentShell = utils.isFile(getContentShellBinaryPath(RELEASE_PATH));
Tim van der Lippe26bb5ad2020-06-01 11:54:14 +010037 if (!hasUserCompiledContentShell) {
Blink Reformat4c46d092018-04-07 15:32:37 +000038 return;
39 }
Tim van der Lippe26bb5ad2020-06-01 11:54:14 +010040 const outDir = path.resolve(RELEASE_PATH, '..');
Blink Reformat4c46d092018-04-07 15:32:37 +000041
Tim van der Lippe26bb5ad2020-06-01 11:54:14 +010042 runTests(outDir, IS_DEBUG_ENABLED);
Blink Reformat4c46d092018-04-07 15:32:37 +000043}
44main();
45
Mathias Bynens98669992019-11-28 08:50:08 +010046function getChromiumSrcPath(isThirdParty) {
47 if (isThirdParty)
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000048 // Assume we're in `chromium/src/third_party/devtools-frontend/src`.
49 {
Mathias Bynens98669992019-11-28 08:50:08 +010050 return path.resolve(CURRENT_PATH, '..', '..', '..');
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000051 }
Mathias Bynens98669992019-11-28 08:50:08 +010052 // Assume we're in `devtools/devtools-frontend`, where `devtools` is
53 // on the same level as `chromium`.
54 const srcPath = path.resolve(CURRENT_PATH, '..', '..', 'chromium', 'src');
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000055 if (!utils.isDir(srcPath)) {
56 throw new Error(
57 `Chromium source directory not found at \`${srcPath}\`. ` +
58 'Either move your standalone `devtools/devtools-frontend` checkout ' +
59 'so that `devtools` is at the same level as `chromium` in ' +
60 '`chromium/src`, or use `--chromium-path`.');
61 }
Mathias Bynens98669992019-11-28 08:50:08 +010062 return srcPath;
63}
64
Blink Reformat4c46d092018-04-07 15:32:37 +000065function getContentShellBinaryPath(dirPath) {
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000066 if (process.platform === 'linux') {
Blink Reformat4c46d092018-04-07 15:32:37 +000067 return path.resolve(dirPath, 'content_shell');
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000068 }
Blink Reformat4c46d092018-04-07 15:32:37 +000069
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000070 if (process.platform === 'win32') {
Blink Reformat4c46d092018-04-07 15:32:37 +000071 return path.resolve(dirPath, 'content_shell.exe');
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000072 }
Blink Reformat4c46d092018-04-07 15:32:37 +000073
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000074 if (process.platform === 'darwin') {
Blink Reformat4c46d092018-04-07 15:32:37 +000075 return path.resolve(dirPath, 'Content Shell.app', 'Contents', 'MacOS', 'Content Shell');
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000076 }
Blink Reformat4c46d092018-04-07 15:32:37 +000077}
78
79function runTests(buildDirectoryPath, useDebugDevtools) {
Mathias Bynens98669992019-11-28 08:50:08 +010080 const testArgs = getInspectorTests().concat([
Blink Reformat4c46d092018-04-07 15:32:37 +000081 '--build-directory',
82 buildDirectoryPath,
83 '--target',
84 TARGET,
85 ]);
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000086 if (useDebugDevtools) {
Blink Reformat4c46d092018-04-07 15:32:37 +000087 testArgs.push('--additional-driver-flag=--debug-devtools');
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000088 } else {
Blink Reformat4c46d092018-04-07 15:32:37 +000089 console.log('TIP: You can debug a test using: npm run debug-test inspector/test-name.html');
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000090 }
Blink Reformat4c46d092018-04-07 15:32:37 +000091
92 if (IS_DEBUG_ENABLED) {
93 testArgs.push('--additional-driver-flag=--remote-debugging-port=9222');
Weizhong Xia9e9e0ec2022-02-11 20:32:17 +000094 testArgs.push('--timeout-ms=6000000');
Blink Reformat4c46d092018-04-07 15:32:37 +000095 console.log('\n=============================================');
Mathias Bynens98669992019-11-28 08:50:08 +010096 const unitTest = testArgs.find(arg => arg.includes('http/tests/devtools/unit/'));
Blink Reformat4c46d092018-04-07 15:32:37 +000097 if (unitTest) {
Mathias Bynens98669992019-11-28 08:50:08 +010098 const unitTestPath = `http://localhost:8080/${unitTest.slice('http/tests/'.length)}`;
99 const link =
Yang Guo49346f12020-02-06 10:52:02 +0100100 `http://localhost:8080/inspector-sources/debug/integration_test_runner.html?test=${unitTestPath}`;
Blink Reformat4c46d092018-04-07 15:32:37 +0000101 console.log('1) Go to: ', link);
102 console.log('2) Go to: http://localhost:9222/, click on "inspected-page.html", and copy the ws query parameter');
Tim van der Lippeba26b2b2020-03-11 14:40:00 +0000103 console.log('3) Open DevTools on DevTools and you can refresh to re-run the test');
Blink Reformat4c46d092018-04-07 15:32:37 +0000104 } else {
105 console.log('Go to: http://localhost:9222/');
106 console.log('Click on link and in console execute: test()');
107 }
108 console.log('=============================================\n');
109 }
Tim van der Lippe03097b02020-11-27 16:25:37 +0000110 const args = [...testArgs, ...getTestFlags()];
Mathias Bynensb0693f22020-01-23 13:17:15 +0100111 console.log(`Running web tests with args: ${args.join(' ')}`);
Tim van der Lippe03097b02020-11-27 16:25:37 +0000112 childProcess.spawn(BLINK_TEST_PATH, args, {stdio: 'inherit'});
Blink Reformat4c46d092018-04-07 15:32:37 +0000113}
114
115function getTestFlags() {
Mathias Bynens98669992019-11-28 08:50:08 +0100116 const flagValues = Object.keys(Flags).map(key => Flags[key]);
Blink Reformat4c46d092018-04-07 15:32:37 +0000117 return process.argv.slice(2).filter(arg => {
Mathias Bynens98669992019-11-28 08:50:08 +0100118 const flagName = utils.includes(arg, '=') ? arg.slice(0, arg.indexOf('=')) : arg;
Blink Reformat4c46d092018-04-07 15:32:37 +0000119 return !utils.includes(flagValues, flagName) && !utils.includes(arg, 'inspector') &&
120 !utils.includes(arg, 'http/tests/devtools');
121 });
122}
123
124function getInspectorTests() {
Mathias Bynens98669992019-11-28 08:50:08 +0100125 const specificTests =
Blink Reformat4c46d092018-04-07 15:32:37 +0000126 process.argv.filter(arg => utils.includes(arg, 'inspector') || utils.includes(arg, 'http/tests/devtools'));
Tim van der Lippeba26b2b2020-03-11 14:40:00 +0000127 if (specificTests.length) {
Blink Reformat4c46d092018-04-07 15:32:37 +0000128 return specificTests;
Tim van der Lippeba26b2b2020-03-11 14:40:00 +0000129 }
Blink Reformat4c46d092018-04-07 15:32:37 +0000130 return [
131 'inspector*',
132 'http/tests/inspector*',
133 'http/tests/devtools',
134 ];
Kent Tamurad3d3f042018-12-12 02:45:28 +0000135}