Changes between Version 24 and Version 25 of Writing Layout Tests for DumpRenderTree
- Timestamp:
- Oct 27, 2011, 4:21:56 PM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Writing Layout Tests for DumpRenderTree
v24 v25 2 2 = Writing good test cases = 3 3 4 ''FIXME: Should have some tips here about how to make a test which is easy to know when it succeeds, things like a 100x100 green block, just printing SUCCESS or FAILURE, and using `dumpAsText()`.'' 5 6 ''FIXME: Should remind folks to write tests that work both in Safari and in DRT. The trick is to test for the existence of a special object like layoutTestController before using it. An example:'' 4 == General tips == 5 6 A good test case should have the following properties: 7 8 * portable 9 * fast 10 * understandable & clear 11 12 === Portable === 13 14 A test should work in DumpRenderTree (of course!) '''and in a WebKit-base browser'''. This means that anything that is specific to DumpRenderTree should not make the test fail if it is not available. 15 16 Bad test: 17 7 18 {{{ 19 <script> 20 layoutTestController.dumpAsText(); 21 </script> 22 }}} 23 24 This will throw an exception in any WebKit-based browser. 25 26 Good test: 27 28 {{{ 29 <script> 8 30 if (window.layoutTestController) 9 31 layoutTestController.dumpAsText() 32 </script> 10 33 }}} 11 34 35 '''Note:''' You get more points if your test works in ANY browsers. 36 37 === fast === 38 39 WebKit has several thousands layout tests that are run in parallel. If your layout test take a lot time, it will slow down everyone's testing. Also DumpRenderTree has a default timer of several seconds before it considers that a test timed out. '''This is true even if you are using waitUntilDone / notifyDone.''' 40 41 Here are some advices to avoid having a slow test case: 42 43 * Do not make unnecessary use of `window.setTimeout` and similar functions which create a lower bound on the time it takes the test to complete. For separating events in time, you can use `eventSender.leapForward`; for waiting on sub-resources, you can use load events (e.g. iframe.onload = doNextStep;) 44 45 * Do not make unnecessary use of external resources: use inline JavaScript and `style` elements instead of `link`s to external stylesheets. You can also use `data:` URLs sometimes for things like frames' `src` attribute. The exceptions are stylesheets and JavaScript libraries that are shared by multiple tests, and cases that test the loading of external resources. (There are various data: url generators on the net.) 46 47 === Understandable & clear === 48 49 ''FIXME: Should have some tips here about how to make a test which is easy to know when it succeeds, things like a 100x100 green block, just printing SUCCESS or FAILURE, and using `dumpAsText()`.'' 50 51 52 One last comment (FIXME: move it to a better section): 53 54 * Tests should not access the Internet. Avoid `http:` URLs in `src` and `href` attributes, in CSS properties and in XMLHttpRequest. Testing WebKit's network layer should be done using the HTTP test facility, to be described below. 55 56 57 == Pixel test tips == 58 12 59 * Do not use fonts other than those bundled with Mac OS X (usually there's no need to specify font families in a test). The only exception to this is the ''Ahem'' font. 13 60 14 * Tests should not access the Internet. Avoid `http:` URLs in `src` and `href` attributes, in CSS properties and in XMLHttpRequest. Testing WebKit's network layer should be done using the HTTP test facility, to be described below. 15 16 * Do not make unnecessary use of `window.setTimeout` and similar functions which create a lower bound on the time it takes the test to complete. For separating events in time, you can use `eventSender.leapForward`; for waiting on sub-resources, you can use load events (e.g. iframe.onload = doNextStep;) 17 18 * Do not make unnecessary use of external resources: use inline JavaScript and `style` elements instead of `link`s to external stylesheets. You can also use `data:` URLs sometimes for things like frames' `src` attribute. The exceptions are stylesheets and JavaScript libraries that are shared by multiple tests, and cases that test the loading of external resources. (There are various data: url generators on the net.) 61 19 62 20 63 = Writing JavaScript-based DOM-only Test Cases =