chromium/third_party/blink/web_tests/editing/selection/mark_with_unfocused_selection.html

<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
test(() => {
  assert_own_property(window, 'testRunner', 'This test requires testRunner');

  assert_selection(
  [
    '<textarea>foo ^bar|</textarea>',
    '<a href="http://www.example.com/">link</a>'
  ].join(''),
  selection => {
    const textarea = selection.document.querySelector('textarea');
    const link = selection.document.querySelector('a');
    textarea.focus();
    testRunner.execCommand('setMark');
    textarea.setSelectionRange(0, 0);
    link.focus();
    testRunner.execCommand('swapWithMark');
    assert_equals(selection.document.activeElement, link);
  },
  [
    '|<textarea>foo bar</textarea>',
    '<a href="http://www.example.com/">link</a>'
  ].join(''));
}, 'Swap-with-mark with unfocused selection in text control');

test(() => {
  assert_own_property(window, 'testRunner', 'This test requires testRunner');

  assert_selection(
  [
    '<div contenteditable>foo ^bar|</div>',
    '<a href="http://www.example.com/">link</a>'
  ].join(''),
  selection => {
    const div = selection.document.querySelector('div');
    const link = selection.document.querySelector('a');
    div.focus();
    testRunner.execCommand('setMark');
    selection.collapse(div, 0);
    link.focus();
    testRunner.execCommand('swapWithMark');
    assert_equals(selection.document.activeElement, link);
  },
  [
    '<div contenteditable>|foo bar</div>',
    '<a href="http://www.example.com/">link</a>'
  ].join(''));
}, 'Swap-with-mark with unfocused selection in contenteditable div');
</script>