Fix js/xpconnect/tests/chrome/test_bug853571.xul and use SpecialPowers more.
authorPeter Van der Beken <peterv@propagandism.org>
Sat, 15 Feb 2014 22:12:35 +0100
changeset 181843 cdd53387bf1a4e03c800483430567808662243e6
parent 181842 53b25b8cafe9b6ecc666dbeb0b93f976922bb39d
child 181844 3ab5bc52b9c556735d99b7fdb349b055feb8bad7
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
bugs853571
milestone32.0a1
Fix js/xpconnect/tests/chrome/test_bug853571.xul and use SpecialPowers more. * * * Fix webspeech tests to work with Window on WebIDL bindings.
content/media/webspeech/synth/ipc/test/file_ipc.html
content/media/webspeech/synth/ipc/test/mochitest.ini
content/media/webspeech/synth/ipc/test/test_ipc.html
dom/plugins/test/mochitest/cocoa_focus.html
dom/tests/browser/browser_ConsoleStorageAPITests.js
js/xpconnect/tests/chrome/test_bug853571.xul
copy from content/media/webspeech/synth/ipc/test/test_ipc.html
copy to content/media/webspeech/synth/ipc/test/file_ipc.html
--- a/content/media/webspeech/synth/ipc/test/test_ipc.html
+++ b/content/media/webspeech/synth/ipc/test/file_ipc.html
@@ -6,18 +6,16 @@
   <script type="application/javascript" src="../../test/common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
   <body>
 
   <script type="application/javascript;version=1.7">
     "use strict";
 
