-var kSerializedScriptValueVersion = 6;
+var kSerializedScriptValueVersion = 7;
function forVersion(version, values) {
var versionTag = 0xff;
return { key: key, value: sortObject(object[key]) };
});
}
+ var jsonA = JSON.stringify(sortObject(a));
+ var jsonB = JSON.stringify(sortObject(b));
+ if (jsonA != jsonB) {
+ debug("areValuesIdentical will fail");
+ debug("object A: " + jsonA);
+ debug("object B: " + jsonB);
+ }
return JSON.stringify(sortObject(a)) === JSON.stringify(sortObject(b));
}
shouldBe("self.blobContent1", "self.blobContent2");
}
-function testFileSerialization() {
- debug("");
- window.jsTestIsAsync = true;
-
+function _testFileSerialization(sourceFile, done) {
function checkIfSameContent(file1, file2, continuation) {
function step1() {
var fileReader = new FileReader();
self.fileContents1 = fileReader.result;
step2();
};
+ fileReader.onerror = function () {
+ testFailed("could not read file1. " + fileReader.error.message);
+ done();
+ }
fileReader.readAsText(file1);
}
function step2() {
self.fileContents2 = fileReader.result;
finish();
};
+ fileReader.onerror = function () {
+ testFailed("could not read file2. " + fileReader.error.message);
+ done();
+ }
fileReader.readAsText(file2);
}
function finish() {
step1();
}
- debug("Test deserialization of File objects");
- self.fileObj1 = new File(['The', ' contents'], 'testfile.txt', {type: 'text/plain', lastModified: 0});
+ self.fileObj1 = sourceFile;
self.fileObj2 = internals.deserializeBuffer(internals.serializeObject(self.fileObj1));
shouldBeTrue("areValuesIdentical(fileObj1, fileObj2)");
self.dictionaryWithFile1 = {file: fileObj1, string: 'stringValue'};
shouldBeTrue("areValuesIdentical(dictionaryWithFile1, dictionaryWithFile2)");
// Read and compare actual contents.
- checkIfSameContent(self.fileObj1, self.fileObj2, finishJSTest);
+ checkIfSameContent(self.fileObj1, self.fileObj2, done);
+}
+
+function testConstructedFileSerialization(done) {
+ debug("");
+ debug("Files created using the File constructor");
+
+ self.sourceFile = new File(['The', ' contents'], 'testfile.txt', {type: 'text/plain', lastModified: 0});
+ _testFileSerialization(sourceFile, done);
+}
+
+function testUserSelectedFileSerialization(done) {
+ debug("");
+ debug("Files selected by the user in an <input type='file'>");
+
+ var fileInput = document.getElementById("fileInput");
+ fileInput.addEventListener("change", function () {
+ self.sourceFile = fileInput.files.item(0);
+ _testFileSerialization(sourceFile, done);
+ });
+
+ eventSender.beginDragWithFiles(["resources/file.txt"]);
+ var centerX = fileInput.offsetLeft + fileInput.offsetWidth / 2;
+ var centerY = fileInput.offsetTop + fileInput.offsetHeight / 2;
+ eventSender.mouseMoveTo(centerX, centerY);
+ eventSender.mouseUp();
+}
+
+function testFileSerialization() {
+ window.jsTestIsAsync = true;
+ testConstructedFileSerialization(function () {
+ testUserSelectedFileSerialization(function () {
+ finishJSTest();
+ });
+ });
}