dom/indexedDB/test/unit/test_names_sorted.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial