netwerk/test/unit/test_ping_aboutnetworking.js

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial