transaction-relaxed-durability.any.js (1783B)
1 // META: script=resources/support-promises.js 2 // META: timeout=long 3 'use strict'; 4 5 /** 6 * This file contains the webplatform smoke tests for the optional 7 * durability parameter of the IndexedDB transaction API. 8 * 9 * @author enne@chromium.org 10 */ 11 12 // Smoke test optional parameter on IndexedDB.transaction. 13 let cases = [ 14 { options: undefined, expected: 'default' }, 15 { options: {}, expected: 'default' }, 16 { options: { durability: 'default'}, expected: 'default' }, 17 { options: { durability: 'relaxed'}, expected: 'relaxed' }, 18 { options: { durability: 'strict'}, expected: 'strict' }, 19 ]; 20 21 for (let i = 0; i < cases.length; ++i) { 22 promise_test(async testCase => { 23 const db = await createDatabase(testCase, db => { 24 createBooksStore(testCase, db); 25 }); 26 const txn = db.transaction(['books'], 'readwrite', cases[i].options); 27 const objectStore = txn.objectStore('books'); 28 objectStore.put({isbn: 'one', title: 'title1'}); 29 await promiseForTransaction(testCase, txn); 30 31 assert_equals(txn.durability, cases[i].expected); 32 33 const txn2 = db.transaction(['books'], 'readonly'); 34 const objectStore2 = txn2.objectStore('books'); 35 const getTitle1 = objectStore2.get('one'); 36 await promiseForTransaction(testCase, txn2); 37 assert_array_equals( 38 [getTitle1.result.title], 39 ['title1'], 40 'The title should match that which was put.'); 41 db.close(); 42 }, 'Committed data can be read back out: case ' + i); 43 } 44 45 promise_test(async testCase => { 46 const db = await createDatabase(testCase, db => { 47 createBooksStore(testCase, db); 48 }); 49 50 assert_throws_js(TypeError, function() { 51 db.transaction(['books'], 'readwrite', { durability: 'invalid' }); 52 }); 53 db.close(); 54 }, 'Invalid durability option throws a TypeError');