Skip to content

Commit

Permalink
Bug 876003 - [MMS] Sending mms to unknown contact via activity will l…
Browse files Browse the repository at this point in the history
…ose the number - r=gnarf

Closes mozilla-b2ggh-9996

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron authored and gnarf committed May 29, 2013
1 parent 6929757 commit fc32391
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 20 deletions.
43 changes: 33 additions & 10 deletions apps/sms/js/activity_handler.js
Expand Up @@ -59,7 +59,7 @@ var ActivityHandler = {
};
}

ActivityHandler.showThreadFromSystemMessage({
ActivityHandler.toView({
body: body,
number: number,
contact: contact || null
Expand Down Expand Up @@ -103,23 +103,46 @@ var ActivityHandler = {
// For "new" message activities, proceed directly to
// new message composition view.
if (!message.threadId && message.number) {
ActivityHandler.showThreadFromSystemMessage(message);
ActivityHandler.toView(message);
return;
}

var request = navigator.mozMobileMessage.getMessage(message.id);

request.onsuccess = function onsuccess() {
ActivityHandler.showThreadFromSystemMessage(message);
ActivityHandler.toView(message);
};

request.onerror = function onerror() {
alert(navigator.mozL10n.get('deleted-sms'));
};
},

showThreadFromSystemMessage:
function ah_showThreadFromSystemMessage(message) {
// Deliver the user to the correct view
// based on the params provided in the
// "message" object.
//
toView: function ah_toView(message) {
/**
* "message" is either a message object that belongs
* to a thread, or a message object from the system.
*
*
* message {
* number: A string phone number to pre-populate
* the recipients list with.
*
* body: An optional body to preset the compose
* input with.
*
* contact: An optional "contact" object
*
* threadId: An option threadId corresponding
* to a new or existing thread.
*
* }
*/

if (!message) {
return;
}
Expand All @@ -130,7 +153,7 @@ var ActivityHandler = {
var contact = message.contact ? message.contact : null;
var threadHash = '#thread=' + threadId;

var showAction = function act_action(number) {
var showAction = function act_action() {
// If we only have a body, just trigger a new message.
if (!threadId) {
MessageManager.activity.body = body || null;
Expand All @@ -151,7 +174,7 @@ var ActivityHandler = {
break;
case '#edit':
history.back();
showAction(threadId);
showAction();
break;
default:
if (locationHash.indexOf('#thread=') !== -1) {
Expand All @@ -173,18 +196,18 @@ var ActivityHandler = {

if (!document.documentElement.lang) {
navigator.mozL10n.ready(function waitLocalized() {
showAction(threadId);
showAction();
});
} else {
if (!document.mozHidden) {
// Case of calling from Notification
showAction(threadId);
showAction();
return;
}
document.addEventListener('mozvisibilitychange',
function waitVisibility() {
document.removeEventListener('mozvisibilitychange', waitVisibility);
showAction(threadId);
showAction();
});
}
},
Expand Down
45 changes: 36 additions & 9 deletions apps/sms/test/unit/activity_handler_test.js
Expand Up @@ -8,13 +8,16 @@ requireApp(
requireApp('sms/shared/test/unit/mocks/mock_navigator_wake_lock.js');
requireApp('sms/shared/test/unit/mocks/mock_notification_helper.js');
requireApp('sms/shared/test/unit/mocks/mock_navigator_moz_apps.js');

requireApp('sms/test/unit/mock_l10n.js');
requireApp('sms/test/unit/mock_alert.js');
requireApp('sms/test/unit/mock_attachment.js');
requireApp('sms/test/unit/mock_black_list.js');
requireApp('sms/test/unit/mock_compose.js');
requireApp('sms/test/unit/mock_contacts.js');
requireApp('sms/test/unit/mock_messages.js');
requireApp('sms/test/unit/mock_black_list.js');
requireApp('sms/test/unit/mock_message_manager.js');
requireApp('sms/test/unit/mock_threads.js');
requireApp('sms/test/unit/mock_contacts.js');
requireApp('sms/test/unit/mock_alert.js');

requireApp('sms/js/utils.js');
requireApp('sms/test/unit/mock_utils.js');
Expand All @@ -23,19 +26,18 @@ requireApp('sms/js/activity_handler.js');

var mocksHelperForActivityHandler = new MocksHelper([
'Attachment',
'Compose',
'BlackList',
'Threads',
'Compose',
'Contacts',
'Utils',
'MessageManager',
'NotificationHelper',
'Threads',
'Utils',
'alert'
]).init();

suite('ActivityHandler', function() {
var mocksHelper = mocksHelperForActivityHandler;

mocksHelper.attachTestHelpers();
mocksHelperForActivityHandler.attachTestHelpers();

var realSetMessageHandler;
var realWakeLock;
Expand Down Expand Up @@ -234,4 +236,29 @@ suite('ActivityHandler', function() {
});
});

suite('"new" activity', function() {
var realMozL10n;

suiteSetup(function() {
realMozL10n = navigator.mozL10n;
navigator.mozL10n = MockL10n;
});
suiteTeardown(function() {
navigator.mozL10n = realMozL10n;
});
test('new message to unknown contact', function(done) {
window.onhashchange = function() {
assert.equal(window.location.hash, '#new');
assert.equal(MessageManager.activity.number, '999');
assert.equal(MessageManager.activity.body, 'foo');
window.onhashchange = null;
done();
};

ActivityHandler.toView({
body: 'foo',
number: '999'
});
});
});
});
3 changes: 3 additions & 0 deletions apps/sms/test/unit/mock_l10n.js
Expand Up @@ -17,6 +17,9 @@
}
return key;
},
ready: function ready(handler) {
setTimeout(handler);
},
DateTimeFormat: DateTimeFormat
};

Expand Down
12 changes: 11 additions & 1 deletion apps/sms/test/unit/mock_message_manager.js
Expand Up @@ -2,5 +2,15 @@

var MockMessageManager = {
getMessages: function() {},
deleteMessage: function() {}
deleteMessage: function() {},
mSetup: function() {
this.activity = {
body: null,
number: null,
contact: null,
recipients: null,
threadId: null,
isLocked: false
};
}
};

0 comments on commit fc32391

Please sign in to comment.