Commit f0739b12 authored by Gurzau Raul's avatar Gurzau Raul
Browse files

Backed out changeset 10c62a0c06f0 (bug 1580962) for remove button related...

Backed out changeset 10c62a0c06f0 (bug 1580962) for remove button related failures at browser_policy_extensions.js on a CLOSED TREE.
parent b17cb9e0
......@@ -393,8 +393,6 @@ addon-options-button =
## Add-on actions
report-addon-button = Report
remove-addon-button = Remove
# The link will always be shown after the other text.
remove-addon-disabled-button = Can’t Be Removed <a data-l10n-name="link">Why?</a>
disable-addon-button = Disable
enable-addon-button = Enable
preferences-addon-button =
......
......@@ -235,7 +235,7 @@
<template name="panel-item">
<link rel="stylesheet" href="chrome://mozapps/content/extensions/panel-item.css">
<button><slot></slot></button><slot name="support-link"></slot>
<button><slot></slot></button>
</template>
<template name="taar-notice">
......
......@@ -715,22 +715,26 @@ class PanelList extends HTMLElement {
// If the menu is opened with the mouse, the active element might be
// somewhere else in the document. In that case we should ignore it
// to avoid walking unrelated DOM nodes.
this.focusWalker.currentNode = this.contains(document.activeElement)
this.walker.currentNode = this.contains(document.activeElement)
? document.activeElement
: this;
let nextItem = moveForward
? this.focusWalker.nextNode()
: this.focusWalker.previousNode();
? this.walker.nextNode()
: this.walker.previousNode();
// If the next item wasn't found, try looping to the top/bottom.
if (!nextItem) {
this.focusWalker.currentNode = this;
this.walker.currentNode = this;
if (moveForward) {
nextItem = this.focusWalker.firstChild();
nextItem = this.walker.firstChild();
} else {
nextItem = this.focusWalker.lastChild();
nextItem = this.walker.lastChild();
}
}
if (nextItem) {
nextItem.focus();
}
break;
} else if (e.key === "Escape") {
let { triggeringEvent } = this;
......@@ -764,44 +768,19 @@ class PanelList extends HTMLElement {
}
}
/**
* A TreeWalker that can be used to focus elements. The returned element will
* be the element that has gained focus based on the requested movement
* through the tree.
*
* Example:
*
* this.focusWalker.currentNode = this;
* // Focus and get the first focusable child.
* let focused = this.focusWalker.nextNode();
* // Focus the second focusable child.
* this.focusWalker.nextNode();
*/
get focusWalker() {
if (!this._focusWalker) {
this._focusWalker = document.createTreeWalker(
this,
NodeFilter.SHOW_ELEMENT,
{
acceptNode: node => {
// No need to look at hidden nodes.
if (node.hidden) {
return NodeFilter.FILTER_REJECT;
}
// Focus the node, if it worked then this is the node we want.
node.focus();
if (node === document.activeElement) {
return NodeFilter.FILTER_ACCEPT;
}
get walker() {
if (!this._walker) {
this._walker = document.createTreeWalker(this, NodeFilter.SHOW_ELEMENT, {
acceptNode: node => {
if (node.disabled || node.hidden || node.localName !== "panel-item") {
return NodeFilter.FILTER_REJECT;
}
// Continue into child nodes if the parent couldn't be focused.
return NodeFilter.FILTER_SKIP;
},
}
);
return NodeFilter.FILTER_ACCEPT;
},
});
}
return this._focusWalker;
return this._walker;
}
async onShow() {
......@@ -818,8 +797,11 @@ class PanelList extends HTMLElement {
triggeringEvent &&
triggeringEvent.mozInputSource === MouseEvent.MOZ_SOURCE_KEYBOARD
) {
this.focusWalker.currentNode = this;
this.focusWalker.nextNode();
this.walker.currentNode = this;
let firstItem = this.walker.nextNode();
if (firstItem) {
firstItem.focus();
}
}
this.sendEvent("shown");
......@@ -913,27 +895,7 @@ class AddonOptions extends HTMLElement {
setElementState(el, card, addon, updateInstall) {
switch (el.getAttribute("action")) {
case "remove":
if (hasPermission(addon, "uninstall")) {
// Regular add-on that can be uninstalled.
el.disabled = false;
el.hidden = false;
document.l10n.setAttributes(el, "remove-addon-button");
} else if (addon.isBuiltin) {
// Likely the built-in themes, can't be removed, that's fine.
el.hidden = true;
} else {
// Likely sideloaded, mention that it can't be removed with a link.
el.hidden = false;
el.disabled = true;
if (!el.querySelector('[slot="support-link"]')) {
let link = document.createElement("a", { is: "support-link" });
link.setAttribute("data-l10n-name", "link");
link.setAttribute("support-page", "cant-remove-addon");
link.setAttribute("slot", "support-link");
el.appendChild(link);
document.l10n.setAttributes(el, "remove-addon-disabled-button");
}
}
el.hidden = !hasPermission(addon, "uninstall");
break;
case "report":
el.hidden = !isAbuseReportSupported(addon);
......
:host {
display: flex;
align-items: center;
}
::slotted(a) {
margin-inline-end: 12px;
}
:host([checked]) {
--icon: url("chrome://global/skin/icons/check.svg");
-moz-context-properties: fill;
......
......@@ -8,11 +8,6 @@ AddonTestUtils.initMochitest(this);
let promptService;
const SUPPORT_URL = Services.urlFormatter.formatURL(
Services.prefs.getStringPref("app.support.baseURL")
);
const REMOVE_SUMO_URL = SUPPORT_URL + "cant-remove-addon";
const SECTION_INDEXES = {
enabled: 0,
disabled: 1,
......@@ -39,10 +34,7 @@ function waitForThemeChange(list) {
return BrowserTestUtils.waitForEvent(list, "move", () => ++moveCount == 2);
}
let mockProvider;
add_task(async function setup() {
mockProvider = new MockProvider();
add_task(async function enableHtmlViews() {
promptService = mockPromptService();
Services.telemetry.clearEvents();
});
......@@ -136,9 +128,6 @@ add_task(async function testExtensionList() {
"remove-addon-button",
"The button has the remove label"
);
// There is a support link when the add-on isn't removeable, verify we don't
// always include one.
ok(!removeButton.querySelector("a"), "There isn't a link in the item");
// Remove but cancel.
let cancelled = BrowserTestUtils.waitForEvent(card, "remove-cancelled");
......@@ -747,48 +736,6 @@ add_task(async function testBuiltInThemeButtons() {
await closeView(win);
});
add_task(async function testSideloadRemoveButton() {
const id = "sideload@mochi.test";
mockProvider.createAddons([
{
id,
name: "Sideloaded",
permissions: 0,
},
]);
let win = await loadInitialView("extension");
let doc = win.document;
let card = getCardByAddonId(doc, id);
let moreOptionsPanel = card.querySelector("panel-list");
let panelOpened = BrowserTestUtils.waitForEvent(moreOptionsPanel, "shown");
moreOptionsPanel.show();
await panelOpened;
// Verify the remove button is visible with a SUMO link.
let removeButton = card.querySelector('[action="remove"]');
ok(removeButton.disabled, "Remove is disabled");
ok(!removeButton.hidden, "Remove is visible");
let sumoLink = removeButton.querySelector("a");
ok(sumoLink, "There's a link");
is(
doc.l10n.getAttributes(removeButton).id,
"remove-addon-disabled-button",
"The can't remove text is shown"
);
sumoLink.focus();
is(doc.activeElement, sumoLink, "The link can be focused");
let newTabOpened = BrowserTestUtils.waitForNewTab(gBrowser, REMOVE_SUMO_URL);
sumoLink.click();
BrowserTestUtils.removeTab(await newTabOpened);
await closeView(win);
});
add_task(async function testOnlyTypeIsShown() {
let win = await loadInitialView("theme");
let doc = win.document;
......@@ -862,6 +809,8 @@ add_task(async function testExtensionGenericIcon() {
});
add_task(async function testSectionHeadingKeys() {
let mockProvider = new MockProvider();
mockProvider.createAddons([
{
id: "test-theme",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment