Bug 1557792 - Show missing private browsing rows in about:addons r=mixedpuppy

For parity with the XUL about:addons page, this commit adds missing rows
to the details view:

- Bug 1557792 - incognito not_allowed should show "Not Allowed in Private Windows"

- Bug 1551947 - extensions with locked private browsing flag should not
  show inputs to control the flag, but "Requires Access to Private Windows"

Differential Revision: https://phabricator.services.mozilla.com/D34936

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Rob Wu 2019-06-13 22:27:30 +00:00
Родитель ea1a345650
Коммит f404754f4b
4 изменённых файлов: 94 добавлений и 12 удалений

Просмотреть файл

@ -310,6 +310,10 @@ addon-details {
padding-bottom: 0;
}
.addon-detail-row-has-help[hidden] + .addon-detail-help-row {
display: none;
}
.addon-detail-row input[type="checkbox"] {
margin: 0;
}

Просмотреть файл

@ -137,7 +137,7 @@
</label>
</div>
</div>
<div class="addon-detail-row addon-detail-row-has-help addon-detail-row-private-browsing">
<div class="addon-detail-row addon-detail-row-has-help addon-detail-row-private-browsing" hidden>
<label data-l10n-id="detail-private-browsing-label"></label>
<div>
<label>
@ -153,6 +153,18 @@
<div class="addon-detail-row addon-detail-help-row" data-l10n-id="addon-detail-private-browsing-help">
<a target="_blank" data-l10n-name="learn-more"></a>
</div>
<div class="addon-detail-row addon-detail-row-has-help addon-detail-row-private-browsing-disallowed" hidden>
<label data-l10n-id="detail-private-disallowed-label"></label>
</div>
<div class="addon-detail-row addon-detail-help-row" data-l10n-id="detail-private-disallowed-description">
<label class="text-link" data-l10n-name="detail-private-browsing-learn-more" data-l10n-args="action" action="pb-learn-more"></label>
</div>
<div class="addon-detail-row addon-detail-row-has-help addon-detail-row-private-browsing-required" hidden>
<label class="learn-more-label-link" data-l10n-id="detail-private-required-label"></label>
</div>
<div class="addon-detail-row addon-detail-help-row" data-l10n-id="detail-private-required-description">
<label class="text-link" data-l10n-name="detail-private-browsing-learn-more" data-l10n-args="action" action="pb-learn-more"></label>
</div>
<div class="addon-detail-row addon-detail-row-author">
<label data-l10n-id="addon-detail-author-label"></label>
<a target="_blank" data-telemetry-name="author"></a>

Просмотреть файл

