1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/datastore/tests/file_transactions.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,129 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <meta charset="utf-8"> 1.8 + <title>Test for DataStore - transactional semantics</title> 1.9 +</head> 1.10 +<body> 1.11 +<div id="container"></div> 1.12 + <script type="application/javascript;version=1.7"> 1.13 + 1.14 + var gStore; 1.15 + 1.16 + function is(a, b, msg) { 1.17 + alert((a === b ? 'OK' : 'KO') + ' ' + msg) 1.18 + } 1.19 + 1.20 + function ok(a, msg) { 1.21 + alert((a ? 'OK' : 'KO')+ ' ' + msg) 1.22 + } 1.23 + 1.24 + function cbError() { 1.25 + alert('KO error'); 1.26 + } 1.27 + 1.28 + function finish() { 1.29 + alert('DONE'); 1.30 + } 1.31 + 1.32 + function testGetDataStores() { 1.33 + navigator.getDataStores('foo').then(function(stores) { 1.34 + is(stores.length, 1, "getDataStores('foo') returns 1 element"); 1.35 + is(stores[0].name, 'foo', 'The dataStore.name is foo'); 1.36 + is(stores[0].readOnly, false, 'The dataStore foo is not in readonly'); 1.37 + 1.38 + gStore = stores[0]; 1.39 + 1.40 + runTest(); 1.41 + }, cbError); 1.42 + } 1.43 + 1.44 + function checkError(e) { 1.45 + ok(e instanceof DOMError, "Expecting a DOMError"); 1.46 + is(e.name, "ConstraintError", "DOMError.name must be ConstraintError"); 1.47 + } 1.48 + 1.49 + var tests = [ 1.50 + // Test for GetDataStore 1.51 + testGetDataStores, 1.52 + 1.53 + // Add 1.54 + function() { gStore.add("data", null, 'foobar').catch(function(e) { 1.55 + ok(true, "Add rejects when the revision is wrong"); 1.56 + checkError(e); runTest(); }); }, 1.57 + 1.58 + function() { gStore.add("data").then(function() { 1.59 + ok(true, "Add succeeded without revisionId"); 1.60 + runTest(); }, cbError); }, 1.61 + 1.62 + function() { gStore.add("data", null, gStore.revisionId).then(function() { 1.63 + ok(true, "Add succeeded with the correct revisionId"); 1.64 + runTest(); }, cbError); }, 1.65 + 1.66 + function() { gStore.add("data", 42, 'foobar').catch(function(e) { 1.67 + ok(true, "Add rejects when the revision is wrong"); 1.68 + checkError(e); runTest(); }); }, 1.69 + 1.70 + function() { gStore.add("data", 42).then(function() { 1.71 + ok(true, "Add succeeded without revisionId"); 1.72 + runTest(); }, cbError); }, 1.73 + 1.74 + function() { gStore.add("data", 43, gStore.revisionId).then(function() { 1.75 + ok(true, "Add succeeded with the correct revisionId"); 1.76 + runTest(); }, cbError); }, 1.77 + 1.78 + // Put 1.79 + function() { gStore.put("data", 42, 'foobar').catch(function(e) { 1.80 + ok(true, "Put rejects when the revision is wrong"); 1.81 + checkError(e); runTest(); }); }, 1.82 + 1.83 + function() { gStore.put("data", 42).then(function() { 1.84 + ok(true, "Put succeeded without revisionId"); 1.85 + runTest(); }, cbError); }, 1.86 + 1.87 + function() { gStore.put("data", 42, gStore.revisionId).then(function() { 1.88 + ok(true, "Put succeeded with the correct revisionId"); 1.89 + runTest(); }, cbError); }, 1.90 + 1.91 + // Remove 1.92 + function() { gStore.remove(42, 'foobar').catch(function(e) { 1.93 + ok(true, "Remove rejects when the revision is wrong"); 1.94 + checkError(e); runTest(); }); }, 1.95 + 1.96 + function() { gStore.remove(42).then(function() { 1.97 + ok(true, "Remove succeeded without revisionId"); 1.98 + runTest(); }, cbError); }, 1.99 + 1.100 + function() { gStore.remove(42, gStore.revisionId).then(function() { 1.101 + ok(true, "Remove succeeded with the correct revisionId"); 1.102 + runTest(); }, cbError); }, 1.103 + 1.104 + // Clear 1.105 + function() { gStore.clear('foobar').catch(function(e) { 1.106 + ok(true, "Clear rejects when the revision is wrong"); 1.107 + checkError(e); runTest(); }); }, 1.108 + 1.109 + function() { gStore.clear().then(function() { 1.110 + ok(true, "Clear succeeded without revisionId"); 1.111 + runTest(); }, cbError); }, 1.112 + 1.113 + function() { gStore.clear(gStore.revisionId).then(function() { 1.114 + ok(true, "Clear succeeded with the correct revisionId"); 1.115 + runTest(); }, cbError); }, 1.116 + 1.117 + ]; 1.118 + 1.119 + function runTest() { 1.120 + if (!tests.length) { 1.121 + finish(); 1.122 + return; 1.123 + } 1.124 + 1.125 + var test = tests.shift(); 1.126 + test(); 1.127 + } 1.128 + 1.129 + runTest(); 1.130 + </script> 1.131 +</body> 1.132 +</html>