Update web-platform-tests to revision 8a2ceb5f18911302b7a5c1cd2791f4ab50ad4326

This commit is contained in:
Josh Matthews 2017-10-12 09:25:50 -04:00
parent 462c272380
commit 1f531f66ea
5377 changed files with 174916 additions and 84369 deletions

View file

@ -0,0 +1,2 @@
@farre
@rmcilroy

View file

@ -0,0 +1,49 @@
<!DOCTYPE html>
<title>window.requestIdleCallback exists</title>
<link rel="author" title="Ross McIlroy" href="mailto:rmcilroy@chromium.org" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(function() {
assert_equals(typeof window.requestIdleCallback, "function");
}, "window.requestIdleCallback is defined", {assert: "The window.requestIdleCallback function is used to request callbacks during browser-defined idle time."});
test(function() {
assert_equals(typeof window.cancelIdleCallback, "function");
}, "window.cancelIdleCallback is defined", {assert: "The window.cancelIdleCallback function is used to cancel callbacks scheduled via requestIdleCallback."});
test(function() {
assert_equals(typeof window.requestIdleCallback(function() {}), "number");
}, "window.requestIdleCallback() returns a number", {assert: "The requestIdleCallback method MUST return a long"});
test(function() {
assert_equals(typeof window.cancelIdleCallback(1), "undefined");
}, "window.cancelIdleCallback() returns undefined", {assert: "The cancelIdleCallback method MUST return void"});
async_test(function() {
// Check whether requestIdleCallback schedules a callback which gets executed
// and the deadline argument is passed correctly.
requestIdleCallback(this.step_func_done(function(deadline) {
assert_equals(arguments.length, 1, "Only one argument should be passed to callback.");
assert_class_string(deadline, "IdleDeadline");
assert_equals(typeof deadline.timeRemaining, "function", "IdleDeadline.timeRemaining MUST be a function which returns the time remaining in milliseconds");
assert_equals(typeof deadline.timeRemaining(), "number", "IdleDeadline.timeRemaining MUST return a double of the time remaining in milliseconds");
assert_true(deadline.timeRemaining() <= 50, "IdleDeadline.timeRemaining() MUST be less than or equal to 50ms in the future.");
assert_equals(typeof deadline.didTimeout, "boolean", "IdleDeadline.didTimeout MUST be a boolean");
assert_false(deadline.didTimeout, "IdleDeadline.didTimeout MUST be false if requestIdleCallback wasn't scheduled due to a timeout");
}));
}, 'requestIdleCallback schedules callbacks');
async_test(function() {
// Check whether requestIdleCallback schedules a callback which gets executed
// and the deadline argument is passed correctly.
var handle = requestIdleCallback(this.step_func(function(deadline) {
assert_unreached("callback should not be called if canceled with cancelIdleCallback");
}));
cancelIdleCallback(handle);
step_timeout(this.step_func_done(), 200);
}, 'cancelIdleCallback cancels callbacks');
</script>
<h1>Basic requestIdleCallback Tests</h1>
<div id="log"></div>

View file

@ -0,0 +1,22 @@
<!doctype html>
<meta charset=utf-8>
<title>requestIdleCallback callback exception reported to error handler</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id="log"></div>
<script>
var custom_exception = 'requestIdleCallbackException';
setup({allow_uncaught_exception : true});
async_test(function (t) {
assert_false(document.hidden, "document.hidden must exist and be false to run this test properly");
addEventListener("error",function(e) {
t.step(function() {
assert_equals(e.error.message, custom_exception);
t.done();
})
});
window.requestIdleCallback(function () {
throw new Error(custom_exception);
});
}, "requestIdleCallback callback exceptions are reported to error handler");
</script>

View file

