Bug 916086 - Remove some more enablePrivilege calls. r=jmaher
authorMartijn Wargers <mwargers@mozilla.com>
Mon, 16 Sep 2013 22:12:29 +0200
changeset 161364 37dd897d1c32c8dacdd997540f270837305d2933
parent 161363 33ec0e812f3b58627579b09b34d27f1305ceb20c
child 161365 eb501139f68a703fdd1470032496fb29a9a66b2c
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs916086
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 916086 - Remove some more enablePrivilege calls. r=jmaher CLOSED TREE
content/smil/test/test_smilTextZoom.xhtml
content/svg/content/test/test_a_href_01.xhtml
content/svg/content/test/test_animLengthObjectIdentity.xhtml
content/xbl/test/test_bug378518.xul
content/xbl/test/test_bug398492.xul
content/xml/document/test/test_viewport.xhtml
content/xul/content/test/test_bug486990.xul
content/xul/templates/tests/chrome/test_bug441785.xul
content/xul/templates/tests/chrome/test_sortservice.xul
docshell/test/test_bug590573.html
docshell/test/test_bug713825.html
dom/plugins/test/mochitest/test_bug539565-1.html
dom/plugins/test/mochitest/test_bug539565-2.html
dom/plugins/test/mochitest/test_bug751809.html
dom/plugins/test/mochitest/test_convertpoint.xul
dom/plugins/test/mochitest/test_copyText.html
layout/base/tests/Makefile.in
layout/base/tests/bug450930.xhtml
layout/base/tests/chrome/Makefile.in
layout/base/tests/chrome/test_bug396367-1.html
layout/base/tests/chrome/test_bug396367-2.html
layout/base/tests/chrome/test_bug420499.xul
layout/base/tests/chrome/test_bug458898.html
layout/base/tests/test_bug458898.html
layout/base/tests/test_scroll_selection_into_view.html
layout/forms/test/test_bug345267.html
layout/forms/test/test_bug378670.html
layout/forms/test/test_bug402198.html
layout/forms/test/test_bug446663.html
layout/generic/test/bug421839-2-page.html
layout/generic/test/test_bug421839-1.html
layout/generic/test/test_bug460532.html
layout/generic/test/test_bug507902.html
layout/generic/test/test_selection_touchevents.html
testing/mochitest/b2g.json
testing/mochitest/tests/SimpleTest/EventUtils.js
--- a/content/smil/test/test_smilTextZoom.xhtml
+++ b/content/smil/test/test_smilTextZoom.xhtml
@@ -40,26 +40,20 @@ function main()
     SimpleTest.finish();
     return;
   }
 
   // Start out pause
   var svg = SMILUtil.getSVGRoot();
   ok(svg.animationsPaused(), "should be paused by <svg> load handler");
   is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
-  
-  // Get handle on nsIMarkupDocumentViewer
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-  const CI = Components.interfaces;
-  var docshell = window.QueryInterface(CI.nsIInterfaceRequestor).getInterface(CI.nsIWebNavigation).QueryInterface(CI.nsIDocShell);
-  var mudv = docshell.contentViewer.QueryInterface(CI.nsIMarkupDocumentViewer);
 
   // Set text zoom to 2x
-  var origTextZoom = mudv.textZoom;
-  mudv.textZoom = 2;
+  var origTextZoom =  SpecialPowers.getTextZoom(window);
+  SpecialPowers.setTextZoom(window, 2);
 
   try {
     // Verify computed style values at various points during animation.
     // * Correct behavior is for the computed values of 'font-size' to be
     // the same as their corresponding specified values, since text zoom
     // should not affect SVG text elements.
     // * I also include tests for an identical animation of the "stroke-width"
     // property, which should _not_ be affected by textZoom.
@@ -78,22 +72,23 @@ function main()
     verifyStyle(text, "font-size",    "40px");
     verifyStyle(rect, "stroke-width", "40px");
     svg.setCurrentTime(3);
     verifyStyle(text, "font-size",    "40px");
     verifyStyle(rect, "stroke-width", "40px");
   } catch (e) {
     // If anything goes wrong, make sure we restore textZoom before bubbling
     // the exception upwards, so that we don't mess up subsequent tests.
-    mudv.textZoom = origTextZoom;
+    SpecialPowers.setTextZoom(window, origTextZoom);
+
     throw e;
   }
 
   // We're done! Restore original text-zoom before finishing
-  mudv.textZoom = origTextZoom;
+  SpecialPowers.setTextZoom(window, origTextZoom);
   SimpleTest.finish();
 }
 
 window.addEventListener("load", main, false);
 ]]>
 </script>
 </pre>
 </body>
