Skip to content

Commit 84ecbcd

Browse files
committed
Bug 1851083 - Do not show the attention badge for mv3 extensions requiring the activeTab permission. r=robwu, a=dmeehan
Differential Revision: https://phabricator.services.mozilla.com/D215038
1 parent a5387ec commit 84ecbcd

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

browser/components/extensions/test/browser/browser_ext_originControls.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ async function makeExtension({
4242
);
4343

4444
let manifest = {
45+
name: `Test extension ${id}`,
4546
manifest_version,
4647
browser_specific_settings: { gecko: { id } },
4748
permissions,
@@ -117,11 +118,12 @@ async function makeExtension({
117118
return ext;
118119
}
119120

120-
async function testQuarantinePopup(popup) {
121+
async function testQuarantinePopup(popup, extensionId) {
122+
const addonName = WebExtensionPolicy.getByID(extensionId).name;
121123
let [title, line1, line2] = await l10n.formatMessages([
122124
{
123125
id: "webext-quarantine-confirmation-title",
124-
args: { addonName: "Generated extension" },
126+
args: { addonName },
125127
},
126128
"webext-quarantine-confirmation-line-1",
127129
"webext-quarantine-confirmation-line-2",
@@ -157,12 +159,13 @@ async function testOriginControls(
157159
let nextMenuItemClassName;
158160

159161
switch (contextMenuId) {
160-
case "toolbar-context-menu":
162+
case "toolbar-context-menu": {
161163
let target = `#${CSS.escape(makeWidgetId(extension.id))}-BAP`;
162164
buttonOrWidget = document.querySelector(target).parentElement;
163165
menu = await openChromeContextMenu(contextMenuId, target);
164166
nextMenuItemClassName = "customize-context-manageExtension";
165167
break;
168+
}
166169

167170
case "unified-extensions-context-menu":
168171
await openExtensionsPanel();
@@ -224,7 +227,7 @@ async function testOriginControls(
224227
: "origin-controls-toolbar-button-permission-needed"
225228
: "origin-controls-toolbar-button",
226229
args: {
227-
extensionTitle: "Generated extension",
230+
extensionTitle: `Test extension ${extension.id}`,
228231
},
229232
},
230233
"Correct l10n message."
@@ -270,7 +273,7 @@ async function testOriginControls(
270273

271274
if (quarantinePopup) {
272275
let popup = await quarantinePopup;
273-
await testQuarantinePopup(popup);
276+
await testQuarantinePopup(popup, extension.id);
274277

275278
if (allowQuarantine) {
276279
popup.button.click();
@@ -417,7 +420,7 @@ const originControlsInContextMenu = async options => {
417420
await testOriginControls(ext2, options, {
418421
items: [ACCESS_OPTIONS, WHEN_CLICKED],
419422
selected: 1,
420-
attention: true,
423+
attention: false,
421424
});
422425

423426
// Could access mochi.test when clicked.
@@ -487,7 +490,7 @@ const originControlsInContextMenu = async options => {
487490
await testOriginControls(ext2, options, {
488491
items: [ACCESS_OPTIONS, WHEN_CLICKED],
489492
selected: 1,
490-
attention: true,
493+
attention: false,
491494
quarantined: false,
492495
});
493496

@@ -577,11 +580,15 @@ const originControlsInContextMenu = async options => {
577580

578581
await testOriginControls(ext1, options, { items: [NO_ACCESS] });
579582

580-
// Click alraedy selected options, expect no permission changes.
583+
// Click already selected options, expect no permission changes.
581584
await testOriginControls(ext2, options, {
582585
items: [ACCESS_OPTIONS, WHEN_CLICKED, ALWAYS_ON],
583586
selected: 1,
584587
click: 1,
588+
// This extension has the activeTab permission, but the current tab
589+
// has a tab url that matches one of the extension host permission
590+
// which is not granted yet and so we expect the attention badge
591+
// to be shown.
585592
attention: true,
586593
});
587594
await testOriginControls(ext3, options, {
@@ -602,12 +609,12 @@ const originControlsInContextMenu = async options => {
602609
if (unifiedButton) {
603610
ok(
604611
unifiedButton.hasAttribute("attention"),
605-
"ext2 is WHEN_CLICKED for example.com, show attention indicator."
612+
"ext2 is WHEN_CLICKED and showing the attention indicator for example.com"
606613
);
607614
Assert.deepEqual(
608615
document.l10n.getAttributes(unifiedButton),
609616
UNIFIED_ATTENTION,
610-
"UEB attention for only one extension."
617+
"UEB attention due to ext2 extension showing an attention indicator."
611618
);
612619
}
613620

@@ -727,9 +734,18 @@ add_task(async function originControls_in_unifiedExtensions_contextMenu() {
727734
});
728735

729736
add_task(async function test_attention_dot_when_pinning_extension() {
730-
const extension = await makeExtension({ permissions: ["activeTab"] });
737+
const extension = await makeExtension({
738+
permissions: ["activeTab"],
739+
host_permissions: ["*://mochi.test/*"],
740+
});
731741
await extension.startup();
732742

743+
await ExtensionPermissions.remove(
744+
extension.id,
745+
{ origins: ["*://mochi.test/*"], permissions: [] },
746+
extension.extension
747+
);
748+
733749
const unifiedButton = document.querySelector("#unified-extensions-button");
734750
const extensionWidgetID = AppUiTestInternals.getBrowserActionWidgetId(
735751
extension.id

toolkit/components/extensions/ExtensionPermissions.sys.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,13 @@ export var OriginControls = {
632632
getAttentionState(policy, window) {
633633
if (policy?.manifestVersion >= 3) {
634634
const state = this.getState(policy, window.gBrowser.selectedTab);
635-
// quarantined is always false when the feature is disabled.
635+
// Request attention when the extension cannot access the current tab,
636+
// but has a host permission that could be granted.
637+
// Quarantined is always false when the feature is disabled.
636638
const quarantined = !!state.quarantined;
637639
const attention =
638640
quarantined ||
639-
(!!state.whenClicked && !state.hasAccess && !state.temporaryAccess);
641+
(!!state.alwaysOn && !state.hasAccess && !state.temporaryAccess);
640642

641643
return { attention, quarantined };
642644
}

0 commit comments

Comments
 (0)