test_websocket_offline.js (1378B)
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 "use strict"; 5 6 // checking to make sure we don't hang as per 1038304 7 // offline so url isn't impt 8 var url = "ws://localhost"; 9 var chan; 10 var offlineStatus; 11 12 var listener = { 13 onAcknowledge() {}, 14 onBinaryMessageAvailable() {}, 15 onMessageAvailable() {}, 16 onServerClose() {}, 17 onStart() { 18 // onStart is not called when a connection fails 19 Assert.ok(false); 20 }, 21 onStop(aContext, aStatusCode) { 22 Assert.notEqual(aStatusCode, Cr.NS_OK); 23 Services.io.offline = offlineStatus; 24 do_test_finished(); 25 }, 26 }; 27 28 function run_test() { 29 offlineStatus = Services.io.offline; 30 Services.io.offline = true; 31 32 try { 33 chan = Cc["@mozilla.org/network/protocol;1?name=ws"].createInstance( 34 Ci.nsIWebSocketChannel 35 ); 36 chan.initLoadInfo( 37 null, // aLoadingNode 38 Services.scriptSecurityManager.getSystemPrincipal(), 39 null, // aTriggeringPrincipal 40 Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL, 41 Ci.nsIContentPolicy.TYPE_WEBSOCKET 42 ); 43 44 var uri = Services.io.newURI(url); 45 chan.asyncOpen(uri, url, {}, 0, listener, null); 46 do_test_pending(); 47 } catch (x) { 48 dump("throwing " + x); 49 do_throw(x); 50 } 51 }