-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add possibility to handle access geolocation dialog(closes #3224)…
… (#7791) ## Purpose #3224 In some cases, you need to handle access geolocation dialog and provide a corresponding result. ## Approach The geolocation window can be invoked when the user call [window.navigator.geolocation.getCurrentPosition](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/getCurrentPosition) or watchPosition. We cannot emulate watchPosition method because it invokes callbacks on changing user geolocation. So, this PR only handles getCurrentPosition method. When this method is called on the page for the first time, the Geolocation access dialog must be shown. All subsequent calls will lead to returning geolocation in the case when the user allowed access, or an error in the case when the user denied access. This handler allows you to return a geolocation or an error when calling getCurrentPosition. If an instance of an Error object was returned, the failCallback function will be called with that error. If any other value is returned, then successCallback will be called with that value. Since this dialog is only shown the first time getCurrentPosition is called, the history contains only one record per URL. ## API ```js // Test test('Expected geolocation object and geolocation error returned after an action', async t => { await t .setNativeDialogHandler((type) => { if (type === 'geolocation') return { timestamp: 12356, coords: {} }; return null; }); .click('#buttonGeo') .setNativeDialogHandler((type) => { if (type !== 'geolocation') return null; const err = new Error('Some error'); err.code = 1; return err; }) .click('#buttonGeo'); const history = await t.getNativeDialogHistory(); // NOTE: Only one record will be added to the history, since dialog appears only on the first geolocation request await t.expect(history).eql([{ type: 'geolocation', url: pageUrl }]); }); // Aplication code: function successCallback(geolocation) { console.log(geolocation) // { timestamp: 12356, coords: {} } } function failCallback(err) { console.log(err.message); // "Some error" console.log(err.code); // 1 } function onGeoButtonClick () { window.navigator.geolocation.getCurrentPosition(successCallback, failCallback) } ``` ## References #3224 ## Pre-Merge TODO - [x] Write tests for your proposed changes - [x] Make sure that existing tests do not fail
- Loading branch information
1 parent
bf58d0c
commit faed539
Showing
6 changed files
with
134 additions
and
43 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
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
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