Bug 778420 - Initial stab at the tests. v2 r=bholley
authorWilliam Chen <wchen@mozilla.com>
Mon, 06 Aug 2012 22:15:49 +0200
changeset 101897 9772a4983ec952277190cac4a5ea7b3268111745
parent 101896 2d2fc75725d8653420ed4a9c550ebbdefd8b6ba5
child 101898 fb0d1d0a683763cbce3fad6a312684cefbf6f058
push id23255
push useremorley@mozilla.com
push dateThu, 09 Aug 2012 11:48:03 +0000
treeherdermozilla-central@9249f0c9ca93 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs778420
milestone17.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 778420 - Initial stab at the tests. v2 r=bholley
browser/base/content/test/test_offlineNotification.html
browser/base/content/test/test_offline_gzip.html
browser/components/feeds/test/test_bug589543.html
content/base/test/test_bug380418.html
content/html/content/test/test_bug523771.html
content/html/document/test/test_bug445004.html
content/html/document/test/test_bug512367.html
dom/tests/mochitest/bugs/test_bug369306.html
dom/tests/mochitest/whatwg/test_bug500328.html
editor/composer/test/test_bug519928.html
editor/libeditor/html/tests/test_bug432225.html
editor/libeditor/html/tests/test_bug468353.html
editor/libeditor/html/tests/test_bug478725.html
editor/libeditor/html/tests/test_bug480972.html
editor/libeditor/html/tests/test_bug520189.html
editor/libeditor/html/tests/test_bug525389.html
editor/libeditor/html/tests/test_root_element_replacement.html
layout/base/tests/test_bug449781.html
--- a/browser/base/content/test/test_offlineNotification.html
+++ b/browser/base/content/test/test_offlineNotification.html
@@ -21,36 +21,36 @@ https://bugzilla.mozilla.org/show_bug.cg
 <iframe id="eventsTestFrame" src="offlineEvent.html"></iframe>
 
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 SimpleTest.waitForExplicitFinish();
+const Cc = SpecialPowers.wrap(Components).classes;
 
 var numFinished = 0;
 
 window.addEventListener("message", function(event) {
     is(event.data, "success", "Child was successfully cached.");
 
     if (++numFinished == 3) {
       // Clean up after ourself
-      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-      var pm = Components.classes["@mozilla.org/permissionmanager;1"].
+      var pm = Cc["@mozilla.org/permissionmanager;1"].
                getService(Components.interfaces.nsIPermissionManager);
-      var ioService = Components.classes["@mozilla.org/network/io-service;1"]
+      var ioService = Cc["@mozilla.org/network/io-service;1"]
                         .getService(Components.interfaces.nsIIOService);
       var uri1 = ioService.newURI(frames.testFrame.location, null, null);
       var uri2 = ioService.newURI(frames.testFrame3.location, null, null);
 
-      var principal1 = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
+      var principal1 = Cc["@mozilla.org/scriptsecuritymanager;1"]
                         .getService(Components.interfaces.nsIScriptSecurityManager)
                         .getNoAppCodebasePrincipal(uri1);
-      var principal2 = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
+      var principal2 = Cc["@mozilla.org/scriptsecuritymanager;1"]
                         .getService(Components.interfaces.nsIScriptSecurityManager)
                         .getNoAppCodebasePrincipal(uri2);
 
       pm.removeFromPrincipal(principal1, "offline-app");
       pm.removeFromPrincipal(principal2, "offline-app");
 
       SimpleTest.finish();
     }
@@ -103,26 +103,25 @@ function testEventHandling() {
 }
 
 function loaded() {
   testEventHandling();
 
   // Click the notification bar's "Allow" button.  This should kick
   // off updates, which will eventually lead to getting messages from
   // the children.
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
+  var wm = SpecialPowers.wrap(Components).classes["@mozilla.org/appshell/window-mediator;1"].
            getService(Components.interfaces.nsIWindowMediator);
   var win = wm.getMostRecentWindow("navigator:browser");
   var notificationBox = win.gBrowser.getNotificationBox();
 
   var notification = notificationBox.getNotificationWithValue("offline-app-requested-mochi.test");
   notification.childNodes[0].click();
 
-  notification = notificationBox.getNotificationWithValue("offline-app-requested-example.com");
+  notification = SpecialPowers.wrap(notificationBox).getNotificationWithValue("offline-app-requested-example.com");
   notification.childNodes[0].click();
 }
 
 </script>
 </pre>
 </body>
 </html>
 
--- a/browser/base/content/test/test_offline_gzip.html
+++ b/browser/base/content/test/test_offline_gzip.html
@@ -27,25 +27,23 @@ cache, it can be fetched from the cache 
 var cacheCount = 0;
 var intervalID = 0;
 
 window.addEventListener("message", handleMessageEvents, false);
 SimpleTest.waitForExplicitFinish();
 
 function finishTest() {
   // Clean up after ourselves.
-  netscape.security.PrivilegeManager
-          .enablePrivilege("UniversalXPConnect");
-  var pm = Components.classes["@mozilla.org/permissionmanager;1"].
+  var Cc = SpecialPowers.wrap(Components).classes;
+  var pm = Cc["@mozilla.org/permissionmanager;1"].
            getService(Components.interfaces.nsIPermissionManager);
 
-  var uri = Components.classes["@mozilla.org/network/io-service;1"]
-              .getService(Components.interfaces.nsIIOService)
+  var uri = Cc["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService)
               .newURI(window.frames[0].location, null, null);
-  var principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
+  var principal = Cc["@mozilla.org/scriptsecuritymanager;1"]
                    .getService(Components.interfaces.nsIScriptSecurityManager)
                    .getNoAppCodebasePrincipal(uri);
 
   pm.removeFromPrincipal(principal, "offline-app");
 
   window.removeEventListener("message", handleMessageEvents, false);
 
   SimpleTest.finish();  
@@ -65,18 +63,16 @@ function handleMessageEvents(event) {
       // in the case of bug 501422.
       frames.testFrame.window.location.reload();
       // Use setInterval to repeatedly call a function which
       // checks that one of two things has occurred:  either
       // the offline cache is udpated (which means our iframe
       // successfully reloaded), or the string "error" appears
       // in the iframe, as in the case of bug 501422.
       intervalID = setInterval(function() {
-        netscape.security.PrivilegeManager
-                .enablePrivilege("UniversalXPConnect");
         // Sometimes document.body may not exist, and trying to access
         // it will throw an exception, so handle this case.
         try {
           var bodyInnerHTML = frames.testFrame.document.body.innerHTML;
         }
         catch (e) {
           var bodyInnerHTML = "";
         }
@@ -98,18 +94,17 @@ function handleMessageEvents(event) {
       ok(false, "cacheCount not 1 or 2");
   }
 }
 
 function loaded() {
   // Click the notification bar's "Allow" button.  This should kick
   // off updates, which will eventually lead to getting messages from
   // the iframe.
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
+  var wm = SpecialPowers.wrap(Components).classes["@mozilla.org/appshell/window-mediator;1"].
            getService(Components.interfaces.nsIWindowMediator);
   var win = wm.getMostRecentWindow("navigator:browser");
   var notificationBox = win.gBrowser.getNotificationBox();
 
   var notification = notificationBox
     .getNotificationWithValue("offline-app-requested-mochi.test");
   notification.childNodes[0].click();
 }
--- a/browser/components/feeds/test/test_bug589543.html
+++ b/browser/components/feeds/test/test_bug589543.html
@@ -15,18 +15,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 589543 **/
 SimpleTest.waitForExplicitFinish();
 
 addLoadEvent(function() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var doc = $("testFrame").contentDocument;
+  var doc = SpecialPowers.wrap($("testFrame").contentDocument);
   var daddy = doc.getElementById("feedSubscribeLine");
   var popup = doc.getAnonymousElementByAttribute(daddy, "anonid", "handlersMenuPopup");
   isnot(popup, null, "Feed preview should have a handlers popup");
 });
 addLoadEvent(SimpleTest.finish);
 
 </script>
 </pre>
--- a/content/base/test/test_bug380418.html
+++ b/content/base/test/test_bug380418.html
@@ -17,24 +17,23 @@
 
 	SimpleTest.waitForExplicitFinish();
 	
 	var request = new XMLHttpRequest();
 	request.open("GET", window.location.href, false);
 	request.send(null);
 	
 	// Try reading headers in privileged context
-	netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-	is(request.getResponseHeader("Set-Cookie"), "test", "Reading Set-Cookie response header in privileged context");
-	is(request.getResponseHeader("Set-Cookie2"), "test2", "Reading Set-Cookie2 response header in privileged context");
-	is(request.getResponseHeader("X-Dummy"), "test", "Reading X-Dummy response header in privileged context");
+	is(SpecialPowers.wrap(request).getResponseHeader("Set-Cookie"), "test", "Reading Set-Cookie response header in privileged context");
+	is(SpecialPowers.wrap(request).getResponseHeader("Set-Cookie2"), "test2", "Reading Set-Cookie2 response header in privileged context");
+	is(SpecialPowers.wrap(request).getResponseHeader("X-Dummy"), "test", "Reading X-Dummy response header in privileged context");
 	
-	ok(/\bSet-Cookie:/i.test(request.getAllResponseHeaders()), "Looking for Set-Cookie in all response headers in privileged context");
-	ok(/\bSet-Cookie2:/i.test(request.getAllResponseHeaders()), "Looking for Set-Cookie2 in all response headers in privileged context");
-	ok(/\bX-Dummy:/i.test(request.getAllResponseHeaders()), "Looking for X-Dummy in all response headers in privileged context");
+	ok(/\bSet-Cookie:/i.test(SpecialPowers.wrap(request).getAllResponseHeaders()), "Looking for Set-Cookie in all response headers in privileged context");
+	ok(/\bSet-Cookie2:/i.test(SpecialPowers.wrap(request).getAllResponseHeaders()), "Looking for Set-Cookie2 in all response headers in privileged context");
+	ok(/\bX-Dummy:/i.test(SpecialPowers.wrap(request).getAllResponseHeaders()), "Looking for X-Dummy in all response headers in privileged context");
 	
 	// Try reading headers in unprivileged context
 	setTimeout(function() {
 	  is(request.getResponseHeader("Set-Cookie"), null, "Reading Set-Cookie response header in unprivileged context");
 	  is(request.getResponseHeader("Set-Cookie2"), null, "Reading Set-Cookie2 response header in unprivileged context");
 	  is(request.getResponseHeader("X-Dummy"), "test", "Reading X-Dummy response header in unprivileged context");
 	  
 	  ok(!/\bSet-Cookie:/i.test(request.getAllResponseHeaders()), "Looking for Set-Cookie in all response headers in unprivileged context");
--- a/content/html/content/test/test_bug523771.html
+++ b/content/html/content/test/test_bug523771.html
@@ -27,36 +27,35 @@ var input2Files =
   [{ name: "523771_file2", type: "", body: "second file contents" },
    { name: "523771_file3.txt", type: "text/plain", body: "123456" },
    { name: "523771_file4.html", type: "text/html", body: "<html>content</html>" }
   ];
 
 SimpleTest.waitForExplicitFinish();
 
 function setFileInputs () {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   f = createFileWithData(input1File.name, input1File.body);
-  singleFileInput.mozSetFileNameArray([f.path], 1);
+  SpecialPowers.wrap(singleFileInput).mozSetFileNameArray([f.path], 1);
 
   var input2FileNames = [];
   for each (file in input2Files) {
     f = createFileWithData(file.name, file.body);
     input2FileNames.push(f.path);
   }
-  multiFileInput.mozSetFileNameArray(input2FileNames, input2FileNames.length);
+  SpecialPowers.wrap(multiFileInput).mozSetFileNameArray(input2FileNames, input2FileNames.length);
 }
 
 function createFileWithData(fileName, fileData) {
-  var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
-                         .getService(Components.interfaces.nsIProperties);
+  var dirSvc = SpecialPowers.wrap(Components).classes["@mozilla.org/file/directory_service;1"]
+                            .getService(Components.interfaces.nsIProperties);
   var testFile = dirSvc.get("ProfD", Components.interfaces.nsIFile);
   testFile.append(fileName);
-  var outStream = Components.
-                  classes["@mozilla.org/network/file-output-stream;1"].
-                  createInstance(Components.interfaces.nsIFileOutputStream);
+  var outStream = SpecialPowers.wrap(Components).
+                    classes["@mozilla.org/network/file-output-stream;1"].
+                    createInstance(Components.interfaces.nsIFileOutputStream);
   outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
                  0666, 0);
   outStream.write(fileData, fileData.length);
   outStream.close();
 
   filesToKill.push(testFile);
 
   return testFile;
--- a/content/html/document/test/test_bug445004.html
+++ b/content/html/document/test/test_bug445004.html
@@ -50,19 +50,17 @@ function checkURI(uri, name, type) {
   var host = uri.match(/^http:\/\/([a-z.0-9]*)/)[1];
   var file = uri.match(/([^\/]*).png$/)[1];
   is(host, file, "Unexpected base URI for test " + name +
      " when testing " + type);
 }
 
 function checkFrame(num) {
   // Just snarf our data
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
-  var outer = window.frames[num]
+  var outer = SpecialPowers.wrap(window.frames[num]);
   name = outer.name;
 
   is(outer.document.baseURI,
      "http://example.org/tests/content/html/document/test/bug445004-outer.html",
      "Unexpected base URI for " + name);
 
   var iswrite = name.match(/write/);
 
--- a/content/html/document/test/test_bug512367.html
+++ b/content/html/document/test/test_bug512367.html
@@ -19,31 +19,29 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 var frame = document.getElementById("i");
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(function() {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   var viewer =
-    frame.contentWindow
-         .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-         .getInterface(Components.interfaces.nsIWebNavigation)
-         .QueryInterface(Components.interfaces.nsIDocShell)
-         .contentViewer
-         .QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
+    SpecialPowers.wrap(frame.contentWindow
+                 .QueryInterface(Components.interfaces.nsIInterfaceRequestor))
+                 .getInterface(Components.interfaces.nsIWebNavigation)
+                 .QueryInterface(Components.interfaces.nsIDocShell)
+                 .contentViewer
+                 .QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
 
   viewer.fullZoom = 1.5;
 
   setTimeout(function() {
     synthesizeMouse(frame, 30, 30, {});
 
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
     is(viewer.fullZoom, 1.5, "Zoom in the image frame should not have been reset");
 
     SimpleTest.finish();
   }, 0);
 });
 </script>
 </pre>
 </body>
--- a/dom/tests/mochitest/bugs/test_bug369306.html
+++ b/dom/tests/mochitest/bugs/test_bug369306.html
@@ -111,40 +111,37 @@ function test5()
       }, w, true);
 
       w.focus();
     }, originatingWindow);
 
     SimpleTest.executeSoon(function() {
       // We have to focus back the originating window but we can't do that with
       // .focus() or .blur() anymore.
-      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-      var fm = Components.classes["@mozilla.org/focus-manager;1"].
-                          getService(Components.interfaces.nsIFocusManager);
+      var fm = SpecialPowers.wrap(Components).classes["@mozilla.org/focus-manager;1"]
+                            .getService(Components.interfaces.nsIFocusManager);
       fm.focusedWindow = window;
     });
   }, w, true);
 }
 
 function finished()
 {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  Components.classes["@mozilla.org/preferences-service;1"]
-            .getService(Components.interfaces.nsIPrefBranch)
-            .setBoolPref("dom.disable_window_flip", gOldPrefValue);
+  SpecialPowers.wrap(Components).classes["@mozilla.org/preferences-service;1"]
+               .getService(Components.interfaces.nsIPrefBranch)
+               .setBoolPref("dom.disable_window_flip", gOldPrefValue);
   SimpleTest.finish();
 }
 
 SimpleTest.waitForExplicitFinish();
 
 
 // dom.disable_window_flip has to be set to true for this test.
-netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-var prefs = Components.classes["@mozilla.org/preferences-service;1"]
-                      .getService(Components.interfaces.nsIPrefBranch);
+var prefs = SpecialPowers.wrap(Components).classes["@mozilla.org/preferences-service;1"]
+                         .getService(Components.interfaces.nsIPrefBranch);
 gOldPrefValue = prefs.getBoolPref("dom.disable_window_flip");
 prefs.setBoolPref("dom.disable_window_flip", true);
 
 // test1 is going to call the next tests.
 SimpleTest.waitForFocus(test1);
 
 </script>
 </pre>
--- a/dom/tests/mochitest/whatwg/test_bug500328.html
+++ b/dom/tests/mochitest/whatwg/test_bug500328.html
@@ -148,41 +148,36 @@ function noPopStateExpected(msg) {
 }
 
 function popstateExpected(msg) {
   is(gNumPopStates, 1, msg);
   gNumPopStates = 0;
 }
 
 function getColor(elem) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var utils = document.defaultView.
+  var utils = SpecialPowers.wrap(document).defaultView.
                 QueryInterface(Components.interfaces.nsIInterfaceRequestor).
                 getInterface(Components.interfaces.nsIDOMWindowUtils);
   return utils.getVisitedDependentComputedStyle(elem, "", "color");
 }
 
 function getSHistory(theWindow)
 {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
   const Ci = Components.interfaces;
-  var sh = theWindow.QueryInterface(Ci.nsIInterfaceRequestor)
-                    .getInterface(Ci.nsIWebNavigation)
-                    .sessionHistory;
+  var sh = SpecialPowers.wrap(theWindow.QueryInterface(Ci.nsIInterfaceRequestor))
+                        .getInterface(Ci.nsIWebNavigation)
+                        .sessionHistory;
   if (!sh || sh == null)
     throw("Couldn't get shistory for window!");
 
   return sh;
 }
 
 function getSHTitle(sh, offset)
 {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
   if (!offset)
     offset = 0;
 
   // False instructs the SHistory not to modify its current index.
   return sh.getEntryAtIndex(sh.index + offset, false).title;
 }
 
 // Tests that win's location ends with str
