Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Bug 1068356 - Authentication screen remains indefinitely when long ta…
Browse files Browse the repository at this point in the history
…pping on the homescreen button in the FxAccount login proccess. r=alive

Conflicts:
	apps/system/js/fxa_ui.js
	apps/system/js/mobileid_dialog.js
  • Loading branch information
ferjm authored and rvandermeulen committed Sep 25, 2014
1 parent 87ee41f commit 95a5168
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 4 deletions.
6 changes: 5 additions & 1 deletion apps/system/js/fxa_ui.js
Expand Up @@ -5,6 +5,7 @@
var FxAccountsUI = {
dialog: null,
panel: null,
iframe: null,
onerrorCb: null,
onsuccessCb: null,

Expand Down Expand Up @@ -62,8 +63,11 @@ var FxAccountsUI = {
},

// Method for reseting the panel.
reset: function fxa_ui_reset() {
reset: function fxa_ui_reset(reason) {
this.panel.innerHTML = '';
if (reason == 'home' || reason == 'holdhome') {
this.onerrorCb && this.onerrorCb('DIALOG_CLOSED_BY_USER');
}
this.onerrorCb = null;
this.onsuccessCb = null;
},
Expand Down
11 changes: 9 additions & 2 deletions apps/system/js/mobileid_dialog.js
Expand Up @@ -104,8 +104,7 @@
this.panel.innerHTML = '';
this.panel.classList.remove('closing');
this.panel.classList.remove('opening');
this.panel.parentNode.removeChild(this.panel);
this.panel = null;
this.reset();

if (typeof onClosed === 'function') {
onClosed();
Expand All @@ -123,6 +122,14 @@
}
};

MobileIdDialog.prototype.reset = function mobileid_reset() {
if (!this.panel) {
return;
}
this.panel.parentNode.removeChild(this.panel);
this.panel = null;
};

exports.MobileIdDialog = MobileIdDialog;

}(window));
6 changes: 5 additions & 1 deletion apps/system/js/mobileid_manager.js
Expand Up @@ -54,7 +54,11 @@ var MobileIdManager = {
},

cleanup: function mobileid_cleanup() {
this.dialog = null;
if (this.dialog) {
this.dialog.reset();
this.dialog = null;
}

if (this.chromeEventId) {
// There's a pending content requests, so we need to notify about
// the flow cancelation
Expand Down
112 changes: 112 additions & 0 deletions apps/system/test/unit/fxa_ui_test.js
@@ -0,0 +1,112 @@
'use strict';

/* global FxAccountsUI */

require('/js/fxa_ui.js');

suite('system/FxAccountsUI', function() {
setup(function() {
window.FxAccountsDialog = function() {};
window.FxAccountsDialog.prototype = {
getView: function() {
return {
removeChild: function() {}
};
}
};
});

teardown(function() {
window.FxAccountsDialog = null;
});

suite('Before init', function() {
test('Should not have a dialog', function() {
assert.isNull(FxAccountsUI.dialog);
});

test('Should not have a panel', function() {
assert.isNull(FxAccountsUI.panel);
});

test('Should not have an iframe', function() {
assert.isNull(FxAccountsUI.iframe);
});
});

suite('After init', function() {
setup(function() {
FxAccountsUI.init();
});

test('Should not have a dialog', function() {
assert.ok(FxAccountsUI.dialog);
});

test('Should not have a panel', function() {
assert.ok(FxAccountsUI.panel);
});

test('Should not have an iframe', function() {
assert.ok(FxAccountsUI.iframe);
});
});

suite('Reset', function() {
var onerrorReason;

setup(function() {
FxAccountsUI.onerrorCb = function(reason) {
onerrorReason = reason;
};
});

suite('Reset "home" reason', function() {
setup(function() {
FxAccountsUI.reset('home');
});

teardown(function() {
onerrorReason = null;
});

test('onerror should be called on reset with "home" reason', function() {
assert.equal(onerrorReason, 'DIALOG_CLOSED_BY_USER');
assert.isNull(FxAccountsUI.onerrorCb);
});
});

suite('Reset "holdhome" reason', function() {
setup(function() {
FxAccountsUI.reset('holdhome');
});

teardown(function() {
onerrorReason = null;
});

test('onerror should be called on reset with "holdhome" reason',
function() {
assert.equal(onerrorReason, 'DIALOG_CLOSED_BY_USER');
assert.isNull(FxAccountsUI.onerrorCb);
});
});

suite('Reset "whatever" reason', function() {
setup(function() {
FxAccountsUI.reset('whatever');
});

teardown(function() {
onerrorReason = null;
});

test('onerror should be called on reset with "whatever" reason',
function() {
assert.isNull(onerrorReason);
assert.isNull(FxAccountsUI.onerrorCb);
});
});

});
});
6 changes: 6 additions & 0 deletions apps/system/test/unit/mobileid_manager_test.js
Expand Up @@ -79,6 +79,9 @@ suite('MobileID Manager', function() {
var chromeEventId = 'fakeId';

MobileIdManager.dialog = {
reset: function() {
},

dispatchEvent: function(eventName, data) {
MobileIdManager.dialog = null;
done();
Expand All @@ -87,12 +90,15 @@ suite('MobileID Manager', function() {

window.applications.mRegisterMockApp(appManifest);

var spy = this.sinon.spy(MobileIdManager.dialog, 'reset');
this.sinon.stub(MobileIdManager, 'sendContentEvent',
function(eventName, data) {
assert.equal(eventName, CONTENT_EVENT);
assert.equal(data.error, 'DIALOG_CLOSED_BY_USER');
assert.equal(MobileIdManager.chromeEventId, chromeEventId);
window.applications.mUnregisterMockApp(appManifest);
assert.ok(spy.calledOnce);
spy.restore();
done();
});

Expand Down

0 comments on commit 95a5168

Please sign in to comment.