Skip to content

Commit

Permalink
Bug 1077996 - Allow disabling Loop FxA support and related items (con…
Browse files Browse the repository at this point in the history
…tacts, direct calling) via loop.fxa.enabled. r=mikedeboer

--HG--
extra : rebase_source : 99b0d348b6725c35c048a491e83c65e5b5e1b13d
  • Loading branch information
mnoorenberghe committed Oct 7, 2014
1 parent 9a74490 commit eed68ae
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
7 changes: 7 additions & 0 deletions browser/components/loop/MozLoopAPI.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,13 @@ function injectLoopAPI(targetWindow) {
}
},

fxAEnabled: {
enumerable: true,
get: function() {
return MozLoopService.fxAEnabled;
},
},

logInToFxA: {
enumerable: true,
writable: true,
Expand Down
12 changes: 12 additions & 0 deletions browser/components/loop/MozLoopService.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ let gPushHandler = null;
let gHawkClient = null;
let gLocalizedStrings = null;
let gInitializeTimer = null;
let gFxAEnabled = true;
let gFxAOAuthClientPromise = null;
let gFxAOAuthClient = null;
let gFxAOAuthTokenData = null;
Expand Down Expand Up @@ -1073,6 +1074,13 @@ this.MozLoopService = {
return;
}

if (Services.prefs.getPrefType("loop.fxa.enabled") == Services.prefs.PREF_BOOL) {
gFxAEnabled = Services.prefs.getBoolPref("loop.fxa.enabled");
if (!gFxAEnabled) {
this.logOutFromFxA();
}
}

// If expiresTime is in the future then kick-off registration.
if (MozLoopServiceInternal.urlExpiryTimeIsInFuture()) {
gInitializeTimerFunc();
Expand Down Expand Up @@ -1260,6 +1268,10 @@ this.MozLoopService = {
MozLoopServiceInternal.doNotDisturb = aFlag;
},

get fxAEnabled() {
return gFxAEnabled;
},

get userProfile() {
return gFxAOAuthProfile;
},
Expand Down
10 changes: 9 additions & 1 deletion browser/components/loop/content/js/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ loop.panel = (function(_, mozL10n) {

render: function() {
var cx = React.addons.classSet;

// For now all of the menu entries require FxA so hide the whole gear if FxA is disabled.
if (!navigator.mozLoop.fxAEnabled) {
return null;
}

return (
React.DOM.div({className: "settings-menu dropdown"},
React.DOM.a({className: "button-settings", onClick: this.showDropdownMenu,
Expand All @@ -248,6 +254,7 @@ loop.panel = (function(_, mozL10n) {
__("settings_menu_item_signout") :
__("settings_menu_item_signin"),
onClick: this.handleClickAuthEntry,
displayed: navigator.mozLoop.fxAEnabled,
icon: this._isSignedIn() ? "signout" : "signin"})
)
)
Expand Down Expand Up @@ -405,7 +412,7 @@ loop.panel = (function(_, mozL10n) {
},

render: function() {
if (navigator.mozLoop.userProfile) {
if (!navigator.mozLoop.fxAEnabled || navigator.mozLoop.userProfile) {
return null;
}
return (
Expand Down Expand Up @@ -582,6 +589,7 @@ loop.panel = (function(_, mozL10n) {
return {
init: init,
UserIdentity: UserIdentity,
AuthLink: AuthLink,
AvailabilityDropdown: AvailabilityDropdown,
CallUrlResult: CallUrlResult,
PanelView: PanelView,
Expand Down
10 changes: 9 additions & 1 deletion browser/components/loop/content/js/panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ loop.panel = (function(_, mozL10n) {

render: function() {
var cx = React.addons.classSet;

// For now all of the menu entries require FxA so hide the whole gear if FxA is disabled.
if (!navigator.mozLoop.fxAEnabled) {
return null;
}

return (
<div className="settings-menu dropdown">
<a className="button-settings" onClick={this.showDropdownMenu}
Expand All @@ -248,6 +254,7 @@ loop.panel = (function(_, mozL10n) {
__("settings_menu_item_signout") :
__("settings_menu_item_signin")}
onClick={this.handleClickAuthEntry}
displayed={navigator.mozLoop.fxAEnabled}
icon={this._isSignedIn() ? "signout" : "signin"} />
</ul>
</div>
Expand Down Expand Up @@ -405,7 +412,7 @@ loop.panel = (function(_, mozL10n) {
},

render: function() {
if (navigator.mozLoop.userProfile) {
if (!navigator.mozLoop.fxAEnabled || navigator.mozLoop.userProfile) {
return null;
}
return (
Expand Down Expand Up @@ -582,6 +589,7 @@ loop.panel = (function(_, mozL10n) {
return {
init: init,
UserIdentity: UserIdentity,
AuthLink: AuthLink,
AvailabilityDropdown: AvailabilityDropdown,
CallUrlResult: CallUrlResult,
PanelView: PanelView,
Expand Down
23 changes: 23 additions & 0 deletions browser/components/loop/test/desktop-local/panel_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe("loop.panel", function() {

navigator.mozLoop = {
doNotDisturb: true,
fxAEnabled: true,
getStrings: function() {
return JSON.stringify({textContent: "fakeText"});
},
Expand Down Expand Up @@ -177,7 +178,18 @@ describe("loop.panel", function() {

sinon.assert.calledOnce(navigator.mozLoop.logInToFxA);
});

it("should be hidden if FxA is not enabled",
function() {
navigator.mozLoop.fxAEnabled = false;
var view = TestUtils.renderIntoDocument(loop.panel.AuthLink());
expect(view.getDOMNode()).to.be.null;
});

afterEach(function() {
navigator.mozLoop.fxAEnabled = true;
});
});

describe("SettingsDropdown", function() {
var view;
Expand All @@ -188,6 +200,17 @@ describe("loop.panel", function() {
navigator.mozLoop.openFxASettings = sandbox.stub();
});

afterEach(function() {
navigator.mozLoop.fxAEnabled = true;
});

it("should be hidden if FxA is not enabled",
function() {
navigator.mozLoop.fxAEnabled = false;
var view = TestUtils.renderIntoDocument(loop.panel.SettingsDropdown());
expect(view.getDOMNode()).to.be.null;
});

it("should show a signin entry when user is not authenticated",
function() {
navigator.mozLoop.loggedInToFxA = false;
Expand Down

0 comments on commit eed68ae

Please sign in to comment.