blob: 44da5d593f8691cc104c88b9b4d0eee03a980b7d [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
<script src="../../../resources/ui-helper.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) {
jsTestIsAsync = true;
var file1 = document.getElementById("file1");
var file2 = document.getElementById("file2");
file1.addEventListener("change", function() {
file2.addEventListener("change", function() {
runTest(file1, file2);
finishJSTest();
});
window.setTimeout(function() {
dragFilesOntoInput(file2, ["bar.txt"]);
}, 0);
});
dragFilesOntoInput(file1, ["foo.txt"]);
}
function runTest(file1, file2) {
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 dragFilesOntoInput(input, files) {
testRunner.setOpenPanelFiles(files);
var centerX = input.offsetLeft + input.offsetWidth / 2;
var centerY = input.offsetTop + input.offsetHeight / 2;
UIHelper.activateAt(centerX, centerY);
}
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>