chromium/third_party/blink/web_tests/editing/caret/caret_affinity_mouse_perturbation.html

<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
const kStyle = `
<style>
div.test {
  font: 10px/10px Ahem;
  width: 30px;
  word-break: break-all;
  padding-right: 10px;
}
</style>`;

// Regression tests for https://crbug.com/919146

// Mouse down at the end of the first line. Without releasing, slightly move
// the mouse around. Caret shouldn't be moved to the second line.
selection_test(
    `${kStyle}<div class="test" contenteditable>foobar</div>`,
    selection => {
      assert_own_property(window, 'eventSender');
      assert_own_property(window, 'internals');

      const div = selection.document.querySelector('div.test');
      const x = selection.computeLeft(div) + 35;
      const y = selection.computeTop(div) + 5;
      eventSender.mouseMoveTo(x - 3, y);
      eventSender.mouseDown();
      eventSender.mouseMoveTo(x + 3, y);
      eventSender.mouseUp();

      assert_equals(internals.textAffinity, 'Upstream');
    },
    `${kStyle}<div class="test" contenteditable>foo|bar</div>`,
    'Drag with upstream caret');

// Set upstream caret at the end of the first line. Then shift+click around the
// caret. Caret should remain upstream at the end of the first line.
selection_test(
    `${kStyle}<div class="test" contenteditable>foobar</div>`,
    selection => {
      assert_own_property(window, 'eventSender');
      assert_own_property(window, 'internals');

      const div = selection.document.querySelector('div.test');
      const x = selection.computeLeft(div) + 35;
      const y = selection.computeTop(div) + 5;
      eventSender.mouseMoveTo(x - 3, y);
      eventSender.mouseDown();
      eventSender.mouseUp();

      eventSender.mouseMoveTo(x + 3, y);
      eventSender.mouseDown(0, ['shiftKey']);
      eventSender.mouseUp(0, ['shiftKey']);

      assert_equals(internals.textAffinity, 'Upstream');
    },
    `${kStyle}<div class="test" contenteditable>foo|bar</div>`,
    'Shift+Click around upstream caret');
</script>