blob: 54a78be91032cfcab9853758ad6ac2059966fc32 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.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"]);
shouldThrow('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>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>