Index: tests/js/polyfills/notifications.polyfill.test.js |
diff --git a/tests/js/polyfills/notifications.polyfill.test.js b/tests/js/polyfills/notifications.polyfill.test.js |
index 0e464fd78b1d83ad92cb4fcc5b0d733208f907f1..016ecd2d86a3ea0ee5fcce5807d7c48612e65ea1 100644 |
--- a/tests/js/polyfills/notifications.polyfill.test.js |
+++ b/tests/js/polyfills/notifications.polyfill.test.js |
@@ -16,12 +16,24 @@ var sandbox = sinon.sandbox.create(); |
QUnit.module('notifications', { |
beforeEach: function () { |
- this.close = sinon.spy(); |
+ var close = this.close = sinon.spy(); |
var Notification = sandbox.stub(self, 'Notification') |
- .returns({close: this.close}); |
+ .returns({close: close}); |
var requestPermission = sandbox.stub(Notification, 'requestPermission') |
.callsArg(0) // Deprecated callback. |
.returns(Promise.resolve()); |
+ this.registration = { |
+ notifications: [], |
+ showNotification: sandbox.spy(function(title, opts) { |
+ this.notifications.push({title: title, opts: opts, close: close}); |
+ return Promise.resolve(); |
+ }), |
+ getNotifications: function() { |
+ return Promise.resolve(this.notifications) |
+ }, |
+ }; |
+ chrome.caterpillar.notifications.getRegistration = sinon.stub() |
+ .returns(Promise.resolve(this.registration)); |
}, |
afterEach: function() { |
sandbox.restore(); |
@@ -30,18 +42,21 @@ QUnit.module('notifications', { |
QUnit.test('creates a minimal notification', function(assert) { |
var done = assert.async(); |
- var opts = {'type': 'basic'} |
+ var opts = {'type': 'basic'}; |
+ var showNotification = this.registration.showNotification; |
chrome.notifications.create(opts, function() { |
- assert.ok(Notification.calledOnce); |
+ assert.ok(Notification.calledOnce || showNotification.calledOnce); |
raymes
2016/02/01 00:14:23
It seems like the old Notification codepath will n
Matthew Alger
2016/02/01 00:50:42
Good idea. Done.
|
done(); |
}); |
}); |
QUnit.test('creates a notification with correct body', function(assert) { |
var done = assert.async(); |
- var opts = {'type': 'basic', 'message': 'méssage'} |
+ var opts = {'type': 'basic', 'message': 'méssage'}; |
+ var showNotification = this.registration.showNotification; |
chrome.notifications.create(opts, function() { |
- assert.equal(Notification.args[0][1].body, 'méssage'); |
+ var creator = Notification.called ? Notification : showNotification; |
+ assert.equal(creator.args[0][1].body, 'méssage'); |
done(); |
}); |
}); |
@@ -49,9 +64,11 @@ QUnit.test('creates a notification with correct body', function(assert) { |
QUnit.test('creates a notification with correct title', |
function(assert) { |
var done = assert.async(); |
- var opts = {'type': 'basic', 'title': 'títle'} |
+ var opts = {'type': 'basic', 'title': 'títle'}; |
+ var showNotification = this.registration.showNotification; |
chrome.notifications.create(opts, function() { |
- assert.equal(Notification.args[0][0], 'títle'); |
+ var creator = Notification.called ? Notification : showNotification; |
+ assert.equal(creator.args[0][0], 'títle'); |
done(); |
}); |
} |
@@ -59,9 +76,11 @@ QUnit.test('creates a notification with correct title', |
QUnit.test('creates a notification with correct ID', function(assert) { |
var done = assert.async(); |
- var opts = {'type': 'basic', 'title': 'títle'} |
+ var opts = {'type': 'basic', 'title': 'títle'}; |
+ var showNotification = this.registration.showNotification; |
chrome.notifications.create('íd', opts, function() { |
- assert.equal(Notification.args[0][1].tag, 'íd'); |
+ var creator = Notification.called ? Notification : showNotification; |
+ assert.equal(creator.args[0][1].tag, 'íd'); |
done(); |
}); |
}); |
@@ -80,9 +99,11 @@ QUnit.test('create closes notifications with same ID', function(assert) { |
QUnit.test('create generates an ID if none is provided', function(assert) { |
var done = assert.async(); |
var clear = sandbox.stub(chrome.notifications, 'clear'); |
+ var showNotification = this.registration.showNotification; |
chrome.notifications.create({'type': 'basic'}, function() { |
- assert.ok('tag' in Notification.args[0][1]); |
- assert.equal(typeof Notification.args[0][1].tag, 'string'); |
+ var creator = Notification.called ? Notification : showNotification; |
+ assert.ok('tag' in creator.args[0][1]); |
+ assert.equal(typeof creator.args[0][1].tag, 'string'); |
done(); |
}); |
}); |
@@ -97,9 +118,11 @@ QUnit.test('create requests notification permissions', function(assert) { |
QUnit.test('create appends the contextMessage to the body', function(assert) { |
var done = assert.async(); |
+ var showNotification = this.registration.showNotification; |
chrome.notifications.create({'type': 'basic', 'message': 'hello', |
'contextMessage': 'world'}, function() { |
- assert.equal(Notification.args[0][1].body, 'hello\n\nworld'); |
+ var creator = Notification.called ? Notification : showNotification; |
+ assert.equal(creator.args[0][1].body, 'hello\n\nworld'); |
done(); |
}); |
}); |
@@ -107,9 +130,11 @@ QUnit.test('create appends the contextMessage to the body', function(assert) { |
QUnit.test('create adds progress text for progress notifications', |
function(assert) { |
var done = assert.async(); |
+ var showNotification = this.registration.showNotification; |
chrome.notifications.create({'type': 'progress', 'message': 'hello', |
'progress': 15}, function() { |
- assert.equal(Notification.args[0][1].body, 'hello\n\nProgress: 15%'); |
+ var creator = Notification.called ? Notification : showNotification; |
+ assert.equal(creator.args[0][1].body, 'hello\n\nProgress: 15%'); |
done(); |
}); |
}); |
@@ -127,9 +152,11 @@ QUnit.test('create warns if an unsupported type is given', function(assert) { |
QUnit.test('creates a notification with the correct icon',function(assert) { |
var done = assert.async(); |
+ var showNotification = this.registration.showNotification; |
chrome.notifications.create({'type': 'basic', 'iconUrl': 'aURL'}, |
function() { |
- assert.equal(Notification.args[0][1].icon, 'aURL'); |
+ var creator = Notification.called ? Notification : showNotification; |
+ assert.equal(creator.args[0][1].icon, 'aURL'); |
done(); |
} |
); |