dom/datastore/tests/file_transactions.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <meta charset="utf-8">
michael@0 5 <title>Test for DataStore - transactional semantics</title>
michael@0 6 </head>
michael@0 7 <body>
michael@0 8 <div id="container"></div>
michael@0 9 <script type="application/javascript;version=1.7">
michael@0 10
michael@0 11 var gStore;
michael@0 12
michael@0 13 function is(a, b, msg) {
michael@0 14 alert((a === b ? 'OK' : 'KO') + ' ' + msg)
michael@0 15 }
michael@0 16
michael@0 17 function ok(a, msg) {
michael@0 18 alert((a ? 'OK' : 'KO')+ ' ' + msg)
michael@0 19 }
michael@0 20
michael@0 21 function cbError() {
michael@0 22 alert('KO error');
michael@0 23 }
michael@0 24
michael@0 25 function finish() {
michael@0 26 alert('DONE');
michael@0 27 }
michael@0 28
michael@0 29 function testGetDataStores() {
michael@0 30 navigator.getDataStores('foo').then(function(stores) {
michael@0 31 is(stores.length, 1, "getDataStores('foo') returns 1 element");
michael@0 32 is(stores[0].name, 'foo', 'The dataStore.name is foo');
michael@0 33 is(stores[0].readOnly, false, 'The dataStore foo is not in readonly');
michael@0 34
michael@0 35 gStore = stores[0];
michael@0 36
michael@0 37 runTest();
michael@0 38 }, cbError);
michael@0 39 }
michael@0 40
michael@0 41 function checkError(e) {
michael@0 42 ok(e instanceof DOMError, "Expecting a DOMError");
michael@0 43 is(e.name, "ConstraintError", "DOMError.name must be ConstraintError");
michael@0 44 }
michael@0 45
michael@0 46 var tests = [
michael@0 47 // Test for GetDataStore
michael@0 48 testGetDataStores,
michael@0 49
michael@0 50 // Add
michael@0 51 function() { gStore.add("data", null, 'foobar').catch(function(e) {
michael@0 52 ok(true, "Add rejects when the revision is wrong");
michael@0 53 checkError(e); runTest(); }); },
michael@0 54
michael@0 55 function() { gStore.add("data").then(function() {
michael@0 56 ok(true, "Add succeeded without revisionId");
michael@0 57 runTest(); }, cbError); },
michael@0 58
michael@0 59 function() { gStore.add("data", null, gStore.revisionId).then(function() {
michael@0 60 ok(true, "Add succeeded with the correct revisionId");
michael@0 61 runTest(); }, cbError); },
michael@0 62
michael@0 63 function() { gStore.add("data", 42, 'foobar').catch(function(e) {
michael@0 64 ok(true, "Add rejects when the revision is wrong");
michael@0 65 checkError(e); runTest(); }); },
michael@0 66
michael@0 67 function() { gStore.add("data", 42).then(function() {
michael@0 68 ok(true, "Add succeeded without revisionId");
michael@0 69 runTest(); }, cbError); },
michael@0 70
michael@0 71 function() { gStore.add("data", 43, gStore.revisionId).then(function() {
michael@0 72 ok(true, "Add succeeded with the correct revisionId");
michael@0 73 runTest(); }, cbError); },
michael@0 74
michael@0 75 // Put
michael@0 76 function() { gStore.put("data", 42, 'foobar').catch(function(e) {
michael@0 77 ok(true, "Put rejects when the revision is wrong");
michael@0 78 checkError(e); runTest(); }); },
michael@0 79
michael@0 80 function() { gStore.put("data", 42).then(function() {
michael@0 81 ok(true, "Put succeeded without revisionId");
michael@0 82 runTest(); }, cbError); },
michael@0 83
michael@0 84 function() { gStore.put("data", 42, gStore.revisionId).then(function() {
michael@0 85 ok(true, "Put succeeded with the correct revisionId");
michael@0 86 runTest(); }, cbError); },
michael@0 87
michael@0 88 // Remove
michael@0 89 function() { gStore.remove(42, 'foobar').catch(function(e) {
michael@0 90 ok(true, "Remove rejects when the revision is wrong");
michael@0 91 checkError(e); runTest(); }); },
michael@0 92
michael@0 93 function() { gStore.remove(42).then(function() {
michael@0 94 ok(true, "Remove succeeded without revisionId");
michael@0 95 runTest(); }, cbError); },
michael@0 96
michael@0 97 function() { gStore.remove(42, gStore.revisionId).then(function() {
michael@0 98 ok(true, "Remove succeeded with the correct revisionId");
michael@0 99 runTest(); }, cbError); },
michael@0 100
michael@0 101 // Clear
michael@0 102 function() { gStore.clear('foobar').catch(function(e) {
michael@0 103 ok(true, "Clear rejects when the revision is wrong");
michael@0 104 checkError(e); runTest(); }); },
michael@0 105
michael@0 106 function() { gStore.clear().then(function() {
michael@0 107 ok(true, "Clear succeeded without revisionId");
michael@0 108 runTest(); }, cbError); },
michael@0 109
michael@0 110 function() { gStore.clear(gStore.revisionId).then(function() {
michael@0 111 ok(true, "Clear succeeded with the correct revisionId");
michael@0 112 runTest(); }, cbError); },
michael@0 113
michael@0 114 ];
michael@0 115
michael@0 116 function runTest() {
michael@0 117 if (!tests.length) {
michael@0 118 finish();
michael@0 119 return;
michael@0 120 }
michael@0 121
michael@0 122 var test = tests.shift();
michael@0 123 test();
michael@0 124 }
michael@0 125
michael@0 126 runTest();
michael@0 127 </script>
michael@0 128 </body>
michael@0 129 </html>

mercurial