pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 1 | # Writing Layout Tests |
| 2 | |
| 3 | _Layout tests_ is a bit of a misnomer. This term is |
| 4 | [a part of our WebKit heritage](https://webkit.org/blog/1452/layout-tests-theory/), |
| 5 | and we use it to refer to every test that is written as a Web page (HTML, SVG, |
| 6 | or XHTML) and lives in |
| 7 | [third_party/WebKit/LayoutTests/](../../third_party/WebKit/LayoutTests). |
| 8 | |
| 9 | [TOC] |
| 10 | |
| 11 | ## Overview |
| 12 | |
| 13 | Layout tests should be used to accomplish one of the following goals: |
| 14 | |
| 15 | 1. The entire surface of Blink that is exposed to the Web should be covered by |
| 16 | tests that we contribute to the |
| 17 | [Web Platform Tests Project](https://github.com/w3c/web-platform-tests) |
| 18 | (WPT). This helps us avoid regressions, and helps us identify Web Platform |
| 19 | areas where the major browsers don't have interoperable implementations. |
| 20 | Furthermore, by contributing to projects such as WPT, we share the burden of |
| 21 | writing tests with the other browser vendors, and we help all the browsers |
| 22 | get better. This is very much in line with our goal to move the Web forward. |
| 23 | 2. When a Blink feature cannot be tested using the tools provided by WPT, and |
| 24 | cannot be easily covered by |
| 25 | [C++ unit tests](https://cs.chromium.org/chromium/src/third_party/WebKit/Source/web/tests/?q=webframetest&sq=package:chromium&type=cs), |
| 26 | the feature must be covered by layout tests, to avoid unexpected regressions. |
| 27 | These tests will use Blink-specific testing APIs that are only available in |
| 28 | [content_shell](./layout_tests_in_content_shell.md). |
| 29 | |
| 30 | *** promo |
| 31 | If you know that Blink layout tests are upstreamed to other projects, such as |
| 32 | [test262](https://github.com/tc39/test262), please update this document. Most |
| 33 | importantly, our guidelines should to make it easy for our tests to be |
pwnall | 6acacd8 | 2016-12-02 01:40:15 | [diff] [blame] | 34 | upstreamed. The |
| 35 | [blink-dev mailing list](https://groups.google.com/a/chromium.org/forum/#!forum/blink-dev) |
| 36 | will be happy to help you harmonize our current guidelines with communal test |
| 37 | repositories. |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 38 | *** |
| 39 | |
| 40 | ### Test Types |
| 41 | |
| 42 | There are four broad types of layout tests, listed in the order of preference. |
| 43 | |
| 44 | * *JavaScript Tests* are the layout test implementation of |
| 45 | [xUnit tests](https://en.wikipedia.org/wiki/XUnit). These tests contain |
| 46 | assertions written in JavaScript, and pass if the assertions evaluate to |
| 47 | true. |
| 48 | * *Reference Tests* render a test page and a reference page, and pass if the two |
| 49 | renderings are identical, according to a pixel-by-pixel comparison. These |
| 50 | tests are less robust, harder to debug, and significantly slower than |
| 51 | JavaScript tests, and are only used when JavaScript tests are insufficient, |
| 52 | such as when testing paint code. |
| 53 | * *Pixel Tests* render a test page and compare the result against a pre-rendered |
| 54 | baseline image in the repository. Pixel tests are less robust than all |
| 55 | alternatives listed above, because the rendering of a page is influenced by |
| 56 | many factors such as the host computer's graphics card and driver, the |
| 57 | platform's text rendering system, and various user-configurable operating |
| 58 | system settings. For this reason, it is common for a pixel test to have a |
| 59 | different reference image for each platform that Blink is tested on. Pixel |
| 60 | tests are least preferred, because the reference images are |
| 61 | [quite cumbersome to manage](./layout_test_expectations.md). |
| 62 | * *Dump Render Tree (DRT) Tests* output a textual representation of the render |
| 63 | tree, which is the key data structure in Blink's page rendering system. The |
| 64 | test passes if the output matches a baseline text file in the repository. In |
| 65 | addition to their text result, DRT tests can also produce an image result |
| 66 | which is compared to an image baseline, similarly to pixel tests (described |
| 67 | above). A DRT test with two results (text and image) passes if _both_ results |
| 68 | match the baselines in the repository. DRT tests are less desirable than all |
| 69 | the alternatives, because they depend on a browser implementation detail. |
| 70 | |
| 71 | ## General Principles |
| 72 | |
| 73 | The principles below are adapted from |
| 74 | [Test the Web Forward's Test Format Guidelines](http://testthewebforward.org/docs/test-format-guidelines.html) |
| 75 | and |
| 76 | [WebKit's Wiki page on Writing good test cases](https://trac.webkit.org/wiki/Writing%20Layout%20Tests%20for%20DumpRenderTree). |
| 77 | |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 78 | *** note |
| 79 | This document intentionally uses _should_ a lot more than _must_, as defined in |
| 80 | [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt). Writing layout tests is a |
| 81 | careful act of balancing many concerns, and this humble document cannot possibly |
| 82 | capture the context that rests in the head of an experienced Blink engineer. |
| 83 | *** |
| 84 | |
pwnall | 6acacd8 | 2016-12-02 01:40:15 | [diff] [blame] | 85 | ### Concise |
| 86 | |
| 87 | Tests should be **concise**, without compromising on the principles below. Every |
| 88 | element and piece of code on the page should be necessary and relevant to what |
| 89 | is being tested. For example, don't build a fully functional signup form if you |
| 90 | only need a text field or a button. |
| 91 | |
| 92 | Content needed to satisfy the principles below is considered necessary. For |
| 93 | example, it is acceptable and desirable to add elements that make the test |
| 94 | self-describing (see below), and to add code that makes the test more reliable |
| 95 | (see below). |
| 96 | |
| 97 | Content that makes test failures easier to debug is considered necessary (to |
| 98 | maintaining a good development speed), and is both acceptable and desirable. |
| 99 | |
| 100 | *** promo |
| 101 | Conciseness is particularly important for reference tests and pixel tests, as |
| 102 | the test pages are rendered in an 800x600px viewport. Having content outside the |
| 103 | viewport is undesirable because the outside content does not get compared, and |
| 104 | because the resulting scrollbars are platform-specific UI widgets, making the |
| 105 | test results less reliable. |
| 106 | *** |
| 107 | |
| 108 | ### Fast |
| 109 | |
| 110 | Tests should be as **fast** as possible, without compromising on the principles |
| 111 | below. Blink has several thousand layout tests that are run in parallel, and |
| 112 | avoiding unnecessary delays is crucial to keeping our Commit Queue in good |
| 113 | shape. |
| 114 | |
| 115 | Avoid |
| 116 | [window.setTimeout](https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout), |
| 117 | as it wastes time on the testing infrastructure. Instead, use specific event |
| 118 | handlers, such as |
| 119 | [window.onload](https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onload), |
| 120 | to decide when to advance to the next step in a test. |
| 121 | |
| 122 | ### Reliable |
| 123 | |
| 124 | Tests should be **reliable** and yield consistent results for a given |
| 125 | implementation. Flaky tests slow down your fellow developers' debugging efforts |
| 126 | and the Commit Queue. |
| 127 | |
| 128 | `window.setTimeout` is again a primary offender here. Asides from wasting time |
| 129 | on a fast system, tests that rely on fixed timeouts can fail when on systems |
| 130 | that are slower than expected. |
| 131 | |
| 132 | Follow the guidelines in this |
| 133 | [PSA on writing reliable layout tests](https://docs.google.com/document/d/1Yl4SnTLBWmY1O99_BTtQvuoffP8YM9HZx2YPkEsaduQ/edit). |
| 134 | |
| 135 | ### Self-Describing |
| 136 | |
| 137 | Tests should be **self-describing**, so that a project member can recognize |
| 138 | whether a test passes or fails without having to read the specification of the |
| 139 | feature being tested. `testharness.js` makes a test self-describing when used |
| 140 | correctly, but tests that degrade to manual tests |
| 141 | [must be carefully designed](http://testthewebforward.org/docs/test-style-guidelines.html) |
| 142 | to be self-describing. |
| 143 | |
| 144 | ### Minimal |
| 145 | |
| 146 | Tests should require a **minimal** amount of cognitive effort to read and |
| 147 | maintain. |
| 148 | |
| 149 | Avoid depending on edge case behavior of features that aren't explicitly covered |
| 150 | by the test. For example, except where testing parsing, tests should contain |
| 151 | valid markup (no parsing errors). |
| 152 | |
| 153 | Tests should provide as much relevant information as possible when failing. |
| 154 | `testharness.js` tests should prefer |
| 155 | [rich assert_ functions](https://github.com/w3c/testharness.js/blob/master/docs/api.md#list-of-assertions) |
| 156 | to combining `assert_true()` with a boolean operator. Using appropriate |
| 157 | `assert_` functions results in better diagnostic output when the assertion |
| 158 | fails. |
| 159 | |
| 160 | 🚧 Prefer JavaScript's |
| 161 | [===](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Identity_strict_equality_()) |
| 162 | operator to |
| 163 | [==](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Comparison_Operators#Equality_()) |
| 164 | so that readers don't have to reason about |
| 165 | [type conversion](http://www.ecma-international.org/ecma-262/6.0/#sec-abstract-equality-comparison). |
| 166 | |
| 167 | *** promo |
| 168 | The === vs == recommendation is still being discussed on |
| 169 | [blink-dev](https://groups.google.com/a/chromium.org/d/topic/blink-dev/XsR6PKRrS1E/discussion). |
| 170 | However, please keep in mind that a fellow developer who has to debug a failing |
| 171 | test may have to consider the |
| 172 | [special cases for ==](http://dorey.github.io/JavaScript-Equality-Table/) when |
| 173 | the types of the two values being compared aren't immediately obvious. |
| 174 | *** |
| 175 | |
| 176 | ### Cross-Platform |
| 177 | |
| 178 | Tests should be as **cross-platform** as reasonably possible. Avoid assumptions |
| 179 | about device type, screen resolution, etc. Unavoidable assumptions should be |
| 180 | documented. |
| 181 | |
| 182 | When possible, tests should only use Web platform features, as specified |
| 183 | in the relevant standards. When the Web platform's APIs are insufficient, |
| 184 | tests should prefer to use WPT extended testing APIs, such as |
| 185 | `wpt_automation`, over Blink-specific testing APIs. |
| 186 | |
| 187 | 🚧 Tests that use testing APIs should feature-test for the presence of |
| 188 | those APIs, and gracefully degrade to manual tests (see below) when the testing |
| 189 | APIs are not available. |
| 190 | |
| 191 | Test pages should use the HTML5 doctype (`<!doctype html>`) unless they |
| 192 | specifically cover |
| 193 | [quirks mode](https://developer.mozilla.org/docs/Quirks_Mode_and_Standards_Mode) |
| 194 | behavior. |
| 195 | |
| 196 | Tests should be written under the assumption that they will be upstreamed |
| 197 | to the WPT project. For example, tests should follow the |
| 198 | [WPT guidelines](http://testthewebforward.org/docs/writing-tests.html). |
| 199 | |
| 200 | Tests should avoid using features that haven't been shipped by the |
| 201 | actively-developed major rendering engines (Blink, WebKit, Gecko, Edge). When |
| 202 | unsure, check [caniuse.com](http://caniuse.com/). By necessity, this |
| 203 | recommendation does not apply to the feature targeted by the test. |
| 204 | |
| 205 | *** note |
| 206 | It may be tempting have a test for a bleeding-edge feature X depend on feature |
| 207 | Y, which has only shipped in beta / development versions of various browsers. |
| 208 | The reasoning would be that all browsers that implement X will have implemented |
| 209 | Y. Please keep in mind that Chrome has un-shipped features that made it to the |
| 210 | Beta channel in the past. |
| 211 | *** |
| 212 | |
| 213 | Tests that use Blink-specific testing APIs should feature-test for the |
| 214 | presence of the testing APIs and degrade to |
| 215 | [manual tests](http://testthewebforward.org/docs/manual-test.html) when |
| 216 | the testing APIs are not present. |
| 217 | |
| 218 | *** promo |
| 219 | The recommendation to degrade to manual tests is still being discussed on |
| 220 | [blink-dev](https://groups.google.com/a/chromium.org/d/topic/blink-dev/XsR6PKRrS1E/discussion). |
| 221 | However, please keep in mind that a manual test can be debugged in the browser, |
| 222 | whereas a test that does not degrade gracefully can only be debugged in the test |
| 223 | runner. Fellow project members and future you will thank you for having your |
| 224 | test work as a manual test. |
| 225 | *** |
| 226 | |
| 227 | ### Self-Contained |
| 228 | |
| 229 | Tests must be **self-contained** and not depend on external network resources. |
| 230 | |
| 231 | Unless used by multiple test files, CSS and JavaScript should be inlined using |
| 232 | `<style>` and `<script>` tags. Content shared by multiple tests should be |
| 233 | placed in a `resources/` directory near the tests that share it. See below for |
| 234 | using multiple origins in a test. |
| 235 | |
| 236 | ### File Names |
| 237 | |
| 238 | Test **file names** should describe what is being tested. |
| 239 | |
| 240 | File names should use `snake-case`, but preserve the case of any embedded API |
| 241 | names. For example, prefer `document-createElement.html` to |
| 242 | `document-create-element.html`. |
| 243 | |
| 244 | ### Modern Features |
| 245 | |
| 246 | Tests should prefer **modern features** in JavaScript and in the Web Platform, |
| 247 | provided that they meet the recommendations above for cross-platform tests. |
| 248 | |
| 249 | Tests should use |
| 250 | [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) |
| 251 | for all JavaScript, except when specifically testing sloppy mode behavior. |
| 252 | Strict mode flags deprecated features and helps catch some errors, such as |
| 253 | forgetting to declare variables. |
| 254 | |
| 255 | 🚧 JavaScript code should prefer |
| 256 | [const](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/const) |
| 257 | and |
| 258 | [let](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/let) |
| 259 | over `var`, |
| 260 | [classes](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Classes) |
| 261 | over other OOP constructs, and |
| 262 | [Promises](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) |
| 263 | over other mechanisms for structuring asynchronous code. |
| 264 | |
| 265 | *** promo |
| 266 | The recommendation to prefer `const` and `let` over `var` is currently being |
| 267 | discussed on |
| 268 | [blink-dev](https://groups.google.com/a/chromium.org/d/topic/blink-dev/XsR6PKRrS1E/discussion). |
| 269 | *** |
| 270 | |
| 271 | ### Character Encoding |
| 272 | |
pwnall | e781948 | 2016-12-17 00:58:40 | [diff] [blame] | 273 | 🚧 Tests should use the UTF-8 **character encoding**, which should be |
| 274 | declared by `<meta charset=utf-8>`. This does not apply when specifically |
| 275 | testing encodings. |
pwnall | 6acacd8 | 2016-12-02 01:40:15 | [diff] [blame] | 276 | |
| 277 | The `<meta>` tag must be the first child of the document's `<head>` element. In |
| 278 | documents that do not have an explicit `<head>`, the `<meta>` tag must follow |
| 279 | the doctype. |
| 280 | |
| 281 | When HTML pages do not explicitly declare a character encoding, browsers |
| 282 | determine the encoding using an |
| 283 | [encoding sniffing algorithm](https://html.spec.whatwg.org/multipage/syntax.html#determining-the-character-encoding) |
| 284 | that will surprise most modern Web developers. Highlights include a default |
| 285 | encoding that depends on the user's locale, and non-standardized |
| 286 | browser-specific heuristics. |
| 287 | |
| 288 | *** promo |
| 289 | The WPT guidelines state that test files that only contain ASCII characters may |
| 290 | omit the `<meta>` tag. This exception is currently discussed on |
| 291 | [blink-dev](https://groups.google.com/a/chromium.org/d/topic/blink-dev/XsR6PKRrS1E/discussion). |
| 292 | If taking that route, please keep in mind that Firefox currently issues a |
| 293 | [development tools](https://developer.mozilla.org/en-US/docs/Tools) warning for |
| 294 | pages without a declared encoding. |
| 295 | *** |
| 296 | |
| 297 | ### Coding Style |
| 298 | |
| 299 | Tests should aim to have a **coding style** that is consistent with |
| 300 | [Google's JavaScript Style Guide](https://google.github.io/styleguide/jsguide.html), |
| 301 | and |
| 302 | [Google's HTML/CSS Style Guide](https://google.github.io/styleguide/htmlcssguide.xml), |
| 303 | with the following exceptions. |
| 304 | |
| 305 | * Rules related to Google Closure and JSDoc do not apply. |
| 306 | * Modern Web Platform and JavaScript features should be preferred to legacy |
| 307 | constructs that target old browsers. |
| 308 | * Per the JavaScript guide, new tests should also follow any per-project |
| 309 | style guide, such as the |
xiaoyin.l | 1003c0b | 2016-12-06 02:51:17 | [diff] [blame] | 310 | [ServiceWorker Tests Style guide](https://www.chromium.org/blink/serviceworker/testing). |
pwnall | 6acacd8 | 2016-12-02 01:40:15 | [diff] [blame] | 311 | |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 312 | ## JavaScript Tests |
| 313 | |
| 314 | Whenever possible, the testing criteria should be expressed in JavaScript. The |
| 315 | alternatives, which will be described in future sections, result in slower and |
| 316 | less reliable tests. |
| 317 | |
| 318 | All new JavaScript tests should be written using the |
| 319 | [testharness.js](https://github.com/w3c/testharness.js/) testing framework. This |
| 320 | framework is used by the tests in the |
| 321 | [web-platform-tests](https://github.com/w3c/web-platform-tests) repository, |
| 322 | which is shared with all the other browser vendors, so `testharness.js` tests |
| 323 | are more accessible to browser developers. |
| 324 | |
| 325 | As a shared framework, `testharness.js` enjoys high-quality documentation, such |
| 326 | as [a tutorial](http://testthewebforward.org/docs/testharness-tutorial.html) and |
| 327 | [API documentation](https://github.com/w3c/testharness.js/blob/master/docs/api.md). |
| 328 | Layout tests should follow the recommendations of the above documents. |
| 329 | Furthermore, layout tests should include relevant |
| 330 | [metadata](http://testthewebforward.org/docs/css-metadata.html). The |
| 331 | specification URL (in `<link rel="help">`) is almost always relevant, and is |
| 332 | incredibly helpful to a developer who needs to understand the test quickly. |
| 333 | |
| 334 | Below is a skeleton for a JavaScript test embedded in an HTML page. Note that, |
| 335 | in order to follow the minimality guideline, the test omits the tags `<html>`, |
| 336 | `<head>`, and `<body>`, as they can be inferred by the HTML parser. |
| 337 | |
| 338 | ```html |
| 339 | <!doctype html> |
| 340 | <meta charset="utf-8"> |
ktyliu | e0bb988 | 2017-01-10 01:47:50 | [diff] [blame^] | 341 | <title>JavaScript: the true literal</title> |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 342 | <link rel="help" href="https://tc39.github.io/ecma262/#sec-boolean-literals"> |
| 343 | <meta name="assert" value="The true literal is equal to itself and immutable"> |
| 344 | <script src="/resources/testharness.js"></script> |
| 345 | <script src="/resources/testharnessreport.js"></script> |
| 346 | <script> |
| 347 | 'use strict'; |
| 348 | |
| 349 | // Synchronous test example. |
| 350 | test(() => { |
| 351 | const value = true; |
| 352 | assert_true(value, 'true literal'); |
| 353 | assert_equals(value.toString(), 'true', 'the string representation of true'); |
| 354 | }, 'The literal true in a synchronous test case'); |
| 355 | |
| 356 | // Asynchronous test example. |
| 357 | async_test(t => { |
| 358 | const originallyTrue = true; |
| 359 | setTimeout(t.step_func_done(() => { |
| 360 | assert_equals(originallyTrue, true); |
| 361 | }), 0); |
| 362 | }, 'The literal true in a setTimeout callback'); |
| 363 | |
| 364 | // Promise test example. |
| 365 | promise_test(() => { |
| 366 | return new Promise((resolve, reject) => { |
| 367 | resolve(true); |
| 368 | }).then(value => { |
| 369 | assert_true(value); |
| 370 | }); |
| 371 | }, 'The literal true used to resolve a Promise'); |
| 372 | |
| 373 | </script> |
| 374 | ``` |
| 375 | |
| 376 | Some points that are not immediately obvious from the example: |
| 377 | |
ktyliu | e0bb988 | 2017-01-10 01:47:50 | [diff] [blame^] | 378 | * The `<meta name="assert">` describes the purpose of the entire file, and |
| 379 | is not redundant to `<title>`. Don't add a `<meta name="assert">` when the |
| 380 | information in the `<title>` is sufficient. |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 381 | * When calling an `assert_` function that compares two values, the first |
| 382 | argument is the actual value (produced by the functionality being tested), and |
| 383 | the second argument is the expected value (known good, golden). The order |
| 384 | is important, because the testing harness relies on it to generate expressive |
| 385 | error messages that are relied upon when debugging test failures. |
| 386 | * The assertion description (the string argument to `assert_` methods) conveys |
| 387 | the way the actual value was obtained. |
| 388 | * If the expected value doesn't make it clear, the assertion description |
| 389 | should explain the desired behavior. |
| 390 | * Test cases with a single assertion should omit the assertion's description |
| 391 | when it is sufficiently clear. |
| 392 | * Each test case describes the circumstance that it tests, without being |
| 393 | redundant. |
| 394 | * Do not start test case descriptions with redundant terms like "Testing" |
| 395 | or "Test for". |
ktyliu | e0bb988 | 2017-01-10 01:47:50 | [diff] [blame^] | 396 | * Test files with a single test case should omit the test case description. |
| 397 | The file's `<title>` should be sufficient to describe the scenario being |
| 398 | tested. |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 399 | * Asynchronous tests have a few subtleties. |
| 400 | * The `async_test` wrapper calls its function with a test case argument that |
| 401 | is used to signal when the test case is done, and to connect assertion |
| 402 | failures to the correct test. |
| 403 | * `t.done()` must be called after all the test case's assertions have |
| 404 | executed. |
| 405 | * Test case assertions (actually, any callback code that can throw |
| 406 | exceptions) must be wrapped in `t.step_func()` calls, so that |
| 407 | assertion failures and exceptions can be traced back to the correct test |
| 408 | case. |
| 409 | * `t.step_func_done()` is a shortcut that combines `t.step_func()` with a |
| 410 | `t.done()` call. |
| 411 | |
| 412 | *** promo |
| 413 | Layout tests that load from `file://` origins must currently use relative paths |
| 414 | to point to |
| 415 | [/resources/testharness.js](../../third_party/WebKit/LayoutTests/resources/testharness.js) |
| 416 | and |
| 417 | [/resources/testharnessreport.js](../../third_party/WebKit/LayoutTests/resources/testharnessreport.js). |
| 418 | This is contrary to the WPT guidelines, which call for absolute paths. |
| 419 | This limitation does not apply to the tests in `LayoutTests/http`, which rely on |
| 420 | an HTTP server, or to the tests in `LayoutTests/imported/wpt`, which are |
| 421 | imported from the [WPT repository](https://github.com/w3c/web-platform-tests). |
| 422 | *** |
| 423 | |
| 424 | ### WPT Supplemental Testing APIs |
| 425 | |
| 426 | Some tests simply cannot be expressed using the Web Platform APIs. For example, |
| 427 | some tests that require a user to perform a gesture, such as a mouse click, |
| 428 | cannot be implemented using Web APIs. The WPT project covers some of these cases |
| 429 | via supplemental testing APIs. |
| 430 | |
| 431 | *** promo |
| 432 | In many cases, the user gesture is not actually necessary. For example, many |
| 433 | event handling tests can use |
| 434 | [synthetic events](https://developer.mozilla.org/docs/Web/Guide/Events/Creating_and_triggering_events). |
| 435 | *** |
| 436 | |
| 437 | *** note |
| 438 | TODO: document wpt_automation. Manual tests might end up moving here. |
| 439 | *** |
| 440 | |
| 441 | ### Relying on Blink-Specific Testing APIs |
| 442 | |
| 443 | Tests that cannot be expressed using the Web Platform APIs or WPT's testing APIs |
| 444 | use Blink-specific testing APIs. These APIs are only available in |
| 445 | [content_shell](./layout_tests_in_content_shell.md), and should only be used as |
| 446 | a last resort. |
| 447 | |
| 448 | A downside of Blink-specific APIs is that they are not as well documented as the |
| 449 | Web Platform features. Learning to use a Blink-specific feature requires finding |
| 450 | other tests that use it, or reading its source code. |
| 451 | |
| 452 | For example, the most popular Blink-specific API is `testRunner`, which is |
| 453 | implemented in |
| 454 | [components/test_runner/test_runner.h](../../components/test_runner/test_runner.h) |
| 455 | and |
| 456 | [components/test_runner/test_runner.cpp](../../components/test_runner/test_runner.cpp). |
| 457 | By skimming the `TestRunnerBindings::Install` method, we learn that the |
| 458 | testRunner API is presented by the `window.testRunner` and |
| 459 | `window.layoutTestsController` objects, which are synonyms. Reading the |
| 460 | `TestRunnerBindings::GetObjectTemplateBuilder` method tells us what properties |
| 461 | are available on the `window.testRunner` object. |
| 462 | |
| 463 | *** aside |
| 464 | `window.testRunner` is the preferred way to access the `testRunner` APIs. |
| 465 | `window.layoutTestsController` is still supported because it is used by |
| 466 | 3rd-party tests. |
| 467 | *** |
| 468 | |
| 469 | *** note |
| 470 | `testRunner` is the most popular testing API because it is also used indirectly |
| 471 | by tests that stick to Web Platform APIs. The `testharnessreport.js` file in |
| 472 | `testharness.js` is specifically designated to hold glue code that connects |
| 473 | `testharness.js` to the testing environment. Our implementation is in |
| 474 | [third_party/WebKit/LayoutTests/resources/testharnessreport.js](../../third_party/WebKit/LayoutTests/resources/testharnessreport.js), |
| 475 | and uses the `testRunner` API. |
| 476 | *** |
| 477 | |
| 478 | See the [components/test_runner/](../../components/test_runner/) directory and |
| 479 | [WebKit's LayoutTests guide](https://trac.webkit.org/wiki/Writing%20Layout%20Tests%20for%20DumpRenderTree) |
| 480 | for other useful APIs. For example, `window.eventSender` |
| 481 | ([components/test_runner/event_sender.h](../../components/test_runner/event_sender.h) |
| 482 | and |
| 483 | [components/test_runner/event_sender.cpp](../../components/test_runner/event_sender.cpp)) |
| 484 | has methods that simulate events input such as keyboard / mouse input and |
| 485 | drag-and-drop. |
| 486 | |
| 487 | Here is a UML diagram of how the `testRunner` bindings fit into Chromium. |
| 488 | |
| 489 | [](https://docs.google.com/drawings/d/1KNRNjlxK0Q3Tp8rKxuuM5mpWf4OJQZmvm9_kpwu_Wwg/edit) |
pwnall | 6acacd8 | 2016-12-02 01:40:15 | [diff] [blame] | 490 | |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 491 | ### Manual Tests |
| 492 | |
pwnall | 6acacd8 | 2016-12-02 01:40:15 | [diff] [blame] | 493 | 🚧 Whenever possible, tests that rely on (WPT's or Blink's) testing APIs |
| 494 | should also be usable as |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 495 | [manual tests](http://testthewebforward.org/docs/manual-test.html). This makes |
| 496 | it easy to debug the test, and to check whether our behavior matches other |
| 497 | browsers. |
| 498 | |
pwnall | 6acacd8 | 2016-12-02 01:40:15 | [diff] [blame] | 499 | *** promo |
| 500 | The recommendation to degrade to manual tests is still being discussed on |
| 501 | [blink-dev](https://groups.google.com/a/chromium.org/d/topic/blink-dev/XsR6PKRrS1E/discussion). |
| 502 | However, please keep in mind that a manual test can be debugged in the browser, |
| 503 | whereas a test that does not degrade gracefully can only be debugged in the test |
| 504 | runner. Fellow project members and future you will thank you for having your |
| 505 | test work as a manual test. |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 506 | *** |
| 507 | |
| 508 | Manual tests should minimize the chance of user error. This implies keeping the |
| 509 | manual steps to a minimum, and having simple and clear instructions that |
| 510 | describe all the configuration changes and user gestures that match the effect |
| 511 | of the Blink-specific APIs used by the test. |
| 512 | |
| 513 | Below is an example of a fairly minimal test that uses a Blink-Specific API |
| 514 | (`window.eventSender`), and gracefully degrades to a manual test. |
| 515 | |
| 516 | ```html |
| 517 | <!doctype html> |
| 518 | <meta charset="utf-8"> |
ktyliu | e0bb988 | 2017-01-10 01:47:50 | [diff] [blame^] | 519 | <title>DOM: Event.isTrusted for UI events</title> |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 520 | <link rel="help" href="https://dom.spec.whatwg.org/#dom-event-istrusted"> |
| 521 | <link rel="help" href="https://dom.spec.whatwg.org/#constructing-events"> |
| 522 | <meta name="assert" |
| 523 | content="Event.isTrusted is true for events generated by user interaction"> |
| 524 | <script src="../../resources/testharness.js"></script> |
| 525 | <script src="../../resources/testharnessreport.js"></script> |
| 526 | |
| 527 | <p>Please click on the button below.</p> |
| 528 | <button>Click Me!</button> |
| 529 | |
| 530 | <script> |
| 531 | 'use strict'; |
| 532 | |
| 533 | setup({ explicit_timeout: true }); |
| 534 | |
| 535 | promise_test(() => { |
| 536 | const button = document.querySelector('button'); |
| 537 | return new Promise((resolve, reject) => { |
| 538 | const button = document.querySelector('button'); |
| 539 | button.addEventListener('click', (event) => { |
| 540 | resolve(event); |
| 541 | }); |
| 542 | |
| 543 | if (window.eventSender) { |
| 544 | eventSender.mouseMoveTo(button.offsetLeft, button.offsetTop); |
| 545 | eventSender.mouseDown(); |
| 546 | eventSender.mouseUp(); |
| 547 | } |
| 548 | }).then((clickEvent) => { |
| 549 | assert_true(clickEvent.isTrusted); |
| 550 | }); |
| 551 | |
| 552 | }, 'Click generated by user interaction'); |
| 553 | |
| 554 | </script> |
| 555 | ``` |
| 556 | |
| 557 | The test exhibits the following desirable features: |
| 558 | |
| 559 | * It has a second specification URL (`<link rel="help">`), because the paragraph |
| 560 | that documents the tested feature (referenced by the primary URL) is not very |
| 561 | informative on its own. |
| 562 | * It links to the |
| 563 | [WHATWG Living Standard](https://wiki.whatwg.org/wiki/FAQ#What_does_.22Living_Standard.22_mean.3F), |
| 564 | rather than to a frozen version of the specification. |
| 565 | * It contains clear instructions for manually triggering the test conditions. |
| 566 | The test starts with a paragraph (`<p>`) that tells the tester exactly what to |
| 567 | do, and the `<button>` that needs to be clicked is clearly labeled. |
| 568 | * It disables the timeout mechanism built into `testharness.js` by calling |
| 569 | `setup({ explicit_timeout: true });` |
| 570 | * It checks for the presence of the Blink-specific testing APIs |
| 571 | (`window.eventSender`) before invoking them. The test does not automatically |
| 572 | fail when the APIs are not present. |
| 573 | * It uses [Promises](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise) |
| 574 | to separate the test setup from the assertions. This is particularly helpful |
| 575 | for manual tests that depend on a sequence of events to occur, as Promises |
| 576 | offer a composable way to express waiting for asynchronous events that avoids |
| 577 | [callback hell](http://stackabuse.com/avoiding-callback-hell-in-node-js/). |
| 578 | |
| 579 | Notice that the test is pretty heavy compared to a minimal JavaScript test that |
| 580 | does not rely on testing APIs. Only use testing APIs when the desired testing |
| 581 | conditions cannot be set up using Web Platform APIs. |
| 582 | |
| 583 | ### Text Test Baselines |
| 584 | |
| 585 | By default, all the test cases in a file that uses `testharness.js` are expected |
| 586 | to pass. However, in some cases, we prefer to add failing test cases to the |
| 587 | repository, so that we can be notified when the failure modes change (e.g., we |
| 588 | want to know if a test starts crashing rather than returning incorrect output). |
| 589 | In these situations, a test file will be accompanied by a baseline, which is an |
| 590 | `-expected.txt` file that contains the test's expected output. |
| 591 | |
| 592 | The baselines are generated automatically when appropriate by |
| 593 | `run-webkit-tests`, which is described [here](./layout_tests.md), and by the |
| 594 | [rebaselining tools](./layout_test_expectations.md). |
| 595 | |
| 596 | Text baselines for `testharness.js` should be avoided, as having a text baseline |
| 597 | associated with a `testharness.js` indicates the presence of a bug. For this |
| 598 | reason, CLs that add text baselines must include a |
| 599 | [crbug.com](https://crbug.com) link for an issue tracking the removal of the |
| 600 | text expectations. |
| 601 | |
| 602 | * When creating tests that will be upstreamed to WPT, and Blink's current |
| 603 | behavior does not match the specification that is being tested, a text |
| 604 | baseline is necessary. Remember to create an issue tracking the expectation's |
| 605 | removal, and to link the issue in the CL description. |
| 606 | * Layout tests that cannot be upstreamed to WPT should use JavaScript to |
| 607 | document Blink's current behavior, rather than using JavaScript to document |
| 608 | desired behavior and a text file to document current behavior. |
| 609 | |
| 610 | ### The js-test.js Legacy Harness |
| 611 | |
| 612 | *** promo |
| 613 | For historical reasons, older tests are written using the `js-test` harness. |
| 614 | This harness is **deprecated**, and should not be used for new tests. |
| 615 | *** |
| 616 | |
| 617 | If you need to understand old tests, the best `js-test` documentation is its |
| 618 | implementation at |
| 619 | [third_party/WebKit/LayoutTests/resources/js-test.js](../../third_party/WebKit/LayoutTests/resources/js-test.js). |
| 620 | |
| 621 | `js-test` tests lean heavily on the Blink-specific `testRunner` testing API. |
| 622 | In a nutshell, the tests call `testRunner.dumpAsText()` to signal that the page |
| 623 | content should be dumped and compared against a text baseline (an |
| 624 | `-expected.txt` file). As a consequence, `js-test` tests are always accompanied |
| 625 | by text baselines. Asynchronous tests also use `testRunner.waitUntilDone()` and |
| 626 | `testRunner.notifyDone()` to tell the testing tools when they are complete. |
| 627 | |
| 628 | ### Tests that use an HTTP Server |
| 629 | |
| 630 | By default, tests are loaded as if via `file:` URLs. Some web platform features |
| 631 | require tests served via HTTP or HTTPS, for example absolute paths (`src=/foo`) |
| 632 | or features restricted to secure protocols. |
| 633 | |
| 634 | HTTP tests are those under `LayoutTests/http/tests` (or virtual variants). Use a |
| 635 | locally running HTTP server (Apache) to run them. Tests are served off of ports |
| 636 | 8000 and 8080 for HTTP, and 8443 for HTTPS. If you run the tests using |
| 637 | `run-webkit-tests`, the server will be started automatically. To run the server |
| 638 | manually to reproduce or debug a failure: |
| 639 | |
| 640 | ```bash |
| 641 | cd src/third_party/WebKit/Tools/Scripts |
| 642 | run-blink-httpd start |
| 643 | ``` |
| 644 | |
| 645 | The layout tests will be served from `http://127.0.0.1:8000`. For example, to |
| 646 | run the test `http/tests/serviceworker/chromium/service-worker-allowed.html`, |
| 647 | navigate to |
| 648 | `http://127.0.0.1:8000/serviceworker/chromium/service-worker-allowed.html`. Some |
| 649 | tests will behave differently if you go to 127.0.0.1 instead of localhost, so |
| 650 | use 127.0.0.1. |
| 651 | |
| 652 | To kill the server, run `run-blink-httpd --server stop`, or just use `taskkill` |
| 653 | or the Task Manager on Windows, and `killall` or Activity Monitor on MacOS. |
| 654 | |
| 655 | The test server sets up an alias to the `LayoutTests/resources` directory. In |
| 656 | HTTP tests, you can access the testing framework at e.g. |
pwnall | e781948 | 2016-12-17 00:58:40 | [diff] [blame] | 657 | `src="/resources/testharness.js"`. |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 658 | |
| 659 | TODO: Document [wptserve](http://wptserve.readthedocs.io/) when we are in a |
| 660 | position to use it to run layout tests. |
| 661 | |
| 662 | ## Reference Tests (Reftests) |
| 663 | |
| 664 | Reference tests, also known as reftests, perform a pixel-by-pixel comparison |
| 665 | between the rendered image of a test page and the rendered image of a reference |
| 666 | page. Most reference tests pass if the two images match, but there are cases |
| 667 | where it is useful to have a test pass when the two images do _not_ match. |
| 668 | |
| 669 | Reference tests are more difficult to debug than JavaScript tests, and tend to |
| 670 | be slower as well. Therefore, they should only be used for functionality that |
| 671 | cannot be covered by JavaScript tests. |
| 672 | |
| 673 | New reference tests should follow the |
| 674 | [WPT reftests guidelines](http://testthewebforward.org/docs/reftests.html). The |
| 675 | most important points are summarized below. |
| 676 | |
pwnall | 6acacd8 | 2016-12-02 01:40:15 | [diff] [blame] | 677 | * 🚧 The test page declares the reference page using a |
| 678 | `<link rel="match">` or `<link rel="mismatch">`, depending on whether the test |
| 679 | passes when the test image matches or does not match the reference image. |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 680 | * The reference page must not use the feature being tested. Otherwise, the test |
| 681 | is meaningless. |
| 682 | * The reference page should be as simple as possible, and should not depend on |
| 683 | advanced features. Ideally, the reference page should render as intended even |
| 684 | on browsers with poor CSS support. |
| 685 | * Reference tests should be self-describing. |
| 686 | * Reference tests do _not_ include `testharness.js`. |
| 687 | |
pwnall | 6acacd8 | 2016-12-02 01:40:15 | [diff] [blame] | 688 | 🚧 Our testing infrastructure was designed for the |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 689 | [WebKit reftests](https://trac.webkit.org/wiki/Writing%20Reftests) that Blink |
| 690 | has inherited. The consequences are summarized below. |
| 691 | |
| 692 | * Each reference page must be in the same directory as its associated test. |
| 693 | Given a test page named `foo` (e.g. `foo.html` or `foo.svg`), |
| 694 | * The reference page must be named `foo-expected` (e.g., |
| 695 | `foo-expected.html`) if the test passes when the two images match. |
| 696 | * The reference page must be named `foo-expected-mismatch` (e.g., |
| 697 | `foo-expected-mismatch.svg`) if the test passes when the two images do |
| 698 | _not_ match. |
| 699 | * Multiple references and chained references are not supported. |
| 700 | |
| 701 | The following example demonstrates a reference test for |
| 702 | [`<ol>`'s reversed attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol). |
| 703 | The example assumes that the test page is named `ol-reversed.html`. |
| 704 | |
| 705 | ```html |
| 706 | <!doctype html> |
| 707 | <meta charset="utf-8"> |
| 708 | <link rel="match" href="ol-reversed-expected.html"> |
| 709 | |
| 710 | <ol reversed> |
| 711 | <li>A</li> |
| 712 | <li>B</li> |
| 713 | <li>C</li> |
| 714 | </ol> |
| 715 | ``` |
| 716 | |
| 717 | The reference page, which must be named `ol-reversed-expected.html`, is below. |
| 718 | |
| 719 | ```html |
| 720 | <!doctype html> |
| 721 | <meta charset="utf-8"> |
| 722 | |
| 723 | <ol> |
| 724 | <li value="3">A</li> |
| 725 | <li value="2">B</li> |
| 726 | <li value="1">C</li> |
| 727 | </ol> |
| 728 | ``` |
| 729 | |
pwnall | 6acacd8 | 2016-12-02 01:40:15 | [diff] [blame] | 730 | *** promo |
| 731 | The method for pointing out a test's reference page is still in flux, and is |
| 732 | being discussed on |
| 733 | [blink-dev](https://groups.google.com/a/chromium.org/d/topic/blink-dev/XsR6PKRrS1E/discussion). |
| 734 | *** |
| 735 | |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 736 | ## Pixel Tests |
| 737 | |
| 738 | `testRunner` APIs such as `window.testRunner.dumpAsTextWithPixelResults()` and |
| 739 | `window.testRunner.dumpDragImage()` create an image result that is associated |
| 740 | with the test. The image result is compared against an image baseline, which is |
| 741 | an `-expected.png` file associated with the test, and the test passes if the |
| 742 | image result is identical to the baseline, according to a pixel-by-pixel |
| 743 | comparison. Tests that have image results (and baselines) are called **pixel |
| 744 | tests**. |
| 745 | |
| 746 | Pixel tests should still follow the principles laid out above. Pixel tests pose |
| 747 | unique challenges to the desire to have *self-describing* and *cross-platform* |
| 748 | tests. The |
| 749 | [WPT test style guidelines](http://testthewebforward.org/docs/test-style-guidelines.html) |
| 750 | contain useful guidance. The most relevant pieces of advice are below. |
| 751 | |
| 752 | * Whenever possible, use a green paragraph / page / square to indicate success. |
| 753 | If that is not possible, make the test self-describing by including a textual |
| 754 | description of the desired (passing) outcome. |
| 755 | * Only use the red color or the word `FAIL` to highlight errors. This does not |
| 756 | apply when testing the color red. |
pwnall | 6acacd8 | 2016-12-02 01:40:15 | [diff] [blame] | 757 | * 🚧 Use the |
| 758 | [Ahem font](https://www.w3.org/Style/CSS/Test/Fonts/Ahem/README) to reduce the |
| 759 | variance introduced by the platform's text rendering system. This does not |
| 760 | apply when testing text, text flow, font selection, font fallback, font |
| 761 | features, or other typographic information. |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 762 | |
| 763 | *** promo |
| 764 | When using `window.testRunner.dumpAsTextWithPixelResults()`, the image result |
| 765 | will always be 800x600px, because test pages are rendered in an 800x600px |
| 766 | viewport. Pixel tests that do not specifically cover scrolling should fit in an |
| 767 | 800x600px viewport without creating scrollbars. |
| 768 | *** |
| 769 | |
pwnall | 6acacd8 | 2016-12-02 01:40:15 | [diff] [blame] | 770 | *** promo |
| 771 | The recommendation of using Ahem in pixel tests is being discussed on |
| 772 | [blink-dev](https://groups.google.com/a/chromium.org/d/topic/blink-dev/XsR6PKRrS1E/discussion). |
| 773 | *** |
| 774 | |
pwnall | 4ea2eb3 | 2016-11-29 02:47:25 | [diff] [blame] | 775 | The following snippet includes the Ahem font in a layout test. |
| 776 | |
| 777 | ```html |
| 778 | <style> |
| 779 | body { |
| 780 | font: 10px Ahem; |
| 781 | } |
| 782 | </style> |
| 783 | <script src="/resources/ahem.js"></script> |
| 784 | ``` |
| 785 | |
| 786 | *** promo |
| 787 | Tests outside `LayoutTests/http` and `LayoutTests/imported/wpt` currently need |
| 788 | to use a relative path to |
| 789 | [/third_party/WebKit/LayoutTests/resources/ahem.js](../../third_party/WebKit/LayoutTests/resources/ahem.js) |
| 790 | *** |
| 791 | |
| 792 | ### Tests that need to paint, raster, or draw a frame of intermediate output |
| 793 | |
| 794 | A layout test does not actually draw frames of output until the test exits. |
| 795 | Tests that need to generate a painted frame can use |
| 796 | `window.testRunner.displayAsyncThen`, which will run the machinery to put up a |
| 797 | frame, then call the passed callback. There is also a library at |
| 798 | `fast/repaint/resources/text-based-repaint.js` to help with writing paint |
| 799 | invalidation and repaint tests. |
| 800 | |
| 801 | ## Dump Render Tree (DRT) Tests |
| 802 | |
| 803 | A Dump Render Tree test renders a web page and produces up to two results, which |
| 804 | are compared against baseline files: |
| 805 | |
| 806 | * All tests output a textual representation of Blink's |
| 807 | [render tree](https://developers.google.com/web/fundamentals/performance/critical-rendering-path/render-tree-construction), |
| 808 | which is compared against an `-expected.txt` text baseline. |
| 809 | * Some tests also output the image of the rendered page, which is compared |
| 810 | against an `-expected.png` image baseline, using the same method as pixel |
| 811 | tests. |
| 812 | |
| 813 | TODO: Document the API used by DRT tests to opt out of producing image results. |
| 814 | |
| 815 | A DRT test passes if _all_ of its results match their baselines. Like pixel |
| 816 | tests, the output of DRT tests depends on platform-specific mechanisms, so DRT |
| 817 | tests often require per-platform baselines. Furthermore, DRT tests depend on the |
| 818 | render tree data structure, which means that if we replace the render tree data |
| 819 | structure, we will need to look at each DRT test and consider whether it is |
| 820 | still meaningful. |
| 821 | |
| 822 | For these reasons, DRT tests should **only** be used to cover aspects of the |
| 823 | layout code that can only be tested by looking at the render tree. Any |
| 824 | combination of the other test types is preferable to a DRT test. DRT tests are |
| 825 | [inherited from WebKit](https://webkit.org/blog/1456/layout-tests-practice/), so |
| 826 | the repository may have some unfortunate examples of DRT tests. |
| 827 | |
| 828 | The following page is an example of a DRT test. |
| 829 | |
| 830 | ```html |
| 831 | <!doctype html> |
| 832 | <meta charset="utf-8"> |
| 833 | <style> |
| 834 | body { font: 10px Ahem; } |
| 835 | span::after { |
| 836 | content: "pass"; |
| 837 | color: green; |
| 838 | } |
| 839 | </style> |
| 840 | <script src="/resources/ahem.js"></script> |
| 841 | |
| 842 | <p><span>Pass if a green PASS appears to the right: </span></p> |
| 843 | ``` |
| 844 | |
| 845 | The most important aspects of the example are that the test page does not |
| 846 | include a testing framework, and that it follows the guidelines for pixel tests. |
| 847 | The test page produces the text result below. |
| 848 | |
| 849 | ``` |
| 850 | layer at (0,0) size 800x600 |
| 851 | LayoutView at (0,0) size 800x600 |
| 852 | layer at (0,0) size 800x30 |
| 853 | LayoutBlockFlow {HTML} at (0,0) size 800x30 |
| 854 | LayoutBlockFlow {BODY} at (8,10) size 784x10 |
| 855 | LayoutBlockFlow {P} at (0,0) size 784x10 |
| 856 | LayoutInline {SPAN} at (0,0) size 470x10 |
| 857 | LayoutText {#text} at (0,0) size 430x10 |
| 858 | text run at (0,0) width 430: "Pass if a green PASS appears to the right: " |
| 859 | LayoutInline {<pseudo:after>} at (0,0) size 40x10 [color=#008000] |
| 860 | LayoutTextFragment (anonymous) at (430,0) size 40x10 |
| 861 | text run at (430,0) width 40: "pass" |
| 862 | ``` |
| 863 | |
| 864 | Notice that the test result above depends on the size of the `<p>` text. The |
| 865 | test page uses the Ahem font (introduced above), whose main design goal is |
| 866 | consistent cross-platform rendering. Had the test used another font, its text |
| 867 | baseline would have depended on the fonts installed on the testing computer, and |
| 868 | on the platform's font rendering system. Please follow the pixel tests |
| 869 | guidelines and write reliable DRT tests! |
| 870 | |
| 871 | WebKit's render tree is described in |
| 872 | [a series of posts](https://webkit.org/blog/114/webcore-rendering-i-the-basics/) |
| 873 | on WebKit's blog. Some of the concepts there still apply to Blink's render tree. |
| 874 | |
| 875 | ## Directory Structure |
| 876 | |
| 877 | The [LayoutTests directory](../../third_party/WebKit/LayoutTests) currently |
| 878 | lacks a strict, formal structure. The following directories have special |
| 879 | meaning: |
| 880 | |
| 881 | * The `http/` directory hosts tests that require an HTTP server (see above). |
| 882 | * The `resources/` subdirectory in every directory contains binary files, such |
| 883 | as media files, and code that is shared by multiple test files. |
| 884 | |
| 885 | *** note |
| 886 | Some layout tests consist of a minimal HTML page that references a JavaScript |
| 887 | file in `resources/`. Please do not use this pattern for new tests, as it goes |
| 888 | against the minimality principle. JavaScript and CSS files should only live in |
| 889 | `resources/` if they are shared by at least two test files. |
| 890 | *** |