dom/datastore/tests/file_transactions.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial