michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: // Errors tested: michael@0: // 200, 403, 404, 500, 2152398849, 2152398862, 2152398864, 2152398867, michael@0: // 2152398868, 2152398878, 2152398890, 2152398919, 2152398920, 2153390069, michael@0: // 2152398918, 2152398861 michael@0: michael@0: var gNextRunFunc; michael@0: var gExpectedStatusCode; michael@0: var gExpectedStatusText; michael@0: michael@0: function run_test() { michael@0: setupTestCommon(); michael@0: michael@0: logTestInfo("testing nsIUpdateCheckListener onload and onerror error code " + michael@0: "and statusText values"); michael@0: michael@0: setUpdateURLOverride(); michael@0: standardInit(); michael@0: // The mock XMLHttpRequest is MUCH faster michael@0: overrideXHR(callHandleEvent); michael@0: do_execute_soon(run_test_pt1); michael@0: } michael@0: michael@0: // Callback function used by the custom XMLHttpRequest implementation to michael@0: // call the nsIDOMEventListener's handleEvent method for onload. michael@0: function callHandleEvent() { michael@0: gXHR.status = gExpectedStatusCode; michael@0: var e = { target: gXHR }; michael@0: gXHR.onload(e); michael@0: } michael@0: michael@0: // Helper functions for testing nsIUpdateCheckListener statusText michael@0: function run_test_helper(aNextRunFunc, aExpectedStatusCode, aMsg) { michael@0: gStatusCode = null; michael@0: gStatusText = null; michael@0: gCheckFunc = check_test_helper; michael@0: gNextRunFunc = aNextRunFunc; michael@0: gExpectedStatusCode = aExpectedStatusCode; michael@0: logTestInfo(aMsg, Components.stack.caller); michael@0: gUpdateChecker.checkForUpdates(updateCheckListener, true); michael@0: } michael@0: michael@0: function check_test_helper() { michael@0: do_check_eq(gStatusCode, gExpectedStatusCode); michael@0: var expectedStatusText = getStatusText(gExpectedStatusCode); michael@0: do_check_eq(gStatusText, expectedStatusText); michael@0: gNextRunFunc(); michael@0: } michael@0: michael@0: /** michael@0: * The following tests use a custom XMLHttpRequest to return the status codes michael@0: */ michael@0: michael@0: // default onerror error message (error code 399 is not defined) michael@0: function run_test_pt1() { michael@0: gStatusCode = null; michael@0: gStatusText = null; michael@0: gCheckFunc = check_test_pt1; michael@0: gExpectedStatusCode = 399; michael@0: logTestInfo("testing default onerror error message"); michael@0: gUpdateChecker.checkForUpdates(updateCheckListener, true); michael@0: } michael@0: michael@0: function check_test_pt1() { michael@0: do_check_eq(gStatusCode, gExpectedStatusCode); michael@0: var expectedStatusText = getStatusText(404); michael@0: do_check_eq(gStatusText, expectedStatusText); michael@0: run_test_pt2(); michael@0: } michael@0: michael@0: // file malformed - 200 michael@0: function run_test_pt2() { michael@0: run_test_helper(run_test_pt3, 200, michael@0: "testing file malformed"); michael@0: } michael@0: michael@0: // access denied - 403 michael@0: function run_test_pt3() { michael@0: run_test_helper(run_test_pt4, 403, michael@0: "testing access denied"); michael@0: } michael@0: michael@0: // file not found - 404 michael@0: function run_test_pt4() { michael@0: run_test_helper(run_test_pt5, 404, michael@0: "testing file not found"); michael@0: } michael@0: michael@0: // internal server error - 500 michael@0: function run_test_pt5() { michael@0: run_test_helper(run_test_pt6, 500, michael@0: "testing internal server error"); michael@0: } michael@0: michael@0: // failed (unknown reason) - NS_BINDING_FAILED (2152398849) michael@0: function run_test_pt6() { michael@0: run_test_helper(run_test_pt7, AUS_Cr.NS_BINDING_FAILED, michael@0: "testing failed (unknown reason)"); michael@0: } michael@0: michael@0: // connection timed out - NS_ERROR_NET_TIMEOUT (2152398862) michael@0: function run_test_pt7() { michael@0: run_test_helper(run_test_pt8, AUS_Cr.NS_ERROR_NET_TIMEOUT, michael@0: "testing connection timed out"); michael@0: } michael@0: michael@0: // network offline - NS_ERROR_OFFLINE (2152398864) michael@0: function run_test_pt8() { michael@0: run_test_helper(run_test_pt9, AUS_Cr.NS_ERROR_OFFLINE, michael@0: "testing network offline"); michael@0: } michael@0: michael@0: // port not allowed - NS_ERROR_PORT_ACCESS_NOT_ALLOWED (2152398867) michael@0: function run_test_pt9() { michael@0: run_test_helper(run_test_pt10, AUS_Cr.NS_ERROR_PORT_ACCESS_NOT_ALLOWED, michael@0: "testing port not allowed"); michael@0: } michael@0: michael@0: // no data was received - NS_ERROR_NET_RESET (2152398868) michael@0: function run_test_pt10() { michael@0: run_test_helper(run_test_pt11, AUS_Cr.NS_ERROR_NET_RESET, michael@0: "testing no data was received"); michael@0: } michael@0: michael@0: // update server not found - NS_ERROR_UNKNOWN_HOST (2152398878) michael@0: function run_test_pt11() { michael@0: run_test_helper(run_test_pt12, AUS_Cr.NS_ERROR_UNKNOWN_HOST, michael@0: "testing update server not found"); michael@0: } michael@0: michael@0: // proxy server not found - NS_ERROR_UNKNOWN_PROXY_HOST (2152398890) michael@0: function run_test_pt12() { michael@0: run_test_helper(run_test_pt13, AUS_Cr.NS_ERROR_UNKNOWN_PROXY_HOST, michael@0: "testing proxy server not found"); michael@0: } michael@0: michael@0: // data transfer interrupted - NS_ERROR_NET_INTERRUPT (2152398919) michael@0: function run_test_pt13() { michael@0: run_test_helper(run_test_pt14, AUS_Cr.NS_ERROR_NET_INTERRUPT, michael@0: "testing data transfer interrupted"); michael@0: } michael@0: michael@0: // proxy server connection refused - NS_ERROR_PROXY_CONNECTION_REFUSED (2152398920) michael@0: function run_test_pt14() { michael@0: run_test_helper(run_test_pt15, AUS_Cr.NS_ERROR_PROXY_CONNECTION_REFUSED, michael@0: "testing proxy server connection refused"); michael@0: } michael@0: michael@0: // server certificate expired - 2153390069 michael@0: function run_test_pt15() { michael@0: run_test_helper(run_test_pt16, 2153390069, michael@0: "testing server certificate expired"); michael@0: } michael@0: michael@0: // network is offline - NS_ERROR_DOCUMENT_NOT_CACHED (2152398918) michael@0: function run_test_pt16() { michael@0: run_test_helper(run_test_pt17, AUS_Cr.NS_ERROR_DOCUMENT_NOT_CACHED, michael@0: "testing network is offline"); michael@0: } michael@0: michael@0: // connection refused - NS_ERROR_CONNECTION_REFUSED (2152398861) michael@0: function run_test_pt17() { michael@0: run_test_helper(doTestFinish, AUS_Cr.NS_ERROR_CONNECTION_REFUSED, michael@0: "testing connection refused"); michael@0: }