Oops. Forgot this file in previous commit.
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Sep 2008 21:22:25 +0000 (21:22 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Sep 2008 21:22:25 +0000 (21:22 +0000)
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@36455 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/transforms/2d/resources/transform-test-utils.js [new file with mode: 0644]

diff --git a/LayoutTests/transforms/2d/resources/transform-test-utils.js b/LayoutTests/transforms/2d/resources/transform-test-utils.js
new file mode 100644 (file)
index 0000000..ae07b0e
--- /dev/null
@@ -0,0 +1,57 @@
+
+// compare matrix() strings with some slop on really small values
+
+function floatingPointEqual(a, b)
+{
+  const kEpsilon = 1e-6;
+  return (Math.abs(a - b) < kEpsilon);
+}
+
+function compareMatrices(a, b)
+{
+  if (a == "none" && b == "none")
+    return true;
+  else {
+    var matrixRegex = /matrix\((.+)\)/;
+
+    if (!matrixRegex.exec(a) || !matrixRegex.exec(b))
+      return false;
+  
+    var aValues = matrixRegex.exec(a)[1];
+    var bValues = matrixRegex.exec(b)[1];
+  
+    var aComps = aValues.split(',');
+    var bComps = bValues.split(',');
+
+    if (aComps.length != bComps.length)
+      return false;
+
+    for (var i = 0; i < aComps.length; ++i)
+    {
+      if (!floatingPointEqual(aComps[i], bComps[i]))
+        return false;
+    }
+  }
+
+  return true;
+}
+
+function testTransforms()
+{
+  var testBox = document.getElementById('test-box');
+  var resultsBox = document.getElementById('results');
+  
+  gTests.forEach(function(curTest) {
+    testBox.style.webkitTransform = 'none'; // reset the transform just in case the next step fails
+    testBox.style.webkitTransform = curTest.transform;
+    var computedTransform = window.getComputedStyle(testBox).webkitTransform;
+
+    var success = compareMatrices(computedTransform, curTest.result);
+    var result;
+    if (success)
+      result = 'transform "<code>' + curTest.transform + '</code>" expected "<code>' + curTest.result + '</code>" : PASS';
+    else
+      result = 'transform "<code>' + curTest.transform + '</code>" expected "<code>' + curTest.result + '</code>", got "<code>' + computedTransform + '</code>" : FAIL';
+    resultsBox.innerHTML += result + '<br>';
+  });
+}