chromium/third_party/blink/web_tests/fast/events/touch/gesture/long-press-drag-drop-touch-editing-combined-in-iframe.html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../../../resources/testharness.js"></script>
<script src="../../../../resources/testharnessreport.js"></script>
<script src="../../../../resources/gesture-util.js"></script>
<script src="../../../../resources/testdriver.js"></script>
<script src="../../../../resources/testdriver-actions.js"></script>
<script src="../../../..//resources/testdriver-vendor.js"></script>
<style>
  iframe {
    height: 200px;
    width: 200px;
    overflow: hidden;
  }
</style>
</head>
<body>
<script>
  if (window.internals)
    internals.settings.setTouchDragDropEnabled(true);

// The iframe will call top.dragStarted() or top.mousedownTriggered() on
// receiving the corresponding event.
function mousedownTriggered() {
  rejectDragStartPromise();
}

function dragStarted(element) {
  resolveDragStartPromise(element);
}

let resolveDragStartPromise = undefined;
let rejectDragStartPromise = undefined;
function dragStartEvent() {
  return new Promise((resolve, reject) => {
    resolveDragStartPromise = resolve;
    rejectDragStartPromise = () => {
      reject('missing dragstart event');
    }
  });
}
</script>
<iframe src="resources/drag-inside-iframe2.html" id=testIframe></iframe>
<p>This test checks long press behavior inside an iframe when both touch drag/drop and touch editing are enabled.<br>
1. Check that long press on a draggable element starts drag.<br>
2. Check that long press on non-draggable text selects the text.<br>
3. Check that long press on selected text starts drag.</p>
<script>
// The runTest method is called when the iframe is loaded via top.runTest().
function runTest() {
  promise_test(async t => {
    preventContextMenu(t);
    const target = document.querySelector('iframe');
    let dragPromise = dragStartEvent();
    let longpressOptions = { x: -50, y: -50, duration: 1200 };
    await touchLongPressElement(target, longpressOptions);
    let result = await dragPromise;
    assert_equals(result.id, 'draggableDiv');

    // Reposition long-press to text.
    longpressOptions = { x: -80, y: 25, duration: 1200 };
    await touchLongPressElement(target, longpressOptions);
    assert_equals(target.contentDocument.getSelection().toString(), 'Some');

    dragPromise = dragStartEvent();
    await touchLongPressElement(target, longpressOptions);
    result = await dragPromise;
    assert_equals(result.id, 'draggableText');
  }, 'Long press drag and drop in an iframe');
}
</script>
</body>
</html>