2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2008-08-24 11:43:50 -07:00
|
|
|
*/
|
|
|
|
|
2009-06-22 12:28:39 -07:00
|
|
|
/* General nsIUpdateCheckListener onload and onerror error code and statusText
|
|
|
|
Tests */
|
2008-08-24 11:43:50 -07:00
|
|
|
|
|
|
|
// Errors tested:
|
2009-06-22 12:28:39 -07:00
|
|
|
// 200, 403, 404, 500, 2152398849, 2152398862, 2152398864, 2152398867,
|
|
|
|
// 2152398868, 2152398878, 2152398890, 2152398919, 2152398920, 2153390069,
|
|
|
|
// 2152398918, 2152398861
|
2008-08-24 11:43:50 -07:00
|
|
|
|
|
|
|
var gNextRunFunc;
|
2009-04-16 18:32:32 -07:00
|
|
|
var gExpectedStatusCode;
|
|
|
|
var gExpectedStatusText;
|
2008-08-24 11:43:50 -07:00
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
do_test_pending();
|
2010-10-19 21:28:29 -07:00
|
|
|
do_register_cleanup(end_test);
|
2009-04-16 18:32:32 -07:00
|
|
|
removeUpdateDirsAndFiles();
|
2010-03-03 10:56:47 -08:00
|
|
|
setUpdateURLOverride();
|
|
|
|
standardInit();
|
|
|
|
// The mock XMLHttpRequest is MUCH faster
|
2009-06-22 12:28:39 -07:00
|
|
|
overrideXHR(callHandleEvent);
|
2010-12-07 12:05:49 -08:00
|
|
|
do_execute_soon(run_test_pt1);
|
2008-08-24 11:43:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function end_test() {
|
2009-05-19 13:24:12 -07:00
|
|
|
cleanUp();
|
2008-08-24 11:43:50 -07:00
|
|
|
}
|
|
|
|
|
2009-06-22 12:28:39 -07:00
|
|
|
// Callback function used by the custom XMLHttpRequest implementation to
|
|
|
|
// call the nsIDOMEventListener's handleEvent method for onload.
|
|
|
|
function callHandleEvent() {
|
|
|
|
gXHR.status = gExpectedStatusCode;
|
|
|
|
var e = { target: gXHR };
|
2011-09-29 09:06:36 -07:00
|
|
|
gXHR.onload(e);
|
2008-08-24 11:43:50 -07:00
|
|
|
}
|
|
|
|
|
2009-06-22 12:28:39 -07:00
|
|
|
// Helper functions for testing nsIUpdateCheckListener statusText
|
|
|
|
function run_test_helper(aNextRunFunc, aExpectedStatusCode, aMsg) {
|
2009-04-16 18:32:32 -07:00
|
|
|
gStatusCode = null;
|
2008-08-24 11:43:50 -07:00
|
|
|
gStatusText = null;
|
|
|
|
gCheckFunc = check_test_helper;
|
|
|
|
gNextRunFunc = aNextRunFunc;
|
2009-06-22 12:28:39 -07:00
|
|
|
gExpectedStatusCode = aExpectedStatusCode;
|
2010-10-19 21:28:29 -07:00
|
|
|
logTestInfo(aMsg, Components.stack.caller);
|
2008-08-24 11:43:50 -07:00
|
|
|
gUpdateChecker.checkForUpdates(updateCheckListener, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_test_helper() {
|
2009-04-16 18:32:32 -07:00
|
|
|
do_check_eq(gStatusCode, gExpectedStatusCode);
|
2009-06-22 12:28:39 -07:00
|
|
|
var expectedStatusText = getStatusText(gExpectedStatusCode);
|
|
|
|
do_check_eq(gStatusText, expectedStatusText);
|
2008-08-24 11:43:50 -07:00
|
|
|
gNextRunFunc();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-06-22 12:28:39 -07:00
|
|
|
* The following tests use a custom XMLHttpRequest to return the status codes
|
2008-08-24 11:43:50 -07:00
|
|
|
*/
|
|
|
|
|
2009-06-22 12:28:39 -07:00
|
|
|
// default onerror error message (error code 399 is not defined)
|
2008-08-24 11:43:50 -07:00
|
|
|
function run_test_pt1() {
|
2009-06-22 12:28:39 -07:00
|
|
|
gStatusCode = null;
|
|
|
|
gStatusText = null;
|
|
|
|
gCheckFunc = check_test_pt1;
|
|
|
|
gExpectedStatusCode = 399;
|
2010-10-19 21:28:29 -07:00
|
|
|
logTestInfo("testing default onerror error message");
|
2009-06-22 12:28:39 -07:00
|
|
|
gUpdateChecker.checkForUpdates(updateCheckListener, true);
|
2008-08-24 11:43:50 -07:00
|
|
|
}
|
|
|
|
|
2009-06-22 12:28:39 -07:00
|
|
|
function check_test_pt1() {
|
|
|
|
do_check_eq(gStatusCode, gExpectedStatusCode);
|
|
|
|
var expectedStatusText = getStatusText(404);
|
|
|
|
do_check_eq(gStatusText, expectedStatusText);
|
|
|
|
run_test_pt2();
|
2008-08-24 11:43:50 -07:00
|
|
|
}
|
|
|
|
|
2009-06-22 12:28:39 -07:00
|
|
|
// file malformed - 200
|
|
|
|
function run_test_pt2() {
|
|
|
|
run_test_helper(run_test_pt3, 200,
|
2010-10-19 21:28:29 -07:00
|
|
|
"testing file malformed");
|
2009-06-22 12:28:39 -07:00
|
|
|
}
|
2008-08-24 11:43:50 -07:00
|
|
|
|
2009-06-22 12:28:39 -07:00
|
|
|
// access denied - 403
|
2008-08-24 11:43:50 -07:00
|
|
|
function run_test_pt3() {
|
2009-06-22 12:28:39 -07:00
|
|
|
run_test_helper(run_test_pt4, 403,
|
2010-10-19 21:28:29 -07:00
|
|
|
"testing access denied");
|
2008-08-24 11:43:50 -07:00
|
|
|
}
|
|
|
|
|
2009-06-22 12:28:39 -07:00
|
|
|
// file not found - 404
|
2008-08-24 11:43:50 -07:00
|
|
|
function run_test_pt4() {
|
2009-06-22 12:28:39 -07:00
|
|
|
run_test_helper(run_test_pt5, 404,
|
2010-10-19 21:28:29 -07:00
|
|
|
"testing file not found");
|
2008-08-24 11:43:50 -07:00
|
|
|
}
|
|
|
|
|
2009-06-22 12:28:39 -07:00
|
|
|
// internal server error - 500
|
2008-08-24 11:43:50 -07:00
|
|
|
function run_test_pt5() {
|
2009-06-22 12:28:39 -07:00
|
|
|
run_test_helper(run_test_pt6, 500,
|
2010-10-19 21:28:29 -07:00
|
|
|
"testing internal server error");
|
2008-08-24 11:43:50 -07:00
|
|
|
}
|
|
|
|
|
2009-06-22 12:28:39 -07:00
|
|
|
// failed (unknown reason) - NS_BINDING_FAILED (2152398849)
|
2008-08-24 11:43:50 -07:00
|
|
|
function run_test_pt6() {
|
2009-06-22 12:28:39 -07:00
|
|
|
run_test_helper(run_test_pt7, AUS_Cr.NS_BINDING_FAILED,
|
2010-10-19 21:28:29 -07:00
|
|
|
"testing failed (unknown reason)");
|
2008-08-24 11:43:50 -07:00
|
|
|
}
|
|
|
|
|
2009-06-22 12:28:39 -07:00
|
|
|
// connection timed out - NS_ERROR_NET_TIMEOUT (2152398862)
|
2008-08-24 11:43:50 -07:00
|
|
|
function run_test_pt7() {
|
2009-06-22 12:28:39 -07:00
|
|
|
run_test_helper(run_test_pt8, AUS_Cr.NS_ERROR_NET_TIMEOUT,
|
2010-10-19 21:28:29 -07:00
|
|
|
"testing connection timed out");
|
2009-06-22 12:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// network offline - NS_ERROR_OFFLINE (2152398864)
|
|
|
|
function run_test_pt8() {
|
|
|
|
run_test_helper(run_test_pt9, AUS_Cr.NS_ERROR_OFFLINE,
|
2010-10-19 21:28:29 -07:00
|
|
|
"testing network offline");
|
2009-06-22 12:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// port not allowed - NS_ERROR_PORT_ACCESS_NOT_ALLOWED (2152398867)
|
|
|
|
function run_test_pt9() {
|
|
|
|
run_test_helper(run_test_pt10, AUS_Cr.NS_ERROR_PORT_ACCESS_NOT_ALLOWED,
|
2010-10-19 21:28:29 -07:00
|
|
|
"testing port not allowed");
|
2009-06-22 12:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// no data was received - NS_ERROR_NET_RESET (2152398868)
|
|
|
|
function run_test_pt10() {
|
|
|
|
run_test_helper(run_test_pt11, AUS_Cr.NS_ERROR_NET_RESET,
|
2010-10-19 21:28:29 -07:00
|
|
|
"testing no data was received");
|
2009-06-22 12:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// update server not found - NS_ERROR_UNKNOWN_HOST (2152398878)
|
|
|
|
function run_test_pt11() {
|
|
|
|
run_test_helper(run_test_pt12, AUS_Cr.NS_ERROR_UNKNOWN_HOST,
|
2010-10-19 21:28:29 -07:00
|
|
|
"testing update server not found");
|
2009-06-22 12:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// proxy server not found - NS_ERROR_UNKNOWN_PROXY_HOST (2152398890)
|
|
|
|
function run_test_pt12() {
|
|
|
|
run_test_helper(run_test_pt13, AUS_Cr.NS_ERROR_UNKNOWN_PROXY_HOST,
|
2010-10-19 21:28:29 -07:00
|
|
|
"testing proxy server not found");
|
2009-06-22 12:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// data transfer interrupted - NS_ERROR_NET_INTERRUPT (2152398919)
|
|
|
|
function run_test_pt13() {
|
|
|
|
run_test_helper(run_test_pt14, AUS_Cr.NS_ERROR_NET_INTERRUPT,
|
2010-10-19 21:28:29 -07:00
|
|
|
"testing data transfer interrupted");
|
2009-06-22 12:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// proxy server connection refused - NS_ERROR_PROXY_CONNECTION_REFUSED (2152398920)
|
|
|
|
function run_test_pt14() {
|
|
|
|
run_test_helper(run_test_pt15, AUS_Cr.NS_ERROR_PROXY_CONNECTION_REFUSED,
|
2010-10-19 21:28:29 -07:00
|
|
|
"testing proxy server connection refused");
|
2009-06-22 12:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// server certificate expired - 2153390069
|
|
|
|
function run_test_pt15() {
|
|
|
|
run_test_helper(run_test_pt16, 2153390069,
|
2010-10-19 21:28:29 -07:00
|
|
|
"testing server certificate expired");
|
2009-06-22 12:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// network is offline - NS_ERROR_DOCUMENT_NOT_CACHED (2152398918)
|
|
|
|
function run_test_pt16() {
|
|
|
|
run_test_helper(run_test_pt17, AUS_Cr.NS_ERROR_DOCUMENT_NOT_CACHED,
|
2010-10-19 21:28:29 -07:00
|
|
|
"testing network is offline");
|
2009-06-22 12:28:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// connection refused - NS_ERROR_CONNECTION_REFUSED (2152398861)
|
|
|
|
function run_test_pt17() {
|
2010-10-19 21:28:29 -07:00
|
|
|
run_test_helper(do_test_finished, AUS_Cr.NS_ERROR_CONNECTION_REFUSED,
|
|
|
|
"testing connection refused");
|
2008-08-24 11:43:50 -07:00
|
|
|
}
|