OLD | NEW |
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 (function() { | 5 (function() { |
6 | 6 |
7 'use strict'; | 7 'use strict'; |
8 | 8 |
9 module('base'); | 9 module('base'); |
10 | 10 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 }); | 225 }); |
226 | 226 |
227 source.addEventListener('foo', sink.listener); | 227 source.addEventListener('foo', sink.listener); |
228 source.raiseEvent('foo'); | 228 source.raiseEvent('foo'); |
229 sinon.assert.calledOnce(sink.listener); | 229 sinon.assert.calledOnce(sink.listener); |
230 | 230 |
231 source.raiseEvent('foo'); | 231 source.raiseEvent('foo'); |
232 sinon.assert.calledOnce(sink.listener); | 232 sinon.assert.calledOnce(sink.listener); |
233 }); | 233 }); |
234 | 234 |
| 235 test('encodeUtf8() can encode UTF8 strings', function() { |
| 236 function toJsArray(arrayBuffer) { |
| 237 var result = []; |
| 238 var array = new Uint8Array(arrayBuffer); |
| 239 for (var i = 0; i < array.length; ++i) { |
| 240 result.push(array[i]); |
| 241 } |
| 242 return result; |
| 243 } |
| 244 |
| 245 // ASCII. |
| 246 QUnit.deepEqual(toJsArray(base.encodeUtf8("ABC")), [0x41, 0x42, 0x43]); |
| 247 |
| 248 // Some arbitrary characters from the basic Unicode plane. |
| 249 QUnit.deepEqual( |
| 250 toJsArray(base.encodeUtf8("挂Ѓф")), |
| 251 [/* 挂 */ 0xE6, 0x8C, 0x82, /* Ѓ */ 0xD0, 0x83, /* ф */ 0xD1, 0x84]); |
| 252 |
| 253 // Unicode surrogate pair for U+1F603. |
| 254 QUnit.deepEqual(toJsArray(base.encodeUtf8("😃")), |
| 255 [0xF0, 0x9F, 0x98, 0x83]); |
| 256 }); |
| 257 |
| 258 test('decodeUtf8() can decode UTF8 strings', function() { |
| 259 // ASCII. |
| 260 QUnit.equal(base.decodeUtf8(new Uint8Array([0x41, 0x42, 0x43]).buffer), |
| 261 "ABC"); |
| 262 |
| 263 // Some arbitrary characters from the basic Unicode plane. |
| 264 QUnit.equal( |
| 265 base.decodeUtf8( |
| 266 new Uint8Array([/* 挂 */ 0xE6, 0x8C, 0x82, |
| 267 /* Ѓ */ 0xD0, 0x83, |
| 268 /* ф */ 0xD1, 0x84]).buffer), |
| 269 "挂Ѓф"); |
| 270 |
| 271 // Unicode surrogate pair for U+1F603. |
| 272 QUnit.equal(base.decodeUtf8(new Uint8Array([0xF0, 0x9F, 0x98, 0x83]).buffer), |
| 273 "😃"); |
| 274 }); |
| 275 |
235 })(); | 276 })(); |
OLD | NEW |