Bug 949537 - Setup substring matching for Chilean numbers. r=gwagner, a=1.4+
authorReuben Morais <reuben.morais@gmail.com>
Sat, 22 Mar 2014 16:07:44 -0300
changeset 185042 5ec0a9eb1ec6db8da07e1a18a00d97bf9cf3962e
parent 185041 ad93689d9dc82cc679d3628ed28f77dca1fc962c
child 185043 d6b4eebd92edacef1e1d09d569bc1cfc34ea10c2
push id5482
push userryanvm@gmail.com
push dateMon, 24 Mar 2014 17:11:47 +0000
treeherdermozilla-aurora@5ec0a9eb1ec6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgwagner, 1
bugs949537
milestone30.0a2
Bug 949537 - Setup substring matching for Chilean numbers. r=gwagner, a=1.4+
b2g/app/b2g.js
dom/contacts/tests/mochitest.ini
dom/contacts/tests/shared.js
dom/contacts/tests/test_contacts_international.html
dom/contacts/tests/test_contacts_substringmatching.html
dom/contacts/tests/test_contacts_substringmatchingCL.html
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -412,16 +412,17 @@ pref("dom.mozContacts.enabled", true);
 pref("dom.navigator-property.disable.mozContacts", false);
 pref("dom.global-constructor.disable.mozContact", false);
 
 // Shortnumber matching needed for e.g. Brazil:
 // 01187654321 can be found with 87654321
 pref("dom.phonenumber.substringmatching.BR", 8);
 pref("dom.phonenumber.substringmatching.CO", 10);
 pref("dom.phonenumber.substringmatching.VE", 7);
+pref("dom.phonenumber.substringmatching.CL", 8);
 
 // WebAlarms
 pref("dom.mozAlarms.enabled", true);
 
 // SimplePush
 pref("services.push.enabled", true);
 // Debugging enabled.
 pref("services.push.debug", false);
--- a/dom/contacts/tests/mochitest.ini
+++ b/dom/contacts/tests/mochitest.ini
@@ -8,13 +8,14 @@ skip-if = (toolkit == 'gonk' && debug) #
 [test_contacts_blobs.html]
 [test_contacts_events.html]
 [test_contacts_getall.html]
 skip-if = (toolkit == 'gonk' && debug) #debug-only failure
 [test_contacts_getall2.html]
 [test_contacts_international.html]
 [test_contacts_substringmatching.html]
 [test_contacts_substringmatchingVE.html]
+[test_contacts_substringmatchingCL.html]
 [test_migration.html]
   support-files =
     test_migration_chrome.js
   skip-if = os == "android"
 
--- a/dom/contacts/tests/shared.js
+++ b/dom/contacts/tests/shared.js
@@ -397,20 +397,22 @@ function next() {
   try {
     var i = index++;
     steps[i]();
   } catch(ex) {
     ok(false, "Caught exception", ex);
   }
 }
 
+SimpleTest.waitForExplicitFinish();
+
 function start_tests() {
   // Skip tests on Android < 4.0 due to test failures on tbpl (see bugs 897924 & 888891)
   let androidVersion = SpecialPowers.Cc['@mozilla.org/system-info;1']
                                     .getService(SpecialPowers.Ci.nsIPropertyBag2)
                                     .getProperty('version');
   if (!isAndroid || androidVersion >= 14) {
-    SimpleTest.waitForExplicitFinish();
-    addLoadEvent(next);
+    next();
   } else {
     ok(true, "Skip tests on Android < 4.0 (bugs 897924 & 888891");
+    SimpleTest.finish();
   }
 }
