Wed, 31 Dec 2014 06:09:35 +0100
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=877302 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 949537 substring matching for 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=949537">Mozilla Bug 949537</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 landlineNumber = "+56 2 27654321"; |
michael@0 | 25 | |
michael@0 | 26 | var number = { |
michael@0 | 27 | local: "87654321", |
michael@0 | 28 | international: "+56 9 87654321" |
michael@0 | 29 | }; |
michael@0 | 30 | |
michael@0 | 31 | var properties = { |
michael@0 | 32 | name: ["Testname2"], |
michael@0 | 33 | tel: [{value: number.international}] |
michael@0 | 34 | }; |
michael@0 | 35 | |
michael@0 | 36 | var req; |
michael@0 | 37 | var steps = [ |
michael@0 | 38 | function () { |
michael@0 | 39 | ok(true, "Adding a contact with a Chilean number"); |
michael@0 | 40 | createResult1 = new mozContact(properties); |
michael@0 | 41 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 42 | req.onsuccess = function () { |
michael@0 | 43 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 44 | sample_id1 = createResult1.id; |
michael@0 | 45 | next(); |
michael@0 | 46 | }; |
michael@0 | 47 | req.onerror = onFailure; |
michael@0 | 48 | }, |
michael@0 | 49 | function () { |
michael@0 | 50 | ok(true, "Searching for Chilean number with prefix"); |
michael@0 | 51 | req = mozContacts.find({ |
michael@0 | 52 | filterBy: ["tel"], |
michael@0 | 53 | filterOp: "match", |
michael@0 | 54 | filterValue: number.international |
michael@0 | 55 | }); |
michael@0 | 56 | req.onsuccess = function () { |
michael@0 | 57 | ise(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 58 | findResult1 = req.result[0]; |
michael@0 | 59 | ise(findResult1.id, sample_id1, "Same ID"); |
michael@0 | 60 | next(); |
michael@0 | 61 | }; |
michael@0 | 62 | req.onerror = onFailure; |
michael@0 | 63 | }, |
michael@0 | 64 | function () { |
michael@0 | 65 | ok(true, "Searching for Chilean number using local number"); |
michael@0 | 66 | req = mozContacts.find({ |
michael@0 | 67 | filterBy: ["tel"], |
michael@0 | 68 | filterOp: "match", |
michael@0 | 69 | filterValue: number.local |
michael@0 | 70 | }); |
michael@0 | 71 | req.onsuccess = function () { |
michael@0 | 72 | ise(req.result.length, 1, "Found 0 contacts."); |
michael@0 | 73 | next(); |
michael@0 | 74 | }; |
michael@0 | 75 | req.onerror = onFailure; |
michael@0 | 76 | }, |
michael@0 | 77 | |
michael@0 | 78 | clearDatabase, |
michael@0 | 79 | |
michael@0 | 80 | function () { |
michael@0 | 81 | ok(true, "Adding contact with mobile number"); |
michael@0 | 82 | createResult1 = new mozContact({tel: [{value: number.international}]}); |
michael@0 | 83 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 84 | req.onsuccess = function () { |
michael@0 | 85 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 86 | sample_id1 = createResult1.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, "Retrieving all contacts"); |
michael@0 | 93 | req = mozContacts.find({}); |
michael@0 | 94 | req.onsuccess = function () { |
michael@0 | 95 | ise(req.result.length, 1, "One contact."); |
michael@0 | 96 | findResult1 = req.result[0]; |
michael@0 | 97 | next(); |
michael@0 | 98 | }; |
michael@0 | 99 | req.onerror = onFailure; |
michael@0 | 100 | }, |
michael@0 | 101 | function () { |
michael@0 | 102 | ok(true, "Retrieving by last 8 digits"); |
michael@0 | 103 | req = mozContacts.find({ |
michael@0 | 104 | filterBy: ["tel"], |
michael@0 | 105 | filterOp: "match", |
michael@0 | 106 | filterValue: number.international.slice(-8) |
michael@0 | 107 | }); |
michael@0 | 108 | req.onsuccess = function () { |
michael@0 | 109 | ise(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 110 | findResult1 = req.result[0]; |
michael@0 | 111 | ise(findResult1.id, sample_id1, "Same ID"); |
michael@0 | 112 | ise(findResult1.tel[0].value, number.international, "Same Value"); |
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, "Retrieving by last 9 digits"); |
michael@0 | 119 | req = mozContacts.find({ |
michael@0 | 120 | filterBy: ["tel"], |
michael@0 | 121 | filterOp: "match", |
michael@0 | 122 | filterValue: number.international.slice(-9) |
michael@0 | 123 | }); |
michael@0 | 124 | req.onsuccess = function () { |
michael@0 | 125 | ise(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 126 | findResult1 = req.result[0]; |
michael@0 | 127 | ise(findResult1.id, sample_id1, "Same ID"); |
michael@0 | 128 | ise(findResult1.tel[0].value, number.international, "Same Value"); |
michael@0 | 129 | next(); |
michael@0 | 130 | }; |
michael@0 | 131 | req.onerror = onFailure; |
michael@0 | 132 | }, |
michael@0 | 133 | function () { |
michael@0 | 134 | ok(true, "Retrieving by last 6 digits"); |
michael@0 | 135 | req = mozContacts.find({ |
michael@0 | 136 | filterBy: ["tel"], |
michael@0 | 137 | filterOp: "match", |
michael@0 | 138 | filterValue: number.international.slice(-6) |
michael@0 | 139 | }); |
michael@0 | 140 | req.onsuccess = function () { |
michael@0 | 141 | ise(req.result.length, 0, "Found exactly zero contacts."); |
michael@0 | 142 | next(); |
michael@0 | 143 | }; |
michael@0 | 144 | req.onerror = onFailure; |
michael@0 | 145 | }, |
michael@0 | 146 | |
michael@0 | 147 | clearDatabase, |
michael@0 | 148 | |
michael@0 | 149 | function () { |
michael@0 | 150 | ok(true, "Adding contact with landline number"); |
michael@0 | 151 | createResult1 = new mozContact({tel: [{value: landlineNumber}]}); |
michael@0 | 152 | req = navigator.mozContacts.save(createResult1); |
michael@0 | 153 | req.onsuccess = function () { |
michael@0 | 154 | ok(createResult1.id, "The contact now has an ID."); |
michael@0 | 155 | sample_id1 = createResult1.id; |
michael@0 | 156 | next(); |
michael@0 | 157 | }; |
michael@0 | 158 | req.onerror = onFailure; |
michael@0 | 159 | }, |
michael@0 | 160 | function () { |
michael@0 | 161 | ok(true, "Retrieving all contacts"); |
michael@0 | 162 | req = mozContacts.find({}); |
michael@0 | 163 | req.onsuccess = function () { |
michael@0 | 164 | ise(req.result.length, 1, "One contact."); |
michael@0 | 165 | findResult1 = req.result[0]; |
michael@0 | 166 | next(); |
michael@0 | 167 | }; |
michael@0 | 168 | req.onerror = onFailure; |
michael@0 | 169 | }, |
michael@0 | 170 | function () { |
michael@0 | 171 | ok(true, "Retrieving by last 7 digits (local number) with landline calling prefix"); |
michael@0 | 172 | req = mozContacts.find({ |
michael@0 | 173 | filterBy: ["tel"], |
michael@0 | 174 | filterOp: "match", |
michael@0 | 175 | filterValue: "022" + landlineNumber.slice(-7) |
michael@0 | 176 | }); |
michael@0 | 177 | req.onsuccess = function () { |
michael@0 | 178 | ise(req.result.length, 1, "Found exactly 1 contact."); |
michael@0 | 179 | findResult1 = req.result[0]; |
michael@0 | 180 | ise(findResult1.id, sample_id1, "Same ID"); |
michael@0 | 181 | ise(findResult1.tel[0].value, landlineNumber, "Same Value"); |
michael@0 | 182 | next(); |
michael@0 | 183 | }; |
michael@0 | 184 | req.onerror = onFailure; |
michael@0 | 185 | }, |
michael@0 | 186 | |
michael@0 | 187 | clearDatabase, |
michael@0 | 188 | |
michael@0 | 189 | function () { |
michael@0 | 190 | ok(true, "all done!\n"); |
michael@0 | 191 | SimpleTest.finish(); |
michael@0 | 192 | } |
michael@0 | 193 | ]; |
michael@0 | 194 | |
michael@0 | 195 | SpecialPowers.pushPrefEnv({ |
michael@0 | 196 | set: [ |
michael@0 | 197 | ["dom.phonenumber.substringmatching.CL", 8], |
michael@0 | 198 | ["ril.lastKnownSimMcc", "730"] |
michael@0 | 199 | ] |
michael@0 | 200 | }, start_tests); |
michael@0 | 201 | </script> |
michael@0 | 202 | </pre> |
michael@0 | 203 | </body> |
michael@0 | 204 | </html> |