blob: 882ddda8329e34083fdcce13b505da86e842f6cb [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');
Yang Guob7a44262019-11-05 14:25:238const utils = require('./utils');
Blink Reformat4c46d092018-04-07 15:32:379
Yang Guob7a44262019-11-05 14:25:2310const Flags = {
Blink Reformat4c46d092018-04-07 15:32:3711 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 14:25:2318const IS_DEBUG_ENABLED =
Blink Reformat4c46d092018-04-07 15:32:3719 utils.includes(process.argv, Flags.DEBUG_DEVTOOLS) || utils.includes(process.argv, Flags.DEBUG_DEVTOOLS_SHORTHAND);
Yang Guob7a44262019-11-05 14:25:2320const CUSTOM_CHROMIUM_PATH = utils.parseArgs(process.argv)[Flags.CHROMIUM_PATH];
Yang Guob7a44262019-11-05 14:25:2321const TARGET = utils.parseArgs(process.argv)[Flags.TARGET] || 'Release';
Blink Reformat4c46d092018-04-07 15:32:3722
Paul Lewis4d806b92020-03-13 14:51:0623const CURRENT_PATH = process.env.PWD || process.cwd(); // Using env.PWD to account for symlinks.
Mathias Bynens98669992019-11-28 07:50:0824const isThirdParty = CURRENT_PATH.includes('third_party');
25const CHROMIUM_SRC_PATH = CUSTOM_CHROMIUM_PATH || getChromiumSrcPath(isThirdParty);
Yang Guob7a44262019-11-05 14:25:2326const 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:3730
31function main() {
Tim van der Lippeba26b2b2020-03-11 14:40:0032 if (!utils.isDir(CACHE_PATH)) {
Blink Reformat4c46d092018-04-07 15:32:3733 fs.mkdirSync(CACHE_PATH);
Tim van der Lippeba26b2b2020-03-11 14:40:0034 }
Blink Reformat4c46d092018-04-07 15:32:3735
Mathias Bynens98669992019-11-28 07:50:0836 const hasUserCompiledContentShell = utils.isFile(getContentShellBinaryPath(RELEASE_PATH));
Tim van der Lippe26bb5ad2020-06-01 10:54:1437 if (!hasUserCompiledContentShell) {
Blink Reformat4c46d092018-04-07 15:32:3738 return;
39 }
Tim van der Lippe26bb5ad2020-06-01 10:54:1440 const outDir = path.resolve(RELEASE_PATH, '..');
Blink Reformat4c46d092018-04-07 15:32:3741
Tim van der Lippe26bb5ad2020-06-01 10:54:1442 runTests(outDir, IS_DEBUG_ENABLED);
Blink Reformat4c46d092018-04-07 15:32:3743}
44main();
45
Blink Reformat4c46d092018-04-07 15:32:3746
Mathias Bynens98669992019-11-28 07:50:0847function getChromiumSrcPath(isThirdParty) {
48 if (isThirdParty)
Tim van der Lippeba26b2b2020-03-11 14:40:0049 // Assume we're in `chromium/src/third_party/devtools-frontend/src`.
50 {
Mathias Bynens98669992019-11-28 07:50:0851 return path.resolve(CURRENT_PATH, '..', '..', '..');
Tim van der Lippeba26b2b2020-03-11 14:40:0052 }
Mathias Bynens98669992019-11-28 07:50:0853 // Assume we're in `devtools/devtools-frontend`, where `devtools` is
54 // on the same level as `chromium`.
55 const srcPath = path.resolve(CURRENT_PATH, '..', '..', 'chromium', 'src');
Tim van der Lippeba26b2b2020-03-11 14:40:0056 if (!utils.isDir(srcPath)) {
57 throw new Error(
58 `Chromium source directory not found at \`${srcPath}\`. ` +
59 'Either move your standalone `devtools/devtools-frontend` checkout ' +
60 'so that `devtools` is at the same level as `chromium` in ' +
61 '`chromium/src`, or use `--chromium-path`.');
62 }
Mathias Bynens98669992019-11-28 07:50:0863 return srcPath;
64}
65
Blink Reformat4c46d092018-04-07 15:32:3766function getContentShellBinaryPath(dirPath) {
Tim van der Lippeba26b2b2020-03-11 14:40:0067 if (process.platform === 'linux') {
Blink Reformat4c46d092018-04-07 15:32:3768 return path.resolve(dirPath, 'content_shell');
Tim van der Lippeba26b2b2020-03-11 14:40:0069 }
Blink Reformat4c46d092018-04-07 15:32:3770
Tim van der Lippeba26b2b2020-03-11 14:40:0071 if (process.platform === 'win32') {
Blink Reformat4c46d092018-04-07 15:32:3772 return path.resolve(dirPath, 'content_shell.exe');
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 === 'darwin') {
Blink Reformat4c46d092018-04-07 15:32:3776 return path.resolve(dirPath, 'Content Shell.app', 'Contents', 'MacOS', 'Content Shell');
Tim van der Lippeba26b2b2020-03-11 14:40:0077 }
Blink Reformat4c46d092018-04-07 15:32:3778}
79
80function runTests(buildDirectoryPath, useDebugDevtools) {
Mathias Bynens98669992019-11-28 07:50:0881 const testArgs = getInspectorTests().concat([
Blink Reformat4c46d092018-04-07 15:32:3782 '--build-directory',
83 buildDirectoryPath,
84 '--target',
85 TARGET,
86 ]);
Tim van der Lippeba26b2b2020-03-11 14:40:0087 if (useDebugDevtools) {
Blink Reformat4c46d092018-04-07 15:32:3788 testArgs.push('--additional-driver-flag=--debug-devtools');
Tim van der Lippeba26b2b2020-03-11 14:40:0089 } else {
Blink Reformat4c46d092018-04-07 15:32:3790 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:0091 }
Blink Reformat4c46d092018-04-07 15:32:3792
93 if (IS_DEBUG_ENABLED) {
94 testArgs.push('--additional-driver-flag=--remote-debugging-port=9222');
95 testArgs.push('--time-out-ms=6000000');
96 console.log('\n=============================================');
Mathias Bynens98669992019-11-28 07:50:0897 const unitTest = testArgs.find(arg => arg.includes('http/tests/devtools/unit/'));
Blink Reformat4c46d092018-04-07 15:32:3798 if (unitTest) {
Mathias Bynens98669992019-11-28 07:50:0899 const unitTestPath = `http://localhost:8080/${unitTest.slice('http/tests/'.length)}`;
100 const link =
Yang Guo49346f12020-02-06 09:52:02101 `http://localhost:8080/inspector-sources/debug/integration_test_runner.html?test=${unitTestPath}`;
Blink Reformat4c46d092018-04-07 15:32:37102 console.log('1) Go to: ', link);
103 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:00104 console.log('3) Open DevTools on DevTools and you can refresh to re-run the test');
Blink Reformat4c46d092018-04-07 15:32:37105 } else {
106 console.log('Go to: http://localhost:9222/');
107 console.log('Click on link and in console execute: test()');
108 }
109 console.log('=============================================\n');
110 }
Tim van der Lippe03097b02020-11-27 16:25:37111 const args = [...testArgs, ...getTestFlags()];
Mathias Bynensb0693f22020-01-23 12:17:15112 console.log(`Running web tests with args: ${args.join(' ')}`);
Tim van der Lippe03097b02020-11-27 16:25:37113 childProcess.spawn(BLINK_TEST_PATH, args, {stdio: 'inherit'});
Blink Reformat4c46d092018-04-07 15:32:37114}
115
116function getTestFlags() {
Mathias Bynens98669992019-11-28 07:50:08117 const flagValues = Object.keys(Flags).map(key => Flags[key]);
Blink Reformat4c46d092018-04-07 15:32:37118 return process.argv.slice(2).filter(arg => {
Mathias Bynens98669992019-11-28 07:50:08119 const flagName = utils.includes(arg, '=') ? arg.slice(0, arg.indexOf('=')) : arg;
Blink Reformat4c46d092018-04-07 15:32:37120 return !utils.includes(flagValues, flagName) && !utils.includes(arg, 'inspector') &&
121 !utils.includes(arg, 'http/tests/devtools');
122 });
123}
124
125function getInspectorTests() {
Mathias Bynens98669992019-11-28 07:50:08126 const specificTests =
Blink Reformat4c46d092018-04-07 15:32:37127 process.argv.filter(arg => utils.includes(arg, 'inspector') || utils.includes(arg, 'http/tests/devtools'));
Tim van der Lippeba26b2b2020-03-11 14:40:00128 if (specificTests.length) {
Blink Reformat4c46d092018-04-07 15:32:37129 return specificTests;
Tim van der Lippeba26b2b2020-03-11 14:40:00130 }
Blink Reformat4c46d092018-04-07 15:32:37131 return [
132 'inspector*',
133 'http/tests/inspector*',
134 'http/tests/devtools',
135 ];
Kent Tamurad3d3f042018-12-12 02:45:28136}