missed a test in 98d58c46e409 when disabling websockets. bug 616733. a=tests
authorPatrick McManus <mcmanus@ducksong.com>
Wed, 08 Dec 2010 15:35:21 -0800
changeset 58914 3a8b2f1490f3176135b6ce540240a7474c6811de
parent 58913 c44ffda23deb31a686eee13f9301c75a85f7ae2e
child 58915 d3d71ad68624097bab58584ed575d3338a84a165
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewerstests
bugs616733
milestone2.0b8pre
missed a test in 98d58c46e409 when disabling websockets. bug 616733. a=tests
content/base/test/test_ws_basic_tests.html
--- a/content/base/test/test_ws_basic_tests.html
+++ b/content/base/test/test_ws_basic_tests.html
@@ -12,45 +12,61 @@
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=472529">Mozilla Bug </a>
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 var ws;
+var oldPrefVal;
+var domBranch;
 
 var params = ["protocol", "resource", "origin", "end"];
 var results = ["test", "/tests/content/base/test/file_ws_basic_tests", "http://mochi.test:8888", "end"];
 
 function forcegc(){
   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   Components.utils.forceGC();
   var wu =  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                   .getInterface(Components.interfaces.nsIDOMWindowUtils);
   wu.garbageCollect();
 }
 
+function finishWSTest() {
+    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+    domBranch.setBoolPref("override-security-block", oldPrefVal);
+    SimpleTest.finish();
+}
+
 function testWebSocket () {
+  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+  var prefService =
+      Components.classes["@mozilla.org/preferences-service;1"]
+      .getService(Components.interfaces.nsIPrefService);
+  domBranch = prefService.getBranch("network.websocket.");
+  oldPrefVal = domBranch.getBoolPref("override-security-block");
+  domBranch.setBoolPref("override-security-block", true);
+
   var url = "ws://mochi.test:8888/tests/content/base/test/file_ws_basic_tests";
   ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_ws_basic_tests", "test");
   is(ws.url, url, "Wrong Websocket.url!");
   ws.onopen = function(e) {
     for (var i = 0; i < params.length; ++i) {
       document.getElementById('log').textContent += "sending " + params[i] + "\n";
       ws.send(params[i]);
     }
   }
   ws.onclose = function(e) {
     is(results.length, 0, "All the messages should have been processed!");
     testWebSocket2();
   }
   ws.onerror = function(e) {
     ok(false, "onerror called!");
-    SimpleTest.finish();
+    finishWSTest();
   }
   ws.onmessage = function(e) {
     document.getElementById('log').textContent += "\n" + e.data;
     is(e.data, results[0], "Unexpected message");
     results.shift();
   }
 }
 
@@ -66,17 +82,17 @@ function testWebSocket2() {
     ws.send("end");
   }
   ws.onclose = function(e) {
     is(messageCount, testCount, "Didn't receive all the messages!");
     testWebSocket3();
   }
   ws.onerror = function(e) {
     ok(false, "onerror called!");
-    SimpleTest.finish();
+    finishWSTest();
   }
   ws.onmessage = function(e) {
     ++messageCount;
     is(e.data, testMessage + messageCount, "Wrong message");
     document.getElementById('log').textContent = messageCount;
     if (messageCount == testCount) {
       this.onmessage = null;
     }
@@ -96,17 +112,17 @@ function testWebSocket3() {
     ws.send("end");
   }
   ws.onclose = function(e) {
     is(messageCount, testCount, "Didn't receive all the messages!");
     testWebSocket4();
   }
   ws.onerror = function(e) {
     ok(false, "onerror called!");
-    SimpleTest.finish();
+    finishWSTest();
   }
   ws.onmessage = function(e) {
     forcegc(); // Do something evil, call cycle collector a lot.
     ++messageCount;
     is(e.data, testMessage + messageCount, "Wrong message");
     document.getElementById('log').textContent = messageCount;
     if (messageCount == testCount) {
       this.onmessage = null;
@@ -123,17 +139,17 @@ function testWebSocket4() {
   }
   ws.onclose = function(e) {
     is(this, ws, "'this' should point to the WebSocket. (2)");
     //ok(e.wasClean, "Connection should have closed cleanly.");
     testWebSocket5();
   }
   ws.onerror = function(e) {
     ok(false, "onerror called!");
-    SimpleTest.finish();
+    finishWSTest();
   }
   ws.onmessage = function(e) {
     is(this, ws, "'this' should point to the WebSocket. (3)");
     is(e.data, longString, "Didn't get the huge message back!");
     document.getElementById('log').textContent += "\nReceived the huge message";
     this.close();
   }
 }
@@ -144,21 +160,21 @@ function testWebSocket5() {
     this.close();
   }
   ws.onclose = function(e) {
     //ok(e.wasClean, "Connection should have closed cleanly.");
     is(this.bufferedAmount, 0, "Shouldn't have anything buffered");
     var msg = "some data";
     this.send(msg);
     ok(this.bufferedAmount, msg.length, "Should have some data buffered");
-    SimpleTest.finish();
+    finishWSTest();
   }
   ws.onerror = function(e) {
     ok(false, "onerror called!");
-    SimpleTest.finish();
+    finishWSTest();
   }
 }
 
 SimpleTest.waitForExplicitFinish();
 
 </script>
 <pre id="log">
 </pre>