Description
(ChatGPT generated plan based on the tests we have)
This plan focuses exclusively on testing the Permissions API using the geolocation
permission. By covering the scenarios below, we aim to ensure thorough coverage of how navigator.permissions.query({ name: 'geolocation' })
behaves, including event firing, revocation, and usage in both Window and Worker contexts.
1. Event Model Expansion
Goal: Verify the "change"
event for PermissionStatus
objects works correctly under multiple conditions.
-
Multiple Listeners
- Test: Call
navigator.permissions.query({ name: 'geolocation' })
once, attach two or more listeners:Then force a state transition fromstatus.addEventListener('change', /* ... */); status.onchange = /* ... */;
"prompt"
→"granted"
(or"denied"
) usingtest_driver.set_permission(...)
. - Check: Ensure all listeners fire exactly once when the state changes.
- Test: Call
-
Multi-step Transitions
- Test: With a single
PermissionStatus
, step through multiple transitions:- "prompt" to "granted"
- "granted" back to "prompt" (simulating revocation or expiry)
- "prompt" to "denied"
- Check: Each state change fires exactly one
"change"
event, and no event fires if the state is forced to remain the same.
- Test: With a single
-
Multiple Watchers
- Test: Call
navigator.permissions.query({ name: 'geolocation' })
two or three times. Store each returnedPermissionStatus
in a separate variable, and attach"change"
listeners to all. - Check: When the permission state changes, all watchers receive the
"change"
event.
- Test: Call
2. Worker Context
Goal: Ensure navigator.permissions
behaves as expected in a Worker (i.e., WorkerNavigator.permissions
).
-
Basic Query in a Worker
- Test: Spin up a dedicated or shared worker, call:
and check the returned
self.navigator.permissions.query({ name: 'notifications' })
PermissionStatus.state
. - Check: Verify it matches the expected state (e.g.,
"prompt"
,"granted"
, or"denied"
) depending on how you configuretest_driver.set_permission(...)
.
- Test: Spin up a dedicated or shared worker, call:
-
Event Handling in a Worker
- Test: Attach a
"change"
listener to the returnedPermissionStatus
, then force state changes. - Check: The
"change"
event fires in the Worker’s context (or is consistently handled according to spec if any constraints apply).
- Test: Attach a
3. Revocation & Lifetime Expiry
Goal: Confirm that reverting from "granted"
to some other state also triggers "change"
events.
-
Manual Revocation Simulation
- Test:
test_driver.set_permission({ name: 'geolocation' }, 'granted')
.- Call
navigator.permissions.query({ name: 'geolocation' })
to confirm it’s"granted"
. - Then forcibly set it to
"prompt"
or"denied"
:test_driver.set_permission({ name: 'geolocation' }, 'denied');
- Check: Confirm the
PermissionStatus
object’s"change"
event fires. Confirmstatus.state
is"denied"
after the event.
- Test:
-
(Optional) Artificial “Expiry”
- If your test environment supports an “expiry-like” scenario, you can replicate it by setting
"granted"
→"prompt"
after some time. You’d still usetest_driver.set_permission(...)
to automate that transition.
- If your test environment supports an “expiry-like” scenario, you can replicate it by setting
4. Non–Fully Active Documents
Goal: Ensure that a document losing “fully active” status stops receiving permission events and/or throws the appropriate exceptions.
-
Iframe Removal
- Test: Put a script in an iframe that calls
navigator.permissions.query({ name: 'geolocation' })
. Store thePermissionStatus
, attach a"change"
listener, then remove the iframe from the DOM. - Check: When you call
test_driver.set_permission({ name: 'geolocation' }, 'granted')
afterwards, confirm that the removed iframe’s listener does not fire.
- Test: Put a script in an iframe that calls
-
Worker in a Removed Iframe
- (If feasible) same idea, but from a Worker in that iframe.
5. WebDriver Extension Commands
Goal: Validate that the user agent’s WebDriver (or BiDi) implementation properly handles the setPermission
command for geolocation.
-
Success Path
- Test:
POST /session/:sessionId/permissions
with:{ "descriptor": { "name": "geolocation" }, "state": "granted" }
- Check that the command returns the correct success response (HTTP 200).
- Query
navigator.permissions.query({ name: 'geolocation' })
in the same session; expect"granted"
.
- Test:
-
Invalid Argument
- Test:
POST /session/:sessionId/permissions
with:{ "descriptor": { "name": "not-a-real-permission" }, "state": "granted" }
- Expect a 400 “invalid argument” error.
- Test:
-
Unsupported State
- Test: If your UA refuses certain states, confirm the same error is returned.
6. Edge Cases
-
No Change
- Test: Force the same state that’s already in effect—e.g., from
"prompt"
→"prompt"
again. - Check: No
"change"
event fires.
- Test: Force the same state that’s already in effect—e.g., from
-
Invalid
PermissionDescriptor
- Test:
navigator.permissions.query({ name: '' })
or some obviously broken descriptor. - Check: Must throw
TypeError
orDOMException("InvalidStateError")
according to the spec rules.
- Test:
7. Implementation Notes
- Automation: Most tests rely on
test_driver.set_permission({ name: 'geolocation' }, newState)
to transition the permission under test. - Cross-Browser: Since geolocation is the only permission guaranteed across major browsers, all tests should revolve around
{ name: 'geolocation' }
. - WPT Integration: Where possible, add these as new
.https.html
or.https.any.js
files in thepermissions/
folder so they can run automatically in WPT infrastructures. - User Interaction: The spec has a “prompt the user to choose” algorithm, but it’s not generally automatable. We can rely on direct state changes (like “prompt” → “granted”) via test harness commands.
Summary
These tests—focusing solely on the geolocation
permission—will expand coverage to include:
- More thorough event model checks (multiple listeners, multiple
PermissionStatus
objects). - Worker usage tests.
- Revocation and lifetime-like expiration scenarios.
- Proper handling of non–fully active documents.
- Validation of the new WebDriver extension command for permissions.
- Edge case and error-condition testing.
By implementing these scenarios, we achieve a much more robust conformance suite for the Permissions spec as it applies to geolocation.