env.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import env, { isEdge, isMac } from '../src/env';
  6. function toLowerCase( str ) {
  7. return str.toLowerCase();
  8. }
  9. describe( 'Env', () => {
  10. beforeEach( () => {
  11. } );
  12. it( 'is an object', () => {
  13. expect( env ).to.be.an( 'object' );
  14. } );
  15. describe( 'isMac', () => {
  16. it( 'is a boolean', () => {
  17. expect( env.isMac ).to.be.a( 'boolean' );
  18. } );
  19. } );
  20. describe( 'isEdge', () => {
  21. it( 'is a boolean', () => {
  22. expect( env.isEdge ).to.be.a( 'boolean' );
  23. } );
  24. } );
  25. describe( 'isMac()', () => {
  26. it( 'returns true for macintosh UA strings', () => {
  27. expect( isMac( 'macintosh' ) ).to.be.true;
  28. expect( isMac( 'foo macintosh bar' ) ).to.be.true;
  29. expect( isMac( toLowerCase(
  30. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) ' +
  31. 'Chrome/61.0.3163.100 Safari/537.36'
  32. ) ) ).to.be.true;
  33. } );
  34. it( 'returns false for non–macintosh UA strings', () => {
  35. expect( isMac( '' ) ).to.be.false;
  36. expect( isMac( 'mac' ) ).to.be.false;
  37. expect( isMac( 'foo' ) ).to.be.false;
  38. } );
  39. } );
  40. describe( 'isEdge()', () => {
  41. it( 'returns true for Edge UA strings', () => {
  42. expect( isEdge( 'edge/12' ) ).to.be.true;
  43. expect( isEdge( 'foo edge/12 bar' ) ).to.be.true;
  44. expect( isEdge( toLowerCase(
  45. 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' +
  46. 'Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393'
  47. ) ) ).to.be.true;
  48. } );
  49. it( 'returns false for non–Edge UA strings', () => {
  50. expect( isEdge( '' ) ).to.be.false;
  51. expect( isEdge( 'mac' ) ).to.be.false;
  52. expect( isEdge( 'foo' ) ).to.be.false;
  53. expect( isEdge( 'ledge' ) ).to.be.false;
  54. expect( isEdge( 'foo edge bar' ) ).to.be.false;
  55. // Chrome
  56. expect( isEdge( toLowerCase(
  57. 'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36'
  58. ) ) ).to.be.false;
  59. // IE11
  60. expect( isEdge( toLowerCase(
  61. 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko'
  62. ) ) ).to.be.false;
  63. } );
  64. } );
  65. } );