README.md
1web-platform-tests
2==================
3
4This directory contains the W3C
5[web-platform-tests](http://github.com/w3c/web-platform-tests). They
6can be run using `mach`:
7
8 mach web-platform-tests
9
10To limit the testrun to certain directories use the `--include` option;
11for example:
12
13 mach web-platform-tests --include=dom
14
15The testsuite contains a mix of javascript tests and reftests. To
16limit the type of tests that get run, use `--test-type=testharness` for
17javascript tests or `--test-type=reftest` for reftests.
18
19FAQ
20---
21
22* I fixed a bug and some tests have started to pass. How do I fix the
23 UNEXPECTED-PASS messages when web-platform-tests is run?
24
25 You need to update the expectation data for those tests. See the
26 section on expectations below.
27
28* I want to write some new tests for the web-platform-tests
29 testsuite. How do I do that?
30
31 See the section on tests below. You can commit the tests directly to
32 the Mozilla repository under `testing/web-platform/tests` and they
33 will be upstreamed next time the test is imported. For this reason
34 please ensure that any tests you write are testing correct-per-spec
35 behaviour even if we don't yet pass, get proper review, and have a
36 commit message that makes sense outside of the Mozilla
37 context. If you are writing tests that should not be upstreamed yet
38 for some reason they must be located under
39 `testing/web-platform/mozilla/tests`.
40
41 It is important to note that in order for the tests to run the
42 manifest file must be updated; this should not be done by hand, but
43 by running `mach wpt-manifest-update` (or `mach web-platform-tests
44 --manifest-update`, if you also wish to run some tests).
45
46 `mach web-platform-tests-create <path>` is a helper script designed
47 to help create new web-platform-tests. It opens a locally configured
48 editor at `<path>` with web-platform-tests boilerplate filled in,
49 and in the background runs `mach web-platform-tests
50 --manifest-update <path>`, so the test being developed is added to
51 the manifest and opened for interactive development.
52
53* How do I write a test that requires the use of a Mozilla-specific
54 feature?
55
56 Tests in the `mozilla/tests/` directory use the same harness but are
57 not synced with any upstream. Be aware that these tests run on the
58 server with a `/_mozilla/` prefix to their URLs.
59
60* A test is unstable; how do I disable it?
61
62 See the section on disabling tests.
63
64Directories
65-----------
66
67`tests/` contains the tests themselves. This is a copy of a certain
68revision of web-platform-tests. Any patches modifying this directory
69will be upstreamed next time the tests are imported.
70
71`harness/` contains the [wptrunner](http://github.com/w3c/wptrunner)
72test runner. Again the contents of this directory will be overwritten
73on update.
74
75`meta/` contains Gecko-specific expectation data. This is explained in
76the following section.
77
78`mozilla/tests` contains tests that will not be upstreamed and may
79make use of Mozilla-specific features.
80
81`mozilla/meta` contains metadata for the Mozilla-specific tests.
82
83Expectation Data
84----------------
85
86With the tests coming from upstream, it is not guaranteed that they
87all pass in Gecko-based browsers. For this reason it is necessary to
88provide metadata about the expected results of each test. This is
89provided in a set of manifest files in the `meta/` subdirectories.
90
91There is one manifest file per test with "non-default"
92expectations. By default tests are expected to PASS, and tests with
93subtests are expected to have an overall status of OK. The manifest
94file of a test has the same path as the test file but under the `meta`
95directory rather than the `tests` directory and has the suffix `.ini`.
96
97The format of these files is similar to `ini` files, but with a couple
98of important differences; sections can be nested using indentation,
99and only `:` is permitted as a key-value separator. For example the
100expectation file for a test with one failing subtest and one erroring
101subtest might look like:
102
103 [filename.html]
104 type: testharness
105
106 [Subtest name for failing test]
107 expected: FAIL
108
109 [Subtest name for erroring test]
110 expected: ERROR
111
112Expectations can also be made platform-specific using a simple
113python-like conditional syntax e.g. for a test that times out on linux
114but otherwise fails:
115
116 [filename.html]
117 type: reftest
118 expected:
119 if os == "linux": TIMEOUT
120 FAIL
121
122The available variables for the conditions are those provided by
123[mozinfo](http://mozbase.readthedocs.org/en/latest/mozinfo.html).
124
125For more information on manifest files, see the
126[wptrunner documentation](http://wptrunner.readthedocs.org/en/latest/expectation.html).
127
128Autogenerating Expectation Data
129-------------------------------
130
131After changing some code it may be necessary to update the expectation
132data for the relevant tests. This can of course be done manually, but
133tools are available to automate much of the process.
134
135First one must run the tests that have changed status, and save the
136raw log output to a file:
137
138 mach web-platform-tests --include=url/of/test.html --log-raw=new_results.log
139
140Then the `web-platform-tests-update` command may be run using this log
141data to update the expectation files:
142
143 mach web-platform-tests-update --no-check-clean new_results.log
144
145By default this only updates the results data for the current
146platform. To forcibly overwrite all existing result data, use the
147`--ignore-existing` option to the update command.
148
149Disabling Tests
150---------------
151
152Tests are disabled using the same manifest files used to set
153expectation values. For example, if a test is unstable on Windows, it
154can be disabled using an ini file with the contents:
155
156 [filename.html]
157 type: testharness
158 disabled:
159 if os == "win": https://bugzilla.mozilla.org/show_bug.cgi?id=1234567
160
161Enabling Prefs
162--------------
163
164Some tests require specific prefs to be enabled before running. These
165prefs can be set in the expectation data using a `prefs` key with a
166comma-seperate list of `pref.name:value` items to set e.g.
167
168 [filename.html]
169 prefs: [dom.serviceWorkers.enabled:true,
170 dom.serviceWorkers.exemptFromPerDomainMax:true,
171 dom.caches.enabled:true]
172
173Setting per-Directory Metadata
174------------------------------
175
176Occasionally it is useful to set metadata for an entire directory of
177tests e.g. to disable then all, or to enable prefs for every test. In
178that case it is possible to create a `__dir__.ini` file in the
179metadata directory corresponding to the tests for which you want to
180set this metadata e.g. to disable all the tests in
181`tests/feature/unsupported/`, one might create
182`meta/feature/unsupported/__dir__.ini` with the contents:
183
184 disabled: Feature is unsupported
185
186Settings set in this way are inherited into subdirectories. It is
187possible to unset a value that has been set in a parent using the
188special token `@Reset` (usually used with prefs), or to force a value
189to true or false using `@True` and `@False`. For example to enable
190the tests in `meta/feature/unsupported/subfeature-supported` one might
191create an ini file
192`meta/feature/unsupported/subfeature-supported/__dir__.ini` like:
193
194 disabled: @False
195
196Test Format
197-----------
198
199Javascript tests are written using
200[testharness.js](http://github.com/w3c/testharness.js/). Reftests are
201similar to standard Gecko reftests without an explicit manifest file,
202but with in-test or filename conventions for identifying the
203reference.
204
205Full documentation on test authoring and submission can be found on
206[testthewebforward.org](http://testthewebforward.org/docs).
207
208Test Manifest
209-------------
210
211web-platform-tests use a large auto-generated JSON file as their
212manifest. This stores data about the type of tests, their references,
213if any, and their timeout, gathered by inspecting the filenames and
214the contents of the test files.
215
216In order to update the manifest it is recommended that you run `mach
217web-platform-tests --manifest-update`. This rescans the test directory
218looking for new, removed, or altered tests.
219
220Running Tests In Other Browsers
221-------------------------------
222
223web-platform-tests is cross browser, and the runner is compatible with
224multiple browsers. Therefore it's possible to check the behaviour of
225tests in other browsers. This is somewhat more involved than running
226them in Firefox since extra dependencies may be required. For example
227to test in Chrome:
228
2291. Download the chromedriver binary and place it somewhere sensible
230 e.g. `~/bin`
231
2322. In your gecko source tree activate the virtualenv created by mach,
233 since this has most dependencies already installed. This is typically
234 in objdir/_virtualenv and is activated via e.g.
235
236 source objdir/_virtualenv/bin/activate
237
2383. Install the extra requirements:
239
240 cd testing/web-platform/harness
241 pip install -r requirements_chrome.txt
242
2434. Edit the config file `testing/web-platform/wptrunner.ini` so that
244 Chrome support is enabled by changing the section that reads:
245
246 [products]
247 firefox =
248
249 to read
250
251 [products]
252 firefox =
253 chrome =
254
255 (alternatively create a new config file elsewhere and use the
256 `--config` option to `runtests.py` to point wptrunner at this config
257 file).
258
2595. Run `runtests.py` using the location of chromedriver as
260 the binary:
261
262 cd testing/web-platform
263 python runtests.py --product=chrome --binary=~/bin/chromedriver --log-mach=-
264
265By default this will use the same test checkout and metadata as are in
266the Gecko tree, so it's easy to compare behaviour relative to Firefox.
267