summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/webappapis
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-18 15:15:49 +0200
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-04-18 15:15:49 +0200
commitc559e3e30f79843f0096332334c81ee0d93029f8 (patch)
tree07ee668e9f82976e2d00912e818b632ea4470170 /testing/web-platform/tests/html/webappapis
parent29de8de78c3260aad1e7844933d5b3cf1033627c (diff)
downloadUXP-c559e3e30f79843f0096332334c81ee0d93029f8.tar
UXP-c559e3e30f79843f0096332334c81ee0d93029f8.tar.gz
UXP-c559e3e30f79843f0096332334c81ee0d93029f8.tar.lz
UXP-c559e3e30f79843f0096332334c81ee0d93029f8.tar.xz
UXP-c559e3e30f79843f0096332334c81ee0d93029f8.zip
moebius#73: DOM - window.requestIdleCallback - improvements (basic)
https://github.com/MoonchildProductions/moebius/pull/73
Diffstat (limited to 'testing/web-platform/tests/html/webappapis')
-rw-r--r--testing/web-platform/tests/html/webappapis/idle-callbacks/callback-suspended.html93
-rw-r--r--testing/web-platform/tests/html/webappapis/idle-callbacks/resources/post_name_on_load.html7
2 files changed, 100 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/webappapis/idle-callbacks/callback-suspended.html b/testing/web-platform/tests/html/webappapis/idle-callbacks/callback-suspended.html
new file mode 100644
index 000000000..6040de922
--- /dev/null
+++ b/testing/web-platform/tests/html/webappapis/idle-callbacks/callback-suspended.html
@@ -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 => {
+ setTimeout(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")
+ ]))
+ .then(_ => win.close())
+ .catch(e => {
+ win.close();
+ throw e;
+ })
+ });
+ });
+
+</script>
diff --git a/testing/web-platform/tests/html/webappapis/idle-callbacks/resources/post_name_on_load.html b/testing/web-platform/tests/html/webappapis/idle-callbacks/resources/post_name_on_load.html
new file mode 100644
index 000000000..4679a6e6e
--- /dev/null
+++ b/testing/web-platform/tests/html/webappapis/idle-callbacks/resources/post_name_on_load.html
@@ -0,0 +1,7 @@
+<!doctype html>
+<script>
+ addEventListener('load', _ => {
+ let params = new URLSearchParams(window.location.search);
+ window.opener.postMessage(params.get('name'), '*');
+ });
+</script>