transaction-scheduling-rw-scopes.any.js (2373B)
1 // META: script=resources/support.js 2 'use strict'; 3 4 indexeddb_test( 5 (t, db) => { 6 const store = db.createObjectStore('store'); 7 db.createObjectStore('a'); 8 db.createObjectStore('b'); 9 db.createObjectStore('c'); 10 }, 11 12 (t, db) => { 13 let transaction1Started = false; 14 let transaction1Complete = false; 15 let transaction2Started = false; 16 let transaction2Complete = false; 17 let transaction3Started = false; 18 let transaction3Complete = false; 19 20 const transaction1 = db.transaction(['a'], 'readwrite'); 21 let request = transaction1.objectStore('a').get(0); 22 request.onerror = t.unreached_func('request should succeed'); 23 request.onsuccess = t.step_func(() => { 24 transaction1Started = true; 25 }); 26 transaction1.onabort = t.unreached_func('transaction1 should complete'); 27 transaction1.oncomplete = t.step_func(() => { 28 transaction1Complete = true; 29 assert_false(transaction2Started); 30 assert_false(transaction3Started); 31 }); 32 33 34 // transaction2 overlaps with transaction1, so must wait until transaction1 35 // completes. 36 const transaction2 = db.transaction(['a', 'b'], 'readwrite'); 37 request = transaction2.objectStore('a').get(0); 38 request.onerror = t.unreached_func('request should succeed'); 39 request.onsuccess = t.step_func(() => { 40 assert_true(transaction1Complete); 41 transaction2Started = true; 42 }); 43 transaction2.onabort = t.unreached_func('transaction2 should complete'); 44 transaction2.oncomplete = t.step_func(() => { 45 transaction2Complete = true; 46 assert_false(transaction3Started); 47 }); 48 49 // transaction3 overlaps with transaction2, so must wait until transaction2 50 // completes even though it does not overlap with transaction1. 51 const transaction3 = db.transaction(['b', 'c'], 'readwrite'); 52 request = transaction3.objectStore('b').get(0); 53 request.onerror = t.unreached_func('request should succeed'); 54 request.onsuccess = t.step_func(() => { 55 assert_true(transaction1Complete); 56 assert_true(transaction2Complete); 57 transaction3Started = true; 58 }); 59 transaction3.onabort = t.unreached_func('transaction3 should complete'); 60 transaction3.oncomplete = t.step_func_done(() => { 61 transaction3Complete = true; 62 }); 63 }, 64 "Check that scope restrictions on read-write transactions are enforced.");