Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test that formatting commands are rejected for EditContext editor</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<div></div>
<script>
'use strict';
const host = document.querySelector('div');
const editContext = new EditContext({text: host.textContent});
host.editContext = editContext;
function reset() {
host.textContent = 'foo';
host.focus();
getSelection().selectAllChildren(host);
}
let firedEvent;
editContext.addEventListener('textupdate', () => {
firedEvent = 'textupdate';
});
host.addEventListener('beforeinput', () => {
firedEvent = 'beforeinput';
});
document.addEventListener('selectionchange', () => {
firedEvent = 'selectionchange';
});
function checkCommand(command, arg) {
reset();
firedEvent = undefined;
SpecialPowers.doCommand(window, command, arg);
is(firedEvent, undefined, `No events should be fired by ${command} command`);
is(host.innerHTML, 'foo', `DOM should not be affected by ${command} command`);
}
add_task(() => {
const COMMANDS = [
'cmd_bold',
['cmd_fontColor', '#ff00ff'],
['cmd_fontFace', 'serif'],
['cmd_fontSize', '20'],
['cmd_formatBlock', '<div>'],
['cmd_highlight', '#ff00ff'],
'cmd_indent',
'cmd_insertHR',
['cmd_insertHTML', 'abc'],
'cmd_italic',
['cmd_align', 'right'],
'cmd_ol',
'cmd_outdent',
'cmd_removeLinks',
'cmd_removeStyles',
'cmd_redo',
'cmd_strikethrough',
'cmd_subscript',
'cmd_superscript',
'cmd_ul',
'cmd_underline',
'cmd_undo',
];
for (let command of COMMANDS) {
if (typeof command === 'string') {
checkCommand(command);
} else {
checkCommand(command[0], command[1]);
}
}
});
</script>
</body>
</html>