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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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  */
     6 const KEY_UPDATE_ARCHIVE_DIR = "UpdArchD"
     8 let gActiveUpdate = null;
    10 function FakeDirProvider() {}
    11 FakeDirProvider.prototype = {
    12   classID: Components.ID("{f30b43a7-2bfa-4e5f-8c4f-abc7dd4ac486}"),
    13   QueryInterface: XPCOMUtils.generateQI([AUS_Ci.nsIDirectoryServiceProvider]),
    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 };
    25 function run_test() {
    26   setupTestCommon();
    28   setUpdateURLOverride();
    29   overrideXHR(xhr_pt1);
    30   standardInit();
    32   logTestInfo("testing that error codes set from a directory provider propagate" +
    33               "up to AUS.downloadUpdate() correctly (Bug 794211).");
    35   gDirProvider = new FakeDirProvider();
    36   gOldProvider = AUS_Cc["@mozilla.org/browser/directory-provider;1"]
    37                        .createInstance(AUS_Ci.nsIDirectoryServiceProvider);
    39   gDirService = AUS_Cc["@mozilla.org/file/directory_service;1"]
    40                        .getService(AUS_Ci.nsIProperties);
    42   gDirService.unregisterProvider(gOldProvider);
    43   gDirService.registerProvider(gDirProvider);
    45   Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, true);
    46   do_execute_soon(run_test_pt1);
    47 }
    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 }
    63 function run_test_pt1() {
    64   gUpdates = null;
    65   gUpdateCount = null;
    66   gCheckFunc = check_test_pt1;
    69   let patches = getRemotePatchString();
    70   let updates = getRemoteUpdateString(patches);
    71   gResponseBody = getRemoteUpdatesXMLString(updates);
    72   gUpdateChecker.checkForUpdates(updateCheckListener, true);
    73 }
    75 function check_test_pt1() {
    76   do_check_eq(gUpdateCount, 1);
    78   gActiveUpdate = gUpdates[0];
    79   do_check_neq(gActiveUpdate, null);
    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);
    85   doTestFinish();
    86 }
    88 function end_test() {
    89   gDirService.unregisterProvider(gDirProvider);
    90   gDirService.registerProvider(gOldProvider);
    91   gActiveUpdate = null;
    92   gDirService = null;
    93   gDirProvider = null;
    94 }

mercurial