forked from shaka-project/shaka-player
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable uninstalling PatchedMediaKeysApple (shaka-project#4471)
Close shaka-project#4469
- Loading branch information
1 parent
83a420f
commit 7166f0c
Showing
5 changed files
with
188 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ Jun Hong Chong <[email protected]> | |
Jürgen Kartnaller <[email protected]> | ||
JW Player <*@jwplayer.com> | ||
Lucas Gabriel Sánchez <[email protected]> | ||
Martin Stark <[email protected]> | ||
Matthias Van Parijs <[email protected]> | ||
Mattias Wadman <[email protected]> | ||
Mohamed Rashid <[email protected]> | ||
|
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 |
---|---|---|
|
@@ -73,6 +73,7 @@ Jun Hong Chong <[email protected]> | |
Jürgen Kartnaller <[email protected]> | ||
Leandro Ribeiro Moreira <[email protected]> | ||
Lucas Gabriel Sánchez <[email protected]> | ||
Martin Stark <[email protected]> | ||
Matias Russitto <[email protected]> | ||
Matthias Van Parijs <[email protected]> | ||
Mattias Wadman <[email protected]> | ||
|
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,124 @@ | ||
describe('PatchedMediaKeys_Apple', () => { | ||
const PatchedMediaKeysApple = shaka.polyfill.PatchedMediaKeysApple; | ||
let originalMediaKeys; | ||
let originalHTMLMediaElementPrototypeSetMediaKeys; | ||
let originalWindowMediaKeys; | ||
let originalWindowMediaKeySystemAccess; | ||
let originalNavigatorRequestMediaKeySystemAccess; | ||
let originalHTMLSVideoElement; | ||
let originalWebKitMediaKeys; | ||
|
||
beforeEach(() => { | ||
originalHTMLSVideoElement = window.HTMLVideoElement; | ||
originalWebKitMediaKeys = window.WebKitMediaKeys; | ||
|
||
Object.defineProperty(window, | ||
'HTMLVideoElement', {value: {}, configurable: true, writable: true}); | ||
Object.defineProperty(window, | ||
'WebKitMediaKeys', {value: {}, configurable: true, writable: true}); | ||
|
||
originalMediaKeys = /** @type {!Object} */ ( | ||
Object.getOwnPropertyDescriptor( | ||
// eslint-disable-next-line no-restricted-syntax | ||
HTMLMediaElement.prototype, 'mediaKeys', | ||
) | ||
); | ||
|
||
// eslint-disable-next-line no-restricted-syntax | ||
originalHTMLMediaElementPrototypeSetMediaKeys = HTMLMediaElement | ||
.prototype.setMediaKeys; | ||
originalWindowMediaKeys = window.MediaKeys; | ||
originalWindowMediaKeySystemAccess = window.MediaKeySystemAccess; | ||
originalNavigatorRequestMediaKeySystemAccess = navigator | ||
.requestMediaKeySystemAccess; | ||
|
||
delete window.shakaMediaKeysPolyfill; | ||
}); | ||
|
||
afterEach(() => { | ||
window.HTMLVideoElement = originalHTMLSVideoElement; | ||
window.WebKitMediaKeys = originalWebKitMediaKeys; | ||
|
||
Object.defineProperty( | ||
// eslint-disable-next-line no-restricted-syntax | ||
HTMLMediaElement.prototype, | ||
'mediaKeys', | ||
originalMediaKeys, | ||
); | ||
|
||
// eslint-disable-next-line no-restricted-syntax | ||
HTMLMediaElement | ||
.prototype.setMediaKeys = | ||
originalHTMLMediaElementPrototypeSetMediaKeys; | ||
window.MediaKeys = originalWindowMediaKeys; | ||
window.MediaKeySystemAccess = originalWindowMediaKeySystemAccess; | ||
navigator | ||
.requestMediaKeySystemAccess = | ||
originalNavigatorRequestMediaKeySystemAccess; | ||
|
||
delete window.shakaMediaKeysPolyfill; | ||
}); | ||
|
||
describe('install', () => { | ||
it('should override browser globals', () => { | ||
shaka.polyfill.PatchedMediaKeysApple.install(); | ||
|
||
expect(shaka.polyfill.PatchedMediaKeysApple.enableUninstall) | ||
.toBe(undefined); | ||
|
||
expect( | ||
originalHTMLMediaElementPrototypeSetMediaKeys, | ||
).not.toEqual( | ||
// eslint-disable-next-line no-restricted-syntax | ||
HTMLMediaElement.prototype.setMediaKeys, | ||
); | ||
|
||
expect( | ||
Object.getOwnPropertyDescriptor( | ||
// eslint-disable-next-line no-restricted-syntax | ||
HTMLMediaElement.prototype, 'mediaKeys', | ||
).value, | ||
).toBeNull(); | ||
|
||
// eslint-disable-next-line no-restricted-syntax | ||
expect(HTMLMediaElement.prototype.setMediaKeys) | ||
.toEqual(PatchedMediaKeysApple.setMediaKeys); | ||
|
||
expect(window.MediaKeys).toEqual(PatchedMediaKeysApple.MediaKeys); | ||
expect(window.MediaKeySystemAccess) | ||
.toEqual(PatchedMediaKeysApple.MediaKeySystemAccess); | ||
expect(navigator.requestMediaKeySystemAccess) | ||
.toEqual(PatchedMediaKeysApple.requestMediaKeySystemAccess); | ||
expect(window.shakaMediaKeysPolyfill).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('uninstall', () => { | ||
it('should restore browser globals', () => { | ||
shaka.polyfill.PatchedMediaKeysApple.install(true); | ||
|
||
expect(shaka.polyfill.PatchedMediaKeysApple.enableUninstall) | ||
.toBe(true); | ||
|
||
shaka.polyfill.PatchedMediaKeysApple.uninstall(); | ||
|
||
expect( | ||
Object.getOwnPropertyDescriptor( | ||
// eslint-disable-next-line no-restricted-syntax | ||
HTMLMediaElement.prototype, 'mediaKeys', | ||
).value, | ||
).not.toBeNull(); | ||
|
||
// eslint-disable-next-line no-restricted-syntax | ||
expect(HTMLMediaElement.prototype.setMediaKeys) | ||
.toEqual(originalHTMLMediaElementPrototypeSetMediaKeys); | ||
|
||
expect(window.MediaKeys).toEqual(originalWindowMediaKeys); | ||
expect(window.MediaKeySystemAccess) | ||
.toEqual(originalWindowMediaKeySystemAccess); | ||
expect(navigator.requestMediaKeySystemAccess) | ||
.toEqual(originalNavigatorRequestMediaKeySystemAccess); | ||
expect(window.shakaMediaKeysPolyfill).toBe(false); | ||
}); | ||
}); | ||
}); |