Best JavaScript code snippet using wpt
idbindex-rename.js
Source:idbindex-rename.js
...241 );242 const authorIndex = store.index("by_author");243 const titleIndex = store.index("by_title");244 return Promise.all([245 checkAuthorIndexContents(testCase, authorIndex, errorMessage),246 checkTitleIndexContents(testCase, titleIndex, errorMessage),247 ]);248}249// Verifies that an object store's key generator is in the same state as the250// key generator created for the books store in the test database's version 1.251//252// The errorMessage is used if the assertions fail. It can state that the253// IndexedDB implementation being tested is incorrect, or that the testing code254// is using it incorrectly.255function checkStoreGenerator(testCase, store, expectedKey, errorMessage) {256 const request = store.put({257 title: "Bedrock Nights " + expectedKey,258 author: "Barney",259 });260 return promiseForRequest(testCase, request).then(result => {261 assert_equals(result, expectedKey, errorMessage);262 });263}264// Verifies that an object store's contents matches the contents used to create265// the books store in the test database's version 1.266//267// The errorMessage is used if the assertions fail. It can state that the268// IndexedDB implementation being tested is incorrect, or that the testing code269// is using it incorrectly.270function checkStoreContents(testCase, store, errorMessage) {271 const request = store.get(123456);272 return promiseForRequest(testCase, request).then(result => {273 assert_equals(result.isbn, BOOKS_RECORD_DATA[0].isbn, errorMessage);274 assert_equals(result.author, BOOKS_RECORD_DATA[0].author, errorMessage);275 assert_equals(result.title, BOOKS_RECORD_DATA[0].title, errorMessage);276 });277}278// Verifies that index matches the 'by_author' index used to create the279// by_author books store in the test database's version 1.280//281// The errorMessage is used if the assertions fail. It can state that the282// IndexedDB implementation being tested is incorrect, or that the testing code283// is using it incorrectly.284function checkAuthorIndexContents(testCase, index, errorMessage) {285 const request = index.get(BOOKS_RECORD_DATA[2].author);286 return promiseForRequest(testCase, request).then(result => {287 assert_equals(result.isbn, BOOKS_RECORD_DATA[2].isbn, errorMessage);288 assert_equals(result.title, BOOKS_RECORD_DATA[2].title, errorMessage);289 });290}291// Verifies that an index matches the 'by_title' index used to create the books292// store in the test database's version 1.293//294// The errorMessage is used if the assertions fail. It can state that the295// IndexedDB implementation being tested is incorrect, or that the testing code296// is using it incorrectly.297function checkTitleIndexContents(testCase, index, errorMessage) {298 const request = index.get(BOOKS_RECORD_DATA[2].title);299 return promiseForRequest(testCase, request).then(result => {300 assert_equals(result.isbn, BOOKS_RECORD_DATA[2].isbn, errorMessage);301 assert_equals(result.author, BOOKS_RECORD_DATA[2].author, errorMessage);302 });303}304// Returns an Uint8Array with pseudorandom data.305//306// The PRNG should be sufficient to defeat compression schemes, but it is not307// cryptographically strong.308function largeValue(size, seed) {309 const buffer = new Uint8Array(size);310 // 32-bit xorshift - the seed can't be zero311 let state = 1000 + seed;312 for (let i = 0; i < size; ++i) {313 state ^= state << 13;314 state ^= state >> 17;315 state ^= state << 5;316 buffer[i] = state & 0xff;317 }318 return buffer;319}320async function deleteAllDatabases(testCase) {321 const dbs_to_delete = await indexedDB.databases();322 for (const db_info of dbs_to_delete) {323 let request = indexedDB.deleteDatabase(db_info.name);324 let eventWatcher = requestWatcher(testCase, request);325 await eventWatcher.wait_for("success");326 }327}328// Keeps the passed transaction alive indefinitely (by making requests329// against the named store). Returns a function that asserts that the330// transaction has not already completed and then ends the request loop so that331// the transaction may autocommit and complete.332function keepAlive(testCase, transaction, storeName) {333 let completed = false;334 transaction.addEventListener("complete", () => {335 completed = true;336 });337 let keepSpinning = true;338 function spin() {339 if (!keepSpinning) return;340 transaction.objectStore(storeName).get(0).onsuccess = spin;341 }342 spin();343 return testCase.step_func(() => {344 assert_false(completed, "Transaction completed while kept alive");345 keepSpinning = false;346 });347}348// Return a promise that resolves after a setTimeout finishes to break up the349// scope of a function's execution.350function timeoutPromise(ms) {351 return new Promise(resolve => {352 setTimeout(resolve, ms);353 });354}355("use strict");356promise_test(testCase => {357 let authorIndex = null,358 authorIndex2 = null;359 let renamedAuthorIndex = null,360 renamedAuthorIndex2 = null;361 return createDatabase(testCase, (database, transaction) => {362 const store = createBooksStore(testCase, database);363 authorIndex = store.index("by_author");364 })365 .then(database => {366 const transaction = database.transaction("books", "readonly");367 const store = transaction.objectStore("books");368 assert_array_equals(369 store.indexNames,370 ["by_author", "by_title"],371 "Test setup should have created two indexes",372 );373 authorIndex2 = store.index("by_author");374 return checkAuthorIndexContents(375 testCase,376 authorIndex2,377 "The index should have the expected contents before any renaming",378 ).then(() => database.close());379 })380 .then(() =>381 migrateDatabase(testCase, 2, (database, transaction) => {382 const store = transaction.objectStore("books");383 renamedAuthorIndex = store.index("by_author");384 renamedAuthorIndex.name = "renamed_by_author";385 assert_equals(386 renamedAuthorIndex.name,387 "renamed_by_author",388 "IDBIndex name should change immediately after a rename",389 );390 assert_array_equals(391 store.indexNames,392 ["by_title", "renamed_by_author"],393 "IDBObjectStore.indexNames should immediately reflect the rename",394 );395 assert_equals(396 store.index("renamed_by_author"),397 renamedAuthorIndex,398 "IDBObjectStore.index should return the renamed index store when " +399 "queried using the new name immediately after the rename",400 );401 assert_throws(402 "NotFoundError",403 () => store.index("by_author"),404 "IDBObjectStore.index should throw when queried using the " +405 "renamed index's old name immediately after the rename",406 );407 }),408 )409 .then(database => {410 const transaction = database.transaction("books", "readonly");411 const store = transaction.objectStore("books");412 assert_array_equals(413 store.indexNames,414 ["by_title", "renamed_by_author"],415 "IDBObjectStore.indexNames should still reflect the rename after " +416 "the versionchange transaction commits",417 );418 renamedAuthorIndex2 = store.index("renamed_by_author");419 return checkAuthorIndexContents(420 testCase,421 renamedAuthorIndex2,422 "Renaming an index should not change its contents",423 ).then(() => database.close());424 })425 .then(() => {426 assert_equals(427 authorIndex.name,428 "by_author",429 "IDBIndex obtained before the rename transaction should not " +430 "reflect the rename",431 );432 assert_equals(433 authorIndex2.name,434 "by_author",435 "IDBIndex obtained before the rename transaction should not " +436 "reflect the rename",437 );438 assert_equals(439 renamedAuthorIndex.name,440 "renamed_by_author",441 "IDBIndex used in the rename transaction should keep reflecting " +442 "the new name after the transaction is committed",443 );444 assert_equals(445 renamedAuthorIndex2.name,446 "renamed_by_author",447 "IDBIndex obtained after the rename transaction should reflect " +448 "the new name",449 );450 });451}, "IndexedDB index rename in new transaction");452promise_test(testCase => {453 let renamedAuthorIndex = null,454 renamedAuthorIndex2 = null;455 return createDatabase(testCase, (database, transaction) => {456 const store = createBooksStore(testCase, database);457 renamedAuthorIndex = store.index("by_author");458 renamedAuthorIndex.name = "renamed_by_author";459 assert_equals(460 renamedAuthorIndex.name,461 "renamed_by_author",462 "IDBIndex name should change immediately after a rename",463 );464 assert_array_equals(465 store.indexNames,466 ["by_title", "renamed_by_author"],467 "IDBObjectStore.indexNames should immediately reflect the rename",468 );469 assert_equals(470 store.index("renamed_by_author"),471 renamedAuthorIndex,472 "IDBObjectStore.index should return the renamed index store when " +473 "queried using the new name immediately after the rename",474 );475 assert_throws(476 "NotFoundError",477 () => store.index("by_author"),478 "IDBObjectStore.index should throw when queried using the " +479 "renamed index's old name immediately after the rename",480 );481 })482 .then(database => {483 const transaction = database.transaction("books", "readonly");484 const store = transaction.objectStore("books");485 assert_array_equals(486 store.indexNames,487 ["by_title", "renamed_by_author"],488 "IDBObjectStore.indexNames should still reflect the rename after " +489 "the versionchange transaction commits",490 );491 renamedAuthorIndex2 = store.index("renamed_by_author");492 return checkAuthorIndexContents(493 testCase,494 renamedAuthorIndex2,495 "Renaming an index should not change its contents",496 ).then(() => database.close());497 })498 .then(() => {499 assert_equals(500 renamedAuthorIndex.name,501 "renamed_by_author",502 "IDBIndex used in the rename transaction should keep reflecting " +503 "the new name after the transaction is committed",504 );505 assert_equals(506 renamedAuthorIndex2.name,507 "renamed_by_author",508 "IDBIndex obtained after the rename transaction should reflect " +509 "the new name",510 );511 });512}, "IndexedDB index rename in the transaction where it is created");513promise_test(testCase => {514 return createDatabase(testCase, (database, transaction) => {515 createBooksStore(testCase, database);516 })517 .then(database => {518 database.close();519 })520 .then(() =>521 migrateDatabase(testCase, 2, (database, transaction) => {522 const store = transaction.objectStore("books");523 const index = store.index("by_author");524 index.name = "by_author";525 assert_array_equals(526 store.indexNames,527 ["by_author", "by_title"],528 "Renaming an index to the same name should not change the " +529 "index's IDBObjectStore.indexNames",530 );531 }),532 )533 .then(database => {534 const transaction = database.transaction("books", "readonly");535 const store = transaction.objectStore("books");536 assert_array_equals(537 store.indexNames,538 ["by_author", "by_title"],539 "Committing a transaction that renames a store to the same name " +540 "should not change the index's IDBObjectStore.indexNames",541 );542 const index = store.index("by_author");543 return checkAuthorIndexContents(544 testCase,545 index,546 "Committing a transaction that renames an index to the same name " +547 "should not change the index's contents",548 ).then(() => database.close());549 });550}, "IndexedDB index rename to the same name succeeds");551promise_test(testCase => {552 return createDatabase(testCase, (database, transaction) => {553 createBooksStore(testCase, database);554 })555 .then(database => {556 database.close();557 })558 .then(() =>559 migrateDatabase(testCase, 2, (database, transaction) => {560 const store = transaction.objectStore("books");561 const index = store.index("by_author");562 store.deleteIndex("by_title");563 index.name = "by_title";564 assert_array_equals(565 store.indexNames,566 ["by_title"],567 "IDBObjectStore.indexNames should immediately reflect the rename",568 );569 }),570 )571 .then(database => {572 const transaction = database.transaction("books", "readonly");573 const store = transaction.objectStore("books");574 assert_array_equals(575 store.indexNames,576 ["by_title"],577 "IDBObjectStore.indexNames should still reflect the rename after " +578 "the versionchange transaction commits",579 );580 const index = store.index("by_title");581 return checkAuthorIndexContents(582 testCase,583 index,584 "Renaming an index should not change its contents",585 ).then(() => database.close());586 });587}, "IndexedDB index rename to the name of a deleted index succeeds");588promise_test(testCase => {589 return createDatabase(testCase, (database, transaction) => {590 createBooksStore(testCase, database);591 })592 .then(database => {593 database.close();594 })595 .then(() =>596 migrateDatabase(testCase, 2, (database, transaction) => {597 const store = transaction.objectStore("books");598 store.index("by_author").name = "tmp";599 store.index("by_title").name = "by_author";600 store.index("tmp").name = "by_title";601 assert_array_equals(602 store.indexNames,603 ["by_author", "by_title"],604 "IDBObjectStore.indexNames should reflect the swap immediately " +605 "after the renames",606 );607 return checkTitleIndexContents(608 testCase,609 store.index("by_author"),610 "Renaming an index should not change its contents",611 );612 }),613 )614 .then(database => {615 const transaction = database.transaction("books", "readonly");616 const store = transaction.objectStore("books");617 assert_array_equals(618 store.indexNames,619 ["by_author", "by_title"],620 "IDBObjectStore.indexNames should still reflect the swap after " +621 "the versionchange transaction commits",622 );623 const index = store.index("by_title");624 return checkAuthorIndexContents(625 testCase,626 index,627 "Renaming an index should not change its contents",628 ).then(() => database.close());629 });630}, "IndexedDB index swapping via renames succeeds");631promise_test(testCase => {632 return createDatabase(testCase, (database, transaction) => {633 createBooksStore(testCase, database);634 })635 .then(database => {636 database.close();637 })638 .then(() =>639 migrateDatabase(testCase, 2, (database, transaction) => {640 const store = transaction.objectStore("books");641 const index = store.index("by_author");642 index.name = 42;643 assert_equals(644 index.name,645 "42",646 "IDBIndex name should change immediately after a rename to a " +647 "number",648 );649 assert_array_equals(650 store.indexNames,651 ["42", "by_title"],652 "IDBObjectStore.indexNames should immediately reflect the " +653 "stringifying rename",654 );655 index.name = true;656 assert_equals(657 index.name,658 "true",659 "IDBIndex name should change immediately after a rename to a " +660 "boolean",661 );662 index.name = {};663 assert_equals(664 index.name,665 "[object Object]",666 "IDBIndex name should change immediately after a rename to an " +667 "object",668 );669 index.name = () => null;670 assert_equals(671 index.name,672 "() => null",673 "IDBIndex name should change immediately after a rename to a " +674 "function",675 );676 index.name = undefined;677 assert_equals(678 index.name,679 "undefined",680 "IDBIndex name should change immediately after a rename to " +681 "undefined",682 );683 }),684 )685 .then(database => {686 const transaction = database.transaction("books", "readonly");687 const store = transaction.objectStore("books");688 assert_array_equals(689 store.indexNames,690 ["by_title", "undefined"],691 "IDBObjectStore.indexNames should reflect the last rename " +692 "after the versionchange transaction commits",693 );694 const index = store.index("undefined");695 return checkAuthorIndexContents(696 testCase,697 index,698 "Renaming an index should not change its contents",699 ).then(() => database.close());700 });701}, "IndexedDB index rename stringifies non-string names");702for (let escapedName of ["", "\\u0000", "\\uDC00\\uD800"])703 (escapedName => {704 const name = JSON.parse('"' + escapedName + '"');705 promise_test(testCase => {706 return createDatabase(testCase, (database, transaction) => {707 createBooksStore(testCase, database);708 })709 .then(database => {710 database.close();711 })712 .then(() =>713 migrateDatabase(testCase, 2, (database, transaction) => {714 const store = transaction.objectStore("books");715 const index = store.index("by_author");716 index.name = name;717 assert_equals(718 index.name,719 name,720 "IDBIndex name should change immediately after the rename",721 );722 assert_array_equals(723 store.indexNames,724 [name, "by_title"].sort(),725 "IDBObjectStore.indexNames should immediately reflect the rename",726 );727 }),728 )729 .then(database => {730 const transaction = database.transaction(731 "books",732 "readonly",733 );734 const store = transaction.objectStore("books");735 assert_array_equals(736 store.indexNames,737 [name, "by_title"].sort(),738 "IDBObjectStore.indexNames should reflect the rename " +739 "after the versionchange transaction commits",740 );741 const index = store.index(name);742 return checkAuthorIndexContents(743 testCase,744 index,745 "Renaming an index should not change its contents",746 ).then(() => database.close());747 });748 }, 'IndexedDB index can be renamed to "' + escapedName + '"');...
idbindex-rename.wpt.t.js
Source:idbindex-rename.wpt.t.js
...14 assert_array_equals(15 store.indexNames, ['by_author', 'by_title'],16 'Test setup should have created two indexes');17 authorIndex2 = store.index('by_author');18 return checkAuthorIndexContents(19 testCase, authorIndex2,20 'The index should have the expected contents before any renaming').21 then(() => database.close());22 }).then(() => migrateDatabase(testCase, 2, (database, transaction) => {23 const store = transaction.objectStore('books');24 renamedAuthorIndex = store.index('by_author');25 renamedAuthorIndex.name = 'renamed_by_author';26 assert_equals(27 renamedAuthorIndex.name, 'renamed_by_author',28 'IDBIndex name should change immediately after a rename');29 assert_array_equals(30 store.indexNames, ['by_title', 'renamed_by_author'],31 'IDBObjectStore.indexNames should immediately reflect the rename');32 assert_equals(33 store.index('renamed_by_author'), renamedAuthorIndex,34 'IDBObjectStore.index should return the renamed index store when ' +35 'queried using the new name immediately after the rename');36 assert_throws_dom(37 'NotFoundError', () => store.index('by_author'),38 'IDBObjectStore.index should throw when queried using the ' +39 "renamed index's old name immediately after the rename");40 })).then(database => {41 const transaction = database.transaction('books', 'readonly');42 const store = transaction.objectStore('books');43 assert_array_equals(44 store.indexNames, ['by_title', 'renamed_by_author'],45 'IDBObjectStore.indexNames should still reflect the rename after ' +46 'the versionchange transaction commits');47 renamedAuthorIndex2 = store.index('renamed_by_author');48 return checkAuthorIndexContents(49 testCase, renamedAuthorIndex2,50 'Renaming an index should not change its contents').then(51 () => database.close());52 }).then(() => {53 assert_equals(54 authorIndex.name, 'by_author',55 'IDBIndex obtained before the rename transaction should not ' +56 'reflect the rename');57 assert_equals(58 authorIndex2.name, 'by_author',59 'IDBIndex obtained before the rename transaction should not ' +60 'reflect the rename');61 assert_equals(62 renamedAuthorIndex.name, 'renamed_by_author',63 'IDBIndex used in the rename transaction should keep reflecting ' +64 'the new name after the transaction is committed');65 assert_equals(66 renamedAuthorIndex2.name, 'renamed_by_author',67 'IDBIndex obtained after the rename transaction should reflect ' +68 'the new name');69 });70 }, 'IndexedDB index rename in new transaction');71 promise_test(testCase => {72 let renamedAuthorIndex = null, renamedAuthorIndex2 = null;73 return createDatabase(testCase, (database, transaction) => {74 const store = createBooksStore(testCase, database);75 renamedAuthorIndex = store.index('by_author');76 renamedAuthorIndex.name = 'renamed_by_author';77 assert_equals(78 renamedAuthorIndex.name, 'renamed_by_author',79 'IDBIndex name should change immediately after a rename');80 assert_array_equals(81 store.indexNames, ['by_title', 'renamed_by_author'],82 'IDBObjectStore.indexNames should immediately reflect the rename');83 assert_equals(84 store.index('renamed_by_author'), renamedAuthorIndex,85 'IDBObjectStore.index should return the renamed index store when ' +86 'queried using the new name immediately after the rename');87 assert_throws_dom(88 'NotFoundError', () => store.index('by_author'),89 'IDBObjectStore.index should throw when queried using the ' +90 "renamed index's old name immediately after the rename");91 }).then(database => {92 const transaction = database.transaction('books', 'readonly');93 const store = transaction.objectStore('books');94 assert_array_equals(95 store.indexNames, ['by_title', 'renamed_by_author'],96 'IDBObjectStore.indexNames should still reflect the rename after ' +97 'the versionchange transaction commits');98 renamedAuthorIndex2 = store.index('renamed_by_author');99 return checkAuthorIndexContents(100 testCase, renamedAuthorIndex2,101 'Renaming an index should not change its contents').then(102 () => database.close());103 }).then(() => {104 assert_equals(105 renamedAuthorIndex.name, 'renamed_by_author',106 'IDBIndex used in the rename transaction should keep reflecting ' +107 'the new name after the transaction is committed');108 assert_equals(109 renamedAuthorIndex2.name, 'renamed_by_author',110 'IDBIndex obtained after the rename transaction should reflect ' +111 'the new name');112 });113 }, 'IndexedDB index rename in the transaction where it is created');114 promise_test(testCase => {115 return createDatabase(testCase, (database, transaction) => {116 createBooksStore(testCase, database);117 }).then(database => {118 database.close();119 }).then(() => migrateDatabase(testCase, 2, (database, transaction) => {120 const store = transaction.objectStore('books');121 const index = store.index('by_author');122 index.name = 'by_author';123 assert_array_equals(124 store.indexNames, ['by_author', 'by_title'],125 'Renaming an index to the same name should not change the ' +126 "index's IDBObjectStore.indexNames");127 })).then(database => {128 const transaction = database.transaction('books', 'readonly');129 const store = transaction.objectStore('books');130 assert_array_equals(131 store.indexNames, ['by_author', 'by_title'],132 'Committing a transaction that renames a store to the same name ' +133 "should not change the index's IDBObjectStore.indexNames");134 const index = store.index('by_author');135 return checkAuthorIndexContents(136 testCase, index,137 'Committing a transaction that renames an index to the same name ' +138 "should not change the index's contents").then(139 () => database.close());140 });141 }, 'IndexedDB index rename to the same name succeeds');142 promise_test(testCase => {143 return createDatabase(testCase, (database, transaction) => {144 createBooksStore(testCase, database);145 }).then(database => {146 database.close();147 }).then(() => migrateDatabase(testCase, 2, (database, transaction) => {148 const store = transaction.objectStore('books');149 const index = store.index('by_author');150 store.deleteIndex('by_title');151 index.name = 'by_title';152 assert_array_equals(153 store.indexNames, ['by_title'],154 'IDBObjectStore.indexNames should immediately reflect the rename');155 })).then(database => {156 const transaction = database.transaction('books', 'readonly');157 const store = transaction.objectStore('books');158 assert_array_equals(159 store.indexNames, ['by_title'],160 'IDBObjectStore.indexNames should still reflect the rename after ' +161 'the versionchange transaction commits');162 const index = store.index('by_title');163 return checkAuthorIndexContents(164 testCase, index,165 'Renaming an index should not change its contents').then(166 () => database.close());167 });168 }, 'IndexedDB index rename to the name of a deleted index succeeds');169 promise_test(testCase => {170 return createDatabase(testCase, (database, transaction) => {171 createBooksStore(testCase, database);172 }).then(database => {173 database.close();174 }).then(() => migrateDatabase(testCase, 2, (database, transaction) => {175 const store = transaction.objectStore('books');176 store.index('by_author').name = 'tmp';177 store.index('by_title').name = 'by_author';178 store.index('tmp').name = 'by_title';179 assert_array_equals(180 store.indexNames, ['by_author', 'by_title'],181 'IDBObjectStore.indexNames should reflect the swap immediately ' +182 'after the renames');183 return checkTitleIndexContents(184 testCase, store.index('by_author'),185 'Renaming an index should not change its contents');186 })).then(database => {187 const transaction = database.transaction('books', 'readonly');188 const store = transaction.objectStore('books');189 assert_array_equals(190 store.indexNames, ['by_author', 'by_title'],191 'IDBObjectStore.indexNames should still reflect the swap after ' +192 'the versionchange transaction commits');193 const index = store.index('by_title');194 return checkAuthorIndexContents(195 testCase, index,196 'Renaming an index should not change its contents').then(197 () => database.close());198 });199 }, 'IndexedDB index swapping via renames succeeds');200 promise_test(testCase => {201 return createDatabase(testCase, (database, transaction) => {202 createBooksStore(testCase, database);203 }).then(database => {204 database.close();205 }).then(() => migrateDatabase(testCase, 2, (database, transaction) => {206 const store = transaction.objectStore('books');207 const index = store.index('by_author');208 index.name = 42;209 assert_equals(index.name, '42',210 'IDBIndex name should change immediately after a rename to a ' +211 'number');212 assert_array_equals(213 store.indexNames, ['42', 'by_title'],214 'IDBObjectStore.indexNames should immediately reflect the ' +215 'stringifying rename');216 index.name = true;217 assert_equals(index.name, 'true',218 'IDBIndex name should change immediately after a rename to a ' +219 'boolean');220 index.name = {};221 assert_equals(index.name, '[object Object]',222 'IDBIndex name should change immediately after a rename to an ' +223 'object');224 index.name = () => null;225 assert_equals(index.name, '() => null',226 'IDBIndex name should change immediately after a rename to a ' +227 'function');228 index.name = undefined;229 assert_equals(index.name, 'undefined',230 'IDBIndex name should change immediately after a rename to ' +231 'undefined');232 })).then(database => {233 const transaction = database.transaction('books', 'readonly');234 const store = transaction.objectStore('books');235 assert_array_equals(236 store.indexNames, ['by_title', 'undefined'],237 'IDBObjectStore.indexNames should reflect the last rename ' +238 'after the versionchange transaction commits');239 const index = store.index('undefined');240 return checkAuthorIndexContents(241 testCase, index,242 'Renaming an index should not change its contents').then(243 () => database.close());244 });245 }, 'IndexedDB index rename stringifies non-string names');246 for (let escapedName of ['', '\\u0000', '\\uDC00\\uD800']) ((escapedName) => {247 const name = JSON.parse('"' + escapedName + '"');248 promise_test(testCase => {249 return createDatabase(testCase, (database, transaction) => {250 createBooksStore(testCase, database);251 }).then(database => {252 database.close();253 }).then(() => migrateDatabase(testCase, 2, (database, transaction) => {254 const store = transaction.objectStore('books');255 const index = store.index('by_author');256 index.name = name;257 assert_equals(index.name, name,258 'IDBIndex name should change immediately after the rename');259 assert_array_equals(260 store.indexNames, [name, 'by_title'].sort(),261 'IDBObjectStore.indexNames should immediately reflect the rename');262 })).then(database => {263 const transaction = database.transaction('books', 'readonly');264 const store = transaction.objectStore('books');265 assert_array_equals(266 store.indexNames, [name, 'by_title'].sort(),267 'IDBObjectStore.indexNames should reflect the rename ' +268 'after the versionchange transaction commits');269 const index = store.index(name);270 return checkAuthorIndexContents(271 testCase, index,272 'Renaming an index should not change its contents').then(273 () => database.close());274 });275 }, 'IndexedDB index can be renamed to "' + escapedName + '"');276 })(escapedName);277 })...
idbindex-rename-errors.wpt.t.js
Source:idbindex-rename-errors.wpt.t.js
...71 store.indexNames, ['by_author', 'by_title'],72 'Committing a transaction with a failed store rename attempt ' +73 "should not change the index's IDBObjectStore.indexNames");74 const index = store.index('by_author');75 return checkAuthorIndexContents(76 testCase, index,77 'Committing a transaction with a failed rename attempt should ' +78 "not change the index's contents").then(() => database.close());79 });80 }, 'IndexedDB index rename to the name of another index throws');81 promise_test(testCase => {82 return createDatabase(testCase, (database, transaction) => {83 createBooksStore(testCase, database);84 }).then(database => {85 database.close();86 }).then(() => migrateDatabase(testCase, 2, (database, transaction) => {87 const store = transaction.objectStore('books');88 const index = store.index('by_author');89 const exception = { name: 'Custom stringifying error' };90 assert_throws_exactly(91 exception,92 () => {93 index.name = {94 toString: () => { throw exception; }95 };96 }, 'IDBObjectStore rename should re-raise toString() exception');97 assert_array_equals(98 store.indexNames, ['by_author', 'by_title'],99 'An index rename that throws an exception should not change the ' +100 "index's IDBObjectStore.indexNames");101 })).then(database => {102 const transaction = database.transaction('books', 'readonly');103 const store = transaction.objectStore('books');104 assert_array_equals(105 store.indexNames, ['by_author', 'by_title'],106 'Committing a transaction with a failed store rename attempt ' +107 "should not change the index's IDBObjectStore.indexNames");108 const index = store.index('by_author');109 return checkAuthorIndexContents(110 testCase, index,111 'Committing a transaction with a failed rename attempt should ' +112 "not change the index's contents").then(() => database.close());113 });114 }, 'IndexedDB index rename handles exceptions when stringifying names');115 })...
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3if (err) {4console.log(err);5} else {6console.log(data);7}8});9## checkAuthorIndexContents(url, callback)10## getLocations(callback)11## getLocations(callback)12## getTestrs(callback)13## getTestStatus(testId, callback)14## getTestResults(testId, callback)15## getTestResults(testId, callback)16## getTestResults(testId, callback)
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3if (err) {4console.log(err);5} else {6console.log(data);7}8});9var wptb =require('ptb');10var path = require('path');11var fs = require('fs');12var testDir = path.join(__dirname, 'test');13var testFile = ahoin(testDir, 'tet.txt');14## ctestFile2 = path.join(testDir, 'test2.txt');15var testFile3 = path.join(testDir, 'test3.txt');16var testFile4 = path.join(testDir, 'test4.txt');17var testFile5 = path.join(testDir, 'test5.txt');18var testFile6 = path.join(testDir, 'test6.txt');19var testFile7 = path.join(testDir, 'test7.txt');20var testFile8 = path.join(testDir, 'test8.txt');21var testFile9 = path.join(testDir, 'test9.txt');22var testFile10 = path.join(testDir, 'test10.txt');23var testFile11 = path.join(testDir, 'test11.txt');24var testFile12 = path.join(testDir, 'test12.txt');25var testFile13 = path.join(testDir, 'test13.txt');26var testFile14 = path.join(testDir, 'test14.txt');27var testFile15 = path.join(testDir, 'test15.txt');28var testFile16 = path.join(testDir, 'test16.txt');29var testFile17 = path.join(testDir, 'test17.txt');30var testFile18 = path.join(testDir, 'test18.txt');31var testFile19 = path.join(testDir, 'test19.txt');32var testFile20 = path.join(testDir, 'test20.txt');33var testFile21 = path.join(testDir, 'test21.txt');34var testFile22 = path.join(testDir, 'test22.txt');35var testFile23 = path.join(testDir, 'test23.txt');36var testFile24 = path.join(testDir, 'test24.txt');37var testFile25 = path.join(testDir, 'test25.txt');38var testFile26 = path.join(testDir, 'test26.txt');39var testFile27 = path.join(testDir, 'test27.txt');40var testFile28 = path.join(testDir, 'test28.txt');41var testFile29 = path.join(testDir, 'test29.txt');42var testFile30 = path.join(testDir, 'test30.txt');43var testFile31 = path.join(testDir, 'test
Using AI Code Generation
1var heckAuthorIndexContents(url, callback)2## getLocations(callback)3## getLocations(callback)4## getTesters(callback)5## getTestStatus(testId, callback)6## getTestResults(testId, callback)7pagetest.org", function(err, data) {8 if(err) {9 console.log(err);
Using AI Code Generation
1var wptools = require('wptools');2var author = 'Ralph Waldo Emerson';3var authorIndex = 'Category:Writers_by_name';4var authorIndexContents = wptools.getAuthorIndexContents(author, authorIndex, function(authorIndexContents) {5 console.log(authorIndexContents);6});
Using AI Code Generation
1var wptools = require('./wptools.js');2console.log("testing checkAuthorIndexContents method");3 console.log("result:");4 console.log(result);5});6 console.log("resul:");7 consolelg(esult);8});9 console.log("result:");10 console.log(result);11});12 #console.log("result:");13# console.log(result);14});15 console.log("result:");16 console.log(result);17});18 console.log("result:");19 console.log(result);20});ults(testId, callback)21console.log("result:");22console.log(result);23});24## getTestResults(testId, callback)
Using AI Code Generation
1var wpt = require('wpt');2var key = "";3var wpt = new wpt(key);4 if(err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var wpt = require('wpt');11var key = "";12var wpt = new wpt(key);13 if(err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wpt = require('wpt');20var key = "";21var wpt = new wpt(key);22 if(err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var wpt = require('wpt');29var key = "";30var wpt = new wpt(key);31 if(err) {32 console.log(err);
Using AI Code Generation
1var wptools = require('wptools');2var author = 'Ralph Waldo Emerson';3var authorIndex = 'Category:Writers_by_name';4var authorIndexContents = wptools.getAuthorIndexContents(author, authorIndex, function(authorIndexContents) {5 console.log(authorIndexContents);6});
Using AI Code Generation
1var wptools = require('./wptools.js');2console.log("testing checkAuthorIndexContents method");3 console.log("result:");4 console.log(result);5});6 console.log("result:");7 console.log(result);8});9 console.log("result:");10 console.log(result);11});12 console.log("result:");13 console.log(result);14});15 console.log("result:");16 console.log(result);17});18 console.log("result:");19 console.log(result);20});21 console.log("result:");22 console.log(result);23});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!