2014-06-25 09:12:07 +04:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
2013-09-19 16:50:21 +04:00
|
|
|
/* 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);
|
2014-05-01 17:57:00 +04:00
|
|
|
|
2013-09-19 16:50:21 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-05-01 17:57:00 +04:00
|
|
|
function test_sockets(serverSocket) {
|
2014-03-13 16:08:04 +04:00
|
|
|
do_test_pending();
|
|
|
|
gDashboard.requestSockets(function(data) {
|
|
|
|
let index = -1;
|
2014-05-01 17:57:00 +04:00
|
|
|
do_print("requestSockets: " + JSON.stringify(data.sockets));
|
2014-03-13 16:08:04 +04:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-09-19 16:50:21 +04:00
|
|
|
function run_test() {
|
2014-09-19 14:36:00 +04:00
|
|
|
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");
|
|
|
|
});
|
|
|
|
|
2014-05-01 17:57:00 +04:00
|
|
|
let serverSocket = Components.classes["@mozilla.org/network/server-socket;1"]
|
|
|
|
.createInstance(Ci.nsIServerSocket);
|
2013-09-19 16:50:21 +04:00
|
|
|
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) {
|
2013-11-20 18:29:01 +04:00
|
|
|
let found = false;
|
2014-05-01 17:57:00 +04:00
|
|
|
do_print("requestDNSInfo: " + JSON.stringify(data.entries));
|
2013-11-20 18:29:01 +04:00
|
|
|
for (let i = 0; i < data.entries.length; i++) {
|
|
|
|
if (data.entries[i].hostname == "localhost") {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
do_check_eq(found, true);
|
2013-09-19 16:50:21 +04:00
|
|
|
|
|
|
|
do_test_finished();
|
2014-05-01 17:57:00 +04:00
|
|
|
test_sockets(serverSocket);
|
2013-09-19 16:50:21 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
do_test_finished();
|
|
|
|
}
|
|
|
|
if (connectionFailed(connInfo.status)) {
|
|
|
|
do_throw(connInfo.status);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|