safari device checks and tests

This commit is contained in:
Kyle Spearrin 2018-01-11 15:49:29 -05:00
parent 3743e5b409
commit 12ad4f6df8
2 changed files with 22 additions and 0 deletions

View File

@ -81,5 +81,25 @@ describe('Browser Utils Service', () => {
const browserPlatformUtilsService = new BrowserPlatformUtilsService();
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Edge);
});
it('should detect safari', () => {
Object.defineProperty(navigator, 'userAgent', {
configurable: true,
value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8'
});
const browserPlatformUtilsService = new BrowserPlatformUtilsService();
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Safari);
});
it('should detect vivaldi', () => {
Object.defineProperty(navigator, 'userAgent', {
configurable: true,
value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.97 Safari/537.36 Vivaldi/1.94.1008.40'
});
const browserPlatformUtilsService = new BrowserPlatformUtilsService();
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Vivaldi);
});
});
});

View File

@ -68,6 +68,8 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
this.deviceCache = DeviceType.Edge;
} else if (navigator.userAgent.indexOf(' Vivaldi/') !== -1) {
this.deviceCache = DeviceType.Vivaldi;
} else if (navigator.userAgent.indexOf('Safari') !== -1 && navigator.userAgent.indexOf('Chrome') === -1) {
this.deviceCache = DeviceType.Safari;
} else if ((window as any).chrome) {
this.deviceCache = DeviceType.Chrome;
}