Bug 1261251 - [e10s] Make toolkit/components/passwordmgr/test/test_bug_627616.html work under e10s. r?MattN draft
authorDrew Willcoxon <adw@mozilla.com>
Fri, 01 Apr 2016 18:14:25 -0700
changeset 347135 80e26c463d0e586d44be7891e67ef616e07fdd9d
parent 347134 7e4c0bee56f35104a4809121e8672f1e659258f5
child 517555 e72861e4986ca91f8d3b1a62d6e5d53e633f7d94
push id14500
push userdwillcoxon@mozilla.com
push dateSat, 02 Apr 2016 01:14:42 +0000
reviewersMattN
bugs1261251
milestone48.0a1
Bug 1261251 - [e10s] Make toolkit/components/passwordmgr/test/test_bug_627616.html work under e10s. r?MattN This moves the entire prompt_chrome.js into a function passed to runInParent(). MozReview-Commit-ID: BLOJf1HIeFM
toolkit/components/passwordmgr/test/mochitest.ini
toolkit/components/passwordmgr/test/mochitest/mochitest.ini
toolkit/components/passwordmgr/test/mochitest/test_bug_627616.html
toolkit/components/passwordmgr/test/test_bug_627616.html
--- a/toolkit/components/passwordmgr/test/mochitest.ini
+++ b/toolkit/components/passwordmgr/test/mochitest.ini
@@ -15,18 +15,16 @@ support-files =
   subtst_privbrowsing_2.html
   subtst_privbrowsing_3.html
   subtst_privbrowsing_4.html
   subtst_prompt_async.html
 
 [test_basic_form_2pw_2.html]
 [test_basic_form_autocomplete.html]
 skip-if = toolkit == 'android' # Bug 1258975 on android.
-[test_bug_627616.html]
-skip-if = toolkit == 'android' # Bug 1258975 on android.
 [test_master_password.html]
 skip-if = toolkit == 'android' # Bug 1258975 on android.
 [test_master_password_cleanup.html]
 skip-if = toolkit == 'android' # Bug 1258975 on android.
 [test_notifications_popup.html]
 skip-if = true || os == "linux" || toolkit == 'android' # bug 934057. Bug 1258975 on android.
 [test_prompt.html]
 skip-if = os == "linux" || toolkit == 'android' # Bug 1258975 on android.
--- a/toolkit/components/passwordmgr/test/mochitest/mochitest.ini
+++ b/toolkit/components/passwordmgr/test/mochitest/mochitest.ini
@@ -12,16 +12,18 @@ support-files =
 [test_basic_form_0pw.html]
 [test_basic_form_1pw.html]
 [test_basic_form_1pw_2.html]
 [test_basic_form_2pw_1.html]
 [test_basic_form_3pw_1.html]
 [test_basic_form_html5.html]
 [test_basic_form_pwevent.html]
 [test_basic_form_pwonly.html]
+[test_bug_627616.html]
+skip-if = toolkit == 'android' # Bug 1258975 on android.
 [test_bug_776171.html]
 [test_case_differences.html]
 skip-if = toolkit == 'android' # autocomplete
 [test_form_action_1.html]
 [test_form_action_2.html]
 [test_form_action_javascript.html]
 [test_formless_autofill.html]
 skip-if = toolkit == 'android' # Bug 1259768
rename from toolkit/components/passwordmgr/test/test_bug_627616.html
rename to toolkit/components/passwordmgr/test/mochitest/test_bug_627616.html
--- a/toolkit/components/passwordmgr/test/test_bug_627616.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_bug_627616.html
@@ -1,79 +1,22 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <meta charset="utf-8">
   <title>Test bug 627616 related to proxy authentication</title>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="text/javascript" src="prompt_common.js"></script>
+  <script type="text/javascript" src="pwmgr_common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <script class="testbody" type="text/javascript">
     SimpleTest.waitForExplicitFinish();
 
-    var Cc = SpecialPowers.Cc;
     var Ci = SpecialPowers.Ci;
