-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add check for navigator locks (#356)
Co-authored-by: DominicGBauer <[email protected]>
- Loading branch information
1 parent
fc2e340
commit 6e58b32
Showing
11 changed files
with
380 additions
and
141 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const getNavigatorLocks = (): LockManager => { | ||
if ('locks' in navigator && navigator.locks) { | ||
return navigator.locks; | ||
} | ||
|
||
throw new Error('Navigator locks are not available in an insecure context. Use a secure context such as HTTPS or http://localhost.'); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { describe, it, expect, vi, afterEach } from 'vitest'; | ||
import { getNavigatorLocks } from '../../src/shared/navigator'; | ||
|
||
describe('getNavigationLocks', () => { | ||
afterEach(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
it('should return native navigator.locks if available', () => { | ||
const mockLocks = { | ||
request: vi.fn(), | ||
query: vi.fn(), | ||
}; | ||
|
||
vi.spyOn(navigator, 'locks', 'get').mockReturnValue(mockLocks); | ||
|
||
const result = getNavigatorLocks(); | ||
expect(result).toBe(mockLocks); | ||
}); | ||
|
||
it('should throw an error if navigator.locks is unavailable', () => { | ||
|
||
vi.spyOn(navigator, 'locks', 'get').mockReturnValue(undefined!); | ||
|
||
expect(() => getNavigatorLocks()).toThrowError('Navigator locks are not available in an insecure context. Use a secure context such as HTTPS or http://localhost.');; | ||
}); | ||
}); |
Oops, something went wrong.