test_names_sorted.js (3515B)
1 /** 2 * Any copyright is dedicated to the Public Domain. 3 * http://creativecommons.org/publicdomain/zero/1.0/ 4 */ 5 6 /* exported testGenerator */ 7 var testGenerator = testSteps(); 8 9 function* testSteps() { 10 const name = this.window ? window.location.pathname : "Splendid Test"; 11 const objectStoreInfo = [ 12 { name: "foo", options: { keyPath: "id" }, location: 1 }, 13 { name: "bar", options: { keyPath: "id" }, location: 0 }, 14 ]; 15 const indexInfo = [ 16 { name: "foo", keyPath: "value", location: 1 }, 17 { name: "bar", keyPath: "value", location: 0 }, 18 ]; 19 20 let request = indexedDB.open(name, 1); 21 request.onerror = errorHandler; 22 request.onupgradeneeded = grabEventAndContinueHandler; 23 request.onsuccess = unexpectedSuccessHandler; 24 let event = yield undefined; 25 let db = event.target.result; 26 27 for (let i = 0; i < objectStoreInfo.length; i++) { 28 let info = objectStoreInfo[i]; 29 let objectStore = info.hasOwnProperty("options") 30 ? db.createObjectStore(info.name, info.options) 31 : db.createObjectStore(info.name); 32 33 // Test index creation, and that it ends up in indexNames. 34 for (let j = 0; j < indexInfo.length; j++) { 35 let info = indexInfo[j]; 36 info.hasOwnProperty("options") 37 ? objectStore.createIndex(info.name, info.keyPath, info.options) 38 : objectStore.createIndex(info.name, info.keyPath); 39 } 40 } 41 42 request.onsuccess = grabEventAndContinueHandler; 43 request.onupgradeneeded = unexpectedSuccessHandler; 44 45 event = yield undefined; 46 47 let objectStoreNames = []; 48 for (let i = 0; i < objectStoreInfo.length; i++) { 49 let info = objectStoreInfo[i]; 50 objectStoreNames.push(info.name); 51 52 is( 53 db.objectStoreNames[info.location], 54 info.name, 55 "Got objectStore name in the right location" 56 ); 57 58 let trans = db.transaction(info.name); 59 let objectStore = trans.objectStore(info.name); 60 for (let j = 0; j < indexInfo.length; j++) { 61 let info = indexInfo[j]; 62 is( 63 objectStore.indexNames[info.location], 64 info.name, 65 "Got index name in the right location" 66 ); 67 } 68 } 69 70 let trans = db.transaction(objectStoreNames); 71 for (let i = 0; i < objectStoreInfo.length; i++) { 72 let info = objectStoreInfo[i]; 73 74 is( 75 trans.objectStoreNames[info.location], 76 info.name, 77 "Got objectStore name in the right location" 78 ); 79 } 80 81 db.close(); 82 83 request = indexedDB.open(name, 1); 84 request.onerror = errorHandler; 85 request.onsuccess = grabEventAndContinueHandler; 86 request.onupgradeneeded = unexpectedSuccessHandler; 87 event = yield undefined; 88 89 db = event.target.result; 90 91 objectStoreNames = []; 92 for (let i = 0; i < objectStoreInfo.length; i++) { 93 let info = objectStoreInfo[i]; 94 objectStoreNames.push(info.name); 95 96 is( 97 db.objectStoreNames[info.location], 98 info.name, 99 "Got objectStore name in the right location" 100 ); 101 102 let trans = db.transaction(info.name); 103 let objectStore = trans.objectStore(info.name); 104 for (let j = 0; j < indexInfo.length; j++) { 105 let info = indexInfo[j]; 106 is( 107 objectStore.indexNames[info.location], 108 info.name, 109 "Got index name in the right location" 110 ); 111 } 112 } 113 114 trans = db.transaction(objectStoreNames); 115 for (let i = 0; i < objectStoreInfo.length; i++) { 116 let info = objectStoreInfo[i]; 117 118 is( 119 trans.objectStoreNames[info.location], 120 info.name, 121 "Got objectStore name in the right location" 122 ); 123 } 124 125 db.close(); 126 127 finishTest(); 128 }