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

Commit

Permalink
Bug 942795 - [email] autoconfig XHR callbacks seem to be firing multi…
Browse files Browse the repository at this point in the history
…ple times on nightly, may produce duplicate accounts; investigate XHR event changes, switch to promises
  • Loading branch information
mcav committed Dec 12, 2013
1 parent 567dcc0 commit d3209db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion data/lib/mailapi/accountcommon.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -306,11 +306,15 @@ Autoconfigurator.prototype = {
}); });
}; };


xhr.ontimeout = xhr.onerror = function() { // Caution: don't overwrite ".onerror" twice here. Just be careful
// to only assign that once until <http://bugzil.la/949722> is fixed.

xhr.ontimeout = function() {
// The effective result is a failure to get configuration info, but make // The effective result is a failure to get configuration info, but make
// sure the status conveys that a timeout occurred. // sure the status conveys that a timeout occurred.
callback('no-config-info', null, { status: 'timeout' }); callback('no-config-info', null, { status: 'timeout' });
}; };

xhr.onerror = function() { xhr.onerror = function() {
// The effective result is a failure to get configuration info, but make // The effective result is a failure to get configuration info, but make
// sure the status conveys that a timeout occurred. // sure the status conveys that a timeout occurred.
Expand Down
16 changes: 15 additions & 1 deletion test/unit/resources/fake_xhr.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function FakeXHR() {
}; };


this.onload = null; this.onload = null;
this.onerror = null;
this.ontimeout = null; this.ontimeout = null;


this.timeout = null; this.timeout = null;
Expand All @@ -37,6 +36,21 @@ FakeXHR.prototype = {
this._args.async = async; this._args.async = async;
}, },


// To prevent regressions related to <https://bugzil.la/949722> in
// which XHRs treat .onerror like .addEventListener('error'), ensure
// that we only assign to this property once for safety:

get onerror() {
return this._onerror;
},

set onerror(fn) {
if (fn && this._onerror) {
throw new Error("onerror already set on XHR! Don't. See bug 949722.");
}
this._onerror = fn;
},

send: function() { send: function() {
this._args.timeout = this.timeout; this._args.timeout = this.timeout;
if (window.gFakeXHRListener) { if (window.gFakeXHRListener) {
Expand Down

0 comments on commit d3209db

Please sign in to comment.