Bug 1464503 [wpt PR 11165] - [PageLifecycle] Add WPT test for lifecycle's onfreeze callback, a=testonly
authorFadi Meawad <fmeawad@chromium.org>
Wed, 06 Jun 2018 17:31:24 +0000
changeset 476477 e5cf8dad80f05a0f1fc088b03cce8da32de4cb84
parent 476476 da62153130d5b6a2b02a335df672a32a8e576a75
child 476478 05c9b364a0dbb7eccbcdea46e398465b61e14735
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1464503, 11165, 837709, 1072899, 563338
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1464503 [wpt PR 11165] - [PageLifecycle] Add WPT test for lifecycle's onfreeze callback, a=testonly Automatic update from web-platform-tests[PageLifecycle] Add WPT test for lifecycle's onfreeze callback Since the onfreeze callback is invoked based on an internal decision from the browser, to be able to test the callback, we are adding support for it from chromeGPUBenchmak as well as in chromedriver/WebDriver. This CL focuses on the chromeGPUBenchmark solution. The WPT test itself, verifies that the onfreeze callback is called, and it also verifies that only fetch keepalive is allowed from withing the callback. Bug: chromium:837709 Change-Id: Ia4cb16dc10625f478ec270617da1a26395a9d29d Reviewed-on: https://chromium-review.googlesource.com/1072899 Reviewed-by: Jonathon Kereliuk <kereliuk@chromium.org> Reviewed-by: Shubhie Panicker <panicker@chromium.org> Reviewed-by: Kenneth Russell <kbr@chromium.org> Commit-Queue: Fadi Meawad <fmeawad@chromium.org> Cr-Commit-Position: refs/heads/master@{#563338} -- wpt-commits: 3d6920b84bac82c45a8da5c8b04b6da0c64f02fd wpt-pr: 11165
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/lifecycle/freeze.html
testing/web-platform/tests/lifecycle/resources/foo.txt
testing/web-platform/tests/lifecycle/resources/window.html
testing/web-platform/tests/resources/testdriver.js
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -287635,16 +287635,26 @@
      {}
     ]
    ],
    "keyboard-map/OWNERS": [
     [
      {}
     ]
    ],
+   "lifecycle/resources/foo.txt": [
+    [
+     {}
+    ]
+   ],
+   "lifecycle/resources/window.html": [
+    [
+     {}
+    ]
+   ],
    "longtask-timing/OWNERS": [
     [
      {}
     ]
    ],
    "longtask-timing/resources/makelongtask.js": [
     [
      {}
@@ -349794,16 +349804,22 @@
     ]
    ],
    "keyboard-map/keyboard-map-https.html": [
     [
      "/keyboard-map/keyboard-map-https.html",
      {}
     ]
    ],
