Bug 1551490 - Fix test failures with inline options in HTML about:addons. r=kmag, a=jcristau
authorRob Wu <rob@robwu.nl>
Sun, 09 Jun 2019 11:18:54 +0000
changeset 533834 09a47b7d1716348806063aa220db1bf8b50b096c
parent 533833 9688b1081c1db3d73d08418b2e78508ec7778d03
child 533835 9dbc53624d7c680cfa9c7d295b225e500dba0288
push id11438
push userjcristau@mozilla.com
push dateWed, 12 Jun 2019 17:34:20 +0000
treeherdermozilla-beta@a2fc7a9510bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag, jcristau
bugs1551490
milestone68.0
Bug 1551490 - Fix test failures with inline options in HTML about:addons. r=kmag, a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D34078
browser/components/extensions/test/browser/browser_ext_optionsPage_modals.js
browser/components/extensions/test/browser/browser_ext_optionsPage_popups.js
browser/components/extensions/test/browser/head.js
toolkit/components/extensions/ExtensionPolicyService.cpp
toolkit/mozapps/extensions/test/browser/browser_html_options_ui.js
toolkit/mozapps/extensions/test/browser/browser_inlinesettings_browser.js
toolkit/mozapps/extensions/test/browser/browser_webext_options.js
toolkit/mozapps/extensions/test/browser/browser_webext_options_addon_reload.js
--- a/browser/components/extensions/test/browser/browser_ext_optionsPage_modals.js
+++ b/browser/components/extensions/test/browser/browser_ext_optionsPage_modals.js
@@ -59,18 +59,17 @@ add_task(async function test_tab_options
       // testcase runs after the dialog gets opened.
       SimpleTest.executeSoon(resolve);
     }, true);
   });
 
   info("Wait the options_ui modal to be opened");
   await onceModalOpened;
 
-  const optionsBrowser = gBrowser.selectedBrowser.contentDocument
-                                 .getElementById("addon-options");
+  const optionsBrowser = getInlineOptionsBrowser(gBrowser.selectedBrowser);
 
   let stack;
 
   // For remote extensions, the stack that contains the tabmodalprompt elements
   // is the parent of the extensions options_ui browser element, otherwise it would
   // be the parent of the currently selected tabbrowser's browser.
   if (optionsBrowser.isRemoteBrowser) {
     stack = optionsBrowser.parentNode;
--- a/browser/components/extensions/test/browser/browser_ext_optionsPage_popups.js
+++ b/browser/components/extensions/test/browser/browser_ext_optionsPage_popups.js
@@ -76,17 +76,17 @@ add_task(async function test_tab_options
   });
 
   const aboutAddonsTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:addons");
 
   await extension.startup();
 
   const pageUrl = await extension.awaitMessage("options-page:loaded");
 
-  const optionsBrowser = gBrowser.selectedBrowser.contentDocument.getElementById("addon-options");
+  const optionsBrowser = getInlineOptionsBrowser(gBrowser.selectedBrowser);
 
   const contentAreaContextMenu = await openContextMenuInOptionsPage(optionsBrowser);
 
   let contextMenuItemIds = [
     "context-openlinkintab",
     "context-openlinkprivate",
     "context-copylink",
   ];
@@ -175,17 +175,17 @@ add_task(async function overrideContext_
     },
   });
 
   const aboutAddonsTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:addons");
 
   await extension.startup();
   await extension.awaitMessage("options-page:loaded");
 
-  const optionsBrowser = gBrowser.selectedBrowser.contentDocument.getElementById("addon-options");
+  const optionsBrowser = getInlineOptionsBrowser(gBrowser.selectedBrowser);
   const contentAreaContextMenu = await openContextMenuInOptionsPage(optionsBrowser);
 
   await extension.awaitMessage("contextmenu-overridden");
 
   const allVisibleMenuItems = Array.from(contentAreaContextMenu.children).filter(elem => {
     return !elem.hidden;
   }).map(elem => elem.id);
 
--- a/browser/components/extensions/test/browser/head.js
+++ b/browser/components/extensions/test/browser/head.js
@@ -12,16 +12,17 @@
  *          toggleBookmarksToolbar
  *          openContextMenu closeContextMenu
  *          openContextMenuInSidebar openContextMenuInPopup
  *          openExtensionContextMenu closeExtensionContextMenu
  *          openActionContextMenu openSubmenu closeActionContextMenu
  *          openTabContextMenu closeTabContextMenu
  *          openToolsMenu closeToolsMenu
  *          imageBuffer imageBufferFromDataURI
+ *          getInlineOptionsBrowser
  *          getListStyleImage getPanelForNode
  *          awaitExtensionPanel awaitPopupResize
  *          promiseContentDimensions alterContent
  *          promisePrefChangeObserved openContextMenuInFrame
  *          promiseAnimationFrame getCustomizableUIPanelID
  *          awaitEvent BrowserWindowIterator
  *          navigateTab historyPushState promiseWindowRestored
  *          getIncognitoWindow startIncognitoMonitorExtension
@@ -115,16 +116,23 @@ var focusWindow = async function focusWi
 function imageBufferFromDataURI(encodedImageData) {
   let decodedImageData = atob(encodedImageData);
   return Uint8Array.from(decodedImageData, byte => byte.charCodeAt(0)).buffer;
 }
 
 let img = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==";
 var imageBuffer = imageBufferFromDataURI(img);
 
