| <!DOCTYPE html> |
| <title>IndexedDB: IDBTransaction.objectStoreNames attribute</title> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| <script> |
| |
| async_test(function(t) { |
| var dbname = document.location + '-' + t.name; |
| var del = indexedDB.deleteDatabase(dbname); |
| del.onerror = t.unreached_func('deleteDatabase should succeed'); |
| var open = indexedDB.open(dbname, 1); |
| open.onerror = t.unreached_func('open should succeed'); |
| |
| var tx; |
| open.onupgradeneeded = t.step_func(function() { |
| var db = open.result; |
| tx = open.transaction; |
| assert_array_equals(db.objectStoreNames, [], |
| 'database should have no stores'); |
| assert_array_equals(tx.objectStoreNames, [], |
| 'transaction objectStoreNames should be empty'); |
| |
| db.createObjectStore('s1'); |
| assert_array_equals(db.objectStoreNames, ['s1'], |
| 'database should have one store'); |
| assert_array_equals(tx.objectStoreNames, ['s1'], |
| 'transaction objectStoreNames should have new store'); |
| |
| db.createObjectStore('s3'); |
| assert_array_equals(db.objectStoreNames, ['s1', 's3'], |
| 'database should have two stores'); |
| assert_array_equals(tx.objectStoreNames, ['s1', 's3'], |
| 'transaction objectStoreNames should have new store'); |
| |
| db.createObjectStore('s2'); |
| assert_array_equals(db.objectStoreNames, ['s1', 's2', 's3'], |
| 'database should have three stores'); |
| assert_array_equals(tx.objectStoreNames, ['s1', 's2', 's3'], |
| 'transaction objectStoreNames should be sorted'); |
| |
| db.deleteObjectStore('s1'); |
| assert_array_equals(db.objectStoreNames, ['s2', 's3'], |
| 'database should have two stores'); |
| assert_array_equals(tx.objectStoreNames, ['s2', 's3'], |
| 'transaction objectStoreNames should be updated after delete'); |
| }); |
| open.onsuccess = t.step_func(function() { |
| var db = open.result; |
| db.close(); |
| |
| assert_array_equals(db.objectStoreNames, ['s2', 's3'], |
| 'connection should have snapshot of store names after close'); |
| assert_array_equals(tx.objectStoreNames, ['s2', 's3'], |
| 'transaction should have snapshot of store names after close'); |
| |
| var open2 = indexedDB.open(dbname, 2); |
| open2.onerror = t.unreached_func('open should succeed'); |
| open2.onupgradeneeded = t.step_func(function() { |
| var db2 = open2.result; |
| var tx2 = open2.transaction; |
| assert_array_equals(db2.objectStoreNames, ['s2', 's3'], |
| 'database should have two stores'); |
| assert_array_equals(tx2.objectStoreNames, ['s2', 's3'], |
| 'transaction should have two stores in scope'); |
| |
| db2.createObjectStore('s4'); |
| assert_array_equals(db2.objectStoreNames, ['s2', 's3', 's4'], |
| 'database should have three stores'); |
| assert_array_equals(tx2.objectStoreNames, ['s2', 's3', 's4'], |
| 'transaction should have new store in scope'); |
| |
| assert_array_equals(db.objectStoreNames, ['s2', 's3'], |
| 'previous connection objectStoreNames should be unchanged'); |
| assert_array_equals(tx.objectStoreNames, ['s2', 's3'], |
| 'previous transaction objectStoreNames should be unchanged'); |
| |
| t.done(); |
| }); |
| }); |
| |
| }, 'IDBTransaction.objectStoreNames in upgrade transactions'); |
| |
| async_test(function(t) { |
| var dbname = document.location + '-' + t.name; |
| var del = indexedDB.deleteDatabase(dbname); |
| del.onerror = t.unreached_func('deleteDatabase should succeed'); |
| var open = indexedDB.open(dbname, 1); |
| open.onerror = t.unreached_func('open should succeed'); |
| |
| open.onupgradeneeded = t.step_func(function() { |
| var db = open.result; |
| assert_array_equals(db.objectStoreNames, [], |
| 'database should have no stores'); |
| db.createObjectStore('s1'); |
| db.createObjectStore('s2'); |
| db.createObjectStore('s3'); |
| assert_array_equals(db.objectStoreNames, ['s1', 's2', 's3'], |
| 'database should have three stores'); |
| }); |
| open.onsuccess = t.step_func(function() { |
| var db = open.result; |
| assert_array_equals(db.transaction('s1').objectStoreNames, ['s1'], |
| 'transaction should have one store in scope'); |
| |
| assert_array_equals(db.transaction(['s1', 's2']).objectStoreNames, |
| ['s1', 's2'], |
| 'transaction should have two stores in scope'); |
| |
| assert_array_equals(db.transaction(['s3', 's1']).objectStoreNames, |
| ['s1', 's3'], |
| 'transaction objectStoreNames should be sorted'); |
| |
| assert_array_equals( |
| db.transaction(['s2', 's1', 's2']).objectStoreNames, |
| ['s1', 's2'], |
| 'transaction objectStoreNames should not have duplicates'); |
| var tx = db.transaction(['s1', 's2']); |
| tx.oncomplete = t.step_func(function() { |
| assert_array_equals(tx.objectStoreNames, ['s1', 's2'], |
| 'transaction objectStoreNames should be unchanged ' + |
| 'when finished'); |
| db.close(); |
| t.done(); |
| }); |
| }); |
| }, 'IDBTransaction.objectStoreNames in simple transactions'); |
| |
| async_test(function(t) { |
| var dbname = document.location + '-' + t.name; |
| var del = indexedDB.deleteDatabase(dbname); |
| del.onerror = t.unreached_func('deleteDatabase should succeed'); |
| var open = indexedDB.open(dbname, 1); |
| open.onerror = t.unreached_func('open should succeed'); |
| |
| var names = [ |
| '', // empty string |
| |
| '\x00', // U+0000 NULL |
| '\xFF', // U+00FF LATIN SMALL LETTER Y WITH DIAERESIS |
| |
| '1', // basic ASCII |
| '12', // basic ASCII |
| '123', // basic ASCII |
| 'abc', // basic ASCII |
| 'ABC', // basic ASCII |
| |
| '\xA2', // U+00A2 CENT SIGN |
| '\u6C34', // U+6C34 CJK UNIFIED IDEOGRAPH (water) |
| '\uD834\uDD1E', // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair) |
| '\uFFFD', // U+FFFD REPLACEMENT CHARACTER |
| |
| '\uD800', // UTF-16 surrogate lead |
| '\uDC00', // UTF-16 surrogate trail |
| ]; |
| names.sort(); |
| |
| open.onupgradeneeded = t.step_func(function() { |
| var db = open.result; |
| var tx = open.transaction; |
| assert_array_equals(db.objectStoreNames, [], |
| 'database should have no stores'); |
| assert_array_equals(tx.objectStoreNames, [], |
| 'transaction should have no stores'); |
| |
| names.slice().reverse().forEach(function(name) { |
| db.createObjectStore(name); |
| }); |
| |
| assert_array_equals(db.objectStoreNames, names, |
| 'database should have names sorted'); |
| assert_array_equals(tx.objectStoreNames, names, |
| 'transaction should have names sorted'); |
| }); |
| open.onsuccess = t.step_func(function() { |
| var db = open.result; |
| var tx = db.transaction(names.slice().reverse().concat(names)); |
| |
| assert_array_equals(db.objectStoreNames, names, |
| 'database should have names sorted with no duplicates'); |
| assert_array_equals(tx.objectStoreNames, names, |
| 'transaction should have names sorted with no duplicates'); |
| |
| db.close(); |
| t.done(); |
| }); |
| }, 'IDBTransaction.objectStoreNames are sorted'); |
| |
| |
| </script> |