Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
17
gaia/apps/emergency-call/test/unit/.jshintrc
Executable file
17
gaia/apps/emergency-call/test/unit/.jshintrc
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"extends": "../../../../.jshintrc",
|
||||
"predef": [
|
||||
"assert",
|
||||
"suite",
|
||||
"test",
|
||||
"setup",
|
||||
"teardown",
|
||||
"suiteSetup",
|
||||
"suiteTeardown",
|
||||
"require",
|
||||
"requireApp",
|
||||
"sinon",
|
||||
"mocha",
|
||||
"loadBodyHTML"
|
||||
]
|
||||
}
|
||||
174
gaia/apps/emergency-call/test/unit/dialer_test.js
Executable file
174
gaia/apps/emergency-call/test/unit/dialer_test.js
Executable file
|
|
@ -0,0 +1,174 @@
|
|||
'use strict';
|
||||
|
||||
/* global CallHandler, CustomElementsHelper, KeypadManager, MockICEContacts,
|
||||
MockNavigatorMozTelephony, MocksHelper, MockSimSettingsHelper,
|
||||
MockTelephonyMessages, Promise */
|
||||
|
||||
require('/test/unit/mock_keypad.js');
|
||||
require('/test/unit/mock_ice_contacts.js');
|
||||
require('/shared/test/unit/mocks/mocks_helper.js');
|
||||
require('/shared/test/unit/mocks/mock_navigator_moz_telephony.js');
|
||||
require('/shared/test/unit/mocks/mock_lazy_loader.js');
|
||||
require('/shared/test/unit/mocks/mock_sim_settings_helper.js');
|
||||
require('/shared/test/unit/mocks/dialer/mock_telephony_messages.js');
|
||||
require(
|
||||
'/shared/test/unit/mocks/elements/gaia_sim_picker/mock_gaia_sim_picker.js');
|
||||
|
||||
require('/js/dialer.js');
|
||||
|
||||
var mocksHelperForDialer = new MocksHelper([
|
||||
'GaiaSimPicker',
|
||||
'KeypadManager',
|
||||
'ICEContacts',
|
||||
'LazyLoader',
|
||||
'SimSettingsHelper',
|
||||
'TelephonyMessages'
|
||||
]).init();
|
||||
|
||||
var customElementsForDialer = new CustomElementsHelper([
|
||||
'GaiaSimPicker'
|
||||
]);
|
||||
|
||||
suite('Emergency Dialer', function() {
|
||||
var realMozTelephony;
|
||||
|
||||
var num = '123';
|
||||
var mockCall;
|
||||
var mockPromise;
|
||||
|
||||
var simPicker;
|
||||
|
||||
mocksHelperForDialer.attachTestHelpers();
|
||||
|
||||
suiteSetup(function() {
|
||||
realMozTelephony = navigator.mozTelephony;
|
||||
navigator.mozTelephony = MockNavigatorMozTelephony;
|
||||
|
||||
CallHandler._telephony = MockNavigatorMozTelephony;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozTelephony = realMozTelephony;
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
simPicker = document.createElement('gaia-sim-picker');
|
||||
simPicker.id = 'sim-picker';
|
||||
document.body.appendChild(simPicker);
|
||||
customElementsForDialer.resolve();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
document.body.removeChild(simPicker);
|
||||
});
|
||||
|
||||
suite('> Telephony API', function() {
|
||||
setup(function() {
|
||||
mockCall = {};
|
||||
mockPromise = Promise.resolve(mockCall);
|
||||
this.sinon.stub(navigator.mozTelephony, 'dialEmergency')
|
||||
.returns(mockPromise);
|
||||
CallHandler.call(num);
|
||||
});
|
||||
|
||||
test('> calls dialEmergency', function() {
|
||||
sinon.assert.calledWith(navigator.mozTelephony.dialEmergency, num);
|
||||
});
|
||||
|
||||
test('> installs onconnected handler', function(done) {
|
||||
mockPromise.then(function() {
|
||||
assert.isFunction(mockCall.onconnected);
|
||||
}).then(done, done);
|
||||
});
|
||||
|
||||
test('> installs ondisconnected handler', function(done) {
|
||||
mockPromise.then(function() {
|
||||
assert.isFunction(mockCall.ondisconnected);
|
||||
}).then(done, done);
|
||||
});
|
||||
|
||||
test('> clears the keypad on connected', function(done) {
|
||||
this.sinon.spy(KeypadManager, 'updatePhoneNumber');
|
||||
mockPromise.then(function() {
|
||||
mockCall.onconnected();
|
||||
sinon.assert.calledWith(KeypadManager.updatePhoneNumber, '');
|
||||
}).then(done, done);
|
||||
});
|
||||
|
||||
test('> clears the keypad on disconnected', function(done) {
|
||||
this.sinon.spy(KeypadManager, 'updatePhoneNumber');
|
||||
mockPromise.then(function() {
|
||||
mockCall.ondisconnected({
|
||||
call: { disconnectedReason: 'NormalCallClearing' }
|
||||
});
|
||||
sinon.assert.calledWith(KeypadManager.updatePhoneNumber, '');
|
||||
}).then(done, done);
|
||||
});
|
||||
|
||||
test('> displays an appropriate message on disconnected', function(done) {
|
||||
this.sinon.spy(MockTelephonyMessages, 'handleDisconnect');
|
||||
mockPromise.then(function() {
|
||||
mockCall.ondisconnected({
|
||||
call: { disconnectedReason: 'NormalCallClearing' }
|
||||
});
|
||||
sinon.assert.calledOnce(MockTelephonyMessages.handleDisconnect);
|
||||
sinon.assert.calledWith(
|
||||
MockTelephonyMessages.handleDisconnect, 'NormalCallClearing', num
|
||||
);
|
||||
}).then(done, done);
|
||||
});
|
||||
});
|
||||
|
||||
suite('> Dialing ICE Contacts Behavior', function() {
|
||||
setup(function() {
|
||||
mockCall = {};
|
||||
mockPromise = Promise.resolve(mockCall);
|
||||
this.sinon.stub(navigator.mozTelephony, 'dialEmergency')
|
||||
.returns(mockPromise);
|
||||
this.sinon.stub(navigator.mozTelephony, 'dial').returns(mockPromise);
|
||||
this.sinon.stub(MockICEContacts, 'isFromICEContact');
|
||||
});
|
||||
|
||||
test('> dials when default outgoing SIM "always ask" and SIM selected',
|
||||
function() {
|
||||
MockSimSettingsHelper._defaultCards.outgoingCall =
|
||||
MockSimSettingsHelper.ALWAYS_ASK_OPTION_VALUE;
|
||||
this.sinon.stub(simPicker, 'getOrPick');
|
||||
MockICEContacts.isFromICEContact.returns(true);
|
||||
|
||||
CallHandler.call(num);
|
||||
simPicker.getOrPick.yield(0);
|
||||
sinon.assert.calledWith(navigator.mozTelephony.dial, num);
|
||||
sinon.assert.calledWith(simPicker.getOrPick,
|
||||
MockSimSettingsHelper.ALWAYS_ASK_OPTION_VALUE,
|
||||
num);
|
||||
});
|
||||
|
||||
[0, 1].forEach(function(cardIndex) {
|
||||
test('> calls dial when ICE dialed with SIM ' + cardIndex, function() {
|
||||
MockSimSettingsHelper._defaultCards.outgoingCall = cardIndex;
|
||||
MockICEContacts.isFromICEContact.returns(true);
|
||||
|
||||
CallHandler.call(num);
|
||||
sinon.assert.calledWith(navigator.mozTelephony.dial, num, cardIndex);
|
||||
});
|
||||
});
|
||||
|
||||
test('> calls dialEmergency when non-ICE Contact is dialed', function() {
|
||||
MockICEContacts.isFromICEContact.returns(false);
|
||||
|
||||
CallHandler.call(num);
|
||||
sinon.assert.calledWith(navigator.mozTelephony.dialEmergency, num);
|
||||
});
|
||||
|
||||
test('> SimPicker NOT called when Emergency number is dialed',
|
||||
function() {
|
||||
MockICEContacts.isFromICEContact.returns(false);
|
||||
this.sinon.spy(simPicker, 'getOrPick');
|
||||
|
||||
CallHandler.call(num);
|
||||
sinon.assert.calledOnce(navigator.mozTelephony.dialEmergency);
|
||||
sinon.assert.notCalled(simPicker.getOrPick);
|
||||
});
|
||||
});
|
||||
});
|
||||
458
gaia/apps/emergency-call/test/unit/ice_contacts_test.js
Executable file
458
gaia/apps/emergency-call/test/unit/ice_contacts_test.js
Executable file
|
|
@ -0,0 +1,458 @@
|
|||
/* globals ICEContacts, ICEStore, MocksHelper, mozContact, MockMozContacts,
|
||||
MockLazyLoader */
|
||||
'use strict';
|
||||
|
||||
require('/shared/test/unit/mocks/mocks_helper.js');
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
require('/shared/test/unit/mocks/mock_lazy_loader.js');
|
||||
require('/shared/test/unit/mocks/mock_mozContacts.js');
|
||||
require('/shared/js/dialer/utils.js');
|
||||
require('/shared/test/unit/mocks/mock_ice_store.js');
|
||||
require('/test/unit/mock_call_handler.js');
|
||||
require('/js/ice_contacts.js');
|
||||
|
||||
var mocksHelperForDialer = new MocksHelper([
|
||||
'LazyLoader',
|
||||
'ICEStore',
|
||||
'CallHandler'
|
||||
]).init();
|
||||
|
||||
suite('ICE contacts bar', function() {
|
||||
var realMozContacts;
|
||||
var container;
|
||||
var iceContactBar;
|
||||
var iceContactsOverlay;
|
||||
var iceContactList;
|
||||
|
||||
mocksHelperForDialer.attachTestHelpers();
|
||||
|
||||
function createDOM() {
|
||||
document.body.innerHTML = '';
|
||||
|
||||
container = document.createElement('div');
|
||||
iceContactBar = document.createElement('section');
|
||||
iceContactBar.id = 'ice-contacts-bar';
|
||||
iceContactBar.class = 'ice-contacts-bar';
|
||||
iceContactBar.setAttribute('hidden', '');
|
||||
iceContactBar.textContent = 'ICE Contacts - In Case of Emergency';
|
||||
container.appendChild(iceContactBar);
|
||||
|
||||
loadBodyHTML('/shared/elements/contacts/contact_list_overlay.html');
|
||||
var iceContactsOverlayTemplate = document.body.querySelector('template');
|
||||
iceContactsOverlay = document.createElement('form');
|
||||
iceContactsOverlay.id = 'contact-list-overlay';
|
||||
iceContactsOverlay.setAttribute('role', 'dialog');
|
||||
iceContactsOverlay.setAttribute('data-type', 'action');
|
||||
iceContactsOverlay.classList.add('overlay');
|
||||
iceContactsOverlay.appendChild(
|
||||
iceContactsOverlayTemplate.content.cloneNode(true));
|
||||
container.appendChild(iceContactsOverlay);
|
||||
|
||||
loadBodyHTML('/shared/elements/contacts/contact_in_overlay.html');
|
||||
var iceContactsOverlayItemTemplate =
|
||||
document.body.querySelector('template');
|
||||
var iceContactsOverlayItem = document.createElement('button');
|
||||
iceContactsOverlayItem.id = 'contact-in-overlay';
|
||||
iceContactsOverlayItem.setAttribute('hidden', '');
|
||||
iceContactsOverlayItem.appendChild(
|
||||
iceContactsOverlayItemTemplate.content.cloneNode(true));
|
||||
container.appendChild(iceContactsOverlayItem);
|
||||
|
||||
document.body.appendChild(container);
|
||||
|
||||
iceContactList = document.getElementById('contact-list');
|
||||
}
|
||||
|
||||
function shouldNotShowICEContactsBar(done) {
|
||||
ICEContacts.updateICEContacts().then(function() {
|
||||
assert.ok(iceContactBar.hasAttribute('hidden'));
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
function shouldIncludeICEContacts(done, length) {
|
||||
ICEContacts.updateICEContacts().then(function() {
|
||||
assert.equal(iceContactList.children.length, length);
|
||||
done();
|
||||
});
|
||||
}
|
||||
|
||||
suiteSetup(function() {
|
||||
realMozContacts = navigator.mozContacts;
|
||||
navigator.mozContacts = MockMozContacts;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozContacts = realMozContacts;
|
||||
document.body.removeChild(container);
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
ICEContacts._initialized = false;
|
||||
createDOM();
|
||||
});
|
||||
|
||||
suite('Initialization', function() {
|
||||
setup(function(done) {
|
||||
navigator.mozContacts.clear();
|
||||
ICEStore.setContacts([]).then(function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('Lazyloads contact list overlay', function(done) {
|
||||
this.sinon.spy(MockLazyLoader, 'load');
|
||||
ICEContacts.updateICEContacts().then(function() {
|
||||
sinon.assert.calledWith(MockLazyLoader.load, [iceContactsOverlay]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('Sets header overlay title', function(done) {
|
||||
ICEContacts.updateICEContacts().then(function() {
|
||||
var header = iceContactsOverlay.querySelector('header');
|
||||
assert.equal(header.dataset.l10nId, 'ice-contacts-overlay-title');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('Should init when calling updateICEContacts', function(done) {
|
||||
ICEContacts._initialized = false;
|
||||
ICEContacts.updateICEContacts().then(function() {
|
||||
assert.isTrue(ICEContacts._initialized);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('No ICE contacts', function() {
|
||||
setup(function(done) {
|
||||
navigator.mozContacts.clear();
|
||||
ICEStore.setContacts([]).then(function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('Should not show the ICE contacts bar', shouldNotShowICEContactsBar);
|
||||
});
|
||||
|
||||
suite('1 ICE contact with no telephone numbers', function() {
|
||||
var contact1;
|
||||
|
||||
setup(function(done) {
|
||||
navigator.mozContacts.clear();
|
||||
contact1 = new mozContact();
|
||||
contact1.givenName = ['ICE Contact'];
|
||||
contact1.familyName = ['1'];
|
||||
contact1.name = [contact1.givenName[0] + ' ' + contact1.familyName[0]];
|
||||
var contact1Req = navigator.mozContacts.save(contact1);
|
||||
contact1Req.onsuccess = function() {
|
||||
ICEStore.setContacts([contact1.id]).then(function() {
|
||||
done();
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
test('Should not show the ICE contacts bar', shouldNotShowICEContactsBar);
|
||||
});
|
||||
|
||||
suite('2 ICE contact with no telephone numbers', function() {
|
||||
var contact1, contact2;
|
||||
|
||||
setup(function(done) {
|
||||
navigator.mozContacts.clear();
|
||||
var iceContacts = [];
|
||||
contact1 = new mozContact();
|
||||
contact1.givenName = ['ICE Contact'];
|
||||
contact1.familyName = ['1'];
|
||||
contact1.name = [contact1.givenName[0] + ' ' + contact1.familyName[0]];
|
||||
var contact1Req = navigator.mozContacts.save(contact1);
|
||||
contact1Req.onsuccess = function() {
|
||||
iceContacts.push(contact1.id);
|
||||
if (iceContacts.length === 2) {
|
||||
ICEStore.setContacts(iceContacts).then(function() {
|
||||
done();
|
||||
});
|
||||
}
|
||||
};
|
||||
contact2 = new mozContact();
|
||||
contact2.givenName = ['ICE Contact'];
|
||||
contact2.familyName = ['2'];
|
||||
contact2.name = [contact2.givenName[0] + ' ' + contact2.familyName[0]];
|
||||
var contact2Req = navigator.mozContacts.save(contact2);
|
||||
contact2Req.onsuccess = function() {
|
||||
iceContacts.push(contact2.id);
|
||||
if (iceContacts.length === 2) {
|
||||
ICEStore.setContacts(iceContacts).then(function() {
|
||||
done();
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
test('Should not show the ICE contacts bar', function(done) {
|
||||
ICEContacts.updateICEContacts().then(function() {
|
||||
assert.ok(iceContactBar.hasAttribute('hidden'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('1 ICE contact with 1 telephone number', function() {
|
||||
var contact1;
|
||||
|
||||
setup(function(done) {
|
||||
navigator.mozContacts.clear();
|
||||
contact1 = new mozContact();
|
||||
contact1.givenName = ['ICE Contact'];
|
||||
contact1.familyName = ['1'];
|
||||
contact1.name = [contact1.givenName[0] + ' ' + contact1.familyName[0]];
|
||||
contact1.tel = [
|
||||
{
|
||||
type: ['home'],
|
||||
value: '111111111'
|
||||
}
|
||||
];
|
||||
var contact1Req = navigator.mozContacts.save(contact1);
|
||||
contact1Req.onsuccess = function() {
|
||||
ICEStore.setContacts([contact1.id]).then(function() {
|
||||
done();
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
test('Should show the ICE contacts bar', function(done) {
|
||||
ICEContacts.updateICEContacts().then(function() {
|
||||
assert.isFalse(
|
||||
iceContactBar.hasAttribute('hidden'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('Should include the ICE contact in the overlay', function(done) {
|
||||
shouldIncludeICEContacts(done, 2);
|
||||
});
|
||||
});
|
||||
|
||||
suite('1 ICE contact with 2 telephone number', function() {
|
||||
var contact1;
|
||||
|
||||
setup(function(done) {
|
||||
navigator.mozContacts.clear();
|
||||
contact1 = new mozContact();
|
||||
contact1.givenName = ['ICE Contact'];
|
||||
contact1.familyName = ['1'];
|
||||
contact1.name = [contact1.givenName[0] + ' ' + contact1.familyName[0]];
|
||||
contact1.tel = [
|
||||
{
|
||||
type: ['home'],
|
||||
value: '111111111'
|
||||
},
|
||||
{
|
||||
type: ['mobile'],
|
||||
value: '222222222'
|
||||
}
|
||||
];
|
||||
var contact1Req = navigator.mozContacts.save(contact1);
|
||||
contact1Req.onsuccess = function() {
|
||||
ICEStore.setContacts([contact1.id]).then(function() {
|
||||
done();
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
test('Should show the ICE contacts bar', function(done) {
|
||||
ICEContacts.updateICEContacts().then(function() {
|
||||
assert.isFalse(iceContactBar.hasAttribute('hidden'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('Should include the ICE contact\'s phone numbers in the overlay',
|
||||
function(done) {
|
||||
shouldIncludeICEContacts(done, 3);
|
||||
});
|
||||
});
|
||||
|
||||
suite('2 ICE contact with 3 telephone numbers the first one and 4 the ' +
|
||||
'second one', function() {
|
||||
var contact1, contact2;
|
||||
|
||||
setup(function(done) {
|
||||
navigator.mozContacts.clear();
|
||||
var iceContacts = [];
|
||||
contact1 = new mozContact();
|
||||
contact1.givenName = ['ICE Contact'];
|
||||
contact1.familyName = ['1'];
|
||||
contact1.name = [contact1.givenName[0] + ' ' + contact1.familyName[0]];
|
||||
contact1.tel = [
|
||||
{
|
||||
type: ['home'],
|
||||
value: '111111111'
|
||||
},
|
||||
{
|
||||
type: ['mobile'],
|
||||
value: '222222222'
|
||||
},
|
||||
{
|
||||
type: ['work'],
|
||||
value: '333333333'
|
||||
}
|
||||
];
|
||||
var contact1Req = navigator.mozContacts.save(contact1);
|
||||
contact1Req.onsuccess = function() {
|
||||
iceContacts.push(contact1.id);
|
||||
if (iceContacts.length === 2) {
|
||||
ICEStore.setContacts(iceContacts).then(function() {
|
||||
done();
|
||||
});
|
||||
}
|
||||
};
|
||||
contact2 = new mozContact();
|
||||
contact2.givenName = ['ICE Contact'];
|
||||
contact2.familyName = ['2'];
|
||||
contact2.name = [contact2.givenName[0] + ' ' + contact2.familyName[0]];
|
||||
contact2.tel = [
|
||||
{
|
||||
type: ['home'],
|
||||
value: '444444444'
|
||||
},
|
||||
{
|
||||
type: ['mobile'],
|
||||
value: '555555555'
|
||||
},
|
||||
{
|
||||
type: ['work'],
|
||||
value: '666666666'
|
||||
},
|
||||
{
|
||||
type: ['other'],
|
||||
value: '777777777'
|
||||
}
|
||||
];
|
||||
var contact2Req = navigator.mozContacts.save(contact2);
|
||||
contact2Req.onsuccess = function() {
|
||||
iceContacts.push(contact2.id);
|
||||
if (iceContacts.length === 2) {
|
||||
ICEStore.setContacts(iceContacts).then(function() {
|
||||
done();
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
test('Should show the ICE contacts bar', function(done) {
|
||||
ICEContacts.updateICEContacts().then(function() {
|
||||
assert.isFalse(iceContactBar.hasAttribute('hidden'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('Should include the ICE contacts\' phone numbers in the overlay',
|
||||
function(done) {
|
||||
shouldIncludeICEContacts(done, 8);
|
||||
});
|
||||
});
|
||||
|
||||
suite('Is from ICE contacts', function() {
|
||||
var contact1;
|
||||
var contact2;
|
||||
|
||||
setup(function(done) {
|
||||
navigator.mozContacts.clear();
|
||||
contact1 = new mozContact();
|
||||
contact1.givenName = ['ICE Contact'];
|
||||
contact1.familyName = ['1'];
|
||||
contact1.name = [contact1.givenName[0] + ' ' + contact1.familyName[0]];
|
||||
contact1.tel = [
|
||||
{
|
||||
type: ['home'],
|
||||
value: '123'
|
||||
}
|
||||
];
|
||||
contact2 = new mozContact();
|
||||
contact2.givenName = ['ICE Contact'];
|
||||
contact2.familyName = ['2'];
|
||||
contact2.name = [contact2.givenName[0] + ' ' + contact2.familyName[0]];
|
||||
contact2.tel = [
|
||||
{
|
||||
type: ['home'],
|
||||
value: '456'
|
||||
}
|
||||
];
|
||||
var contact1Req = navigator.mozContacts.save(contact1);
|
||||
contact1Req.onsuccess = function() {
|
||||
ICEStore.setContacts([contact1.id]).then(function() {
|
||||
done();
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
test('Should include contact1', function() {
|
||||
ICEContacts.updateICEContacts().then(function() {
|
||||
assert.isTrue(ICEContacts.isFromICEContact('123'));
|
||||
});
|
||||
});
|
||||
|
||||
test('Should not include contact2', function() {
|
||||
ICEContacts.updateICEContacts().then(function() {
|
||||
assert.isFalse(ICEContacts.isFromICEContact('456'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
suite('Should create correct DOM', function() {
|
||||
var contact1;
|
||||
|
||||
setup(function(done) {
|
||||
navigator.mozContacts.clear();
|
||||
contact1 = new mozContact();
|
||||
contact1.givenName = ['ICE Contact'];
|
||||
contact1.familyName = ['1'];
|
||||
contact1.name = [contact1.givenName[0] + ' ' + contact1.familyName[0]];
|
||||
contact1.tel = [
|
||||
{
|
||||
type: ['home'],
|
||||
value: '123'
|
||||
}
|
||||
];
|
||||
var contact1Req = navigator.mozContacts.save(contact1);
|
||||
contact1Req.onsuccess = function() {
|
||||
ICEStore.setContacts([contact1.id]).then(function() {
|
||||
ICEContacts.updateICEContacts().then(function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
test('Should include name element', function() {
|
||||
assert.equal(iceContactsOverlay.querySelector('.js-name').textContent,
|
||||
contact1.name);
|
||||
});
|
||||
|
||||
test('Should include tel-type element', function() {
|
||||
assert.equal(
|
||||
iceContactsOverlay.querySelector('.js-tel-type').dataset.l10nId,
|
||||
contact1.tel[0].type);
|
||||
});
|
||||
|
||||
test('Should include time element', function() {
|
||||
assert.equal(iceContactsOverlay.querySelector('.js-tel').textContent,
|
||||
contact1.tel[0].value);
|
||||
});
|
||||
|
||||
test('Should include cancel button', function() {
|
||||
assert.ok(
|
||||
iceContactsOverlay.querySelector('#contact-list-overlay-cancel'));
|
||||
});
|
||||
|
||||
test('Tapping a contact dials them', function() {
|
||||
this.sinon.spy(CallHandler, 'call');
|
||||
iceContactsOverlay.querySelector('button').click();
|
||||
sinon.assert.calledWith(CallHandler.call, contact1.tel[0].value);
|
||||
});
|
||||
});
|
||||
*/
|
||||
});
|
||||
243
gaia/apps/emergency-call/test/unit/keypad_test.js
Executable file
243
gaia/apps/emergency-call/test/unit/keypad_test.js
Executable file
|
|
@ -0,0 +1,243 @@
|
|||
/* globals gTonesFrequencies, KeypadManager, loadBodyHTML,
|
||||
MockIccManager, MockL10n, MockNavigatorMozTelephony,
|
||||
MockNavigatorSettings, MockSettingsListener, MocksHelper,
|
||||
MockTonePlayer
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
require('/shared/test/unit/mocks/mock_confirm_dialog.js');
|
||||
require('/shared/test/unit/mocks/mock_iccmanager.js');
|
||||
require('/shared/test/unit/mocks/mock_l10n.js');
|
||||
require('/shared/test/unit/mocks/mock_lazy_loader.js');
|
||||
require('/shared/test/unit/mocks/mock_navigator_moz_settings.js');
|
||||
require('/shared/test/unit/mocks/mock_navigator_moz_telephony.js');
|
||||
require('/shared/test/unit/mocks/mock_settings_listener.js');
|
||||
require('/shared/test/unit/mocks/dialer/mock_call.js');
|
||||
require('/shared/test/unit/mocks/dialer/mock_utils.js');
|
||||
require('/shared/test/unit/mocks/dialer/mock_tone_player.js');
|
||||
|
||||
require('/shared/js/dialer/dtmf_tone.js');
|
||||
require('/js/keypad.js');
|
||||
|
||||
|
||||
var mocksHelperForKeypad = new MocksHelper([
|
||||
'LazyLoader',
|
||||
'Utils',
|
||||
'SettingsListener',
|
||||
'TonePlayer'
|
||||
]).init();
|
||||
|
||||
suite('Keypad', function() {
|
||||
var subject;
|
||||
var realMozIccManager;
|
||||
var realMozL10n;
|
||||
var realMozSettings;
|
||||
var realMozTelephony;
|
||||
|
||||
mocksHelperForKeypad.attachTestHelpers();
|
||||
|
||||
// Dummy node used as event target
|
||||
var dummyNode = document.createElement('div');
|
||||
|
||||
/**
|
||||
* Simulate a touchstart event
|
||||
*
|
||||
* @param key {String} The target's dataset value, the touched key
|
||||
*/
|
||||
function mockTouchStart(key) {
|
||||
var fakeEvent = {
|
||||
target: dummyNode,
|
||||
preventDefault: function() {},
|
||||
stopPropagation: function() {},
|
||||
type: 'touchstart'
|
||||
};
|
||||
dummyNode.dataset.value = key;
|
||||
subject.keyHandler(fakeEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate a touchend event
|
||||
*
|
||||
* @param key {String} The target's dataset value, the touched key
|
||||
*/
|
||||
function mockTouchEnd(key) {
|
||||
var fakeEvent = {
|
||||
target: dummyNode,
|
||||
preventDefault: function() {},
|
||||
stopPropagation: function() {},
|
||||
type: 'touchend'
|
||||
};
|
||||
dummyNode.dataset.value = key;
|
||||
subject.keyHandler(fakeEvent);
|
||||
}
|
||||
|
||||
suiteSetup(function() {
|
||||
realMozIccManager = navigator.mozIccManager;
|
||||
navigator.mozIccManager = new MockIccManager();
|
||||
|
||||
realMozL10n = navigator.mozL10n;
|
||||
navigator.mozL10n = MockL10n;
|
||||
|
||||
realMozSettings = navigator.mozSettings;
|
||||
navigator.mozSettings = MockNavigatorSettings;
|
||||
MockNavigatorSettings.mSyncRepliesOnly = true;
|
||||
|
||||
realMozTelephony = navigator.mozTelephony;
|
||||
navigator.mozTelephony = MockNavigatorMozTelephony;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozIccManager = realMozIccManager;
|
||||
navigator.mozL10n = realMozL10n;
|
||||
navigator.mozSettings = realMozSettings;
|
||||
MockNavigatorSettings.mSyncRepliesOnly = false;
|
||||
MockNavigatorMozTelephony.mSuiteTeardown();
|
||||
navigator.mozTelephony = realMozTelephony;
|
||||
});
|
||||
|
||||
setup(function() {
|
||||
loadBodyHTML('/test/unit/mock_dialer_index.html');
|
||||
|
||||
dummyNode = document.createElement('div');
|
||||
|
||||
subject = KeypadManager;
|
||||
subject.init(false);
|
||||
|
||||
this.sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
dummyNode = null;
|
||||
MockNavigatorMozTelephony.mTeardown();
|
||||
});
|
||||
|
||||
suite('Keypad Manager', function() {
|
||||
test('initializates the TonePlayer to use the "system" channel',
|
||||
function() {
|
||||
this.sinon.spy(MockTonePlayer, 'init');
|
||||
KeypadManager.init(/* oncall */ false);
|
||||
|
||||
sinon.assert.calledWith(MockTonePlayer.init, 'system');
|
||||
});
|
||||
|
||||
test('sanitizePhoneNumber', function(done) {
|
||||
var testCases = {
|
||||
'111-111-1111': '111-111-1111',
|
||||
' 222-222-2222 ': '222-222-2222',
|
||||
' 333 - 333 - 3333 ': '333-333-3333',
|
||||
'4444 4444 4444': '444444444444',
|
||||
'555\n555\n5555': '5555555555',
|
||||
'666\t666\t6666': '6666666666'
|
||||
};
|
||||
|
||||
var counter = 0;
|
||||
|
||||
function verifyNumber(index) {
|
||||
return function() {
|
||||
var sanitized = subject.sanitizePhoneNumber(index);
|
||||
assert.equal(sanitized, testCases[index]);
|
||||
};
|
||||
}
|
||||
|
||||
for (var i in testCases) {
|
||||
counter++;
|
||||
test('#sanitizePhoneNumber - test case ' + counter, verifyNumber(i));
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
test('Adds active class to keys when pressed', function() {
|
||||
subject._phoneNumber = '';
|
||||
|
||||
mockTouchStart('1');
|
||||
assert.isTrue(dummyNode.classList.contains('active'));
|
||||
mockTouchEnd('1');
|
||||
assert.isFalse(dummyNode.classList.contains('active'));
|
||||
});
|
||||
|
||||
test('Multi-tap events are ignored', function() {
|
||||
mockTouchStart('1');
|
||||
assert.equal(subject._phoneNumber, '1');
|
||||
mockTouchStart('2');
|
||||
assert.equal(subject._phoneNumber, '1');
|
||||
mockTouchEnd('2');
|
||||
assert.equal(subject._phoneNumber, '1');
|
||||
mockTouchEnd('1');
|
||||
assert.equal(subject._phoneNumber, '1');
|
||||
});
|
||||
|
||||
suite('Audible and DTMF tones when composing numbers', function() {
|
||||
|
||||
setup(function() {
|
||||
subject._observePreferences();
|
||||
MockSettingsListener.mCallbacks['phone.ring.keypad'](true);
|
||||
});
|
||||
|
||||
test('Pressing a button plays a short tone', function() {
|
||||
var startSpy = this.sinon.spy(MockTonePlayer, 'start');
|
||||
var stopSpy = this.sinon.spy(MockTonePlayer, 'stop');
|
||||
|
||||
mockTouchStart('1');
|
||||
assert.isTrue(startSpy.calledWith(gTonesFrequencies['1'], true));
|
||||
mockTouchEnd('1');
|
||||
assert.isTrue(stopSpy.calledOnce);
|
||||
});
|
||||
|
||||
test('Button tones are disabled via prefs', function() {
|
||||
var startSpy = this.sinon.spy(MockTonePlayer, 'start');
|
||||
|
||||
MockSettingsListener.mCallbacks['phone.ring.keypad'](false);
|
||||
mockTouchStart('1');
|
||||
assert.isTrue(startSpy.notCalled);
|
||||
mockTouchEnd('1');
|
||||
assert.isTrue(startSpy.notCalled);
|
||||
});
|
||||
|
||||
test('Pressing a button does not play a DTMF tone', function() {
|
||||
var startToneSpy =
|
||||
this.sinon.spy(MockNavigatorMozTelephony, 'startTone');
|
||||
var stopToneSpy =
|
||||
this.sinon.spy(MockNavigatorMozTelephony, 'stopTone');
|
||||
|
||||
mockTouchStart('1');
|
||||
assert.isTrue(stopToneSpy.notCalled);
|
||||
assert.isTrue(startToneSpy.notCalled);
|
||||
});
|
||||
});
|
||||
|
||||
suite('Keypad vibration', function() {
|
||||
setup(function() {
|
||||
this.sinon.spy(navigator, 'vibrate');
|
||||
subject._observePreferences();
|
||||
});
|
||||
|
||||
test('vibrates if setting is set', function() {
|
||||
MockSettingsListener.mCallbacks['keyboard.vibration'](true);
|
||||
|
||||
mockTouchStart('1');
|
||||
sinon.assert.calledWith(navigator.vibrate, 50);
|
||||
});
|
||||
|
||||
test('does not vibrate if setting is not set', function() {
|
||||
MockSettingsListener.mCallbacks['keyboard.vibration'](false);
|
||||
|
||||
mockTouchStart('1');
|
||||
sinon.assert.notCalled(navigator.vibrate);
|
||||
});
|
||||
});
|
||||
|
||||
suite('Long press', function() {
|
||||
setup(function() {
|
||||
this.sinon.spy(window, 'setTimeout');
|
||||
});
|
||||
|
||||
test('should not try to detect the voicemail action', function() {
|
||||
mockTouchStart('1');
|
||||
sinon.assert.calledOnce(window.setTimeout);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
7
gaia/apps/emergency-call/test/unit/mock_call_handler.js
Executable file
7
gaia/apps/emergency-call/test/unit/mock_call_handler.js
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
/* exported MockCallHandler */
|
||||
|
||||
var MockCallHandler = {
|
||||
call: function() {}
|
||||
};
|
||||
80
gaia/apps/emergency-call/test/unit/mock_dialer_index.html
Executable file
80
gaia/apps/emergency-call/test/unit/mock_dialer_index.html
Executable file
|
|
@ -0,0 +1,80 @@
|
|||
<section id="keyboard-view" class="full-height">
|
||||
<div id="phone-number-view-container">
|
||||
<div class="phone-number-view-wrapper-input">
|
||||
<input id="phone-number-view" type="text" class="phone-number-font font-light" readonly="readonly" data-l10n-id="phoneNumberInput">
|
||||
<div id="fake-phone-number-view"></div>
|
||||
</div>
|
||||
<button id="keypad-delete" class="reset-button" data-value="delete" data-l10n-id="keypadDelete">
|
||||
</button>
|
||||
</div>
|
||||
<section id="ice-contacts-bar" class="ice-contacts-bar" hidden data-l10n-id="ice-contacts-bar-text">
|
||||
ICE Contacts - In Case of Emergency
|
||||
</section>
|
||||
<article id="keyboard-container">
|
||||
<section id="keypad" dir="ltr">
|
||||
<div class="keypad-row">
|
||||
<div class="keypad-key" role="key" data-value="1">
|
||||
<span>1</span>
|
||||
<em class="keypad-subicon" data-l10n-id="voiceMailKey"></em>
|
||||
</div>
|
||||
<div class="keypad-key" role="key" data-value="2">
|
||||
<span>2</span>
|
||||
<em>ABC</em>
|
||||
</div>
|
||||
<div class="keypad-key" role="key" data-value="3">
|
||||
<span>3</span>
|
||||
<em>DEF</em>
|
||||
</div>
|
||||
</div>
|
||||
<div class="keypad-row">
|
||||
<div class="keypad-key" role="key" data-value="4">
|
||||
<span>4</span>
|
||||
<em>GHI</em>
|
||||
</div>
|
||||
<div class="keypad-key" role="key" data-value="5">
|
||||
<span>5</span>
|
||||
<em>JKL</em>
|
||||
</div>
|
||||
<div class="keypad-key" role="key" data-value="6">
|
||||
<span>6</span>
|
||||
<em>MNO</em>
|
||||
</div>
|
||||
</div>
|
||||
<div class="keypad-row">
|
||||
<div class="keypad-key" role="key" data-value="7">
|
||||
<span>7</span>
|
||||
<em>PQRS</em>
|
||||
</div>
|
||||
<div class="keypad-key" role="key" data-value="8">
|
||||
<span>8</span>
|
||||
<em>TUV</em>
|
||||
</div>
|
||||
<div class="keypad-key" role="key" data-value="9">
|
||||
<span>9</span>
|
||||
<em>WXYZ</em>
|
||||
</div>
|
||||
</div>
|
||||
<div class="keypad-row">
|
||||
<div class="keypad-key" role="key" data-value="*" data-l10n-id="asterisk">
|
||||
<div class="asterisk">*</div>
|
||||
</div>
|
||||
<div class="keypad-key" role="key" data-value="0">
|
||||
<span>0</span>
|
||||
<em class="font-size-plus">+</em>
|
||||
</div>
|
||||
<div class="keypad-key" role="key" data-type="dial" data-value="#" data-l10n-id="hashSign">
|
||||
<div class="sharp">#</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<section id="keypad-callbar">
|
||||
<span role="button" id="keypad-callbar-cancel" class='keypad-callbar-button cancel' data-type="action" data-value="cancel" >
|
||||
<div data-l10n-id="cancel">Cancel</div>
|
||||
</span>
|
||||
<span role="button" id="keypad-callbar-call-action" data-type="action" data-value="make-call">
|
||||
<div>
|
||||
</div>
|
||||
</span>
|
||||
</section>
|
||||
</article>
|
||||
</section>
|
||||
7
gaia/apps/emergency-call/test/unit/mock_ice_contacts.js
Executable file
7
gaia/apps/emergency-call/test/unit/mock_ice_contacts.js
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
/* exported MockICEContacts */
|
||||
|
||||
'use strict';
|
||||
|
||||
var MockICEContacts = {
|
||||
isFromICEContact: function() {}
|
||||
};
|
||||
33
gaia/apps/emergency-call/test/unit/mock_keypad.js
Executable file
33
gaia/apps/emergency-call/test/unit/mock_keypad.js
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
/* exported MockKeypadManager */
|
||||
|
||||
var MockKeypadManager = {
|
||||
init: function() {},
|
||||
maxFontSize: 12,
|
||||
minFontSize: 8,
|
||||
formatPhoneNumber:
|
||||
function khm_formatPhoneNumber(ellipsisSide) {
|
||||
this.mFormatPhoneNumberCalled = true;
|
||||
},
|
||||
mFormatPhoneNumberCalled: false,
|
||||
updateAdditionalContactInfo:
|
||||
function khm_updateAdditionalContactInfo(ellipsisSide, maxFontSize) {
|
||||
this.mUpdateAdditionalContactInfo = true;
|
||||
},
|
||||
mUpdateAdditionalContactInfo: false,
|
||||
mTearDown: function khm_tearDown() {
|
||||
this.mFormatPhoneNumberCalled = false;
|
||||
this.mUpdateAdditionalContactInfo = false;
|
||||
},
|
||||
|
||||
mOnMakeCall: null,
|
||||
updatePhoneNumber: function khm_updatePhoneNumber(number) {
|
||||
this._phoneNumber = number;
|
||||
},
|
||||
makeCall: function makeCall() {
|
||||
if (this.mOnMakeCall) {
|
||||
this.mOnMakeCall(this._phoneNumber);
|
||||
}
|
||||
}
|
||||
};
|
||||
4
gaia/apps/emergency-call/test/unit/setup.js
Executable file
4
gaia/apps/emergency-call/test/unit/setup.js
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
require('/shared/test/unit/mocks/mocks_helper.js');
|
||||
require('/shared/test/unit/mocks/elements/custom_elements_helper.js');
|
||||
Loading…
Reference in a new issue