dom/contacts/tests/test_contacts_getall.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/contacts/tests/test_contacts_getall.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,152 @@
     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 +
    1.27 +let req;
    1.28 +
    1.29 +let steps = [
    1.30 +  function start() {
    1.31 +    SpecialPowers.Cc["@mozilla.org/tools/profiler;1"].getService(SpecialPowers.Ci.nsIProfiler).AddMarker("GETALL_START");
    1.32 +    next();
    1.33 +  },
    1.34 +  clearDatabase,
    1.35 +  addContacts,
    1.36 +
    1.37 +  function() {
    1.38 +    ok(true, "Delete the current contact while iterating");
    1.39 +    req = mozContacts.getAll({});
    1.40 +    let count = 0;
    1.41 +    let previousId = null;
    1.42 +    req.onsuccess = function() {
    1.43 +      if (req.result) {
    1.44 +        ok(true, "on success");
    1.45 +        if (previousId) {
    1.46 +          isnot(previousId, req.result.id, "different contacts returned");
    1.47 +        }
    1.48 +        previousId = req.result.id;
    1.49 +        count++;
    1.50 +        let delReq = mozContacts.remove(req.result);
    1.51 +        delReq.onsuccess = function() {
    1.52 +          ok(true, "deleted current contact");
    1.53 +          req.continue();
    1.54 +        };
    1.55 +      } else {
    1.56 +        is(count, 40, "returned 40 contacts");
    1.57 +        next();
    1.58 +      }
    1.59 +    };
    1.60 +  },
    1.61 +
    1.62 +  clearDatabase,
    1.63 +  addContacts,
    1.64 +
    1.65 +  function() {
    1.66 +    ok(true, "Iterating through the contact list inside a cursor callback");
    1.67 +    let count1 = 0, count2 = 0;
    1.68 +    let req1 = mozContacts.getAll({});
    1.69 +    let req2;
    1.70 +    req1.onsuccess = function() {
    1.71 +      if (count1 == 0) {
    1.72 +        count1++;
    1.73 +        req2 = mozContacts.getAll({});
    1.74 +        req2.onsuccess = function() {
    1.75 +          if (req2.result) {
    1.76 +            count2++;
    1.77 +            req2.continue();
    1.78 +          } else {
    1.79 +            is(count2, 40, "inner cursor returned 40 contacts");
    1.80 +            req1.continue();
    1.81 +          }
    1.82 +        };
    1.83 +      } else {
    1.84 +        if (req1.result) {
    1.85 +          count1++;
    1.86 +          req1.continue();
    1.87 +        } else {
    1.88 +          is(count1, 40, "outer cursor returned 40 contacts");
    1.89 +          next();
    1.90 +        }
    1.91 +      }
    1.92 +    };
    1.93 +  },
    1.94 +
    1.95 +  clearDatabase,
    1.96 +  addContacts,
    1.97 +
    1.98 +  function() {
    1.99 +    ok(true, "20 concurrent cursors");
   1.100 +    const NUM_CURSORS = 20;
   1.101 +    let completed = 0;
   1.102 +    for (let i = 0; i < NUM_CURSORS; ++i) {
   1.103 +      mozContacts.getAll({}).onsuccess = (function(i) {
   1.104 +        let count = 0;
   1.105 +        return function(event) {
   1.106 +          let req = event.target;
   1.107 +          if (req.result) {
   1.108 +            count++;
   1.109 +            req.continue();
   1.110 +          } else {
   1.111 +            is(count, 40, "cursor " + i + " returned 40 contacts");
   1.112 +            if (++completed == NUM_CURSORS) {
   1.113 +              next();
   1.114 +            }
   1.115 +          }
   1.116 +        };
   1.117 +      })(i);
   1.118 +    }
   1.119 +  },
   1.120 +
   1.121 +  clearDatabase,
   1.122 +  addContacts,
   1.123 +
   1.124 +  function() {
   1.125 +    if (!SpecialPowers.isMainProcess()) {
   1.126 +      // We stop calling continue() intentionally here to see if the cursor gets
   1.127 +      // cleaned up properly in the parent.
   1.128 +      ok(true, "Leaking a cursor");
   1.129 +      req = mozContacts.getAll({
   1.130 +        sortBy: "familyName",
   1.131 +        sortOrder: "ascending"
   1.132 +      });
   1.133 +      req.onsuccess = function(event) {
   1.134 +        next();
   1.135 +      };
   1.136 +      req.onerror = onFailure;
   1.137 +    } else {
   1.138 +      next();
   1.139 +    }
   1.140 +  },
   1.141 +
   1.142 +  clearDatabase,
   1.143 +
   1.144 +  function() {
   1.145 +    ok(true, "all done!\n");
   1.146 +    SpecialPowers.Cc["@mozilla.org/tools/profiler;1"].getService(SpecialPowers.Ci.nsIProfiler).AddMarker("GETALL_END");
   1.147 +    SimpleTest.finish();
   1.148 +  }
   1.149 +];
   1.150 +
   1.151 +start_tests();
   1.152 +</script>
   1.153 +</pre>
   1.154 +</body>
   1.155 +</html>

mercurial