Chromium Code Reviews| Index: remoting/webapp/crd/js/typecheck_unittest.js |
| diff --git a/remoting/webapp/crd/js/typecheck_unittest.js b/remoting/webapp/crd/js/typecheck_unittest.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5fef389bed949a3cfbc1fbd406c3688a608b9139 |
| --- /dev/null |
| +++ b/remoting/webapp/crd/js/typecheck_unittest.js |
| @@ -0,0 +1,267 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +(function() { |
| + |
| +'use strict'; |
| + |
| +var anArray = ['an array']; |
| +var aBoolean = false; |
| +var aNumber = 42; |
| +var anObject = {name: 'my object'}; |
| +var aString = 'woo'; |
| + |
| +var anotherArray = ['another array']; |
| +var anotherBoolean = true; |
| +var anotherNumber = -42; |
| +var anotherObject = {name: 'a bad object'}; |
| +var anotherString = 'boo!'; |
| + |
| +var testObj = { |
| + anArray: anArray, |
| + aBoolean: aBoolean, |
| + aNumber: aNumber, |
| + anObject: anObject, |
| + aString: aString, |
| + aNull: null, |
| + anUndefined: undefined |
| +}; |
| + |
| +QUnit.module('typecheck', { |
| + setup: function() { |
|
kelvinp
2015/03/17 21:41:48
empty setup, teardown is not required.
John Williams
2015/03/18 17:23:01
Done.
|
| + }, |
| + teardown: function() { |
| + } |
| +}); |
| + |
| +QUnit.test('assertDefined', function() { |
| + QUnit.strictEqual(assertDefined(anArray), anArray); |
|
kelvinp
2015/03/17 21:41:48
I have migrated to the latest syntax
QUnit.test('
John Williams
2015/03/18 17:23:01
Done.
BTW, what would you think about switching t
kelvinp
2015/03/18 17:52:19
Jasmine is one of the candidate when I investigate
John Williams
2015/03/18 20:20:18
Acknowledged.
|
| + QUnit.strictEqual(assertDefined(aBoolean), aBoolean); |
| + QUnit.strictEqual(assertDefined(aNumber), aNumber); |
| + QUnit.strictEqual(assertDefined(anObject), anObject); |
| + QUnit.strictEqual(assertDefined(aString), aString); |
| + QUnit.strictEqual(assertDefined(null), null); |
| + QUnit.throws(assertDefined.bind(null, undefined), Error); |
| +}); |
| + |
| +QUnit.test('assertArray', function() { |
| + QUnit.strictEqual(assertArray(anArray), anArray); |
| + QUnit.throws(assertArray.bind(null, aBoolean), Error); |
| + QUnit.throws(assertArray.bind(null, aNumber), Error); |
| + QUnit.throws(assertArray.bind(null, anObject), Error); |
| + QUnit.throws(assertArray.bind(null, aString), Error); |
| + QUnit.throws(assertArray.bind(null, null), Error); |
| + QUnit.throws(assertArray.bind(null, undefined), Error); |
| +}); |
| + |
| +QUnit.test('assertBoolean', function() { |
| + QUnit.strictEqual(assertBoolean(aBoolean), aBoolean); |
| + QUnit.throws(assertNumber.bind(null, anArray), Error); |
| + QUnit.throws(assertBoolean.bind(null, aNumber), Error); |
| + QUnit.throws(assertBoolean.bind(null, anObject), Error); |
| + QUnit.throws(assertBoolean.bind(null, aString), Error); |
| + QUnit.throws(assertBoolean.bind(null, null), Error); |
| + QUnit.throws(assertBoolean.bind(null, undefined), Error); |
| +}); |
| + |
| +QUnit.test('assertNumber', function() { |
| + QUnit.strictEqual(assertNumber(aNumber), aNumber); |
| + QUnit.throws(assertNumber.bind(null, anArray), Error); |
| + QUnit.throws(assertNumber.bind(null, aBoolean), Error); |
| + QUnit.throws(assertNumber.bind(null, anObject), Error); |
| + QUnit.throws(assertNumber.bind(null, aString), Error); |
| + QUnit.throws(assertNumber.bind(null, null), Error); |
| + QUnit.throws(assertNumber.bind(null, undefined), Error); |
| +}); |
| + |
| +QUnit.test('assertObject', function() { |
| + QUnit.strictEqual(assertObject(anObject), anObject); |
| + QUnit.throws(assertObject.bind(null, anArray), Error); |
| + QUnit.throws(assertObject.bind(null, aBoolean), Error); |
| + QUnit.throws(assertObject.bind(null, aNumber), Error); |
| + QUnit.throws(assertObject.bind(null, aString), Error); |
| + QUnit.throws(assertObject.bind(null, null), Error); |
| + QUnit.throws(assertObject.bind(null, undefined), Error); |
| +}); |
| + |
| +QUnit.test('assertString', function() { |
| + QUnit.strictEqual(assertString(aString), aString); |
| + QUnit.throws(assertString.bind(null, anArray), Error); |
| + QUnit.throws(assertString.bind(null, aBoolean), Error); |
| + QUnit.throws(assertString.bind(null, aNumber), Error); |
| + QUnit.throws(assertString.bind(null, anObject), Error); |
| + QUnit.throws(assertString.bind(null, null), Error); |
| + QUnit.throws(assertString.bind(null, undefined), Error); |
| +}); |
| + |
| +QUnit.test('getAttr', function() { |
| + QUnit.strictEqual(getAttr(testObj, 'anArray'), anArray); |
| + QUnit.strictEqual(getAttr(testObj, 'aBoolean'), aBoolean); |
| + QUnit.strictEqual(getAttr(testObj, 'aNumber'), aNumber); |
| + QUnit.strictEqual(getAttr(testObj, 'anObject'), anObject); |
| + QUnit.strictEqual(getAttr(testObj, 'aString'), aString); |
| + QUnit.strictEqual(getAttr(testObj, 'aNull'), null); |
| + QUnit.throws(getAttr.bind(null, testObj, 'noSuchKey'), Error); |
| + QUnit.throws(getAttr.bind(null, testObj, 'anUndefined'), Error); |
| + |
| + QUnit.strictEqual(getAttr(testObj, 'anArray', anotherArray), anArray); |
| + QUnit.strictEqual(getAttr(testObj, 'aBoolean', anotherBoolean), aBoolean); |
| + QUnit.strictEqual(getAttr(testObj, 'aNumber', anotherNumber), aNumber); |
| + QUnit.strictEqual(getAttr(testObj, 'anObject', anotherObject), anObject); |
| + QUnit.strictEqual(getAttr(testObj, 'aString', anotherString), aString); |
| + QUnit.strictEqual(getAttr(testObj, 'aNull', anotherString), null); |
| + QUnit.strictEqual( |
| + getAttr(testObj, 'noSuchKey', anotherString), anotherString); |
| + QUnit.strictEqual( |
| + getAttr(testObj, 'anUndefined', anotherString), anotherString); |
| +}); |
| + |
| +QUnit.test('getArrayAttr', function() { |
| + QUnit.strictEqual(getArrayAttr(testObj, 'anArray'), anArray); |
| + QUnit.strictEqual(getArrayAttr(testObj, 'anArray', anotherArray), anArray); |
| + |
| + QUnit.throws(getArrayAttr.bind(null, testObj, 'aBoolean'), Error); |
| + QUnit.throws(getArrayAttr.bind(null, testObj, 'aNumber'), Error); |
| + QUnit.throws(getArrayAttr.bind(null, testObj, 'anObject'), Error); |
| + QUnit.throws(getArrayAttr.bind(null, testObj, 'aString'), Error); |
| + QUnit.throws(getArrayAttr.bind(null, testObj, 'aNull'), Error); |
| + QUnit.throws(getArrayAttr.bind(null, testObj, 'anUndefined'), Error); |
| + QUnit.throws(getArrayAttr.bind(null, testObj, 'noSuchKey'), Error); |
| + |
| + QUnit.strictEqual( |
| + getArrayAttr(testObj, 'aBoolean', anotherArray), anotherArray); |
| + QUnit.strictEqual( |
| + getArrayAttr(testObj, 'aNumber', anotherArray), anotherArray); |
| + QUnit.strictEqual( |
| + getArrayAttr(testObj, 'anObject', anotherArray), anotherArray); |
| + QUnit.strictEqual( |
| + getArrayAttr(testObj, 'aString', anotherArray), anotherArray); |
| + QUnit.strictEqual( |
| + getArrayAttr(testObj, 'aNull', anotherArray), anotherArray); |
| + QUnit.strictEqual( |
| + getArrayAttr(testObj, 'anUndefined', anotherArray), anotherArray); |
| + QUnit.strictEqual( |
| + getArrayAttr(testObj, 'noSuchKey', anotherArray), anotherArray); |
| +}); |
| + |
| +QUnit.test('getBooleanAttr', function() { |
| + QUnit.strictEqual(getBooleanAttr(testObj, 'aBoolean'), aBoolean); |
| + QUnit.strictEqual( |
| + getBooleanAttr(testObj, 'aBoolean', anotherBoolean), aBoolean); |
| + |
| + QUnit.throws(getBooleanAttr.bind(null, testObj, 'anArray'), Error); |
| + QUnit.throws(getBooleanAttr.bind(null, testObj, 'aNumber'), Error); |
| + QUnit.throws(getBooleanAttr.bind(null, testObj, 'anObject'), Error); |
| + QUnit.throws(getBooleanAttr.bind(null, testObj, 'aString'), Error); |
| + QUnit.throws(getBooleanAttr.bind(null, testObj, 'aNull'), Error); |
| + QUnit.throws(getBooleanAttr.bind(null, testObj, 'anUndefined'), Error); |
| + QUnit.throws(getBooleanAttr.bind(null, testObj, 'noSuchKey'), Error); |
| + |
| + QUnit.strictEqual( |
| + getBooleanAttr(testObj, 'anArray', anotherBoolean), anotherBoolean); |
| + QUnit.strictEqual( |
| + getBooleanAttr(testObj, 'aNumber', anotherBoolean), anotherBoolean); |
| + QUnit.strictEqual( |
| + getBooleanAttr(testObj, 'anObject', anotherBoolean), anotherBoolean); |
| + QUnit.strictEqual( |
| + getBooleanAttr(testObj, 'aString', anotherBoolean), anotherBoolean); |
| + QUnit.strictEqual( |
| + getBooleanAttr(testObj, 'aNull', anotherBoolean), anotherBoolean); |
| + QUnit.strictEqual( |
| + getBooleanAttr(testObj, 'anUndefined', anotherBoolean), anotherBoolean); |
| + QUnit.strictEqual( |
| + getBooleanAttr(testObj, 'noSuchKey', anotherBoolean), anotherBoolean); |
| +}); |
| + |
| +QUnit.test('getNumberAttr', function() { |
| + QUnit.strictEqual( |
| + getNumberAttr(testObj, 'aNumber'), aNumber); |
| + QUnit.strictEqual( |
| + getNumberAttr(testObj, 'aNumber', anotherNumber), aNumber); |
| + |
| + QUnit.throws(getNumberAttr.bind(null, testObj, 'anArray'), Error); |
| + QUnit.throws(getNumberAttr.bind(null, testObj, 'aBoolean'), Error); |
| + QUnit.throws(getNumberAttr.bind(null, testObj, 'anObject'), Error); |
| + QUnit.throws(getNumberAttr.bind(null, testObj, 'aString'), Error); |
| + QUnit.throws(getNumberAttr.bind(null, testObj, 'aNull'), Error); |
| + QUnit.throws(getNumberAttr.bind(null, testObj, 'anUndefined'), Error); |
| + QUnit.throws(getNumberAttr.bind(null, testObj, 'noSuchKey'), Error); |
| + |
| + QUnit.strictEqual( |
| + getNumberAttr(testObj, 'anArray', anotherNumber), anotherNumber); |
| + QUnit.strictEqual( |
| + getNumberAttr(testObj, 'aBoolean', anotherNumber), anotherNumber); |
| + QUnit.strictEqual( |
| + getNumberAttr(testObj, 'anObject', anotherNumber), anotherNumber); |
| + QUnit.strictEqual( |
| + getNumberAttr(testObj, 'aString', anotherNumber), anotherNumber); |
| + QUnit.strictEqual( |
| + getNumberAttr(testObj, 'aNull', anotherNumber), anotherNumber); |
| + QUnit.strictEqual( |
| + getNumberAttr(testObj, 'anUndefined', anotherNumber), anotherNumber); |
| + QUnit.strictEqual( |
| + getNumberAttr(testObj, 'noSuchKey', anotherNumber), anotherNumber); |
| +}); |
| + |
| +QUnit.test('getObjectAttr', function() { |
| + QUnit.strictEqual( |
| + getObjectAttr(testObj, 'anObject'), anObject); |
| + QUnit.strictEqual( |
| + getObjectAttr(testObj, 'anObject', anotherObject), anObject); |
| + |
| + QUnit.throws(getObjectAttr.bind(null, testObj, 'anArray'), Error); |
| + QUnit.throws(getObjectAttr.bind(null, testObj, 'aBoolean'), Error); |
| + QUnit.throws(getObjectAttr.bind(null, testObj, 'aNumber'), Error); |
| + QUnit.throws(getObjectAttr.bind(null, testObj, 'aString'), Error); |
| + QUnit.throws(getObjectAttr.bind(null, testObj, 'aNull'), Error); |
| + QUnit.throws(getObjectAttr.bind(null, testObj, 'anUndefined'), Error); |
| + QUnit.throws(getObjectAttr.bind(null, testObj, 'noSuchKey'), Error); |
| + |
| + QUnit.strictEqual( |
| + getObjectAttr(testObj, 'anArray', anotherObject), anotherObject); |
| + QUnit.strictEqual( |
| + getObjectAttr(testObj, 'aBoolean', anotherObject), anotherObject); |
| + QUnit.strictEqual( |
| + getObjectAttr(testObj, 'aNumber', anotherObject), anotherObject); |
| + QUnit.strictEqual( |
| + getObjectAttr(testObj, 'aString', anotherObject), anotherObject); |
| + QUnit.strictEqual( |
| + getObjectAttr(testObj, 'aNull', anotherObject), anotherObject); |
| + QUnit.strictEqual( |
| + getObjectAttr(testObj, 'anUndefined', anotherObject), anotherObject); |
| + QUnit.strictEqual( |
| + getObjectAttr(testObj, 'noSuchKey', anotherObject), anotherObject); |
| +}); |
| + |
| +QUnit.test('getStringAttr', function() { |
| + QUnit.strictEqual( |
| + getStringAttr(testObj, 'aString'), aString); |
| + QUnit.strictEqual( |
| + getStringAttr(testObj, 'aString', anotherString), aString); |
| + |
| + QUnit.throws(getStringAttr.bind(null, testObj, 'anArray'), Error); |
| + QUnit.throws(getStringAttr.bind(null, testObj, 'aBoolean'), Error); |
| + QUnit.throws(getStringAttr.bind(null, testObj, 'aNumber'), Error); |
| + QUnit.throws(getStringAttr.bind(null, testObj, 'anObject'), Error); |
| + QUnit.throws(getStringAttr.bind(null, testObj, 'aNull'), Error); |
| + QUnit.throws(getStringAttr.bind(null, testObj, 'anUndefined'), Error); |
| + QUnit.throws(getStringAttr.bind(null, testObj, 'noSuchKey'), Error); |
| + |
| + QUnit.strictEqual( |
| + getStringAttr(testObj, 'anArray', anotherString), anotherString); |
| + QUnit.strictEqual( |
| + getStringAttr(testObj, 'aBoolean', anotherString), anotherString); |
| + QUnit.strictEqual( |
| + getStringAttr(testObj, 'aNumber', anotherString), anotherString); |
| + QUnit.strictEqual( |
| + getStringAttr(testObj, 'anObject', anotherString), anotherString); |
| + QUnit.strictEqual( |
| + getStringAttr(testObj, 'aNull', anotherString), anotherString); |
| + QUnit.strictEqual( |
| + getStringAttr(testObj, 'anUndefined', anotherString), anotherString); |
| + QUnit.strictEqual( |
| + getStringAttr(testObj, 'noSuchKey', anotherString), anotherString); |
| +}); |
| + |
| +})(); |