Update web-platform-tests to revision 3137d1d2d7757366a69f8a449b458b5057e0e81e

This commit is contained in:
Ms2ger 2016-12-28 09:51:21 +01:00
parent 81ca858678
commit d6ba94ca28
2339 changed files with 89274 additions and 9328 deletions

View file

@ -0,0 +1,51 @@
<!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);
setTimeout(this.step_func(function() {
this.done();
}), 200);
}, 'cancelIdleCallback cancels callbacks');
</script>
<h1>Basic requestIdleCallback Tests</h1>
<div id="log"></div>

View file

@ -0,0 +1,75 @@
<!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 two separate calls to requestIdleCallbacks can run in the same
// idle period.
var callback_1_deadline;
var callback_1_has_run = false;
var callback_1 = function(deadline) {
callback_1_has_run = true;
var remaining = deadline.timeRemaining();
if (remaining >= 5) {
// Should be enough time to run the next callback in the current idle
// period.
callback_1_deadline = performance.now() + remaining;
}
};
var callback_2 = this.step_func(function(deadline) {
assert_true(callback_1_has_run, "Should run callbacks in order of posting if they don't have a timeout.");
if (callback_1_deadline != undefined) {
assert_true(performance.now() < callback_1_deadline, "Should be able to run both callbacks in the same idle period.");
this.done();
} else {
// Might not have had enough idle time, so try again.
callback_1_has_run = false;
setTimeout(function() {
requestIdleCallback(callback_1);
requestIdleCallback(callback_2);
}, 0);
}
});
requestIdleCallback(callback_1);
requestIdleCallback(callback_2);
}, 'requestIdleCallback can run multiple different requestIdleCallback callbacks in the same idle period.');
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,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>