Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
Add try/catch for mozId (bug 1123849)
Browse files Browse the repository at this point in the history
  • Loading branch information
muffinresearch committed Feb 5, 2015
1 parent 33c5698 commit 0cd439f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
13 changes: 12 additions & 1 deletion public/js/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ define([
}
return false;
},
hasMozId: function(nav) {
nav = nav || navigator;
var mozId;
try {
mozId = nav.mozId;
} catch(e) {
// Handle exception due to bug 1129650
logger.error(e);
}
return typeof mozId !== 'undefined';
},
supportsNativeFxA: function(nav) {
// Until Native FxA is ready, let's not check this.
if (!settings.enableNativeFxA) {
Expand All @@ -131,7 +142,7 @@ define([
// native FxA support.
nav = nav || navigator;
var uaMatch = nav.userAgent.match(/rv:(\d{2})/);
var hasNativeFxA = this.bodyData.fxaAuthUrl && nav.mozId && uaMatch && uaMatch[1] >= 34;
var hasNativeFxA = this.bodyData.fxaAuthUrl && utils.hasMozId(nav) && uaMatch && uaMatch[1] >= 34;
return hasNativeFxA;
}
},
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,28 @@ define(['utils', 'settings'], function(utils, settings) {
mozId: {},
userAgent: 'Mozilla/5.0 (Mobile; rv:34.0) Gecko/26.0 Firefox/34.0'
}));

assert.notOk(utils.supportsNativeFxA({
userAgent: 'Mozilla/5.0 (Mobile; rv:34.0) Gecko/26.0 Firefox/34.0'
}));
});


test('hasMozID util', function() {
assert.equal(utils.hasMozId({
get mozId(){
throw new Error('AWOOGA');
}
}), false);

assert.equal(utils.hasMozId({
mozId: {}
}), true);

assert.equal(utils.hasMozId({}), false);
});


test('test native-FxA UA detection when enableNativeFxA is false', function() {
settings.enableNativeFxA = false;

Expand Down

0 comments on commit 0cd439f

Please sign in to comment.