Bug 784560 - Fix more tests. r=mccr8
authorBobby Holley <bobbyholley@gmail.com>
Thu, 23 Aug 2012 11:45:28 -0700
changeset 105234 e5fc65cdf0d470f6b26b1914b6bc65684d1c35da
parent 105233 a24e5db2886ddcb021dd8e5ae1ea2d8758aa26df
child 105235 9ecd49f138f0ecb9f5b15f13c76792092d7077cb
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewersmccr8
bugs784560
milestone17.0a1
Bug 784560 - Fix more tests. r=mccr8
browser/base/content/test/test_contextmenu.html
content/base/test/test_bug333198.html
content/events/test/test_bug226361.xhtml
content/events/test/test_bug493251.html
content/events/test/test_bug545268.html
content/events/test/test_bug574663.html
content/events/test/test_bug593959.html
docshell/test/navigation/NavigationUtils.js
docshell/test/test_bug511449.html
layout/generic/test/test_bug391747.html
toolkit/components/places/tests/mochitest/test_bug_461710.html
toolkit/components/prompts/test/prompt_common.js
toolkit/components/prompts/test/test_bug620145.html
toolkit/components/satchel/test/satchel_common.js
toolkit/components/satchel/test/test_bug_511615.html
uriloader/exthandler/tests/mochitest/handlerApps.js
widget/tests/test_bug760802.html
--- a/browser/base/content/test/test_contextmenu.html
+++ b/browser/base/content/test/test_contextmenu.html
@@ -47,23 +47,23 @@ function openContextMenuFor(element, shi
 function closeContextMenu() {
     contextMenu.hidePopup();
 }
 
 function executeCopyCommand(command, expectedValue)
 {
   // Just execute the command directly rather than simulating a context menu
   // press to avoid having to deal with its asynchronous nature
-  subwindow.controllers.getControllerForCommand(command).doCommand(command);
+  SpecialPowers.wrap(subwindow).controllers.getControllerForCommand(command).doCommand(command);
 
   // The easiest way to check the clipboard is to paste the contents into a
   // textbox
   input.focus();
   input.value = "";
-  input.controllers.getControllerForCommand("cmd_paste").doCommand("cmd_paste");
+  SpecialPowers.wrap(input).controllers.getControllerForCommand("cmd_paste").doCommand("cmd_paste");
   is(input.value, expectedValue, "paste for command " + command);
 }
 
 function invokeItemAction(generatedItemId)
 {
   var item = contextMenu.getElementsByAttribute("generateditemid",
                                                 generatedItemId)[0];
   ok(item, "Got generated XUL menu item");
@@ -245,17 +245,16 @@ function checkMenu(menu, expectedItems, 
  *
  * Called by a popupshowing event handler. Each test checks for expected menu
  * contents, closes the popup, and finally triggers the popup on a new element
  * (thus kicking off another cycle).
  *
  */
 function runTest(testNum) {
   // Seems we need to enable this again, or sendKeyEvent() complaints.
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   ok(true, "Starting test #" + testNum);
 
   var inspectItems = [];
   if (SpecialPowers.getBoolPref("devtools.inspector.enabled")) {
     inspectItems = ["---", null,
                     "context-inspect", true];
   }
 
--- a/content/base/test/test_bug333198.html
+++ b/content/base/test/test_bug333198.html
@@ -25,32 +25,25 @@ var focusTester;
 var focusTester2;
 var focusCount = 0;
 var eventCount = 0;
 function clickHandler() {
   ++eventCount;
 }
 
 function suppressEvents(suppress) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-        .getInterface(Components.interfaces.nsIDOMWindowUtils)
-        .suppressEventHandling(suppress);
+  SpecialPowers.DOMWindowUtils.suppressEventHandling(suppress);
 }
 
 function sendEvents() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  windowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                      .getInterface(Components.interfaces.nsIDOMWindowUtils);
+  windowUtils = SpecialPowers.getDOMWindowUtils(window);
   windowUtils.sendMouseEvent("mousedown", 1, 1, 0, 1, 0);
   windowUtils.sendMouseEvent("mouseup", 1, 1, 0, 1, 0);
 
-  iframeUtils = document.getElementById("ifr").contentWindow
-                        .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                        .getInterface(Components.interfaces.nsIDOMWindowUtils);
+  iframeUtils = SpecialPowers.getDOMWindowUtils(document.getElementById("ifr").contentWindow);
   iframeUtils.sendMouseEvent("mousedown", 1, 1, 0, 1, 0);
   iframeUtils.sendMouseEvent("mouseup", 1, 1, 0, 1, 0);
 }
 
 function runTest() {
   window.focus();
   focusTester = document.getElementsByTagName("input")[0];
   focusTester.blur();
--- a/content/events/test/test_bug226361.xhtml
+++ b/content/events/test/test_bug226361.xhtml
@@ -43,19 +43,17 @@ function setOrRestoreTabFocus(newValue) 
     prefs.setIntPref("tabfocus", newValue);
   }
 }
 
 // =================================
 
 var doc = document;
 function tab_to(id) {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var wu =  doc.defaultView.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                .getInterface(Components.interfaces.nsIDOMWindowUtils);
+  var wu = SpecialPowers.DOMWindowUtils;
   wu.sendKeyEvent('keypress',  9, 0, 0);
   is(doc.activeElement.id, id, "element with id=" + id + " should have focus");
 }
 
 function tab_iframe() {
   doc = document;
   tab_to('iframe');
 
--- a/content/events/test/test_bug493251.html
+++ b/content/events/test/test_bug493251.html
@@ -26,37 +26,31 @@ https://bugzilla.mozilla.org/show_bug.cg
   var mouseUp = 0;
   var mouseClick = 0;
 
   var keyDown = 0;
   var keyPress = 0;
   var keyUp = 0;
 
   function suppressEventHandling(aSuppress) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                    getInterface(Components.interfaces.nsIDOMWindowUtils);
+    var utils = SpecialPowers.getDOMWindowUtils(win);
     ok(true, "suppressEventHandling: aSuppress=" + aSuppress);
     utils.suppressEventHandling(aSuppress);
   }
 
   function dispatchKeyEvent(type) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                    getInterface(Components.interfaces.nsIDOMWindowUtils);
+    var utils = SpecialPowers.getDOMWindowUtils(win);
     ok(true, "Dipatching key event: type=" + type);
     utils.sendKeyEvent(type, 
                        Components.interfaces.nsIDOMKeyEvent.DOM_VK_A,
                        0, 0);
   }
 
   function dispatchMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                    getInterface(Components.interfaces.nsIDOMWindowUtils);
