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

Side by Side Diff: remoting/webapp/crd/js/xmpp_stream_parser_unittest.js

Issue 1133913002: [Chromoting] Move shared webapp JS files from crd/js -> base/js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « remoting/webapp/crd/js/xmpp_stream_parser.js ('k') | remoting/webapp/files.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 (function() {
6
7 'use strict';
8
9 /** @type {Function} */
10 var onStanzaStr = null;
11
12 /** @type {function(string):void} */
13 var onError = function(msg) {};
14
15 /** @type {remoting.XmppStreamParser} */
16 var parser = null;
17
18 QUnit.module('XmppStreamParser', {
19 beforeEach: function() {
20 onStanzaStr = sinon.spy();
21 onError = /** @type {function(string):void} */ (sinon.spy());
22 /** @param {Element} stanza */
23 function onStanza(stanza) {
24 onStanzaStr(new XMLSerializer().serializeToString(stanza));
25 }
26 parser = new remoting.XmppStreamParser();
27 parser.setCallbacks(onStanza, onError);
28 }
29 });
30
31
32 QUnit.test('should parse XMPP stream', function() {
33 parser.appendData(base.encodeUtf8('<stream><iq>text</iq>'));
34 sinon.assert.calledWith(onStanzaStr, '<iq>text</iq>');
35 });
36
37 QUnit.test('should handle multiple incoming stanzas', function() {
38 parser.appendData(base.encodeUtf8('<stream><iq>text</iq><iq>more text</iq>'));
39 sinon.assert.calledWith(onStanzaStr, '<iq>text</iq>');
40 sinon.assert.calledWith(onStanzaStr, '<iq>more text</iq>');
41 });
42
43 QUnit.test('should ignore whitespace between stanzas', function() {
44 parser.appendData(base.encodeUtf8('<stream> <iq>text</iq>'));
45 sinon.assert.calledWith(onStanzaStr, '<iq>text</iq>');
46 });
47
48 QUnit.test('should assemble messages from small chunks', function() {
49 parser.appendData(base.encodeUtf8('<stream><i'));
50 parser.appendData(base.encodeUtf8('q>'));
51
52 // Split one UTF-8 sequence into two chunks
53 var data = base.encodeUtf8('😃');
54 parser.appendData(data.slice(0, 2));
55 parser.appendData(data.slice(2));
56
57 parser.appendData(base.encodeUtf8('</iq>'));
58
59 sinon.assert.calledWith(onStanzaStr, '<iq>😃</iq>');
60 });
61
62 QUnit.test('should stop parsing on errors', function() {
63 parser.appendData(base.encodeUtf8('<stream>error<iq>text</iq>'));
64 sinon.assert.calledWith(onError);
65 sinon.assert.notCalled(onStanzaStr);
66 });
67
68 QUnit.test('should fail on invalid stream header', function() {
69 parser.appendData(base.encodeUtf8('<stream p=\'>'));
70 sinon.assert.calledWith(onError);
71 });
72
73 QUnit.test('should fail on loose text', function() {
74 parser.appendData(base.encodeUtf8('stream'));
75 sinon.assert.calledWith(onError);
76 });
77
78 QUnit.test('should fail on loose text with incomplete UTF-8 sequences',
79 function() {
80 var buffer = base.encodeUtf8('<stream>Ñ„')
81 // Crop last byte.
82 buffer = buffer.slice(0, buffer.byteLength - 1);
83 parser.appendData(buffer);
84 sinon.assert.calledWith(onError);
85 });
86
87 QUnit.test('should fail on incomplete UTF-8 sequences', function() {
88 var buffer = base.encodeUtf8('<stream><iq>Ñ„')
89 // Crop last byte.
90 buffer = buffer.slice(0, buffer.byteLength - 1);
91 parser.appendData(buffer);
92 parser.appendData(base.encodeUtf8('</iq>'));
93 sinon.assert.calledWith(onError);
94 });
95
96 })();
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/xmpp_stream_parser.js ('k') | remoting/webapp/files.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698