|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <meta charset="utf-8"> |
|
5 <title>Test for DataStore - bug 976311 app1</title> |
|
6 </head> |
|
7 <body> |
|
8 <p id="display"></p> |
|
9 <div id="content" style="display: none"> |
|
10 |
|
11 </div> |
|
12 <pre id="test"> |
|
13 <script type="application/javascript;version=1.7"> |
|
14 |
|
15 var gStores = []; |
|
16 var expectedWhere; |
|
17 |
|
18 function is(a, b, msg) { |
|
19 ok(a === b, msg); |
|
20 } |
|
21 |
|
22 function ok(a, msg) { |
|
23 alert((a ? 'OK' : 'KO')+ ' ' + msg) |
|
24 } |
|
25 |
|
26 function cbError() { |
|
27 alert('KO error'); |
|
28 } |
|
29 |
|
30 function finish() { |
|
31 alert('DONE'); |
|
32 } |
|
33 |
|
34 function checkEvent(id) { |
|
35 is(expectedWhere, id, "Message on the correct DS: " + id + " " + expectedWhere); |
|
36 runTest(); |
|
37 } |
|
38 |
|
39 function testGetDataStores() { |
|
40 navigator.getDataStores('foo').then(function(stores) { |
|
41 is(stores.length, 2, "getDataStores('foo') returns 1 element"); |
|
42 |
|
43 is(stores[0].name, 'foo', 'The dataStore.name is foo'); |
|
44 is(stores[0].readOnly, false, 'The dataStore foo is not in readonly'); |
|
45 stores[0].onchange = function(evt) { checkEvent(0); } |
|
46 gStores.push(stores[0]); |
|
47 |
|
48 is(stores[1].name, 'foo', 'The dataStore.name is foo'); |
|
49 is(stores[1].readOnly, false, 'The dataStore foo is not in readonly'); |
|
50 stores[1].onchange = function(evt) { checkEvent(1); } |
|
51 gStores.push(stores[1]); |
|
52 |
|
53 runTest(); |
|
54 }, cbError); |
|
55 } |
|
56 |
|
57 function testStoreAdd(where, value) { |
|
58 expectedWhere = where; |
|
59 dump("ADD TO: " + gStores[where].owner + "\n"); |
|
60 gStores[where].add({ a: value }); |
|
61 } |
|
62 |
|
63 var tests = [ |
|
64 // Test for GetDataStore |
|
65 testGetDataStores, |
|
66 |
|
67 function() { testStoreAdd(0, 1); }, |
|
68 function() { testStoreAdd(1, 2); }, |
|
69 function() { testStoreAdd(0, 3); }, |
|
70 function() { testStoreAdd(1, 4); } |
|
71 ]; |
|
72 |
|
73 function runTest() { |
|
74 if (!tests.length) { |
|
75 finish(); |
|
76 return; |
|
77 } |
|
78 |
|
79 var test = tests.shift(); |
|
80 test(); |
|
81 } |
|
82 |
|
83 runTest(); |
|
84 </script> |
|
85 </pre> |
|
86 </body> |
|
87 </html> |
|
88 |