dom/contacts/tests/test_contacts_international.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/contacts/tests/test_contacts_international.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,274 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=815833
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 815833 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=815833">Mozilla Bug 815833</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 number1 = {
    1.28 +  local: "7932012345",
    1.29 +  international: "+557932012345"
    1.30 +};
    1.31 +
    1.32 +var number2 = {
    1.33 +  local: "7932012346",
    1.34 +  international: "+557932012346"
    1.35 +};
    1.36 +
    1.37 +var properties1 = {
    1.38 +  name: ["Testname1"],
    1.39 +  tel: [{type: ["work"], value: number1.local, carrier: "testCarrier"} , {type: ["home", "fax"], value: number2.local}],
    1.40 +};
    1.41 +
    1.42 +var shortNumber = "888";
    1.43 +var properties2 = {
    1.44 +  name: ["Testname2"],
    1.45 +  tel: [{type: ["work"], value: shortNumber, carrier: "testCarrier"}]
    1.46 +};
    1.47 +
    1.48 +var number3 = {
    1.49 +  local: "7932012345",
    1.50 +  international: "+557932012345"
    1.51 +};
    1.52 +
    1.53 +var properties3 = {
    1.54 +  name: ["Testname2"],
    1.55 +  tel: [{value: number3.international}]
    1.56 +};
    1.57 +
    1.58 +var req;
    1.59 +var createResult1;
    1.60 +var findResult1;
    1.61 +var sample_id1;
    1.62 +
    1.63 +var steps = [
    1.64 +  function () {
    1.65 +    ok(true, "Deleting database");
    1.66 +    req = mozContacts.clear();
    1.67 +    req.onsuccess = function () {
    1.68 +      ok(true, "Deleted the database");
    1.69 +      next();
    1.70 +    };
    1.71 +    req.onerror = onFailure;
    1.72 +  },
    1.73 +  function () {
    1.74 +    ok(true, "Adding a new contact1");
    1.75 +    createResult1 = new mozContact(properties1);
    1.76 +    req = navigator.mozContacts.save(createResult1);
    1.77 +    req.onsuccess = function () {
    1.78 +      ok(createResult1.id, "The contact now has an ID.");
    1.79 +      sample_id1 = createResult1.id;
    1.80 +      next();
    1.81 +    };
    1.82 +    req.onerror = onFailure;
    1.83 +  },
    1.84 +  function () {
    1.85 +    ok(true, "Adding a new contact2");
    1.86 +    var createResult2 = new mozContact(properties2);
    1.87 +    req = navigator.mozContacts.save(createResult2);
    1.88 +    req.onsuccess = function () {
    1.89 +      ok(createResult2.id, "The contact now has an ID.");
    1.90 +      next();
    1.91 +    };
    1.92 +    req.onerror = onFailure;
    1.93 +  },
    1.94 +  function () {
    1.95 +    ok(true, "Searching for local number");
    1.96 +    var options = {filterBy: ["tel"],
    1.97 +                   filterOp: "startsWith",
    1.98 +                   filterValue: number1.local};
    1.99 +    req = mozContacts.find(options);
   1.100 +    req.onsuccess = function () {
   1.101 +      ise(req.result.length, 1, "Found exactly 1 contact.");
   1.102 +      findResult1 = req.result[0];
   1.103 +      ise(findResult1.id, sample_id1, "Same ID");
   1.104 +      next();
   1.105 +    };
   1.106 +    req.onerror = onFailure;
   1.107 +  },
   1.108 +  function () {
   1.109 +    ok(true, "Searching for international number");
   1.110 +    var options = {filterBy: ["tel"],
   1.111 +                   filterOp: "startsWith",
   1.112 +                   filterValue: number1.international};
   1.113 +    req = mozContacts.find(options);
   1.114 +    req.onsuccess = function () {
   1.115 +      ise(req.result.length, 0, "Found exactly 0 contacts.");
   1.116 +      next();
   1.117 +    };
   1.118 +    req.onerror = onFailure;
   1.119 +  },
   1.120 +  function () {
   1.121 +    ok(true, "Searching for a short number matching the prefix");
   1.122 +    var shortNumber = number1.local.substring(0, 3);
   1.123 +    var options = {filterBy: ["tel"],
   1.124 +                   filterOp: "equals",
   1.125 +                   filterValue: shortNumber};
   1.126 +    req = mozContacts.find(options);
   1.127 +    req.onsuccess = function() {
   1.128 +      ise(req.result.length, 0, "The prefix short number should not match any contact.");
   1.129 +      next();
   1.130 +    };
   1.131 +    req.onerror = onFailure;
   1.132 +  },
   1.133 +  function () {
   1.134 +    ok(true, "Searching for a short number matching the suffix");
   1.135 +    var shortNumber = number1.local.substring(number1.local.length - 3);
   1.136 +    var options = {filterBy: ["tel"],
   1.137 +                   filterOp: "equals",
   1.138 +                   filterValue: shortNumber};
   1.139 +    req = mozContacts.find(options);
   1.140 +    req.onsuccess = function() {
   1.141 +      ise(req.result.length, 0, "The suffix short number should not match any contact.");
   1.142 +      next();
   1.143 +    };
   1.144 +    req.onerror = onFailure;
   1.145 +  },
   1.146 +  function () {
   1.147 +    ok(true, "Searching for a short number matching a contact");
   1.148 +    var options = {filterBy: ["tel"],
   1.149 +                   filterOp: "equals",
   1.150 +                   filterValue: shortNumber};
   1.151 +    req = mozContacts.find(options);
   1.152 +    req.onsuccess = function() {
   1.153 +      ise(req.result.length, 1, "Found the contact equally matching the shortNumber.");
   1.154 +      next();
   1.155 +    };
   1.156 +    req.onerror = onFailure;
   1.157 +  },
   1.158 +  function() {
   1.159 +    ok(true, "Modifying number");
   1.160 +    if (!findResult1) {
   1.161 +      SpecialPowers.executeSoon(next);
   1.162 +    } else {
   1.163 +      findResult1.tel[0].value = number2.local;
   1.164 +      req = mozContacts.save(findResult1);
   1.165 +      req.onsuccess = function () {
   1.166 +        next();
   1.167 +      };
   1.168 +    }
   1.169 +  },
   1.170 +  function () {
   1.171 +    ok(true, "Searching for local number");
   1.172 +    var options = {filterBy: ["tel"],
   1.173 +                   filterOp: "startsWith",
   1.174 +                   filterValue: number1.local};
   1.175 +    req = mozContacts.find(options);
   1.176 +    req.onsuccess = function () {
   1.177 +      ise(req.result.length, 0, "Found exactly 0 contact.");
   1.178 +      next();
   1.179 +    };
   1.180 +    req.onerror = onFailure;
   1.181 +  },
   1.182 +  function () {
   1.183 +    ok(true, "Searching for local number");
   1.184 +    var options = {filterBy: ["tel"],
   1.185 +                   filterOp: "startsWith",
   1.186 +                   filterValue: number1.international};
   1.187 +    req = mozContacts.find(options);
   1.188 +    req.onsuccess = function () {
   1.189 +      ise(req.result.length, 0, "Found exactly 0 contact.");
   1.190 +      next();
   1.191 +    };
   1.192 +    req.onerror = onFailure;
   1.193 +  },
   1.194 +  function () {
   1.195 +    ok(true, "Searching for local number");
   1.196 +    var options = {filterBy: ["tel"],
   1.197 +                   filterOp: "startsWith",
   1.198 +                   filterValue: number2.local};
   1.199 +    req = mozContacts.find(options);
   1.200 +    req.onsuccess = function () {
   1.201 +      ise(req.result.length, 1, "Found exactly 1 contact.");
   1.202 +      findResult1 = req.result[0];
   1.203 +      ise(findResult1.id, sample_id1, "Same ID");
   1.204 +      next();
   1.205 +    };
   1.206 +    req.onerror = onFailure;
   1.207 +  },
   1.208 +  function () {
   1.209 +    ok(true, "Searching for local number");
   1.210 +    var options = {filterBy: ["tel"],
   1.211 +                   filterOp: "startsWith",
   1.212 +                   filterValue: number2.international};
   1.213 +    req = mozContacts.find(options);
   1.214 +    req.onsuccess = function () {
   1.215 +      ise(req.result.length, 0, "Found exactly 1 contact.");
   1.216 +      next();
   1.217 +    };
   1.218 +    req.onerror = onFailure;
   1.219 +  },
   1.220 +  function () {
   1.221 +    ok(true, "Deleting database");
   1.222 +    req = mozContacts.clear();
   1.223 +    req.onsuccess = function () {
   1.224 +      ok(true, "Deleted the database");
   1.225 +      next();
   1.226 +    }
   1.227 +    req.onerror = onFailure;
   1.228 +  },
   1.229 +  function () {
   1.230 +    ok(true, "Adding a contact with a Brazilian country code");
   1.231 +    createResult1 = new mozContact(properties3);
   1.232 +    req = navigator.mozContacts.save(createResult1);
   1.233 +    req.onsuccess = function () {
   1.234 +      ok(createResult1.id, "The contact now has an ID.");
   1.235 +      sample_id1 = createResult1.id;
   1.236 +      next();
   1.237 +    };
   1.238 +    req.onerror = onFailure;
   1.239 +  },
   1.240 +  function () {
   1.241 +    ok(true, "Searching for Brazilian number using local number");
   1.242 +    var options = {filterBy: ["tel"],
   1.243 +                   filterOp: "match",
   1.244 +                   filterValue: number3.local};
   1.245 +    req = mozContacts.find(options);
   1.246 +    req.onsuccess = function () {
   1.247 +      ise(req.result.length, 1, "Found exactly 1 contact.");
   1.248 +      findResult1 = req.result[0];
   1.249 +      ise(findResult1.id, sample_id1, "Same ID");
   1.250 +      next();
   1.251 +    };
   1.252 +    req.onerror = onFailure;
   1.253 +  },
   1.254 +  function () {
   1.255 +    ok(true, "Deleting database");
   1.256 +    req = mozContacts.clear();
   1.257 +    req.onsuccess = function () {
   1.258 +      ok(true, "Deleted the database");
   1.259 +      next();
   1.260 +    }
   1.261 +    req.onerror = onFailure;
   1.262 +  },
   1.263 +  function () {
   1.264 +    ok(true, "all done!\n");
   1.265 +    SimpleTest.finish();
   1.266 +  }
   1.267 +];
   1.268 +
   1.269 +SpecialPowers.pushPrefEnv({
   1.270 +  set: [
   1.271 +    ["ril.lastKnownSimMcc", "000"]
   1.272 +  ]
   1.273 +}, start_tests);
   1.274 +</script>
   1.275 +</pre>
   1.276 +</body>
   1.277 +</html>

mercurial