summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/file/input-file-write-files.html
blob: 43ebca376ef05f2462960968982898a3cb019e20 (plain)
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
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<input type="file" name="file1" id="file1">
<input type="file" name="file2" id="file2">
<script>
description("This tests the files attribute in file input forms");

if (window.testRunner) {
    var file1 = document.getElementById("file1");
    var file2 = document.getElementById("file2");
    dragFilesOntoInput(file1, ["foo.txt"]);
    dragFilesOntoInput(file2, ["bar.txt"]);

    file1.files = "foo";
    shouldBe("file1.files.length", "1");
    shouldBeEqualToString("file1.files.item(0).name", "foo.txt");

    file1.files = null;
    shouldBe("file1.files.length", "1");
    shouldBeEqualToString("file1.files.item(0).name", "foo.txt");

    // From current W3C spec, files attribute should be read only,
    // but WebKit implement it to be writable intentionally.
    // See: https://bugs.webkit.org/show_bug.cgi?id=87154#c15
    file1.files = file2.files;
    shouldBe("file1.files.length", "1");
    shouldBeEqualToString("file1.files.item(0).name", "bar.txt");
}

function moveMouseToCenterOfElement(element) {
    var centerX = element.offsetLeft + element.offsetWidth / 2;
    var centerY = element.offsetTop + element.offsetHeight / 2;
    eventSender.mouseMoveTo(centerX, centerY);
}

function dragFilesOntoInput(input, files) {
    eventSender.beginDragWithFiles(files);
    moveMouseToCenterOfElement(input);
    eventSender.mouseUp();
}
</script>
</body>
</html>