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 #16370 from Rik/dsds-notification-965853
Browse files Browse the repository at this point in the history
Bug 965853 - Display SIM indication in missed call notification r=etienne
  • Loading branch information
rik committed Feb 24, 2014
2 parents ba8f528 + 3826f33 commit 77e8cea
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 64 deletions.
3 changes: 2 additions & 1 deletion apps/communications/dialer/js/calls_handler.js
Expand Up @@ -213,7 +213,8 @@ var CallsHandler = (function callsHandler() {
if (call.state == 'disconnected') {
var callInfo = {
type: 'notification',
number: call.number
number: call.number,
serviceId: call.serviceId
};
postToMainWindow(callInfo);
}
Expand Down
11 changes: 8 additions & 3 deletions apps/communications/dialer/js/dialer.js
Expand Up @@ -50,11 +50,16 @@ var CallHandler = (function callHandler() {
};
}

function handleNotificationRequest(number) {
function handleNotificationRequest(number, serviceId) {
LazyLoader.load('/dialer/js/utils.js', function() {
Contacts.findByNumber(number, function lookup(contact, matchingTel) {
LazyL10n.get(function localized(_) {
var title = _('missedCall');
var title;
if (navigator.mozIccManager.iccIds.length > 1) {
title = _('missedCallMultiSim', {n: serviceId + 1});
} else {
title = _('missedCall');
}

var body;
if (!number) {
Expand Down Expand Up @@ -219,7 +224,7 @@ var CallHandler = (function callHandler() {
} else if (data.type === 'notification') {
// We're being asked to send a missed call notification
NavbarManager.ensureResources(function() {
handleNotificationRequest(data.number);
handleNotificationRequest(data.number, data.serviceId);
});
} else if (data.type === 'recent') {
NavbarManager.ensureResources(function() {
Expand Down
1 change: 1 addition & 0 deletions apps/communications/dialer/locales/dialer.en-US.properties
Expand Up @@ -31,6 +31,7 @@ ignore=Ignore Call
incoming=Incoming
missed=Missed
missedCall=Missed call
missedCallMultiSim=SIM {{ n }} - Missed call
mmi-error=An error occurred while sending the message
mmi-session-expired=Session expired
mmi-successfully-sent=Message successfully sent
Expand Down
25 changes: 25 additions & 0 deletions apps/communications/dialer/test/unit/calls_handler_test.js
Expand Up @@ -128,6 +128,31 @@ suite('calls handler', function() {
this.sinon.clock.tick(1000);
assert.isTrue(vibrateSpy.called);
});

suite('> call isn\'t picked up', function() {
setup(function() {
MockMozTelephony.mTriggerCallsChanged();
MockMozTelephony.calls = [];
MockMozTelephony.mTriggerCallsChanged();
var windowOpener = {postMessage: function() {}};
Object.defineProperty(window, 'opener', {
configurable: true,
get: function() {
return windowOpener;
}
});
this.sinon.spy(window.opener, 'postMessage');
mockCall._disconnect();
});

test('should notify the user', function() {
sinon.assert.calledWith(window.opener.postMessage, {
type: 'notification',
number: mockCall.number,
serviceId: mockCall.serviceId
});
});
});
});

suite('> hanging up the last incoming call', function() {
Expand Down
143 changes: 113 additions & 30 deletions apps/communications/dialer/test/unit/dialer_test.js
@@ -1,17 +1,51 @@
'use strict';

/* global NavbarManager */
/* global CallHandler, MocksHelper, MockLazyL10n, MockNavigatormozApps,
MockNavigatorMozIccManager, NavbarManager, Notification */

requireApp('communications/dialer/test/unit/mock_contacts.js');
requireApp('communications/dialer/test/unit/mock_l10n.js');
requireApp('communications/dialer/test/unit/mock_lazy_loader.js');
requireApp('communications/dialer/test/unit/mock_utils.js');

require('/shared/test/unit/mocks/mock_navigator_moz_apps.js');
require('/shared/test/unit/mocks/mock_navigator_moz_icc_manager.js');
require('/shared/test/unit/mocks/mock_notification.js');
require('/shared/test/unit/mocks/mock_notification_helper.js');
require('/shared/test/unit/mocks/mock_settings_listener.js');

requireApp('communications/dialer/js/dialer.js');

var mocksHelperForDialer = new MocksHelper([
'Contacts',
'LazyL10n',
'LazyLoader',
'Notification',
'NotificationHelper',
'SettingsListener',
'Utils'
]).init();

suite('navigation bar', function() {
var domContactsIframe;
var domOptionRecents;
var domOptionContacts;
var domOptionKeypad;
var domViews;

var realMozApps;
var realMozIccManager;

mocksHelperForDialer.attachTestHelpers();

setup(function() {
realMozApps = navigator.mozApps;
navigator.mozApps = MockNavigatormozApps;

realMozIccManager = navigator.mozIccManager;
navigator.mozIccManager = MockNavigatorMozIccManager;


domViews = document.createElement('section');
domViews.id = 'views';

Expand All @@ -33,53 +67,102 @@ suite('navigation bar', function() {

document.body.appendChild(domViews);

CallHandler.init();
NavbarManager.init();
});

teardown(function() {
MockNavigatorMozIccManager.mTeardown();
navigator.mozIccManager = realMozIccManager;

MockNavigatormozApps.mTeardown();
navigator.mozApps = realMozApps;

document.body.removeChild(domViews);
});

suite('> show / hide', function() {
test('NavbarManager.hide() should hide navbar', function() {
NavbarManager.hide();
suite('CallHandler', function() {
suite('> missed call notification', function() {
var notificationObject;

setup(function() {
this.sinon.spy(window, 'Notification');
MockNavigatorMozIccManager.addIcc('12345', {'cardState': 'ready'});
notificationObject = {
type: 'notification',
number: '123',
serviceId: 1
};
});

assert.isTrue(domViews.classList.contains('hide-toolbar'));
});
test('> One SIM', function(done) {
window.postMessage(notificationObject, '*');

test('NavbarManager.show() should show navbar', function() {
NavbarManager.show();
setTimeout(function() {
MockNavigatormozApps.mTriggerLastRequestSuccess();
sinon.assert.calledWith(Notification, 'missedCall');
done();
});
});

assert.isFalse(domViews.classList.contains('hide-toolbar'));
test('> Two SIMs', function(done) {
MockNavigatorMozIccManager.addIcc('6789', {
'cardState': 'ready'
});
window.postMessage(notificationObject, '*');

setTimeout(function() {
MockNavigatormozApps.mTriggerLastRequestSuccess();
sinon.assert.calledWith(Notification, 'missedCallMultiSim');
assert.deepEqual(MockLazyL10n.keys.missedCallMultiSim, {n: 2});
done();
});
});
});
});

suite('Second tap on contacts tab', function() {
test('Listens to click events', function() {
this.sinon.spy(domOptionContacts, 'addEventListener');
NavbarManager.init();
sinon.assert.calledWith(domOptionContacts.addEventListener, 'click',
NavbarManager.contactsTabTap);
});
suite('NavbarManager', function() {
suite('> show / hide', function() {
test('NavbarManager.hide() should hide navbar', function() {
NavbarManager.hide();

suite('contactsTabTap', function() {
teardown(function() {
window.location.hash = '';
assert.isTrue(domViews.classList.contains('hide-toolbar'));
});

test('only works when it is a second tap', function() {
NavbarManager.contactsTabTap();
assert.isFalse(
domContactsIframe.src.contains('/contacts/index.html#home')
);
test('NavbarManager.show() should show navbar', function() {
NavbarManager.show();

assert.isFalse(domViews.classList.contains('hide-toolbar'));
});
});

suite('Second tap on contacts tab', function() {
test('Listens to click events', function() {
this.sinon.spy(domOptionContacts, 'addEventListener');
NavbarManager.init();
sinon.assert.calledWith(domOptionContacts.addEventListener, 'click',
NavbarManager.contactsTabTap);
});

test('goes to home list', function() {
window.location.hash = '#contacts-view';
NavbarManager.contactsTabTap();
assert.isTrue(
domContactsIframe.src.contains('/contacts/index.html#home')
);
suite('contactsTabTap', function() {
teardown(function() {
window.location.hash = '';
});

test('only works when it is a second tap', function() {
NavbarManager.contactsTabTap();
assert.isFalse(
domContactsIframe.src.contains('/contacts/index.html#home')
);
});

test('goes to home list', function() {
window.location.hash = '#contacts-view';
NavbarManager.contactsTabTap();
assert.isTrue(
domContactsIframe.src.contains('/contacts/index.html#home')
);
});
});
});
});
Expand Down
6 changes: 4 additions & 2 deletions apps/communications/dialer/test/unit/handled_call_test.js
Expand Up @@ -114,7 +114,7 @@ suite('dialer/handled_call', function() {
});

test('call event listener', function() {
assert.isTrue(mockCall._listenerAdded);
assert.isTrue(mockCall._eventListeners.statechange.length > 0);
});

suite('node', function() {
Expand Down Expand Up @@ -359,6 +359,7 @@ suite('dialer/handled_call', function() {

suite('from a regular call', function() {
setup(function() {
this.sinon.spy(mockCall, 'removeEventListener');
mockCall._disconnect();
});
test('should save the recents entry', function() {
Expand All @@ -371,7 +372,8 @@ suite('dialer/handled_call', function() {
});

test('should remove listener on the call', function() {
assert.isTrue(mockCall._listenerRemoved);
sinon.assert.calledWith(mockCall.removeEventListener,
'statechange', subject);
});

test('should keep the call', function() {
Expand Down
58 changes: 35 additions & 23 deletions apps/communications/dialer/test/unit/mock_call.js
@@ -1,8 +1,15 @@
'use strict';

/* exported MockCall */

function MockCall(aNumber, aState) {
this._listenerAdded = false;
this._listenerRemoved = false;
this._eventListeners = {
'statechange': [],
'disconnected': []
};

this.number = aNumber;
this.serviceId = 1;
this.state = aState;

this.answer = function() {};
Expand All @@ -16,42 +23,31 @@ function MockCall(aNumber, aState) {
this.mVoicemailNumbers = ['123'];
this.voicemail = this.mVoicemailNumbers.indexOf(this.number) >= 0;

this.addEventListener = (function(event, handler) {
if (event == 'statechange') {
this._listenerAdded = true;
this._handler = handler;
}

if (event == 'disconnected') {
this._disconnectHandler = handler;
this.addEventListener = (function(type, handler) {
if (this._eventListeners[type]) {
this._eventListeners[type].push(handler);
}
}).bind(this);

this.removeEventListener = (function(event) {
if (event == 'statechange') {
this._listenerRemoved = true;
this.removeEventListener = (function(type, handler) {
if (this._eventListeners[type]) {
var idx = this._eventListeners[type].indexOf(handler);
this._eventListeners[type].splice(idx, 1);
}
}).bind(this);


// Mocking the events
this.mChangeState = (function(state) {
if (this._handler) {
this.state = state;
if ('handleEvent' in this._handler) {
this._handler.handleEvent({call: this});
}
}
this.state = state;
this._mTriggerEventListeners('statechange');
}).bind(this);

this._connect = this.mChangeState.bind(this, 'connected');

this._disconnect = (function() {
this.mChangeState('disconnected');

if (this._disconnectHandler) {
this._disconnectHandler();
}
this._mTriggerEventListeners('disconnected');
}).bind(this);

this._hold = (function() {
Expand All @@ -63,4 +59,20 @@ function MockCall(aNumber, aState) {
this.mChangeState('resuming');
this.mChangeState('connected');
}).bind(this);

this._mTriggerEventListeners = function(type) {
if (!this._eventListeners[type]) {
return;
}

var self = this;
this._eventListeners[type].forEach(function(callback) {
if (typeof callback === 'function') {
callback({call: self});
} else if (typeof callback == 'object' &&
typeof callback.handleEvent === 'function') {
callback.handleEvent({call: self});
}
});
};
}
4 changes: 4 additions & 0 deletions apps/communications/dialer/test/unit/mock_l10n.js
@@ -1,3 +1,7 @@
'use strict';

/* exported MockMozL10n */

var MockMozL10n = {
get: function get(key) {
return key;
Expand Down

0 comments on commit 77e8cea

Please sign in to comment.