diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /netwerk/test/unit/test_websocket_offline.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_websocket_offline.js')
-rw-r--r-- | netwerk/test/unit/test_websocket_offline.js | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_websocket_offline.js b/netwerk/test/unit/test_websocket_offline.js new file mode 100644 index 0000000000..1f13879dbc --- /dev/null +++ b/netwerk/test/unit/test_websocket_offline.js @@ -0,0 +1,51 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + +// checking to make sure we don't hang as per 1038304 +// offline so url isn't impt +var url = "ws://localhost"; +var chan; +var offlineStatus; + +var listener = { + onAcknowledge(aContext, aSize) {}, + onBinaryMessageAvailable(aContext, aMsg) {}, + onMessageAvailable(aContext, aMsg) {}, + onServerClose(aContext, aCode, aReason) {}, + onStart(aContext) { + // onStart is not called when a connection fails + Assert.ok(false); + }, + onStop(aContext, aStatusCode) { + Assert.notEqual(aStatusCode, Cr.NS_OK); + Services.io.offline = offlineStatus; + do_test_finished(); + }, +}; + +function run_test() { + offlineStatus = Services.io.offline; + Services.io.offline = true; + + try { + chan = Cc["@mozilla.org/network/protocol;1?name=ws"].createInstance( + Ci.nsIWebSocketChannel + ); + chan.initLoadInfo( + null, // aLoadingNode + Services.scriptSecurityManager.getSystemPrincipal(), + null, // aTriggeringPrincipal + Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_SEC_CONTEXT_IS_NULL, + Ci.nsIContentPolicy.TYPE_WEBSOCKET + ); + + var uri = Services.io.newURI(url); + chan.asyncOpen(uri, url, {}, 0, listener, null); + do_test_pending(); + } catch (x) { + dump("throwing " + x); + do_throw(x); + } +} |