michael@0: /* michael@0: Distributed under both the W3C Test Suite License [1] and the W3C michael@0: 3-clause BSD License [2]. To contribute to a W3C Test Suite, see the michael@0: policies and contribution forms [3]. michael@0: michael@0: [1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license michael@0: [2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license michael@0: [3] http://www.w3.org/2004/10/27-testcases michael@0: */ michael@0: michael@0: /* michael@0: * == Introduction == michael@0: * michael@0: * This file provides a framework for writing testcases. It is intended to michael@0: * provide a convenient API for making common assertions, and to work both michael@0: * for testing synchronous and asynchronous DOM features in a way that michael@0: * promotes clear, robust, tests. michael@0: * michael@0: * == Basic Usage == michael@0: * michael@0: * To use this file, import the script and the testharnessreport script into michael@0: * the test document: michael@0: * michael@0: * michael@0: * michael@0: * Within each file one may define one or more tests. Each test is atomic michael@0: * in the sense that a single test has a single result (pass/fail/timeout). michael@0: * Within each test one may have a number of asserts. The test fails at the michael@0: * first failing assert, and the remainder of the test is (typically) not run. michael@0: * michael@0: * If the file containing the tests is a HTML file with an element of id "log" michael@0: * this will be populated with a table containing the test results after all michael@0: * the tests have run. michael@0: * michael@0: * NOTE: By default tests must be created before the load event fires. For ways michael@0: * to create tests after the load event, see "Determining when all tests michael@0: * are complete", below michael@0: * michael@0: * == Synchronous Tests == michael@0: * michael@0: * To create a synchronous test use the test() function: michael@0: * michael@0: * test(test_function, name, properties) michael@0: * michael@0: * test_function is a function that contains the code to test. For example a michael@0: * trivial passing test would be: michael@0: * michael@0: * test(function() {assert_true(true)}, "assert_true with true") michael@0: * michael@0: * The function passed in is run in the test() call. michael@0: * michael@0: * properties is an object that overrides default test properties. The michael@0: * recognised properties are: michael@0: * timeout - the test timeout in ms michael@0: * michael@0: * e.g. michael@0: * test(test_function, "Sample test", {timeout:1000}) michael@0: * michael@0: * would run test_function with a timeout of 1s. michael@0: * michael@0: * Additionally, test-specific metadata can be passed in the properties. These michael@0: * are used when the individual test has different metadata from that stored michael@0: * in the
. michael@0: * The recognized metadata properties are: michael@0: * michael@0: * help - The url of the part of the specification being tested michael@0: * michael@0: * assert - A human readable description of what the test is attempting michael@0: * to prove michael@0: * michael@0: * author - Name and contact information for the author of the test in the michael@0: * format: "NameResult | Test Name | " michael@0: + (assertions ? "Assertion | " : "") michael@0: + "Message |
---|---|---|---|
' michael@0: + escape_html(status_text[tests[i].status]) michael@0: + " | " michael@0: + escape_html(tests[i].name) michael@0: + " | " michael@0: + (assertions ? escape_html(get_assertion(tests[i])) + " | " : "") michael@0: + escape_html(tests[i].message ? tests[i].message : " ") michael@0: + " |