Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / pasteboard / script-tests / files-during-page-drags.js
blob2bc1a7082ada5d1ef070381d4b4145da7d2eb9af
1 description("Make sure that .files arrays are always empty for non-file drags.");
3 var testContainer = document.createElement('div');
4 // Put dragables at the top so that logging does not cause them to move off screen (where we can't drag).
5 document.body.insertBefore(testContainer, document.body.firstChild);
7 var dragTarget = document.createElement('div');
8 dragTarget.innerHTML = "drag target";
9 dragTarget.style.cssText = 'width: 100px; height: 100px; background-color: blue';
10 testContainer.appendChild(dragTarget);
12 var droppedFiles = null;
13 dragTarget.ondragenter = function() {
14 event.dataTransfer.dropEffect = "copy";
16 dragTarget.ondragover = function() {
17 event.dataTransfer.dropEffect = "copy";
18 event.preventDefault();
20 dragTarget.ondrop = function() {
21 if (window.eventSender) {
22 if (droppedFiles)
23 testFailed("droppedFiles should have been cleared before making a drop");
24 droppedFiles = event.dataTransfer.files;
25 } else
26 debug("Got drop with files: " + event.dataTransfer.files + " length: " + event.dataTransfer.files.length)
29 var image = document.createElement('img');
30 image.src = "resources/apple.gif";
31 testContainer.appendChild(image);
33 // If we don't add a <br> then the line height of the <a> is the same as the <img> and the click-to-drag hits undragable whitespace.
34 testContainer.appendChild(document.createElement('br'));
36 var link = document.createElement('a');
37 link.innerHTML = "Draggable link";
38 link.href = "resources/apple.gif"
39 testContainer.appendChild(link);
41 function moveMouseToCenterOfElement(element)
43 var centerX = element.offsetLeft + element.offsetWidth / 2;
44 var centerY = element.offsetTop + element.offsetHeight / 2;
45 eventSender.mouseMoveTo(centerX, centerY);
48 function dragFromSourceToTarget(source, target)
50 moveMouseToCenterOfElement(source);
51 eventSender.mouseDown();
52 moveMouseToCenterOfElement(target);
53 eventSender.mouseUp();
56 function testDrag(source)
58 dragFromSourceToTarget(source, dragTarget);
59 if (!droppedFiles)
60 testFailed("Drop of " + source.tagName + " never occured!");
61 else if (droppedFiles.length == 0)
62 testPassed("Drag of " + source.tagName + " resulted in empty files array.");
63 else
64 testFailed("Drag of " + source.tagName + " resulted in non-empty files array! (files: " + droppedFiles.length + ")");
65 droppedFiles = null;
68 function runTest()
70 testDrag(link);
71 testDrag(image);
74 if (window.eventSender) {
75 runTest();
76 // Clean up after ourselves
77 document.body.removeChild(testContainer);
78 } else {
79 testFailed("This test is not interactive, please run using DumpRenderTree");
82 var successfullyParsed = true;