toolkit/mozapps/update/tests/unit_aus_update/downloadFileTooBig_gonk.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial