foolip | eda32ab | 2017-02-16 19:21:58 | [diff] [blame] | 1 | # web-platform-tests |
qyearsley | 4f0acca4 | 2017-01-30 08:18:43 | [diff] [blame] | 2 | |
rbyers | 6299b913 | 2017-02-10 18:06:57 | [diff] [blame] | 3 | Interoperability between browsers is |
qyearsley | 9c9781a | 2017-02-11 00:08:39 | [diff] [blame] | 4 | [critical](https://www.chromium.org/blink/platform-predictability) to Chromium's |
| 5 | mission of improving the web. We believe that leveraging and contributing to a |
| 6 | shared test suite is one of the most important tools in achieving |
| 7 | interoperability between browsers. The [web-platform-tests |
Philip Jägenstedt | 3a3d5b8 | 2018-05-31 15:25:35 | [diff] [blame] | 8 | repository](https://github.com/web-platform-tests/wpt) is the primary shared |
Quinten Yearsley | fab627a | 2017-03-29 22:30:18 | [diff] [blame] | 9 | test suite where all browser engines are collaborating. |
qyearsley | 4f0acca4 | 2017-01-30 08:18:43 | [diff] [blame] | 10 | |
Jeff Carpenter | abd1360 | 2017-03-29 22:49:59 | [diff] [blame] | 11 | Chromium has a 2-way import/export process with the upstream web-platform-tests |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 12 | repository, where tests are imported into |
Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 13 | [web_tests/external/wpt](../../third_party/blink/web_tests/external/wpt) |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 14 | and any changes to the imported tests are also exported to web-platform-tests. |
| 15 | |
Philip Jägenstedt | 3a3d5b8 | 2018-05-31 15:25:35 | [diff] [blame] | 16 | See https://web-platform-tests.org/ for general documentation on |
foolip | eda32ab | 2017-02-16 19:21:58 | [diff] [blame] | 17 | web-platform-tests, including tips for writing and reviewing tests. |
| 18 | |
qyearsley | 4f0acca4 | 2017-01-30 08:18:43 | [diff] [blame] | 19 | [TOC] |
| 20 | |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 21 | ## Writing tests |
qyearsley | 4f0acca4 | 2017-01-30 08:18:43 | [diff] [blame] | 22 | |
foolip | eda32ab | 2017-02-16 19:21:58 | [diff] [blame] | 23 | To contribute changes to web-platform-tests, just commit your changes directly |
Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 24 | to [web_tests/external/wpt](../../third_party/blink/web_tests/external/wpt) |
qyearsley | 4f0acca4 | 2017-01-30 08:18:43 | [diff] [blame] | 25 | and the changes will be automatically upstreamed within 24 hours. |
| 26 | |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 27 | Changes involving adding, removing or modifying tests can all be upstreamed. |
| 28 | Any changes outside of |
Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 29 | [external/wpt](../../third_party/blink/web_tests/external/wpt) will not be |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 30 | upstreamed, and any changes `*-expected.txt`, `OWNERS`, and `MANIFEST.json`, |
| 31 | will also not be upstreamed. |
rbyers | 6299b913 | 2017-02-10 18:06:57 | [diff] [blame] | 32 | |
Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 33 | Running the web tests will automatically regenerate MANIFEST.json to pick up |
Jeff Carpenter | eb1ff6b | 2017-03-02 23:21:58 | [diff] [blame] | 34 | any local modifications. |
foolip | 2f19855 | 2017-02-24 16:42:35 | [diff] [blame] | 35 | |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 36 | Most tests are written using testharness.js, see |
Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 37 | [Writing Web Tests](./writing_web_tests.md) and |
| 38 | [Web Tests Tips](./web_tests_tips.md) for general guidelines. |
qyearsley | 9c9781a | 2017-02-11 00:08:39 | [diff] [blame] | 39 | |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 40 | ### Write tests against specifications |
| 41 | |
foolip | eda32ab | 2017-02-16 19:21:58 | [diff] [blame] | 42 | Tests in web-platform-tests are expected to match behavior defined by the |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 43 | relevant specification. In other words, all assertions that a test makes |
| 44 | should be derived from a specification's normative requirements, and not go |
| 45 | beyond them. It is often necessary to change the specification to clarify what |
| 46 | is and isn't required. |
| 47 | |
Philip Jägenstedt | 8bb32fa | 2018-01-27 14:39:26 | [diff] [blame] | 48 | When implementation experience is needed to inform the specification work, |
Philip Jägenstedt | 3a3d5b8 | 2018-05-31 15:25:35 | [diff] [blame] | 49 | [tentative tests](https://web-platform-tests.org/writing-tests/file-names.html) |
Philip Jägenstedt | 8bb32fa | 2018-01-27 14:39:26 | [diff] [blame] | 50 | can be appropriate. It should be apparent in context why the test is tentative |
| 51 | and what needs to be resolved to make it non-tentative. |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 52 | |
| 53 | ### Tests that require testing APIs |
| 54 | |
Philip Jägenstedt | 3a3d5b8 | 2018-05-31 15:25:35 | [diff] [blame] | 55 | [testdriver.js](https://web-platform-tests.org/writing-tests/testdriver.html) |
Philip Jägenstedt | 8bb32fa | 2018-01-27 14:39:26 | [diff] [blame] | 56 | provides a means to automate tests that cannot be written purely using web |
| 57 | platform APIs, similar to `internals.*` and `eventSender.*` in regular Blink |
Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 58 | web tests. |
Philip Jägenstedt | 8bb32fa | 2018-01-27 14:39:26 | [diff] [blame] | 59 | |
| 60 | If no testdriver.js API exists, check if it's a |
Philip Jägenstedt | 3a3d5b8 | 2018-05-31 15:25:35 | [diff] [blame] | 61 | [known issue](https://github.com/web-platform-tests/wpt/labels/testdriver.js) |
Luke Zielinski | 64ff949 | 2019-05-30 17:42:29 | [diff] [blame] | 62 | and otherwise consider filing a new issue. For instructions on how to add a new |
| 63 | testing API, see [WPT Test Automation for |
| 64 | Chromium](https://docs.google.com/document/d/18BpD41vyX1cFZ77CE0a_DJYlGpdvyLlx3pwXVRxUzvI/preview#) |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 65 | |
| 66 | An alternative is to write manual tests that are automated with scripts from |
Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 67 | [wpt_automation](../../third_party/blink/web_tests/external/wpt_automation). |
Quinten Yearsley | e577029f | 2017-07-06 00:21:03 | [diff] [blame] | 68 | Injection of JS in manual tests is determined by `loadAutomationScript` in |
Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 69 | [testharnessreport.js](../../third_party/blink/web_tests/resources/testharnessreport.js). |
Quinten Yearsley | e577029f | 2017-07-06 00:21:03 | [diff] [blame] | 70 | |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 71 | Such tests still require case-by-case automation to run for other browser |
| 72 | engines, but are more valuable than purely manual tests. |
| 73 | |
Quinten Yearsley | e577029f | 2017-07-06 00:21:03 | [diff] [blame] | 74 | Manual tests that have no automation are still imported, but skipped in |
Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 75 | [NeverFixTests](../../third_party/blink/web_tests/NeverFixTests); see |
Quinten Yearsley | e577029f | 2017-07-06 00:21:03 | [diff] [blame] | 76 | [issue 738489](https://crbug.com/738489). |
| 77 | |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 78 | ### Adding new top-level directories |
qyearsley | 9c9781a | 2017-02-11 00:08:39 | [diff] [blame] | 79 | |
| 80 | Entirely new top-level directories should generally be added upstream, since |
| 81 | that's the only way to add an OWNERS file upstream. After adding a new top-level |
| 82 | directory upstream, you should add a line for it in `W3CImportExpectations`. |
| 83 | |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 84 | Adding the new directory (and `W3CImportExpectations` entry) in Chromium and |
| 85 | later adding an OWNERS file upstream also works. |
| 86 | |
qyearsley | 4f0acca4 | 2017-01-30 08:18:43 | [diff] [blame] | 87 | ### Will the exported commits be linked to my GitHub profile? |
| 88 | |
| 89 | The email you commit with in Chromium will be the author of the commit on |
| 90 | GitHub. You can [add it as a secondary address on your GitHub |
| 91 | account](https://help.github.com/articles/adding-an-email-address-to-your-github-account/) |
| 92 | to link your exported commits to your GitHub profile. |
| 93 | |
Philip Jägenstedt | f7e99cf | 2018-01-22 15:54:29 | [diff] [blame] | 94 | If you are a Googler, you can also register your GitHub account at go/github, |
| 95 | making it easier for other Googlers to find you. |
| 96 | |
qyearsley | 4f0acca4 | 2017-01-30 08:18:43 | [diff] [blame] | 97 | ### What if there are conflicts? |
| 98 | |
| 99 | This cannot be avoided entirely as the two repositories are independent, but |
| 100 | should be rare with frequent imports and exports. When it does happen, manual |
| 101 | intervention will be needed and in non-trivial cases you may be asked to help |
| 102 | resolve the conflict. |
| 103 | |
| 104 | ### Direct pull requests |
| 105 | |
foolip | eda32ab | 2017-02-16 19:21:58 | [diff] [blame] | 106 | It's still possible to make direct pull requests to web-platform-tests, see |
Stephen McGruer | a12b34f8 | 2020-07-10 16:00:42 | [diff] [blame] | 107 | https://web-platform-tests.org/writing-tests/github-intro.html. |
| 108 | |
| 109 | ### wpt_internal |
| 110 | |
| 111 | It is sometimes desirable to write WPT tests that either test Chromium-specific |
| 112 | behaviors, or that cannot yet be upstreamed to WPT (e.g. because the spec is |
| 113 | very nascent). For these cases, we maintain a separate directory, |
| 114 | [wpt_internal](../third_party/blink/web_tests/wpt_internal) that runs under the |
| 115 | WPT testing infrastructure (e.g. uses wptserve, etc), but which is not |
| 116 | upstreamed to WPT. |
| 117 | |
| 118 | Please see the `wpt_internal` |
| 119 | [README](../third_party/blink/web_tests/wpt_internal/README) for more details. |
| 120 | |
| 121 | **Note**: A significant downside of `wpt_internal` is that your tests may be |
| 122 | broken by upstream changes to the resources scripts (e.g. `testharness.js`), as |
| 123 | `wpt_internal` does not use the forked version of `testharness.js` used by all |
| 124 | other non-`external/wpt` tests. Use of [WPT-NOTIFY](#wpt_notify) is recommended |
| 125 | to ensure you are notified of breakages. |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 126 | |
Jeff Carpenter | 11b548b | 2017-11-03 23:05:22 | [diff] [blame] | 127 | ## Running tests |
| 128 | |
Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 129 | Same as Blink web tests, you can use |
| 130 | [`run_web_tests.py`](web_tests.md#running-the-tests) to run any WPT test. |
Jeff Carpenter | 11b548b | 2017-11-03 23:05:22 | [diff] [blame] | 131 | |
| 132 | One thing to note is that glob patterns for WPT tests are not yet supported. |
| 133 | |
Xianzhu Wang | 0a37e9d | 2019-03-27 21:27:29 | [diff] [blame] | 134 | See [Running WPT tests in Content Shell](web_tests_in_content_shell.md#Running-WPT-Tests-in-Content-Shell) |
| 135 | for debugging etc. |
| 136 | |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 137 | ## Reviewing tests |
| 138 | |
| 139 | Anyone who can review code and tests in Chromium can also review changes in |
Kent Tamura | 59ffb02 | 2018-11-27 05:30:56 | [diff] [blame] | 140 | [external/wpt](../../third_party/blink/web_tests/external/wpt) |
foolip | df2a863 | 2017-02-15 15:03:16 | [diff] [blame] | 141 | that will be automatically upstreamed. There will be no additional review in |
| 142 | web-platform-tests as part of the export process. |
| 143 | |
| 144 | If upstream reviewers have feedback on the changes, discuss on the pull request |
| 145 | created during export, and if necessary work on a new pull request to iterate |
| 146 | until everyone is satisfied. |
| 147 | |
| 148 | When reviewing tests, check that they match the relevant specification, which |
| 149 | may not fully match the implementation. See also |
| 150 | [Write tests against specifications](#Write-tests-against-specifications). |
Stephen McGruer | a12b34f8 | 2020-07-10 16:00:42 | [diff] [blame] | 151 | |
| 152 | ## Importing tests |
| 153 | |
| 154 | Chromium has a [mirror](https://chromium.googlesource.com/external/w3c/web-platform-tests/) |
| 155 | of the GitHub repo and periodically imports a subset of the tests to |
| 156 | run as part of the regular Blink web test testing process. |
| 157 | |
| 158 | The goals of this process are to be able to run web-platform-tests unmodified |
| 159 | locally just as easily as we can run the Blink tests, and ensure that we are |
| 160 | tracking tip-of-tree in the web-platform-tests repository as closely as |
| 161 | possible, and running as many of the tests as possible. |
| 162 | |
| 163 | ### Automatic import process |
| 164 | |
| 165 | There is an automatic process for updating the Chromium copy of |
| 166 | web-platform-tests. The import is done by the builder [wpt-importer |
| 167 | builder][wpt-importer]. |
| 168 | |
| 169 | The easiest way to check the status of recent imports is to look at: |
| 170 | |
| 171 | - Recent logs on LUCI for [wpt-importer builder][wpt-importer] |
| 172 | - Recent CLs created by [WPT |
| 173 | Autoroller](https://chromium-review.googlesource.com/q/owner:wpt-autoroller%2540chops-service-accounts.iam.gserviceaccount.com). |
| 174 | |
| 175 | The import jobs will generally be green if either there was nothing to do, |
| 176 | or a CL was successfully submitted. |
| 177 | |
| 178 | For maintainers: |
| 179 | |
| 180 | - The source lives in |
| 181 | [third_party/blink/tools/wpt_import.py](../../third_party/blink/tools/wpt_import.py). |
| 182 | - If the importer starts misbehaving, it can be disabled by landing a |
| 183 | [CL to skip the update step](https://crrev.com/c/1961906/). |
| 184 | |
| 185 | ### WPT-NOTIFY |
| 186 | |
| 187 | Test owners can elect to have the importer automatically file bugs against a |
| 188 | component when imported changes introduce failures. This includes new tests that |
| 189 | fail in Chromium, as well as new failures introduced to an existing test. To |
| 190 | opt-in to this functionality, create an `OWNERS` file in the appropriate |
| 191 | `external/wpt/` subdirectory that contains the `WPT-NOTIFY` tag. For example, |
| 192 | `external/wpt/css/css-grid/OWNERS` looks like: |
| 193 | |
| 194 | ``` |
| 195 | # TEAM: [email protected] |
| 196 | # COMPONENT: Blink>Layout>Grid |
| 197 | # WPT-NOTIFY: true |
| 198 | ``` |
| 199 | |
| 200 | When a test under `external/wpt/css/css-grid/` newly fails in a WPT import, the |
| 201 | importer will automatically file a bug against the Blink>Layout>Grid component |
| 202 | in [crbug.com][https://crbug.com], with details of which test failed and the |
| 203 | output. |
| 204 | |
| 205 | Note that we are considering making WPT-NOTIFY opt-out instead of opt-in: see |
| 206 | https://crbug.com/845232 |
| 207 | |
| 208 | ### Enabling import for a new directory |
| 209 | |
| 210 | If you wish to add more tests (by un-skipping some of the directories currently |
| 211 | skipped in `W3CImportExpectations`), you can modify that file locally and commit |
| 212 | it, and on the next auto-import, the new tests should be imported. |
| 213 | |
| 214 | If you want to import immediately (in order to try the tests out locally, etc) |
| 215 | you can also run `wpt-import`, but this is not required. |
| 216 | |
| 217 | Remember your import might fail due to GitHub's limit for unauthenticated |
| 218 | requests, so consider [passing your GitHub credentials](#GitHub-credentials) to |
| 219 | the script. |
| 220 | |
| 221 | ### Skipped tests |
| 222 | |
| 223 | We control which tests are imported via a file called |
| 224 | [W3CImportExpectations](../../third_party/blink/web_tests/W3CImportExpectations), |
| 225 | which has a list of directories to skip while importing. |
| 226 | |
| 227 | In addition to the directories and tests explicitly skipped there, tests may |
| 228 | also be skipped for a couple other reasons, e.g. if the file path is too long |
| 229 | for Windows. To check what files are skipped in import, check the recent logs |
| 230 | for [wpt-importer builder][wpt-importer]. |
| 231 | |
| 232 | ### Waterfall failures caused by automatic imports. |
| 233 | |
| 234 | If there are new test failures that start after an auto-import, |
| 235 | there are several possible causes, including: |
| 236 | |
| 237 | 1. New baselines for flaky tests were added (https://crbug.com/701234). |
| 238 | 2. Modified tests should have new results for non-Release builds but they weren't added (https://crbug.com/725160). |
| 239 | 3. New baselines were added for tests with non-deterministic test results (https://crbug.com/705125). |
| 240 | |
| 241 | Because these tests are imported from the Web Platform tests, it is better |
| 242 | to have them in the repository (and marked failing) than not, so prefer to |
| 243 | [add test expectations](web_test_expectations.md) rather than reverting. |
| 244 | However, if a huge number of tests are failing, please revert the CL so we |
| 245 | can fix it manually. |
| 246 | |
| 247 | [wpt-importer]: https://ci.chromium.org/p/infra/builders/luci.infra.cron/wpt-importer |
| 248 | |
| 249 | ## Exporting tests |
| 250 | |
| 251 | If you upload a CL with any changes in |
| 252 | [third_party/blink/web_tests/external/wpt](../../third_party/blink/web_tests/external/wpt), |
| 253 | once you add reviewers the exporter will create a provisional pull request with |
| 254 | those changes in the [upstream WPT GitHub repository](https://github.com/web-platform-tests/wpt/). |
| 255 | The exporter runs on [wpt-exporter builder][wpt-exporter]. |
| 256 | |
| 257 | Once you're ready to land your CL, please follow the link posted by the bot and |
| 258 | check the status of the required checks of the GitHub PR. If it's green, go |
| 259 | ahead landing your CL and the exporter will automatically merge the PR. |
| 260 | |
| 261 | If GitHub status is red on the PR, please try to resolve the failures before |
| 262 | merging. If you run into any issues, or if you have a CL with WPT changes that |
| 263 | the exporter did not pick up, please reach out to [email protected]. |
| 264 | |
| 265 | Additional things to note: |
| 266 | |
| 267 | - CLs that change over 1000 files will not be exported. |
| 268 | - All PRs use the |
| 269 | [`chromium-export`](https://github.com/web-platform-tests/wpt/pulls?utf8=%E2%9C%93&q=is%3Apr%20label%3Achromium-export) label. |
| 270 | - All PRs for CLs that haven't yet been landed in Chromium also use the |
| 271 | [`do not merge yet`](https://github.com/web-platform-tests/wpt/pulls?q=is%3Apr+is%3Aopen+label%3A%22do+not+merge+yet%22) label. |
| 272 | - The exporter cannot create upstream PRs for in-flight CLs with binary files |
| 273 | (e.g. webm files). An export PR will still be made after the CL lands. |
| 274 | |
| 275 | For maintainers: |
| 276 | |
| 277 | - The source lives in |
| 278 | [third_party/blink/tools/wpt_export.py](../../third_party/blink/tools/wpt_export.py). |
| 279 | - If the exporter starts misbehaving (for example, creating the same PR over |
| 280 | and over again), put it in "dry run" mode by landing [this CL](https://crrev.com/c/462381/). |
| 281 | |
| 282 | [wpt-exporter]: https://ci.chromium.org/p/infra/builders/luci.infra.cron/wpt-exporter |
| 283 | |
| 284 | ## Notes for WPT infra maintainers |
| 285 | |
| 286 | ### Manual import |
| 287 | |
| 288 | To pull the latest versions of the tests that are currently being imported, you |
| 289 | can also directly invoke the |
| 290 | [wpt-import](../../third_party/blink/tools/wpt_import.py) script. |
| 291 | |
| 292 | That script will pull the latest version of the tests from our mirrors of the |
| 293 | upstream repositories. If any new versions of tests are found, they will be |
| 294 | committed locally to your local repository. You may then upload the changes. |
| 295 | |
| 296 | Remember your import might fail due to GitHub's limit for unauthenticated |
| 297 | requests, so consider [passing your GitHub credentials](#GitHub-credentials) to |
| 298 | the script. |
| 299 | |
| 300 | ### GitHub credentials |
| 301 | |
| 302 | When manually running the `wpt-import` and `wpt-export` scripts, several |
| 303 | requests are made to GitHub to query the status of pull requests, look for |
| 304 | existing exported commits etc. GitHub has a [fairly |
| 305 | low](https://developer.github.com/v3/#rate-limiting) request limit for |
| 306 | unauthenticated requests, so it is recommended that you let `wpt-export` and |
| 307 | `wpt-import` use your GitHub credentials when sending requests: |
| 308 | |
| 309 | 1. Generate a new [personal access token](https://github.com/settings/tokens) |
| 310 | 1. Set up your credentials by either: |
| 311 | * Setting the `GH_USER` environment variable to your GitHub user name |
| 312 | and the `GH_TOKEN` environment variable to the access token you have |
| 313 | just created **or** |
| 314 | * Creating a JSON file with two keys: `GH_USER`, your GitHub user name, |
| 315 | and `GH_TOKEN`, the access token you have just generated. After that, |
| 316 | pass `--credentials-json <path-to-json>` to `wpt-export` and |
| 317 | `wpt-import`. |