5 <title>Test for DataStore - string or unsigned long keys
</title>
8 <div id=
"container"></div>
9 <script type=
"application/javascript;version=1.7">
15 function is(a, b, msg) {
16 alert((a === b ? 'OK' : 'KO') + ' ' + msg)
20 alert((a ? 'OK' : 'KO')+ ' ' + msg)
31 function testGetDataStores() {
32 navigator.getDataStores('foo').then(function(stores) {
38 function testAdd_noKey(key) {
42 gStore.add({ a:
42 }).then(function(id) {
43 is(id, key,
"Id must be " + key +
" received: " + id);
47 function testAdd_withKey(key) {
51 gStore.add({ a:
42 }, key).then(function(id) {
52 is(id, key,
"Id must be " + key +
" received: " + id);
56 function testPut(key) {
60 gStore.put({ a:
42 }, key).then(function(id) {
61 is(id, key,
"Id must be " + key +
" received: " + id);
65 function testGet(key) {
66 gStore.get(key).then(function(value) {
67 ok(value,
"Object received!");
68 is(value.a,
42,
"Object received with right value!");
73 function testArrayGet(key) {
74 gStore.get.apply(gStore, key).then(function(values) {
75 is(values.length, key.length,
"Object received!");
76 for (var i =
0; i < values.length; ++i) {
77 is(values[i].a,
42,
"Object received with right value!");
84 function testRemove(key, success) {
88 gStore.remove(key).then(function(value) {
89 is(value, success,
"Status must be " + success +
" received: " + value);
97 function eventListener() {
98 gStore.onchange = function(e) {
99 is(e.operation, gEvent,
"Operation matches: " + e.operation +
" " + gEvent);
100 ok(e.id === gChangeId,
"Operation id matches");
108 // Test for GetDataStore
115 function() { testAdd_noKey(
1); },
116 function() { testAdd_withKey(
123); },
117 function() { testAdd_noKey(
124); },
118 function() { testAdd_withKey('foobar'); },
119 function() { testAdd_noKey(
125); },
120 function() { testAdd_withKey('
125'); },
121 function() { testAdd_withKey('
126'); },
122 function() { testAdd_noKey(
126); },
125 function() { testPut(
42); },
126 function() { testPut('
42'); },
129 function() { testGet('
42'); },
130 function() { testGet(
42); },
131 function() { testGet(
1); },
132 function() { testGet(
123); },
133 function() { testGet(
124); },
134 function() { testGet('foobar'); },
135 function() { testGet(
125); },
136 function() { testGet('
125'); },
137 function() { testGet('
126'); },
138 function() { testGet(
126); },
139 function() { testArrayGet(['
42',
42,
1,
123,
124, 'foobar',
125, '
125', '
126',
126]); },
142 function() { testRemove(
42, true); },
143 function() { testRemove('
42', true); },
144 function() { testRemove('
43', false); },
145 function() { testRemove(
43, false); },
154 var test = tests.shift();