Reftest.rst (35331B)
1 Layout Engine Visual Tests (reftest) 2 ==================================== 3 4 Layout Engine Visual Tests (reftest) 5 L. David Baron <dbaron@dbaron.org>, Mozilla Corporation 6 July 19, 2006 7 8 This code is designed to run tests of Mozilla's layout engine. These 9 tests consist of an HTML (or other format) file along with a reference 10 in the same format. The tests are run based on a manifest file, and for 11 each test, PASS or FAIL is reported, and UNEXPECTED is reported if the 12 result (PASS or FAIL) was not the expected result noted in the manifest. 13 14 Images of the display of both tests are captured, and most test types 15 involve comparing these images (e.g., test types == or !=) to determine 16 whether the test passed. The captures of the tests are taken in a 17 viewport that is 800 pixels wide and 1000 pixels tall, so any content 18 outside that area will be ignored (except for any scrollbars that are 19 displayed). Ideally, however, tests should be written so that they fit 20 within 600x600, since we may in the future want to switch to 600x600 to 21 match http://lists.w3.org/Archives/Public/www-style/2012Sep/0562.html . 22 23 Why this way? 24 ------------- 25 26 Writing HTML tests where the reference rendering is also in HTML is 27 harder than simply writing bits of HTML that can be regression-tested by 28 comparing the rendering of an older build to that of a newer build 29 (perhaps using stored reference images from the older build). However, 30 comparing across time has major disadvantages: 31 32 * Comparisons across time either require two runs for every test, or 33 they require stored reference images appropriate for the platform and 34 configuration (often limiting testing to a very specific 35 configuration). 36 37 * Comparisons across time may fail due to expected changes, for 38 example, changes in the default style sheet for HTML, changes in the 39 appearance of form controls, or changes in default preferences like 40 default font size or default colors. 41 42 Using tests for which the pass criteria were explicitly chosen allows 43 running tests at any time to see whether they still pass. 44 45 Manifest Format 46 --------------- 47 48 The test manifest format is a plain text file. A line starting with a 49 ``"#"`` is a comment. Lines may be commented using whitespace followed by 50 a ``"#"`` and the comment. Each non-blank line (after removal of comments) 51 must be one of the following: 52 53 Inclusion of another manifest 54 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 55 56 ``<skip-type>* include <relative_path>`` 57 58 ``<skip-type>`` is one of the skip or skip-if items (see their definitions 59 in ``<failure-type>`` below). If any of the skip types evaluate to true (i.e. 60 they are a plain ``skip`` or they are a ``skip-if`` with a condition that 61 evaluates to true), then the include statement is skipped. Otherwise, 62 reftests in the specified manifest are included in the set of reftests 63 that are run. 64 65 A test item 66 ~~~~~~~~~~~ 67 68 ``[ <failure-type> | <preference> ]* [<http>] <type> <url> <url_ref>`` 69 70 where 71 72 a. ``<failure-type>`` (optional) is one of the following: 73 74 ``fails`` 75 The test passes if the images of the two renderings DO NOT meet the 76 conditions specified in the ``<type>``. 77 78 ``fails-if(condition)`` 79 If the condition is met, the test passes if the images of the two 80 renderings DO NOT meet the conditions of ``<type>``. If the condition 81 is not met, the test passes if the conditions of ``<type>`` are met. 82 83 ``needs-focus`` 84 The test fails or times out if the reftest window is not focused. 85 86 ``random`` 87 The results of the test are random and therefore not to be considered in the output. 88 89 ``random-if(condition)`` 90 The results of the test are random if a given condition is met. 91 92 ``silentfail`` 93 This test may fail silently, and if that happens it should count as if 94 the test passed. This is useful for cases where silent failure is the 95 intended behavior (for example, in an out of memory situation in 96 JavaScript, we stop running the script silently and immediately, in 97 hopes of reclaiming enough memory to keep the browser functioning). 98 99 ``silentfail-if(condition)`` 100 This test may fail silently if the condition is met. 101 102 ``skip`` 103 This test should not be run. This is useful when a test fails in a 104 catastrophic way, such as crashing or hanging the browser. Using 105 ``skip`` is preferred to simply commenting out the test because we 106 want to report the test failure at the end of the test run. 107 108 ``skip-if(condition)`` 109 If the condition is met, the test is not run. This is useful if, for 110 example, the test crashes only on a particular platform (i.e. it 111 allows us to get test coverage on the other platforms). 112 113 ``slow`` 114 The test may take a long time to run, so run it if slow tests are 115 either enabled or not disabled (test manifest interpreters may choose 116 whether or not to run such tests by default). 117 118 ``slow-if(condition)`` 119 If the condition is met, the test is treated as if ``slow`` had been 120 specified. This is useful for tests which are slow only on particular 121 platforms (e.g. a test which exercised out-of-memory behavior might be 122 fast on a 32-bit system but inordinately slow on a 64-bit system). 123 124 ``fuzzy(minDiff-maxDiff,minPixelCount-maxPixelCount)`` 125 This allows a test to pass if the pixel value differences are between 126 ``minDiff`` and ``maxDiff``, inclusive, and the total number of 127 different pixels is between ``minPixelCount`` and ``maxPixelCount``, 128 inclusive. It can also be used with ``!=`` to ensure that the 129 difference is outside the specified interval. Note that with ``!=`` 130 tests the minimum bounds of the ranges must be zero. 131 132 Fuzzy tends to be used for two different sorts of cases. The main 133 case is tests that are expected to be equal, but actually fail in a 134 minor way (e.g., an antialiasing difference), and we want to ensure 135 that the test doesn't regress further so we don't want to mark the 136 test as failing. For these cases, test annotations should be the 137 tightest bounds possible: if the behavior is entirely deterministic 138 this means a range like ``fuzzy(1-1,8-8)``, and if at all possible, 139 the ranges should not include 0. In cases where the test only 140 sometimes fails, this unfortunately requires using 0 in both ranges, 141 which means that we won't get reports of an unexpected pass if the 142 problem is fixed (allowing us to remove the ``fuzzy()`` annotation 143 and expect the test to pass from then on). 144 145 The second case where fuzzy is used is tests that are supposed 146 to allow some amount of variability (i.e., tests where the 147 specification allows variability such that we can't assert 148 that all pixels are the same). Such tests should generally be 149 avoided (for example, by covering up the pixels that can vary 150 with another element), but when they are needed, the ranges in 151 the ``fuzzy()`` annotation should generally include 0. 152 153 ``fuzzy-if(condition,minDiff-maxDiff,minPixelCount-maxPixelCount)`` 154 If the condition is met, the test is treated as if ``fuzzy`` had been 155 specified. This is useful if there are differences on particular 156 platforms. See ``fuzzy()`` above. 157 158 ``require-or(cond1&&cond2&&...,fallback)`` 159 Require some particular setup be performed or environmental 160 condition(s) made true (eg setting debug mode) before the test 161 is run. If any condition is unknown, unimplemented, or fails, 162 revert to the fallback failure-type. 163 Example: ``require-or(debugMode,skip)`` 164 165 ``asserts(count)`` 166 Loading the test and reference is known to assert exactly 167 ``count`` times. 168 NOTE: An asserts() notation with a non-zero count or maxCount 169 suppresses use of a cached canvas for the test with the 170 annotation. However, if later occurrences of the same test 171 are not annotated, they will use the cached canvas 172 (potentially from the load that asserted). This allows 173 repeated use of the same test or reference to be annotated 174 correctly (which may be particularly useful when the uses are 175 in different subdirectories that can be tested independently), 176 but does not force them to be, nor does it force suppression 177 of caching for a common reference when it is the test that 178 asserts. 179 180 ``asserts-if(condition,count)`` 181 Same as above, but only if condition is true. 182 183 ``asserts(minCount-maxCount)`` 184 Loading the test and reference is known to assert between 185 minCount and maxCount times, inclusive. 186 NOTE: See above regarding canvas caching. 187 188 ``asserts-if(condition,minCount-maxCount)`` 189 Same as above, but only if condition is true. 190 191 ``noautofuzz`` 192 Disables the autofuzzing behaviour hard-coded in the reftest harness 193 for specific platform configurations. The autofuzzing is intended to 194 compensate for inherent nondeterminism that results in intermittently 195 fuzzy results (with small amounts of fuzz) across many/all tests on 196 a given platform. Specifying 'noautofuzz' on the test will disable 197 the autofuzzing for that test and require an exact match. 198 199 Conditions are JavaScript expressions *without spaces* in them. 200 They are evaluated in a sandbox in which a limited set of 201 variables are defined. See the BuildConditionSandbox function in 202 ``layout/tools/reftest.js`` for details. 203 204 Examples of using conditions: :: 205 206 207 fails-if(winWidget) == test reference 208 asserts-if(cocoaWidget,2) load crashtest 209 210 211 b. ``<preference>`` (optional) is a string of the form 212 213 ``pref(<name>,<value>)`` 214 215 ``test-pref(<name>,<value>)`` 216 217 ``ref-pref(<name>,<value>)`` 218 219 where ``<name>`` is the name of a preference setting, as seen in 220 about:config, and ``<value>`` is the value to which this preference 221 should be set. ``<value>`` may be a boolean (true/false), an integer, 222 or a quoted string *without spaces*, according to the type of the 223 preference. 224 225 The preference will be set to the specified value prior to 226 rendering the test and/or reference canvases (pref() applies to 227 both, test-pref() only to the test, and ref-pref() only to the 228 reference), and will be restored afterwards so that following 229 tests are not affected. Note that this feature is only useful for 230 "live" preferences that take effect immediately, without requiring 231 a browser restart. 232 233 c. ``<http>``, if present, is one of the strings (sans quotes) "HTTP" or 234 "HTTP(..)" or "HTTP(../..)" or "HTTP(../../..)", etc. , indicating that 235 the test should be run over an HTTP server because it requires certain 236 HTTP headers or a particular HTTP status. (Don't use this if your test 237 doesn't require this functionality, because it unnecessarily slows down 238 the test.) 239 240 With "HTTP", HTTP tests have the restriction that any resource an HTTP 241 test accesses must be accessed using a relative URL, and the test and 242 the resource must be within the directory containing the reftest 243 manifest that describes the test (or within a descendant directory). 244 The variants "HTTP(..)", etc., can be used to relax this restriction by 245 allowing resources in the parent directory, etc. 246 247 To modify the HTTP status or headers of a resource named FOO, create a 248 sibling file named FOO^headers^ with the following contents: 249 250 ``[<http-status>]`` 251 252 ``<http-header>*`` 253 254 ``<http-status>`` 255 A line of the form "HTTP ###[ <description>]", where ### indicates 256 the desired HTTP status and <description> indicates a desired HTTP 257 status description, if any. If this line is omitted, the default is 258 "HTTP 200 OK". 259 260 ``<http-header>`` 261 A line in standard HTTP header line format, i.e. 262 "Field-Name: field-value". You may not repeat the use of a Field-Name 263 and must coalesce such headers together, and each header must be 264 specified on a single line, but otherwise the format exactly matches 265 that from HTTP itself. 266 267 HTTP tests may also incorporate SJS files. SJS files provide similar 268 functionality to CGI scripts, in that the response they produce can be 269 dependent on properties of the incoming request. Currently these 270 properties are restricted to method type and headers, but eventually 271 it should be possible to examine data in the body of the request as 272 well when computing the generated response. An SJS file is a JavaScript 273 file with a .sjs extension which defines a global `handleRequest` 274 function (called every time that file is loaded during reftests) in this 275 format: :: 276 277 function handleRequest(request, response) 278 { 279 response.setStatusLine(request.httpVersion, 200, "OK"); 280 281 // You *probably* want this, or else you'll get bitten if you run 282 // reftest multiple times with the same profile. 283 response.setHeader("Cache-Control", "no-cache"); 284 285 response.write("any ASCII data you want"); 286 287 var outputStream = response.bodyOutputStream; 288 // ...anything else you want to do, synchronously... 289 } 290 291 For more details on exactly which functions and properties are available 292 on request/response in handleRequest, see the nsIHttpRe(quest|sponse) 293 definitions in ``netwerk/test/httpserver/nsIHttpServer.idl``. 294 295 HTTP tests can also make use of example.org URIs in order to test cross 296 site behaviour. "example.org/filename" will access filename in the same 297 directly as the current reftest. (Not currently implemented for android.) 298 299 d. ``<type>`` is one of the following: 300 301 ``==`` 302 The test passes if the images of the two renderings are the SAME. 303 304 ``!=`` 305 The test passes if the images of the two renderings are DIFFERENT. 306 307 ``load`` 308 The test passes unconditionally if the page loads. url_ref must be 309 omitted, and the test cannot be marked as fails or random. (Used to 310 test for crashes, hangs, assertions, and leaks.) 311 312 ``script`` 313 The loaded page records the test's pass or failure status in a 314 JavaScript data structure accessible through the following API. 315 316 ``getTestCases()`` returns an array of test result objects 317 representing the results of the tests performed by the page. 318 319 Each test result object has two methods: 320 321 ``testPassed()`` returns true if the test result object passed, 322 otherwise it returns false. 323 324 ``testDescription()`` returns a string describing the test 325 result. 326 327 ``url_ref`` must be omitted. The test may be marked as fails or 328 random. (Used to test the JavaScript Engine.) 329 330 ``print`` 331 The test passes if the printouts (as PDF) of the two renderings 332 are the SAME by applying the following comparisons: 333 334 - The number of pages generated for both printouts must match. 335 - The text content of both printouts must match (rasterized text 336 does not match real text). 337 338 You can specify a print range by setting the reftest-print-range 339 attribute on the document element. Example: :: 340 341 <html reftest-print-range="2-3"> 342 ... 343 344 345 The following example would lead to a single page print: :: 346 347 <html reftest-print-range="2-2"> 348 ... 349 350 You can also print selected elements only: :: 351 352 <html reftest-print-range="selection"> 353 ... 354 355 Make sure to include code in your test that actually selects something. 356 357 Future additions to the set of comparisons might include: 358 359 - Matching the paper size 360 - Validating printed headers and footers 361 - Testing (fuzzy) position of elements 362 - Testing specific print related CSS properties 363 364 The main difference between ``print`` and ``==/!=`` reftests is that 365 ``print`` makes us compare the structure of print results (by parsing 366 the output PDF) rather than taking screenshots and comparing pixel 367 values. This allows us to test for common printing related issues 368 like text being rasterized when it shouldn't. This difference in 369 behavior is also why this is its own reftest operator, rather than 370 a flavor of ``==/!=``. It would be somewhat misleading to list these 371 print reftests as ``==/!=``, because they don't actually check for 372 pixel matching. 373 374 See the chapter about Pagination Tests if you are looking for testing 375 layout in pagination mode. 376 377 e. ``<url>`` is either a relative file path or an absolute URL for the 378 test page 379 380 f. ``<url_ref>`` is either a relative file path or an absolute URL for 381 the reference page 382 383 The only difference between ``<url>`` and ``<url_ref>`` is that results of 384 the test are reported using ``<url>`` only. 385 386 Specification of a url prefix 387 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 388 389 ``url-prefix <string>`` 390 391 ``<string>`` will be prepended to relative ``<url>`` and ``<url_ref>`` for 392 all following test items in the manifest. 393 394 ``<string>`` will not be prepended to the relative path when including 395 another manifest, e.g. ``include <relative_path>.`` 396 397 ``<string>`` will not be prepended to any ``<url>`` or ``<url_ref>`` matching 398 the pattern ``/^\w+:/``. This will prevent the prefix from being applied to 399 any absolute url containing a protocol such as ``data:``, ``about:``, or 400 ``http:``. 401 402 While the typical use of url-prefix is expected to be as the first line of 403 a manifest, it is legal to use it anywhere in a manifest. Subsequent uses 404 of url-prefix overwrite any existing values. 405 406 Specification of defaults 407 ~~~~~~~~~~~~~~~~~~~~~~~~~ 408 409 ``defaults [<failure-type> | <preference> | <http>]`` 410 411 where ``<failure-type>``, ``<preference>``, and ``<http>`` are defined above. 412 413 The default settings will be used for all following test items in the manifest. 414 Any test specific settings will override the defaults, just as later items 415 within a line override earlier ones. 416 417 A defaults line with no settings will reset the defaults to be empty. 418 419 As with url-prefix, defaults will often be used at the start of a manifest file 420 so that it applies to all test items, but it is legal for defaults to appear 421 anywhere in the manifest. A subsequent defaults will reset any previous default 422 settings and overwrite them with the new settings. 423 424 It is invalid to set non-skip defaults before an include line, just as it is 425 invalid to specify non-skip settings directly on the include line itself. If a 426 manifest needs to use both defaults and include, the include should appear 427 before the defaults. If it's important to specify the include later on in the 428 manifest, a blank defaults line directly preceding the include can be used to 429 reset the defaults. 430 431 This test manifest format could be used by other harnesses, such as ones 432 that do not depend on XUL, or even ones testing other layout engines. 433 434 Running Tests 435 ------------- 436 437 To run a given reftest use something like the following :: 438 439 ./mach reftest <path to individual test or directory> 440 441 As an example, if we wanted to run the reftests relevant to async scrolling, 442 run something like the following:: 443 444 ./mach reftest ./layout/reftest/async-scrolling &> reftest.out 445 446 and then search/grep reftest.out for "UNEXPECTED". 447 448 There are two scripts provided to convert the reftest.out to HTML. 449 clean-reftest-output.pl converts reftest.out into simple HTML, stripping 450 lines from the log that aren't relevant. reftest-to-html.pl converts 451 the output into html that makes it easier to visually check for 452 failures. See :ref:`debugging failures <debugging-failures>` for 453 more details on making sense of reftest results. 454 455 Testable Areas 456 -------------- 457 458 This framework is capable of testing many areas of the layout engine. 459 It is particularly well-suited to testing dynamic change handling (by 460 comparison to the static end-result as a reference) and incremental 461 layout (comparison of a script-interrupted layout to one that was not). 462 However, it is also possible to write tests for many other things that 463 can be described in terms of equivalence, for example: 464 465 * CSS cascading could be tested by comparing the result of a 466 complicated set of style rules that makes a word green to <span 467 style="color:green">word</span>. 468 469 * <canvas> compositing operators could be tested by comparing the 470 result of drawing using canvas to a block-level element with the 471 desired color as a CSS background-color. 472 473 * CSS counters could be tested by comparing the text output by counters 474 with a page containing the text written out 475 476 * complex margin collapsing could be tested by comparing the complex 477 case to a case where the margin is written out, or where the margin 478 space is created by an element with 'height' and transparent 479 background 480 481 When it is not possible to test by equivalence, it may be possible to 482 test by non-equivalence. For example, testing justification in cases 483 with more than two words, or more than three different words, is 484 difficult. However, it is simple to test that justified text is at 485 least displayed differently from left-, center-, or right-aligned text. 486 487 Writing Tests 488 ------------- 489 490 When writing tests for this framework, it is important for the test to 491 depend only on behaviors that are known to be correct and permanent. 492 For example, tests should not depend on default font sizes, default 493 margins of the body element, the default style sheet used for HTML, the 494 default appearance of form controls, or anything else that can be 495 avoided. 496 497 In general, the best way to achieve this is to make the test and the 498 reference identical in as many aspects as possible. For example: 499 500 Good test markup: :: 501 502 <div style="color:green"><table><tr><td><span>green 503 </span></td></tr></table></div> 504 505 Good reference markup: :: 506 507 <div><table><tr><td><span style="color:green">green 508 </span></td></tr></table></div> 509 510 BAD reference markup: :: 511 512 <!-- 3px matches the default cellspacing and cellpadding --> 513 <div style="color:green; padding: 3px">green 514 </div> 515 516 BAD test markup: :: 517 518 <!-- span doesn't change the positioning, so skip it --> 519 <div style="color:green"><table><tr><td>green 520 </td></tr></table></div> 521 522 Asynchronous Tests: class="reftest-wait" 523 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 524 525 Normally reftest takes a snapshot of the given markup's rendering right 526 after the load event fires for content. If your test needs to postpone 527 the moment the snapshot is taken, it should make sure a class 528 'reftest-wait' is on the root element by the moment the load event 529 fires. The easiest way to do this is to put it in the markup, e.g.: :: 530 531 <html class="reftest-wait"> 532 533 When your test is ready, you should remove this class from the root 534 element, for example using this code: :: 535 536 document.documentElement.className = ""; 537 538 539 Note that in layout tests it is often enough to trigger layout using :: 540 541 document.body.offsetWidth // HTML example 542 543 When possible, you should use this technique instead of making your 544 test async. 545 546 Invalidation Tests: MozReftestInvalidate Event 547 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 548 549 When a test (or reference) uses reftest-wait, reftest tracks invalidation 550 via MozAfterPaint and updates the test image in the same way that 551 a regular window would be repainted. Therefore it is possible to test 552 invalidation-related bugs by setting up initial content and then 553 dynamically modifying it before removing reftest-wait. However, it is 554 important to get the timing of these dynamic modifications right so that 555 the test doesn't accidentally pass because a full repaint of the window 556 was already pending. To help with this, reftest fires one MozReftestInvalidate 557 event at the document root element for a reftest-wait test when it is safe to 558 make changes that should test invalidation. The event bubbles up to the 559 document and window so you can set listeners there too. For example, :: 560 561 function doTest() { 562 document.body.style.border = ""; 563 document.documentElement.removeAttribute('class'); 564 } 565 document.addEventListener("MozReftestInvalidate", doTest, false); 566 567 Painting Tests: class="reftest-no-paint" 568 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 569 570 If an element shouldn't be painted, set the class "reftest-no-paint" on it 571 when doing an invalidation test. Causing a repaint in your 572 MozReftestInvalidate handler (for example, by changing the body's background 573 colour) will accurately test whether the element is painted. 574 575 Display List Tests: class="reftest-[no-]display-list" 576 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 577 578 These classes work similarly to reftest-no-paint, but check if the element has 579 display items created or not. These classes are useful for checking the behaviour 580 of retained display lists, where the display list is incrementally updated by 581 changes, rather than thrown out and rebuilt from scratch. 582 583 Opaque Layer Tests: class="reftest-opaque-layer" 584 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 585 586 If an element should be assigned to a PaintedLayer that's opaque, set the class 587 "reftest-opaque-layer" on it. This checks whether the layer is opaque during 588 the last paint of the test, and it works whether your test is an invalidation 589 test or not. In order to pass the test, the element has to have a primary 590 frame, and that frame's display items must all be assigned to a single painted 591 layer and no other layers, so it can't be used on elements that create stacking 592 contexts (active or inactive). 593 594 Layerization Tests: reftest-assigned-layer="layer-name" 595 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 596 597 If two elements should be assigned to the same PaintedLayer, choose any string 598 value as the layer name and set the attribute reftest-assigned-layer="yourname" 599 on both elements. Reftest will check whether all elements with the same 600 reftest-assigned-layer value share the same layer. It will also test whether 601 elements with different reftest-assigned-layer values are assigned to different 602 layers. 603 The same restrictions as with class="reftest-opaque-layer" apply: All elements 604 must have a primary frame, and that frame's display items must all be assigned 605 to the same PaintedLayer and no other layers. If these requirements are not 606 met, the test will fail. 607 608 Snapshot The Whole Window: class="reftest-snapshot-all" 609 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 610 611 In a reftest-wait test, to disable testing of invalidation and force the final 612 snapshot to be taken of the whole window, set the "reftest-snapshot-all" 613 class on the root element. 614 615 Avoid triggering flushes: class="reftest-no-flush" 616 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 617 618 The reftest harness normally triggers flushes by calling 619 getBoundingClientRect on the root element. If the root element of the 620 test has class="reftest-no-flush", it doesn't do this. 621 622 This is useful for testing animations on the compositor thread, since 623 the flushing will cause a main thread style update. 624 625 Zoom Tests: reftest-zoom="<float>" 626 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 627 628 When the root element of a test has a "reftest-zoom" attribute, that zoom 629 factor is applied when rendering the test. The corresponds to the desktop "full 630 zoom" style zoom. The reftest document will be 800 device pixels wide by 1000 631 device pixels high. The reftest harness assumes that the CSS pixel dimensions 632 are 800/zoom and 1000/zoom. For best results therefore, choose zoom factors 633 that do not require rounding when we calculate the number of appunits per 634 device pixel; i.e. the zoom factor should divide 60, so 60/zoom is an integer. 635 636 Setting Scrollport Size: reftest-scrollport-w/h="<int>" 637 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 638 639 If either of the "reftest-scrollport-w" and "reftest-scrollport-h" attributes on 640 the root element are non-zero, sets the scroll-position-clamping scroll-port 641 size to the given size in CSS pixels. This does not affect the size of the 642 snapshot that is taken. 643 644 Setting Resolution: reftest-resolution="<float>" 645 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 646 647 If the root element of a test has a "reftest-resolution" attribute, the page 648 is rendered with the specified resolution (as if the user pinch-zoomed in 649 to that scale). Note that the difference between reftest-async-zoom and 650 reftest-resolution is that reftest-async-zoom only applies the scale in 651 the compositor, while reftest-resolution causes the page to be paint at that 652 resolution. This attribute can be used together with initial-scale in meta 653 viewport tag, in such cases initial-scale is applied first then 654 reftest-resolution changes the scale. 655 656 This attributes requires the pref apz.allow_zooming=true to have an effect. 657 658 Setting Async Scroll Mode: reftest-async-scroll attribute 659 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 660 661 If the "reftest-async-scroll" attribute is set on the root element, we try to 662 enable async scrolling and zooming for the document. This is unsupported in many 663 configurations. 664 665 Setting Displayport Dimensions: reftest-displayport-x/y/w/h="<int>" 666 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 667 668 If any of the "reftest-displayport-x", "reftest-displayport-y", 669 "reftest-displayport-w" and "reftest-displayport-h" attributes on the root 670 element are nonzero, sets the displayport dimensions to the given bounds in 671 CSS pixels. This does not affect the size of the snapshot that is taken. 672 673 When the "reftest-async-scroll" attribute is set on the root element, *all* 674 elements in the document are checked for "reftest-displayport-x/y/w/h" and have 675 displayports set on them when those attributes are present. 676 677 Testing Async Scrolling: reftest-async-scroll-x/y="<int>" 678 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 679 680 When the "reftest-async-scroll" attribute is set on the root element, for any 681 element where either the "reftest-async-scroll-x" or "reftest-async-scroll-y 682 attributes are nonzero, at the end of the test take the snapshot with the given 683 offset (in CSS pixels) added to the async scroll offset. 684 685 Testing Async Zooming: reftest-async-zoom="<float>" 686 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 687 688 When the "reftest-async-zoom" attribute is present on the root element then at 689 the end of the test take the snapshot with the given async zoom on top of any 690 existing zoom. Content is not re-rendered at the new zoom level. This 691 corresponds to the mobile style "pinch zoom" style of zoom. This is unsupported 692 in many configurations, and any tests using this will probably want to have 693 pref(apz.allow_zooming,true) on them. 694 695 Pagination Tests: class="reftest-paged" 696 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 697 698 Now that the patch for bug 374050 has landed 699 (https://bugzilla.mozilla.org/show_bug.cgi?id=374050), it is possible to 700 create reftests that run in a paginated context. 701 702 The page size used is 5in wide and 3in tall (with the default half-inch 703 margins). This is to allow tests to have less text and to make the 704 entire test fit on the screen. 705 706 There is a layout/reftests/printing directory for pagination reftests; however, 707 there is nothing special about this directory. You can put pagination reftests 708 anywhere that is appropriate. 709 710 The suggested first lines for any pagination test is: :: 711 712 <!DOCTYPE html><html class="reftest-paged"> 713 <style>html{font-size:12pt}</style> 714 715 The reftest-paged class on the root element triggers the reftest to 716 switch into page mode. Fixing the font size is suggested, although not 717 required, because the pages are a fixed size in inches. The switch to page mode 718 happens on load if the reftest-wait class is not present; otherwise it happens 719 immediately after firing the MozReftestInvalidate event. 720 721 The underlying layout support for this mode isn't really complete; it 722 doesn't use exactly the same codepath as real print preview/print. In 723 particular, scripting and frames are likely to cause problems; it is untested, 724 though. That said, it should be sufficient for testing layout issues related 725 to pagination. 726 727 Process Crash Tests: class="reftest-expect-process-crash" 728 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 729 730 If you are running a test that causes a process 731 under Electrolysis to crash as part of a reftest, this will cause process 732 crash minidump files to be left in the profile directory. The test 733 infrastructure that runs the reftests will notice these minidump files and 734 dump out information from them, and these additional error messages in the logs 735 can end up erroneously being associated with other errors from the reftest run. 736 They are also confusing, since the appearance of "PROCESS-CRASH" messages in 737 the test run output can seem like a real problem, when in fact it is the 738 expected behavior. 739 740 To indicate to the reftest framework that a test is expecting a 741 process to crash, have the test include "reftest-expect-process-crash" as 742 one of the root element's classes by the time the test has finished. This will 743 cause any minidump files that are generated while running the test to be removed 744 and they won't cause any error messages in the test run output. 745 746 Skip Forcing A Content Process Layer-Tree Update: reftest-no-sync-layers attribute 747 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 748 749 Normally when an multi-process reftest test ends, we force the content process 750 to push a layer-tree update to the compositor before taking the snapshot. 751 Setting the "reftest-no-sync-layers" attribute on the root element skips this 752 step, enabling testing that layer-tree updates are being correctly generated. 753 However the test must manually wait for a MozAfterPaint event before ending. 754 755 SpecialPowers 756 ------------- 757 758 Some tests may require synthesized user input events or other functions that 759 normally cannot be run from a typical script. Layout reftests have access to 760 `SpecialPowers` for such cases. 761 762 Test authors have ability to access the privilegd `nsIDOMWindowUtils` interface 763 using `SpecialPowers.getDOMWindowUtils(window)`. The interface contains many 764 interesting abilities, including event synthesization. 765 766 Debugging Failures 767 ------------------ 768 769 The Reftest Analyzer has been created to make debugging reftests a bit easier. 770 If a reftest is failing, upload the log to the Reftest Analyzer to view the 771 differences between the expected result and the actual outcome of the reftest. 772 The Reftest Analyzer can be found at the following url: 773 774 https://hg.mozilla.org/mozilla-central/raw-file/tip/layout/tools/reftest/reftest-analyzer.xhtml