+   "lifecycle/freeze.html": [
+    [
+     "/lifecycle/freeze.html",
+     {}
+    ]
+   ],
    "longtask-timing/longtask-attributes.html": [
     [
      "/longtask-timing/longtask-attributes.html",
      {}
     ]
    ],
    "longtask-timing/longtask-in-childiframe-crossorigin.html": [
     [
@@ -587405,16 +587421,28 @@
   "keyboard-map/idlharness.https.html": [
    "3215b6729d83ca2841baf6eb33445eb07e0a7c25",
    "testharness"
   ],
   "keyboard-map/keyboard-map-https.html": [
    "28b559875ce9514702d181cb4cb5e0a207083e2d",
    "testharness"
   ],
+  "lifecycle/freeze.html": [
+   "aca6ab2b23924ff891dc2abc26eb3067ad099e5b",
+   "testharness"
+  ],
+  "lifecycle/resources/foo.txt": [
+   "b909d6288b51d2b2dfe06382f057a5892826949b",
+   "support"
+  ],
+  "lifecycle/resources/window.html": [
+   "3c839ba3697d5ce8bcda99824af7dea7b37534c1",
+   "support"
+  ],
   "longtask-timing/OWNERS": [
    "30a9c29ba53bac131c0cca801c01dddb4779824e",
    "support"
   ],
   "longtask-timing/longtask-attributes.html": [
    "247359327818f59871be00d22942f6ecde5281a7",
    "testharness"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/freeze.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>TestDriver freeze method</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+var test = async_test('Test freeze callback.');
+var childWindow = window.open('resources/window.html', 'Child Window');
+var total_steps = 0;
+
+const StepStatus = {
+  ADDED: 0,
+  SUCCESS: 1,
+  FAIL: 2,
+};
+
+var steps_map = new Map();
+
+function add_step(name) {
+  steps_map[name] = StepStatus.ADDED;
+  total_steps++;
+}
+
+function step_success(name) {
+  total_steps--;
+  steps_map[name] = StepStatus.SUCCESS;
+  if (total_steps == 0)
+    test.done();
+}
+
+function step_fail(name) {
+  total_steps--;
+  steps_map[name] = StepStatus.FAIL;
+  test.step(() => assert_unreached('During onfreeze: ' + name + ' failed to behave as expected.'));
+  if (total_steps == 0)
+    test.done();
+}
+
+test.step_timeout(() => {
+  for (var step in steps_map) {
+    if(steps_map[step] == StepStatus.ADDED)
+      test.step(() => assert_unreached('During onfreeze: ' + step + ' never finshed.'));
+  }
+}, 1000);
+
+</script>
+
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/resources/foo.txt
@@ -0,0 +1,1 @@
+Sample test file for fetch inside onfreeze.
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/lifecycle/resources/window.html
@@ -0,0 +1,66 @@
+<!doctype html>
+<html>
+<head><title>Frozen Window</title></head>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<body>
+<h1>This window will be frozen</h1>
+<script>
+
+const freezingStepName = 'testOnFreeze';
+
+function testFetch(keepalive) {
+  var name = 'testfetch' + (keepalive ? 'with' : 'without') + 'keepalive';
+  window.opener.add_step(name);
+
+  function handler(expected) {
+    if (expected == true)
+      window.opener.step_success(name);
+    else
+      window.opener.step_fail(name);
+  }
+
+  fetch('foo.txt', {
+    keepalive: keepalive
+  }).then(() => handler(keepalive)).catch(() => handler(!keepalive));
+}
+
+function testXHR(async) {
+  var name = 'test' + (async ? 'Async' : 'Sync') + 'XHR';
+  window.opener.add_step(name);
+  var xhr = new XMLHttpRequest();
+  xhr.onreadystatechange = () => {
+    if (xhr.readyState === 4) {
+      if (xhr.status === 0)
+        window.opener.step_success(name);
+      else
+        window.opener.step_fail(name);
+    }
+  }
+  xhr.open('GET', 'foo.txt', async);
+  try {
+    xhr.send(null);
+  } catch {
+    window.opener.step_success(name);
+  };
+}
+
+window.document.addEventListener("freeze", () => {
+  // Testing fetch, only fetch keepalive should succeed.
+  testFetch(true /* keepalive */);
+  testFetch(false /* keepalive */);
+  // Testing XHR, both sync and async should fail.
+  testXHR(true /* async */);
+  testXHR(false /* sync */);
+  window.opener.step_success(freezingStepName);
+});
+
+onload = function() {
+  window.opener.focus();
+  window.opener.add_step(freezingStepName);
+  test_driver.freeze();
+};
+
+</script>
+</body>
+</html>
\ No newline at end of file
--- a/testing/web-platform/tests/resources/testdriver.js
+++ b/testing/web-platform/tests/resources/testdriver.js
@@ -114,16 +114,31 @@
 
             var pointerInteractablePaintTree = getPointerInteractablePaintTree(element);
             if (pointerInteractablePaintTree.length === 0 ||
                 !element.contains(pointerInteractablePaintTree[0])) {
                 return Promise.reject(new Error("element send_keys intercepted error"));
             }
 
             return window.test_driver_internal.send_keys(element, keys);
+        },
+
+        /**
+         * Freeze the current page
+         *
+         * The freeze function transitions the page from the HIDDEN state to
+         * the FROZEN state as described in {@link
+         * https://github.com/WICG/page-lifecycle/blob/master/README.md|Lifecycle API
+         * for Web Pages}
+         *
+         * @returns {Promise} fullfilled after the freeze request is sent, or rejected
+         *                    in case the WebDriver command errors
+         */
+        freeze: function() {
+            return window.test_driver_internal.freeze();
         }
     };
 
     window.test_driver_internal = {
         /**
          * Triggers a user-initated click
          *
          * @param {Element} element - element to be clicked
@@ -138,11 +153,21 @@
          * Triggers a user-initated click
          *
          * @param {Element} element - element to be clicked
          * @param {String} keys - keys to send to the element
          * @returns {Promise} fulfilled after keys are sent or rejected if click fails
          */
         send_keys: function(element, keys) {
             return Promise.reject(new Error("unimplemented"));
+        },
+
+        /**
+         * Freeze the current page
+         *
+         * @returns {Promise} fullfilled after freeze request is sent, otherwise
+         * it gets rejected
+         */
+        freeze: function() {
+            return Promise.reject(new Error("unimplemented"));
         }
     };
 })();