summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorkelvinp <kelvinp@chromium.org>2015-03-17 15:27:39 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-17 22:28:10 +0000
commit831563d9c72e009bdae47c174421da85faad3aa6 (patch)
treead8c087aa23047ae7c65cd2b294e910a30414ef8 /remoting
parent062b1514d0077f522db152400641be3b955abdb7 (diff)
downloadchromium_src-831563d9c72e009bdae47c174421da85faad3aa6.zip
chromium_src-831563d9c72e009bdae47c174421da85faad3aa6.tar.gz
chromium_src-831563d9c72e009bdae47c174421da85faad3aa6.tar.bz2
Migrate remoting webapp unittests to use QUnit 2.0 syntax.
Summary of changes: Global renaming: test => QUnit.test() equal => assert.equal() notEqual => assert.notEqual() deepEqual=> assert.deepEqual() ok => assert.ok() module => QUnit.module() setup => beforeEach teardown => afterEach Async test migration: asyncTest => QUnit.test(function(assert) { ... }); QUnit.start() => var done = assert.async(); done(); return promise directly for async tests. BUG=467817 Review URL: https://codereview.chromium.org/1017613002 Cr-Commit-Position: refs/heads/master@{#320996}
Diffstat (limited to 'remoting')
-rw-r--r--remoting/webapp/base/js/base_event_hook_unittest.js10
-rw-r--r--remoting/webapp/base/js/base_unittest.js198
-rw-r--r--remoting/webapp/base/js/ipc_unittest.js95
-rw-r--r--remoting/webapp/crd/js/apps_v2_migration_unittest.js66
-rw-r--r--remoting/webapp/crd/js/desktop_viewport_unittest.js138
-rw-r--r--remoting/webapp/crd/js/dns_blackhole_checker_unittest.js47
-rw-r--r--remoting/webapp/crd/js/error_unittest.js85
-rw-r--r--remoting/webapp/crd/js/fallback_signal_strategy_unittest.js243
-rw-r--r--remoting/webapp/crd/js/host_table_entry_unittest.js65
-rw-r--r--remoting/webapp/crd/js/identity_unittest.js47
-rw-r--r--remoting/webapp/crd/js/l10n_unittest.js43
-rw-r--r--remoting/webapp/crd/js/menu_button_unittest.js43
-rw-r--r--remoting/webapp/crd/js/xhr_unittest.js192
-rw-r--r--remoting/webapp/crd/js/xmpp_connection_unittest.js61
-rw-r--r--remoting/webapp/crd/js/xmpp_login_handler_unittest.js15
-rw-r--r--remoting/webapp/crd/js/xmpp_stream_parser_unittest.js23
-rw-r--r--remoting/webapp/js_proto/qunit_proto.js71
-rw-r--r--remoting/webapp/unittests/spy_promise_unittest.js176
18 files changed, 811 insertions, 807 deletions
diff --git a/remoting/webapp/base/js/base_event_hook_unittest.js b/remoting/webapp/base/js/base_event_hook_unittest.js
index bbbc7ef..d8523f7 100644
--- a/remoting/webapp/base/js/base_event_hook_unittest.js
+++ b/remoting/webapp/base/js/base_event_hook_unittest.js
@@ -48,15 +48,15 @@ function raiseAllEvents() {
eventSource.raiseEvent('customEvent');
}
-module('base.EventHook', {
- setup: function() {
+QUnit.module('base.EventHook', {
+ beforeEach: function() {
domElement = /** @type {HTMLElement} */ (document.createElement('div'));
eventSource = new base.EventSourceImpl();
eventSource.defineEvents(['customEvent']);
myChromeEvent = new chromeMocks.Event();
listener = new Listener(domElement);
},
- tearDown: function() {
+ afterEach: function() {
domElement = null;
eventSource = null;
myChromeEvent = null;
@@ -64,7 +64,7 @@ module('base.EventHook', {
}
});
-test('EventHook should hook events when constructed', function() {
+QUnit.test('EventHook should hook events when constructed', function() {
raiseAllEvents();
sinon.assert.calledOnce(listener.onClickEvent);
sinon.assert.calledOnce(listener.onChromeEvent);
@@ -72,7 +72,7 @@ test('EventHook should hook events when constructed', function() {
listener.dispose();
});
-test('EventHook should unhook events when disposed', function() {
+QUnit.test('EventHook should unhook events when disposed', function() {
listener.dispose();
raiseAllEvents();
sinon.assert.notCalled(listener.onClickEvent);
diff --git a/remoting/webapp/base/js/base_unittest.js b/remoting/webapp/base/js/base_unittest.js
index a5a6a6f..eb7116d 100644
--- a/remoting/webapp/base/js/base_unittest.js
+++ b/remoting/webapp/base/js/base_unittest.js
@@ -6,19 +6,19 @@
'use strict';
-module('base');
+QUnit.module('base');
-test('mix(dest, src) should copy properties from |src| to |dest|',
- function() {
+QUnit.test('mix(dest, src) should copy properties from |src| to |dest|',
+ function(assert) {
var src = { a: 'a', b: 'b'};
var dest = { c: 'c'};
base.mix(dest, src);
- deepEqual(dest, {a: 'a', b: 'b', c: 'c'});
+ assert.deepEqual(dest, {a: 'a', b: 'b', c: 'c'});
});
-test('mix(dest, src) should assert if properties are overwritten',
- function() {
+QUnit.test('mix(dest, src) should assert if properties are overwritten',
+ function(assert) {
var src = { a: 'a', b: 'b'};
var dest = { a: 'a'};
@@ -33,45 +33,45 @@ test('mix(dest, src) should assert if properties are overwritten',
}
});
-test('values(obj) should return an array containing the values of |obj|',
- function() {
+QUnit.test('values(obj) should return an array containing the values of |obj|',
+ function(assert) {
var output = base.values({ a: 'a', b: 'b'});
- notEqual(output.indexOf('a'), -1, '"a" should be in the output');
- notEqual(output.indexOf('b'), -1, '"b" should be in the output');
+ assert.notEqual(output.indexOf('a'), -1, '"a" should be in the output');
+ assert.notEqual(output.indexOf('b'), -1, '"b" should be in the output');
});
-test('deepCopy(obj) should return null on NaN and undefined',
- function() {
- QUnit.equal(base.deepCopy(NaN), null);
- QUnit.equal(base.deepCopy(undefined), null);
+QUnit.test('deepCopy(obj) should return null on NaN and undefined',
+ function(assert) {
+ assert.equal(base.deepCopy(NaN), null);
+ assert.equal(base.deepCopy(undefined), null);
});
-test('deepCopy(obj) should copy primitive types recursively',
- function() {
- QUnit.equal(base.deepCopy(1), 1);
- QUnit.equal(base.deepCopy('hello'), 'hello');
- QUnit.equal(base.deepCopy(false), false);
- QUnit.equal(base.deepCopy(null), null);
- QUnit.deepEqual(base.deepCopy([1, 2]), [1, 2]);
- QUnit.deepEqual(base.deepCopy({'key': 'value'}), {'key': 'value'});
- QUnit.deepEqual(base.deepCopy(
+QUnit.test('deepCopy(obj) should copy primitive types recursively',
+ function(assert) {
+ assert.equal(base.deepCopy(1), 1);
+ assert.equal(base.deepCopy('hello'), 'hello');
+ assert.equal(base.deepCopy(false), false);
+ assert.equal(base.deepCopy(null), null);
+ assert.deepEqual(base.deepCopy([1, 2]), [1, 2]);
+ assert.deepEqual(base.deepCopy({'key': 'value'}), {'key': 'value'});
+ assert.deepEqual(base.deepCopy(
{'key': {'key_nested': 'value_nested'}}),
{'key': {'key_nested': 'value_nested'}}
);
- QUnit.deepEqual(base.deepCopy([1, [2, [3]]]), [1, [2, [3]]]);
+ assert.deepEqual(base.deepCopy([1, [2, [3]]]), [1, [2, [3]]]);
});
-test('modify the original after deepCopy(obj) should not affect the copy',
- function() {
+QUnit.test('modify the original after deepCopy(obj) should not affect the copy',
+ function(assert) {
var original = [1, 2, 3, 4];
var copy = base.deepCopy(original);
original[2] = 1000;
- QUnit.deepEqual(copy, [1, 2, 3, 4]);
+ assert.deepEqual(copy, [1, 2, 3, 4]);
});
-test('dispose(obj) should invoke the dispose method on |obj|',
- function() {
+QUnit.test('dispose(obj) should invoke the dispose method on |obj|',
+ function(assert) {
/**
* @constructor
* @implements {base.Disposable}
@@ -84,51 +84,51 @@ test('dispose(obj) should invoke the dispose method on |obj|',
sinon.assert.called(obj.dispose);
});
-test('dispose(obj) should not crash if |obj| is null',
- function() {
- expect(0);
+QUnit.test('dispose(obj) should not crash if |obj| is null',
+ function(assert) {
+ assert.expect(0);
base.dispose(null);
});
-test('urljoin(url, opt_param) should return url if |opt_param| is missing',
- function() {
- QUnit.equal(
+QUnit.test(
+ 'urljoin(url, opt_param) should return url if |opt_param| is missing',
+ function(assert) {
+ assert.equal(
base.urlJoin('http://www.chromium.org'), 'http://www.chromium.org');
});
-test('urljoin(url, opt_param) should urlencode |opt_param|',
- function() {
+QUnit.test('urljoin(url, opt_param) should urlencode |opt_param|',
+ function(assert) {
var result = base.urlJoin('http://www.chromium.org', {
a: 'a',
foo: 'foo',
escapist: ':/?#[]@$&+,;='
});
- QUnit.equal(
+ assert.equal(
result,
'http://www.chromium.org?a=a&foo=foo' +
'&escapist=%3A%2F%3F%23%5B%5D%40%24%26%2B%2C%3B%3D');
});
-test('escapeHTML(str) should escape special characters', function() {
- QUnit.equal(
+QUnit.test('escapeHTML(str) should escape special characters', function(assert){
+ assert.equal(
base.escapeHTML('<script>alert("hello")</script>'),
'&lt;script&gt;alert("hello")&lt;/script&gt;');
});
-QUnit.asyncTest('Promise.sleep(delay) should fulfill the promise after |delay|',
+QUnit.test('Promise.sleep(delay) should fulfill the promise after |delay|',
/**
* 'this' is not defined for jscompile, so it can't figure out the type of
* this.clock.
* @suppress {reportUnknownTypes|checkVars|checkTypes}
*/
- function() {
+ function(assert) {
var isCalled = false;
var clock = /** @type {QUnit.Clock} */ (this.clock);
- base.Promise.sleep(100).then(function(){
+ var promise = base.Promise.sleep(100).then(function(){
isCalled = true;
- ok(true, 'Promise.sleep() is fulfilled after delay.');
- QUnit.start();
+ assert.ok(true, 'Promise.sleep() is fulfilled after delay.');
});
// Tick the clock for 2 seconds and check if the promise is fulfilled.
@@ -137,28 +137,33 @@ QUnit.asyncTest('Promise.sleep(delay) should fulfill the promise after |delay|',
// Promise fulfillment always occur on a new stack. Therefore, we will run
// the verification in a requestAnimationFrame.
window.requestAnimationFrame(function(){
- ok(!isCalled, 'Promise.sleep() should not be fulfilled prematurely.');
+ assert.ok(
+ !isCalled, 'Promise.sleep() should not be fulfilled prematurely.');
clock.tick(101);
});
-});
-QUnit.asyncTest('Promise.negate should fulfill iff the promise does not.',
- function() {
+ return promise;
+});
- base.Promise.negate(Promise.reject()).then(
- QUnit.ok.bind(null, true),
- /** @type {Function} */ (QUnit.ok.bind(null, false)));
- base.Promise.negate(Promise.resolve()).then(
- QUnit.ok.bind(null, false),
- /** @type {Function} */ (QUnit.ok.bind(null, true)));
- window.requestAnimationFrame(function(){
- QUnit.start();
+QUnit.test('Promise.negate should fulfill iff the promise does not.',
+ function(assert) {
+ return base.Promise.negate(Promise.reject())
+ .then(function() {
+ assert.ok(true);
+ }).catch(function() {
+ assert.ok(false);
+ }).then(function() {
+ return base.Promise.negate(Promise.resolve());
+ }).then(function() {
+ assert.ok(false);
+ }).catch(function() {
+ assert.ok(true);
});
});
-module('base.Deferred');
+QUnit.module('base.Deferred');
-QUnit.asyncTest('resolve() should fulfill the underlying promise.', function() {
+QUnit.test('resolve() should fulfill the underlying promise.', function(assert){
/** @returns {Promise} */
function async() {
var deferred = new base.Deferred();
@@ -166,17 +171,14 @@ QUnit.asyncTest('resolve() should fulfill the underlying promise.', function() {
return deferred.promise();
}
- async().then(
- /** @param {string} value */
- function(value){
- QUnit.equal(value, 'bar');
- QUnit.start();
- }, function() {
- QUnit.ok(false, 'The reject handler should not be invoked.');
- });
+ return async().then(function(/** string */ value){
+ assert.equal(value, 'bar');
+ }, function() {
+ assert.ok(false, 'The reject handler should not be invoked.');
+ });
});
-QUnit.asyncTest('reject() should fail the underlying promise.', function() {
+QUnit.test('reject() should fail the underlying promise.', function(assert) {
/** @returns {Promise} */
function async() {
var deferred = new base.Deferred();
@@ -184,11 +186,10 @@ QUnit.asyncTest('reject() should fail the underlying promise.', function() {
return deferred.promise();
}
- async().then(function(){
- QUnit.ok(false, 'The then handler should not be invoked.');
+ return async().then(function(){
+ assert.ok(false, 'The then handler should not be invoked.');
}, function(value) {
- QUnit.equal(value, 'bar');
- QUnit.start();
+ assert.equal(value, 'bar');
});
});
@@ -197,26 +198,27 @@ QUnit.asyncTest('reject() should fail the underlying promise.', function() {
var source = null;
var listener = null;
-module('base.EventSource', {
- setup: function() {
+QUnit.module('base.EventSource', {
+ beforeEach: function() {
source = new base.EventSourceImpl();
source.defineEvents(['foo', 'bar']);
listener = sinon.spy();
source.addEventListener('foo', listener);
},
- teardown: function() {
+ afterEach: function() {
source = null;
listener = null;
}
});
-test('raiseEvent() should invoke the listener', function() {
+QUnit.test('raiseEvent() should invoke the listener', function() {
source.raiseEvent('foo');
sinon.assert.called(listener);
});
-test('raiseEvent() should invoke the listener with the correct event data',
- function() {
+QUnit.test(
+ 'raiseEvent() should invoke the listener with the correct event data',
+ function(assert) {
var data = {
field: 'foo'
};
@@ -224,26 +226,26 @@ test('raiseEvent() should invoke the listener with the correct event data',
sinon.assert.calledWith(listener, data);
});
-test(
+QUnit.test(
'raiseEvent() should not invoke listeners that are added during raiseEvent',
- function() {
+ function(assert) {
source.addEventListener('foo', function() {
source.addEventListener('foo', function() {
- ok(false);
+ assert.ok(false);
});
- ok(true);
+ assert.ok(true);
});
source.raiseEvent('foo');
});
-test('raiseEvent() should not invoke listeners of a different event',
- function() {
+QUnit.test('raiseEvent() should not invoke listeners of a different event',
+ function(assert) {
source.raiseEvent('bar');
sinon.assert.notCalled(listener);
});
-test('raiseEvent() should assert when undeclared events are raised',
- function() {
+QUnit.test('raiseEvent() should assert when undeclared events are raised',
+ function(assert) {
sinon.stub(base.debug, 'assert');
try {
source.raiseEvent('undefined');
@@ -254,10 +256,10 @@ test('raiseEvent() should assert when undeclared events are raised',
}
});
-test(
+QUnit.test(
'removeEventListener() should not invoke the listener in subsequent ' +
'calls to |raiseEvent|',
- function() {
+ function(assert) {
source.raiseEvent('foo');
sinon.assert.calledOnce(listener);
@@ -266,9 +268,9 @@ test(
sinon.assert.calledOnce(listener);
});
-test('removeEventListener() should work even if the listener ' +
+QUnit.test('removeEventListener() should work even if the listener ' +
'is removed during |raiseEvent|',
- function() {
+ function(assert) {
var sink = {};
sink.listener = sinon.spy(function() {
source.removeEventListener('foo', sink.listener);
@@ -282,7 +284,7 @@ test('removeEventListener() should work even if the listener ' +
sinon.assert.calledOnce(sink.listener);
});
-test('encodeUtf8() can encode UTF8 strings', function() {
+QUnit.test('encodeUtf8() can encode UTF8 strings', function(assert) {
/** @type {function(ArrayBuffer):Array} */
function toJsArray(arrayBuffer) {
var result = [];
@@ -294,25 +296,25 @@ test('encodeUtf8() can encode UTF8 strings', function() {
}
// ASCII.
- QUnit.deepEqual(toJsArray(base.encodeUtf8("ABC")), [0x41, 0x42, 0x43]);
+ assert.deepEqual(toJsArray(base.encodeUtf8("ABC")), [0x41, 0x42, 0x43]);
// Some arbitrary characters from the basic Unicode plane.
- QUnit.deepEqual(
+ assert.deepEqual(
toJsArray(base.encodeUtf8("挂Ѓф")),
[/* 挂 */ 0xE6, 0x8C, 0x82, /* Ѓ */ 0xD0, 0x83, /* ф */ 0xD1, 0x84]);
// Unicode surrogate pair for U+1F603.
- QUnit.deepEqual(toJsArray(base.encodeUtf8("😃")),
+ assert.deepEqual(toJsArray(base.encodeUtf8("😃")),
[0xF0, 0x9F, 0x98, 0x83]);
});
-test('decodeUtf8() can decode UTF8 strings', function() {
+QUnit.test('decodeUtf8() can decode UTF8 strings', function(assert) {
// ASCII.
- QUnit.equal(base.decodeUtf8(new Uint8Array([0x41, 0x42, 0x43]).buffer),
+ assert.equal(base.decodeUtf8(new Uint8Array([0x41, 0x42, 0x43]).buffer),
"ABC");
// Some arbitrary characters from the basic Unicode plane.
- QUnit.equal(
+ assert.equal(
base.decodeUtf8(
new Uint8Array([/* 挂 */ 0xE6, 0x8C, 0x82,
/* Ѓ */ 0xD0, 0x83,
@@ -320,7 +322,7 @@ test('decodeUtf8() can decode UTF8 strings', function() {
"挂Ѓф");
// Unicode surrogate pair for U+1F603.
- QUnit.equal(base.decodeUtf8(new Uint8Array([0xF0, 0x9F, 0x98, 0x83]).buffer),
+ assert.equal(base.decodeUtf8(new Uint8Array([0xF0, 0x9F, 0x98, 0x83]).buffer),
"😃");
});
diff --git a/remoting/webapp/base/js/ipc_unittest.js b/remoting/webapp/base/js/ipc_unittest.js
index e786147..1634d86 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();
@@ -33,16 +23,16 @@ module('base.Ipc', {
QUnit.test(
'register() should return false if the request type was already registered',
- function() {
+ function(assert) {
var handler1 = function() {};
var handler2 = function() {};
- QUnit.equal(true, ipc_.register('foo', handler1));
- QUnit.equal(false, ipc_.register('foo', handler2));
+ assert.equal(true, ipc_.register('foo', handler1));
+ assert.equal(false, ipc_.register('foo', handler2));
});
-QUnit.asyncTest(
+QUnit.test(
'send() should invoke a registered handler with the correct arguments',
- function() {
+ function(assert) {
var handler = sinon.spy();
var argArray = [1, 2, 3];
var argDict = {
@@ -51,68 +41,72 @@ 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() {
+ function(assert) {
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() {
+ assert.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();
+ assert.equal(error, base.Ipc.Error.UNSUPPORTED_REQUEST_TYPE);
});
});
-QUnit.asyncTest(
+QUnit.test(
'send() should raise exceptions on unknown request types',
- function() {
+ function(assert) {
var handler = sinon.spy();
ipc_.register('foo', handler);
- base.Ipc.invoke('bar', 'hello', 'world').then(fail, function(error) {
- QUnit.equal(error, base.Ipc.Error.UNSUPPORTED_REQUEST_TYPE);
- pass();
+ return base.Ipc.invoke('bar', 'hello', 'world').then(function() {
+ assert.ok(false, 'Invoking unknown request types should fail.');
+ }).catch(function(error) {
+ assert.equal(error, base.Ipc.Error.UNSUPPORTED_REQUEST_TYPE);
});
});
-QUnit.asyncTest(
+QUnit.test(
'send() should raise exceptions on request from another extension',
- function() {
+ function(assert) {
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) {
- QUnit.equal(error, base.Ipc.Error.INVALID_REQUEST_ORIGIN);
- pass();
+ var promise = base.Ipc.invoke('foo', 'hello', 'world').then(function() {
+ assert.ok(false, 'Requests from another extension should fail.');
+ }).catch(function(error) {
+ assert.equal(error, base.Ipc.Error.INVALID_REQUEST_ORIGIN);
});
chrome.runtime.id = oldId;
+ return promise;
});
-QUnit.asyncTest(
+QUnit.test(
'send() should pass exceptions raised by the handler to the caller',
- function() {
+ function(assert) {
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) {
- QUnit.equal(error, 'Whatever can go wrong, will go wrong.');
- pass();
+ return base.Ipc.invoke('foo').then(function() {
+ assert.ok(false, 'Exceptions expected.');
+ }).catch(function(error) {
+ assert.equal(error, 'Whatever can go wrong, will go wrong.');
});
});
-QUnit.asyncTest(
+QUnit.test(
'send() should pass the return value of the handler to the caller',
- function() {
+ function(assert) {
var handlers = {
'boolean': function() { return false; },
'number': function() { return 12; },
@@ -127,14 +121,13 @@ QUnit.asyncTest(
testCases.push(base.Ipc.invoke(ipcName));
}
- 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);
+ return Promise.all(testCases).then(function(results){
+ assert.equal(results[0], false);
+ assert.equal(results[1], 12);
+ assert.equal(results[2], 'string');
+ assert.deepEqual(results[3], [1,2]);
+ assert.deepEqual(results[4], {key1: 'value1', key2: 'value2'});
+ });
});
})();
diff --git a/remoting/webapp/crd/js/apps_v2_migration_unittest.js b/remoting/webapp/crd/js/apps_v2_migration_unittest.js
index 097a80f..456cc47 100644
--- a/remoting/webapp/crd/js/apps_v2_migration_unittest.js
+++ b/remoting/webapp/crd/js/apps_v2_migration_unittest.js
@@ -4,7 +4,6 @@
/**
* @fileoverview
- * @suppress {checkTypes|checkVars|reportUnknownTypes|visibility}
*/
(function() {
@@ -15,16 +14,6 @@
var mockIsAppsV2 = null;
var mockChromeStorage = {};
-function pass() {
- ok(true);
- QUnit.start();
-}
-
-function fail() {
- ok(false);
- QUnit.start();
-}
-
/**
* @param {string} v1UserName
* @param {string} v1UserEmail
@@ -56,64 +45,65 @@ function setMigrationData_(v1UserName, v1UserEmail, v1HasHosts) {
}
}
-module('AppsV2Migration', {
- setup: function() {
+QUnit.module('AppsV2Migration', {
+ beforeEach: function() {
chromeMocks.activate(['storage']);
mockIsAppsV2 = sinon.stub(base, 'isAppsV2');
remoting.identity = new remoting.Identity();
},
- teardown: function() {
+ afterEach: function() {
chromeMocks.restore();
mockIsAppsV2.restore();
remoting.identity = null;
}
});
-QUnit.asyncTest(
+QUnit.test(
'hasHostsInV1App() should reject the promise if v1 user has same identity',
- function() {
+ function(assert) {
+ assert.expect(0);
setMigrationData_('v1userName', 'v2user@gmail.com', true);
mockIsAppsV2.returns(true);
- remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);
+ return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());
});
-QUnit.asyncTest(
+QUnit.test(
'hasHostsInV1App() should reject the promise if v1 user has no hosts',
- function() {
+ function(assert) {
+ assert.expect(0);
setMigrationData_('v1userName', 'v1user@gmail.com', false);
mockIsAppsV2.returns(true);
- remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);
+ return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());
});
-QUnit.asyncTest(
- 'hasHostsInV1App() should reject the promise in v1', function() {
- setMigrationData_('v1userName', 'v1user@gmail.com', true);
- mockIsAppsV2.returns(false);
- remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);
+QUnit.test('hasHostsInV1App() should reject the promise in v1',
+ function(assert) {
+ assert.expect(0);
+ setMigrationData_('v1userName', 'v1user@gmail.com', true);
+ mockIsAppsV2.returns(false);
+ return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());
});
-QUnit.asyncTest(
+QUnit.test(
'hasHostsInV1App() should return v1 identity if v1 user has hosts',
- function() {
+ function(assert) {
setMigrationData_('v1userName', 'v1user@gmail.com', true);
mockIsAppsV2.returns(true);
- remoting.AppsV2Migration.hasHostsInV1App().then(
- /** @param {{email:string, name:string}} result */
- function(result) {
- QUnit.equal(result.email, 'v1user@gmail.com');
- QUnit.equal(result.fullName, 'v1userName');
- pass();
- }, fail
- );
+ return remoting.AppsV2Migration.hasHostsInV1App().then(
+ function(/** {email:string, fullName:string} */ result) {
+ assert.equal(result.email, 'v1user@gmail.com');
+ assert.equal(result.fullName, 'v1userName');
+ });
});
-QUnit.asyncTest(
+QUnit.test(
'saveUserInfo() should clear the preferences on v2',
- function() {
+ function(assert) {
+ assert.expect(0);
setMigrationData_('v1userName', 'v1user@gmail.com', true);
mockIsAppsV2.returns(true);
remoting.AppsV2Migration.saveUserInfo();
- remoting.AppsV2Migration.hasHostsInV1App().then(fail, pass);
+ return base.Promise.negate(remoting.AppsV2Migration.hasHostsInV1App());
});
})();
diff --git a/remoting/webapp/crd/js/desktop_viewport_unittest.js b/remoting/webapp/crd/js/desktop_viewport_unittest.js
index 238c925..e9a3ddb 100644
--- a/remoting/webapp/crd/js/desktop_viewport_unittest.js
+++ b/remoting/webapp/crd/js/desktop_viewport_unittest.js
@@ -24,306 +24,306 @@ function dpi(x, y) {
return {x: x, y: y};
}
-module('DesktopViewport');
+QUnit.module('DesktopViewport');
-test('choosePluginSize() handles low-DPI client & host',
- function() {
+QUnit.test('choosePluginSize() handles low-DPI client & host',
+ function(assert) {
// 1. Client & host size the same.
var pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 1.0, size(640, 480), dpi(96, 96), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, 480));
+ assert.deepEqual(pluginSize, size(640, 480));
// 2. Client logical dimensions smaller than host's.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 1.0, size(1024, 600), dpi(96, 96), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
+ assert.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
// 3. Client Y dimension larger than host's, X dimension smaller.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 640), 1.0, size(1024, 600), dpi(96, 96), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
+ assert.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
// 4. Client dimensions larger than host's by <2x.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1280, 900), 1.0, size(640, 480), dpi(96, 96), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, 480));
+ assert.deepEqual(pluginSize, size(640, 480));
// 5. Client dimensions larger than host's by >2x.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1280, 1024), 1.0, size(640, 480), dpi(96, 96), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(2 * 640, 2 * 480));
+ assert.deepEqual(pluginSize, size(2 * 640, 2 * 480));
// 6. Client X dimension larger than host's, Y dimension smaller.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1152, 600), 1.0, size(1024, 768), dpi(96, 96), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(1024 * (600 / 768), 600));
+ assert.deepEqual(pluginSize, size(1024 * (600 / 768), 600));
});
-test('choosePluginSize() handles high-DPI client, low-DPI host',
- function() {
+QUnit.test('choosePluginSize() handles high-DPI client, low-DPI host',
+ function(assert) {
// 1. Client & host size the same.
var pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 2.0, size(640, 480), dpi(96, 96), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, 480));
+ assert.deepEqual(pluginSize, size(640, 480));
// 2. Client logical dimensions smaller than host's.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 2.0, size(1024, 600), dpi(96, 96), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
+ assert.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
// 3. Client Y dimension larger than host's, X dimension smaller.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 640), 2.0, size(1024, 600), dpi(96, 96), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
+ assert.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
// 4. Client logical dimensions larger than host's by <2x.
// Host dimensions fit into the client's _device_ dimensions 3x, so the
// size in client DIPs should be 1:3/2.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1280, 900), 2.0, size(640, 480), dpi(96, 96), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640 * 3 / 2.0, 480 * 3 / 2.0));
+ assert.deepEqual(pluginSize, size(640 * 3 / 2.0, 480 * 3 / 2.0));
// 5. Client dimensions larger than host's by >2x.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1280, 1024), 2.0, size(640, 480), dpi(96, 96), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
+ assert.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
// 6. Client X dimension larger than host's, Y dimension smaller.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1152, 600), 2.0, size(1024, 768), dpi(96, 96), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(1024 * (600 / 768), 600));
+ assert.deepEqual(pluginSize, size(1024 * (600 / 768), 600));
});
-test('choosePluginSize() handles low-DPI client, high-DPI host',
- function() {
+QUnit.test('choosePluginSize() handles low-DPI client, high-DPI host',
+ function(assert) {
// 1. Client & host size the same.
var pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 1.0, size(640, 480), dpi(192, 192), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, 480));
+ assert.deepEqual(pluginSize, size(640, 480));
// 2. Client logical dimensions smaller than host's.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 1.0, size(1024, 600), dpi(192, 192), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
+ assert.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
// 3. Client Y dimension larger than host's, X dimension smaller.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 640), 1.0, size(1024, 600), dpi(192, 192), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
+ assert.deepEqual(pluginSize, size(640, (640 / 1024) * 600));
// 4. Client dimensions larger than host's by <2x.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1280, 900), 1.0, size(640, 480), dpi(192, 192), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, 480));
+ assert.deepEqual(pluginSize, size(640, 480));
// 5. Client dimensions larger than host's by >2x.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1280, 1024), 1.0, size(640, 480), dpi(192, 192), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
+ assert.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
// 6. Client X dimension larger than host's, Y dimension smaller.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1152, 600), 1.0, size(1024, 768), dpi(192, 192), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(1024 * (600 / 768), 600));
+ assert.deepEqual(pluginSize, size(1024 * (600 / 768), 600));
});
-test('choosePluginSize() handles high-DPI client and host',
- function() {
+QUnit.test('choosePluginSize() handles high-DPI client and host',
+ function(assert) {
// 1. Client & host size the same.
var pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 2.0, size(640, 480), dpi(192, 192), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, 480));
+ assert.deepEqual(pluginSize, size(640, 480));
// 2. Client logical dimensions smaller than host's.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 2.0, size(1024, 600), dpi(192, 192), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(1024 / 2.0, 600 / 2.0));
+ assert.deepEqual(pluginSize, size(1024 / 2.0, 600 / 2.0));
// 3. Client Y dimension larger than host's, X dimension smaller.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 640), 2.0, size(1024, 600), dpi(192, 192), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(1024 / 2.0, 600 / 2.0));
+ assert.deepEqual(pluginSize, size(1024 / 2.0, 600 / 2.0));
// 4. Client logical dimensions larger than host's by <2x.
// Host dimensions fit into the client's _device_ dimensions 3x, so the
// size in client DIPs should be 1:3/2.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1280, 900), 2.0, size(640, 480), dpi(192, 192), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640 * 3 / 2.0, 480 * 3 / 2.0));
+ assert.deepEqual(pluginSize, size(640 * 3 / 2.0, 480 * 3 / 2.0));
// 5. Client dimensions larger than host's by >2x.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1280, 1024), 2.0, size(640, 480), dpi(192, 192), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
+ assert.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
// 6. Client X dimension larger than host's, Y dimension smaller.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1152, 600), 2.0, size(1024, 768), dpi(192, 192), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(1024 / 2.0, 768 / 2.0));
+ assert.deepEqual(pluginSize, size(1024 / 2.0, 768 / 2.0));
});
-test('choosePluginSize() handles high-DPI client, 150% DPI host',
- function() {
+QUnit.test('choosePluginSize() handles high-DPI client, 150% DPI host',
+ function(assert) {
// 1. Client & host size the same.
var pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 2.0, size(640, 480), dpi(144, 144), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, 480));
+ assert.deepEqual(pluginSize, size(640, 480));
// 2. Client dimensions smaller than host's.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 2.0, size(1024, 600), dpi(144, 144), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(1024 / 2.0, 600 / 2.0));
+ assert.deepEqual(pluginSize, size(1024 / 2.0, 600 / 2.0));
// 3. Client Y dimension larger than host's, X dimension smaller.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 640), 2.0, size(1024, 600), dpi(144, 144), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(1024 / 2.0, 600 / 2.0));
+ assert.deepEqual(pluginSize, size(1024 / 2.0, 600 / 2.0));
// 4. Client dimensions larger than host's by <2x.
// Host dimensions fit into the client's _device_ dimensions 3x, so the
// size in client DIPs should be 1:3/2.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1280, 900), 2.0, size(640, 480), dpi(144, 144), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640 * 3 / 2.0, 480 * 3 / 2.0));
+ assert.deepEqual(pluginSize, size(640 * 3 / 2.0, 480 * 3 / 2.0));
// 5. Client dimensions larger than host's by >2x.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1280, 1024), 2.0, size(640, 480), dpi(144, 144), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
+ assert.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
// 6. Client X dimension larger than host's, Y dimension smaller.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1152, 600), 2.0, size(1024, 768), dpi(144, 144), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(1024 / 2.0, 768 / 2.0));
+ assert.deepEqual(pluginSize, size(1024 / 2.0, 768 / 2.0));
});
-test('choosePluginSize() handles high-DPI client, 125% DPI host',
- function() {
+QUnit.test('choosePluginSize() handles high-DPI client, 125% DPI host',
+ function(assert) {
// 1. Client & host size the same.
var pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 2.0, size(640, 480), dpi(120, 120), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, 480));
+ assert.deepEqual(pluginSize, size(640, 480));
// 2. Client dimensions smaller than host's.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 2.0, size(1024, 600), dpi(120, 120), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, 600 * (640 / 1024)));
+ assert.deepEqual(pluginSize, size(640, 600 * (640 / 1024)));
// 3. Client Y dimension larger than host's, X dimension smaller.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 640), 2.0, size(1024, 600), dpi(120, 120), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640, 600 * (640 / 1024)));
+ assert.deepEqual(pluginSize, size(640, 600 * (640 / 1024)));
// 4. Client dimensions larger than host's by <2x.
// Host dimensions fit into the client's _device_ dimensions 3x, so the
// size in client DIPs should be 1:3/2.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1280, 900), 2.0, size(640, 480), dpi(120, 120), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(640 * 3 / 2.0, 480 * 3 / 2.0));
+ assert.deepEqual(pluginSize, size(640 * 3 / 2.0, 480 * 3 / 2.0));
// 5. Client dimensions larger than host's by >2x.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1280, 1024), 2.0, size(640, 480), dpi(120, 120), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
+ assert.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
// 6. Client X dimension larger than host's, Y dimension smaller.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1152, 600), 2.0, size(1024, 768), dpi(120, 120), 1.0, false, true);
- QUnit.deepEqual(pluginSize, size(1024 * (600 / 768), 600));
+ assert.deepEqual(pluginSize, size(1024 * (600 / 768), 600));
});
-test('choosePluginSize() with shrink-to-fit disabled',
- function() {
+QUnit.test('choosePluginSize() with shrink-to-fit disabled',
+ function(assert) {
// 1. Client & host size the same.
var pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 1.0, size(640, 480), dpi(96, 96), 1.0, false, false);
- QUnit.deepEqual(pluginSize, size(640, 480));
+ assert.deepEqual(pluginSize, size(640, 480));
// 2. Client logical dimensions smaller than host's.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 1.0, size(1024, 600), dpi(96, 96), 1.0, false, false);
- QUnit.deepEqual(pluginSize, size(1024, 600));
+ assert.deepEqual(pluginSize, size(1024, 600));
// 3. Client dimensions larger than host's by <2x.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1280, 900), 1.0, size(640, 480), dpi(96, 96), 1.0, false, false);
- QUnit.deepEqual(pluginSize, size(640, 480));
+ assert.deepEqual(pluginSize, size(640, 480));
// 4. Client dimensions larger than host's by >2x.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1280, 1024), 1.0, size(640, 480), dpi(96, 96), 1.0, false, false);
- QUnit.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
+ assert.deepEqual(pluginSize, size(1280, (1280 / 640) * 480));
// 5. Client smaller than host, client high-DPI, host low-DPI.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 2.0, size(1024, 600), dpi(96, 96), 1.0, false, false);
- QUnit.deepEqual(pluginSize, size(1024, 600));
+ assert.deepEqual(pluginSize, size(1024, 600));
// 6. Client smaller than host, client low-DPI, host high-DPI.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 1.0, size(1024, 600), dpi(192, 192), 1.0, false, false);
- QUnit.deepEqual(pluginSize, size(1024, 600));
+ assert.deepEqual(pluginSize, size(1024, 600));
// 7. Client smaller than host, both high-DPI.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 2.0, size(1024, 600), dpi(192, 192), 1.0, false, false);
- QUnit.deepEqual(pluginSize, size(512, (512 / 1024) * 600));
+ assert.deepEqual(pluginSize, size(512, (512 / 1024) * 600));
// 8. Client smaller than host, client high-DPI, host 150% DPI.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 2.0, size(1024, 600), dpi(144, 144), 1.0, false, false);
- QUnit.deepEqual(pluginSize, size(512, (512 / 1024) * 600));
+ assert.deepEqual(pluginSize, size(512, (512 / 1024) * 600));
});
-test('choosePluginSize() full-screen multi-monitor optimization',
- function() {
+QUnit.test('choosePluginSize() full-screen multi-monitor optimization',
+ function(assert) {
// Each test has a host sized to approximate two or more monitors.
// 1. Client & host per-monitor dimensions match, two monitors side-by-side.
var pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 1.0, size(2 * 640, 480), dpi(96, 96), 1.0, true, true);
- QUnit.deepEqual(pluginSize, size(2 * 640, 480));
+ assert.deepEqual(pluginSize, size(2 * 640, 480));
// 2. Client & host per-monitor dimensions match, two monitors stacked.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 1.0, size(640, 2 * 480), dpi(96, 96), 1.0, true, true);
- QUnit.deepEqual(pluginSize, size(640, 2 * 480));
+ assert.deepEqual(pluginSize, size(640, 2 * 480));
// 3. Client larger, two monitors stacked.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1024, 768), 1.0, size(640, 2 * 480), dpi(96, 96), 1.0, true, true);
- QUnit.deepEqual(pluginSize, size(640 * (768 / (2 * 480)), 768));
+ assert.deepEqual(pluginSize, size(640 * (768 / (2 * 480)), 768));
// 4. Client smaller, two monitors stacked.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 1.0, size(1024, 2 * 768), dpi(96, 96), 1.0, true, true);
- QUnit.deepEqual(pluginSize, size(640, 2 * 768 * (640 / 1024)));
+ assert.deepEqual(pluginSize, size(640, 2 * 768 * (640 / 1024)));
// 5. Client wide-screen, host two standard monitors stacked.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(1920, 1080), 1.0, size(1024, 2 * 768), dpi(96, 96), 1.0,
true, true);
- QUnit.deepEqual(pluginSize, size(1024 * (1080 / (2 * 768)), 1080));
+ assert.deepEqual(pluginSize, size(1024 * (1080 / (2 * 768)), 1080));
// 6. Client & host per-monitor dimensions match, two monitors stacked,
// high-DPI client.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 2.0, size(640, 2 * 480), dpi(96, 96), 1.0, true, true);
- QUnit.deepEqual(pluginSize, size(640, 2 * 480));
+ assert.deepEqual(pluginSize, size(640, 2 * 480));
// 7. Client & host per-monitor dimensions match, two monitors stacked,
// high-DPI host.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 1.0, size(640, 2 * 480), dpi(192, 192),
1.0, true, true);
- QUnit.deepEqual(pluginSize, size(640, 2 * 480));
+ assert.deepEqual(pluginSize, size(640, 2 * 480));
// 8. Client & host per-monitor dimensions match, two monitors stacked,
// high-DPI client & host.
pluginSize = remoting.DesktopViewport.choosePluginSize(
size(640, 480), 2.0, size(640, 2 * 480), dpi(192, 192),
1.0, true, true);
- QUnit.deepEqual(pluginSize, size(640 / 2.0, (2 * 480) / 2.0));
+ assert.deepEqual(pluginSize, size(640 / 2.0, (2 * 480) / 2.0));
});
})();
diff --git a/remoting/webapp/crd/js/dns_blackhole_checker_unittest.js b/remoting/webapp/crd/js/dns_blackhole_checker_unittest.js
index 6c55345..9b0be49 100644
--- a/remoting/webapp/crd/js/dns_blackhole_checker_unittest.js
+++ b/remoting/webapp/crd/js/dns_blackhole_checker_unittest.js
@@ -25,8 +25,8 @@ var checker = null;
var signalStrategy = null;
var fakeXhrs;
-module('dns_blackhole_checker', {
- setup: function() {
+QUnit.module('dns_blackhole_checker', {
+ beforeEach: function(assert) {
fakeXhrs = [];
sinon.useFakeXMLHttpRequest().onCreate = function(xhr) {
fakeXhrs.push(xhr);
@@ -46,12 +46,12 @@ module('dns_blackhole_checker', {
sinon.assert.calledWith(signalStrategy.connect, 'server', 'username',
'authToken');
- QUnit.equal(fakeXhrs.length, 1, 'exactly one XHR is issued');
- QUnit.equal(
+ assert.equal(fakeXhrs.length, 1, 'exactly one XHR is issued');
+ assert.equal(
fakeXhrs[0].url, remoting.DnsBlackholeChecker.URL_TO_REQUEST_,
'the correct URL is requested');
},
- teardown: function() {
+ afterEach: function() {
base.dispose(checker);
sinon.assert.calledWith(onStateChange,
remoting.SignalStrategy.State.CLOSED);
@@ -62,8 +62,8 @@ module('dns_blackhole_checker', {
},
});
-test('success',
- function() {
+QUnit.test('success',
+ function(assert) {
fakeXhrs[0].respond(200);
sinon.assert.notCalled(onStateChange);
@@ -74,20 +74,20 @@ test('success',
].forEach(function(state) {
signalStrategy.setStateForTesting(state);
sinon.assert.calledWith(onStateChange, state);
- equal(checker.getState(), state);
+ assert.equal(checker.getState(), state);
});
}
);
-test('http response after connected',
- function() {
+QUnit.test('http response after connected',
+ function(assert) {
[
remoting.SignalStrategy.State.CONNECTING,
remoting.SignalStrategy.State.HANDSHAKE,
].forEach(function(state) {
signalStrategy.setStateForTesting(state);
sinon.assert.calledWith(onStateChange, state);
- equal(checker.getState(), state);
+ assert.equal(checker.getState(), state);
});
onStateChange.reset();
@@ -95,7 +95,7 @@ test('http response after connected',
// signal strategy has connected.
signalStrategy.setStateForTesting(remoting.SignalStrategy.State.CONNECTED);
sinon.assert.notCalled(onStateChange);
- equal(checker.getState(), remoting.SignalStrategy.State.HANDSHAKE);
+ assert.equal(checker.getState(), remoting.SignalStrategy.State.HANDSHAKE);
// Verify that DnsBlackholeChecker goes to CONNECTED state after the
// the HTTP request has succeeded.
@@ -105,8 +105,8 @@ test('http response after connected',
}
);
-test('connect failed',
- function() {
+QUnit.test('connect failed',
+ function(assert) {
fakeXhrs[0].respond(200);
sinon.assert.notCalled(onStateChange);
@@ -120,12 +120,13 @@ test('connect failed',
}
);
-test('blocked',
- function() {
+QUnit.test('blocked',
+ function(assert) {
fakeXhrs[0].respond(400);
sinon.assert.calledWith(onStateChange,
remoting.SignalStrategy.State.FAILED);
- equal(checker.getError().getTag(), remoting.Error.Tag.NOT_AUTHORIZED);
+ assert.equal(checker.getError().getTag(),
+ remoting.Error.Tag.NOT_AUTHORIZED);
onStateChange.reset();
[
@@ -135,20 +136,20 @@ test('blocked',
].forEach(function(state) {
signalStrategy.setStateForTesting(state);
sinon.assert.notCalled(onStateChange);
- equal(checker.getState(), remoting.SignalStrategy.State.FAILED);
+ assert.equal(checker.getState(), remoting.SignalStrategy.State.FAILED);
});
}
);
-test('blocked after connected',
- function() {
+QUnit.test('blocked after connected',
+ function(assert) {
[
remoting.SignalStrategy.State.CONNECTING,
remoting.SignalStrategy.State.HANDSHAKE,
].forEach(function(state) {
signalStrategy.setStateForTesting(state);
sinon.assert.calledWith(onStateChange, state);
- equal(checker.getState(), state);
+ assert.equal(checker.getState(), state);
});
onStateChange.reset();
@@ -156,14 +157,14 @@ test('blocked after connected',
// signal strategy has connected.
signalStrategy.setStateForTesting(remoting.SignalStrategy.State.CONNECTED);
sinon.assert.notCalled(onStateChange);
- equal(checker.getState(), remoting.SignalStrategy.State.HANDSHAKE);
+ assert.equal(checker.getState(), remoting.SignalStrategy.State.HANDSHAKE);
// Verify that DnsBlackholeChecker goes to FAILED state after it gets the
// blocked HTTP response.
fakeXhrs[0].respond(400);
sinon.assert.calledWith(onStateChange,
remoting.SignalStrategy.State.FAILED);
- ok(checker.getError().hasTag(remoting.Error.Tag.NOT_AUTHORIZED));
+ assert.ok(checker.getError().hasTag(remoting.Error.Tag.NOT_AUTHORIZED));
}
);
diff --git a/remoting/webapp/crd/js/error_unittest.js b/remoting/webapp/crd/js/error_unittest.js
index 31df1b8..85250f0 100644
--- a/remoting/webapp/crd/js/error_unittest.js
+++ b/remoting/webapp/crd/js/error_unittest.js
@@ -6,104 +6,99 @@
'use strict';
-QUnit.module('error', {
- setup: function() {
- },
- teardown: function() {
- }
-});
+QUnit.module('error');
-QUnit.test('error constructor 1', function() {
+QUnit.test('error constructor 1', function(assert) {
var error = new remoting.Error(remoting.Error.Tag.HOST_OVERLOAD);
- QUnit.equal(error.getTag(), remoting.Error.Tag.HOST_OVERLOAD);
- QUnit.equal(error.toString(), remoting.Error.Tag.HOST_OVERLOAD);
+ assert.equal(error.getTag(), remoting.Error.Tag.HOST_OVERLOAD);
+ assert.equal(error.toString(), remoting.Error.Tag.HOST_OVERLOAD);
});
-QUnit.test('error constructor 2', function() {
+QUnit.test('error constructor 2', function(assert) {
var error = new remoting.Error(
remoting.Error.Tag.HOST_IS_OFFLINE,
'detail');
- QUnit.equal(error.getTag(), remoting.Error.Tag.HOST_IS_OFFLINE);
- QUnit.ok(error.toString().indexOf(remoting.Error.Tag.HOST_IS_OFFLINE) != -1);
- QUnit.ok(error.toString().indexOf('detail') != -1);
+ assert.equal(error.getTag(), remoting.Error.Tag.HOST_IS_OFFLINE);
+ assert.ok(error.toString().indexOf(remoting.Error.Tag.HOST_IS_OFFLINE) != -1);
+ assert.ok(error.toString().indexOf('detail') != -1);
});
-QUnit.test('hasTag', function() {
+QUnit.test('hasTag', function(assert) {
var error = new remoting.Error(remoting.Error.Tag.HOST_OVERLOAD);
- QUnit.ok(error.hasTag(remoting.Error.Tag.HOST_OVERLOAD));
- QUnit.ok(error.hasTag(
+ assert.ok(error.hasTag(remoting.Error.Tag.HOST_OVERLOAD));
+ assert.ok(error.hasTag(
remoting.Error.Tag.HOST_OVERLOAD,
remoting.Error.Tag.HOST_IS_OFFLINE));
- QUnit.ok(!error.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE));
+ assert.ok(!error.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE));
});
-QUnit.test('constructor methods', function() {
- QUnit.ok(remoting.Error.none().hasTag(remoting.Error.Tag.NONE));
- QUnit.ok(remoting.Error.unexpected().hasTag(remoting.Error.Tag.UNEXPECTED));
+QUnit.test('constructor methods', function(assert) {
+ assert.ok(remoting.Error.none().hasTag(remoting.Error.Tag.NONE));
+ assert.ok(remoting.Error.unexpected().hasTag(remoting.Error.Tag.UNEXPECTED));
});
-QUnit.test('isNone', function() {
- QUnit.ok(remoting.Error.none().isNone());
- QUnit.ok(!remoting.Error.unexpected().isNone());
- QUnit.ok(!new remoting.Error(remoting.Error.Tag.CANCELLED).isNone());
+QUnit.test('isNone', function(assert) {
+ assert.ok(remoting.Error.none().isNone());
+ assert.ok(!remoting.Error.unexpected().isNone());
+ assert.ok(!new remoting.Error(remoting.Error.Tag.CANCELLED).isNone());
});
-QUnit.test('fromHttpStatus', function() {
- QUnit.ok(remoting.Error.fromHttpStatus(200).isNone());
- QUnit.ok(remoting.Error.fromHttpStatus(201).isNone());
- QUnit.ok(!remoting.Error.fromHttpStatus(500).isNone());
- QUnit.equal(
+QUnit.test('fromHttpStatus', function(assert) {
+ assert.ok(remoting.Error.fromHttpStatus(200).isNone());
+ assert.ok(remoting.Error.fromHttpStatus(201).isNone());
+ assert.ok(!remoting.Error.fromHttpStatus(500).isNone());
+ assert.equal(
remoting.Error.fromHttpStatus(0).getTag(),
remoting.Error.Tag.NETWORK_FAILURE);
- QUnit.equal(
+ assert.equal(
remoting.Error.fromHttpStatus(100).getTag(),
remoting.Error.Tag.UNEXPECTED);
- QUnit.equal(
+ assert.equal(
remoting.Error.fromHttpStatus(200).getTag(),
remoting.Error.Tag.NONE);
- QUnit.equal(
+ assert.equal(
remoting.Error.fromHttpStatus(201).getTag(),
remoting.Error.Tag.NONE);
- QUnit.equal(
+ assert.equal(
remoting.Error.fromHttpStatus(400).getTag(),
remoting.Error.Tag.AUTHENTICATION_FAILED);
- QUnit.equal(
+ assert.equal(
remoting.Error.fromHttpStatus(401).getTag(),
remoting.Error.Tag.AUTHENTICATION_FAILED);
- QUnit.equal(
+ assert.equal(
remoting.Error.fromHttpStatus(402).getTag(),
remoting.Error.Tag.UNEXPECTED);
- QUnit.equal(
+ assert.equal(
remoting.Error.fromHttpStatus(403).getTag(),
remoting.Error.Tag.NOT_AUTHORIZED);
- QUnit.equal(
+ assert.equal(
remoting.Error.fromHttpStatus(404).getTag(),
remoting.Error.Tag.NOT_FOUND);
- QUnit.equal(
+ assert.equal(
remoting.Error.fromHttpStatus(500).getTag(),
remoting.Error.Tag.SERVICE_UNAVAILABLE);
- QUnit.equal(
+ assert.equal(
remoting.Error.fromHttpStatus(501).getTag(),
remoting.Error.Tag.SERVICE_UNAVAILABLE);
- QUnit.equal(
+ assert.equal(
remoting.Error.fromHttpStatus(600).getTag(),
remoting.Error.Tag.UNEXPECTED);
});
-QUnit.test('handler 1', function() {
+QUnit.test('handler 1', function(assert) {
/** @type {!remoting.Error} */
var reportedError;
var onError = function(/** !remoting.Error */ arg) {
reportedError = arg;
};
remoting.Error.handler(onError)('not a real tag');
- QUnit.ok(reportedError instanceof remoting.Error);
- QUnit.equal(reportedError.getTag(), remoting.Error.Tag.UNEXPECTED);
+ assert.ok(reportedError instanceof remoting.Error);
+ assert.equal(reportedError.getTag(), remoting.Error.Tag.UNEXPECTED);
});
-QUnit.test('handler 2', function() {
+QUnit.test('handler 2', function(assert) {
/** @type {!remoting.Error} */
var reportedError;
var onError = function(/** !remoting.Error */ arg) {
@@ -111,7 +106,7 @@ QUnit.test('handler 2', function() {
};
var origError = new remoting.Error(remoting.Error.Tag.HOST_IS_OFFLINE);
remoting.Error.handler(onError)(origError);
- QUnit.equal(reportedError, origError);
+ assert.equal(reportedError, origError);
});
})();
diff --git a/remoting/webapp/crd/js/fallback_signal_strategy_unittest.js b/remoting/webapp/crd/js/fallback_signal_strategy_unittest.js
index 9f97a72..147e664 100644
--- a/remoting/webapp/crd/js/fallback_signal_strategy_unittest.js
+++ b/remoting/webapp/crd/js/fallback_signal_strategy_unittest.js
@@ -13,18 +13,21 @@
'use strict';
/** @constructor */
-var MockLogToServer = function() {
+var MockLogToServer = function(/** QUnit.Assert */ assert) {
/** @type {(sinon.Spy|Function)} */
this.logSignalStrategyProgress = sinon.spy();
+ this.assert_ = assert;
};
/** @type {function(...)} */
MockLogToServer.prototype.assertProgress = function() {
- equal(this.logSignalStrategyProgress.callCount * 2, arguments.length);
+ this.assert_.equal(this.logSignalStrategyProgress.callCount * 2,
+ arguments.length);
for (var i = 0; i < this.logSignalStrategyProgress.callCount; ++i) {
- equal(this.logSignalStrategyProgress.getCall(i).args[0], arguments[2 * i]);
- equal(this.logSignalStrategyProgress.getCall(i).args[1],
- arguments[2 * i + 1]);
+ this.assert_.equal(
+ this.logSignalStrategyProgress.getCall(i).args[0], arguments[2 * i]);
+ this.assert_.equal(this.logSignalStrategyProgress.getCall(i).args[1],
+ arguments[2 * i + 1]);
}
};
@@ -47,25 +50,26 @@ var secondary = null;
var logToServer = null;
/**
+ * @param {QUnit.Assert} assert
* @param {remoting.MockSignalStrategy} baseSignalStrategy
* @param {remoting.SignalStrategy.State} state
* @param {boolean} expectCallback
*/
-function setState(baseSignalStrategy, state, expectCallback) {
+function setState(assert, baseSignalStrategy, state, expectCallback) {
onStateChange.reset();
baseSignalStrategy.setStateForTesting(state);
if (expectCallback) {
- equal(onStateChange.callCount, 1);
- ok(onStateChange.calledWith(state));
- equal(strategy.getState(), state);
+ assert.equal(onStateChange.callCount, 1);
+ assert.ok(onStateChange.calledWith(state));
+ assert.equal(strategy.getState(), state);
} else {
- ok(!onStateChange.called);
+ assert.ok(!onStateChange.called);
}
-};
+}
-module('fallback_signal_strategy', {
- setup: function() {
+QUnit.module('fallback_signal_strategy', {
+ beforeEach: function(/** QUnit.Assert */ assert) {
onStateChange = sinon.spy();
onIncomingStanzaCallback = sinon.spy();
strategy = new remoting.FallbackSignalStrategy(
@@ -77,9 +81,9 @@ module('fallback_signal_strategy', {
strategy.setIncomingStanzaCallback(onIncomingStanzaCallback);
primary = strategy.primary_;
secondary = strategy.secondary_;
- logToServer = new MockLogToServer();
+ logToServer = new MockLogToServer(assert);
},
- teardown: function() {
+ afterEach: function() {
onStateChange = null;
onIncomingStanzaCallback = null;
strategy = null;
@@ -89,66 +93,69 @@ module('fallback_signal_strategy', {
},
});
-test('primary succeeds; send & receive routed to it',
- function() {
- ok(!onStateChange.called);
- ok(!primary.connect.called);
+QUnit.test('primary succeeds; send & receive routed to it',
+ function(assert) {
+ assert.ok(!onStateChange.called);
+ assert.ok(!primary.connect.called);
strategy.connect('server', 'username', 'authToken');
- ok(primary.connect.calledWith('server', 'username', 'authToken'));
+ assert.ok(primary.connect.calledWith('server', 'username', 'authToken'));
- setState(primary, remoting.SignalStrategy.State.NOT_CONNECTED, true);
- setState(primary, remoting.SignalStrategy.State.CONNECTING, true);
- setState(primary, remoting.SignalStrategy.State.HANDSHAKE, true);
+ setState(assert, primary, remoting.SignalStrategy.State.NOT_CONNECTED,
+ true);
+ setState(assert, primary, remoting.SignalStrategy.State.CONNECTING, true);
+ setState(assert, primary, remoting.SignalStrategy.State.HANDSHAKE, true);
- setState(primary, remoting.SignalStrategy.State.CONNECTED, true);
- equal(strategy.getJid(), 'primary-jid');
+ setState(assert, primary, remoting.SignalStrategy.State.CONNECTED, true);
+ assert.equal(strategy.getJid(), 'primary-jid');
strategy.sendConnectionSetupResults(logToServer);
logToServer.assertProgress(
remoting.SignalStrategy.Type.XMPP,
remoting.FallbackSignalStrategy.Progress.SUCCEEDED);
- ok(!onIncomingStanzaCallback.called);
+ assert.ok(!onIncomingStanzaCallback.called);
primary.onIncomingStanzaCallback_('test-receive-primary');
secondary.onIncomingStanzaCallback_('test-receive-secondary');
- ok(onIncomingStanzaCallback.calledOnce);
- ok(onIncomingStanzaCallback.calledWith('test-receive-primary'));
+ assert.ok(onIncomingStanzaCallback.calledOnce);
+ assert.ok(onIncomingStanzaCallback.calledWith('test-receive-primary'));
- ok(!primary.sendMessage.called);
+ assert.ok(!primary.sendMessage.called);
strategy.sendMessage('test-send');
- ok(primary.sendMessage.calledOnce);
- ok(primary.sendMessage.calledWith('test-send'));
+ assert.ok(primary.sendMessage.calledOnce);
+ assert.ok(primary.sendMessage.calledWith('test-send'));
- ok(!primary.dispose.called);
- ok(!secondary.dispose.called);
- setState(primary, remoting.SignalStrategy.State.CLOSED, true);
+ assert.ok(!primary.dispose.called);
+ assert.ok(!secondary.dispose.called);
+ setState(assert, primary, remoting.SignalStrategy.State.CLOSED, true);
strategy.dispose();
- ok(primary.dispose.calledOnce);
- ok(secondary.dispose.calledOnce);
+ assert.ok(primary.dispose.calledOnce);
+ assert.ok(secondary.dispose.calledOnce);
}
);
-test('primary fails; secondary succeeds; send & receive routed to it',
- function() {
- ok(!onStateChange.called);
- ok(!primary.connect.called);
+QUnit.test('primary fails; secondary succeeds; send & receive routed to it',
+ function(assert) {
+ assert.ok(!onStateChange.called);
+ assert.ok(!primary.connect.called);
strategy.connect('server', 'username', 'authToken');
- ok(primary.connect.calledWith('server', 'username', 'authToken'));
+ assert.ok(primary.connect.calledWith('server', 'username', 'authToken'));
- setState(primary, remoting.SignalStrategy.State.NOT_CONNECTED,
- true);
- setState(primary, remoting.SignalStrategy.State.CONNECTING, true);
+ setState(assert, primary, remoting.SignalStrategy.State.NOT_CONNECTED,
+ true);
+ setState(assert, primary, remoting.SignalStrategy.State.CONNECTING, true);
- ok(!secondary.connect.called);
- setState(primary, remoting.SignalStrategy.State.FAILED, false);
- ok(secondary.connect.calledWith('server', 'username', 'authToken'));
+ assert.ok(!secondary.connect.called);
+ setState(assert, primary, remoting.SignalStrategy.State.FAILED, false);
+ assert.ok(secondary.connect.calledWith('server', 'username', 'authToken'));
- setState(secondary, remoting.SignalStrategy.State.NOT_CONNECTED, false);
- setState(secondary, remoting.SignalStrategy.State.CONNECTING, false);
- setState(secondary, remoting.SignalStrategy.State.HANDSHAKE, true);
+ setState(assert, secondary, remoting.SignalStrategy.State.NOT_CONNECTED,
+ false);
+ setState(assert, secondary, remoting.SignalStrategy.State.CONNECTING,
+ false);
+ setState(assert, secondary, remoting.SignalStrategy.State.HANDSHAKE, true);
- setState(secondary, remoting.SignalStrategy.State.CONNECTED, true);
- equal(strategy.getJid(), 'secondary-jid');
+ setState(assert, secondary, remoting.SignalStrategy.State.CONNECTED, true);
+ assert.equal(strategy.getJid(), 'secondary-jid');
strategy.sendConnectionSetupResults(logToServer);
logToServer.assertProgress(
@@ -157,60 +164,64 @@ test('primary fails; secondary succeeds; send & receive routed to it',
remoting.SignalStrategy.Type.WCS,
remoting.FallbackSignalStrategy.Progress.SUCCEEDED);
- ok(!onIncomingStanzaCallback.called);
+ assert.ok(!onIncomingStanzaCallback.called);
primary.onIncomingStanzaCallback_('test-receive-primary');
secondary.onIncomingStanzaCallback_('test-receive-secondary');
- ok(onIncomingStanzaCallback.calledOnce);
- ok(onIncomingStanzaCallback.calledWith('test-receive-secondary'));
+ assert.ok(onIncomingStanzaCallback.calledOnce);
+ assert.ok(onIncomingStanzaCallback.calledWith('test-receive-secondary'));
- ok(!secondary.sendMessage.called);
+ assert.ok(!secondary.sendMessage.called);
strategy.sendMessage('test-send');
- ok(!primary.sendMessage.called);
- ok(secondary.sendMessage.calledOnce);
- ok(secondary.sendMessage.calledWith('test-send'));
+ assert.ok(!primary.sendMessage.called);
+ assert.ok(secondary.sendMessage.calledOnce);
+ assert.ok(secondary.sendMessage.calledWith('test-send'));
}
);
-test('primary fails; secondary fails',
- function() {
- ok(!onStateChange.called);
- ok(!primary.connect.called);
+QUnit.test('primary fails; secondary fails',
+ function(assert) {
+ assert.ok(!onStateChange.called);
+ assert.ok(!primary.connect.called);
strategy.connect('server', 'username', 'authToken');
- ok(primary.connect.calledWith('server', 'username', 'authToken'));
-
- setState(primary, remoting.SignalStrategy.State.NOT_CONNECTED, true);
- ok(!secondary.connect.called);
- setState(primary, remoting.SignalStrategy.State.CONNECTING, true);
- setState(primary, remoting.SignalStrategy.State.FAILED, false);
- ok(secondary.connect.calledWith('server', 'username', 'authToken'));
- setState(secondary, remoting.SignalStrategy.State.NOT_CONNECTED, false);
- setState(primary, remoting.SignalStrategy.State.CONNECTING, false);
- setState(secondary, remoting.SignalStrategy.State.FAILED, true);
+ assert.ok(primary.connect.calledWith('server', 'username', 'authToken'));
+
+ setState(assert, primary, remoting.SignalStrategy.State.NOT_CONNECTED,
+ true);
+ assert.ok(!secondary.connect.called);
+ setState(assert, primary, remoting.SignalStrategy.State.CONNECTING, true);
+ setState(assert, primary, remoting.SignalStrategy.State.FAILED, false);
+ assert.ok(secondary.connect.calledWith('server', 'username', 'authToken'));
+ setState(assert, secondary, remoting.SignalStrategy.State.NOT_CONNECTED,
+ false);
+ setState(assert, primary, remoting.SignalStrategy.State.CONNECTING, false);
+ setState(assert, secondary, remoting.SignalStrategy.State.FAILED, true);
}
);
-test('primary times out; secondary succeeds',
- function() {
- ok(!onStateChange.called);
- ok(!primary.connect.called);
+QUnit.test('primary times out; secondary succeeds',
+ function(assert) {
+ assert.ok(!onStateChange.called);
+ assert.ok(!primary.connect.called);
strategy.connect('server', 'username', 'authToken');
- ok(primary.connect.calledWith('server', 'username', 'authToken'));
+ assert.ok(primary.connect.calledWith('server', 'username', 'authToken'));
- setState(primary, remoting.SignalStrategy.State.NOT_CONNECTED,
+ setState(assert, primary, remoting.SignalStrategy.State.NOT_CONNECTED,
true);
- setState(primary, remoting.SignalStrategy.State.CONNECTING, true);
+ setState(assert, primary, remoting.SignalStrategy.State.CONNECTING, true);
this.clock.tick(strategy.PRIMARY_CONNECT_TIMEOUT_MS_ - 1);
- ok(!secondary.connect.called);
+ assert.ok(!secondary.connect.called);
this.clock.tick(1);
- ok(secondary.connect.calledWith('server', 'username', 'authToken'));
- setState(secondary, remoting.SignalStrategy.State.NOT_CONNECTED, false);
- setState(secondary, remoting.SignalStrategy.State.CONNECTING, false);
- setState(secondary, remoting.SignalStrategy.State.HANDSHAKE, true);
- setState(secondary, remoting.SignalStrategy.State.CONNECTED, true);
+ assert.ok(secondary.connect.calledWith('server', 'username', 'authToken'));
+ setState(assert, secondary, remoting.SignalStrategy.State.NOT_CONNECTED,
+ false);
+ setState(assert, secondary, remoting.SignalStrategy.State.CONNECTING,
+ false);
+ setState(assert, secondary, remoting.SignalStrategy.State.HANDSHAKE, true);
+ setState(assert, secondary, remoting.SignalStrategy.State.CONNECTED, true);
strategy.sendConnectionSetupResults(logToServer);
- setState(secondary, remoting.SignalStrategy.State.CLOSED, true);
- setState(primary, remoting.SignalStrategy.State.FAILED, false);
+ setState(assert, secondary, remoting.SignalStrategy.State.CLOSED, true);
+ setState(assert, primary, remoting.SignalStrategy.State.FAILED, false);
logToServer.assertProgress(
remoting.SignalStrategy.Type.XMPP,
@@ -222,46 +233,50 @@ test('primary times out; secondary succeeds',
}
);
-test('primary times out; secondary fails',
- function() {
- ok(!onStateChange.called);
- ok(!primary.connect.called);
+QUnit.test('primary times out; secondary fails',
+ function(assert) {
+ assert.ok(!onStateChange.called);
+ assert.ok(!primary.connect.called);
strategy.connect('server', 'username', 'authToken');
- ok(primary.connect.calledWith('server', 'username', 'authToken'));
+ assert.ok(primary.connect.calledWith('server', 'username', 'authToken'));
- setState(primary, remoting.SignalStrategy.State.NOT_CONNECTED,
+ setState(assert, primary, remoting.SignalStrategy.State.NOT_CONNECTED,
true);
- setState(primary, remoting.SignalStrategy.State.CONNECTING, true);
+ setState(assert, primary, remoting.SignalStrategy.State.CONNECTING, true);
this.clock.tick(strategy.PRIMARY_CONNECT_TIMEOUT_MS_ - 1);
- ok(!secondary.connect.called);
+ assert.ok(!secondary.connect.called);
this.clock.tick(1);
- ok(secondary.connect.calledWith('server', 'username', 'authToken'));
- setState(secondary, remoting.SignalStrategy.State.NOT_CONNECTED, false);
- setState(secondary, remoting.SignalStrategy.State.CONNECTING, false);
- setState(secondary, remoting.SignalStrategy.State.FAILED, true);
+ assert.ok(secondary.connect.calledWith('server', 'username', 'authToken'));
+ setState(assert, secondary, remoting.SignalStrategy.State.NOT_CONNECTED,
+ false);
+ setState(assert, secondary, remoting.SignalStrategy.State.CONNECTING,
+ false);
+ setState(assert, secondary, remoting.SignalStrategy.State.FAILED, true);
}
);
-test('primary times out; secondary succeeds; primary succeeds late',
- function() {
- ok(!onStateChange.called);
- ok(!primary.connect.called);
+QUnit.test('primary times out; secondary succeeds; primary succeeds late',
+ function(assert) {
+ assert.ok(!onStateChange.called);
+ assert.ok(!primary.connect.called);
strategy.connect('server', 'username', 'authToken');
- ok(primary.connect.calledWith('server', 'username', 'authToken'));
+ assert.ok(primary.connect.calledWith('server', 'username', 'authToken'));
- setState(primary, remoting.SignalStrategy.State.NOT_CONNECTED,
+ setState(assert, primary, remoting.SignalStrategy.State.NOT_CONNECTED,
true);
- setState(primary, remoting.SignalStrategy.State.CONNECTING, true);
+ setState(assert, primary, remoting.SignalStrategy.State.CONNECTING, true);
this.clock.tick(strategy.PRIMARY_CONNECT_TIMEOUT_MS_);
- ok(secondary.connect.calledWith('server', 'username', 'authToken'));
- setState(secondary, remoting.SignalStrategy.State.NOT_CONNECTED, false);
- setState(secondary, remoting.SignalStrategy.State.CONNECTING, false);
- setState(secondary, remoting.SignalStrategy.State.HANDSHAKE, true);
- setState(secondary, remoting.SignalStrategy.State.CONNECTED, true);
+ assert.ok(secondary.connect.calledWith('server', 'username', 'authToken'));
+ setState(assert, secondary, remoting.SignalStrategy.State.NOT_CONNECTED,
+ false);
+ setState(assert, secondary, remoting.SignalStrategy.State.CONNECTING,
+ false);
+ setState(assert, secondary, remoting.SignalStrategy.State.HANDSHAKE, true);
+ setState(assert, secondary, remoting.SignalStrategy.State.CONNECTED, true);
strategy.sendConnectionSetupResults(logToServer);
- setState(primary, remoting.SignalStrategy.State.HANDSHAKE, false);
- setState(primary, remoting.SignalStrategy.State.CONNECTED, false);
+ setState(assert, primary, remoting.SignalStrategy.State.HANDSHAKE, false);
+ setState(assert, primary, remoting.SignalStrategy.State.CONNECTED, false);
logToServer.assertProgress(
remoting.SignalStrategy.Type.XMPP,
diff --git a/remoting/webapp/crd/js/host_table_entry_unittest.js b/remoting/webapp/crd/js/host_table_entry_unittest.js
index 9f36d78..01c4ea6 100644
--- a/remoting/webapp/crd/js/host_table_entry_unittest.js
+++ b/remoting/webapp/crd/js/host_table_entry_unittest.js
@@ -12,8 +12,8 @@ var onConnect_ = null;
var onRename_ = null;
var onDelete_ = null;
-module('HostTableEntry', {
- setup: function() {
+QUnit.module('HostTableEntry', {
+ beforeEach: function() {
onConnect_ = /** @type {function(string)} */ (sinon.spy());
onRename_ = /** @type {function(remoting.HostTableEntry)} */ (sinon.spy());
onDelete_ = /** @type {function(remoting.HostTableEntry)} */ (sinon.spy());
@@ -32,7 +32,7 @@ module('HostTableEntry', {
return tag;
});
},
- teardown: function() {
+ afterEach: function() {
hostTableEntry_.dispose();
hostTableEntry_ = null;
$testStub(chrome.i18n.getMessage).restore();
@@ -59,23 +59,25 @@ function setHost(hostName, status, opt_offlineReason) {
function sendKeydown(/** HTMLElement */ target, /** number */ keyCode) {
var event = document.createEvent('KeyboardEvent');
Object.defineProperty(
- event, 'which', {get: function() { return keyCode; }});
+ event, 'which', {get: function(assert) { return keyCode; }});
event.initKeyboardEvent("keydown", true, true, document.defaultView,
false, false, false, false, keyCode, keyCode);
target.dispatchEvent(event);
}
function verifyVisible(
+ /** QUnit.Assert */ assert,
/** HTMLElement*/ element,
/** boolean */ isVisible,
/** string= */ opt_name) {
var expectedVisibility = (isVisible) ? 'visible' : 'hidden';
- QUnit.equal(element.hidden, !isVisible,
+ assert.equal(element.hidden, !isVisible,
'Element ' + opt_name + ' should be ' + expectedVisibility);
}
-test('Clicking on the confirm button in the confirm dialog deletes the host',
- function() {
+QUnit.test(
+ 'Clicking on the confirm button in the confirm dialog deletes the host',
+ function(assert) {
// Setup.
sinon.stub(remoting, 'setMode', function(/** remoting.AppMode */ mode) {
if (mode === remoting.AppMode.CONFIRM_HOST_DELETE) {
@@ -93,9 +95,9 @@ test('Clicking on the confirm button in the confirm dialog deletes the host',
$testStub(remoting.setMode).restore();
});
-test(
+QUnit.test(
'Clicking on the cancel button in the confirm dialog cancels host deletion',
- function() {
+ function(assert) {
// Setup.
sinon.stub(remoting, 'setMode', function(/** remoting.AppMode */ mode) {
if (mode === remoting.AppMode.CONFIRM_HOST_DELETE) {
@@ -113,7 +115,8 @@ test(
$testStub(remoting.setMode).restore();
});
-test('Clicking on the rename button shows the input field.', function() {
+QUnit.test('Clicking on the rename button shows the input field.',
+ function(assert) {
// Invoke.
hostTableEntry_.element().querySelector('.rename-button').click();
@@ -121,24 +124,24 @@ test('Clicking on the rename button shows the input field.', function() {
var inputField =
hostTableEntry_.element().querySelector('.host-rename-input');
- verifyVisible(inputField, true, 'inputField');
- QUnit.equal(document.activeElement, inputField);
+ verifyVisible(assert, inputField, true, 'inputField');
+ assert.equal(document.activeElement, inputField);
});
-test('Host renaming is canceled on ESCAPE key.', function() {
+QUnit.test('Host renaming is canceled on ESCAPE key.', function(assert) {
// Invoke.
var inputField =
hostTableEntry_.element().querySelector('.host-rename-input');
hostTableEntry_.element().querySelector('.rename-button').click();
// Verify.
- verifyVisible(inputField, true, 'inputField');
- QUnit.equal(document.activeElement, inputField);
+ verifyVisible(assert, inputField, true, 'inputField');
+ assert.equal(document.activeElement, inputField);
sendKeydown(inputField, 27 /* ESCAPE */);
- verifyVisible(inputField, false, 'inputField');
+ verifyVisible(assert, inputField, false, 'inputField');
});
-test('Host renaming commits on ENTER.', function() {
+QUnit.test('Host renaming commits on ENTER.', function(assert) {
// Invoke.
var inputField =
hostTableEntry_.element().querySelector('.host-rename-input');
@@ -147,49 +150,51 @@ test('Host renaming commits on ENTER.', function() {
sendKeydown(inputField, 13 /* ENTER */);
// Verify
- verifyVisible(inputField, false, 'inputField');
+ verifyVisible(assert, inputField, false, 'inputField');
sinon.assert.called(onRename_);
- QUnit.equal(hostTableEntry_.host.hostName, 'Renamed Host');
+ assert.equal(hostTableEntry_.host.hostName, 'Renamed Host');
// Renaming shouldn't trigger a connection request.
sinon.assert.notCalled(onConnect_);
});
-test('HostTableEntry renders the host name correctly.', function() {
+QUnit.test('HostTableEntry renders the host name correctly.', function(assert) {
var label = hostTableEntry_.element().querySelector('.host-name-label');
- QUnit.equal(label.innerText, 'LocalHost');
+ assert.equal(label.innerText, 'LocalHost');
});
-test('HostTableEntry renders an offline host correctly.', function() {
+QUnit.test('HostTableEntry renders an offline host correctly.',
+ function(assert) {
setHost('LocalHost', 'OFFLINE', 'INITIALIZATION_FAILED');
var label = hostTableEntry_.element().querySelector('.host-name-label');
- QUnit.equal(label.innerText, 'OFFLINE');
- QUnit.equal(label.title, 'OFFLINE_REASON_INITIALIZATION_FAILED');
+ assert.equal(label.innerText, 'OFFLINE');
+ assert.equal(label.title, 'OFFLINE_REASON_INITIALIZATION_FAILED');
});
-test('HostTableEntry renders an out-of-date host correctly', function() {
+QUnit.test('HostTableEntry renders an out-of-date host correctly',
+ function(assert) {
sinon.stub(remoting.Host, 'needsUpdate').returns(true);
setHost('LocalHost', 'ONLINE');
var warningOverlay =
hostTableEntry_.element().querySelector('.warning-overlay');
var label = hostTableEntry_.element().querySelector('.host-name-label');
- verifyVisible(warningOverlay, true, 'warning overlay');
- QUnit.equal(label.innerText, 'UPDATE_REQUIRED');
+ verifyVisible(assert, warningOverlay, true, 'warning overlay');
+ assert.equal(label.innerText, 'UPDATE_REQUIRED');
});
-test('Clicking on an online host connects it', function() {
+QUnit.test('Clicking on an online host connects it', function(assert) {
hostTableEntry_.element().querySelector('.host-name-label').click();
sinon.assert.calledWith(onConnect_,
encodeURIComponent(hostTableEntry_.host.hostId));
});
-test('Clicking on an offline host should be a no-op', function() {
+QUnit.test('Clicking on an offline host should be a no-op', function(assert) {
setHost('LocalHost', 'OFFLINE');
hostTableEntry_.element().querySelector('.host-name-label').click();
sinon.assert.notCalled(onConnect_);
});
-test('HostTableEntry handles host that is null', function() {
+QUnit.test('HostTableEntry handles host that is null', function(assert) {
hostTableEntry_.setHost(null);
hostTableEntry_.element().querySelector('.host-name-label').click();
sinon.assert.notCalled(onConnect_);
diff --git a/remoting/webapp/crd/js/identity_unittest.js b/remoting/webapp/crd/js/identity_unittest.js
index 5bd9452c8..3971e61 100644
--- a/remoting/webapp/crd/js/identity_unittest.js
+++ b/remoting/webapp/crd/js/identity_unittest.js
@@ -16,22 +16,25 @@ var getAuthToken = null;
var identity = null;
/**
+ * @param {QUnit.Assert} assert
* @constructor
* @implements {remoting.Identity.ConsentDialog}
*/
-var MockConsent = function() {
+var MockConsent = function(assert) {
/** @type {boolean} */
this.grantConsent = true;
/** @type {Array<string> | undefined} */
this.scopes = undefined;
+ /** @private {QUnit.Assert} */
+ this.assert_ = assert;
};
MockConsent.prototype.show = function() {
// The consent dialog should only be shown if a previous call to getAuthToken
// with {interactive: false} failed, and it should occur before any call with
// {interactive: true}.
- ok(getAuthToken.calledOnce);
- ok(getAuthToken.calledWith({'interactive': false}));
+ this.assert_.ok(getAuthToken.calledOnce);
+ this.assert_.ok(getAuthToken.calledWith({'interactive': false}));
getAuthToken.reset();
if (this.grantConsent) {
@@ -40,28 +43,28 @@ MockConsent.prototype.show = function() {
return Promise.resolve();
};
-module('Identity', {
- setup: function() {
+QUnit.module('Identity', {
+ beforeEach: function(/** QUnit.Assert*/ assert) {
chromeMocks.identity.mock$clearToken();
chromeMocks.activate(['identity', 'runtime']);
- consentDialog = new MockConsent();
+ consentDialog = new MockConsent(assert);
promptForConsent = sinon.spy(consentDialog, 'show');
identity = new remoting.Identity(consentDialog);
getAuthToken = sinon.spy(chromeMocks.identity, 'getAuthToken');
},
- teardown: function() {
+ afterEach: function() {
chromeMocks.restore();
getAuthToken.restore();
}
});
-test('consent is requested only on first invocation', function() {
- ok(!promptForConsent.called);
+QUnit.test('consent is requested only on first invocation', function(assert) {
+ assert.ok(!promptForConsent.called);
return identity.getToken().then(
function(/** string */ token) {
- ok(promptForConsent.called);
- ok(getAuthToken.calledOnce);
- ok(getAuthToken.calledWith({'interactive': true}));
+ assert.ok(promptForConsent.called);
+ assert.ok(getAuthToken.calledOnce);
+ assert.ok(getAuthToken.calledWith({'interactive': true}));
// Request another token.
promptForConsent.reset();
@@ -69,33 +72,33 @@ test('consent is requested only on first invocation', function() {
return identity.getToken();
}).then(function(/** string */ token) {
- ok(!promptForConsent.called);
- ok(getAuthToken.calledOnce);
- ok(getAuthToken.calledWith({'interactive': true}));
- equal(token, 'token');
+ assert.ok(!promptForConsent.called);
+ assert.ok(getAuthToken.calledOnce);
+ assert.ok(getAuthToken.calledWith({'interactive': true}));
+ assert.equal(token, 'token');
});
});
-test('cancellations are reported correctly', function() {
+QUnit.test('cancellations are reported correctly', function(assert) {
consentDialog.grantConsent = false;
chromeMocks.runtime.lastError.message = 'The user did not approve access.';
return identity.getToken().then(
function(/** string */ token) {
- ok(false, 'expected getToken() to fail');
+ assert.ok(false, 'expected getToken() to fail');
}).catch(function(/** remoting.Error */ error) {
- equal(error.getTag(), remoting.Error.Tag.CANCELLED);
+ assert.equal(error.getTag(), remoting.Error.Tag.CANCELLED);
});
});
-test('other errors are reported correctly', function() {
+QUnit.test('other errors are reported correctly', function(assert) {
consentDialog.grantConsent = false;
chromeMocks.runtime.lastError.message = '<some other error message>';
return identity.getToken().then(
function(/** string */ token) {
- ok(false, 'expected getToken() to fail');
+ assert.ok(false, 'expected getToken() to fail');
}).catch(function(/** remoting.Error */ error) {
- equal(error.getTag(), remoting.Error.Tag.NOT_AUTHENTICATED);
+ assert.equal(error.getTag(), remoting.Error.Tag.NOT_AUTHENTICATED);
});
});
diff --git a/remoting/webapp/crd/js/l10n_unittest.js b/remoting/webapp/crd/js/l10n_unittest.js
index 78ea48e..bbb1425 100644
--- a/remoting/webapp/crd/js/l10n_unittest.js
+++ b/remoting/webapp/crd/js/l10n_unittest.js
@@ -6,46 +6,47 @@
'use strict';
-module('l10n', {
- setup: function() {
+QUnit.module('l10n', {
+ beforeEach: function() {
sinon.stub(chrome.i18n, 'getMessage');
},
- teardown: function() {
+ afterEach: function() {
$testStub(chrome.i18n.getMessage).restore();
}
});
-test('getTranslationOrError(tag) should return tag on error', function() {
+QUnit.test('getTranslationOrError(tag) should return tag on error',
+ function(assert) {
var translation = l10n.getTranslationOrError('non_existent_tag');
- equal(translation, 'non_existent_tag');
+ assert.equal(translation, 'non_existent_tag');
});
-test('localizeElementFromTag() should replace innerText by default',
- function() {
+QUnit.test('localizeElementFromTag() should replace innerText by default',
+ function(assert) {
var element = document.createElement('div');
$testStub(chrome.i18n.getMessage).withArgs('tag')
.returns('<b>Hello World</b>');
l10n.localizeElementFromTag(element, 'tag');
- equal(element.innerHTML, '&lt;b&gt;Hello World&lt;/b&gt;');
+ assert.equal(element.innerHTML, '&lt;b&gt;Hello World&lt;/b&gt;');
});
-test('localizeElementFromTag() should replace innerHTML if flag is set',
- function() {
+QUnit.test('localizeElementFromTag() should replace innerHTML if flag is set',
+ function(assert) {
var element = document.createElement('div');
$testStub(chrome.i18n.getMessage).withArgs('tag')
.returns('<b>Hello World</b>');
l10n.localizeElementFromTag(element, 'tag', null, true);
- equal(element.innerHTML, '<b>Hello World</b>');
+ assert.equal(element.innerHTML, '<b>Hello World</b>');
});
-test(
+QUnit.test(
'localizeElement() should replace innerText using the "i18n-content" ' +
'attribute as the tag',
- function() {
+ function(assert) {
var element = document.createElement('div');
element.setAttribute('i18n-content', 'tag');
$testStub(chrome.i18n.getMessage).withArgs('tag')
@@ -53,13 +54,13 @@ test(
l10n.localizeElement(element);
- equal(element.innerHTML, '&lt;b&gt;Hello World&lt;/b&gt;');
+ assert.equal(element.innerHTML, '&lt;b&gt;Hello World&lt;/b&gt;');
});
-test(
+QUnit.test(
'localize() should replace element title using the "i18n-title" ' +
'attribute as the tag',
- function() {
+ function(assert) {
var fixture = document.getElementById('qunit-fixture');
fixture.innerHTML = '<div class="target" i18n-title="tag"></div>';
$testStub(chrome.i18n.getMessage)
@@ -69,10 +70,10 @@ test(
l10n.localize();
var target = document.querySelector('.target');
- equal(target.title, 'localized title');
+ assert.equal(target.title, 'localized title');
});
-test('localize() should support string substitutions', function() {
+QUnit.test('localize() should support string substitutions', function(assert) {
var fixture = document.getElementById('qunit-fixture');
fixture.innerHTML =
'<div class="target" ' +
@@ -87,10 +88,10 @@ test('localize() should support string substitutions', function() {
l10n.localize();
var target = document.querySelector('.target');
- equal(target.innerText, 'localized');
+ assert.equal(target.innerText, 'localized');
});
-test('localize() should support tag substitutions', function() {
+QUnit.test('localize() should support tag substitutions', function(assert) {
var fixture = document.getElementById('qunit-fixture');
fixture.innerHTML =
'<div class="target" i18n-content="tag"' +
@@ -105,7 +106,7 @@ test('localize() should support tag substitutions', function() {
l10n.localize();
var target = document.querySelector('.target');
- equal(target.innerText, 'localized');
+ assert.equal(target.innerText, 'localized');
});
})();
diff --git a/remoting/webapp/crd/js/menu_button_unittest.js b/remoting/webapp/crd/js/menu_button_unittest.js
index 1367b0d..c664618 100644
--- a/remoting/webapp/crd/js/menu_button_unittest.js
+++ b/remoting/webapp/crd/js/menu_button_unittest.js
@@ -13,8 +13,8 @@ var onHide = null;
/** @type {remoting.MenuButton} */
var menuButton = null;
-module('MenuButton', {
- setup: function() {
+QUnit.module('MenuButton', {
+ beforeEach: function() {
var fixture = document.getElementById('qunit-fixture');
fixture.innerHTML =
'<span class="menu-button" id="menu-button-container">' +
@@ -30,28 +30,29 @@ module('MenuButton', {
/** @type {function():void} */ (onShow),
/** @type {function():void} */ (onHide));
},
- teardown: function() {
+ afterEach: function() {
onShow = null;
onHide = null;
menuButton = null;
}
});
-test('should display on click', function() {
+QUnit.test('should display on click', function(assert) {
var menu = menuButton.menu();
- ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
+ assert.ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
menuButton.button().click();
- ok(menu.offsetWidth != 0 && menu.offsetHeight != 0);
+ assert.ok(menu.offsetWidth != 0 && menu.offsetHeight != 0);
});
-test('should dismiss when the menu is clicked', function() {
+QUnit.test('should dismiss when the menu is clicked', function(assert) {
var menu = menuButton.menu();
menuButton.button().click();
menu.click();
- ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
+ assert.ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
});
-test('should dismiss when anything outside the menu is clicked', function() {
+QUnit.test('should dismiss when anything outside the menu is clicked',
+ function(assert) {
var menu = menuButton.menu();
menuButton.button().click();
var x = menu.offsetRight + 1;
@@ -59,36 +60,36 @@ test('should dismiss when anything outside the menu is clicked', function() {
var notMenu = document.elementFromPoint(x, y);
base.debug.assert(notMenu != menu);
notMenu.click();
- ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
+ assert.ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
});
-test('should dismiss when menu item is clicked', function() {
+QUnit.test('should dismiss when menu item is clicked', function(assert) {
var menu = menuButton.menu();
menuButton.button().click();
var element = document.getElementById('menu-option-1');
element.click();
- ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
+ assert.ok(menu.offsetWidth == 0 && menu.offsetHeight == 0);
});
-test('should invoke callbacks', function() {
- ok(!onShow.called);
+QUnit.test('should invoke callbacks', function(assert) {
+ assert.ok(!onShow.called);
menuButton.button().click();
- ok(onShow.called);
- ok(!onHide.called);
+ assert.ok(onShow.called);
+ assert.ok(!onHide.called);
menuButton.menu().click();
- ok(onHide.called);
+ assert.ok(onHide.called);
});
-test('select method should set/unset background image', function() {
+QUnit.test('select method should set/unset background image', function(assert) {
var element = document.getElementById('menu-option-1');
var style = window.getComputedStyle(element);
- ok(style.backgroundImage == 'none');
+ assert.ok(style.backgroundImage == 'none');
remoting.MenuButton.select(element, true);
style = window.getComputedStyle(element);
- ok(style.backgroundImage != 'none');
+ assert.ok(style.backgroundImage != 'none');
remoting.MenuButton.select(element, false);
style = window.getComputedStyle(element);
- ok(style.backgroundImage == 'none');
+ assert.ok(style.backgroundImage == 'none');
});
}());
diff --git a/remoting/webapp/crd/js/xhr_unittest.js b/remoting/webapp/crd/js/xhr_unittest.js
index ea32042..7102c2e 100644
--- a/remoting/webapp/crd/js/xhr_unittest.js
+++ b/remoting/webapp/crd/js/xhr_unittest.js
@@ -10,195 +10,197 @@
(function() {
'use strict';
+QUnit.module('xhr');
-module('xhr', {
- setup: function() {
- },
- teardown: function() {
- }
-});
-
-test('urlencodeParamHash', function() {
- QUnit.equal(
+QUnit.test('urlencodeParamHash', function(assert) {
+ assert.equal(
remoting.xhr.urlencodeParamHash({}),
'');
- QUnit.equal(
+ assert.equal(
remoting.xhr.urlencodeParamHash({'key': 'value'}),
'key=value');
- QUnit.equal(
+ assert.equal(
remoting.xhr.urlencodeParamHash({'key /?=&': 'value /?=&'}),
'key%20%2F%3F%3D%26=value%20%2F%3F%3D%26');
- QUnit.equal(
+ assert.equal(
remoting.xhr.urlencodeParamHash({'k1': 'v1', 'k2': 'v2'}),
'k1=v1&k2=v2');
});
-asyncTest('basic GET', function() {
+QUnit.test('basic GET', function(assert) {
sinon.useFakeXMLHttpRequest();
+ var done = assert.async();
var request = remoting.xhr.start({
method: 'GET',
url: 'http://foo.com',
onDone: function(xhr) {
- QUnit.ok(xhr === request);
- QUnit.equal(xhr.status, 200);
- QUnit.equal(xhr.responseText, 'body');
- QUnit.start();
+ assert.ok(xhr === request);
+ assert.equal(xhr.status, 200);
+ assert.equal(xhr.responseText, 'body');
+ done();
}
});
- QUnit.equal(request.method, 'GET');
- QUnit.equal(request.url, 'http://foo.com');
- QUnit.equal(request.withCredentials, false);
- QUnit.equal(request.requestBody, null);
- QUnit.ok(!('Content-type' in request.requestHeaders));
+ assert.equal(request.method, 'GET');
+ assert.equal(request.url, 'http://foo.com');
+ assert.equal(request.withCredentials, false);
+ assert.equal(request.requestBody, null);
+ assert.ok(!('Content-type' in request.requestHeaders));
request.respond(200, {}, 'body');
});
-asyncTest('GET with param string', function() {
+QUnit.test('GET with param string', function(assert) {
+ var done = assert.async();
sinon.useFakeXMLHttpRequest();
var request = remoting.xhr.start({
method: 'GET',
url: 'http://foo.com',
onDone: function(xhr) {
- QUnit.ok(xhr === request);
- QUnit.equal(xhr.status, 200);
- QUnit.equal(xhr.responseText, 'body');
- QUnit.start();
+ assert.ok(xhr === request);
+ assert.equal(xhr.status, 200);
+ assert.equal(xhr.responseText, 'body');
+ done();
},
urlParams: 'the_param_string'
});
- QUnit.equal(request.method, 'GET');
- QUnit.equal(request.url, 'http://foo.com?the_param_string');
- QUnit.equal(request.withCredentials, false);
- QUnit.equal(request.requestBody, null);
- QUnit.ok(!('Content-type' in request.requestHeaders));
+ assert.equal(request.method, 'GET');
+ assert.equal(request.url, 'http://foo.com?the_param_string');
+ assert.equal(request.withCredentials, false);
+ assert.equal(request.requestBody, null);
+ assert.ok(!('Content-type' in request.requestHeaders));
request.respond(200, {}, 'body');
});
-asyncTest('GET with param object', function() {
+QUnit.test('GET with param object', function(assert) {
+ var done = assert.async();
sinon.useFakeXMLHttpRequest();
var request = remoting.xhr.start({
method: 'GET',
url: 'http://foo.com',
onDone: function(xhr) {
- QUnit.ok(xhr === request);
- QUnit.equal(xhr.status, 200);
- QUnit.equal(xhr.responseText, 'body');
- QUnit.start();
+ assert.ok(xhr === request);
+ assert.equal(xhr.status, 200);
+ assert.equal(xhr.responseText, 'body');
+ done();
},
urlParams: {'a': 'b', 'c': 'd'}
});
- QUnit.equal(request.method, 'GET');
- QUnit.equal(request.url, 'http://foo.com?a=b&c=d');
- QUnit.equal(request.withCredentials, false);
- QUnit.equal(request.requestBody, null);
- QUnit.ok(!('Content-type' in request.requestHeaders));
+ assert.equal(request.method, 'GET');
+ assert.equal(request.url, 'http://foo.com?a=b&c=d');
+ assert.equal(request.withCredentials, false);
+ assert.equal(request.requestBody, null);
+ assert.ok(!('Content-type' in request.requestHeaders));
request.respond(200, {}, 'body');
});
-asyncTest('GET with headers', function() {
+QUnit.test('GET with headers', function(assert) {
sinon.useFakeXMLHttpRequest();
+ var done = assert.async();
var request = remoting.xhr.start({
method: 'GET',
url: 'http://foo.com',
onDone: function(xhr) {
- QUnit.ok(xhr === request);
- QUnit.equal(xhr.status, 200);
- QUnit.equal(xhr.responseText, 'body');
- QUnit.start();
+ assert.ok(xhr === request);
+ assert.equal(xhr.status, 200);
+ assert.equal(xhr.responseText, 'body');
+ done();
},
headers: {'Header1': 'headerValue1', 'Header2': 'headerValue2'}
});
- QUnit.equal(request.method, 'GET');
- QUnit.equal(request.url, 'http://foo.com');
- QUnit.equal(request.withCredentials, false);
- QUnit.equal(request.requestBody, null);
- QUnit.equal(
+ assert.equal(request.method, 'GET');
+ assert.equal(request.url, 'http://foo.com');
+ assert.equal(request.withCredentials, false);
+ assert.equal(request.requestBody, null);
+ assert.equal(
request.requestHeaders['Header1'],
'headerValue1');
- QUnit.equal(
+ assert.equal(
request.requestHeaders['Header2'],
'headerValue2');
- QUnit.ok(!('Content-type' in request.requestHeaders));
+ assert.ok(!('Content-type' in request.requestHeaders));
request.respond(200, {}, 'body');
});
-asyncTest('GET with credentials', function() {
+QUnit.test('GET with credentials', function(assert) {
sinon.useFakeXMLHttpRequest();
+ var done = assert.async();
var request = remoting.xhr.start({
method: 'GET',
url: 'http://foo.com',
onDone: function(xhr) {
- QUnit.ok(xhr === request);
- QUnit.equal(xhr.status, 200);
- QUnit.equal(xhr.responseText, 'body');
- QUnit.start();
+ assert.ok(xhr === request);
+ assert.equal(xhr.status, 200);
+ assert.equal(xhr.responseText, 'body');
+ done();
},
withCredentials: true
});
- QUnit.equal(request.method, 'GET');
- QUnit.equal(request.url, 'http://foo.com');
- QUnit.equal(request.withCredentials, true);
- QUnit.equal(request.requestBody, null);
- QUnit.ok(!('Content-type' in request.requestHeaders));
+ assert.equal(request.method, 'GET');
+ assert.equal(request.url, 'http://foo.com');
+ assert.equal(request.withCredentials, true);
+ assert.equal(request.requestBody, null);
+ assert.ok(!('Content-type' in request.requestHeaders));
request.respond(200, {}, 'body');
});
-asyncTest('POST with text content', function() {
+QUnit.test('POST with text content', function(assert) {
sinon.useFakeXMLHttpRequest();
+ var done = assert.async();
var request = remoting.xhr.start({
method: 'POST',
url: 'http://foo.com',
onDone: function(xhr) {
- QUnit.ok(xhr === request);
- QUnit.equal(xhr.status, 200);
- QUnit.equal(xhr.responseText, 'body');
- QUnit.start();
+ assert.ok(xhr === request);
+ assert.equal(xhr.status, 200);
+ assert.equal(xhr.responseText, 'body');
+ done();
},
textContent: 'the_content_string'
});
- QUnit.equal(request.method, 'POST');
- QUnit.equal(request.url, 'http://foo.com');
- QUnit.equal(request.withCredentials, false);
- QUnit.equal(request.requestBody, 'the_content_string');
- QUnit.ok(!('Content-type' in request.requestHeaders));
+ assert.equal(request.method, 'POST');
+ assert.equal(request.url, 'http://foo.com');
+ assert.equal(request.withCredentials, false);
+ assert.equal(request.requestBody, 'the_content_string');
+ assert.ok(!('Content-type' in request.requestHeaders));
request.respond(200, {}, 'body');
});
-asyncTest('POST with form content', function() {
+QUnit.test('POST with form content', function(assert) {
sinon.useFakeXMLHttpRequest();
+ var done = assert.async();
var request = remoting.xhr.start({
method: 'POST',
url: 'http://foo.com',
onDone: function(xhr) {
- QUnit.ok(xhr === request);
- QUnit.equal(xhr.status, 200);
- QUnit.equal(xhr.responseText, 'body');
- QUnit.start();
+ assert.ok(xhr === request);
+ assert.equal(xhr.status, 200);
+ assert.equal(xhr.responseText, 'body');
+ done();
},
formContent: {'a': 'b', 'c': 'd'}
});
- QUnit.equal(request.method, 'POST');
- QUnit.equal(request.url, 'http://foo.com');
- QUnit.equal(request.withCredentials, false);
- QUnit.equal(request.requestBody, 'a=b&c=d');
- QUnit.equal(
+ assert.equal(request.method, 'POST');
+ assert.equal(request.url, 'http://foo.com');
+ assert.equal(request.withCredentials, false);
+ assert.equal(request.requestBody, 'a=b&c=d');
+ assert.equal(
request.requestHeaders['Content-type'],
'application/x-www-form-urlencoded');
request.respond(200, {}, 'body');
});
-asyncTest('defaultResponse 200', function() {
+QUnit.test('defaultResponse 200', function(assert) {
sinon.useFakeXMLHttpRequest();
+ var done = assert.async();
var onDone = function() {
- QUnit.ok(true);
- QUnit.start();
+ assert.ok(true);
+ done();
};
var onError = function(error) {
- QUnit.ok(false);
- QUnit.start();
+ assert.ok(false);
+ done();
};
var request = remoting.xhr.start({
@@ -210,17 +212,17 @@ asyncTest('defaultResponse 200', function() {
});
-asyncTest('defaultResponse 404', function() {
+QUnit.test('defaultResponse 404', function(assert) {
sinon.useFakeXMLHttpRequest();
-
+ var done = assert.async();
var onDone = function() {
- QUnit.ok(false);
- QUnit.start();
+ assert.ok(false);
+ done();
};
var onError = function(error) {
- QUnit.ok(true);
- QUnit.start();
+ assert.ok(true);
+ done();
};
var request = remoting.xhr.start({
diff --git a/remoting/webapp/crd/js/xmpp_connection_unittest.js b/remoting/webapp/crd/js/xmpp_connection_unittest.js
index f631e2b..a96ef9b 100644
--- a/remoting/webapp/crd/js/xmpp_connection_unittest.js
+++ b/remoting/webapp/crd/js/xmpp_connection_unittest.js
@@ -24,19 +24,23 @@ function onStateChange(/** remoting.SignalStrategy.State */ state) {
stateChangeHandler(state)
};
-/** @returns {Promise} */
-function expectNextState(/** remoting.SignalStrategy.State */ expectedState) {
+/**
+ * @param {QUnit.Assert} assert
+ * @param {remoting.SignalStrategy.State} expectedState
+ * @returns {Promise}
+ */
+function expectNextState(assert, expectedState) {
return new Promise(function(resolve, reject) {
stateChangeHandler = function(/** remoting.SignalStrategy.State */ state) {
- QUnit.equal(state, expectedState);
- QUnit.equal(connection.getState(), expectedState);
+ assert.equal(state, expectedState);
+ assert.equal(connection.getState(), expectedState);
resolve(0);
}
});
}
-module('XmppConnection', {
- setup: function() {
+QUnit.module('XmppConnection', {
+ beforeEach: function() {
onStanzaStr = sinon.spy();
/** @param {Element} stanza */
function onStanza(stanza) {
@@ -53,30 +57,34 @@ module('XmppConnection', {
}
});
-QUnit.asyncTest('should go to FAILED state when failed to connect', function() {
+QUnit.test('should go to FAILED state when failed to connect',
+ function(assert) {
+ var done = assert.async();
$testStub(socket.connect).withArgs("xmpp.example.com", 123)
.returns(new Promise(function(resolve, reject) { reject(-1); }));
var deferredSend = new base.Deferred();
$testStub(socket.send).onFirstCall().returns(deferredSend.promise());
- expectNextState(remoting.SignalStrategy.State.CONNECTING).then(onConnecting);
+ expectNextState(assert, remoting.SignalStrategy.State.CONNECTING)
+ .then(onConnecting);
connection.connect('xmpp.example.com:123', 'testUsername@gmail.com',
'testToken');
function onConnecting() {
- expectNextState(remoting.SignalStrategy.State.FAILED).then(onFailed);
+ expectNextState(assert, remoting.SignalStrategy.State.FAILED)
+ .then(onFailed);
}
function onFailed() {
sinon.assert.calledWith(socket.dispose);
- QUnit.ok(connection.getError().hasTag(remoting.Error.Tag.NETWORK_FAILURE));
-
- QUnit.start();
+ assert.ok(connection.getError().hasTag(remoting.Error.Tag.NETWORK_FAILURE));
+ done();
}
});
-QUnit.asyncTest('should use XmppLoginHandler for handshake', function() {
+QUnit.test('should use XmppLoginHandler for handshake', function(assert) {
+
$testStub(socket.connect).withArgs("xmpp.example.com", 123)
.returns(new Promise(function(resolve, reject) { resolve(0) }));
@@ -86,24 +94,17 @@ QUnit.asyncTest('should use XmppLoginHandler for handshake', function() {
var parser = new remoting.XmppStreamParser();
var parserMock = sinon.mock(parser);
var setCallbacksCalled = parserMock.expects('setCallbacks').once();
+ var State = remoting.SignalStrategy.State;
- expectNextState(remoting.SignalStrategy.State.CONNECTING).then(onConnecting);
- connection.connect(
- 'xmpp.example.com:123', 'testUsername@gmail.com', 'testToken');
-
- function onConnecting() {
- expectNextState(remoting.SignalStrategy.State.HANDSHAKE).then(onHandshake);
- }
-
- function onHandshake() {
+ var promise = expectNextState(assert, State.CONNECTING).then(function() {
+ return expectNextState(assert, State.HANDSHAKE);
+ }).then(function() {
var handshakeDoneCallback =
connection.loginHandler_.getHandshakeDoneCallbackForTesting();
-
- expectNextState(remoting.SignalStrategy.State.CONNECTED).then(onConnected);
+ var onConnected = expectNextState(assert, State.CONNECTED);
handshakeDoneCallback('test@example.com/123123', parser);
- }
-
- function onConnected() {
+ return onConnected;
+ }).then(function() {
setCallbacksCalled.verify();
// Simulate read() callback with |data|. It should be passed to
@@ -114,9 +115,11 @@ QUnit.asyncTest('should use XmppLoginHandler for handshake', function() {
parserMock.expects('appendData').once().withArgs(data);
$testStub(socket.startReceiving).getCall(0).args[0](data);
appendDataCalled.verify();
+ });
- QUnit.start();
- }
+ connection.connect(
+ 'xmpp.example.com:123', 'testUsername@gmail.com', 'testToken');
+ return promise;
});
})();
diff --git a/remoting/webapp/crd/js/xmpp_login_handler_unittest.js b/remoting/webapp/crd/js/xmpp_login_handler_unittest.js
index dfd1a61..d06a847 100644
--- a/remoting/webapp/crd/js/xmpp_login_handler_unittest.js
+++ b/remoting/webapp/crd/js/xmpp_login_handler_unittest.js
@@ -32,8 +32,8 @@ var onError = function(error, message) {};
/** @type {remoting.XmppLoginHandler} */
var loginHandler = null;
-module('XmppLoginHandler', {
- setup: function() {
+QUnit.module('XmppLoginHandler', {
+ beforeEach: function() {
sendMessage_spy = sinon.spy();
sendMessage = /** @type {function(string):void} */ (sendMessage_spy);
startTls_spy = sinon.spy();
@@ -85,7 +85,7 @@ function handshakeBase() {
'</stream:features>'));
}
-test('should authenticate', function() {
+QUnit.test('should authenticate', function() {
handshakeBase();
loginHandler.onDataReceived(
@@ -122,7 +122,7 @@ test('should authenticate', function() {
sinon.assert.calledWith(onHandshakeDone);
});
-test('use <starttls> handshake', function() {
+QUnit.test('use <starttls> handshake', function() {
loginHandler = new remoting.XmppLoginHandler(
'google.com', testUsername, testToken, true, sendMessage,
startTls, onHandshakeDone, onError);
@@ -155,8 +155,9 @@ test('use <starttls> handshake', function() {
sinon.assert.calledWith(startTls);
});
-test('should return AUTHENTICATION_FAILED error when failed to authenticate',
- function() {
+QUnit.test(
+ 'should return AUTHENTICATION_FAILED error when failed to authenticate',
+ function() {
handshakeBase();
loginHandler.onDataReceived(
@@ -166,7 +167,7 @@ test('should return AUTHENTICATION_FAILED error when failed to authenticate',
remoting.Error.Tag.AUTHENTICATION_FAILED));
});
-test('should return UNEXPECTED error when failed to parse stream',
+QUnit.test('should return UNEXPECTED error when failed to parse stream',
function() {
handshakeBase();
loginHandler.onDataReceived(
diff --git a/remoting/webapp/crd/js/xmpp_stream_parser_unittest.js b/remoting/webapp/crd/js/xmpp_stream_parser_unittest.js
index ec6cc45..564d0e3 100644
--- a/remoting/webapp/crd/js/xmpp_stream_parser_unittest.js
+++ b/remoting/webapp/crd/js/xmpp_stream_parser_unittest.js
@@ -15,8 +15,8 @@ var onError = function(msg) {};
/** @type {remoting.XmppStreamParser} */
var parser = null;
-module('XmppStreamParser', {
- setup: function() {
+QUnit.module('XmppStreamParser', {
+ beforeEach: function() {
onStanzaStr = sinon.spy();
onError = /** @type {function(string):void} */ (sinon.spy());
/** @param {Element} stanza */
@@ -29,23 +29,23 @@ module('XmppStreamParser', {
});
-test('should parse XMPP stream', function() {
+QUnit.test('should parse XMPP stream', function() {
parser.appendData(base.encodeUtf8('<stream><iq>text</iq>'));
sinon.assert.calledWith(onStanzaStr, '<iq>text</iq>');
});
-test('should handle multiple incoming stanzas', function() {
+QUnit.test('should handle multiple incoming stanzas', function() {
parser.appendData(base.encodeUtf8('<stream><iq>text</iq><iq>more text</iq>'));
sinon.assert.calledWith(onStanzaStr, '<iq>text</iq>');
sinon.assert.calledWith(onStanzaStr, '<iq>more text</iq>');
});
-test('should ignore whitespace between stanzas', function() {
+QUnit.test('should ignore whitespace between stanzas', function() {
parser.appendData(base.encodeUtf8('<stream> <iq>text</iq>'));
sinon.assert.calledWith(onStanzaStr, '<iq>text</iq>');
});
-test('should assemble messages from small chunks', function() {
+QUnit.test('should assemble messages from small chunks', function() {
parser.appendData(base.encodeUtf8('<stream><i'));
parser.appendData(base.encodeUtf8('q>'));
@@ -59,23 +59,24 @@ test('should assemble messages from small chunks', function() {
sinon.assert.calledWith(onStanzaStr, '<iq>😃</iq>');
});
-test('should stop parsing on errors', function() {
+QUnit.test('should stop parsing on errors', function() {
parser.appendData(base.encodeUtf8('<stream>error<iq>text</iq>'));
sinon.assert.calledWith(onError);
sinon.assert.notCalled(onStanzaStr);
});
-test('should fail on invalid stream header', function() {
+QUnit.test('should fail on invalid stream header', function() {
parser.appendData(base.encodeUtf8('<stream p=\'>'));
sinon.assert.calledWith(onError);
});
-test('should fail on loose text', function() {
+QUnit.test('should fail on loose text', function() {
parser.appendData(base.encodeUtf8('stream'));
sinon.assert.calledWith(onError);
});
-test('should fail on loose text with incomplete UTF-8 sequences', function() {
+QUnit.test('should fail on loose text with incomplete UTF-8 sequences',
+ function() {
var buffer = base.encodeUtf8('<stream>ф')
// Crop last byte.
buffer = buffer.slice(0, buffer.byteLength - 1);
@@ -83,7 +84,7 @@ test('should fail on loose text with incomplete UTF-8 sequences', function() {
sinon.assert.calledWith(onError);
});
-test('should fail on incomplete UTF-8 sequences', function() {
+QUnit.test('should fail on incomplete UTF-8 sequences', function() {
var buffer = base.encodeUtf8('<stream><iq>ф')
// Crop last byte.
buffer = buffer.slice(0, buffer.byteLength - 1);
diff --git a/remoting/webapp/js_proto/qunit_proto.js b/remoting/webapp/js_proto/qunit_proto.js
index 8eb9645..2b2816c1 100644
--- a/remoting/webapp/js_proto/qunit_proto.js
+++ b/remoting/webapp/js_proto/qunit_proto.js
@@ -22,77 +22,68 @@ QUnit.Clock = function() {};
/** @param {number} ticks */
QUnit.Clock.prototype.tick = function(ticks) {};
+/** @param {Function} f */
+QUnit.testStart = function(f) {};
/**
- * @param {string} desc
- * @param {Function} f
+ * @interface
*/
-QUnit.asyncTest = function(desc, f) {};
+QUnit.Assert = function() {};
/**
- * @param {*} a
- * @param {*} b
- * @param {string=} opt_message
+ * @return {function():void}
*/
-QUnit.deepEqual = function(a, b, opt_message) {};
+QUnit.Assert.prototype.async = function() {};
/**
* @param {*} a
* @param {*} b
- * @param {string=} opt_message
+ * @param {string=} opt_desc
*/
-QUnit.equal = function(a, b, opt_message) {};
+QUnit.Assert.prototype.notEqual = function(a, b, opt_desc) {};
/**
- * @param {*} a
+ * @param {boolean} cond
+ * @param {string=} desc
+ * @return {boolean}
*/
-QUnit.expect = function(a) {};
+QUnit.Assert.prototype.ok = function(cond, desc) {};
/**
- * @param {string} desc
- * @param {Object=} dict
+ * @param {*} a
+ * @param {*} b
+ * @param {string=} opt_message
*/
-QUnit.module = function(desc, dict) {};
+QUnit.Assert.prototype.deepEqual = function(a, b, opt_message) {};
/**
* @param {*} a
* @param {*} b
- * @param {string=} opt_desc
+ * @param {string=} opt_message
*/
-QUnit.notEqual = function(a, b, opt_desc) {};
+QUnit.Assert.prototype.equal = function(a, b, opt_message) {};
/**
- * @param {boolean} cond
- * @param {string=} desc
- * @return {boolean}
+ * @param {number} assertionCount
*/
-QUnit.ok = function(cond, desc) {};
-
-QUnit.start = function() {};
+QUnit.Assert.prototype.expect = function(assertionCount) {};
/**
- * @param {string} desc
- * @param {Function} f
+ * @typedef {{
+ * beforeEach: (function(QUnit.Assert=) | undefined),
+ * afterEach: (function(QUnit.Assert=) | undefined)
+ * }}
*/
-QUnit.test = function(desc, f) {};
-
-/** @param {Function} f */
-QUnit.testStart = function(f) {};
+QUnit.ModuleArgs;
/**
- * @interface
+ * @param {string} desc
+ * @param {QUnit.ModuleArgs=} opt_args=
*/
-QUnit.Assert = function() {};
+QUnit.module = function(desc, opt_args) {};
/**
- * @return {function():void}
+ * @param {string} desc
+ * @param {function(QUnit.Assert)} f
*/
-QUnit.Assert.prototype.async = function() {};
-
-var deepEqual = QUnit.deepEqual;
-var equal = QUnit.equal;
-var expect = QUnit.expect;
-var module = QUnit.module;
-var notEqual = QUnit.notEqual;
-var ok = QUnit.ok;
-var test = QUnit.test;
+QUnit.test = function(desc, f) {}; \ No newline at end of file
diff --git a/remoting/webapp/unittests/spy_promise_unittest.js b/remoting/webapp/unittests/spy_promise_unittest.js
index 20c201d..099ba09 100644
--- a/remoting/webapp/unittests/spy_promise_unittest.js
+++ b/remoting/webapp/unittests/spy_promise_unittest.js
@@ -9,21 +9,21 @@
var originalGlobalPromise = Promise;
QUnit.module('spy_promise', {
- beforeEach: function() {
- assertInitialState();
+ beforeEach: function(/** QUnit.Assert*/ assert) {
+ assertInitialState(assert);
base.SpyPromise.reset(); // Defend against broken tests.
},
- afterEach: function() {
- assertInitialState();
+ afterEach: function(/** QUnit.Assert*/ assert) {
+ assertInitialState(assert);
}
});
-function assertInitialState() {
- QUnit.equal(Promise, originalGlobalPromise);
- QUnit.ok(
+function assertInitialState(/** QUnit.Assert */ assert) {
+ assert.equal(Promise, originalGlobalPromise);
+ assert.ok(
!base.SpyPromise.isSettleAllRunning(),
'settleAll should not be running');
- QUnit.equal(
+ assert.equal(
base.SpyPromise.unsettledCount, 0,
'base.SpyPromise.unsettledCount should be zero ' +
'before/after any test finishes');
@@ -32,217 +32,217 @@ function assertInitialState() {
/**
* @return {!Promise}
*/
-function finish() {
+function finish(/** QUnit.Assert */ assert) {
return base.SpyPromise.settleAll().then(function() {
- QUnit.equal(
+ assert.equal(
base.SpyPromise.unsettledCount, 0,
'base.SpyPromise.unsettledCount should be zero ' +
'after settleAll finishes.');
});
-};
+}
-QUnit.test('run', function(/** QUnit.Assert */ assert) {
+QUnit.test('run', function(assert) {
var done = assert.async();
- QUnit.notEqual(base.SpyPromise, originalGlobalPromise);
+ assert.notEqual(base.SpyPromise, originalGlobalPromise);
return base.SpyPromise.run(function() {
- QUnit.equal(Promise, base.SpyPromise);
- QUnit.equal(base.SpyPromise.unsettledCount, 0);
+ assert.equal(Promise, base.SpyPromise);
+ assert.equal(base.SpyPromise.unsettledCount, 0);
var dummy1 = new Promise(function(resolve) { resolve(null); });
- QUnit.equal(base.SpyPromise.unsettledCount, 1);
+ assert.equal(base.SpyPromise.unsettledCount, 1);
}).then(function() {
- QUnit.equal(Promise, originalGlobalPromise);
- QUnit.equal(base.SpyPromise.unsettledCount, 0);
+ assert.equal(Promise, originalGlobalPromise);
+ assert.equal(base.SpyPromise.unsettledCount, 0);
done();
});
});
-QUnit.test('activate/restore', function() {
- QUnit.notEqual(base.SpyPromise, originalGlobalPromise);
+QUnit.test('activate/restore', function(assert) {
+ assert.notEqual(base.SpyPromise, originalGlobalPromise);
base.SpyPromise.activate();
- QUnit.notEqual(base.SpyPromise, originalGlobalPromise);
- QUnit.equal(base.SpyPromise.unsettledCount, 0);
+ assert.notEqual(base.SpyPromise, originalGlobalPromise);
+ assert.equal(base.SpyPromise.unsettledCount, 0);
var dummy1 = new Promise(function(resolve) { resolve(null); });
- QUnit.equal(base.SpyPromise.unsettledCount, 1);
+ assert.equal(base.SpyPromise.unsettledCount, 1);
base.SpyPromise.restore();
- QUnit.equal(Promise, originalGlobalPromise);
- return finish();
+ assert.equal(Promise, originalGlobalPromise);
+ return finish(assert);
});
-QUnit.test('new/then', function(/** QUnit.Assert */ assert) {
+QUnit.test('new/then', function(assert) {
var done = assert.async();
new base.SpyPromise(function(resolve, reject) {
resolve('hello');
}).then(function(/**string*/ value) {
- QUnit.equal(base.SpyPromise.unsettledCount, 0);
- QUnit.equal(value, 'hello');
+ assert.equal(base.SpyPromise.unsettledCount, 0);
+ assert.equal(value, 'hello');
done();
});
- QUnit.equal(base.SpyPromise.unsettledCount, 1);
- return finish();
+ assert.equal(base.SpyPromise.unsettledCount, 1);
+ return finish(assert);
});
-QUnit.test('new/catch', function(/** QUnit.Assert */ assert) {
+QUnit.test('new/catch', function(assert) {
var done = assert.async();
new base.SpyPromise(function(resolve, reject) {
reject('hello');
}).catch(function(/**string*/ value) {
- QUnit.equal(base.SpyPromise.unsettledCount, 0);
- QUnit.equal(value, 'hello');
+ assert.equal(base.SpyPromise.unsettledCount, 0);
+ assert.equal(value, 'hello');
done();
});
- QUnit.equal(base.SpyPromise.unsettledCount, 1);
- return finish();
+ assert.equal(base.SpyPromise.unsettledCount, 1);
+ return finish(assert);
});
-QUnit.test('new+throw/catch', function(/** QUnit.Assert */ assert) {
+QUnit.test('new+throw/catch', function(assert) {
var done = assert.async();
new base.SpyPromise(function(resolve, reject) {
throw 'hello';
}).catch(function(/**string*/ value) {
- QUnit.equal(base.SpyPromise.unsettledCount, 0);
- QUnit.equal(value, 'hello');
+ assert.equal(base.SpyPromise.unsettledCount, 0);
+ assert.equal(value, 'hello');
done();
});
- QUnit.equal(base.SpyPromise.unsettledCount, 1);
- return finish();
+ assert.equal(base.SpyPromise.unsettledCount, 1);
+ return finish(assert);
});
-QUnit.test('resolve/then', function(/** QUnit.Assert */ assert) {
+QUnit.test('resolve/then', function(assert) {
var done = assert.async();
base.SpyPromise.resolve('hello').then(function(/**string*/ value) {
- QUnit.equal(base.SpyPromise.unsettledCount, 0);
- QUnit.equal(value, 'hello');
+ assert.equal(base.SpyPromise.unsettledCount, 0);
+ assert.equal(value, 'hello');
done();
});
- QUnit.equal(base.SpyPromise.unsettledCount, 1);
- return finish();
+ assert.equal(base.SpyPromise.unsettledCount, 1);
+ return finish(assert);
});
-QUnit.test('reject/then', function(/** QUnit.Assert */ assert) {
+QUnit.test('reject/then', function(assert) {
var done = assert.async();
base.SpyPromise.reject('hello').then(null, function(/**string*/ value) {
- QUnit.equal(base.SpyPromise.unsettledCount, 0);
- QUnit.equal(value, 'hello');
+ assert.equal(base.SpyPromise.unsettledCount, 0);
+ assert.equal(value, 'hello');
done();
});
- QUnit.equal(base.SpyPromise.unsettledCount, 1);
- return finish();
+ assert.equal(base.SpyPromise.unsettledCount, 1);
+ return finish(assert);
});
-QUnit.test('reject/catch', function(/** QUnit.Assert */ assert) {
+QUnit.test('reject/catch', function(assert) {
var done = assert.async();
base.SpyPromise.reject('hello').catch(function(/**string*/ value) {
- QUnit.equal(base.SpyPromise.unsettledCount, 0);
- QUnit.equal(value, 'hello');
+ assert.equal(base.SpyPromise.unsettledCount, 0);
+ assert.equal(value, 'hello');
done();
});
- QUnit.equal(base.SpyPromise.unsettledCount, 1);
- return finish();
+ assert.equal(base.SpyPromise.unsettledCount, 1);
+ return finish(assert);
});
-QUnit.test('all', function(/** QUnit.Assert */ assert) {
+QUnit.test('all', function(assert) {
var done = assert.async();
base.SpyPromise.all([Promise.resolve(1), Promise.resolve(2)]).
then(function(/**string*/ value) {
- QUnit.equal(base.SpyPromise.unsettledCount, 0);
- QUnit.deepEqual(value, [1, 2]);
+ assert.equal(base.SpyPromise.unsettledCount, 0);
+ assert.deepEqual(value, [1, 2]);
done();
});
- QUnit.equal(base.SpyPromise.unsettledCount, 1);
- return finish();
+ assert.equal(base.SpyPromise.unsettledCount, 1);
+ return finish(assert);
});
-QUnit.test('race', function(/** QUnit.Assert */ assert) {
+QUnit.test('race', function(assert) {
var done = assert.async();
var fast = Promise.resolve('fast');
var slow = new Promise(function() {}); // never settled
base.SpyPromise.race([fast, slow]).
then(function(/**string*/ value) {
- QUnit.equal(base.SpyPromise.unsettledCount, 0);
- QUnit.equal(value, 'fast');
+ assert.equal(base.SpyPromise.unsettledCount, 0);
+ assert.equal(value, 'fast');
done();
});
- QUnit.equal(base.SpyPromise.unsettledCount, 1);
- return finish();
+ assert.equal(base.SpyPromise.unsettledCount, 1);
+ return finish(assert);
});
-QUnit.test('resolve/then/then', function(/** QUnit.Assert */ assert) {
+QUnit.test('resolve/then/then', function(assert) {
var done = assert.async();
base.SpyPromise.resolve('hello').then(function(/**string*/ value) {
- QUnit.equal(value, 'hello');
+ assert.equal(value, 'hello');
return 'goodbye';
}).then(function(/**string*/ value) {
- QUnit.equal(value, 'goodbye');
+ assert.equal(value, 'goodbye');
done();
});
- return finish();
+ return finish(assert);
});
-QUnit.test('resolve/then+throw/catch', function(/** QUnit.Assert */ assert) {
+QUnit.test('resolve/then+throw/catch', function(assert) {
var done = assert.async();
base.SpyPromise.resolve('hello').then(function(/**string*/ value) {
- QUnit.equal(value, 'hello');
+ assert.equal(value, 'hello');
throw 'goodbye';
}).catch(function(/**string*/ value) {
- QUnit.equal(value, 'goodbye');
+ assert.equal(value, 'goodbye');
done();
});
- return finish();
+ return finish(assert);
});
-QUnit.test('reject/catch/then', function(/** QUnit.Assert */ assert) {
+QUnit.test('reject/catch/then', function(assert) {
var done = assert.async();
base.SpyPromise.reject('hello').catch(function(/**string*/ value) {
- QUnit.equal(value, 'hello');
+ assert.equal(value, 'hello');
return 'goodbye';
}).then(function(/**string*/ value) {
- QUnit.equal(value, 'goodbye');
+ assert.equal(value, 'goodbye');
done();
});
- return finish();
+ return finish(assert);
});
-QUnit.test('reject/catch+throw/catch', function(/** QUnit.Assert */ assert) {
+QUnit.test('reject/catch+throw/catch', function(assert) {
var done = assert.async();
base.SpyPromise.reject('hello').catch(function(/**string*/ value) {
- QUnit.equal(value, 'hello');
+ assert.equal(value, 'hello');
throw 'goodbye';
}).catch(function(/**string*/ value) {
- QUnit.equal(value, 'goodbye');
+ assert.equal(value, 'goodbye');
done();
});
- return finish();
+ return finish(assert);
});
-QUnit.test('settleAll timeout = 100', function(/** QUnit.Assert */ assert) {
+QUnit.test('settleAll timeout = 100', function(assert) {
var done = assert.async();
var startTime = Date.now();
var neverResolved = new base.SpyPromise(function() {});
return base.SpyPromise.settleAll(100).catch(function(error) {
- QUnit.ok(error instanceof Error);
- QUnit.ok(startTime + 200 < Date.now());
+ assert.ok(error instanceof Error);
+ assert.ok(startTime + 200 < Date.now());
done();
});
});
-QUnit.test('settleAll timeout = 500', function(/** QUnit.Assert */ assert) {
+QUnit.test('settleAll timeout = 500', function(assert) {
var done = assert.async();
var startTime = Date.now();
var neverResolved = new base.SpyPromise(function() {});
return base.SpyPromise.settleAll(500).catch(function(error) {
- QUnit.ok(startTime + 750 < Date.now());
+ assert.ok(startTime + 750 < Date.now());
done();
});
});
-QUnit.test('settleAll timeout = 1000', function(/** QUnit.Assert */ assert) {
+QUnit.test('settleAll timeout = 1000', function(assert) {
var done = assert.async();
var startTime = Date.now();
var neverResolved = new base.SpyPromise(function() {});
return base.SpyPromise.settleAll(1000).catch(function(error) {
- QUnit.ok(startTime + 1500 < Date.now());
+ assert.ok(startTime + 1500 < Date.now());
done();
});
});