mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
111 lines
2.4 KiB
HTML
111 lines
2.4 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Test for DataStore - add([array]) remove([array])</title>
|
|
</head>
|
|
<body>
|
|
<div id="container"></div>
|
|
<script type="application/javascript;version=1.7">
|
|
|
|
var gStore;
|
|
|
|
function is(a, b, msg) {
|
|
alert((a === b ? 'OK' : 'KO') + ' ' + msg)
|
|
}
|
|
|
|
function ok(a, msg) {
|
|
alert((a ? 'OK' : 'KO')+ ' ' + msg)
|
|
}
|
|
|
|
function cbError() {
|
|
alert('KO error');
|
|
}
|
|
|
|
function finish() {
|
|
alert('DONE');
|
|
}
|
|
|
|
function testGetDataStores() {
|
|
navigator.getDataStores('foo').then(function(stores) {
|
|
is(stores.length, 1, "getDataStores('foo') returns 1 element");
|
|
is(stores[0].name, 'foo', 'The dataStore.name is foo');
|
|
is(stores[0].readOnly, false, 'The dataStore foo is not in readonly');
|
|
|
|
var store = stores[0];
|
|
ok("get" in store, "store.get exists");
|
|
ok("put" in store, "store.put exists");
|
|
ok("add" in store, "store.add exists");
|
|
ok("remove" in store, "store.remove exists");
|
|
ok("clear" in store, "store.clear exists");
|
|
|
|
gStore = stores[0];
|
|
|
|
runTest();
|
|
}, cbError);
|
|
}
|
|
|
|
var itemNumber = 60;
|
|
|
|
function testStoreAdd() {
|
|
var objects = [];
|
|
for (var i = 0; i < itemNumber; ++i) {
|
|
objects.push(i);
|
|
}
|
|
|
|
function testStoreAddInternal() {
|
|
if (!objects.length) {
|
|
ok(true, "We inserted " + itemNumber + " items");
|
|
runTest();
|
|
return;
|
|
}
|
|
|
|
var obj = objects.shift();
|
|
gStore.add(obj).then(function() {
|
|
ok(true, "We inserted a new item!");
|
|
testStoreAddInternal();
|
|
}, cbError);
|
|
}
|
|
|
|
testStoreAddInternal();
|
|
}
|
|
|
|
function testStoreGet() {
|
|
var objects = [];
|
|
for (var i = 1; i <= itemNumber; ++i) {
|
|
objects.push(i);
|
|
}
|
|
|
|
gStore.get.apply(gStore, objects).then(function(data) {
|
|
is(data.length, objects.length, "Get - Data matches");
|
|
for (var i = 0; i < data.length; ++i) {
|
|
is(data[i], objects[i] - 1, "Get - Data matches: " + i + " " + data[i] + " == " + objects[i]);
|
|
}
|
|
runTest();
|
|
}, cbError);
|
|
}
|
|
|
|
var tests = [
|
|
// Test for GetDataStore
|
|
testGetDataStores,
|
|
|
|
// Add many items
|
|
function() { testStoreAdd() },
|
|
function() { testStoreGet() },
|
|
];
|
|
|
|
function runTest() {
|
|
if (!tests.length) {
|
|
finish();
|
|
return;
|
|
}
|
|
|
|
var test = tests.shift();
|
|
test();
|
|
}
|
|
|
|
runTest();
|
|
</script>
|
|
</body>
|
|
</html>
|