|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
4 */ |
|
5 |
|
6 // Needs to be in sync w/ nsUpdateService.js |
|
7 const NETWORK_ERROR_OFFLINE = 111; |
|
8 |
|
9 function run_test() { |
|
10 setupTestCommon(); |
|
11 |
|
12 logTestInfo("testing when an update check fails because the network is " + |
|
13 "offline that we check again when the network comes online " + |
|
14 "(Bug 794211)."); |
|
15 |
|
16 setUpdateURLOverride(); |
|
17 Services.prefs.setBoolPref(PREF_APP_UPDATE_AUTO, false); |
|
18 |
|
19 overrideXHR(null); |
|
20 overrideUpdatePrompt(updatePrompt); |
|
21 standardInit(); |
|
22 |
|
23 do_execute_soon(run_test_pt1); |
|
24 } |
|
25 |
|
26 function run_test_pt1() { |
|
27 gResponseBody = null; |
|
28 gCheckFunc = check_test_pt1; |
|
29 gXHRCallback = xhr_pt1; |
|
30 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
31 } |
|
32 |
|
33 function xhr_pt1() { |
|
34 gXHR.status = AUS_Cr.NS_ERROR_OFFLINE; |
|
35 gXHR.onerror({ target: gXHR }); |
|
36 } |
|
37 |
|
38 function check_test_pt1(request, update) { |
|
39 do_check_eq(gStatusCode, AUS_Cr.NS_ERROR_OFFLINE); |
|
40 do_check_eq(update.errorCode, NETWORK_ERROR_OFFLINE); |
|
41 |
|
42 // Forward the error to AUS, which should register the online observer |
|
43 gAUS.onError(request, update); |
|
44 |
|
45 // Trigger another check by notifying the offline status observer |
|
46 gXHRCallback = xhr_pt2; |
|
47 Services.obs.notifyObservers(gAUS, "network:offline-status-changed", "online"); |
|
48 } |
|
49 |
|
50 var updatePrompt = { |
|
51 showUpdateAvailable: function(update) { |
|
52 check_test_pt2(update); |
|
53 } |
|
54 }; |
|
55 |
|
56 function xhr_pt2() { |
|
57 var patches = getLocalPatchString(); |
|
58 var updates = getLocalUpdateString(patches); |
|
59 var responseBody = getLocalUpdatesXMLString(updates); |
|
60 |
|
61 gXHR.status = 200; |
|
62 gXHR.responseText = responseBody; |
|
63 try { |
|
64 var parser = AUS_Cc["@mozilla.org/xmlextras/domparser;1"]. |
|
65 createInstance(AUS_Ci.nsIDOMParser); |
|
66 gXHR.responseXML = parser.parseFromString(responseBody, "application/xml"); |
|
67 } catch (e) { |
|
68 } |
|
69 gXHR.onload({ target: gXHR }); |
|
70 } |
|
71 |
|
72 function check_test_pt2(update) { |
|
73 // We just verify that there are updates to know the check succeeded. |
|
74 do_check_neq(update, null); |
|
75 do_check_eq(update.name, "App Update Test"); |
|
76 |
|
77 doTestFinish(); |
|
78 } |