Bug 855165 - Migrate to new Notification API and close notifications #15307
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ | |
|
||
/*global ThreadListUI, ThreadUI, Threads, SMIL, MozSmsFilter, Compose, | ||
Utils, LinkActionHandler, Contacts, Attachment, GroupView, | ||
ReportView, Utils, LinkActionHandler, Contacts, Attachment, Drafts */ | ||
ReportView, Utils, LinkActionHandler, Contacts, Attachment, Drafts, | ||
Notification */ | ||
|
||
/*exported MessageManager */ | ||
|
||
|
@@ -358,6 +359,20 @@ var MessageManager = { | |
|
||
ThreadListUI.mark(threadId, 'read'); | ||
|
||
var targetTag = 'threadId:' + threadId; | ||
Notification.get({tag: targetTag}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is untested. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you mean that it is still lacking unit tests, it's right, that even why I did not yet put any review flag: it's not finished. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just pushed some test for this. |
||
.then( | ||
function onSuccess(notifications) { | ||
for (var i = 0; i < notifications.length; i++) { | ||
notifications[i].close(); | ||
} | ||
}, | ||
function onError(reason) { | ||
console.error('Notification.get(tag: ' + targetTag + '): ' + | ||
reason); | ||
} | ||
); | ||
|
||
// Update Header | ||
ThreadUI.updateHeaderData(function headerUpdated() { | ||
if (willSlide) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
/*global Notify, Compose, mocha, MocksHelper, ActivityHandler, Contacts, | ||
MessageManager, Attachment, ThreadUI */ | ||
/*global MockNavigatormozSetMessageHandler, MockNavigatormozApps, | ||
MockNavigatorWakeLock, MockNotificationHelper, MockOptionMenu, | ||
Mockalert, MockMessages, MockNavigatorSettings, MockL10n, | ||
MockNavigatorWakeLock, MockOptionMenu, Mockalert, | ||
MockMessages, MockNavigatorSettings, MockL10n, | ||
MockNavigatormozMobileMessage */ | ||
|
||
'use strict'; | ||
|
@@ -13,6 +13,7 @@ requireApp( | |
'sms/shared/test/unit/mocks/mock_navigator_moz_set_message_handler.js' | ||
); | ||
requireApp('sms/shared/test/unit/mocks/mock_navigator_wake_lock.js'); | ||
requireApp('sms/shared/test/unit/mocks/mock_notification.js'); | ||
requireApp('sms/shared/test/unit/mocks/mock_notification_helper.js'); | ||
requireApp('sms/shared/test/unit/mocks/mock_navigator_moz_apps.js'); | ||
requireApp('sms/shared/test/unit/mocks/mock_navigator_moz_settings.js'); | ||
|
@@ -42,6 +43,7 @@ var mocksHelperForActivityHandler = new MocksHelper([ | |
'Compose', | ||
'Contacts', | ||
'MessageManager', | ||
'Notification', | ||
'NotificationHelper', | ||
'OptionMenu', | ||
'SettingsURL', | ||
|
@@ -171,21 +173,27 @@ suite('ActivityHandler', function() { | |
|
||
suite('contact retrieved (after getSelf)', function() { | ||
var contactName = '<&>'; | ||
var sendSpy; | ||
setup(function() { | ||
sendSpy = this.sinon.spy(window, 'Notification'); | ||
this.sinon.stub(Contacts, 'findByPhoneNumber') | ||
.callsArgWith(1, [{name: [contactName]}]); | ||
MockNavigatormozApps.mTriggerLastRequestSuccess(); | ||
}); | ||
|
||
test('passes contact name in plain text', function() { | ||
assert.equal(MockNotificationHelper.mTitle, contactName); | ||
sinon.assert.called(sendSpy); | ||
var notification = sendSpy.firstCall.thisValue; | ||
assert.equal(notification.title, contactName); | ||
}); | ||
}); | ||
|
||
suite('contact without name (after getSelf)', function() { | ||
var phoneNumber = '+1111111111'; | ||
var oldSender; | ||
var sendSpy; | ||
setup(function() { | ||
sendSpy = this.sinon.spy(window, 'Notification'); | ||
oldSender = message.sender; | ||
message.sender = phoneNumber; | ||
this.sinon.stub(Contacts, 'findByPhoneNumber') | ||
|
@@ -202,22 +210,26 @@ suite('ActivityHandler', function() { | |
|
||
|
||
test('phone in notification title when contact without name', function() { | ||
assert.equal(MockNotificationHelper.mTitle, phoneNumber); | ||
sinon.assert.called(sendSpy); | ||
var notification = sendSpy.firstCall.thisValue; | ||
assert.equal(notification.title, phoneNumber); | ||
}); | ||
}); | ||
|
||
suite('after getSelf', function() { | ||
var sendSpy; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're keeping the iconURL code, these tests need to be kept as well. |
||
setup(function() { | ||
sendSpy = this.sinon.spy(window, 'Notification'); | ||
MockNavigatormozApps.mTriggerLastRequestSuccess(); | ||
}); | ||
|
||
test('a notification is sent', function() { | ||
assert.equal(MockNotificationHelper.mBody, message.body); | ||
|
||
sinon.assert.called(sendSpy); | ||
var notification = sendSpy.firstCall.thisValue; | ||
assert.equal(notification.body, message.body); | ||
var expectedicon = 'sms?threadId=' + message.threadId + '&number=' + | ||
message.sender + '&id=' + message.id; | ||
|
||
assert.equal(MockNotificationHelper.mIcon, expectedicon); | ||
assert.equal(notification.icon, expectedicon); | ||
}); | ||
|
||
test('the lock is released', function() { | ||
|
@@ -226,9 +238,10 @@ suite('ActivityHandler', function() { | |
|
||
suite('click on the notification', function() { | ||
setup(function() { | ||
assert.ok(MockNotificationHelper.mClickCB); | ||
var notification = sendSpy.firstCall.thisValue; | ||
assert.ok(notification.mEvents.click); | ||
this.sinon.stub(ActivityHandler, 'handleMessageNotification'); | ||
MockNotificationHelper.mClickCB(); | ||
notification.mEvents.click(); | ||
}); | ||
|
||
test('launches the app', function() { | ||
|
@@ -289,6 +302,7 @@ suite('ActivityHandler', function() { | |
title: title, | ||
body: body, | ||
imageURL: 'url?id=' + messageId + '&threadId=' + threadId, | ||
tag: 'threadId:' + threadId, | ||
clicked: true | ||
}; | ||
|
||
|
@@ -317,6 +331,7 @@ suite('ActivityHandler', function() { | |
body: body, | ||
imageURL: 'url?id=' + messageId + '&threadId=' + threadId + | ||
'&type=class0', | ||
tag: 'threadId:' + threadId, | ||
clicked: true | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
function MockNotification(title, options) { | ||
this.id = options.id || 0; | ||
this.title = title; | ||
this.icon = options.icon || undefined; | ||
this.body = options.body || undefined; | ||
this.tag = options.tag || undefined; | ||
this.mEvents = {}; | ||
} | ||
|
||
MockNotification.prototype.close = function() { | ||
// nothing to do | ||
}; | ||
|
||
MockNotification.prototype.addEventListener = | ||
function mockNotification_addEventListener(evt, callback) { | ||
this.mEvents[evt] = callback; | ||
}; | ||
|
||
MockNotification.get = function mockNotification_get(options) { | ||
return { | ||
then: function() {} | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re: my previous question about the string value: is this why the
tag
is a string?