Complete all steps before proceeding
Press down for additional steps
- Two files: Test file + Reference file
- Test file uses the feature you're testing
- Reference file is an exact visual match without using the feature you're testing
- Self-describing (works both manually and with automation)
- Cross-browser & cross-platform
Basic test for the transform property described in the CSS3 Transforms spec using the translate()
function
Spec Links:
http://www.w3.org/TR/css3-transforms/#transform-property
http://www.w3.org/TR/css3-transforms/#two-d-transform-functions
Press down-arrow for Windows instructions
Update your local CSSWG test repository
Complete this step unless you just cloned the repository during setup
From a terminal window, type the following:
$ cd [path to repo]/test
$ hg pull -u
$ ls -lR contributors/ttwf/samples
Note: These files can also be downloaded from here:
ttwf-reftest-tutorial-starter.zip
Press up-arrow for OSX instructions
Update your local CSSWG test repository
Complete this step unless you just cloned the repository during setup
From a command prompt, type the following:
> cd [path to repo]\test
> hg pull -u
> dir contributors\ttwf\samples
Note: These files can also be downloaded from here:
ttwf-reftest-tutorial-starter.zip
Press down-arrow for Windows instructions
Create a directory for your new test
$ cd [path to repo]/test/contributors/ttwf/
$ mkdir -p yourName/incoming
$ cd yourName/incoming
Press up-arrow for OSX instructions
Create a directory for your new test
> cd [path to repo]\test\contributors\ttwf
> mkdir yourName\incoming
> cd yourName\incoming
Press down-arrow for Windows instructions
Copy the starter files to your incoming directory
From your incoming directory created in previous step
$ cp -R ../../samples/ttwf-reftest-tutorial-starter/* .
Press up-arrow for OSX instructions
Copy the starter files to your incoming directory
From your incoming directory created in previous step
> xcopy /e ..\..\samples\ttwf-reftest-tutorial-starter .
Open the ttwf-reftest-tutorial-starter-001.html file in a editor
Add the test metadata
Title & Author
<!DOCTYPE html>
<html>
<head>
<title>CSS Transforms Test: transform property with translate function</title>
<link rel="author" title="Your Name" href="mailto:youremail@address.com">
. . .
Note: Each metadata element is described in detail on the CSSWG Wiki
http://wiki.csswg.org/test/format#template-details
Add the test metadata
Path to reference file
<!DOCTYPE html>
<html>
<head>
. . .
<link rel="match" href="reference/ttwf-reftest-tutorial-starter-ref.html">
. . .
Note: Each metadata element is described in detail on the CSSWG Wiki
http://wiki.csswg.org/test/format#template-details
Add the test metadata
Spec links
<!DOCTYPE html>
<html>
<head>
. . .
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#transform-property">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#two-d-transform-functions">
. . .
Note: Each metadata element is described in detail on the CSSWG Wiki
http://wiki.csswg.org/test/format#template-details
Add the transform property to the test element
<style type="text/css">
.greenSquare {
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
transform: translate(100px,100px);
}
. . .
</style>
Create an element that is visible only upon failure
<style type="text/css">
. . .
.redSquare {
position: absolute;
width: 98px;
height: 98px;
top: 101px;
left: 101px;
}
</style>
Add green fill color to denote passing condition
.greenSquare {
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
transform: translate(100px,100px);
background: green;
}
Add the red fill color to denote failing condition
.redSquare {
position: absolute;
width: 98px;
height: 98px;
top: 101px;
left: 101px;
background: red;
}
</style>
Add a statement to the test page to make this a self-describing test
<body>
<p>The test passes if there is a green square and no red.</p>
. . .
</body>
Open the reference/ttwf-reftest-tutorial-starter-ref.html file in an editor
Add the reference metadata
Title & Author
<!DOCTYPE html>
<html>
<head>
<title>CSS Transforms Reference file</title>
<link rel="author" title="Your Name" href="mailto:youremail@address.com">
. . .
Position and fill the reference element so it matches the test file exactly in a passing condition
<style type="text/css">
.greenSquare {
position: absolute;
width: 100px;
height: 100px;
top: 100px;
left: 100px;
background: green;
}
</style>
Add the self-describing statement here, too
<body>
<p>The test passes if there is a green square and no red.</p>
. . .
</body>
Examine your test and reference files in the browser and confirm they are identical
Press the down-arrow for a vendor-prefixed version of this tutorial
.greenSquare {
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100px;
-webkit-transform: translate(100px,100px);
-moz-transform: translate(100px,100px);
-ms-transform: translate(100px,100px);
-o-transform: translate(100px,100px);
background: green;
}
Press the down-arrow for an alternative to adding vendor prefixes manually
We recommend a script to use during test development:
http://leaverou.github.com/prefixfree
The prefixfree.jsapi.js extension can be used for unprefixed JS APIs tests:
https://github.com/LeaVerou/prefixfree/tree/gh-pages/plugins
During test development, include the scripts is your tests like this:
<-- Remember to remove before pushing to W3C test suite -->
<script src="prefixfree.js"></script>
<script src="plugins/prefixfree.jsapi.js"></script>
Press the down-arrow for Windows instructions
Add your new test & reference file to the repository
$ cd [path to repo]/test/contributors/ttwf/yourName/incoming
$ hg add ttwf-reftest-tutorial-001.html
$ hg add reference
$ hg commit -m "TTWF reftest tutorial"
$ hg push
Note: If you receive the following error:
abort: push creates new remote head ...
Your local repository is out of sync with the test repository
Do the following to resolve the issue:
Only complete these steps if you received the error message above
$ hg pull
$ hg merge
$ hg commit -m "Merge"
$ hg push
Press the up-arrow for OSX instructions
Add your new test & reference file to the repository
> cd [path to repo]\test\contributors\ttwf\yourName\incoming
> hg add ttwf-reftest-tutorial-001.html
> hg add reference
> hg commit -m "TTWF reftest tutorial"
> hg push
Note: If you receive the following error:
abort: push creates new remote head ...
Your local repository is out of sync with the test repository
Do the following to resolve the issue:
Only complete these steps if you received the error message above
> hg pull
> hg merge
> hg commit -m "Merge"
> hg push
Press down-arrow for Windows instructions
Incorporate feedback & move test to the submitted folder
$ cd [path to repo]/test/contributors/ttwf/yourName
$ hg pull -u
$ hg merge
$ hg commit -m "merging"
$ hg mv incoming/ttwf-reftest-tutorial-001.html submitted/ttwf-reftest-tutorial-001.html
$ hg mv incoming/reference/ttwf-reftest-tutorial-ref.html submitted/reference/ttwf-reftest-tutorial-ref.html
$ hg commit -m "moved the TTWF reftest tutorial to the submitted folder"
$ hg push
Press down-arrow for OSX instructions
Incorporate feedback & move test to the submitted folder
> cd [path to repo]\test\contributors\ttwf\yourName
> hg pull -u
> hg merge
> hg commit -m "merging"
> hg mv incoming\ttwf-reftest-tutorial-001.html submitted\ttwf-reftest-tutorial-001.html
> hg mv incoming\reference\ttwf-reftest-tutorial-ref.html submitted\reference\ttwf-reftest-tutorial-ref.html
> hg commit -m "moved the TTWF reftest tutorial to the submitted folder"
> hg push
testharness.js and testharnessreport.js
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
Press down for more
id="log"
should exist in test file
test(test_function, name, properties)
async_test()
is also defined by testharness.js for asychronous testingtest()
test()
Press down for more
test(test_function, name, properties)
test_function
must be an object, not a function calltest_function
should be testharness assert method
test(function() { assert_true(true) }, name, properties)
test(test_function, name, properties)
name
is a string that identifies the testname
should be short, unique, and must not changename
will be displayed in the test results table
test(function() { assert_true(true) }, "test_name", properties)
test(test_function, name, properties)
properties
is an object that overrides defaultsproperties
is an optional argumenttimeout
and metadata
test(function() { assert_true(true) }, "test_name",
{timeout:1000,
help: 'http://www.w3.org/TR/spec#section',
author: ['Bill Gates <bgates@msn.com>', 'Steve Jobs http://apple.com/sjobs'],
assert: 'This should always be true.'})
For detail on how to define per-test metadata, see the CSSWG Script Test Wiki Page
test_function
for test()
description
argument that is only output if the assertion fails
test()
Press down for more
assert_equals(actual, expected, description)
actual
: The actual value from the functionality being testedexpected
: The expected valuedescription
(optional): Output only if the assertion fails
assert_equals(getActualData("myElement"), 100, "Expected value for myElement is 100")
Basic test for the transform property described in the CSS3 Transforms spec using the translate()
function
Similar to Reftest example, this time testing API instead of rendering
Spec Links:
http://www.w3.org/TR/css3-transforms/#transform-property
http://www.w3.org/TR/css3-transforms/#two-d-transform-functions
Press down for more
A JavaScript starter file was copied during Setup
Open the ttwf-js-tutorial-001.html file in an editor
<!DOCTYPE html>
<html>
<head>
<title>CSS Transforms API Test: transform translate</title>
<link rel="author" title="Your Name" href="mailto:youremail@address.com">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#transform-property">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#two-d-transform-functions">
<meta name="assert" content="The transform should be translate(100px,100px)">
</head>
<body>
</body>
</html>
Update Metadata
author
metadataflags
metadata
flags
document a test's prerequisitesflags
is available on the CSSWG Wiki Test Format page
<title>CSS Transforms API Test: transform translate</title>
<link rel="author" title="Jim Tester" href="mailto:jimmyt@yahoo.com">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#transform-property">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#two-d-transform-functions">
<meta name="flags" content="dom">
<meta name="assert" content="The transform should be translate(100px,100px)">
Import the W3C JavaScript Test Harness files
Add the following lines to the starter file above the style
block
...
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
...
Note: During development, the path to the resources
directory should match the directory's location on the local machine
The path to these scripts must point to the /resources
directory before pushing to the CSSWG Test repository
The head
block of your starter file should appear as follows
With your actual name and email address for the author
metadata
<!DOCTYPE html>
<html>
<head>
<title>CSS Transforms API Test: transform translate</title>
<link rel="author" title="Your Name" href="mailto:youremail@address.com">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#transform-property">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#two-d-transform-functions">
<meta name="flags" content="dom">
<meta name="assert" content="The transform should be translate(100px,100px)">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
...
Add a div
to be used as the test element to the <body>
...
<body>
<div id="myDiv"></div>
<body>
...
The transform
will be applied to this element
Add a <div>
with id="log"
for test results
...
<body>
<div id="myDiv"></div>
<div id="log"></div>
<body>
...
testharness.js will add an HTML table that contains test results to this element
Create a <script>
block that will contain the JavaScript
...
<body>
<div id="myDiv"></div>
<div id="log"></div>
<script>
</script>
<body>
...
Starter file should now appear as follows
<!DOCTYPE html>
<html>
<head>
<title>CSS Transforms API Test: transform translate</title>
<link rel="author" title="Your Name" href="mailto:youremail@address.com">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#transform-property">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#two-d-transform-functions">
<meta name="flags" content="dom">
<meta name="assert" content="The transform should be translate(100px,100px)">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="myDiv"></div>
<div id="log"></div>
<script>
</script>
</body>
</html>
Set the transform
on the test element in JavaScript
...
<body>
<div id="myDiv"></div>
<div id="log"></div>
<script>
// Set the transform
document.getElementById("myDiv").style.transform = "translate(100px,100px)";
</script>
</body>
</html>
Add a call to test()
to your script
block
Use assert_equals
inside test_function
...
<body>
<div id="myDiv"></div>
<div id="log"></div>
<script>
// Set the transform
document.getElementById("myDiv").style.transform = "translate(100px,100px)";
// Verify that the transform was set as expected
test(function() {assert_equals( //test arg1: test_function
document.getElementById("myDiv").style.getPropertyCSSValue("transform").cssText, //assert_equals arg 1: actual
"translate(100px,100px)", //assert_equals arg 2: expected
"transform should be translate(100px,100px)")}, //assert_equals arg 3: description
"Transform_Translate_100px_100px"); //test arg2: name
</script>
</body>
</html>
Comments on test arguments added for clarity, can be omitted
<!DOCTYPE html>
<html>
<head>
<title>CSS Transforms API Test: transform translate</title>
<link rel="author" title="Your Name" href="mailto:youremail@address.com">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#transform-property">
<link rel="help" href="http://www.w3.org/TR/css3-transforms/#two-d-transform-functions">
<meta name="flags" content="dom">
<meta name="assert" content="The transform should be translate(100px,100px)">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<div id="myDiv"></div>
<div id="log"></div>
<script>
document.getElementById("myDiv").style.transform = "translate(100px,100px)";
test(function() {assert_equals(
document.getElementById("myDiv").style.getPropertyCSSValue("transform").cssText,
"translate(100px,100px)", "transform should be translate(100px,100px)")},
"Transform_Translate_100px_100px");
</script>
</body>
</html>
Press the down-arrow for Windows instructions
Add your new test file to the repository
$ cd [path to repo]/test/contributors/ttwf/yourName/incoming
$ hg add ttwf-js-tutorial-001.html
$ hg commit -m "TTWF JavaScript tutorial"
$ hg push
If you receive the error:
abort: push creates new remote head ...
Your local repository is out of sync with the test repository. To resolve:
$ hg pull
$ hg merge
$ hg commit -m "Merge"
$ hg push
Press the up-arrow for OSX instructions
Add your new test file to the repository
> cd [path to repo]\test\contributors\ttwf\yourName\incoming
> hg add ttwf-js-tutorial-001.html
> hg commit -m "TTWF JavaScript tutorial"
> hg push
If you receive the error:
abort: push creates new remote head ...
Your local repository is out of sync with the test repository. To resolve:
> hg pull
> hg merge
> hg commit -m "Merge"
> hg push
Press down-arrow for Windows instructions
Incorporate feedback & move test to the submitted folder
$ cd [path to repo]/test/contributors/ttwf/yourName
$ hg mv incoming/ttwf-js-tutorial-001.html submitted/ttwf-js-tutorial-001.html
$ hg commit -m "moved the TTWF JavaScript tutorial to the submitted folder"
$ hg push
Press down-arrow for OSX instructions
Incorporate feedback & move test to the submitted folder
> cd [path to repo]\test\contributors\ttwf\yourName
> hg mv incoming\ttwf-js-tutorial-001.html submitted\ttwf-js-tutorial-001.html
> hg commit -m "moved the TTWF JavaScript tutorial to the submitted folder"
> hg push
You have completed both a W3C Reftest and JavaScript Test
Press down for more
Press down for more
abort: push creates new remote head ...