dom/contacts/tests/test_contacts_getall2.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 <!--
     4 https://bugzilla.mozilla.org/show_bug.cgi?id=836519
     5 -->
     6 <head>
     7   <title>Mozilla Bug 836519</title>
     8   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
     9   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    10   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    11 </head>
    12 <body>
    14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=836519">Mozilla Bug 836519</a>
    15 <p id="display"></p>
    16 <div id="content" style="display: none">
    18 </div>
    19 <pre id="test">
    20 <script type="text/javascript;version=1.8" src="http://mochi.test:8888/tests/dom/contacts/tests/shared.js"></script>
    21 <script class="testbody" type="text/javascript;version=1.8">
    22 "use strict";
    23 let req;
    25 let steps = [
    26   clearDatabase,
    27   function() {
    28     // add a contact
    29     createResult1 = new mozContact({});
    30     req = navigator.mozContacts.save(createResult1);
    31     req.onsuccess = function() {
    32       next();
    33     };
    34     req.onerror = onFailure;
    35   },
    37   getOne(),
    38   getOne("Retrieving one contact with getAll - cached"),
    40   clearDatabase,
    41   addContacts,
    43   getAll(),
    44   getAll("Retrieving 40 contacts with getAll - cached"),
    46   function() {
    47     ok(true, "Deleting one contact");
    48     req = mozContacts.remove(createResult1);
    49     req.onsuccess = function() {
    50       next();
    51     };
    52     req.onerror = onFailure;
    53   },
    54   function() {
    55     ok(true, "Test cache invalidation");
    56     req = mozContacts.getAll({});
    57     let count = 0;
    58     req.onsuccess = function(event) {
    59       ok(true, "on success");
    60       if (req.result) {
    61         ok(true, "result is valid");
    62         count++;
    63         req.continue();
    64       } else {
    65         is(count, 39, "last contact - 39 contacts returned");
    66         next();
    67       }
    68     };
    69     req.onerror = onFailure;
    70   },
    72   clearDatabase,
    73   addContacts,
    75   function() {
    76     ok(true, "Test cache consistency when deleting contact during getAll");
    77     req = mozContacts.find({});
    78     req.onsuccess = function(e) {
    79       let lastContact = e.target.result[e.target.result.length-1];
    80       req = mozContacts.getAll({});
    81       let count = 0;
    82       let firstResult = true;
    83       req.onsuccess = function(event) {
    84         ok(true, "on success");
    85         if (firstResult) {
    86           if (req.result) {
    87             count++;
    88           }
    89           let delReq = mozContacts.remove(lastContact);
    90           delReq.onsuccess = function() {
    91             firstResult = false;
    92             req.continue();
    93           };
    94         } else {
    95           if (req.result) {
    96             ok(true, "result is valid");
    97             count++;
    98             req.continue();
    99           } else {
   100             is(count, 40, "last contact - 40 contacts returned");
   101             next();
   102           }
   103         }
   104       };
   105     };
   106   },
   108   clearDatabase,
   110   function() {
   111     ok(true, "all done!\n");
   112     SimpleTest.finish();
   113   }
   114 ];
   116 start_tests();
   117 </script>
   118 </pre>
   119 </body>
   120 </html>

mercurial