chromium/third_party/blink/web_tests/editing/execCommand/query-command-state.html

<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
const isMac = navigator.platform.indexOf('Mac') === 0;
function query_command_test(command, contents, expectedStates) {
  const expectedState = expectedStates[isMac ? 'mac' : 'other'];
  selection_test(
      `<div contenteditable>${contents}</div>`,
      selection => {
        assert_equals(
            selection.document.queryCommandState(command),
            expectedState,
            "State");
        assert_equals(
            selection.document.queryCommandValue(command),
            expectedState.toString(),
            "Value");
      },
      `<div contenteditable>${contents}</div>`,
      `queryCommandState(${command}) returns ${expectedState} when selecting ${contents}`);
}

query_command_test(
    'bold', '^hello|',
    {mac: false, other: false});
query_command_test(
    'bold', '^<i>hello</i>|',
    {mac: false, other: false});
query_command_test(
    'bold', '^<b>hello</b>|',
    {mac: true, other: true});
query_command_test(
    'bold', '^hello <b>world</b>|',
    {mac: false, other: false});
query_command_test(
    'bold', '^<b>hello</b> world|',
    {mac: true, other: false});
query_command_test(
    'bold', 'hello <b>^world</b> |Webkit',
    {mac: true, other: false});
query_command_test(
    'bold', '<b>hello</b> ^world| <b>WebKit</b>',
    {mac: false, other: false});
query_command_test(
    'bold', '<i>hello <b>^world</b> |WebKit</i>',
    {mac: true, other: false});
query_command_test(
    'bold', '<b>hello <i>^hello|</i> WebKit</b>',
    {mac: true, other: true});
query_command_test(
    'bold', '<b><div>hello <i>^hello|</i> WebKit</div></b>',
    {mac: true, other: true});
query_command_test(
    'bold', '^<b style="font-weight: normal;">hello</b>|',
    {mac: false, other: false});
query_command_test(
    'bold', '^<i style="font-weight: bold;">hello</i>|',
    {mac: true, other: true});
query_command_test(
    'bold', '^<b>hello</b> world <b>WebKit</b>|',
    {mac: true, other: false});
query_command_test(
    'bold', '^<b>hello</b><b> world</b>|',
    {mac: true, other: true});
query_command_test(
    'bold', '^<div><b>hello</b></div><p><b> WebKit</b></p>|',
    {mac: true, other: true});
query_command_test(
    'italic', '^hello|',
    {mac: false, other: false});
query_command_test(
    'italic', '^<b>hello</b>|',
    {mac: false, other: false});
query_command_test(
    'italic', '^<i>hello</i>|',
    {mac: true, other: true});
query_command_test(
    'italic', '^<i>hello</i> world|',
    {mac: true, other: false});
query_command_test(
    'italic', '^hello <i>world</i>|',
    {mac: false, other: false});
query_command_test(
    'italic', '^<i><div>hello world</div></i>|',
    {mac: true, other: true});
query_command_test(
    'italic',
    '^<div style="font-style: italic">hello <span style="font-style: normal;">hello</span></div>|',
    {mac: true, other: false});
query_command_test(
    'subscript', '^hello|',
    {mac: false, other: false});
query_command_test(
    'subscript', '^<sup>hello</sup>|',
    {mac: false, other: false});
query_command_test(
    'subscript', '^<sub>hello</sub>|',
    {mac: true, other: true});
query_command_test(
    'subscript', '^<sub>hello</sub> world|',
    {mac: true, other: false});
query_command_test(
    'subscript', '^hello <sub>world</sub>|',
    {mac: false, other: false});
query_command_test(
    'subscript', '^<div style="vertical-align: sub;">hello world</div>|',
    {mac: true, other: true});
query_command_test(
    'subscript', 'hello <span style="vertical-align: sub;">^world</span> |WebKit',
    {mac: true, other: false});
query_command_test(
    'superscript', '^hello|',
    {mac: false, other: false});
query_command_test(
    'superscript', '^<sub>hello</sub>|',
    {mac: false, other: false});
query_command_test(
    'superscript', '^<sup>hello</sup>|',
    {mac: true, other: true});
query_command_test(
    'superscript', '^<sup>hello</sup> world|',
    {mac: true, other: false});
query_command_test(
    'superscript', '^hello <sup>world</sup>|',
    {mac: false, other: false});
query_command_test(
    'superscript',
    '^<span style="vertical-align: super;">hello</span><span style="vertical-align: sub;">world</span>|',
    {mac: true, other: false});
query_command_test(
    'superscript', '^hello<span style="vertical-align: super;">world</span>|',
    {mac: false, other: false});
query_command_test(
    'underline', '^hello|',
    {mac: false, other: false});
query_command_test(
    'underline', '^<s>hello</s>|',
    {mac: false, other: false});
query_command_test(
    'underline', '^<u>hello</u>|',
    {mac: true, other: true});
query_command_test(
    'underline', '^<u>hello</u> world|',
    {mac: true, other: false});
query_command_test(
    'underline', '^hello <u>world</u>|',
    {mac: false, other: false});
query_command_test(
    'underline', '^<u><div>hello world</div></u>|',
    {mac: true, other: true});
query_command_test(
    'underline', '<u><s><div>hello ^world |WebKit</div></s></u>',
    {mac: true, other: true});
query_command_test(
    'underline', '<s><u>hello</u> ^world</s> |WebKit',
    {mac: false, other: false});
query_command_test(
    'underline', '<u><s>hello</s> ^world</u> |WebKit',
    {mac: true, other: false});
query_command_test(
    'underline', '<s>hello <u>^world|</u></s><u> WebKit</u>',
    {mac: true, other: true});
query_command_test(
    'strikeThrough', '^hello|',
    {mac: false, other: false});
query_command_test(
    'strikeThrough', '^<u>hello</u>|',
    {mac: false, other: false});
query_command_test(
    'strikeThrough', '^<s>hello</s>|',
    {mac: true, other: true});
query_command_test(
    'strikeThrough', '^<s>hello</s> world|',
    {mac: true, other: false});
query_command_test(
    'strikeThrough', '^hello <s>world</s>|',
    {mac: false, other: false});
query_command_test(
    'strikeThrough', '^<s><div>hello world</div></s>|',
    {mac: true, other: true});
query_command_test(
    'strikeThrough', '<s><u><div>hello ^world |WebKit</div></u></s>',
    {mac: true, other: true});
query_command_test(
    'strikeThrough', '<u><s>hello</s> ^world</u> |WebKit',
    {mac: false, other: false});
query_command_test(
    'strikeThrough', 'hello <s>^world |WebKit</s>',
    {mac: true, other: true});
query_command_test(
    'strikeThrough', 'hello^ <s>world |WebKit</s>',
    {mac: false, other: false});
</script>