-    var systemPrincipal = SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal();
-
-    testNum = 1;
-
-    var login, login2;
-
-    var resolveCallback = SpecialPowers.wrapCallbackObject({
-
-      QueryInterface : function (iid) {
-        const interfaces = [Ci.nsIProtocolProxyCallback, Ci.nsISupports];
-
-        if (!interfaces.some( function(v) { return iid.equals(v) } ))
-          throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
-        return this;
-      },
-
-      onProxyAvailable : function (req, uri, pi, status) {
-         init2(SpecialPowers.wrap(pi).host, SpecialPowers.wrap(pi).port);
-      }
-    });
-
-    function init1() {
-        var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
-        var pps = Cc["@mozilla.org/network/protocol-proxy-service;1"].getService();
-
-        var channel = ios.newChannel2("http://example.com",
-                                      null,
-                                      null,
-                                      null,      // aLoadingNode
-                                      systemPrincipal,
-                                      null,      // aTriggeringPrincipal
-                                      Ci.nsILoadInfo.SEC_NORMAL,
-                                      Ci.nsIContentPolicy.TYPE_OTHER);
-        pps.asyncResolve(channel, 0, resolveCallback);
-    }
-
-    function init2(proxyHost, proxyPort) {
-
-        var mozproxy = "moz-proxy://" + proxyHost + ":" + proxyPort;
-
-        var pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
-        login = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);
-        login.init(mozproxy, null, "proxy_realm", "proxy_user", "proxy_pass", "", "");
-        pwmgr.addLogin(login);
-
-        login2 = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(Ci.nsILoginInfo);
-        login2.init("http://mochi.test:8888", null, "mochirealm", "user1name", "user1pass", "", "");
-        pwmgr.addLogin(login2);
-        startCallbackTimer();
-    }
-    function cleanup() {
-        var pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
-        pwmgr.removeLogin(login);
-        pwmgr.removeLogin(login2);
-        timer.cancel();
-    }
 
     function makeXHR(expectedStatus, expectedText, extra) {
       var xhr =  new XMLHttpRequest();
       xhr.open("GET", "authenticate.sjs?" +
                       "proxy_user=proxy_user&" +
                       "proxy_pass=proxy_pass&" +
                       "proxy_realm=proxy_realm&" +
                       "user=user1name&" +
@@ -107,35 +50,141 @@
       SpecialPowers.wrap(xhr).channel.loadFlags |= Ci.nsIChannel.LOAD_ANONYMOUS;
       xhr.send();
     }
 
     var gExpectedDialogs = 0;
     var gCurrentTest;
     function runNextTest() {
       is(gExpectedDialogs, 0, "received expected number of auth dialogs");
-      Cc["@mozilla.org/network/http-auth-manager;1"].getService(SpecialPowers.Ci.nsIHttpAuthManager).clearAll();
-      if (pendingTests.length > 0) {
-        ({expectedDialogs: gExpectedDialogs,
-          test: gCurrentTest} = pendingTests.shift());
-        gCurrentTest.call(this);
-      } else {
-        cleanup();
-        SimpleTest.finish();
-      }
+      mm.sendAsyncMessage("prepareForNextTest");
+      mm.addMessageListener("prepareForNextTestDone", function prepared(msg) {
+        mm.removeMessageListener("prepareForNextTestDone", prepared);
+        if (pendingTests.length > 0) {
+          ({expectedDialogs: gExpectedDialogs,
+            test: gCurrentTest} = pendingTests.shift());
+          gCurrentTest.call(this);
+        } else {
+          mm.sendAsyncMessage("cleanup");
+          mm.addMessageListener("cleanupDone", msg => {
+            // mm.destroy() is called as a cleanup function by runInParent(), no
+            // need to do it here.
+            SimpleTest.finish();
+          });
+        }
+      });
     }
 
     var pendingTests = [{expectedDialogs: 2, test: testNonAnonymousCredentials},
                         {expectedDialogs: 1, test: testAnonymousCredentials},
                         {expectedDialogs: 0, test: testAnonymousNoAuth}];
-    init1();
-    runNextTest();
+
+    let mm = runInParent(() => {
+      const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+
+      Cu.import("resource://gre/modules/Services.jsm");
+      Cu.import("resource://gre/modules/Timer.jsm");
+      Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+      let channel = Services.io.newChannel2(
+        "http://example.com",
+        null,
+        null,
+        null,      // aLoadingNode
+        Services.scriptSecurityManager.getSystemPrincipal(),
+        null,      // aTriggeringPrincipal
+        Ci.nsILoadInfo.SEC_NORMAL,
+        Ci.nsIContentPolicy.TYPE_OTHER
+      );
+
+      let gLogin;
+      let gLogin2;
+
+      let pps = Cc["@mozilla.org/network/protocol-proxy-service;1"].
+                getService(Ci.nsIProtocolProxyService);
+      pps.asyncResolve(channel, 0, {
+        onProxyAvailable(req, uri, pi, status) {
+          let mozproxy = "moz-proxy://" + pi.host + ":" + pi.port;
+          gLogin = Cc["@mozilla.org/login-manager/loginInfo;1"].
+                   createInstance(Ci.nsILoginInfo);
+          gLogin.init(mozproxy, null, "proxy_realm", "proxy_user", "proxy_pass",
+                      "", "");
+          Services.logins.addLogin(gLogin);
+
+          gLogin2 = Cc["@mozilla.org/login-manager/loginInfo;1"].
+                    createInstance(Ci.nsILoginInfo);
+          gLogin2.init("http://mochi.test:8888", null, "mochirealm", "user1name",
+                       "user1pass", "", "");
+          Services.logins.addLogin(gLogin2);
+
+          startWatchingForPrompts();
+          sendAsyncMessage("setupDone");
+        },
+        QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolProxyCallback]),
+      });
+
+      addMessageListener("prepareForNextTest", message => {
+        Cc["@mozilla.org/network/http-auth-manager;1"].
+          getService(Ci.nsIHttpAuthManager).
+          clearAll();
+        sendAsyncMessage("prepareForNextTestDone");
+      });
 
-    function handleDialog(doc, testNum)
-    {
-        var dialog = doc.getElementById("commonDialog");
-        dialog.acceptDialog();
-        gExpectedDialogs--;
-        startCallbackTimer();
-    }
+      addMessageListener("cleanup", message => {
+        stopWatchingForPrompts();
+        Services.logins.removeLogin(gLogin);
+        Services.logins.removeLogin(gLogin2);
+        sendAsyncMessage("cleanupDone");
+      });
+
+      let gInterval;
+
+      function startWatchingForPrompts() {
+        gInterval = setInterval(() => {
+          let doc = getDialogDoc();
+          if (doc) {
+            let dialog = doc.getElementById("commonDialog");
+            dialog.acceptDialog();
+            sendAsyncMessage("promptAccepted");
+          }
+        }, 100);
+      }
+
+      function stopWatchingForPrompts() {
+        clearInterval(gInterval);
+      }
+
+      function getDialogDoc() {
+        // Find the <browser> which contains notifyWindow, by looking
+        // through all the open windows and all the <browsers> in each.
+        let enumerator = Services.wm.getXULWindowEnumerator(null);
+        while (enumerator.hasMoreElements()) {
+          let win = enumerator.getNext();
+          let windowDocShell = win.QueryInterface(Ci.nsIXULWindow).docShell;
+          let containedDocShells = windowDocShell.getDocShellEnumerator(
+                                            Ci.nsIDocShellTreeItem.typeChrome,
+                                            Ci.nsIDocShell.ENUMERATE_FORWARDS);
+          while (containedDocShells.hasMoreElements()) {
+              // Get the corresponding document for this docshell
+              let childDocShell = containedDocShells.getNext();
+              // We don't want it if it's not done loading.
+              if (childDocShell.busyFlags != Ci.nsIDocShell.BUSY_FLAGS_NONE)
+                continue;
+              let childDoc = childDocShell.QueryInterface(Ci.nsIDocShell)
+                                          .contentViewer
+                                          .DOMDocument;
+              if (childDoc.location.href == "chrome://global/content/commonDialog.xul")
+                return childDoc;
+          }
+        }
+        return null;
+      }
+    });
+
+    mm.addMessageListener("promptAccepted", msg => {
+      gExpectedDialogs--;
+    });
+    mm.addMessageListener("setupDone", msg => {
+      runNextTest();
+    });
 </script>
 </body>
 </html>