2 // compare matrix() strings with some slop on really small values
4 function floatingPointEqual(a, b)
7 return (Math.abs(a - b) < kEpsilon);
10 function compareMatrices(a, b)
12 if (a == "none" && b == "none")
15 var matrixRegex = /matrix(?:3d)?\((.+)\)/;
17 var resultA = matrixRegex.exec(a);
18 var resultB = matrixRegex.exec(b);
19 if (!resultA || !resultB)
22 var aValues = resultA[1];
23 var bValues = resultB[1];
25 var aComps = aValues.split(',');
26 var bComps = bValues.split(',');
28 if (aComps.length != bComps.length)
31 for (var i = 0; i < aComps.length; ++i)
33 if (!floatingPointEqual(aComps[i], bComps[i]))
40 function testTransforms()
42 var testBox = document.getElementById('test-box');
43 var resultsBox = document.getElementById('results');
45 gTests.forEach(function(curTest) {
46 testBox.style.webkitTransform = 'none'; // reset the transform just in case the next step fails
47 testBox.style.webkitTransform = curTest.transform;
48 var computedTransform = window.getComputedStyle(testBox).webkitTransform;
50 var success = compareMatrices(computedTransform, curTest.result);
53 result = 'transform "<code>' + curTest.transform + '</code>" expected "<code>' + curTest.result + '</code>" : PASS';
55 result = 'transform "<code>' + curTest.transform + '</code>" expected "<code>' + curTest.result + '</code>", got "<code>' + computedTransform + '</code>" : FAIL';
56 resultsBox.innerHTML += result + '<br>';