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

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-14 15:49:07 +00:00
Родитель bbb1e5a221
Коммит 4a505cf223
3 изменённых файлов: 102 добавлений и 14 удалений

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

@ -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>
@ -150,9 +150,21 @@
</label>
</div>
</div>
<div class="addon-detail-row addon-detail-help-row" data-l10n-id="addon-detail-private-browsing-help">
<div class="addon-detail-row addon-detail-help-row" data-l10n-id="addon-detail-private-browsing-help" hidden>
<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" hidden>
<label class="text-link" data-l10n-name="detail-private-browsing-learn-more" action="pb-learn-more" aria-role="link" tabindex="0"></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" hidden>
<label class="text-link" data-l10n-name="detail-private-browsing-learn-more" action="pb-learn-more" aria-role="link" tabindex="0"></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";
@ -1168,11 +1169,13 @@ class AddonDetails extends HTMLElement {
this.render();
}
this.deck.addEventListener("view-changed", this);
this.addEventListener("keypress", this);
}
disconnectedCallback() {
this.inlineOptions.destroyBrowser();
this.deck.removeEventListener("view-changed", this);
this.removeEventListener("keypress", this);
}
handleEvent(e) {
@ -1197,6 +1200,11 @@ class AddonDetails extends HTMLElement {
}
break;
}
} else if (e.type == "keypress") {
if (e.keyCode == KeyEvent.DOM_VK_RETURN &&
e.target.getAttribute("action") === "pb-learn-more") {
e.target.click();
}
}
}
@ -1280,19 +1288,29 @@ class AddonDetails extends HTMLElement {
this.querySelector(".addon-detail-row-updates").hidden =
!hasPermission(addon, "upgrade");
let pbRow = this.querySelector(".addon-detail-row-private-browsing");
if (!allowPrivateBrowsingByDefault && addon.type == "extension" &&
addon.incognito != "not_allowed") {
// By default, all private browsing rows are hidden. Possibly show one.
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") {
let pbRowNotAllowed =
this.querySelector(".addon-detail-row-private-browsing-disallowed");
pbRowNotAllowed.hidden = false;
pbRowNotAllowed.nextElementSibling.hidden = false;
} else if (!hasPermission(addon, "change-privatebrowsing")) {
let pbRowRequired =
this.querySelector(".addon-detail-row-private-browsing-required");
pbRowRequired.hidden = false;
pbRowRequired.nextElementSibling.hidden = false;
} else {
let pbRow = this.querySelector(".addon-detail-row-private-browsing");
pbRow.hidden = false;
pbRow.nextElementSibling.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 +1576,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({