dom/datastore/tests/file_bug976311.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4   <meta charset="utf-8">
     5   <title>Test for DataStore - bug 976311 app1</title>
     6 </head>
     7 <body>
     8 <p id="display"></p>
     9 <div id="content" style="display: none">
    11 </div>
    12 <pre id="test">
    13   <script type="application/javascript;version=1.7">
    15   var gStores = [];
    16   var expectedWhere;
    18   function is(a, b, msg) {
    19     ok(a === b, msg);
    20   }
    22   function ok(a, msg) {
    23     alert((a ? 'OK' : 'KO')+ ' ' + msg)
    24   }
    26   function cbError() {
    27     alert('KO error');
    28   }
    30   function finish() {
    31     alert('DONE');
    32   }
    34   function checkEvent(id) {
    35     is(expectedWhere, id, "Message on the correct DS: " + id + " " + expectedWhere);
    36     runTest();
    37   }
    39   function testGetDataStores() {
    40     navigator.getDataStores('foo').then(function(stores) {
    41       is(stores.length, 2, "getDataStores('foo') returns 1 element");
    43       is(stores[0].name, 'foo', 'The dataStore.name is foo');
    44       is(stores[0].readOnly, false, 'The dataStore foo is not in readonly');
    45       stores[0].onchange = function(evt) { checkEvent(0); }
    46       gStores.push(stores[0]);
    48       is(stores[1].name, 'foo', 'The dataStore.name is foo');
    49       is(stores[1].readOnly, false, 'The dataStore foo is not in readonly');
    50       stores[1].onchange = function(evt) { checkEvent(1); }
    51       gStores.push(stores[1]);
    53       runTest();
    54     }, cbError);
    55   }
    57   function testStoreAdd(where, value) {
    58     expectedWhere = where;
    59     dump("ADD TO: " + gStores[where].owner + "\n");
    60     gStores[where].add({ a: value });
    61   }
    63   var tests = [
    64     // Test for GetDataStore
    65     testGetDataStores,
    67     function() { testStoreAdd(0, 1); },
    68     function() { testStoreAdd(1, 2); },
    69     function() { testStoreAdd(0, 3); },
    70     function() { testStoreAdd(1, 4); }
    71   ];
    73   function runTest() {
    74     if (!tests.length) {
    75       finish();
    76       return;
    77     }
    79     var test = tests.shift();
    80     test();
    81   }
    83   runTest();
    84   </script>
    85 </pre>
    86 </body>
    87 </html>

mercurial