Skip to content
Permalink
Browse files
[CB-2406] Add ArrayBuffer and Blob FileWriter tests
  • Loading branch information
clelland committed Jun 12, 2013
1 parent 579475e commit cf3e6ac5045a6d01cbf7fed029c8532c3fbc0080
Showing 1 changed file with 98 additions and 0 deletions.
@@ -3467,6 +3467,104 @@ describe('File API', function() {

waitsFor(function() { return verifier.wasCalled; }, "verifier never called", Tests.TEST_TIMEOUT);

runs(function() {
expect(verifier).toHaveBeenCalled();
expect(fail).not.toHaveBeenCalled();
});
});
it("file.spec.104 should be able to write binary data from an ArrayBuffer", function() {
var fileName = "bufferwriter.bin",
filePath = root.fullPath + '/' + fileName,
theWriter,
// file content
data = new ArrayBuffer(32),
dataView = new Int8Array(data),
fail = createFail('FileWriter'),
// for verifying file length
length = 32,
verifier = jasmine.createSpy().andCallFake(function(evt) {
expect(theWriter.length).toBe(length);
expect(theWriter.position).toBe(length);

// cleanup
deleteFile(fileName);
}),
// writes file content
write_file = function(fileEntry) {
fileEntry.createWriter(function(writer) {
theWriter = writer;
theWriter.onwriteend = verifier;
theWriter.write(data);
}, fail);
};

for (i=0; i < dataView.length; i++) {
dataView[i] = i;
}

// creates file, then write content
runs(function() {
createFile(fileName, write_file);
});

waitsFor(function() { return verifier.wasCalled; }, "verifier", Tests.TEST_TIMEOUT);

runs(function() {
expect(verifier).toHaveBeenCalled();
expect(fail).not.toHaveBeenCalled();
});
});
it("file.spec.105 should be able to write binary data from a Blob", function() {
var fileName = "blobwriter.bin",
filePath = root.fullPath + '/' + fileName,
theWriter,
fail = createFail('FileWriter'),
// file content
data = new ArrayBuffer(32),
dataView = new Int8Array(data),
blob,
// for verifying file length
length = 32,
verifier = jasmine.createSpy().andCallFake(function(evt) {
expect(theWriter.length).toBe(length);
expect(theWriter.position).toBe(length);

// cleanup
deleteFile(fileName);
}),
// writes file content
write_file = function(fileEntry) {
fileEntry.createWriter(function(writer) {
theWriter = writer;
theWriter.onwriteend = verifier;
theWriter.write(blob);
}, fail);
};
for (i=0; i < dataView.length; i++) {
dataView[i] = i;
}
try {
// Mobile Safari: Use Blob constructor
blob = new Blob([data], {"type": "application/octet-stream"})
} catch(e) {
if (window.WebKitBlobBuilder) {
// Android Browser: Use deprecated BlobBuilder
var builder = new WebKitBlobBuilder()
builder.append(data)
blob = builder.getBlob('application/octet-stream');
} else {
// We have no way defined to create a Blob, so fail
fail();
}
}

// creates file, then write content
runs(function() {
createFile(fileName, write_file);
});

waitsFor(function() { return verifier.wasCalled; }, "verifier", Tests.TEST_TIMEOUT);

runs(function() {
expect(verifier).toHaveBeenCalled();
expect(fail).not.toHaveBeenCalled();

0 comments on commit cf3e6ac

Please sign in to comment.