summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/geolocation/test_hidden.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/tests/mochitest/geolocation/test_hidden.html
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/tests/mochitest/geolocation/test_hidden.html')
-rw-r--r--dom/tests/mochitest/geolocation/test_hidden.html110
1 files changed, 110 insertions, 0 deletions
diff --git a/dom/tests/mochitest/geolocation/test_hidden.html b/dom/tests/mochitest/geolocation/test_hidden.html
new file mode 100644
index 0000000000..25f7f80d43
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_hidden.html
@@ -0,0 +1,110 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1653549
+-->
+<meta charset="utf-8">
+<title>Test that geolocation position can't be gotten when document is hidden</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<script src="geolocation_common.js"></script>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css" />
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1653549">Mozilla Bug 1653549</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+
+<script class="testbody">
+SimpleTest.waitForExplicitFinish();
+
+// Little promise wrapper helper.
+function p(f) {
+ return new Promise((r) => f(r));
+}
+
+resume_geolocationProvider(async () => {
+ // Initialize
+ await new Promise((r) => force_prompt(true, r));
+ const popupWindow = window.open("popup.html");
+ popupWindow.opener = window;
+ await new Promise((r) =>
+ window.addEventListener("message", r, { once: true })
+ );
+
+ // Confirm everything is working ok...
+ const geo = popupWindow.navigator.geolocation;
+ await new Promise((resolve, reject) => {
+ geo.getCurrentPosition(resolve, reject);
+ });
+
+ // Hide the document...
+ const hiddenPromise = new Promise(
+ (r) => (popupWindow.document.onvisibilitychange = r)
+ );
+ await SimpleTest.promiseFocus(window);
+ await hiddenPromise;
+
+ // The following promises only resolve successfully when document is visible,
+ // meaning that position updates are ignored when the document is hidden.
+ let success = false;
+ let watchId = null;
+ const watchPositionPromise = new Promise((resolve) => {
+ watchId = geo.watchPosition(
+ () => {
+ ok(success, "watchPosition was called.");
+ if (!success) {
+ throw new Error("watchPosition was called too early");
+ }
+ resolve();
+ },
+ () => {
+ ok(false, "Error callback of watchPosition must not be called.");
+ }
+ );
+ });
+
+ const currentPositionPromise = new Promise((resolve) => {
+ geo.getCurrentPosition(
+ () => {
+ ok(success, "getCurrentPosition was called.");
+ if (!success){
+ throw new Error("getCurrentPosition was called too early");
+ }
+ resolve();
+ },
+ () => {
+ ok(false, "Error callback of getCurrentPosition must not be called.");
+ }
+ );
+ });
+
+ // Send data to be ignored...
+ await p(start_sending_garbage);
+ await p(stop_sending_garbage);
+ await p(resume_geolocationProvider);
+
+ // Refocus popup window...
+ const visiblePopupPromise = new Promise(
+ (r) => (popupWindow.document.onvisibilitychange = r)
+ );
+ await SimpleTest.promiseFocus(popupWindow);
+ await visiblePopupPromise;
+
+ // Resuming the geolocation events must now cause the promises to resolve correctly (with success = true).
+ success = true;
+ await p(resume_geolocationProvider);
+ await Promise.all([currentPositionPromise, watchPositionPromise]);
+
+ // Cleanup and finish!
+ geo.clearWatch(watchId);
+ await SimpleTest.promiseFocus(window);
+ popupWindow.close();
+ SimpleTest.finish();
+});
+
+</script>
+</pre>
+</body>
+</html>
+