Skip to content

Commit

Permalink
Bug 993018 - Replace the "place new call" postMessages with a WebActi…
Browse files Browse the repository at this point in the history
…vity

in order to remove a callscreen->appWindow dependency.
  • Loading branch information
etiennesegonzac committed Apr 7, 2014
1 parent 1130c4e commit 5c78a28
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 37 deletions.
14 changes: 8 additions & 6 deletions apps/communications/dialer/js/call_screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,14 @@ var CallScreen = {
},

placeNewCall: function cs_placeNewCall() {
navigator.mozApps.getSelf().onsuccess = function(evt) {
var app = evt.target.result;
CallsHandler.requestContactsTab();
app.launch('dialer');
window.resizeTo(100, 40);
};
new MozActivity({
name: 'dial',
data: {
type: 'webtelephony/number',
number: ''
}
});
window.resizeTo(100, 40);
},

render: function cs_render(layout_type) {
Expand Down
5 changes: 0 additions & 5 deletions apps/communications/dialer/js/calls_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,6 @@ var CallsHandler = (function callsHandler() {
telephony.conferenceGroup.add(telephony.active);
}

function requestContactsTab() {
postToMainWindow('request-contacts');
}

return {
setup: setup,

Expand All @@ -788,7 +784,6 @@ var CallsHandler = (function callsHandler() {
checkCalls: onCallsChanged,
mergeActiveCallWith: mergeActiveCallWith,
mergeConferenceGroupWithActiveCall: mergeConferenceGroupWithActiveCall,
requestContactsTab: requestContactsTab,
updateAllPhoneNumberDisplays: updateAllPhoneNumberDisplays,

get activeCall() {
Expand Down
9 changes: 4 additions & 5 deletions apps/communications/dialer/js/dialer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var CallHandler = (function callHandler() {
var callScreenWindow = null;
var callScreenWindowReady = false;
var btCommandsToForward = [];
var currentActivity = null;
var FB_SYNC_ERROR_PARAM = 'isSyncError';

/* === Settings === */
Expand All @@ -20,14 +19,16 @@ var CallHandler = (function callHandler() {
if (activity.source.name != 'dial')
return;

currentActivity = activity;

var number = activity.source.data.number;
if (number) {
KeypadManager.updatePhoneNumber(number, 'begin', false);
if (window.location.hash != '#keyboard-view') {
window.location.hash = '#keyboard-view';
}
} else {
if (window.location.hash != '#contacts-view') {
window.location.hash = '#contacts-view';
}
}
}

Expand Down Expand Up @@ -217,8 +218,6 @@ var CallHandler = (function callHandler() {
handleCallScreenClosing();
} else if (data === 'ready') {
handleCallScreenReady();
} else if (data == 'request-contacts') {
window.location.hash = '#contacts-view';
} else if (!data.type) {
return;
} else if (data.type === 'notification') {
Expand Down
30 changes: 11 additions & 19 deletions apps/communications/dialer/test/unit/call_screen_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
mocha.globals(['resizeTo']);

require('/shared/test/unit/mocks/mock_navigator_moz_settings.js');
require('/shared/test/unit/mocks/mock_navigator_moz_apps.js');
require('/shared/test/unit/mocks/mock_navigator_moz_telephony.js');
require('/shared/test/unit/mocks/mock_moz_activity.js');

requireApp('communications/dialer/test/unit/mock_handled_call.js');
requireApp('communications/dialer/test/unit/mock_calls_handler.js');
Expand All @@ -18,13 +18,13 @@ if (!this.CallScreen) {

var mocksHelperForCallScreen = new MocksHelper([
'CallsHandler',
'MozActivity',
'LazyL10n'
]).init();


suite('call screen', function() {
var realMozTelephony;
var realMozApps;

var screen;
var container;
Expand All @@ -51,16 +51,12 @@ suite('call screen', function() {
realMozTelephony = navigator.mozTelephony;
navigator.mozTelephony = MockNavigatorMozTelephony;

realMozApps = navigator.mozApps;
navigator.mozApps = MockNavigatormozApps;

navigator.mozL10n = MockMozL10n;
});

suiteTeardown(function() {
MockNavigatorMozTelephony.mSuiteTeardown();
navigator.mozTelephony = realMozTelephony;
navigator.mozApps = realMozApps;
});

setup(function(done) {
Expand Down Expand Up @@ -156,7 +152,6 @@ suite('call screen', function() {

teardown(function() {
MockNavigatorMozTelephony.mTeardown();
MockNavigatormozApps.mTeardown();
screen.parentNode.removeChild(screen);
});

Expand Down Expand Up @@ -714,24 +709,21 @@ suite('call screen', function() {
});

suite('placeNewCall', function() {
test('launches the dialer app', function() {
CallScreen.placeNewCall();
MockNavigatormozApps.mTriggerLastRequestSuccess();
assert.equal(MockNavigatormozApps.mAppWasLaunchedWithEntryPoint,
'dialer');
});

test('requests the contacts tab in the dialer app', function() {
var requestSpy = this.sinon.spy(MockCallsHandler, 'requestContactsTab');
test('launches the dialer app with an empty dial activity', function() {
CallScreen.placeNewCall();
MockNavigatormozApps.mTriggerLastRequestSuccess();
assert.isTrue(requestSpy.calledOnce);
var activity = MockMozActivity.calls[0];
assert.deepEqual(activity, {
name: 'dial',
data: {
type: 'webtelephony/number',
number: ''
}
});
});

test('resizes the call screen in status bar mode', function() {
var resizeSpy = this.sinon.spy(window, 'resizeTo');
CallScreen.placeNewCall();
MockNavigatormozApps.mTriggerLastRequestSuccess();
assert.equal(resizeSpy.firstCall.args[1], 40);
});
});
Expand Down
66 changes: 65 additions & 1 deletion apps/communications/dialer/test/unit/dialer_test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
'use strict';

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

require(
'/shared/test/unit/mocks/mock_navigator_moz_set_message_handler.js'
);
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_keypad.js');
requireApp('communications/dialer/test/unit/mock_utils.js');

require('/shared/test/unit/mocks/mock_accessibility_helper.js');
Expand All @@ -22,6 +27,7 @@ var mocksHelperForDialer = new MocksHelper([
'Contacts',
'LazyL10n',
'LazyLoader',
'KeypadManager',
'Notification',
'NotificationHelper',
'SettingsListener',
Expand All @@ -37,6 +43,7 @@ suite('navigation bar', function() {

var realMozApps;
var realMozIccManager;
var realSetMessageHandler;

mocksHelperForDialer.attachTestHelpers();

Expand All @@ -47,6 +54,9 @@ suite('navigation bar', function() {
realMozIccManager = navigator.mozIccManager;
navigator.mozIccManager = MockNavigatorMozIccManager;

realSetMessageHandler = navigator.mozSetMessageHandler;
navigator.mozSetMessageHandler = MockNavigatormozSetMessageHandler;
MockNavigatormozSetMessageHandler.mSetup();

domViews = document.createElement('section');
domViews.id = 'views';
Expand Down Expand Up @@ -77,6 +87,9 @@ suite('navigation bar', function() {
MockNavigatorMozIccManager.mTeardown();
navigator.mozIccManager = realMozIccManager;

MockNavigatormozSetMessageHandler.mTeardown();
navigator.mozSetMessageHandler = realSetMessageHandler;

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

Expand Down Expand Up @@ -136,6 +149,57 @@ suite('navigation bar', function() {
window.postMessage(notificationObject, '*');
});
});

suite('> WebActivities support', function() {
var activity;
var originalHash;

function triggerActivity(activity) {
MockNavigatormozSetMessageHandler.mTrigger('activity', activity);
}

setup(function() {
originalHash = window.location.hash;

activity = {
source: {
name: 'dial',
data: {
type: 'webtelephony/number',
number: '12345'
}
}
};
});

teardown(function() {
window.location.hash = originalHash;
});

suite('> dial activity with a number', function() {
test('should fill the phone number view', function() {
var spy = this.sinon.spy(MockKeypadManager, 'updatePhoneNumber');
triggerActivity(activity);
sinon.assert.calledWith(spy, '12345', 'begin', false);
});

test('should show the keypad view', function() {
triggerActivity(activity);
assert.equal(window.location.hash, '#keyboard-view');
});
});

suite('> dial without a number', function() {
setup(function() {
activity.source.data.number = '';
});

test('should show the contacts view', function() {
triggerActivity(activity);
assert.equal(window.location.hash, '#contacts-view');
});
});
});
});

suite('NavbarManager', function() {
Expand Down
1 change: 0 additions & 1 deletion apps/communications/dialer/test/unit/mock_calls_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ var MockCallsHandler = {
checkCalls: function() {},
mergeActiveCallWith: function() {},
mergeConferenceGroupWithActiveCall: function() {},
requestContactsTab: function() {},
end: function() {},
answer: function() {},
updateAllPhoneNumberDisplays: function() {},
Expand Down

0 comments on commit 5c78a28

Please sign in to comment.