| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>IndexedDB: Exception Order of IDBObjectStore.createIndex()</title> | 2 <title>IndexedDB: Exception Order of IDBObjectStore.createIndex()</title> |
| 3 <link rel="author" title="Mozilla" href="https://www.mozilla.org"> | 3 <link rel="author" title="Mozilla" href="https://www.mozilla.org"> |
| 4 <link rel="help" href="http://w3c.github.io/IndexedDB/#dom-idbobjectstore-create
index"> | 4 <link rel="help" href="http://w3c.github.io/IndexedDB/#dom-idbobjectstore-create
index"> |
| 5 <script src="/resources/testharness.js"></script> | 5 <script src="/resources/testharness.js"></script> |
| 6 <script src="/resources/testharnessreport.js"></script> | 6 <script src="/resources/testharnessreport.js"></script> |
| 7 <script src="support.js"></script> |
| 7 <script> | 8 <script> |
| 8 | 9 |
| 9 function indexeddb_test(description, upgrade_func, open_func = null) { | |
| 10 async_test(function(t) { | |
| 11 var dbname = document.location + "-" + t.name; | |
| 12 var del = indexedDB.deleteDatabase(dbname); | |
| 13 del.onerror = t.unreached_func("deleteDatabase should succeed"); | |
| 14 var open = indexedDB.open(dbname, 1); | |
| 15 open.onerror = t.unreached_func("open should succeed"); | |
| 16 open.onupgradeneeded = t.step_func(function() { | |
| 17 var db = open.result; | |
| 18 var tx = open.transaction; | |
| 19 upgrade_func(t, db, tx); | |
| 20 }); | |
| 21 if (open_func) { | |
| 22 open.onsuccess = t.step_func(function() { | |
| 23 var db = open.result; | |
| 24 open_func(t, db); | |
| 25 }); | |
| 26 } | |
| 27 }, description); | |
| 28 } | |
| 29 | |
| 30 indexeddb_test( | 10 indexeddb_test( |
| 31 "InvalidStateError(Incorrect mode) vs. TransactionInactiveError", | |
| 32 function(t, db, txn) { | 11 function(t, db, txn) { |
| 33 var store = db.createObjectStore("s"); | 12 var store = db.createObjectStore("s"); |
| 34 }, | 13 }, |
| 35 function(t, db) { | 14 function(t, db) { |
| 36 var txn = db.transaction("s"); | 15 var txn = db.transaction("s"); |
| 37 var store = txn.objectStore("s"); | 16 var store = txn.objectStore("s"); |
| 38 txn.oncomplete = function() { | 17 txn.oncomplete = function() { |
| 39 assert_throws("InvalidStateError", function() { | 18 assert_throws("InvalidStateError", function() { |
| 40 store.createIndex("index", "foo"); | 19 store.createIndex("index", "foo"); |
| 41 }, "Mode check should precede state check of the transaction"); | 20 }, "Mode check should precede state check of the transaction"); |
| 42 t.done(); | 21 t.done(); |
| 43 }; | 22 }; |
| 44 } | 23 }, |
| 24 "InvalidStateError(Incorrect mode) vs. TransactionInactiveError" |
| 45 ); | 25 ); |
| 46 | 26 |
| 47 var gDeletedObjectStore; | 27 var gDeletedObjectStore; |
| 48 indexeddb_test( | 28 indexeddb_test( |
| 49 "InvalidStateError(Deleted ObjectStore) vs. TransactionInactiveError", | |
| 50 function(t, db, txn) { | 29 function(t, db, txn) { |
| 51 gDeletedObjectStore = db.createObjectStore("s"); | 30 gDeletedObjectStore = db.createObjectStore("s"); |
| 52 db.deleteObjectStore("s"); | 31 db.deleteObjectStore("s"); |
| 53 txn.oncomplete = function() { | 32 txn.oncomplete = function() { |
| 54 assert_throws("InvalidStateError", function() { | 33 assert_throws("InvalidStateError", function() { |
| 55 gDeletedObjectStore.createIndex("index", "foo"); | 34 gDeletedObjectStore.createIndex("index", "foo"); |
| 56 }, "Deletion check should precede transaction-state check"); | 35 }, "Deletion check should precede transaction-state check"); |
| 57 t.done(); | 36 t.done(); |
| 58 }; | 37 }; |
| 59 } | 38 }, |
| 39 null, |
| 40 "InvalidStateError(Deleted ObjectStore) vs. TransactionInactiveError" |
| 60 ); | 41 ); |
| 61 | 42 |
| 62 indexeddb_test( | 43 indexeddb_test( |
| 63 "TransactionInactiveError vs. ConstraintError", | |
| 64 function(t, db, txn) { | 44 function(t, db, txn) { |
| 65 var store = db.createObjectStore("s"); | 45 var store = db.createObjectStore("s"); |
| 66 store.createIndex("index", "foo"); | 46 store.createIndex("index", "foo"); |
| 67 txn.oncomplete = function() { | 47 txn.oncomplete = function() { |
| 68 assert_throws("TransactionInactiveError", function() { | 48 assert_throws("TransactionInactiveError", function() { |
| 69 store.createIndex("index", "foo"); | 49 store.createIndex("index", "foo"); |
| 70 }, "Transaction-state check should precede index name check"); | 50 }, "Transaction-state check should precede index name check"); |
| 71 t.done(); | 51 t.done(); |
| 72 }; | 52 }; |
| 73 } | 53 }, |
| 54 null, |
| 55 "TransactionInactiveError vs. ConstraintError" |
| 74 ); | 56 ); |
| 75 | 57 |
| 76 indexeddb_test( | 58 indexeddb_test( |
| 77 "ConstraintError vs. SyntaxError", | |
| 78 function(t, db) { | 59 function(t, db) { |
| 79 var store = db.createObjectStore("s"); | 60 var store = db.createObjectStore("s"); |
| 80 store.createIndex("index", "foo"); | 61 store.createIndex("index", "foo"); |
| 81 assert_throws("ConstraintError", function() { | 62 assert_throws("ConstraintError", function() { |
| 82 store.createIndex("index", "invalid key path"); | 63 store.createIndex("index", "invalid key path"); |
| 83 }, "Index name check should precede syntax check of the key path"); | 64 }, "Index name check should precede syntax check of the key path"); |
| 84 assert_throws("ConstraintError", function() { | 65 assert_throws("ConstraintError", function() { |
| 85 store.createIndex("index", | 66 store.createIndex("index", |
| 86 ["invalid key path 1", "invalid key path 2"]); | 67 ["invalid key path 1", "invalid key path 2"]); |
| 87 }, "Index name check should precede syntax check of the key path"); | 68 }, "Index name check should precede syntax check of the key path"); |
| 88 t.done(); | 69 t.done(); |
| 89 } | 70 }, |
| 71 null, |
| 72 "ConstraintError vs. SyntaxError" |
| 90 ); | 73 ); |
| 91 | 74 |
| 92 indexeddb_test( | 75 indexeddb_test( |
| 93 "SyntaxError vs. InvalidAccessError", | |
| 94 function(t, db) { | 76 function(t, db) { |
| 95 var store = db.createObjectStore("s"); | 77 var store = db.createObjectStore("s"); |
| 96 assert_throws("SyntaxError", function() { | 78 assert_throws("SyntaxError", function() { |
| 97 store.createIndex("index", | 79 store.createIndex("index", |
| 98 ["invalid key path 1", "invalid key path 2"], | 80 ["invalid key path 1", "invalid key path 2"], |
| 99 { multiEntry: true }); | 81 { multiEntry: true }); |
| 100 }, "Syntax check should precede multiEntry check of the key path"); | 82 }, "Syntax check should precede multiEntry check of the key path"); |
| 101 t.done(); | 83 t.done(); |
| 102 } | 84 }, |
| 85 null, |
| 86 "SyntaxError vs. InvalidAccessError" |
| 103 ); | 87 ); |
| 104 | 88 |
| 105 </script> | 89 </script> |
| OLD | NEW |