-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry-pick 267815.490@safari-7617-branch (837e693). https://bugs.web…
…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
1 parent
db46056
commit 03ed5c1
Showing
3 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
LayoutTests/http/tests/security/isolate-geolocation-watch-id-per-document-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
72 changes: 72 additions & 0 deletions
72
LayoutTests/http/tests/security/isolate-geolocation-watch-id-per-document.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
LayoutTests/http/tests/security/resources/popup-watchid.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |