Bug 1120748: Resolve intermittent failure of browser_ssl_error_reports.js (r=ttaubert)

This commit is contained in:
Mark Goodwin 2015-04-15 15:49:51 +01:00
parent 17716f5ecb
commit f715289309

View File

@ -20,63 +20,32 @@ add_task(function* test_send_report_manual_nocert() {
// creates a promise of the message in an error page
function createNetworkErrorMessagePromise(aBrowser) {
let progressListener;
let promise = new Promise(function(resolve, reject) {
// Error pages do not fire "load" events, so use a progressListener.
let originalDocumentURI = aBrowser.contentDocument.documentURI;
progressListener = {
onLocationChange: function(aWebProgress, aRequest, aLocation, aFlags) {
// Make sure nothing other than an error page is loaded.
if (!(aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_ERROR_PAGE)) {
reject("location change was not to an error page");
}
},
let loadedListener = function() {
let doc = aBrowser.contentDocument;
onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) {
let doc = aBrowser.contentDocument;
if (doc && doc.getElementById("reportCertificateError")) {
let documentURI = doc.documentURI;
if (doc && doc.getElementById("reportCertificateError")) {
// Wait until the documentURI changes (from about:blank) this should
// be the error page URI.
let documentURI = doc.documentURI;
if (documentURI == originalDocumentURI) {
return;
}
aWebProgress.removeProgressListener(progressListener,
Ci.nsIWebProgress.NOTIFY_LOCATION |
Ci.nsIWebProgress.NOTIFY_STATE_REQUEST);
let matchArray = /about:neterror\?.*&d=([^&]*)/.exec(documentURI);
if (!matchArray) {
reject("no network error message found in URI")
aBrowser.removeEventListener("DOMContentLoaded", loadedListener, true);
let matchArray = /about:neterror\?.*&d=([^&]*)/.exec(documentURI);
if (!matchArray) {
reject("no network error message found in URI");
return;
}
let errorMsg = matchArray[1];
resolve(decodeURIComponent(errorMsg));
}
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener,
Ci.nsISupportsWeakReference])
let errorMsg = matchArray[1];
resolve(decodeURIComponent(errorMsg));
}
};
aBrowser.addProgressListener(progressListener,
Ci.nsIWebProgress.NOTIFY_LOCATION |
Ci.nsIWebProgress.NOTIFY_STATE_REQUEST);
aBrowser.addEventListener("DOMContentLoaded", loadedListener, true);
});
// Ensure the weak progress listener is kept alive as long as the promise.
createNetworkErrorMessagePromise.listeners.set(promise, progressListener);
return promise;
}
// Keep a map of promises to their progress listeners so
// the weak progress listeners aren't GCed too early.
createNetworkErrorMessagePromise.listeners = new WeakMap();
// check we can set the 'automatically send' pref
add_task(function* test_set_automatic() {
setup();