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

Side by Side Diff: remoting/webapp/unittests/dns_blackhole_checker_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, 9 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 SignalStrategy.
8 * @suppress {checkTypes|checkVars|reportUnknownTypes|visibility}
9 */
10
5 (function() { 11 (function() {
6 12
7 'use strict'; 13 'use strict';
8 14
15 /** @type {(sinon.$spy|function(remoting.SignalStrategy.State))} */
9 var onStateChange = null; 16 var onStateChange = null;
17
18 /** @type {(sinon.$spy|function(Element):void)} */
10 var onIncomingStanzaCallback = null; 19 var onIncomingStanzaCallback = null;
20
21 /** @type {remoting.DnsBlackholeChecker} */
11 var checker = null; 22 var checker = null;
23
24 /** @type {remoting.MockSignalStrategy} */
12 var signalStrategy = null; 25 var signalStrategy = null;
13 26
14 module('dns_blackhole_checker', { 27 module('dns_blackhole_checker', {
15 setup: function() { 28 setup: function() {
16 sinon.stub(remoting.xhr, 'get'); 29 sinon.$setupStub(remoting.xhr, 'get');
17 30
18 onStateChange = sinon.spy(); 31 onStateChange = sinon.spy();
19 onIncomingStanzaCallback = sinon.spy(); 32 onIncomingStanzaCallback = sinon.spy();
20 signalStrategy = new remoting.MockSignalStrategy(); 33 signalStrategy = new remoting.MockSignalStrategy();
21 checker = new remoting.DnsBlackholeChecker(signalStrategy); 34 checker = new remoting.DnsBlackholeChecker(signalStrategy);
22 35
23 checker.setStateChangedCallback(onStateChange); 36 checker.setStateChangedCallback(onStateChange);
24 checker.setIncomingStanzaCallback(onIncomingStanzaCallback); 37 checker.setIncomingStanzaCallback(onIncomingStanzaCallback);
25 38
26 sinon.assert.notCalled(onStateChange); 39 sinon.assert.notCalled(onStateChange);
27 sinon.assert.notCalled(signalStrategy.connect); 40 sinon.assert.notCalled(signalStrategy.connect);
28 checker.connect('server', 'username', 'authToken'); 41 checker.connect('server', 'username', 'authToken');
29 sinon.assert.calledWith(signalStrategy.connect, 'server', 'username', 42 sinon.assert.calledWith(signalStrategy.connect, 'server', 'username',
30 'authToken'); 43 'authToken');
31 44
32 sinon.assert.calledWith(remoting.xhr.get, 45 sinon.assert.calledWith(remoting.xhr.get,
33 remoting.DnsBlackholeChecker.URL_TO_REQUEST_); 46 remoting.DnsBlackholeChecker.URL_TO_REQUEST_);
34 }, 47 },
35 teardown: function() { 48 teardown: function() {
36 base.dispose(checker); 49 base.dispose(checker);
37 sinon.assert.calledWith(onStateChange, 50 sinon.assert.calledWith(onStateChange,
38 remoting.SignalStrategy.State.CLOSED); 51 remoting.SignalStrategy.State.CLOSED);
39 52
40 onStateChange = null; 53 onStateChange = null;
41 onIncomingStanzaCallback = null; 54 onIncomingStanzaCallback = null;
42 checker = null; 55 checker = null;
43 56
44 remoting.xhr.get.restore(); 57 remoting.xhr.get.$testStub.restore();
45 }, 58 },
46 }); 59 });
47 60
48 test('success', 61 test('success',
49 function() { 62 function() {
50 remoting.xhr.get.getCall(0).args[1]({status: 200}); 63 remoting.xhr.get.$testStub.getCall(0).args[1]({status: 200});
51 sinon.assert.notCalled(onStateChange); 64 sinon.assert.notCalled(onStateChange);
52 65
53 [ 66 [
54 remoting.SignalStrategy.State.CONNECTING, 67 remoting.SignalStrategy.State.CONNECTING,
55 remoting.SignalStrategy.State.HANDSHAKE, 68 remoting.SignalStrategy.State.HANDSHAKE,
56 remoting.SignalStrategy.State.CONNECTED 69 remoting.SignalStrategy.State.CONNECTED
57 ].forEach(function(state) { 70 ].forEach(function(state) {
58 signalStrategy.setStateForTesting(state); 71 signalStrategy.setStateForTesting(state);
59 sinon.assert.calledWith(onStateChange, state); 72 sinon.assert.calledWith(onStateChange, state);
60 equal(checker.getState(), state); 73 equal(checker.getState(), state);
(...skipping 14 matching lines...) Expand all
75 onStateChange.reset(); 88 onStateChange.reset();
76 89
77 // Verify that DnsBlackholeChecker stays in HANDSHAKE state even if the 90 // Verify that DnsBlackholeChecker stays in HANDSHAKE state even if the
78 // signal strategy has connected. 91 // signal strategy has connected.
79 signalStrategy.setStateForTesting(remoting.SignalStrategy.State.CONNECTED); 92 signalStrategy.setStateForTesting(remoting.SignalStrategy.State.CONNECTED);
80 sinon.assert.notCalled(onStateChange); 93 sinon.assert.notCalled(onStateChange);
81 equal(checker.getState(), remoting.SignalStrategy.State.HANDSHAKE); 94 equal(checker.getState(), remoting.SignalStrategy.State.HANDSHAKE);
82 95
83 // Verify that DnsBlackholeChecker goes to CONNECTED state after the 96 // Verify that DnsBlackholeChecker goes to CONNECTED state after the
84 // the HTTP request has succeeded. 97 // the HTTP request has succeeded.
85 remoting.xhr.get.getCall(0).args[1]({status: 200}); 98 remoting.xhr.get.$testStub.getCall(0).args[1]({status: 200});
86 sinon.assert.calledWith(onStateChange, 99 sinon.assert.calledWith(onStateChange,
87 remoting.SignalStrategy.State.CONNECTED); 100 remoting.SignalStrategy.State.CONNECTED);
88 } 101 }
89 ); 102 );
90 103
91 test('connect failed', 104 test('connect failed',
92 function() { 105 function() {
93 remoting.xhr.get.getCall(0).args[1]({status: 200}); 106 remoting.xhr.get.$testStub.getCall(0).args[1]({status: 200});
94 sinon.assert.notCalled(onStateChange); 107 sinon.assert.notCalled(onStateChange);
95 108
96 [ 109 [
97 remoting.SignalStrategy.State.CONNECTING, 110 remoting.SignalStrategy.State.CONNECTING,
98 remoting.SignalStrategy.State.FAILED 111 remoting.SignalStrategy.State.FAILED
99 ].forEach(function(state) { 112 ].forEach(function(state) {
100 signalStrategy.setStateForTesting(state); 113 signalStrategy.setStateForTesting(state);
101 sinon.assert.calledWith(onStateChange, state); 114 sinon.assert.calledWith(onStateChange, state);
102 }); 115 });
103 } 116 }
104 ); 117 );
105 118
106 test('blocked', 119 test('blocked',
107 function() { 120 function() {
108 remoting.xhr.get.getCall(0).args[1]({status: 400}); 121 remoting.xhr.get.$testStub.getCall(0).args[1]({status: 400});
109 sinon.assert.calledWith(onStateChange, 122 sinon.assert.calledWith(onStateChange,
110 remoting.SignalStrategy.State.FAILED); 123 remoting.SignalStrategy.State.FAILED);
111 equal(checker.getError(), remoting.Error.NOT_AUTHORIZED); 124 equal(checker.getError(), remoting.Error.NOT_AUTHORIZED);
112 onStateChange.reset(); 125 onStateChange.reset();
113 126
114 [ 127 [
115 remoting.SignalStrategy.State.CONNECTING, 128 remoting.SignalStrategy.State.CONNECTING,
116 remoting.SignalStrategy.State.HANDSHAKE, 129 remoting.SignalStrategy.State.HANDSHAKE,
117 remoting.SignalStrategy.State.CONNECTED 130 remoting.SignalStrategy.State.CONNECTED
118 ].forEach(function(state) { 131 ].forEach(function(state) {
(...skipping 17 matching lines...) Expand all
136 onStateChange.reset(); 149 onStateChange.reset();
137 150
138 // Verify that DnsBlackholeChecker stays in HANDSHAKE state even if the 151 // Verify that DnsBlackholeChecker stays in HANDSHAKE state even if the
139 // signal strategy has connected. 152 // signal strategy has connected.
140 signalStrategy.setStateForTesting(remoting.SignalStrategy.State.CONNECTED); 153 signalStrategy.setStateForTesting(remoting.SignalStrategy.State.CONNECTED);
141 sinon.assert.notCalled(onStateChange); 154 sinon.assert.notCalled(onStateChange);
142 equal(checker.getState(), remoting.SignalStrategy.State.HANDSHAKE); 155 equal(checker.getState(), remoting.SignalStrategy.State.HANDSHAKE);
143 156
144 // Verify that DnsBlackholeChecker goes to FAILED state after it gets the 157 // Verify that DnsBlackholeChecker goes to FAILED state after it gets the
145 // blocked HTTP response. 158 // blocked HTTP response.
146 remoting.xhr.get.getCall(0).args[1]({status: 400}); 159 remoting.xhr.get.$testStub.getCall(0).args[1]({status: 400});
147 sinon.assert.calledWith(onStateChange, 160 sinon.assert.calledWith(onStateChange,
148 remoting.SignalStrategy.State.FAILED); 161 remoting.SignalStrategy.State.FAILED);
149 equal(checker.getError(), remoting.Error.NOT_AUTHORIZED); 162 equal(checker.getError(), remoting.Error.NOT_AUTHORIZED);
150 } 163 }
151 ); 164 );
152 165
153 })(); 166 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698