Bug 913853 - Remove enablePrivilege usage from tests for prompt. r=bholley
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Tue, 10 Sep 2013 07:57:53 +0900
changeset 146257 a9010c9e50713353ff38bdff46391f8570bccb79
parent 146256 e9a2e269aa9e34fff22d6f1a71a2e281fb908304
child 146258 39d27a8b3b3ae44416fe7819a1492ad1b186cf61
push id33511
push userVYV03354@nifty.ne.jp
push dateMon, 09 Sep 2013 22:58:27 +0000
treeherdermozilla-inbound@a9010c9e5071 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs913853
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 913853 - Remove enablePrivilege usage from tests for prompt. r=bholley
toolkit/components/prompts/test/prompt_common.js
toolkit/components/prompts/test/test_bug620145.html
toolkit/components/prompts/test/test_bug625187.html
toolkit/components/prompts/test/test_bug861605.html
toolkit/components/prompts/test/test_modal_prompts.html
toolkit/components/prompts/test/test_modal_select.html
--- a/toolkit/components/prompts/test/prompt_common.js
+++ b/toolkit/components/prompts/test/prompt_common.js
@@ -1,12 +1,10 @@
-netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
-const Ci = Components.interfaces;
-const Cc = Components.classes;
+const Ci = SpecialPowers.Ci;
+const Cc = SpecialPowers.Cc;
 ok(Ci != null, "Access Ci");
 ok(Cc != null, "Access Cc");
 
 var didDialog;
 
 var isSelectDialog = false;
 var isTabModal = false;
 var usePromptService = true;
