forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IndexedDB Auto-Increment Test (web-platform-tests#5152)
Test that auto-increment primary keys used in compound indices are handled properly.
- Loading branch information
1 parent
40b8f72
commit 317fa3b
Showing
1 changed file
with
52 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,52 @@ | ||
<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<title>IDBObjectStore.createIndex() - AutoIncrement in Compound Index</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="support.js"></script> | ||
<script> | ||
indexeddb_test( | ||
function(t, db, txn) { | ||
// No auto-increment | ||
var store = db.createObjectStore("Store1", {keyPath: "id"}); | ||
store.createIndex("CompoundKey", ["num", "id"]); | ||
|
||
// Add data | ||
store.put({id: 1, num: 100}); | ||
}, | ||
function(t, db) { | ||
var store = db.transaction("Store1", "readwrite").objectStore("Store1"); | ||
|
||
store.openCursor().onsuccess = t.step_func(function(e) { | ||
var item = event.target.result.value; | ||
store.index("CompoundKey").get([item.num, item.id]).onsuccess = t.step_func(function(e) { | ||
assert_equals(e.target.result ? e.target.result.num : null, 100, 'Expected 100.'); | ||
t.done(); | ||
}); | ||
}); | ||
}, | ||
"Explicit Primary Key" | ||
); | ||
|
||
indexeddb_test( | ||
function(t, db, txn) { | ||
// Auto-increment | ||
var store = db.createObjectStore("Store2", {keyPath: "id", autoIncrement: true}); | ||
store.createIndex("CompoundKey", ["num", "id"]); | ||
|
||
// Add data | ||
store.put({num: 100}); | ||
}, | ||
function(t, db) { | ||
var store = db.transaction("Store2", "readwrite").objectStore("Store2"); | ||
store.openCursor().onsuccess = t.step_func(function(e) { | ||
var item = event.target.result.value; | ||
store.index("CompoundKey").get([item.num, item.id]).onsuccess = t.step_func(function(e) { | ||
assert_equals(e.target.result ? e.target.result.num : null, 100, 'Expected 100.'); | ||
t.done(); | ||
}); | ||
}); | ||
}, | ||
"Auto-Increment Primary Key" | ||
); | ||
</script> |