Chromium Code Reviews| 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..de103707a6de56fc3a94331a250c4c5694925883 100644 |
| --- a/tests/js/polyfills/notifications.polyfill.test.js |
| +++ b/tests/js/polyfills/notifications.polyfill.test.js |
| @@ -17,11 +17,25 @@ var sandbox = sinon.sandbox.create(); |
| QUnit.module('notifications', { |
| beforeEach: function () { |
| this.close = sinon.spy(); |
| + var close = this.close; |
|
raymes
2016/01/28 04:36:56
Can this be inlined?
Matthew Alger
2016/01/28 05:18:02
Yup. Done.
|
| 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.getRegistration = chrome.caterpillar.notifications.getRegistration; |
|
raymes
2016/01/28 04:36:56
This seems unneeded
Matthew Alger
2016/01/28 05:18:02
It was so that I could restore getRegistration lat
|
| + this.showNotification = sandbox.spy(function(title, opts) { |
| + this.notifications.push({title: title, opts: opts, close: close}); |
| + return Promise.resolve(); |
| + }); |
|
raymes
2016/01/28 04:36:56
This would be clearer if you defined:
this.registr
Matthew Alger
2016/01/28 05:18:02
Done.
|
| + chrome.caterpillar.notifications.getRegistration = sinon.stub() |
| + .returns(Promise.resolve({ |
| + notifications: [], |
| + showNotification: this.showNotification, |
| + getNotifications: function() { |
| + return Promise.resolve(this.notifications) |
| + }, |
| + })); |
| }, |
| afterEach: function() { |
| sandbox.restore(); |
| @@ -30,18 +44,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.showNotification; |
| chrome.notifications.create(opts, function() { |
| - assert.ok(Notification.calledOnce); |
| + assert.ok(Notification.calledOnce || showNotification.calledOnce); |
| 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.showNotification; |
| chrome.notifications.create(opts, function() { |
| - assert.equal(Notification.args[0][1].body, 'méssage'); |
| + var creator = Notification.called ? Notification : showNotification; |
|
raymes
2016/01/28 04:36:56
This would be simpler if we just had the one codep
Matthew Alger
2016/01/28 05:18:02
Do you mean dropping support for new Notification?
|
| + assert.equal(creator.args[0][1].body, 'méssage'); |
| done(); |
| }); |
| }); |
| @@ -49,9 +66,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.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 +78,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.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 +101,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.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 +120,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.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 +132,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.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 +154,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.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(); |
| } |
| ); |