diff options
author | commit-queue@webkit.org <commit-queue@webkit.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2012-10-26 10:18:15 +0000 |
---|---|---|
committer | commit-queue@webkit.org <commit-queue@webkit.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538> | 2012-10-26 10:18:15 +0000 |
commit | 00c40b9b1028188e1599be0f1de1a6ec8d0435ed (patch) | |
tree | 61f0201e637c7af43f4daf5dac96f91b0eb54df8 /third_party/WebKit/LayoutTests/fast/forms | |
parent | 65ad8f02f778d72b976618c4dc05009545a8e7c7 (diff) | |
download | chromium_src-00c40b9b1028188e1599be0f1de1a6ec8d0435ed.zip chromium_src-00c40b9b1028188e1599be0f1de1a6ec8d0435ed.tar.gz chromium_src-00c40b9b1028188e1599be0f1de1a6ec8d0435ed.tar.bz2 |
fast/forms/file/input-file-write-files.html should cover correct setting value
https://bugs.webkit.org/show_bug.cgi?id=100085
Patch by Li Yin <li.yin@intel.com> on 2012-10-26
Reviewed by Kentaro Hara.
Source/WebCore:
From Spec: http://dev.w3.org/html5/spec/single-page.html#dom-input-value-filename
On setting, if the new value is the empty string, it must empty the list of selected
files; otherwise, it must throw an InvalidStateError exception.
Test: fast/forms/file/input-file-value.html
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::setValue):
(WebCore):
* html/HTMLInputElement.h:
(HTMLInputElement):
* html/HTMLInputElement.idl:
LayoutTests:
The test input-file-value.html is split from input-file-write-test.html.
And add correct setting value for files attribute, verify the files attribute
is writable or not.
* fast/forms/file/input-file-value-expected.txt: Added.
* fast/forms/file/input-file-value.html: Added.
* fast/forms/file/input-file-write-files-expected.txt:
* fast/forms/file/input-file-write-files.html:
git-svn-id: svn://svn.chromium.org/blink/trunk@132599 bbb929c8-8fbe-4397-9dbb-9b2b20218538
Diffstat (limited to 'third_party/WebKit/LayoutTests/fast/forms')
6 files changed, 107 insertions, 74 deletions
diff --git a/third_party/WebKit/LayoutTests/fast/forms/file/file-setrangetext-expected.txt b/third_party/WebKit/LayoutTests/fast/forms/file/file-setrangetext-expected.txt index 52e412e..ee40485 100644 --- a/third_party/WebKit/LayoutTests/fast/forms/file/file-setrangetext-expected.txt +++ b/third_party/WebKit/LayoutTests/fast/forms/file/file-setrangetext-expected.txt @@ -6,7 +6,7 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE Running tests on input with attributes: {"type":"file"} -element.value = '0123456789XYZ' +PASS element.value = '0123456789XYZ' threw exception Error: INVALID_STATE_ERR: DOM Exception 11. PASS element.setRangeText('ABC', 0, 0) threw exception Error: INVALID_STATE_ERR: DOM Exception 11. PASS element.value is "" PASS successfullyParsed is true diff --git a/third_party/WebKit/LayoutTests/fast/forms/file/input-file-value-expected.txt b/third_party/WebKit/LayoutTests/fast/forms/file/input-file-value-expected.txt new file mode 100644 index 0000000..f35089d --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/forms/file/input-file-value-expected.txt @@ -0,0 +1,16 @@ +This tests the value attribute in file input forms + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +PASS file.value is "C:\\fakepath\\foo.txt" +PASS file.files.length is 1 +PASS file.value = 'foo' threw exception Error: INVALID_STATE_ERR: DOM Exception 11. +PASS file.value is "C:\\fakepath\\foo.txt" +PASS file.files.length is 1 +PASS file.value is "" +PASS file.files.length is 0 +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/third_party/WebKit/LayoutTests/fast/forms/file/input-file-value.html b/third_party/WebKit/LayoutTests/fast/forms/file/input-file-value.html new file mode 100644 index 0000000..8b79797 --- /dev/null +++ b/third_party/WebKit/LayoutTests/fast/forms/file/input-file-value.html @@ -0,0 +1,42 @@ +<!DOCTYPE html> +<html> +<head> +<script src="../../js/resources/js-test-pre.js"></script> +</head> +<body> +<input type="file" name="file" id="file"> + +<script> +description("This tests the value attribute in file input forms"); + +if (window.testRunner) { + var file = document.getElementById("file"); + dragFilesOntoInput(file, ["foo.txt"]); + + shouldBeEqualToString("file.value", "C:\\fakepath\\foo.txt"); + shouldBe("file.files.length", "1"); + + shouldThrow("file.value = 'foo'"); + shouldBeEqualToString("file.value", "C:\\fakepath\\foo.txt"); + shouldBe("file.files.length", "1"); + + file.value = ""; + shouldBeEqualToString("file.value", ""); + shouldBe("file.files.length", "0"); +} + +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="../../js/resources/js-test-post.js"></script> +</body> +</html> diff --git a/third_party/WebKit/LayoutTests/fast/forms/file/input-file-write-files-expected.txt b/third_party/WebKit/LayoutTests/fast/forms/file/input-file-write-files-expected.txt index f57d608..56bff05 100644 --- a/third_party/WebKit/LayoutTests/fast/forms/file/input-file-write-files-expected.txt +++ b/third_party/WebKit/LayoutTests/fast/forms/file/input-file-write-files-expected.txt @@ -1,6 +1,15 @@ -Test drops files here +This tests the files attribute in file input forms -PASS: 1 file after drag -PASS: writing nonempty string to value had no effect -PASS: writing empty string to value cleared files +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + +PASS file1.files.length is 1 +PASS file1.files.item(0).name is "foo.txt" +PASS file1.files.length is 1 +PASS file1.files.item(0).name is "foo.txt" +PASS file1.files.length is 1 +PASS file1.files.item(0).name is "bar.txt" +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/third_party/WebKit/LayoutTests/fast/forms/file/input-file-write-files.html b/third_party/WebKit/LayoutTests/fast/forms/file/input-file-write-files.html index 0d5e54c..63be80c 100644 --- a/third_party/WebKit/LayoutTests/fast/forms/file/input-file-write-files.html +++ b/third_party/WebKit/LayoutTests/fast/forms/file/input-file-write-files.html @@ -1,85 +1,48 @@ <!DOCTYPE html> <html> +<head> +<script src="../../js/resources/js-test-pre.js"></script> +</head> <body> -<div id="droptarget">Test drops files here</div> -<form> -<input type="file" name="files" id="files"> -</form> -<pre id='output'></pre> - +<input type="file" name="file1" id="file1"> +<input type="file" name="file2" id="file2"> <script> -function log(message) -{ - document.getElementById('output').appendChild(document.createTextNode(message + "\n")); -} +description("This tests the files attribute in file input forms"); -function onInputFileChange() -{ - var files = document.getElementById("files").files; - if (files.length != 1) - log("FAIL: Expected 1 file after drag.") - else - log("PASS: 1 file after drag"); +if (window.testRunner) { + var file1 = document.getElementById("file1"); + var file2 = document.getElementById("file2"); + dragFilesOntoInput(file1, ["foo.txt"]); + dragFilesOntoInput(file2, ["bar.txt"]); - doStringTest(); + file1.files = "foo"; + shouldBe("file1.files.length", "1"); + shouldBeEqualToString("file1.files.item(0).name", "foo.txt"); - if (window.testRunner) - testRunner.notifyDone(); -} + file1.files = null; + shouldBe("file1.files.length", "1"); + shouldBeEqualToString("file1.files.item(0).name", "foo.txt"); -function handleDragOver(e) { - e.stopPropagation(); - e.preventDefault(); + // 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 handleDrop(e) { - e.stopPropagation(); - e.preventDefault(); - document.getElementById("files").files = e.dataTransfer.files; +function moveMouseToCenterOfElement(element) { + var centerX = element.offsetLeft + element.offsetWidth / 2; + var centerY = element.offsetTop + element.offsetHeight / 2; + eventSender.mouseMoveTo(centerX, centerY); } -var droptarget = document.getElementById('droptarget'); -droptarget.addEventListener('dragover', handleDragOver, false); -droptarget.addEventListener('drop', handleDrop, false); - -function doTest(fileList) -{ - // This drops files on a div, which copies them to the input element, whose - // callback calls notifyDone(). - document.getElementById("files").onchange = onInputFileChange; - var fi = document.getElementById("files"); - eventSender.beginDragWithFiles(['../resources/test.txt']); - eventSender.mouseMoveTo(droptarget.offsetLeft + 10, droptarget.offsetTop + droptarget.offsetHeight / 2); +function dragFilesOntoInput(input, files) { + eventSender.beginDragWithFiles(files); + moveMouseToCenterOfElement(input); eventSender.mouseUp(); } - -function doStringTest() -{ - var files = document.getElementById("files"); - files.files = "foo"; // Shouldn't crash. - - files.value = "foo"; // Should do nothing. - if (files.files.length > 0) - log("PASS: writing nonempty string to value had no effect"); - else - log("FAIL: writing nonempty string to value cleared elements"); - - files.value = ""; - if (files.files.length === 0) - log("PASS: writing empty string to value cleared files"); - else - log("FAIL: writing empty string to value did not clear files"); -} - -if (window.testRunner) { - testRunner.dumpAsText(); - testRunner.waitUntilDone(); -} - -if (window.eventSender) { - doTest(); -} - </script> +<script src="../../js/resources/js-test-post.js"></script> </body> </html> diff --git a/third_party/WebKit/LayoutTests/fast/forms/resources/common-setrangetext.js b/third_party/WebKit/LayoutTests/fast/forms/resources/common-setrangetext.js index e55e309..d24e2de 100644 --- a/third_party/WebKit/LayoutTests/fast/forms/resources/common-setrangetext.js +++ b/third_party/WebKit/LayoutTests/fast/forms/resources/common-setrangetext.js @@ -145,7 +145,10 @@ function runTestsShouldFail(tagName, attributes) document.body.appendChild(element); debug("<hr>"); debug("Running tests on " + tagName + " with attributes: " + JSON.stringify(attributes) + "\n"); - evalAndLog("element.value = '0123456789XYZ'"); + if (element.getAttribute("type") == "file") + shouldThrow("element.value = '0123456789XYZ'"); + else + evalAndLog("element.value = '0123456789XYZ'"); var initialValue = element.value; shouldThrow("element.setRangeText('ABC', 0, 0)"); // setRangeText() shouldn't do anything on non-text form controls. |