From 1cfc5531f66643c5acb19aeedc271ef58aa80cc7 Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Thu, 25 Apr 2013 08:40:18 -0700 Subject: [PATCH 01/13] Bug 862250 - Make 'equals' searches on tel only match the value entered by the user. r=gwagner --HG-- extra : rebase_source : 2652c484e01b9b6bb8c27212fc76cb5d9ddfba2d --- dom/contacts/fallback/ContactDB.jsm | 34 ++++++++++++-- dom/contacts/tests/test_contacts_basics.html | 47 ++++++++++++++++++-- 2 files changed, 73 insertions(+), 8 deletions(-) diff --git a/dom/contacts/fallback/ContactDB.jsm b/dom/contacts/fallback/ContactDB.jsm index 0b244163227..1e0249c66ea 100644 --- a/dom/contacts/fallback/ContactDB.jsm +++ b/dom/contacts/fallback/ContactDB.jsm @@ -19,7 +19,7 @@ Cu.import("resource://gre/modules/PhoneNumberUtils.jsm"); Cu.import("resource://gre/modules/Timer.jsm"); const DB_NAME = "contacts"; -const DB_VERSION = 8; +const DB_VERSION = 9; const STORE_NAME = "contacts"; const SAVED_GETALL_STORE_NAME = "getallcache"; const CHUNK_SIZE = 20; @@ -315,6 +315,28 @@ ContactDB.prototype = { } else if (currVersion == 7) { if (DEBUG) debug("Adding object store for cached searches"); db.createObjectStore(SAVED_GETALL_STORE_NAME); + } else if (currVersion == 8) { + if (DEBUG) debug("Make exactTel only contain the value entered by the user"); + if (!objectStore) { + objectStore = aTransaction.objectStore(STORE_NAME); + } + + objectStore.openCursor().onsuccess = function(event) { + let cursor = event.target.result; + if (cursor) { + if (cursor.value.properties.tel) { + cursor.value.search.exactTel = []; + cursor.value.properties.tel.forEach( + function(tel) { + let normalized = PhoneNumberUtils.normalize(tel.value.toString()); + cursor.value.search.exactTel.push(normalized); + } + ); + cursor.update(cursor.value); + } + cursor.continue(); + } + }; } } @@ -417,9 +439,10 @@ ContactDB.prototype = { // Chop off the first characters let number = aContact.properties[field][i].value; - contact.search.exactTel.push(number); let search = {}; if (number) { + number = number.toString(); + contact.search.exactTel.push(PhoneNumberUtils.normalize(number)); for (let i = 0; i < number.length; i++) { search[number.substring(i, number.length)] = 1; } @@ -442,7 +465,6 @@ ContactDB.prototype = { } if (parsedNumber.internationalNumber && number.toString() !== parsedNumber.internationalNumber) { - contact.search.exactTel.push(parsedNumber.internationalNumber); let digits = parsedNumber.internationalNumber.match(/\d/g); if (digits) { digits = digits.join(''); @@ -775,7 +797,11 @@ ContactDB.prototype = { if (DEBUG) debug("Getting index: " + key); // case sensitive let index = store.index(key); - request = index.mozGetAll(options.filterValue, limit); + let filterValue = options.filterValue; + if (key == "tel") { + filterValue = PhoneNumberUtils.normalize(filterValue); + } + request = index.mozGetAll(filterValue, limit); } else { // not case sensitive let tmp = typeof options.filterValue == "string" diff --git a/dom/contacts/tests/test_contacts_basics.html b/dom/contacts/tests/test_contacts_basics.html index 8393efda273..1457f275556 100644 --- a/dom/contacts/tests/test_contacts_basics.html +++ b/dom/contacts/tests/test_contacts_basics.html @@ -87,7 +87,7 @@ var properties1 = { familyName: ["TestFamilyName","Wagner"], givenName: ["Test1","Test2"], nickname: "nicktest", - tel: [{type: ["work"], value: "123456", carrier: "testCarrier"} , {type: ["home", "fax"], value: "+9-876-5432"}], + tel: [{type: ["work"], value: "123456", carrier: "testCarrier"} , {type: ["home", "fax"], value: "+55 (31) 9876-3456"}], adr: adr1, email: [{type: ["work"], value: "x@y.com"}] }; @@ -333,12 +333,12 @@ var steps = [ checkContacts(createResult1, properties1); dump("findResult: " + JSON.stringify(findResult1) + "\n"); // Some manual testing. Testint the testfunctions - // tel: [{type: ["work"], value: "123456", carrier: "testCarrier"} , {type: ["home", "fax"], value: "+9-876-5432"}], + // tel: [{type: ["work"], value: "123456", carrier: "testCarrier"} , {type: ["home", "fax"], value: "+55 (31) 9876-3456"}], is(findResult1.tel[0].carrier, "testCarrier", "Same Carrier"); is(findResult1.tel[0].type, "work", "Same type"); is(findResult1.tel[0].value, "123456", "Same Value"); is(findResult1.tel[1].type[1], "fax", "Same type"); - is(findResult1.tel[1].value, "+9-876-5432", "Same Value"); + is(findResult1.tel[1].value, "+55 (31) 9876-3456", "Same Value"); is(findResult1.adr[0].countryName, "country 1", "Same country"); @@ -503,6 +503,45 @@ var steps = [ }; req.onerror = onFailure; }, + function () { + ok(true, "Retrieving by tel exact"); + var options = {filterBy: ["tel"], + filterOp: "equals", + filterValue: "+55 319 8 7 6 3456"}; + req = mozContacts.find(options); + req.onsuccess = function () { + is(req.result.length, 1, "Found exactly 1 contact."); + findResult1 = req.result[0]; + ok(findResult1.id == sample_id1, "Same ID"); + checkContacts(createResult1, properties1); + next(); + }; + req.onerror = onFailure; + }, + function () { + ok(true, "Retrieving by tel exact with substring"); + var options = {filterBy: ["tel"], + filterOp: "equals", + filterValue: "3456"}; + req = mozContacts.find(options); + req.onsuccess = function () { + is(req.result.length, 0, "Found no contacts."); + next(); + }; + req.onerror = onFailure; + }, + function () { + ok(true, "Retrieving by tel exact with substring"); + var options = {filterBy: ["tel"], + filterOp: "equals", + filterValue: "+55 (31)"}; + req = mozContacts.find(options); + req.onsuccess = function () { + is(req.result.length, 0, "Found no contacts."); + next(); + }; + req.onerror = onFailure; + }, function () { ok(true, "Retrieving by substring tel2"); var options = {filterBy: ["tel"], @@ -522,7 +561,7 @@ var steps = [ ok(true, "Retrieving by substring tel3"); var options = {filterBy: ["tel"], filterOp: "contains", - filterValue: "98765432"}; + filterValue: "98763456"}; req = mozContacts.find(options); req.onsuccess = function () { is(req.result.length, 1, "Found exactly 1 contact."); From 8325d83c1b51708cc829f8dcc19ee66d0c34da19 Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Thu, 25 Apr 2013 09:08:32 -0700 Subject: [PATCH 02/13] Bug 862250 - Add 'match' filterOp for telephone numbers. r=gwagner --HG-- extra : rebase_source : ff5240597f467c9af008bfc043b1717f23b90185 --- dom/contacts/fallback/ContactDB.jsm | 52 ++++++++++++-- dom/contacts/tests/test_contacts_basics.html | 74 +++++++++++++++++++- 2 files changed, 118 insertions(+), 8 deletions(-) diff --git a/dom/contacts/fallback/ContactDB.jsm b/dom/contacts/fallback/ContactDB.jsm index 1e0249c66ea..c55672f1a00 100644 --- a/dom/contacts/fallback/ContactDB.jsm +++ b/dom/contacts/fallback/ContactDB.jsm @@ -19,7 +19,7 @@ Cu.import("resource://gre/modules/PhoneNumberUtils.jsm"); Cu.import("resource://gre/modules/Timer.jsm"); const DB_NAME = "contacts"; -const DB_VERSION = 9; +const DB_VERSION = 10; const STORE_NAME = "contacts"; const SAVED_GETALL_STORE_NAME = "getallcache"; const CHUNK_SIZE = 20; @@ -337,6 +337,28 @@ ContactDB.prototype = { cursor.continue(); } }; + } else if (currVersion == 9) { + if (DEBUG) debug("Add a telMatch index with national and international numbers"); + objectStore.createIndex("telMatch", "search.parsedTel", {multiEntry: true}); + objectStore.openCursor().onsuccess = function(event) { + let cursor = event.target.result; + if (cursor) { + if (cursor.value.properties.tel) { + cursor.value.search.parsedTel = []; + cursor.value.properties.tel.forEach( + function(tel) { + cursor.value.search.parsedTel.push(parsed.nationalNumber); + cursor.value.search.parsedTel.push(PhoneNumberUtils.normalize(parsed.nationalFormat)); + cursor.value.search.parsedTel.push(parsed.internationalNumber); + cursor.value.search.parsedTel.push(PhoneNumberUtils.normalize(parsed.internationalFormat)); + cursor.value.search.parsedTel.push(PhoneNumberUtils.normalize(tel.value.toString())); + } + ); + cursor.update(cursor.value); + } + cursor.continue(); + } + }; } } @@ -424,7 +446,8 @@ ContactDB.prototype = { email: [], category: [], tel: [], - exactTel: [] + exactTel: [], + parsedTel: [] }; for (let field in aContact.properties) { @@ -443,6 +466,7 @@ ContactDB.prototype = { if (number) { number = number.toString(); contact.search.exactTel.push(PhoneNumberUtils.normalize(number)); + contact.search.parsedTel.push(PhoneNumberUtils.normalize(number)); for (let i = 0; i < number.length; i++) { search[number.substring(i, number.length)] = 1; } @@ -463,8 +487,14 @@ ContactDB.prototype = { debug("NationalNumber: " + parsedNumber.nationalNumber); debug("NationalFormat: " + parsedNumber.nationalFormat); } + + contact.search.parsedTel.push(parsedNumber.nationalNumber); + contact.search.parsedTel.push(PhoneNumberUtils.normalize(parsedNumber.nationalFormat)); + contact.search.parsedTel.push(parsedNumber.internationalNumber); + contact.search.parsedTel.push(PhoneNumberUtils.normalize(parsedNumber.internationalFormat)); + if (parsedNumber.internationalNumber && - number.toString() !== parsedNumber.internationalNumber) { + number !== parsedNumber.internationalNumber) { let digits = parsedNumber.internationalNumber.match(/\d/g); if (digits) { digits = digits.join(''); @@ -753,7 +783,7 @@ ContactDB.prototype = { if (DEBUG) debug("ContactDB:find val:" + aOptions.filterValue + " by: " + aOptions.filterBy + " op: " + aOptions.filterOp); let self = this; this.newTxn("readonly", STORE_NAME, function (txn, store) { - if (aOptions && (aOptions.filterOp == "equals" || aOptions.filterOp == "contains")) { + if (aOptions && (["equals", "contains", "match"].indexOf(aOptions.filterOp) >= 0)) { self._findWithIndex(txn, store, aOptions); } else { self._findAll(txn, store, aOptions); @@ -802,11 +832,19 @@ ContactDB.prototype = { filterValue = PhoneNumberUtils.normalize(filterValue); } request = index.mozGetAll(filterValue, limit); + } else if (options.filterOp == "match") { + if (DEBUG) debug("match"); + if (key != "tel") { + dump("ContactDB: 'match' filterOp only works on tel\n"); + return txn.abort(); + } + + let index = store.index("telMatch"); + let normalized = PhoneNumberUtils.normalize(options.filterValue) + request = index.mozGetAll(normalized, limit); } else { // not case sensitive - let tmp = typeof options.filterValue == "string" - ? options.filterValue.toLowerCase() - : options.filterValue.toString().toLowerCase(); + let tmp = options.filterValue.toString().toLowerCase(); if (key === 'tel') { let digits = tmp.match(/\d/g); if (digits) { diff --git a/dom/contacts/tests/test_contacts_basics.html b/dom/contacts/tests/test_contacts_basics.html index 1457f275556..26464ac891f 100644 --- a/dom/contacts/tests/test_contacts_basics.html +++ b/dom/contacts/tests/test_contacts_basics.html @@ -87,7 +87,7 @@ var properties1 = { familyName: ["TestFamilyName","Wagner"], givenName: ["Test1","Test2"], nickname: "nicktest", - tel: [{type: ["work"], value: "123456", carrier: "testCarrier"} , {type: ["home", "fax"], value: "+55 (31) 9876-3456"}], + tel: [{type: ["work"], value: "123456", carrier: "testCarrier"} , {type: ["home", "fax"], value: "+55 (31) 9876-3456"}, {type: ["home"], value: "+49 451 491934"}], adr: adr1, email: [{type: ["work"], value: "x@y.com"}] }; @@ -542,6 +542,78 @@ var steps = [ }; req.onerror = onFailure; }, + function () { + ok(true, "Retrieving by tel match national number"); + var options = {filterBy: ["tel"], + filterOp: "match", + filterValue: "3198763456"}; + req = mozContacts.find(options); + req.onsuccess = function () { + is(req.result.length, 1, "Found exactly 1 contact."); + findResult1 = req.result[0]; + ok(findResult1.id == sample_id1, "Same ID"); + checkContacts(createResult1, properties1); + next(); + }; + req.onerror = onFailure; + }, + function () { + ok(true, "Retrieving by tel match national format"); + var options = {filterBy: ["tel"], + filterOp: "match", + filterValue: "0451 491934"}; + req = mozContacts.find(options); + req.onsuccess = function () { + is(req.result.length, 1, "Found exactly 1 contact."); + findResult1 = req.result[0]; + ok(findResult1.id == sample_id1, "Same ID"); + checkContacts(createResult1, properties1); + next(); + }; + req.onerror = onFailure; + }, + function () { + ok(true, "Retrieving by tel match entered number"); + var options = {filterBy: ["tel"], + filterOp: "match", + filterValue: "123456"}; + req = mozContacts.find(options); + req.onsuccess = function () { + is(req.result.length, 1, "Found exactly 1 contact."); + findResult1 = req.result[0]; + ok(findResult1.id == sample_id1, "Same ID"); + checkContacts(createResult1, properties1); + next(); + }; + req.onerror = onFailure; + }, + function () { + ok(true, "Retrieving by tel match international number"); + var options = {filterBy: ["tel"], + filterOp: "match", + filterValue: "+55 31 98763456"}; + req = mozContacts.find(options); + req.onsuccess = function () { + is(req.result.length, 1, "Found exactly 1 contact."); + findResult1 = req.result[0]; + ok(findResult1.id == sample_id1, "Same ID"); + checkContacts(createResult1, properties1); + next(); + }; + req.onerror = onFailure; + } + function () { + ok(true, "Retrieving by match with field other than tel"); + var options = {filterBy: ["givenName"], + filterOp: "match", + filterValue: "my friends call me 555-4040"}; + req = mozContacts.find(options); + req.onsuccess = onUnwantedSuccess; + req.onerror = function() { + ok(true, "Failed"); + next(); + } + }, function () { ok(true, "Retrieving by substring tel2"); var options = {filterBy: ["tel"], From d1432b1adae03fbb09c72b368edd86fc8ba96299 Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Thu, 25 Apr 2013 09:34:38 -0700 Subject: [PATCH 03/13] Bug 862250 - Follow up, fixing test. --- dom/contacts/tests/test_contacts_basics.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom/contacts/tests/test_contacts_basics.html b/dom/contacts/tests/test_contacts_basics.html index 26464ac891f..9ce45d50029 100644 --- a/dom/contacts/tests/test_contacts_basics.html +++ b/dom/contacts/tests/test_contacts_basics.html @@ -601,7 +601,7 @@ var steps = [ next(); }; req.onerror = onFailure; - } + }, function () { ok(true, "Retrieving by match with field other than tel"); var options = {filterBy: ["givenName"], From 3541bd638a99ced0d635f24aa96f97f61ad63fd8 Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Thu, 25 Apr 2013 20:53:25 -0400 Subject: [PATCH 04/13] Bug 844323 - Prelude part 1: Use a pref to in nsHTMLMediaElement to control whether we talk to the audio service. r=amarchesini Previously, we used #ifdef B2G. Using a pref allows us to write mochitests which run in desktop Firefox that test the audio service and its interaction with other components. --- b2g/app/b2g.js | 5 +- content/html/content/src/HTMLMediaElement.cpp | 46 +++++++++++-------- mobile/android/app/mobile.js | 3 ++ 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/b2g/app/b2g.js b/b2g/app/b2g.js index 24e8154ef9d..b1cc016bb85 100644 --- a/b2g/app/b2g.js +++ b/b2g/app/b2g.js @@ -665,6 +665,9 @@ pref("memory_info_dumper.watch_fifo.directory", "/data/local"); pref("general.useragent.enable_overrides", true); +// Make