dom/contacts/tests/test_contacts_getall2.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/contacts/tests/test_contacts_getall2.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=836519
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Mozilla Bug 836519</title>
    1.11 +  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
    1.12 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.14 +</head>
    1.15 +<body>
    1.16 +
    1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=836519">Mozilla Bug 836519</a>
    1.18 +<p id="display"></p>
    1.19 +<div id="content" style="display: none">
    1.20 +
    1.21 +</div>
    1.22 +<pre id="test">
    1.23 +<script type="text/javascript;version=1.8" src="http://mochi.test:8888/tests/dom/contacts/tests/shared.js"></script>
    1.24 +<script class="testbody" type="text/javascript;version=1.8">
    1.25 +"use strict";
    1.26 +let req;
    1.27 +
    1.28 +let steps = [
    1.29 +  clearDatabase,
    1.30 +  function() {
    1.31 +    // add a contact
    1.32 +    createResult1 = new mozContact({});
    1.33 +    req = navigator.mozContacts.save(createResult1);
    1.34 +    req.onsuccess = function() {
    1.35 +      next();
    1.36 +    };
    1.37 +    req.onerror = onFailure;
    1.38 +  },
    1.39 +
    1.40 +  getOne(),
    1.41 +  getOne("Retrieving one contact with getAll - cached"),
    1.42 +
    1.43 +  clearDatabase,
    1.44 +  addContacts,
    1.45 +
    1.46 +  getAll(),
    1.47 +  getAll("Retrieving 40 contacts with getAll - cached"),
    1.48 +
    1.49 +  function() {
    1.50 +    ok(true, "Deleting one contact");
    1.51 +    req = mozContacts.remove(createResult1);
    1.52 +    req.onsuccess = function() {
    1.53 +      next();
    1.54 +    };
    1.55 +    req.onerror = onFailure;
    1.56 +  },
    1.57 +  function() {
    1.58 +    ok(true, "Test cache invalidation");
    1.59 +    req = mozContacts.getAll({});
    1.60 +    let count = 0;
    1.61 +    req.onsuccess = function(event) {
    1.62 +      ok(true, "on success");
    1.63 +      if (req.result) {
    1.64 +        ok(true, "result is valid");
    1.65 +        count++;
    1.66 +        req.continue();
    1.67 +      } else {
    1.68 +        is(count, 39, "last contact - 39 contacts returned");
    1.69 +        next();
    1.70 +      }
    1.71 +    };
    1.72 +    req.onerror = onFailure;
    1.73 +  },
    1.74 +
    1.75 +  clearDatabase,
    1.76 +  addContacts,
    1.77 +
    1.78 +  function() {
    1.79 +    ok(true, "Test cache consistency when deleting contact during getAll");
    1.80 +    req = mozContacts.find({});
    1.81 +    req.onsuccess = function(e) {
    1.82 +      let lastContact = e.target.result[e.target.result.length-1];
    1.83 +      req = mozContacts.getAll({});
    1.84 +      let count = 0;
    1.85 +      let firstResult = true;
    1.86 +      req.onsuccess = function(event) {
    1.87 +        ok(true, "on success");
    1.88 +        if (firstResult) {
    1.89 +          if (req.result) {
    1.90 +            count++;
    1.91 +          }
    1.92 +          let delReq = mozContacts.remove(lastContact);
    1.93 +          delReq.onsuccess = function() {
    1.94 +            firstResult = false;
    1.95 +            req.continue();
    1.96 +          };
    1.97 +        } else {
    1.98 +          if (req.result) {
    1.99 +            ok(true, "result is valid");
   1.100 +            count++;
   1.101 +            req.continue();
   1.102 +          } else {
   1.103 +            is(count, 40, "last contact - 40 contacts returned");
   1.104 +            next();
   1.105 +          }
   1.106 +        }
   1.107 +      };
   1.108 +    };
   1.109 +  },
   1.110 +
   1.111 +  clearDatabase,
   1.112 +
   1.113 +  function() {
   1.114 +    ok(true, "all done!\n");
   1.115 +    SimpleTest.finish();
   1.116 +  }
   1.117 +];
   1.118 +
   1.119 +start_tests();
   1.120 +</script>
   1.121 +</pre>
   1.122 +</body>
   1.123 +</html>

mercurial