-    SimpleTest.waitForExplicitFinish();
-
     function iframeScriptFirst() {
       content.wrappedJSObject.RunSet.reloadAndRunAll({
           preventDefault: function() { },
           __exposedProps__: { preventDefault: 'r' }
       });
     }
 
     function iframeScriptSecond() {
--- a/content/media/webspeech/synth/ipc/test/mochitest.ini
+++ b/content/media/webspeech/synth/ipc/test/mochitest.ini
@@ -1,5 +1,7 @@
 [DEFAULT]
 skip-if = e10s
+support-files =
+  file_ipc.html
 
 [test_ipc.html]
 skip-if = buildapp == 'b2g' || toolkit == 'android' #bug 857673 # b2g(comp.classes['@mozilla.org/special-powers-observer;1'] is undefined) b2g-debug(comp.classes['@mozilla.org/special-powers-observer;1'] is undefined) b2g-desktop(comp.classes['@mozilla.org/special-powers-observer;1'] is undefined)
--- a/content/media/webspeech/synth/ipc/test/test_ipc.html
+++ b/content/media/webspeech/synth/ipc/test/test_ipc.html
@@ -1,191 +1,17 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <title>Test for OOP TTS</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="application/javascript" src="../../test/common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
   <body>
-
+  <iframe id="testFrame"></iframe>
   <script type="application/javascript;version=1.7">
-    "use strict";
-
     SimpleTest.waitForExplicitFinish();
 
-    function iframeScriptFirst() {
-      content.wrappedJSObject.RunSet.reloadAndRunAll({
-          preventDefault: function() { },
-          __exposedProps__: { preventDefault: 'r' }
-      });
-    }
-
-    function iframeScriptSecond() {
-      let TestRunner = content.wrappedJSObject.TestRunner;
-
-      let oldComplete = TestRunner.onComplete;
-
-      TestRunner.onComplete = function() {
-        TestRunner.onComplete = oldComplete;
-
-        sendAsyncMessage("test:SpeechSynthesis:ipcTestComplete", {
-          result: JSON.stringify(TestRunner._failedTests)
-        });
-
-        if (oldComplete) {
-          oldComplete();
-        }
-      };
-
-      let oldLog = TestRunner.log;
-      TestRunner.log = function(msg) {
-        sendAsyncMessage("test:SpeechSynthesis:ipcTestMessage", { msg: msg });
-      }
-    }
-
-    let regex = /^(TEST-PASS|TEST-UNEXPECTED-PASS|TEST-KNOWN-FAIL|TEST-UNEXPECTED-FAIL|TEST-DEBUG-INFO) \| ([^\|]+) \|(.*)/;
-
-    function onTestMessage(data) {
-      let message = SpecialPowers.wrap(data).json.msg;
-      let match = regex.exec(message);
-      if (match) {
-        let state = match[1];
-        let details = match[2] + " | " + match[3];
-
-        switch (state) {
-          case "TEST-PASS":
-          case "TEST-KNOWN-FAIL":
-            ok(true, details);
-            break;
-
-          case "TEST-UNEXPECTED-FAIL":
-          case "TEST-UNEXPECTED-PASS":
-            ok(false, details);
-            break;
-
-          case "TEST-DEBUG-INFO":
-          default:
-            info(details);
-        }
-      }
-    }
-
-    function onTestComplete() {
-      let comp = SpecialPowers.wrap(SpecialPowers.Components);
-      let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
-      let spObserver = comp.classes["@mozilla.org/special-powers-observer;1"]
-                            .getService(comp.interfaces.nsIMessageListener);
-
-      mm.removeMessageListener("SPPrefService", spObserver);
-      mm.removeMessageListener("SPProcessCrashService", spObserver);
-      mm.removeMessageListener("SPPingService", spObserver);
-      mm.removeMessageListener("SpecialPowers.Quit", spObserver);
-      mm.removeMessageListener("SPPermissionManager", spObserver);
-
-      mm.removeMessageListener("test:SpeechSynthesis:ipcTestMessage", onTestMessage);
-      mm.removeMessageListener("test:SpeechSynthesis:ipcTestComplete", onTestComplete);
-
-      let ppmm = SpecialPowers.Cc["@mozilla.org/parentprocessmessagemanager;1"]
-        .getService(SpecialPowers.Ci.nsIMessageBroadcaster);
-      ppmm.removeMessageListener("test:SpeechSynthesis:ipcSynthAddVoice", onSynthAddVoice);
-      ppmm.removeMessageListener("test:SpeechSynthesis:ipcSynthSetDefault", onSynthSetDefault);
-      ppmm.removeMessageListener("test:SpeechSynthesis:ipcSynthCleanup", onSynthCleanup);
-
-      SimpleTest.executeSoon(function () { SimpleTest.finish(); });
-    }
-
-    function onSynthAddVoice(data) {
-      let message = SpecialPowers.wrap(data).json;
-      return synthAddVoice.apply(synthAddVoice, message);
-    }
-
-    function onSynthSetDefault(data) {
-      let message = SpecialPowers.wrap(data).json;
-      synthSetDefault.apply(synthSetDefault, message);
-    }
-
-    function onSynthCleanup(data) {
-      synthCleanup();
-    }
-
-    function runTests() {
-      let iframe = document.createElement("iframe");
-      SpecialPowers.wrap(iframe).mozbrowser = true;
-      iframe.id = "iframe";
-      iframe.style.width = "100%";
-      iframe.style.height = "1000px";
-
-      function iframeLoadSecond() {
-        ok(true, "Got second iframe load event.");
-        iframe.removeEventListener("mozbrowserloadend", iframeLoadSecond);
-        let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
-        mm.loadFrameScript("data:,(" + iframeScriptSecond.toString() + ")();",
-                           false);
-      }
-
-      function iframeLoadFirst() {
-        ok(true, "Got first iframe load event.");
-        iframe.removeEventListener("mozbrowserloadend", iframeLoadFirst);
-        iframe.addEventListener("mozbrowserloadend", iframeLoadSecond);
-
-        let mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
-
-        let comp = SpecialPowers.wrap(SpecialPowers.Components);
-
-        let spObserver =
-          comp.classes["@mozilla.org/special-powers-observer;1"]
-              .getService(comp.interfaces.nsIMessageListener);
-
-        mm.addMessageListener("SPPrefService", spObserver);
-        mm.addMessageListener("SPProcessCrashService", spObserver);
-        mm.addMessageListener("SPPingService", spObserver);
-        mm.addMessageListener("SpecialPowers.Quit", spObserver);
-        mm.addMessageListener("SPPermissionManager", spObserver);
-
-        mm.addMessageListener("test:SpeechSynthesis:ipcTestMessage", onTestMessage);
-        mm.addMessageListener("test:SpeechSynthesis:ipcTestComplete", onTestComplete);
-
-        let specialPowersBase = "chrome://specialpowers/content/";
-        mm.loadFrameScript(specialPowersBase + "MozillaLogger.js", false);
-        mm.loadFrameScript(specialPowersBase + "specialpowersAPI.js", false);
-        mm.loadFrameScript(specialPowersBase + "specialpowers.js", false);
-
-        mm.loadFrameScript("data:,(" + iframeScriptFirst.toString() + ")();", false);
-
-        let ppmm = SpecialPowers.Cc["@mozilla.org/parentprocessmessagemanager;1"]
-          .getService(SpecialPowers.Ci.nsIMessageBroadcaster);
-        ppmm.addMessageListener("test:SpeechSynthesis:ipcSynthAddVoice", onSynthAddVoice);
-        ppmm.addMessageListener("test:SpeechSynthesis:ipcSynthSetDefault", onSynthSetDefault);
-        ppmm.addMessageListener("test:SpeechSynthesis:ipcSynthCleanup", onSynthCleanup);
-      }
-
-      iframe.addEventListener("mozbrowserloadend", iframeLoadFirst);
-
-      // Strip this filename and one directory level and then add "/test".
-      let href =  window.location.href;
-      href = href.substring(0, href.lastIndexOf('/'));
-      href = href.substring(0, href.lastIndexOf('/'));
-      href = href.substring(0, href.lastIndexOf('/'));
-      iframe.src = href + "/test?consoleLevel=INFO";
-
-      document.body.appendChild(iframe);
-    }
-
-    addEventListener("load", function() {
-
-      SpecialPowers.addPermission("browser", true, document);
-      SpecialPowers.pushPrefEnv({
-        "set": [
-          // TODO: remove this as part of bug 820712
-          ["network.disable.ipc.security", true],
-
-          ["dom.ipc.browser_frames.oop_by_default", true],
-          ["dom.mozBrowserFramesEnabled", true],
-          ["browser.pagethumbnails.capturing_disabled", true]
-        ]
-      }, runTests);
-    });
-
+    SpecialPowers.pushPrefEnv({ set: [['media.webspeech.synth.enabled', true]] },
+                              function() { document.getElementById("testFrame").src = "file_ipc.html"; });
   </script>
 </body>
 </html>
--- a/dom/plugins/test/mochitest/cocoa_focus.html
+++ b/dom/plugins/test/mochitest/cocoa_focus.html
@@ -11,18 +11,17 @@
     }
 
     function ok(aValue, aMessage) {
       window.opener.SimpleTest.ok(aValue, aMessage);
     }
 
     function runTests() {
       netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-      var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                                        getInterface(Components.interfaces.nsIDOMWindowUtils);
+      var utils = SpecialPowers.DOMWindowUtils;
 
       var plugin1 = document.getElementById("plugin1"); // What we're testing.
       var plugin2 = document.getElementById("plugin2"); // Dummy.
 
       var plugin1Bounds = plugin1.getBoundingClientRect();
       var plugin2Bounds = plugin2.getBoundingClientRect();
 
       var plugin1X = (window.mozInnerScreenX + plugin1Bounds.left + 10);
--- a/dom/tests/browser/browser_ConsoleStorageAPITests.js
+++ b/dom/tests/browser/browser_ConsoleStorageAPITests.js
@@ -94,12 +94,10 @@ function test()
       win.console.warn("this", "is", "a", "warn message");
       win.console.error("this", "is", "a", "error message");
     });
   }, false);
 }
 
 function getWindowId(aWindow)
 {
-  return aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
-                .getInterface(Ci.nsIDOMWindowUtils)
-                .currentInnerWindowID;
+  return SpecialPowers.getDOMWindowUtils(aWindow).currentInnerWindowID;
 }
