blob: e45c77a39a8282128507c10d3f559da812532013 [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371// 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 14:25:235const childProcess = require('child_process');
6const fs = require('fs');
7const path = require('path');
Nikolay Vitkov41c69112025-01-31 15:20:048
Yang Guob7a44262019-11-05 14:25:239const utils = require('./utils');
Blink Reformat4c46d092018-04-07 15:32:3710
Yang Guob7a44262019-11-05 14:25:2311const Flags = {
Blink Reformat4c46d092018-04-07 15:32:3712 DEBUG_DEVTOOLS: '--debug-devtools',
13 DEBUG_DEVTOOLS_SHORTHAND: '-d',
14 FETCH_CONTENT_SHELL: '--fetch-content-shell',
15 CHROMIUM_PATH: '--chromium-path', // useful for bisecting
16 TARGET: '--target', // build sub-directory (e.g. Release, Default)
17};
18
Yang Guob7a44262019-11-05 14:25:2319const IS_DEBUG_ENABLED =
Blink Reformat4c46d092018-04-07 15:32:3720 utils.includes(process.argv, Flags.DEBUG_DEVTOOLS) || utils.includes(process.argv, Flags.DEBUG_DEVTOOLS_SHORTHAND);
Yang Guob7a44262019-11-05 14:25:2321const CUSTOM_CHROMIUM_PATH = utils.parseArgs(process.argv)[Flags.CHROMIUM_PATH];
Yang Guob7a44262019-11-05 14:25:2322const TARGET = utils.parseArgs(process.argv)[Flags.TARGET] || 'Release';
Blink Reformat4c46d092018-04-07 15:32:3723
Paul Lewis4d806b92020-03-13 14:51:0624const CURRENT_PATH = process.env.PWD || process.cwd(); // Using env.PWD to account for symlinks.
Mathias Bynens98669992019-11-28 07:50:0825const isThirdParty = CURRENT_PATH.includes('third_party');
26const CHROMIUM_SRC_PATH = CUSTOM_CHROMIUM_PATH || getChromiumSrcPath(isThirdParty);
Yang Guob7a44262019-11-05 14:25:2327const RELEASE_PATH = path.resolve(CHROMIUM_SRC_PATH, 'out', TARGET);
28const BLINK_TEST_PATH = path.resolve(CHROMIUM_SRC_PATH, 'third_party', 'blink', 'tools', 'run_web_tests.py');
29const DEVTOOLS_PATH = path.resolve(CHROMIUM_SRC_PATH, 'third_party', 'devtools-frontend', 'src');
30const CACHE_PATH = path.resolve(DEVTOOLS_PATH, '.test_cache');
Blink Reformat4c46d092018-04-07 15:32:3731
32function main() {
Tim van der Lippeba26b2b2020-03-11 14:40:0033 if (!utils.isDir(CACHE_PATH)) {
Blink Reformat4c46d092018-04-07 15:32:3734 fs.mkdirSync(CACHE_PATH);
Tim van der Lippeba26b2b2020-03-11 14:40:0035 }
Blink Reformat4c46d092018-04-07 15:32:3736
Dustin J. Mitchell1526a1b2023-01-13 22:04:4937 const contentShellBinaryPath = getContentShellBinaryPath(RELEASE_PATH);
38 const hasUserCompiledContentShell = utils.isFile(contentShellBinaryPath);
Tim van der Lippe26bb5ad2020-06-01 10:54:1439 if (!hasUserCompiledContentShell) {
Dustin J. Mitchell1526a1b2023-01-13 22:04:4940 throw new Error(
41 `${contentShellBinaryPath} not found. ` +
42 'Ensure you have built a release version of `chrome` or use ' +
43 '`--target=Debug`.');
Blink Reformat4c46d092018-04-07 15:32:3744 }
Philip Pfaffe95700cc2025-06-27 12:43:1745 const outDir = path.resolve(RELEASE_PATH);
Blink Reformat4c46d092018-04-07 15:32:3746
Tim van der Lippe26bb5ad2020-06-01 10:54:1447 runTests(outDir, IS_DEBUG_ENABLED);
Blink Reformat4c46d092018-04-07 15:32:3748}
49main();
50
Mathias Bynens98669992019-11-28 07:50:0851function getChromiumSrcPath(isThirdParty) {
52 if (isThirdParty)
Tim van der Lippeba26b2b2020-03-11 14:40:0053 // Assume we're in `chromium/src/third_party/devtools-frontend/src`.
54 {
Mathias Bynens98669992019-11-28 07:50:0855 return path.resolve(CURRENT_PATH, '..', '..', '..');
Tim van der Lippeba26b2b2020-03-11 14:40:0056 }
Mathias Bynens98669992019-11-28 07:50:0857 // Assume we're in `devtools/devtools-frontend`, where `devtools` is
58 // on the same level as `chromium`.
59 const srcPath = path.resolve(CURRENT_PATH, '..', '..', 'chromium', 'src');
Tim van der Lippeba26b2b2020-03-11 14:40:0060 if (!utils.isDir(srcPath)) {
61 throw new Error(
62 `Chromium source directory not found at \`${srcPath}\`. ` +
63 'Either move your standalone `devtools/devtools-frontend` checkout ' +
64 'so that `devtools` is at the same level as `chromium` in ' +
65 '`chromium/src`, or use `--chromium-path`.');
66 }
Mathias Bynens98669992019-11-28 07:50:0867 return srcPath;
68}
69
Blink Reformat4c46d092018-04-07 15:32:3770function getContentShellBinaryPath(dirPath) {
Tim van der Lippeba26b2b2020-03-11 14:40:0071 if (process.platform === 'linux') {
Blink Reformat4c46d092018-04-07 15:32:3772 return path.resolve(dirPath, 'content_shell');
Tim van der Lippeba26b2b2020-03-11 14:40:0073 }
Blink Reformat4c46d092018-04-07 15:32:3774
Tim van der Lippeba26b2b2020-03-11 14:40:0075 if (process.platform === 'win32') {
Blink Reformat4c46d092018-04-07 15:32:3776 return path.resolve(dirPath, 'content_shell.exe');
Tim van der Lippeba26b2b2020-03-11 14:40:0077 }
Blink Reformat4c46d092018-04-07 15:32:3778
Tim van der Lippeba26b2b2020-03-11 14:40:0079 if (process.platform === 'darwin') {
Blink Reformat4c46d092018-04-07 15:32:3780 return path.resolve(dirPath, 'Content Shell.app', 'Contents', 'MacOS', 'Content Shell');
Tim van der Lippeba26b2b2020-03-11 14:40:0081 }
Blink Reformat4c46d092018-04-07 15:32:3782}
83
84function runTests(buildDirectoryPath, useDebugDevtools) {
Mathias Bynens98669992019-11-28 07:50:0885 const testArgs = getInspectorTests().concat([
Blink Reformat4c46d092018-04-07 15:32:3786 '--build-directory',
87 buildDirectoryPath,
88 '--target',
89 TARGET,
90 ]);
Tim van der Lippeba26b2b2020-03-11 14:40:0091 if (useDebugDevtools) {
Blink Reformat4c46d092018-04-07 15:32:3792 testArgs.push('--additional-driver-flag=--debug-devtools');
Tim van der Lippeba26b2b2020-03-11 14:40:0093 } else {
Blink Reformat4c46d092018-04-07 15:32:3794 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:0095 }
Blink Reformat4c46d092018-04-07 15:32:3796
97 if (IS_DEBUG_ENABLED) {
Philip Pfaffe75e3ab62023-03-01 11:33:1298 testArgs.push('--additional-driver-flag=--remote-allow-origins=*');
Blink Reformat4c46d092018-04-07 15:32:3799 testArgs.push('--additional-driver-flag=--remote-debugging-port=9222');
Weizhong Xia9e9e0ec2022-02-11 20:32:17100 testArgs.push('--timeout-ms=6000000');
Blink Reformat4c46d092018-04-07 15:32:37101 console.log('\n=============================================');
Mathias Bynens98669992019-11-28 07:50:08102 const unitTest = testArgs.find(arg => arg.includes('http/tests/devtools/unit/'));
Blink Reformat4c46d092018-04-07 15:32:37103 if (unitTest) {
Mathias Bynens98669992019-11-28 07:50:08104 const unitTestPath = `http://localhost:8080/${unitTest.slice('http/tests/'.length)}`;
105 const link =
Yang Guo49346f12020-02-06 09:52:02106 `http://localhost:8080/inspector-sources/debug/integration_test_runner.html?test=${unitTestPath}`;
Blink Reformat4c46d092018-04-07 15:32:37107 console.log('1) Go to: ', link);
108 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:00109 console.log('3) Open DevTools on DevTools and you can refresh to re-run the test');
Blink Reformat4c46d092018-04-07 15:32:37110 } else {
111 console.log('Go to: http://localhost:9222/');
112 console.log('Click on link and in console execute: test()');
113 }
114 console.log('=============================================\n');
115 }
Tim van der Lippe03097b02020-11-27 16:25:37116 const args = [...testArgs, ...getTestFlags()];
Mathias Bynensb0693f22020-01-23 12:17:15117 console.log(`Running web tests with args: ${args.join(' ')}`);
Tim van der Lippe03097b02020-11-27 16:25:37118 childProcess.spawn(BLINK_TEST_PATH, args, {stdio: 'inherit'});
Blink Reformat4c46d092018-04-07 15:32:37119}
120
121function getTestFlags() {
Mathias Bynens98669992019-11-28 07:50:08122 const flagValues = Object.keys(Flags).map(key => Flags[key]);
Blink Reformat4c46d092018-04-07 15:32:37123 return process.argv.slice(2).filter(arg => {
Mathias Bynens98669992019-11-28 07:50:08124 const flagName = utils.includes(arg, '=') ? arg.slice(0, arg.indexOf('=')) : arg;
Blink Reformat4c46d092018-04-07 15:32:37125 return !utils.includes(flagValues, flagName) && !utils.includes(arg, 'inspector') &&
126 !utils.includes(arg, 'http/tests/devtools');
127 });
128}
129
130function getInspectorTests() {
Mathias Bynens98669992019-11-28 07:50:08131 const specificTests =
Blink Reformat4c46d092018-04-07 15:32:37132 process.argv.filter(arg => utils.includes(arg, 'inspector') || utils.includes(arg, 'http/tests/devtools'));
Tim van der Lippeba26b2b2020-03-11 14:40:00133 if (specificTests.length) {
Blink Reformat4c46d092018-04-07 15:32:37134 return specificTests;
Tim van der Lippeba26b2b2020-03-11 14:40:00135 }
Blink Reformat4c46d092018-04-07 15:32:37136 return [
137 'inspector*',
138 'http/tests/inspector*',
139 'http/tests/devtools',
140 ];
Kent Tamurad3d3f042018-12-12 02:45:28141}