2014-12-17 23:42:40 +00:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Appends a div to the document body.
|
|
|
|
*
|
|
|
|
* @param t The testharness.js Test object. If provided, this will be used
|
|
|
|
* to register a cleanup callback to remove the div when the test
|
|
|
|
* finishes.
|
2015-03-04 02:49:43 +00:00
|
|
|
*
|
|
|
|
* @param attrs A dictionary object with attribute names and values to set on
|
|
|
|
* the div.
|
2014-12-17 23:42:40 +00:00
|
|
|
*/
|
2015-03-04 02:49:43 +00:00
|
|
|
function addDiv(t, attrs) {
|
2014-12-17 23:42:40 +00:00
|
|
|
var div = document.createElement('div');
|
2015-03-04 02:49:43 +00:00
|
|
|
if (attrs) {
|
|
|
|
for (var attrName in attrs) {
|
|
|
|
div.setAttribute(attrName, attrs[attrName]);
|
|
|
|
}
|
|
|
|
}
|
2014-12-17 23:42:40 +00:00
|
|
|
document.body.appendChild(div);
|
|
|
|
if (t && typeof t.add_cleanup === 'function') {
|
2015-03-04 02:49:43 +00:00
|
|
|
t.add_cleanup(function() {
|
|
|
|
if (div.parentNode) {
|
|
|
|
div.parentNode.removeChild(div);
|
|
|
|
}
|
|
|
|
});
|
2014-12-17 23:42:40 +00:00
|
|
|
}
|
|
|
|
return div;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Promise wrapper for requestAnimationFrame.
|
|
|
|
*/
|
|
|
|
function waitForFrame() {
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
window.requestAnimationFrame(resolve);
|
|
|
|
});
|
|
|
|
}
|
2014-12-17 23:42:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper that takes a sequence of N players and returns:
|
|
|
|
*
|
|
|
|
* Promise.all([players[0].ready, players[1].ready, ... players[N-1].ready]);
|
|
|
|
*/
|
|
|
|
function waitForAllPlayers(players) {
|
|
|
|
return Promise.all(players.map(function(player) { return player.ready; }));
|
|
|
|
}
|
2015-03-04 02:49:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a Promise that is resolved after the next two animation frames have
|
|
|
|
* occured (that is, after two consecutive requestAnimationFrame callbacks
|
|
|
|
* have been called).
|
|
|
|
*/
|
|
|
|
function waitForTwoAnimationFrames() {
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
|
|
window.requestAnimationFrame(function() {
|
|
|
|
window.requestAnimationFrame(function() {
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-06 15:23:17 +00:00
|
|
|
/**
|
|
|
|
* Flush the computed style for the given element. This is useful, for example,
|
|
|
|
* when we are testing a transition and need the initial value of a property
|
|
|
|
* to be computed so that when we synchronouslyet set it to a different value
|
|
|
|
* we actually get a transition instead of that being the initial value.
|
|
|
|
*/
|
|
|
|
function flushComputedStyle(elem) {
|
|
|
|
var cs = window.getComputedStyle(elem);
|
|
|
|
cs.marginLeft;
|
|
|
|
}
|
|
|
|
|