chromium/third_party/blink/web_tests/editing/selection/drag_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>
// Regression tests for crbug.com/717453.

function mouseMoveTo(element) {
  const document = element.ownerDocument;
  const mouseX = document.offsetLeft + element.offsetLeft + element.offsetWidth / 2;
  const mouseY = document.offsetTop + element.offsetTop + element.offsetHeight / 2;
  eventSender.mouseMoveTo(mouseX, mouseY);
}

test(() => {
  assert_not_equals(window.eventSender, 'This test requires eventSender');

  assert_selection(
  [
    '<textarea id="source">^text|</textarea>',
    '<a href="http://www.example.com/" id="link">link</a>',
    '<textarea id="target"></textarea>'
  ].join(''),
  selection => {
    const document = selection.document;
    const source = document.getElementById('source');
    const link = document.getElementById('link');
    const target = document.getElementById('target');
    source.focus();
    mouseMoveTo(link);
    eventSender.mouseDown();
    eventSender.leapForward(500);
    mouseMoveTo(target);
    eventSender.mouseUp();
  },
  [
    '<textarea id="source">text</textarea>',
    '<a href="http://www.example.com/" id="link">link</a>',
    '<textarea id="target">^http://www.example.com/|</textarea>'
  ].join(''));
}, 'Drag link with unfocused selection in text control');

test(() => {
  assert_not_equals(window.eventSender, 'This test requires eventSender');

  assert_selection(
  [
    '<div contenteditable id="source">^text|</div>',
    '<a href="http://www.example.com/" id="link">link</a>',
    '<textarea id="target"></textarea>'
  ].join(''),
  selection => {
    const document = selection.document;
    const source = document.getElementById('source');
    const link = document.getElementById('link');
    const target = document.getElementById('target');
    source.focus();
    mouseMoveTo(link);
    eventSender.mouseDown();
    eventSender.leapForward(500);
    mouseMoveTo(target);
    eventSender.mouseUp();
  },
  [
    '<div contenteditable id="source">text</div>',
    '<a href="http://www.example.com/" id="link">link</a>',
    '<textarea id="target">^http://www.example.com/|</textarea>'
  ].join(''));
}, 'Drag link with unfocused selection in contenteditable div');

test(() => {
  assert_not_equals(window.eventSender, 'This test requires eventSender');

  assert_selection(
  [
    '<div id="source">^text|</div>',
    '<a href="http://www.example.com/" id="link">link</a>',
    '<textarea id="target"></textarea>'
  ].join(''),
  selection => {
    const document = selection.document;
    const source = document.getElementById('source');
    const link = document.getElementById('link');
    const target = document.getElementById('target');
    document.body.focus();
    mouseMoveTo(link);
    eventSender.mouseDown();
    eventSender.leapForward(500);
    mouseMoveTo(target);
    eventSender.mouseUp();
  },
  [
    '<div id="source">text</div>',
    '<a href="http://www.example.com/" id="link">link</a>',
    '<textarea id="target">^http://www.example.com/|</textarea>'
  ].join(''));
}, 'Drag link with unfocused selection in uneditable text');
</script>