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

Unified Diff: LayoutTests/virtual/threaded/fast/idle-callback/basic.html

Issue 1119683003: Implement requestIdleCallback API (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address Review Comments Created 5 years, 4 months 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: LayoutTests/virtual/threaded/fast/idle-callback/basic.html
diff --git a/LayoutTests/virtual/threaded/fast/idle-callback/basic.html b/LayoutTests/virtual/threaded/fast/idle-callback/basic.html
new file mode 100644
index 0000000000000000000000000000000000000000..cd53fc40b1e7ca3d4190080c8eb7d7822ad26e79
--- /dev/null
+++ b/LayoutTests/virtual/threaded/fast/idle-callback/basic.html
@@ -0,0 +1,69 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8" />
+<title>window.requestIdleCallback exists</title>
+<link rel="author" title="Ross McIlroy" href="mailto:rmcilroy@chromium.org" />
+<link rel="help" href="http://www.w3.org/TR/requestidlecallback/"/>
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+<link rel="stylesheet" href="../../resources/testharness.css" />
+<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(function(deadline) {
+ assert_equals(typeof deadline, "object", "IdleDeadline MUST be passed to callback.");
+ assert_equals(typeof deadline.deadline, "number", "IdleDeadline.deadline MUST be a DOMHighResTimeStamp");
+ var now = performance.now();
+ assert_true((deadline.deadline - now) <= 50, "IdleDeadline.deadline MUST be less than or equal to 50ms in the future.");
+ assert_equals(typeof deadline.isExceeded, "function", "IdleDeadline.isExceeded MUST be a function");
+ assert_equals(typeof deadline.isExceeded(), "boolean", "IdleDeadline.isExceeded MUST return a boolean");
+ if (!deadline.isExceeded()) {
+ // If the deadline has not been exceeded now, then it should be greater than
+ // the than what performance.now() returned earlier.
+ assert_true(now < deadline.deadline, "performance.now() should be less than deadline if isExceeded returned true.");
+ }
+ 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");
+ this.done();
+ }));
+}, '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>Description</h1>
+<p>This test validates that window.requestIdleCallback and window.cancelIdleCallback exist and are a functions.</p>
+</head>
+<body>
+<div id="log"></div>
+
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698