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

Commit 53b7c94

Browse files
authored
Merge pull request #254 from ckeditor/t/ckeditor5-engine/1439
Feature: Implemented `env#isGecko()`. See ckeditor/ckeditor5-engine#1439.
2 parents ff69bd6 + beb03af commit 53b7c94

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/env.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ const env = {
3131
* @static
3232
* @member {Boolean} module:utils/env~env#isEdge
3333
*/
34-
isEdge: isEdge( userAgent )
34+
isEdge: isEdge( userAgent ),
35+
36+
/**
37+
* Indicates that the application is running in Firefox (Gecko).
38+
*
39+
* @static
40+
* @member {Boolean} module:utils/env~env#isEdge
41+
*/
42+
isGecko: isGecko( userAgent )
3543
};
3644

3745
export default env;
@@ -55,3 +63,13 @@ export function isMac( userAgent ) {
5563
export function isEdge( userAgent ) {
5664
return !!userAgent.match( /edge\/(\d+.?\d*)/ );
5765
}
66+
67+
/**
68+
* Checks if User Agent represented by the string is Firefox (Gecko).
69+
*
70+
* @param {String} userAgent **Lowercase** `navigator.userAgent` string.
71+
* @returns {Boolean} Whether User Agent is Firefox or not.
72+
*/
73+
export function isGecko( userAgent ) {
74+
return !!userAgent.match( /gecko\/\d+/ );
75+
}

tests/env.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* For licensing, see LICENSE.md.
44
*/
55

6-
import env, { isEdge, isMac } from '../src/env';
6+
import env, { isEdge, isMac, isGecko } from '../src/env';
77

88
function toLowerCase( str ) {
99
return str.toLowerCase();
@@ -29,6 +29,12 @@ describe( 'Env', () => {
2929
} );
3030
} );
3131

32+
describe( 'isGecko', () => {
33+
it( 'is a boolean', () => {
34+
expect( env.isGecko ).to.be.a( 'boolean' );
35+
} );
36+
} );
37+
3238
describe( 'isMac()', () => {
3339
it( 'returns true for macintosh UA strings', () => {
3440
expect( isMac( 'macintosh' ) ).to.be.true;
@@ -75,4 +81,26 @@ describe( 'Env', () => {
7581
) ) ).to.be.false;
7682
} );
7783
} );
84+
85+
describe( 'isGecko()', () => {
86+
it( 'returns true for Firefox UA strings', () => {
87+
expect( isGecko( 'gecko/42' ) ).to.be.true;
88+
expect( isGecko( 'foo gecko/42 bar' ) ).to.be.true;
89+
90+
expect( isGecko( toLowerCase(
91+
'mozilla/5.0 (macintosh; intel mac os x 10.13; rv:62.0) gecko/20100101 firefox/62.0'
92+
) ) ).to.be.true;
93+
} );
94+
95+
it( 'returns false for non–Edge UA strings', () => {
96+
expect( isGecko( '' ) ).to.be.false;
97+
expect( isGecko( 'foo' ) ).to.be.false;
98+
expect( isGecko( 'Mozilla' ) ).to.be.false;
99+
100+
// Chrome
101+
expect( isGecko( toLowerCase(
102+
'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36'
103+
) ) ).to.be.false;
104+
} );
105+
} );
78106
} );

0 commit comments

Comments
 (0)