@@ -14,55 +12,54 @@ var usePromptService = true;
 var timer; // keep in outer scope so it's not GC'd before firing
 function startCallbackTimer() {
     didDialog = false;
 
     // Delay before the callback twiddles the prompt.
     const dialogDelay = 10;
 
     // Use a timer to invoke a callback to twiddle the authentication dialog
-    timer = SpecialPowers.wrap(Components)
-                         .classes["@mozilla.org/timer;1"]
-                         .createInstance(Ci.nsITimer);
+    timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
     timer.init(observer, dialogDelay, Ci.nsITimer.TYPE_ONE_SHOT);
 }
 
 
 var observer = {
     QueryInterface : function (iid) {
         const interfaces = [Ci.nsIObserver,
                             Ci.nsISupports, Ci.nsISupportsWeakReference];
 
         if (!interfaces.some( function(v) { return iid.equals(v) } ))
-            throw Components.results.NS_ERROR_NO_INTERFACE;
+            throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
         return this;
     },
 
-    observe : function (subject, topic, data) {
-        netscape.security.PrivilegeManager
-                         .enablePrivilege('UniversalXPConnect');
-
+    observe : SpecialPowers.wrapCallback(function (subject, topic, data) {
+      try {
         if (isTabModal) {
           var promptBox = getTabModalPromptBox(window);
           ok(promptBox, "got tabmodal promptbox");
-          var prompts = promptBox.listPrompts();
+          var prompts = SpecialPowers.wrap(promptBox).listPrompts();
           if (prompts.length)
               handleDialog(prompts[0].Dialog.ui, testNum);
           else
               startCallbackTimer(); // try again in a bit
         } else {
           var doc = getDialogDoc();
           if (isSelectDialog && doc)
               handleDialog(doc, testNum);
           else if (doc)
               handleDialog(doc.defaultView.Dialog.ui, testNum);
           else
               startCallbackTimer(); // try again in a bit
         }
-    }
+      } catch (e) {
+        ok(false, "Exception thrown in the timer callback: " + e + " at " + (e.fileName || e.filename) + ":" + (e.lineNumber || e.linenumber));
+      }
+    })
 };
 
 function getTabModalPromptBox(domWin) {
     var promptBox = null;
 
     // Given a content DOM window, returns the chrome window it's in.
     function getChromeWindow(aWindow) {
         var chromeWin = SpecialPowers.wrap(aWindow).QueryInterface(Ci.nsIInterfaceRequestor)
--- a/toolkit/components/prompts/test/test_bug620145.html
+++ b/toolkit/components/prompts/test/test_bug620145.html
@@ -86,14 +86,14 @@ function handleDialog(ui, testNum)
   if (!selectionTest) {
     todo(false, "Selection test is disabled when tab modal prompts are not enabled.");
   } else {
     synthesizeMouse($("text"), 25, 55, { type: "mousemove" });
     is(window.getSelection().toString(), "", "selection not made");
   }
 
   ok(true, "handleDialog sending mouseclick to dialog...");
-  synthesizeMouse(ui.button0, 5, 5, { }, ui.button0.ownerDocument.defaultView);
+  synthesizeMouse(ui.button0, 5, 5, { }, SpecialPowers.unwrap(ui.button0.ownerDocument.defaultView));
 }
 </script>
 
 </body>
 </html>
--- a/toolkit/components/prompts/test/test_bug625187.html
+++ b/toolkit/components/prompts/test/test_bug625187.html
@@ -28,26 +28,23 @@
 <script class="testbody" type="text/javascript">
 SimpleTest.waitForExplicitFinish();
 
 var testNum = 0;
 var dialogNum = 0;
 
 function hasTabModalPrompts() {
   var prefName = "prompts.tab_modal.enabled";
-  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
-  Components.utils.import("resource://gre/modules/Services.jsm");
+  var Services = SpecialPowers.Cu.import("resource://gre/modules/Services.jsm").Services;
   return Services.prefs.getPrefType(prefName) == Services.prefs.PREF_BOOL &&
          Services.prefs.getBoolPref(prefName);
 }
 
 function runtest()
 {
-  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
   isTabModal = hasTabModalPrompts();
 
   // This test depends on tab modal prompts being enabled.
   if (!isTabModal) {
     todo(false, "Test disabled when tab modal prompts are not enabled.");
     SimpleTest.finish();
     return;
   }
@@ -55,17 +52,17 @@ function runtest()
   startCallbackTimer();
 
   var button = document.querySelector("button");
   dispatchMouseEvent(button, "click");
 
   startCallbackTimer();
 
   var iframe = document.getElementById("iframe_diff_origin");
-  button = iframe.contentWindow.document.getElementById("btn1");
+  button = SpecialPowers.wrap(iframe.contentWindow).document.getElementById("btn1");
   dispatchMouseEvent(button, "click");
 
   startCallbackTimer();
 
   iframe = document.getElementById("iframe_same_origin");
   button = iframe.contentWindow.document.getElementById("btn1");
   dispatchMouseEvent(button, "click");
 
@@ -82,23 +79,23 @@ function handleDialog(ui)
   dialogNum++;
   if (dialogNum == 1 || dialogNum == 3 || dialogNum == 4)
     is(ui.infoTitle.getAttribute("hidden"), "true",
        "dialog #" + dialogNum + ": the tabprompt infoTitle element is hidden");
   else if (dialogNum == 2)
     ok(!ui.infoTitle.hasAttribute("hidden"),
        "dialog #" + dialogNum + ": the tabprompt infoTitle element is not hidden");
 
-  synthesizeMouse(ui.button0, 2, 2, {}, ui.button0.ownerDocument.defaultView);
+  synthesizeMouse(ui.button0, 2, 2, {}, SpecialPowers.unwrap(ui.button0.ownerDocument.defaultView));
 }
 
 function dispatchMouseEvent(target, type)
 {
-  var win = target.ownerDocument.defaultView;
+  var win = SpecialPowers.unwrap(target.ownerDocument.defaultView);
   var e = document.createEvent("MouseEvent");
   e.initEvent(type, false, false, win, 0, 1, 1, 1, 1,
               false, false, false, false, 0, null);
   var utils = SpecialPowers.getDOMWindowUtils(win);
-  utils.dispatchDOMEventViaPresShell(target, e, true);
+  utils.dispatchDOMEventViaPresShell(SpecialPowers.unwrap(target), e, true);
 }
 </script>
 </body>
 </html>
--- a/toolkit/components/prompts/test/test_bug861605.html
+++ b/toolkit/components/prompts/test/test_bug861605.html
@@ -56,14 +56,14 @@ function runtest()
     ok(false, "confirm() without arguments should not throw!");
   }
 
   SimpleTest.finish();
 }
 
 function handleDialog(ui, testNum)
 {
-  synthesizeMouse(ui.button0, 5, 5, { }, ui.button0.ownerDocument.defaultView);
+  synthesizeMouse(ui.button0, 5, 5, { }, SpecialPowers.unwrap(ui.button0.ownerDocument.defaultView));
 }
 </script>
 
 </body>
 </html>
