2 <title>IndexedDB: IDBTransaction.objectStoreNames attribute
</title>
3 <script src=
"../../resources/testharness.js"></script>
4 <script src=
"../../resources/testharnessreport.js"></script>
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');
15 open
.onupgradeneeded
= t
.step_func(function() {
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');
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');
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');
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');
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');
47 open
.onsuccess
= t
.step_func(function() {
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');
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');
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');
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');
81 }, 'IDBTransaction.objectStoreNames in upgrade transactions');
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');
90 open
.onupgradeneeded
= t
.step_func(function() {
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');
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');
105 assert_array_equals(db
.transaction(['s1', 's2']).objectStoreNames
,
107 'transaction should have two stores in scope');
109 assert_array_equals(db
.transaction(['s3', 's1']).objectStoreNames
,
111 'transaction objectStoreNames should be sorted');
114 db
.transaction(['s2', 's1', 's2']).objectStoreNames
,
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 ' +
126 }, 'IDBTransaction.objectStoreNames in simple transactions');
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');
138 '\x00', // U+0000 NULL
139 '\xFF', // U+00FF LATIN SMALL LETTER Y WITH DIAERESIS
143 '123', // basic ASCII
144 'abc', // basic ASCII
145 'ABC', // basic ASCII
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
152 '\uD800', // UTF-16 surrogate lead
153 '\uDC00', // UTF-16 surrogate trail
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');
165 names
.slice().reverse().forEach(function(name
) {
166 db
.createObjectStore(name
);
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');
174 open
.onsuccess
= t
.step_func(function() {
175 var db
= open
.result
;
176 var tx
= db
.transaction(names
.slice().reverse().concat(names
));
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');
186 }, 'IDBTransaction.objectStoreNames are sorted');