OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <title>IndexedDB: IDBTransaction.objectStoreNames attribute</title> | |
3 <script src="../../resources/testharness.js"></script> | |
4 <script src="../../resources/testharnessreport.js"></script> | |
5 <script> | |
6 | |
7 async_test(function(t) { | |
8 var dbname = document.location + '-' + t.name; | |
9 var del = indexedDB.deleteDatabase(dbname); | |
10 del.onerror = t.unreached_func('deleteDatabase should succeed'); | |
11 var open = indexedDB.open(dbname, 1); | |
12 open.onerror = t.unreached_func('open should succeed'); | |
13 | |
14 var tx; | |
15 open.onupgradeneeded = t.step_func(function() { | |
16 var db = open.result; | |
17 tx = open.transaction; | |
18 assert_array_equals(db.objectStoreNames, [], | |
19 'database should have no stores'); | |
20 assert_array_equals(tx.objectStoreNames, [], | |
21 'transaction objectStoreNames should be empty'); | |
22 | |
23 db.createObjectStore('s1'); | |
24 assert_array_equals(db.objectStoreNames, ['s1'], | |
25 'database should have one store'); | |
26 assert_array_equals(tx.objectStoreNames, ['s1'], | |
27 'transaction objectStoreNames should have new store'); | |
28 | |
29 db.createObjectStore('s3'); | |
30 assert_array_equals(db.objectStoreNames, ['s1', 's3'], | |
31 'database should have two stores'); | |
32 assert_array_equals(tx.objectStoreNames, ['s1', 's3'], | |
33 'transaction objectStoreNames should have new store'); | |
34 | |
35 db.createObjectStore('s2'); | |
36 assert_array_equals(db.objectStoreNames, ['s1', 's2', 's3'], | |
37 'database should have three stores'); | |
38 assert_array_equals(tx.objectStoreNames, ['s1', 's2', 's3'], | |
39 'transaction objectStoreNames should be sorted'); | |
40 | |
41 db.deleteObjectStore('s1'); | |
42 assert_array_equals(db.objectStoreNames, ['s2', 's3'], | |
43 'database should have two stores'); | |
44 assert_array_equals(tx.objectStoreNames, ['s2', 's3'], | |
45 'transaction objectStoreNames should be updated after delete'); | |
46 }); | |
47 open.onsuccess = t.step_func(function() { | |
48 var db = open.result; | |
49 db.close(); | |
50 | |
51 assert_array_equals(db.objectStoreNames, ['s2', 's3'], | |
52 'connection should have snapshot of store names after close'); | |
53 assert_array_equals(tx.objectStoreNames, ['s2', 's3'], | |
54 'transaction should have snapshot of store names after close'); | |
55 | |
56 var open2 = indexedDB.open(dbname, 2); | |
57 open2.onerror = t.unreached_func('open should succeed'); | |
58 open2.onupgradeneeded = t.step_func(function() { | |
59 var db2 = open2.result; | |
60 var tx2 = open2.transaction; | |
61 assert_array_equals(db2.objectStoreNames, ['s2', 's3'], | |
62 'database should have two stores'); | |
63 assert_array_equals(tx2.objectStoreNames, ['s2', 's3'], | |
64 'transaction should have two stores in scope'); | |
65 | |
66 db2.createObjectStore('s4'); | |
67 assert_array_equals(db2.objectStoreNames, ['s2', 's3', 's4'], | |
68 'database should have three stores'); | |
69 assert_array_equals(tx2.objectStoreNames, ['s2', 's3', 's4'], | |
70 'transaction should have new store in scope'); | |
71 | |
72 assert_array_equals(db.objectStoreNames, ['s2', 's3'], | |
73 'previous connection objectStoreNames should be unchanged'); | |
74 assert_array_equals(tx.objectStoreNames, ['s2', 's3'], | |
75 'previous transaction objectStoreNames should be unchanged'); | |
76 | |
77 t.done(); | |
78 }); | |
79 }); | |
80 | |
81 }, 'IDBTransaction.objectStoreNames in upgrade transactions'); | |
82 | |
83 async_test(function(t) { | |
84 var dbname = document.location + '-' + t.name; | |
85 var del = indexedDB.deleteDatabase(dbname); | |
86 del.onerror = t.unreached_func('deleteDatabase should succeed'); | |
87 var open = indexedDB.open(dbname, 1); | |
88 open.onerror = t.unreached_func('open should succeed'); | |
89 | |
90 open.onupgradeneeded = t.step_func(function() { | |
91 var db = open.result; | |
92 assert_array_equals(db.objectStoreNames, [], | |
93 'database should have no stores'); | |
94 db.createObjectStore('s1'); | |
95 db.createObjectStore('s2'); | |
96 db.createObjectStore('s3'); | |
97 assert_array_equals(db.objectStoreNames, ['s1', 's2', 's3'], | |
98 'database should have three stores'); | |
99 }); | |
100 open.onsuccess = t.step_func(function() { | |
101 var db = open.result; | |
102 assert_array_equals(db.transaction('s1').objectStoreNames, ['s1'], | |
103 'transaction should have one store in scope'); | |
104 | |
105 assert_array_equals(db.transaction(['s1', 's2']).objectStoreNames, | |
106 ['s1', 's2'], | |
107 'transaction should have two stores in scope'); | |
108 | |
109 assert_array_equals(db.transaction(['s3', 's1']).objectStoreNames, | |
110 ['s1', 's3'], | |
111 'transaction objectStoreNames should be sorted'); | |
112 | |
113 assert_array_equals( | |
114 db.transaction(['s2', 's1', 's2']).objectStoreNames, | |
115 ['s1', 's2'], | |
116 'transaction objectStoreNames should not have duplicates'); | |
117 var tx = db.transaction(['s1', 's2']); | |
118 tx.oncomplete = t.step_func(function() { | |
119 assert_array_equals(tx.objectStoreNames, ['s1', 's2'], | |
120 'transaction objectStoreNames should be unchanged ' + | |
121 'when finished'); | |
122 db.close(); | |
123 t.done(); | |
124 }); | |
125 }); | |
126 }, 'IDBTransaction.objectStoreNames in simple transactions'); | |
127 | |
128 async_test(function(t) { | |
129 var dbname = document.location + '-' + t.name; | |
130 var del = indexedDB.deleteDatabase(dbname); | |
131 del.onerror = t.unreached_func('deleteDatabase should succeed'); | |
132 var open = indexedDB.open(dbname, 1); | |
133 open.onerror = t.unreached_func('open should succeed'); | |
134 | |
135 var names = [ | |
136 '', // empty string | |
137 | |
138 '\x00', // U+0000 NULL | |
139 '\xFF', // U+00FF LATIN SMALL LETTER Y WITH DIAERESIS | |
140 | |
141 '1', // basic ASCII | |
142 '12', // basic ASCII | |
143 '123', // basic ASCII | |
144 'abc', // basic ASCII | |
145 'ABC', // basic ASCII | |
146 | |
147 '\xA2', // U+00A2 CENT SIGN | |
148 '\u6C34', // U+6C34 CJK UNIFIED IDEOGRAPH (water) | |
149 '\uD834\uDD1E', // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair) | |
150 '\uFFFD', // U+FFFD REPLACEMENT CHARACTER | |
151 | |
152 '\uD800', // UTF-16 surrogate lead | |
153 '\uDC00', // UTF-16 surrogate trail | |
154 ]; | |
155 names.sort(); | |
156 | |
157 open.onupgradeneeded = t.step_func(function() { | |
158 var db = open.result; | |
159 var tx = open.transaction; | |
160 assert_array_equals(db.objectStoreNames, [], | |
161 'database should have no stores'); | |
162 assert_array_equals(tx.objectStoreNames, [], | |
163 'transaction should have no stores'); | |
164 | |
165 names.slice().reverse().forEach(function(name) { | |
166 db.createObjectStore(name); | |
167 }); | |
168 | |
169 assert_array_equals(db.objectStoreNames, names, | |
170 'database should have names sorted'); | |
171 assert_array_equals(tx.objectStoreNames, names, | |
172 'transaction should have names sorted'); | |
173 }); | |
174 open.onsuccess = t.step_func(function() { | |
175 var db = open.result; | |
176 var tx = db.transaction(names.slice().reverse().concat(names)); | |
177 | |
178 assert_array_equals(db.objectStoreNames, names, | |
179 'database should have names sorted with no duplicates'); | |
180 assert_array_equals(tx.objectStoreNames, names, | |
181 'transaction should have names sorted with no duplicates'); | |
182 | |
183 db.close(); | |
184 t.done(); | |
185 }); | |
186 }, 'IDBTransaction.objectStoreNames are sorted'); | |
187 | |
188 | |
189 </script> | |
OLD | NEW |