@ -0,0 +1,43 @@
<!DOCTYPE html>
<title>window.requestIdleCallback callback behavior during idle periods.</title>
<link rel="author" title="Ross McIlroy" href="mailto:rmcilroy@chromium.org" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function() {
// Check that if an idle callback calls requestIdleCallback, the new callback
// doesn't get the same deadline (i.e., runs in a new idle period).
var previous_deadline = undefined;
var idle_callbacks_remaining = 10;
var rIC = this.step_func(function(deadline) {
var now = performance.now();
var remaining = deadline.timeRemaining();
var new_deadline = now + remaining;
if (previous_deadline != undefined) {
assert_true(new_deadline > previous_deadline, "A requestIdleCallback scheduled during an idle period should be called back with a deadline greater than that in the current idle period.");
}
// Schedule a new requestIdleCallback.
if (--idle_callbacks_remaining > 0) {
previous_deadline = new_deadline;
requestIdleCallback(rIC);
} else {
this.done();
}
});
// Spin an empty rAF loop to cause an idle period each frame.
var idle_task_posted = false;
requestAnimationFrame(function rAFLoop() {
if (!idle_task_posted) {
requestIdleCallback(rIC);
idle_task_posted = true;
}
requestAnimationFrame(rAFLoop);
});
}, 'Check that if an idle callback calls requestIdleCallback the new callback doesn\'t run in the current idle period.');
</script>
<h1>Test of requestIdleCallback idle period behavior</h1>
<p>This test validates that window.requestIdleCallback deals with callbacks during idle periods correctly.</p>
<div id="log"></div>

View file

@ -0,0 +1,17 @@
<!doctype html>
<meta charset=utf-8>
<title></title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id="log"></div>
<iframe style="display:none" id="frame"></iframe>
<script>
async_test(function (t) {
let frame = document.getElementById("frame");
frame.contentWindow.test = function() {
frame.contentWindow.requestIdleCallback(t.step_func_done());
}
frame.contentWindow.test();
});
</script>

View file

@ -0,0 +1,12 @@
<!doctype html>
<meta charset=utf-8>
<title>requestIdleCallback callback must be called eventually</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id="log"></div>
<script>
async_test(function (t) {
assert_false(document.hidden, "document.hidden must exist and be false to run this test properly");
window.requestIdleCallback(t.step_func_done());
}, "requestIdleCallback callback is invoked at least once before the timeout");
</script>

View file

@ -0,0 +1,46 @@
<!doctype html>
<meta charset=utf-8>
<title>multiple calls to requestIdleCallback</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id="log"></div>
<script>
let option = {timeout: 50};
async_test(function (t) {
assert_false(document.hidden, "document.hidden must exist and be false to run this test properly");
var counter = 0;
function f(c) {
assert_equals(counter, c);
if (counter === 49) {
t.done();
}
++counter;
}
for (var i = 0; i < 100; ++i) {
let j = i;
window.requestIdleCallback(t.step_func(function () { f(j) }), option);
}
}, "requestIdleCallback callbacks should be invoked in order (called iteratively)");
async_test(function (t) {
assert_false(document.hidden, "document.hidden must exist and be false to run this test properly");
var counter = 0;
function f(c) {
assert_equals(counter, c);
if (counter === 49) {
t.done();
}
++counter;
window.requestIdleCallback(t.step_func(function () { f(c + 1) }), option);
}
window.requestIdleCallback(t.step_func(function () { f(0) }), option);
}, "requestIdleCallback callbacks should be invoked in order (called recursively)");
let generateIdlePeriods = _ => requestAnimationFrame(generateIdlePeriods);
generateIdlePeriods();
</script>

View file

@ -0,0 +1,30 @@
<!doctype html>
<meta charset=utf-8>
<title>requestIdleCallback on removed frame shouldn't call back</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
async_test(function (t) {
assert_false(document.hidden, "document.hidden must exist and be false to run this test properly");
function start() {
var frame = document.createElement('iframe');
frame.addEventListener('load', _ => connect(frame), {once:true});
frame.src = "about:blank";
document.body.appendChild(frame);
}
function connect(frame) {
var contentWindow = frame.contentWindow;
contentWindow.requestIdleCallback(_ => callback0(frame, contentWindow));
t.step_timeout(function() { t.done(); }, 1000);
}
function callback0(f, w) {
document.body.removeChild(f);
w.requestIdleCallback(t.unreached_func("requestIdleCallback callback should not trigger the callback"));
}
addEventListener('load', start, {once:true});
}, "calling requestIdleCallback on a contentWindow from a removed iframe should not trigger the callback");
</script>

View file

