idbcursor-primarykey.any.js (1360B)
1 // META: global=window,worker 2 // META: title=IDBCursor.primaryKey 3 // META: script=resources/support.js 4 5 'use strict'; 6 7 function cursor_primarykey(key) { 8 async_test(t => { 9 let db; 10 11 const open_rq = createdb(t); 12 open_rq.onupgradeneeded = t.step_func(e => { 13 db = e.target.result; 14 const objStore = db.createObjectStore('test'); 15 objStore.createIndex('index', ''); 16 17 objStore.add('data', key); 18 }); 19 20 open_rq.onsuccess = t.step_func(e => { 21 const cursor_rq = db.transaction('test', 'readonly') 22 .objectStore('test') 23 .index('index') 24 .openCursor(); 25 26 cursor_rq.onsuccess = t.step_func(e => { 27 const cursor = e.target.result; 28 29 assert_equals(cursor.value, 'data', 'prerequisite cursor.value'); 30 assert_equals(cursor.key, 'data', 'prerequisite cursor.key'); 31 32 assert_key_equals(cursor.primaryKey, key, 'primaryKey'); 33 assert_readonly(cursor, 'primaryKey'); 34 35 if (key instanceof Array) { 36 cursor.primaryKey.push('new'); 37 key.push('new'); 38 39 assert_key_equals( 40 cursor.primaryKey, key, 'primaryKey after array push'); 41 } 42 43 t.done(); 44 }); 45 }); 46 }); 47 } 48 49 cursor_primarykey(1); 50 cursor_primarykey('key'); 51 cursor_primarykey(['my', 'key']);