diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /netwerk/test/unit/test_ping_aboutnetworking.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'netwerk/test/unit/test_ping_aboutnetworking.js')
-rw-r--r-- | netwerk/test/unit/test_ping_aboutnetworking.js | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_ping_aboutnetworking.js b/netwerk/test/unit/test_ping_aboutnetworking.js new file mode 100644 index 000000000..6db46cb93 --- /dev/null +++ b/netwerk/test/unit/test_ping_aboutnetworking.js @@ -0,0 +1,86 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* 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/. */ + +const gDashboard = Cc['@mozilla.org/network/dashboard;1'] + .getService(Ci.nsIDashboard); + +function connectionFailed(status) { + let status_ok = [ + "NS_NET_STATUS_RESOLVING_HOST" + ,"NS_NET_STATUS_RESOLVED_HOST" + ,"NS_NET_STATUS_CONNECTING_TO" + ,"NS_NET_STATUS_CONNECTED_TO" + ]; + for (let i = 0; i < status_ok.length; i++) { + if (status == status_ok[i]) { + return false; + } + } + + return true; +} + +function test_sockets(serverSocket) { + do_test_pending(); + gDashboard.requestSockets(function(data) { + let index = -1; + do_print("requestSockets: " + JSON.stringify(data.sockets)); + for (let i = 0; i < data.sockets.length; i++) { + if (data.sockets[i].host == "127.0.0.1") { + index = i; + break; + } + } + do_check_neq(index, -1); + do_check_eq(data.sockets[index].port, serverSocket.port); + do_check_eq(data.sockets[index].tcp, 1); + + do_test_finished(); + }); +} + +function run_test() { + var ps = Cc["@mozilla.org/preferences-service;1"] + .getService(Ci.nsIPrefBranch); + // disable network changed events to avoid the the risk of having the dns + // cache getting flushed behind our back + ps.setBoolPref("network.notify.changed", false); + + do_register_cleanup(function() { + ps.clearUserPref("network.notify.changed"); + }); + + let serverSocket = Components.classes["@mozilla.org/network/server-socket;1"] + .createInstance(Ci.nsIServerSocket); + serverSocket.init(-1, true, -1); + + do_test_pending(); + gDashboard.requestConnection("localhost", serverSocket.port, + "tcp", 15, function(connInfo) { + if (connInfo.status == "NS_NET_STATUS_CONNECTED_TO") { + do_test_pending(); + gDashboard.requestDNSInfo(function(data) { + let found = false; + do_print("requestDNSInfo: " + JSON.stringify(data.entries)); + for (let i = 0; i < data.entries.length; i++) { + if (data.entries[i].hostname == "localhost") { + found = true; + break; + } + } + do_check_eq(found, true); + + do_test_finished(); + test_sockets(serverSocket); + }); + + do_test_finished(); + } + if (connectionFailed(connInfo.status)) { + do_throw(connInfo.status); + } + }); +} + |