Changeset 80896 in webkit


Ignore:
Timestamp:
Mar 11, 2011 3:44:26 PM (13 years ago)
Author:
ericu@chromium.org
Message:

2010-3-11 Eric Uhrhane <ericu@chromium.org>

Reviewed by David Levin.

Add tests for FileWriter
https://bugs.webkit.org/show_bug.cgi?id=44363

Fix small bugs in the utility functions and add setFileContents().

  • fast/filesystem/resources/file-writer-utils.js:

Port the GC Blob test over to the new FileWriter utilities.

  • fast/filesystem/file-writer-gc-blob-expected.txt:
  • fast/filesystem/file-writer-gc-blob.html:
  • fast/filesystem/resources/file-writer-gc-blob.js: Copied from LayoutTests/fast/filesystem/file-writer-gc-blob.html.

Add tests for progress events and overlapping writes [via seek].

  • fast/filesystem/file-writer-events-expected.txt: Added.
  • fast/filesystem/file-writer-events.html: Added.
  • fast/filesystem/resources/file-writer-events.js: Added.
  • fast/filesystem/file-writer-write-overlapped-expected.txt: Added.
  • fast/filesystem/file-writer-write-overlapped.html: Added.
  • fast/filesystem/resources/file-writer-write-overlapped.js: Added.

Worker versions of the above tests.

  • fast/filesystem/workers/file-writer-events-expected.txt: Added.
  • fast/filesystem/workers/file-writer-events.html: Added.
  • fast/filesystem/workers/file-writer-gc-blob-expected.html: Added.
  • fast/filesystem/workers/file-writer-gc-blob.html: Added.
  • fast/filesystem/workers/file-writer-write-overlapped-expected.html: Added.
  • fast/filesystem/workers/file-writer-write-overlapped.html: Added.
