Bug 914940 - Remove some enablePrivilige calls. r=jgriffin
authorMartijn Wargers <mwargers@mozilla.com>
Wed, 11 Sep 2013 10:51:09 +0200
changeset 159583 a1a846de1a8aff4c1bd00f7e72e2c912222f108f
parent 159582 7fa0fd335e9f78d21d2b7c22d30884e26e9b695a
child 159584 35a772328e246abec98b50226213514ce9d5fe43
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgriffin
bugs914940
milestone26.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 914940 - Remove some enablePrivilige calls. r=jgriffin
caps/tests/mochitest/test_bug470804.html
content/base/test/copypaste.js
content/base/test/file_bug557892.html
content/base/test/test_XHRSendData.html
content/base/test/test_bug218236.html
content/base/test/test_bug382871.html
content/base/test/test_bug403852.html
content/base/test/test_bug416383.html
content/base/test/test_bug421602.html
content/base/test/test_bug448993.html
content/base/test/test_bug456262.html
content/base/test/test_bug459424.html
content/base/test/test_bug465767.html
content/base/test/test_bug592829.html
content/base/test/test_mozfiledataurl.html
content/canvas/test/webgl/test_webgl_conformance_test_suite.html
content/events/test/bug426082.html
content/events/test/bug656379-1.html
content/events/test/test_bug402089.html
content/events/test/test_bug448602.html
content/events/test/test_bug450876.html
content/events/test/test_bug456273.html
content/events/test/test_bug605242.html
content/html/content/test/forms/test_pattern_attribute.html
content/html/content/test/forms/test_validation.html
content/html/content/test/test_bug209275.xhtml
content/html/content/test/test_bug406596.html
content/html/content/test/test_bug421640.html
content/html/content/test/test_bug460568.html
content/html/content/test/test_bug481335.xhtml
content/html/content/test/test_formSubmission2.html
content/html/document/test/test_bug446483.html
content/html/document/test/test_viewport.html
--- a/caps/tests/mochitest/test_bug470804.html
+++ b/caps/tests/mochitest/test_bug470804.html
@@ -16,20 +16,18 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 470804
     Passing a null targetURL to checkLoadURIWithPrincipal shouldn't crash
  **/
 
-netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-const nsIScriptSecurityManager = Components.interfaces.nsIScriptSecurityManager;
-var secMan = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
-                       .getService(nsIScriptSecurityManager);
+const nsIScriptSecurityManager = SpecialPowers.Ci.nsIScriptSecurityManager;
+var secMan = SpecialPowers.Services.scriptSecurityManager;
 var principal = SpecialPowers.wrap(document).nodePrincipal;
 isnot(principal, undefined, "Should have a principal");
 isnot(principal, null, "Should have a non-null principal");
 is(secMan.isSystemPrincipal(principal), false,
    "Shouldn't have system principal here");
 try {
   secMan.checkLoadURIWithPrincipal(principal, null,
                                    nsIScriptSecurityManager.STANDARD);
--- a/content/base/test/copypaste.js
+++ b/content/base/test/copypaste.js
@@ -25,31 +25,28 @@ function modifySelection(s) {
 function getLoadContext() {
   var Ci = SpecialPowers.Ci;
   return SpecialPowers.wrap(window).QueryInterface(Ci.nsIInterfaceRequestor)
                                    .getInterface(Ci.nsIWebNavigation)
                                    .QueryInterface(Ci.nsILoadContext);
 }
 
 function testCopyPaste (isXHTML) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
   var suppressUnicodeCheckIfHidden = !!isXHTML;
   var suppressHTMLCheck = !!isXHTML;
 
-  var webnav = window.QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
+  var webnav = SpecialPowers.wrap(window).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
                      .getInterface(SpecialPowers.Ci.nsIWebNavigation)
 
   var docShell = webnav.QueryInterface(SpecialPowers.Ci.nsIDocShell);
 
   var documentViewer = docShell.contentViewer
                                .QueryInterface(SpecialPowers.Ci.nsIContentViewerEdit);
 
-  var clipboard = SpecialPowers.Cc["@mozilla.org/widget/clipboard;1"]
-                            .getService(SpecialPowers.Ci.nsIClipboard);
+  var clipboard = SpecialPowers.Services.clipboard;
 
   var textarea = SpecialPowers.wrap(document.getElementById('input'));
 
   function copySelectionToClipboard(suppressUnicodeCheck) {
     documentViewer.copySelection();
     if (!suppressUnicodeCheck)
       ok(clipboard.hasDataMatchingFlavors(["text/unicode"], 1,1), "check text/unicode");
     if (!suppressHTMLCheck)
@@ -83,24 +80,24 @@ function testCopyPaste (isXHTML) {
     copySelectionToClipboard();
   }
   function getClipboardData(mime) {
     var transferable = SpecialPowers.Cc['@mozilla.org/widget/transferable;1']
                                     .createInstance(SpecialPowers.Ci.nsITransferable);
     transferable.init(getLoadContext());
     transferable.addDataFlavor(mime);
     clipboard.getData(transferable, 1);
-    var data = {};
+    var data = SpecialPowers.createBlankObject();
     transferable.getTransferData(mime, data, {}) ;
     return data;
   }
   function testClipboardValue(mime, expected) {
     if (suppressHTMLCheck && mime == "text/html")
       return null;
-    var data = getClipboardData(mime);
+    var data = SpecialPowers.wrap(getClipboardData(mime));
     is (data.value == null ? data.value :
         data.value.QueryInterface(SpecialPowers.Ci.nsISupportsString).data,
       expected,
       mime + " value in the clipboard");
     return data.value;
   }
   function testPasteText(expected) {
     textarea.value="";
--- a/content/base/test/file_bug557892.html
+++ b/content/base/test/file_bug557892.html
@@ -7,21 +7,18 @@ function run() {
   classList = window.frames[0].document.documentElement.classList;
   window.frames[0].location.reload();
   interval = setInterval(function(aClassList) {aClassList.toggle('a'); forcegc();}, 10, classList);
   // Let the interval run for awhile and close the window after 2 seconds.
   setTimeout(function() { clearInterval(interval); window.opener.done(); window.close(); }, 2000);
 }
 
 function forcegc(){
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  Components.utils.forceGC();
-  var wu =  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                  .getInterface(Components.interfaces.nsIDOMWindowUtils);
-  wu.garbageCollect();
+  SpecialPowers.forceGC();
+  SpecialPowers.gc();
 }
 
     </script>
   </head>
   <body onload="run()">
     <iframe></iframe>
   </body>
 </html>
--- a/content/base/test/test_XHRSendData.html
+++ b/content/base/test/test_XHRSendData.html
@@ -33,18 +33,16 @@ testDoc1 = xhr.responseXML;
 is(testDoc1.inputEncoding, "windows-1252", "wrong encoding");
 
 testDoc2 = document.implementation.createDocument("", "", null);
 testDoc2.appendChild(testDoc2.createComment(" doc 2 "));
 testDoc2.appendChild(testDoc2.createElement("res"));
 testDoc2.documentElement.appendChild(testDoc2.createTextNode("text"));
 is(testDoc2.inputEncoding, null, "wrong encoding");
 
-netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
 var testData = "blahblahblahblahblahblahblaaaaaaaah. blah.";
 var extensions = [".txt",".png",".jpg",".gif",".xml", "noext"];
 var fileTypes = ["text/plain", "image/png", "image/jpeg", "image/gif", "text/xml", null];
 var testFiles = new Array;
 var testDOMFiles = new Array;
 
 // arraybuffer test objects
 var shortArray = new ArrayBuffer(1);
@@ -67,24 +65,23 @@ var longInt8View1 = new Int8Array(longAr
 var longInt8View2 = new Int8Array(longArray, 256, 128)
 
 extensions.forEach(
     function (extension) {
       var testFile = createFileWithDataExt(testData, extension);
       testFiles.push(testFile);
 
       var fileList = document.getElementById('fileList');
-      fileList.value = testFile.path;
+      SpecialPowers.wrap(fileList).value = testFile.path;
       testDOMFiles.push(fileList.files[0]);
     }
 );
 
 function createFileWithDataExt(fileData, extension) {
-  var dirSvc = SpecialPowers.Cc["@mozilla.org/file/directory_service;1"].getService(SpecialPowers.Ci.nsIProperties);
-  var testFile = dirSvc.get("ProfD", SpecialPowers.Ci.nsIFile);
+  var testFile = SpecialPowers.Services.dirsvc.get("ProfD", SpecialPowers.Ci.nsIFile);
   testFile.append("testfile" + extension);
   var outStream = SpecialPowers.Cc["@mozilla.org/network/file-output-stream;1"].createInstance(SpecialPowers.Ci.nsIFileOutputStream);
   outStream.init(testFile, 0x02 | 0x08 | 0x20, 0666, 0);
   outStream.write(fileData, fileData.length);
   outStream.close();
 
   return testFile;
 }
--- a/content/base/test/test_bug218236.html
+++ b/content/base/test/test_bug218236.html
@@ -60,18 +60,16 @@ function doAbort2() {
 }
 
 /* Utility functions */
 
 function runNextTest() {
   if (tests.length > 0) {
     var test = tests.shift();
 
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
     // Initialize state variables
     testName = test[0]
     currentState = 0;
     currentSequence = [];
     expectedSequence = test[2];
     currentCallback = test[3];
     postSendCallback = test[4];
 
--- a/content/base/test/test_bug382871.html
+++ b/content/base/test/test_bug382871.html
@@ -28,20 +28,17 @@ function loadHandler(evt) {
 function runTest() {
   var xhr = new XMLHttpRequest();
   xhr.onload = loadHandler;
   xhr.randomProperty = true;
   xhr.upload.randomProperty = true;
   xhr.open("GET", "test_bug382871.html");
   xhr.send();
   xhr = null;
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-        .getInterface(Components.interfaces.nsIDOMWindowUtils)
-        .garbageCollect();
+  SpecialPowers.gc();
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(runTest);
 
 </script>
 </pre>
 </body>
--- a/content/base/test/test_bug403852.html
+++ b/content/base/test/test_bug403852.html
@@ -16,24 +16,21 @@ https://bugzilla.mozilla.org/show_bug.cg
   <canvas id="canvas"></canvas>
 </p>
 <div id="content" style="display: none">
 </div>
 
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
-netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
-var dirSvc = SpecialPowers.Cc["@mozilla.org/file/directory_service;1"].getService(SpecialPowers.Ci.nsIProperties);
-var testFile = dirSvc.get("ProfD", SpecialPowers.Ci.nsIFile);
+var testFile = SpecialPowers.Services.dirsvc.get("ProfD", SpecialPowers.Ci.nsIFile);
 testFile.append("prefs.js");
 
 var fileList = document.getElementById('fileList');
-fileList.value = testFile.path;
+SpecialPowers.wrap(fileList).value = testFile.path;
 
 // Make sure the file is accessible with indexed notation
 var domFile = fileList.files[0];
 
 is(domFile.name, "prefs.js", "fileName should be prefs.js");
 
 ok("lastModifiedDate" in domFile, "lastModifiedDate must be present");
 
--- a/content/base/test/test_bug416383.html
+++ b/content/base/test/test_bug416383.html
@@ -16,26 +16,23 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <div id="test_parent"><div someattr="foo"></div></div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 416383 **/
 
 function runTest() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   var testParent = document.getElementById("test_parent");
   var attrs = testParent.firstChild.attributes;
   ok(attrs != null, "Element should have attributes!");
   var attr = testParent.firstChild.getAttributeNode("someattr");
   ok(attr.value == "foo", "The value of the attribute should be 'foo'!");
   testParent.removeChild(testParent.firstChild);
-  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-        .getInterface(Components.interfaces.nsIDOMWindowUtils)
-        .garbageCollect();
+  SpecialPowers.gc();
   ok(true, "Browser should not crash!")
 
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(runTest);
 addLoadEvent(SimpleTest.finish);
 
--- a/content/base/test/test_bug421602.html
+++ b/content/base/test/test_bug421602.html
@@ -18,40 +18,33 @@ https://bugzilla.mozilla.org/show_bug.cg
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 421602 **/
 SimpleTest.waitForExplicitFinish();
 
 var img1loaded = false;
 var img1errored = false;
 
-function gc() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-        .getInterface(Components.interfaces.nsIDOMWindowUtils)
-        .garbageCollect();
-}
-
 // Our test image
 function loadTestImage() {
   var img1 = new Image();
   img1.onload = function() {
     img1loaded = true;
     finishTest();
   }
   img1.onerror = function() {
     img1errored = true;
     finishTest();
   }
   img1.src = window.location.href + "?image1=true";
 }
 loadTestImage();
 
 // Probably overkill to gc() more than once, but let's be safe
-gc(); gc(); gc();
+SpecialPowers.gc(); SpecialPowers.gc(); SpecialPowers.gc();
 
 function finishTest() {
   is(img1errored, true, "Image 1 should error");
   is(img1loaded, false, "Image 1 should not load");
   SimpleTest.finish();
 }
 </script>
 </pre>
--- a/content/base/test/test_bug448993.html
+++ b/content/base/test/test_bug448993.html
@@ -14,35 +14,28 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 448993 **/
 
-function gc() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-        .getInterface(Components.interfaces.nsIDOMWindowUtils)
-        .garbageCollect();
-}
-
 function runTest() {
   var a = document.getElementById("a");
   var b = document.getElementById("b");
   var c = document.getElementById("c")
   var r = document.createRange();
   r.setStart(b, 0); 
   r.setEnd(a, 2); 
   c.appendChild(b);
   r.extractContents();
   var s = document.createRange();
   s.setEnd(b, 0); 
-  gc();
+  SpecialPowers.gc();
   s.deleteContents();
   ok(true, "test did not crash");
   SimpleTest.finish();
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(runTest);
 
--- a/content/base/test/test_bug456262.html
+++ b/content/base/test/test_bug456262.html
@@ -15,24 +15,21 @@ https://bugzilla.mozilla.org/show_bug.cg
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 456262 **/
 
 function runTest() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   document.expando = document;
   document.documentElement.expando = document;
   document.documentElement.setAttribute("foo", "bar");
   document.documentElement.getAttributeNode("foo").expando = document;
-  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-        .getInterface(Components.interfaces.nsIDOMWindowUtils)
-        .garbageCollect();
+  SpecialPowers.gc();
   ok(document.expando, "Should have preserved the expando!");
   ok(document.documentElement.expando, "Should have preserved the expando!");
   ok(document.documentElement.getAttributeNode('foo').expando,
      "Should have preserved the expando!");
 }
 
 runTest();
 
--- a/content/base/test/test_bug459424.html
+++ b/content/base/test/test_bug459424.html
@@ -15,24 +15,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 459424 **/
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(function() {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-  var viewer =
-    window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-          .getInterface(Components.interfaces.nsIWebNavigation)
-          .QueryInterface(Components.interfaces.nsIDocShell)
-          .contentViewer
-          .QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
-  viewer.fullZoom = 2;
+  SpecialPowers.setFullZoom(window, 2);
   is(true, true, "Gotta test something");
-  viewer.fullZoom = 1;
+  SpecialPowers.setFullZoom(window, 1);
   SimpleTest.finish();
 });
 </script>
 </pre>
 </body>
 </html>
--- a/content/base/test/test_bug465767.html
+++ b/content/base/test/test_bug465767.html
@@ -14,29 +14,22 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 465767 **/
 
-function CC() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-        .getInterface(Components.interfaces.nsIDOMWindowUtils)
-        .garbageCollect();
-}
-
 function runTest() {
   var node = document.createElement("div");
   var e = null;
   try {
     document.implementation.createDocument("", "", null).adoptNode(node);
-    CC();
+    SpecialPowers.gc();
     document.implementation.createDocument("", "", null).adoptNode(node);
   } catch(ex) {
     e = ex;
   }
   is(e, null, ".adoptNode didn't succeed!");
   SimpleTest.finish();
 }
 
--- a/content/base/test/test_bug592829.html
+++ b/content/base/test/test_bug592829.html
@@ -14,22 +14,20 @@ https://bugzilla.mozilla.org/show_bug.cg
 <script type="application/javascript">
 /** Test for Bug 592829 **/
 
 // NOTE! It's imperative that we don't call .init() here. Otherwise we're not
 // testing what happens if parsing fails.
 // If we ever change how DOMParser initilization works, just update this code
 // to create a DOMParser which is not allowed to parse XUL.
 
-netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
 var isXUL = true;
 try {
   var x =
-    Components.classes["@mozilla.org/xmlextras/domparser;1"]
+    SpecialPowers.Cc
       .getService(Components.interfaces.nsIDOMParser)
       .parseFromString('<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"/>', "text/xml");
   isXUL = x.documentElement.namespaceURI ==
     "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 }
 catch (ex) {
   isXUL = false;
 }
--- a/content/base/test/test_mozfiledataurl.html
+++ b/content/base/test/test_mozfiledataurl.html
@@ -204,20 +204,18 @@ var basePath = "";
 function getFile(name) {
   if (!basePath) {
     let xhr = new XMLHttpRequest;
     xhr.open("GET", "/dynamic/getMyDirectory.sjs", false);
     xhr.send();
     basePath = xhr.responseText;
   }
 
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
   var fileList = document.getElementById('fileList');
-  fileList.value = basePath + name;
+  SpecialPowers.wrap(fileList).value = basePath + name;
 
   return fileList.files[0];
 }
 
 </script>
 </pre>
 </body>
 </html>
--- a/content/canvas/test/webgl/test_webgl_conformance_test_suite.html
+++ b/content/canvas/test/webgl/test_webgl_conformance_test_suite.html
@@ -85,20 +85,17 @@ function start() {
   var kOS = null;
   var kOSVersion = null;
   var kGLDriver = null;
 
   if (navigator.platform.indexOf('Win') == 0) {
     kOS = OS_WINDOWS;
     
     // code borrowed from browser/modules/test/browser_taskbar_preview.js
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-    var version = SpecialPowers.Cc['@mozilla.org/system-info;1']
-                               .getService(SpecialPowers.Ci.nsIPropertyBag2)
-                               .getProperty('version');
+    var version = SpecialPowers.Services.sysinfo.getProperty('version');
     kOSVersion = parseFloat(version);
     // Version 6.0 is Vista, 6.1 is 7.
   } else if (navigator.platform.indexOf('Mac') == 0) {
     kOS = OS_MAC;
     
     var versionMatch = /Mac OS X (\d+.\d+)/.exec(navigator.userAgent);
     kOSVersion = versionMatch ? parseFloat(versionMatch[1]) : null;
   } else if (navigator.appVersion.indexOf('Android') != -1) {
@@ -134,17 +131,16 @@ function start() {
     info('GL driver not detected.');
   }
   
   var requestLongerTimeoutLen = 3;
   if (kOS == OS_ANDROID)
     requestLongerTimeoutLen = 6;
 
   function getEnv(env) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
     var envsvc = SpecialPowers.Cc["@mozilla.org/process/environment;1"].getService(SpecialPowers.Ci.nsIEnvironment);
     var val = envsvc.get(env);
     if (val == "")
       return null;
     return val;
   }
 
   var reportType = WebGLTestHarnessModule.TestHarness.reportType;
--- a/content/events/test/bug426082.html
+++ b/content/events/test/bug426082.html
@@ -44,18 +44,17 @@ function isRectContainedInRectFromRegion
     return rect.left >= r.left &&
            rect.top >= r.top &&
            rect.right <= r.right &&
            rect.bottom <= r.bottom;
   });
 }
 
 function paintListener(e) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  if (isRectContainedInRectFromRegion(buttonRect(), e.clientRects)) {
+  if (isRectContainedInRectFromRegion(buttonRect(), SpecialPowers.wrap(e).clientRects)) {
     gNeedsPaint = false;
     currentSnapshot = takeSnapshot();
   }
 }
 
 var gNeedsPaint = false;
 function executeTests() {
   var testYielder = tests();
--- a/content/events/test/bug656379-1.html
+++ b/content/events/test/bug656379-1.html
@@ -60,18 +60,17 @@ function isRectContainedInRectFromRegion
     return rect.left >= r.left &&
            rect.top >= r.top &&
            rect.right <= r.right &&
            rect.bottom <= r.bottom;
   });
 }
 
 function paintListener(e) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  if (isRectContainedInRectFromRegion(buttonRect(), e.clientRects)) {
+  if (isRectContainedInRectFromRegion(buttonRect(), SpecialPowers.wrap(e).clientRects)) {
     gNeedsPaint = false;
     currentSnapshot = takeSnapshot();
   }
 }
 
 var gNeedsPaint = false;
 function executeTests() {
   var testYielder = tests();
--- a/content/events/test/test_bug402089.html
+++ b/content/events/test/test_bug402089.html
@@ -47,19 +47,17 @@ function clickHandler(e) {
   e.stopPropagation();
   e.preventDefault();
   window.removeEventListener("click", clickHandler, true);
   setTimeout(testCachedEvent, 10);
 }
 
 function doTest() {
   window.addEventListener("click", clickHandler, true);
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-  var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                     getInterface(Components.interfaces.nsIDOMWindowUtils);
+  var utils = SpecialPowers.getDOMWindowUtils(window);
   utils.sendMouseEvent("mousedown", 1, 1, 0, 1, 0);
   utils.sendMouseEvent("mouseup", 1, 1, 0, 1, 0);
 
 }
 
 SimpleTest.waitForExplicitFinish();
 </script>
 </pre>
--- a/content/events/test/test_bug448602.html
+++ b/content/events/test/test_bug448602.html
@@ -146,18 +146,17 @@ function runTests() {
     ok(false, "Should have thrown an exception.");
   } catch (ex) {
     ok(true, "We should be still running.");
   }
   setTimeout(testAllListener, 0);
 }
 
 function dispatchTrusted(t, o) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  t.dispatchEvent(new Event("testevent", o));
+  SpecialPowers.dispatchEvent(window, t, new Event("testevent", o));
 }
 
 function testAllListener() {
   els = SpecialPowers.wrap(els);
   var results = [];
   var expectedResults =
     [ { target: "testlevel3", phase: 3, trusted: false },
       { target: "testlevel3", phase: 3, trusted: false },
--- a/content/events/test/test_bug450876.html
+++ b/content/events/test/test_bug450876.html
@@ -15,24 +15,21 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 450876 **/
 
 function doTest() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   is(document.activeElement, document.body, "body element should be focused");
   document.getElementById('a').focus();
   is(document.activeElement, document.getElementById('a'), "link should have focus");
-  var wu =  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                .getInterface(Components.interfaces.nsIDOMWindowUtils);
   is(document.hasFocus(), true, "document should be focused");
-  wu.sendKeyEvent('keypress',  9, 0, 0);
+  SpecialPowers.DOMWindowUtils.sendKeyEvent('keypress',  9, 0, 0);
   is(document.activeElement, document.getElementById('a'), "body element should be focused");
   is(document.hasFocus(), false, "document should not be focused");
 
   SimpleTest.finish();
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(doTest);
--- a/content/events/test/test_bug456273.html
+++ b/content/events/test/test_bug456273.html
@@ -18,22 +18,21 @@ https://bugzilla.mozilla.org/show_bug.cg
 <div id="edit456273" contenteditable="true">text</div>
 
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 456273 **/
 
 function doTest() {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
   var ev = document.createEvent('KeyEvents');
   ev.initKeyEvent("keypress", true, true, null, true, false,
                  false, false, 0, "z".charCodeAt(0));
-  document.getElementById('edit456273').dispatchEvent(ev);
+  SpecialPowers.dispatchEvent(window, document.getElementById('edit456273'), ev);
+
   ok(true, "PASS");
   SimpleTest.finish();
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(doTest);
 
 </script>
--- a/content/events/test/test_bug605242.html
+++ b/content/events/test/test_bug605242.html
@@ -16,29 +16,24 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 605242 **/
 
 SimpleTest.waitForExplicitFinish();
 
+var utils = SpecialPowers.getDOMWindowUtils(window);
 function sendMouseDown(el) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   var rect = el.getBoundingClientRect();
-  var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                    .getInterface(Components.interfaces.nsIDOMWindowUtils);
   utils.sendMouseEvent('mousedown', rect.left + 5, rect.top + 5, 0, 1, 0);
 }
 
 function sendMouseUp(el) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   var rect = el.getBoundingClientRect();
-  var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                    .getInterface(Components.interfaces.nsIDOMWindowUtils);
   utils.sendMouseEvent('mouseup', rect.left + 5, rect.top + 5, 0, 1, 0);
 }
 
 function runTest() {
   var b = document.getElementById("testbutton");
   sendMouseDown(b);
   var l = document.querySelectorAll(":active");
 
--- a/content/html/content/test/forms/test_pattern_attribute.html
+++ b/content/html/content/test/forms/test_pattern_attribute.html
@@ -29,46 +29,41 @@ var gInvalid = false;
 function invalidEventHandler(e)
 {
   is(e.type, "invalid", "Invalid event type should be invalid");
   gInvalid = true;
 }
 
 function completeValidityCheck(element, alwaysValid, isBarred)
 {
-  if (element.type == 'file') {
-    // Need privileges to set a filename with .value.
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  }
-
   // Check when pattern matches.
   if (element.type == 'email') {
     element.pattern = ".*@bar.com";
     element.value = "foo@bar.com";
   } else if (element.type == 'url') {
     element.pattern = "http://.*\\.com$";
     element.value = "http://mozilla.com";
   } else {
     element.pattern = "foo";
-    element.value = "foo";
+    SpecialPowers.wrap(element).value = "foo";
   }
 
   checkValidPattern(element, true, isBarred);
 
   // Check when pattern does not match.
 
   if (element.type == 'email') {
     element.pattern = ".*@bar.com";
     element.value = "foo@foo.com";
   } else if (element.type == 'url') {
     element.pattern = "http://.*\\.com$";
     element.value = "http://mozilla.org";
   } else {
     element.pattern = "foo";
-    element.value = "bar";
+    SpecialPowers.wrap(element).value = "bar";
   }
 
   if (!alwaysValid) {
     checkInvalidPattern(element, true);
   } else {
     checkValidPattern(element, true, isBarred);
   }
 }
--- a/content/html/content/test/forms/test_validation.html
+++ b/content/html/content/test/forms/test_validation.html
@@ -263,20 +263,18 @@ function checkCheckValidity(element)
 }
 
 function checkValidityStateObjectAliveWithoutElement(element)
 {
   // We are creating a temporary element and getting it's ValidityState object.
   // Then, we make sure it is removed by the garbage collector and we check the
   // ValidityState default values (it should not crash).
 
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   var v = document.createElement(element).validity;
-  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-    getInterface(Components.interfaces.nsIDOMWindowUtils).garbageCollect();
+  SpecialPowers.gc();
 
   ok(!v.valueMissing,
     "When the element is not alive, it shouldn't suffer from constraint validation");
   ok(!v.typeMismatch,
     "When the element is not alive, it shouldn't suffer from constraint validation");
   ok(!v.patternMismatch,
     "When the element is not alive, it shouldn't suffer from constraint validation");
   ok(!v.tooLong,
--- a/content/html/content/test/test_bug209275.xhtml
+++ b/content/html/content/test/test_bug209275.xhtml
@@ -72,19 +72,17 @@ function link123HrefIs(href, testNum) {
   is($('link1').href, href, "link1 test " + testNum);
   is($('link2').href, href, "link2 test " + testNum);
   is($('link3').href, href, "link3 test " + testNum);
 }
 
 var gGen;
 
 function visitedDependentComputedStyle(win, elem, property) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                getInterface(Components.interfaces.nsIDOMWindowUtils);
+  var utils = SpecialPowers.getDOMWindowUtils(window);
   return utils.getVisitedDependentComputedStyle(elem, "", property);
 }
 
 function getColor(elem) {
   return visitedDependentComputedStyle(document.defaultView, elem, "color");
 }
 
 function getFill(elem) {
--- a/content/html/content/test/test_bug406596.html
+++ b/content/html/content/test/test_bug406596.html
@@ -20,19 +20,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   <div tabindex="0">This text is not editable but is focusable</div>
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 406596 **/
 
 function testTabbing(click, focus, selectionOffset) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var wu =  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                  .getInterface(Components.interfaces.nsIDOMWindowUtils);
+  var wu = SpecialPowers.getDOMWindowUtils(window);
 
   var elem = document.getElementById(click);
   var rect = elem.getBoundingClientRect();
   var selection = window.getSelection();
 
   var x = (rect.left + rect.right) / 4;
   var y = (rect.top + rect.bottom) / 2;
   wu.sendMouseEvent("mousedown", x, y, 0, 1, 0);
--- a/content/html/content/test/test_bug421640.html
+++ b/content/html/content/test/test_bug421640.html
@@ -16,19 +16,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   <div><button id="button">Test</button></div> 
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 421640 **/
 
 function test(click, focus, nextFocus) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var wu =  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                  .getInterface(Components.interfaces.nsIDOMWindowUtils);
+  var wu = SpecialPowers.getDOMWindowUtils(window);
 
   var selection = window.getSelection();
   var edit = document.getElementById("edit");
   var text = edit.firstChild;
 
   selection.removeAllRanges();
 
   var rect = edit.getBoundingClientRect();
--- a/content/html/content/test/test_bug460568.html
+++ b/content/html/content/test/test_bug460568.html
@@ -31,25 +31,24 @@ function runTest()
 
   function isReallyEditable()
   {
     editor.focus();
     var range = document.createRange();
     range.selectNodeContents(editor);
     var prevStr = range.toString();
 
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-    var docShell =
-      window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-            .getInterface(Components.interfaces.nsIWebNavigation)
-            .QueryInterface(Components.interfaces.nsIDocShell);
+    var docShell = SpecialPowers.wrap(window)
+            .QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
+            .getInterface(SpecialPowers.Ci.nsIWebNavigation)
+            .QueryInterface(SpecialPowers.Ci.nsIDocShell);
     var controller =
-          docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                  .getInterface(Components.interfaces.nsISelectionDisplay)
-                  .QueryInterface(Components.interfaces.nsISelectionController);
+          docShell.QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
+                  .getInterface(SpecialPowers.Ci.nsISelectionDisplay)
+                  .QueryInterface(SpecialPowers.Ci.nsISelectionController);
     var sel = controller.getSelection(controller.SELECTION_NORMAL);
     sel.collapse(anchorInEditor, 0);
     synthesizeKey('a', {});
     range.selectNodeContents(editor);
     return prevStr != range.toString();
   }
 
   focused = false;
--- a/content/html/content/test/test_bug481335.xhtml
+++ b/content/html/content/test/test_bug481335.xhtml
@@ -46,20 +46,17 @@ let tests = testIterator();
 function continueTest() {
   tests.next();
 }
 
 function checkLinkColor(aElmId, aExpectedColor, aMessage) {
   // Because link coloring is asynchronous, we wait until we get the right
   // result, or we will time out (resulting in a failure).
   function getColor() {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    var utils = document.defaultView.
-                  QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                  getInterface(Components.interfaces.nsIDOMWindowUtils);
+    var utils = SpecialPowers.getDOMWindowUtils(window);
     return utils.getVisitedDependentComputedStyle($(aElmId), "", "color");
   }
   while (getColor() != aExpectedColor) {
     setTimeout(continueTest, 0);
     return false;
   }
   is(getColor(), aExpectedColor, aMessage);
   return true;
--- a/content/html/content/test/test_formSubmission2.html
+++ b/content/html/content/test/test_formSubmission2.html
@@ -147,20 +147,17 @@ function checkSubmission(sub, expected) 
 
 function clickImage(aTarget, aX, aY)
 {
   aTarget.style.position = "absolute";
   aTarget.style.top = "0";
   aTarget.style.left = "0";
   aTarget.offsetTop;
 
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var wu = aTarget.ownerDocument.defaultView
-    .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-    .getInterface(Components.interfaces.nsIDOMWindowUtils);
+  var wu = SpecialPowers.getDOMWindowUtils(aTarget.ownerDocument.defaultView);
 
   wu.sendMouseEvent('mousedown',  aX, aY, 0, 1, 0);
   wu.sendMouseEvent('mouseup',  aX, aY, 0, 0, 0);
 
   aTarget.style.position = "";
   aTarget.style.top = "";
   aTarget.style.left = "";
 }
--- a/content/html/document/test/test_bug446483.html
+++ b/content/html/document/test/test_bug446483.html
@@ -15,20 +15,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 446483 **/
 
 function gc() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-        .getInterface(Components.interfaces.nsIDOMWindowUtils)
-        .garbageCollect();
+  SpecialPowers.gc();
 }
 
 function runTest() {
   document.getElementById('display').innerHTML =
     '<iframe src="bug446483-iframe.html"><\/iframe>\n' +
     '<iframe src="bug446483-iframe.html"><\/iframe>\n';
 
   setInterval(gc, 1000);
--- a/content/html/document/test/test_viewport.html
+++ b/content/html/document/test/test_viewport.html
@@ -22,20 +22,17 @@ href="https://bugzilla.mozilla.org/show_
 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"));