2007-12-18 00:20:40 +03:00
<!DOCTYPE HTML>
< html >
< head >
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=403852
-->
< title > Test for Bug 403852< / title >
< script type = "text/javascript" src = "/tests/SimpleTest/SimpleTest.js" > < / script >
< link rel = "stylesheet" type = "text/css" href = "/tests/SimpleTest/test.css" / >
< / head >
< body >
< a target = "_blank" href = "https://bugzilla.mozilla.org/show_bug.cgi?id=403852" > Mozilla Bug 403852< / a >
< p id = "display" >
< input id = "fileList" type = "file" > < / input >
< / p >
< div id = "content" style = "display: none" >
< / div >
< pre id = "test" >
< script class = "testbody" type = "text/javascript" >
2015-01-27 03:23:00 +03:00
SimpleTest.waitForExplicitFinish();
2007-12-18 00:20:40 +03:00
2015-01-27 03:23:00 +03:00
var url = SimpleTest.getTestFileURL("bug403852_fileOpener.js");
var script = SpecialPowers.loadChromeScript(url);
script.addMessageListener("file.opened", onOpened);
script.sendAsyncMessage("file.open");
2007-12-18 00:20:40 +03:00
2015-01-27 03:23:00 +03:00
function onOpened(message) {
var fileList = document.getElementById('fileList');
SpecialPowers.wrap(fileList).mozSetFileArray([message.file]);
2007-12-18 00:20:40 +03:00
2015-01-27 03:23:00 +03:00
// Make sure the file is accessible with indexed notation
var domFile = fileList.files[0];
2007-12-18 00:20:40 +03:00
2015-01-27 03:23:00 +03:00
is(domFile.name, "prefs.js", "fileName should be prefs.js");
2007-12-18 00:20:40 +03:00
2015-01-27 03:23:00 +03:00
ok("lastModifiedDate" in domFile, "lastModifiedDate must be present");
2012-05-22 02:11:56 +04:00
2015-01-27 03:23:00 +03:00
var d = new Date(message.mtime);
2015-02-10 11:31:00 +03:00
is(d.getTime(), domFile.lastModifiedDate.getTime(), "lastModifiedDate should be the same");
2012-05-22 02:11:56 +04:00
2015-01-27 03:23:00 +03:00
var x = new Date();
2014-10-08 20:15:22 +04:00
2015-01-27 03:23:00 +03:00
// In our implementation of File object, lastModifiedDate is unknown only for new objects.
// Using canvas or input[type=file] elements, we 'often' have a valid lastModifiedDate values.
// For canvas we use memory files and the lastModifiedDate is now().
var f = new File([new Blob(['test'], {type: 'text/plain'})], "test-name");
2014-10-08 20:15:22 +04:00
2015-01-27 03:23:00 +03:00
var y = f.lastModifiedDate;
var z = new Date();
2012-10-04 18:38:18 +04:00
2015-01-27 03:23:00 +03:00
ok((x.getTime() < = y.getTime()) & & (y.getTime() < = z.getTime()), "lastModifiedDate of file which does not have last modified date should be current time");
2015-02-10 11:31:00 +03:00
var d = new Date(message.fileDate);
is(d.getTime(), message.fileWithDate.lastModifiedDate.getTime(), "lastModifiedDate should be the same when lastModified is set: " + message.fileWithDate.lastModified);
2015-01-27 03:23:00 +03:00
script.destroy();
SimpleTest.finish();
}
2012-10-04 18:38:18 +04:00
2007-12-18 00:20:40 +03:00
< / script >
< / pre >
< / body > < / html >