reading-autoincrement-indexes.any.js (4057B)
1 // META: global=window,dedicatedworker,sharedworker,serviceworker 2 // META: script=resources/support-promises.js 3 // META: script=resources/reading-autoincrement-common.js 4 'use strict'; 5 6 promise_test(async testCase => { 7 const database = await setupAutoincrementDatabase(testCase); 8 9 const transaction = database.transaction(['store'], 'readonly'); 10 const store = transaction.objectStore('store'); 11 const index = store.index('by_id'); 12 const request = index.getAll(); 13 const result = await promiseForRequest(testCase, request); 14 assert_equals(result.length, 32); 15 for (let i = 1; i <= 32; ++i) { 16 assert_equals(result[i - 1].id, i, 'Autoincrement key'); 17 assert_equals(result[i - 1].name, nameForId(i), 'String property'); 18 } 19 20 database.close(); 21 }, 'IDBIndex.getAll() for an index on the autoincrement key'); 22 23 promise_test(async testCase => { 24 const database = await setupAutoincrementDatabase(testCase); 25 26 const transaction = database.transaction(['store'], 'readonly'); 27 const store = transaction.objectStore('store'); 28 const index = store.index('by_id'); 29 const request = index.getAllKeys(); 30 const result = await promiseForRequest(testCase, request); 31 assert_equals(result.length, 32); 32 for (let i = 1; i <= 32; ++i) 33 assert_equals(result[i - 1], i, 'Autoincrement key'); 34 35 database.close(); 36 }, 'IDBIndex.getAllKeys() for an index on the autoincrement key'); 37 38 promise_test(async testCase => { 39 const database = await setupAutoincrementDatabase(testCase); 40 41 const transaction = database.transaction(['store'], 'readonly'); 42 const store = transaction.objectStore('store'); 43 const index = store.index('by_id'); 44 45 for (let i = 1; i <= 32; ++i) { 46 const request = index.get(i); 47 const result = await promiseForRequest(testCase, request); 48 assert_equals(result.id, i, 'autoincrement key'); 49 assert_equals(result.name, nameForId(i), 'string property'); 50 } 51 52 database.close(); 53 }, 'IDBIndex.get() for an index on the autoincrement key'); 54 55 promise_test(async testCase => { 56 const database = await setupAutoincrementDatabase(testCase); 57 58 const stringSortedIds = idsSortedByStringCompare(); 59 60 const transaction = database.transaction(['store'], 'readonly'); 61 const store = transaction.objectStore('store'); 62 const index = store.index('by_name'); 63 const request = index.getAll(); 64 const result = await promiseForRequest(testCase, request); 65 assert_equals(result.length, 32); 66 for (let i = 1; i <= 32; ++i) { 67 assert_equals(result[i - 1].id, stringSortedIds[i - 1], 68 'autoincrement key'); 69 assert_equals(result[i - 1].name, nameForId(stringSortedIds[i - 1]), 70 'string property'); 71 } 72 73 database.close(); 74 }, 'IDBIndex.getAll() for an index not covering the autoincrement key'); 75 76 promise_test(async testCase => { 77 const database = await setupAutoincrementDatabase(testCase); 78 79 const stringSortedIds = idsSortedByStringCompare(); 80 81 const transaction = database.transaction(['store'], 'readonly'); 82 const store = transaction.objectStore('store'); 83 const index = store.index('by_name'); 84 const request = index.getAllKeys(); 85 const result = await promiseForRequest(testCase, request); 86 assert_equals(result.length, 32); 87 for (let i = 1; i <= 32; ++i) 88 assert_equals(result[i - 1], stringSortedIds[i - 1], 'String property'); 89 90 database.close(); 91 }, 'IDBIndex.getAllKeys() returns correct result for an index not covering ' + 92 'the autoincrement key'); 93 94 promise_test(async testCase => { 95 const database = await setupAutoincrementDatabase(testCase); 96 97 const transaction = database.transaction(['store'], 'readonly'); 98 const store = transaction.objectStore('store'); 99 const index = store.index('by_name'); 100 101 for (let i = 1; i <= 32; ++i) { 102 const request = index.get(nameForId(i)); 103 const result = await promiseForRequest(testCase, request); 104 assert_equals(result.id, i, 'Autoincrement key'); 105 assert_equals(result.name, nameForId(i), 'String property'); 106 } 107 108 database.close(); 109 }, 'IDBIndex.get() for an index not covering the autoincrement key');