Bug 1686929 - only show the inspect a11y properties menuitem for devtools users, r=jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D105086
This commit is contained in:
Gijs Kruitbosch 2021-03-01 10:28:01 +00:00
Родитель 6ae3424306
Коммит 109ba19200
5 изменённых файлов: 72 добавлений и 3 удалений

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

@ -620,10 +620,12 @@ class nsContextMenu {
var showInspectA11Y = var showInspectA11Y =
showInspect && showInspect &&
Services.prefs.getBoolPref("devtools.accessibility.enabled", false) && Services.prefs.getBoolPref("devtools.accessibility.enabled", false) &&
this.inTabBrowser &&
Services.prefs.getBoolPref("devtools.enabled", true) && Services.prefs.getBoolPref("devtools.enabled", true) &&
Services.prefs.getBoolPref("devtools.accessibility.enabled", true) && (Services.prefs.getBoolPref("devtools.everOpened", false) ||
!Services.prefs.getBoolPref("devtools.policy.disabled", false); // Note: this is a legacy usecase, we will remove it in bug 1695257,
// once existing users have had time to set devtools.everOpened
// through normal use, and we've passed an ESR cycle (91).
nsContextMenu.DevToolsShim.isDevToolsUser());
this.showItem("context-viewsource", shouldShow); this.showItem("context-viewsource", shouldShow);
this.showItem("inspect-separator", showInspect); this.showItem("inspect-separator", showInspect);

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

@ -15,6 +15,7 @@ support-files =
../../../../../toolkit/components/pdfjs/test/file_pdfjs_test.pdf ../../../../../toolkit/components/pdfjs/test/file_pdfjs_test.pdf
contextmenu_common.js contextmenu_common.js
[browser_contextmenu_inspect.js]
[browser_contextmenu_keyword.js] [browser_contextmenu_keyword.js]
skip-if = toolkit == "gtk" || (os == "win" && processor == "aarch64") # disabled on Linux due to bug 513558, aarch64 due to 1533161 skip-if = toolkit == "gtk" || (os == "win" && processor == "aarch64") # disabled on Linux due to bug 513558, aarch64 due to 1533161
[browser_contextmenu_loadblobinnewtab.js] [browser_contextmenu_loadblobinnewtab.js]

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

@ -0,0 +1,61 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/**
* Check that we show the inspect item(s) as appropriate.
*/
add_task(async function test_contextmenu_inspect() {
await SpecialPowers.pushPrefEnv({
set: [
["devtools.selfxss.count", 0],
["devtools.everOpened", false],
],
});
let contextMenu = document.getElementById("contentAreaContextMenu");
await BrowserTestUtils.withNewTab("about:blank", async browser => {
for (let [pref, value, expectation] of [
["devtools.selfxss.count", 10, true],
["devtools.selfxss.count", 0, false],
["devtools.everOpened", false, false],
["devtools.everOpened", true, true],
]) {
await SpecialPowers.pushPrefEnv({
set: [["devtools.selfxss.count", value]],
});
is(contextMenu.state, "closed", "checking if popup is closed");
let promisePopupShown = BrowserTestUtils.waitForEvent(
contextMenu,
"popupshown"
);
let promisePopupHidden = BrowserTestUtils.waitForEvent(
contextMenu,
"popuphidden"
);
await BrowserTestUtils.synthesizeMouse(
"body",
2,
2,
{ type: "contextmenu", button: 2 },
browser
);
await promisePopupShown;
let inspectItem = document.getElementById("context-inspect");
ok(
!inspectItem.hidden,
`Inspect should be shown (pref ${pref} is ${value}).`
);
let inspectA11y = document.getElementById("context-inspect-a11y");
is(
inspectA11y.hidden,
!expectation,
`A11y should be ${
expectation ? "visible" : "hidden"
} (pref ${pref} is ${value}).`
);
contextMenu.hidePopup();
await promisePopupHidden;
}
});
});

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

@ -1422,6 +1422,7 @@ Toolbox.prototype = {
}, },
_pingTelemetry: function() { _pingTelemetry: function() {
Services.prefs.setBoolPref("devtools.everOpened", true);
this.telemetry.toolOpened("toolbox", this.sessionId, this); this.telemetry.toolOpened("toolbox", this.sessionId, this);
this.telemetry this.telemetry

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

@ -191,6 +191,10 @@ const DevToolsShim = {
this._gDevTools.restoreDevToolsSession(session); this._gDevTools.restoreDevToolsSession(session);
}, },
isDevToolsUser() {
return DevtoolsStartup.isDevToolsUser();
},
/** /**
* Called from nsContextMenu.js in mozilla-central when using the Inspect Accessibility * Called from nsContextMenu.js in mozilla-central when using the Inspect Accessibility
* context menu item. * context menu item.