зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1143934 - Fix assorted forms mochitests for e10s-compatibility. r=smaug
The bug 143220 test no longer attempts to read the chrome value property from the input elements, because that would use PBlob::GetFilePath which isn't allowed on B2G, and those checks aren't really necessary anymore.
This commit is contained in:
Родитель
010b5fcc6f
Коммит
5f05e21de0
|
@ -17,11 +17,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=345339
|
|||
src="http://mochi.test:8888/tests/dom/base/test/345339_iframe.html">
|
||||
</iframe>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
<script class="testbody" type="text/javascript;version=1.7">
|
||||
/** Test for Bug 345339 **/
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var filePath;
|
||||
const testData = "Test data\n";
|
||||
let file = new File([testData],
|
||||
"345339_test.file",
|
||||
{ type: "text/plain" });
|
||||
|
||||
function afterLoad() {
|
||||
var iframeDoc = $("testframe").contentDocument;
|
||||
|
@ -32,15 +35,7 @@ function afterLoad() {
|
|||
iframeDoc.getElementById("password").value = "123456";
|
||||
iframeDoc.getElementById("hidden").value = "gecko";
|
||||
|
||||
var file = SpecialPowers.Cc["@mozilla.org/file/directory_service;1"]
|
||||
.getService(SpecialPowers.Ci.nsIProperties)
|
||||
.get("TmpD", SpecialPowers.Ci.nsILocalFile);
|
||||
file.append("345339_test.file");
|
||||
// Only the file's path is used, so it doesn't need to be created.
|
||||
// See also bug 1058977.
|
||||
filePath = file.path;
|
||||
|
||||
SpecialPowers.wrap(iframeDoc).getElementById("file").value = filePath;
|
||||
SpecialPowers.wrap(iframeDoc).getElementById("file").mozSetFileArray([file]);
|
||||
|
||||
/* Reload the page */
|
||||
$("testframe").setAttribute("onload", "afterReload()");
|
||||
|
@ -62,10 +57,26 @@ function afterReload() {
|
|||
"password field value forgotten");
|
||||
is(iframeDoc.getElementById("hidden").value, "gecko",
|
||||
"hidden field value preserved");
|
||||
is(SpecialPowers.wrap(iframeDoc).getElementById("file").value, filePath,
|
||||
"file field value preserved");
|
||||
|
||||
SimpleTest.finish();
|
||||
// The new file object isn't ===, but it's extensionally equal:
|
||||
let newFile = iframeDoc.getElementById("file").files[0];
|
||||
for (let prop of ["name", "lastModified", "size", "type"]) {
|
||||
is(newFile[prop], file[prop],
|
||||
"file field " + prop + " property preserved");
|
||||
}
|
||||
let reader = new FileReader();
|
||||
reader.onloadend = function() {
|
||||
SimpleTest.finish();
|
||||
};
|
||||
reader.onload = function() {
|
||||
is(reader.result, testData,
|
||||
"file field contents preserved")
|
||||
};
|
||||
reader.onerror = function() {
|
||||
is(reader.error, null,
|
||||
"FileReader error");
|
||||
};
|
||||
reader.readAsText(newFile);
|
||||
}
|
||||
</script>
|
||||
</pre>
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||
Cu.importGlobalProperties(["File"]);
|
||||
|
||||
addMessageListener("files.open", function (message) {
|
||||
sendAsyncMessage("files.opened", message.map(path => new File(path)));
|
||||
});
|
|
@ -68,12 +68,10 @@ skip-if = buildapp == 'mulet'
|
|||
[test_label_control_attribute.html]
|
||||
[test_label_input_controls.html]
|
||||
[test_max_attribute.html]
|
||||
skip-if = e10s
|
||||
[test_maxlength_attribute.html]
|
||||
[test_meter_element.html]
|
||||
[test_meter_pseudo-classes.html]
|
||||
[test_min_attribute.html]
|
||||
skip-if = e10s
|
||||
[test_mozistextfield.html]
|
||||
[test_novalidate_attribute.html]
|
||||
[test_option_disabled.html]
|
||||
|
@ -85,14 +83,12 @@ skip-if = e10s
|
|||
[test_radio_in_label.html]
|
||||
[test_radio_radionodelist.html]
|
||||
[test_required_attribute.html]
|
||||
skip-if = e10s
|
||||
[test_restore_form_elements.html]
|
||||
[test_save_restore_radio_groups.html]
|
||||
[test_select_selectedOptions.html]
|
||||
[test_select_validation.html]
|
||||
[test_set_range_text.html]
|
||||
[test_step_attribute.html]
|
||||
skip-if = e10s
|
||||
[test_stepup_stepdown.html]
|
||||
[test_textarea_attributes_reflection.html]
|
||||
[test_validation.html]
|
||||
|
|
|
@ -175,14 +175,9 @@ for (var test of data) {
|
|||
checkValidity(input, true, apply, apply);
|
||||
break;
|
||||
case 'file':
|
||||
var dirSvc = SpecialPowers.Cc["@mozilla.org/file/directory_service;1"]
|
||||
.getService(SpecialPowers.Ci.nsIProperties);
|
||||
var file = dirSvc.get("ProfD", SpecialPowers.Ci.nsIFile);
|
||||
file.append('635499_file');
|
||||
// Only the file's path is used, so it doesn't need to be created.
|
||||
// See also bug 1058977.
|
||||
var file = new File([''], '635499_file');
|
||||
|
||||
SpecialPowers.wrap(input).value = file.path;
|
||||
SpecialPowers.wrap(input).mozSetFileArray([file]);
|
||||
checkValidity(input, true, apply, apply);
|
||||
|
||||
break;
|
||||
|
|
|
@ -173,14 +173,9 @@ for (var test of data) {
|
|||
checkValidity(input, true, apply, apply);
|
||||
break;
|
||||
case 'file':
|
||||
var dirSvc = SpecialPowers.Cc["@mozilla.org/file/directory_service;1"]
|
||||
.getService(SpecialPowers.Ci.nsIProperties);
|
||||
var file = dirSvc.get("ProfD", SpecialPowers.Ci.nsIFile);
|
||||
file.append('635499_file');
|
||||
// Only the file's path is used, so it doesn't need to be created.
|
||||
// See also bug 1058977.
|
||||
var file = new File([''], '635499_file');
|
||||
|
||||
SpecialPowers.wrap(input).value = file.path;
|
||||
SpecialPowers.wrap(input).mozSetFileArray([file]);
|
||||
checkValidity(input, true, apply, apply);
|
||||
|
||||
break;
|
||||
|
|
|
@ -41,9 +41,12 @@ function completeValidityCheck(element, alwaysValid, isBarred)
|
|||
} else if (element.type == 'url') {
|
||||
element.pattern = "http://.*\\.com$";
|
||||
element.value = "http://mozilla.com";
|
||||
} else if (element.type == 'file') {
|
||||
element.pattern = "foo";
|
||||
SpecialPowers.wrap(element).mozSetFileArray([new File(["foo"], "foo")]);
|
||||
} else {
|
||||
element.pattern = "foo";
|
||||
SpecialPowers.wrap(element).value = "foo";
|
||||
element.value = "foo";
|
||||
}
|
||||
|
||||
checkValidPattern(element, true, isBarred);
|
||||
|
@ -56,9 +59,12 @@ function completeValidityCheck(element, alwaysValid, isBarred)
|
|||
} else if (element.type == 'url') {
|
||||
element.pattern = "http://.*\\.com$";
|
||||
element.value = "http://mozilla.org";
|
||||
} else if (element.type == 'file') {
|
||||
element.pattern = "foo";
|
||||
SpecialPowers.wrap(element).mozSetFileArray([new File(["bar"], "bar")]);
|
||||
} else {
|
||||
element.pattern = "foo";
|
||||
SpecialPowers.wrap(element).value = "bar";
|
||||
element.value = "bar";
|
||||
}
|
||||
|
||||
if (!alwaysValid) {
|
||||
|
|
|
@ -314,18 +314,7 @@ function checkInputRequiredValidityForFile()
|
|||
element.type = 'file'
|
||||
document.forms[0].appendChild(element);
|
||||
|
||||
function createFile(fileName) {
|
||||
var dirSvc = SpecialPowers.Cc["@mozilla.org/file/directory_service;1"]
|
||||
.getService(SpecialPowers.Ci.nsIProperties);
|
||||
var testFile = dirSvc.get("ProfD", SpecialPowers.Ci.nsIFile);
|
||||
testFile.append(fileName);
|
||||
// Only the file's path is used, so it doesn't need to be created.
|
||||
// See also bug 1058977.
|
||||
|
||||
return testFile;
|
||||
}
|
||||
|
||||
var file = createFile("345822_file");
|
||||
var file = new File([""], "345822_file");
|
||||
|
||||
SpecialPowers.wrap(element).value = "";
|
||||
element.required = false;
|
||||
|
@ -334,7 +323,7 @@ function checkInputRequiredValidityForFile()
|
|||
element.required = true;
|
||||
checkSufferingFromBeingMissing(element, true);
|
||||
|
||||
SpecialPowers.wrap(element).value = file.path;
|
||||
SpecialPowers.wrap(element).mozSetFileArray([file]);
|
||||
checkNotSufferingFromBeingMissing(element);
|
||||
|
||||
SpecialPowers.wrap(element).value = "";
|
||||
|
@ -344,7 +333,7 @@ function checkInputRequiredValidityForFile()
|
|||
checkNotSufferingFromBeingMissing(element);
|
||||
|
||||
element.focus();
|
||||
SpecialPowers.wrap(element).value = file.path;
|
||||
SpecialPowers.wrap(element).mozSetFileArray([file]);
|
||||
element.required = true;
|
||||
element.blur();
|
||||
element.form.reset();
|
||||
|
|
|
@ -128,14 +128,9 @@ for (var test of data) {
|
|||
checkValidity(input, true, apply);
|
||||
break;
|
||||
case 'file':
|
||||
var dirSvc = SpecialPowers.Cc["@mozilla.org/file/directory_service;1"]
|
||||
.getService(SpecialPowers.Ci.nsIProperties);
|
||||
var file = dirSvc.get("ProfD", SpecialPowers.Ci.nsIFile);
|
||||
file.append('635499_file');
|
||||
// Only the file's path is used, so it doesn't need to be created.
|
||||
// See also bug 1058977.
|
||||
var file = new File([''], '635499_file');
|
||||
|
||||
SpecialPowers.wrap(input).value = file.path;
|
||||
SpecialPowers.wrap(input).mozSetFileArray([file]);
|
||||
checkValidity(input, true, apply);
|
||||
|
||||
break;
|
||||
|
|
|
@ -178,6 +178,7 @@ support-files =
|
|||
file_srcdoc.html
|
||||
file_window_open_close_outer.html
|
||||
file_window_open_close_inner.html
|
||||
formSubmission_chrome.js
|
||||
form_submit_server.sjs
|
||||
formData_worker.js
|
||||
formData_test.js
|
||||
|
@ -459,7 +460,7 @@ skip-if = (toolkit == 'gonk' && debug) || e10s #debug-only failure
|
|||
[test_embed_attributes_reflection.html]
|
||||
[test_formData.html]
|
||||
[test_formSubmission.html]
|
||||
skip-if = buildapp == 'b2g' || toolkit == 'android' || e10s #TIMED_OUT # b2g(NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) b2g-debug(NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) b2g-desktop(NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)
|
||||
skip-if = buildapp == 'b2g' || toolkit == 'android' #TIMED_OUT # b2g(NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) b2g-debug(NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) b2g-desktop(NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)
|
||||
[test_formSubmission2.html]
|
||||
skip-if = toolkit == 'android'
|
||||
[test_formelements.html]
|
||||
|
|
|
@ -18,49 +18,53 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=143220
|
|||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
<script class="testbody" type="text/javascript;version=1.7">
|
||||
|
||||
/** Test for Bug 143220 **/
|
||||
var leafName;
|
||||
var fullPath;
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
const helperURL = SimpleTest.getTestFileURL("simpleFileOpener.js");
|
||||
const helper = SpecialPowers.loadChromeScript(helperURL);
|
||||
helper.addMessageListener("fail", function onFail(message) {
|
||||
is(message, null, "chrome script failed");
|
||||
SimpleTest.finish();
|
||||
});
|
||||
helper.addMessageListener("file.opened", onFileOpened);
|
||||
helper.sendAsyncMessage("file.open", "test_bug143220.txt");
|
||||
|
||||
function onFileOpened(message) {
|
||||
const { leafName, fullPath, domFile } = message;
|
||||
|
||||
function initVals() {
|
||||
var dirSvc = SpecialPowers.Cc["@mozilla.org/file/directory_service;1"]
|
||||
.getService(SpecialPowers.Ci.nsIProperties);
|
||||
var file = dirSvc.get("XpcomLib", SpecialPowers.Ci.nsILocalFile);
|
||||
isnot(file, null, "Must have file here");
|
||||
function initControl1() {
|
||||
SpecialPowers.wrap($("i1")).mozSetFileArray([domFile]);
|
||||
}
|
||||
|
||||
leafName = file.leafName;
|
||||
fullPath = file.path;
|
||||
function initControl2() {
|
||||
SpecialPowers.wrap($("i2")).mozSetFileArray([domFile]);
|
||||
}
|
||||
|
||||
// Check that we can't just set the value
|
||||
try {
|
||||
$("i1").value = fullPath;
|
||||
is(0, 1, "Should have thrown exception on set!");
|
||||
} catch(e) {
|
||||
is($("i1").value, "", "Shouldn't have value here");
|
||||
}
|
||||
|
||||
initControl1();
|
||||
initControl2();
|
||||
|
||||
is($("i1").value, leafName, "Leaking full value?");
|
||||
is($("i2").value, leafName, "Leaking full value?");
|
||||
|
||||
helper.addMessageListener("file.removed", onFileRemoved);
|
||||
helper.sendAsyncMessage("file.remove", null);
|
||||
}
|
||||
|
||||
function initControl1() {
|
||||
SpecialPowers.wrap($("i1")).value = fullPath;
|
||||
is(SpecialPowers.wrap($("i1")).value, fullPath, "Should have set full path 1");
|
||||
function onFileRemoved() {
|
||||
helper.destroy();
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function initControl2() {
|
||||
SpecialPowers.wrap($("i2")).value = fullPath;
|
||||
is(SpecialPowers.wrap($("i2")).value, fullPath, "Should have set full path 2");
|
||||
}
|
||||
|
||||
initVals();
|
||||
|
||||
// Check that we can't just set the value
|
||||
try {
|
||||
$("i1").value = fullPath;
|
||||
is(0, 1, "Should have thrown exception on set!");
|
||||
} catch(e) {
|
||||
is($("i1").value, "", "Shouldn't have value here");
|
||||
}
|
||||
|
||||
initControl1();
|
||||
initControl2();
|
||||
|
||||
is($("i1").value, leafName, "Leaking full value?");
|
||||
is($("i2").value, leafName, "Leaking full value?");
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
|
|
|
@ -399,41 +399,59 @@ t_6_v</textarea>
|
|||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var myFile1, myFile2, emptyFile;
|
||||
const placeholder_myFile1 = {};
|
||||
const placeholder_myFile2 = {};
|
||||
const placeholder_emptyFile = {};
|
||||
|
||||
(function setFileNames() {
|
||||
var myFile1, myFile2, emptyFile;
|
||||
let openerURL = SimpleTest.getTestFileURL("formSubmission_chrome.js");
|
||||
let opener = SpecialPowers.loadChromeScript(openerURL);
|
||||
|
||||
{
|
||||
let xhr = new XMLHttpRequest;
|
||||
xhr.open("GET", "/dynamic/getMyDirectory.sjs", false);
|
||||
xhr.send();
|
||||
var basePath = xhr.responseText;
|
||||
let basePath = xhr.responseText;
|
||||
|
||||
singleFile = basePath + "file_formSubmission_text.txt";
|
||||
multiFile = [basePath + "file_formSubmission_text.txt",
|
||||
basePath + "file_formSubmission_img.jpg"];
|
||||
opener.addMessageListener("files.opened", onFilesOpened);
|
||||
opener.sendAsyncMessage("files.open", [
|
||||
basePath + "file_formSubmission_text.txt",
|
||||
basePath + "file_formSubmission_img.jpg",
|
||||
]);
|
||||
}
|
||||
|
||||
function onFilesOpened(files) {
|
||||
let [textFile, imageFile] = files;
|
||||
opener.destroy();
|
||||
|
||||
let singleFile = textFile;
|
||||
let multiFile = [textFile, imageFile];
|
||||
|
||||
var addList = document.getElementsByClassName("setfile");
|
||||
let i = 0;
|
||||
var input;
|
||||
while (input = addList[i++]) {
|
||||
if (input.classList.contains("multi")) {
|
||||
SpecialPowers.wrap(input).mozSetFileNameArray(multiFile, multiFile.length);
|
||||
SpecialPowers.wrap(input).mozSetFileArray(multiFile);
|
||||
}
|
||||
else {
|
||||
SpecialPowers.wrap(input).value = singleFile;
|
||||
SpecialPowers.wrap(input).mozSetFileArray([singleFile]);
|
||||
}
|
||||
}
|
||||
|
||||
input = document.createElement("input");
|
||||
input.type = "file";
|
||||
input.multiple = true;
|
||||
SpecialPowers.wrap(input).mozSetFileNameArray(multiFile, multiFile.length);
|
||||
SpecialPowers.wrap(input).mozSetFileArray(multiFile);
|
||||
myFile1 = input.files[0];
|
||||
myFile2 = input.files[1];
|
||||
is(myFile1.size, 20, "File1 size");
|
||||
is(myFile2.size, 2711, "File2 size");
|
||||
emptyFile = { name: "", type: "application/octet-stream" };
|
||||
})();
|
||||
|
||||
// Now, actually run the tests; see below.
|
||||
onFilesSet();
|
||||
};
|
||||
|
||||
var expectedSub = [
|
||||
// Default input
|
||||
|
@ -495,13 +513,13 @@ var expectedSub = [
|
|||
// Reset button
|
||||
// Unknown button
|
||||
// File
|
||||
{ name: "file_1", value: myFile1 },
|
||||
{ name: "file_2", value: emptyFile },
|
||||
{ name: "file_1", value: placeholder_myFile1 },
|
||||
{ name: "file_2", value: placeholder_emptyFile },
|
||||
// Multiple file
|
||||
{ name: "file_3", value: myFile1 },
|
||||
{ name: "file_4", value: myFile1 },
|
||||
{ name: "file_4", value: myFile2 },
|
||||
{ name: "file_5", value: emptyFile },
|
||||
{ name: "file_3", value: placeholder_myFile1 },
|
||||
{ name: "file_4", value: placeholder_myFile1 },
|
||||
{ name: "file_4", value: placeholder_myFile2 },
|
||||
{ name: "file_5", value: placeholder_emptyFile },
|
||||
// Textarea
|
||||
{ name: "t1", value: "t_1_v" },
|
||||
{ name: "t2", value: "" },
|
||||
|
@ -562,12 +580,12 @@ var expectedSub = [
|
|||
{ name: "msel_31", value: "msel_31_v1" },
|
||||
];
|
||||
|
||||
expectedAugment = [
|
||||
var expectedAugment = [
|
||||
{ name: "aName", value: "aValue" },
|
||||
//{ name: "aNameBool", value: "false" },
|
||||
{ name: "aNameNum", value: "9.2" },
|
||||
{ name: "aNameFile1", value: myFile1 },
|
||||
{ name: "aNameFile2", value: myFile2 },
|
||||
{ name: "aNameFile1", value: placeholder_myFile1 },
|
||||
{ name: "aNameFile2", value: placeholder_myFile2 },
|
||||
//{ name: "aNameObj", value: "[object XMLHttpRequest]" },
|
||||
//{ name: "aNameNull", value: "null" },
|
||||
//{ name: "aNameUndef", value: "undefined" },
|
||||
|
@ -661,10 +679,13 @@ function setDisabled(list, state) {
|
|||
});
|
||||
}
|
||||
|
||||
var gen = runTest();
|
||||
addLoadEvent(function() {
|
||||
gen.next();
|
||||
});
|
||||
var gen;
|
||||
function onFilesSet() {
|
||||
gen = runTest();
|
||||
addLoadEvent(function() {
|
||||
gen.next();
|
||||
});
|
||||
}
|
||||
|
||||
function runTest() {
|
||||
// Set up the expectedSub array
|
||||
|
@ -676,17 +697,17 @@ function runTest() {
|
|||
yield undefined; // Wait for both FileReaders. We don't care which order they finish.
|
||||
yield undefined;
|
||||
function fileFixup(o) {
|
||||
if (o.value == myFile1) {
|
||||
if (o.value === placeholder_myFile1) {
|
||||
o.value = fileReader1.result;
|
||||
o.fileName = myFile1.name;
|
||||
o.contentType = myFile1.type;
|
||||
}
|
||||
else if (o.value == myFile2) {
|
||||
else if (o.value === placeholder_myFile2) {
|
||||
o.value = fileReader2.result;
|
||||
o.fileName = myFile2.name;
|
||||
o.contentType = myFile2.type;
|
||||
}
|
||||
else if (o.value == emptyFile) {
|
||||
else if (o.value === placeholder_emptyFile) {
|
||||
o.value = "";
|
||||
o.fileName = emptyFile.name;
|
||||
o.contentType = emptyFile.type;
|
||||
|
|
Загрузка…
Ссылка в новой задаче