Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Unified Diff: remoting/webapp/base/js/ipc_unittest.js

Issue 1017613002: Migrate Remoting Webapp Unittests to use QUnit 2.0 syntax. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Async test migration Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..6a00e93969b1b2e727b1427fd23651ec034e8877 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);
+ });
});
-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);
Jamie 2015/03/17 17:57:15 ok(false) is not very useful without an associated
kelvinp 2015/03/17 18:13:58 Done.
+ }).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);
+ }).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);
+ }).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);
+ }).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);
+ });
});
})();

Powered by Google App Engine
This is Rietveld 408576698