Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / netwerk / test / unit / test_ping_aboutnetworking.js
blobfbaaeaa405e10922f88fe0a0e6ae079b467ad6a5
1 /* -*- indent-tabs-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 "use strict";
8 const gDashboard = Cc["@mozilla.org/network/dashboard;1"].getService(
9 Ci.nsIDashboard
12 function connectionFailed(status) {
13 let status_ok = [
14 "NS_NET_STATUS_RESOLVING_HOST",
15 "NS_NET_STATUS_RESOLVED_HOST",
16 "NS_NET_STATUS_CONNECTING_TO",
17 "NS_NET_STATUS_CONNECTED_TO",
19 for (let i = 0; i < status_ok.length; i++) {
20 if (status == status_ok[i]) {
21 return false;
25 return true;
28 function test_sockets(serverSocket) {
29 // TODO: enable this test in bug 1581892.
30 if (mozinfo.socketprocess_networking) {
31 info("skip test_sockets");
32 do_test_finished();
33 return;
36 do_test_pending();
37 gDashboard.requestSockets(function (data) {
38 let index = -1;
39 info("requestSockets: " + JSON.stringify(data.sockets));
40 for (let i = 0; i < data.sockets.length; i++) {
41 if (data.sockets[i].host == "127.0.0.1") {
42 index = i;
43 break;
46 Assert.notEqual(index, -1);
47 Assert.equal(data.sockets[index].port, serverSocket.port);
48 Assert.equal(data.sockets[index].type, "TCP");
50 do_test_finished();
51 });
54 function run_test() {
55 var ps = Services.prefs;
56 // disable network changed events to avoid the the risk of having the dns
57 // cache getting flushed behind our back
58 ps.setBoolPref("network.notify.changed", false);
59 // Localhost is hardcoded to loopback and isn't cached, disable that with this pref
60 ps.setBoolPref("network.proxy.allow_hijacking_localhost", true);
62 registerCleanupFunction(function () {
63 ps.clearUserPref("network.notify.changed");
64 ps.clearUserPref("network.proxy.allow_hijacking_localhost");
65 });
67 let serverSocket = Cc["@mozilla.org/network/server-socket;1"].createInstance(
68 Ci.nsIServerSocket
70 serverSocket.init(-1, true, -1);
72 do_test_pending();
73 gDashboard.requestConnection(
74 "localhost",
75 serverSocket.port,
76 "tcp",
77 15,
78 function (connInfo) {
79 if (connInfo.status == "NS_NET_STATUS_CONNECTED_TO") {
80 do_test_pending();
81 gDashboard.requestDNSInfo(function (data) {
82 let found = false;
83 info("requestDNSInfo: " + JSON.stringify(data.entries));
84 for (let i = 0; i < data.entries.length; i++) {
85 if (data.entries[i].hostname == "localhost") {
86 found = true;
87 break;
90 Assert.equal(found, true);
92 do_test_finished();
93 test_sockets(serverSocket);
94 });
96 do_test_finished();
98 if (connectionFailed(connInfo.status)) {
99 do_throw(connInfo.status);