Bug 1421176 - nsMultiplexInputStream::Available() sanitize - mochitest - r=smaug

This is a test to check if nsMultiplexInputStream supports empty inputStreams.
This commit is contained in:
Andrea Marchesini 2017-11-30 20:00:23 +01:00
Родитель 3589e9efe6
Коммит 827b28d3b6
3 изменённых файлов: 62 добавлений и 3 удалений

Просмотреть файл

@ -1,8 +1,8 @@
[DEFAULT]
support-files =
support-files = script_file.js
[test_ipcBlob_fileReaderSync.html]
support-files = script_file.js
[test_ipcBlob_workers.html]
[test_ipcBlob_createImageBitmap.html]
support-files = green.jpg
[test_ipcBlob_emptyMultiplex.html]

Просмотреть файл

@ -7,7 +7,7 @@ addMessageListener("file.open", function (e) {
.QueryInterface(Ci.nsIProperties)
.get("ProfD", Ci.nsIFile);
testFile.append("ipc_fileReader_testing");
testFile.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0o600);
testFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0o600);
var outStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
@ -22,3 +22,21 @@ addMessageListener("file.open", function (e) {
sendAsyncMessage("file.opened", { file });
});
});
addMessageListener("emptyfile.open", function (e) {
var testFile = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIDirectoryService)
.QueryInterface(Ci.nsIProperties)
.get("ProfD", Ci.nsIFile);
testFile.append("ipc_fileReader_testing");
testFile.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0o600);
var outStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
outStream.init(testFile, 0x02 | 0x08 | 0x20, // write, create, truncate
0666, 0);
File.createFromNsIFile(testFile).then(function(file) {
sendAsyncMessage("emptyfile.opened", { file });
});
});

Просмотреть файл

@ -0,0 +1,41 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test an empty IPCBlob together with other parts</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script type="text/javascript">
function checkContent(msg, content) {
return new Promise(resolve => {
let fr = new FileReader();
fr.readAsText(new Blob(content));
fr.onloadend = () => {
is(fr.result, "Hello world!", "The content matches: " + msg);
resolve();
};
});
}
SimpleTest.waitForExplicitFinish();
let url = SimpleTest.getTestFileURL("script_file.js");
let script = SpecialPowers.loadChromeScript(url);
script.addMessageListener("emptyfile.opened", message => {
checkContent("middle", ["Hello ", message.file, "world!"]).
then(() => checkContent("begin", [message.file, "Hello world!"])).
then(() => checkContent("end", ["Hello world!", message.file])).
then(() => checkContent("random", [message.file, message.file, "Hello world!", message.file])).
then(SimpleTest.finish);
});
script.sendAsyncMessage("emptyfile.open");
</script>
</pre>
</body>
</html>