File: data-transfer-items-file-dragout.html

package info (click to toggle)
qtwebkit 2.3.4.dfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 290,116 kB
  • ctags: 272,544
  • sloc: cpp: 1,417,496; python: 85,048; ansic: 39,353; perl: 38,858; ruby: 10,313; objc: 9,505; xml: 8,679; asm: 3,864; yacc: 2,458; sh: 1,237; lex: 813; makefile: 592; java: 228; php: 79
file content (79 lines) | stat: -rw-r--r-- 2,852 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html>
<body>
<p><b>BUG ID: 76367</b> <a href="http://bugs.webkit.org/show_bug.cgi?id=76367">Bugzilla bug </a> Add DataTransferItems support for drag-and-drop'ed files and texts</p>

<p id="test" style="background-color:skyblue; padding:3px;"><b>STEPS TO TEST:</b> <br>
1. Open the <a href="resources">$(WebKitRoot)/ManualTests/resources</a> folder in your native file browser.<br>
2. Drag and drop a file into the 'Drop files here' area below.<br>
3. Drag out <a href="#" id="dragout" draggable="true">this link</a> out of the browser window into a different folder in the native file browser).
</p>

<div id="destination" style="min-height:100px; margin: 5px; border: solid 1px black">Drop files here </div>

<p id="success" style="background-color:palegreen; padding:3px;"><b>TEST PASS:</b>
The same file you dropped in the step 2 should be dragged out to the folder in the step 3.  The file should have the same content and the same file name as the dropped file.  (NOTE: this does not work for multiple files yet.)
</p>

<p id="failure" style="background-color:#FF3300; padding:3px;"><b>TEST FAIL:</b>
Nothing happens or a different file from the dropped one (likely a text file with the page title) is dragged out.
</p>
<p id="console"></p>

<script>
function log(text)
{
    var console = document.getElementById('console');
    console.appendChild(document.createTextNode(text));
    console.appendChild(document.createElement('br'));
}

function test(expect, actual)
{
    log((expect == actual ? 'PASS' : 'FAIL') + ': "' + expect + '" == "' + actual + '"');
}

var destination = document.getElementById('destination');
destination.addEventListener('dragover', handleDragOver, false);
destination.addEventListener('drop', handleDrop, false);

function handleDragOver(e)
{
    e.stopPropagation();
    e.preventDefault();
}

function handleDrop(e)
{
    e.stopPropagation();
    e.preventDefault();

    log('Verifying contents of DataTransferItems...');
    var items = e.dataTransfer.items;
    var files = [];
    test(1, items.length);

    for (var i = 0; i < items.length; ++i) {
        test('file', items[i].kind);
        var file = items[i].getAsFile();
        log('Dragged files: ' + file.name);
        log('Dragged file size: ' + file.size);
        files.push(file);
    }

    // Setting up dragout items.
    log('Setting up dragging out with the dropped items...');
    var source = document.getElementById('dragout');
    source.addEventListener('dragstart', function(e) {
        for (var i = 0; i < files.length; ++i) {
            log('Dragging out ' + files[i].name);
            e.dataTransfer.items.add(files[i]);
        }
    }, false);

    log('Please dragout the link (noted in the step 3) and see if the same file you dropped in in the step 2 is properly drag out.');
}

</script>
</body>
</html>