Bug 1548383 - Support extensions.getAddons.showPane in HTML discopane r=aswan
authorRob Wu <rob@robwu.nl>
Sat, 11 May 2019 17:14:26 +0000
changeset 532339 5724b63be8ac9c9833bea9c1ab49d58d76db477f
parent 532338 784c0c4b688bde6491539ad89a5f44b939c4fd7e
child 532340 4440662cd0177f3fc3200cff190daed47d71a167
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1548383
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 1548383 - Support extensions.getAddons.showPane in HTML discopane r=aswan Differential Revision: https://phabricator.services.mozilla.com/D30727
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/test/browser/browser.ini
toolkit/mozapps/extensions/test/browser/browser_html_discover_view_prefs.js
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -746,17 +746,17 @@ var gViewController = {
       // shown. Include it in viewObjects so it gets initialized and shutdown.
       this.viewObjects._availableUpdatesSidebar = gUpdatesView;
     } else {
       this.viewObjects.list = gListView;
       this.viewObjects.detail = gDetailView;
       this.viewObjects.updates = gUpdatesView;
     }
 
-    if (useHtmlDiscover) {
+    if (useHtmlDiscover && isDiscoverEnabled()) {
       this.viewObjects.discover = htmlView("discover");
     } else {
       this.viewObjects.discover = gDiscoverView;
     }
 
     for (let type in this.viewObjects) {
       let view = this.viewObjects[type];
       view.initialize();
--- a/toolkit/mozapps/extensions/test/browser/browser.ini
+++ b/toolkit/mozapps/extensions/test/browser/browser.ini
@@ -76,16 +76,17 @@ skip-if = os == "linux" && !debug # Bug 
 skip-if = true # Bug 1449071 - Frequent failures
 [browser_globalwarnings.js]
 [browser_gmpProvider.js]
 skip-if = os == 'linux' && !debug # Bug 1398766
 [browser_html_abuse_report.js]
 [browser_html_detail_view.js]
 [browser_html_discover_view.js]
 [browser_html_discover_view_clientid.js]
+[browser_html_discover_view_prefs.js]
 [browser_html_list_view.js]
 [browser_html_message_bar.js]
 [browser_html_plugins.js]
 skip-if = (os == 'win' && processor == 'aarch64') # aarch64 has no plugin support, bug 1525174 and 1547495
 [browser_html_recent_updates.js]
 [browser_html_updates.js]
 [browser_inlinesettings_browser.js]
 skip-if = os == 'mac' || os == 'linux' # Bug 1483347
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/browser_html_discover_view_prefs.js
@@ -0,0 +1,71 @@
+/* eslint max-len: ["error", 80] */
+"use strict";
+
+const {
+  AddonTestUtils,
+} = ChromeUtils.import("resource://testing-common/AddonTestUtils.jsm");
+
+AddonTestUtils.initMochitest(this);
+const server = AddonTestUtils.createHttpServer();
+const TEST_API_URL = `http://localhost:${server.identity.primaryPort}/discoapi`;
+
+async function checkIfDiscoverVisible(expectVisible) {
+  let requestCount = 0;
+  let requestPromise = new Promise(resolve => {
+    // Overwrites previous request handler, if any.
+    server.registerPathHandler("/discoapi", (request, response) => {
+      ++requestCount;
+      response.write(`{"results": []}`);
+      resolve();
+    });
+  });
+
+  // Open about:addons with default view.
+  let managerWindow = await open_manager(null);
+  let categoryUtilities = new CategoryUtilities(managerWindow);
+
+  is(categoryUtilities.isTypeVisible("discover"), expectVisible,
+    "Visibility of discopane");
+
+  await wait_for_view_load(managerWindow);
+  if (expectVisible) {
+    is(categoryUtilities.selectedCategory, "discover",
+       "Expected discopane as the default view");
+    await requestPromise;
+    is(requestCount, 1, "Expected discovery API request");
+  } else {
+    // The next view (after discopane) is the extension list.
+    is(categoryUtilities.selectedCategory, "extension",
+       "Should fall back to another view when the discopane is disabled");
+    is(requestCount, 0, "Discovery API should not be requested");
+  }
+
+  await close_manager(managerWindow);
+}
+
+add_task(async function setup() {
+  await SpecialPowers.pushPrefEnv({
+    set: [
+      ["extensions.getAddons.discovery.api_url", TEST_API_URL],
+      ["extensions.htmlaboutaddons.discover.enabled", true],
+    ],
+  });
+});
+
+add_task(async function showPane_true() {
+  await SpecialPowers.pushPrefEnv({
+    set: [[PREF_DISCOVER_ENABLED, true]],
+    clear: [[PREF_UI_LASTCATEGORY]],
+  });
+  await checkIfDiscoverVisible(true);
+  await SpecialPowers.popPrefEnv();
+});
+
+add_task(async function showPane_false() {
+  await SpecialPowers.pushPrefEnv({
+    set: [[PREF_DISCOVER_ENABLED, false]],
+    clear: [[PREF_UI_LASTCATEGORY]],
+  });
+  await checkIfDiscoverVisible(false);
+  await SpecialPowers.popPrefEnv();
+});