Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: LayoutTests/fast/forms/file/file-input-change-event.html

Issue 148983008: Reduce test code duplication in fast/forms/file (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | LayoutTests/fast/forms/file/file-input-empty-validation.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <script src="../../../resources/js-test.js"></script> 4 <script src="../../../resources/js-test.js"></script>
5 <script src="resources/file-drag-common.js"></script>
5 </head> 6 </head>
6 <body> 7 <body>
7 <input type="file" id="singleFile" name="upfile" onchange="singleFileSelected()" /> 8 <input type="file" id="singleFile" name="upfile" onchange="singleFileSelected()" />
8 <input type="file" id="multipleFiles" name="upfile[]" multiple="multiple" onchan ge="multipleFilesSelected()" /> 9 <input type="file" id="multipleFiles" name="upfile[]" multiple="multiple" onchan ge="multipleFilesSelected()" />
9 <div id="console"></div> 10 <div id="console"></div>
10 <script> 11 <script>
11 var changeDispatched; 12 var changeDispatched;
12 13
13 description("This tests the condition that triggers a 'change' event on file inp ut forms."); 14 description("This tests the condition that triggers a 'change' event on file inp ut forms.");
14 15
15 if (window.testRunner) { 16 if (window.testRunner) {
16 var singleFileInput = document.getElementById("singleFile"); 17 var singleFileInput = document.getElementById("singleFile");
17 var multipleFilesInput = document.getElementById("multipleFiles"); 18 var multipleFilesInput = document.getElementById("multipleFiles");
18 19
19 debug("Test that the 'change' event is triggered on a single file form when a selected file is changed:"); 20 debug("Test that the 'change' event is triggered on a single file form when a selected file is changed:");
20 dragFilesOntoInput(singleFileInput, ["foo.txt"]); 21 dragFilesOntoFileInput(singleFileInput, ["foo.txt"]);
21 shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\foo.txt"); 22 shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\foo.txt");
22 shouldBe("changeDispatched", "true"); 23 shouldBeTrue("changeDispatched");
23 24
24 dragFilesOntoInput(singleFileInput, ["bar.txt"]); 25 dragFilesOntoFileInput(singleFileInput, ["bar.txt"]);
25 shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\bar.txt"); 26 shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\bar.txt");
26 shouldBe("changeDispatched", "true"); 27 shouldBeTrue("changeDispatched");
27 28
28 dragFilesOntoInput(singleFileInput, ["bar.txt"]); 29 dragFilesOntoFileInput(singleFileInput, ["bar.txt"]);
29 shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\bar.txt"); 30 shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\bar.txt");
30 shouldBe("changeDispatched", "false"); 31 shouldBeFalse("changeDispatched");
31 32
32 dragFilesOntoInput(singleFileInput, ["foo.txt"]); 33 dragFilesOntoFileInput(singleFileInput, ["foo.txt"]);
33 shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\foo.txt"); 34 shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\foo.txt");
34 shouldBe("changeDispatched", "true"); 35 shouldBeTrue("changeDispatched");
35 36
36 dragFilesOntoButtonInsideFileInput(singleFileInput, ["baz.png"]); 37 dragFilesOntoButtonInsideFileInput(singleFileInput, ["baz.png"]);
37 shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\baz.png"); 38 shouldBeEqualToString("singleFileInput.value", "C:\\fakepath\\baz.png");
38 shouldBe("changeDispatched", "true"); 39 shouldBeTrue("changeDispatched");
39 40
40 debug(""); 41 debug("");
41 debug("Test that the 'change' event is triggered on a multiple file form whe n a selected file is changed:"); 42 debug("Test that the 'change' event is triggered on a multiple file form whe n a selected file is changed:");
42 dragFilesOntoInput(multipleFilesInput, ["foo.txt"]); 43 dragFilesOntoFileInput(multipleFilesInput, ["foo.txt"]);
43 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt"); 44 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
44 shouldBe("changeDispatched", "true"); 45 shouldBeTrue("changeDispatched");
45 46
46 dragFilesOntoInput(multipleFilesInput, ["bar.txt"]); 47 dragFilesOntoFileInput(multipleFilesInput, ["bar.txt"]);
47 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt"); 48 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt");
48 shouldBe("changeDispatched", "true"); 49 shouldBeTrue("changeDispatched");
49 50
50 dragFilesOntoInput(multipleFilesInput, ["bar.txt"]); 51 dragFilesOntoFileInput(multipleFilesInput, ["bar.txt"]);
51 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt"); 52 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt");
52 shouldBe("changeDispatched", "false"); 53 shouldBeFalse("changeDispatched");
53 54
54 dragFilesOntoInput(multipleFilesInput, ["foo.txt"]); 55 dragFilesOntoFileInput(multipleFilesInput, ["foo.txt"]);
55 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt"); 56 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
56 shouldBe("changeDispatched", "true"); 57 shouldBeTrue("changeDispatched");
57 58
58 debug("Test that the 'change' event is triggered on a multiple file form whe n selected files are changed:"); 59 debug("Test that the 'change' event is triggered on a multiple file form whe n selected files are changed:");
59 dragFilesOntoInput(multipleFilesInput, ["foo.txt", "bar.txt"]); 60 dragFilesOntoFileInput(multipleFilesInput, ["foo.txt", "bar.txt"]);
60 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt"); 61 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
61 shouldBe("changeDispatched", "true"); 62 shouldBeTrue("changeDispatched");
62 63
63 dragFilesOntoInput(multipleFilesInput, ["foo.txt"]); 64 dragFilesOntoFileInput(multipleFilesInput, ["foo.txt"]);
64 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt"); 65 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
65 shouldBe("changeDispatched", "true"); 66 shouldBeTrue("changeDispatched");
66 67
67 dragFilesOntoInput(multipleFilesInput, ["foo.txt", "bar.txt"]); 68 dragFilesOntoFileInput(multipleFilesInput, ["foo.txt", "bar.txt"]);
68 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt"); 69 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
69 shouldBe("changeDispatched", "true"); 70 shouldBeTrue("changeDispatched");
70 71
71 dragFilesOntoInput(multipleFilesInput, ["foo.txt", "bar.txt", "baz.txt"]); 72 dragFilesOntoFileInput(multipleFilesInput, ["foo.txt", "bar.txt", "baz.txt"] );
72 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt"); 73 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
73 shouldBe("changeDispatched", "true"); 74 shouldBeTrue("changeDispatched");
74 75
75 dragFilesOntoInput(multipleFilesInput, ["foo.txt", "bar.txt"]); 76 dragFilesOntoFileInput(multipleFilesInput, ["foo.txt", "bar.txt"]);
76 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt"); 77 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\foo.txt");
77 shouldBe("changeDispatched", "true"); 78 shouldBeTrue("changeDispatched");
78 79
79 dragFilesOntoInput(multipleFilesInput, ["bar.txt", "foo.txt"]); 80 dragFilesOntoFileInput(multipleFilesInput, ["bar.txt", "foo.txt"]);
80 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt"); 81 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt");
81 shouldBe("changeDispatched", "true"); 82 shouldBeTrue("changeDispatched");
82 83
83 dragFilesOntoInput(multipleFilesInput, ["bar.txt", "foo.txt"]); 84 dragFilesOntoFileInput(multipleFilesInput, ["bar.txt", "foo.txt"]);
84 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt"); 85 shouldBeEqualToString("multipleFilesInput.value", "C:\\fakepath\\bar.txt");
85 shouldBe("changeDispatched", "false"); 86 shouldBeFalse("changeDispatched");
86 } 87 }
87 88
88 function singleFileSelected() { 89 function singleFileSelected() {
89 changeDispatched = true; 90 changeDispatched = true;
90 } 91 }
91 92
92 function multipleFilesSelected() { 93 function multipleFilesSelected() {
93 changeDispatched = true; 94 changeDispatched = true;
94 } 95 }
95 96
96 function moveMouseToCenterOfElement(element) { 97 function dragFilesOntoFileInput(input, files) {
97 var centerX = element.offsetLeft + element.offsetWidth / 2;
98 var centerY = element.offsetTop + element.offsetHeight / 2;
99 eventSender.mouseMoveTo(centerX, centerY);
100 }
101
102 function dragFilesOntoInput(input, files) {
103 changeDispatched = false; 98 changeDispatched = false;
104 eventSender.beginDragWithFiles(files); 99 dragFilesOntoInput(input, files);
105 moveMouseToCenterOfElement(input);
106 eventSender.mouseUp();
107 } 100 }
108 101
109 function dragFilesOntoButtonInsideFileInput(input, files) { 102 function dragFilesOntoButtonInsideFileInput(input, files) {
110 changeDispatched = false; 103 changeDispatched = false;
111 eventSender.beginDragWithFiles(files); 104 eventSender.beginDragWithFiles(files);
112 eventSender.mouseMoveTo(input.offsetLeft + 10, input.offsetTop + input.offse tHeight / 2); 105 eventSender.mouseMoveTo(input.offsetLeft + 10, input.offsetTop + input.offse tHeight / 2);
113 eventSender.mouseUp(); 106 eventSender.mouseUp();
114 } 107 }
115 </script> 108 </script>
116 </body> 109 </body>
117 </html> 110 </html>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/fast/forms/file/file-input-empty-validation.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698