1 if (this.importScripts) {
2 importScripts('fs-worker-common.js');
3 importScripts('file-writer-utils.js');
6 description("Test that FileWriter can continue immediately after an abort.");
13 var truncateLength = 7;
14 var blobSize = 1100000;
17 { // Setup method set that writes, then aborts that write before completion.
20 onwritestart : abortWrite,
23 onwriteend : checkLengthAndCallFollowOnAction
25 { // Method set that does a complete write.
27 verifyLength : blobSize,
31 onwriteend : checkLengthAndStartNextTest
33 { // Setup method set that writes, then aborts that write before completion.
35 verifyLength : blobSize, // Left over from the previous test.
36 onwritestart : abortWrite,
39 onwriteend : checkLengthAndCallFollowOnAction
41 { // Method set that does a complete truncate.
42 action : startTruncate,
43 verifyLength : truncateLength,
47 onwriteend : checkLengthAndCompleteTest
53 function tenXBlob(blob) {
54 var bb = new WebKitBlobBuilder();
55 for (var i = 0; i < 10; ++i) {
61 // These methods set up a write, abort it as soon as it starts, then initiate
62 // the follow on action.
63 function abortWrite(e) {
64 testPassed("Calling abort");
68 function logAbort(e) {
69 testPassed("Saw abort");
72 function checkLengthAndCallFollowOnAction(e) {
73 testPassed("Saw writeend 0.");
74 shouldBe("writer.length", "" + expectedLength);
78 // For the second method set, verify completion and move on to the next test.
79 function checkLengthAndStartNextTest(e) {
80 shouldBe("writer.length", "" + expectedLength);
81 testPassed("Saw writeend 1.");
85 function checkLengthAndCompleteTest(e) {
86 shouldBe("writer.length", "" + expectedLength);
87 testPassed("All tests complete.");
91 function startWrite() {
92 // Let's make it about a megabyte.
93 var bb = new WebKitBlobBuilder();
94 bb.append("lorem ipsum");
95 var blob = tenXBlob(bb.getBlob());
96 blob = tenXBlob(blob);
97 blob = tenXBlob(blob);
98 blob = tenXBlob(blob);
99 blob = tenXBlob(blob);
100 var size = blob.size;
101 shouldBe("" + size, "blobSize");
105 function startTruncate() {
106 writer.truncate(truncateLength);
109 function setupWriter(methodSetIndex, writer) {
110 writer.onerror = onError;
112 var methods = methodSet[methodSetIndex];
113 writer.onabort = methods.onabort;
114 writer.onwritestart = methods.onwritestart;
115 writer.onwrite = methods.onwrite;
116 writer.onwriteend = methods.onwriteend;
117 expectedLength = methods.verifyLength;
121 function runTest(initIndex, testIndex) {
122 followOnAction = testIndex;
123 setupWriter(initIndex, writer);
126 function doFollowOnAction() {
127 shouldBeTrue("followOnAction == 1 || followOnAction == 3");
128 setupWriter(followOnAction, writer);
131 var jsTestIsAsync = true;
132 setupAndRunTest(2*1024*1024, 'file-writer-abort',
133 function (fileEntry, fileWriter) {
134 fileEntryForCleanup = fileEntry;