--- a/dom/contacts/tests/test_contacts_international.html
+++ b/dom/contacts/tests/test_contacts_international.html
@@ -38,23 +38,23 @@ var properties1 = {
 
 var shortNumber = "888";
 var properties2 = {
   name: ["Testname2"],
   tel: [{type: ["work"], value: shortNumber, carrier: "testCarrier"}]
 };
 
 var number3 = {
-  international1: "0041557932012345",
-  international2: "+557932012345"
+  local: "7932012345",
+  international: "+557932012345"
 };
 
 var properties3 = {
   name: ["Testname2"],
-  tel: [{value: number3.international2}]
+  tel: [{value: number3.international}]
 };
 
 var req;
 var createResult1;
 var findResult1;
 var sample_id1;
 
 var steps = [
@@ -90,69 +90,69 @@ var steps = [
   },
   function () {
     ok(true, "Searching for local number");
     var options = {filterBy: ["tel"],
                    filterOp: "startsWith",
                    filterValue: number1.local};
     req = mozContacts.find(options);
     req.onsuccess = function () {
-      ok(req.result.length == 1, "Found exactly 1 contact.");
+      ise(req.result.length, 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
-      ok(findResult1.id == sample_id1, "Same ID");
+      ise(findResult1.id, sample_id1, "Same ID");
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Searching for international number");
     var options = {filterBy: ["tel"],
                    filterOp: "startsWith",
                    filterValue: number1.international};
     req = mozContacts.find(options);
     req.onsuccess = function () {
-      ok(req.result.length == 0, "Found exactly 0 contacts.");
+      ise(req.result.length, 0, "Found exactly 0 contacts.");
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Searching for a short number matching the prefix");
     var shortNumber = number1.local.substring(0, 3);
     var options = {filterBy: ["tel"],
                    filterOp: "equals",
                    filterValue: shortNumber};
     req = mozContacts.find(options);
     req.onsuccess = function() {
-      ok(req.result.length == 0, "The prefix short number should not match any contact.");
+      ise(req.result.length, 0, "The prefix short number should not match any contact.");
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Searching for a short number matching the suffix");
     var shortNumber = number1.local.substring(number1.local.length - 3);
     var options = {filterBy: ["tel"],
                    filterOp: "equals",
                    filterValue: shortNumber};
     req = mozContacts.find(options);
     req.onsuccess = function() {
-      ok(req.result.length == 0, "The suffix short number should not match any contact.");
+      ise(req.result.length, 0, "The suffix short number should not match any contact.");
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Searching for a short number matching a contact");
     var options = {filterBy: ["tel"],
                    filterOp: "equals",
                    filterValue: shortNumber};
     req = mozContacts.find(options);
     req.onsuccess = function() {
-      ok(req.result.length == 1, "Found the contact equally matching the shortNumber.");
+      ise(req.result.length, 1, "Found the contact equally matching the shortNumber.");
       next();
     };
     req.onerror = onFailure;
   },
   function() {
     ok(true, "Modifying number");
     if (!findResult1) {
       SpecialPowers.executeSoon(next);
@@ -166,89 +166,89 @@ var steps = [
   },
   function () {
     ok(true, "Searching for local number");
     var options = {filterBy: ["tel"],
                    filterOp: "startsWith",
                    filterValue: number1.local};
     req = mozContacts.find(options);
     req.onsuccess = function () {
-      ok(req.result.length == 0, "Found exactly 0 contact.");
+      ise(req.result.length, 0, "Found exactly 0 contact.");
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Searching for local number");
     var options = {filterBy: ["tel"],
                    filterOp: "startsWith",
                    filterValue: number1.international};
     req = mozContacts.find(options);
     req.onsuccess = function () {
-      ok(req.result.length == 0, "Found exactly 0 contact.");
+      ise(req.result.length, 0, "Found exactly 0 contact.");
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Searching for local number");
     var options = {filterBy: ["tel"],
                    filterOp: "startsWith",
                    filterValue: number2.local};
     req = mozContacts.find(options);
     req.onsuccess = function () {
-      ok(req.result.length == 1, "Found exactly 1 contact.");
+      ise(req.result.length, 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
-      ok(findResult1.id == sample_id1, "Same ID");
+      ise(findResult1.id, sample_id1, "Same ID");
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Searching for local number");
     var options = {filterBy: ["tel"],
                    filterOp: "startsWith",
                    filterValue: number2.international};
     req = mozContacts.find(options);
     req.onsuccess = function () {
-      ok(req.result.length == 0, "Found exactly 1 contact.");
+      ise(req.result.length, 0, "Found exactly 1 contact.");
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Deleting database");
     req = mozContacts.clear();
     req.onsuccess = function () {
       ok(true, "Deleted the database");
       next();
     }
     req.onerror = onFailure;
   },
   function () {
-    ok(true, "Adding a new contact with country code");
+    ok(true, "Adding a contact with a Brazilian country code");
     createResult1 = new mozContact(properties3);
     req = navigator.mozContacts.save(createResult1);
     req.onsuccess = function () {
       ok(createResult1.id, "The contact now has an ID.");
       sample_id1 = createResult1.id;
       next();
     };
     req.onerror = onFailure;
   },
   function () {
-    ok(true, "Searching for international number with prefix");
+    ok(true, "Searching for Brazilian number using local number");
     var options = {filterBy: ["tel"],
                    filterOp: "match",
-                   filterValue: number3.international1};
+                   filterValue: number3.local};
     req = mozContacts.find(options);
     req.onsuccess = function () {
-      ok(req.result.length == 1, "Found exactly 1 contact.");
+      ise(req.result.length, 1, "Found exactly 1 contact.");
       findResult1 = req.result[0];
-      ok(findResult1.id == sample_id1, "Same ID");
+      ise(findResult1.id, sample_id1, "Same ID");
       next();
     };
     req.onerror = onFailure;
   },
   function () {
     ok(true, "Deleting database");
     req = mozContacts.clear();
     req.onsuccess = function () {
@@ -258,13 +258,17 @@ var steps = [
     req.onerror = onFailure;
   },
   function () {
     ok(true, "all done!\n");
     SimpleTest.finish();
   }
 ];
 
-start_tests();
+SpecialPowers.pushPrefEnv({
+  set: [
+    ["ril.lastKnownSimMcc", "000"]
+  ]
+}, start_tests);
 </script>
 </pre>
 </body>
 </html>
--- a/dom/contacts/tests/test_contacts_substringmatching.html
+++ b/dom/contacts/tests/test_contacts_substringmatching.html
@@ -40,16 +40,25 @@ var prop2 = {
 var prop3 = {
   tel: [{ value: "+43332112346" }]
 };
 
 var prop4 = {
   tel: [{ value: "(0414) 233-9888" }]
 };
 
+var brazilianNumber = {
+  international1: "0041557932012345",
+  international2: "+557932012345"
+};
+
+var prop5 = {
+  tel: [{value: brazilianNumber.international2}]
+};
+
 var req;
 var steps = [
   function () {
     ok(true, "Deleting database");
     req = mozContacts.clear()
     req.onsuccess = function () {
       ok(true, "Deleted the database");
       next();
@@ -289,16 +298,50 @@ var steps = [
     req = mozContacts.clear()
     req.onsuccess = function () {
       ok(true, "Deleted the database");
       next();
     }
     req.onerror = onFailure;
   },
   function () {
+    ok(true, "Adding a new contact with a Brazilian country code");
+    createResult1 = new mozContact(prop5);
+    req = navigator.mozContacts.save(createResult1);
+    req.onsuccess = function () {
+      ok(createResult1.id, "The contact now has an ID.");
+      sample_id1 = createResult1.id;
+      next();
+    };
+    req.onerror = onFailure;
+  },
+  function () {
+    ok(true, "Searching for international number with prefix");
+    var options = {filterBy: ["tel"],
+                   filterOp: "match",
+                   filterValue: brazilianNumber.international1};
+    req = mozContacts.find(options);
+    req.onsuccess = function () {
+      ok(req.result.length == 1, "Found exactly 1 contact.");
+      findResult1 = req.result[0];
+      ok(findResult1.id == sample_id1, "Same ID");
+      next();
+    };
+    req.onerror = onFailure;
+  },
+  function () {
+    ok(true, "Deleting database");
+    req = mozContacts.clear()
+    req.onsuccess = function () {
+      ok(true, "Deleted the database");
+      next();
+    }
+    req.onerror = onFailure;
+  },
+  function () {
     ok(true, "all done!\n");
     SpecialPowers.clearUserPref("dom.phonenumber.substringmatching.BR");
     SpecialPowers.clearUserPref("ril.lastKnownSimMcc");
     SimpleTest.finish();
   }
 ];
 
 start_tests();
new file mode 100644
--- /dev/null
+++ b/dom/contacts/tests/test_contacts_substringmatchingCL.html
@@ -0,0 +1,204 @@
+<!DOCTYPE html>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=877302
+-->
+<head>
+  <title>Test for Bug 949537 substring matching for WebContacts</title>
+  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=949537">Mozilla Bug 949537</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script type="text/javascript;version=1.8" src="http://mochi.test:8888/tests/dom/contacts/tests/shared.js"></script>
+<script class="testbody" type="text/javascript">
+"use strict";
+
+var landlineNumber = "+56 2 27654321";
+
+var number = {
+  local: "87654321",
+  international: "+56 9 87654321"
+};
+
+var properties = {
+  name: ["Testname2"],
+  tel: [{value: number.international}]
+};
+
+var req;
+var steps = [
+  function () {
+    ok(true, "Adding a contact with a Chilean number");
+    createResult1 = new mozContact(properties);
+    req = navigator.mozContacts.save(createResult1);
+    req.onsuccess = function () {
+      ok(createResult1.id, "The contact now has an ID.");
+      sample_id1 = createResult1.id;
+      next();
+    };
+    req.onerror = onFailure;
+  },
+  function () {
+    ok(true, "Searching for Chilean number with prefix");
+    req = mozContacts.find({
+      filterBy: ["tel"],
+      filterOp: "match",
+      filterValue: number.international
+    });
+    req.onsuccess = function () {
+      ise(req.result.length, 1, "Found exactly 1 contact.");
+      findResult1 = req.result[0];
+      ise(findResult1.id, sample_id1, "Same ID");
+      next();
+    };
+    req.onerror = onFailure;
+  },
+  function () {
+    ok(true, "Searching for Chilean number using local number");
+    req = mozContacts.find({
+      filterBy: ["tel"],
+      filterOp: "match",
+      filterValue: number.local
+    });
+    req.onsuccess = function () {
+      ise(req.result.length, 1, "Found 0 contacts.");
+      next();
+    };
+    req.onerror = onFailure;
+  },
+
+  clearDatabase,
+
+  function () {
+    ok(true, "Adding contact with mobile number");
+    createResult1 = new mozContact({tel: [{value: number.international}]});
+    req = navigator.mozContacts.save(createResult1);
+    req.onsuccess = function () {
+      ok(createResult1.id, "The contact now has an ID.");
+      sample_id1 = createResult1.id;
+      next();
+    };
+    req.onerror = onFailure;
+  },
+  function () {
+    ok(true, "Retrieving all contacts");
+    req = mozContacts.find({});
+    req.onsuccess = function () {
+      ise(req.result.length, 1, "One contact.");
+      findResult1 = req.result[0];
+      next();
+    };
+    req.onerror = onFailure;
+  },
+  function () {
+    ok(true, "Retrieving by last 8 digits");
+    req = mozContacts.find({
+      filterBy: ["tel"],
+      filterOp: "match",
+      filterValue: number.international.slice(-8)
+    });
+    req.onsuccess = function () {
+      ise(req.result.length, 1, "Found exactly 1 contact.");
+      findResult1 = req.result[0];
+      ise(findResult1.id, sample_id1, "Same ID");
+      ise(findResult1.tel[0].value, number.international, "Same Value");
+      next();
+    };
+    req.onerror = onFailure;
+  },
+  function () {
+    ok(true, "Retrieving by last 9 digits");
+    req = mozContacts.find({
+      filterBy: ["tel"],
+      filterOp: "match",
+      filterValue: number.international.slice(-9)
+    });
+    req.onsuccess = function () {
+      ise(req.result.length, 1, "Found exactly 1 contact.");
+      findResult1 = req.result[0];
+      ise(findResult1.id, sample_id1, "Same ID");
+      ise(findResult1.tel[0].value, number.international, "Same Value");
+      next();
+    };
+    req.onerror = onFailure;
+  },
+  function () {
+    ok(true, "Retrieving by last 6 digits");
+    req = mozContacts.find({
+      filterBy: ["tel"],
+      filterOp: "match",
+      filterValue: number.international.slice(-6)
+    });
+    req.onsuccess = function () {
+      ise(req.result.length, 0, "Found exactly zero contacts.");
+      next();
+    };
+    req.onerror = onFailure;
+  },
+
+  clearDatabase,
+
+  function () {
+    ok(true, "Adding contact with landline number");
+    createResult1 = new mozContact({tel: [{value: landlineNumber}]});
+    req = navigator.mozContacts.save(createResult1);
+    req.onsuccess = function () {
+      ok(createResult1.id, "The contact now has an ID.");
+      sample_id1 = createResult1.id;
+      next();
+    };
+    req.onerror = onFailure;
+  },
+  function () {
+    ok(true, "Retrieving all contacts");
+    req = mozContacts.find({});
+    req.onsuccess = function () {
+      ise(req.result.length, 1, "One contact.");
+      findResult1 = req.result[0];
+      next();
+    };
+    req.onerror = onFailure;
+  },
+  function () {
+    ok(true, "Retrieving by last 7 digits (local number) with landline calling prefix");
+    req = mozContacts.find({
+      filterBy: ["tel"],
+      filterOp: "match",
+      filterValue: "022" + landlineNumber.slice(-7)
+    });
+    req.onsuccess = function () {
+      ise(req.result.length, 1, "Found exactly 1 contact.");
+      findResult1 = req.result[0];
+      ise(findResult1.id, sample_id1, "Same ID");
+      ise(findResult1.tel[0].value, landlineNumber, "Same Value");
+      next();
+    };
+    req.onerror = onFailure;
+  },
+
+  clearDatabase,
+
+  function () {
+    ok(true, "all done!\n");
+    SimpleTest.finish();
+  }
+];
+
+SpecialPowers.pushPrefEnv({
+  set: [
+    ["dom.phonenumber.substringmatching.CL", 8],
+    ["ril.lastKnownSimMcc", "730"]
+  ]
+}, start_tests);
+</script>
+</pre>
+</body>
+</html>