Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upstream an assortment of IndexedDB tests to WPT.
BUG=683463 Review-Url: https://codereview.chromium.org/2664623002 Cr-Commit-Position: refs/heads/master@{#447038}
- Loading branch information
Showing
8 changed files
with
311 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<title>IndexedDB: Error attributes are DOMExceptions</title> | ||
<link rel="help" href="https://w3c.github.io/IndexedDB/#idbrequest"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="support.js"></script> | ||
<script> | ||
|
||
indexeddb_test( | ||
function(t, db) { | ||
db.createObjectStore('store'); | ||
}, | ||
function(t, db) { | ||
var tx = db.transaction('store', 'readwrite'); | ||
var store = tx.objectStore('store'); | ||
var r1 = store.add('value', 'key'); | ||
r1.onerror = t.unreached_func('first add should succeed'); | ||
|
||
var r2 = store.add('value', 'key'); | ||
r2.onsuccess = t.unreached_func('second add should fail'); | ||
|
||
r2.onerror = t.step_func(function() { | ||
assert_true(r2.error instanceof DOMException); | ||
assert_equals(r2.error.name, 'ConstraintError'); | ||
}); | ||
|
||
tx.oncomplete = t.unreached_func('transaction should not complete'); | ||
tx.onabort = t.step_func(function() { | ||
assert_true(tx.error instanceof DOMException); | ||
assert_equals(tx.error.name, 'ConstraintError'); | ||
t.done(); | ||
}); | ||
}, | ||
'IDBRequest and IDBTransaction error properties should be DOMExceptions' | ||
); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<title>IndexedDB: IDBCursor advance() Exception Ordering</title> | ||
<link rel="help" href="https://w3c.github.io/IndexedDB/#dom-idbcursor-advance"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="support.js"></script> | ||
<script> | ||
|
||
indexeddb_test( | ||
(t, db) => { | ||
const store = db.createObjectStore('s'); | ||
store.put('value', 'key'); | ||
}, | ||
(t, db) => { | ||
const tx = db.transaction('s'); | ||
const store = tx.objectStore('s'); | ||
|
||
const r = store.openKeyCursor(); | ||
r.onsuccess = t.step_func(() => { | ||
r.onsuccess = null; | ||
|
||
const cursor = r.result; | ||
|
||
setTimeout(t.step_func(() => { | ||
assert_throws(new TypeError, () => { cursor.advance(0); }, | ||
'"zero" check (TypeError) should precede ' + | ||
'"not active" check (TransactionInactiveError)'); | ||
t.done(); | ||
}), 0); | ||
}); | ||
}, | ||
'IDBCursor.advance exception order: TypeError vs. TransactionInactiveError' | ||
); | ||
|
||
indexeddb_test( | ||
(t, db) => { | ||
const store = db.createObjectStore('s'); | ||
|
||
const s = db.createObjectStore('s2'); | ||
s.put('value', 'key'); | ||
|
||
const r = s.openKeyCursor(); | ||
r.onsuccess = t.step_func(() => { | ||
r.onsuccess = null; | ||
|
||
const cursor = r.result; | ||
db.deleteObjectStore('s2'); | ||
|
||
setTimeout(t.step_func(() => { | ||
assert_throws('TransactionInactiveError', () => { cursor.advance(1); }, | ||
'"not active" check (TransactionInactiveError) ' + | ||
'should precede "deleted" check (InvalidStateError)'); | ||
t.done(); | ||
}), 0); | ||
}); | ||
}, | ||
(t, db) => {}, | ||
'IDBCursor.advance exception order: ' + | ||
'TransactionInactiveError vs. InvalidStateError #1' | ||
); | ||
|
||
indexeddb_test( | ||
(t, db) => { | ||
const store = db.createObjectStore('s'); | ||
store.put('value', 'key'); | ||
}, | ||
(t, db) => { | ||
const tx = db.transaction('s'); | ||
const store = tx.objectStore('s'); | ||
|
||
const r = store.openKeyCursor(); | ||
r.onsuccess = t.step_func(() => { | ||
r.onsuccess = null; | ||
|
||
const cursor = r.result; | ||
cursor.advance(1); | ||
|
||
setTimeout(t.step_func(() => { | ||
assert_throws('TransactionInactiveError', () => { cursor.advance(1); }, | ||
'"not active" check (TransactionInactiveError) ' + | ||
'should precede "got value" check (InvalidStateError)'); | ||
t.done(); | ||
}), 0); | ||
}); | ||
}, | ||
'IDBCursor.advance exception order: ' + | ||
'TransactionInactiveError vs. InvalidStateError #2' | ||
); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<title>IndexedDB: IDBIndex getAll() uses [EnforceRange]</title> | ||
<link rel="help" href="https://w3c.github.io/IndexedDB/#index-interface"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="support.js"></script> | ||
<script> | ||
|
||
indexeddb_test( | ||
(t, db) => { | ||
const store = db.createObjectStore('store'); | ||
const index = store.createIndex('index', 'keyPath'); | ||
}, | ||
(t, db) => { | ||
const tx = db.transaction('store'); | ||
const store = tx.objectStore('store'); | ||
const index = store.index('index'); | ||
[NaN, Infinity, -Infinity, -1, -Number.MAX_SAFE_INTEGER].forEach(count => { | ||
assert_throws(TypeError(), () => { index.getAll(null, count); }, | ||
`getAll with count ${count} count should throw TypeError`); | ||
}); | ||
t.done(); | ||
}, | ||
`IDBIndex.getAll() uses [EnforceRange]` | ||
); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<title>IndexedDB: IDBIndex getAllKeys() uses [EnforceRange]</title> | ||
<link rel="help" href="https://w3c.github.io/IndexedDB/#index-interface"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="support.js"></script> | ||
<script> | ||
|
||
indexeddb_test( | ||
(t, db) => { | ||
const store = db.createObjectStore('store'); | ||
const index = store.createIndex('index', 'keyPath'); | ||
}, | ||
(t, db) => { | ||
const tx = db.transaction('store'); | ||
const store = tx.objectStore('store'); | ||
const index = store.index('index'); | ||
[NaN, Infinity, -Infinity, -1, -Number.MAX_SAFE_INTEGER].forEach(count => { | ||
assert_throws(TypeError(), () => { index.getAllKeys(null, count); }, | ||
`getAllKeys with count ${count} count should throw TypeError`); | ||
}); | ||
t.done(); | ||
}, | ||
`IDBIndex.getAllKeys() uses [EnforceRange]` | ||
); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<title>IndexedDB: IDBObjectStore getAll() uses [EnforceRange]</title> | ||
<link rel="help" href="https://w3c.github.io/IndexedDB/#object-store-interface"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="support.js"></script> | ||
<script> | ||
|
||
indexeddb_test( | ||
(t, db) => { | ||
const store = db.createObjectStore('store'); | ||
}, | ||
(t, db) => { | ||
const tx = db.transaction('store'); | ||
const store = tx.objectStore('store'); | ||
[NaN, Infinity, -Infinity, -1, -Number.MAX_SAFE_INTEGER].forEach(count => { | ||
assert_throws(TypeError(), () => { store.getAll(null, count); }, | ||
`getAll with count ${count} count should throw TypeError`); | ||
}); | ||
t.done(); | ||
}, | ||
`IDBObjectStore.getAll() uses [EnforceRange]` | ||
); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<title>IndexedDB: IDBIObjectStore getAllKeys() uses [EnforceRange]</title> | ||
<link rel="help" href="https://w3c.github.io/IndexedDB/#object-store-interface"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="support.js"></script> | ||
<script> | ||
|
||
indexeddb_test( | ||
(t, db) => { | ||
const store = db.createObjectStore('store'); | ||
}, | ||
(t, db) => { | ||
const tx = db.transaction('store'); | ||
const store = tx.objectStore('store'); | ||
[NaN, Infinity, -Infinity, -1, -Number.MAX_SAFE_INTEGER].forEach(count => { | ||
assert_throws(TypeError(), () => { store.getAllKeys(null, count); }, | ||
`getAllKeys with count ${count} count should throw TypeError`); | ||
}); | ||
t.done(); | ||
}, | ||
`IDBObjectStore.getAllKeys() uses [EnforceRange]` | ||
); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<!doctype html> | ||
<meta charset=utf-8> | ||
<title>IndexedDB: open and delete requests are processed as a FIFO queue</title> | ||
<link rel="help" href="https://w3c.github.io/IndexedDB/#request-connection-queue"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="support.js"></script> | ||
<script> | ||
|
||
async_test(t => { | ||
let db_name = 'db' + self.location.pathname + '-' + t.name; | ||
indexedDB.deleteDatabase(db_name); | ||
|
||
// Open and hold connection while other requests are queued up. | ||
let r = indexedDB.open(db_name, 1); | ||
r.onerror = t.unreached_func('open should succeed'); | ||
r.onsuccess = t.step_func(e => { | ||
let db = r.result; | ||
|
||
let saw = expect(t, [ | ||
'open1 success', | ||
'open1 versionchange', | ||
'delete1 blocked', | ||
'delete1 success', | ||
'open2 success', | ||
'open2 versionchange', | ||
'delete2 blocked', | ||
'delete2 success' | ||
]); | ||
|
||
function open(token, version) { | ||
let r = indexedDB.open(db_name, version); | ||
r.onsuccess = t.step_func(e => { | ||
saw(token + ' success'); | ||
let db = r.result; | ||
db.onversionchange = t.step_func(e => { | ||
saw(token + ' versionchange'); | ||
setTimeout(t.step_func(() => db.close()), 0); | ||
}); | ||
}); | ||
r.onblocked = t.step_func(e => saw(token + ' blocked')); | ||
r.onerror = t.unreached_func('open should succeed'); | ||
} | ||
|
||
function deleteDatabase(token) { | ||
let r = indexedDB.deleteDatabase(db_name); | ||
r.onsuccess = t.step_func(e => saw(token + ' success')); | ||
r.onblocked = t.step_func(e => saw(token + ' blocked')); | ||
r.onerror = t.unreached_func('deleteDatabase should succeed'); | ||
} | ||
|
||
open('open1', 2); | ||
deleteDatabase('delete1'); | ||
open('open2', 3); | ||
deleteDatabase('delete2'); | ||
|
||
// Now unblock the queue. | ||
db.close(); | ||
}); | ||
|
||
}, 'Opens and deletes are processed in order'); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters