-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[testdriver] extend testdriver with geolocation emulation #52128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
20ff6b6
[testdriver] extend testdriver with geolocation emulation
sadym-chromium 4fca376
test
sadym-chromium 563efad
text
sadym-chromium 3d66c91
expectation
sadym-chromium 4d21f8e
fix mypy
sadym-chromium 9c13236
fix expectation path
sadym-chromium File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...metadata/infrastructure/testdriver/bidi/emulation/set_geolocation_override.https.html.ini
This file contains hidden or 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,3 @@ | ||
| [set_geolocation_override.https.html] | ||
| expected: | ||
| if product != "chrome": ERROR |
71 changes: 71 additions & 0 deletions
71
infrastructure/testdriver/bidi/emulation/set_geolocation_override.https.html
This file contains hidden or 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,71 @@ | ||
| <!DOCTYPE html> | ||
| <meta charset="utf-8"/> | ||
| <title>TestDriver bidi.emulation.set_geolocation_override method</title> | ||
| <script src="/resources/testharness.js"></script> | ||
| <script src="/resources/testharnessreport.js"></script> | ||
| <script src="/resources/testdriver.js?feature=bidi"></script> | ||
| <script src="/resources/testdriver-vendor.js"></script> | ||
|
|
||
| <script> | ||
| promise_setup(async () => { | ||
| // Ensure permission is granted before proceeding. | ||
| await test_driver.bidi.permissions.set_permission({ | ||
| descriptor: {name: "geolocation"}, | ||
| state: "granted", | ||
| }); | ||
|
|
||
| // Ensure any previously set geolocation emulations are cleared. | ||
| await test_driver.bidi.emulation.set_geolocation_override( | ||
| {coordinates: null}); | ||
| }); | ||
|
|
||
| /** Get the current geolocation or error */ | ||
| function get_current_geolocation() { | ||
| return new Promise( | ||
| resolve => window.navigator.geolocation.getCurrentPosition( | ||
| position => resolve(position.coords.toJSON()), | ||
| error => resolve({code: error.code, message: error.message}), | ||
| // Fail fast if geolocation is not available. | ||
| {timeout: 500} | ||
| )) | ||
| } | ||
|
|
||
| /** Asserts that relevant coordinate properties match */ | ||
| function assert_coordinates_match(actual, expected) { | ||
| for (const key in expected) { | ||
| assert_equals(actual[key], expected[key], | ||
| `"${key}" should match the expected value ${expected[key]}`); | ||
| } | ||
| } | ||
|
|
||
| const SOME_COORDINATES = { | ||
| latitude: 52.51, | ||
| longitude: 13.39, | ||
| accuracy: 0.5, | ||
| altitude: 34, | ||
| altitudeAccuracy: 0.75, | ||
| heading: 180, | ||
| speed: 2.77 | ||
| }; | ||
|
|
||
| promise_test(async (t) => { | ||
| // Get the initial geolocation (might be error). | ||
| const initial_coords = await get_current_geolocation(); | ||
|
|
||
| // Set the geolocation override | ||
| await test_driver.bidi.emulation.set_geolocation_override({ | ||
| coordinates: SOME_COORDINATES | ||
| }); | ||
|
|
||
| // Get the geolocation after setting the override. | ||
| const coords = await get_current_geolocation(); | ||
| // Assert the coordinates match the override. | ||
| assert_coordinates_match(coords, SOME_COORDINATES); | ||
|
|
||
| // Clear the geolocation override. | ||
| await test_driver.bidi.emulation.set_geolocation_override( | ||
| {coordinates: null}); | ||
| // Assert coordinates are set to the original value. | ||
| assert_coordinates_match(await get_current_geolocation(), initial_coords); | ||
| }, "emulate geolocation and clear override"); | ||
| </script> | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.