blob-valid-before-commit.any.js (1453B)
1 // META: title=Blob Valid Before Commit 2 // META: script=resources/support.js 3 'use strict'; 4 5 let key = "key"; 6 7 indexeddb_test( 8 function upgrade(t, db) { 9 db.createObjectStore('store'); 10 }, 11 function success(t, db) { 12 const blobAContent = "Blob A content"; 13 const blobBContent = "Blob B content"; 14 const blobA = new Blob([blobAContent], {"type" : "text/plain"}); 15 const blobB = new Blob([blobBContent], {"type" : "text/plain"}); 16 const value = { a0: blobA, a1: blobA, b0: blobB }; 17 18 const tx = db.transaction('store', 'readwrite'); 19 const store = tx.objectStore('store'); 20 21 store.put(value, key); 22 const request = store.get(key); 23 24 request.onsuccess = t.step_func(function() { 25 const record = request.result; 26 27 const promise1 = record.a0.text().then(t.step_func(text => { assert_equals(text, blobAContent); }, 28 t.unreached_func())); 29 30 const promise2 = record.a1.text().then(t.step_func(text => { assert_equals(text, blobAContent); }, 31 t.unreached_func())); 32 33 const promise3 = record.b0.text().then(t.step_func(text => { assert_equals(text, blobBContent); }, 34 t.unreached_func())); 35 36 Promise.all([promise1, promise2, promise3]).then(function() { 37 // The test passes if it successfully completes. 38 t.done(); 39 }); 40 }); 41 }, 42 "Blobs can be read back before their records are committed.");