Bug 1550647 - Updated test to check for addon-install-blocked events, improved AddonManger fullscreen block. r=johannh
authorPaul Zuehlcke <pzuhlcke@mozilla.com>
Tue, 14 May 2019 07:53:05 +0000
changeset 532568 a928c7e7995bccca093bc5809ae53a007d9d04a3
parent 532567 a15e072aac3f4e1fbfc78a9931c0290fba2d09cd
child 532569 b23f1b4655818d6d64517ddd7fa74fae1fbd9507
push id11270
push userrgurzau@mozilla.com
push dateWed, 15 May 2019 15:07:19 +0000
treeherdermozilla-beta@571bc76da583 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1550647
milestone68.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 1550647 - Updated test to check for addon-install-blocked events, improved AddonManger fullscreen block. r=johannh Differential Revision: https://phabricator.services.mozilla.com/D30955
browser/base/content/browser-addons.js
toolkit/mozapps/extensions/AddonManager.jsm
toolkit/mozapps/extensions/test/xpinstall/browser_block_fullscreen_prompt.js
--- a/browser/base/content/browser-addons.js
+++ b/browser/base/content/browser-addons.js
@@ -347,23 +347,20 @@ var gXPInstallObserver = {
     Services.telemetry
             .getHistogramById("SECURITY_UI")
             .add(Ci.nsISecurityUITelemetry.WARNING_CONFIRM_ADDON_INSTALL);
   },
 
   // IDs of addon install related notifications
   NOTIFICATION_IDS: [
     "addon-install-blocked",
-    "addon-install-blocked-silent",
     "addon-install-complete",
     "addon-install-confirmation",
-    "addon-install-disabled",
     "addon-install-failed",
     "addon-install-origin-blocked",
-    "addon-install-started",
     "addon-progress",
     "addon-webext-permissions",
     "xpinstall-disabled",
   ],
 
   // Remove all opened addon installation notifications
   removeAllNotifications(browser) {
     this.NOTIFICATION_IDS.forEach((id) => {
--- a/toolkit/mozapps/extensions/AddonManager.jsm
+++ b/toolkit/mozapps/extensions/AddonManager.jsm
@@ -1789,37 +1789,37 @@ var AddonManagerInternal = {
     // main tab's browser). Check this by seeing if the browser we've been
     // passed is in a content type docshell and if so get the outer-browser.
     let topBrowser = aBrowser;
     let docShell = aBrowser.ownerGlobal.docShell;
     if (docShell.itemType == Ci.nsIDocShellTreeItem.typeContent)
       topBrowser = docShell.chromeEventHandler;
 
     try {
-      if (!this.isInstallEnabled(aMimetype)) {
+      if (topBrowser.ownerGlobal.fullScreen) {
+        // Addon installation and the resulting notifications should be blocked in fullscreen for security and usability reasons.
+        // Installation prompts in fullscreen can trick the user into installing unwanted addons.
+        // In fullscreen the notification box does not have a clear visual association with its parent anymore.
+        aInstall.cancel();
+
+        this.installNotifyObservers("addon-install-blocked-silent", topBrowser,
+                                    aInstallingPrincipal.URI, aInstall);
+        return;
+      } else if (!this.isInstallEnabled(aMimetype)) {
         aInstall.cancel();
 
         this.installNotifyObservers("addon-install-disabled", topBrowser,
                                     aInstallingPrincipal.URI, aInstall);
         return;
       } else if (aInstallingPrincipal.isNullPrincipal || !aBrowser.contentPrincipal || !aInstallingPrincipal.subsumes(aBrowser.contentPrincipal)) {
         aInstall.cancel();
 
         this.installNotifyObservers("addon-install-origin-blocked", topBrowser,
                                     aInstallingPrincipal.URI, aInstall);
         return;
-      } else if (topBrowser.ownerGlobal.fullScreen) {
-        // Addon installation and the resulting notifications should be blocked in fullscreen for security and usability reasons.
-        // Installation prompts in fullscreen can trick the user into installing unwanted addons.
-        // In fullscreen the notification box does not have a clear visual association with its parent anymore.
-        aInstall.cancel();
-
-        this.installNotifyObservers("addon-install-blocked-silent", topBrowser,
-                                    aInstallingPrincipal.URI, aInstall);
-        return;
       }
 
       // The install may start now depending on the web install listener,
       // listen for the browser navigating to a new origin and cancel the
       // install in that case.
       new BrowserListener(aBrowser, aInstallingPrincipal, aInstall);
 
       let startInstall = (source) => {
--- a/toolkit/mozapps/extensions/test/xpinstall/browser_block_fullscreen_prompt.js
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_block_fullscreen_prompt.js
@@ -5,104 +5,85 @@
 "use strict";
 
 // This test tends to trigger a race in the fullscreen time telemetry,
 // where the fullscreen enter and fullscreen exit events (which use the
 // same histogram ID) overlap. That causes TelemetryStopwatch to log an
 // error.
 SimpleTest.ignoreAllUncaughtExceptions(true);
 
-const ADDON_FILE_URI = "http://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/amosigned.xpi";
-
-const ADDON_EVENTS = [
-  "addon-install-blocked",
-  "addon-install-blocked-silent",
-  "addon-install-complete",
-  "addon-install-confirmation",
-  "addon-install-disabled",
-  "addon-install-failed",
-  "addon-install-origin-blocked",
-  "addon-install-started",
-  "addon-progress",
-  "addon-webext-permissions",
-  "xpinstall-disabled",
-];
-
-/**
- * Registers observers for addon installation events and resolves promise on first matching event
- */
-function waitForNextAddonEvent() {
-  return Promise.race(ADDON_EVENTS.map( async (eventStr) => {
-    await TestUtils.topicObserved(eventStr);
-    return eventStr;
-  }));
-}
-
 /**
  * Spawns content task in browser to enter / leave fullscreen
  * @param browser - Browser to use for JS fullscreen requests
  * @param {Boolean} fullscreenState - true to enter fullscreen, false to leave
  */
 function changeFullscreen(browser, fullscreenState) {
   return ContentTask.spawn(browser, fullscreenState, async function(state) {
     if (state) {
       await content.document.body.requestFullscreen();
     } else {
       await content.document.exitFullscreen();
     }
   });
 }
 
+function triggerInstall(browser, trigger) {
+  return ContentTask.spawn(browser, trigger, async function(trigger) {
+    content.InstallTrigger.install(trigger);
+  });
+}
+
 // This tests if addon installation is blocked when requested in fullscreen
 add_task(async function testFullscreenBlockAddonInstallPrompt() {
   // Open example.com
-  await BrowserTestUtils.withNewTab("http://example.com", async function(browser) {
-    await changeFullscreen(browser, true);
+  await BrowserTestUtils.openNewForegroundTab(gBrowser, TESTROOT);
 
-    // Navigate to addon file path
-    BrowserTestUtils.loadURI(browser, ADDON_FILE_URI);
+  // Enter and wait for fullscreen
+  await changeFullscreen(gBrowser.selectedBrowser, true);
+  await TestUtils.waitForCondition(() => window.fullScreen, "Waiting for window to enter fullscreen");
 
-    // Wait for addon manager event and check if installation has been blocked
-    let eventStr = await waitForNextAddonEvent();
-
-    Assert.equal(eventStr, "addon-install-blocked-silent", "Addon installation was blocked");
+  // Trigger addon installation and expect it to be blocked
+  let addonEventPromise = TestUtils.topicObserved("addon-install-blocked-silent");
+  await triggerInstall(gBrowser.selectedBrowser, {"XPI": "amosigned.xpi"});
+  await addonEventPromise;
 
-    // Test if addon installation prompt has been blocked
-    let panelOpened;
-    try {
-      panelOpened = await TestUtils.waitForCondition(() => PopupNotifications.isPanelOpen, 100, 10);
-    } catch (ex) {
-      panelOpened = false;
-    }
-    is(panelOpened, false, "Addon installation prompt not opened");
+  // Test if addon installation prompt has been blocked
+  let panelOpened;
+  try {
+    panelOpened = await TestUtils.waitForCondition(() => PopupNotifications.isPanelOpen, 100, 10);
+  } catch (ex) {
+    panelOpened = false;
+  }
+  is(panelOpened, false, "Addon installation prompt not opened");
 
-    window.fullScreen = false;
-  });
+  window.fullScreen = false;
+  await BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
 
 
 // This tests if the addon install prompt is closed when entering fullscreen
 add_task(async function testFullscreenCloseAddonInstallPrompt() {
-  // Open example.com
-  await BrowserTestUtils.withNewTab("http://example.com", async function(browser) {
-    // Navigate to addon file path
-    BrowserTestUtils.loadURI(browser, ADDON_FILE_URI);
+  let triggers = encodeURIComponent(JSON.stringify({
+    "XPI": "amosigned.xpi",
+  }));
+  let target = TESTROOT + "installtrigger.html?" + triggers;
 
-    // Test if addon installation started
-    let eventStr = await waitForNextAddonEvent();
-
-    Assert.ok(eventStr === "addon-install-started", "Addon installation started");
+  // Open example.com
+  await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com");
 
-    // Test if addon installation prompt is visible
-    await TestUtils.waitForCondition(() => PopupNotifications.isPanelOpen, "Waiting for addon installation prompt to open");
-    Assert.ok(ADDON_EVENTS.some(id => PopupNotifications.getNotification(id, browser) != null), "Opened notification is installation prompt");
-
-    // Test for addon installation prompt close
-    let panelClosePromise = TestUtils.waitForCondition(() => !PopupNotifications.isPanelOpen, "Waiting for addon installation prompt to close");
+  // Trigger addon installation
+  let addonEventPromise = TestUtils.topicObserved("addon-install-blocked");
+  BrowserTestUtils.loadURI(gBrowser.selectedBrowser, target);
+  // Wait for addon install event
+  await addonEventPromise;
 
-    // Switch to fullscreen
-    await changeFullscreen(browser, true);
+  // Test if addon installation prompt is visible
+  await TestUtils.waitForCondition(() => PopupNotifications.isPanelOpen, "Waiting for addon installation prompt to open");
+  Assert.ok(PopupNotifications.getNotification("addon-install-blocked", gBrowser.selectedBrowser) != null, "Opened notification is installation blocked prompt");
 
-    await panelClosePromise;
+  // Switch to fullscreen and test for addon installation prompt close
+  await changeFullscreen(gBrowser.selectedBrowser, true);
+  await TestUtils.waitForCondition(() => window.fullScreen, "Waiting for window to enter fullscreen");
+  await TestUtils.waitForCondition(() => !PopupNotifications.isPanelOpen, "Waiting for addon installation prompt to close");
 
-    window.fullScreen = false;
-  });
+  window.fullScreen = false;
+  await BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });