Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /**
2 * Any copyright is dedicated to the Public Domain.
3 * http://creativecommons.org/publicdomain/zero/1.0/
4 */
6 var testGenerator = testSteps();
8 function testSteps()
9 {
10 const objectStoreData = [
11 { name: "", options: { keyPath: "id", autoIncrement: true } },
12 { name: null, options: { keyPath: "ss" } },
13 { name: undefined, options: { } },
14 { name: "4", options: { autoIncrement: true } },
15 ];
17 const indexData = [
18 { name: "", keyPath: "name", options: { unique: true } },
19 { name: null, keyPath: "height", options: { } }
20 ];
22 const data = [
23 { ss: "237-23-7732", name: "Ann", height: 60 },
24 { ss: "237-23-7733", name: "Bob", height: 65 }
25 ];
27 let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1);
28 request.onerror = errorHandler;
29 request.onupgradeneeded = grabEventAndContinueHandler;
30 let event = yield undefined;
32 let db = event.target.result;
33 db.onerror = errorHandler;
35 event.target.onsuccess = continueToNextStep;
37 for (let objectStoreIndex in objectStoreData) {
38 const objectStoreInfo = objectStoreData[objectStoreIndex];
39 let objectStore = db.createObjectStore(objectStoreInfo.name,
40 objectStoreInfo.options);
41 for (let indexIndex in indexData) {
42 const indexInfo = indexData[indexIndex];
43 let index = objectStore.createIndex(indexInfo.name,
44 indexInfo.keyPath,
45 indexInfo.options);
46 }
47 }
48 yield undefined;
50 ok(true, "Initial setup");
52 for (let objectStoreIndex in objectStoreData) {
53 const info = objectStoreData[objectStoreIndex];
55 for (let indexIndex in indexData) {
56 const objectStoreName = objectStoreData[objectStoreIndex].name;
57 const indexName = indexData[indexIndex].name;
59 let objectStore =
60 db.transaction(objectStoreName, "readwrite")
61 .objectStore(objectStoreName);
62 ok(true, "Got objectStore " + objectStoreName);
64 for (let dataIndex in data) {
65 const obj = data[dataIndex];
66 let key;
67 if (!info.options.keyPath && !info.options.autoIncrement) {
68 key = obj.ss;
69 }
70 objectStore.add(obj, key);
71 }
73 let index = objectStore.index(indexName);
74 ok(true, "Got index " + indexName);
76 let keyIndex = 0;
78 index.openCursor().onsuccess = function(event) {
79 let cursor = event.target.result;
80 if (!cursor) {
81 continueToNextStep();
82 return;
83 }
85 is(cursor.key, data[keyIndex][indexData[indexIndex].keyPath],
86 "Good key");
87 is(cursor.value.ss, data[keyIndex].ss, "Correct ss");
88 is(cursor.value.name, data[keyIndex].name, "Correct name");
89 is(cursor.value.height, data[keyIndex].height, "Correct height");
91 if (!keyIndex) {
92 let obj = cursor.value;
93 obj.updated = true;
95 cursor.update(obj).onsuccess = function(event) {
96 ok(true, "Object updated");
97 cursor.continue();
98 keyIndex++
99 }
100 return;
101 }
103 cursor.delete().onsuccess = function(event) {
104 ok(true, "Object deleted");
105 cursor.continue();
106 keyIndex++
107 }
108 };
109 yield undefined;
111 is(keyIndex, 2, "Saw all the items");
113 keyIndex = 0;
115 db.transaction(objectStoreName).objectStore(objectStoreName)
116 .openCursor()
117 .onsuccess = function(event) {
118 let cursor = event.target.result;
119 if (!cursor) {
120 continueToNextStep();
121 return;
122 }
124 is(cursor.value.ss, data[keyIndex].ss, "Correct ss");
125 is(cursor.value.name, data[keyIndex].name, "Correct name");
126 is(cursor.value.height, data[keyIndex].height, "Correct height");
127 is(cursor.value.updated, true, "Correct updated flag");
129 cursor.continue();
130 keyIndex++;
131 };
132 yield undefined;
134 is(keyIndex, 1, "Saw all the items");
136 db.transaction(objectStoreName, "readwrite")
137 .objectStore(objectStoreName).clear()
138 .onsuccess = continueToNextStep;
139 yield undefined;
141 objectStore = index = null; // Bug 943409 workaround.
142 }
143 }
145 finishTest();
146 yield undefined;
147 }