blob: 1083d1e7db5396793efc3442cdf1189490fc85b9 [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
Robert Ma4f6eff12020-08-18 22:44:4555#### `testdriver.js`
56
Philip Jägenstedt3a3d5b82018-05-31 15:25:3557[testdriver.js](https://web-platform-tests.org/writing-tests/testdriver.html)
Philip Jägenstedt8bb32fa2018-01-27 14:39:2658provides a means to automate tests that cannot be written purely using web
59platform APIs, similar to `internals.*` and `eventSender.*` in regular Blink
Maksim Sadym8e2731f2025-03-11 16:14:5360web tests. It uses either [WebDriver Classic](https://www.w3.org/TR/webdriver/),
61or [WebDriver BiDi](https://www.w3.org/TR/webdriver-bidi/) protocols.
Philip Jägenstedt8bb32fa2018-01-27 14:39:2662
Maksim Sadym8e2731f2025-03-11 16:14:5363[WPT Test Automation for Chromium](https://docs.google.com/document/d/18BpD41vyX1cFZ77CE0a_DJYlGpdvyLlx3pwXVRxUzvI/edit?usp=sharing) overview.
64
65The recommended way to extend `testdriver.js` is by adding extending
66[WebDriver BiDi](https://www.w3.org/TR/webdriver-bidi/) protocol.
67
68##### WebDriver BiDi Specification
69
70The WebDriver BiDi protocol was designed to support cross-browser testing. It is
71extensible by design, and can be extended by a separate specification.
72
73###### Example
74
75The [WebDriver BiDi extension module](https://www.w3.org/TR/webdriver-bidi/#protocol-modules) `permissions` is outlined in an external specification: https://www.w3.org/TR/permissions/#automation-webdriver-bidi.
76
77##### WPT wdspec tests
78
79The specification part should be accompanied by WPT wdspec tests. These tests
80allow for implementations to verify they implement the BiDi extension properly.
81The process is described here: https://web-platform-tests.org/writing-tests/wdspec.html#extending-webdriver-bidi.
82
83###### Example
84
85WPT tests for permissions.setPermission command: webdriver/tests/bidi/external/permissions/set_permission.
86
87##### Implement the required endpoints in CDP
88
89Under the hood, Chromium is controlled by Chrome Devtools Protocol
90(https://chromedevtools.github.io/devtools-protocol/). This means that in order
91to implement the WebDriver BiDi commands, the corresponding commands should be
92added to CDP.
93
94##### Implement WebDriver BiDi commands using CDP
95
96The [BiDi-CDP Mapper](https://github.com/GoogleChromeLabs/chromium-bidi) is an
97implementation of WebDriver BiDi in Chromium, and is used by ChromeDriver. It
98translates WebDriver BiDi commands into Chrome DevTools Protocol (CDP) commands.
99
100[How to add the new commands to BiDi-CDP Mapper and roll it in ChromeDriver](https://github.com/GoogleChromeLabs/chromium-bidi#adding-new-command).
101
102###### Example
103
104[Implement permissions.setPermission”](https://github.com/GoogleChromeLabs/chromium-bidi/pull/1645).
105
106##### Extend `testdriver.js`
107
108In order to expose the new method to WPT tests, `testdriver.js` should be
109updated with the new method. This process is described in the [“Testdriver extension tutorial”](https://web-platform-tests.org/writing-tests/testdriver-extension-tutorial.html), referred to in “WebDriver BiDi” sections.
110
111###### Example
112
113[Add `test_driver.bidi.permissions.set_permission`](https://github.com/web-platform-tests/wpt/pull/49170).
foolipdf2a8632017-02-15 15:03:16114
Robert Ma4f6eff12020-08-18 22:44:45115#### MojoJS
116
117Some specs may define testing APIs (e.g.
118[WebUSB](https://wicg.github.io/webusb/test/)), which may be polyfilled with
119internal API like [MojoJS](../../mojo/public/js/README.md). MojoJS is only
120allowed in WPT for this purpose. Please reach out to
Raphael Kubo da Costafec70fa2023-03-02 18:36:44121blink-dev@chromium.org before following the process below for adding a new
Robert Ma4f6eff12020-08-18 22:44:45122test-only API:
123
Ken Rockot6355f092021-02-02 19:42:58124 1. Create a full list of `*.mojom.m.js` files that you need, including all
125 dependencies. Generated modules load dependencies recursively by default,
Robert Ma4f6eff12020-08-18 22:44:45126 so you can check the network panel of DevTools to see the full list of
127 dependencies it loads.
Raphael Kubo da Costafec70fa2023-03-02 18:36:44128 2. Check [linux-archive-rel.json](../../infra/archive_config/linux-archive-rel.json) and add any
Ken Rockot6355f092021-02-02 19:42:58129 missing `*.mojom.m.js` files to the `mojojs.zip` archive. Globs are
130 supported in `filename`. Do not copy Mojom bindings into WPT.
Robert Ma4f6eff12020-08-18 22:44:45131 3. Meanwhile in Chromium, you can create a helper for your WPT tests to do
132 browser-specific setup using
133 [test-only-api.js](../../third_party/blink/web_tests/external/wpt/resources/test-only-api.js).
134 See
135 [webxr_util.js](../../third_party/blink/web_tests/external/wpt/webxr/resources/webxr_util.js)
136 as an example. You can write tests using this helper right away, but they
137 will not work upstream (i.e. on https://wpt.fyi ) until your change in step
138 2 is included in official channels, as `mojojs.zip` is built alongside with
139 Chrome.
140
141#### `wpt_automation`
142
143An alternative to the above options is to write manual tests that are automated
144with scripts from
Kent Tamura59ffb022018-11-27 05:30:56145[wpt_automation](../../third_party/blink/web_tests/external/wpt_automation).
Quinten Yearsleye577029f2017-07-06 00:21:03146Injection of JS in manual tests is determined by `loadAutomationScript` in
Kent Tamura59ffb022018-11-27 05:30:56147[testharnessreport.js](../../third_party/blink/web_tests/resources/testharnessreport.js).
Quinten Yearsleye577029f2017-07-06 00:21:03148
foolipdf2a8632017-02-15 15:03:16149Such tests still require case-by-case automation to run for other browser
150engines, but are more valuable than purely manual tests.
151
Quinten Yearsleye577029f2017-07-06 00:21:03152Manual tests that have no automation are still imported, but skipped in
Kent Tamura59ffb022018-11-27 05:30:56153[NeverFixTests](../../third_party/blink/web_tests/NeverFixTests); see
Quinten Yearsleye577029f2017-07-06 00:21:03154[issue 738489](https://crbug.com/738489).
155
Robert Ma4f6eff12020-08-18 22:44:45156### Contribution process
157
158Changes made in
159[web_tests/external/wpt](../../third_party/blink/web_tests/external/wpt) are
160[automatically exported to GitHub](#exporting-tests).
161
162It's still possible to make direct pull requests to web-platform-tests, see
163https://web-platform-tests.org/writing-tests/github-intro.html.
164
foolipdf2a8632017-02-15 15:03:16165### Adding new top-level directories
qyearsley9c9781a2017-02-11 00:08:39166
167Entirely new top-level directories should generally be added upstream, since
168that's the only way to add an OWNERS file upstream. After adding a new top-level
169directory upstream, you should add a line for it in `W3CImportExpectations`.
170
foolipdf2a8632017-02-15 15:03:16171Adding the new directory (and `W3CImportExpectations` entry) in Chromium and
172later adding an OWNERS file upstream also works.
173
Robert Ma4f6eff12020-08-18 22:44:45174### `wpt_internal`
Stephen McGruera12b34f82020-07-10 16:00:42175
176It is sometimes desirable to write WPT tests that either test Chromium-specific
177behaviors, or that cannot yet be upstreamed to WPT (e.g. because the spec is
178very nascent). For these cases, we maintain a separate directory,
Chris Mumfordbbe6b8e2021-09-09 21:06:18179[wpt_internal](../../third_party/blink/web_tests/wpt_internal) that runs under the
Stephen McGruera12b34f82020-07-10 16:00:42180WPT testing infrastructure (e.g. uses wptserve, etc), but which is not
181upstreamed to WPT.
182
183Please see the `wpt_internal`
sisidovski805efc22021-09-10 23:40:44184[README](../../third_party/blink/web_tests/wpt_internal/README.md) for more details.
Stephen McGruera12b34f82020-07-10 16:00:42185
186**Note**: A significant downside of `wpt_internal` is that your tests may be
187broken by upstream changes to the resources scripts (e.g. `testharness.js`), as
188`wpt_internal` does not use the forked version of `testharness.js` used by all
Robert Maa23460e72020-12-20 12:39:27189other non-`external/wpt` tests. Use of [new failure
190notifications](#new-failure-notifications) is recommended to ensure you are
191notified of breakages.
foolipdf2a8632017-02-15 15:03:16192
Jeff Carpenter11b548b2017-11-03 23:05:22193## Running tests
194
Kent Tamura59ffb022018-11-27 05:30:56195Same as Blink web tests, you can use
Weizhong Xiac994d2c72023-11-17 16:13:13196[`run_web_tests.py`](web_tests.md#running-the-tests) to run any WPT test. This
197will run WPT tests in Content Shell. You can also run [`run_wpt_tests.py`](run_web_platform_tests.md) to
198run WPT tests with Chrome.
Jonathan Lee1124233e2023-07-24 18:20:41199
Jeff Carpenter11b548b2017-11-03 23:05:22200One thing to note is that glob patterns for WPT tests are not yet supported.
201
Xianzhu Wang0a37e9d2019-03-27 21:27:29202See [Running WPT tests in Content Shell](web_tests_in_content_shell.md#Running-WPT-Tests-in-Content-Shell)
203for debugging etc.
204
foolipdf2a8632017-02-15 15:03:16205## Reviewing tests
206
207Anyone who can review code and tests in Chromium can also review changes in
Kent Tamura59ffb022018-11-27 05:30:56208[external/wpt](../../third_party/blink/web_tests/external/wpt)
foolipdf2a8632017-02-15 15:03:16209that will be automatically upstreamed. There will be no additional review in
210web-platform-tests as part of the export process.
211
212If upstream reviewers have feedback on the changes, discuss on the pull request
213created during export, and if necessary work on a new pull request to iterate
214until everyone is satisfied.
215
216When reviewing tests, check that they match the relevant specification, which
217may not fully match the implementation. See also
218[Write tests against specifications](#Write-tests-against-specifications).
Stephen McGruera12b34f82020-07-10 16:00:42219
220## Importing tests
221
222Chromium has a [mirror](https://chromium.googlesource.com/external/w3c/web-platform-tests/)
223of the GitHub repo and periodically imports a subset of the tests to
224run as part of the regular Blink web test testing process.
225
226The goals of this process are to be able to run web-platform-tests unmodified
227locally just as easily as we can run the Blink tests, and ensure that we are
228tracking tip-of-tree in the web-platform-tests repository as closely as
229possible, and running as many of the tests as possible.
230
231### Automatic import process
232
233There is an automatic process for updating the Chromium copy of
234web-platform-tests. The import is done by the builder [wpt-importer
235builder][wpt-importer].
236
237The easiest way to check the status of recent imports is to look at:
238
239- Recent logs on LUCI for [wpt-importer builder][wpt-importer]
240- Recent CLs created by [WPT
241 Autoroller](https://chromium-review.googlesource.com/q/owner:wpt-autoroller%2540chops-service-accounts.iam.gserviceaccount.com).
242
243The import jobs will generally be green if either there was nothing to do,
244or a CL was successfully submitted.
245
246For maintainers:
247
248- The source lives in
249 [third_party/blink/tools/wpt_import.py](../../third_party/blink/tools/wpt_import.py).
250- If the importer starts misbehaving, it can be disabled by landing a
251 [CL to skip the update step](https://crrev.com/c/1961906/).
252
Robert Maa23460e72020-12-20 12:39:27253### New failure notifications
Stephen McGruera12b34f82020-07-10 16:00:42254
An Sung183d2ac2023-08-24 00:05:08255The importer automatically file bugs against a component when imported changes
256introduce failures as long as test owners did not choose to opt-out the failure
257notification mechanism. This includes new tests that fail in Chromium, as well
258as new failures introduced to an existing test. Test owners are encouraged to
259create an `DIR_METADATA` file in the appropriate `external/wpt/` subdirectory
Jonathan Lee61fc72852024-02-05 19:55:49260that contains at least the `buganizer_public.component_id` field, which the
261importer will use to file bugs.
An Sung183d2ac2023-08-24 00:05:08262For example, `external/wpt/css/css-grid/DIR_METADATA` looks like:
Stephen McGruera12b34f82020-07-10 16:00:42263
264```
nihardamar3afa5562023-09-28 21:41:21265buganizer_public {
266 component_id: 1415957
267}
Robert Maa23460e72020-12-20 12:39:27268team_email: "[email protected]"
Stephen McGruera12b34f82020-07-10 16:00:42269```
270
Jonathan Leeaafbd5e2023-07-11 01:52:39271When tests under `external/wpt/css/css-grid/` newly fail in a WPT import, the
Jonathan Lee61fc72852024-02-05 19:55:49272importer will automatically file a bug against the `Chromium>Blink>Layout>Grid`
273component in [issues.chromium.org](https://issues.chromium.org/issues), with
274details of which tests failed and the outputs.
Jonathan Leeaafbd5e2023-07-11 01:52:39275The importer will also copy `[email protected]` (the `team_email`) and any
276`external/wpt/css/css-grid/OWNERS` on the bug.
277
278Failing tests are grouped according to the most specific `DIR_METADATA` that
279they roll up to.
Stephen McGruera12b34f82020-07-10 16:00:42280
An Sung183d2ac2023-08-24 00:05:08281To opt-out of this notification, add `wpt.notify` field set to `NO` to the
282corresponding `DIR_METADATA`.
283For example, the following `DIR_METADATA` will suppress notification from tests
284under the located directory:
285
286```
Jonathan Lee61fc72852024-02-05 19:55:49287buganizer_public {
288 component_id: 1415957
An Sung183d2ac2023-08-24 00:05:08289}
290team_email: "[email protected]"
291wpt {
292 notify: NO
293}
294```
Stephen McGruera12b34f82020-07-10 16:00:42295
Robert Ma4f6eff12020-08-18 22:44:45296### Skipped tests (and how to re-enable them)
Stephen McGruera12b34f82020-07-10 16:00:42297
298We control which tests are imported via a file called
299[W3CImportExpectations](../../third_party/blink/web_tests/W3CImportExpectations),
300which has a list of directories to skip while importing.
301
302In addition to the directories and tests explicitly skipped there, tests may
303also be skipped for a couple other reasons, e.g. if the file path is too long
304for Windows. To check what files are skipped in import, check the recent logs
305for [wpt-importer builder][wpt-importer].
306
Robert Ma4f6eff12020-08-18 22:44:45307If you wish to un-skip some of the directories currently skipped in
308`W3CImportExpectations`, you can modify that file locally and commit it, and on
309the next auto-import, the new tests should be imported.
310
311If you want to import immediately (in order to try the tests out locally, etc)
312you can also run `wpt-import`, but this is not required.
313
314Remember your import might fail due to GitHub's limit for unauthenticated
315requests, so consider [passing your GitHub credentials](#GitHub-credentials) to
316the script.
317
Stephen McGruera12b34f82020-07-10 16:00:42318### Waterfall failures caused by automatic imports.
319
320If there are new test failures that start after an auto-import,
321there are several possible causes, including:
322
323 1. New baselines for flaky tests were added (https://crbug.com/701234).
324 2. Modified tests should have new results for non-Release builds but they weren't added (https://crbug.com/725160).
325 3. New baselines were added for tests with non-deterministic test results (https://crbug.com/705125).
326
327Because these tests are imported from the Web Platform tests, it is better
328to have them in the repository (and marked failing) than not, so prefer to
329[add test expectations](web_test_expectations.md) rather than reverting.
330However, if a huge number of tests are failing, please revert the CL so we
331can fix it manually.
332
333[wpt-importer]: https://ci.chromium.org/p/infra/builders/luci.infra.cron/wpt-importer
334
335## Exporting tests
336
337If you upload a CL with any changes in
338[third_party/blink/web_tests/external/wpt](../../third_party/blink/web_tests/external/wpt),
Weizhong Xia55d9df522024-06-03 16:35:00339once your CL is ready to submit the exporter will create a provisional pull request with
Stephen McGruera12b34f82020-07-10 16:00:42340those changes in the [upstream WPT GitHub repository](https://github.com/web-platform-tests/wpt/).
341The exporter runs on [wpt-exporter builder][wpt-exporter].
342
343Once you're ready to land your CL, please follow the link posted by the bot and
344check the status of the required checks of the GitHub PR. If it's green, go
345ahead landing your CL and the exporter will automatically merge the PR.
346
347If GitHub status is red on the PR, please try to resolve the failures before
348merging. If you run into any issues, or if you have a CL with WPT changes that
Raphael Kubo da Costafec70fa2023-03-02 18:36:44349the exporter did not pick up, please reach out to blink-dev@chromium.org.
Stephen McGruera12b34f82020-07-10 16:00:42350
351Additional things to note:
352
353- CLs that change over 1000 files will not be exported.
354- All PRs use the
355 [`chromium-export`](https://github.com/web-platform-tests/wpt/pulls?utf8=%E2%9C%93&q=is%3Apr%20label%3Achromium-export) label.
356- All PRs for CLs that haven't yet been landed in Chromium also use the
357 [`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.
358- The exporter cannot create upstream PRs for in-flight CLs with binary files
359 (e.g. webm files). An export PR will still be made after the CL lands.
360
Robert Ma4f6eff12020-08-18 22:44:45361### Will the exported commits be linked to my GitHub profile?
Stephen McGruera12b34f82020-07-10 16:00:42362
Robert Ma4f6eff12020-08-18 22:44:45363The email you commit with in Chromium will be the author of the commit on
364GitHub. You can [add it as a secondary address on your GitHub
365account](https://help.github.com/articles/adding-an-email-address-to-your-github-account/)
366to link your exported commits to your GitHub profile.
367
368If you are a Googler, you can also register your GitHub account at go/github,
369making it easier for other Googlers to find you.
370
371### What if there are conflicts?
372
373This cannot be avoided entirely as the two repositories are independent, but
374should be rare with frequent imports and exports. When it does happen, manual
375intervention will be needed and in non-trivial cases you may be asked to help
376resolve the conflict.
Stephen McGruera12b34f82020-07-10 16:00:42377
378[wpt-exporter]: https://ci.chromium.org/p/infra/builders/luci.infra.cron/wpt-exporter
379
380## Notes for WPT infra maintainers
381
Stephen McGruerba2aa522021-02-26 21:27:43382### Importer
383
384#### Rubber-Stamper bot
385
386To allow the importer to land CLs without human intervention, it utilizes the
387[Rubber-Stamper
John Palmer046f9872021-05-24 01:24:56388bot](https://chromium.googlesource.com/infra/infra/+/refs/heads/main/go/src/infra/appengine/rubber-stamper/README.md)
Stephen McGruerba2aa522021-02-26 21:27:43389to approve import CLs.
390
391Adding the Rubber-Stamper as a reviewer is one of the last steps the importer
392takes, once tests have been rebaselined and the CQ passes. If the Rubber-Stamper
393cannot approve a CL, it will leave a comment on the CL explaining why - this
394will also cause the importer to go red.
395
396![Rubber-Stamber bot rejecting a CL](images/wpt_import_rubber_stamper_reject.png)
397
398There are two possibilities when the Rubber-Stamper rejects an import: either it
399is a valid rejection, because the import changes code files (`.py`, `.bat`,
400`.sh`), or it is invalid and we're missing an allowlist rule for a file the
401importer is allowed to modify.
402
403For valid rejections, it is the job of the rotation sheriff to land the CL
404manually. You need to un-abandon the import, `CR+1` it yourself, and `CQ+2` it.
405If you don't have permission to do that (e.g. are not a committer), contact
Raphael Kubo da Costafec70fa2023-03-02 18:36:44406[email protected].
Stephen McGruerba2aa522021-02-26 21:27:43407
Raphael Kubo da Costafec70fa2023-03-02 18:36:44408For invalid rejections, message [email protected] or add an exception
Stephen McGruerba2aa522021-02-26 21:27:43409rule yourself. [This is an example
410CL](https://chrome-internal-review.googlesource.com/c/infradata/config/+/3608170)
411that adds an exception rule. (Note that you need internal access to access this
412repository).
413
414#### Manual import
Stephen McGruera12b34f82020-07-10 16:00:42415
416To pull the latest versions of the tests that are currently being imported, you
417can also directly invoke the
418[wpt-import](../../third_party/blink/tools/wpt_import.py) script.
419
420That script will pull the latest version of the tests from our mirrors of the
421upstream repositories. If any new versions of tests are found, they will be
422committed locally to your local repository. You may then upload the changes.
423
424Remember your import might fail due to GitHub's limit for unauthenticated
425requests, so consider [passing your GitHub credentials](#GitHub-credentials) to
426the script.
427
Robert Ma4f6eff12020-08-18 22:44:45428### Exporter
429
430- The source lives in
431 [third_party/blink/tools/wpt_export.py](../../third_party/blink/tools/wpt_export.py).
432- If the exporter starts misbehaving (for example, creating the same PR over
433 and over again), put it in "dry run" mode by landing [this
434 CL](https://crrev.com/c/462381/).
435
Stephen McGruera12b34f82020-07-10 16:00:42436### GitHub credentials
437
438When manually running the `wpt-import` and `wpt-export` scripts, several
439requests are made to GitHub to query the status of pull requests, look for
440existing exported commits etc. GitHub has a [fairly
441low](https://developer.github.com/v3/#rate-limiting) request limit for
442unauthenticated requests, so it is recommended that you let `wpt-export` and
443`wpt-import` use your GitHub credentials when sending requests:
444
445 1. Generate a new [personal access token](https://github.com/settings/tokens)
446 1. Set up your credentials by either:
447 * Setting the `GH_USER` environment variable to your GitHub user name
448 and the `GH_TOKEN` environment variable to the access token you have
449 just created **or**
450 * Creating a JSON file with two keys: `GH_USER`, your GitHub user name,
451 and `GH_TOKEN`, the access token you have just generated. After that,
452 pass `--credentials-json <path-to-json>` to `wpt-export` and
453 `wpt-import`.
Yoshisato Yanagisawa638e2ee02021-12-09 05:52:08454
455### Debugging failed web platform tests
456
457This section explains the way to debug web platform tests.
458Please build `blink_tests` before running commands below.
459It is explained in [Running Web Tests](./web_tests.md#running-web-tests).
460
461#### Running test(s)
462
463The way to run web tests is explained in [Running the
464Tests](./web_tests.md#running-the-tests).
465
466Assume that you are writing the test named `wpt_internal/fake/foobar.html`.
467You may want to run only the tests and you do not want to run all tests under
468`wpt_internal/fake`. The following command narrows down the test to only
469`wpt_internal/fake/foobar.html`.
470
471```bash
472third_party/blink/tools/run_web_tests.py -t Default \
473third_party/blink/web_tests/wpt_internal/fake/foobar.html
474```
475
476#### Logging
477
478During the debug, you may want to log what happens during the test.
479You can use `console.log` in JavaScript to log arbitrary strings.
480
481```
482e.g.
483console.log('fake has been executed.');
484console.log('foo=' + foo);
485```
486
487Logs are written under `$root_build_dir/layout-test-results`.
488If you have tested `wpt_internal/fake/foobar.html`, the log will be stored in
489`$root_build_dir/layout-test-results/wpt_internal/fake/foobar-stderr.txt`.
490You can change output directory with `--results-directory=<output directory>`.
491
492#### Checking HTTP servers
493
494For some test cases, you may use .headers file to set arbitrary HTTP headers.
495To verify what is set to headers, you can run an HTTP server used for WPT
496by yourself. The following command starts the HTTP server for you:
497
498```bash
499third_party/blink/tools/run_blink_wptserve.py
500```
501
502To see headers returned by the server, you can use `curl -v`.
503`curl` will show headers in stderr. You may want to use `|& less` to
504see output if it is too long.
505
506```bash
507curl -v http://localhost:8081/wpt_internal/fake/foobar.html |& less
508```
Takahiro961b2422022-01-19 00:14:29509
510#### Debugging with a debugger
511
512You are able to debug the inside of Chromium with a debugger for particular
513WPT tests. Refer to [Running web tests using the content shell](https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/testing/web_tests_in_content_shell.md)
514for details.