Bug 1591501 - Click category to go back to list in about:addons r=rpl
authorMark Striemer <mstriemer@mozilla.com>
Wed, 13 Nov 2019 21:20:05 +0000
changeset 501831 16bc115ecd46ed37ff921ed4273532c16d3b0205
parent 501830 628967f53151659cf2666e15d50f37fd80952d9a
child 501832 7071b1bdd74110deca5dea19250a2d571223d698
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrpl
bugs1591501
milestone72.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 1591501 - Click category to go back to list in about:addons r=rpl Differential Revision: https://phabricator.services.mozilla.com/D51317
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/test/browser/browser.ini
toolkit/mozapps/extensions/test/browser/browser_sidebar_categories.js
toolkit/mozapps/extensions/test/browser/head.js
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -823,29 +823,22 @@ var gCategories = {
       this.node.value = gViewDefault;
     }
     // If the previous node is the discover panel which has since been disabled set to default
     if (this.node.value == "addons://discover/" && !isDiscoverEnabled()) {
       this.node.value = gViewDefault;
     }
 
     this.node.addEventListener("select", () => {
+      // This is needed for keyboard support.
       gViewController.loadView(this.node.selectedItem.value);
     });
-
-    this.node.addEventListener("click", aEvent => {
-      var selectedItem = this.node.selectedItem;
-      if (
-        aEvent.target.localName == "richlistitem" &&
-        aEvent.target == selectedItem
-      ) {
-        var viewId = selectedItem.value;
-
-        gViewController.loadView(viewId);
-      }
+    this.node.addEventListener("click", () => {
+      // This is needed to return from details/shortcuts back to the list view.
+      gViewController.loadView(this.node.selectedItem.value);
     });
   },
 
   shutdown() {
     AddonManager.removeTypeListener(this);
   },
 
   _defineCustomElement() {
--- a/toolkit/mozapps/extensions/test/browser/browser.ini
+++ b/toolkit/mozapps/extensions/test/browser/browser.ini
@@ -94,16 +94,17 @@ skip-if = verify
 [browser_manage_shortcuts_hidden.js]
 [browser_page_options_install_addon.js]
 [browser_page_options_updates.js]
 [browser_panel_item_accesskey.js]
 [browser_pluginprefs.js]
 [browser_reinstall.js]
 [browser_search_bar_focus.js]
 [browser_shortcuts_duplicate_check.js]
+[browser_sidebar_categories.js]
 [browser_task_next_test.js]
 [browser_updateid.js]
 [browser_updatessl.js]
 [browser_webapi.js]
 [browser_webapi_abuse_report.js]
 support-files =
   head_abuse_report.js
 [browser_webapi_access.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/browser_sidebar_categories.js
@@ -0,0 +1,53 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const THEME_ID = "default-theme@mozilla.org";
+
+add_task(async function testClickingSidebarEntriesChangesView() {
+  let win = await loadInitialView("extension");
+  let doc = win.document;
+  let { managerWindow } = win;
+  let themeCategory = managerWindow.document.getElementById("category-theme");
+
+  let assertViewHas = (selector, msg) => ok(doc.querySelector(selector), msg);
+  let assertListView = type =>
+    assertViewHas(`addon-list[type="${type}"]`, `On ${type} list`);
+
+  assertListView("extension");
+
+  let loaded = waitForViewLoad(win);
+  themeCategory.click();
+  await loaded;
+
+  assertListView("theme");
+
+  loaded = waitForViewLoad(win);
+  getAddonCard(win, THEME_ID).click();
+  await loaded;
+
+  ok(!doc.querySelector("addon-list"), "No more addon-list");
+  assertViewHas(
+    `addon-card[addon-id="${THEME_ID}"][expanded]`,
+    "Detail view now"
+  );
+
+  loaded = waitForViewLoad(win);
+  EventUtils.synthesizeMouseAtCenter(
+    themeCategory.firstElementChild,
+    {},
+    managerWindow
+  );
+  await loaded;
+
+  assertListView("theme");
+
+  loaded = waitForViewLoad(win);
+  EventUtils.synthesizeKey("VK_UP", {}, managerWindow);
+  await loaded;
+
+  assertListView("extension");
+
+  await closeView(win);
+});
--- a/toolkit/mozapps/extensions/test/browser/head.js
+++ b/toolkit/mozapps/extensions/test/browser/head.js
@@ -325,18 +325,22 @@ function check_all_in_list(aManager, aId
   for (let inlistItem of inlist) {
     if (!aIds.includes(inlistItem)) {
       ok(false, "Shouldn't have seen " + inlistItem + " in the list");
     }
   }
 }
 
 function get_addon_element(aManager, aId) {
-  const doc = aManager.getHtmlBrowser().contentDocument;
-  return doc.querySelector(`addon-card[addon-id="${aId}"]`);
+  const win = aManager.getHtmlBrowser().contentWindow;
+  return getAddonCard(win, aId);
+}
+
+function getAddonCard(win, id) {
+  return win.document.querySelector(`addon-card[addon-id="${id}"]`);
 }
 
 function wait_for_view_load(
   aManagerWindow,
   aCallback,
   aForceWait,
   aLongerTimeout
 ) {