chromium/third_party/blink/web_tests/editing/inserting/insert_br.html

<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
test(() => assert_selection(
    '<div contenteditable><span>foo|</span></div>',
    'insertLineBreak',
    '<div contenteditable><span>foo<br>|<br></span></div>'),
    'Insert line break at end of text');

test(() => assert_selection(
    '<div contenteditable><span>foo|<br>bar</span></div>',
    'insertLineBreak',
    '<div contenteditable><span>foo<br>|<br>bar</span></div>'),
    'Insert line break before line break');

test(() => assert_selection(
    '<div contenteditable><span>foo|bar</span></div>',
    'insertLineBreak',
    '<div contenteditable><span>foo<br>|bar</span></div>'),
    'Insert line break between text');

test(() => assert_selection(
    '<div contenteditable><span>foo|</span></div>',
    selection => {
        selection.document.execCommand('insertLineBreak');
        selection.document.execCommand('insertLineBreak');
    },
    '<div contenteditable><span>foo<br><br>|<br></span></div>'),
    'Insert two line breaks');

test(() => assert_selection(
    '<div contenteditable><span>foo|</span></div>',
    selection => {
        selection.document.execCommand('insertLineBreak');
        selection.document.execCommand('insertLineBreak');
        selection.document.execCommand('insertText', false, 'c');
    },
    '<div contenteditable><span>foo<br><br>c|</span></div>'),
    'Insert two line breaks and a character');

test(() => assert_selection(
    '<div contenteditable><span>|foo</span></div>',
    'insertLineBreak',
    '<div contenteditable><span><br>|foo</span></div>'),
    'Insert line break before text');

test(() => assert_selection(
    '<div contenteditable><span>foo| bar</span></div>',
    'insertLineBreak',
    '<div contenteditable><span>foo<br>|\u{00A0}bar</span></div>'),
    'Insert line break between words');

test(() => assert_selection(
    '<div contenteditable>|foo</div>',
    selection => {
        selection.document.execCommand('insertLineBreak');
        selection.document.execCommand('insertText', false, ' ');
    },
    '<div contenteditable><br>\u{00A0}|foo</div>'),
    'Insert space after BR becomeas NBSP');

test(() => assert_selection(
    '<div contenteditable style="white-space:pre">foo\n|\n</div>',
    'insertLineBreak',
    '<div contenteditable style="white-space:pre">foo\n\n|\n</div>'),
    'Insert a newline character for white-space:pre');
</script>