Location:
trunk/LayoutTests
Files:
12 added
4 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r80892 r80896  
     12010-3-11  Eric Uhrhane  <ericu@chromium.org>
     2
     3        Reviewed by David Levin.
     4
     5        Add tests for FileWriter
     6        https://bugs.webkit.org/show_bug.cgi?id=44363
     7
     8        Fix small bugs in the utility functions and add setFileContents().
     9        * fast/filesystem/resources/file-writer-utils.js:
     10
     11        Port the GC Blob test over to the new FileWriter utilities.
     12        * fast/filesystem/file-writer-gc-blob-expected.txt:
     13        * fast/filesystem/file-writer-gc-blob.html:
     14        * fast/filesystem/resources/file-writer-gc-blob.js: Copied from LayoutTests/fast/filesystem/file-writer-gc-blob.html.
     15
     16        Add tests for progress events and overlapping writes [via seek].
     17        * fast/filesystem/file-writer-events-expected.txt: Added.
     18        * fast/filesystem/file-writer-events.html: Added.
     19        * fast/filesystem/resources/file-writer-events.js: Added.
     20        * fast/filesystem/file-writer-write-overlapped-expected.txt: Added.
     21        * fast/filesystem/file-writer-write-overlapped.html: Added.
     22        * fast/filesystem/resources/file-writer-write-overlapped.js: Added.
     23
     24        Worker versions of the above tests.
     25        * fast/filesystem/workers/file-writer-events-expected.txt: Added.
     26        * fast/filesystem/workers/file-writer-events.html: Added.
     27        * fast/filesystem/workers/file-writer-gc-blob-expected.html: Added.
     28        * fast/filesystem/workers/file-writer-gc-blob.html: Added.
     29        * fast/filesystem/workers/file-writer-write-overlapped-expected.html: Added.
     30        * fast/filesystem/workers/file-writer-write-overlapped.html: Added.
     31
    1322011-03-11  Anton D'Auria  <adauria@apple.com>
    233
  • trunk/LayoutTests/fast/filesystem/file-writer-gc-blob-expected.txt

    r69560 r80896  
     1Test that a blob won't get garbage-collected while being written out by a FileWriter.
     2
     3On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
     4
    15starting test
    26PASS Successfully wrote blob.
     
    48
    59TEST COMPLETE
     10
  • trunk/LayoutTests/fast/filesystem/file-writer-gc-blob.html

    r69560 r80896  
    11<!DOCTYPE HTML>
    22<html>
    3 <head>
    4 <title>File Writer test</title>
    5 <link rel="stylesheet" href="../js/resources/js-test-style.css">
    6 <script src="../js/resources/js-test-pre.js"></script>
    7 <script>
    8     var fileEntry;
    9 
    10     function cleanUp() {
    11       var needToCallFinish = true;
    12       try {
    13         if (fileEntry) {
    14           fileEntry.remove(finishJSTest, finishJSTest);
    15           needToCallFinish = false;
    16         }
    17       } catch (ex) {
    18       }
    19       if (needToCallFinish) {
    20         finishJSTest();
    21       }
    22     }
    23 
    24     function stringifyObj(o) {
    25         s = "";
    26         if (o)
    27             for (index in o) {
    28                 s += index + ": " + o[index] + "\n";
    29             }
    30         return s;
    31     }
    32 
    33     function onError(e) {
    34         debug("Caught an error.");
    35         if (e && e.code) {  // Each FileError has a code.
    36           debug("Error code: " + e.code);
    37         }
    38         testFailed(stringifyObj(e));
    39         cleanUp();
    40     }
    41 
    42     function onSuccess() {
    43         testPassed("Successfully wrote blob.");
    44         cleanUp();
    45     }
    46 
    47     function tenXBlob(blob) {
    48         var bb = new BlobBuilder();
    49         for (var i = 0; i < 10; ++i) {
    50             bb.append(blob);
    51         }
    52         return bb.getBlob();
    53     }
    54 
    55     function startWrite(writer) {
    56         // Let's make it about a megabyte.
    57         var bb = new BlobBuilder();
    58         bb.append("lorem ipsum");
    59         var blob = tenXBlob(bb.getBlob());
    60         blob = tenXBlob(bb.getBlob());
    61         blob = tenXBlob(bb.getBlob());
    62         blob = tenXBlob(bb.getBlob());
    63         blob = tenXBlob(bb.getBlob());
    64         writer.onerror = onError;
    65         writer.onwriteend = onSuccess;
    66         writer.write(blob);
    67     }
    68 
    69     function useFileWriter(writer) {
    70         startWrite(writer);
    71         gc();
    72     }
    73 
    74     function fileCallback(f) {
    75         fileEntry = f;
    76         fileEntry.createWriter(useFileWriter, onError);
    77     }
    78 
    79     function runTest() {
    80         debug("starting test");
    81         if (window.requestFileSystem) {
    82             requestFileSystem(0, 1024*1024,
    83                 function(fs) {
    84                     fs.root.getFile("test.txt", {create:true}, fileCallback,
    85                                     onError);
    86                 },
    87                 onError);
    88         } else {
    89             debug("This test requires FileSystem API support.");
    90         }
    91     }
    92     window.successfullyParsed = true;
    93     window.jsTestIsAsync = true;
    94 </script>
    95 </head>
    96 <body onload="runTest()">
     3 <head>
     4    <link rel="stylesheet" href="../js/resources/js-test-style.css">
     5    <title>File Writer GC Blob</title>
     6    <script src="../js/resources/js-test-pre.js"></script>
     7    <script src="resources/file-writer-utils.js"></script>
     8 </head>
     9 <body>
    9710    <div id="description"></div>
    9811    <div id="console"></div>
     12    <script src="resources/file-writer-gc-blob.js"></script>
    9913    <script src="../js/resources/js-test-post.js"></script>
    100 </body>
     14 </body>
    10115</html>
    102 
  • trunk/LayoutTests/fast/filesystem/resources/file-writer-gc-blob.js

    r73484 r80896  
    1 <!DOCTYPE HTML>
    2 <html>
    3 <head>
    4 <title>File Writer test</title>
    5 <link rel="stylesheet" href="../js/resources/js-test-style.css">
    6 <script src="../js/resources/js-test-pre.js"></script>
    7 <script>
    8     var fileEntry;
    9 
    10     function cleanUp() {
    11       var needToCallFinish = true;
    12       try {
    13         if (fileEntry) {
    14           fileEntry.remove(finishJSTest, finishJSTest);
    15           needToCallFinish = false;
     1if (this.importScripts) {
     2    importScripts('fs-worker-common.js');
     3    importScripts('file-writer-utils.js');
     4    function gc() {
     5        if (typeof GCController !== "undefined")
     6            GCController.collect();
     7        else {
     8            function gcRec(n) {
     9                if (n < 1)
     10                    return {};
     11                var temp = {i: "ab" + i + (i / 100000)};
     12                temp += "foo";
     13                gcRec(n-1);
     14            }
     15            for (var i = 0; i < 1000; i++)
     16                gcRec(10)
    1617        }
    17       } catch (ex) {
    18       }
    19       if (needToCallFinish) {
    20         finishJSTest();
    21       }
    2218    }
    2319
    24     function stringifyObj(o) {
    25         s = "";
    26         if (o)
    27             for (index in o) {
    28                 s += index + ": " + o[index] + "\n";
    29             }
    30         return s;
     20}
     21
     22description("Test that a blob won't get garbage-collected while being written out by a FileWriter.");
     23
     24var fileEntry;
     25
     26function onTestSuccess() {
     27    testPassed("Successfully wrote blob.");
     28    cleanUp();
     29}
     30
     31function tenXBlob(blob) {
     32    var bb = new BlobBuilder();
     33    for (var i = 0; i < 10; ++i) {
     34        bb.append(blob);
    3135    }
     36    return bb.getBlob();
     37}
    3238
    33     function onError(e) {
    34         debug("Caught an error.");
    35         if (e && e.code) {  // Each FileError has a code.
    36           debug("Error code: " + e.code);
    37         }
    38         testFailed(stringifyObj(e));
    39         cleanUp();
    40     }
     39function startWrite(writer) {
     40    // Let's make it about a megabyte.
     41    var bb = new BlobBuilder();
     42    bb.append("lorem ipsum");
     43    var blob = tenXBlob(bb.getBlob());
     44    blob = tenXBlob(blob);
     45    blob = tenXBlob(blob);
     46    blob = tenXBlob(blob);
     47    blob = tenXBlob(blob);
     48    writer.onerror = onError;
     49    writer.onwriteend = onTestSuccess;
     50    writer.write(blob);
     51}
    4152
    42     function onSuccess() {
    43         testPassed("Successfully wrote blob.");
    44         cleanUp();
    45     }
    46 
    47     function tenXBlob(blob) {
    48         var bb = new BlobBuilder();
    49         for (var i = 0; i < 10; ++i) {
    50             bb.append(blob);
    51         }
    52         return bb.getBlob();
    53     }
    54 
    55     function startWrite(writer) {
    56         // Let's make it about a megabyte.
    57         var bb = new BlobBuilder();
    58         bb.append("lorem ipsum");
    59         var blob = tenXBlob(bb.getBlob());
    60         blob = tenXBlob(bb.getBlob());
    61         blob = tenXBlob(bb.getBlob());
    62         blob = tenXBlob(bb.getBlob());
    63         blob = tenXBlob(bb.getBlob());
    64         writer.onerror = onError;
    65         writer.onwriteend = onSuccess;
    66         writer.write(blob);
    67     }
    68 
    69     function useFileWriter(writer) {
    70         startWrite(writer);
    71         gc();
    72     }
    73 
    74     function fileCallback(f) {
    75         fileEntry = f;
    76         fileEntry.createWriter(useFileWriter, onError);
    77     }
    78 
    79     function runTest() {
    80         debug("starting test");
    81         if (window.requestFileSystem) {
    82             requestFileSystem(0, 1024*1024,
    83                 function(fs) {
    84                     fs.root.getFile("test.txt", {create:true}, fileCallback,
    85                                     onError);
    86                 },
    87                 onError);
    88         } else {
    89             debug("This test requires FileSystem API support.");
    90         }
    91     }
    92     window.successfullyParsed = true;
    93     window.jsTestIsAsync = true;
    94 </script>
    95 </head>
    96 <body onload="runTest()">
    97     <div id="description"></div>
    98     <div id="console"></div>
    99     <script src="../js/resources/js-test-post.js"></script>
    100 </body>
    101 </html>
    102 
     53function runTest(unusedFileEntry, fileWriter) {
     54    startWrite(fileWriter);
     55    gc();
     56}
     57var jsTestIsAsync = true;
     58setupAndRunTest(2*1024*1024, 'file-writer-gc-blob', runTest);
     59var successfullyParsed = true;
  • trunk/LayoutTests/fast/filesystem/resources/file-writer-utils.js

    r75864 r80896  
    104104function createEmptyFile(fileSystem, fileName, onSuccess)
    105105{
    106     function getSuccessFunc(fileEntry, fileWriter) {
     106    function getSuccessFunc(fileEntry) {
     107        // Create a fresh FileWriter here, rather than pass in the used one.
     108        // This way we don't accidentally leave our event handlers attached.
    107109        return function() {
    108             onSuccess(fileEntry, fileWriter);
     110            fileEntry.createWriter(function(fw) {
     111                onSuccess(fileEntry, fw);
     112            }, onError);
    109113        }
    110114    }
    111115    function getFileWriterCallback(fileEntry) {
    112116        return function(fileWriter) {
    113             var successFunc = getSuccessFunc(fileEntry, fileWriter);
     117            var successFunc = getSuccessFunc(fileEntry);
    114118            fileWriter.onError = onError;
    115             fileWriter.onwrite = function() {
     119            // FIXME: This should be onwrite, but the spec and code need to be changed to allow that.  See https://bugs.webkit.org/show_bug.cgi?id=50846.
     120            fileWriter.onwriteend = function() {
    116121                verifyFileLength(fileEntry, 0, successFunc);
    117122            };
     
    135140    fileWriter.seek(offset);
    136141    fileWriter.write(blob);
    137     fileWriter.onwrite = function() {
     142    fileWriter.onerror = onError;
     143    if (offset < 0)
     144        offset += fileWriter.length;
     145    assert(offset >= 0);
     146    // FIXME: This should be onwrite, but the spec and code need to be changed to allow that.  See https://bugs.webkit.org/show_bug.cgi?id=50846.
     147    fileWriter.onwriteend = function() {
     148        fileWriter.onwriteend = null;
    138149        verifyByteRangeAsString(fileEntry, offset, data, onSuccess);
    139150    };
     151}
     152
     153function setFileContents(fileEntry, fileWriter, contents, onSuccess) {
     154    fileWriter.onerror = onError;
     155    // FIXME: This should be onwrite, but the spec and code need to be changed to allow that.  See https://bugs.webkit.org/show_bug.cgi?id=50846.
     156    fileWriter.onwriteend = function() {
     157        writeString(fileEntry, fileWriter, 0, contents, onSuccess);
     158    };
     159    fileWriter.truncate(0);
    140160}
    141161
Note: See TracChangeset for help on using the changeset viewer.