1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/datastore/tests/file_readonly.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<head> 1.7 + <meta charset="utf-8"> 1.8 + <title>Test for DataStore - basic operation on a readonly db</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 + function is(a, b, msg) { 1.15 + dump((a === b ? 'OK' : 'KO') + ' ' + msg + "\n") 1.16 + alert((a === b ? 'OK' : 'KO') + ' ' + msg) 1.17 + } 1.18 + 1.19 + function ok(a, msg) { 1.20 + alert((a ? 'OK' : 'KO')+ ' ' + msg) 1.21 + } 1.22 + 1.23 + function cbError() { 1.24 + alert('KO error'); 1.25 + } 1.26 + 1.27 + function finish() { 1.28 + alert('DONE'); 1.29 + } 1.30 + 1.31 + function runTest() { 1.32 + navigator.getDataStores('bar').then(function(stores) { 1.33 + is(stores.length, 1, "getDataStores('bar') returns 1 element"); 1.34 + is(stores[0].name, 'bar', 'The dataStore.name is bar'); 1.35 + is(stores[0].readOnly, true, 'The dataStore bar is eadonly'); 1.36 + 1.37 + var store = stores[0]; 1.38 + ok("get" in store, "store.get exists"); 1.39 + ok("put" in store, "store.put exists"); 1.40 + ok("add" in store, "store.add exists"); 1.41 + ok("remove" in store, "store.remove exists"); 1.42 + ok("clear" in store, "store.clear exists"); 1.43 + 1.44 + var f = store.clear(); 1.45 + f = f.then(cbError, function() { 1.46 + ok(true, "store.clear() fails because the db is readonly"); 1.47 + return store.remove(123); 1.48 + }); 1.49 + 1.50 + f = f.then(cbError, function() { 1.51 + ok(true, "store.remove() fails because the db is readonly"); 1.52 + return store.add(123, true); 1.53 + }); 1.54 + 1.55 + f = f.then(cbError, function() { 1.56 + ok(true, "store.add() fails because the db is readonly"); 1.57 + return store.put({}, 123); 1.58 + }) 1.59 + 1.60 + f = f.then(cbError, function() { 1.61 + ok(true, "store.put() fails because the db is readonly"); 1.62 + }) 1.63 + 1.64 + f.then(function() { 1.65 + // All done. 1.66 + ok(true, "All done"); 1.67 + finish(); 1.68 + }); 1.69 + }, cbError); 1.70 + } 1.71 + 1.72 + runTest(); 1.73 + </script> 1.74 +</body> 1.75 +</html>