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 #11063 from steveck-chung/bug-891785
Browse files Browse the repository at this point in the history
Bug 891785 - [MMS] smil.parse doesn't work well if message.attachments is null. r=gnarf
  • Loading branch information
steveck-chung committed Jul 23, 2013
2 parents 8574aee + 3a89d59 commit 94bd919
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 2 deletions.
12 changes: 12 additions & 0 deletions apps/sms/js/desktop_sms_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,18 @@
subject: 'Error download',
timestamp: new Date(Date.now() - 150000),
expiryDate: new Date(Date.now() - ONE_DAY_TIME)
},
{
threadId: 8,
sender: '123456',
type: 'mms',
delivery: 'received',
deliveryStatus: ['success'],
subject: 'No attachment error',
smil: '<smil><body><par><text src="text1"/></par></body></smil>',
attachments: null,
timestamp: new Date(Date.now() - 150000),
expiryDate: new Date(Date.now() + ONE_DAY_TIME)
}
],
threads: [
Expand Down
19 changes: 18 additions & 1 deletion apps/sms/js/thread_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,12 @@ var ThreadUI = global.ThreadUI = {
var classNames = ['message', message.type, delivery];

var notDownloaded = delivery === 'not-downloaded';
var attachments = message.attachments;
// Returning attachments would be different based on gecko version:
// null in b2g18 / empty array in master.
var noAttachment = (message.type === 'mms' && !notDownloaded &&
(attachments === null || attachments.length === 0));
var _ = navigator.mozL10n.get;

if (delivery === 'received' || notDownloaded) {
classNames.push('incoming');
Expand All @@ -1089,6 +1095,11 @@ var ThreadUI = global.ThreadUI = {
bodyHTML = this._createNotDownloadedHTML(message, classNames);
}

if (noAttachment) {
classNames = classNames.concat(['error', 'no-attachment']);
bodyHTML = Utils.escapeHTML(_('no-attachment-text'));
}

messageDOM.className = classNames.join(' ');
messageDOM.id = 'message-' + message.id;
messageDOM.dataset.messageId = message.id;
Expand All @@ -1100,7 +1111,7 @@ var ThreadUI = global.ThreadUI = {
safe: ['bodyHTML']
});

if (message.type === 'mms' && !notDownloaded) { // MMS
if (message.type === 'mms' && !notDownloaded && !noAttachment) { // MMS
var pElement = messageDOM.querySelector('p');
SMIL.parse(message, function(slideArray) {
pElement.appendChild(ThreadUI.createMmsContent(slideArray));
Expand Down Expand Up @@ -1306,6 +1317,12 @@ var ThreadUI = global.ThreadUI = {
return;
}

// Do nothing for no attachment error because it's not possible to
// retrieve message again in this edge case.
if (elems.message.classList.contains('no-attachment')) {
return;
}

// Click events originating from a "pack-end" aside of an error message
// should trigger a prompt for retransmission.
if (elems.message.classList.contains('error') && elems.packEnd) {
Expand Down
1 change: 1 addition & 0 deletions apps/sms/locales/sms.en-US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,5 @@ downloading = downloading
unnamed-attachment = untitled
file-too-large = The file you have selected is too large
resize-image = Resizing the attached image
no-attachment-text = There is a problem with the attached file and it cannot be downloaded.

114 changes: 113 additions & 1 deletion apps/sms/test/unit/thread_ui_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,6 @@ suite('thread_ui.js >', function() {
suite('expired message', function() {
var message = testMessages[3];
var element;
var element;
var notDownloadedMessage;
var button;
setup(function() {
Expand Down Expand Up @@ -1262,6 +1261,119 @@ suite('thread_ui.js >', function() {
});
});

suite('No attachment error handling', function() {
var testMessages = [{
id: 1,
threadId: 8,
sender: '123456',
type: 'mms',
delivery: 'received',
deliveryStatus: ['success'],
subject: 'No attachment testing',
smil: '<smil><body><par><text src="cid:1"/>' +
'</par></body></smil>',
attachments: null,
timestamp: new Date(Date.now() - 150000),
expiryDate: new Date(Date.now())
},
{
id: 2,
threadId: 8,
sender: '123456',
type: 'mms',
delivery: 'received',
deliveryStatus: ['success'],
subject: 'Empty attachment testing',
smil: '<smil><body><par><text src="cid:1"/>' +
'</par></body></smil>',
attachments: [],
timestamp: new Date(Date.now() - 100000),
expiryDate: new Date(Date.now())
}];
setup(function() {
this.sinon.stub(Utils.date.format, 'localeFormat', function() {
return 'date_stub';
});
this.sinon.stub(MessageManager, 'retrieveMMS', function() {
return {};
});
});

suite('no attachment message', function() {
var message = testMessages[0];
var element;
var noAttachmentMessage;
setup(function() {
ThreadUI.appendMessage(message);
element = document.getElementById('message-' + message.id);
noAttachmentMessage = element.querySelector('p');
});
test('element has correct data-message-id', function() {
assert.equal(element.dataset.messageId, message.id);
});
test('no-attachment class present', function() {
assert.isTrue(element.classList.contains('no-attachment'));
});
test('error class present', function() {
assert.isTrue(element.classList.contains('error'));
});
test('pending class absent', function() {
assert.isFalse(element.classList.contains('pending'));
});
test('message is correct', function() {
assert.equal(noAttachmentMessage.textContent,
'no-attachment-text');
});
suite('clicking', function() {
setup(function() {
ThreadUI.handleMessageClick({
target: element
});
});
test('Should not call retrieveMMS', function() {
assert.isFalse(MessageManager.retrieveMMS.called);
});
});
});

suite('Empty attachment message', function() {
var message = testMessages[1];
var element;
var noAttachmentMessage;
setup(function() {
ThreadUI.appendMessage(message);
element = document.getElementById('message-' + message.id);
noAttachmentMessage = element.querySelector('p');
});
test('element has correct data-message-id', function() {
assert.equal(element.dataset.messageId, message.id);
});
test('no-attachment class present', function() {
assert.isTrue(element.classList.contains('no-attachment'));
});
test('error class present', function() {
assert.isTrue(element.classList.contains('error'));
});
test('pending class absent', function() {
assert.isFalse(element.classList.contains('pending'));
});
test('message is correct', function() {
assert.equal(noAttachmentMessage.textContent,
'no-attachment-text');
});
suite('clicking', function() {
setup(function() {
ThreadUI.handleMessageClick({
target: element
});
});
test('Should not call retrieveMMS', function() {
assert.isFalse(MessageManager.retrieveMMS.called);
});
});
});
});

suite('resendMessage', function() {
setup(function() {
this.receivers = ['1234'];
Expand Down

0 comments on commit 94bd919

Please sign in to comment.