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

Unified Diff: remoting/webapp/unittests/base_unittest.js

Issue 514343002: XMPP implementation in JavaScript. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/webapp/unittests/base_unittest.js
diff --git a/remoting/webapp/unittests/base_unittest.js b/remoting/webapp/unittests/base_unittest.js
index c36c6acad4254dca35fcf7affb8194799e603138..437006516e6b2ed3790398fac218292cf8f545cf 100644
--- a/remoting/webapp/unittests/base_unittest.js
+++ b/remoting/webapp/unittests/base_unittest.js
@@ -232,4 +232,42 @@ test('removeEventListener() should work even if the listener ' +
sinon.assert.calledOnce(sink.listener);
});
+test('encodeUtf8() can encode UTF8 strings', function() {
+ function toJsArray(arrayBuffer) {
+ var result = [];
+ var array = new Uint8Array(arrayBuffer);
+ for (var i = 0; i < array.length; ++i) {
+ result.push(array[i]);
+ }
+ return result;
+ }
+
+ // ASCII.
+ QUnit.deepEqual(toJsArray(base.encodeUtf8("ABC")), [0x41, 0x42, 0x43]);
+
+ // Some arbitrary characters from the basic Unicode plane.
+ QUnit.deepEqual(toJsArray(base.encodeUtf8("挂Ѓф")),
+ [0xE6, 0x8C, 0x82, 0xD0, 0x83, 209, 132]);
Jamie 2014/08/29 02:14:08 Why not hex for the last two? Also, it might be wo
Sergey Ulanov 2014/08/29 23:40:28 Done.
+
+ // Unicode surrogate pair for U+1F603.
+ QUnit.deepEqual(toJsArray(base.encodeUtf8("😃")),
Jamie 2014/08/29 02:14:08 I always felt we needed more smiley faces in our s
Sergey Ulanov 2014/08/29 23:40:28 Acknowledged.
+ [0xF0, 0x9F, 0x98, 0x83]);
+});
+
+test('decodeUtf8() can decode UTF8 strings', function() {
+ // ASCII.
+ QUnit.equal(base.decodeUtf8(new Uint8Array([0x41, 0x42, 0x43]).buffer),
+ "ABC");
+
+ // Some arbitrary characters from the basic Unicode plane.
+ QUnit.equal(
+ base.decodeUtf8(
+ new Uint8Array([0xE6, 0x8C, 0x82, 0xD0, 0x83, 209, 132]).buffer),
+ "挂Ѓф");
+
+ // Unicode surrogate pair for U+1F603.
+ QUnit.equal(base.decodeUtf8(new Uint8Array([0xF0, 0x9F, 0x98, 0x83]).buffer),
+ "😃");
+});
+
})();

Powered by Google App Engine
This is Rietveld 408576698