mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
Update web-platform-tests to revision 5a754b40cd49c0404863c431b58cc311dc5d167c
This commit is contained in:
parent
8950345e0e
commit
32efe41299
107 changed files with 4243 additions and 435 deletions
232
tests/wpt/web-platform-tests/IndexedDB/idbindex_getAll.html
Normal file
232
tests/wpt/web-platform-tests/IndexedDB/idbindex_getAll.html
Normal file
|
@ -0,0 +1,232 @@
|
|||
<!DOCTYPE html>
|
||||
<title>IndexedDB: Test IDBIndex.getAll.</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
setup({explicit_done: true});
|
||||
|
||||
var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
|
||||
var ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
|
||||
|
||||
function doSetup(dbName, dbVersion, onsuccess) {
|
||||
var delete_request = indexedDB.deleteDatabase(dbName);
|
||||
delete_request.onerror = function() {
|
||||
assert_unreached('deleteDatabase should not fail');
|
||||
};
|
||||
delete_request.onsuccess = function(e) {
|
||||
var req = indexedDB.open(dbName, dbVersion);
|
||||
req.onsuccess = onsuccess;
|
||||
req.onerror = function() {
|
||||
assert_unreached('open should not fail');
|
||||
};
|
||||
req.onupgradeneeded = function(evt) {
|
||||
var connection = evt.target.result;
|
||||
|
||||
var store = connection.createObjectStore('generated',
|
||||
{autoIncrement: true, keyPath: 'id'});
|
||||
var index = store.createIndex('test_idx', 'upper');
|
||||
alphabet.forEach(function(letter) {
|
||||
store.put({ch: letter, upper: letter.toUpperCase()});
|
||||
});
|
||||
|
||||
store = connection.createObjectStore('out-of-line', null);
|
||||
index = store.createIndex('test_idx', 'upper');
|
||||
alphabet.forEach(function(letter) {
|
||||
store.put({ch: letter, upper: letter.toUpperCase()}, letter);
|
||||
});
|
||||
|
||||
store = connection.createObjectStore('out-of-line-not-unique', null);
|
||||
index = store.createIndex('test_idx', 'half');
|
||||
alphabet.forEach(function(letter) {
|
||||
if (letter <= 'm')
|
||||
store.put({ch: letter, half: 'first'}, letter);
|
||||
else
|
||||
store.put({ch: letter, half: 'second'}, letter);
|
||||
});
|
||||
|
||||
store = connection.createObjectStore('out-of-line-multi', null);
|
||||
index = store.createIndex('test_idx', 'attribs', {multiEntry: true});
|
||||
alphabet.forEach(function(letter) {
|
||||
attrs = [];
|
||||
if (['a', 'e', 'i', 'o', 'u'].indexOf(letter) != -1)
|
||||
attrs.push('vowel');
|
||||
else
|
||||
attrs.push('consonant');
|
||||
if (letter == 'a')
|
||||
attrs.push('first');
|
||||
if (letter == 'z')
|
||||
attrs.push('last');
|
||||
store.put({ch: letter, attribs: attrs}, letter);
|
||||
});
|
||||
|
||||
store = connection.createObjectStore('empty', null);
|
||||
index = store.createIndex('test_idx', 'upper');
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function createGetAllRequest(t, storeName, connection, range, maxCount) {
|
||||
var transaction = connection.transaction(storeName, 'readonly');
|
||||
var store = transaction.objectStore(storeName);
|
||||
var index = store.index('test_idx');
|
||||
var req = index.getAll(range, maxCount);
|
||||
req.onerror = t.unreached_func('getAll request should succeed');
|
||||
return req;
|
||||
}
|
||||
|
||||
doSetup(location.pathname + '-IDBIndex.getAll', 1, function(evt) {
|
||||
var connection = evt.target.result;
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection, 'C');
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_class_string(data, 'Array', 'result should be an array');
|
||||
assert_array_equals(data.map(function(e) { return e.ch; }), ['c']);
|
||||
assert_array_equals(data.map(function(e) { return e.upper; }), ['C']);
|
||||
t.done();
|
||||
});
|
||||
}, 'Single item get');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'empty', connection);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, [],
|
||||
'getAll() on empty object store should return an empty array');
|
||||
t.done();
|
||||
});
|
||||
}, 'Empty object store');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_class_string(data, 'Array', 'result should be an array');
|
||||
assert_array_equals(data.map(function(e) { return e.ch; }), alphabet);
|
||||
assert_array_equals(data.map(function(e) { return e.upper; }), ALPHABET);
|
||||
t.done();
|
||||
});
|
||||
}, 'Get all keys');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection, undefined,
|
||||
10);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_class_string(data, 'Array', 'result should be an array');
|
||||
assert_array_equals(data.map(function(e) { return e.ch; }), 'abcdefghij'.split(''));
|
||||
assert_array_equals(data.map(function(e) { return e.upper; }), 'ABCDEFGHIJ'.split(''));
|
||||
t.done();
|
||||
});
|
||||
}, 'maxCount=10');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('G', 'M'));
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_array_equals(data.map(function(e) { return e.ch; }), 'ghijklm'.split(''));
|
||||
assert_array_equals(data.map(function(e) { return e.upper; }), 'GHIJKLM'.split(''));
|
||||
t.done();
|
||||
});
|
||||
}, 'Get bound range');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('G', 'M'), 3);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_class_string(data, 'Array', 'result should be an array');
|
||||
assert_array_equals(data.map(function(e) { return e.ch; }), 'ghi'.split(''));
|
||||
assert_array_equals(data.map(function(e) { return e.upper; }), 'GHI'.split(''));
|
||||
t.done();
|
||||
});
|
||||
}, 'Get bound range with maxCount');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('G', 'K', false, true));
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_class_string(data, 'Array', 'result should be an array');
|
||||
assert_array_equals(data.map(function(e) { return e.ch; }), 'ghij'.split(''));
|
||||
assert_array_equals(data.map(function(e) { return e.upper; }), 'GHIJ'.split(''));
|
||||
t.done();
|
||||
});
|
||||
}, 'Get upper excluded');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('G', 'K', true, false));
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_class_string(data, 'Array', 'result should be an array');
|
||||
assert_array_equals(data.map(function(e) { return e.ch; }), 'hijk'.split(''));
|
||||
assert_array_equals(data.map(function(e) { return e.upper; }), 'HIJK'.split(''));
|
||||
t.done();
|
||||
});
|
||||
}, 'Get lower excluded');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'generated',
|
||||
connection, IDBKeyRange.bound(4, 15), 3);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_true(Array.isArray(data));
|
||||
assert_equals(data.length, 0);
|
||||
t.done();
|
||||
});
|
||||
}, 'Get bound range (generated) with maxCount');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line',
|
||||
connection, "Doesn't exist");
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, [],
|
||||
'getAll() using a nonexistent key should return an empty array');
|
||||
t.done();
|
||||
req.onerror = t.unreached_func('getAll request should succeed');
|
||||
});
|
||||
}, 'Non existent key');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection,
|
||||
undefined, 0);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_class_string(data, 'Array', 'result should be an array');
|
||||
assert_array_equals(data.map(function(e) { return e.ch; }), alphabet);
|
||||
assert_array_equals(data.map(function(e) { return e.upper; }), ALPHABET);
|
||||
t.done();
|
||||
});
|
||||
}, 'maxCount=0');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line-not-unique', connection,
|
||||
'first');
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_class_string(data, 'Array', 'result should be an array');
|
||||
assert_array_equals(data.map(function(e) { return e.ch; }), 'abcdefghijklm'.split(''));
|
||||
assert_true(data.every(function(e) { return e.half === 'first'; }));
|
||||
t.done();
|
||||
});
|
||||
}, 'Retrieve multiEntry key');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line-multi', connection,
|
||||
'vowel');
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_class_string(data, 'Array', 'result should be an array');
|
||||
assert_array_equals(data.map(function(e) { return e.ch; }), ['a', 'e', 'i', 'o', 'u']);
|
||||
assert_array_equals(data[0].attribs, ['vowel', 'first']);
|
||||
assert_true(data.every(function(e) { return e.attribs[0] === 'vowel'; }));
|
||||
t.done();
|
||||
});
|
||||
}, 'Retrieve one key multiple values');
|
||||
|
||||
// Explicit done needed in case async_test body fails synchronously.
|
||||
done();
|
||||
});
|
||||
|
||||
</script>
|
207
tests/wpt/web-platform-tests/IndexedDB/idbindex_getAllKeys.html
Normal file
207
tests/wpt/web-platform-tests/IndexedDB/idbindex_getAllKeys.html
Normal file
|
@ -0,0 +1,207 @@
|
|||
<!DOCTYPE html>
|
||||
<title>IndexedDB: Test IDBIndex.getAllKeys.</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
setup({explicit_done: true});
|
||||
|
||||
var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
|
||||
|
||||
function doSetup(dbName, dbVersion, onsuccess) {
|
||||
var delete_request = indexedDB.deleteDatabase(dbName);
|
||||
delete_request.onerror = function() {
|
||||
assert_unreached('deleteDatabase should not fail');
|
||||
};
|
||||
delete_request.onsuccess = function(e) {
|
||||
var req = indexedDB.open(dbName, dbVersion);
|
||||
req.onsuccess = onsuccess;
|
||||
req.onerror = function() {
|
||||
assert_unreached('open should not fail');
|
||||
};
|
||||
req.onupgradeneeded = function(evt) {
|
||||
var connection = evt.target.result;
|
||||
|
||||
var store = connection.createObjectStore('generated',
|
||||
{autoIncrement: true, keyPath: 'id'});
|
||||
var index = store.createIndex('test_idx', 'upper');
|
||||
alphabet.forEach(function(letter) {
|
||||
store.put({ch: letter, upper: letter.toUpperCase()});
|
||||
});
|
||||
|
||||
store = connection.createObjectStore('out-of-line', null);
|
||||
index = store.createIndex('test_idx', 'upper');
|
||||
alphabet.forEach(function(letter) {
|
||||
store.put({ch: letter, upper: letter.toUpperCase()}, letter);
|
||||
});
|
||||
|
||||
store = connection.createObjectStore('out-of-line-multi', null);
|
||||
index = store.createIndex('test_idx', 'attribs', {multiEntry: true});
|
||||
alphabet.forEach(function(letter) {
|
||||
attrs = [];
|
||||
if (['a', 'e', 'i', 'o', 'u'].indexOf(letter) != -1)
|
||||
attrs.push('vowel');
|
||||
else
|
||||
attrs.push('consonant');
|
||||
if (letter == 'a')
|
||||
attrs.push('first');
|
||||
if (letter == 'z')
|
||||
attrs.push('last');
|
||||
store.put({ch: letter, attribs: attrs}, letter.toUpperCase());
|
||||
});
|
||||
|
||||
store = connection.createObjectStore('empty', null);
|
||||
index = store.createIndex('test_idx', 'upper');
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function createGetAllKeysRequest(t, storeName, connection, range, maxCount) {
|
||||
var transaction = connection.transaction(storeName, 'readonly');
|
||||
var store = transaction.objectStore(storeName);
|
||||
var index = store.index('test_idx');
|
||||
var req = index.getAllKeys(range, maxCount);
|
||||
req.onerror = t.unreached_func('getAllKeys request should succeed');
|
||||
return req;
|
||||
}
|
||||
|
||||
doSetup(location.pathname + '-IDBIndex.getAllKeys', 1, function(evt) {
|
||||
var connection = evt.target.result;
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection, 'C');
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_array_equals(evt.target.result, ['c']);
|
||||
t.done();
|
||||
});
|
||||
}, 'Single item get');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'empty', connection);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, [],
|
||||
'getAllKeys() on empty object store should return empty array');
|
||||
t.done();
|
||||
});
|
||||
}, 'Empty object store');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, alphabet,
|
||||
'getAllKeys() should return a..z');
|
||||
t.done();
|
||||
});
|
||||
}, 'Get all keys');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'generated', connection);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result,
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
||||
19, 20, 21, 22, 23, 24, 25, 26],
|
||||
'getAllKeys() should return 1..26');
|
||||
t.done();
|
||||
});
|
||||
}, 'Get all generated keys');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection, undefined,
|
||||
10);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result,
|
||||
'abcdefghij'.split(''),
|
||||
'getAllKeys() should return a..j');
|
||||
t.done();
|
||||
});
|
||||
}, 'maxCount=10');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('G', 'M'));
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result,
|
||||
'ghijklm'.split(''),
|
||||
'getAllKeys() should return g..m');
|
||||
t.done();
|
||||
});
|
||||
}, 'Get bound range');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('G', 'M'), 3);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result,
|
||||
['g', 'h', 'i'],
|
||||
'getAllKeys() should return g..i');
|
||||
t.done();
|
||||
});
|
||||
}, 'Get bound range with maxCount');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('G', 'K', false, true));
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result,
|
||||
['g', 'h', 'i', 'j'],
|
||||
'getAllKeys() should return g..j');
|
||||
t.done();
|
||||
});
|
||||
}, 'Get upper excluded');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('G', 'K', true, false));
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result,
|
||||
['h', 'i', 'j', 'k'],
|
||||
'getAllKeys() should return h..k');
|
||||
t.done();
|
||||
});
|
||||
}, 'Get lower excluded');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'generated',
|
||||
connection, IDBKeyRange.bound(4, 15), 3);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, [],
|
||||
'getAllKeys() should return []');
|
||||
t.done();
|
||||
});
|
||||
}, 'Get bound range (generated) with maxCount');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line',
|
||||
connection, "Doesn't exist");
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, [],
|
||||
'getAllKeys() using a nonexistent key should return empty array');
|
||||
t.done();
|
||||
req.onerror = t.unreached_func('getAllKeys request should succeed');
|
||||
});
|
||||
}, 'Non existent key');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection,
|
||||
undefined, 0);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, alphabet,
|
||||
'getAllKeys() should return a..z');
|
||||
t.done();
|
||||
});
|
||||
}, 'maxCount=0');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line-multi', connection,
|
||||
'vowel');
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, ['A','E','I','O','U'])
|
||||
t.done();
|
||||
});
|
||||
req.onerror = t.unreached_func('getAllKeys request should succeed');
|
||||
}, 'Retrieve multiEntry keys');
|
||||
|
||||
// Explicit done needed in case async_test body fails synchronously.
|
||||
done();
|
||||
});
|
||||
|
||||
</script>
|
|
@ -0,0 +1,174 @@
|
|||
<!DOCTYPE html>
|
||||
<title>IndexedDB: Test IDBObjectStore.getAll.</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
setup({explicit_done: true});
|
||||
|
||||
var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
|
||||
|
||||
function doSetup(dbName, dbVersion, onsuccess) {
|
||||
var delete_request = indexedDB.deleteDatabase(dbName);
|
||||
delete_request.onerror = function() {
|
||||
assert_unreached('deleteDatabase should not fail');
|
||||
};
|
||||
delete_request.onsuccess = function(e) {
|
||||
var req = indexedDB.open(dbName, dbVersion);
|
||||
req.onsuccess = onsuccess;
|
||||
req.onerror = function() {
|
||||
assert_unreached('open should not fail');
|
||||
};
|
||||
req.onupgradeneeded = function(evt) {
|
||||
var connection = evt.target.result;
|
||||
|
||||
var store = connection.createObjectStore('generated',
|
||||
{autoIncrement: true, keyPath: 'id'});
|
||||
alphabet.forEach(function(letter) {
|
||||
store.put({ch: letter});
|
||||
});
|
||||
|
||||
store = connection.createObjectStore('out-of-line', null);
|
||||
alphabet.forEach(function(letter) {
|
||||
store.put('value-' + letter, letter);
|
||||
});
|
||||
|
||||
store = connection.createObjectStore('empty', null);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function createGetAllRequest(t, storeName, connection, range, maxCount) {
|
||||
var transaction = connection.transaction(storeName, 'readonly');
|
||||
var store = transaction.objectStore(storeName);
|
||||
var req = store.getAll(range, maxCount);
|
||||
req.onerror = t.unreached_func('getAll request should succeed');
|
||||
return req;
|
||||
}
|
||||
|
||||
doSetup(location.pathname + '-IDBObjectStore.getAll', 1, function(evt) {
|
||||
var connection = evt.target.result;
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection, 'c');
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, ['value-c']);
|
||||
t.done();
|
||||
});
|
||||
}, 'Single item get');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'generated', connection, 3);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_true(Array.isArray(data));
|
||||
assert_equals(data.length, 1);
|
||||
assert_equals(data[0].id, 3);
|
||||
assert_equals(data[0].ch, 'c');
|
||||
t.done();
|
||||
});
|
||||
}, 'Single item get (generated key)');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'empty', connection);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, [],
|
||||
'getAll() on empty object store should return an empty array');
|
||||
t.done();
|
||||
});
|
||||
}, 'getAll on empty object store');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result,
|
||||
alphabet.map(function(c) { return 'value-' + c; }));
|
||||
t.done();
|
||||
});
|
||||
}, 'Get all values');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection, undefined,
|
||||
10);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result,
|
||||
'abcdefghij'.split('').map(function(c) { return 'value-' + c; }));
|
||||
t.done();
|
||||
});
|
||||
}, 'Test maxCount');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('g', 'm'));
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result,
|
||||
'ghijklm'.split('').map(function(c) { return 'value-' + c; }));
|
||||
t.done();
|
||||
});
|
||||
}, 'Get bound range');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('g', 'm'), 3);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, ['g', 'h', 'i']
|
||||
.map(function(c) { return 'value-' + c; }));
|
||||
t.done();
|
||||
});
|
||||
}, 'Get bound range with maxCount');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('g', 'k', false, true));
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, ['g', 'h', 'i', 'j']
|
||||
.map(function(c) { return 'value-' + c; }));
|
||||
t.done();
|
||||
});
|
||||
}, 'Get upper excluded');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('g', 'k', true, false));
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, ['h', 'i', 'j', 'k']
|
||||
.map(function(c) { return 'value-' + c; }));
|
||||
t.done();
|
||||
});
|
||||
}, 'Get lower excluded');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'generated', connection,
|
||||
IDBKeyRange.bound(4, 15), 3);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_true(Array.isArray(data));
|
||||
assert_array_equals(data.map(function(e) { return e.ch; }), ['d', 'e', 'f']);
|
||||
assert_array_equals(data.map(function(e) { return e.id; }), [4, 5, 6]);
|
||||
t.done();
|
||||
});
|
||||
}, 'Get bound range (generated) with maxCount');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection,
|
||||
"Doesn't exist");
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, [],
|
||||
'getAll() using a nonexistent key should return an empty array');
|
||||
t.done();
|
||||
});
|
||||
req.onerror = t.unreached_func('getAll request should succeed');
|
||||
}, 'Non existent key');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllRequest(t, 'out-of-line', connection, undefined, 0);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result,
|
||||
alphabet.map(function(c) { return 'value-' + c; }));
|
||||
t.done();
|
||||
});
|
||||
}, 'zero maxCount');
|
||||
|
||||
// Explicit done needed in case async_test body fails synchronously.
|
||||
done();
|
||||
});
|
||||
|
||||
</script>
|
|
@ -0,0 +1,167 @@
|
|||
<!DOCTYPE html>
|
||||
<title>IndexedDB: Test IDBObjectStore.getAllKeys.</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
setup({explicit_done: true});
|
||||
|
||||
var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split('');
|
||||
|
||||
function doSetup(dbName, dbVersion, onsuccess) {
|
||||
var delete_request = indexedDB.deleteDatabase(dbName);
|
||||
delete_request.onerror = function() {
|
||||
assert_unreached('deleteDatabase should not fail');
|
||||
};
|
||||
delete_request.onsuccess = function(e) {
|
||||
var req = indexedDB.open(dbName, dbVersion);
|
||||
req.onsuccess = onsuccess;
|
||||
req.onerror = function() {
|
||||
assert_unreached('open should not fail');
|
||||
};
|
||||
req.onupgradeneeded = function(evt) {
|
||||
var connection = evt.target.result;
|
||||
|
||||
var store = connection.createObjectStore('generated',
|
||||
{autoIncrement: true, keyPath: 'id'});
|
||||
alphabet.forEach(function(letter) {
|
||||
store.put({ch: letter});
|
||||
});
|
||||
|
||||
store = connection.createObjectStore('out-of-line', null);
|
||||
alphabet.forEach(function(letter) {
|
||||
store.put('value-' + letter, letter);
|
||||
});
|
||||
|
||||
store = connection.createObjectStore('empty', null);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function createGetAllKeysRequest(t, storeName, connection, range, maxCount) {
|
||||
var transaction = connection.transaction(storeName, 'readonly');
|
||||
var store = transaction.objectStore(storeName);
|
||||
var req = store.getAllKeys(range, maxCount);
|
||||
req.onerror = t.unreached_func('getAllKeys request should succeed');
|
||||
return req;
|
||||
}
|
||||
|
||||
doSetup(location.pathname + '-IDBObjectStore.getAllKeys', 1, function(evt) {
|
||||
var connection = evt.target.result;
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection, 'c');
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, ['c']);
|
||||
t.done();
|
||||
});
|
||||
}, 'Single item get');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'generated', connection, 3);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_true(Array.isArray(data));
|
||||
assert_array_equals(data, [3]);
|
||||
t.done();
|
||||
});
|
||||
}, 'Single item get (generated key)');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'empty', connection);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, [],
|
||||
'getAllKeys() on empty object store should return an empty ' +
|
||||
'array');
|
||||
t.done();
|
||||
});
|
||||
}, 'getAllKeys on empty object store');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, alphabet);
|
||||
t.done();
|
||||
});
|
||||
}, 'Get all values');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection, undefined,
|
||||
10);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, 'abcdefghij'.split(''));
|
||||
t.done();
|
||||
});
|
||||
}, 'Test maxCount');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('g', 'm'));
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, 'ghijklm'.split(''));
|
||||
t.done();
|
||||
});
|
||||
}, 'Get bound range');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('g', 'm'), 3);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, ['g', 'h', 'i']);
|
||||
t.done();
|
||||
});
|
||||
}, 'Get bound range with maxCount');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('g', 'k', false, true));
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, ['g', 'h', 'i', 'j']);
|
||||
t.done();
|
||||
});
|
||||
}, 'Get upper excluded');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection,
|
||||
IDBKeyRange.bound('g', 'k', true, false));
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, ['h', 'i', 'j', 'k']);
|
||||
t.done();
|
||||
});
|
||||
}, 'Get lower excluded');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'generated', connection,
|
||||
IDBKeyRange.bound(4, 15), 3);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
var data = evt.target.result;
|
||||
assert_true(Array.isArray(data));
|
||||
assert_array_equals(data, [4, 5, 6]);
|
||||
t.done();
|
||||
});
|
||||
}, 'Get bound range (generated) with maxCount');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection,
|
||||
"Doesn't exist");
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, [],
|
||||
'getAllKeys() using a nonexistent key should return an ' +
|
||||
'empty array');
|
||||
t.done();
|
||||
});
|
||||
req.onerror = t.unreached_func('getAllKeys request should succeed');
|
||||
}, 'Non existent key');
|
||||
|
||||
async_test(function(t) {
|
||||
var req = createGetAllKeysRequest(t, 'out-of-line', connection, undefined,
|
||||
0);
|
||||
req.onsuccess = t.step_func(function(evt) {
|
||||
assert_array_equals(evt.target.result, alphabet);
|
||||
t.done();
|
||||
});
|
||||
}, 'zero maxCount');
|
||||
|
||||
// Explicit done needed in case async_test body fails synchronously.
|
||||
done();
|
||||
});
|
||||
|
||||
</script>
|
|
@ -0,0 +1,182 @@
|
|||
<!DOCTYPE html>
|
||||
<title>IndexedDB: IDBTransaction.objectStoreNames attribute</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
|
||||
function indexeddb_test(upgrade_func, open_func, description) {
|
||||
async_test(function(t) {
|
||||
var dbname = document.location + '-' + t.name;
|
||||
var del = indexedDB.deleteDatabase(dbname);
|
||||
del.onerror = t.unreached_func('deleteDatabase should succeed');
|
||||
var open = indexedDB.open(dbname, 1);
|
||||
open.onerror = t.unreached_func('open should succeed');
|
||||
open.onupgradeneeded = t.step_func(function() {
|
||||
var db = open.result;
|
||||
var tx = open.transaction;
|
||||
upgrade_func(t, db, tx);
|
||||
});
|
||||
open.onsuccess = t.step_func(function() {
|
||||
var db = open.result;
|
||||
open_func(t, db);
|
||||
});
|
||||
}, description);
|
||||
}
|
||||
|
||||
function with_stores_test(store_names, open_func, description) {
|
||||
indexeddb_test(function(t, db, tx) {
|
||||
store_names.forEach(function(name) {
|
||||
db.createObjectStore(name);
|
||||
});
|
||||
}, open_func, description);
|
||||
}
|
||||
|
||||
indexeddb_test(function(t, db, tx) {
|
||||
assert_array_equals(tx.objectStoreNames, [],
|
||||
'transaction objectStoreNames should be empty');
|
||||
assert_array_equals(db.objectStoreNames, tx.objectStoreNames,
|
||||
'connection and transacton objectStoreNames should match');
|
||||
|
||||
db.createObjectStore('s1');
|
||||
assert_array_equals(tx.objectStoreNames, ['s1'],
|
||||
'transaction objectStoreNames should have new store');
|
||||
assert_array_equals(db.objectStoreNames, tx.objectStoreNames,
|
||||
'connection and transacton objectStoreNames should match');
|
||||
|
||||
db.createObjectStore('s3');
|
||||
assert_array_equals(tx.objectStoreNames, ['s1', 's3'],
|
||||
'transaction objectStoreNames should have new store');
|
||||
assert_array_equals(db.objectStoreNames, tx.objectStoreNames,
|
||||
'connection and transacton objectStoreNames should match');
|
||||
|
||||
db.createObjectStore('s2');
|
||||
assert_array_equals(tx.objectStoreNames, ['s1', 's2', 's3'],
|
||||
'transaction objectStoreNames should be sorted');
|
||||
assert_array_equals(db.objectStoreNames, tx.objectStoreNames,
|
||||
'connection and transacton objectStoreNames should match');
|
||||
|
||||
db.deleteObjectStore('s1');
|
||||
assert_array_equals(tx.objectStoreNames, ['s2', 's3'],
|
||||
'transaction objectStoreNames should be updated after delete');
|
||||
assert_array_equals(db.objectStoreNames, tx.objectStoreNames,
|
||||
'connection and transacton objectStoreNames should match');
|
||||
}, function(t, db) {
|
||||
t.done();
|
||||
}, 'IDBTransaction.objectStoreNames - during upgrade transaction');
|
||||
|
||||
(function() {
|
||||
var saved_tx;
|
||||
indexeddb_test(function(t, db, tx) {
|
||||
saved_tx = tx;
|
||||
db.createObjectStore('s2');
|
||||
db.createObjectStore('s3');
|
||||
}, function(t, db) {
|
||||
db.close();
|
||||
var open2 = indexedDB.open(db.name, db.version + 1);
|
||||
open2.onerror = t.unreached_func('open should succeed');
|
||||
open2.onupgradeneeded = t.step_func(function() {
|
||||
var db2 = open2.result;
|
||||
var tx2 = open2.transaction;
|
||||
assert_array_equals(tx2.objectStoreNames, ['s2', 's3'],
|
||||
'transaction should have previous stores in scope');
|
||||
assert_array_equals(db2.objectStoreNames, tx2.objectStoreNames,
|
||||
'connection and transacton objectStoreNames should match');
|
||||
|
||||
db2.createObjectStore('s4');
|
||||
assert_array_equals(tx2.objectStoreNames, ['s2', 's3', 's4'],
|
||||
'transaction should have new store in scope');
|
||||
assert_array_equals(db2.objectStoreNames, tx2.objectStoreNames,
|
||||
'connection and transacton objectStoreNames should match');
|
||||
|
||||
assert_array_equals(saved_tx.objectStoreNames, ['s2', 's3'],
|
||||
'previous transaction objectStoreNames should be unchanged');
|
||||
assert_array_equals(db.objectStoreNames, saved_tx.objectStoreNames,
|
||||
'connection and transaction objectStoreNames should match');
|
||||
t.done();
|
||||
});
|
||||
}, 'IDBTransaction.objectStoreNames - value after close');
|
||||
}());
|
||||
|
||||
with_stores_test(['s1', 's2'], function(t, db) {
|
||||
assert_array_equals(db.transaction('s1').objectStoreNames, ['s1'],
|
||||
'transaction should have one store in scope');
|
||||
assert_array_equals(db.transaction(['s1', 's2']).objectStoreNames,
|
||||
['s1', 's2'],
|
||||
'transaction should have two stores in scope');
|
||||
t.done();
|
||||
}, 'IDBTransaction.objectStoreNames - transaction scope');
|
||||
|
||||
with_stores_test(['s1', 's2'], function(t, db) {
|
||||
var tx = db.transaction(['s1', 's2'], 'readwrite');
|
||||
tx.objectStore('s1').put(0, 0);
|
||||
tx.onabort = t.unreached_func('transaction should complete');
|
||||
tx.oncomplete = t.step_func(function() {
|
||||
assert_array_equals(tx.objectStoreNames, ['s1', 's2'],
|
||||
'objectStoreNames should return scope after transaction commits');
|
||||
t.done();
|
||||
});
|
||||
}, 'IDBTransaction.objectStoreNames - value after commit');
|
||||
|
||||
with_stores_test(['s1', 's2'], function(t, db) {
|
||||
var tx = db.transaction(['s1', 's2'], 'readwrite');
|
||||
tx.objectStore('s1').put(0, 0);
|
||||
tx.objectStore('s1').add(0, 0);
|
||||
tx.oncomplete = t.unreached_func('transaction should abort');
|
||||
tx.onabort = t.step_func(function() {
|
||||
assert_array_equals(tx.objectStoreNames, ['s1', 's2'],
|
||||
'objectStoreNames should return scope after transaction aborts');
|
||||
t.done();
|
||||
});
|
||||
}, 'IDBTransaction.objectStoreNames - value after abort');
|
||||
|
||||
with_stores_test(['s1', 's2', 's3'], function(t, db) {
|
||||
assert_array_equals(db.transaction(['s3', 's2', 's1']).objectStoreNames,
|
||||
['s1', 's2', 's3'],
|
||||
'transaction objectStoreNames should be sorted');
|
||||
t.done();
|
||||
}, 'IDBTransaction.objectStoreNames - sorting');
|
||||
|
||||
with_stores_test(['s1', 's2'], function(t, db) {
|
||||
assert_array_equals(
|
||||
db.transaction(['s2', 's1', 's2']).objectStoreNames,
|
||||
['s1', 's2'],
|
||||
'transaction objectStoreNames should not have duplicates');
|
||||
t.done();
|
||||
}, 'IDBTransaction.objectStoreNames - no duplicates');
|
||||
|
||||
var unusual_names = [
|
||||
'', // empty string
|
||||
|
||||
'\x00', // U+0000 NULL
|
||||
'\xFF', // U+00FF LATIN SMALL LETTER Y WITH DIAERESIS
|
||||
|
||||
'1', // basic ASCII
|
||||
'12', // basic ASCII
|
||||
'123', // basic ASCII
|
||||
'abc', // basic ASCII
|
||||
'ABC', // basic ASCII
|
||||
|
||||
'\xA2', // U+00A2 CENT SIGN
|
||||
'\u6C34', // U+6C34 CJK UNIFIED IDEOGRAPH (water)
|
||||
'\uD834\uDD1E', // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair)
|
||||
'\uFFFD', // U+FFFD REPLACEMENT CHARACTER
|
||||
|
||||
'\uD800', // UTF-16 surrogate lead
|
||||
'\uDC00', // UTF-16 surrogate trail
|
||||
];
|
||||
unusual_names.sort();
|
||||
|
||||
indexeddb_test(function(t, db, tx) {
|
||||
unusual_names.slice().reverse().forEach(function(name) {
|
||||
db.createObjectStore(name);
|
||||
});
|
||||
assert_array_equals(tx.objectStoreNames, unusual_names,
|
||||
'transaction should have names sorted');
|
||||
}, function(t, db) {
|
||||
var tx = db.transaction(unusual_names.slice().reverse().concat(unusual_names));
|
||||
assert_array_equals(tx.objectStoreNames, unusual_names,
|
||||
'transaction should have names sorted with no duplicates');
|
||||
t.done();
|
||||
}, 'IDBTransaction.objectStoreNames - unusual names');
|
||||
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue