Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 var gExpectedStatus = null;
7 var gNextTestFunc = null;
9 var asyncXHR = {
10 load: function() {
11 var request = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
12 .createInstance(Components.interfaces.nsIXMLHttpRequest);
13 request.open("GET", "http://localhost:4444/test_error_code.xml", true);
15 var self = this;
16 request.addEventListener("error", function(event) { self.onError(event); }, false);
17 request.send(null);
18 },
19 onError: function doAsyncRequest_onError(event) {
20 var request = event.target.channel.QueryInterface(Components.interfaces.nsIRequest);
21 do_check_eq(request.status, gExpectedStatus);
22 gNextTestFunc();
23 }
24 }
26 function run_test() {
27 do_test_pending();
28 do_timeout(0, run_test_pt1);
29 }
31 // network offline
32 function run_test_pt1() {
33 var ioService = Components.classes["@mozilla.org/network/io-service;1"]
34 .getService(Components.interfaces.nsIIOService);
36 try {
37 ioService.manageOfflineStatus = false;
38 }
39 catch (e) {
40 }
41 ioService.offline = true;
43 gExpectedStatus = Components.results.NS_ERROR_OFFLINE;
44 gNextTestFunc = run_test_pt2;
45 dump("Testing error returned by async XHR when the network is offline\n");
46 asyncXHR.load();
47 }
49 // connection refused
50 function run_test_pt2() {
51 var ioService = Components.classes["@mozilla.org/network/io-service;1"]
52 .getService(Components.interfaces.nsIIOService);
53 ioService.offline = false;
55 gExpectedStatus = Components.results.NS_ERROR_CONNECTION_REFUSED;
56 gNextTestFunc = end_test;
57 dump("Testing error returned by aync XHR when the connection is refused\n");
58 asyncXHR.load();
59 }
61 function end_test() {
62 do_test_finished();
63 }