--- a/editor/composer/test/test_bug519928.html
+++ b/editor/composer/test/test_bug519928.html
@@ -17,21 +17,20 @@ https://bugzilla.mozilla.org/show_bug.cg
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 var iframe = document.getElementById("load-frame");
 
 function enableJS() allowJS(true, iframe);
 function disableJS() allowJS(false, iframe);
 function allowJS(allow, frame) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  frame.contentWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                     .getInterface(Components.interfaces.nsIWebNavigation)
-                     .QueryInterface(Components.interfaces.nsIDocShell)
-                     .allowJavascript = allow;
+  SpecialPowers.wrap(frame.contentWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor))
+               .getInterface(Components.interfaces.nsIWebNavigation)
+               .QueryInterface(Components.interfaces.nsIDocShell)
+               .allowJavascript = allow;
 }
 function expectJSAllowed(allowed, testCondition, callback) {
   window.ICanRunMyJS = false;
   var self_ = window;
   testCondition();
 
   var doc = iframe.contentDocument;
   doc.body.innerHTML = "<iframe></iframe>";
--- a/editor/libeditor/html/tests/test_bug432225.html
+++ b/editor/libeditor/html/tests/test_bug432225.html
@@ -31,32 +31,31 @@ function getEdit() {
 
 function editDoc() {
   return getEdit().contentDocument;
 }
 
 function getSpellCheckSelection() {
   var Ci = Components.interfaces;
   var win = editDoc().defaultView;
-  var editingSession = win.QueryInterface(Ci.nsIInterfaceRequestor)
-                          .getInterface(Ci.nsIWebNavigation)
-                          .QueryInterface(Ci.nsIInterfaceRequestor)
-                          .getInterface(Ci.nsIEditingSession);
+  var editingSession = SpecialPowers.wrap(win.QueryInterface(Ci.nsIInterfaceRequestor))
+                                    .getInterface(Ci.nsIWebNavigation)
+                                    .QueryInterface(Ci.nsIInterfaceRequestor)
+                                    .getInterface(Ci.nsIEditingSession);
   var editor = editingSession.getEditorForWindow(win);
   var selcon = editor.selectionController;
   return selcon.getSelection(selcon.SELECTION_SPELLCHECK);  
 }
 
 function runTest() {
   editDoc().designMode = "on";
   setTimeout(function() { addWords(100); }, 0);
 }  
  
 function addWords(aLimit) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   if (aLimit == 0) {
     is(isSpellingCheckOk(), true, "All misspellings accounted for.");
     SimpleTest.finish();
     return;
   }
   getEdit().focus();
   sendString('aa OK ');
   gMisspeltWords.push("aa");
--- a/editor/libeditor/html/tests/test_bug468353.html
+++ b/editor/libeditor/html/tests/test_bug468353.html
@@ -15,18 +15,16 @@ https://bugzilla.mozilla.org/show_bug.cg
   <iframe></iframe>
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 var styleSheets = null;
 
 function checkStylesheets() {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
   // Evidently RemoveStyleSheet is the only method in nsIEditorStyleSheets
   // that would throw. RemoveOverrideStyleSheet returns NS_OK even if the
   // sheet is not there
   var removed = 0;
   try
   {
     styleSheets.removeStyleSheet("resource://gre/res/designmode.css");
     removed++;
@@ -38,32 +36,30 @@ function checkStylesheets() {
     removed++;
   }
   catch (ex) { }
 
   is(removed, 0, "Should have thrown if stylesheet was not there");
 }
 
 function runTest() {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
   const Ci = Components.interfaces;
   const Cc = Components.classes;
 
   /** Found while fixing bug 440614 **/
   var editframe = window.frames[0];
   var editdoc = editframe.document;
   var editor = null;
   editdoc.write('');
   editdoc.close();
 
   editdoc.designMode='on';
 
   // Hold the reference to the editor
-  editor = editframe.QueryInterface(Ci.nsIInterfaceRequestor)
+  editor = SpecialPowers.wrap(editframe.QueryInterface(Ci.nsIInterfaceRequestor))
                         .getInterface(Ci.nsIWebNavigation)
                         .QueryInterface(Ci.nsIInterfaceRequestor)
                         .getInterface(Ci.nsIEditingSession)
                         .getEditorForWindow(editframe);
 
   styleSheets = editor.QueryInterface(Ci.nsIEditorStyleSheets);
 
   editdoc.designMode='off';
@@ -72,34 +68,34 @@ function runTest() {
   
   // Let go
   editor = null;
   styleSheets = null;
   
   editdoc.body.contentEditable = true;
   
   // Hold the reference to the editor
-  editor = editframe.QueryInterface(Ci.nsIInterfaceRequestor)
+  editor = SpecialPowers.wrap(editframe.QueryInterface(Ci.nsIInterfaceRequestor))
                         .getInterface(Ci.nsIWebNavigation)
                         .QueryInterface(Ci.nsIInterfaceRequestor)
                         .getInterface(Ci.nsIEditingSession)
                         .getEditorForWindow(editframe);
 
   styleSheets = editor.QueryInterface(Ci.nsIEditorStyleSheets);
   
   editdoc.body.contentEditable = false;
   
   checkStylesheets();
 
   editdoc.designMode = "on";
   editdoc.body.contentEditable = true;
   editdoc.designMode = "off";
 
   // Hold the reference to the editor
-  editor = editframe.QueryInterface(Ci.nsIInterfaceRequestor)
+  editor = SpecialPowers.wrap(editframe.QueryInterface(Ci.nsIInterfaceRequestor))
                         .getInterface(Ci.nsIWebNavigation)
                         .QueryInterface(Ci.nsIInterfaceRequestor)
                         .getInterface(Ci.nsIEditingSession)
                         .getEditorForWindow(editframe);
 
   styleSheets = editor.QueryInterface(Ci.nsIEditorStyleSheets);
 
   editdoc.body.contentEditable = false;
--- a/editor/libeditor/html/tests/test_bug478725.html
+++ b/editor/libeditor/html/tests/test_bug478725.html
@@ -3,18 +3,16 @@
 <title>Test for bug 478725</title>
 <style src="/tests/SimpleTest/test.css" type="text/css"></style>
 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
 
 <script class="testbody" type="application/javascript">
 
 function runTest() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
   function verifyContent(s) {
     var e = document.getElementById('i1');
     var doc = e.contentDocument;
     is(doc.body.innerHTML, s, "");
   }
 
   function pasteInto(html,target_id) {
     var e = document.getElementById('i1');
@@ -22,17 +20,17 @@ function runTest() {
     doc.designMode = "on";
     doc.body.innerHTML = html;
     e = doc.getElementById(target_id);
     doc.defaultView.focus();
     var selection = doc.defaultView.getSelection();
     selection.removeAllRanges();
     selection.selectAllChildren(e);
     selection.collapseToEnd();
-    doc.execCommand("paste", false, null);
+    SpecialPowers.wrap(doc).execCommand("paste", false, null);
    return e;
   }
 
   function copyToClipBoard(s,asHTML,target_id) {
     var e = document.getElementById('i2');
     var doc = e.contentDocument;
     if (asHTML) {
       doc.body.innerHTML = s;
@@ -46,17 +44,17 @@ function runTest() {
     selection.removeAllRanges();
     if (!target_id) {
       selection.selectAllChildren(doc.body);
     } else {
       var range = document.createRange();
       range.selectNode(doc.getElementById(target_id));
       selection.addRange(range);
     }
-    doc.execCommand("copy", false, null);
+    SpecialPowers.wrap(doc).execCommand("copy", false, null);
     return e;
   }
 
   copyToClipBoard("<dl><dd>Hello Kitty</dd></dl>", true);
   pasteInto('<ol><li id="paste_here">X</li></ol>',"paste_here");
   verifyContent('<ol><li id="paste_here">X<dl><dd>Hello Kitty</dd></dl></li></ol>');
 
   copyToClipBoard("<li>Hello Kitty</li>", true);
--- a/editor/libeditor/html/tests/test_bug480972.html
+++ b/editor/libeditor/html/tests/test_bug480972.html
@@ -3,18 +3,16 @@
 <title>Test for bug 480972</title>
 <style src="/tests/SimpleTest/test.css" type="text/css"></style>
 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
 
 <script class="testbody" type="application/javascript">
 
 function runTest() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
   function verifyContent(s) {
     var e = document.getElementById('i1');
     var doc = e.contentDocument;
     is(doc.body.innerHTML, s, "");
   }
 
   function pasteInto(html,target_id) {
     var e = document.getElementById('i1');
@@ -25,17 +23,17 @@ function runTest() {
     if (target_id)
       e = doc.getElementById(target_id);
     else
       e = doc.body;
     var selection = doc.defaultView.getSelection();
     selection.removeAllRanges();
     selection.selectAllChildren(e);
     selection.collapseToEnd();
-    doc.execCommand("paste", false, null);
+    SpecialPowers.wrap(doc).execCommand("paste", false, null);
    return e;
   }
 
   function copyToClipBoard(s,asHTML,target_id) {
     var e = document.getElementById('i2');
     var doc = e.contentDocument;
     if (asHTML) {
       doc.body.innerHTML = s;
@@ -49,17 +47,17 @@ function runTest() {
     selection.removeAllRanges();
     if (!target_id) {
       selection.selectAllChildren(doc.body);
     } else {
       var range = document.createRange();
       range.selectNode(doc.getElementById(target_id));
       selection.addRange(range);
     }
-    doc.execCommand("copy", false, null);
+    SpecialPowers.wrap(doc).execCommand("copy", false, null);
     return e;
   }
 
   copyToClipBoard('<span>Hello</span><span>Kitty</span>', true);
   pasteInto('');
   verifyContent('<span>Hello</span><span>Kitty</span>');
 
   copyToClipBoard("<dl><dd>Hello Kitty</dd></dl><span>Hello</span><span>Kitty</span>", true);
--- a/editor/libeditor/html/tests/test_bug520189.html
+++ b/editor/libeditor/html/tests/test_bug520189.html
@@ -558,43 +558,41 @@ function getLoadContext() {
 function runTest(test) {
   var elem = document.getElementById(test.id);
   if ("isIFrame" in test) {
     elem.contentDocument.designMode = "on";
     elem.contentWindow.focus();
   } else
     elem.focus();
 
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
-  var trans = Components.classes["@mozilla.org/widget/transferable;1"]
-                        .createInstance(Components.interfaces.nsITransferable);
+  var trans = SpecialPowers.wrap(Components).classes["@mozilla.org/widget/transferable;1"]
+                           .createInstance(Components.interfaces.nsITransferable);
   trans.init(getLoadContext());
-  var data = Components.classes["@mozilla.org/supports-string;1"]
-                       .createInstance(Components.interfaces.nsISupportsString);
+  var data = SpecialPowers.wrap(Components).classes["@mozilla.org/supports-string;1"]
+                          .createInstance(Components.interfaces.nsISupportsString);
   data.data = test.payload;
   trans.addDataFlavor("text/html");
   trans.setTransferData("text/html", data, data.data.length * 2);
 
   if ("indirectPaste" in test) {
     var editor, win;
     if ("isIFrame" in test) {
       win = elem.contentDocument.defaultView;
     } else {
       getSelection().collapse(elem, 0);
       win = window;
     }
-    editor = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                .getInterface(Components.interfaces.nsIWebNavigation)
-                .QueryInterface(Components.interfaces.nsIEditorDocShell)
-                .editor;
+    editor = SpecialPowers.wrap(win).QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+                          .getInterface(Components.interfaces.nsIWebNavigation)
+                          .QueryInterface(Components.interfaces.nsIEditorDocShell)
+                          .editor;
     editor.pasteTransferable(trans);
   } else {
-    var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"]
-                              .getService(Components.interfaces.nsIClipboard);
+    var clipboard = SpecialPowers.wrap(Components).classes["@mozilla.org/widget/clipboard;1"]
+                                 .getService(Components.interfaces.nsIClipboard);
 
     clipboard.setData(trans, null, Components.interfaces.nsIClipboard.kGlobalClipboard);
 
     synthesizeKey("V", {accelKey: true});
   }
 
   if ("checkResult" in test) {
     if ("isIFrame" in test) {
--- a/editor/libeditor/html/tests/test_bug525389.html
+++ b/editor/libeditor/html/tests/test_bug525389.html
@@ -2,39 +2,39 @@
 <html><head>
 <title>Test for bug 525389</title>
 <style src="/tests/SimpleTest/test.css" type="text/css"></style>
 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
 <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
 
 <script class="testbody" type="application/javascript">
 
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils);
-  var Cc = Components.classes;
+  var utils = SpecialPowers.wrap(window)
+                .QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils);
+  var Cc = SpecialPowers.wrap(Components).classes;
   var Ci = Components.interfaces;
 
 function getLoadContext() {
-  return window.QueryInterface(Ci.nsIInterfaceRequestor)
+  return SpecialPowers.wrap(window)
+               .QueryInterface(Ci.nsIInterfaceRequestor)
                .getInterface(Ci.nsIWebNavigation)
                .QueryInterface(Ci.nsILoadContext);
 }
 
 function runTest() {
   var pasteCount = 0;
   var pasteFunc = function (event) { pasteCount++; };
 
   function verifyContent(s) {
     var e = document.getElementById('i1');
     var doc = e.contentDocument;
     is(doc.body.innerHTML, s, "");
   }
 
   function pasteInto(trans, html, target_id) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
     var e = document.getElementById('i1');
     var doc = e.contentDocument;
     doc.designMode = "on";
     doc.body.innerHTML = html;
     doc.defaultView.focus();
     if (target_id)
       e = doc.getElementById(target_id);
     else
@@ -48,32 +48,29 @@ function runTest() {
     e.addEventListener("paste", pasteFunc, false);
     utils.sendContentCommandEvent("pasteTransferable", trans);
     e.removeEventListener("paste", pasteFunc, false);
 
     return e;
   }
 
   function getTransferableFromClipboard(asHTML) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
     var trans = Cc["@mozilla.org/widget/transferable;1"].createInstance(Ci.nsITransferable);
     trans.init(getLoadContext());
     if (asHTML) {
       trans.addDataFlavor("text/html");
     } else {
       trans.addDataFlavor("text/unicode");
     }    
     var clip = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard);
     clip.getData(trans, Ci.nsIClipboard.kGlobalClipboard);
     return trans;
   }
 
   function makeTransferable(s,asHTML,target_id) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-
     var e = document.getElementById('i2');
     var doc = e.contentDocument;
     if (asHTML) {
       doc.body.innerHTML = s;
     } else {
       var text = doc.createTextNode(s);
       doc.body.appendChild(text);
     }
@@ -107,17 +104,16 @@ function runTest() {
       ssData.data = doc.body.innerHTML;
       trans.setTransferData("text/unicode", ssData, ssData.length * 2);
     }
 
     return trans;
   }
 
   function copyToClipBoard(s,asHTML,target_id) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
     var e = document.getElementById('i2');
     var doc = e.contentDocument;
     if (asHTML) {
       doc.body.innerHTML = s;
     } else {
       var text = doc.createTextNode(s);
       doc.body.appendChild(text);
     }
@@ -127,17 +123,17 @@ function runTest() {
     selection.removeAllRanges();
     if (!target_id) {
       selection.selectAllChildren(doc.body);
     } else {
       var range = document.createRange();
       range.selectNode(doc.getElementById(target_id));
       selection.addRange(range);
     }
-    doc.execCommand("copy", false, null);
+    SpecialPowers.wrap(doc).execCommand("copy", false, null);
     return e;
   }
 
   copyToClipBoard('<span>Hello</span><span>Kitty</span>', true);
   var trans = getTransferableFromClipboard(true);
   pasteInto(trans, '');
   verifyContent('<span>Hello</span><span>Kitty</span>');
   is(pasteCount, 1, "paste event was not triggered");
--- a/editor/libeditor/html/tests/test_root_element_replacement.html
+++ b/editor/libeditor/html/tests/test_root_element_replacement.html
@@ -17,18 +17,16 @@
 <pre id="test">
 </pre>
 
 <script class="testbody" type="application/javascript">
 
 SimpleTest.waitForExplicitFinish();
 SimpleTest.waitForFocus(runTest);
 
-netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
 function runDesignModeTest(aDoc, aFocus, aNewSource)
 {
   aDoc.designMode = "on";
 
   if (aFocus) {
     aDoc.documentElement.focus();
   }
 
@@ -78,21 +76,19 @@ const kTests = [
     args: [ "<body contenteditable='true' id='focus'></body>" ] },
 ];
 
 var gIFrame;
 var gSetFocusToIFrame = false;
 
 function onLoadIFrame()
 {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
   var frameDoc = gIFrame.contentWindow.document;
 
-  var selCon = gIFrame.contentWindow.
+  var selCon = SpecialPowers.wrap(gIFrame).contentWindow.
     QueryInterface(Components.interfaces.nsIInterfaceRequestor).
     getInterface(Components.interfaces.nsIWebNavigation).
     QueryInterface(Components.interfaces.nsIInterfaceRequestor).
     getInterface(Components.interfaces.nsISelectionDisplay).
     QueryInterface(Components.interfaces.nsISelectionController);
   var utils = window.
     QueryInterface(Components.interfaces.nsIInterfaceRequestor).
     getInterface(Components.interfaces.nsIDOMWindowUtils);
--- a/layout/base/tests/test_bug449781.html
+++ b/layout/base/tests/test_bug449781.html
@@ -31,19 +31,18 @@ addLoadEvent(function() {
 
   s2 = snapshotWindow(window);
 
   var equal, str1, str2;
   [equal, str1, str2] = compareSnapshots(s1, s2, true);
   ok(equal, "Show/hide should have no effect",
      "got " + str1 + " but expected " + str2);
 
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   var viewer =
-    $("ourFrame").contentWindow
+    SpecialPowers.wrap($("ourFrame")).contentWindow
                  .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                  .getInterface(Components.interfaces.nsIWebNavigation)
                  .QueryInterface(Components.interfaces.nsIDocShell)
                  .contentViewer
                  .QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);
   viewer.fullZoom = 2;
   
   s3 = snapshotWindow(window);