+    var utils = SpecialPowers.getDOMWindowUtils(win);
     ok(true, "Dipatching mouse event: aType=" + aType + ", aX=" + aX + ", aY" +
                aY + ", aButton=" + aButton + ", aClickCount=" + aClickCount +
                ", aModifiers=" + aModifiers);
     utils.sendMouseEvent(aType, aX, aY, aButton, aClickCount, aModifiers);
   }
 
   function dumpEvent(aEvent) {
     var detail = "target=" + aEvent.target + ", originalTarget=" +
@@ -83,18 +77,17 @@ https://bugzilla.mozilla.org/show_bug.cg
           ", shiftKey=" + (aEvent.shiftKey ? "PRESSED" : "no") +
           ", metaKey=" + (aEvent.metaKey ? "PRESSED" : "no") +
           ", button=" + aEvent.button +
           ", relatedTarget=" + aEvent.relatedTarget;
         break;
     }
     ok(true, aEvent.type + " event is handled: " + detail);
 
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    var fm = Components.classes["@mozilla.org/focus-manager;1"].
+    var fm = SpecialPowers.wrap(Components).classes["@mozilla.org/focus-manager;1"].
                         getService(Components.interfaces.nsIFocusManager);
     ok(true, "focused element is \"" + fm.focusedElement +
              "\" and focused window is \"" + fm.focusedWindow +
              "\" (the testing window is \"" + win + "\"");
   }
 
   function doTest() {
     win.document.getElementsByTagName("input")[0].focus();
--- a/content/events/test/test_bug545268.html
+++ b/content/events/test/test_bug545268.html
@@ -29,28 +29,24 @@ https://bugzilla.mozilla.org/show_bug.cg
   var mouseUp = 0;
   var mouseClick = 0;
 
   var keyDown = 0;
   var keyPress = 0;
   var keyUp = 0;
 
   function dispatchKeyEvent(type) {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    var utils = subwin.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                    getInterface(Components.interfaces.nsIDOMWindowUtils);
+    var utils = SpecialPowers.getDOMWindowUtils(subwin);
     utils.sendKeyEvent(type, 
                        Components.interfaces.nsIDOMKeyEvent.DOM_VK_A,
                        0, 0);
   }
 
   function doTest() {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                    getInterface(Components.interfaces.nsIDOMWindowUtils);
+    var utils = SpecialPowers.getDOMWindowUtils(win);
     var f = win.document.getElementById("f");
     subwin = f.contentWindow;
     subwin.document.getElementsByTagName("input")[0].focus();
     subwin.addEventListener("keydown", function(e) { ++keyDown; }, true);
     subwin.addEventListener("keypress", function(e) { ++keyPress; }, true);
     subwin.addEventListener("keyup", function(e) { ++keyUp; }, true);
     subwin.addEventListener("mousedown", function(e) { ++mouseDown; }, true);
     subwin.addEventListener("mouseup", function(e) { ++mouseUp; }, true);
@@ -76,34 +72,30 @@ https://bugzilla.mozilla.org/show_bug.cg
     is(keyDown, 1, "Wrong number events (7)");
     is(keyPress, 1, "Wrong number events (8)");
     is(keyUp, 1, "Wrong number events (9)");
 
     setTimeout(continueTest1, 0);
     }
 
   function continueTest1() {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                    getInterface(Components.interfaces.nsIDOMWindowUtils);
+    var utils = SpecialPowers.getDOMWindowUtils(win);
     dispatchKeyEvent("keydown");
     utils.suppressEventHandling(true);
     dispatchKeyEvent("keypress");
     dispatchKeyEvent("keyup");
     is(keyDown, 2, "Wrong number events (10)");
     is(keyPress, 1, "Wrong number events (11)");
     is(keyUp, 1, "Wrong number events (12)");
     utils.suppressEventHandling(false);
     setTimeout(continueTest2, 0);
   }
 
   function continueTest2() {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                    getInterface(Components.interfaces.nsIDOMWindowUtils);
+    var utils = SpecialPowers.getDOMWindowUtils(win);
     is(keyDown, 2, "Wrong number events (13)");
     is(keyPress, 2, "Wrong number events (14)");
     is(keyUp, 2, "Wrong number events (15)");
 
     utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
     utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
     is(mouseDown, 1, "Wrong number events (16)");
     is(mouseUp, 1, "Wrong number events (17)");
@@ -116,19 +108,17 @@ https://bugzilla.mozilla.org/show_bug.cg
     is(mouseDown, 1, "Wrong number events (19)");
     is(mouseUp, 1, "Wrong number events (20)");
     is(mouseClick, 1, "Wrong number events (21)");
 
     setTimeout(continueTest3, 0);
   }
 
   function continueTest3() {
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                    getInterface(Components.interfaces.nsIDOMWindowUtils);
+    var utils = SpecialPowers.getDOMWindowUtils(win);
     utils.sendMouseEvent("mousedown", 5, 5, 0, 1, 0);
     utils.suppressEventHandling(true);
     utils.sendMouseEvent("mouseup", 5, 5, 0, 1, 0);
     utils.suppressEventHandling(false);
     setTimeout(continueTest4, 1000);
   }
 
   function continueTest4() {
--- a/content/events/test/test_bug574663.html
+++ b/content/events/test/test_bug574663.html
@@ -39,19 +39,17 @@ function sendTouchpadScrollMotion(scroll
 
 function runTest() {
   var win = open('data:text/html,<!DOCTYPE html>\n' +
     '<div id="scrollbox" style="height: 100px; overflow: auto;">' +
     '  <div style="height: 1000px;"></div>' +
     '</div>', '_blank', 'width=300,height=300');
   SimpleTest.waitForFocus(function () {
     var scrollbox = win.document.getElementById("scrollbox");
-    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-    let winUtils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                      .getInterface(Components.interfaces.nsIDOMWindowUtils);
+    let winUtils = SpecialPowers.getDOMWindowUtils(win);
     let outstandingTests = [
       [false, false],
       [false, true],
       [true, false],
       [true, true],
     ];
     function nextTest() {
       netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
--- a/content/events/test/test_bug593959.html
+++ b/content/events/test/test_bug593959.html
@@ -21,30 +21,27 @@ https://bugzilla.mozilla.org/show_bug.cg
   
 </div>
 <pre id="test">
 <script type="application/javascript">
 
 /** Test for Bug 593959 **/
 
   function doTest() {
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-    var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                       .getInterface(Components.interfaces.nsIDOMWindowUtils);
+    var utils = SpecialPowers.getDOMWindowUtils(window);
     var e = document.createEvent("MouseEvent");
     e.initEvent("mousedown", false, false, window, 0, 1, 1, 1, 1,
                 false, false, false, false, 0, null);
     utils.dispatchDOMEventViaPresShell(document.body, e, true);
     
     is(document.querySelector("body:active"), document.body, "body should be active!")
     
     var ifrwindow = document.getElementById("ifr").contentWindow;
     
-    var utils2 = ifrwindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                          .getInterface(Components.interfaces.nsIDOMWindowUtils);
+    var utils2 = SpecialPowers.getDOMWindowUtils(ifrwindow);
    
     var e2 = ifrwindow.document.createEvent("MouseEvent");
     e2.initEvent("mouseup", false, false, ifrwindow, 0, 1, 1, 1, 1,
                  false, false, false, false, 0, null);
     utils2.dispatchDOMEventViaPresShell(ifrwindow.document.body, e2, true);
     
     isnot(document.querySelector("body:active"), document.body, "body shouldn't be active!")
 
--- a/docshell/test/navigation/NavigationUtils.js
+++ b/docshell/test/navigation/NavigationUtils.js
@@ -53,17 +53,17 @@ function navigateByHyperlink(name) {
 
 ///////////////////////////////////////////////////////////////////////////
 // Functions that call into Mochitest framework
 ///////////////////////////////////////////////////////////////////////////
 
 function isNavigated(wnd, message) {
   var result = null;
   try {
-    result = wnd.document.body.innerHTML;
+    result = SpecialPowers.wrap(wnd).document.body.innerHTML;
   } catch(ex) {
     result = ex;
   }
   is(result, body, message);
 }
 
 function isBlank(wnd, message) {
   var result = null;
@@ -104,26 +104,26 @@ function xpcEnumerateContentWindows(call
                         .classes["@mozilla.org/embedcomp/window-watcher;1"]
                         .getService(Ci.nsIWindowWatcher);
   var enumerator = ww.getWindowEnumerator();
 
   var contentWindows = [];
 
   while (enumerator.hasMoreElements()) {
     var win = enumerator.getNext();
-    if (typeof ChromeWindow != "undefined" && SpecialPowers.call_Instanceof(win, ChromeWindow)) {
+    if (/ChromeWindow/.exec(win)) {
       var docshellTreeNode = win.QueryInterface(Ci.nsIInterfaceRequestor)
                                 .getInterface(Ci.nsIWebNavigation)
                                 .QueryInterface(Ci.nsIDocShellTreeNode);
       var childCount = docshellTreeNode.childCount;
       for (var i = 0; i < childCount; ++i) {
         var childTreeNode = docshellTreeNode.getChildAt(i);
 
         // we're only interested in content docshells
-        if (childTreeNode.itemType != Ci.nsIDocShellTreeItem.typeContent)
+        if (SpecialPowers.unwrap(childTreeNode.itemType) != Ci.nsIDocShellTreeItem.typeContent)
           continue;
 
         var webNav = childTreeNode.QueryInterface(Ci.nsIWebNavigation);
         contentWindows.push(webNav.document.defaultView);
       }
     } else {
       contentWindows.push(win);
     }
--- a/docshell/test/test_bug511449.html
+++ b/docshell/test/test_bug511449.html
@@ -33,19 +33,17 @@ function runTest() {
   SimpleTest.waitForFocus(runNextTest, win);
 }
 
 function runNextTest() {
   var didClose = false;
   win.onunload = function() {
     didClose = true;
   }
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-  var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                  getInterface(Components.interfaces.nsIDOMWindowUtils);
+  var utils = SpecialPowers.getDOMWindowUtils(win);
   utils.sendNativeKeyEvent(0, MAC_VK_ANSI_W, 0x4000 /* cmd */, "w", "w");
 
   setTimeout(function () {
     ok(didClose, "Cmd+W should have closed the tab");
     if (!didClose) {
       win.close();
     }
     SimpleTest.finish();
--- a/layout/generic/test/test_bug391747.html
+++ b/layout/generic/test/test_bug391747.html
@@ -14,25 +14,22 @@ https://bugzilla.mozilla.org/show_bug.cg
 <p id="display"></p>
 <div id="content" style="display: block">
 <iframe id="iframe_391747" src="data:text/html,<table><tr><td style='width:500px;height:500px;border:1px solid blue'>x</td>"></iframe>
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 function ctrlclick_391747(doc,x,y){
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var wu =  doc.defaultView.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-               .getInterface(Components.interfaces.nsIDOMWindowUtils);
+  var wu =  SpecialPowers.getDOMWindowUtils(doc.defaultView);
   wu.sendMouseEvent('mousedown',  x, y, 0, 1, 2);
   wu.sendMouseEvent('mouseup',  x, y, 0, 1, 2);
 }
 
 function select_391747(doc){
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   var range = doc.createRange();
   range.setStart(doc, 0);
   range.setEnd(doc, 0);
   doc.defaultView.getSelection().addRange(range);
 }
 
 function boom_391747() {
   var target = document.getElementById('iframe_391747')
--- a/toolkit/components/places/tests/mochitest/test_bug_461710.html
+++ b/toolkit/components/places/tests/mochitest/test_bug_461710.html
@@ -12,25 +12,24 @@ https://bugzilla.mozilla.org/show_bug.cg
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=461710">Mozilla Bug 461710</a>
 <p id="display"></p>
 <iframe id="iframe"></iframe>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 461710 **/
 
-netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 SimpleTest.waitForExplicitFinish();
 
 const Ci = Components.interfaces;
-const Cc = Components.classes;
-const Cr = Components.results;
+const Cc = SpecialPowers.wrap(Components).classes;
+const Cr = SpecialPowers.wrap(Components).results;
 
-Components.utils.import("resource://gre/modules/NetUtil.jsm");
-Components.utils.import("resource://gre/modules/Services.jsm");
+SpecialPowers.wrap(Components).utils.import("resource://gre/modules/NetUtil.jsm", window);
+var Services = SpecialPowers.Services;
 
 var gIframe = document.getElementById("iframe");
 
 /**
  * Helper function which waits until another function returns true, and
  * then notifies a callback.
  *
  * Original function stolen from docshell/test/chrome/docshell_helpers.js.
@@ -68,18 +67,16 @@ var subtests = [
                    "visited_page.html",   // 1
                    "link_page.html",      // 2
                    "link_page-2.html",    // 3
                    "link_page-3.html"     // 4
                ];
 
 var testNum = 0;
 function loadNextTest() {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
   // run the initialization code for each test
   switch (++testNum) {
     case 1:
       // nothing to do here
       break;
 
     case 2:
       ok(!pb.privateBrowsingEnabled, "Test #" + testNum + " should be run outside of private mode");
@@ -110,19 +107,17 @@ function loadNextTest() {
     SimpleTest.executeSoon(handleLoad);
   });
 
   gIframe.src = prefix + subtests[testNum-1];
 }
 
 function getColor(doc, win, id) {
   var elem = doc.getElementById(id);
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var utils = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                getInterface(Components.interfaces.nsIDOMWindowUtils);
+  var utils = SpecialPowers.getDOMWindowUtils(win);
   return utils.getVisitedDependentComputedStyle(elem, "", "color");
 }
 
 function checkTest() {
   switch (testNum) {
     case 1:
       // nothing to do here, we just want to mark the page as visited
       break;
@@ -154,29 +149,26 @@ function checkTest() {
 }
 
 
 var _PBSvc = null;
 function get_PBSvc() {
   if (_PBSvc)
     return _PBSvc;
 
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   try {
     _PBSvc = Cc["@mozilla.org/privatebrowsing;1"].
              getService(Ci.nsIPrivateBrowsingService);
     return _PBSvc;
   } catch (e) {}
   return null;
 }
 
 
 function handleLoad() {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
   checkTest();
 
   if (testNum < subtests.length) {
     loadNextTest();
   } else {
     try {
       Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session");
     } catch(ex) {}
@@ -184,31 +176,28 @@ function handleLoad() {
   }
 }
 
 const URI_VISITED_RESOLUTION_TOPIC = "visited-status-resolution";
 var observer = {
   uri: null,
   resolved: true,
   observe: function (aSubject, aTopic, aData) {
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 
-    if (this.uri.equals(aSubject.QueryInterface(Ci.nsIURI))) {
+    if (this.uri.equals(SpecialPowers.wrap(aSubject).QueryInterface(Ci.nsIURI))) {
       this.resolved = true;
 
       Services.obs.removeObserver(this, aTopic);
     }
   },
   expectURL: function (url, aOverrideTopic) {
     ok(this.resolved, "Can't set the expected URL when another is yet to be resolved");
     this.resolved = false;
 
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
-    this.uri = NetUtil.newURI(url);
+    this.uri = SpecialPowers.wrap(NetUtil).newURI(url);
     var topic = aOverrideTopic || URI_VISITED_RESOLUTION_TOPIC;
     Services.obs.addObserver(this, topic, false);
   }
 };
 
 var pb = get_PBSvc();
 if (!pb) { // Private Browsing might not be available
   ok(true, "Private Browsing is not available");
--- a/toolkit/components/prompts/test/prompt_common.js
+++ b/toolkit/components/prompts/test/prompt_common.js
@@ -60,38 +60,38 @@ var observer = {
     }
 };
 
 function getTabModalPromptBox(domWin) {
     var promptBox = null;
 
     // Given a content DOM window, returns the chrome window it's in.
     function getChromeWindow(aWindow) {
-        var chromeWin = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+        var chromeWin = SpecialPowers.wrap(aWindow).QueryInterface(Ci.nsIInterfaceRequestor)
                                .getInterface(Ci.nsIWebNavigation)
                                .QueryInterface(Ci.nsIDocShell)
                                .chromeEventHandler.ownerDocument.defaultView;
-        return XPCNativeWrapper.unwrap(chromeWin);
+        return chromeWin;
     }
 
     try {
         // Get the topmost window, in case we're in a frame.
         var promptWin = domWin.top;
 
         // Get the chrome window for the content window we're using.
-        // (Unwrap because we need a non-IDL property below.)
         var chromeWin = getChromeWindow(promptWin);
 
         if (chromeWin.getTabModalPromptBox)
             promptBox = chromeWin.getTabModalPromptBox(promptWin);
     } catch (e) {
         // If any errors happen, just assume no tabmodal prompter.
     }
 
-    return promptBox;
+    // Callers get confused by a wrapped promptBox here.
+    return SpecialPowers.unwrap(promptBox);
 }
 
 function getDialogDoc() {
   // Trudge through all the open windows, until we find the one
   // that has either commonDialog.xul or selectDialog.xul loaded.
   var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
            getService(Ci.nsIWindowMediator);
   //var enumerator = wm.getEnumerator("navigator:browser");
--- a/toolkit/components/prompts/test/test_bug620145.html
+++ b/toolkit/components/prompts/test/test_bug620145.html
@@ -22,19 +22,17 @@
 </div>
 <button id="button" onmouseup="openAlert()">Button</button>
 
 <script class="testbody" type="text/javascript">
 SimpleTest.waitForExplicitFinish();
 
 var selectionTest = false;
 var testNum = 0;
-var utils = SpecialPowers.wrap(window)
-                        .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-                        .getInterface(Components.interfaces.nsIDOMWindowUtils);
+var utils = SpecialPowers.DOMWindowUtils;
 
 function hasTabModalPrompts() {
   var prefName = "prompts.tab_modal.enabled";
   var Services = SpecialPowers.wrap(Components).utils
                               .import("resource://gre/modules/Services.jsm")
                               .Services;
   return Services.prefs.getPrefType(prefName) == Services.prefs.PREF_BOOL &&
          Services.prefs.getBoolPref(prefName);
--- a/toolkit/components/satchel/test/satchel_common.js
+++ b/toolkit/components/satchel/test/satchel_common.js
@@ -1,16 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
- 
-netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 
-Components.utils.import("resource://gre/modules/Services.jsm");
-Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+var Services = SpecialPowers.Services;
 
 /*
  * $_
  *
  * Returns the element with the specified |name| attribute.
  */
 function $_(formNum, name) {
   var form = document.getElementById("form" + formNum);
@@ -35,56 +32,51 @@ function $_(formNum, name) {
   }
 
   return element;
 }
 
 // Mochitest gives us a sendKey(), but it's targeted to a specific element.
 // This basically sends an untargeted key event, to whatever's focused.
 function doKey(aKey, modifier) {
-    // Seems we need to enable this again, or sendKeyEvent() complaints.
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
     var keyName = "DOM_VK_" + aKey.toUpperCase();
     var key = Components.interfaces.nsIDOMKeyEvent[keyName];
 
     // undefined --> null
     if (!modifier)
         modifier = null;
 
     // Window utils for sending fake sey events.
-    var wutils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
-                          getInterface(Components.interfaces.nsIDOMWindowUtils);
+    var wutils = SpecialPowers.getDOMWindowUtils(window);
 
     wutils.sendKeyEvent("keydown",  key, 0, modifier);
     wutils.sendKeyEvent("keypress", key, 0, modifier);
     wutils.sendKeyEvent("keyup",    key, 0, modifier);
 }
 
 
 function getAutocompletePopup() {
     var Ci = Components.interfaces;
-    chromeWin = window
+    chromeWin = SpecialPowers.wrap(window)
                     .QueryInterface(Ci.nsIInterfaceRequestor)
                     .getInterface(Ci.nsIWebNavigation)
                     .QueryInterface(Ci.nsIDocShellTreeItem)
                     .rootTreeItem
                     .QueryInterface(Ci.nsIInterfaceRequestor)
                     .getInterface(Ci.nsIDOMWindow)
                     .QueryInterface(Ci.nsIDOMChromeWindow);
     autocompleteMenu = chromeWin.document.getElementById("PopupAutoComplete");
     ok(autocompleteMenu, "Got autocomplete popup");
 
     return autocompleteMenu;
 }
 
 
 function cleanUpFormHist() {
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  var formhist = Components.classes["@mozilla.org/satchel/form-history;1"].
+  var formhist = SpecialPowers.wrap(Components).classes["@mozilla.org/satchel/form-history;1"].
                  getService(Components.interfaces.nsIFormHistory2);
   formhist.removeAllEntries();
 }
 cleanUpFormHist();
 
 
 var checkObserver = {
   verifyStack: [],
@@ -93,18 +85,16 @@ var checkObserver = {
   waitForChecks: function(callback) {
     if (this.verifyStack.length == 0)
       callback();
     else
       this.callback = callback;
   },
 
   observe: function(subject, topic, data) {
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
     if (data != "addEntry" && data != "modifyEntry")
       return;
     ok(this.verifyStack.length > 0, "checking if saved form data was expected");
 
     // Make sure that every piece of data we expect to be saved is saved, and no
     // more. Here it is assumed that for every entry satchel saves or modifies, a
     // message is sent.
     //
--- a/toolkit/components/satchel/test/test_bug_511615.html
+++ b/toolkit/components/satchel/test/test_bug_511615.html
@@ -24,25 +24,24 @@ Form History test: form field autocomple
     <button type="submit">Submit</button>
   </form>
 </div>
 
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Form History autocomplete **/
-netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
 
 var autocompletePopup = getAutocompletePopup();
 autocompletePopup.style.direction = "ltr";
 
 var input = $_(1, "field1");
 
 // Get the form history service
-var fh = Components.classes["@mozilla.org/satchel/form-history;1"].
+var fh = SpecialPowers.wrap(Components).classes["@mozilla.org/satchel/form-history;1"].
          getService(Components.interfaces.nsIFormHistory2);
 ok(fh != null, "got form history service");
 
 fh.removeAllEntries();
 fh.addEntry("field1", "value1");
 fh.addEntry("field1", "value2");
 fh.addEntry("field1", "value3");
 fh.addEntry("field1", "value4");
@@ -121,253 +120,221 @@ function doClickUnprivileged() {
 /*
  * Main section of test...
  *
  * This is a bit hacky, because the events are either being sent or
  * processes asynchronously, so we need to interrupt our flow with lots of
  * setTimeout() calls. The case statements are executed in order, one per
  * timeout.
  */
-var nextTestPrivledged = true;
 function runTest(testNum) {
   ok(true, "Starting test #" + testNum);
 
-  if (nextTestPrivledged) {
-      ok(true, "This test is privileged.");
-      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-      nextTestPrivledged = false;
-  }
-
   switch(testNum) {
     //
     // Check initial state
     //
     case 1:
         input.value = "";
         checkForm("");
         is(autocompletePopup.popupOpen, false, "popup should be initially closed");
         break;
 
     //
     // Try to open the autocomplete popup from untrusted events.
     //
     // try a focus()
     case 2:
         input.focus();
-        nextTestPrivledged = true;
         break;
     case 3:
         checkPopupOpen(false);
         checkForm("");
         break;
     // try a click()
     case 4:
         input.click();
-        nextTestPrivledged = true;
         break;
     case 5:
         checkPopupOpen(false);
         checkForm("");
         break;
     // try a mouseclick event
     case 6:
         doClickUnprivileged();
-        nextTestPrivledged = true;
         break;
     case 7:
         checkPopupOpen(false);
         checkForm("");
         break;
     // try a down-arrow
     case 8:
         doKeyUnprivileged("down");
-        nextTestPrivledged = true;
         break;
     case 9:
         checkPopupOpen(false);
         checkForm("");
         break;
     // try a page-down
     case 10:
         doKeyUnprivileged("page_down");
-        nextTestPrivledged = true;
         break;
     case 11:
         checkPopupOpen(false);
         checkForm("");
         break;
     // try a return
     case 12:
 // XXX this causes later tests to fail for some reason.
 //        doKeyUnprivileged("return"); // not "enter"!
-        nextTestPrivledged = true;
         break;
     case 13:
         checkPopupOpen(false);
         checkForm("");
         break;
     // try a keypress
     case 14:
         doKeyUnprivileged('v');
-        nextTestPrivledged = true;
         break;
     case 15:
         checkPopupOpen(false);
         checkForm("");
         break;
     // try a space
     case 16:
         doKeyUnprivileged(" ");
-        nextTestPrivledged = true;
         break;
     case 17:
         checkPopupOpen(false);
         checkForm("");
         break;
     // backspace
     case 18:
         doKeyUnprivileged("back_space");
-        nextTestPrivledged = true;
         break;
     case 19:
         checkPopupOpen(false);
         checkForm("");
-        nextTestPrivledged = true;
         break;
     case 20:
         // We're privileged for this test, so open the popup.
         checkPopupOpen(false);
         checkForm("");
         doKey("down");
-        nextTestPrivledged = true;
         break;
     case 21:
         checkPopupOpen(true, -1);
         checkForm("");
         testNum = 99;
         break;
 
     //
     // Try to change the selected autocomplete item from untrusted events
     //
 
     // try a down-arrow
     case 100:
         doKeyUnprivileged("down");
-        nextTestPrivledged = true;
         break;
     case 101:
         checkPopupOpen(true, -1);
         checkForm("");
         break;
     // try a page-down
     case 102:
         doKeyUnprivileged("page_down");
-        nextTestPrivledged = true;
         break;
     case 103:
         checkPopupOpen(true, -1);
         checkForm("");
-        nextTestPrivledged = true;
         break;
     // really adjust the index
     case 104:
         // (We're privileged for this test.) Try a privileged down-arrow.
         doKey("down");
-        nextTestPrivledged = true;
         break;
     case 105:
         checkPopupOpen(true, 0);
         checkForm("");
         break;
     // try a down-arrow
     case 106:
         doKeyUnprivileged("down");
-        nextTestPrivledged = true;
         break;
     case 107:
         checkPopupOpen(true, 0);
         checkForm("");
         break;
     // try a page-down
     case 108:
         doKeyUnprivileged("page_down");
-        nextTestPrivledged = true;
         break;
     case 109:
         checkPopupOpen(true, 0);
         checkForm("");
     // try a keypress
     case 110:
         // XXX this causes the popup to close, and makes the value "vaa" (sic)
         //doKeyUnprivileged('a');
-        nextTestPrivledged = true;
         break;
     case 111:
         checkPopupOpen(true, 0);
         checkForm("");
         testNum = 199;
         break;
 
     //
     // Try to use the selected autocomplete item from untrusted events
     //
     // try a right-arrow
     case 200:
         doKeyUnprivileged("right");
-        nextTestPrivledged = true;
         break;
     case 201:
         checkPopupOpen(true, 0);
         checkForm("");
         break;
     // try a space
     case 202:
         doKeyUnprivileged(" ");
-        nextTestPrivledged = true;
         break;
     case 203:
         // XXX we should ignore this input while popup is open?
         checkPopupOpen(true, 0);
         checkForm("");
         break;
     // backspace
     case 204:
         doKeyUnprivileged("back_space");
-        nextTestPrivledged = true;
         break;
     case 205:
         // XXX we should ignore this input while popup is open?
         checkPopupOpen(true, 0);
         checkForm("");
-        nextTestPrivledged = true;
         break;
     case 206:
         // (this space intentionally left blank)
-        nextTestPrivledged = true;
         break;
     case 207:
         checkPopupOpen(true, 0);
         checkForm("");
         break;
     // try a return
     case 208:
 // XXX this seems to cause problems with reliably closing the popup
 //        doKeyUnprivileged("return"); // not "enter"!
-        nextTestPrivledged = true;
         break;
     case 209:
         checkPopupOpen(true, 0);
         checkForm("");
         break;
     // Send a real Escape to ensure popup closed at end of test.
     case 210:
         // Need to use doKey(), even though this test is not privileged.
         doKey("escape");
-        nextTestPrivledged = true;
         break;
     case 211:
         checkPopupOpen(false);
         checkForm("");
         is(autocompletePopup.style.direction, "rtl", "direction should have been changed from ltr to rtl");
 
         SimpleTest.finish();
         return;
--- a/uriloader/exthandler/tests/mochitest/handlerApps.js
+++ b/uriloader/exthandler/tests/mochitest/handlerApps.js
@@ -1,63 +1,61 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 // handlerApp.xhtml grabs this for verification purposes via window.opener
 var testURI = "webcal://127.0.0.1/rheeeeet.html";
 
+const Cc = SpecialPowers.wrap(Components).classes;
+
 function test() {
 
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); 
-
   // set up the web handler object
-  var webHandler = 
-    Components.classes["@mozilla.org/uriloader/web-handler-app;1"].
+  var webHandler = Cc["@mozilla.org/uriloader/web-handler-app;1"].
     createInstance(Components.interfaces.nsIWebHandlerApp);
   webHandler.name = "Test Web Handler App";
   webHandler.uriTemplate =
       "http://mochi.test:8888/tests/uriloader/exthandler/tests/mochitest/" + 
       "handlerApp.xhtml?uri=%s";
   
   // set up the uri to test with
-  var ioService = Components.classes["@mozilla.org/network/io-service;1"].
+  var ioService = Cc["@mozilla.org/network/io-service;1"].
     getService(Components.interfaces.nsIIOService);
   var uri = ioService.newURI(testURI, null, null);
 
   // create a window, and launch the handler in it
   var newWindow = window.open("", "handlerWindow", "height=300,width=300");
   var windowContext = 
-    newWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor). 
+    SpecialPowers.wrap(newWindow).QueryInterface(Components.interfaces.nsIInterfaceRequestor).
     getInterface(Components.interfaces.nsIWebNavigation).
     QueryInterface(Components.interfaces.nsIDocShell);
  
   webHandler.launchWithURI(uri, windowContext); 
 
   // if we get this far without an exception, we've at least partly passed
   // (remaining check in handlerApp.xhtml)
   ok(true, "webHandler launchWithURI (existing window/tab) started");
 
   // make the web browser launch in its own window/tab
   webHandler.launchWithURI(uri);
   
   // if we get this far without an exception, we've passed
   ok(true, "webHandler launchWithURI (new window/tab) test started");
 
   // set up the local handler object
-  var localHandler = 
-    Components.classes["@mozilla.org/uriloader/local-handler-app;1"].
+  var localHandler = Cc["@mozilla.org/uriloader/local-handler-app;1"].
     createInstance(Components.interfaces.nsILocalHandlerApp);
   localHandler.name = "Test Local Handler App";
   
   // get a local app that we know will be there and do something sane
-  var osString = Components.classes["@mozilla.org/xre/app-info;1"].
+  var osString = Cc["@mozilla.org/xre/app-info;1"].
                  getService(Components.interfaces.nsIXULRuntime).OS;
 
-  var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"].
+  var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
                getService(Components.interfaces.nsIDirectoryServiceProvider);
   if (osString == "WINNT") {
     var windowsDir = dirSvc.getFile("WinD", {});
     var exe = windowsDir.clone().QueryInterface(Components.interfaces.nsILocalFile);
     exe.appendRelativePath("SYSTEM32\\HOSTNAME.EXE");
 
   } else if (osString == "Darwin") { 
     var localAppsDir = dirSvc.getFile("LocApp", {});
@@ -68,42 +66,42 @@ function test() {
                             // information in their running copy of iCal
 
     if (navigator.userAgent.match(/ SeaMonkey\//)) {
       // SeaMonkey tinderboxes don't like to have iCal lingering (and focused)
       // on next test suite run(s).
       todo(false, "On SeaMonkey, testing OS X as generic Unix. (Bug 749872)");
 
       // assume a generic UNIX variant
-      exe = Components.classes["@mozilla.org/file/local;1"].
+      exe = Cc["@mozilla.org/file/local;1"].
             createInstance(Components.interfaces.nsILocalFile);
       exe.initWithPath("/bin/echo");
     }
   } else {
     // assume a generic UNIX variant
-    exe = Components.classes["@mozilla.org/file/local;1"].
+    exe = Cc["@mozilla.org/file/local;1"].
           createInstance(Components.interfaces.nsILocalFile);
     exe.initWithPath("/bin/echo");
   }
 
   localHandler.executable = exe;
   localHandler.launchWithURI(ioService.newURI(testURI, null, null));
 
   // if we get this far without an exception, we've passed
   ok(true, "localHandler launchWithURI test");
 
   // if we ever decide that killing iCal is the right thing to do, change 
   // the if statement below from "NOTDarwin" to "Darwin"
   if (osString == "NOTDarwin") {
 
-    var killall = Components.classes["@mozilla.org/file/local;1"].
+    var killall = Cc["@mozilla.org/file/local;1"].
                   createInstance(Components.interfaces.nsILocalFile);
     killall.initWithPath("/usr/bin/killall");
   
-    var process = Components.classes["@mozilla.org/process/util;1"].
+    var process = Cc["@mozilla.org/process/util;1"].
                   createInstance(Components.interfaces.nsIProcess);
     process.init(killall);
     
     var args = ['iCal'];
     process.run(false, args, args.length);
   }
 
   SimpleTest.waitForExplicitFinish();
--- a/widget/tests/test_bug760802.html
+++ b/widget/tests/test_bug760802.html
@@ -20,17 +20,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <pre id="test">
 <script type="application/javascript">
 
 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 
 function getBaseWindowInterface(win) {
-  return win.QueryInterface(Ci.nsIInterfaceRequestor)
+  return SpecialPowers.wrap(win).QueryInterface(Ci.nsIInterfaceRequestor)
     .getInterface(Ci.nsIWebNavigation)
     .QueryInterface(Ci.nsIDocShellTreeItem)
     .treeOwner
     .QueryInterface(Ci.nsIInterfaceRequestor)
     .nsIBaseWindow;
 }
 
 function getBaseWindowInterfaceFromDocShell(win) {
@@ -69,17 +69,17 @@ ok(
 
 ok(typeof(nativeHandle) === "string", "nativeHandle should be a string");
 ok(nativeHandle.match(/^0x[0-9a-f]+$/), "nativeHandle should have a memory address format");
 
 var iWin = window.document.getElementById("iframe_not_editable").contentWindow;
 is(getBaseWindowInterface(iWin).nativeHandle, nativeHandle,
               "the nativeHandle of an iframe should be its parent's nativeHandle");
 
-var dialog = window.openDialog("data:text/plain,this is an active window.", "_blank",
+var dialog = SpecialPowers.wrap(window).openDialog("data:text/plain,this is an active window.", "_blank",
                                "chrome,dialog=yes,width=100,height=100");
 
 isnot(getBaseWindowInterface(dialog).nativeHandle, "",
       "the nativeHandle of a dialog should not be empty");
 
 dialog.close();
 
 todo(false, "the nativeHandle of a window without a mainWidget should be empty"); // how to build a window without a mainWidget ?