dom/contacts/tests/test_contacts_international.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.

michael@0 1 <!DOCTYPE html>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=815833
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 815833 WebContacts</title>
michael@0 8 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
michael@0 9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 11 </head>
michael@0 12 <body>
michael@0 13
michael@0 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=815833">Mozilla Bug 815833</a>
michael@0 15 <p id="display"></p>
michael@0 16 <div id="content" style="display: none">
michael@0 17
michael@0 18 </div>
michael@0 19 <pre id="test">
michael@0 20 <script type="text/javascript;version=1.8" src="http://mochi.test:8888/tests/dom/contacts/tests/shared.js"></script>
michael@0 21 <script class="testbody" type="text/javascript">
michael@0 22 "use strict";
michael@0 23
michael@0 24 var number1 = {
michael@0 25 local: "7932012345",
michael@0 26 international: "+557932012345"
michael@0 27 };
michael@0 28
michael@0 29 var number2 = {
michael@0 30 local: "7932012346",
michael@0 31 international: "+557932012346"
michael@0 32 };
michael@0 33
michael@0 34 var properties1 = {
michael@0 35 name: ["Testname1"],
michael@0 36 tel: [{type: ["work"], value: number1.local, carrier: "testCarrier"} , {type: ["home", "fax"], value: number2.local}],
michael@0 37 };
michael@0 38
michael@0 39 var shortNumber = "888";
michael@0 40 var properties2 = {
michael@0 41 name: ["Testname2"],
michael@0 42 tel: [{type: ["work"], value: shortNumber, carrier: "testCarrier"}]
michael@0 43 };
michael@0 44
michael@0 45 var number3 = {
michael@0 46 local: "7932012345",
michael@0 47 international: "+557932012345"
michael@0 48 };
michael@0 49
michael@0 50 var properties3 = {
michael@0 51 name: ["Testname2"],
michael@0 52 tel: [{value: number3.international}]
michael@0 53 };
michael@0 54
michael@0 55 var req;
michael@0 56 var createResult1;
michael@0 57 var findResult1;
michael@0 58 var sample_id1;
michael@0 59
michael@0 60 var steps = [
michael@0 61 function () {
michael@0 62 ok(true, "Deleting database");
michael@0 63 req = mozContacts.clear();
michael@0 64 req.onsuccess = function () {
michael@0 65 ok(true, "Deleted the database");
michael@0 66 next();
michael@0 67 };
michael@0 68 req.onerror = onFailure;
michael@0 69 },
michael@0 70 function () {
michael@0 71 ok(true, "Adding a new contact1");
michael@0 72 createResult1 = new mozContact(properties1);
michael@0 73 req = navigator.mozContacts.save(createResult1);
michael@0 74 req.onsuccess = function () {
michael@0 75 ok(createResult1.id, "The contact now has an ID.");
michael@0 76 sample_id1 = createResult1.id;
michael@0 77 next();
michael@0 78 };
michael@0 79 req.onerror = onFailure;
michael@0 80 },
michael@0 81 function () {
michael@0 82 ok(true, "Adding a new contact2");
michael@0 83 var createResult2 = new mozContact(properties2);
michael@0 84 req = navigator.mozContacts.save(createResult2);
michael@0 85 req.onsuccess = function () {
michael@0 86 ok(createResult2.id, "The contact now has an ID.");
michael@0 87 next();
michael@0 88 };
michael@0 89 req.onerror = onFailure;
michael@0 90 },
michael@0 91 function () {
michael@0 92 ok(true, "Searching for local number");
michael@0 93 var options = {filterBy: ["tel"],
michael@0 94 filterOp: "startsWith",
michael@0 95 filterValue: number1.local};
michael@0 96 req = mozContacts.find(options);
michael@0 97 req.onsuccess = function () {
michael@0 98 ise(req.result.length, 1, "Found exactly 1 contact.");
michael@0 99 findResult1 = req.result[0];
michael@0 100 ise(findResult1.id, sample_id1, "Same ID");
michael@0 101 next();
michael@0 102 };
michael@0 103 req.onerror = onFailure;
michael@0 104 },
michael@0 105 function () {
michael@0 106 ok(true, "Searching for international number");
michael@0 107 var options = {filterBy: ["tel"],
michael@0 108 filterOp: "startsWith",
michael@0 109 filterValue: number1.international};
michael@0 110 req = mozContacts.find(options);
michael@0 111 req.onsuccess = function () {
michael@0 112 ise(req.result.length, 0, "Found exactly 0 contacts.");
michael@0 113 next();
michael@0 114 };
michael@0 115 req.onerror = onFailure;
michael@0 116 },
michael@0 117 function () {
michael@0 118 ok(true, "Searching for a short number matching the prefix");
michael@0 119 var shortNumber = number1.local.substring(0, 3);
michael@0 120 var options = {filterBy: ["tel"],
michael@0 121 filterOp: "equals",
michael@0 122 filterValue: shortNumber};
michael@0 123 req = mozContacts.find(options);
michael@0 124 req.onsuccess = function() {
michael@0 125 ise(req.result.length, 0, "The prefix short number should not match any contact.");
michael@0 126 next();
michael@0 127 };
michael@0 128 req.onerror = onFailure;
michael@0 129 },
michael@0 130 function () {
michael@0 131 ok(true, "Searching for a short number matching the suffix");
michael@0 132 var shortNumber = number1.local.substring(number1.local.length - 3);
michael@0 133 var options = {filterBy: ["tel"],
michael@0 134 filterOp: "equals",
michael@0 135 filterValue: shortNumber};
michael@0 136 req = mozContacts.find(options);
michael@0 137 req.onsuccess = function() {
michael@0 138 ise(req.result.length, 0, "The suffix short number should not match any contact.");
michael@0 139 next();
michael@0 140 };
michael@0 141 req.onerror = onFailure;
michael@0 142 },
michael@0 143 function () {
michael@0 144 ok(true, "Searching for a short number matching a contact");
michael@0 145 var options = {filterBy: ["tel"],
michael@0 146 filterOp: "equals",
michael@0 147 filterValue: shortNumber};
michael@0 148 req = mozContacts.find(options);
michael@0 149 req.onsuccess = function() {
michael@0 150 ise(req.result.length, 1, "Found the contact equally matching the shortNumber.");
michael@0 151 next();
michael@0 152 };
michael@0 153 req.onerror = onFailure;
michael@0 154 },
michael@0 155 function() {
michael@0 156 ok(true, "Modifying number");
michael@0 157 if (!findResult1) {
michael@0 158 SpecialPowers.executeSoon(next);
michael@0 159 } else {
michael@0 160 findResult1.tel[0].value = number2.local;
michael@0 161 req = mozContacts.save(findResult1);
michael@0 162 req.onsuccess = function () {
michael@0 163 next();
michael@0 164 };
michael@0 165 }
michael@0 166 },
michael@0 167 function () {
michael@0 168 ok(true, "Searching for local number");
michael@0 169 var options = {filterBy: ["tel"],
michael@0 170 filterOp: "startsWith",
michael@0 171 filterValue: number1.local};
michael@0 172 req = mozContacts.find(options);
michael@0 173 req.onsuccess = function () {
michael@0 174 ise(req.result.length, 0, "Found exactly 0 contact.");
michael@0 175 next();
michael@0 176 };
michael@0 177 req.onerror = onFailure;
michael@0 178 },
michael@0 179 function () {
michael@0 180 ok(true, "Searching for local number");
michael@0 181 var options = {filterBy: ["tel"],
michael@0 182 filterOp: "startsWith",
michael@0 183 filterValue: number1.international};
michael@0 184 req = mozContacts.find(options);
michael@0 185 req.onsuccess = function () {
michael@0 186 ise(req.result.length, 0, "Found exactly 0 contact.");
michael@0 187 next();
michael@0 188 };
michael@0 189 req.onerror = onFailure;
michael@0 190 },
michael@0 191 function () {
michael@0 192 ok(true, "Searching for local number");
michael@0 193 var options = {filterBy: ["tel"],
michael@0 194 filterOp: "startsWith",
michael@0 195 filterValue: number2.local};
michael@0 196 req = mozContacts.find(options);
michael@0 197 req.onsuccess = function () {
michael@0 198 ise(req.result.length, 1, "Found exactly 1 contact.");
michael@0 199 findResult1 = req.result[0];
michael@0 200 ise(findResult1.id, sample_id1, "Same ID");
michael@0 201 next();
michael@0 202 };
michael@0 203 req.onerror = onFailure;
michael@0 204 },
michael@0 205 function () {
michael@0 206 ok(true, "Searching for local number");
michael@0 207 var options = {filterBy: ["tel"],
michael@0 208 filterOp: "startsWith",
michael@0 209 filterValue: number2.international};
michael@0 210 req = mozContacts.find(options);
michael@0 211 req.onsuccess = function () {
michael@0 212 ise(req.result.length, 0, "Found exactly 1 contact.");
michael@0 213 next();
michael@0 214 };
michael@0 215 req.onerror = onFailure;
michael@0 216 },
michael@0 217 function () {
michael@0 218 ok(true, "Deleting database");
michael@0 219 req = mozContacts.clear();
michael@0 220 req.onsuccess = function () {
michael@0 221 ok(true, "Deleted the database");
michael@0 222 next();
michael@0 223 }
michael@0 224 req.onerror = onFailure;
michael@0 225 },
michael@0 226 function () {
michael@0 227 ok(true, "Adding a contact with a Brazilian country code");
michael@0 228 createResult1 = new mozContact(properties3);
michael@0 229 req = navigator.mozContacts.save(createResult1);
michael@0 230 req.onsuccess = function () {
michael@0 231 ok(createResult1.id, "The contact now has an ID.");
michael@0 232 sample_id1 = createResult1.id;
michael@0 233 next();
michael@0 234 };
michael@0 235 req.onerror = onFailure;
michael@0 236 },
michael@0 237 function () {
michael@0 238 ok(true, "Searching for Brazilian number using local number");
michael@0 239 var options = {filterBy: ["tel"],
michael@0 240 filterOp: "match",
michael@0 241 filterValue: number3.local};
michael@0 242 req = mozContacts.find(options);
michael@0 243 req.onsuccess = function () {
michael@0 244 ise(req.result.length, 1, "Found exactly 1 contact.");
michael@0 245 findResult1 = req.result[0];
michael@0 246 ise(findResult1.id, sample_id1, "Same ID");
michael@0 247 next();
michael@0 248 };
michael@0 249 req.onerror = onFailure;
michael@0 250 },
michael@0 251 function () {
michael@0 252 ok(true, "Deleting database");
michael@0 253 req = mozContacts.clear();
michael@0 254 req.onsuccess = function () {
michael@0 255 ok(true, "Deleted the database");
michael@0 256 next();
michael@0 257 }
michael@0 258 req.onerror = onFailure;
michael@0 259 },
michael@0 260 function () {
michael@0 261 ok(true, "all done!\n");
michael@0 262 SimpleTest.finish();
michael@0 263 }
michael@0 264 ];
michael@0 265
michael@0 266 SpecialPowers.pushPrefEnv({
michael@0 267 set: [
michael@0 268 ["ril.lastKnownSimMcc", "000"]
michael@0 269 ]
michael@0 270 }, start_tests);
michael@0 271 </script>
michael@0 272 </pre>
michael@0 273 </body>
michael@0 274 </html>

mercurial