idbobjectstore_add4.htm
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
<title> IDBObjectStore.add() - add where an index has unique:true specified </title>
<script type="text/javascript" src="support.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script type="text/javascript">
var objectStoreName = "objectstore";
var record = {indexedProperty:"data"};
var db = null;
var t = async_test();
function RunTest() {
var rqOpen = window.indexedDB.open(databaseName, databaseVersion);
rqOpen.onupgradeneeded = t.step_func(function(event) {
db = event.target.result;
db.onerror = t.step_func(assert_database_error);
var objStore = db.createObjectStore(objectStoreName, {autoIncrement:true});
objStore.createIndex("i1", "indexedProperty", {unique:true});
objStore.add(record);
var rqAdd = objStore.add(record);
rqAdd.onsuccess = t.step_func( function(event) { assert_unexpected_success(event); });
rqAdd.onerror = t.step_func(function(event) {
event.stopPropagation();
event.preventDefault();
assert_equals(event.target.error.name, "ConstraintError", 'event.target.error.name');
t.done();
});
});
rqOpen.onerror = t.step_func(assert_open_request_error);
}
add_completion_callback(function() { if(db) db.close(); });
setup(function() {
var rqDelete = window.indexedDB.deleteDatabase(databaseName);
rqDelete.onsuccess = t.step_func( RunTest );
});
</script>
</head>
<body>
<div id="log"></div>
</body>
</html>