dom/datastore/tests/file_readonly.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:c5791fdfde4c
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Test for DataStore - basic operation on a readonly db</title>
6 </head>
7 <body>
8 <div id="container"></div>
9 <script type="application/javascript;version=1.7">
10
11 function is(a, b, msg) {
12 dump((a === b ? 'OK' : 'KO') + ' ' + msg + "\n")
13 alert((a === b ? 'OK' : 'KO') + ' ' + msg)
14 }
15
16 function ok(a, msg) {
17 alert((a ? 'OK' : 'KO')+ ' ' + msg)
18 }
19
20 function cbError() {
21 alert('KO error');
22 }
23
24 function finish() {
25 alert('DONE');
26 }
27
28 function runTest() {
29 navigator.getDataStores('bar').then(function(stores) {
30 is(stores.length, 1, "getDataStores('bar') returns 1 element");
31 is(stores[0].name, 'bar', 'The dataStore.name is bar');
32 is(stores[0].readOnly, true, 'The dataStore bar is eadonly');
33
34 var store = stores[0];
35 ok("get" in store, "store.get exists");
36 ok("put" in store, "store.put exists");
37 ok("add" in store, "store.add exists");
38 ok("remove" in store, "store.remove exists");
39 ok("clear" in store, "store.clear exists");
40
41 var f = store.clear();
42 f = f.then(cbError, function() {
43 ok(true, "store.clear() fails because the db is readonly");
44 return store.remove(123);
45 });
46
47 f = f.then(cbError, function() {
48 ok(true, "store.remove() fails because the db is readonly");
49 return store.add(123, true);
50 });
51
52 f = f.then(cbError, function() {
53 ok(true, "store.add() fails because the db is readonly");
54 return store.put({}, 123);
55 })
56
57 f = f.then(cbError, function() {
58 ok(true, "store.put() fails because the db is readonly");
59 })
60
61 f.then(function() {
62 // All done.
63 ok(true, "All done");
64 finish();
65 });
66 }, cbError);
67 }
68
69 runTest();
70 </script>
71 </body>
72 </html>

mercurial