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 #33727 from Ilphrin/master
Browse files Browse the repository at this point in the history
Bug 1151847 - [Network Alerts][Refactoring] Use notification "data". r=azasypkin
  • Loading branch information
BavarianTomcat committed Jan 5, 2016
2 parents 0d79de5 + 1f45ff1 commit 64dd32a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
3 changes: 2 additions & 1 deletion apps/network-alerts/js/attention/attention.js
Expand Up @@ -42,7 +42,8 @@ function sendNotification() {
navigator.mozL10n.get(title), {
body: body,
tag: '' + Date.now(), // needs to be unique
icon: NotificationHelper.getIconURI(app) + '?titleID=' + title
icon: NotificationHelper.getIconURI(app),
data: { title }
}
);

Expand Down
4 changes: 1 addition & 3 deletions apps/network-alerts/js/notification/notification.js
@@ -1,5 +1,3 @@
/* global Utils */

'use strict';

(function(exports) {
Expand All @@ -18,7 +16,7 @@ function onNotification(message) {
return;
}

var title = Utils.parseParams(message.imageURL).titleID;
var title = message.data.title;

var url = [
'attention.html?title=',
Expand Down
2 changes: 1 addition & 1 deletion apps/network-alerts/test/unit/attention/attention_test.js
Expand Up @@ -107,7 +107,7 @@ suite('Network Alerts - Attention Screen', function() {

assert.equal(MockNotifications[0].title, localizedTitle);
assert.equal(MockNotifications[0].body, body);
assert.ok(MockNotifications[0].icon.endsWith('titleID=' + title));
assert.equal(MockNotifications[0].data.title, title);

sinon.assert.called(Notify.notify);
});
Expand Down
18 changes: 4 additions & 14 deletions apps/network-alerts/test/unit/notification/notification_test.js
@@ -1,27 +1,16 @@
/* global MocksHelper,
NotificationHandler,
Utils
/* global NotificationHandler
*/
'use strict';

require('/test/unit/mock_utils.js');
require('/js/notification/notification.js');

var mocksForNotification = new MocksHelper([
'Utils'
]);

suite('Network Alerts - Notification handling', function() {
mocksForNotification.attachTestHelpers();

setup(function() {
this.sinon.stub(window, 'close');
this.sinon.stub(window, 'open');
// We only need titleID after parsing, so mock parseParams that simply
// return fake titleID for testing.
this.sinon.stub(Utils, 'parseParams').returns({
titleID: 'titleID'
});

if (!window.navigator.mozSetMessageHandler) {
window.navigator.mozSetMessageHandler = function() {};
Expand All @@ -34,15 +23,16 @@ suite('Network Alerts - Notification handling', function() {
var message = {
title: 'Some title',
body: 'Some body',
clicked: true
clicked: true,
data: { title: 'Some title' }
};

var handlerStub = window.navigator.mozSetMessageHandler;
handlerStub.withArgs('notification').yield(message);

var expectedUrl = [
'attention.html?',
'title=titleID&',
'title=Some%20title&',
'body=Some%20body&',
'notification=1'
].join('');
Expand Down

0 comments on commit 64dd32a

Please sign in to comment.