Bug 1573224 [wpt PR 18339] - Expose XRVisibilityState, a=testonly
authorBrandon Jones <bajones@chromium.org>
Wed, 14 Aug 2019 10:57:10 +0000
changeset 488119 de0528635d593db5e09eb5119b0c4bb12c0b0d15
parent 488118 37fa0d77d7385e795c8d4ad3d12b3bb047808411
child 488120 6dadd5a887df764d0842af4ca9866a54317d6bff
push id36435
push usercbrindusan@mozilla.com
push dateThu, 15 Aug 2019 09:46:49 +0000
treeherdermozilla-central@0db07ff50ab5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1573224, 18339, 987030, 1744650, 686040
milestone70.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 1573224 [wpt PR 18339] - Expose XRVisibilityState, a=testonly Automatic update from web-platform-tests Expose XRVisibilityState Replaces the previous XRSession "blur" and "focus" events with the visibilityState attribute and an associated "visibilitychange" event. Bug: 987030 Change-Id: I1d60dd50102b4d3be583ae023cad8994ab17b01b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1744650 Reviewed-by: Brian Sheedy <bsheedy@chromium.org> Reviewed-by: Klaus Weidner <klausw@chromium.org> Commit-Queue: Brandon Jones <bajones@chromium.org> Cr-Commit-Position: refs/heads/master@{#686040} -- wpt-commits: 033cff019de41220b9446661ee5527e7475d27e1 wpt-pr: 18339
testing/web-platform/tests/webxr/xrSession_visibilityState.https.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/webxr/xrSession_visibilityState.https.html
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/webxr_util.js"></script>
+<script src="resources/webxr_test_constants.js"></script>
+<canvas id="webgl-canvas"></canvas>
+
+<script>
+let testName = "Ensures that the XRSession's visibilityState is correctly "
+  + "reported and that the associated visibilitychange event fires.";
+
+let watcherDone = new Event("watcherdone");
+let frameFired = new Event("framefired");
+
+let fakeDeviceInitParams = TRACKED_IMMERSIVE_DEVICE;
+
+let testFunction = function(session, fakeDeviceController, t) {
+  let eventWatcher = new EventWatcher(
+    t, session, ["visibilitychange", "visibilitychange", "framefired", "watcherdone"]);
+  let eventPromise = eventWatcher.wait_for(
+    ["visibilitychange", "visibilitychange", "framefired", "watcherdone"]);
+
+  function onFrame(t, frame) {
+    t.step( () => {
+      // The session should not fire any animation frames while the visibility
+      // state is hidden.
+      assert_not_equals(session.visibilityState, "hidden");
+    });
+
+    // Make sure the frame does fire when the visibility is changed back to "visible"
+    session.dispatchEvent(frameFired);
+  }
+
+  function onSessionVisibilityChangeHidden(event) {
+    t.step( () => {
+      assert_equals(session.visibilityState, "hidden");
+    });
+
+    session.removeEventListener("visibilitychange", onSessionVisibilityChangeHidden, false);
+    session.addEventListener("visibilitychange", onSessionVisibilityChangeVisible, false);
+
+    session.requestAnimationFrame()
+
+    t.step_timeout(() => {
+      fakeDeviceController.simulateVisibilityChange("visible");
+    }, 300);
+  }
+
+  function onSessionVisibilityChangeVisible(event) {
+    t.step( () => {
+      assert_equals(session.visibilityState, "visible");
+    });
+
+    session.removeEventListener("visibilitychange", onSessionVisibilityChangeVisible, false);
+    session.addEventListener("visibilitychange", onSessionVisibilityChangeInvalid, false);
+    fakeDeviceController.simulateVisibilityChange("visible");
+
+    t.step_timeout(() => {
+      session.dispatchEvent(watcherDone);
+    }, 300);
+  }
+
+  function onSessionVisibilityChangeInvalid(event) {
+    t.step( () => {
+      assert_not_reached("Should not fire visibilitychange events for the same state");
+    });
+  }
+
+  t.step( () => {
+    // Session visibility should start out as "visible"
+    assert_equals(session.visibilityState, "visible");
+  });
+
+  session.addEventListener("visibilitychange", onSessionVisibilityChangeHidden, false);
+  fakeDeviceController.simulateVisibilityChange("hidden");
+};
+
+xr_session_promise_test(
+  testName, testFunction, fakeDeviceInitParams, 'immersive-vr');
+
+</script>