Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #254 from ckeditor/t/ckeditor5-engine/1439
Browse files Browse the repository at this point in the history
Feature: Implemented `env#isGecko()`. See ckeditor/ckeditor5-engine#1439.
  • Loading branch information
Reinmar authored Oct 24, 2018
2 parents ff69bd6 + beb03af commit 53b7c94
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ const env = {
* @static
* @member {Boolean} module:utils/env~env#isEdge
*/
isEdge: isEdge( userAgent )
isEdge: isEdge( userAgent ),

/**
* Indicates that the application is running in Firefox (Gecko).
*
* @static
* @member {Boolean} module:utils/env~env#isEdge
*/
isGecko: isGecko( userAgent )
};

export default env;
Expand All @@ -55,3 +63,13 @@ export function isMac( userAgent ) {
export function isEdge( userAgent ) {
return !!userAgent.match( /edge\/(\d+.?\d*)/ );
}

/**
* Checks if User Agent represented by the string is Firefox (Gecko).
*
* @param {String} userAgent **Lowercase** `navigator.userAgent` string.
* @returns {Boolean} Whether User Agent is Firefox or not.
*/
export function isGecko( userAgent ) {
return !!userAgent.match( /gecko\/\d+/ );
}
30 changes: 29 additions & 1 deletion tests/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* For licensing, see LICENSE.md.
*/

import env, { isEdge, isMac } from '../src/env';
import env, { isEdge, isMac, isGecko } from '../src/env';

function toLowerCase( str ) {
return str.toLowerCase();
Expand All @@ -29,6 +29,12 @@ describe( 'Env', () => {
} );
} );

describe( 'isGecko', () => {
it( 'is a boolean', () => {
expect( env.isGecko ).to.be.a( 'boolean' );
} );
} );

describe( 'isMac()', () => {
it( 'returns true for macintosh UA strings', () => {
expect( isMac( 'macintosh' ) ).to.be.true;
Expand Down Expand Up @@ -75,4 +81,26 @@ describe( 'Env', () => {
) ) ).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;
} );
} );
} );

0 comments on commit 53b7c94

Please sign in to comment.