-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix webOS 4 & 5 utility methods (#6463)
webOS platforms don't contain OS version explicitly in user agent, instead they signal it via chrome version. This PR fixes webOS 4 & 5 methods and unifies all webOS check methods.
- Loading branch information
1 parent
151a6ab
commit f3ba2a6
Showing
2 changed files
with
64 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*! @license | ||
* Shaka Player | ||
* Copyright 2016 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
describe('Platform', () => { | ||
const originalUserAgent = navigator.userAgent; | ||
|
||
// See: https://webostv.developer.lge.com/develop/specifications/web-api-and-web-engine#useragent-string | ||
// eslint-disable-next-line max-len | ||
const webOs3 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.2.1 Chrome/38.0.2125.122 Safari/537.36 WebAppManager'; | ||
// eslint-disable-next-line max-len | ||
const webOs4 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.34 Safari/537.36 WebAppManager'; | ||
// eslint-disable-next-line max-len | ||
const webOs5 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 WebAppManager'; | ||
|
||
afterEach(() => { | ||
setUserAgent(originalUserAgent); | ||
}); | ||
|
||
it('checks is webOS 3', () => { | ||
setUserAgent(webOs3); | ||
expect(shaka.util.Platform.isWebOS3()).toBe(true); | ||
setUserAgent(webOs4); | ||
expect(shaka.util.Platform.isWebOS3()).toBe(false); | ||
setUserAgent(webOs5); | ||
expect(shaka.util.Platform.isWebOS3()).toBe(false); | ||
}); | ||
|
||
it('checks is webOS 4', () => { | ||
setUserAgent(webOs3); | ||
expect(shaka.util.Platform.isWebOS4()).toBe(false); | ||
setUserAgent(webOs4); | ||
expect(shaka.util.Platform.isWebOS4()).toBe(true); | ||
setUserAgent(webOs5); | ||
expect(shaka.util.Platform.isWebOS4()).toBe(false); | ||
}); | ||
|
||
it('checks is webOS 5', () => { | ||
setUserAgent(webOs3); | ||
expect(shaka.util.Platform.isWebOS5()).toBe(false); | ||
setUserAgent(webOs4); | ||
expect(shaka.util.Platform.isWebOS5()).toBe(false); | ||
setUserAgent(webOs5); | ||
expect(shaka.util.Platform.isWebOS5()).toBe(true); | ||
}); | ||
}); | ||
|
||
/** @param {string} userAgent */ | ||
function setUserAgent(userAgent) { | ||
Object.defineProperty( | ||
navigator, 'userAgent', {value: userAgent, configurable: true}); | ||
} |