Revision 95a4dac471e2eb2811555819a623676b597b5997 authored by kritisingh1 on 14 March 2018, 19:47:02 UTC, committed by kritisingh1 on 14 March 2018, 19:47:02 UTC
1 parent 4fa2165
idbobjectstore_getKey.html
<!doctype html>
<meta charset=utf-8>
<title>IndexedDB: Test IDBObjectStore.getKey()</title>
<meta name=timeout content=long>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>
<script>
function getkey_test(func, name) {
indexeddb_test(
function(t, db, tx) {
var basic = db.createObjectStore('basic');
var key_path_store = db.createObjectStore('key path',
{keyPath: 'id'});
var key_generator_store = db.createObjectStore('key generator',
{autoIncrement: true});
var key_generator_and_path_store = db.createObjectStore(
'key generator and key path',
{autoIncrement: true, key_path: 'id'});
for (var i = 1; i <= 10; ++i) {
basic.put('value: ' + i, i);
key_path_store.put({id: i});
key_generator_store.put('value: ' + i);
key_generator_and_path_store.put({});
}
},
func,
name
);
}
getkey_test(function(t, db) {
var tx = db.transaction('basic');
var store = tx.objectStore('basic');
assert_throws(TypeError(), function() { store.getKey(); });
assert_throws({name: 'DataError'}, function() { store.getKey(null); });
assert_throws({name: 'DataError'}, function() { store.getKey({}); });
t.done();
}, 'IDBObjectStore.getKey() - invalid parameters');
[
'basic',
'key path',
'key generator',
'key generator and key path'
].forEach(function(store_name) {
getkey_test(function(t, db) {
var tx = db.transaction(store_name);
var store = tx.objectStore(store_name);
var request = store.getKey(5);
request.onerror = t.unreached_func('request failed');
request.onsuccess = t.step_func(function() {
assert_equals(request.result, 5);
});
tx.onabort = t.unreached_func('transaction aborted');
tx.oncomplete = t.step_func(function() { t.done(); });
}, 'IDBObjectStore.getKey() - ' + store_name + ' - key');
getkey_test(function(t, db) {
var tx = db.transaction(store_name);
var store = tx.objectStore(store_name);
var request = store.getKey(IDBKeyRange.lowerBound(4.5));
request.onerror = t.unreached_func('request failed');
request.onsuccess = t.step_func(function() {
assert_equals(request.result, 5);
});
tx.onabort = t.unreached_func('transaction aborted');
tx.oncomplete = t.step_func(function() { t.done(); });
}, 'IDBObjectStore.getKey() - ' + store_name + ' - range');
getkey_test(function(t, db) {
var tx = db.transaction(store_name);
var store = tx.objectStore(store_name);
var request = store.getKey(11);
request.onerror = t.unreached_func('request failed');
request.onsuccess = t.step_func(function() {
assert_equals(request.result, undefined);
});
tx.onabort = t.unreached_func('transaction aborted');
tx.oncomplete = t.step_func(function() { t.done(); });
}, 'IDBObjectStore.getKey() - ' + store_name + ' - key - no match');
getkey_test(function(t, db) {
var tx = db.transaction(store_name);
var store = tx.objectStore(store_name);
var request = store.getKey(IDBKeyRange.lowerBound(11));
request.onerror = t.unreached_func('request failed');
request.onsuccess = t.step_func(function() {
assert_equals(request.result, undefined);
});
tx.onabort = t.unreached_func('transaction aborted');
tx.oncomplete = t.step_func(function() { t.done(); });
}, 'IDBObjectStore.getKey() - ' + store_name + ' - range - no match');
});
</script>
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...