blob: 3c7ff67428b01fdb613cfc9c30fe7ee03e7af84a [file] [log] [blame] [view]
Kent Tamura59ffb022018-11-27 05:30:561# Running web tests using the content shell
pwnalld8a250722016-11-09 18:24:032
Raphael Kubo da Costa6d16d3a2020-12-01 16:47:083[TOC]
4
Xianzhu Wang0a37e9d2019-03-27 21:27:295## Compiling
pwnalld8a250722016-11-09 18:24:036
Kent Tamura59ffb022018-11-27 05:30:567If you want to run web tests,
8[build the target `blink_tests`](web_tests.md); this includes all the other
pwnalld8a250722016-11-09 18:24:039binaries required to run the tests.
10
Xianzhu Wang0a37e9d2019-03-27 21:27:2911## Running
12
13### Using `run_web_tests.py`
pwnalld8a250722016-11-09 18:24:0314
Kent Tamura59ffb022018-11-27 05:30:5615You can run web tests using `run_web_tests.py` (in
Kent Tamuraa045a7f2018-04-25 05:08:1116`src/third_party/blink/tools`).
pwnalld8a250722016-11-09 18:24:0317
18```bash
Robert Ma7ed16792020-06-16 16:38:5219third_party/blink/tools/run_web_tests.py -t <build directory> storage/indexeddb
pwnalld8a250722016-11-09 18:24:0320```
Xianzhu Wang0a37e9d2019-03-27 21:27:2921To see a complete list of arguments supported, run with `--help`.
pwnalld8a250722016-11-09 18:24:0322
Robert Ma7ed16792020-06-16 16:38:5223*** promo
24Windows users need to use `third_party/blink/tools/run_web_tests.bat` instead.
25***
26
27*** promo
Xianzhu Wang0a37e9d2019-03-27 21:27:2928You can add `<path>/third_party/blink/tools` into `PATH` so that you can
29run it from anywhere without the full path.
30***
31
32### Run Web Tests Directly with Content Shell
33
34In some cases (e.g. for debugging), you can run web tests directly with
35Content Shell executable, with the `--run-web-tests` flag:
pwnalld8a250722016-11-09 18:24:0336
37```bash
Xianzhu Wang0a37e9d2019-03-27 21:27:2938out/Default/content_shell --run-web-tests <url>|<full_test_source_path>|<relative_test_path>
pwnalld8a250722016-11-09 18:24:0339```
40
Xianzhu Wang0a37e9d2019-03-27 21:27:2941`<relative_test_path>` is relative to the [web_tests](../../third_party/blink/web_tests)
42directory, regardless of the current directory.
43
44For example:
45
46```bash
47out/Default/content_shell --run-web-tests fast/forms/001.html
48```
49or
50
51```bash
52out/Default/content_shell --run-web-tests \
53 /home/user/chrome/src/third_party/blink/web_tests/fast/forms/001.html
54```
55or
56
57```bash
58out/Default/content_shell --run-web-tests ~/test/temp-test.html
59```
60
61By default, it dumps the text result only (as the dump of pixels and audio
Robert Ma0d0b6642019-07-18 19:12:0062binary data is not human readable) and quits. This can meet the requirement of
63most debugging requirements. If you need to interactively debug the test page
64(e.g. using devtools), you'll need to run Content Shell [as a simple
65browser](#As-a-simple-browser).
Xianzhu Wang0a37e9d2019-03-27 21:27:2966
Robert Ma0d0b6642019-07-18 19:12:0067In rare cases, to run Content Shell in the exact same way as
Xianzhu Wang0a37e9d2019-03-27 21:27:2968`run_web_tests.py` runs it, you need to run it in the
Arnaud Mandyf0d227a2021-02-04 14:00:3169[protocol mode](../../content/web_test/browser/test_info_extractor.h).
pwnalld8a250722016-11-09 18:24:0370
71*** note
72On the Mac, use `Content Shell.app`, not `content_shell`.
73
74```bash
Xianzhu Wang0a37e9d2019-03-27 21:27:2975out/Default/Content\ Shell.app/Contents/MacOS/Content\ Shell ...
pwnalld8a250722016-11-09 18:24:0376```
Xianzhu Wang0a37e9d2019-03-27 21:27:2977On Windows, use `content_shell.exe`.
pwnalld8a250722016-11-09 18:24:0378***
79
Xianzhu Wang0a37e9d2019-03-27 21:27:2980#### Running HTTP Tests in Content Shell
pwnalld8a250722016-11-09 18:24:0381
Xianzhu Wang0a37e9d2019-03-27 21:27:2982HTTP tests reside under [web_tests/http/tests](../../third_party/blink/web_tests/http/tests).
Johannf5b32022020-09-11 14:20:2283You need to start a web server first. By default it serves generated files from
84out/Release:
pwnalld8a250722016-11-09 18:24:0385
86```bash
Fabrice de Gans7820a772022-09-16 00:10:3087vpython3 third_party/blink/tools/run_blink_httpd.py -t <build directory>
Xianzhu Wang0a37e9d2019-03-27 21:27:2988```
89Then run the test with a localhost URL:
90
91```bash
92out/Default/content_shell --run-web-tests http://localhost:8000/<test>
93```
94
Johann5aa23b52020-06-12 17:00:5295It may be necessary specify [--enable-blink-features](https://source.chromium.org/search?q=%22--enable-blink-features%3D%22) explicitly for some tests.
96
Xianzhu Wang0a37e9d2019-03-27 21:27:2997#### Running WPT Tests in Content Shell
98
99Similar to HTTP tests, many WPT (a.k.a. web-platform-tests under
100[web_tests/external/wpt](../../third_party/blink/web_tests/external/wpt) directory)
101tests require some setup before running in Content Shell:
102
103```bash
Kent Tamurabfdb70b2022-07-26 09:12:54104vpython3 third_party/blink/tools/run_blink_wptserve.py -t <build directory>
Johanna06b6712020-06-02 08:51:35105```
106
Xianzhu Wang0a37e9d2019-03-27 21:27:29107Then run the test:
108
109```bash
110out/Default/content_shell --run-web-tests http://localhost:8001/<test>
111```
Robert Ma0d0b6642019-07-18 19:12:00112
113If the test requires HTTPS (e.g. the file name contains ".https."), use the
114following command instead:
115
116```bash
117out/Default/content_shell --run-web-tests https://localhost:8444/<test>
118```
Xianzhu Wang0a37e9d2019-03-27 21:27:29119
120### As a simple browser
121
122You can run the shell directly as a simple browser:
123
124```bash
125out/Default/content_shell
126```
127
128This allows you see how your changes look in Chromium. You can inspect the page
129by right clicking and selecting 'Inspect Element'.
130
131You can also use `--remote-debugging-port`
132
133```bash
134out/Default/content_shell --remote-debugging-port=9222
135```
136and open `http://localhost:9222` from another browser to inspect the page.
137This is useful when you don't want DevTools to run in the same Content Shell,
138e.g. when you are logging a lot and don't want the log from DevTools
139or when DevTools is unstable in the current revision due to some bugs.
140
Robert Ma0d0b6642019-07-18 19:12:00141#### Debug WPT
142
143If you want to debug WPT with devtools in Content Shell, you will first need to
144start the server:
145
146```bash
Kent Tamurabfdb70b2022-07-26 09:12:54147vpython3 third_party/blink/tools/run_blink_wptserve.py
Robert Ma0d0b6642019-07-18 19:12:00148```
149
150Then start Content Shell with some additional flags:
151
152```bash
Hayato Ito33c9a1f2023-09-11 02:38:41153out/Default/content_shell --enable-experimental-web-platform-features --ignore-certificate-errors --host-resolver-rules="MAP nonexistent.*.test ^NOTFOUND, MAP *.test. 127.0.0.1, MAP *.test 127.0.0.1"
Robert Ma0d0b6642019-07-18 19:12:00154```
155
Takahiro961b2422022-01-19 00:14:29156You are also able to debug the inside of Chromium with a debugger for
157particular WPT tests. After starting the WPT server, run particular tests via
158Content Shell from the debugger with the following command.
159(Refer to your debugger's manual for how to start a program from your debugger.)
160
161```bash
162out/Default/content_shell --run-web-tests http://localhost:8001/<test>
163```
164
165Chromium adopts multi-process architecture. If you want to debug the child
166renderer processes, use `--single-process` Content Shell option, or
167`--renderer-startup-dialog` option and attach the debugger to the renderer
168processes after starting the tests. Refer to the Debugging section below for details.
169
Xianzhu Wang0a37e9d2019-03-27 21:27:29170## Debugging
171
172### `--single-process`
173
174The command line switch `--single-process` is useful for starting
175content_shell in gdb. In most cases, `--single-process` is good for debugging
176except when you want to debug the multiple process behavior or when we have
177some bug breaking `--single-process` in particular cases.
178
179### Web tests
180
181See [Run Web Tests Directly with Content Shell](#Run-Web-Tests-Directly-with-Content-Shell).
182In most cases you don't need `--single-process` because `content_shell` is
183in single process mode when running most web tests.
184
Yang Guo708d74b2019-10-31 08:06:08185See [DevTools frontend](../../third_party/devtools-frontend/src/README.md#basics)
Xianzhu Wang0a37e9d2019-03-27 21:27:29186for the commands that are useful for debugging devtools web tests.
187
188### In The Default Multiple Process Mode
189
190In rare cases, you need to debug Content Shell in multiple process mode.
191You can ask Content Shell to wait for you to attach a debugger once it spawns a
192renderer process by adding the `--renderer-startup-dialog` flag:
193
194```bash
195out/Default/content_shell --renderer-startup-dialog --no-sandbox
pwnalld8a250722016-11-09 18:24:03196```
197
198Debugging workers and other subprocesses is simpler with
199`--wait-for-debugger-children`, which can have one of two values: `plugin` or
200`renderer`.
201
202## Future Work
203
204### Reusing existing testing objects
205
206To avoid writing (and maintaining!) yet another test controller, it is desirable
207to reuse an existing test controller. A possible solution would be to change
208DRT's test controller to not depend on DRT's implementation of the Blink
209objects, but rather on the Blink interfaces. In addition, we would need to
210extract an interface from the test shell object that can be implemented by
211content shell. This would allow for directly using DRT's test controller in
212content shell.