Bumping manifests a=b2g-bump
[gecko.git] / dom / datastore / tests / file_keys.html
blobff93df42d3ff7c52876b68904cb39272e3157127
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Test for DataStore - string or unsigned long keys</title>
6 </head>
7 <body>
8 <div id="container"></div>
9 <script type="application/javascript;version=1.7">
11 var gStore;
12 var gEvent;
13 var gChangeId;
15 function is(a, b, msg) {
16 alert((a === b ? 'OK' : 'KO') + ' ' + msg)
19 function ok(a, msg) {
20 alert((a ? 'OK' : 'KO')+ ' ' + msg)
23 function cbError() {
24 alert('KO error');
27 function finish() {
28 alert('DONE');
31 function testGetDataStores() {
32 navigator.getDataStores('foo').then(function(stores) {
33 gStore = stores[0];
34 runTest();
35 }, cbError);
38 function testAdd_noKey(key) {
39 gEvent = 'added';
40 gChangeId = key;
42 gStore.add({ a: 42 }).then(function(id) {
43 is(id, key, "Id must be " + key + " received: " + id);
44 });
47 function testAdd_withKey(key) {
48 gEvent = 'added';
49 gChangeId = key;
51 gStore.add({ a: 42 }, key).then(function(id) {
52 is(id, key, "Id must be " + key + " received: " + id);
53 });
56 function testPut(key) {
57 gEvent = 'updated';
58 gChangeId = key;
60 gStore.put({ a: 42 }, key).then(function(id) {
61 is(id, key, "Id must be " + key + " received: " + id);
62 });
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!");
69 runTest();
70 });
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!");
80 runTest();
81 });
84 function testRemove(key, success) {
85 gEvent = 'removed';
86 gChangeId = key;
88 gStore.remove(key).then(function(value) {
89 is(value, success, "Status must be " + success + " received: " + value);
90 if (value == false) {
91 runTest();
92 return;
94 });
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");
101 runTest();
104 runTest();
107 var tests = [
108 // Test for GetDataStore
109 testGetDataStores,
111 // Event listener
112 eventListener,
114 // add
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); },
124 // put
125 function() { testPut(42); },
126 function() { testPut('42'); },
128 // get
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]); },
141 // remove
142 function() { testRemove(42, true); },
143 function() { testRemove('42', true); },
144 function() { testRemove('43', false); },
145 function() { testRemove(43, false); },
148 function runTest() {
149 if (!tests.length) {
150 finish();
151 return;
154 var test = tests.shift();
155 test();
158 runTest();
159 </script>
160 </body>
161 </html>