michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: // Needs to be in sync w/ nsUpdateService.js michael@0: const NETWORK_ERROR_OFFLINE = 111; michael@0: michael@0: function run_test() { michael@0: setupTestCommon(); michael@0: michael@0: logTestInfo("testing when an update check fails because the network is " + michael@0: "offline that we check again when the network comes online " + michael@0: "(Bug 794211)."); michael@0: michael@0: setUpdateURLOverride(); michael@0: Services.prefs.setBoolPref(PREF_APP_UPDATE_AUTO, false); michael@0: michael@0: overrideXHR(null); michael@0: overrideUpdatePrompt(updatePrompt); michael@0: standardInit(); michael@0: michael@0: do_execute_soon(run_test_pt1); michael@0: } michael@0: michael@0: function run_test_pt1() { michael@0: gResponseBody = null; michael@0: gCheckFunc = check_test_pt1; michael@0: gXHRCallback = xhr_pt1; michael@0: gUpdateChecker.checkForUpdates(updateCheckListener, true); michael@0: } michael@0: michael@0: function xhr_pt1() { michael@0: gXHR.status = AUS_Cr.NS_ERROR_OFFLINE; michael@0: gXHR.onerror({ target: gXHR }); michael@0: } michael@0: michael@0: function check_test_pt1(request, update) { michael@0: do_check_eq(gStatusCode, AUS_Cr.NS_ERROR_OFFLINE); michael@0: do_check_eq(update.errorCode, NETWORK_ERROR_OFFLINE); michael@0: michael@0: // Forward the error to AUS, which should register the online observer michael@0: gAUS.onError(request, update); michael@0: michael@0: // Trigger another check by notifying the offline status observer michael@0: gXHRCallback = xhr_pt2; michael@0: Services.obs.notifyObservers(gAUS, "network:offline-status-changed", "online"); michael@0: } michael@0: michael@0: var updatePrompt = { michael@0: showUpdateAvailable: function(update) { michael@0: check_test_pt2(update); michael@0: } michael@0: }; michael@0: michael@0: function xhr_pt2() { michael@0: var patches = getLocalPatchString(); michael@0: var updates = getLocalUpdateString(patches); michael@0: var responseBody = getLocalUpdatesXMLString(updates); michael@0: michael@0: gXHR.status = 200; michael@0: gXHR.responseText = responseBody; michael@0: try { michael@0: var parser = AUS_Cc["@mozilla.org/xmlextras/domparser;1"]. michael@0: createInstance(AUS_Ci.nsIDOMParser); michael@0: gXHR.responseXML = parser.parseFromString(responseBody, "application/xml"); michael@0: } catch (e) { michael@0: } michael@0: gXHR.onload({ target: gXHR }); michael@0: } michael@0: michael@0: function check_test_pt2(update) { michael@0: // We just verify that there are updates to know the check succeeded. michael@0: do_check_neq(update, null); michael@0: do_check_eq(update.name, "App Update Test"); michael@0: michael@0: doTestFinish(); michael@0: }