--- a/toolkit/components/prompts/test/test_modal_prompts.html
+++ b/toolkit/components/prompts/test/test_modal_prompts.html
@@ -12,24 +12,20 @@ Prompter tests: modal prompts
 
 <div id="content" style="display: none">
   <iframe id="iframe"></iframe>
 </div>
 
 <pre id="test">
 <script class="testbody" type="text/javascript;version=1.8">
 
-netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
-var isOSX = ("nsILocalFileMac" in Components.interfaces);
-var isLinux = ("@mozilla.org/gnome-gconf-service;1" in Components.classes);
+var isOSX = ("nsILocalFileMac" in SpecialPowers.Ci);
+var isLinux = ("@mozilla.org/gnome-gconf-service;1" in SpecialPowers.Cc);
 
 function pollDialog(okButton) {
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
     if (okButton.disabled)
         return;
 
     ok(true, "dialog button is enabled now");
     pollTimer.cancel();
     pollTimer = null;
     okButton.click();
     didDialog = true;
@@ -51,51 +47,50 @@ function checkExpectedState(ui, state) {
 
 
     function isDefaultButton(b) {
         return (b.hasAttribute("default") &&
                 b.getAttribute("default") == "true");
     }
 
     let shouldBeDefault;
-    shouldBeDefault = (state.defButton == ui.button0);
+    shouldBeDefault = SpecialPowers.compare(state.defButton, ui.button0);
     is(isDefaultButton(ui.button0), shouldBeDefault, "checking button0 default");
-    shouldBeDefault = (state.defButton == ui.button1);
+    shouldBeDefault = SpecialPowers.compare(state.defButton, ui.button1);
     is(isDefaultButton(ui.button1), shouldBeDefault, "checking button1 default");
-    shouldBeDefault = (state.defButton == ui.button2);
+    shouldBeDefault = SpecialPowers.compare(state.defButton, ui.button2);
     is(isDefaultButton(ui.button2), shouldBeDefault, "checking button2 default");
 
     let fm = Cc["@mozilla.org/focus-manager;1"].
              getService(Ci.nsIFocusManager);
     let e = fm.focusedElement;
     ok(true, "focused element is a " + (e ? e.localName : "<null>"));
     if (isLinux && !e) {
         todo(false, "Focus seems missing on Linux");
         return;
     }
 
     if (isOSX && state.focused && state.focused.localName == "button")
-        ok(ui.infoBody == e, "buttons don't focus on OS X");
+        ok(SpecialPowers.compare(ui.infoBody, e), "buttons don't focus on OS X");
     else if (state.focused)
-        ok(state.focused == e, "Checking focused element");
+        ok(SpecialPowers.compare(state.focused, e), "Checking focused element");
     else
         is(e, null, "Not expecting a focused element");
 }
 
 
 /*
  * handleDialog
  *
  * Invoked a short period of time after calling startCallbackTimer(), and
  * allows testing the actual prompt dialog while it's being displayed. Tests
  * should call startCallbackTimer() each time the auth dialog is expected (the
  * timer is a one-shot).
  */
 function handleDialog(ui, testNum) {
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
     ok(true, "--- handleDialog for test " + testNum +
              " --- (isTabModal=" + isTabModal + ", usePromptService=" + usePromptService + ")");
 
     let textField = ui.loginTextbox;
     let passField = ui.password1Textbox;
     let checkbox  = ui.checkbox;
     let clickOK   = true;
     let state;
@@ -753,20 +748,19 @@ function handleDialog(ui, testNum) {
 
     if (testNum == 24) {
         ui.button2.click();
     } else if (testNum == 26) {
         // Buttons are disabled at the moment, poll until they're reenabled.
         // Can't use setInterval here, because the window's in a modal state
         // and thus DOM events are suppressed.
         pollTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-        pollTimer.initWithCallback(function() {
-          netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+        pollTimer.initWithCallback(SpecialPowers.wrapCallback(function() {
           pollDialog(ui.button0);
-        },
+        }),
                                    100, Ci.nsITimer.TYPE_REPEATING_SLACK);
         return;
     } else {
         if (clickOK)
             ui.button0.click();
         else
             ui.button1.click();
     }
@@ -1184,20 +1178,17 @@ function runTests() {
 
     // ===== test 100 =====
     // promptAuth with empty realm
     // (promptAuth is only accessible from the prompt service)
     testNum = 100;
     if (usePromptService) {
         startCallbackTimer();
         checkVal.value = false;
-        promptArgs = [channel, level, authinfo, "Check me out!", checkVal];
-        if (usePromptService)
-            promptArgs.unshift(window);
-        isOK = prompter.promptAuth.apply(null, promptArgs);
+        isOK = prompter.promptAuth(window, channel, level, authinfo, "Check me out!", checkVal);
         is(isOK, true, "checked expected retval");
         is(authinfo.username, "username", "checking filled username");
         is(authinfo.password, "password", "checking filled password");
         is(checkVal.value, true, "expected checkbox setting");
         ok(didDialog, "handleDialog was invoked");
     }
 
     // ===== test 101 =====
@@ -1208,20 +1199,17 @@ function runTests() {
         startCallbackTimer();
         checkVal.value = false;
         var longString = "";
         for (var i = 0; i < 20; i++)
             longString += "abcdefghi "; // 200 chars long
         authinfo.realm = longString;
         authinfo.username = "";
         authinfo.password = "";
-        promptArgs = [channel, level, authinfo, "Check me out!", checkVal];
-        if (usePromptService)
-            promptArgs.unshift(window);
-        isOK = prompter.promptAuth.apply(null, promptArgs);
+        isOK = prompter.promptAuth(window, channel, level, authinfo, "Check me out!", checkVal);
         is(isOK, true, "checked expected retval");
         is(authinfo.username, "username", "checking filled username");
         is(authinfo.password, "password", "checking filled password");
         is(checkVal.value, true, "expected checkbox setting");
         ok(didDialog, "handleDialog was invoked");
     }
 }
 
--- a/toolkit/components/prompts/test/test_modal_select.html
+++ b/toolkit/components/prompts/test/test_modal_select.html
@@ -12,27 +12,23 @@ Prompter tests: modal prompts
 
 <div id="content" style="display: none">
   <iframe id="iframe"></iframe>
 </div>
 
 <pre id="test">
 <script class="testbody" type="text/javascript;version=1.8">
 
-netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
 let prompter = Cc["@mozilla.org/embedcomp/prompt-service;1"].
                getService(Ci.nsIPromptService2);
 let ioService = Cc["@mozilla.org/network/io-service;1"].
                 getService(Ci.nsIIOService);
 let pollTimer;
 
 function pollDialog(dialog) {
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
-
     if (dialog.getButton("accept").disabled)
         return;
 
     ok(true, "dialog button is enabled now");
     pollTimer.cancel();
     pollTimer = null;
     dialog.acceptDialog();
     didDialog = true;
@@ -61,17 +57,16 @@ function checkExpectedSelectState(doc, s
  * handleDialog
  *
  * Invoked a short period of time after calling startCallbackTimer(), and
  * allows testing the actual prompt dialog while it's being displayed. Tests
  * should call startCallbackTimer() each time the auth dialog is expected (the
  * timer is a one-shot).
  */
 function handleDialog(doc, testNum) {
-    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
     ok(true, "--- handleDialog for test " + testNum + " ---");
 
     let dialog    = doc.getElementsByTagName("dialog")[0];
     let listbox   = doc.getElementById("list");
     let clickOK   = true;
     let state;
 
     // XXX check focused element