Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #17396 from svic/Bug_974725
Browse files Browse the repository at this point in the history
Bug_974725: [B2G][NFC] Support different vcard mime types for Contacts
  • Loading branch information
rvandermeulen committed Apr 1, 2014
2 parents ac2ef36 + ee63ced commit 3864767
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 3 deletions.
17 changes: 16 additions & 1 deletion apps/system/js/nfc_manager.js
Expand Up @@ -362,6 +362,20 @@ var NfcManager = {

// Miscellaneous utility functions to handle formating the JSON for activities

isTypeMatch: function nm_isTypeMatch(type, stringTypeArray) {
var strType = NfcUtils.toUTF8(type);
if (stringTypeArray && stringTypeArray.length) {
for (var i = 0; i < stringTypeArray.length; i++) {
if (strType === stringTypeArray[i]) {
this._debug('Found a type match.');
return true;
}
}
}
this._debug('Did not find a match.');
return false;
},

formatEmpty: function nm_formatEmpty(record) {
this._debug('Activity for empty tag.');
return {
Expand Down Expand Up @@ -480,7 +494,8 @@ var NfcManager = {
var activityText = null;

this._debug('HandleMimeMedia');
if (NfcUtils.equalArrays(record.type, NfcUtils.fromUTF8('text/vcard'))) {
if (this.isTypeMatch(record.type,
['text/vcard', 'text/x-vCard', 'text/x-vcard'])) {
activityText = this.formatVCardRecord(record);
} else {
activityText = {
Expand Down
77 changes: 75 additions & 2 deletions apps/system/test/unit/nfc_manager_test.js
@@ -1,14 +1,22 @@
'use strict';

/* globals MocksHelper,
MozNDEFRecord, NfcBuffer, NDEF, NfcUtils, NfcManagerUtils */
MozNDEFRecord, NfcBuffer, NDEF, NfcManager, NfcManagerUtils, NfcUtils
*/

require('/shared/test/unit/mocks/mock_moz_ndefrecord.js');
require('/shared/test/unit/mocks/mock_settings_listener.js');
require('/shared/js/nfc_utils.js');
requireApp('system/test/unit/mock_activity.js');
requireApp('system/test/unit/mock_screen_manager.js');
requireApp('system/test/unit/mock_settingslistener_installer.js');
requireApp('system/js/nfc_manager_utils.js');
requireApp('system/js/nfc_manager.js');

var mocksForNfcUtils = new MocksHelper([
'MozNDEFRecord'
'MozActivity',
'MozNDEFRecord',
'ScreenManager'
]).init();

suite('Nfc Utility functions', function() {
Expand Down Expand Up @@ -161,4 +169,69 @@ suite('Nfc Utility functions', function() {

});

suite('Activity Routing', function() {
var vcard;
var activityInjection1;
var activityInjection2;
var activityInjection3;

setup(function() {
vcard = 'BEGIN:VCARD\n';
vcard += 'VERSION:2.1\n';
vcard += 'N:Office;Mozilla;;;\n';
vcard += 'FN:Mozilla Office\n';
vcard += 'TEL;PREF:1-555-555-5555\n';
vcard += 'END:VCARD';

activityInjection1 = {
type: 'techDiscovered',
techList: ['P2P','NDEF'],
records: [{
tnf: NDEF.TNF_MIME_MEDIA,
type: NfcUtils.fromUTF8('text/vcard'),
id: new Uint8Array(),
payload: NfcUtils.fromUTF8(vcard)
}],
sessionToken: '{e9364a8b-538c-4c9d-84e2-e6ce524afd17}'
};
activityInjection2 = {
type: 'techDiscovered',
techList: ['P2P','NDEF'],
records: [{
tnf: NDEF.TNF_MIME_MEDIA,
type: NfcUtils.fromUTF8('text/x-vcard'),
id: new Uint8Array(),
payload: NfcUtils.fromUTF8(vcard)
}],
sessionToken: '{e9364a8b-538c-4c9d-84e2-e6ce524afd18}'
};
activityInjection3 = {
type: 'techDiscovered',
techList: ['P2P','NDEF'],
records: [{
tnf: NDEF.TNF_MIME_MEDIA,
type: NfcUtils.fromUTF8('text/x-vCard'),
id: new Uint8Array(),
payload: NfcUtils.fromUTF8(vcard)
}],
sessionToken: '{e9364a8b-538c-4c9d-84e2-e6ce524afd19}'
};
});

test('text/vcard', function() {
var stubFormatVCardRecord = sinon.spy(NfcManager, 'formatVCardRecord');

NfcManager.handleTechnologyDiscovered(activityInjection1);
assert.isTrue(stubFormatVCardRecord.calledOnce);

NfcManager.handleTechnologyDiscovered(activityInjection2);
assert.isTrue(stubFormatVCardRecord.calledTwice);

NfcManager.handleTechnologyDiscovered(activityInjection3);
assert.isTrue(stubFormatVCardRecord.calledThrice);

stubFormatVCardRecord.restore();
});
});

});

0 comments on commit 3864767

Please sign in to comment.