blob: 9f612eb1b4a9ea1e73ac638a7a0e46f6fa35be68 [file] [log] [blame]
Confirm basic Blob/File/FileList functionality.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
dbname = "blob-basics-metadata.html"
indexedDB.deleteDatabase(dbname)
indexedDB.open(dbname)
store = db.createObjectStore('storeName')
store.put('value', 'key')
testBlob():
PASS FileReader != null is true
test_content = 'This is a test. This is only a test.'
blob = new Blob([test_content])
validateResult(blob):
PASS blob.size == test_content.length is true
transaction = db.transaction('storeName', 'readwrite')
store = transaction.objectStore('storeName')
store.put(blob, 'blobkey')
transaction = db.transaction('storeName', 'readwrite')
store = transaction.objectStore('storeName')
request = store.get('blobkey')
PASS event.target.result.size == test_content.length is true
testFile():
file = fileInput.files[0]
validateResult(file):
PASS file.name == fileInput.files[0].name is true
transaction = db.transaction('storeName', 'readwrite')
store = transaction.objectStore('storeName')
store.put(file, 'filekey')
transaction = db.transaction('storeName', 'readwrite')
store = transaction.objectStore('storeName')
request = store.get('filekey')
PASS event.target.result.name == fileInput.files[0].name is true
testNewFile():
newFile = new File([test_content], 'filename', {type:'text/plain'})
validateResult(newFile):
PASS newFile.name == newFile.name is true
transaction = db.transaction('storeName', 'readwrite')
store = transaction.objectStore('storeName')
store.put(newFile, 'newFilekey')
transaction = db.transaction('storeName', 'readwrite')
store = transaction.objectStore('storeName')
request = store.get('newFilekey')
PASS event.target.result.name == newFile.name is true
testFileList():
filelist = fileInput.files
validateResult(filelist):
PASS filelist[1].name == fileInput.files[1].name is true
transaction = db.transaction('storeName', 'readwrite')
store = transaction.objectStore('storeName')
store.put(filelist, 'filelistkey')
transaction = db.transaction('storeName', 'readwrite')
store = transaction.objectStore('storeName')
request = store.get('filelistkey')
PASS event.target.result[1].name == fileInput.files[1].name is true
testCursor():
transaction = db.transaction('storeName', 'readonly')
store = transaction.objectStore('storeName')
request = store.openCursor()
PASS cursor.value.size == test_content.length is true
cursor.continue();
PASS cursor.value.name == fileInput.files[0].name is true
cursor.continue();
PASS cursor.value[1].name == fileInput.files[1].name is true
cursor.continue();
PASS cursor.value == 'value' is true
cursor.continue();
PASS cursor.value.name == newFile.name is true
cursor.continue();
PASS cursor is null
PASS successfullyParsed is true
TEST COMPLETE