зеркало из https://github.com/mozilla/gecko-dev.git
Additional tests from Bug 451164. r=dtownsend
This commit is contained in:
Родитель
4c398cc681
Коммит
e41c70573b
|
@ -49,6 +49,8 @@ var gAUS = null;
|
|||
var gUpdateChecker = null;
|
||||
var gPrefs = null;
|
||||
var gTestserver = null;
|
||||
var gXHR = null;
|
||||
var gXHRCallback = null;
|
||||
|
||||
/* Initializes the most commonly used global vars used by tests */
|
||||
function startAUS() {
|
||||
|
@ -99,6 +101,81 @@ function toggleOffline(aOffline) {
|
|||
ioService.offline = aOffline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the bare bones XMLHttpRequest implementation below.
|
||||
*
|
||||
* @param callback
|
||||
* The callback function that will call the nsIDomEventListener's
|
||||
* handleEvent method.
|
||||
*
|
||||
* Example of the callback function
|
||||
*
|
||||
* function callHandleEvent() {
|
||||
* gXHR.status = gExpectedStatus;
|
||||
* var e = { target: gXHR };
|
||||
* gXHR.onload.handleEvent(e);
|
||||
* }
|
||||
*/
|
||||
function overrideXHR(callback) {
|
||||
gXHRCallback = callback;
|
||||
gXHR = new xhr();
|
||||
var registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
|
||||
registrar.registerFactory(gXHR.classID, gXHR.classDescription,
|
||||
gXHR.contractID, gXHR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bare bones XMLHttpRequest implementation for testing onprogress, onerror,
|
||||
* and onload nsIDomEventListener handleEvent.
|
||||
*/
|
||||
function xhr() {
|
||||
}
|
||||
xhr.prototype = {
|
||||
overrideMimeType: function(mimetype) { },
|
||||
setRequestHeader: function(header, value) { },
|
||||
status: null,
|
||||
channel: { set notificationCallbacks(val) { } },
|
||||
_url: null,
|
||||
_method: null,
|
||||
open: function (method, url) { gXHR._method = method; gXHR._url = url; },
|
||||
send: function(body) {
|
||||
do_timeout(0, "gXHRCallback()"); // Use a timeout so the XHR completes
|
||||
},
|
||||
_onprogress: null,
|
||||
set onprogress(val) { gXHR._onprogress = val; },
|
||||
get onprogress() { return gXHR._onprogress; },
|
||||
_onerror: null,
|
||||
set onerror(val) { gXHR._onerror = val; },
|
||||
get onerror() { return gXHR._onerror; },
|
||||
_onload: null,
|
||||
set onload(val) { gXHR._onload = val; },
|
||||
get onload() { return gXHR._onload; },
|
||||
flags: AUS_Ci.nsIClassInfo.SINGLETON,
|
||||
implementationLanguage: AUS_Ci.nsIProgrammingLanguage.JAVASCRIPT,
|
||||
getHelperForLanguage: function(language) null,
|
||||
getInterfaces: function(count) {
|
||||
var interfaces = [AUS_Ci.nsIXMLHttpRequest, AUS_Ci.nsIJSXMLHttpRequest];
|
||||
count.value = interfaces.length;
|
||||
return interfaces;
|
||||
},
|
||||
classDescription: "XMLHttpRequest",
|
||||
contractID: "@mozilla.org/xmlextras/xmlhttprequest;1",
|
||||
classID: Components.ID("{c9b37f43-4278-4304-a5e0-600991ab08cb}"),
|
||||
createInstance: function (outer, aIID) {
|
||||
if (outer != null)
|
||||
throw AUS_Cr.NS_ERROR_NO_AGGREGATION;
|
||||
return gXHR.QueryInterface(aIID);
|
||||
},
|
||||
QueryInterface: function(aIID) {
|
||||
if (aIID.equals(AUS_Ci.nsIXMLHttpRequest) ||
|
||||
aIID.equals(AUS_Ci.nsIJSXMLHttpRequest) ||
|
||||
aIID.equals(AUS_Ci.nsIClassInfo) ||
|
||||
aIID.equals(AUS_Ci.nsISupports))
|
||||
return gXHR;
|
||||
throw AUS_Cr.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes the updates directory and the active-update.xml file if they exist.
|
||||
* This prevents some tests from failing due to files being left behind when
|
||||
|
|
|
@ -36,6 +36,15 @@
|
|||
* ***** END LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
if (gXHR) {
|
||||
gXHRCallback = null;
|
||||
// null out the event handlers to prevent a mFreeCount leak of 1
|
||||
gXHR.onerror = null;
|
||||
gXHR.onload = null;
|
||||
gXHR.onprogress = null;
|
||||
gXHR = null;
|
||||
}
|
||||
|
||||
gUpdateChecker = null;
|
||||
gAUS = null;
|
||||
gPrefs = null;
|
||||
|
|
|
@ -0,0 +1,202 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is the Application Update Service.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Robert Strong <robert.bugzilla@gmail.com>.
|
||||
*
|
||||
* Portions created by the Initial Developer are Copyright (C) 2008
|
||||
* the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/* General nsIUpdateCheckListener onload error code statusText Tests */
|
||||
|
||||
// Errors tested:
|
||||
// 2152398849, 2152398862, 2152398864, 2152398867, 2152398868, 2152398878,
|
||||
// 2152398890, 2152398919, 2152398920, default (404)
|
||||
|
||||
const DIR_DATA = "data"
|
||||
const URL_PREFIX = "http://localhost:4444/" + DIR_DATA + "/";
|
||||
|
||||
const PREF_APP_UPDATE_URL_OVERRIDE = "app.update.url.override";
|
||||
|
||||
const URI_UPDATES_PROPERTIES = "chrome://mozapps/locale/update/updates.properties";
|
||||
const gUpdateBundle = AUS_Cc["@mozilla.org/intl/stringbundle;1"]
|
||||
.getService(AUS_Ci.nsIStringBundleService)
|
||||
.createBundle(URI_UPDATES_PROPERTIES);
|
||||
|
||||
var gStatusCode;
|
||||
var gStatusText;
|
||||
var gExpectedStatusCode;
|
||||
var gExpectedStatusText;
|
||||
var gCheckFunc;
|
||||
var gNextRunFunc;
|
||||
|
||||
function run_test() {
|
||||
do_test_pending();
|
||||
startAUS();
|
||||
overrideXHR(callHandleEvent);
|
||||
do_timeout(0, "run_test_pt1()");
|
||||
}
|
||||
|
||||
function end_test() {
|
||||
do_test_finished();
|
||||
}
|
||||
|
||||
// Returns human readable status text from the updates.properties bundle
|
||||
function getStatusText(aErrCode) {
|
||||
try {
|
||||
return gUpdateBundle.GetStringFromName("checker_error-" + aErrCode);
|
||||
}
|
||||
catch (e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Callback function used by the custom XMLHttpRequest implemetation to
|
||||
// call the nsIDOMEventListener's handleEvent method for onload.
|
||||
function callHandleEvent() {
|
||||
gXHR.status = gExpectedStatusCode;
|
||||
var e = { target: gXHR };
|
||||
gXHR.onload.handleEvent(e);
|
||||
}
|
||||
|
||||
// Helper functions for testing nsIUpdateCheckListener onload error statusTexts
|
||||
function run_test_helper(aUpdateXML, aMsg, aExpectedStatusCode,
|
||||
aExpectedStatusText, aNextRunFunc) {
|
||||
gStatusCode = null;
|
||||
gStatusText = null;
|
||||
gCheckFunc = check_test_helper;
|
||||
gNextRunFunc = aNextRunFunc;
|
||||
gExpectedStatusCode = aExpectedStatusCode;
|
||||
gExpectedStatusText = aExpectedStatusText;
|
||||
var url = URL_PREFIX + aUpdateXML;
|
||||
dump("Testing: " + aMsg + " - " + url + "\n");
|
||||
gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
|
||||
gUpdateChecker.checkForUpdates(updateCheckListener, true);
|
||||
}
|
||||
|
||||
function check_test_helper() {
|
||||
do_check_eq(gStatusCode, gExpectedStatusCode);
|
||||
do_check_eq(gStatusText, gExpectedStatusText);
|
||||
gNextRunFunc();
|
||||
}
|
||||
|
||||
/**
|
||||
* The following tests use a custom XMLHttpRequest to return the status codes
|
||||
*/
|
||||
|
||||
// failed (unknown reason)
|
||||
function run_test_pt1() {
|
||||
run_test_helper("aus-0051_general-1.xml", "failed (unknown reason)",
|
||||
2152398849, getStatusText("2152398849"), run_test_pt2);
|
||||
}
|
||||
|
||||
// connection timed out
|
||||
function run_test_pt2() {
|
||||
run_test_helper("aus-0051_general-2.xml", "connection timed out",
|
||||
2152398862, getStatusText("2152398862"), run_test_pt3);
|
||||
}
|
||||
|
||||
// network offline
|
||||
function run_test_pt3() {
|
||||
run_test_helper("aus-0051_general-3.xml", "network offline",
|
||||
2152398864, getStatusText("2152398864"), run_test_pt4);
|
||||
}
|
||||
|
||||
// port not allowed
|
||||
function run_test_pt4() {
|
||||
run_test_helper("aus-0051_general-4.xml", "port not allowed",
|
||||
2152398867, getStatusText("2152398867"), run_test_pt5);
|
||||
}
|
||||
|
||||
// no data was received
|
||||
function run_test_pt5() {
|
||||
run_test_helper("aus-0051_general-5.xml", "no data was received",
|
||||
2152398868, getStatusText("2152398868"), run_test_pt6);
|
||||
}
|
||||
|
||||
// update server not found
|
||||
function run_test_pt6() {
|
||||
run_test_helper("aus-0051_general-6.xml", "update server not found",
|
||||
2152398878, getStatusText("2152398878"), run_test_pt7);
|
||||
}
|
||||
|
||||
// proxy server not found
|
||||
function run_test_pt7() {
|
||||
run_test_helper("aus-0051_general-7.xml", "proxy server not found",
|
||||
2152398890, getStatusText("2152398890"), run_test_pt8);
|
||||
}
|
||||
|
||||
// data transfer interrupted
|
||||
function run_test_pt8() {
|
||||
run_test_helper("aus-0051_general-8.xml", "data transfer interrupted",
|
||||
2152398919, getStatusText("2152398919"), run_test_pt9);
|
||||
}
|
||||
|
||||
// proxy server connection refused
|
||||
function run_test_pt9() {
|
||||
run_test_helper("aus-0051_general-9.xml", "proxy server connection refused",
|
||||
2152398920, getStatusText("2152398920"), run_test_pt10);
|
||||
}
|
||||
|
||||
// default onload error message (error code 1152398920 is not defined)
|
||||
function run_test_pt10() {
|
||||
run_test_helper("aus-0051_general-10.xml", "default onload error message",
|
||||
1152398920, getStatusText("404"), end_test);
|
||||
}
|
||||
|
||||
// Update check listener
|
||||
const updateCheckListener = {
|
||||
onProgress: function(request, position, totalSize) {
|
||||
},
|
||||
|
||||
onCheckComplete: function(request, updates, updateCount) {
|
||||
dump("onCheckComplete request.status = " + request.status + "\n\n");
|
||||
// Use a timeout to allow the XHR to complete
|
||||
do_timeout(0, "gCheckFunc()");
|
||||
},
|
||||
|
||||
onError: function(request, update) {
|
||||
gStatusCode = request.status;
|
||||
gStatusText = update.statusText;
|
||||
dump("onError: request.status = " + gStatusCode + ", update.statusText = " + gStatusText + "\n\n");
|
||||
// Use a timeout to allow the XHR to complete
|
||||
do_timeout(0, "gCheckFunc()");
|
||||
},
|
||||
|
||||
QueryInterface: function(aIID) {
|
||||
if (!aIID.equals(AUS_Ci.nsIUpdateCheckListener) &&
|
||||
!aIID.equals(AUS_Ci.nsISupports))
|
||||
throw AUS_Cr.NS_ERROR_NO_INTERFACE;
|
||||
|
||||
return this;
|
||||
}
|
||||
};
|
Загрузка…
Ссылка в новой задаче