| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- /**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
- import env, { isEdge, isMac, isGecko, isSafari } from '../src/env';
- function toLowerCase( str ) {
- return str.toLowerCase();
- }
- describe( 'Env', () => {
- it( 'is an object', () => {
- expect( env ).to.be.an( 'object' );
- } );
- describe( 'isMac', () => {
- it( 'is a boolean', () => {
- expect( env.isMac ).to.be.a( 'boolean' );
- } );
- } );
- describe( 'isEdge', () => {
- it( 'is a boolean', () => {
- expect( env.isEdge ).to.be.a( 'boolean' );
- } );
- } );
- describe( 'isGecko', () => {
- it( 'is a boolean', () => {
- expect( env.isGecko ).to.be.a( 'boolean' );
- } );
- } );
- describe( 'isSafari', () => {
- it( 'is a boolean', () => {
- expect( env.isSafari ).to.be.a( 'boolean' );
- } );
- } );
- describe( 'isMac()', () => {
- it( 'returns true for macintosh UA strings', () => {
- expect( isMac( 'macintosh' ) ).to.be.true;
- expect( isMac( 'foo macintosh bar' ) ).to.be.true;
- expect( isMac( toLowerCase(
- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) ' +
- 'Chrome/61.0.3163.100 Safari/537.36'
- ) ) ).to.be.true;
- } );
- it( 'returns false for non–macintosh UA strings', () => {
- expect( isMac( '' ) ).to.be.false;
- expect( isMac( 'mac' ) ).to.be.false;
- expect( isMac( 'foo' ) ).to.be.false;
- } );
- } );
- describe( 'isEdge()', () => {
- it( 'returns true for Edge UA strings', () => {
- expect( isEdge( 'edge/12' ) ).to.be.true;
- expect( isEdge( 'foo edge/12 bar' ) ).to.be.true;
- expect( isEdge( toLowerCase(
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' +
- 'Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393'
- ) ) ).to.be.true;
- } );
- it( 'returns false for non–Edge UA strings', () => {
- expect( isEdge( '' ) ).to.be.false;
- expect( isEdge( 'mac' ) ).to.be.false;
- expect( isEdge( 'foo' ) ).to.be.false;
- expect( isEdge( 'ledge' ) ).to.be.false;
- expect( isEdge( 'foo edge bar' ) ).to.be.false;
- // Chrome
- expect( isEdge( toLowerCase(
- 'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36'
- ) ) ).to.be.false;
- // IE11
- expect( isEdge( toLowerCase(
- 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko'
- ) ) ).to.be.false;
- } );
- } );
- describe( 'isGecko()', () => {
- it( 'returns true for Firefox UA strings', () => {
- expect( isGecko( 'gecko/42' ) ).to.be.true;
- expect( isGecko( 'foo gecko/42 bar' ) ).to.be.true;
- expect( isGecko( toLowerCase(
- 'mozilla/5.0 (macintosh; intel mac os x 10.13; rv:62.0) gecko/20100101 firefox/62.0'
- ) ) ).to.be.true;
- } );
- it( 'returns false for non–Edge UA strings', () => {
- expect( isGecko( '' ) ).to.be.false;
- expect( isGecko( 'foo' ) ).to.be.false;
- expect( isGecko( 'Mozilla' ) ).to.be.false;
- // Chrome
- expect( isGecko( toLowerCase(
- 'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36'
- ) ) ).to.be.false;
- } );
- } );
- describe( 'isSafari()', () => {
- /* eslint-disable max-len */
- it( 'returns true for Safari UA strings', () => {
- expect( isSafari( toLowerCase(
- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.3 Safari/605.1.15'
- ) ) ).to.be.true;
- expect( isSafari( toLowerCase(
- 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1'
- ) ) ).to.be.true;
- } );
- it( 'returns false for non-Safari UA strings', () => {
- expect( isSafari( toLowerCase(
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36'
- ) ) ).to.be.false;
- expect( isSafari( toLowerCase(
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0'
- ) ) ).to.be.false;
- expect( isSafari( toLowerCase(
- 'Mozilla/5.0 (Linux; Android 7.1; Mi A1 Build/N2G47H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.83 Mobile Safari/537.36'
- ) ) ).to.be.false;
- } );
- /* eslint-enable max-len */
- } );
- } );
|