File size: 1,207 Bytes
e1d589b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | 'use strict';
function waitForEvent(target, type, options) {
return new Promise((resolve, reject) => {
target.addEventListener(type, resolve, options);
});
}
function waitForAnimationFrame(w) {
let targetWindow = w || window;
return new Promise((resolve, reject) => {
targetWindow.requestAnimationFrame(resolve);
});
}
function waitForEvent(target, type, options) {
return new Promise((resolve, reject) => {
target.addEventListener(type, resolve, options);
});
}
function waitForLoad(target) {
return waitForEvent(target, 'load');
}
function timeOut(test, ms) {
return new Promise((resolve, reject) => {
test.step_timeout(resolve, ms);
});
}
// If an element with autofocus is connected to a document and this function
// is called, the autofocus result is deterministic after returning from the
// function.
// Exception: If the document has script-blocking style sheets, this function
// doesn't work well.
async function waitUntilStableAutofocusState(w) {
let targetWindow = w || window;
// Awaiting two animation frames is an easy way to determine autofocus state.
await waitForAnimationFrame(targetWindow);
await waitForAnimationFrame(targetWindow);
}
|