Skip to content

Commit

Permalink
[Contacts] Support querying contact icons.
Browse files Browse the repository at this point in the history
Adds a feature flag for using icons in the Contacts API. Also adds all
of the piping between blink & mojo, and updates the web tests.

Bug: 1020564
Change-Id: I854b1a077792b007f631180d857a8f5abdbb6048
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1895339
Reviewed-by: Ken Buchanan <kenrb@chromium.org>
Reviewed-by: Finnur Thorarinsson <finnur@chromium.org>
Reviewed-by: Ian Vollick <vollick@chromium.org>
Commit-Queue: Rayan Kanso <rayankans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712275}
  • Loading branch information
rayankans authored and chromium-wpt-export-bot committed Nov 4, 2019
1 parent db1f18f commit c83de9b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
14 changes: 12 additions & 2 deletions contacts/contacts-select.https.window.js
Expand Up @@ -64,13 +64,15 @@ contactsTestWithUserActivation(async (test, setSelectedContacts) => {
city: 'Scranton',
addressLine: ['Schrute Farms'],
};
const michaelIcons = [new Blob('image binary data'.split(''), {type: 'image/test'})];

// Returns two contacts with all information available.
setSelectedContacts([
{ name: ['Dwight Schrute'], email: ['dwight@schrutefarmsbnb.com'], tel: ['000-0000'], address: [dwightAddress] },
{ name: ['Michael Scott', 'Prison Mike'], email: ['michael@dundermifflin.com'] },
{ name: ['Michael Scott', 'Prison Mike'], email: ['michael@dundermifflin.com'], icon: michaelIcons },
]);

let results = await navigator.contacts.select(['name', 'email', 'tel', 'address'], { multiple: true });
let results = await navigator.contacts.select(['name', 'email', 'icon', 'tel', 'address'], { multiple: true });
assert_equals(results.length, 2);
results = results.sort((c1, c2) => JSON.stringify(c1) < JSON.stringify(c2) ? -1 : 1);

Expand All @@ -81,11 +83,17 @@ contactsTestWithUserActivation(async (test, setSelectedContacts) => {
assert_own_property(michael, 'email');
assert_own_property(michael, 'tel');
assert_own_property(michael, 'address');
assert_own_property(michael, 'icon');

assert_array_equals(michael.name, ['Michael Scott', 'Prison Mike']);
assert_array_equals(michael.email, ['michael@dundermifflin.com']);
assert_array_equals(michael.tel, []);
assert_array_equals(michael.address, []);

assert_equals(michael.icon.length, michaelIcons.length);
assert_equals(michael.icon[0].type, michaelIcons[0].type);
assert_equals(michael.icon[0].size, michaelIcons[0].size);
assert_equals(await michael.icon[0].text(), await michaelIcons[0].text());
}

{
Expand All @@ -94,10 +102,12 @@ contactsTestWithUserActivation(async (test, setSelectedContacts) => {
assert_own_property(dwight, 'email');
assert_own_property(dwight, 'tel');
assert_own_property(dwight, 'address');
assert_own_property(dwight, 'icon');

assert_array_equals(dwight.name, ['Dwight Schrute']);
assert_array_equals(dwight.email, ['dwight@schrutefarmsbnb.com']);
assert_array_equals(dwight.tel, ['000-0000']);
assert_array_equals(dwight.icon, []);

assert_equals(dwight.address.length, 1);
const selectedAddress = dwight.address[0];
Expand Down
16 changes: 11 additions & 5 deletions resources/chromium/contacts_manager_mock.js
Expand Up @@ -34,11 +34,11 @@ const WebContactsTest = (() => {
};
}

async select(multiple, includeNames, includeEmails, includeTel, includeAddresses) {
async select(multiple, includeNames, includeEmails, includeTel, includeAddresses, includeIcons) {
if (this.selectedContacts_ === null)
return {contacts: null};

const contactInfos = this.selectedContacts_.map(contact => {
const contactInfos = await Promise.all(this.selectedContacts_.map(async contact => {
const contactInfo = new blink.mojom.ContactInfo();
if (includeNames)
contactInfo.name = contact.name || [];
Expand All @@ -47,11 +47,17 @@ const WebContactsTest = (() => {
if (includeTel)
contactInfo.tel = contact.tel || [];
if (includeAddresses) {
contactInfo.address = contact.address || [];
contactInfo.address = contactInfo.address.map(address => this.formatAddress_(address));
contactInfo.address = (contact.address || []).map(address => this.formatAddress_(address));
}
if (includeIcons) {
contactInfo.icon = await Promise.all(
(contact.icon || []).map(async blob => ({
mimeType: blob.type,
data: (await blob.text()).split('').map(s => s.charCodeAt(0)),
})));
}
return contactInfo;
});
}));

if (!contactInfos.length) return {contacts: []};
if (!multiple) return {contacts: [contactInfos[0]]};
Expand Down

0 comments on commit c83de9b

Please sign in to comment.