--- a/content/svg/content/test/test_a_href_01.xhtml
+++ b/content/svg/content/test/test_a_href_01.xhtml
@@ -1,15 +1,16 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=620295
 -->
 <head>
   <title>Test that activating SVG 'a' elements navigate to their xlink:href</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=620295">Mozilla Bug 620295</a>
 <p id="display"></p>
 <pre id="test">
 <script class="testbody" type="text/javascript"><![CDATA[
 
@@ -37,18 +38,16 @@ function frameLoaded() {
 
 function doNavigationIfReady() {
   if (didWindowLoad && frameLoadCount == testCount) {
     doNavigation();
   }
 }
 
 function doNavigation() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
   // Test clicking on an unmodified <a>.
   doNavigationTest(1, "a_href_helper_01.svg");
   // Test clicking on an <a> whose xlink:href is modified by assigning to href.baseVal.
   doNavigationTest(2, "a_href_helper_02_03.svg", function(a) { a.href.baseVal = "a_href_destination.svg"; });
   // Test clicking on an <a> whose xlink:href is modified by a setAttributeNS call.
   doNavigationTest(3, "a_href_helper_02_03.svg", function(a) { a.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", "a_href_destination.svg"); });
   // Test clicking on an <a> whose xlink:href is modified by animation.
   doNavigationTest(4, "a_href_helper_04.svg");
@@ -62,24 +61,17 @@ function doNavigationTest(testNumber, in
     ok(endsWith(iframe.contentWindow.location, "a_href_destination.svg"), "Final href of test " + testNumber);
     if (++navigationCount == testCount) {
       SimpleTest.finish();
     }
   };
   if (f) {
     f(a);
   }
-  dispatchClickEvent(a);
-}
-
-function dispatchClickEvent(element) {
-  var event = element.ownerDocument.createEvent("MouseEvent");
-  event.initMouseEvent("click", true, true, element.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false,
-                       false, false, 0, null);
-  element.dispatchEvent(event);
+  sendMouseEvent({type:'click'}, a);
 }
 
 window.onload = windowLoaded;
 
 ]]></script>
 </pre>
 <div id="content" style="visibility: hidden">
 <!-- These must come after frameLoaded is defined -->
--- a/content/svg/content/test/test_animLengthObjectIdentity.xhtml
+++ b/content/svg/content/test/test_animLengthObjectIdentity.xhtml
@@ -60,20 +60,17 @@ function main() {
       "Got different animVal SVGLength objects during animation");
   }
 
   // Drop all references to the tear off objects
   var oldValue = circle.cx.animVal.value; // Just a float, not an object ref
   animLength = null;
   baseVal = null;
   animVal = null;
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-        .getInterface(Components.interfaces.nsIDOMWindowUtils)
-        .garbageCollect();
+  SpecialPowers.gc();
 
   // The tearoff objects should no longer exist and we should create new ones.
   // If somehow, the tearoff objects have died and yet not been removed from the
   // hashmap we'll end up in all sorts of trouble when we try to access them.
   // So in the following, we're not really interested in the value, just that we
   // don't crash.
   is(circle.cx.animVal.value, oldValue,
     "Unexpected result accessing new(?) length object.");
--- a/content/xbl/test/test_bug378518.xul
+++ b/content/xbl/test/test_bug378518.xul
@@ -47,17 +47,16 @@ https://bugzilla.mozilla.org/show_bug.cg
 
     SimpleTest.expectAssertions(1);
 
     var myBoxClicked = false;
     var myCheckBoxClicked = false;
     var myExtendedBoxClicked = false;
 
     function testClick(elemName) {
-      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
       var wu  =
         window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
               .getInterface(Components.interfaces.nsIDOMWindowUtils);
 
       var a = document.getElementById(elemName).getBoundingClientRect();
       wu.sendMouseEvent('mousedown',  a.left + 1, a.top + 1, 0, 1, 0);
       wu.sendMouseEvent('mouseup',  a.left + 1, a.top + 1, 0, 1, 0);
     }
--- a/content/xbl/test/test_bug398492.xul
+++ b/content/xbl/test/test_bug398492.xul
@@ -28,17 +28,16 @@ https://bugzilla.mozilla.org/show_bug.cg
   
   <!-- test code goes here -->
   <script type="application/javascript"><![CDATA[
 
     /** Test for Bug 398492 **/
     SimpleTest.waitForExplicitFinish();
 
     function getXBLParent(node) {
-      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
       var utils = Components.classes["@mozilla.org/inspector/dom-utils;1"]
                             .getService(Components.interfaces.inIDOMUtils);
       return utils.getParentForNode(node, true);
     }
 
     addLoadEvent(function() {
       var n = $("testbox");
       var kid = n.firstChild;
--- a/content/xml/document/test/test_viewport.xhtml
+++ b/content/xml/document/test/test_viewport.xhtml
@@ -19,24 +19,18 @@ href="https://bugzilla.mozilla.org/show_
 <![CDATA[
 
 /** Test for Viewport META Tag **/
 
 SimpleTest.waitForExplicitFinish();
 
 function testViewport() {
 
-  /* We need to access the document headers, which are chrome-only. */
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
   /* Grab Viewport Metadata from the document header. */
-  var iRequester =
-    window.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
-  var windowUtils =
-    iRequester.getInterface(Components.interfaces.nsIDOMWindowUtils);
+  var windowUtils = SpecialPowers.getDOMWindowUtils(window);
   var vpWidth =
     parseInt(windowUtils.getDocumentMetadata("viewport-width"));
   var vpHeight =
     parseInt(windowUtils.getDocumentMetadata("viewport-height"));
   var vpInitialScale = 
     parseFloat(windowUtils.getDocumentMetadata("viewport-initial-scale"));
   var vpMaxScale = 
     parseFloat(windowUtils.getDocumentMetadata("viewport-maximum-scale"));
--- a/content/xul/content/test/test_bug486990.xul
+++ b/content/xul/content/test/test_bug486990.xul
@@ -80,64 +80,55 @@ https://bugzilla.mozilla.org/show_bug.cg
   function contextMenuStopper(evt) {
     evt.stopPropagation();
   }
 
   function contextMenuPreventer(evt) {
     evt.preventDefault();
   }
 
-  function allowDisableContextMenu(allow) {
-    const prefSvcContractID = "@mozilla.org/preferences-service;1";
-    const prefSvcIID = SpecialPowers.Ci.nsIPrefService;
-    var prefs = SpecialPowers.Cc[prefSvcContractID].getService(prefSvcIID)
-                                                   .getBranch("dom.event.contextmenu.");
-    try {
-      if (allow) {
-        if (prefs.prefHasUserValue("enabled")) {
-          prefs.clearUserPref("enabled");
-        }
-      } else {
-        prefs.setBoolPref("enabled", allow);
-      }
-    } catch(ex) {}
-  }
-  
+  var tb;
   function runTests() {
     document.addEventListener("foo", fooListener, true);
     var e1 = document.createEvent("Event");
     e1.initEvent("foo", true, true);
     document.dispatchEvent(e1);
     is(eventCount, 1, "Wrong event count");
     ok(prevented, "Default handling should have been prevented.");
 
     prevented = false;
     var e2 = document.createEvent("Event");
     e2.initEvent("foo", false, false);
     document.dispatchEvent(e1);
     is(eventCount, 2, "Wrong event count");
     ok(prevented, "Default handling should have been prevented.");
 
-    var tb = document.getElementById("testbutton");
+    tb = document.getElementById("testbutton");
     dispatchTrustedContextMenuEvent(tb);
     is(popupshowingcount, 1, "Should have got 'popupShowing' event!");
 
     tb.addEventListener("contextmenu", contextMenuStopper, true);
     dispatchTrustedContextMenuEvent(tb);
     is(popupshowingcount, 2, "Should have got 'popupShowing' event!");
 
     tb.addEventListener("contextmenu", contextMenuPreventer, true);
     dispatchTrustedContextMenuEvent(tb);
     is(popupshowingcount, 2, "Should not have got 'popupShowing' event!");
 
-    allowDisableContextMenu(false);
+    SpecialPowers.pushPrefEnv({"set": [["dom.event.contextmenu.enabled", false]]}, test2);
+  }
+
+  function test2() {
     dispatchTrustedContextMenuEvent(tb);
     is(popupshowingcount, 3, "Should have got 'popupShowing' event!");
 
-    allowDisableContextMenu(true);
+    SpecialPowers.pushPrefEnv({"set": [["dom.event.contextmenu.enabled", true]]}, test3);
+  }
+
+  function test3() {
     dispatchTrustedContextMenuEvent(tb);
     is(popupshowingcount, 3, "Should not have got 'popupshowing' event!");
 
     var s = document.getElementById("select");
     s.addEventListener("click", clickListener, true);
     s.addEventListener("mousedown", mouseDownListener, true);
     s.addEventListener("mouseup", mouseUpListener, true);
 
@@ -151,18 +142,14 @@ https://bugzilla.mozilla.org/show_bug.cg
     is(clickCount, 1, "Should not have got click event!");
     is(mouseDownCount, 2, "Should have got mousedown event!");
     is(mouseUpCount, 2, "Should have got mouseup event!");
 
     SimpleTest.finish();
   }
 
   function dispatchTrustedContextMenuEvent(target) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    var e = document.createEvent("MouseEvent");
-    e.initMouseEvent("contextmenu", true, true, window, 0, 0, 0, 0, 0, 
-                      false, false, false, false, 2, null);
-    return target.dispatchEvent(e);
+    return sendMouseEvent({type:"contextmenu"}, target, window);
   }
 
   ]]>
   </script>
 </window>
--- a/content/xul/templates/tests/chrome/test_bug441785.xul
+++ b/content/xul/templates/tests/chrome/test_bug441785.xul
@@ -80,17 +80,16 @@ var TemplateBuilderListener = {
   }
 };
 
 function runTest() {
   var tree = document.getElementById('t');
   var treec = document.getElementById('tc');
 
   try {
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
     var rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"].
                        getService(Components.interfaces.nsIRDFService);
 
     var s1 = window.location.href.replace(/test_bug441785.xul/, "bug441785-1.rdf");
     var ds1 = rdfService.GetDataSourceBlocking(s1);
 
     var s2 = window.location.href.replace(/test_bug441785.xul/, "bug441785-2.rdf");
     var ds2 = rdfService.GetDataSourceBlocking(s2);
--- a/content/xul/templates/tests/chrome/test_sortservice.xul
+++ b/content/xul/templates/tests/chrome/test_sortservice.xul
@@ -26,18 +26,16 @@ var tests = [
   [["Cat", "cat", "Candy", "candy"], "comparecase", ["Candy Cat candy cat"]],
   [["1", "102", "22", "One", "40", "Two"], "integer", ["1 22 40 102 One Two"]],
 ];
 
 SimpleTest.waitForExplicitFinish();
 
 function doTests()
 {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
   var box = document.getElementById("box");
 
   const sortService = Components.classes["@mozilla.org/xul/xul-sort-service;1"].
                         getService(Components.interfaces.nsIXULSortService);
 
   for (let t = 0; t < tests.length; t++) {
     var test = tests[t];
 
--- a/docshell/test/test_bug590573.html
+++ b/docshell/test/test_bug590573.html
@@ -91,35 +91,32 @@ function page2PageShow()
   }
   else {
     dump('Ignoring page2 pageshow.\n');
   }
 }
 
 function dumpSHistory(theWindow)
 {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
-  const Ci = Components.interfaces;
-  let sh = theWindow.QueryInterface(Ci.nsIInterfaceRequestor)
-                    .getInterface(Ci.nsIWebNavigation)
+  let sh = SpecialPowers.wrap(theWindow).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
+                    .getInterface(SpecialPowers.Ci.nsIWebNavigation)
                     .sessionHistory;
   if (!sh) {
     dump(" window has no shistory.\n");
     return;
   }
 
   dump(" count: " + sh.count + "\n");
   dump(" index: " + sh.index + "\n");
   dump(" requestedIndex: " + sh.requestedIndex + "\n");
 
   for (let i = 0; i < sh.count; i++) {
     let shentry = sh.getEntryAtIndex(i, false);
     dump(" " + i + ": " + shentry.URI.spec + '\n');
-    shentry.QueryInterface(Ci.nsISHContainer);
+    shentry.QueryInterface(SpecialPowers.Ci.nsISHContainer);
     for (let j = 0; j < shentry.childCount; j++) {
       let child = shentry.GetChildAt(j);
       dump("   child " + j + ": " + child.URI.spec + '\n');
     }
   }
 
   return sh;
 }
--- a/docshell/test/test_bug713825.html
+++ b/docshell/test/test_bug713825.html
@@ -17,25 +17,24 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** 
  * Test for Bug 713825 
  *  test that nsIDocCharset still works backward compatibly
  */
-netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-var Ci = Components.interfaces;
-var docShell = window.QueryInterface(Ci.nsIInterfaceRequestor).
+var Ci = SpecialPowers.Ci;
+var docShell = SpecialPowers.wrap(window).QueryInterface(Ci.nsIInterfaceRequestor).
                       getInterface(Ci.nsIWebNavigation).
                       QueryInterface(Ci.nsIDocShell);
 
 var charset1 = docShell.charset;
 var charset2 = docShell.QueryInterface(Ci.nsIDocCharset).charset;
-var charset3 = window.QueryInterface(Ci.nsIInterfaceRequestor).
+var charset3 = SpecialPowers.wrap(window).QueryInterface(Ci.nsIInterfaceRequestor).
                       getInterface(Ci.nsIDocCharset).charset;
 
 /* if we get here without throwing and the three charsets are equal, all is OK */
 is(charset1, charset2, "QI'd nsIDocCharset.charset should equal nsIDocShell.charset");
 is(charset1, charset3, "getInterface'd nsIDocCharset.charset should equal nsIDocShell.charset");
 
 </script>
 </pre>
--- a/dom/plugins/test/mochitest/test_bug539565-1.html
+++ b/dom/plugins/test/mochitest/test_bug539565-1.html
@@ -7,23 +7,16 @@ https://bugzilla.mozilla.org/show_bug.cg
   <title>Test #1 for Bug 539565</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
   <script type="application/javascript" src="utils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 
   <script class="testbody" type="text/javascript">
 function runTests() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  viewer = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                 .getInterface(Components.interfaces.nsIWebNavigation)
-                 .QueryInterface(Components.interfaces.nsIDocShell)
-                 .contentViewer
-                 .QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
-
   var moveBy = 17;
   var waitedForPaint = 0;
   function waitForPaint(func) {
     waitedForPaint = 0;
     var testplugin = $("plugin1");
     testplugin.last_paint_count = testplugin.getPaintCount ? testplugin.getPaintCount() : -2;
     function waitForPaintCountIncrement() {
       waitedForPaint++;
@@ -35,39 +28,36 @@ function runTests() {
         setTimeout(func,0);
       } else
         setTimeout(waitForPaintCountIncrement, 50);
     }
     waitForPaintCountIncrement();
   }
 
   function doClick(x,y,func) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    synthesizeMouse($("plugin1"), x, y, {}, window); 
+    synthesizeMouse($("plugin1"), x, y, {}, window);
     setTimeout(func,0);
   }
 
   function verify(test,x,y,next) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
     var p = $("plugin1").getLastMouseX();
     const delta = 2;
     ok(p-delta <= x && x <= p+delta, "test"+test+" LastMouseX got " + p + " expected " + x + 
-                                     " with fullZoom="+viewer.fullZoom+" MozTransform='"+$("container").style.MozTransform+"'");
+                                     " with fullZoom="+SpecialPowers.getFullZoom(window)+" MozTransform='"+$("container").style.MozTransform+"'");
     p = $("plugin1").getLastMouseY();
     ok(p-delta <= y && y <= p+delta, "test"+test+" LastMouseY got " + p + " expected " + y +
-                                     " with fullZoom="+viewer.fullZoom+" MozTransform='"+$("container").style.MozTransform+"'");
+                                     " with fullZoom="+SpecialPowers.getFullZoom(window)+" MozTransform='"+$("container").style.MozTransform+"'");
     if (next) next();
   }
 
   function click(x,y,next) {
     waitForPaint(function(){doClick(x,y,next);})
   }
   function zoom(factor) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    viewer.fullZoom = factor;
+    SpecialPowers.setFullZoom(window, factor);
   }
 
   function test1() { // fullZoom=1 (sanity check)
     zoom(1);
     click(55,136, function(){verify("1",55,136,test2)});
   }
   function test2() { // fullZoom=2
     zoom(2);
--- a/dom/plugins/test/mochitest/test_bug539565-2.html
+++ b/dom/plugins/test/mochitest/test_bug539565-2.html
@@ -7,23 +7,16 @@ https://bugzilla.mozilla.org/show_bug.cg
   <title>Test #2 for Bug 539565</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
   <script type="application/javascript" src="utils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 
   <script class="testbody" type="text/javascript">
 function runTests() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  viewer = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                 .getInterface(Components.interfaces.nsIWebNavigation)
-                 .QueryInterface(Components.interfaces.nsIDocShell)
-                 .contentViewer
-                 .QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
-
   var moveBy = 17;
   var waitedForPaint = 0;
   function waitForPaint(func) {
     waitedForPaint = 0;
     var testplugin = $("plugin1");
     testplugin.last_paint_count = testplugin.getPaintCount ? testplugin.getPaintCount() : -2;
     function waitForPaintCountIncrement() {
       waitedForPaint++;
@@ -35,39 +28,36 @@ function runTests() {
         setTimeout(func,0);
       } else
         setTimeout(waitForPaintCountIncrement, 50);
     }
     waitForPaintCountIncrement();
   }
 
   function doClick(x,y,func) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
     synthesizeMouse($("plugin1"), x, y, {}, window); 
     setTimeout(func,0);
   }
 
   function verify(test,x,y,next) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
     var p = $("plugin1").getLastMouseX();
     const delta = 2;
     ok(p-delta <= x && x <= p+delta, "test"+test+" LastMouseX got " + p + " expected " + x + 
-                                     " with fullZoom="+viewer.fullZoom+" MozTransform='"+$("container").style.MozTransform+"'");
+                                     " with fullZoom="+SpecialPowers.getFullZoom(window)+" MozTransform='"+$("container").style.MozTransform+"'");
     p = $("plugin1").getLastMouseY();
     ok(p-delta <= y && y <= p+delta, "test"+test+" LastMouseY got " + p + " expected " + y +
-                                     " with fullZoom="+viewer.fullZoom+" MozTransform='"+$("container").style.MozTransform+"'");
+                                     " with fullZoom="+SpecialPowers.getFullZoom(window)+" MozTransform='"+$("container").style.MozTransform+"'");
     if (next) next();
   }
 
   function click(x,y,next) {
     waitForPaint(function(){doClick(x,y,next);})
   }
   function zoom(factor) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    viewer.fullZoom = factor;
