blob: d4be954bded80af70a3b0499d5e921b1f513818b [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
187[TestExpectations](../../WebKit/LayoutTests/TestExpectations) file (and related
188files, including
189[skia_test_expectations.txt](../../skia/skia_test_expectations.txt))
pwnall4ea2eb32016-11-29 02:47:25190contains the list of all known layout test failures. See the
191[Layout Test Expectations documentation](./layout_test_expectations.md) for more
192on this.
pwnallae101a5f2016-11-08 00:24:38193
194## Testing Runtime Flags
195
196There are two ways to run layout tests with additional command-line arguments:
197
198* Using `--additional-driver-flag`:
199
200 ```bash
201 run-webkit-tests --additional-driver-flag=--blocking-repaint
202 ```
203
204 This tells the test harness to pass `--blocking-repaint` to the
205 content_shell binary.
206
207 It will also look for flag-specific expectations in
208 `LayoutTests/FlagExpectations/blocking-repaint`, if this file exists. The
209 suppressions in this file override the main TestExpectations file.
210
211* Using a *virtual test suite* defined in
212 [LayoutTests/VirtualTestSuites](https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/LayoutTests/VirtualTestSuites).
213 A virtual test suite runs a subset of layout tests under a specific path with
214 additional flags. For example, you could test a (hypothetical) new mode for
215 repainting using the following virtual test suite:
216
217 ```json
218 {
219 "prefix": "blocking_repaint",
220 "base": "fast/repaint",
221 "args": ["--blocking-repaint"],
222 }
223 ```
224
225 This will create new "virtual" tests of the form
226 `virtual/blocking_repaint/fast/repaint/...`` which correspond to the files
227 under `LayoutTests/fast/repaint` and pass `--blocking-repaint` to
228 content_shell when they are run.
229
230 These virtual tests exist in addition to the original `fast/repaint/...`
231 tests. They can have their own expectations in TestExpectations, and their own
232 baselines. The test harness will use the non-virtual baselines as a fallback.
233 However, the non-virtual expectations are not inherited: if
234 `fast/repaint/foo.html` is marked `[ Fail ]`, the test harness still expects
235 `virtual/blocking_repaint/fast/repaint/foo.html` to pass. If you expect the
236 virtual test to also fail, it needs its own suppression.
237
238 The "prefix" value does not have to be unique. This is useful if you want to
239 run multiple directories with the same flags (but see the notes below about
240 performance). Using the same prefix for different sets of flags is not
241 recommended.
242
243For flags whose implementation is still in progress, virtual test suites and
244flag-specific expectations represent two alternative strategies for testing.
245Consider the following when choosing between them:
246
247* The
248 [waterfall builders](https://dev.chromium.org/developers/testing/chromium-build-infrastructure/tour-of-the-chromium-buildbot)
249 and [try bots](https://dev.chromium.org/developers/testing/try-server-usage)
250 will run all virtual test suites in addition to the non-virtual tests.
251 Conversely, a flag-specific expectations file won't automatically cause the
252 bots to test your flag - if you want bot coverage without virtual test suites,
253 you will need to set up a dedicated bot for your flag.
254
255* Due to the above, virtual test suites incur a performance penalty for the
256 commit queue and the continuous build infrastructure. This is exacerbated by
257 the need to restart `content_shell` whenever flags change, which limits
258 parallelism. Therefore, you should avoid adding large numbers of virtual test
259 suites. They are well suited to running a subset of tests that are directly
260 related to the feature, but they don't scale to flags that make deep
261 architectural changes that potentially impact all of the tests.
262
263## Tracking Test Failures
264
265All bugs, associated with layout test failures must have the
266[Test-Layout](https://crbug.com/?q=label:Test-Layout) label. Depending on how
267much you know about the bug, assign the status accordingly:
268
269* **Unconfirmed** -- You aren't sure if this is a simple rebaseline, possible
270 duplicate of an existing bug, or a real failure
271* **Untriaged** -- Confirmed but unsure of priority or root cause.
272* **Available** -- You know the root cause of the issue.
273* **Assigned** or **Started** -- You will fix this issue.
274
275When creating a new layout test bug, please set the following properties:
276
277* Components: a sub-component of Blink
278* OS: **All** (or whichever OS the failure is on)
279* Priority: 2 (1 if it's a crash)
280* Type: **Bug**
281* Labels: **Test-Layout**
282
283You can also use the _Layout Test Failure_ template, which will pre-set these
284labels for you.
285
pwnallae101a5f2016-11-08 00:24:38286## Debugging Layout Tests
287
288After the layout tests run, you should get a summary of tests that pass or fail.
289If something fails unexpectedly (a new regression), you will get a content_shell
290window with a summary of the unexpected failures. Or you might have a failing
291test in mind to investigate. In any case, here are some steps and tips for
292finding the problem.
293
294* Take a look at the result. Sometimes tests just need to be rebaselined (see
295 below) to account for changes introduced in your patch.
296 * Load the test into a trunk Chrome or content_shell build and look at its
297 result. (For tests in the http/ directory, start the http server first.
298 See above. Navigate to `http://localhost:8000/` and proceed from there.)
299 The best tests describe what they're looking for, but not all do, and
300 sometimes things they're not explicitly testing are still broken. Compare
301 it to Safari, Firefox, and IE if necessary to see if it's correct. If
302 you're still not sure, find the person who knows the most about it and
303 ask.
304 * Some tests only work properly in content_shell, not Chrome, because they
305 rely on extra APIs exposed there.
306 * Some tests only work properly when they're run in the layout-test
307 framework, not when they're loaded into content_shell directly. The test
308 should mention that in its visible text, but not all do. So try that too.
309 See "Running the tests", above.
310* If you think the test is correct, confirm your suspicion by looking at the
311 diffs between the expected result and the actual one.
312 * Make sure that the diffs reported aren't important. Small differences in
313 spacing or box sizes are often unimportant, especially around fonts and
314 form controls. Differences in wording of JS error messages are also
315 usually acceptable.
316 * `./run_webkit_tests.py path/to/your/test.html --full-results-html` will
317 produce a page including links to the expected result, actual result, and
318 diff.
319 * Add the `--sources` option to `run_webkit_tests.py` to see exactly which
320 expected result it's comparing to (a file next to the test, something in
321 platform/mac/, something in platform/chromium-win/, etc.)
322 * If you're still sure it's correct, rebaseline the test (see below).
323 Otherwise...
324* If you're lucky, your test is one that runs properly when you navigate to it
325 in content_shell normally. In that case, build the Debug content_shell
326 project, fire it up in your favorite debugger, and load the test file either
327 from a file:// URL.
328 * You'll probably be starting and stopping the content_shell a lot. In VS,
329 to save navigating to the test every time, you can set the URL to your
330 test (file: or http:) as the command argument in the Debugging section of
331 the content_shell project Properties.
332 * If your test contains a JS call, DOM manipulation, or other distinctive
333 piece of code that you think is failing, search for that in the Chrome
334 solution. That's a good place to put a starting breakpoint to start
335 tracking down the issue.
336 * Otherwise, you're running in a standard message loop just like in Chrome.
337 If you have no other information, set a breakpoint on page load.
338* If your test only works in full layout-test mode, or if you find it simpler to
339 debug without all the overhead of an interactive session, start the
340 content_shell with the command-line flag `--run-layout-test`, followed by the
341 URL (file: or http:) to your test. More information about running layout tests
pwnalld8a250722016-11-09 18:24:03342 in content_shell can be found [here](./layout_tests_in_content_shell.md).
pwnallae101a5f2016-11-08 00:24:38343 * In VS, you can do this in the Debugging section of the content_shell
344 project Properties.
345 * Now you're running with exactly the same API, theme, and other setup that
346 the layout tests use.
347 * Again, if your test contains a JS call, DOM manipulation, or other
348 distinctive piece of code that you think is failing, search for that in
349 the Chrome solution. That's a good place to put a starting breakpoint to
350 start tracking down the issue.
351 * If you can't find any better place to set a breakpoint, start at the
352 `TestShell::RunFileTest()` call in `content_shell_main.cc`, or at
353 `shell->LoadURL() within RunFileTest()` in `content_shell_win.cc`.
354* Debug as usual. Once you've gotten this far, the failing layout test is just a
355 (hopefully) reduced test case that exposes a problem.
356
357### Debugging HTTP Tests
358
359To run the server manually to reproduce/debug a failure:
360
361```bash
362cd src/third_party/WebKit/Tools/Scripts
363run-blink-httpd start
364```
365
366The layout tests will be served from `http://127.0.0.1:8000`. For example, to
367run the test
368`LayoutTest/http/tests/serviceworker/chromium/service-worker-allowed.html`,
369navigate to
370`http://127.0.0.1:8000/serviceworker/chromium/service-worker-allowed.html`. Some
371tests will behave differently if you go to 127.0.0.1 vs localhost, so use
372127.0.0.1.
373
374To kill the server, run `run-blink-httpd --server stop`, or just use `taskkill`
375or the Task Manager on Windows, and `killall` or Activity Monitor on MacOS.
376
377The test server sets up an alias to `LayoutTests/resources` directory. In HTTP
378tests, you can access testing framework at e.g.
379`src="/js-test-resources/js-test.js"`.
380
381### Tips
382
383Check https://test-results.appspot.com/ to see how a test did in the most recent
384~100 builds on each builder (as long as the page is being updated regularly).
385
386A timeout will often also be a text mismatch, since the wrapper script kills the
387content_shell before it has a chance to finish. The exception is if the test
388finishes loading properly, but somehow hangs before it outputs the bit of text
389that tells the wrapper it's done.
390
391Why might a test fail (or crash, or timeout) on buildbot, but pass on your local
392machine?
393* If the test finishes locally but is slow, more than 10 seconds or so, that
394 would be why it's called a timeout on the bot.
395* Otherwise, try running it as part of a set of tests; it's possible that a test
396 one or two (or ten) before this one is corrupting something that makes this
397 one fail.
398* If it consistently works locally, make sure your environment looks like the
399 one on the bot (look at the top of the stdio for the webkit_tests step to see
400 all the environment variables and so on).
401* If none of that helps, and you have access to the bot itself, you may have to
402 log in there and see if you can reproduce the problem manually.
403
404### Debugging Inspector Tests
405
406* Add `window.debugTest = true;` to your test code as follows:
407
408 ```javascript
409 window.debugTest = true;
410 function test() {
411 /* TEST CODE */
412 }
413 ```
414
415* Do one of the following:
416 * Option A) Run from the chromium/src folder:
417 `blink/tools/run_layout_tests.sh
418 --additional_driver_flag='--remote-debugging-port=9222'
419 --time-out-ms=6000000`
420 * Option B) If you need to debug an http/tests/inspector test, start httpd
421 as described above. Then, run content_shell:
422 `out/Default/content_shell --remote-debugging-port=9222 --run-layout-test
423 http://127.0.0.1:8000/path/to/test.html`
424* Open `http://localhost:9222` in a stable/beta/canary Chrome, click the single
425 link to open the devtools with the test loaded.
426* You may need to replace devtools.html with inspector.html in your URL (or you
427 can use local chrome inspection of content_shell from chrome://inspect
428 instead)
429* In the loaded devtools, set any required breakpoints and execute `test()` in
430 the console to actually start the test.
431
432## Rebaselining Layout Tests
433
pwnalld8a250722016-11-09 18:24:03434*** promo
435To automatically re-baseline tests across all Chromium platforms, using the
pwnallae101a5f2016-11-08 00:24:38436buildbot results, see the
pwnalld8a250722016-11-09 18:24:03437[Rebaselining keywords in TestExpectations](./layout_test_expectations.md)
438and the
pwnallae101a5f2016-11-08 00:24:38439[Rebaselining Tool](https://trac.webkit.org/wiki/Rebaseline).
440Alternatively, to manually run and test and rebaseline it on your workstation,
pwnalld8a250722016-11-09 18:24:03441read on.
442***
pwnallae101a5f2016-11-08 00:24:38443
444By default, text-only tests (ones that call `testRunner.dumpAsText()`) produce
445only text results. Other tests produce both new text results and new image
446results (the image baseline comprises two files, `-expected.png` and
447 `-expected.checksum`). So you'll need either one or three `-expected.\*` files
448in your new baseline, depending on whether you have a text-only test or not. If
449you enable `--no-pixel-tests`, only new text results will be produced, even for
450tests that do image comparisons.
451
452```bash
453cd src/third_party/WebKit
454Tools/Scripts/run-webkit-tests --new-baseline foo/bar/test.html
455```
456
457The above command will generate a new baseline for
458`LayoutTests/foo/bar/test.html` and put the output files in the right place,
459e.g.
460`LayoutTests/platform/chromium-win/LayoutTests/foo/bar/test-expected.{txt,png,checksum}`.
461
462When you rebaseline a test, make sure your commit description explains why the
463test is being re-baselined. If this is a special case (i.e., something we've
464decided to be different with upstream), please put a README file next to the new
465expected output explaining the difference.
466
467## W3C Tests
468
469In addition to layout tests developed and run just by the Blink team, there are
470also W3C conformance tests. For more info, see
471[Importing the W3C Tests](https://www.chromium.org/blink/importing-the-w3c-tests).
472
473## Known Issues
474
475See
476[bugs with the component Blink>Infra](https://bugs.chromium.org/p/chromium/issues/list?can=2&q=component%3ABlink%3EInfra)
477for issues related to Blink tools, include the layout test runner.
478
479* Windows and Linux: Do not copy and paste while the layout tests are running,
480 as it may interfere with the editing/pasteboard and other clipboard-related
481 tests. (Mac tests swizzle NSClipboard to avoid any conflicts).
482* If QuickTime is not installed, the plugin tests
483 `fast/dom/object-embed-plugin-scripting.html` and
484 `plugins/embed-attributes-setting.html` are expected to fail.