Improve robustness of wpt animation interpolation tests.

This patch fixes the problem where subtle changes to numerical values in matrix interpolation cause mismatches in the expected results.

To address the issue:
* Styles are checked to see if they are of the form matrix(...) or matrix3d(...).
* If the style is a matrix, then arguments are rounded and the style is reconstructed.

Bug: 797472

Change-Id: I44d6e0ed13e24dc2ecfeeacbcd4809d6dcdb6465
Reviewed-on: https://chromium-review.googlesource.com/c/1337640
Reviewed-by: Xida Chen <xidachen@chromium.org>
Commit-Queue: Kevin Ellis <kevers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608466}
diff --git a/css/css-transforms/animation/resources/interpolation-testcommon.js b/css/css-transforms/animation/resources/interpolation-testcommon.js
index 3791b0a..73ce9ce 100644
--- a/css/css-transforms/animation/resources/interpolation-testcommon.js
+++ b/css/css-transforms/animation/resources/interpolation-testcommon.js
@@ -11,6 +11,28 @@
     return 'cubic-bezier(0, ' + y + ', 1, ' + y + ')';
   }
 
+  function RoundMatrix(style) {
+    var matrixMatch = style.match(/^(matrix(3d)?)\(.+\)$/);
+    if (!!matrixMatch) {
+      var matrixType = matrixMatch[1];
+      var matrixArgs = style.substr(matrixType.length);
+      var extractmatrix = function(matrixStr) {
+        var list = [];
+        var regex = /[+\-]?[0-9]+[.]?[0-9]*(e[+/-][0-9]+)?/g;
+        var match = undefined;
+        do {
+          match = regex.exec(matrixStr);
+          if (match) {
+            list.push(parseFloat(parseFloat(match[0]).toFixed(6)));
+          }
+        } while (match);
+        return list;
+      }
+      return matrixType + '(' + extractmatrix(matrixArgs).join(', ') + ')';
+    }
+    return style;
+  }
+
   test(function(){
     assert_true(CSS.supports(settings.property, settings.from), 'Value "' + settings.from + '" is supported by ' + settings.property);
     assert_true(CSS.supports(settings.property, settings.to), 'Value "' + settings.to + '" is supported by ' + settings.property);
@@ -49,7 +71,9 @@
       document.body.appendChild(reference);
       reference.style = '';
 
-      assert_equals(getComputedStyle(target)[settings.property], getComputedStyle(reference)[settings.property]);
+      var observed = RoundMatrix(getComputedStyle(target)[settings.property]);
+      var expected = RoundMatrix(getComputedStyle(reference)[settings.property]);
+      assert_equals(observed, expected);
     }, message_prefix + 'Animation between "' + settings.from + '" and "' + settings.to + '" at progress ' + progress);
   }
 }