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

Side by Side Diff: remoting/webapp/base/js/dns_blackhole_checker_unittest.js

Issue 1633273002: Fix broken remoting webapp javascript unittest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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/remoting_webapp_files.gypi ('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
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 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * TODO(garykac): Create interface for SignalStrategy. 7 * TODO(garykac): Create interface for SignalStrategy.
8 * @suppress {checkTypes|checkVars|reportUnknownTypes|visibility} 8 * @suppress {checkTypes|checkVars|reportUnknownTypes|visibility}
9 */ 9 */
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 }); 67 });
68 68
69 QUnit.test('success', 69 QUnit.test('success',
70 function(assert) { 70 function(assert) {
71 function checkState(state) { 71 function checkState(state) {
72 signalStrategy.setStateForTesting(state); 72 signalStrategy.setStateForTesting(state);
73 sinon.assert.calledWith(onStateChange, state); 73 sinon.assert.calledWith(onStateChange, state);
74 assert.equal(checker.getState(), state); 74 assert.equal(checker.getState(), state);
75 } 75 }
76 76
77 return base.SpyPromise.run(function() { 77 return Promise.resolve().then(function() {
78 fakeXhr.respond(200); 78 fakeXhr.respond(200);
79 }).then(function() { 79 }).then(function() {
80 sinon.assert.notCalled(onStateChange); 80 sinon.assert.notCalled(onStateChange);
81 checkState(remoting.SignalStrategy.State.CONNECTING); 81 checkState(remoting.SignalStrategy.State.CONNECTING);
82 checkState(remoting.SignalStrategy.State.HANDSHAKE); 82 checkState(remoting.SignalStrategy.State.HANDSHAKE);
83 checkState(remoting.SignalStrategy.State.CONNECTED); 83 checkState(remoting.SignalStrategy.State.CONNECTED);
84 }); 84 });
85 }); 85 });
86 86
87 QUnit.test('http response after connected', 87 QUnit.test('http response after connected',
88 function(assert) { 88 function(assert) {
89 function checkState(state) { 89 function checkState(state) {
90 signalStrategy.setStateForTesting(state); 90 signalStrategy.setStateForTesting(state);
91 sinon.assert.calledWith(onStateChange, state); 91 sinon.assert.calledWith(onStateChange, state);
92 assert.equal(checker.getState(), state); 92 assert.equal(checker.getState(), state);
93 } 93 }
94 94
95 checkState(remoting.SignalStrategy.State.CONNECTING); 95 checkState(remoting.SignalStrategy.State.CONNECTING);
96 checkState(remoting.SignalStrategy.State.HANDSHAKE); 96 checkState(remoting.SignalStrategy.State.HANDSHAKE);
97 onStateChange.reset(); 97 onStateChange.reset();
98 98
99 // Verify that DnsBlackholeChecker stays in HANDSHAKE state even if the 99 // Verify that DnsBlackholeChecker stays in HANDSHAKE state even if the
100 // signal strategy has connected. 100 // signal strategy has connected.
101 return base.SpyPromise.run(function() { 101 return Promise.resolve().then(function() {
102 signalStrategy.setStateForTesting( 102 signalStrategy.setStateForTesting(
103 remoting.SignalStrategy.State.CONNECTED); 103 remoting.SignalStrategy.State.CONNECTED);
104 }).then(function() { 104 }).then(function() {
105 sinon.assert.notCalled(onStateChange); 105 sinon.assert.notCalled(onStateChange);
106 assert.equal(checker.getState(), remoting.SignalStrategy.State.HANDSHAKE); 106 assert.equal(checker.getState(), remoting.SignalStrategy.State.HANDSHAKE);
107 107
108 // Verify that DnsBlackholeChecker goes to CONNECTED state after the 108 // Verify that DnsBlackholeChecker goes to CONNECTED state after the
109 // the HTTP request has succeeded. 109 // the HTTP request has succeeded.
110 return base.SpyPromise.run(function() { 110 return Promise.resolve().then(function() {
111 fakeXhr.respond(200); 111 fakeXhr.respond(200);
112 }); 112 });
113 }).then(function() { 113 }).then(function() {
114 sinon.assert.calledWith(onStateChange, 114 sinon.assert.calledWith(onStateChange,
115 remoting.SignalStrategy.State.CONNECTED); 115 remoting.SignalStrategy.State.CONNECTED);
116 }); 116 });
117 }); 117 });
118 118
119 QUnit.test('connect failed', 119 QUnit.test('connect failed',
120 function(assert) { 120 function(assert) {
121 function checkState(state) { 121 function checkState(state) {
122 signalStrategy.setStateForTesting(state); 122 signalStrategy.setStateForTesting(state);
123 sinon.assert.calledWith(onStateChange, state); 123 sinon.assert.calledWith(onStateChange, state);
124 }; 124 };
125 125
126 return base.SpyPromise.run(function() { 126 return Promise.resolve().then(function() {
127 fakeXhr.respond(200); 127 fakeXhr.respond(200);
128 }).then(function() { 128 }).then(function() {
129 sinon.assert.notCalled(onStateChange); 129 sinon.assert.notCalled(onStateChange);
130 checkState(remoting.SignalStrategy.State.CONNECTING); 130 checkState(remoting.SignalStrategy.State.CONNECTING);
131 checkState(remoting.SignalStrategy.State.FAILED); 131 checkState(remoting.SignalStrategy.State.FAILED);
132 }); 132 });
133 }); 133 });
134 134
135 QUnit.test('blocked', 135 QUnit.test('blocked',
136 function(assert) { 136 function(assert) {
137 function checkState(state) { 137 function checkState(state) {
138 assert.equal(checker.getError().getTag(), 138 assert.equal(checker.getError().getTag(),
139 remoting.Error.Tag.NOT_AUTHORIZED); 139 remoting.Error.Tag.NOT_AUTHORIZED);
140 onStateChange.reset(); 140 onStateChange.reset();
141 signalStrategy.setStateForTesting(state); 141 signalStrategy.setStateForTesting(state);
142 sinon.assert.notCalled(onStateChange); 142 sinon.assert.notCalled(onStateChange);
143 assert.equal(checker.getState(), 143 assert.equal(checker.getState(),
144 checker.getState(), 144 checker.getState(),
145 remoting.SignalStrategy.State.FAILED, 145 remoting.SignalStrategy.State.FAILED,
146 'checker state is still FAILED'); 146 'checker state is still FAILED');
147 }; 147 };
148 148
149 return base.SpyPromise.run(function() { 149 return Promise.resolve().then(function() {
150 fakeXhr.respond(400); 150 fakeXhr.respond(400);
151 }).then(function() { 151 }).then(function() {
152 sinon.assert.calledWith( 152 sinon.assert.calledWith(
153 onStateChange, remoting.SignalStrategy.State.FAILED); 153 onStateChange, remoting.SignalStrategy.State.FAILED);
154 assert.equal( 154 assert.equal(
155 checker.getError().getTag(), 155 checker.getError().getTag(),
156 remoting.Error.Tag.NOT_AUTHORIZED, 156 remoting.Error.Tag.NOT_AUTHORIZED,
157 'checker error is NOT_AUTHORIZED'); 157 'checker error is NOT_AUTHORIZED');
158 checkState(remoting.SignalStrategy.State.CONNECTING); 158 checkState(remoting.SignalStrategy.State.CONNECTING);
159 checkState(remoting.SignalStrategy.State.HANDSHAKE); 159 checkState(remoting.SignalStrategy.State.HANDSHAKE);
160 checkState(remoting.SignalStrategy.State.FAILED); 160 checkState(remoting.SignalStrategy.State.FAILED);
161 }); 161 });
162 }); 162 });
163 163
164 QUnit.test('blocked after connected', 164 QUnit.test('blocked after connected',
165 function(assert) { 165 function(assert) {
166 function checkState(state) { 166 function checkState(state) {
167 signalStrategy.setStateForTesting(state); 167 signalStrategy.setStateForTesting(state);
168 sinon.assert.calledWith(onStateChange, state); 168 sinon.assert.calledWith(onStateChange, state);
169 assert.equal(checker.getState(), state); 169 assert.equal(checker.getState(), state);
170 }; 170 };
171 171
172 checkState(remoting.SignalStrategy.State.CONNECTING); 172 checkState(remoting.SignalStrategy.State.CONNECTING);
173 checkState(remoting.SignalStrategy.State.HANDSHAKE); 173 checkState(remoting.SignalStrategy.State.HANDSHAKE);
174 onStateChange.reset(); 174 onStateChange.reset();
175 175
176 // Verify that DnsBlackholeChecker stays in HANDSHAKE state even 176 // Verify that DnsBlackholeChecker stays in HANDSHAKE state even
177 // if the signal strategy has connected. 177 // if the signal strategy has connected.
178 return base.SpyPromise.run(function() { 178 return Promise.resolve().then(function() {
179 signalStrategy.setStateForTesting( 179 signalStrategy.setStateForTesting(
180 remoting.SignalStrategy.State.CONNECTED); 180 remoting.SignalStrategy.State.CONNECTED);
181 }).then(function() { 181 }).then(function() {
182 sinon.assert.notCalled(onStateChange); 182 sinon.assert.notCalled(onStateChange);
183 assert.equal(checker.getState(), remoting.SignalStrategy.State.HANDSHAKE); 183 assert.equal(checker.getState(), remoting.SignalStrategy.State.HANDSHAKE);
184 184
185 // Verify that DnsBlackholeChecker goes to FAILED state after it 185 // Verify that DnsBlackholeChecker goes to FAILED state after it
186 // gets the blocked HTTP response. 186 // gets the blocked HTTP response.
187 return base.SpyPromise.run(function() { 187 return Promise.resolve().then(function() {
188 fakeXhr.respond(400); 188 fakeXhr.respond(400);
189 }); 189 });
190 }).then(function() { 190 }).then(function() {
191 sinon.assert.calledWith(onStateChange, 191 sinon.assert.calledWith(onStateChange,
192 remoting.SignalStrategy.State.FAILED); 192 remoting.SignalStrategy.State.FAILED);
193 assert.ok(checker.getError().hasTag(remoting.Error.Tag.NOT_AUTHORIZED)); 193 assert.ok(checker.getError().hasTag(remoting.Error.Tag.NOT_AUTHORIZED));
194 }); 194 });
195 } 195 }
196 ); 196 );
197 197
198 })(); 198 })();
OLDNEW
« no previous file with comments | « remoting/remoting_webapp_files.gypi ('k') | remoting/webapp/files.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698