Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/fast/dnd/resources/dropEffect-common.js |
| diff --git a/third_party/WebKit/LayoutTests/fast/dnd/resources/dropEffect-common.js b/third_party/WebKit/LayoutTests/fast/dnd/resources/dropEffect-common.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3a2a2f9c0c5584225f707018cd5e678e42988392 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/fast/dnd/resources/dropEffect-common.js |
| @@ -0,0 +1,77 @@ |
| +const mouseMoveToCenter = element => { |
| + const clientRect = element.getBoundingClientRect(); |
| + const centerX = (clientRect.left + clientRect.right) / 2; |
| + const centerY = (clientRect.top + clientRect.bottom) / 2; |
| + eventSender.mouseMoveTo(centerX, centerY); |
| +}; |
| + |
| +const dropEffectTest = params => { |
| + promise_test(t => { |
| + document.querySelector('.test-description').textContent = |
| + JSON.stringify(params); |
| + |
| + const dragged = document.querySelector('.dragged'); |
| + if (dragged && !dragged.classList.contains('no-ondragstart')) { |
| + dragged.ondragstart = t.step_func(event => { |
| + event.dataTransfer.setData('text/plain', 'Needed to work in Firefox'); |
|
jsbell
2017/03/02 22:06:45
Happen to have a link to a bug?
pwnall
2017/03/02 22:34:29
I've been cargo-culting this from other tests arou
|
| + if ('allowed' in params) |
| + event.dataTransfer.effectAllowed = params.allowed; |
| + }); |
| + } |
| + |
| + const dropZone = document.querySelector('.dropzone'); |
| + dropZone.ondragover = t.step_func(event => { |
| + event.preventDefault(); |
| + if ('drop' in params) |
| + event.dataTransfer.dropEffect = params.drop; |
| + }); |
| + let gotDrop = false; |
| + dropZone.ondrop = t.step_func(event => { |
| + event.preventDefault(); |
| + gotDrop = true; |
| + }); |
| + |
| + return new Promise((resolve, reject) => { |
|
jsbell
2017/03/02 22:06:45
Nit: Move this up to the top of the `t => {` block
pwnall
2017/03/02 22:34:29
Done.
|
| + const doneButton = document.querySelector('.done'); |
| + |
| + if (dragged) { |
| + dragged.ondragend = t.step_func(event => { |
| + resolve(event.dataTransfer.dropEffect); |
| + }); |
| + } else { |
| + doneButton.onclick = t.step_func(() => { |
| + resolve('none'); |
| + }); |
| + } |
| + |
| + if (window.eventSender) { |
| + if (dragged) { |
| + mouseMoveToCenter(dragged); |
| + eventSender.mouseDown(); |
| + } else { |
| + eventSender.mouseMoveTo(0, 0); |
| + eventSender.beginDragWithFiles(['resources/dragged-file.txt']); |
| + } |
| + setTimeout(() => { |
| + mouseMoveToCenter(dropZone); |
| + eventSender.mouseUp(); |
| + if (doneButton) { |
| + setTimeout(() => { |
| + const clickEvent = new Event('click'); |
| + doneButton.dispatchEvent(clickEvent); |
| + }, 100); |
| + } |
| + }, 100); |
| + } |
| + }).then((dragOperation) => { |
|
jsbell
2017/03/02 22:06:45
nit: no () needed
pwnall
2017/03/02 22:34:29
Done.
|
| + if ('operation' in params) { |
| + assert_true(gotDrop, 'drop target should have received a drop event'); |
| + assert_equals(dragOperation, params.operation); |
| + } else { |
| + assert_true( |
| + !gotDrop, 'drop target should not have received a drop event'); |
| + assert_equals(dragOperation, 'none'); |
| + } |
| + }); |
| + }, `effectAllowed: ${params.allowed} dropEffect: ${params.drop}`); |
| +}; |