dom/datastore/tests/file_duplicate.html

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:1d4645755094
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Test for DataStore - duplicate keys</title>
6 </head>
7 <body>
8 <div id="container"></div>
9 <script type="application/javascript;version=1.7">
10
11 var gStore;
12 var gEvent;
13 var gChangeId;
14
15 function ok(a, msg) {
16 alert((a ? 'OK' : 'KO')+ ' ' + msg)
17 }
18
19 function is(a, b, msg) {
20 ok(a === b, msg);
21 }
22
23 function cbError() {
24 alert('KO error');
25 }
26
27 function finish() {
28 alert('DONE');
29 }
30
31 function testGetDataStores() {
32 navigator.getDataStores('foo').then(function(stores) {
33 gStore = stores[0];
34 runTest();
35 }, cbError);
36 }
37
38 function testAdd(success) {
39 gStore.add({ a: 42 }, 'test').then(function() {
40 is(success, true, "Record added");
41 runTest();
42 }, function(e) {
43 is(success, false, "Record failed");
44 ok(e instanceof DOMError, "DOMError received");
45 is(e.name, 'ConstraintError', 'e.name: ConstraintError');
46 is(e.message, '', 'e.message');
47 runTest();
48 });
49 }
50
51 var tests = [
52 // Test for GetDataStore
53 testGetDataStores,
54
55 // add
56 function() { testAdd(true); },
57
58 // add duplicate
59 function() { testAdd(false); }
60 ];
61
62 function runTest() {
63 if (!tests.length) {
64 finish();
65 return;
66 }
67
68 var test = tests.shift();
69 test();
70 }
71
72 runTest();
73 </script>
74 </body>
75 </html>

mercurial