@ -0,0 +1,93 @@
<!doctype html>
<meta charset=utf-8>
<title>Dispatching idle callbacks should be able to be suspended and then resumed</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id="log"></div>
<script>
function withEventListener(target, event, handler) {
handler = handler || (e => e);
return new Promise(resolve => {
let wrapper = function(e) {
let result = handler(e);
if (!result) {
return;
}
resolve(result);
}
target.addEventListener(event, wrapper, { once: true });
});
}
function makePostBackUrl(name) {
return new URL('resources/post_name_on_load.html?name=' + name,
window.location).href;
}
function waitForMessage(message, handler) {
return withEventListener(window, 'message', e => (e.data === message) && handler(e));;
}
function withWindow(name) {
let win = window.open(makePostBackUrl(name))
return waitForMessage(name, _ => win);
}
function navigateWindow(win, name) {
win.location = makePostBackUrl(name);
return waitForMessage(name, _ => win);
}
function waitDuration(delay) {
return new Promise(resolve => {
step_timeout(resolve, delay);
})
}
function goBack(win) {
var p = withEventListener(win, 'pagehide');
win.history.back();
return p;
}
promise_test(t => {
let idleCalled = false;
let running = true;
return withWindow('foo')
.then(win => {
let callback = function(d) {
idleCalled = true;
if (running) {
win.requestIdleCallback(callback);
}
};
win.requestIdleCallback(callback);
return navigateWindow(win, 'bar')
.then(_ => idleCalled = false)
.then(_ => waitDuration(2000))
.then(_ => {
assert_false(idleCalled, "idle callback shouldn't have been called yet");
return goBack(win);
})
.then(_ => Promise.race([
// At this point it's a matter of having bfcache ...
waitDuration(2000)
.then(_ => {
assert_true(idleCalled, "idle callback should've been called by now");
running = false;
}),
// ... or not. If not, we expect a load event.
waitForMessage("foo", _ => win)
]))
.then(_ => win.close())
.catch(e => {
win.close();
throw e;
})
});
});
</script>

View file

@ -0,0 +1,69 @@
<!DOCTYPE html>
<title>window.requestIdleCallback deals with timeouts correctly</title>
<link rel="author" title="Ross McIlroy" href="mailto:rmcilroy@chromium.org" />
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function() {
// Check whether requestIdleCallback with a timeout works when the event loop
// is busy.
var busy_raf_loop_iterations_remaining = 10; // Should take 20 * 40 = 400ms
var idle_callback_scheduled;
var idle_callback = this.step_func_done(function(deadline) {
assert_false(deadline.didTimeout, "IdleDeadline.didTimeout MUST be false if requestIdleCallback wasn't scheduled due to a timeout");
assert_equals(busy_raf_loop_iterations_remaining, 0, "Busy rAF loop should be finished by the time we get scheduled");
});
var busy_raf_loop_iterations_remaining = 10; // Should take 20 * 40 = 400ms
requestAnimationFrame(this.step_func(function busyRAFLoop() {
var start_time = performance.now();
if (!idle_callback_scheduled) {
idle_callback_scheduled = start_time;
requestIdleCallback(idle_callback);
}
// Use up the whole frame budget.
while (performance.now() - start_time < 40) {
}
if (busy_raf_loop_iterations_remaining > 0) {
busy_raf_loop_iterations_remaining--;
requestAnimationFrame(busyRAFLoop);
}
}));
}, 'requestIdleCallback not scheduled when event loop is busy.');
async_test(function() {
// Check whether requestIdleCallback with a timeout works when the event loop
// is busy.
var busy_raf_loop_iterations_remaining = 10; // Should take 20 * 40 = 400ms
var timeout = 200;
var idle_callback_scheduled;
var idle_callback = this.step_func_done(function(deadline) {
var time_delta = performance.now() - idle_callback_scheduled;
assert_true(time_delta >= timeout, "Should only have been run after timeout");
assert_true(deadline.timeRemaining() == 0, "IdleDeadline.timeRemaining MUST be equal to zero if requestIdleCallback was scheduled due to a timeout");
assert_true(deadline.didTimeout, "IdleDeadline.didTimeout MUST be true if requestIdleCallback was scheduled due to a timeout");
assert_true(busy_raf_loop_iterations_remaining > 0, "Busy rAF loop should still be going");
});
requestAnimationFrame(this.step_func(function busyRAFLoop() {
var start_time = performance.now();
if (!idle_callback_scheduled) {
idle_callback_scheduled = start_time;
requestIdleCallback(idle_callback, { timeout: timeout });
}
// Use up the whole frame budget.
while (performance.now() - start_time < 40) {
}
if (busy_raf_loop_iterations_remaining > 0) {
busy_raf_loop_iterations_remaining--;
requestAnimationFrame(busyRAFLoop);
}
}));
}, 'requestIdleCallback scheduled with timeout when event loop is busy.');
</script>
<h1>Test of requestIdleCallback timeout behavior</h1>
<div id="log"></div>

