env.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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, isGecko } 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( 'isGecko', () => {
  26. it( 'is a boolean', () => {
  27. expect( env.isGecko ).to.be.a( 'boolean' );
  28. } );
  29. } );
  30. describe( 'isMac()', () => {
  31. it( 'returns true for macintosh UA strings', () => {
  32. expect( isMac( 'macintosh' ) ).to.be.true;
  33. expect( isMac( 'foo macintosh bar' ) ).to.be.true;
  34. expect( isMac( toLowerCase(
  35. 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) ' +
  36. 'Chrome/61.0.3163.100 Safari/537.36'
  37. ) ) ).to.be.true;
  38. } );
  39. it( 'returns false for non–macintosh UA strings', () => {
  40. expect( isMac( '' ) ).to.be.false;
  41. expect( isMac( 'mac' ) ).to.be.false;
  42. expect( isMac( 'foo' ) ).to.be.false;
  43. } );
  44. } );
  45. describe( 'isEdge()', () => {
  46. it( 'returns true for Edge UA strings', () => {
  47. expect( isEdge( 'edge/12' ) ).to.be.true;
  48. expect( isEdge( 'foo edge/12 bar' ) ).to.be.true;
  49. expect( isEdge( toLowerCase(
  50. 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' +
  51. 'Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393'
  52. ) ) ).to.be.true;
  53. } );
  54. it( 'returns false for non–Edge UA strings', () => {
  55. expect( isEdge( '' ) ).to.be.false;
  56. expect( isEdge( 'mac' ) ).to.be.false;
  57. expect( isEdge( 'foo' ) ).to.be.false;
  58. expect( isEdge( 'ledge' ) ).to.be.false;
  59. expect( isEdge( 'foo edge bar' ) ).to.be.false;
  60. // Chrome
  61. expect( isEdge( toLowerCase(
  62. 'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36'
  63. ) ) ).to.be.false;
  64. // IE11
  65. expect( isEdge( toLowerCase(
  66. 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko'
  67. ) ) ).to.be.false;
  68. } );
  69. } );
  70. describe( 'isGecko()', () => {
  71. it( 'returns true for Firefox UA strings', () => {
  72. expect( isGecko( 'gecko/42' ) ).to.be.true;
  73. expect( isGecko( 'foo gecko/42 bar' ) ).to.be.true;
  74. expect( isGecko( toLowerCase(
  75. 'mozilla/5.0 (macintosh; intel mac os x 10.13; rv:62.0) gecko/20100101 firefox/62.0'
  76. ) ) ).to.be.true;
  77. } );
  78. it( 'returns false for non–Edge UA strings', () => {
  79. expect( isGecko( '' ) ).to.be.false;
  80. expect( isGecko( 'foo' ) ).to.be.false;
  81. expect( isGecko( 'Mozilla' ) ).to.be.false;
  82. // Chrome
  83. expect( isGecko( toLowerCase(
  84. 'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36'
  85. ) ) ).to.be.false;
  86. } );
  87. } );
  88. } );