dom/contacts/tests/test_contacts_substringmatchingVE.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/contacts/tests/test_contacts_substringmatchingVE.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,132 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=877302
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 877302 substring matching for WebContacts</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=877302">Mozilla Bug 877302</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">
    1.25 +"use strict";
    1.26 +
    1.27 +var prop = {
    1.28 +  tel: [{value: "7932012345" }, {value: "7704143727591"}]
    1.29 +};
    1.30 +
    1.31 +var prop2 = {
    1.32 +  tel: [{value: "7932012345" }, {value: "+58 212 5551212"}]
    1.33 +};
    1.34 +
    1.35 +var req;
    1.36 +var steps = [
    1.37 +  function () {
    1.38 +    ok(true, "Deleting database");
    1.39 +    req = mozContacts.clear()
    1.40 +    req.onsuccess = function () {
    1.41 +      ok(true, "Deleted the database");
    1.42 +      next();
    1.43 +    }
    1.44 +    req.onerror = onFailure;
    1.45 +  },
    1.46 +  function () {
    1.47 +    ok(true, "Adding contact");
    1.48 +    createResult1 = new mozContact(prop);
    1.49 +    req = navigator.mozContacts.save(createResult1);
    1.50 +    req.onsuccess = function () {
    1.51 +      ok(createResult1.id, "The contact now has an ID.");
    1.52 +      sample_id1 = createResult1.id;
    1.53 +      next();
    1.54 +    };
    1.55 +    req.onerror = onFailure;
    1.56 +  },
    1.57 +  function () {
    1.58 +    ok(true, "Retrieving all contacts");
    1.59 +    req = mozContacts.find({});
    1.60 +    req.onsuccess = function () {
    1.61 +      is(req.result.length, 1, "One contact.");
    1.62 +      findResult1 = req.result[0];
    1.63 +      next();
    1.64 +    };
    1.65 +    req.onerror = onFailure;
    1.66 +  },
    1.67 +  function () {
    1.68 +    ok(true, "Retrieving by substring 1");
    1.69 +    var length = prop.tel[0].value.length;
    1.70 +    var num = "04143727591"
    1.71 +    var options = {filterBy: ["tel"],
    1.72 +                   filterOp: "match",
    1.73 +                   filterValue: num};
    1.74 +    req = mozContacts.find(options);
    1.75 +    req.onsuccess = function () {
    1.76 +      is(req.result.length, 1, "Found exactly 1 contact.");
    1.77 +      findResult1 = req.result[0];
    1.78 +      ok(findResult1.id == sample_id1, "Same ID");
    1.79 +      is(findResult1.tel[1].value, "7704143727591", "Same Value");
    1.80 +      next();
    1.81 +    };
    1.82 +    req.onerror = onFailure;
    1.83 +  },
    1.84 +  function () {
    1.85 +    ok(true, "Adding contact");
    1.86 +    createResult1 = new mozContact(prop2);
    1.87 +    req = navigator.mozContacts.save(createResult1);
    1.88 +    req.onsuccess = function () {
    1.89 +      ok(createResult1.id, "The contact now has an ID.");
    1.90 +      sample_id1 = createResult1.id;
    1.91 +      next();
    1.92 +    };
    1.93 +    req.onerror = onFailure;
    1.94 +  },
    1.95 +  function () {
    1.96 +    ok(true, "Retrieving by substring 2");
    1.97 +    var num = "5551212";
    1.98 +    var options = {filterBy: ["tel"],
    1.99 +                   filterOp: "match",
   1.100 +                   filterValue: num};
   1.101 +    req = mozContacts.find(options);
   1.102 +    req.onsuccess = function () {
   1.103 +      is(req.result.length, 1, "Found exactly 1 contact.");
   1.104 +      findResult1 = req.result[0];
   1.105 +      ok(findResult1.id == sample_id1, "Same ID");
   1.106 +      is(findResult1.tel[1].value, "+58 212 5551212", "Same Value");
   1.107 +      next();
   1.108 +    };
   1.109 +    req.onerror = onFailure;
   1.110 +  },
   1.111 +  function () {
   1.112 +    ok(true, "Deleting database");
   1.113 +    req = mozContacts.clear()
   1.114 +    req.onsuccess = function () {
   1.115 +      ok(true, "Deleted the database");
   1.116 +      next();
   1.117 +    }
   1.118 +    req.onerror = onFailure;
   1.119 +  },
   1.120 +  function () {
   1.121 +    ok(true, "all done!\n");
   1.122 +    SimpleTest.finish();
   1.123 +  }
   1.124 +];
   1.125 +
   1.126 +SpecialPowers.pushPrefEnv({
   1.127 +  set: [
   1.128 +    ["dom.phonenumber.substringmatching.VE", 7],
   1.129 +    ["ril.lastKnownSimMcc", "734"]
   1.130 +  ]
   1.131 +}, start_tests);
   1.132 +</script>
   1.133 +</pre>
   1.134 +</body>
   1.135 +</html>

mercurial