2 <script src=
"../../resources/js-test.js"></script>
3 <script src=
"resources/shared.js"></script>
6 description("Confirm that IndexedDB can store an empty File from the Filesystem API");
8 function prepareDatabase()
10 db
= event
.target
.result
;
11 var trans
= event
.target
.transaction
;
12 evalAndLog("store = db.createObjectStore('storeName')");
13 evalAndLog("store.put('value', 'key')");
14 trans
.onerror
= unexpectedErrorCallback
;
15 trans
.onabort
= unexpectedAbortCallback
;
18 var fileValidation
= ".size == 0";
19 function testEmptyFilesystemFile()
22 evalAndLog("file = window.emptyFile");
23 validateResult("file", fileValidation
, cleanupFs
);
26 function validateResult(variable
, validation
, onSuccess
)
28 var keyName
= variable
+ "key";
30 debug("validateResult(" + variable
+ "):");
31 shouldBeTrue(variable
+ validation
);
32 evalAndLog("transaction = db.transaction('storeName', 'readwrite')");
33 evalAndLog("store = transaction.objectStore('storeName')");
34 evalAndLog("store.put(" + variable
+ ", '" + keyName
+ "')");
35 transaction
.onerror
= unexpectedErrorCallback
;
36 transaction
.onabort
= unexpectedAbortCallback
;
37 var onGetSuccess = function (e
) {
38 shouldBeTrue("event.target.result" + validation
);
41 transaction
.oncomplete = function () {
42 doRead(keyName
, onGetSuccess
);
46 function doRead(keyName
, onSuccess
)
48 evalAndLog("transaction = db.transaction('storeName', 'readwrite')");
49 evalAndLog("store = transaction.objectStore('storeName')");
50 evalAndLog("request = store.get('" + keyName
+ "')");
51 request
.onsuccess
= onSuccess
;
52 transaction
.onerror
= unexpectedErrorCallback
;
53 transaction
.onabort
= unexpectedAbortCallback
;
56 function fsError(error
)
58 debug("Filesystem error:" + error
.name
);
61 function fsCreated(fs
)
63 debug("Got FileSystem:" + fs
.name
);
64 window
.fileSystem
= fs
;
66 fs
.root
.getFile("empty.txt", {create
: true}, function(entry
) {
67 entry
.file(function(file
) {
68 window
.emptyFile
= file
;
69 indexedDBTest(prepareDatabase
, testEmptyFilesystemFile
);
74 if (window
.webkitRequestFileSystem
)
75 window
.webkitRequestFileSystem(TEMPORARY
, 100, fsCreated
, fsError
);
77 alert("This test requires the FileSystem API");
81 if (window
.fileSystem
) {
82 var fs
= window
.fileSystem
;
83 // cleanupFs shouldn't get called again if an error occurs below.
84 window
.fileSystem
= null;
85 fs
.root
.getFile("empty.txt", {create
: false}, function (entry
) {
86 entry
.remove(finishJSTest
, fsError
);