@ -63,6 +63,7 @@ const PERMISSION_MASKS = {
"never-activate": AddonManager.PERM_CAN_DISABLE,
uninstall: AddonManager.PERM_CAN_UNINSTALL,
upgrade: AddonManager.PERM_CAN_UPGRADE,
"change-privatebrowsing": AddonManager.PERM_CAN_CHANGE_PRIVATEBROWSING_ACCESS,
};
const PREF_DISCOVERY_API_URL = "extensions.getAddons.discovery.api_url";
@ -1280,19 +1281,26 @@ class AddonDetails extends HTMLElement {
this.querySelector(".addon-detail-row-updates").hidden =
!hasPermission(addon, "upgrade");
// By default, all private browsing rows are hidden. Possibly show one.
let pbRow = this.querySelector(".addon-detail-row-private-browsing");
if (!allowPrivateBrowsingByDefault && addon.type == "extension" &&
addon.incognito != "not_allowed") {
let pbRowNotAllowed =
this.querySelector(".addon-detail-row-private-browsing-disallowed");
let pbRowRequired =
this.querySelector(".addon-detail-row-private-browsing-required");
if (allowPrivateBrowsingByDefault || addon.type != "extension") {
// All add-addons of this type are allowed in private browsing mode, so
// do not show any UI.
} else if (addon.incognito == "not_allowed") {
pbRowNotAllowed.hidden = false;
} else if (!hasPermission(addon, "change-privatebrowsing")) {
pbRowRequired.hidden = false;
} else {
pbRow.hidden = false;
let isAllowed = await isAllowedInPrivateBrowsing(addon);
pbRow.querySelector(`[value="${isAllowed ? 1 : 0}"]`).checked = true;
let learnMore = pbRow.nextElementSibling
.querySelector('a[data-l10n-name="learn-more"]');
learnMore.href = SUPPORT_URL + "extensions-pb";
} else {
// Remove the help row, which is right after the settings.
pbRow.nextElementSibling.hidden = true;
// Then remove the actual settings.
pbRow.hidden = true;
}
// Author.
@ -1558,6 +1566,10 @@ class AddonCard extends HTMLElement {
e.target.getAttribute("url"), "tab");
}
break;
case "pb-learn-more":
windowRoot.ownerGlobal.openTrustedLinkIn(
SUPPORT_URL + "extensions-pb", "tab");
break;
default:
// Handle a click on the card itself.
if (!this.expanded) {

Просмотреть файл

@ -91,6 +91,7 @@ function checkIsModifiable(expected) {
} else {
is_element_hidden(getHtmlElem(".addon-detail-row-private-browsing"), "Private browsing should be hidden");
}
checkHelpRow(".addon-detail-row-private-browsing", expected);
return;
}
if (expected) {
@ -105,10 +106,12 @@ function checkIsModifiable(expected) {
// Check whether the details view shows that private browsing is forcibly disallowed.
function checkIsDisallowed(expected) {
if (gManagerWindow.useHtmlViews) {
// TODO bug 1557792: Show when private browsing is forcibly disallowed.
if (expected) {
is_element_hidden(getHtmlElem(".addon-detail-row-private-browsing"), "Private browsing cannot both be allowed and disallowed");
is_element_visible(getHtmlElem(".addon-detail-row-private-browsing-disallowed"), "Private browsing should be disallowed");
} else {
is_element_hidden(getHtmlElem(".addon-detail-row-private-browsing-disallowed"), "Private browsing should not be disallowed");
}
checkHelpRow(".addon-detail-row-private-browsing-disallowed", expected);
return;
}
if (expected) {
@ -123,10 +126,12 @@ function checkIsDisallowed(expected) {
// Check whether the details view shows that private browsing is forcibly allowed.
function checkIsRequired(expected) {
if (gManagerWindow.useHtmlViews) {
// TODO bug 1557792: Show when private browsing is forcibly allowed.
if (expected) {
is_element_hidden(getHtmlElem(".addon-detail-row-private-browsing"), "Private browsing cannot both be mutable and required");
is_element_visible(getHtmlElem(".addon-detail-row-private-browsing-required"), "Private browsing should be required");
} else {
is_element_hidden(getHtmlElem(".addon-detail-row-private-browsing-required"), "Private browsing should not be required");
}
checkHelpRow(".addon-detail-row-private-browsing-required", expected);
return;
}
if (expected) {
@ -138,6 +143,16 @@ function checkIsRequired(expected) {
}
}
function checkHelpRow(selector, expected) {
let helpRow = getHtmlElem(`${selector} + .addon-detail-help-row`);
if (expected) {
is_element_visible(helpRow, `Help row should be shown: ${selector}`);
is_element_visible(helpRow.querySelector("a, [action='pb-learn-more']"), "Expected learn more link");
} else {
is_element_hidden(helpRow, `Help row should be hidden: ${selector}`);
}
}
async function hasPrivateAllowed(id) {
let perms = await ExtensionPermissions.get(id);
return perms.permissions.length == 1 &&
@ -491,9 +506,48 @@ async function test_addon_postinstall_incognito_hidden_checkbox(withHtmlViews) {
await addon.uninstall();
}
// It is not possible to create a privileged add-on and install it, so just
// simulate an installed privileged add-on and check the UI.
await test_incognito_of_privileged_addons();
// No popPrefEnv because of bug 1557397.
}
// Checks that the private browsing flag of privileged add-ons cannot be modified.
async function test_incognito_of_privileged_addons() {
// In mochitests it is not possible to create and install a privileged add-on
// or a system add-on, so create a mock provider that simulates privileged
// add-ons (which lack the PERM_CAN_CHANGE_PRIVATEBROWSING_ACCESS permission).
let provider = new MockProvider();
provider.createAddons([{
name: "default incognito",
id: "default-incognito@mock",
incognito: "spanning", // This is the default.
// Anything without the PERM_CAN_CHANGE_PRIVATEBROWSING_ACCESS permission.
permissions: 0,
}, {
name: "not_allowed incognito",
id: "not-allowed-incognito@mock",
incognito: "not_allowed",
// Anything without the PERM_CAN_CHANGE_PRIVATEBROWSING_ACCESS permission.
permissions: 0,
}]);
gManagerWindow = await open_manager("addons://detail/default-incognito%40mock");
checkIsModifiable(false);
checkIsRequired(true);
checkIsDisallowed(false);
await close_manager(gManagerWindow);
gManagerWindow = await open_manager("addons://detail/not-allowed-incognito%40mock");
checkIsModifiable(false);
checkIsRequired(false);
checkIsDisallowed(true);
await close_manager(gManagerWindow);
provider.unregister();
}
add_task(async function test_badge_and_toggle_incognito_on_XUL_aboutaddons() {
await SpecialPowers.pushPrefEnv({