Skip to content

Commit

Permalink
Bug 1706266 - part 2: Disable some Gecko specific edit commands in re…
Browse files Browse the repository at this point in the history
…lease and beta channel, and all of them in nightly channel r=smaug

The telemetry result is written in bug 1706266 comment 1:
https://bugzilla.mozilla.org/show_bug.cgi?id=1706266#c1

`increasefontsize`, `decreasefontsize`, `gethtml`, `heading` and `readonly` are
obviously not used by web apps in the wild.  Therefore, they can be disabled
in all channels.

`contentReadOnly` and `insertBrOnReturn` are odd.  The usage is really low (less
than 1% of beta users).  However, the number of documents which used the command
is about 1k samples.  The result of the commands are not tiny (making the editor
not editable or changing the behavior at typing `Enter` key in `<div>`, `<p>`,
etc).  Therefore, it's hard to use them in web apps which supports not only
Gecko.  So I guess that they are collected the number of used by automated
tests of somebody because of the constant number in other beta versions.
Perhaps, we should disable it only in Nightly channel for now, and after a
couple of releases, we should try to disable those commands too later.

Depends on D130328

Differential Revision: https://phabricator.services.mozilla.com/D130329
  • Loading branch information
masayuki-nakano committed Nov 5, 2021
1 parent 855a9e3 commit 823d9ec
Show file tree
Hide file tree
Showing 13 changed files with 405 additions and 92 deletions.
49 changes: 49 additions & 0 deletions dom/base/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4901,6 +4901,55 @@ Document::InternalCommandData Document::ConvertToInternalCommand(
if (!sInternalCommandDataHashtable->Get(aHTMLCommandName, &commandData)) {
return InternalCommandData();
}
// Ignore if the command is disabled by a corresponding pref due to Gecko
// specific.
switch (commandData.mCommand) {
case Command::FormatIncreaseFontSize:
MOZ_DIAGNOSTIC_ASSERT(
aHTMLCommandName.LowerCaseEqualsLiteral("increasefontsize"));
if (!StaticPrefs::dom_document_edit_command_increasefontsize_enabled()) {
return InternalCommandData();
}
break;
case Command::FormatDecreaseFontSize:
MOZ_DIAGNOSTIC_ASSERT(
aHTMLCommandName.LowerCaseEqualsLiteral("decreasefontsize"));
if (!StaticPrefs::dom_document_edit_command_decreasefontsize_enabled()) {
return InternalCommandData();
}
break;
case Command::GetHTML:
MOZ_DIAGNOSTIC_ASSERT(aHTMLCommandName.LowerCaseEqualsLiteral("gethtml"));
if (!StaticPrefs::dom_document_edit_command_gethtml_enabled()) {
return InternalCommandData();
}
break;
case Command::FormatBlock:
if (!StaticPrefs::dom_document_edit_command_heading_enabled() &&
aHTMLCommandName.LowerCaseEqualsLiteral("heading")) {
return InternalCommandData();
}
break;
case Command::SetDocumentReadOnly:
if (!StaticPrefs::dom_document_edit_command_contentReadOnly_enabled() &&
aHTMLCommandName.LowerCaseEqualsLiteral("contentreadonly")) {
return InternalCommandData();
}
if (!StaticPrefs::dom_document_edit_command_readonly_enabled() &&
aHTMLCommandName.LowerCaseEqualsLiteral("readonly")) {
return InternalCommandData();
}
break;
case Command::SetDocumentInsertBROnEnterKeyPress:
MOZ_DIAGNOSTIC_ASSERT(
aHTMLCommandName.LowerCaseEqualsLiteral("insertbronreturn"));
if (!StaticPrefs::dom_document_edit_command_insertBrOnReturn_enabled()) {
return InternalCommandData();
}
break;
default:
break;
}
if (!aAdjustedValue) {
// No further work to do
return commandData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var knownFailures = {
},
'a' : {
'createbookmark-0' : true,
'decreasefontsize-0' : !SpecialPowers.getBoolPref("dom.document.edit_command.decreasefontsize.enabled"),
'fontsize-1' : true,
'subscript-1' : true,
'superscript-1' : true,
Expand All @@ -42,5 +43,5 @@ var knownFailures = {
};

function isKnownFailure(type, test, param) {
return (type in knownFailures) && ((test + "-" + param) in knownFailures[type]);
return (type in knownFailures) && knownFailures[type][test + "-" + param];
}
93 changes: 69 additions & 24 deletions editor/libeditor/tests/browserscope/lib/richtext2/currentStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@
*/
const knownFailures = {
value: {
"A-Proposed-CB:name_TEXT-1_SI-dM": true,
"A-Proposed-CB:name_TEXT-1_SI-body": true,
"A-Proposed-CB:name_TEXT-1_SI-div": true,
"A-Proposed-DECFS:2_TEXT-1_SI-dM": !SpecialPowers.getBoolPref("dom.document.edit_command.decreasefontsize.enabled", false),
"A-Proposed-DECFS:2_TEXT-1_SI-body": !SpecialPowers.getBoolPref("dom.document.edit_command.decreasefontsize.enabled", false),
"A-Proposed-DECFS:2_TEXT-1_SI-div": !SpecialPowers.getBoolPref("dom.document.edit_command.decreasefontsize.enabled", false),
"A-Proposed-FS:18px_TEXT-1_SI-dM": true,
"A-Proposed-FS:18px_TEXT-1_SI-body": true,
"A-Proposed-FS:18px_TEXT-1_SI-div": true,
"A-Proposed-FS:large_TEXT-1_SI-dM": true,
"A-Proposed-FS:large_TEXT-1_SI-body": true,
"A-Proposed-FS:large_TEXT-1_SI-div": true,
"A-Proposed-CB:name_TEXT-1_SI-dM": true,
"A-Proposed-CB:name_TEXT-1_SI-body": true,
"A-Proposed-CB:name_TEXT-1_SI-div": true,
"A-Proposed-H:H1_TEXT-1_SC-dM": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"A-Proposed-H:H1_TEXT-1_SC-body": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"A-Proposed-H:H1_TEXT-1_SC-div": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"A-Proposed-INCFS:2_TEXT-1_SI-dM": !SpecialPowers.getBoolPref("dom.document.edit_command.increasefontsize.enabled", false),
"A-Proposed-INCFS:2_TEXT-1_SI-body": !SpecialPowers.getBoolPref("dom.document.edit_command.increasefontsize.enabled", false),
"A-Proposed-INCFS:2_TEXT-1_SI-div": !SpecialPowers.getBoolPref("dom.document.edit_command.increasefontsize.enabled", false),
"AC-Proposed-SUB_TEXT-1_SI-dM": true,
"AC-Proposed-SUB_TEXT-1_SI-body": true,
"AC-Proposed-SUB_TEXT-1_SI-div": true,
Expand Down Expand Up @@ -264,39 +273,63 @@ const knownFailures = {
"I-Proposed-IIMG:._IMG-1_SO-dM": true,
"I-Proposed-IIMG:._IMG-1_SO-body": true,
"I-Proposed-IIMG:._IMG-1_SO-div": true,
"Q-Proposed-UNSELECT_TEXT-1-dM": true,
"Q-Proposed-UNSELECT_TEXT-1-body": true,
"Q-Proposed-UNSELECT_TEXT-1-div": true,
"Q-Proposed-CONTENTREADONLY_TEXT-1-dM": !SpecialPowers.getBoolPref("dom.document.edit_command.contentReadOnly.enabled", false),
"Q-Proposed-CONTENTREADONLY_TEXT-1-body": !SpecialPowers.getBoolPref("dom.document.edit_command.contentReadOnly.enabled", false),
"Q-Proposed-CONTENTREADONLY_TEXT-1-div": !SpecialPowers.getBoolPref("dom.document.edit_command.contentReadOnly.enabled", false),
"Q-Proposed-CREATEBOOKMARK_TEXT-1-dM": true,
"Q-Proposed-CREATEBOOKMARK_TEXT-1-body": true,
"Q-Proposed-CREATEBOOKMARK_TEXT-1-div": true,
"Q-Proposed-UNBOOKMARK_TEXT-1-dM": true,
"Q-Proposed-UNBOOKMARK_TEXT-1-body": true,
"Q-Proposed-UNBOOKMARK_TEXT-1-div": true,
"Q-Proposed-DECREASEFONTSIZE_TEXT-1-dM": !SpecialPowers.getBoolPref("dom.document.edit_command.decreasefontsize.enabled", false),
"Q-Proposed-DECREASEFONTSIZE_TEXT-1-body": !SpecialPowers.getBoolPref("dom.document.edit_command.decreasefontsize.enabled", false),
"Q-Proposed-DECREASEFONTSIZE_TEXT-1-div": !SpecialPowers.getBoolPref("dom.document.edit_command.decreasefontsize.enabled", false),
"Q-Proposed-HEADING_TEXT-1-dM": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"Q-Proposed-HEADING_TEXT-1-body": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"Q-Proposed-HEADING_TEXT-1-div": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"Q-Proposed-INCREASEFONTSIZE_TEXT-1-dM": !SpecialPowers.getBoolPref("dom.document.edit_command.increasefontsize.enabled", false),
"Q-Proposed-INCREASEFONTSIZE_TEXT-1-body": !SpecialPowers.getBoolPref("dom.document.edit_command.increasefontsize.enabled", false),
"Q-Proposed-INCREASEFONTSIZE_TEXT-1-div": !SpecialPowers.getBoolPref("dom.document.edit_command.increasefontsize.enabled", false),
"Q-Proposed-PASTE_TEXT-1-dM": true,
"Q-Proposed-PASTE_TEXT-1-body": true,
"Q-Proposed-PASTE_TEXT-1-div": true,
"QE-Proposed-UNSELECT_TEXT-1-dM": true,
"QE-Proposed-UNSELECT_TEXT-1-body": true,
"QE-Proposed-UNSELECT_TEXT-1-div": true,
"QE-Proposed-REDO_TEXT-1-dM": true,
"QE-Proposed-REDO_TEXT-1-body": true,
"QE-Proposed-REDO_TEXT-1-div": true,
"QE-Proposed-CREATEBOOKMARK_TEXT-1-dM": true,
"QE-Proposed-CREATEBOOKMARK_TEXT-1-body": true,
"QE-Proposed-CREATEBOOKMARK_TEXT-1-div": true,
"QE-Proposed-UNBOOKMARK_TEXT-1-dM": true,
"QE-Proposed-UNBOOKMARK_TEXT-1-body": true,
"QE-Proposed-UNBOOKMARK_TEXT-1-div": true,
"Q-Proposed-UNBOOKMARK_TEXT-1-dM": true,
"Q-Proposed-UNBOOKMARK_TEXT-1-body": true,
"Q-Proposed-UNBOOKMARK_TEXT-1-div": true,
"Q-Proposed-UNSELECT_TEXT-1-dM": true,
"Q-Proposed-UNSELECT_TEXT-1-body": true,
"Q-Proposed-UNSELECT_TEXT-1-div": true,
"QE-Proposed-CONTENTREADONLY_TEXT-1-dM": !SpecialPowers.getBoolPref("dom.document.edit_command.contentReadOnly.enabled", false),
"QE-Proposed-CONTENTREADONLY_TEXT-1-body": !SpecialPowers.getBoolPref("dom.document.edit_command.contentReadOnly.enabled", false),
"QE-Proposed-CONTENTREADONLY_TEXT-1-div": !SpecialPowers.getBoolPref("dom.document.edit_command.contentReadOnly.enabled", false),
"QE-Proposed-COPY_TEXT-1-dM": true,
"QE-Proposed-COPY_TEXT-1-body": true,
"QE-Proposed-COPY_TEXT-1-div": true,
"QE-Proposed-CREATEBOOKMARK_TEXT-1-dM": true,
"QE-Proposed-CREATEBOOKMARK_TEXT-1-body": true,
"QE-Proposed-CREATEBOOKMARK_TEXT-1-div": true,
"QE-Proposed-CUT_TEXT-1-dM": true,
"QE-Proposed-CUT_TEXT-1-body": true,
"QE-Proposed-CUT_TEXT-1-div": true,
"QE-Proposed-DECREASEFONTSIZE_TEXT-1-dM": !SpecialPowers.getBoolPref("dom.document.edit_command.decreasefontsize.enabled", false),
"QE-Proposed-DECREASEFONTSIZE_TEXT-1-body": !SpecialPowers.getBoolPref("dom.document.edit_command.decreasefontsize.enabled", false),
"QE-Proposed-DECREASEFONTSIZE_TEXT-1-div": !SpecialPowers.getBoolPref("dom.document.edit_command.decreasefontsize.enabled", false),
"QE-Proposed-HEADING_TEXT-1-dM": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"QE-Proposed-HEADING_TEXT-1-body": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"QE-Proposed-HEADING_TEXT-1-div": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"QE-Proposed-INCREASEFONTSIZE_TEXT-1-dM": !SpecialPowers.getBoolPref("dom.document.edit_command.increasefontsize.enabled", false),
"QE-Proposed-INCREASEFONTSIZE_TEXT-1-body": !SpecialPowers.getBoolPref("dom.document.edit_command.increasefontsize.enabled", false),
"QE-Proposed-INCREASEFONTSIZE_TEXT-1-div": !SpecialPowers.getBoolPref("dom.document.edit_command.increasefontsize.enabled", false),
"QE-Proposed-PASTE_TEXT-1-dM": true,
"QE-Proposed-PASTE_TEXT-1-body": true,
"QE-Proposed-PASTE_TEXT-1-div": true,
"QE-Proposed-REDO_TEXT-1-dM": true,
"QE-Proposed-REDO_TEXT-1-body": true,
"QE-Proposed-REDO_TEXT-1-div": true,
"QE-Proposed-UNBOOKMARK_TEXT-1-dM": true,
"QE-Proposed-UNBOOKMARK_TEXT-1-body": true,
"QE-Proposed-UNBOOKMARK_TEXT-1-div": true,
"QE-Proposed-UNSELECT_TEXT-1-dM": true,
"QE-Proposed-UNSELECT_TEXT-1-body": true,
"QE-Proposed-UNSELECT_TEXT-1-div": true,
"QS-Proposed-SUB_SPAN.sub-1-SI-dM": true,
"QS-Proposed-SUB_SPAN.sub-1-SI-body": true,
"QS-Proposed-SUB_SPAN.sub-1-SI-div": true,
Expand Down Expand Up @@ -399,9 +432,18 @@ const knownFailures = {
"QV-Proposed-FB_H1-H2.TEXT.H2-1_SM-dM": true,
"QV-Proposed-FB_H1-H2.TEXT.H2-1_SM-body": true,
"QV-Proposed-FB_H1-H2.TEXT.H2-1_SM-div": true,
"QV-Proposed-H_P-1_SC-dM": true,
"QV-Proposed-H_P-1_SC-body": true,
"QV-Proposed-H_P-1_SC-div": true,
"QV-Proposed-H_H1-1_SC-dM": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"QV-Proposed-H_H1-1_SC-body": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"QV-Proposed-H_H1-1_SC-div": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"QV-Proposed-H_H3-1_SC-dM": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"QV-Proposed-H_H3-1_SC-body": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"QV-Proposed-H_H3-1_SC-div": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"QV-Proposed-H_H1-H2-H3-H4-1_SC-dM": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"QV-Proposed-H_H1-H2-H3-H4-1_SC-body": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"QV-Proposed-H_H1-H2-H3-H4-1_SC-div": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"QV-Proposed-H_P-1_SC-dM": SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"QV-Proposed-H_P-1_SC-body": SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"QV-Proposed-H_P-1_SC-div": SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"QV-Proposed-FS_FONTs:fs:l-1_SI-dM": true,
"QV-Proposed-FS_FONTs:fs:l-1_SI-body": true,
"QV-Proposed-FS_FONTs:fs:l-1_SI-div": true,
Expand Down Expand Up @@ -584,6 +626,9 @@ const knownFailures = {
"A-Proposed-CB:name_TEXT-1_SI-dM": true,
"A-Proposed-CB:name_TEXT-1_SI-body": true,
"A-Proposed-CB:name_TEXT-1_SI-div": true,
"A-Proposed-H:H1_TEXT-1_SC-dM": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"A-Proposed-H:H1_TEXT-1_SC-body": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"A-Proposed-H:H1_TEXT-1_SC-div": !SpecialPowers.getBoolPref("dom.document.edit_command.heading.enabled", false),
"AC-Proposed-B_TEXT-1_SI-dM": true,
"AC-Proposed-B_TEXT-1_SI-body": true,
"AC-Proposed-B_TEXT-1_SI-div": true,
Expand Down
4 changes: 2 additions & 2 deletions editor/libeditor/tests/browserscope/test_richtext2.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@
case "div":
var row = results[category.id][group][test_id][structure];
var testName = [category.id, group, test_id, structure].join("-");
(testName in knownFailures.value || testName in platformFailures.value ? todo_is : is)(
(knownFailures.value[testName] || platformFailures.value[testName] ? todo_is : is)(
row.valscore, 1, "Browserscope richtext2 value: " + testName);
(testName in knownFailures.select || testName in platformFailures.select ? todo_is : is)(
(knownFailures.select[testName] || platformFailures.select[testName] ? todo_is : is)(
row.selscore, 1, "Browserscope richtext2 selection: " + testName);
}
}
Expand Down
16 changes: 0 additions & 16 deletions editor/libeditor/tests/test_bug408231.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@
/** Test for Bug 408231 **/

var commandEnabledResults = [
["contentReadOnly", "true"],
["copy", "false"],
["createlink", "true"],
["cut", "false"],
["decreasefontsize", "true"],
["delete", "true"],
["fontname", "true"],
["fontsize", "true"],
["formatblock", "true"],
["heading", "true"],
["hilitecolor", "true"],
["increasefontsize", "true"],
["indent", "true"],
["inserthorizontalrule", "true"],
["inserthtml", "true"],
Expand Down Expand Up @@ -60,18 +56,14 @@
];

var commandIndetermResults = [
["contentReadOnly", "false"],
["copy", "false"],
["createlink", "false"],
["cut", "false"],
["decreasefontsize", "false"],
["delete", "false"],
["fontname", "false"],
["fontsize", "false"],
["formatblock", "false"],
["heading", "false"],
["hilitecolor", "false"],
["increasefontsize", "false"],
["indent", "false"],
["inserthorizontalrule", "false"],
["inserthtml", "false"],
Expand Down Expand Up @@ -100,18 +92,14 @@
];

var commandStateResults = [
["contentReadOnly", "false"],
["copy", "false"],
["createlink", "false"],
["cut", "false"],
["decreasefontsize", "false"],
["delete", "false"],
["fontname", "false"],
["fontsize", "false"],
["formatblock", "false"],
["heading", "false"],
["hilitecolor", "false"],
["increasefontsize", "false"],
["indent", "false"],
["inserthorizontalrule", "false"],
["inserthtml", "false"],
Expand Down Expand Up @@ -140,18 +128,14 @@
];

var commandValueResults = [
["contentReadOnly", ""],
["copy", ""],
["createlink", ""],
["cut", ""],
["decreasefontsize", ""],
["delete", ""],
["fontname", "serif"],
["fontsize", ""],
["formatblock", ""],
["heading", ""],
["hilitecolor", "transparent"],
["increasefontsize", ""],
["indent", ""],
["inserthorizontalrule", ""],
["inserthtml", ""],
Expand Down
19 changes: 11 additions & 8 deletions editor/libeditor/tests/test_bug676401.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,23 @@
}

function IsCommandEnabled(command) {
var enabled;

ensureNobodyHasFocus();

// non-editable div: should return false unless alwaysEnabled
window.getSelection().selectAllChildren(gBlock1);
enabled = document.queryCommandEnabled(command);
is(enabled, alwaysEnabledCommands.includes(command),
"'" + command + "' should not be enabled on a non-editable block.");
is(
document.queryCommandEnabled(command),
alwaysEnabledCommands.includes(command) && document.queryCommandSupported(command),
"'" + command + "' should not be enabled on a non-editable block."
);

// editable div: should return true
// editable div: should return true if it's supported
window.getSelection().selectAllChildren(gBlock2);
enabled = document.queryCommandEnabled(command);
is(enabled, true, "'" + command + "' should be enabled on an editable block.");
is(
document.queryCommandEnabled(command),
document.queryCommandSupported(command),
"'" + command + "' should be enabled on an editable block."
);
}

function runTests() {
Expand Down
20 changes: 16 additions & 4 deletions editor/libeditor/tests/test_bug767684.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,20 @@
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=767684">Mozilla Bug 767684</a>
<div contenteditable>foo<b>bar</b>baz</div>
<script>
getSelection().selectAllChildren(document.querySelector("div"));
document.execCommand("increaseFontSize");
is(document.querySelector("div").innerHTML, "<big>foo<b>bar</b>baz</big>",
"All selected text must be embiggened");
SimpleTest.waitForExplicitFinish();
(async () => {
await SpecialPowers.pushPrefEnv({
set: [
["dom.document.edit_command.increasefontsize.enabled", true]
],
});
getSelection().selectAllChildren(document.querySelector("div"));
document.execCommand("increaseFontSize");
is(
document.querySelector("div").innerHTML,
"<big>foo<b>bar</b>baz</big>",
"All selected text must be embiggened"
);
SimpleTest.finish();
})();
</script>
2 changes: 1 addition & 1 deletion editor/libeditor/tests/test_bug832025.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
sel.collapse(test, test.childNodes.length);

// make it a H1
document.execCommand("heading", false, "H1");
document.execCommand("formatBlock", false, "H1");
// simulate a CR key
sendKey("return");
// insert some text
Expand Down
Loading

0 comments on commit 823d9ec

Please sign in to comment.