blob: 08c8bcada54c60f2629e4534c337adb2926e5bd2 [file] [log] [blame] [view]
pwnallae101a5f2016-11-08 00:24:381# Layout Tests
2
3Layout tests are used by Blink to test many components, including but not
4limited to layout and rendering. In general, layout tests involve loading pages
5in a test renderer (`content_shell`) and comparing the rendered output or
6JavaScript output against an expected output file.
7
pwnall4ea2eb32016-11-29 02:47:258This document covers running and debugging existing layout tests. See the
9[Writing Layout Tests documentation](./writing_layout_tests.md) if you find
10yourself writing layout tests.
11
pwnallae101a5f2016-11-08 00:24:3812[TOC]
13
14## Running Layout Tests
15
16### Initial Setup
17
18Before you can run the layout tests, you need to build the `blink_tests` target
19to get `content_shell` and all of the other needed binaries.
20
21```bash
22ninja -C out/Release blink_tests
23```
24
25On **Android** (layout test support
26[currently limited to KitKat and earlier](https://crbug.com/567947)) you need to
27build and install `content_shell_apk` instead. See also:
28[Android Build Instructions](../android_build_instructions.md).
29
30```bash
31ninja -C out/Default content_shell_apk
32adb install -r out/Default/apks/ContentShell.apk
33```
34
35On **Mac**, you probably want to strip the content_shell binary before starting
36the tests. If you don't, you'll have 5-10 running concurrently, all stuck being
37examined by the OS crash reporter. This may cause other failures like timeouts
38where they normally don't occur.
39
40```bash
41strip ./xcodebuild/{Debug,Release}/content_shell.app/Contents/MacOS/content_shell
42```
43
44### Running the Tests
45
46TODO: mention `testing/xvfb.py`
47
48The test runner script is in
49`third_party/WebKit/Tools/Scripts/run-webkit-tests`.
50
51To specify which build directory to use (e.g. out/Default, out/Release,
52out/Debug) you should pass the `-t` or `--target` parameter. For example, to
53use the build in `out/Default`, use:
54
55```bash
56python third_party/WebKit/Tools/Scripts/run-webkit-tests -t Default
57```
58
59For Android (if your build directory is `out/android`):
60
61```bash
62python third_party/WebKit/Tools/Scripts/run-webkit-tests -t android --android
63```
64
65Tests marked as `[ Skip ]` in
66[TestExpectations](../../third_party/WebKit/LayoutTests/TestExpectations)
67won't be run at all, generally because they cause some intractable tool error.
68To force one of them to be run, either rename that file or specify the skipped
pwnall4ea2eb32016-11-29 02:47:2569test as the only one on the command line (see below). Read the
70[Layout Test Expectations documentation](./layout_test_expectations.md) to learn
71more about TestExpectations and related files.
pwnallae101a5f2016-11-08 00:24:3872
pwnall4ea2eb32016-11-29 02:47:2573*** promo
74Currently only the tests listed in
pwnallae101a5f2016-11-08 00:24:3875[SmokeTests](../../third_party/WebKit/LayoutTests/SmokeTests)
76are run on the Android bots, since running all layout tests takes too long on
77Android (and may still have some infrastructure issues). Most developers focus
78their Blink testing on Linux. We rely on the fact that the Linux and Android
79behavior is nearly identical for scenarios outside those covered by the smoke
80tests.
pwnall4ea2eb32016-11-29 02:47:2581***
pwnallae101a5f2016-11-08 00:24:3882
83To run only some of the tests, specify their directories or filenames as
84arguments to `run_webkit_tests.py` relative to the layout test directory
85(`src/third_party/WebKit/LayoutTests`). For example, to run the fast form tests,
86use:
87
88```bash
89Tools/Scripts/run-webkit-tests fast/forms
90```
91
92Or you could use the following shorthand:
93
94```bash
95Tools/Scripts/run-webkit-tests fast/fo\*
96```
97
98*** promo
99Example: To run the layout tests with a debug build of `content_shell`, but only
100test the SVG tests and run pixel tests, you would run:
101
102```bash
103Tools/Scripts/run-webkit-tests -t Default svg
104```
105***
106
107As a final quick-but-less-robust alternative, you can also just use the
108content_shell executable to run specific tests by using (for Windows):
109
110```bash
111out/Default/content_shell.exe --run-layout-test --no-sandbox full_test_source_path
112```
113
114as in:
115
116```bash
117out/Default/content_shell.exe --run-layout-test --no-sandbox \
118 c:/chrome/src/third_party/WebKit/LayoutTests/fast/forms/001.html
119```
120
121but this requires a manual diff against expected results, because the shell
122doesn't do it for you.
123
124To see a complete list of arguments supported, run: `run-webkit-tests --help`
125
126*** note
127**Linux Note:** We try to match the Windows render tree output exactly by
128matching font metrics and widget metrics. If there's a difference in the render
129tree output, we should see if we can avoid rebaselining by improving our font
130metrics. For additional information on Linux Layout Tests, please see
131[docs/layout_tests_linux.md](../layout_tests_linux.md).
132***
133
134*** note
135**Mac Note:** While the tests are running, a bunch of Appearance settings are
136overridden for you so the right type of scroll bars, colors, etc. are used.
137Your main display's "Color Profile" is also changed to make sure color
138correction by ColorSync matches what is expected in the pixel tests. The change
139is noticeable, how much depends on the normal level of correction for your
140display. The tests do their best to restore your setting when done, but if
141you're left in the wrong state, you can manually reset it by going to
142System Preferences → Displays → Color and selecting the "right" value.
143***
144
145### Test Harness Options
146
147This script has a lot of command line flags. You can pass `--help` to the script
148to see a full list of options. A few of the most useful options are below:
149
150| Option | Meaning |
151|:----------------------------|:--------------------------------------------------|
152| `--debug` | Run the debug build of the test shell (default is release). Equivalent to `-t Debug` |
153| `--nocheck-sys-deps` | Don't check system dependencies; this allows faster iteration. |
154| `--verbose` | Produce more verbose output, including a list of tests that pass. |
155| `--no-pixel-tests` | Disable the pixel-to-pixel PNG comparisons and image checksums for tests that don't call `testRunner.dumpAsText()` |
156| `--reset-results` | Write all generated results directly into the given directory, overwriting what's there. |
157| `--new-baseline` | Write all generated results into the most specific platform directory, overwriting what's there. Equivalent to `--reset-results --add-platform-expectations` |
158| `--renderer-startup-dialog` | Bring up a modal dialog before running the test, useful for attaching a debugger. |
159| `--fully-parallel` | Run tests in parallel using as many child processes as the system has cores. |
160| `--driver-logging` | Print C++ logs (LOG(WARNING), etc). |
161
162## Success and Failure
163
164A test succeeds when its output matches the pre-defined expected results. If any
165tests fail, the test script will place the actual generated results, along with
166a diff of the actual and expected results, into
167`src/out/Default/layout_test_results/`, and by default launch a browser with a
168summary and link to the results/diffs.
169
170The expected results for tests are in the
171`src/third_party/WebKit/LayoutTests/platform` or alongside their respective
172tests.
173
174*** note
175Tests which use [testharness.js](https://github.com/w3c/testharness.js/)
176do not have expected result files if all test cases pass.
177***
178
179A test that runs but produces the wrong output is marked as "failed", one that
180causes the test shell to crash is marked as "crashed", and one that takes longer
181than a certain amount of time to complete is aborted and marked as "timed out".
182A row of dots in the script's output indicates one or more tests that passed.
183
184## Test expectations
185
186The
qyearsley23599b72017-02-16 19:10:42187[TestExpectations](../../third_party/WebKit/LayoutTests/TestExpectations) file (and related
188files) contains the list of all known layout test failures. See the
pwnall4ea2eb32016-11-29 02:47:25189[Layout Test Expectations documentation](./layout_test_expectations.md) for more
190on this.
pwnallae101a5f2016-11-08 00:24:38191
192## Testing Runtime Flags
193
194There are two ways to run layout tests with additional command-line arguments:
195
196* Using `--additional-driver-flag`:
197
198 ```bash
199 run-webkit-tests --additional-driver-flag=--blocking-repaint
200 ```
201
202 This tells the test harness to pass `--blocking-repaint` to the
203 content_shell binary.
204
205 It will also look for flag-specific expectations in
206 `LayoutTests/FlagExpectations/blocking-repaint`, if this file exists. The
207 suppressions in this file override the main TestExpectations file.
208
209* Using a *virtual test suite* defined in
qyearsley23599b72017-02-16 19:10:42210 [LayoutTests/VirtualTestSuites](../../third_party/WebKit/LayoutTests/VirtualTestSuites).
pwnallae101a5f2016-11-08 00:24:38211 A virtual test suite runs a subset of layout tests under a specific path with
212 additional flags. For example, you could test a (hypothetical) new mode for
213 repainting using the following virtual test suite:
214
215 ```json
216 {
217 "prefix": "blocking_repaint",
218 "base": "fast/repaint",
219 "args": ["--blocking-repaint"],
220 }
221 ```
222
223 This will create new "virtual" tests of the form
224 `virtual/blocking_repaint/fast/repaint/...`` which correspond to the files
225 under `LayoutTests/fast/repaint` and pass `--blocking-repaint` to
226 content_shell when they are run.
227
228 These virtual tests exist in addition to the original `fast/repaint/...`
229 tests. They can have their own expectations in TestExpectations, and their own
230 baselines. The test harness will use the non-virtual baselines as a fallback.
231 However, the non-virtual expectations are not inherited: if
232 `fast/repaint/foo.html` is marked `[ Fail ]`, the test harness still expects
233 `virtual/blocking_repaint/fast/repaint/foo.html` to pass. If you expect the
234 virtual test to also fail, it needs its own suppression.
235
236 The "prefix" value does not have to be unique. This is useful if you want to
237 run multiple directories with the same flags (but see the notes below about
238 performance). Using the same prefix for different sets of flags is not
239 recommended.
240
241For flags whose implementation is still in progress, virtual test suites and
242flag-specific expectations represent two alternative strategies for testing.
243Consider the following when choosing between them:
244
245* The
246 [waterfall builders](https://dev.chromium.org/developers/testing/chromium-build-infrastructure/tour-of-the-chromium-buildbot)
247 and [try bots](https://dev.chromium.org/developers/testing/try-server-usage)
248 will run all virtual test suites in addition to the non-virtual tests.
249 Conversely, a flag-specific expectations file won't automatically cause the
250 bots to test your flag - if you want bot coverage without virtual test suites,
251 you will need to set up a dedicated bot for your flag.
252
253* Due to the above, virtual test suites incur a performance penalty for the
254 commit queue and the continuous build infrastructure. This is exacerbated by
255 the need to restart `content_shell` whenever flags change, which limits
256 parallelism. Therefore, you should avoid adding large numbers of virtual test
257 suites. They are well suited to running a subset of tests that are directly
258 related to the feature, but they don't scale to flags that make deep
259 architectural changes that potentially impact all of the tests.
260
261## Tracking Test Failures
262
263All bugs, associated with layout test failures must have the
264[Test-Layout](https://crbug.com/?q=label:Test-Layout) label. Depending on how
265much you know about the bug, assign the status accordingly:
266
267* **Unconfirmed** -- You aren't sure if this is a simple rebaseline, possible
268 duplicate of an existing bug, or a real failure
269* **Untriaged** -- Confirmed but unsure of priority or root cause.
270* **Available** -- You know the root cause of the issue.
271* **Assigned** or **Started** -- You will fix this issue.
272
273When creating a new layout test bug, please set the following properties:
274
275* Components: a sub-component of Blink
276* OS: **All** (or whichever OS the failure is on)
277* Priority: 2 (1 if it's a crash)
278* Type: **Bug**
279* Labels: **Test-Layout**
280
281You can also use the _Layout Test Failure_ template, which will pre-set these
282labels for you.
283
pwnallae101a5f2016-11-08 00:24:38284## Debugging Layout Tests
285
286After the layout tests run, you should get a summary of tests that pass or fail.
287If something fails unexpectedly (a new regression), you will get a content_shell
288window with a summary of the unexpected failures. Or you might have a failing
289test in mind to investigate. In any case, here are some steps and tips for
290finding the problem.
291
292* Take a look at the result. Sometimes tests just need to be rebaselined (see
293 below) to account for changes introduced in your patch.
294 * Load the test into a trunk Chrome or content_shell build and look at its
295 result. (For tests in the http/ directory, start the http server first.
296 See above. Navigate to `http://localhost:8000/` and proceed from there.)
297 The best tests describe what they're looking for, but not all do, and
298 sometimes things they're not explicitly testing are still broken. Compare
299 it to Safari, Firefox, and IE if necessary to see if it's correct. If
300 you're still not sure, find the person who knows the most about it and
301 ask.
302 * Some tests only work properly in content_shell, not Chrome, because they
303 rely on extra APIs exposed there.
304 * Some tests only work properly when they're run in the layout-test
305 framework, not when they're loaded into content_shell directly. The test
306 should mention that in its visible text, but not all do. So try that too.
307 See "Running the tests", above.
308* If you think the test is correct, confirm your suspicion by looking at the
309 diffs between the expected result and the actual one.
310 * Make sure that the diffs reported aren't important. Small differences in
311 spacing or box sizes are often unimportant, especially around fonts and
312 form controls. Differences in wording of JS error messages are also
313 usually acceptable.
314 * `./run_webkit_tests.py path/to/your/test.html --full-results-html` will
315 produce a page including links to the expected result, actual result, and
316 diff.
317 * Add the `--sources` option to `run_webkit_tests.py` to see exactly which
318 expected result it's comparing to (a file next to the test, something in
319 platform/mac/, something in platform/chromium-win/, etc.)
320 * If you're still sure it's correct, rebaseline the test (see below).
321 Otherwise...
322* If you're lucky, your test is one that runs properly when you navigate to it
323 in content_shell normally. In that case, build the Debug content_shell
324 project, fire it up in your favorite debugger, and load the test file either
qyearsley23599b72017-02-16 19:10:42325 from a `file:` URL.
pwnallae101a5f2016-11-08 00:24:38326 * You'll probably be starting and stopping the content_shell a lot. In VS,
327 to save navigating to the test every time, you can set the URL to your
qyearsley23599b72017-02-16 19:10:42328 test (`file:` or `http:`) as the command argument in the Debugging section of
pwnallae101a5f2016-11-08 00:24:38329 the content_shell project Properties.
330 * If your test contains a JS call, DOM manipulation, or other distinctive
331 piece of code that you think is failing, search for that in the Chrome
332 solution. That's a good place to put a starting breakpoint to start
333 tracking down the issue.
334 * Otherwise, you're running in a standard message loop just like in Chrome.
335 If you have no other information, set a breakpoint on page load.
336* If your test only works in full layout-test mode, or if you find it simpler to
337 debug without all the overhead of an interactive session, start the
338 content_shell with the command-line flag `--run-layout-test`, followed by the
qyearsley23599b72017-02-16 19:10:42339 URL (`file:` or `http:`) to your test. More information about running layout tests
pwnalld8a250722016-11-09 18:24:03340 in content_shell can be found [here](./layout_tests_in_content_shell.md).
pwnallae101a5f2016-11-08 00:24:38341 * In VS, you can do this in the Debugging section of the content_shell
342 project Properties.
343 * Now you're running with exactly the same API, theme, and other setup that
344 the layout tests use.
345 * Again, if your test contains a JS call, DOM manipulation, or other
346 distinctive piece of code that you think is failing, search for that in
347 the Chrome solution. That's a good place to put a starting breakpoint to
348 start tracking down the issue.
349 * If you can't find any better place to set a breakpoint, start at the
350 `TestShell::RunFileTest()` call in `content_shell_main.cc`, or at
351 `shell->LoadURL() within RunFileTest()` in `content_shell_win.cc`.
352* Debug as usual. Once you've gotten this far, the failing layout test is just a
353 (hopefully) reduced test case that exposes a problem.
354
355### Debugging HTTP Tests
356
357To run the server manually to reproduce/debug a failure:
358
359```bash
360cd src/third_party/WebKit/Tools/Scripts
361run-blink-httpd start
362```
363
364The layout tests will be served from `http://127.0.0.1:8000`. For example, to
365run the test
366`LayoutTest/http/tests/serviceworker/chromium/service-worker-allowed.html`,
367navigate to
368`http://127.0.0.1:8000/serviceworker/chromium/service-worker-allowed.html`. Some
369tests will behave differently if you go to 127.0.0.1 vs localhost, so use
370127.0.0.1.
371
372To kill the server, run `run-blink-httpd --server stop`, or just use `taskkill`
373or the Task Manager on Windows, and `killall` or Activity Monitor on MacOS.
374
375The test server sets up an alias to `LayoutTests/resources` directory. In HTTP
376tests, you can access testing framework at e.g.
377`src="/js-test-resources/js-test.js"`.
378
379### Tips
380
381Check https://test-results.appspot.com/ to see how a test did in the most recent
382~100 builds on each builder (as long as the page is being updated regularly).
383
384A timeout will often also be a text mismatch, since the wrapper script kills the
385content_shell before it has a chance to finish. The exception is if the test
386finishes loading properly, but somehow hangs before it outputs the bit of text
387that tells the wrapper it's done.
388
389Why might a test fail (or crash, or timeout) on buildbot, but pass on your local
390machine?
391* If the test finishes locally but is slow, more than 10 seconds or so, that
392 would be why it's called a timeout on the bot.
393* Otherwise, try running it as part of a set of tests; it's possible that a test
394 one or two (or ten) before this one is corrupting something that makes this
395 one fail.
396* If it consistently works locally, make sure your environment looks like the
397 one on the bot (look at the top of the stdio for the webkit_tests step to see
398 all the environment variables and so on).
399* If none of that helps, and you have access to the bot itself, you may have to
400 log in there and see if you can reproduce the problem manually.
401
402### Debugging Inspector Tests
403
404* Add `window.debugTest = true;` to your test code as follows:
405
406 ```javascript
407 window.debugTest = true;
408 function test() {
409 /* TEST CODE */
410 }
411 ```
412
413* Do one of the following:
414 * Option A) Run from the chromium/src folder:
415 `blink/tools/run_layout_tests.sh
416 --additional_driver_flag='--remote-debugging-port=9222'
417 --time-out-ms=6000000`
418 * Option B) If you need to debug an http/tests/inspector test, start httpd
419 as described above. Then, run content_shell:
420 `out/Default/content_shell --remote-debugging-port=9222 --run-layout-test
421 http://127.0.0.1:8000/path/to/test.html`
422* Open `http://localhost:9222` in a stable/beta/canary Chrome, click the single
423 link to open the devtools with the test loaded.
424* You may need to replace devtools.html with inspector.html in your URL (or you
qyearsley23599b72017-02-16 19:10:42425 can use local chrome inspection of content_shell from `chrome://inspect`
pwnallae101a5f2016-11-08 00:24:38426 instead)
427* In the loaded devtools, set any required breakpoints and execute `test()` in
428 the console to actually start the test.
429
430## Rebaselining Layout Tests
431
pwnalld8a250722016-11-09 18:24:03432*** promo
433To automatically re-baseline tests across all Chromium platforms, using the
pwnallae101a5f2016-11-08 00:24:38434buildbot results, see the
pwnalld8a250722016-11-09 18:24:03435[Rebaselining keywords in TestExpectations](./layout_test_expectations.md)
436and the
pwnallae101a5f2016-11-08 00:24:38437[Rebaselining Tool](https://trac.webkit.org/wiki/Rebaseline).
438Alternatively, to manually run and test and rebaseline it on your workstation,
pwnalld8a250722016-11-09 18:24:03439read on.
440***
pwnallae101a5f2016-11-08 00:24:38441
442By default, text-only tests (ones that call `testRunner.dumpAsText()`) produce
443only text results. Other tests produce both new text results and new image
444results (the image baseline comprises two files, `-expected.png` and
445 `-expected.checksum`). So you'll need either one or three `-expected.\*` files
446in your new baseline, depending on whether you have a text-only test or not. If
447you enable `--no-pixel-tests`, only new text results will be produced, even for
448tests that do image comparisons.
449
450```bash
451cd src/third_party/WebKit
452Tools/Scripts/run-webkit-tests --new-baseline foo/bar/test.html
453```
454
455The above command will generate a new baseline for
456`LayoutTests/foo/bar/test.html` and put the output files in the right place,
457e.g.
458`LayoutTests/platform/chromium-win/LayoutTests/foo/bar/test-expected.{txt,png,checksum}`.
459
460When you rebaseline a test, make sure your commit description explains why the
461test is being re-baselined. If this is a special case (i.e., something we've
462decided to be different with upstream), please put a README file next to the new
463expected output explaining the difference.
464
foolipbbd0f452017-02-11 00:09:53465## Web Platform Tests
pwnallae101a5f2016-11-08 00:24:38466
foolipbbd0f452017-02-11 00:09:53467In addition to layout tests developed and run just by the Blink team, there is
468also a shared test suite, see [Web Platform Tests](./web_platform_tests.md).
pwnallae101a5f2016-11-08 00:24:38469
470## Known Issues
471
472See
473[bugs with the component Blink>Infra](https://bugs.chromium.org/p/chromium/issues/list?can=2&q=component%3ABlink%3EInfra)
474for issues related to Blink tools, include the layout test runner.
475
476* Windows and Linux: Do not copy and paste while the layout tests are running,
477 as it may interfere with the editing/pasteboard and other clipboard-related
478 tests. (Mac tests swizzle NSClipboard to avoid any conflicts).
479* If QuickTime is not installed, the plugin tests
480 `fast/dom/object-embed-plugin-scripting.html` and
481 `plugins/embed-attributes-setting.html` are expected to fail.