summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/forms/file/file-input-change-event.html
blob: 6cb16d3036112e833ca5708e4ff0760d0fa605d7 (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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="resources/file-drag-common.js"></script>
</head>
<body>
<input type="file" id="singleFile" name="upfile" onchange="singleFileSelected()" />
<input type="file" id="multipleFiles" name="upfile[]" multiple="multiple" onchange="multipleFilesSelected()" />
<div id="console"></div>
<script>
var changeDispatched;

description("This tests the condition that triggers a 'change' event on file input forms.");

if (window.testRunner) {
    var singleFileInput = document.getElementById("singleFile");
    var multipleFilesInput = document.getElementById("multipleFiles");

    debug("Test that the 'change' event is triggered on a single file form when a selected file is changed:");
    dragFilesOntoFileInput(singleFileInput, ["foo.txt"]);
    shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\foo.txt");
    shouldBeTrue("changeDispatched");

    dragFilesOntoFileInput(singleFileInput, ["bar.txt"]);
    shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\bar.txt");
    shouldBeTrue("changeDispatched");

    dragFilesOntoFileInput(singleFileInput, ["bar.txt"]);
    shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\bar.txt");
    shouldBeFalse("changeDispatched");

    dragFilesOntoFileInput(singleFileInput, ["foo.txt"]);
    shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\foo.txt");
    shouldBeTrue("changeDispatched");

    dragFilesOntoButtonInsideFileInput(singleFileInput, ["baz.png"]);
    shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\baz.png");
    shouldBeTrue("changeDispatched");

    debug("");
    debug("Test that the 'change' event is triggered on a multiple file form when a selected file is changed:");
    dragFilesOntoFileInput(multipleFilesInput, ["foo.txt"]);
    shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
    shouldBeTrue("changeDispatched");

    dragFilesOntoFileInput(multipleFilesInput, ["bar.txt"]);
    shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt");
    shouldBeTrue("changeDispatched");

    dragFilesOntoFileInput(multipleFilesInput, ["bar.txt"]);
    shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt");
    shouldBeFalse("changeDispatched");

    dragFilesOntoFileInput(multipleFilesInput, ["foo.txt"]);
    shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
    shouldBeTrue("changeDispatched");

    debug("Test that the 'change' event is triggered on a multiple file form when selected files are changed:");
    dragFilesOntoFileInput(multipleFilesInput, ["foo.txt", "bar.txt"]);
    shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
    shouldBeTrue("changeDispatched");

    dragFilesOntoFileInput(multipleFilesInput, ["foo.txt"]);
    shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
    shouldBeTrue("changeDispatched");

    dragFilesOntoFileInput(multipleFilesInput, ["foo.txt", "bar.txt"]);
    shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
    shouldBeTrue("changeDispatched");

    dragFilesOntoFileInput(multipleFilesInput, ["foo.txt", "bar.txt", "baz.txt"]);
    shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
    shouldBeTrue("changeDispatched");

    dragFilesOntoFileInput(multipleFilesInput, ["foo.txt", "bar.txt"]);
    shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
    shouldBeTrue("changeDispatched");

    dragFilesOntoFileInput(multipleFilesInput, ["bar.txt", "foo.txt"]);
    shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt");
    shouldBeTrue("changeDispatched");

    dragFilesOntoFileInput(multipleFilesInput, ["bar.txt", "foo.txt"]);
    shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt");
    shouldBeFalse("changeDispatched");
}

function singleFileSelected() {
    changeDispatched = true;
}

function multipleFilesSelected() {
    changeDispatched = true;
}

function dragFilesOntoFileInput(input, files) {
    changeDispatched = false;
    dragFilesOntoInput(input, files);
}

function dragFilesOntoButtonInsideFileInput(input, files) {
    changeDispatched = false;
    eventSender.beginDragWithFiles(files);
    eventSender.mouseMoveTo(input.offsetLeft + 10, input.offsetTop + input.offsetHeight / 2);
    eventSender.mouseUp();
}
</script>
</body>
</html>