Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 1 | # Running web tests using the content shell |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 2 | |
Raphael Kubo da Costa | 6d16d3a | 2020-12-01 16:47:08 | [diff] [blame] | 3 | [TOC] |
| 4 | |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 5 | ## Compiling |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 6 | |
Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 7 | If you want to run web tests, |
| 8 | [build the target `blink_tests`](web_tests.md); this includes all the other |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 9 | binaries required to run the tests. |
| 10 | |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 11 | ## Running |
| 12 | |
| 13 | ### Using `run_web_tests.py` |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 14 | |
Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 15 | You can run web tests using `run_web_tests.py` (in |
Kent Tamura | a045a7f | 2018-04-25 05:08:11 | [diff] [blame] | 16 | `src/third_party/blink/tools`). |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 17 | |
| 18 | ```bash |
Robert Ma | 7ed1679 | 2020-06-16 16:38:52 | [diff] [blame] | 19 | third_party/blink/tools/run_web_tests.py -t <build directory> storage/indexeddb |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 20 | ``` |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 21 | To see a complete list of arguments supported, run with `--help`. |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 22 | |
Robert Ma | 7ed1679 | 2020-06-16 16:38:52 | [diff] [blame] | 23 | *** promo |
| 24 | Windows users need to use `third_party/blink/tools/run_web_tests.bat` instead. |
| 25 | *** |
| 26 | |
| 27 | *** promo |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 28 | You can add `<path>/third_party/blink/tools` into `PATH` so that you can |
| 29 | run it from anywhere without the full path. |
| 30 | *** |
| 31 | |
| 32 | ### Run Web Tests Directly with Content Shell |
| 33 | |
| 34 | In some cases (e.g. for debugging), you can run web tests directly with |
| 35 | Content Shell executable, with the `--run-web-tests` flag: |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 36 | |
| 37 | ```bash |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 38 | out/Default/content_shell --run-web-tests <url>|<full_test_source_path>|<relative_test_path> |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 39 | ``` |
| 40 | |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 41 | `<relative_test_path>` is relative to the [web_tests](../../third_party/blink/web_tests) |
| 42 | directory, regardless of the current directory. |
| 43 | |
| 44 | For example: |
| 45 | |
| 46 | ```bash |
| 47 | out/Default/content_shell --run-web-tests fast/forms/001.html |
| 48 | ``` |
| 49 | or |
| 50 | |
| 51 | ```bash |
| 52 | out/Default/content_shell --run-web-tests \ |
| 53 | /home/user/chrome/src/third_party/blink/web_tests/fast/forms/001.html |
| 54 | ``` |
| 55 | or |
| 56 | |
| 57 | ```bash |
| 58 | out/Default/content_shell --run-web-tests ~/test/temp-test.html |
| 59 | ``` |
| 60 | |
| 61 | By default, it dumps the text result only (as the dump of pixels and audio |
Robert Ma | 0d0b664 | 2019-07-18 19:12:00 | [diff] [blame] | 62 | binary data is not human readable) and quits. This can meet the requirement of |
| 63 | most 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 |
| 65 | browser](#As-a-simple-browser). |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 66 | |
Robert Ma | 0d0b664 | 2019-07-18 19:12:00 | [diff] [blame] | 67 | In rare cases, to run Content Shell in the exact same way as |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 68 | `run_web_tests.py` runs it, you need to run it in the |
Arnaud Mandy | f0d227a | 2021-02-04 14:00:31 | [diff] [blame] | 69 | [protocol mode](../../content/web_test/browser/test_info_extractor.h). |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 70 | |
| 71 | *** note |
| 72 | On the Mac, use `Content Shell.app`, not `content_shell`. |
| 73 | |
| 74 | ```bash |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 75 | out/Default/Content\ Shell.app/Contents/MacOS/Content\ Shell ... |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 76 | ``` |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 77 | On Windows, use `content_shell.exe`. |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 78 | *** |
| 79 | |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 80 | #### Running HTTP Tests in Content Shell |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 81 | |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 82 | HTTP tests reside under [web_tests/http/tests](../../third_party/blink/web_tests/http/tests). |
Johann | f5b3202 | 2020-09-11 14:20:22 | [diff] [blame] | 83 | You need to start a web server first. By default it serves generated files from |
| 84 | out/Release: |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 85 | |
| 86 | ```bash |
Fabrice de Gans | 7820a77 | 2022-09-16 00:10:30 | [diff] [blame] | 87 | vpython3 third_party/blink/tools/run_blink_httpd.py -t <build directory> |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 88 | ``` |
| 89 | Then run the test with a localhost URL: |
| 90 | |
| 91 | ```bash |
| 92 | out/Default/content_shell --run-web-tests http://localhost:8000/<test> |
| 93 | ``` |
| 94 | |
Johann | 5aa23b5 | 2020-06-12 17:00:52 | [diff] [blame] | 95 | It 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 Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 97 | #### Running WPT Tests in Content Shell |
| 98 | |
| 99 | Similar 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) |
| 101 | tests require some setup before running in Content Shell: |
| 102 | |
| 103 | ```bash |
Kent Tamura | bfdb70b | 2022-07-26 09:12:54 | [diff] [blame] | 104 | vpython3 third_party/blink/tools/run_blink_wptserve.py -t <build directory> |
Johann | a06b671 | 2020-06-02 08:51:35 | [diff] [blame] | 105 | ``` |
| 106 | |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 107 | Then run the test: |
| 108 | |
| 109 | ```bash |
| 110 | out/Default/content_shell --run-web-tests http://localhost:8001/<test> |
| 111 | ``` |
Robert Ma | 0d0b664 | 2019-07-18 19:12:00 | [diff] [blame] | 112 | |
| 113 | If the test requires HTTPS (e.g. the file name contains ".https."), use the |
| 114 | following command instead: |
| 115 | |
| 116 | ```bash |
| 117 | out/Default/content_shell --run-web-tests https://localhost:8444/<test> |
| 118 | ``` |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 119 | |
| 120 | ### As a simple browser |
| 121 | |
| 122 | You can run the shell directly as a simple browser: |
| 123 | |
| 124 | ```bash |
| 125 | out/Default/content_shell |
| 126 | ``` |
| 127 | |
| 128 | This allows you see how your changes look in Chromium. You can inspect the page |
| 129 | by right clicking and selecting 'Inspect Element'. |
| 130 | |
| 131 | You can also use `--remote-debugging-port` |
| 132 | |
| 133 | ```bash |
| 134 | out/Default/content_shell --remote-debugging-port=9222 |
| 135 | ``` |
| 136 | and open `http://localhost:9222` from another browser to inspect the page. |
| 137 | This is useful when you don't want DevTools to run in the same Content Shell, |
| 138 | e.g. when you are logging a lot and don't want the log from DevTools |
| 139 | or when DevTools is unstable in the current revision due to some bugs. |
| 140 | |
Robert Ma | 0d0b664 | 2019-07-18 19:12:00 | [diff] [blame] | 141 | #### Debug WPT |
| 142 | |
| 143 | If you want to debug WPT with devtools in Content Shell, you will first need to |
| 144 | start the server: |
| 145 | |
| 146 | ```bash |
Kent Tamura | bfdb70b | 2022-07-26 09:12:54 | [diff] [blame] | 147 | vpython3 third_party/blink/tools/run_blink_wptserve.py |
Robert Ma | 0d0b664 | 2019-07-18 19:12:00 | [diff] [blame] | 148 | ``` |
| 149 | |
| 150 | Then start Content Shell with some additional flags: |
| 151 | |
| 152 | ```bash |
Hayato Ito | 33c9a1f | 2023-09-11 02:38:41 | [diff] [blame] | 153 | out/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 Ma | 0d0b664 | 2019-07-18 19:12:00 | [diff] [blame] | 154 | ``` |
| 155 | |
Takahiro | 961b242 | 2022-01-19 00:14:29 | [diff] [blame] | 156 | You are also able to debug the inside of Chromium with a debugger for |
| 157 | particular WPT tests. After starting the WPT server, run particular tests via |
| 158 | Content 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 |
| 162 | out/Default/content_shell --run-web-tests http://localhost:8001/<test> |
| 163 | ``` |
| 164 | |
| 165 | Chromium adopts multi-process architecture. If you want to debug the child |
| 166 | renderer processes, use `--single-process` Content Shell option, or |
| 167 | `--renderer-startup-dialog` option and attach the debugger to the renderer |
| 168 | processes after starting the tests. Refer to the Debugging section below for details. |
| 169 | |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 170 | ## Debugging |
| 171 | |
| 172 | ### `--single-process` |
| 173 | |
| 174 | The command line switch `--single-process` is useful for starting |
| 175 | content_shell in gdb. In most cases, `--single-process` is good for debugging |
| 176 | except when you want to debug the multiple process behavior or when we have |
| 177 | some bug breaking `--single-process` in particular cases. |
| 178 | |
| 179 | ### Web tests |
| 180 | |
| 181 | See [Run Web Tests Directly with Content Shell](#Run-Web-Tests-Directly-with-Content-Shell). |
| 182 | In most cases you don't need `--single-process` because `content_shell` is |
| 183 | in single process mode when running most web tests. |
| 184 | |
Yang Guo | 708d74b | 2019-10-31 08:06:08 | [diff] [blame] | 185 | See [DevTools frontend](../../third_party/devtools-frontend/src/README.md#basics) |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 186 | for the commands that are useful for debugging devtools web tests. |
| 187 | |
| 188 | ### In The Default Multiple Process Mode |
| 189 | |
| 190 | In rare cases, you need to debug Content Shell in multiple process mode. |
| 191 | You can ask Content Shell to wait for you to attach a debugger once it spawns a |
| 192 | renderer process by adding the `--renderer-startup-dialog` flag: |
| 193 | |
| 194 | ```bash |
| 195 | out/Default/content_shell --renderer-startup-dialog --no-sandbox |
pwnall | d8a25072 | 2016-11-09 18:24:03 | [diff] [blame] | 196 | ``` |
| 197 | |
| 198 | Debugging 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 | |
| 206 | To avoid writing (and maintaining!) yet another test controller, it is desirable |
| 207 | to reuse an existing test controller. A possible solution would be to change |
| 208 | DRT's test controller to not depend on DRT's implementation of the Blink |
| 209 | objects, but rather on the Blink interfaces. In addition, we would need to |
| 210 | extract an interface from the test shell object that can be implemented by |
| 211 | content shell. This would allow for directly using DRT's test controller in |
| 212 | content shell. |