Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 name = this.window ? window.location.pathname : "Splendid Test";
11 const objectStoreInfo = [
12 { name: "1", options: { keyPath: null } },
13 { name: "2", options: { keyPath: null, autoIncrement: true } },
14 { name: "3", options: { keyPath: null, autoIncrement: false } },
15 { name: "4", options: { keyPath: null } },
16 { name: "5", options: { keyPath: "foo" } },
17 { name: "6" },
18 { name: "7", options: null },
19 { name: "8", options: { autoIncrement: true } },
20 { name: "9", options: { autoIncrement: false } },
21 { name: "10", options: { keyPath: "foo", autoIncrement: false } },
22 { name: "11", options: { keyPath: "foo", autoIncrement: true } },
23 { name: "" },
24 { name: null },
25 { name: undefined }
26 ];
28 let request = indexedDB.open(name, 1);
29 request.onerror = errorHandler;
30 request.onupgradeneeded = grabEventAndContinueHandler;
31 request.onsuccess = unexpectedSuccessHandler;
32 let event = yield undefined;
34 let db = event.target.result;
36 let count = db.objectStoreNames.length;
37 is(count, 0, "correct objectStoreNames length");
39 try {
40 db.createObjectStore("foo", "bar");
41 ok(false, "createObjectStore with bad options should throw");
42 }
43 catch(e) {
44 ok(true, "createObjectStore with bad options");
45 }
47 ok(db.createObjectStore("foo", { foo: "" }),
48 "createObjectStore with unknown options should not throw");
49 db.deleteObjectStore("foo");
51 for (let index in objectStoreInfo) {
52 index = parseInt(index);
53 const info = objectStoreInfo[index];
55 let objectStore = info.hasOwnProperty("options") ?
56 db.createObjectStore(info.name, info.options) :
57 db.createObjectStore(info.name);
59 is(db.objectStoreNames.length, index + 1,
60 "updated objectStoreNames list");
62 let name = info.name;
63 if (name === null) {
64 name = "null";
65 }
66 else if (name === undefined) {
67 name = "undefined";
68 }
70 let found = false;
71 for (let i = 0; i <= index; i++) {
72 if (db.objectStoreNames.item(i) == name) {
73 found = true;
74 break;
75 }
76 }
77 is(found, true, "objectStoreNames contains name");
79 is(objectStore.name, name, "Bad name");
80 is(objectStore.keyPath, info.options && info.options.keyPath ?
81 info.options.keyPath : null,
82 "Bad keyPath");
83 if(objectStore.indexNames.length, 0, "Bad indexNames");
85 ok(event.target.transaction, "event has a transaction");
86 ok(event.target.transaction.db === db, "transaction has the right db");
87 is(event.target.transaction.mode, "versionchange",
88 "transaction has the correct mode");
89 is(event.target.transaction.objectStoreNames.length, index + 1,
90 "transaction has correct objectStoreNames list");
91 found = false;
92 for (let j = 0; j < event.target.transaction.objectStoreNames.length;
93 j++) {
94 if (event.target.transaction.objectStoreNames.item(j) == name) {
95 found = true;
96 break;
97 }
98 }
99 is(found, true, "transaction has correct objectStoreNames list");
100 }
102 // Can't handle autoincrement and empty keypath
103 let ex;
104 try {
105 db.createObjectStore("storefail", { keyPath: "", autoIncrement: true });
106 }
107 catch(e) {
108 ex = e;
109 }
110 ok(ex, "createObjectStore with empty keyPath and autoIncrement should throw");
111 is(ex.name, "InvalidAccessError", "should throw right exception");
112 ok(ex instanceof DOMException, "should throw right exception");
113 is(ex.code, DOMException.INVALID_ACCESS_ERR, "should throw right exception");
115 // Can't handle autoincrement and array keypath
116 let ex;
117 try {
118 db.createObjectStore("storefail", { keyPath: ["a"], autoIncrement: true });
119 }
120 catch(e) {
121 ex = e;
122 }
123 ok(ex, "createObjectStore with array keyPath and autoIncrement should throw");
124 is(ex.name, "InvalidAccessError", "should throw right exception");
125 ok(ex instanceof DOMException, "should throw right exception");
126 is(ex.code, DOMException.INVALID_ACCESS_ERR, "should throw right exception");
128 request.onsuccess = grabEventAndContinueHandler;
129 request.onupgradeneeded = unexpectedSuccessHandler;
131 event = yield undefined;
133 finishTest();
134 yield undefined;
135 }