+    SpecialPowers.setFullZoom(window, factor);
   }
 
   function test3() { // fullZoom=1 + scale(2)
     zoom(1);
     //
     // ======================== BUG WARNING =========================================
     // 'container' already has -moz-transform:scale(2) in its style attribute.
     // Removing that and setting MozTransform dynamically here (as in test4)
--- a/dom/plugins/test/mochitest/test_bug751809.html
+++ b/dom/plugins/test/mochitest/test_bug751809.html
@@ -13,17 +13,16 @@
 </head>
 
 <body onload="go();">
   <embed id="plugin" type="application/x-test" width="400" height="400" drawmode="solid" color="FF00FFFF"></embed>
 
   <script type="application/javascript;version=1.7">
 
   SimpleTest.waitForExplicitFinish();
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 
   const Ci = Components.interfaces;
   const utils = window.QueryInterface(Ci.nsIInterfaceRequestor).
                                     getInterface(Ci.nsIDOMWindowUtils);
 
   function waitForCondition(condition, nextTest, errorMsg) {
     var tries = 0;
     var interval = setInterval(function() {
--- a/dom/plugins/test/mochitest/test_convertpoint.xul
+++ b/dom/plugins/test/mochitest/test_convertpoint.xul
@@ -24,18 +24,16 @@ function runTests() {
   // Poll to see if the plugin is in the right place yet.
   // Check if x-coordinate 0 in plugin space is 0 in window space. If it is,
   // the plugin hasn't been placed yet.
   if (pluginElement.convertPointX(1, 0, 0, 2) == 0) {
     setTimeout(runTests, 0);
     return;
   }
 
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
   var domWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                              .getInterface(Components.interfaces.nsIDOMWindowUtils);
   var devPxPerCSSPx = domWindowUtils.screenPixelsPerCSSPixel;
 
   var pluginRect = pluginElement.getBoundingClientRect();
   var pluginX = (pluginRect.left * devPxPerCSSPx) + ((window.mozInnerScreenX * devPxPerCSSPx) - window.screenX);
   var pluginY = (pluginRect.top * devPxPerCSSPx) + ((window.mozInnerScreenY * devPxPerCSSPx) - window.screenY);
 
--- a/dom/plugins/test/mochitest/test_copyText.html
+++ b/dom/plugins/test/mochitest/test_copyText.html
@@ -2,18 +2,16 @@
 <html>
 <head>
   <title>Test copying text from browser to plugin</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="text/javascript" src="utils.js"></script>
 
   <script class="testbody" type="text/javascript">
 function runTests() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
   var text = " some text \n to copy 'n paste "
   var textElt = document.getElementById("input");
   var plugin = document.getElementById("plugin1");
 
   textElt.focus();
   textElt.value = text;
   textElt.select();
   SpecialPowers.wrap(textElt).editor.copy();
--- a/layout/base/tests/Makefile.in
+++ b/layout/base/tests/Makefile.in
@@ -27,17 +27,16 @@ MOCHITEST_FILES =	\
 		test_bug399284.html \
 		test_bug399951.html \
 		test_bug404209.xhtml \
 		test_bug416896.html \
 		test_bug423523.html \
 		test_bug449781.html \
 		test_bug450930.xhtml \
 		bug450930.xhtml \
-		test_bug458898.html \
 		test_bug465448.xul \
 		test_bug469170.html \
 		test_bug471126.html \
 		test_bug435293-scale.html \
 		test_bug435293-interaction.html \
 		test_bug435293-skew.html \
 		test_reftests_with_caret.html \
 		     bug106855-1.html \
--- a/layout/base/tests/bug450930.xhtml
+++ b/layout/base/tests/bug450930.xhtml
@@ -95,21 +95,20 @@ function checkGotSubdoc(list, container)
 }
 
 function runTest1() {
   // test basic functionality
   var iterations = 0;
   var foundExactRect = false;
 
   function listener(event) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    var r = event.boundingClientRect;
+    var r = SpecialPowers.wrap(event).boundingClientRect;
     var bounds = document.getElementById('d').getBoundingClientRect();
     checkContains(r, bounds, "");
-    if (isRectInList(bounds, event.clientRects)) {
+    if (isRectInList(bounds, SpecialPowers.wrap(event).clientRects)) {
       foundExactRect = true;
     }
     window.removeEventListener("MozAfterPaint", listener, false);
     ++iterations;
     if (iterations < 4) {
       setTimeout(triggerPaint, 100);
     } else {
       window.opener.ok(foundExactRect, "Found exact rect");
@@ -128,20 +127,19 @@ function runTest1() {
 function runTest2(frameID, containerID) {
   // test reporting of painting in subdocuments
   var fired = 0;
   var gotSubdocPrivileged = false;
   var iframe = document.getElementById(frameID);
   var container = document.getElementById(containerID);
 
   function listener(event) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    if (checkGotSubdoc(event.clientRects, container))
+    if (checkGotSubdoc(SpecialPowers.wrap(event).clientRects, container))
       gotSubdocPrivileged = true;
-    if (event.clientRects.length > 0) {
+    if (SpecialPowers.wrap(event).clientRects.length > 0) {
       if (++fired == 1)
         setTimeout(check, 100);
     }
   }
 
   function check() {
     window.opener.is(fired, 1, "Wrong event count (" + frameID + ")");
     window.opener.ok(gotSubdocPrivileged, "Didn't get subdoc invalidation while we were privileged (" + frameID + ")");
--- a/layout/base/tests/chrome/Makefile.in
+++ b/layout/base/tests/chrome/Makefile.in
@@ -2,16 +2,17 @@
 # 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/.
 
 MOCHITEST_CHROME_FILES = \
 	test_bug370436.html \
 	test_bug396367-1.html \
 	test_bug396367-2.html \
 	test_bug420499.xul \
+	test_bug458898.html \
 	test_bug495648.xul \
 	bug495648.rdf \
 	test_bug504311.xul \
 	test_bug514660.xul \
 	test_bug533845.xul \
 	test_bug551434.html \
 	bug551434_childframe.html \
 	test_bug708062.html \
--- a/layout/base/tests/chrome/test_bug396367-1.html
+++ b/layout/base/tests/chrome/test_bug396367-1.html
@@ -13,17 +13,16 @@ https://bugzilla.mozilla.org/show_bug.cg
     function finish() {
       ok(true, "didn't crash");
       var docviewer = getdocviewer();
       docviewer.textZoom = 1;
       SimpleTest.finish();
     }
 
     function getdocviewer() {
-      //netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
       var navigator1 = top.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebNavigation);
       var docShell = navigator1.QueryInterface(Components.interfaces.nsIDocShell);
       var docviewer = docShell.contentViewer.QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
       return docviewer;
     }
   </script>
 </head>
 <body>
--- a/layout/base/tests/chrome/test_bug396367-2.html
+++ b/layout/base/tests/chrome/test_bug396367-2.html
@@ -14,17 +14,16 @@ https://bugzilla.mozilla.org/show_bug.cg
     function finish() {
       ok(true, "didn't crash");
       var docviewer = getdocviewer();
       docviewer.textZoom = 1;
       SimpleTest.finish();
     }
 
     function getdocviewer() {
-      //netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
       var navigator1 = top.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebNavigation);
       var docShell = navigator1.QueryInterface(Components.interfaces.nsIDocShell);
       var docviewer = docShell.contentViewer.QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
       return docviewer;
     }
   </script>
 </head>
 <body>
--- a/layout/base/tests/chrome/test_bug420499.xul
+++ b/layout/base/tests/chrome/test_bug420499.xul
@@ -62,17 +62,16 @@ https://bugzilla.mozilla.org/show_bug.cg
     function getSelectionController() {
       return document.docShell
         .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
         .getInterface(Components.interfaces.nsISelectionDisplay)
         .QueryInterface(Components.interfaces.nsISelectionController);
     }
 
     function isCaretVisible() {
-      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
       window.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
       var docShell = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                             .getInterface(Components.interfaces.nsIWebNavigation)
                             .QueryInterface(Components.interfaces.nsIDocShell);
       var selCon = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
         .getInterface(Components.interfaces.nsISelectionDisplay)
         .QueryInterface(Components.interfaces.nsISelectionController);
       return selCon.caretVisible;
rename from layout/base/tests/test_bug458898.html
rename to layout/base/tests/chrome/test_bug458898.html
--- a/layout/base/tests/test_bug458898.html
+++ b/layout/base/tests/chrome/test_bug458898.html
@@ -1,34 +1,31 @@
 <!DOCTYPE HTML>
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=458898
 -->
 <head>
   <title>Test for Bug 458898</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
-  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <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" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=458898">Mozilla Bug 458898</a>
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 SimpleTest.waitForExplicitFinish();
-// This should be rewritten as a chrome test
-netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
 var win = window.openDialog("data:text/html,<div style='height:200px; width:100px;'>");
 
 function loaded() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   var disableWindowResizePref = "dom.disable_window_move_resize";
   var oldPrefValue = SpecialPowers.getBoolPref(disableWindowResizePref);
   SpecialPowers.setBoolPref(disableWindowResizePref, false);
   win.sizeToContent();
   ok(win.innerWidth >= 100, "innerWidth: " + win.innerWidth + " >= 100 ?");
   ok(win.innerHeight >= 200, "innerHeight: " + win.innerHeight + " >= 200 ?");
   win.close();
   SpecialPowers.setBoolPref(disableWindowResizePref, oldPrefValue);
--- a/layout/base/tests/test_scroll_selection_into_view.html
+++ b/layout/base/tests/test_scroll_selection_into_view.html
@@ -66,23 +66,22 @@
 
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 var ANCHOR = 0;
 var FOCUS = 1;
 
 function testCollapsed(id, vPercent, startAt, expected) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var selection = window.getSelection().QueryInterface(Components.interfaces.nsISelectionPrivate);
+  var selection = window.getSelection().QueryInterface(SpecialPowers.Ci.nsISelectionPrivate);
 
   var c = document.getElementById("c" + id);
   var target = document.getElementById("target" + id);
   if (target.contentDocument) {
-    selection = target.contentWindow.getSelection().QueryInterface(Components.interfaces.nsISelectionPrivate);
+    selection = target.contentWindow.getSelection().QueryInterface(SpecialPowers.Ci.nsISelectionPrivate);
     target = target.contentDocument.getElementById("target" + id);
   }
   selection.collapse(target.parentNode, 0);
   c.scrollTop = startAt;
   selection.scrollIntoView(FOCUS, true, vPercent, 0);
   is(c.scrollTop, expected, "Scrolling " + target.id +
      " into view with vPercent " + vPercent + ", starting at " + startAt);
 }
--- a/layout/forms/test/test_bug345267.html
+++ b/layout/forms/test/test_bug345267.html
@@ -61,18 +61,17 @@ is($("u4").value, "abcdefghijkl",
 is($("target").value, "abcdefghijklm", "Test starting state incorrect");
 $("target").focus();
 $("target").selectionStart = $("target").selectionEnd = 13;
 sendKey("back_space");
 is($("target").value, "abcdefghijkl", "Should only delete one char");
 sendKey("back_space");
 is($("target").value, "abcdefghijk", "Should only delete one char again");
 (function () {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-  $("target").controllers.getControllerForCommand('cmd_undo')
+  SpecialPowers.wrap($("target")).controllers.getControllerForCommand('cmd_undo')
                          .doCommand('cmd_undo');
 })();
 is($("target").value, "abcdefghijklm",
    "Should be able to undo deletion in the face of maxlength");
 sendString("nopq");
 is($("target").value, "abcdefghijklm",
    "Typing should have no effect when already past maxlength");
 
--- a/layout/forms/test/test_bug378670.html
+++ b/layout/forms/test/test_bug378670.html
@@ -1,53 +1,49 @@
 <!DOCTYPE HTML>
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=378670
 -->
 <head>
   <title>Test for Bug 378670</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=378670">Mozilla Bug 378670</a>
 <p id="display"></p>
 <div id="content" style="display: none">
   
 </div>
 Clicking on the select should not crash Mozilla
 <select id="select">
 <option>1</option>
 <option>2</option>
 </select>
 
 <pre id="test">
 <script>
-document.getElementsByTagName('*')[3].addEventListener('popupshowing', function(e) {e.target.parentNode.removeChild(e.target) }, true);
+document.body.addEventListener('popupshowing', function(e) {e.target.parentNode.removeChild(e.target) }, true);
 </script>
 <script type="application/javascript">
 
 /** Test for Bug 378670 **/
 
 SimpleTest.waitForExplicitFinish();
 
 function clickit() {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   var select = document.getElementById('select');
-  var evt = document.createEvent("MouseEvents");
-  evt.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
-  select.dispatchEvent(evt);
-  evt.initMouseEvent("mouseup", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
-  select.dispatchEvent(evt);
-  evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
-  select.dispatchEvent(evt);
+
+  sendMouseEvent({type:'mousedown'}, select);
+  sendMouseEvent({type:'mouseup'}, select);
+  sendMouseEvent({type:'click'}, select);
 
   setTimeout(finish, 200);
-
 }
 
 window.addEventListener('load', clickit, false);
 
 function finish()
 {
   ok(true, "This is a mochikit version of a crash test. To complete is to pass.");
   SimpleTest.finish();
--- a/layout/forms/test/test_bug402198.html
+++ b/layout/forms/test/test_bug402198.html
@@ -47,23 +47,22 @@ https://bugzilla.mozilla.org/show_bug.cg
 function doe3() {
   document.documentElement.style.display = 'none';
   document.body.offsetHeight;
   document.documentElement.style.display = '';
   document.body.offsetHeight;
 
   document.getElementById('a').focus();
   document.body.style.display = 'none';
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var wu =  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                  .getInterface(Components.interfaces.nsIDOMWindowUtils);
-  wu.sendKeyEvent('keypress',  9, 0, 4);
+
+  synthesizeKey('VK_TAB', {type: "keypress", shiftKey: true});
 
   is(0, 0, "this is a crash/assertion test, so we're ok if we survived this far");
   SimpleTest.finish();
+  setTimeout(function() {document.body.style.display = '';}, 400);
 }
 
 function do_test() {
   setTimeout(doe3,300);
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(do_test);
--- a/layout/forms/test/test_bug446663.html
+++ b/layout/forms/test/test_bug446663.html
@@ -18,26 +18,25 @@ https://bugzilla.mozilla.org/show_bug.cg
   
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 446663 **/
 
 function test_edit_cmds(id) {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 
   var elm = document.getElementById(id);
   elm.focus();
   elm.select();
-  elm.controllers.getControllerForCommand('cmd_cut')
+  SpecialPowers.wrap(elm).controllers.getControllerForCommand('cmd_cut')
                          .doCommand('cmd_cut');
   is(elm.value, '', id + " cut");
 
-  elm.controllers.getControllerForCommand('cmd_undo')
+  SpecialPowers.wrap(elm).controllers.getControllerForCommand('cmd_undo')
                          .doCommand('cmd_undo');
   is(elm.value, '123', id + " undo");
 }
 
 var inputHappened = false;
 function inputListener() {
   inputHappened = true;
   $(id).removeEventListener("input", inputListener, false);
--- a/layout/generic/test/bug421839-2-page.html
+++ b/layout/generic/test/bug421839-2-page.html
@@ -1,19 +1,17 @@
 <html>
 <head>
 </head>
 <body style="position: absolute;">
 <iframe id="a"></iframe>
 <iframe></iframe>
 <script>
 function tripleclick(){
-netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-var wu =  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                .getInterface(Components.interfaces.nsIDOMWindowUtils);
+var wu =  SpecialPowers.getDOMWindowUtils(window);
 wu.sendMouseEvent('mousedown',  100, 100, 0, 1, 0);
 setTimeout(tripleclick,20);
 }
 setTimeout(tripleclick,200,0, 0);
 
 function doe2() {
 document.body.setAttribute('style', 'position: absolute;');
 document.body.offsetHeight;
--- a/layout/generic/test/test_bug421839-1.html
+++ b/layout/generic/test/test_bug421839-1.html
@@ -27,34 +27,29 @@ var counter = 0;
 
 SimpleTest.waitForExplicitFinish();
 
 var doc = document;
 if (document.getElementById('iframe'))
   doc = document.getElementById('iframe').contentDocument;
 
 function toggleIframe(){
- netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   var x=document.getElementById('iframe');
   x.style.display = x.style.display == 'none' ? x.style.display = '' : x.style.display = 'none';
   setTimeout(toggleIframe,100);
 
   if (++counter == 4)
     setTimeout(finish, 200);
 
 }
 setTimeout(toggleIframe,100);
 
 function ctrlclick(i){
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var wu =  doc.defaultView.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-               .getInterface(Components.interfaces.nsIDOMWindowUtils);
-
-  var wu2 =  top.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                .getInterface(Components.interfaces.nsIDOMWindowUtils);
+  var wu = SpecialPowers.getDOMWindowUtils(doc.defaultView);
+  var wu2 = SpecialPowers.getDOMWindowUtils(top);
 
   try
   {
     wu.sendMouseEvent('mousedown',  2*i, 2*i, 0, 1, 0);
     wu2.sendMouseEvent('mousemove',  500*i, 500*i, 0, 0, 0);
     //wu.sendMouseEvent('mouseup',  2*i, 2*i, 0, 1, 2);
   }
   catch(e)
--- a/layout/generic/test/test_bug460532.html
+++ b/layout/generic/test/test_bug460532.html
@@ -14,36 +14,32 @@ https://bugzilla.mozilla.org/show_bug.cg
 <p id="display"></p>
 <div id="content" style="display: block">
 lorem ipsum.
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 function select_460532(){
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
   var content = document.getElementById('content');
   var node = content.firstChild;
 
   var range = document.createRange();
   range.setStart(node, 0);
   range.setEnd(node, 5);
   window.getSelection().addRange(range);
 
   range = document.createRange();
   range.setStart(node, 0);
   range.setEnd(node, 6);
   window.getSelection().addRange(range);
 }
 
 function click_460532(){
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var wu =  document.defaultView.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-               .getInterface(Components.interfaces.nsIDOMWindowUtils);
+  var wu = SpecialPowers.getDOMWindowUtils(window);
   var content = document.getElementById('content');
   var rect = content.getBoundingClientRect();
   wu.sendMouseEvent('mousedown', rect.left+5, rect.top+5, 0, 1, 0);
   wu.sendMouseEvent('mouseup', rect.left+5, rect.top+5, 0, 1, 0);
   ok(true, "pass");
   SimpleTest.finish();
 }
 
--- a/layout/generic/test/test_bug507902.html
+++ b/layout/generic/test/test_bug507902.html
@@ -23,21 +23,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 // data to determine the frame size.
 //
 // The 'broken' icon should be displayed when the URL is invalid (either
 // a bad server or a file that fails to be sniffed to an appropriate
 // mimetype).
 //
 
 // Boilerplate
-netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-const Cc = Components.classes;
-const Ci = Components.interfaces;
-gWindowUtils = window.QueryInterface(Ci.nsIInterfaceRequestor).
-                 getInterface(Ci.nsIDOMWindowUtils);
+gWindowUtils = SpecialPowers.getDOMWindowUtils(window);
 
 // URL + paths
 //
 // We have a separate copy of the icons in the test directory to
 // avoid any firefox caching mechanisms that might affect the
 // behavior of the load.
 var us = window.location.href;
 var baseURL = us.substring(0, us.lastIndexOf('/') + 1);
@@ -357,31 +353,28 @@ function disableBorderAndPad() {
   divContainer.style.borderStyle = "";
 }
 
 //
 // Helper canvas methods. This is mostly copped directly from the reftest framework
 //
 
 function drawWindowToCanvas(canvasName) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   var win = testFrameElem.contentWindow;
   var ctx = canvases[canvasName].getContext("2d");
   // drawWindow always draws one canvas pixel for each CSS pixel in the source
   // window, so scale the drawing to show the zoom (making each canvas pixel be one
   // device pixel instead)
   ctx.drawWindow(win, win.scrollX, win.scrollY,
                  Math.ceil(canvases[canvasName].width),
                  Math.ceil(canvases[canvasName].height),
                  "rgb(255,255,255)");
 }
 
 function canvasesAreEqual(canvas1Name, canvas2Name) {
-
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   var c1 = canvases[canvas1Name];
   var c2 = canvases[canvas2Name];
   var differences = gWindowUtils.compareCanvases(c1, c2, {});
   return (differences == 0);
 }
 
 </script>
 </pre>
--- a/layout/generic/test/test_selection_touchevents.html
+++ b/layout/generic/test/test_selection_touchevents.html
@@ -16,31 +16,31 @@ var div1 = document.getElementById("div1
 
 function sendTouch(aType, aX, aY) {
   var cwu = SpecialPowers.getDOMWindowUtils(window);
   cwu.sendTouchEvent(aType, [0], [aX], [aY], [1], [1], [0], [1], 1, 0, true);
 }
 
 function test()
 {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
   var selection = window.getSelection();
   selection.removeAllRanges();
   var rect = div1.getBoundingClientRect();
 
   // Position the caret using a fake mouse click
+  var Ci = SpecialPowers.Ci;
   var cwu = SpecialPowers.getDOMWindowUtils(window);
   cwu.sendMouseEventToWindow("mousedown", rect.left + rect.width/2, rect.top + rect.height/2, 0, 0, 0, true);
   cwu.sendMouseEventToWindow("mouseup",   rect.left + rect.width/2, rect.top + rect.height/2, 0, 0, 0, true);
-  var selectionController = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                                   getInterface(Components.interfaces.nsIWebNavigation).
-                                   QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                                   getInterface(Components.interfaces.nsISelectionDisplay).
-                                   QueryInterface(Components.interfaces.nsISelectionController);
+  var selectionController = SpecialPowers.wrap(window).
+                              QueryInterface(Ci.nsIInterfaceRequestor).
+                              getInterface(Ci.nsIWebNavigation).
+                              QueryInterface(Ci.nsIInterfaceRequestor).
+                              getInterface(Ci.nsISelectionDisplay).
+                              QueryInterface(Ci.nsISelectionController);
 
   selectionController.wordMove(false, false);
   selectionController.wordMove(true, true);
   isnot(selection.rangeCount, 0, "Something should be selected");
   var string = selection.toString();
 
   sendTouch("touchstart", rect.right, rect.top + rect.height/2);
   sendTouch("touchmove",  rect.left, rect.top + rect.height/2);
--- a/testing/mochitest/b2g.json
+++ b/testing/mochitest/b2g.json
@@ -390,17 +390,16 @@
     "dom/workers/test/test_xhr_system.html":"",
     "dom/workers/test/test_closeOnGC.html": "times out",
     "dom/workers/test/test_errorPropagation.html":"times out",
     "dom/workers/test/test_errorwarning.html":"Failed to load script: errorwarning_worker.js",
     "dom/workers/test/test_fibonacci.html":"Failed to load script: fibonacci_worker.js",
     "dom/workers/test/test_relativeLoad.html":"Failed to load script: relativeLoad_import.js",
 
     "layout/base/tests/test_bug450930.xhtml":"times out",
-    "layout/base/tests/test_bug458898.html":"nsIDOMJSWindow.openDialog error",
     "layout/base/tests/test_bug603550.html":"Components.classes[@mozilla.org/widget/dragservice;1] is undefined",
     "layout/base/tests/test_bug629838.html":"depends on plugins support",
     "layout/base/tests/test_mozPaintCount.html":"depends on plugins support",
     "layout/forms/test/test_bug348236.html":"select form control popup",
     "layout/forms/test/test_bug446663.html":"needs copy support",
     "layout/forms/test/test_bug564115.html":"times out on window.open and focus event",
     "layout/forms/test/test_bug571352.html":"shift-click multi-select not working?",
     "layout/forms/test/test_textarea_resize.html":"resizing textarea not available in b2g",
--- a/testing/mochitest/tests/SimpleTest/EventUtils.js
+++ b/testing/mochitest/tests/SimpleTest/EventUtils.js
@@ -39,17 +39,17 @@ window.__defineGetter__('_EU_Ci', functi
 function getElement(id) {
   return ((typeof(id) == "string") ?
     document.getElementById(id) : id); 
 };   
 
 this.$ = this.getElement;
 
 function sendMouseEvent(aEvent, aTarget, aWindow) {
-  if (['click', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 'mouseout'].indexOf(aEvent.type) == -1) {
+  if (['click', 'contextmenu', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 'mouseout'].indexOf(aEvent.type) == -1) {
     throw new Error("sendMouseEvent doesn't know about event type '" + aEvent.type + "'");
   }
 
   if (!aWindow) {
     aWindow = window;
   }
 
   if (!(aTarget instanceof aWindow.Element)) {
@@ -69,25 +69,25 @@ function sendMouseEvent(aEvent, aTarget,
   var screenXArg       = aEvent.screenX       || 0;
   var screenYArg       = aEvent.screenY       || 0;
   var clientXArg       = aEvent.clientX       || 0;
   var clientYArg       = aEvent.clientY       || 0;
   var ctrlKeyArg       = aEvent.ctrlKey       || false;
   var altKeyArg        = aEvent.altKey        || false;
   var shiftKeyArg      = aEvent.shiftKey      || false;
   var metaKeyArg       = aEvent.metaKey       || false;
-  var buttonArg        = aEvent.button        || 0;
+  var buttonArg        = aEvent.button        || (aEvent.type == 'contextmenu' ? 2 : 0);
   var relatedTargetArg = aEvent.relatedTarget || null;
 
   event.initMouseEvent(typeArg, canBubbleArg, cancelableArg, viewArg, detailArg,
                        screenXArg, screenYArg, clientXArg, clientYArg,
                        ctrlKeyArg, altKeyArg, shiftKeyArg, metaKeyArg,
                        buttonArg, relatedTargetArg);
 
-  SpecialPowers.dispatchEvent(aWindow, aTarget, event);
+  return SpecialPowers.dispatchEvent(aWindow, aTarget, event);
 }
 
 /**
  * Send the char aChar to the focused element.  This method handles casing of
  * chars (sends the right charcode, and sends a shift key for uppercase chars).
  * No other modifiers are handled at this point.
  *
  * For now this method only works for ASCII characters and emulates the shift