|
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 const KEY_UPDATE_ARCHIVE_DIR = "UpdArchD" |
|
7 |
|
8 let gActiveUpdate = null; |
|
9 |
|
10 function FakeDirProvider() {} |
|
11 FakeDirProvider.prototype = { |
|
12 classID: Components.ID("{f30b43a7-2bfa-4e5f-8c4f-abc7dd4ac486}"), |
|
13 QueryInterface: XPCOMUtils.generateQI([AUS_Ci.nsIDirectoryServiceProvider]), |
|
14 |
|
15 getFile: function(prop, persistent) { |
|
16 if (prop == KEY_UPDATE_ARCHIVE_DIR) { |
|
17 if (gActiveUpdate) { |
|
18 gActiveUpdate.errorCode = AUS_Cr.NS_ERROR_FILE_TOO_BIG; |
|
19 } |
|
20 } |
|
21 return null; |
|
22 } |
|
23 }; |
|
24 |
|
25 function run_test() { |
|
26 setupTestCommon(); |
|
27 |
|
28 setUpdateURLOverride(); |
|
29 overrideXHR(xhr_pt1); |
|
30 standardInit(); |
|
31 |
|
32 logTestInfo("testing that error codes set from a directory provider propagate" + |
|
33 "up to AUS.downloadUpdate() correctly (Bug 794211)."); |
|
34 |
|
35 gDirProvider = new FakeDirProvider(); |
|
36 gOldProvider = AUS_Cc["@mozilla.org/browser/directory-provider;1"] |
|
37 .createInstance(AUS_Ci.nsIDirectoryServiceProvider); |
|
38 |
|
39 gDirService = AUS_Cc["@mozilla.org/file/directory_service;1"] |
|
40 .getService(AUS_Ci.nsIProperties); |
|
41 |
|
42 gDirService.unregisterProvider(gOldProvider); |
|
43 gDirService.registerProvider(gDirProvider); |
|
44 |
|
45 Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, true); |
|
46 do_execute_soon(run_test_pt1); |
|
47 } |
|
48 |
|
49 function xhr_pt1() { |
|
50 gXHR.status = 200; |
|
51 gXHR.responseText = gResponseBody; |
|
52 try { |
|
53 var parser = AUS_Cc["@mozilla.org/xmlextras/domparser;1"]. |
|
54 createInstance(AUS_Ci.nsIDOMParser); |
|
55 gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml"); |
|
56 } catch (e) { |
|
57 gXHR.responseXML = null; |
|
58 } |
|
59 var e = { target: gXHR }; |
|
60 gXHR.onload(e); |
|
61 } |
|
62 |
|
63 function run_test_pt1() { |
|
64 gUpdates = null; |
|
65 gUpdateCount = null; |
|
66 gCheckFunc = check_test_pt1; |
|
67 |
|
68 |
|
69 let patches = getRemotePatchString(); |
|
70 let updates = getRemoteUpdateString(patches); |
|
71 gResponseBody = getRemoteUpdatesXMLString(updates); |
|
72 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
73 } |
|
74 |
|
75 function check_test_pt1() { |
|
76 do_check_eq(gUpdateCount, 1); |
|
77 |
|
78 gActiveUpdate = gUpdates[0]; |
|
79 do_check_neq(gActiveUpdate, null); |
|
80 |
|
81 let state = gAUS.downloadUpdate(gActiveUpdate, true); |
|
82 do_check_eq(state, "null"); |
|
83 do_check_eq(gActiveUpdate.errorCode >>> 0 , AUS_Cr.NS_ERROR_FILE_TOO_BIG); |
|
84 |
|
85 doTestFinish(); |
|
86 } |
|
87 |
|
88 function end_test() { |
|
89 gDirService.unregisterProvider(gDirProvider); |
|
90 gDirService.registerProvider(gOldProvider); |
|
91 gActiveUpdate = null; |
|
92 gDirService = null; |
|
93 gDirProvider = null; |
|
94 } |