Chromium Code Reviews| Index: remoting/webapp/base/js/ipc_unittest.js |
| diff --git a/remoting/webapp/base/js/ipc_unittest.js b/remoting/webapp/base/js/ipc_unittest.js |
| index e786147e50933e2f64e4e70155cbb72b0d6f3644..02bc63b7ec9a67b1777cd2435c924d6477251693 100644 |
| --- a/remoting/webapp/base/js/ipc_unittest.js |
| +++ b/remoting/webapp/base/js/ipc_unittest.js |
| @@ -9,22 +9,12 @@ |
| /** @type {base.Ipc} */ |
| var ipc_; |
| -function pass() { |
| - ok(true); |
| - QUnit.start(); |
| -} |
| - |
| -function fail() { |
| - ok(false); |
| - QUnit.start(); |
| -} |
| - |
| -module('base.Ipc', { |
| - setup: function() { |
| +QUnit.module('base.Ipc', { |
| + beforeEach: function() { |
| chromeMocks.activate(['runtime']); |
| ipc_ = base.Ipc.getInstance(); |
| }, |
| - teardown: function() { |
| + afterEach: function() { |
| base.Ipc.deleteInstance(); |
| ipc_ = null; |
| chromeMocks.restore(); |
| @@ -40,7 +30,7 @@ QUnit.test( |
| QUnit.equal(false, ipc_.register('foo', handler2)); |
| }); |
| -QUnit.asyncTest( |
| +QUnit.test( |
| 'send() should invoke a registered handler with the correct arguments', |
| function() { |
| var handler = sinon.spy(); |
| @@ -51,66 +41,70 @@ QUnit.asyncTest( |
| }; |
| ipc_.register('foo', handler); |
| - base.Ipc.invoke('foo', 1, false, 'string', argArray, argDict).then( |
| + return base.Ipc.invoke('foo', 1, false, 'string', argArray, argDict).then( |
| function() { |
| sinon.assert.calledWith(handler, 1, false, 'string', argArray, argDict); |
| - pass(); |
| - }, fail); |
| + }); |
|
John Williams
2015/03/17 19:22:37
Nit: put the closing '}' in the same comlumn as th
|
| }); |
| -QUnit.asyncTest( |
| +QUnit.test( |
| 'send() should not invoke a handler that is unregistered', |
| function() { |
| var handler = sinon.spy(); |
| ipc_.register('foo', handler); |
| ipc_.unregister('foo'); |
| - base.Ipc.invoke('foo', 'hello', 'world').then(fail, function(error) { |
| + return base.Ipc.invoke('foo', 'hello', 'world').then(function() { |
| + QUnit.ok(false, 'Invoking an unregistered handler should fail.'); |
| + }).catch(function(error) { |
| sinon.assert.notCalled(handler); |
| QUnit.equal(error, base.Ipc.Error.UNSUPPORTED_REQUEST_TYPE); |
| - pass(); |
| }); |
| }); |
| -QUnit.asyncTest( |
| +QUnit.test( |
| 'send() should raise exceptions on unknown request types', |
| function() { |
| var handler = sinon.spy(); |
| ipc_.register('foo', handler); |
| - base.Ipc.invoke('bar', 'hello', 'world').then(fail, function(error) { |
| + return base.Ipc.invoke('bar', 'hello', 'world').then(function() { |
| + QUnit.ok(false, 'Invoking unknown request types should fail.'); |
| + }).catch(function(error) { |
| QUnit.equal(error, base.Ipc.Error.UNSUPPORTED_REQUEST_TYPE); |
| - pass(); |
| }); |
| }); |
| -QUnit.asyncTest( |
| +QUnit.test( |
| 'send() should raise exceptions on request from another extension', |
| function() { |
| var handler = sinon.spy(); |
| var oldId = chrome.runtime.id; |
| ipc_.register('foo', handler); |
| chrome.runtime.id = 'foreign-extension'; |
| - base.Ipc.invoke('foo', 'hello', 'world').then(fail, function(error) { |
| + var promise = base.Ipc.invoke('foo', 'hello', 'world').then(function() { |
| + QUnit.ok(false, 'Requests from another extension should fail.'); |
| + }).catch(function(error) { |
| QUnit.equal(error, base.Ipc.Error.INVALID_REQUEST_ORIGIN); |
| - pass(); |
| }); |
| chrome.runtime.id = oldId; |
| + return promise; |
| }); |
| -QUnit.asyncTest( |
| +QUnit.test( |
| 'send() should pass exceptions raised by the handler to the caller', |
| function() { |
| var handler = function() { |
| throw new Error('Whatever can go wrong, will go wrong.'); |
| }; |
| ipc_.register('foo', handler); |
| - base.Ipc.invoke('foo').then(fail, function(error) { |
| + return base.Ipc.invoke('foo').then(function() { |
| + QUnit.ok(false, 'Exceptions expected.'); |
| + }).catch(function(error) { |
| QUnit.equal(error, 'Whatever can go wrong, will go wrong.'); |
| - pass(); |
| }); |
| }); |
| -QUnit.asyncTest( |
| +QUnit.test( |
| 'send() should pass the return value of the handler to the caller', |
| function() { |
| var handlers = { |
| @@ -127,14 +121,13 @@ QUnit.asyncTest( |
| testCases.push(base.Ipc.invoke(ipcName)); |
| } |
| - Promise.all(testCases).then(function(results){ |
| + return Promise.all(testCases).then(function(results){ |
| QUnit.equal(results[0], false); |
| QUnit.equal(results[1], 12); |
| QUnit.equal(results[2], 'string'); |
| QUnit.deepEqual(results[3], [1,2]); |
| QUnit.deepEqual(results[4], {key1: 'value1', key2: 'value2'}); |
| - pass(); |
| - }, fail); |
| + }); |
| }); |
| })(); |