View file

@ -0,0 +1,43 @@
<!doctype html>
<meta charset=utf-8>
<title>requestIdleCallback timeout callback must be called with didTimeout equal to true</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id="log"></div>
<script>
async_test(function (t) {
assert_false(document.hidden, "document.hidden must exist and be false to run this test properly");
var counter = 0;
function g(deadline) {
assert_true(deadline.didTimeout)
t.done();
}
function f(deadline) {
assert_false(deadline.didTimeout);
window.requestIdleCallback(t.step_func(g), {timeout:300});
var d = Date.now() + 500;
while (Date.now() < d) {
}
}
window.requestIdleCallback(t.step_func(f));
}, "requestIdleCallback callback should time out");
async_test(function (t) {
assert_false(document.hidden, "document.hidden must exist and be false to run this test properly");
function g(deadline) {
assert_false(deadline.didTimeout)
t.done();
}
function f(deadline) {
assert_false(deadline.didTimeout);
window.requestIdleCallback(t.step_func(g), {timeout:100000});
}
window.requestIdleCallback(t.step_func(f));
}, "requestIdleCallback callback should not time out");
</script>

View file

@ -0,0 +1,16 @@
<!doctype html>
<meta charset=utf-8>
<title></title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
async_test(function (t) {
requestIdleCallback(function() {
requestIdleCallback(t.step_func_done(function () {}))
var xhr = new XMLHttpRequest();
xhr.open("GET", "www.emample.com", false);
xhr.onload = t.step_func(function () {});
xhr.send(null);
});
}, "re-schedule idle callbacks after sync xhr");
</script>

View file

@ -0,0 +1,32 @@
<!doctype html>
<meta charset=utf-8>
<title>cancelling idle requests</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id="log"></div>
<script>
test(function (t) {
window.cancelIdleCallback(42);
assert_true(true);
}, "cancelIdleCallback does nothing if there is no callback with the given handle");
async_test(function (t) {
assert_false(document.hidden, "document.hidden must exist and be false to run this test properly");
var neverCalled = true;
var handle = window.requestIdleCallback(function () {
neverCalled = false;
});
window.cancelIdleCallback(handle);
t.step_timeout(function() {
assert_true(neverCalled);
t.done();
}, 2000);
}, "A cancelled callback is never invoked");
async_test(function (t) {
var handle = requestIdleCallback(t.step_func_done(function () {
cancelIdleCallback(handle);
}));
}, "Cancelling the currently executing idle callback should be allowed");
</script>

View file

@ -0,0 +1,34 @@
<!doctype html>
<meta charset=utf-8>
<title>idlharness test</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/resources/WebIDLParser.js"></script>
<script src="/resources/idlharness.js"></script>
<pre id='untested_idl' style='display:none'>
[PrimaryGlobal]
interface Window {
};
</pre>
<pre id='idl'>
partial interface Window {
unsigned long requestIdleCallback(IdleRequestCallback callback,
optional IdleRequestOptions options);
void cancelIdleCallback(unsigned long handle);
};
dictionary IdleRequestOptions {
unsigned long timeout;
};
callback IdleRequestCallback = void (IdleDeadline deadline);
</pre>
<script>
var idl_array = new IdlArray();
idl_array.add_untested_idls(document.getElementById("untested_idl").textContent);
idl_array.add_idls(document.getElementById("idl").textContent);
idl_array.add_objects({Window: ["window"]});
idl_array.test();
</script>

View file

@ -0,0 +1,7 @@
<!doctype html>
<script>
addEventListener('load', _ => {
let params = new URLSearchParams(window.location.search);
window.opener.postMessage(params.get('name'), '*');
});
</script>