chromium/third_party/blink/web_tests/editing/selection/user-select/user-select-all.html

<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<div id="log"></div>
<script>
test(() => {
    assert_selection(
        '<div>foo<span style="-webkit-user-select:all">|bar</span>baz</div>',
        selection => selection.modify('extend', 'forward', 'character'),
        '<div>foo<span style="-webkit-user-select:all">^bar|</span>baz</div>');
    assert_selection(
        '<div>foo<span style="-webkit-user-select:all">|bar</span>baz</div>',
        selection => selection.modify('extend', 'right', 'character'),
        '<div>foo<span style="-webkit-user-select:all">^bar|</span>baz</div>');
    assert_selection(
        '<div>foo<span style="-webkit-user-select:all">^bar|</span>baz</div>',
        selection => selection.modify('extend', 'backward', 'character'),
        '<div>foo|<span style="-webkit-user-select:all">bar</span>baz</div>');
    assert_selection(
        '<div>foo<span style="-webkit-user-select:all">^bar|</span>baz</div>',
        selection => selection.modify('extend', 'left', 'character'),
        '<div>foo|<span style="-webkit-user-select:all">bar</span>baz</div>');
}, 'Modify extend skips over user-select:all.');
test(() => {
    assert_selection(
        '<div>foo<span style="-webkit-user-select:all">|bar</span>baz</div>',
        selection => selection.modify('move', 'forward', 'character'),
        '<div>foo<span style="-webkit-user-select:all">b|ar</span>baz</div>');
    assert_selection(
        '<div>foo<span style="-webkit-user-select:all">|bar</span>baz</div>',
        selection => selection.modify('move', 'right', 'character'),
        '<div>foo<span style="-webkit-user-select:all">b|ar</span>baz</div>');
    assert_selection(
        '<div>foo<span style="-webkit-user-select:all">bar|</span>baz</div>',
        selection => selection.modify('move', 'backward', 'character'),
        '<div>foo<span style="-webkit-user-select:all">ba|r</span>baz</div>');
    assert_selection(
        '<div>foo<span style="-webkit-user-select:all">bar|</span>baz</div>',
        selection => selection.modify('move', 'left', 'character'),
        '<div>foo<span style="-webkit-user-select:all">ba|r</span>baz</div>');
}, 'Modify move is not affected by user-select:all.');

function mouseDownAt(x, y) {
  assert_own_property(window, 'eventSender');
  eventSender.dragMode = false;
  eventSender.mouseMoveTo(x, y);
  eventSender.mouseDown();
}

function mouseMoveFromTo(y, fromX, toX) {
  mouseDownAt(fromX, y);
  eventSender.leapForward(100);
  eventSender.mouseMoveTo(toX, y);
  eventSender.mouseUp();
}

const kSample = [
  '<div id="div">',
    'abc <span style="user-select:all">',
      'def <span id="middle">ghi </span>jkl ',
    '</span>mno',
  '</div>'
].join('');

test(() => assert_selection(
  kSample,
  selection => {
    const div = selection.document.getElementById('div');
    const middle = selection.document.getElementById('middle');
    mouseDownAt(selection.computeLeft(middle), selection.computeTop(div));
  },
  '<div id="div">abc <span style="user-select:all">^def <span id="middle">ghi </span>jkl |</span>mno</div>'),
  'Click inside user-select:all');

test(() => assert_selection(
  kSample,
  selection => {
    const div = selection.document.getElementById('div');
    const middle = selection.document.getElementById('middle');
    mouseMoveFromTo(selection.computeTop(div),
                    selection.computeLeft(div),
                    selection.computeLeft(middle));
  },
  '<div id="div">^abc <span style="user-select:all">def <span id="middle">ghi </span>jkl |</span>mno</div>'),
  'Drag from left of user-select:all to inside user-select:all');

test(() => assert_selection(
  kSample,
  selection => {
    const div = selection.document.getElementById('div');
    const middle = selection.document.getElementById('middle');
    mouseMoveFromTo(selection.computeTop(div),
                    selection.computeLeft(div) + div.offsetWidth,
                    selection.computeLeft(middle));
  },
  '<div id="div">abc <span style="user-select:all">|def <span id="middle">ghi </span>jkl </span>mno^</div>'),
  'Drag from right of user-select:all to inside user-select:all');

test(() => {
    assert_selection(
        '<div>foo<span style="-webkit-user-select:all">bar<span id="middle">bar</span>bar</span>|baz</div>',
        selection => {
            var middle = selection.document.getElementById('middle');
            selection.selectAllChildren(middle);},
        '<div>foo<span style="-webkit-user-select:all">bar<span id="middle">^bar|</span>bar</span>baz</div>');
}, 'Selection.selectAllChildren is not affected by  user-select:all.');
</script>