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 #31727 from ferjm/bug1201419.nfc.contacts
Browse files Browse the repository at this point in the history
Bug 1201419 - [NFC] Unable to share contact via NFC. r=francisco
  • Loading branch information
ferjm committed Sep 8, 2015
2 parents faa048a + 6da9b22 commit 9450623
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 55 deletions.
37 changes: 16 additions & 21 deletions apps/communications/contacts/js/nfc.js
@@ -1,7 +1,11 @@
'use strict';

/* global LazyLoader, ContactToVcard, MozNDEFRecord, fb, utils,
NDEF, NfcUtils, utils*/
/* global ContactToVcard */
/* global LazyLoader */
/* global MozNDEFRecord*/
/* global NDEF */
/* global NfcUtils */

/* exported NFC */

(function(exports) {
Expand All @@ -12,18 +16,17 @@

var startListening = function(contact) {
if (!mozNfc) {
console.warning('NFC is not available');
return;
}

currentContact = contact;
// We cannot share Facebook data via NFC so we check if the contact
// is an FB contacts. However, if the contact is linked to a regular
// mozContact, we can share linked data
if (fb && !(fb.isFbContact(contact) && !fb.isFbLinked(contact))) {
mozNfc.onpeerready = handlePeerReady;
} else {
mozNfc.onpeerready = handlePeerReadyForFb;
if (!contact) {
console.error('Missing contact. Cannot share via NFC');
return;
}

currentContact = contact;
mozNfc.onpeerready = handlePeerReady;
};

var stopListening = function() {
Expand Down Expand Up @@ -52,7 +55,7 @@
function success() {
sendContact();
},
// use default batch size
// Use default batch size.
null,
// We don't want to share a profile photo via NFC,
// like on Android:
Expand All @@ -71,19 +74,11 @@
});

var promise = mozNfcPeer.sendNDEF([NDEFRecord]);
promise.then(() => {
console.log('Contact succesfuly sent');
}).catch(e => {
console.log('Something goes wrong : ' + e);
promise.catch(e => {
console.error('Something goes wrong %s', e);
});
};

var handlePeerReadyForFb = function() {
utils.status.show({
id: 'facebook-export-forbidden'
});
};

var nfc_tools = {
startListening: startListening,
stopListening: stopListening
Expand Down
Expand Up @@ -147,8 +147,6 @@ wall-post = Wall post

share-contact = Share Contact

facebook-export-forbidden = The contact cannot be shared due to Facebook constraint.

otherAccount = Other accounts
facebookSwitchMsg = Sync friends

Expand Down
29 changes: 8 additions & 21 deletions apps/communications/contacts/test/unit/nfc_test.js
@@ -1,21 +1,24 @@
'use strict';

/* global MockMozNfc, NFC, MocksHelper, fb,
MockMozNDEFRecord, mozContact, NfcUtils */
/* global MocksHelper */
/* global MockMozNDEFRecord */
/* global MockMozNfc */
/* global mozContact */
/* global NFC */
/* global NfcUtils */

require('/shared/test/unit/mocks/mock_moz_ndefrecord.js');
require('/shared/test/unit/mocks/mock_lazy_loader.js');
require('/shared/test/unit/mocks/mock_moz_nfc.js');
require('/shared/js/contact2vcard.js');
require('/shared/js/setImmediate.js');
require('/shared/js/nfc_utils.js');
requireApp('communications/contacts/test/unit/mock_fb.js');
requireApp('communications/contacts/test/unit/mock_l10n.js');
requireApp('communications/contacts/test/unit/mock_navigation.js');
require('/shared/test/unit/mocks/mock_moz_contact.js');

var mocksHelperForNFC = new MocksHelper([
'fb', 'Contacts', 'LazyLoader', 'mozContact'
'Contacts', 'LazyLoader', 'mozContact'
]);
mocksHelperForNFC.init();

Expand Down Expand Up @@ -55,16 +58,12 @@ suite('NFC', function() {
window.utils = realUtils;
});

teardown(function() {
fb.setIsFbContact(false);
});

test('onpeerready is null on start', function() {
assert.isNull(navigator.mozNfc.onpeerready);
});

test('onpeerready set when startListening() fire', function() {
NFC.startListening();
NFC.startListening({} /* empty contact */);
assert.equal(typeof navigator.mozNfc.onpeerready, 'function');
});

Expand All @@ -73,18 +72,6 @@ suite('NFC', function() {
assert.isNull(navigator.mozNfc.onpeerready);
});

test('Facebook contact should not be shared', function() {
var spy = this.sinon.spy(window.utils.status, 'show');
fb.setIsFbContact(true);
NFC.startListening();
navigator.mozNfc.onpeerready(
{
peer: MockMozNfc.MockNFCPeer
}
);
sinon.assert.called(spy);
});

// Bug 1013845
test('Shares diacritic characters correctly', function(done) {
var realSendNDEF = MockMozNfc.MockNFCPeer.sendNDEF;
Expand Down
@@ -1,23 +1,24 @@
'use strict';

/* global utils */
/* global MatchService */
/* global ContactsService */
/* global LazyLoader */
/* global ContactToVcardBlob */
/* global VcardFilename */
/* global LazyLoader */
/* global MatchService */
/* global MozActivity */
/* global NFC */
/* global ParamUtils */
/* global utils */
/* global VcardFilename */

/* exported Details */

/*
* Once the deatils view is loaded, we will listen events dispatched
* from the UI. This events will come with the info needed in order
* Once the details view is loaded, we will listen for events dispatched
* from the UI. These events will come with the info needed in order
* to execute actions related with the UI (back, toggle favorite, share...).
*
* Controller will *not* contain any code related with the DOM/UI,
* and will rely on the info provided by the event.
* and will rely on the info provided by the events.
*/
(function(exports) {

Expand Down Expand Up @@ -180,6 +181,14 @@

function setContact(contactID) {
_contactID = contactID;
LazyLoader.load('/contacts/js/nfc.js', () => {
ContactsService.get(contactID, contact => {
NFC.startListening(contact);
}, error => {
console.error('Could not get contact from ID %s. ' +
'Unable to initialize NFC. %s', contactID, error);
});
});
}

function handleEditAction(evt) {
Expand Down
Expand Up @@ -133,8 +133,6 @@ show-fb-profile = View Facebook profile
msg-send = Message
wall-post = Wall post

facebook-export-forbidden = The contact cannot be shared due to Facebook constraint.

otherAccount = Other accounts
facebookSwitchMsg = Sync friends

Expand Down
Expand Up @@ -152,8 +152,6 @@ show-fb-profile = 查看 Facebook 的个人资料
msg-send = 信息
wall-post = 留言板

facebook-export-forbidden = 由于 Facebook 限制,无法共享该联系人。

otherAccount = 其他账户
facebookSwitchMsg = 同步朋友

Expand Down

0 comments on commit 9450623

Please sign in to comment.