blob: a20e72858ebe74efd60704353f91e958ddd2d3d0 [file] [log] [blame] [view]
foolipeda32ab2017-02-16 19:21:581# web-platform-tests
qyearsley4f0acca42017-01-30 08:18:432
rbyers6299b9132017-02-10 18:06:573Interoperability between browsers is
qyearsley9c9781a2017-02-11 00:08:394[critical](https://www.chromium.org/blink/platform-predictability) to Chromium's
5mission of improving the web. We believe that leveraging and contributing to a
6shared test suite is one of the most important tools in achieving
7interoperability between browsers. The [web-platform-tests
Philip Jägenstedt3a3d5b82018-05-31 15:25:358repository](https://github.com/web-platform-tests/wpt) is the primary shared
Quinten Yearsleyfab627a2017-03-29 22:30:189test suite where all browser engines are collaborating.
qyearsley4f0acca42017-01-30 08:18:4310
Jeff Carpenterabd13602017-03-29 22:49:5911Chromium has a 2-way import/export process with the upstream web-platform-tests
foolipdf2a8632017-02-15 15:03:1612repository, where tests are imported into
Kent Tamura59ffb022018-11-27 05:30:5613[web_tests/external/wpt](../../third_party/blink/web_tests/external/wpt)
foolipdf2a8632017-02-15 15:03:1614and any changes to the imported tests are also exported to web-platform-tests.
15
Philip Jägenstedt3a3d5b82018-05-31 15:25:3516See https://web-platform-tests.org/ for general documentation on
foolipeda32ab2017-02-16 19:21:5817web-platform-tests, including tips for writing and reviewing tests.
18
qyearsley4f0acca42017-01-30 08:18:4319[TOC]
20
foolipdf2a8632017-02-15 15:03:1621## Writing tests
qyearsley4f0acca42017-01-30 08:18:4322
foolipeda32ab2017-02-16 19:21:5823To contribute changes to web-platform-tests, just commit your changes directly
Kent Tamura59ffb022018-11-27 05:30:5624to [web_tests/external/wpt](../../third_party/blink/web_tests/external/wpt)
qyearsley4f0acca42017-01-30 08:18:4325and the changes will be automatically upstreamed within 24 hours.
26
foolipdf2a8632017-02-15 15:03:1627Changes involving adding, removing or modifying tests can all be upstreamed.
28Any changes outside of
Kent Tamura59ffb022018-11-27 05:30:5629[external/wpt](../../third_party/blink/web_tests/external/wpt) will not be
foolipdf2a8632017-02-15 15:03:1630upstreamed, and any changes `*-expected.txt`, `OWNERS`, and `MANIFEST.json`,
31will also not be upstreamed.
rbyers6299b9132017-02-10 18:06:5732
Kent Tamura59ffb022018-11-27 05:30:5633Running the web tests will automatically regenerate MANIFEST.json to pick up
Jeff Carpentereb1ff6b2017-03-02 23:21:5834any local modifications.
foolip2f198552017-02-24 16:42:3535
foolipdf2a8632017-02-15 15:03:1636Most tests are written using testharness.js, see
Kent Tamura59ffb022018-11-27 05:30:5637[Writing Web Tests](./writing_web_tests.md) and
38[Web Tests Tips](./web_tests_tips.md) for general guidelines.
qyearsley9c9781a2017-02-11 00:08:3939
foolipdf2a8632017-02-15 15:03:1640### Write tests against specifications
41
foolipeda32ab2017-02-16 19:21:5842Tests in web-platform-tests are expected to match behavior defined by the
foolipdf2a8632017-02-15 15:03:1643relevant specification. In other words, all assertions that a test makes
44should be derived from a specification's normative requirements, and not go
45beyond them. It is often necessary to change the specification to clarify what
46is and isn't required.
47
Philip Jägenstedt8bb32fa2018-01-27 14:39:2648When implementation experience is needed to inform the specification work,
Philip Jägenstedt3a3d5b82018-05-31 15:25:3549[tentative tests](https://web-platform-tests.org/writing-tests/file-names.html)
Philip Jägenstedt8bb32fa2018-01-27 14:39:2650can be appropriate. It should be apparent in context why the test is tentative
51and what needs to be resolved to make it non-tentative.
foolipdf2a8632017-02-15 15:03:1652
53### Tests that require testing APIs
54
Philip Jägenstedt3a3d5b82018-05-31 15:25:3555[testdriver.js](https://web-platform-tests.org/writing-tests/testdriver.html)
Philip Jägenstedt8bb32fa2018-01-27 14:39:2656provides a means to automate tests that cannot be written purely using web
57platform APIs, similar to `internals.*` and `eventSender.*` in regular Blink
Kent Tamura59ffb022018-11-27 05:30:5658web tests.
Philip Jägenstedt8bb32fa2018-01-27 14:39:2659
60If no testdriver.js API exists, check if it's a
Philip Jägenstedt3a3d5b82018-05-31 15:25:3561[known issue](https://github.com/web-platform-tests/wpt/labels/testdriver.js)
Luke Zielinski64ff9492019-05-30 17:42:2962and otherwise consider filing a new issue. For instructions on how to add a new
63testing API, see [WPT Test Automation for
64Chromium](https://docs.google.com/document/d/18BpD41vyX1cFZ77CE0a_DJYlGpdvyLlx3pwXVRxUzvI/preview#)
foolipdf2a8632017-02-15 15:03:1665
66An alternative is to write manual tests that are automated with scripts from
Kent Tamura59ffb022018-11-27 05:30:5667[wpt_automation](../../third_party/blink/web_tests/external/wpt_automation).
Quinten Yearsleye577029f2017-07-06 00:21:0368Injection of JS in manual tests is determined by `loadAutomationScript` in
Kent Tamura59ffb022018-11-27 05:30:5669[testharnessreport.js](../../third_party/blink/web_tests/resources/testharnessreport.js).
Quinten Yearsleye577029f2017-07-06 00:21:0370
foolipdf2a8632017-02-15 15:03:1671Such tests still require case-by-case automation to run for other browser
72engines, but are more valuable than purely manual tests.
73
Quinten Yearsleye577029f2017-07-06 00:21:0374Manual tests that have no automation are still imported, but skipped in
Kent Tamura59ffb022018-11-27 05:30:5675[NeverFixTests](../../third_party/blink/web_tests/NeverFixTests); see
Quinten Yearsleye577029f2017-07-06 00:21:0376[issue 738489](https://crbug.com/738489).
77
foolipdf2a8632017-02-15 15:03:1678### Adding new top-level directories
qyearsley9c9781a2017-02-11 00:08:3979
80Entirely new top-level directories should generally be added upstream, since
81that's the only way to add an OWNERS file upstream. After adding a new top-level
82directory upstream, you should add a line for it in `W3CImportExpectations`.
83
foolipdf2a8632017-02-15 15:03:1684Adding the new directory (and `W3CImportExpectations` entry) in Chromium and
85later adding an OWNERS file upstream also works.
86
qyearsley4f0acca42017-01-30 08:18:4387### Will the exported commits be linked to my GitHub profile?
88
89The email you commit with in Chromium will be the author of the commit on
90GitHub. You can [add it as a secondary address on your GitHub
91account](https://help.github.com/articles/adding-an-email-address-to-your-github-account/)
92to link your exported commits to your GitHub profile.
93
Philip Jägenstedtf7e99cf2018-01-22 15:54:2994If you are a Googler, you can also register your GitHub account at go/github,
95making it easier for other Googlers to find you.
96
qyearsley4f0acca42017-01-30 08:18:4397### What if there are conflicts?
98
99This cannot be avoided entirely as the two repositories are independent, but
100should be rare with frequent imports and exports. When it does happen, manual
101intervention will be needed and in non-trivial cases you may be asked to help
102resolve the conflict.
103
104### Direct pull requests
105
foolipeda32ab2017-02-16 19:21:58106It's still possible to make direct pull requests to web-platform-tests, see
Stephen McGruera12b34f82020-07-10 16:00:42107https://web-platform-tests.org/writing-tests/github-intro.html.
108
109### wpt_internal
110
111It is sometimes desirable to write WPT tests that either test Chromium-specific
112behaviors, or that cannot yet be upstreamed to WPT (e.g. because the spec is
113very nascent). For these cases, we maintain a separate directory,
114[wpt_internal](../third_party/blink/web_tests/wpt_internal) that runs under the
115WPT testing infrastructure (e.g. uses wptserve, etc), but which is not
116upstreamed to WPT.
117
118Please 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
122broken 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
124other non-`external/wpt` tests. Use of [WPT-NOTIFY](#wpt_notify) is recommended
125to ensure you are notified of breakages.
foolipdf2a8632017-02-15 15:03:16126
Jeff Carpenter11b548b2017-11-03 23:05:22127## Running tests
128
Kent Tamura59ffb022018-11-27 05:30:56129Same as Blink web tests, you can use
130[`run_web_tests.py`](web_tests.md#running-the-tests) to run any WPT test.
Jeff Carpenter11b548b2017-11-03 23:05:22131
132One thing to note is that glob patterns for WPT tests are not yet supported.
133
Xianzhu Wang0a37e9d2019-03-27 21:27:29134See [Running WPT tests in Content Shell](web_tests_in_content_shell.md#Running-WPT-Tests-in-Content-Shell)
135for debugging etc.
136
foolipdf2a8632017-02-15 15:03:16137## Reviewing tests
138
139Anyone who can review code and tests in Chromium can also review changes in
Kent Tamura59ffb022018-11-27 05:30:56140[external/wpt](../../third_party/blink/web_tests/external/wpt)
foolipdf2a8632017-02-15 15:03:16141that will be automatically upstreamed. There will be no additional review in
142web-platform-tests as part of the export process.
143
144If upstream reviewers have feedback on the changes, discuss on the pull request
145created during export, and if necessary work on a new pull request to iterate
146until everyone is satisfied.
147
148When reviewing tests, check that they match the relevant specification, which
149may not fully match the implementation. See also
150[Write tests against specifications](#Write-tests-against-specifications).
Stephen McGruera12b34f82020-07-10 16:00:42151
152## Importing tests
153
154Chromium has a [mirror](https://chromium.googlesource.com/external/w3c/web-platform-tests/)
155of the GitHub repo and periodically imports a subset of the tests to
156run as part of the regular Blink web test testing process.
157
158The goals of this process are to be able to run web-platform-tests unmodified
159locally just as easily as we can run the Blink tests, and ensure that we are
160tracking tip-of-tree in the web-platform-tests repository as closely as
161possible, and running as many of the tests as possible.
162
163### Automatic import process
164
165There is an automatic process for updating the Chromium copy of
166web-platform-tests. The import is done by the builder [wpt-importer
167builder][wpt-importer].
168
169The 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
175The import jobs will generally be green if either there was nothing to do,
176or a CL was successfully submitted.
177
178For 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
187Test owners can elect to have the importer automatically file bugs against a
188component when imported changes introduce failures. This includes new tests that
189fail in Chromium, as well as new failures introduced to an existing test. To
190opt-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
200When a test under `external/wpt/css/css-grid/` newly fails in a WPT import, the
201importer will automatically file a bug against the Blink>Layout>Grid component
202in [crbug.com][https://crbug.com], with details of which test failed and the
203output.
204
205Note that we are considering making WPT-NOTIFY opt-out instead of opt-in: see
206https://crbug.com/845232
207
208### Enabling import for a new directory
209
210If you wish to add more tests (by un-skipping some of the directories currently
211skipped in `W3CImportExpectations`), you can modify that file locally and commit
212it, and on the next auto-import, the new tests should be imported.
213
214If you want to import immediately (in order to try the tests out locally, etc)
215you can also run `wpt-import`, but this is not required.
216
217Remember your import might fail due to GitHub's limit for unauthenticated
218requests, so consider [passing your GitHub credentials](#GitHub-credentials) to
219the script.
220
221### Skipped tests
222
223We control which tests are imported via a file called
224[W3CImportExpectations](../../third_party/blink/web_tests/W3CImportExpectations),
225which has a list of directories to skip while importing.
226
227In addition to the directories and tests explicitly skipped there, tests may
228also be skipped for a couple other reasons, e.g. if the file path is too long
229for Windows. To check what files are skipped in import, check the recent logs
230for [wpt-importer builder][wpt-importer].
231
232### Waterfall failures caused by automatic imports.
233
234If there are new test failures that start after an auto-import,
235there 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
241Because these tests are imported from the Web Platform tests, it is better
242to have them in the repository (and marked failing) than not, so prefer to
243[add test expectations](web_test_expectations.md) rather than reverting.
244However, if a huge number of tests are failing, please revert the CL so we
245can fix it manually.
246
247[wpt-importer]: https://ci.chromium.org/p/infra/builders/luci.infra.cron/wpt-importer
248
249## Exporting tests
250
251If you upload a CL with any changes in
252[third_party/blink/web_tests/external/wpt](../../third_party/blink/web_tests/external/wpt),
253once you add reviewers the exporter will create a provisional pull request with
254those changes in the [upstream WPT GitHub repository](https://github.com/web-platform-tests/wpt/).
255The exporter runs on [wpt-exporter builder][wpt-exporter].
256
257Once you're ready to land your CL, please follow the link posted by the bot and
258check the status of the required checks of the GitHub PR. If it's green, go
259ahead landing your CL and the exporter will automatically merge the PR.
260
261If GitHub status is red on the PR, please try to resolve the failures before
262merging. If you run into any issues, or if you have a CL with WPT changes that
263the exporter did not pick up, please reach out to [email protected].
264
265Additional 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
275For 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
288To pull the latest versions of the tests that are currently being imported, you
289can also directly invoke the
290[wpt-import](../../third_party/blink/tools/wpt_import.py) script.
291
292That script will pull the latest version of the tests from our mirrors of the
293upstream repositories. If any new versions of tests are found, they will be
294committed locally to your local repository. You may then upload the changes.
295
296Remember your import might fail due to GitHub's limit for unauthenticated
297requests, so consider [passing your GitHub credentials](#GitHub-credentials) to
298the script.
299
300### GitHub credentials
301
302When manually running the `wpt-import` and `wpt-export` scripts, several
303requests are made to GitHub to query the status of pull requests, look for
304existing exported commits etc. GitHub has a [fairly
305low](https://developer.github.com/v3/#rate-limiting) request limit for
306unauthenticated 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`.