Bug 1175267 - Part 2: Ensure that process does not switch for file:// XPI installs. r=Mossop, a=gchang
authorBob Owen <bobowencode@gmail.com>
Wed, 10 May 2017 17:34:36 +0100
changeset 396397 41389795f3945a98384bc63d33160e4c8be35175
parent 396396 7e720ada7954585f6fe04e82c74becc9a690e1f7
child 396398 6ff47bf39febedf714dbbfbdcb6f56be7fcdcba9
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop, gchang
bugs1175267
milestone54.0
Bug 1175267 - Part 2: Ensure that process does not switch for file:// XPI installs. r=Mossop, a=gchang
toolkit/mozapps/extensions/test/browser/browser.ini
toolkit/mozapps/extensions/test/browser/browser_file_xpi_no_process_switch.js
--- a/toolkit/mozapps/extensions/test/browser/browser.ini
+++ b/toolkit/mozapps/extensions/test/browser/browser.ini
@@ -49,16 +49,17 @@ support-files =
   !/toolkit/mozapps/extensions/test/xpinstall/unsigned.xpi
   !/toolkit/mozapps/extensions/test/xpinstall/amosigned.xpi
 
 [browser_addonrepository_performance.js]
 [browser_bug557956.js]
 [browser_bug616841.js]
 [browser_cancelCompatCheck.js]
 [browser_checkAddonCompatibility.js]
+[browser_file_xpi_no_process_switch.js]
 [browser_getmorethemes.js]
 [browser_gmpProvider.js]
 [browser_hotfix.js]
 # Verifies the old style of signing hotfixes
 skip-if = require_signing
 [browser_installssl.js]
 [browser_newaddon.js]
 [browser_updatessl.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/browser_file_xpi_no_process_switch.js
@@ -0,0 +1,101 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+
+const addonInstallId = "addon-install-confirmation";
+
+let fileurl1 = get_addon_file_url("browser_dragdrop1.xpi");
+let fileurl2 = get_addon_file_url("browser_dragdrop2.xpi");
+
+function promiseInstallNotification(aBrowser) {
+  return new Promise(resolve => {
+    function popupshown(event) {
+      if (event.target.getAttribute("popupid") != addonInstallId) {
+        return;
+      }
+
+      let notification =
+        PopupNotifications.getNotification(addonInstallId, aBrowser);
+      if (!notification) {
+        return;
+      }
+
+      PopupNotifications.panel.removeEventListener("popupshown", popupshown);
+      ok(true, `Got ${addonInstallId} popup for browser`);
+      notification.remove();
+      resolve();
+    }
+
+    PopupNotifications.panel.addEventListener("popupshown", popupshown);
+  });
+}
+
+function waitForAnyNewTabAndInstallNotification() {
+  return new Promise((resolve) => {
+    gBrowser.tabContainer.addEventListener("TabOpen", function(openEvent) {
+      let newTab = openEvent.target;
+      resolve([newTab, promiseInstallNotification(newTab.linkedBrowser)]);
+    }, {once: true});
+  });
+}
+
+function CheckBrowserInPid(browser, expectedPid, message) {
+  return ContentTask.spawn(browser, { expectedPid, message }, (arg) => {
+    is(Services.appinfo.processID, arg.expectedPid, arg.message);
+  });
+}
+
+function* testOpenedAndDraggedXPI(aBrowser) {
+  // Get the current pid for browser for comparison later.
+  let browserPid = yield ContentTask.spawn(aBrowser, null, () => {
+    return Services.appinfo.processID;
+  });
+
+  // No process switch for XPI file:// URI in the urlbar.
+  let promiseNotification = promiseInstallNotification(aBrowser);
+  let urlbar = document.getElementById("urlbar");
+  urlbar.value = fileurl1.spec;
+  urlbar.focus();
+  EventUtils.synthesizeKey("KEY_Enter", { code: "Enter" });
+  yield promiseNotification;
+  yield CheckBrowserInPid(aBrowser, browserPid,
+                          "Check that browser has not switched process.");
+
+  // No process switch for XPI file:// URI dragged to tab.
+  let tab = gBrowser.getTabForBrowser(aBrowser);
+  promiseNotification = promiseInstallNotification(aBrowser);
+  let effect = EventUtils.synthesizeDrop(tab, tab,
+               [[{type: "text/uri-list", data: fileurl1.spec}]],
+               "move");
+  is(effect, "move", "Drag should be accepted");
+  yield promiseNotification;
+  yield CheckBrowserInPid(aBrowser, browserPid,
+                          "Check that browser has not switched process.");
+
+  // No process switch for two XPI file:// URIs dragged to tab.
+  promiseNotification = promiseInstallNotification(aBrowser);
+  let promiseTabAndNotification = waitForAnyNewTabAndInstallNotification();
+  effect = EventUtils.synthesizeDrop(tab, tab,
+           [[{type: "text/uri-list", data: fileurl1.spec}],
+            [{type: "text/uri-list", data: fileurl2.spec}]],
+           "move");
+  is(effect, "move", "Drag should be accepted");
+  let [newTab, newTabInstallNotification] = yield promiseTabAndNotification;
+  yield promiseNotification;
+  if (gBrowser.selectedTab != newTab) {
+    yield BrowserTestUtils.switchTab(gBrowser, newTab);
+  }
+  yield newTabInstallNotification;
+  yield BrowserTestUtils.removeTab(newTab);
+  yield CheckBrowserInPid(aBrowser, browserPid,
+                          "Check that browser has not switched process.");
+}
+
+// Test for bug 1175267.
+add_task(function* () {
+  yield SpecialPowers.pushPrefEnv({
+    set: [["xpinstall.customConfirmationUI", true]]
+  });
+
+  yield BrowserTestUtils.withNewTab("http://example.com", testOpenedAndDraggedXPI);
+  yield BrowserTestUtils.withNewTab("about:robots", testOpenedAndDraggedXPI);
+});