Bug 566251 - Findbar chrome tests shouldn't use nsIThreadManager directly. r=gavin
authorGraeme McCutcheon <graememcc_firefox@graeme-online.co.uk>
Wed, 02 Jun 2010 11:22:54 +0100
changeset 43014 2e351d9a80cac71f4e7b4a14dba7500e4ac7f2ea
parent 43013 ae1773250d396bc89cd69631a404f3d34b41f2a2
child 43015 a206d1143cc2191b3c4881fe9225a6c9047d9574
push idunknown
push userunknown
push dateunknown
reviewersgavin
bugs566251
milestone1.9.3a5pre
Bug 566251 - Findbar chrome tests shouldn't use nsIThreadManager directly. r=gavin
toolkit/content/tests/chrome/bug263683_window.xul
toolkit/content/tests/chrome/bug331215_window.xul
toolkit/content/tests/chrome/bug451286_window.xul
toolkit/content/tests/chrome/bug451540_window.xul
--- a/toolkit/content/tests/chrome/bug263683_window.xul
+++ b/toolkit/content/tests/chrome/bug263683_window.xul
@@ -38,52 +38,45 @@
    - ***** END LICENSE BLOCK ***** -->
 
 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
 
 <window id="263683test"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         width="600"
         height="600"
-        onload="onLoad();"
+        onload="SimpleTest.executeSoon(startTest);"
         title="263683 test">
 
   <script type="application/javascript"><![CDATA[
     const Ci = Components.interfaces;
     const Cc = Components.classes;
     const Cr = Components.results;
 
     var gFindBar = null;
     var gBrowser;
 
-    function ok(condition, message) {
-      window.opener.wrappedJSObject.SimpleTest.ok(condition, message);
+    var imports = ["SimpleTest", "ok"];
+    for each (var import in imports) {
+      window[import] = window.opener.wrappedJSObject[import];
     }
 
     function finish() {
       window.close();
-      window.opener.wrappedJSObject.SimpleTest.finish();
+      SimpleTest.finish();
     }
 
-    function onLoad() {
-      var _delayedOnLoad = function() {
-        gFindBar = document.getElementById("FindToolbar");
-        gBrowser = document.getElementById("content");
-        gBrowser.addEventListener("pageshow", onPageShow, false);
-        gBrowser.loadURI('data:text/html,<h2>Text mozilla</h2><input id="inp" type="text" />');
-      }
-      let tm = Cc["@mozilla.org/thread-manager;1"].
-               getService(Ci.nsIThreadManager);
-      tm.mainThread.dispatch({
-        run: function() _delayedOnLoad()
-      }, Ci.nsIThread.DISPATCH_NORMAL);
+    function startTest() {
+      gFindBar = document.getElementById("FindToolbar");
+      gBrowser = document.getElementById("content");
+      gBrowser.addEventListener("pageshow", onPageShow, false);
+      gBrowser.loadURI('data:text/html,<h2>Text mozilla</h2><input id="inp" type="text" />');
     }
 
     function onPageShow() {
-      gBrowser.removeEventListener("load", onPageShow, true);
       gFindBar.open();
       var search = "mozilla";
       gFindBar._findField.value = search;
       var matchCase = gFindBar.getElement("find-case-sensitive");
       if (matchCase.checked)
         matchCase.doCommand();
 
       gFindBar._find();
--- a/toolkit/content/tests/chrome/bug331215_window.xul
+++ b/toolkit/content/tests/chrome/bug331215_window.xul
@@ -38,48 +38,42 @@
    - ***** END LICENSE BLOCK ***** -->
 
 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
 
 <window id="331215test"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         width="600"
         height="600"
-        onload="onLoad();"
+        onload="SimpleTest.executeSoon(startTest);"
         title="331215 test">
 
   <script type="application/javascript"><![CDATA[
     const Ci = Components.interfaces;
     const Cc = Components.classes;
     const Cr = Components.results;
 
     var gFindBar = null;
     var gBrowser;
 
-    function ok(condition, message) {
-      window.opener.wrappedJSObject.SimpleTest.ok(condition, message);
+    var imports = ["SimpleTest", "ok"];
+    for each (var import in imports) {
+      window[import] = window.opener.wrappedJSObject[import];
     }
 
     function finish() {
       window.close();
-      window.opener.wrappedJSObject.SimpleTest.finish();
+      SimpleTest.finish();
     }
 
-    function onLoad() {
-      var _delayedOnLoad = function() {
-        gFindBar = document.getElementById("FindToolbar");
-        gBrowser = document.getElementById("content");
-        gBrowser.addEventListener("pageshow", onPageShow, false);
-        gBrowser.loadURI("data:text/plain,latest");
-      }
-      let tm = Cc["@mozilla.org/thread-manager;1"].
-               getService(Ci.nsIThreadManager);
-      tm.mainThread.dispatch({
-        run: function() _delayedOnLoad()
-      }, Ci.nsIThread.DISPATCH_NORMAL);
+    function startTest() {
+      gFindBar = document.getElementById("FindToolbar");
+      gBrowser = document.getElementById("content");
+      gBrowser.addEventListener("pageshow", onPageShow, false);
+      gBrowser.loadURI("data:text/plain,latest");
     }
 
     function onPageShow() {
       document.getElementById("cmd_find").doCommand();
       enterStringIntoFindField("test");
       document.commandDispatcher
               .getControllerForCommand("cmd_moveTop")
               .doCommand("cmd_moveTop");
--- a/toolkit/content/tests/chrome/bug451286_window.xul
+++ b/toolkit/content/tests/chrome/bug451286_window.xul
@@ -38,61 +38,54 @@
    - ***** END LICENSE BLOCK ***** -->
 
 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
 
 <window id="451286test"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         width="600"
         height="600"
-        onload="onLoad();"
+        onload="SimpleTest.executeSoon(startTest);"
         title="451286 test (also tests bug 493658)">
 
   <script type="application/javascript"><![CDATA[
     const Ci = Components.interfaces;
     const Cc = Components.classes;
     const Cr = Components.results;
     const SEARCH_TEXT = "text";
     const DATAURI = "data:text/html," + SEARCH_TEXT;
 
     var gFindBar = null;
     var gBrowser;
 
-    var imports = [ "SimpleTest", "ok", "snapshotWindow", "compareSnapshots"];
+    var imports = ["SimpleTest", "ok", "snapshotWindow", "compareSnapshots"];
     for each (var import in imports) {
       window[import] = window.opener.wrappedJSObject[import];
     }
 
     function finish() {
       window.close();
-      window.opener.wrappedJSObject.SimpleTest.finish();
+      SimpleTest.finish();
     }
 
-    function onLoad() {
-      var _delayedOnLoad = function() {
-        gFindBar = document.getElementById("FindToolbar");
-        gBrowser = document.getElementById("content");
-        gBrowser.addEventListener("pageshow", onPageShow, false);
+    function startTest() {
+      gFindBar = document.getElementById("FindToolbar");
+      gBrowser = document.getElementById("content");
+      gBrowser.addEventListener("pageshow", onPageShow, false);
 
-        // Bug 451286. An iframe that should be highlighted
-        var visible = "<iframe id='visible' src='" + DATAURI + "'></iframe>";
+      // Bug 451286. An iframe that should be highlighted
+      var visible = "<iframe id='visible' src='" + DATAURI + "'></iframe>";
 
-        // Bug 493658. An invisible iframe that shouldn't interfere with
-        // highlighting matches lying after it in the document
-        var invisible = "<iframe id='invisible' style='display: none;' " +
-                        "src='" + DATAURI + "'></iframe>";
+      // Bug 493658. An invisible iframe that shouldn't interfere with
+      // highlighting matches lying after it in the document
+      var invisible = "<iframe id='invisible' style='display: none;' " +
+                      "src='" + DATAURI + "'></iframe>";
 
-        var uri = DATAURI + invisible + SEARCH_TEXT + visible + SEARCH_TEXT;
-        gBrowser.loadURI(uri);
-      }
-      let tm = Cc["@mozilla.org/thread-manager;1"].
-               getService(Ci.nsIThreadManager);
-      tm.mainThread.dispatch({
-        run: function() _delayedOnLoad()
-      }, Ci.nsIThread.DISPATCH_NORMAL);
+      var uri = DATAURI + invisible + SEARCH_TEXT + visible + SEARCH_TEXT;
+      gBrowser.loadURI(uri);
     }
 
     function onPageShow(aEvent) {
       // Don't respond to pageshow events coming from the <iframes>
       if (aEvent.target != gBrowser.contentDocument)
         return;
 
       gBrowser.removeEventListener("pageshow", onPageShow, false);
--- a/toolkit/content/tests/chrome/bug451540_window.xul
+++ b/toolkit/content/tests/chrome/bug451540_window.xul
@@ -56,41 +56,34 @@
 
     var sendCtrl = true;
     var sendMeta = false;
     if (navigator.platform.indexOf("Mac") >= 0) {
       sendCtrl = false;
       sendMeta = true;
     }
 
-    var imports = [ "SimpleTest", "ok", "finish"];
+    var imports = [ "SimpleTest", "ok"];
       for each (var import in imports) {
         window[import] = window.opener.wrappedJSObject[import];
       }
 
 
     function finishTest() {
       window.close();
       SimpleTest.finish();
     }
 
-    function onLoad() {
-      var _delayedOnLoad = function() {
-        gFindBar = document.getElementById("FindToolbar");
-        gBrowser = document.getElementById("content");
-        gBrowser.addEventListener("pageshow", onPageShow, false);
-        var data = 'data:text/html,<input id="inp" type="text" />';
-        data +='<textarea id="tarea"/>'
-        gBrowser.loadURI(data);
-      }
-      let tm = Cc["@mozilla.org/thread-manager;1"].
-               getService(Ci.nsIThreadManager);
-      tm.mainThread.dispatch({
-        run: function() _delayedOnLoad()
-      }, Ci.nsIThread.DISPATCH_NORMAL);
+    function startTest() {
+      gFindBar = document.getElementById("FindToolbar");
+      gBrowser = document.getElementById("content");
+      gBrowser.addEventListener("pageshow", onPageShow, false);
+      var data = 'data:text/html,<input id="inp" type="text" />';
+      data +='<textarea id="tarea"/>'
+      gBrowser.loadURI(data);
     }
 
     function resetForNextTest(aElement, aText) {
       if (!aText)
         aText = SEARCH_TEXT;
 
       // Turn off highlighting
       var highlightButton = gFindBar.getElement("highlight");
@@ -287,14 +280,14 @@
       gFindBar.open();
       var input = gBrowser.contentDocument.getElementById("inp");
       testInput(input, "Input:");
       var textarea = gBrowser.contentDocument.getElementById("tarea");
       testInput(textarea, "Textarea:");
       finishTest();
     }
 
-    window.opener.wrappedJSObject.SimpleTest.waitForFocus(onLoad, window);
+    SimpleTest.waitForFocus(startTest, window);
   ]]></script>
 
   <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   <findbar id="FindToolbar" browserid="content"/>
 </window>