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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/update/tests/unit_aus_update/updateCheckOnLoadOnErrorStatusText.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,169 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 + */
     1.8 +
     1.9 +// Errors tested:
    1.10 +// 200, 403, 404, 500, 2152398849, 2152398862, 2152398864, 2152398867,
    1.11 +// 2152398868, 2152398878, 2152398890, 2152398919, 2152398920, 2153390069,
    1.12 +// 2152398918, 2152398861
    1.13 +
    1.14 +var gNextRunFunc;
    1.15 +var gExpectedStatusCode;
    1.16 +var gExpectedStatusText;
    1.17 +
    1.18 +function run_test() {
    1.19 +  setupTestCommon();
    1.20 +
    1.21 +  logTestInfo("testing nsIUpdateCheckListener onload and onerror error code " +
    1.22 +              "and statusText values");
    1.23 +
    1.24 +  setUpdateURLOverride();
    1.25 +  standardInit();
    1.26 +  // The mock XMLHttpRequest is MUCH faster
    1.27 +  overrideXHR(callHandleEvent);
    1.28 +  do_execute_soon(run_test_pt1);
    1.29 +}
    1.30 +
    1.31 +// Callback function used by the custom XMLHttpRequest implementation to
    1.32 +// call the nsIDOMEventListener's handleEvent method for onload.
    1.33 +function callHandleEvent() {
    1.34 +  gXHR.status = gExpectedStatusCode;
    1.35 +  var e = { target: gXHR };
    1.36 +  gXHR.onload(e);
    1.37 +}
    1.38 +
    1.39 +// Helper functions for testing nsIUpdateCheckListener statusText
    1.40 +function run_test_helper(aNextRunFunc, aExpectedStatusCode, aMsg) {
    1.41 +  gStatusCode = null;
    1.42 +  gStatusText = null;
    1.43 +  gCheckFunc = check_test_helper;
    1.44 +  gNextRunFunc = aNextRunFunc;
    1.45 +  gExpectedStatusCode = aExpectedStatusCode;
    1.46 +  logTestInfo(aMsg, Components.stack.caller);
    1.47 +  gUpdateChecker.checkForUpdates(updateCheckListener, true);
    1.48 +}
    1.49 +
    1.50 +function check_test_helper() {
    1.51 +  do_check_eq(gStatusCode, gExpectedStatusCode);
    1.52 +  var expectedStatusText = getStatusText(gExpectedStatusCode);
    1.53 +  do_check_eq(gStatusText, expectedStatusText);
    1.54 +  gNextRunFunc();
    1.55 +}
    1.56 +
    1.57 +/**
    1.58 + * The following tests use a custom XMLHttpRequest to return the status codes
    1.59 + */
    1.60 +
    1.61 +// default onerror error message (error code 399 is not defined)
    1.62 +function run_test_pt1() {
    1.63 +  gStatusCode = null;
    1.64 +  gStatusText = null;
    1.65 +  gCheckFunc = check_test_pt1;
    1.66 +  gExpectedStatusCode = 399;
    1.67 +  logTestInfo("testing default onerror error message");
    1.68 +  gUpdateChecker.checkForUpdates(updateCheckListener, true);
    1.69 +}
    1.70 +
    1.71 +function check_test_pt1() {
    1.72 +  do_check_eq(gStatusCode, gExpectedStatusCode);
    1.73 +  var expectedStatusText = getStatusText(404);
    1.74 +  do_check_eq(gStatusText, expectedStatusText);
    1.75 +  run_test_pt2();
    1.76 +}
    1.77 +
    1.78 +// file malformed - 200
    1.79 +function run_test_pt2() {
    1.80 +  run_test_helper(run_test_pt3, 200,
    1.81 +                  "testing file malformed");
    1.82 +}
    1.83 +
    1.84 +// access denied - 403
    1.85 +function run_test_pt3() {
    1.86 +  run_test_helper(run_test_pt4, 403,
    1.87 +                  "testing access denied");
    1.88 +}
    1.89 +
    1.90 +// file not found - 404
    1.91 +function run_test_pt4() {
    1.92 +  run_test_helper(run_test_pt5, 404,
    1.93 +                  "testing file not found");
    1.94 +}
    1.95 +
    1.96 +// internal server error - 500
    1.97 +function run_test_pt5() {
    1.98 +  run_test_helper(run_test_pt6, 500,
    1.99 +                  "testing internal server error");
   1.100 +}
   1.101 +
   1.102 +// failed (unknown reason) - NS_BINDING_FAILED (2152398849)
   1.103 +function run_test_pt6() {
   1.104 +  run_test_helper(run_test_pt7, AUS_Cr.NS_BINDING_FAILED,
   1.105 +                  "testing failed (unknown reason)");
   1.106 +}
   1.107 +
   1.108 +// connection timed out - NS_ERROR_NET_TIMEOUT (2152398862)
   1.109 +function run_test_pt7() {
   1.110 +  run_test_helper(run_test_pt8, AUS_Cr.NS_ERROR_NET_TIMEOUT,
   1.111 +                  "testing connection timed out");
   1.112 +}
   1.113 +
   1.114 +// network offline - NS_ERROR_OFFLINE (2152398864)
   1.115 +function run_test_pt8() {
   1.116 +  run_test_helper(run_test_pt9, AUS_Cr.NS_ERROR_OFFLINE,
   1.117 +                  "testing network offline");
   1.118 +}
   1.119 +
   1.120 +// port not allowed - NS_ERROR_PORT_ACCESS_NOT_ALLOWED (2152398867)
   1.121 +function run_test_pt9() {
   1.122 +  run_test_helper(run_test_pt10, AUS_Cr.NS_ERROR_PORT_ACCESS_NOT_ALLOWED,
   1.123 +                  "testing port not allowed");
   1.124 +}
   1.125 +
   1.126 +// no data was received - NS_ERROR_NET_RESET (2152398868)
   1.127 +function run_test_pt10() {
   1.128 +  run_test_helper(run_test_pt11, AUS_Cr.NS_ERROR_NET_RESET,
   1.129 +                  "testing no data was received");
   1.130 +}
   1.131 +
   1.132 +// update server not found - NS_ERROR_UNKNOWN_HOST (2152398878)
   1.133 +function run_test_pt11() {
   1.134 +  run_test_helper(run_test_pt12, AUS_Cr.NS_ERROR_UNKNOWN_HOST,
   1.135 +                  "testing update server not found");
   1.136 +}
   1.137 +
   1.138 +// proxy server not found - NS_ERROR_UNKNOWN_PROXY_HOST (2152398890)
   1.139 +function run_test_pt12() {
   1.140 +  run_test_helper(run_test_pt13, AUS_Cr.NS_ERROR_UNKNOWN_PROXY_HOST,
   1.141 +                  "testing proxy server not found");
   1.142 +}
   1.143 +
   1.144 +// data transfer interrupted - NS_ERROR_NET_INTERRUPT (2152398919)
   1.145 +function run_test_pt13() {
   1.146 +  run_test_helper(run_test_pt14, AUS_Cr.NS_ERROR_NET_INTERRUPT,
   1.147 +                  "testing data transfer interrupted");
   1.148 +}
   1.149 +
   1.150 +// proxy server connection refused - NS_ERROR_PROXY_CONNECTION_REFUSED (2152398920)
   1.151 +function run_test_pt14() {
   1.152 +  run_test_helper(run_test_pt15, AUS_Cr.NS_ERROR_PROXY_CONNECTION_REFUSED,
   1.153 +                  "testing proxy server connection refused");
   1.154 +}
   1.155 +
   1.156 +// server certificate expired - 2153390069
   1.157 +function run_test_pt15() {
   1.158 +  run_test_helper(run_test_pt16, 2153390069,
   1.159 +                  "testing server certificate expired");
   1.160 +}
   1.161 +
   1.162 +// network is offline - NS_ERROR_DOCUMENT_NOT_CACHED (2152398918)
   1.163 +function run_test_pt16() {
   1.164 +  run_test_helper(run_test_pt17, AUS_Cr.NS_ERROR_DOCUMENT_NOT_CACHED,
   1.165 +                  "testing network is offline");
   1.166 +}
   1.167 +
   1.168 +// connection refused - NS_ERROR_CONNECTION_REFUSED (2152398861)
   1.169 +function run_test_pt17() {
   1.170 +  run_test_helper(doTestFinish, AUS_Cr.NS_ERROR_CONNECTION_REFUSED,
   1.171 +                  "testing connection refused");
   1.172 +}

mercurial