diff options
author | Pierre Ossman <ossman@cendio.se> | 2022-12-23 16:26:00 +0100 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2022-12-27 12:50:57 +0100 |
commit | 8fb30fb9dc6771ca0e0c2ca8a37d13ee37a503da (patch) | |
tree | 7c8ebb6e3a9506a77b0e08eb5c2e4be58f032bf8 | |
parent | ee5e3c5fa3f247d032d48554cb41a63315522870 (diff) | |
download | novnc-8fb30fb9dc6771ca0e0c2ca8a37d13ee37a503da.tar.gz |
Add unit tests for OS detection
-rw-r--r-- | tests/test.browser.js | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/tests/test.browser.js b/tests/test.browser.js index f80b12e..4fdc084 100644 --- a/tests/test.browser.js +++ b/tests/test.browser.js @@ -1,9 +1,69 @@ /* eslint-disable no-console */ const expect = chai.expect; -import { isSafari, isFirefox, isChrome, isChromium, isOpera, isEdge, +import { isMac, isWindows, isIOS, + isSafari, isFirefox, isChrome, isChromium, isOpera, isEdge, isGecko, isWebKit, isBlink } from '../core/util/browser.js'; +describe('OS detection', function () { + let origNavigator; + beforeEach(function () { + // window.navigator is a protected read-only property in many + // environments, so we need to redefine it whilst running these + // tests. + origNavigator = Object.getOwnPropertyDescriptor(window, "navigator"); + + Object.defineProperty(window, "navigator", {value: {}}); + }); + + afterEach(function () { + Object.defineProperty(window, "navigator", origNavigator); + }); + + it('should handle macOS', function () { + const platforms = [ + "MacIntel", + "MacPPC", + ]; + + platforms.forEach((platform) => { + navigator.platform = platform; + expect(isMac()).to.be.true; + expect(isWindows()).to.be.false; + expect(isIOS()).to.be.false; + }); + }); + + it('should handle Windows', function () { + const platforms = [ + "Win32", + "Win64", + ]; + + platforms.forEach((platform) => { + navigator.platform = platform; + expect(isMac()).to.be.false; + expect(isWindows()).to.be.true; + expect(isIOS()).to.be.false; + }); + }); + + it('should handle iOS', function () { + const platforms = [ + "iPhone", + "iPod", + "iPad", + ]; + + platforms.forEach((platform) => { + navigator.platform = platform; + expect(isMac()).to.be.false; + expect(isWindows()).to.be.false; + expect(isIOS()).to.be.true; + }); + }); +}); + describe('Browser detection', function () { let origNavigator; beforeEach(function () { |