netwerk/test/unit/test_ping_aboutnetworking.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 /* -*- Mode: Javasript; indent-tab-mode: nil; js-indent-level: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 const gDashboard = Cc['@mozilla.org/network/dashboard;1']
michael@0 7 .getService(Ci.nsIDashboard);
michael@0 8
michael@0 9 function connectionFailed(status) {
michael@0 10 let status_ok = [
michael@0 11 "NS_NET_STATUS_RESOLVING_HOST"
michael@0 12 ,"NS_NET_STATUS_RESOLVED_HOST"
michael@0 13 ,"NS_NET_STATUS_CONNECTING_TO"
michael@0 14 ,"NS_NET_STATUS_CONNECTED_TO"
michael@0 15 ];
michael@0 16 for (let i = 0; i < status_ok.length; i++) {
michael@0 17 if (status == status_ok[i]) {
michael@0 18 return false;
michael@0 19 }
michael@0 20 }
michael@0 21
michael@0 22 return true;
michael@0 23 }
michael@0 24
michael@0 25 function test_sockets(serverSocket) {
michael@0 26 do_test_pending();
michael@0 27 gDashboard.requestSockets(function(data) {
michael@0 28 let index = -1;
michael@0 29 do_print("requestSockets: " + JSON.stringify(data.sockets));
michael@0 30 for (let i = 0; i < data.sockets.length; i++) {
michael@0 31 if (data.sockets[i].host == "127.0.0.1") {
michael@0 32 index = i;
michael@0 33 break;
michael@0 34 }
michael@0 35 }
michael@0 36 do_check_neq(index, -1);
michael@0 37 do_check_eq(data.sockets[index].port, serverSocket.port);
michael@0 38 do_check_eq(data.sockets[index].tcp, 1);
michael@0 39
michael@0 40 do_test_finished();
michael@0 41 });
michael@0 42 }
michael@0 43
michael@0 44 function run_test() {
michael@0 45 let serverSocket = Components.classes["@mozilla.org/network/server-socket;1"]
michael@0 46 .createInstance(Ci.nsIServerSocket);
michael@0 47 serverSocket.init(-1, true, -1);
michael@0 48
michael@0 49 do_test_pending();
michael@0 50 gDashboard.requestConnection("localhost", serverSocket.port,
michael@0 51 "tcp", 15, function(connInfo) {
michael@0 52 if (connInfo.status == "NS_NET_STATUS_CONNECTED_TO") {
michael@0 53 do_test_pending();
michael@0 54 gDashboard.requestDNSInfo(function(data) {
michael@0 55 let found = false;
michael@0 56 do_print("requestDNSInfo: " + JSON.stringify(data.entries));
michael@0 57 for (let i = 0; i < data.entries.length; i++) {
michael@0 58 if (data.entries[i].hostname == "localhost") {
michael@0 59 found = true;
michael@0 60 break;
michael@0 61 }
michael@0 62 }
michael@0 63 do_check_eq(found, true);
michael@0 64
michael@0 65 do_test_finished();
michael@0 66 test_sockets(serverSocket);
michael@0 67 });
michael@0 68
michael@0 69 do_test_finished();
michael@0 70 }
michael@0 71 if (connectionFailed(connInfo.status)) {
michael@0 72 do_throw(connInfo.status);
michael@0 73 }
michael@0 74 });
michael@0 75 }
michael@0 76

mercurial