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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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 // Errors tested:
     7 // 200, 403, 404, 500, 2152398849, 2152398862, 2152398864, 2152398867,
     8 // 2152398868, 2152398878, 2152398890, 2152398919, 2152398920, 2153390069,
     9 // 2152398918, 2152398861
    11 var gNextRunFunc;
    12 var gExpectedStatusCode;
    13 var gExpectedStatusText;
    15 function run_test() {
    16   setupTestCommon();
    18   logTestInfo("testing nsIUpdateCheckListener onload and onerror error code " +
    19               "and statusText values");
    21   setUpdateURLOverride();
    22   standardInit();
    23   // The mock XMLHttpRequest is MUCH faster
    24   overrideXHR(callHandleEvent);
    25   do_execute_soon(run_test_pt1);
    26 }
    28 // Callback function used by the custom XMLHttpRequest implementation to
    29 // call the nsIDOMEventListener's handleEvent method for onload.
    30 function callHandleEvent() {
    31   gXHR.status = gExpectedStatusCode;
    32   var e = { target: gXHR };
    33   gXHR.onload(e);
    34 }
    36 // Helper functions for testing nsIUpdateCheckListener statusText
    37 function run_test_helper(aNextRunFunc, aExpectedStatusCode, aMsg) {
    38   gStatusCode = null;
    39   gStatusText = null;
    40   gCheckFunc = check_test_helper;
    41   gNextRunFunc = aNextRunFunc;
    42   gExpectedStatusCode = aExpectedStatusCode;
    43   logTestInfo(aMsg, Components.stack.caller);
    44   gUpdateChecker.checkForUpdates(updateCheckListener, true);
    45 }
    47 function check_test_helper() {
    48   do_check_eq(gStatusCode, gExpectedStatusCode);
    49   var expectedStatusText = getStatusText(gExpectedStatusCode);
    50   do_check_eq(gStatusText, expectedStatusText);
    51   gNextRunFunc();
    52 }
    54 /**
    55  * The following tests use a custom XMLHttpRequest to return the status codes
    56  */
    58 // default onerror error message (error code 399 is not defined)
    59 function run_test_pt1() {
    60   gStatusCode = null;
    61   gStatusText = null;
    62   gCheckFunc = check_test_pt1;
    63   gExpectedStatusCode = 399;
    64   logTestInfo("testing default onerror error message");
    65   gUpdateChecker.checkForUpdates(updateCheckListener, true);
    66 }
    68 function check_test_pt1() {
    69   do_check_eq(gStatusCode, gExpectedStatusCode);
    70   var expectedStatusText = getStatusText(404);
    71   do_check_eq(gStatusText, expectedStatusText);
    72   run_test_pt2();
    73 }
    75 // file malformed - 200
    76 function run_test_pt2() {
    77   run_test_helper(run_test_pt3, 200,
    78                   "testing file malformed");
    79 }
    81 // access denied - 403
    82 function run_test_pt3() {
    83   run_test_helper(run_test_pt4, 403,
    84                   "testing access denied");
    85 }
    87 // file not found - 404
    88 function run_test_pt4() {
    89   run_test_helper(run_test_pt5, 404,
    90                   "testing file not found");
    91 }
    93 // internal server error - 500
    94 function run_test_pt5() {
    95   run_test_helper(run_test_pt6, 500,
    96                   "testing internal server error");
    97 }
    99 // failed (unknown reason) - NS_BINDING_FAILED (2152398849)
   100 function run_test_pt6() {
   101   run_test_helper(run_test_pt7, AUS_Cr.NS_BINDING_FAILED,
   102                   "testing failed (unknown reason)");
   103 }
   105 // connection timed out - NS_ERROR_NET_TIMEOUT (2152398862)
   106 function run_test_pt7() {
   107   run_test_helper(run_test_pt8, AUS_Cr.NS_ERROR_NET_TIMEOUT,
   108                   "testing connection timed out");
   109 }
   111 // network offline - NS_ERROR_OFFLINE (2152398864)
   112 function run_test_pt8() {
   113   run_test_helper(run_test_pt9, AUS_Cr.NS_ERROR_OFFLINE,
   114                   "testing network offline");
   115 }
   117 // port not allowed - NS_ERROR_PORT_ACCESS_NOT_ALLOWED (2152398867)
   118 function run_test_pt9() {
   119   run_test_helper(run_test_pt10, AUS_Cr.NS_ERROR_PORT_ACCESS_NOT_ALLOWED,
   120                   "testing port not allowed");
   121 }
   123 // no data was received - NS_ERROR_NET_RESET (2152398868)
   124 function run_test_pt10() {
   125   run_test_helper(run_test_pt11, AUS_Cr.NS_ERROR_NET_RESET,
   126                   "testing no data was received");
   127 }
   129 // update server not found - NS_ERROR_UNKNOWN_HOST (2152398878)
   130 function run_test_pt11() {
   131   run_test_helper(run_test_pt12, AUS_Cr.NS_ERROR_UNKNOWN_HOST,
   132                   "testing update server not found");
   133 }
   135 // proxy server not found - NS_ERROR_UNKNOWN_PROXY_HOST (2152398890)
   136 function run_test_pt12() {
   137   run_test_helper(run_test_pt13, AUS_Cr.NS_ERROR_UNKNOWN_PROXY_HOST,
   138                   "testing proxy server not found");
   139 }
   141 // data transfer interrupted - NS_ERROR_NET_INTERRUPT (2152398919)
   142 function run_test_pt13() {
   143   run_test_helper(run_test_pt14, AUS_Cr.NS_ERROR_NET_INTERRUPT,
   144                   "testing data transfer interrupted");
   145 }
   147 // proxy server connection refused - NS_ERROR_PROXY_CONNECTION_REFUSED (2152398920)
   148 function run_test_pt14() {
   149   run_test_helper(run_test_pt15, AUS_Cr.NS_ERROR_PROXY_CONNECTION_REFUSED,
   150                   "testing proxy server connection refused");
   151 }
   153 // server certificate expired - 2153390069
   154 function run_test_pt15() {
   155   run_test_helper(run_test_pt16, 2153390069,
   156                   "testing server certificate expired");
   157 }
   159 // network is offline - NS_ERROR_DOCUMENT_NOT_CACHED (2152398918)
   160 function run_test_pt16() {
   161   run_test_helper(run_test_pt17, AUS_Cr.NS_ERROR_DOCUMENT_NOT_CACHED,
   162                   "testing network is offline");
   163 }
   165 // connection refused - NS_ERROR_CONNECTION_REFUSED (2152398861)
   166 function run_test_pt17() {
   167   run_test_helper(doTestFinish, AUS_Cr.NS_ERROR_CONNECTION_REFUSED,
   168                   "testing connection refused");
   169 }

mercurial