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

Side by Side Diff: remoting/webapp/unittests/base_unittest.js

Issue 959963002: [Chromoting] Enable jscompile for webapp unittests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /**
6 * @fileoverview
7 * TODO(garykac): Create interface for base.Disposable.
kelvinp 2015/02/26 00:31:30 base.Disposable is already an interface. Am I mis
garykac 2015/02/28 02:33:33 Nope. I missed it. Enabling jscompile for this fil
8 * @suppress {checkTypes|checkVars|reportUnknownTypes|visibility}
9 */
10
5 (function() { 11 (function() {
6 12
7 'use strict'; 13 'use strict';
8 14
9 module('base'); 15 module('base');
10 16
11 test('mix(dest, src) should copy properties from |src| to |dest|', 17 test('mix(dest, src) should copy properties from |src| to |dest|',
12 function() { 18 function() {
13 var src = { a: 'a', b: 'b'}; 19 var src = { a: 'a', b: 'b'};
14 var dest = { c: 'c'}; 20 var dest = { c: 'c'};
15 21
16 base.mix(dest, src); 22 base.mix(dest, src);
17 deepEqual(dest, {a: 'a', b: 'b', c: 'c'}); 23 deepEqual(dest, {a: 'a', b: 'b', c: 'c'});
18 }); 24 });
19 25
20 test('mix(dest, src) should assert if properties are overwritten', 26 test('mix(dest, src) should assert if properties are overwritten',
21 function() { 27 function() {
22 var src = { a: 'a', b: 'b'}; 28 var src = { a: 'a', b: 'b'};
23 var dest = { a: 'a'}; 29 var dest = { a: 'a'};
24 30
25 sinon.spy(base.debug, 'assert'); 31 sinon.$setupStub(base.debug, 'assert');
26 32
27 try { 33 try {
28 base.mix(dest, src); 34 base.mix(dest, src);
29 } catch (e) { 35 } catch (e) {
30 } finally { 36 } finally {
31 sinon.assert.called(base.debug.assert); 37 sinon.assert.called(base.debug.assert);
32 base.debug.assert.restore(); 38 base.debug.assert.$testStub.restore();
33 } 39 }
34 }); 40 });
35 41
36 test('values(obj) should return an array containing the values of |obj|', 42 test('values(obj) should return an array containing the values of |obj|',
37 function() { 43 function() {
38 var output = base.values({ a: 'a', b: 'b'}); 44 var output = base.values({ a: 'a', b: 'b'});
39 45
40 notEqual(output.indexOf('a'), -1, '"a" should be in the output'); 46 notEqual(output.indexOf('a'), -1, '"a" should be in the output');
41 notEqual(output.indexOf('b'), -1, '"b" should be in the output'); 47 notEqual(output.indexOf('b'), -1, '"b" should be in the output');
42 }); 48 });
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 'http://www.chromium.org?a=a&foo=foo' + 109 'http://www.chromium.org?a=a&foo=foo' +
104 '&escapist=%3A%2F%3F%23%5B%5D%40%24%26%2B%2C%3B%3D'); 110 '&escapist=%3A%2F%3F%23%5B%5D%40%24%26%2B%2C%3B%3D');
105 }); 111 });
106 112
107 test('escapeHTML(str) should escape special characters', function() { 113 test('escapeHTML(str) should escape special characters', function() {
108 QUnit.equal( 114 QUnit.equal(
109 base.escapeHTML('<script>alert("hello")</script>'), 115 base.escapeHTML('<script>alert("hello")</script>'),
110 '&lt;script&gt;alert("hello")&lt;/script&gt;'); 116 '&lt;script&gt;alert("hello")&lt;/script&gt;');
111 }); 117 });
112 118
119 /** @this {QUnit.$test} */
113 QUnit.asyncTest('Promise.sleep(delay) should fulfill the promise after |delay|', 120 QUnit.asyncTest('Promise.sleep(delay) should fulfill the promise after |delay|',
114 function() { 121 function() {
115 var isCalled = false; 122 var isCalled = false;
116 var clock = this.clock; 123 var clock = /** @type {QUnit.$clock} */ (this.clock);
117 124
118 base.Promise.sleep(100).then(function(){ 125 base.Promise.sleep(100).then(function(){
119 isCalled = true; 126 isCalled = true;
120 ok(true, 'Promise.sleep() is fulfilled after delay.'); 127 ok(true, 'Promise.sleep() is fulfilled after delay.');
121 QUnit.start(); 128 QUnit.start();
122 }); 129 });
123 130
124 // Tick the clock for 2 seconds and check if the promise is fulfilled. 131 // Tick the clock for 2 seconds and check if the promise is fulfilled.
125 clock.tick(2); 132 clock.tick(2);
126 133
(...skipping 21 matching lines...) Expand all
148 155
149 module('base.Deferred'); 156 module('base.Deferred');
150 157
151 QUnit.asyncTest('resolve() should fulfill the underlying promise.', function() { 158 QUnit.asyncTest('resolve() should fulfill the underlying promise.', function() {
152 function async() { 159 function async() {
153 var deferred = new base.Deferred(); 160 var deferred = new base.Deferred();
154 deferred.resolve('bar'); 161 deferred.resolve('bar');
155 return deferred.promise(); 162 return deferred.promise();
156 } 163 }
157 164
158 async().then(function(value){ 165 async().then(
159 QUnit.equal(value, 'bar'); 166 /** @param {string} value */
160 QUnit.start(); 167 function(value){
161 }, function() { 168 QUnit.equal(value, 'bar');
162 QUnit.ok(false, 'The reject handler should not be invoked.'); 169 QUnit.start();
163 }); 170 }, function() {
171 QUnit.ok(false, 'The reject handler should not be invoked.');
172 });
164 }); 173 });
165 174
166 QUnit.asyncTest('reject() should fail the underlying promise.', function() { 175 QUnit.asyncTest('reject() should fail the underlying promise.', function() {
167 function async() { 176 function async() {
168 var deferred = new base.Deferred(); 177 var deferred = new base.Deferred();
169 deferred.reject('bar'); 178 deferred.reject('bar');
170 return deferred.promise(); 179 return deferred.promise();
171 } 180 }
172 181
173 async().then(function(){ 182 async().then(
174 QUnit.ok(false, 'The then handler should not be invoked.'); 183 function(){
175 }, function(value) { 184 QUnit.ok(false, 'The then handler should not be invoked.');
176 QUnit.equal(value, 'bar'); 185 },
177 QUnit.start(); 186 /** @param {string} value */
178 }); 187 function(value) {
188 QUnit.equal(value, 'bar');
189 QUnit.start();
190 });
179 }); 191 });
180 192
181 193
194 /** @type {base.EventSourceImpl} */
182 var source = null; 195 var source = null;
183 var listener = null; 196 var listener = null;
184 197
185 module('base.EventSource', { 198 module('base.EventSource', {
186 setup: function() { 199 setup: function() {
187 source = new base.EventSourceImpl(); 200 source = new base.EventSourceImpl();
188 source.defineEvents(['foo', 'bar']); 201 source.defineEvents(['foo', 'bar']);
189 listener = sinon.spy(); 202 listener = sinon.spy();
190 source.addEventListener('foo', listener); 203 source.addEventListener('foo', listener);
191 }, 204 },
(...skipping 30 matching lines...) Expand all
222 }); 235 });
223 236
224 test('raiseEvent() should not invoke listeners of a different event', 237 test('raiseEvent() should not invoke listeners of a different event',
225 function() { 238 function() {
226 source.raiseEvent('bar'); 239 source.raiseEvent('bar');
227 sinon.assert.notCalled(listener); 240 sinon.assert.notCalled(listener);
228 }); 241 });
229 242
230 test('raiseEvent() should assert when undeclared events are raised', 243 test('raiseEvent() should assert when undeclared events are raised',
231 function() { 244 function() {
232 sinon.spy(base.debug, 'assert'); 245 sinon.$setupStub(base.debug, 'assert');
233 try { 246 try {
234 source.raiseEvent('undefined'); 247 source.raiseEvent('undefined');
235 } catch (e) { 248 } catch (e) {
236 } finally { 249 } finally {
237 sinon.assert.called(base.debug.assert); 250 sinon.assert.called(base.debug.assert);
238 base.debug.assert.restore(); 251 base.debug.assert.$testStub.restore();
239 } 252 }
240 }); 253 });
241 254
242 test( 255 test(
243 'removeEventListener() should not invoke the listener in subsequent ' + 256 'removeEventListener() should not invoke the listener in subsequent ' +
244 'calls to |raiseEvent|', 257 'calls to |raiseEvent|',
245 function() { 258 function() {
246 source.raiseEvent('foo'); 259 source.raiseEvent('foo');
247 sinon.assert.calledOnce(listener); 260 sinon.assert.calledOnce(listener);
248 261
(...skipping 12 matching lines...) Expand all
261 274
262 source.addEventListener('foo', sink.listener); 275 source.addEventListener('foo', sink.listener);
263 source.raiseEvent('foo'); 276 source.raiseEvent('foo');
264 sinon.assert.calledOnce(sink.listener); 277 sinon.assert.calledOnce(sink.listener);
265 278
266 source.raiseEvent('foo'); 279 source.raiseEvent('foo');
267 sinon.assert.calledOnce(sink.listener); 280 sinon.assert.calledOnce(sink.listener);
268 }); 281 });
269 282
270 test('encodeUtf8() can encode UTF8 strings', function() { 283 test('encodeUtf8() can encode UTF8 strings', function() {
284 /** @type {function(ArrayBuffer):Array} */
271 function toJsArray(arrayBuffer) { 285 function toJsArray(arrayBuffer) {
272 var result = []; 286 var result = [];
273 var array = new Uint8Array(arrayBuffer); 287 var array = new Uint8Array(arrayBuffer);
274 for (var i = 0; i < array.length; ++i) { 288 for (var i = 0; i < array.length; ++i) {
275 result.push(array[i]); 289 result.push(array[i]);
276 } 290 }
277 return result; 291 return result;
278 } 292 }
279 293
280 // ASCII. 294 // ASCII.
(...skipping 21 matching lines...) Expand all
302 /* Ѓ */ 0xD0, 0x83, 316 /* Ѓ */ 0xD0, 0x83,
303 /* ф */ 0xD1, 0x84]).buffer), 317 /* ф */ 0xD1, 0x84]).buffer),
304 "挂Ѓф"); 318 "挂Ѓф");
305 319
306 // Unicode surrogate pair for U+1F603. 320 // Unicode surrogate pair for U+1F603.
307 QUnit.equal(base.decodeUtf8(new Uint8Array([0xF0, 0x9F, 0x98, 0x83]).buffer), 321 QUnit.equal(base.decodeUtf8(new Uint8Array([0xF0, 0x9F, 0x98, 0x83]).buffer),
308 "😃"); 322 "😃");
309 }); 323 });
310 324
311 })(); 325 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698