--- a/js/xpconnect/tests/chrome/test_bug853571.xul
+++ b/js/xpconnect/tests/chrome/test_bug853571.xul
@@ -30,26 +30,34 @@ https://bugzilla.mozilla.org/show_bug.cg
 
     // Test with a sandboxPrototype.
     checkSource(iwin, new Cu.Sandbox(iwin, { sandboxPrototype: iwin }), iwin, "should be able to impersonate the prototype");
     yield;
 
     SimpleTest.finish();
   }
 
-  let gen = mainTest();
+  var gen;
+  function runTest() {
+    gen = mainTest();
+    gen.next();
+  }
 
   function checkSource(target, sb, expectedSource, message) {
     target.addEventListener("message", function listener(event) {
       target.removeEventListener("message", listener);
       is(event.source, expectedSource, message);
-      gen.next();
+      try {
+        gen.next();
+      } catch (e if e instanceof StopIteration) {
+        // We're done.
+      }
     });
 
     sb.target = target;
     Cu.evalInSandbox("target.postMessage('foo', '*');", sb);
   }
 
 
   ]]>
   </script>
-  <iframe id="ifr" type="content" onload="gen.next();" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
+  <iframe id="ifr" type="content" onload="runTest()" src="http://example.org/tests/js/xpconnect/tests/mochitest/file_empty.html" />
 </window>