| OLD | NEW |
| 1 var kSerializedScriptValueVersion = 4; |
| 2 |
| 3 function forVersion(version, values) { |
| 4 var versionTag = 0xff; |
| 5 var versionPrefix = [ (version << 8) | versionTag ]; |
| 6 |
| 7 return versionPrefix.concat(values) |
| 8 } |
| 9 |
| 1 function expectBufferValue(bytesPerElement, expectedValues, buffer) { | 10 function expectBufferValue(bytesPerElement, expectedValues, buffer) { |
| 2 expectedBufferValues = expectedValues; | 11 expectedBufferValues = expectedValues; |
| 3 var arrayClass; | 12 var arrayClass; |
| 4 if (bytesPerElement == 1) | 13 if (bytesPerElement == 1) |
| 5 arrayClass = Uint8Array; | 14 arrayClass = Uint8Array; |
| 6 else | 15 else |
| 7 arrayClass = Uint16Array; | 16 arrayClass = Uint16Array; |
| 8 bufferView = new arrayClass(buffer); | 17 bufferView = new arrayClass(buffer); |
| 9 shouldBe("bufferView.length", "expectedBufferValues.length"); | 18 shouldBe("bufferView.length", "expectedBufferValues.length"); |
| 10 var success = (bufferView.length == expectedBufferValues.length); | 19 var success = (bufferView.length == expectedBufferValues.length); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 return Object.keys(object).sort().map(function(key) { | 62 return Object.keys(object).sort().map(function(key) { |
| 54 return { key: key, value: sortObject(object[key]) }; | 63 return { key: key, value: sortObject(object[key]) }; |
| 55 }); | 64 }); |
| 56 } | 65 } |
| 57 return JSON.stringify(sortObject(a)) === JSON.stringify(sortObject(b)); | 66 return JSON.stringify(sortObject(a)) === JSON.stringify(sortObject(b)); |
| 58 } | 67 } |
| 59 | 68 |
| 60 function _testSerialization(bytesPerElement, obj, values, oldFormat, serializeEx
ceptionValue) { | 69 function _testSerialization(bytesPerElement, obj, values, oldFormat, serializeEx
ceptionValue) { |
| 61 debug(""); | 70 debug(""); |
| 62 | 71 |
| 72 values = forVersion(kSerializedScriptValueVersion, values); |
| 73 |
| 63 if (!serializeExceptionValue) { | 74 if (!serializeExceptionValue) { |
| 64 self.obj = obj; | 75 self.obj = obj; |
| 65 debug("Deserialize to " + JSON.stringify(obj) + ":"); | 76 debug("Deserialize to " + JSON.stringify(obj) + ":"); |
| 66 self.newObj = internals.deserializeBuffer(makeBuffer(bytesPerElement, va
lues)); | 77 self.newObj = internals.deserializeBuffer(makeBuffer(bytesPerElement, va
lues)); |
| 67 shouldBe("JSON.stringify(newObj)", "JSON.stringify(obj)"); | 78 shouldBe("JSON.stringify(newObj)", "JSON.stringify(obj)"); |
| 68 shouldBeTrue("areValuesIdentical(newObj, obj)"); | 79 shouldBeTrue("areValuesIdentical(newObj, obj)"); |
| 69 | 80 |
| 70 if (oldFormat) { | 81 if (oldFormat) { |
| 71 self.newObj = internals.deserializeBuffer(makeBuffer(bytesPerElement
, oldFormat)); | 82 self.newObj = internals.deserializeBuffer(makeBuffer(bytesPerElement
, oldFormat)); |
| 72 shouldBe("JSON.stringify(newObj)", "JSON.stringify(obj)"); | 83 shouldBe("JSON.stringify(newObj)", "JSON.stringify(obj)"); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // Compare contents too. | 117 // Compare contents too. |
| 107 var xhr1 = new XMLHttpRequest(); | 118 var xhr1 = new XMLHttpRequest(); |
| 108 xhr1.open("GET", URL.createObjectURL(self.blobObj1), false); | 119 xhr1.open("GET", URL.createObjectURL(self.blobObj1), false); |
| 109 xhr1.send(); | 120 xhr1.send(); |
| 110 self.blobContent1 = xhr1.response; | 121 self.blobContent1 = xhr1.response; |
| 111 var xhr2 = new XMLHttpRequest(); | 122 var xhr2 = new XMLHttpRequest(); |
| 112 xhr2.open("GET", URL.createObjectURL(self.blobObj2), false); | 123 xhr2.open("GET", URL.createObjectURL(self.blobObj2), false); |
| 113 xhr2.send(); | 124 xhr2.send(); |
| 114 self.blobContent2 = xhr2.response; | 125 self.blobContent2 = xhr2.response; |
| 115 shouldBe("self.blobContent1", "self.blobContent2"); | 126 shouldBe("self.blobContent1", "self.blobContent2"); |
| 116 } | 127 } |
| 128 |
| 129 function testFileSerialization() { |
| 130 debug(""); |
| 131 window.jsTestIsAsync = true; |
| 132 |
| 133 function checkIfSameContent(file1, file2, continuation) { |
| 134 function step1() { |
| 135 var fileReader = new FileReader(); |
| 136 fileReader.onload = function () { |
| 137 self.fileContents1 = fileReader.result; |
| 138 step2(); |
| 139 }; |
| 140 fileReader.readAsText(file1); |
| 141 } |
| 142 function step2() { |
| 143 var fileReader = new FileReader(); |
| 144 fileReader.onload = function () { |
| 145 self.fileContents2 = fileReader.result; |
| 146 finish(); |
| 147 }; |
| 148 fileReader.readAsText(file2); |
| 149 } |
| 150 function finish() { |
| 151 shouldBe("self.fileContents1", "self.fileContents2"); |
| 152 continuation(); |
| 153 } |
| 154 step1(); |
| 155 } |
| 156 |
| 157 debug("Test deserialization of File objects"); |
| 158 self.fileObj1 = new File(['The', ' contents'], 'testfile.txt', {type: 'text/
plain', lastModified: 0}); |
| 159 self.fileObj2 = internals.deserializeBuffer(internals.serializeObject(self.f
ileObj1)); |
| 160 shouldBeTrue("areValuesIdentical(fileObj1, fileObj2)"); |
| 161 self.dictionaryWithFile1 = {file: fileObj1, string: 'stringValue'}; |
| 162 self.dictionaryWithFile2 = internals.deserializeBuffer(internals.serializeOb
ject(dictionaryWithFile1)); |
| 163 shouldBeTrue("areValuesIdentical(dictionaryWithFile1, dictionaryWithFile2)")
; |
| 164 |
| 165 // Read and compare actual contents. |
| 166 checkIfSameContent(self.fileObj1, self.fileObj2, finishJSTest); |
| 167 } |
| OLD | NEW |