Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add layout test coverage for the Permissions API
https://bugs.webkit.org/show_bug.cgi?id=245239 Reviewed by Sihui Liu. Previously, Permissions API functionality was only being tested in macOS wk2 because the permission state being queried for was that of the Notifications API, which is available only on macOS. This patch adds test coverage for all wk2 platforms by querying for the permission state of the Geolocation API, which is available on all wk2 platforms. * LayoutTests/http/tests/permissions/permission-status-onchange-event-dedicated-worker-expected.txt: Renamed from LayoutTests/http/tests/permissions/worker-permission-status-onchange-event-expected.txt. * LayoutTests/http/tests/permissions/permission-status-onchange-event-dedicated-worker.html: Renamed from LayoutTests/http/tests/permissions/worker-permission-status-onchange-event.html. * LayoutTests/http/tests/permissions/permission-status-onchange-event-dedicated-worker.js: Renamed from LayoutTests/http/tests/permissions/worker-permission-status-onchange-event.js. (onmessage): * LayoutTests/http/tests/permissions/permission-status-onchange-event-service-worker-expected.txt: Copied from LayoutTests/http/tests/permissions/service-worker-permission-status-onchange-event-expected.txt. * LayoutTests/http/tests/permissions/permission-status-onchange-event-service-worker.html: Renamed from LayoutTests/http/tests/permissions/service-worker-permission-status-onchange-event.html. * LayoutTests/http/tests/permissions/permission-status-onchange-event-service-worker.js: Renamed from LayoutTests/http/tests/permissions/service-worker-permission-status-onchange-event.js. (self.onmessage): * LayoutTests/http/tests/permissions/permission-status-onchange-event-shared-worker-expected.txt: Renamed from LayoutTests/http/tests/permissions/shared-worker-permission-status-onchange-event-expected.txt. * LayoutTests/http/tests/permissions/permission-status-onchange-event-shared-worker.html: Renamed from LayoutTests/http/tests/permissions/shared-worker-permission-status-onchange-event.html. * LayoutTests/http/tests/permissions/permission-status-onchange-event-shared-worker.js: Renamed from LayoutTests/http/tests/permissions/shared-worker-permission-status-onchange-event.js. (port.onmessage): (onconnect): * LayoutTests/http/tests/permissions/permission-status-onchange-event-window-expected.txt: Added. * LayoutTests/http/tests/permissions/permission-status-onchange-event-window.html: Added. * LayoutTests/http/tests/permissions/permissions-query-dedicated-workers-expected.txt: Copied from LayoutTests/http/tests/permissions/service-worker-permission-status-onchange-event-expected.txt. * LayoutTests/http/tests/permissions/permissions-query-dedicated-workers.html: Added. * LayoutTests/http/tests/permissions/permissions-query-dedicated-workers.js: Added. (onmessage): * LayoutTests/http/tests/permissions/permissions-query-service-worker-expected.txt: Copied from LayoutTests/http/tests/permissions/service-worker-permission-status-onchange-event-expected.txt. * LayoutTests/http/tests/permissions/permissions-query-service-worker.html: Added. * LayoutTests/http/tests/permissions/permissions-query-service-worker.js: Added. (self.onmessage): * LayoutTests/http/tests/permissions/permissions-query-shared-worker-expected.txt: Renamed from LayoutTests/http/tests/permissions/service-worker-permission-status-onchange-event-expected.txt. * LayoutTests/http/tests/permissions/permissions-query-shared-worker.html: Added. * LayoutTests/http/tests/permissions/permissions-query-shared-worker.js: Added. (port.onmessage): (onconnect): * LayoutTests/http/tests/permissions/permissions-query-window-expected.txt: Added. * LayoutTests/http/tests/permissions/permissions-query-window.html: Added. * Source/WebKit/UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::queryPermission): Canonical link: https://commits.webkit.org/254562@main
- Loading branch information
1 parent
8c822fa
commit 4a97e14
Showing
23 changed files
with
361 additions
and
15 deletions.
There are no files selected for viewing
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
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
File renamed without changes.
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
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
File renamed without changes.
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
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
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
LayoutTests/http/tests/permissions/permission-status-onchange-event-window-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,12 @@ | ||
This test checks that the Permissions API on-change event works in window contexts. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS permissionStatusState is "prompt" | ||
PASS permissionStatusState is "granted" | ||
PASS onChangeCalled became true | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
34 changes: 34 additions & 0 deletions
34
LayoutTests/http/tests/permissions/permission-status-onchange-event-window.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,34 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="/resources/js-test-pre.js"></script> | ||
<script src="/resources/notifications-test-pre.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
|
||
description("This test checks that the Permissions API on-change event works in window contexts.") | ||
|
||
jsTestIsAsync = true; | ||
|
||
navigator.permissions.query({ name: "geolocation" }).then((permissionStatus)=>{ | ||
permissionStatusState = permissionStatus.state; | ||
shouldBeEqualToString("permissionStatusState", "prompt"); | ||
|
||
onChangeCalled = false; | ||
permissionStatus.onchange = () => { | ||
permissionStatusState = permissionStatus.state; | ||
shouldBeEqualToString("permissionStatusState", "granted"); | ||
onChangeCalled = true; | ||
}; | ||
|
||
testRunner.setGeolocationPermission(true); | ||
shouldBecomeEqual("onChangeCalled", "true", () => { | ||
finishJSTest(); | ||
}); | ||
}); | ||
|
||
</script> | ||
<script src="/resources/js-test-post.js"></script> | ||
</body> | ||
</html> |
15 changes: 15 additions & 0 deletions
15
LayoutTests/http/tests/permissions/permissions-query-dedicated-workers-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,15 @@ | ||
This test checks that Permissions::query() works for dedicated workers | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS message.data is "prompt" | ||
PASS receivedPostMessageResponse became true | ||
PASS message.data is "granted" | ||
PASS receivedPostMessageResponse became true | ||
PASS message.data is "prompt" | ||
PASS receivedPostMessageResponse became true | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
60 changes: 60 additions & 0 deletions
60
LayoutTests/http/tests/permissions/permissions-query-dedicated-workers.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,60 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="/resources/js-test-pre.js"></script> | ||
<script src="/resources/notifications-test-pre.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
|
||
description("This test checks that Permissions::query() works for dedicated workers") | ||
|
||
jsTestIsAsync = true; | ||
|
||
var expectedData = null; | ||
var receivedPostMessageResponse = true; | ||
|
||
var worker = new Worker('permissions-query-dedicated-workers.js'); | ||
worker.onmessage = function(message) { | ||
window.message = message; | ||
shouldBeEqualToString("message.data", expectedData); | ||
receivedPostMessageResponse = true; | ||
} | ||
|
||
async function defaultTest() | ||
{ | ||
receivedPostMessageResponse = false; | ||
expectedData = "prompt"; | ||
worker.postMessage(1); | ||
await shouldBecomeEqual("receivedPostMessageResponse", "true"); | ||
} | ||
|
||
async function grantTest() | ||
{ | ||
receivedPostMessageResponse = false; | ||
expectedData = "granted"; | ||
testRunner.setGeolocationPermission(true); | ||
worker.postMessage(2); | ||
await shouldBecomeEqual("receivedPostMessageResponse", "true"); | ||
} | ||
|
||
async function denyTest() | ||
{ | ||
receivedPostMessageResponse = false; | ||
expectedData = "prompt"; | ||
testRunner.setGeolocationPermission(false); | ||
worker.postMessage(3); | ||
await shouldBecomeEqual("receivedPostMessageResponse", "true"); | ||
} | ||
|
||
(async function () { | ||
await defaultTest(); | ||
await grantTest(); | ||
await denyTest(); | ||
finishJSTest(); | ||
})(); | ||
|
||
</script> | ||
<script src="/resources/js-test-post.js"></script> | ||
</body> | ||
</html> |
5 changes: 5 additions & 0 deletions
5
LayoutTests/http/tests/permissions/permissions-query-dedicated-workers.js
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,5 @@ | ||
onmessage = function(e) { | ||
navigator.permissions.query({ name: "geolocation" }).then((status) => { | ||
postMessage(status.state); | ||
}); | ||
} |
15 changes: 15 additions & 0 deletions
15
LayoutTests/http/tests/permissions/permissions-query-service-worker-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,15 @@ | ||
This test checks that Permissions::query() works for service workers | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS message.data is "prompt" | ||
PASS receivedPostMessageResponse became true | ||
PASS message.data is "granted" | ||
PASS receivedPostMessageResponse became true | ||
PASS message.data is "prompt" | ||
PASS receivedPostMessageResponse became true | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
66 changes: 66 additions & 0 deletions
66
LayoutTests/http/tests/permissions/permissions-query-service-worker.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,66 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="/resources/js-test-pre.js"></script> | ||
<script src="/resources/notifications-test-pre.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
|
||
description("This test checks that Permissions::query() works for service workers") | ||
|
||
jsTestIsAsync = true; | ||
|
||
var expectedData = null; | ||
var receivedPostMessageResponse = true; | ||
|
||
navigator.serviceWorker.register('permissions-query-service-worker.js'); | ||
navigator.serviceWorker.addEventListener('message', (message) => { | ||
window.message = message; | ||
shouldBeEqualToString("message.data", expectedData); | ||
receivedPostMessageResponse = true; | ||
}); | ||
|
||
async function defaultTest() | ||
{ | ||
receivedPostMessageResponse = false; | ||
expectedData = "prompt"; | ||
navigator.serviceWorker.ready.then((registration) => { | ||
registration.active.postMessage(1); | ||
}); | ||
await shouldBecomeEqual("receivedPostMessageResponse", "true"); | ||
} | ||
|
||
async function grantTest() | ||
{ | ||
receivedPostMessageResponse = false; | ||
expectedData = "granted"; | ||
testRunner.setGeolocationPermission(true); | ||
navigator.serviceWorker.ready.then((registration) => { | ||
registration.active.postMessage(2); | ||
}); | ||
await shouldBecomeEqual("receivedPostMessageResponse", "true"); | ||
} | ||
|
||
async function denyTest() | ||
{ | ||
receivedPostMessageResponse = false; | ||
expectedData = "prompt"; | ||
testRunner.setGeolocationPermission(false); | ||
navigator.serviceWorker.ready.then((registration) => { | ||
registration.active.postMessage(3); | ||
}); | ||
await shouldBecomeEqual("receivedPostMessageResponse", "true"); | ||
} | ||
|
||
(async function () { | ||
await defaultTest(); | ||
await grantTest(); | ||
await denyTest(); | ||
finishJSTest(); | ||
})(); | ||
|
||
</script> | ||
<script src="/resources/js-test-post.js"></script> | ||
</body> | ||
</html> |
5 changes: 5 additions & 0 deletions
5
LayoutTests/http/tests/permissions/permissions-query-service-worker.js
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,5 @@ | ||
self.onmessage = (event) => { | ||
navigator.permissions.query({ name: "geolocation" }).then((status) => { | ||
event.source.postMessage(status.state); | ||
}); | ||
}; |
15 changes: 15 additions & 0 deletions
15
LayoutTests/http/tests/permissions/permissions-query-shared-worker-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,15 @@ | ||
This test checks that Permissions::query() works for shared workers | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS message.data is "prompt" | ||
PASS receivedPostMessageResponse became true | ||
PASS message.data is "granted" | ||
PASS receivedPostMessageResponse became true | ||
PASS message.data is "prompt" | ||
PASS receivedPostMessageResponse became true | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
Oops, something went wrong.