Bug 1301305 - Move propertyToIDL to testcommon.js; r?hiro
We would like to use this method in the next patch.
MozReview-Commit-ID: CSdwlVInyds
--- a/dom/animation/test/mozilla/file_discrete-animations.html
+++ b/dom/animation/test/mozilla/file_discrete-animations.html
@@ -138,28 +138,16 @@ for (let property in gMozillaSpecificPro
testAnimationSamples(animation, idlName,
[{ time: 0, expected: from.toLowerCase() },
{ time: 940, expected: from.toLowerCase() },
{ time: 960, expected: to.toLowerCase() }]);
}, property + " should animate between '"
+ from + "' and '" + to + "' with keyframe easing");
}
-function propertyToIDL(property) {
- var prefixMatch = property.match(/^-(\w+)-/);
- if (prefixMatch) {
- var prefix = prefixMatch[1] === "moz" ? "Moz" : prefixMatch[1];
- property = prefix + property.substring(prefixMatch[0].length - 1);
- }
- // https://drafts.csswg.org/cssom/#css-property-to-idl-attribute
- return property.replace(/-([a-z])/gi, function(str, group) {
- return group.toUpperCase();
- });
-}
-
function testAnimationSamples(animation, idlName, testSamples) {
const target = animation.effect.target;
testSamples.forEach(testSample => {
animation.currentTime = testSample.time;
assert_equals(getComputedStyle(target)[idlName], testSample.expected,
"The value should be " + testSample.expected +
" at " + testSample.time + "ms");
});
--- a/dom/animation/test/testcommon.js
+++ b/dom/animation/test/testcommon.js
@@ -133,16 +133,32 @@ function addStyle(t, rules) {
if (t && typeof t.add_cleanup === 'function') {
t.add_cleanup(function() {
extraStyle.remove();
});
}
}
/**
+ * Takes a CSS property (e.g. margin-left) and returns the equivalent IDL
+ * name (e.g. marginLeft).
+ */
+function propertyToIDL(property) {
+ var prefixMatch = property.match(/^-(\w+)-/);
+ if (prefixMatch) {
+ var prefix = prefixMatch[1] === 'moz' ? 'Moz' : prefixMatch[1];
+ property = prefix + property.substring(prefixMatch[0].length - 1);
+ }
+ // https://drafts.csswg.org/cssom/#css-property-to-idl-attribute
+ return property.replace(/-([a-z])/gi, function(str, group) {
+ return group.toUpperCase();
+ });
+}
+
+/**
* Promise wrapper for requestAnimationFrame.
*/
function waitForFrame() {
return new Promise(function(resolve, reject) {
window.requestAnimationFrame(resolve);
});
}
@@ -209,17 +225,17 @@ if (opener) {
opener.add_completion_callback(function() {
self.close();
});
opener.done();
}
}
/**
- * Return a new MutaionObserver which started observing |target| element
+ * Return a new MutationObserver which started observing |target| element
* with { animations: true, subtree: |subtree| } option.
* NOTE: This observer should be used only with takeRecords(). If any of
* MutationRecords are observed in the callback of the MutationObserver,
* it will raise an assertion.
*/
function setupSynchronousObserver(t, target, subtree) {
var observer = new MutationObserver(records => {
assert_unreached("Any MutationRecords should not be observed in this " +