test_global_data.js (1785B)
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 objectStore = { 12 name: "Objects", 13 options: { keyPath: "id", autoIncrement: true }, 14 }; 15 16 let request = indexedDB.open(name, 1); 17 request.onerror = errorHandler; 18 request.onupgradeneeded = grabEventAndContinueHandler; 19 let event = yield undefined; 20 21 let db1 = event.target.result; 22 23 is(db1.objectStoreNames.length, 0, "No objectStores in db1"); 24 25 db1.createObjectStore(objectStore.name, objectStore.options); 26 27 continueToNextStep(); 28 yield undefined; 29 30 request = indexedDB.open(name, 1); 31 request.onerror = errorHandler; 32 request.onsuccess = grabEventAndContinueHandler; 33 event = yield undefined; 34 35 let db2 = event.target.result; 36 37 ok(db1 !== db2, "Databases are not the same object"); 38 39 is(db1.objectStoreNames.length, 1, "1 objectStore in db1"); 40 is(db1.objectStoreNames.item(0), objectStore.name, "Correct name"); 41 42 is(db2.objectStoreNames.length, 1, "1 objectStore in db2"); 43 is(db2.objectStoreNames.item(0), objectStore.name, "Correct name"); 44 45 let objectStore1 = db1 46 .transaction(objectStore.name) 47 .objectStore(objectStore.name); 48 is(objectStore1.name, objectStore.name, "Same name"); 49 is(objectStore1.keyPath, objectStore.options.keyPath, "Same keyPath"); 50 51 let objectStore2 = db2 52 .transaction(objectStore.name) 53 .objectStore(objectStore.name); 54 55 ok(objectStore1 !== objectStore2, "Different objectStores"); 56 is(objectStore1.name, objectStore2.name, "Same name"); 57 is(objectStore1.keyPath, objectStore2.keyPath, "Same keyPath"); 58 59 finishTest(); 60 }