Skip to content

Commit

Permalink
Cherry-pick 267815.490@safari-7617-branch (837e693). https://bugs.web…
Browse files Browse the repository at this point in the history
…kit.org/show_bug.cgi?id=263277

    Add test for Geolocation WatchID
    https://bugs.webkit.org/show_bug.cgi?id=263277
    rdar://8731258

    Reviewed by David Kilzer.

    Add a test that confirms the Geolocation WatchID is unique per document.

    * LayoutTests/http/tests/security/isolate-geolocation-watch-id-per-document-expected.txt: Added.
    * LayoutTests/http/tests/security/isolate-geolocation-watch-id-per-document.html: Added.
    * LayoutTests/http/tests/security/resources/popup-watchid.html: Added.

    Canonical link: https://commits.webkit.org/267815.490@safari-7617-branch

Canonical link: https://commits.webkit.org/266719.176@webkitglib/2.42
  • Loading branch information
sysrqb authored and mcatanzaro committed Dec 13, 2023
1 parent db46056 commit 03ed5c1
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Tests that when the website's data is cleared, the watchID is reset, too.

On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".


PASS watchID should increment for every request: 2 vs 2
PASS Success callback 1 invoked
PASS Success callback 2 invoked
PASS Every Document should get its own watchID counter: 1 vs 1
PASS Every Document should get its own watchID counter: 1 vs 1
PASS Every Document should get its own watchID counter: 1 vs 1
PASS successfullyParsed is true

TEST COMPLETE
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
</head>
<body>
<script>
description("Tests that when the website's data is cleared, the watchID is reset, too.");

function initGeolocation() {
if (window.testRunner) {
testRunner.setGeolocationPermission(true);
testRunner.setMockGeolocationPosition(51.478, -0.166, 100);
}
}

// watchId is 1-indexed, so we initialize index 0 as true
let watchPositionsSuccessful = [ true, false, false ];
let popup;
let popupCount = 0;

const iframeResource = "resources/popup-watchid.html";

let i = 0;

function maybeOpenPopup() {
if (watchPositionsSuccessful.every((success) => success))
popup = window.open(iframeResource);
}

function getWatchPosition(i) {
return navigator.geolocation.watchPosition(function() {
testPassed(`Success callback ${i} invoked`);
watchPositionsSuccessful[i] = true;
maybeOpenPopup();
}, function(err) {
testFailed(`Error callback ${i} invoked unexpectedly`);
finishJSTest();
});
}

initGeolocation();

let watchId1 = getWatchPosition(++i);
let watchId2 = getWatchPosition(++i);
expectTrue(watchId2 == 2, `watchID should increment for every request: ${watchId2} vs 2`);

window.addEventListener("message", (e) => {
expectTrue(e.data == 1, `Every Document should get its own watchID counter: ${e.data} vs 1`);
popup.close();
switch (popupCount) {
case 0: {
popup = window.open(iframeResource);
break;
}
case 1: {
popup = window.open(`http://localhost:8000/security/${iframeResource}`);
break;
}
case 2: {
finishJSTest();
break;
}
}
popupCount++;
});

window.jsTestIsAsync = true;
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>
11 changes: 11 additions & 0 deletions LayoutTests/http/tests/security/resources/popup-watchid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<body>
<script>
if (window.testRunner)
testRunner.setGeolocationPermission(false);
let watchID = navigator.geolocation.watchPosition(function() { });
window.opener.postMessage(watchID, "*");
</script>
</body>
</html>

0 comments on commit 03ed5c1

Please sign in to comment.