Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/storage/indexeddb/exception-order.html |
| diff --git a/third_party/WebKit/LayoutTests/storage/indexeddb/exception-order.html b/third_party/WebKit/LayoutTests/storage/indexeddb/exception-order.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..542a83df58c4d30edaf446f62c2273d0bea169d1 |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/storage/indexeddb/exception-order.html |
| @@ -0,0 +1,227 @@ |
| +<!DOCTYPE html> |
| +<title>IndexedDB: Exception Ordering</title> |
| +<script src="../../resources/testharness.js"></script> |
|
pwnall
2016/09/01 19:03:52
Would it make sense to point to the spec that you'
jsbell
2016/09/01 20:20:46
Done.
|
| +<script src="../../resources/testharnessreport.js"></script> |
| +<script src="resources/testharness-helpers.js"></script> |
| +<script> |
| + |
| +indexeddb_test( |
|
pwnall
2016/09/01 19:03:52
Can we upstream tests that reference helpers? I'm
jsbell
2016/09/01 20:20:46
Yes. There's a variation of this in web-platform-t
|
| + function(t, db) { |
| + db.createObjectStore('s'); |
| + }, |
| + function(t, db) { |
| + db.close(); |
| + assert_throws('InvalidStateError', function() { |
| + // Could throw: |
| + // * InvalidStateError (connection is closed) |
| + // * InvalidAccessError (stores is empty) |
| + db.transaction([]); |
| + }, 'Connection closed check should precede stores check'); |
|
pwnall
2016/09/01 19:03:52
Should the comment above be merged into the assert
jsbell
2016/09/01 20:20:46
Done.
|
| + t.done(); |
| + }, |
| + 'IDBDatabase.transaction exception order: InvalidStateError vs. InvalidAccessError' |
| +); |
| + |
|
pwnall
2016/09/01 19:03:52
Would it make sense to also have a test for Invali
jsbell
2016/09/01 20:20:46
Done.
|
| +indexeddb_test( |
| + function(t, db) { |
| + db.createObjectStore('s'); |
| + }, |
| + function(t, db) { |
| + assert_throws('NotFoundError', function() { |
| + // Could throw: |
| + // * NotFoundError (no such store) |
| + // * InvalidAccessError (invalid mode) |
| + db.transaction('no-such-store', 'versionchange'); |
| + }, 'Stores check should precede mode check'); |
| + t.done(); |
| + }, |
| + 'IDBDatabase.transaction exception order: NotFoundError vs. InvalidAccessError' |
| +); |
| + |
| +indexeddb_test( |
| + function(t, db) { |
| + db.createObjectStore('s'); |
| + assert_throws('SyntaxError', function() { |
|
pwnall
2016/09/01 19:03:52
I think the spec [1] says exactly the opposite. Th
jsbell
2016/09/01 20:20:46
Yes. Firefox matches the code here, so I'll just u
|
| + // Could throw: |
| + // * SyntaxError (invalid keypath) |
| + // * ConstraintError (duplicate store name) |
| + db.createObjectStore('s', {keyPath: 'not a valid key path'}); |
| + }, 'Keypad validation should precede store name check'); |
|
pwnall
2016/09/01 19:03:52
Keypad -> keypath?
jsbell
2016/09/01 20:20:46
Done.
|
| + t.done(); |
| + }, |
| + function(t, db) {}, |
| + 'IDBDatabase.createObjectStore exception order: ConstraintError vs. SyntaxError' |
| +); |
| + |
| +indexeddb_test( |
| + function(t, db) { |
| + var s = db.createObjectStore('s'); |
| + s.put('value', 'key'); |
| + }, |
| + function(t, db) { |
| + var s = db.transaction('s', 'readonly').objectStore('s'); |
| + var r = s.openKeyCursor(); |
| + r.onsuccess = t.step_func(function() { |
| + r.onsuccess = null; |
| + var cursor = r.result; |
| + setTimeout(t.step_func(function() { |
| + assert_throws('TransactionInactiveError', function() { |
| + // Could throw: |
| + // * TransactionInactiveError (not in callback) |
| + // * DataError (invalid key) |
| + cursor.continue({not:"a valid key"}); |
| + }, 'Inactive check should precede key check'); |
| + t.done(); |
| + }), 0); |
| + }); |
| + }, |
| + 'IDBCursor.continue exception order: TransactionInactiveError vs. DataError' |
| +); |
| + |
| +indexeddb_test( |
| + function(t, db) { |
| + var s = db.createObjectStore('s'); |
| + s.put('value', 'key'); |
| + }, |
| + function(t, db) { |
| + var s = db.transaction('s', 'readonly').objectStore('s'); |
| + var r = s.openKeyCursor(); |
| + r.onsuccess = t.step_func(function() { |
| + r.onsuccess = null; |
| + var cursor = r.result; |
| + cursor.continue(); |
| + assert_throws('InvalidStateError', function() { |
| + // Could throw: |
| + // * InvalidStateError (cursor already advancing) |
| + // * DataError (invalid key) |
| + cursor.continue({not:"a valid key"}); |
| + }, 'Inactive check should precede key check'); |
| + t.done(); |
| + }); |
| + }, |
| + 'IDBCursor.continue exception order: InvalidStateError vs. DataError' |
| +); |
| + |
|
pwnall
2016/09/01 19:03:52
Would it also make sense to test TransactionInacti
jsbell
2016/09/01 20:20:46
Done.
|
| +indexeddb_test( |
| + function(t, db) { |
| + var s = db.createObjectStore('s'); |
| + s.put('value', 'key'); |
| + }, |
| + function(t, db) { |
| + var s = db.transaction('s', 'readonly').objectStore('s'); |
| + var r = s.openCursor(); |
| + r.onsuccess = t.step_func(function() { |
| + r.onsuccess = null; |
| + var cursor = r.result; |
| + setTimeout(t.step_func(function() { |
| + assert_throws('TransactionInactiveError', function() { |
| + // Could throw: |
| + // * TransactionInactiveError (not in callback) |
| + // * ReadOnlyError (key cursor) |
| + cursor.delete(); |
| + }, 'Inactive check should precede readonly check'); |
| + t.done(); |
| + }), 0); |
| + }); |
| + }, |
| + 'IDBCursor.delete exception order: TransactionInactiveError vs. ReadOnlyError' |
| +); |
| + |
| +indexeddb_test( |
| + function(t, db) { |
| + var s = db.createObjectStore('s'); |
| + s.put('value', 'key'); |
| + }, |
| + function(t, db) { |
| + var s = db.transaction('s', 'readonly').objectStore('s'); |
| + var r = s.openCursor(); |
| + r.onsuccess = t.step_func(function() { |
| + r.onsuccess = null; |
| + var cursor = r.result; |
| + cursor.continue(); |
| + assert_throws('ReadOnlyError', function() { |
| + // Could throw: |
| + // * ReadOnlyError (read only transaction) |
| + // * InvalidStateError (cursor already advancing) |
|
pwnall
2016/09/01 19:03:52
The spec [1] lists 3 causes that could end up in I
jsbell
2016/09/01 20:20:46
I did 2 of 3 (and ditto for "update"). You can't h
|
| + cursor.delete(); |
| + }, 'State check should precede readonly check'); |
| + t.done(); |
| + }); |
| + }, |
| + 'IDBCursor.delete exception order: ReadOnlyError vs. InvalidStateError' |
| +); |
| + |
| +indexeddb_test( |
| + function(t, db) { |
| + var s = db.createObjectStore('s'); |
| + s.put('value', 'key'); |
| + }, |
| + function(t, db) { |
| + var s = db.transaction('s', 'readonly').objectStore('s'); |
| + var r = s.openCursor(); |
| + r.onsuccess = t.step_func(function() { |
| + r.onsuccess = null; |
| + var cursor = r.result; |
| + setTimeout(t.step_func(function() { |
| + assert_throws('TransactionInactiveError', function() { |
| + // Could throw: |
| + // * TransactionInactiveError (not in callback) |
| + // * ReadOnlyError (key cursor) |
| + cursor.update('value2'); |
| + }, 'Inactive check should precede readonly check'); |
| + t.done(); |
| + }), 0); |
| + }); |
| + }, |
| + 'IDBCursor.update exception order: TransactionInactiveError vs. ReadOnlyError' |
| +); |
| + |
| +indexeddb_test( |
| + function(t, db) { |
| + var s = db.createObjectStore('s'); |
| + s.put('value', 'key'); |
| + }, |
| + function(t, db) { |
| + var s = db.transaction('s', 'readonly').objectStore('s'); |
| + var r = s.openCursor(); |
| + r.onsuccess = t.step_func(function() { |
| + r.onsuccess = null; |
| + var cursor = r.result; |
| + cursor.continue(); |
| + assert_throws('ReadOnlyError', function() { |
| + // Could throw: |
| + // * ReadOnlyError (read only transaction) |
| + // * InvalidStateError (cursor already advancing) |
| + cursor.update('value2'); |
| + }, 'Readonly check should precede got value check'); |
| + t.done(); |
| + }); |
| + }, |
| + 'IDBCursor.update exception order: ReadOnlyError vs. InvalidStateError' |
| +); |
| + |
| +indexeddb_test( |
| + function(t, db) { |
| + var s = db.createObjectStore('s', {keyPath: 'id'}); |
| + s.put({id: 123, data: 'value'}); |
| + }, |
| + function(t, db) { |
| + var s = db.transaction('s', 'readwrite').objectStore('s'); |
| + var r = s.openCursor(); |
| + r.onsuccess = t.step_func(function() { |
| + r.onsuccess = null; |
| + var cursor = r.result; |
| + cursor.continue(); |
| + assert_throws('InvalidStateError', function() { |
| + // Could throw: |
| + // * InvalidStateError (cursor already advancing) |
| + // * DataError (modified key) |
| + cursor.update({id: 123, data: 'value2'}); |
| + }, 'Got value check should precede key check'); |
| + t.done(); |
| + }); |
| + }, |
| + 'IDBCursor.update exception order: InvalidStateError vs. DataError' |
| +); |
| + |
| +</script> |