Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: third_party/WebKit/LayoutTests/imported/wpt/html/webappapis/idle-callbacks/basic.html

Issue 2517743002: Import wpt@5a1f188e0536ad023936cc62f9a00617299dc192 (Closed)
Patch Set: rebased Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/imported/wpt/html/webappapis/idle-callbacks/basic.html
diff --git a/third_party/WebKit/LayoutTests/imported/wpt/html/webappapis/idle-callbacks/basic.html b/third_party/WebKit/LayoutTests/imported/wpt/html/webappapis/idle-callbacks/basic.html
new file mode 100644
index 0000000000000000000000000000000000000000..68976a6963fa5726a00f6773b26d6c537233e236
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/imported/wpt/html/webappapis/idle-callbacks/basic.html
@@ -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>

Powered by Google App Engine
This is Rietveld 408576698