OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../../resources/js-test.js"></script> |
| 3 <script src="resources/shared.js"></script> |
| 4 <script> |
| 5 |
| 6 description("Confirm that IndexedDB can store an empty File from the Filesystem
API"); |
| 7 |
| 8 function prepareDatabase() |
| 9 { |
| 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; |
| 16 } |
| 17 |
| 18 var fileValidation = ".size == 0"; |
| 19 function testEmptyFilesystemFile() |
| 20 { |
| 21 preamble(); |
| 22 evalAndLog("file = window.emptyFile"); |
| 23 validateResult("file", fileValidation, cleanupFs); |
| 24 } |
| 25 |
| 26 function validateResult(variable, validation, onSuccess) |
| 27 { |
| 28 var keyName = variable + "key"; |
| 29 debug(""); |
| 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); |
| 39 onSuccess(); |
| 40 } |
| 41 transaction.oncomplete = function () { |
| 42 doRead(keyName, onGetSuccess); |
| 43 } |
| 44 } |
| 45 |
| 46 function doRead(keyName, onSuccess) |
| 47 { |
| 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; |
| 54 } |
| 55 |
| 56 function fsError(error) |
| 57 { |
| 58 debug("Filesystem error:" + error.name); |
| 59 cleanupFs(); |
| 60 } |
| 61 function fsCreated(fs) |
| 62 { |
| 63 debug("Got FileSystem:" + fs.name); |
| 64 window.fileSystem = fs; |
| 65 |
| 66 fs.root.getFile("empty.txt", {create: true}, function(entry) { |
| 67 entry.file(function(file) { |
| 68 window.emptyFile = file; |
| 69 indexedDBTest(prepareDatabase, testEmptyFilesystemFile); |
| 70 }); |
| 71 }, fsError); |
| 72 } |
| 73 |
| 74 if (window.webkitRequestFileSystem) |
| 75 window.webkitRequestFileSystem(TEMPORARY, 100, fsCreated, fsError); |
| 76 else |
| 77 alert("This test requires the FileSystem API"); |
| 78 |
| 79 function cleanupFs() |
| 80 { |
| 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); |
| 87 }, fsError); |
| 88 } |
| 89 } |
| 90 </script> |
OLD | NEW |