blob: c2e6e44b84e95cb4c7ee7b035813dff499152769 [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
Yang Guob7a44262019-11-05 15:25:23 +010023const PYTHON = process.platform === 'win32' ? 'python.bat' : 'python';
Blink Reformat4c46d092018-04-07 15:32:37 +000024
Paul Lewis4d806b92020-03-13 14:51:06 +000025const CURRENT_PATH = process.env.PWD || process.cwd(); // Using env.PWD to account for symlinks.
Mathias Bynens98669992019-11-28 08:50:08 +010026const isThirdParty = CURRENT_PATH.includes('third_party');
27const CHROMIUM_SRC_PATH = CUSTOM_CHROMIUM_PATH || getChromiumSrcPath(isThirdParty);
Yang Guob7a44262019-11-05 15:25:23 +010028const RELEASE_PATH = path.resolve(CHROMIUM_SRC_PATH, 'out', TARGET);
29const BLINK_TEST_PATH = path.resolve(CHROMIUM_SRC_PATH, 'third_party', 'blink', 'tools', 'run_web_tests.py');
30const DEVTOOLS_PATH = path.resolve(CHROMIUM_SRC_PATH, 'third_party', 'devtools-frontend', 'src');
31const CACHE_PATH = path.resolve(DEVTOOLS_PATH, '.test_cache');
Blink Reformat4c46d092018-04-07 15:32:37 +000032
33function main() {
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000034 if (!utils.isDir(CACHE_PATH)) {
Blink Reformat4c46d092018-04-07 15:32:37 +000035 fs.mkdirSync(CACHE_PATH);
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000036 }
Blink Reformat4c46d092018-04-07 15:32:37 +000037
Mathias Bynens98669992019-11-28 08:50:08 +010038 const hasUserCompiledContentShell = utils.isFile(getContentShellBinaryPath(RELEASE_PATH));
Tim van der Lippe26bb5ad2020-06-01 11:54:14 +010039 if (!hasUserCompiledContentShell) {
Blink Reformat4c46d092018-04-07 15:32:37 +000040 return;
41 }
Tim van der Lippe26bb5ad2020-06-01 11:54:14 +010042 const outDir = path.resolve(RELEASE_PATH, '..');
Blink Reformat4c46d092018-04-07 15:32:37 +000043
Tim van der Lippe26bb5ad2020-06-01 11:54:14 +010044 runTests(outDir, IS_DEBUG_ENABLED);
Blink Reformat4c46d092018-04-07 15:32:37 +000045}
46main();
47
Blink Reformat4c46d092018-04-07 15:32:37 +000048
Mathias Bynens98669992019-11-28 08:50:08 +010049function getChromiumSrcPath(isThirdParty) {
50 if (isThirdParty)
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000051 // Assume we're in `chromium/src/third_party/devtools-frontend/src`.
52 {
Mathias Bynens98669992019-11-28 08:50:08 +010053 return path.resolve(CURRENT_PATH, '..', '..', '..');
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000054 }
Mathias Bynens98669992019-11-28 08:50:08 +010055 // 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 Lippeba26b2b2020-03-11 14:40:00 +000058 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 Bynens98669992019-11-28 08:50:08 +010065 return srcPath;
66}
67
Blink Reformat4c46d092018-04-07 15:32:37 +000068function getContentShellBinaryPath(dirPath) {
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000069 if (process.platform === 'linux') {
Blink Reformat4c46d092018-04-07 15:32:37 +000070 return path.resolve(dirPath, 'content_shell');
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000071 }
Blink Reformat4c46d092018-04-07 15:32:37 +000072
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000073 if (process.platform === 'win32') {
Blink Reformat4c46d092018-04-07 15:32:37 +000074 return path.resolve(dirPath, 'content_shell.exe');
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000075 }
Blink Reformat4c46d092018-04-07 15:32:37 +000076
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000077 if (process.platform === 'darwin') {
Blink Reformat4c46d092018-04-07 15:32:37 +000078 return path.resolve(dirPath, 'Content Shell.app', 'Contents', 'MacOS', 'Content Shell');
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000079 }
Blink Reformat4c46d092018-04-07 15:32:37 +000080}
81
82function runTests(buildDirectoryPath, useDebugDevtools) {
Mathias Bynens98669992019-11-28 08:50:08 +010083 const testArgs = getInspectorTests().concat([
Blink Reformat4c46d092018-04-07 15:32:37 +000084 '--build-directory',
85 buildDirectoryPath,
86 '--target',
87 TARGET,
88 ]);
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000089 if (useDebugDevtools) {
Blink Reformat4c46d092018-04-07 15:32:37 +000090 testArgs.push('--additional-driver-flag=--debug-devtools');
Tim van der Lippeba26b2b2020-03-11 14:40:00 +000091 } else {
Blink Reformat4c46d092018-04-07 15:32:37 +000092 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 +000093 }
Blink Reformat4c46d092018-04-07 15:32:37 +000094
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 Bynens98669992019-11-28 08:50:08 +010099 const unitTest = testArgs.find(arg => arg.includes('http/tests/devtools/unit/'));
Blink Reformat4c46d092018-04-07 15:32:37 +0000100 if (unitTest) {
Mathias Bynens98669992019-11-28 08:50:08 +0100101 const unitTestPath = `http://localhost:8080/${unitTest.slice('http/tests/'.length)}`;
102 const link =
Yang Guo49346f12020-02-06 10:52:02 +0100103 `http://localhost:8080/inspector-sources/debug/integration_test_runner.html?test=${unitTestPath}`;
Blink Reformat4c46d092018-04-07 15:32:37 +0000104 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 Lippeba26b2b2020-03-11 14:40:00 +0000106 console.log('3) Open DevTools on DevTools and you can refresh to re-run the test');
Blink Reformat4c46d092018-04-07 15:32:37 +0000107 } 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 Bynens98669992019-11-28 08:50:08 +0100113 const args = [BLINK_TEST_PATH].concat(testArgs).concat(getTestFlags());
Mathias Bynensb0693f22020-01-23 13:17:15 +0100114 console.log(`Running web tests with args: ${args.join(' ')}`);
Blink Reformat4c46d092018-04-07 15:32:37 +0000115 childProcess.spawn(PYTHON, args, {stdio: 'inherit'});
116}
117
118function getTestFlags() {
Mathias Bynens98669992019-11-28 08:50:08 +0100119 const flagValues = Object.keys(Flags).map(key => Flags[key]);
Blink Reformat4c46d092018-04-07 15:32:37 +0000120 return process.argv.slice(2).filter(arg => {
Mathias Bynens98669992019-11-28 08:50:08 +0100121 const flagName = utils.includes(arg, '=') ? arg.slice(0, arg.indexOf('=')) : arg;
Blink Reformat4c46d092018-04-07 15:32:37 +0000122 return !utils.includes(flagValues, flagName) && !utils.includes(arg, 'inspector') &&
123 !utils.includes(arg, 'http/tests/devtools');
124 });
125}
126
127function getInspectorTests() {
Mathias Bynens98669992019-11-28 08:50:08 +0100128 const specificTests =
Blink Reformat4c46d092018-04-07 15:32:37 +0000129 process.argv.filter(arg => utils.includes(arg, 'inspector') || utils.includes(arg, 'http/tests/devtools'));
Tim van der Lippeba26b2b2020-03-11 14:40:00 +0000130 if (specificTests.length) {
Blink Reformat4c46d092018-04-07 15:32:37 +0000131 return specificTests;
Tim van der Lippeba26b2b2020-03-11 14:40:00 +0000132 }
Blink Reformat4c46d092018-04-07 15:32:37 +0000133 return [
134 'inspector*',
135 'http/tests/inspector*',
136 'http/tests/devtools',
137 ];
Kent Tamurad3d3f042018-12-12 02:45:28 +0000138}