Bug 912103 - Tests for about:networking - http, dns, sockets, and websockets. r=valentin.gosu
authorRobert Bindar <robertbindar@gmail.com>
Wed, 11 Sep 2013 09:49:51 -0400
changeset 146672 2a18454f0aa33f03aca93fba340c0b1bc0a25ea2
parent 146671 d4d34d4d06e762abafea07aa1c83c32704defe70
child 146673 947a298ea5bb90af2c2d7ba4e2630ff61ae97052
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersvalentin.gosu
bugs912103
milestone26.0a1
Bug 912103 - Tests for about:networking - http, dns, sockets, and websockets. r=valentin.gosu
netwerk/test/unit/test_about_networking.js
netwerk/test/unit/xpcshell.ini
toolkit/content/tests/chrome/Makefile.in
toolkit/content/tests/chrome/file_about_networking_wsh.py
toolkit/content/tests/chrome/test_about_networking.html
new file mode 100644
--- /dev/null
+++ b/netwerk/test/unit/test_about_networking.js
@@ -0,0 +1,52 @@
+/* -*- Mode: Javasript; indent-tab-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 Cc = Components.classes;
+const Ci = Components.interfaces;
+
+let gDashboard = Cc['@mozilla.org/network/dashboard;1']
+  .getService(Ci.nsIDashboard);
+
+const RESOLVE_DISABLE_IPV6 = (1 << 5);
+
+add_test(function test_http() {
+  gDashboard.requestHttpConnections(function(data) {
+    do_check_neq(data.host.indexOf("example.com"), -1);
+
+    run_next_test();
+  });
+});
+
+add_test(function test_dns() {
+  gDashboard.requestDNSInfo(function(data) {
+    do_check_neq(data.hostname.indexOf("example.com"), -1);
+
+    run_next_test();
+  });
+});
+
+add_test(function test_sockets() {
+  let dns = Cc["@mozilla.org/network/dns-service;1"].getService(Ci.nsIDNSService);
+  let record = dns.resolve("example.com", RESOLVE_DISABLE_IPV6);
+  let answer = record.getNextAddrAsString();
+
+  gDashboard.requestSockets(function(data) {
+    do_check_neq(data.host.indexOf(answer), -1);
+
+    run_next_test();
+  });
+});
+
+function run_test() {
+  let ioService = Cc["@mozilla.org/network/io-service;1"]
+    .getService(Ci.nsIIOService);
+  let uri = ioService.newURI("http://example.com", null, null);
+  let channel = ioService.newChannelFromURI(uri);
+
+  channel.open();
+
+  run_next_test();
+}
+
--- a/netwerk/test/unit/xpcshell.ini
+++ b/netwerk/test/unit/xpcshell.ini
@@ -241,8 +241,9 @@ run-sequentially = Hardcoded hash value 
 run-sequentially = Hardcoded hash value includes port 4444.
 [test_bug826063.js]
 [test_bug812167.js]
 # Bug 675039: intermittent fail on Android-armv6 
 skip-if = os == "android"
 [test_tldservice_nextsubdomain.js]
 [test_about_protocol.js]
 [test_bug856978.js]
+[test_about_networking.js]
--- a/toolkit/content/tests/chrome/Makefile.in
+++ b/toolkit/content/tests/chrome/Makefile.in
@@ -164,8 +164,12 @@ else
 MOCHITEST_CHROME_FILES += test_autocomplete_mac_caret.xul
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
 MOCHITEST_CHROME_FILES += $(filter disabled-temporarily, test_cursorsnap.xul) \
 		window_cursorsnap_dialog.xul \
 		window_cursorsnap_wizard.xul
 endif
+
+MOCHITEST_CHROME_FILES += test_about_networking.html \
+		file_about_networking_wsh.py
+
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/chrome/file_about_networking_wsh.py
@@ -0,0 +1,9 @@
+from mod_pywebsocket import msgutil
+
+def web_socket_do_extra_handshake(request):
+	pass
+
+def web_socket_transfer_data(request):
+	while not request.client_terminated:
+		msgutil.receive_message(request)
+
new file mode 100644
--- /dev/null
+++ b/toolkit/content/tests/chrome/test_about_networking.html
@@ -0,0 +1,52 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=912103
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug </title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+
+  SimpleTest.waitForExplicitFinish();
+
+  function runTest() {
+    const Cc = Components.classes;
+    const Ci = Components.interfaces;
+
+    var dashboard = Cc['@mozilla.org/network/dashboard;1']
+                      .getService(Ci.nsIDashboard);
+    dashboard.enableLogging = true;
+
+    var wsURI = "ws://mochi.test:8888/chrome/toolkit/content/tests/chrome/file_about_networking";
+    var websocket = new WebSocket(wsURI);
+
+    websocket.addEventListener("open", function() {
+      dashboard.requestWebsocketConnections(function(data) {
+        isnot(data.hostport.indexOf("mochi.test:8888"), -1,
+              "tested websocket entry not found");
+        websocket.close();
+        SimpleTest.finish();
+      });
+    });
+  }
+
+  window.addEventListener("DOMContentLoaded", function run() {
+    window.removeEventListener("DOMContentLoaded", run);
+    runTest();
+  });
+
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=912103">Mozilla Bug </a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>