Skip to content

Commit

Permalink
IndexedDB Auto-Increment Test (web-platform-tests#5152)
Browse files Browse the repository at this point in the history
Test that auto-increment primary keys used in compound indices are handled properly.
  • Loading branch information
ssigwart authored and inexorabletash committed Mar 20, 2017
1 parent 40b8f72 commit 317fa3b
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions IndexedDB/idbobjectstore_createIndex15-autoincrement.htm
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>

0 comments on commit 317fa3b

Please sign in to comment.