+function getInlineOptionsBrowser(aboutAddonsBrowser) {
+  let {contentWindow} = aboutAddonsBrowser;
+  let htmlBrowser = contentWindow.document.getElementById("html-view-browser");
+  return htmlBrowser.contentDocument.getElementById("addon-inline-options") ||
+    contentWindow.document.getElementById("addon-options");
+}
+
 function getListStyleImage(button) {
   let style = button.ownerGlobal.getComputedStyle(button);
 
   let match = /^url\("(.*)"\)$/.exec(style.listStyleImage);
 
   return match && match[1];
 }
 
--- a/toolkit/components/extensions/ExtensionPolicyService.cpp
+++ b/toolkit/components/extensions/ExtensionPolicyService.cpp
@@ -413,28 +413,35 @@ void ExtensionPolicyService::CheckReques
 }
 
 static bool CheckParentFrames(nsPIDOMWindowOuter* aWindow,
                               WebExtensionPolicy& aPolicy) {
   nsCOMPtr<nsIURI> aboutAddons;
   if (NS_FAILED(NS_NewURI(getter_AddRefs(aboutAddons), "about:addons"))) {
     return false;
   }
+  nsCOMPtr<nsIURI> htmlAboutAddons;
+  if (NS_FAILED(
+          NS_NewURI(getter_AddRefs(htmlAboutAddons),
+                    "chrome://mozapps/content/extensions/aboutaddons.html"))) {
+    return false;
+  }
 
   auto* piWin = aWindow;
   while ((piWin = piWin->GetScriptableParentOrNull())) {
     auto* win = nsGlobalWindowOuter::Cast(piWin);
 
     auto* principal = BasePrincipal::Cast(win->GetPrincipal());
     if (nsContentUtils::IsSystemPrincipal(principal)) {
       // The add-on manager is a special case, since it contains extension
       // options pages in same-type <browser> frames.
+      nsIURI* uri = win->GetDocumentURI();
       bool equals;
-      if (NS_SUCCEEDED(win->GetDocumentURI()->Equals(aboutAddons, &equals)) &&
-          equals) {
+      if ((NS_SUCCEEDED(uri->Equals(aboutAddons, &equals)) && equals) ||
+          (NS_SUCCEEDED(uri->Equals(htmlAboutAddons, &equals)) && equals)) {
         return true;
       }
     }
 
     if (principal->AddonPolicy() != &aPolicy) {
       return false;
     }
   }
--- a/toolkit/mozapps/extensions/test/browser/browser_html_options_ui.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_html_options_ui.js
@@ -168,16 +168,17 @@ add_task(async function testInlineOption
 
   is(browser.clientWidth, stack.clientWidth, "The browser width is set again");
   ok(stack.clientWidth > 0, "The stack has a width");
 
   await closeView(win);
   await extension.unload();
 });
 
+// Regression test against bug 1409697
 add_task(async function testCardRerender() {
   let id = "rerender@mochi.test";
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       applications: {gecko: {id}},
       options_ui: {
         page: "options.html",
       },
--- a/toolkit/mozapps/extensions/test/browser/browser_inlinesettings_browser.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_inlinesettings_browser.js
@@ -4,16 +4,23 @@
 /* eslint-disable mozilla/no-arbitrary-setTimeout */
 
 /* globals TestUtils */
 
 let {ExtensionTestCommon} = ChromeUtils.import("resource://testing-common/ExtensionTestCommon.jsm");
 
 ChromeUtils.import("resource://testing-common/ContentTask.jsm", {});
 
+// This test is testing resizing of the inline options in XUL about:addons. The
+// behavior in HTML about:addons is checked in the testInlineOptions task of
+// browser_html_options_ui.js.
+SpecialPowers.pushPrefEnv({
+  set: [["extensions.htmlaboutaddons.enabled", false]],
+});
+
 var gAddon;
 var gOtherAddon;
 var gManagerWindow;
 var gCategoryUtilities;
 
 function installAddon(details) {
   let id = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator)
                                               .generateUUID().number;
--- a/toolkit/mozapps/extensions/test/browser/browser_webext_options.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_webext_options.js
@@ -1,14 +1,20 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 ChromeUtils.import("resource://testing-common/ContentTask.jsm", {});
 
+// This test is testing XUL about:addons UI (the HTML about:addons preferences
+// panel is already tested in browser_html_options_ui.js).
+SpecialPowers.pushPrefEnv({
+  set: [["extensions.htmlaboutaddons.enabled", false]],
+});
+
 // Wrapper to run a test that consists of:
 //  1. opening the add-ons manager viewing the list of extensions
 //  2. installing an extension (using the provider installer callable)
 //  3. opening the preferences panel for the new extension and verifying
 //     that it opens cleanly
 async function runTest(installer) {
   let mgrWindow = await open_manager("addons://list/extension");
 
--- a/toolkit/mozapps/extensions/test/browser/browser_webext_options_addon_reload.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_webext_options_addon_reload.js
@@ -1,15 +1,21 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 const {AddonTestUtils} = ChromeUtils.import("resource://testing-common/AddonTestUtils.jsm");
 const {ExtensionParent} = ChromeUtils.import("resource://gre/modules/ExtensionParent.jsm");
 
+// This test is testing XUL about:addons UI (the HTML about:addons options page
+// is tested by the testCardRerender test in browser_html_options_ui.js).
+SpecialPowers.pushPrefEnv({
+  set: [["extensions.htmlaboutaddons.enabled", false]],
+});
+
 // This test function helps to detect when an addon options browser have been inserted
 // in the about:addons page.
 function waitOptionsBrowserInserted() {
   return new Promise(resolve => {
     async function listener(eventName, browser) {
       // wait for a webextension XUL browser element that is owned by the "about:addons" page.
       if (browser.ownerDocument.location.href == "about:addons") {
         ExtensionParent.apiManager.off("extension-browser-inserted", listener);