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

Side by Side Diff: third_party/WebKit/Source/modules/websockets/DOMWebSocketTest.cpp

Issue 2068053002: Rename Blink constants generated from IDL files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 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 unified diff | Download patch
OLDNEW
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 #include "modules/websockets/DOMWebSocket.h" 5 #include "modules/websockets/DOMWebSocket.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/V8Binding.h" 8 #include "bindings/core/v8/V8Binding.h"
9 #include "bindings/core/v8/V8BindingForTesting.h" 9 #include "bindings/core/v8/V8BindingForTesting.h"
10 #include "core/dom/DOMTypedArray.h" 10 #include "core/dom/DOMTypedArray.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 TEST(DOMWebSocketTest, connectToBadURL) 140 TEST(DOMWebSocketTest, connectToBadURL)
141 { 141 {
142 V8TestingScope scope; 142 V8TestingScope scope;
143 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 143 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
144 webSocketScope.socket().connect("xxx", Vector<String>(), scope.getExceptionS tate()); 144 webSocketScope.socket().connect("xxx", Vector<String>(), scope.getExceptionS tate());
145 145
146 146
147 EXPECT_TRUE(scope.getExceptionState().hadException()); 147 EXPECT_TRUE(scope.getExceptionState().hadException());
148 EXPECT_EQ(SyntaxError, scope.getExceptionState().code()); 148 EXPECT_EQ(SyntaxError, scope.getExceptionState().code());
149 EXPECT_EQ("The URL 'xxx' is invalid.", scope.getExceptionState().message()); 149 EXPECT_EQ("The URL 'xxx' is invalid.", scope.getExceptionState().message());
150 EXPECT_EQ(DOMWebSocket::CLOSED, webSocketScope.socket().readyState()); 150 EXPECT_EQ(DOMWebSocket::kClosed, webSocketScope.socket().readyState());
151 } 151 }
152 152
153 TEST(DOMWebSocketTest, connectToNonWsURL) 153 TEST(DOMWebSocketTest, connectToNonWsURL)
154 { 154 {
155 V8TestingScope scope; 155 V8TestingScope scope;
156 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 156 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
157 webSocketScope.socket().connect("http://example.com/", Vector<String>(), sco pe.getExceptionState()); 157 webSocketScope.socket().connect("http://example.com/", Vector<String>(), sco pe.getExceptionState());
158 158
159 159
160 EXPECT_TRUE(scope.getExceptionState().hadException()); 160 EXPECT_TRUE(scope.getExceptionState().hadException());
161 EXPECT_EQ(SyntaxError, scope.getExceptionState().code()); 161 EXPECT_EQ(SyntaxError, scope.getExceptionState().code());
162 EXPECT_EQ("The URL's scheme must be either 'ws' or 'wss'. 'http' is not allo wed.", scope.getExceptionState().message()); 162 EXPECT_EQ("The URL's scheme must be either 'ws' or 'wss'. 'http' is not allo wed.", scope.getExceptionState().message());
163 EXPECT_EQ(DOMWebSocket::CLOSED, webSocketScope.socket().readyState()); 163 EXPECT_EQ(DOMWebSocket::kClosed, webSocketScope.socket().readyState());
164 } 164 }
165 165
166 TEST(DOMWebSocketTest, connectToURLHavingFragmentIdentifier) 166 TEST(DOMWebSocketTest, connectToURLHavingFragmentIdentifier)
167 { 167 {
168 V8TestingScope scope; 168 V8TestingScope scope;
169 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 169 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
170 webSocketScope.socket().connect("ws://example.com/#fragment", Vector<String> (), scope.getExceptionState()); 170 webSocketScope.socket().connect("ws://example.com/#fragment", Vector<String> (), scope.getExceptionState());
171 171
172 172
173 EXPECT_TRUE(scope.getExceptionState().hadException()); 173 EXPECT_TRUE(scope.getExceptionState().hadException());
174 EXPECT_EQ(SyntaxError, scope.getExceptionState().code()); 174 EXPECT_EQ(SyntaxError, scope.getExceptionState().code());
175 EXPECT_EQ("The URL contains a fragment identifier ('fragment'). Fragment ide ntifiers are not allowed in WebSocket URLs.", scope.getExceptionState().message( )); 175 EXPECT_EQ("The URL contains a fragment identifier ('fragment'). Fragment ide ntifiers are not allowed in WebSocket URLs.", scope.getExceptionState().message( ));
176 EXPECT_EQ(DOMWebSocket::CLOSED, webSocketScope.socket().readyState()); 176 EXPECT_EQ(DOMWebSocket::kClosed, webSocketScope.socket().readyState());
177 } 177 }
178 178
179 TEST(DOMWebSocketTest, invalidPort) 179 TEST(DOMWebSocketTest, invalidPort)
180 { 180 {
181 V8TestingScope scope; 181 V8TestingScope scope;
182 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 182 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
183 webSocketScope.socket().connect("ws://example.com:7", Vector<String>(), scop e.getExceptionState()); 183 webSocketScope.socket().connect("ws://example.com:7", Vector<String>(), scop e.getExceptionState());
184 184
185 185
186 EXPECT_TRUE(scope.getExceptionState().hadException()); 186 EXPECT_TRUE(scope.getExceptionState().hadException());
187 EXPECT_EQ(SecurityError, scope.getExceptionState().code()); 187 EXPECT_EQ(SecurityError, scope.getExceptionState().code());
188 EXPECT_EQ("The port 7 is not allowed.", scope.getExceptionState().message()) ; 188 EXPECT_EQ("The port 7 is not allowed.", scope.getExceptionState().message()) ;
189 EXPECT_EQ(DOMWebSocket::CLOSED, webSocketScope.socket().readyState()); 189 EXPECT_EQ(DOMWebSocket::kClosed, webSocketScope.socket().readyState());
190 } 190 }
191 191
192 // FIXME: Add a test for Content Security Policy. 192 // FIXME: Add a test for Content Security Policy.
193 193
194 TEST(DOMWebSocketTest, invalidSubprotocols) 194 TEST(DOMWebSocketTest, invalidSubprotocols)
195 { 195 {
196 V8TestingScope scope; 196 V8TestingScope scope;
197 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 197 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
198 Vector<String> subprotocols; 198 Vector<String> subprotocols;
199 subprotocols.append("@subprotocol-|'\"x\x01\x02\x03x"); 199 subprotocols.append("@subprotocol-|'\"x\x01\x02\x03x");
200 200
201 webSocketScope.socket().connect("ws://example.com/", subprotocols, scope.get ExceptionState()); 201 webSocketScope.socket().connect("ws://example.com/", subprotocols, scope.get ExceptionState());
202 202
203 EXPECT_TRUE(scope.getExceptionState().hadException()); 203 EXPECT_TRUE(scope.getExceptionState().hadException());
204 EXPECT_EQ(SyntaxError, scope.getExceptionState().code()); 204 EXPECT_EQ(SyntaxError, scope.getExceptionState().code());
205 EXPECT_EQ("The subprotocol '@subprotocol-|'\"x\\u0001\\u0002\\u0003x' is inv alid.", scope.getExceptionState().message()); 205 EXPECT_EQ("The subprotocol '@subprotocol-|'\"x\\u0001\\u0002\\u0003x' is inv alid.", scope.getExceptionState().message());
206 EXPECT_EQ(DOMWebSocket::CLOSED, webSocketScope.socket().readyState()); 206 EXPECT_EQ(DOMWebSocket::kClosed, webSocketScope.socket().readyState());
207 } 207 }
208 208
209 TEST(DOMWebSocketTest, insecureRequestsUpgrade) 209 TEST(DOMWebSocketTest, insecureRequestsUpgrade)
210 { 210 {
211 V8TestingScope scope; 211 V8TestingScope scope;
212 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 212 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
213 { 213 {
214 InSequence s; 214 InSequence s;
215 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "wss://exampl e.com/endpoint"), String())).WillOnce(Return(true)); 215 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "wss://exampl e.com/endpoint"), String())).WillOnce(Return(true));
216 } 216 }
217 217
218 scope.document().setInsecureRequestPolicy(kUpgradeInsecureRequests); 218 scope.document().setInsecureRequestPolicy(kUpgradeInsecureRequests);
219 webSocketScope.socket().connect("ws://example.com/endpoint", Vector<String>( ), scope.getExceptionState()); 219 webSocketScope.socket().connect("ws://example.com/endpoint", Vector<String>( ), scope.getExceptionState());
220 220
221 EXPECT_FALSE(scope.getExceptionState().hadException()); 221 EXPECT_FALSE(scope.getExceptionState().hadException());
222 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 222 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
223 EXPECT_EQ(KURL(KURL(), "wss://example.com/endpoint"), webSocketScope.socket( ).url()); 223 EXPECT_EQ(KURL(KURL(), "wss://example.com/endpoint"), webSocketScope.socket( ).url());
224 } 224 }
225 225
226 TEST(DOMWebSocketTest, insecureRequestsDoNotUpgrade) 226 TEST(DOMWebSocketTest, insecureRequestsDoNotUpgrade)
227 { 227 {
228 V8TestingScope scope; 228 V8TestingScope scope;
229 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 229 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
230 { 230 {
231 InSequence s; 231 InSequence s;
232 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/endpoint"), String())).WillOnce(Return(true)); 232 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/endpoint"), String())).WillOnce(Return(true));
233 } 233 }
234 234
235 scope.document().setInsecureRequestPolicy(kLeaveInsecureRequestsAlone); 235 scope.document().setInsecureRequestPolicy(kLeaveInsecureRequestsAlone);
236 webSocketScope.socket().connect("ws://example.com/endpoint", Vector<String>( ), scope.getExceptionState()); 236 webSocketScope.socket().connect("ws://example.com/endpoint", Vector<String>( ), scope.getExceptionState());
237 237
238 EXPECT_FALSE(scope.getExceptionState().hadException()); 238 EXPECT_FALSE(scope.getExceptionState().hadException());
239 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 239 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
240 EXPECT_EQ(KURL(KURL(), "ws://example.com/endpoint"), webSocketScope.socket() .url()); 240 EXPECT_EQ(KURL(KURL(), "ws://example.com/endpoint"), webSocketScope.socket() .url());
241 } 241 }
242 242
243 TEST(DOMWebSocketTest, channelConnectSuccess) 243 TEST(DOMWebSocketTest, channelConnectSuccess)
244 { 244 {
245 V8TestingScope scope; 245 V8TestingScope scope;
246 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 246 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
247 Vector<String> subprotocols; 247 Vector<String> subprotocols;
248 subprotocols.append("aa"); 248 subprotocols.append("aa");
249 subprotocols.append("bb"); 249 subprotocols.append("bb");
250 250
251 { 251 {
252 InSequence s; 252 InSequence s;
253 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/hoge"), String("aa, bb"))).WillOnce(Return(true)); 253 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/hoge"), String("aa, bb"))).WillOnce(Return(true));
254 } 254 }
255 255
256 webSocketScope.socket().connect("ws://example.com/hoge", Vector<String>(subp rotocols), scope.getExceptionState()); 256 webSocketScope.socket().connect("ws://example.com/hoge", Vector<String>(subp rotocols), scope.getExceptionState());
257 257
258 258
259 EXPECT_FALSE(scope.getExceptionState().hadException()); 259 EXPECT_FALSE(scope.getExceptionState().hadException());
260 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 260 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
261 EXPECT_EQ(KURL(KURL(), "ws://example.com/hoge"), webSocketScope.socket().url ()); 261 EXPECT_EQ(KURL(KURL(), "ws://example.com/hoge"), webSocketScope.socket().url ());
262 } 262 }
263 263
264 TEST(DOMWebSocketTest, channelConnectFail) 264 TEST(DOMWebSocketTest, channelConnectFail)
265 { 265 {
266 V8TestingScope scope; 266 V8TestingScope scope;
267 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 267 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
268 Vector<String> subprotocols; 268 Vector<String> subprotocols;
269 subprotocols.append("aa"); 269 subprotocols.append("aa");
270 subprotocols.append("bb"); 270 subprotocols.append("bb");
271 271
272 { 272 {
273 InSequence s; 273 InSequence s;
274 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String("aa, bb"))).WillOnce(Return(false)); 274 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String("aa, bb"))).WillOnce(Return(false));
275 EXPECT_CALL(webSocketScope.channel(), disconnect()); 275 EXPECT_CALL(webSocketScope.channel(), disconnect());
276 } 276 }
277 277
278 webSocketScope.socket().connect("ws://example.com/", Vector<String>(subproto cols), scope.getExceptionState()); 278 webSocketScope.socket().connect("ws://example.com/", Vector<String>(subproto cols), scope.getExceptionState());
279 279
280 280
281 EXPECT_TRUE(scope.getExceptionState().hadException()); 281 EXPECT_TRUE(scope.getExceptionState().hadException());
282 EXPECT_EQ(SecurityError, scope.getExceptionState().code()); 282 EXPECT_EQ(SecurityError, scope.getExceptionState().code());
283 EXPECT_EQ("An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.", scope.getExceptionState().message()); 283 EXPECT_EQ("An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.", scope.getExceptionState().message());
284 EXPECT_EQ(DOMWebSocket::CLOSED, webSocketScope.socket().readyState()); 284 EXPECT_EQ(DOMWebSocket::kClosed, webSocketScope.socket().readyState());
285 } 285 }
286 286
287 TEST(DOMWebSocketTest, isValidSubprotocolString) 287 TEST(DOMWebSocketTest, isValidSubprotocolString)
288 { 288 {
289 EXPECT_TRUE(DOMWebSocket::isValidSubprotocolString("Helloworld!!")); 289 EXPECT_TRUE(DOMWebSocket::isValidSubprotocolString("Helloworld!!"));
290 EXPECT_FALSE(DOMWebSocket::isValidSubprotocolString("Hello, world!!")); 290 EXPECT_FALSE(DOMWebSocket::isValidSubprotocolString("Hello, world!!"));
291 EXPECT_FALSE(DOMWebSocket::isValidSubprotocolString(String())); 291 EXPECT_FALSE(DOMWebSocket::isValidSubprotocolString(String()));
292 EXPECT_FALSE(DOMWebSocket::isValidSubprotocolString("")); 292 EXPECT_FALSE(DOMWebSocket::isValidSubprotocolString(""));
293 293
294 const char validCharacters[] = "!#$%&'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWX YZ^_`abcdefghijklmnopqrstuvwxyz|~"; 294 const char validCharacters[] = "!#$%&'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWX YZ^_`abcdefghijklmnopqrstuvwxyz|~";
(...skipping 20 matching lines...) Expand all
315 Vector<String> subprotocols; 315 Vector<String> subprotocols;
316 subprotocols.append("aa"); 316 subprotocols.append("aa");
317 subprotocols.append("bb"); 317 subprotocols.append("bb");
318 { 318 {
319 InSequence s; 319 InSequence s;
320 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String("aa, bb"))).WillOnce(Return(true)); 320 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String("aa, bb"))).WillOnce(Return(true));
321 } 321 }
322 webSocketScope.socket().connect("ws://example.com/", subprotocols, scope.get ExceptionState()); 322 webSocketScope.socket().connect("ws://example.com/", subprotocols, scope.get ExceptionState());
323 323
324 EXPECT_FALSE(scope.getExceptionState().hadException()); 324 EXPECT_FALSE(scope.getExceptionState().hadException());
325 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 325 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
326 326
327 webSocketScope.socket().didConnect("bb", "cc"); 327 webSocketScope.socket().didConnect("bb", "cc");
328 328
329 EXPECT_EQ(DOMWebSocket::OPEN, webSocketScope.socket().readyState()); 329 EXPECT_EQ(DOMWebSocket::kOpen, webSocketScope.socket().readyState());
330 EXPECT_EQ("bb", webSocketScope.socket().protocol()); 330 EXPECT_EQ("bb", webSocketScope.socket().protocol());
331 EXPECT_EQ("cc", webSocketScope.socket().extensions()); 331 EXPECT_EQ("cc", webSocketScope.socket().extensions());
332 } 332 }
333 333
334 TEST(DOMWebSocketTest, didClose) 334 TEST(DOMWebSocketTest, didClose)
335 { 335 {
336 V8TestingScope scope; 336 V8TestingScope scope;
337 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 337 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
338 { 338 {
339 InSequence s; 339 InSequence s;
340 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 340 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
341 EXPECT_CALL(webSocketScope.channel(), disconnect()); 341 EXPECT_CALL(webSocketScope.channel(), disconnect());
342 } 342 }
343 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 343 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
344 344
345 EXPECT_FALSE(scope.getExceptionState().hadException()); 345 EXPECT_FALSE(scope.getExceptionState().hadException());
346 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 346 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
347 347
348 webSocketScope.socket().didClose(WebSocketChannelClient::ClosingHandshakeInc omplete, 1006, ""); 348 webSocketScope.socket().didClose(WebSocketChannelClient::ClosingHandshakeInc omplete, 1006, "");
349 349
350 EXPECT_EQ(DOMWebSocket::CLOSED, webSocketScope.socket().readyState()); 350 EXPECT_EQ(DOMWebSocket::kClosed, webSocketScope.socket().readyState());
351 } 351 }
352 352
353 TEST(DOMWebSocketTest, maximumReasonSize) 353 TEST(DOMWebSocketTest, maximumReasonSize)
354 { 354 {
355 V8TestingScope scope; 355 V8TestingScope scope;
356 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 356 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
357 { 357 {
358 InSequence s; 358 InSequence s;
359 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 359 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
360 EXPECT_CALL(webSocketScope.channel(), failMock(_, _, _)); 360 EXPECT_CALL(webSocketScope.channel(), failMock(_, _, _));
361 } 361 }
362 StringBuilder reason; 362 StringBuilder reason;
363 for (size_t i = 0; i < 123; ++i) 363 for (size_t i = 0; i < 123; ++i)
364 reason.append('a'); 364 reason.append('a');
365 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 365 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
366 366
367 EXPECT_FALSE(scope.getExceptionState().hadException()); 367 EXPECT_FALSE(scope.getExceptionState().hadException());
368 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 368 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
369 369
370 webSocketScope.socket().close(1000, reason.toString(), scope.getExceptionSta te()); 370 webSocketScope.socket().close(1000, reason.toString(), scope.getExceptionSta te());
371 371
372 EXPECT_FALSE(scope.getExceptionState().hadException()); 372 EXPECT_FALSE(scope.getExceptionState().hadException());
373 EXPECT_EQ(DOMWebSocket::CLOSING, webSocketScope.socket().readyState()); 373 EXPECT_EQ(DOMWebSocket::kClosing, webSocketScope.socket().readyState());
374 } 374 }
375 375
376 TEST(DOMWebSocketTest, reasonSizeExceeding) 376 TEST(DOMWebSocketTest, reasonSizeExceeding)
377 { 377 {
378 V8TestingScope scope; 378 V8TestingScope scope;
379 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 379 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
380 { 380 {
381 InSequence s; 381 InSequence s;
382 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 382 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
383 } 383 }
384 StringBuilder reason; 384 StringBuilder reason;
385 for (size_t i = 0; i < 124; ++i) 385 for (size_t i = 0; i < 124; ++i)
386 reason.append('a'); 386 reason.append('a');
387 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 387 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
388 388
389 EXPECT_FALSE(scope.getExceptionState().hadException()); 389 EXPECT_FALSE(scope.getExceptionState().hadException());
390 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 390 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
391 391
392 webSocketScope.socket().close(1000, reason.toString(), scope.getExceptionSta te()); 392 webSocketScope.socket().close(1000, reason.toString(), scope.getExceptionSta te());
393 393
394 EXPECT_TRUE(scope.getExceptionState().hadException()); 394 EXPECT_TRUE(scope.getExceptionState().hadException());
395 EXPECT_EQ(SyntaxError, scope.getExceptionState().code()); 395 EXPECT_EQ(SyntaxError, scope.getExceptionState().code());
396 EXPECT_EQ("The message must not be greater than 123 bytes.", scope.getExcept ionState().message()); 396 EXPECT_EQ("The message must not be greater than 123 bytes.", scope.getExcept ionState().message());
397 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 397 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
398 } 398 }
399 399
400 TEST(DOMWebSocketTest, closeWhenConnecting) 400 TEST(DOMWebSocketTest, closeWhenConnecting)
401 { 401 {
402 V8TestingScope scope; 402 V8TestingScope scope;
403 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 403 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
404 { 404 {
405 InSequence s; 405 InSequence s;
406 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 406 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
407 EXPECT_CALL(webSocketScope.channel(), failMock(String("WebSocket is clos ed before the connection is established."), WarningMessageLevel, _)); 407 EXPECT_CALL(webSocketScope.channel(), failMock(String("WebSocket is clos ed before the connection is established."), WarningMessageLevel, _));
408 } 408 }
409 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 409 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
410 410
411 EXPECT_FALSE(scope.getExceptionState().hadException()); 411 EXPECT_FALSE(scope.getExceptionState().hadException());
412 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 412 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
413 413
414 webSocketScope.socket().close(1000, "bye", scope.getExceptionState()); 414 webSocketScope.socket().close(1000, "bye", scope.getExceptionState());
415 415
416 EXPECT_FALSE(scope.getExceptionState().hadException()); 416 EXPECT_FALSE(scope.getExceptionState().hadException());
417 EXPECT_EQ(DOMWebSocket::CLOSING, webSocketScope.socket().readyState()); 417 EXPECT_EQ(DOMWebSocket::kClosing, webSocketScope.socket().readyState());
418 } 418 }
419 419
420 TEST(DOMWebSocketTest, close) 420 TEST(DOMWebSocketTest, close)
421 { 421 {
422 V8TestingScope scope; 422 V8TestingScope scope;
423 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 423 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
424 { 424 {
425 InSequence s; 425 InSequence s;
426 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 426 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
427 EXPECT_CALL(webSocketScope.channel(), close(3005, String("bye"))); 427 EXPECT_CALL(webSocketScope.channel(), close(3005, String("bye")));
428 } 428 }
429 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 429 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
430 430
431 EXPECT_FALSE(scope.getExceptionState().hadException()); 431 EXPECT_FALSE(scope.getExceptionState().hadException());
432 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 432 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
433 433
434 webSocketScope.socket().didConnect("", ""); 434 webSocketScope.socket().didConnect("", "");
435 EXPECT_EQ(DOMWebSocket::OPEN, webSocketScope.socket().readyState()); 435 EXPECT_EQ(DOMWebSocket::kOpen, webSocketScope.socket().readyState());
436 webSocketScope.socket().close(3005, "bye", scope.getExceptionState()); 436 webSocketScope.socket().close(3005, "bye", scope.getExceptionState());
437 437
438 EXPECT_FALSE(scope.getExceptionState().hadException()); 438 EXPECT_FALSE(scope.getExceptionState().hadException());
439 EXPECT_EQ(DOMWebSocket::CLOSING, webSocketScope.socket().readyState()); 439 EXPECT_EQ(DOMWebSocket::kClosing, webSocketScope.socket().readyState());
440 } 440 }
441 441
442 TEST(DOMWebSocketTest, closeWithoutReason) 442 TEST(DOMWebSocketTest, closeWithoutReason)
443 { 443 {
444 V8TestingScope scope; 444 V8TestingScope scope;
445 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 445 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
446 { 446 {
447 InSequence s; 447 InSequence s;
448 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 448 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
449 EXPECT_CALL(webSocketScope.channel(), close(3005, String())); 449 EXPECT_CALL(webSocketScope.channel(), close(3005, String()));
450 } 450 }
451 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 451 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
452 452
453 EXPECT_FALSE(scope.getExceptionState().hadException()); 453 EXPECT_FALSE(scope.getExceptionState().hadException());
454 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 454 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
455 455
456 webSocketScope.socket().didConnect("", ""); 456 webSocketScope.socket().didConnect("", "");
457 EXPECT_EQ(DOMWebSocket::OPEN, webSocketScope.socket().readyState()); 457 EXPECT_EQ(DOMWebSocket::kOpen, webSocketScope.socket().readyState());
458 webSocketScope.socket().close(3005, scope.getExceptionState()); 458 webSocketScope.socket().close(3005, scope.getExceptionState());
459 459
460 EXPECT_FALSE(scope.getExceptionState().hadException()); 460 EXPECT_FALSE(scope.getExceptionState().hadException());
461 EXPECT_EQ(DOMWebSocket::CLOSING, webSocketScope.socket().readyState()); 461 EXPECT_EQ(DOMWebSocket::kClosing, webSocketScope.socket().readyState());
462 } 462 }
463 463
464 TEST(DOMWebSocketTest, closeWithoutCodeAndReason) 464 TEST(DOMWebSocketTest, closeWithoutCodeAndReason)
465 { 465 {
466 V8TestingScope scope; 466 V8TestingScope scope;
467 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 467 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
468 { 468 {
469 InSequence s; 469 InSequence s;
470 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 470 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
471 EXPECT_CALL(webSocketScope.channel(), close(-1, String())); 471 EXPECT_CALL(webSocketScope.channel(), close(-1, String()));
472 } 472 }
473 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 473 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
474 474
475 EXPECT_FALSE(scope.getExceptionState().hadException()); 475 EXPECT_FALSE(scope.getExceptionState().hadException());
476 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 476 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
477 477
478 webSocketScope.socket().didConnect("", ""); 478 webSocketScope.socket().didConnect("", "");
479 EXPECT_EQ(DOMWebSocket::OPEN, webSocketScope.socket().readyState()); 479 EXPECT_EQ(DOMWebSocket::kOpen, webSocketScope.socket().readyState());
480 webSocketScope.socket().close(scope.getExceptionState()); 480 webSocketScope.socket().close(scope.getExceptionState());
481 481
482 EXPECT_FALSE(scope.getExceptionState().hadException()); 482 EXPECT_FALSE(scope.getExceptionState().hadException());
483 EXPECT_EQ(DOMWebSocket::CLOSING, webSocketScope.socket().readyState()); 483 EXPECT_EQ(DOMWebSocket::kClosing, webSocketScope.socket().readyState());
484 } 484 }
485 485
486 TEST(DOMWebSocketTest, closeWhenClosing) 486 TEST(DOMWebSocketTest, closeWhenClosing)
487 { 487 {
488 V8TestingScope scope; 488 V8TestingScope scope;
489 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 489 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
490 { 490 {
491 InSequence s; 491 InSequence s;
492 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 492 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
493 EXPECT_CALL(webSocketScope.channel(), close(-1, String())); 493 EXPECT_CALL(webSocketScope.channel(), close(-1, String()));
494 } 494 }
495 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 495 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
496 496
497 EXPECT_FALSE(scope.getExceptionState().hadException()); 497 EXPECT_FALSE(scope.getExceptionState().hadException());
498 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 498 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
499 499
500 webSocketScope.socket().didConnect("", ""); 500 webSocketScope.socket().didConnect("", "");
501 EXPECT_EQ(DOMWebSocket::OPEN, webSocketScope.socket().readyState()); 501 EXPECT_EQ(DOMWebSocket::kOpen, webSocketScope.socket().readyState());
502 webSocketScope.socket().close(scope.getExceptionState()); 502 webSocketScope.socket().close(scope.getExceptionState());
503 EXPECT_FALSE(scope.getExceptionState().hadException()); 503 EXPECT_FALSE(scope.getExceptionState().hadException());
504 EXPECT_EQ(DOMWebSocket::CLOSING, webSocketScope.socket().readyState()); 504 EXPECT_EQ(DOMWebSocket::kClosing, webSocketScope.socket().readyState());
505 505
506 webSocketScope.socket().close(scope.getExceptionState()); 506 webSocketScope.socket().close(scope.getExceptionState());
507 507
508 EXPECT_FALSE(scope.getExceptionState().hadException()); 508 EXPECT_FALSE(scope.getExceptionState().hadException());
509 EXPECT_EQ(DOMWebSocket::CLOSING, webSocketScope.socket().readyState()); 509 EXPECT_EQ(DOMWebSocket::kClosing, webSocketScope.socket().readyState());
510 } 510 }
511 511
512 TEST(DOMWebSocketTest, closeWhenClosed) 512 TEST(DOMWebSocketTest, closeWhenClosed)
513 { 513 {
514 V8TestingScope scope; 514 V8TestingScope scope;
515 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 515 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
516 { 516 {
517 InSequence s; 517 InSequence s;
518 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 518 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
519 EXPECT_CALL(webSocketScope.channel(), close(-1, String())); 519 EXPECT_CALL(webSocketScope.channel(), close(-1, String()));
520 EXPECT_CALL(webSocketScope.channel(), disconnect()); 520 EXPECT_CALL(webSocketScope.channel(), disconnect());
521 } 521 }
522 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 522 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
523 523
524 EXPECT_FALSE(scope.getExceptionState().hadException()); 524 EXPECT_FALSE(scope.getExceptionState().hadException());
525 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 525 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
526 526
527 webSocketScope.socket().didConnect("", ""); 527 webSocketScope.socket().didConnect("", "");
528 EXPECT_EQ(DOMWebSocket::OPEN, webSocketScope.socket().readyState()); 528 EXPECT_EQ(DOMWebSocket::kOpen, webSocketScope.socket().readyState());
529 webSocketScope.socket().close(scope.getExceptionState()); 529 webSocketScope.socket().close(scope.getExceptionState());
530 EXPECT_FALSE(scope.getExceptionState().hadException()); 530 EXPECT_FALSE(scope.getExceptionState().hadException());
531 EXPECT_EQ(DOMWebSocket::CLOSING, webSocketScope.socket().readyState()); 531 EXPECT_EQ(DOMWebSocket::kClosing, webSocketScope.socket().readyState());
532 532
533 webSocketScope.socket().didClose(WebSocketChannelClient::ClosingHandshakeCom plete, 1000, String()); 533 webSocketScope.socket().didClose(WebSocketChannelClient::ClosingHandshakeCom plete, 1000, String());
534 EXPECT_EQ(DOMWebSocket::CLOSED, webSocketScope.socket().readyState()); 534 EXPECT_EQ(DOMWebSocket::kClosed, webSocketScope.socket().readyState());
535 webSocketScope.socket().close(scope.getExceptionState()); 535 webSocketScope.socket().close(scope.getExceptionState());
536 536
537 EXPECT_FALSE(scope.getExceptionState().hadException()); 537 EXPECT_FALSE(scope.getExceptionState().hadException());
538 EXPECT_EQ(DOMWebSocket::CLOSED, webSocketScope.socket().readyState()); 538 EXPECT_EQ(DOMWebSocket::kClosed, webSocketScope.socket().readyState());
539 } 539 }
540 540
541 TEST(DOMWebSocketTest, sendStringWhenConnecting) 541 TEST(DOMWebSocketTest, sendStringWhenConnecting)
542 { 542 {
543 V8TestingScope scope; 543 V8TestingScope scope;
544 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 544 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
545 { 545 {
546 InSequence s; 546 InSequence s;
547 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 547 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
548 } 548 }
549 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 549 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
550 550
551 EXPECT_FALSE(scope.getExceptionState().hadException()); 551 EXPECT_FALSE(scope.getExceptionState().hadException());
552 552
553 webSocketScope.socket().send("hello", scope.getExceptionState()); 553 webSocketScope.socket().send("hello", scope.getExceptionState());
554 554
555 EXPECT_TRUE(scope.getExceptionState().hadException()); 555 EXPECT_TRUE(scope.getExceptionState().hadException());
556 EXPECT_EQ(InvalidStateError, scope.getExceptionState().code()); 556 EXPECT_EQ(InvalidStateError, scope.getExceptionState().code());
557 EXPECT_EQ("Still in CONNECTING state.", scope.getExceptionState().message()) ; 557 EXPECT_EQ("Still in CONNECTING state.", scope.getExceptionState().message()) ;
558 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 558 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
559 } 559 }
560 560
561 TEST(DOMWebSocketTest, sendStringWhenClosing) 561 TEST(DOMWebSocketTest, sendStringWhenClosing)
562 { 562 {
563 V8TestingScope scope; 563 V8TestingScope scope;
564 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 564 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
565 Checkpoint checkpoint; 565 Checkpoint checkpoint;
566 { 566 {
567 InSequence s; 567 InSequence s;
568 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 568 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
569 EXPECT_CALL(webSocketScope.channel(), failMock(_, _, _)); 569 EXPECT_CALL(webSocketScope.channel(), failMock(_, _, _));
570 } 570 }
571 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 571 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
572 572
573 EXPECT_FALSE(scope.getExceptionState().hadException()); 573 EXPECT_FALSE(scope.getExceptionState().hadException());
574 574
575 webSocketScope.socket().close(scope.getExceptionState()); 575 webSocketScope.socket().close(scope.getExceptionState());
576 EXPECT_FALSE(scope.getExceptionState().hadException()); 576 EXPECT_FALSE(scope.getExceptionState().hadException());
577 577
578 webSocketScope.socket().send("hello", scope.getExceptionState()); 578 webSocketScope.socket().send("hello", scope.getExceptionState());
579 579
580 EXPECT_FALSE(scope.getExceptionState().hadException()); 580 EXPECT_FALSE(scope.getExceptionState().hadException());
581 EXPECT_EQ(DOMWebSocket::CLOSING, webSocketScope.socket().readyState()); 581 EXPECT_EQ(DOMWebSocket::kClosing, webSocketScope.socket().readyState());
582 } 582 }
583 583
584 TEST(DOMWebSocketTest, sendStringWhenClosed) 584 TEST(DOMWebSocketTest, sendStringWhenClosed)
585 { 585 {
586 V8TestingScope scope; 586 V8TestingScope scope;
587 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 587 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
588 Checkpoint checkpoint; 588 Checkpoint checkpoint;
589 { 589 {
590 InSequence s; 590 InSequence s;
591 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 591 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
592 EXPECT_CALL(webSocketScope.channel(), disconnect()); 592 EXPECT_CALL(webSocketScope.channel(), disconnect());
593 EXPECT_CALL(checkpoint, Call(1)); 593 EXPECT_CALL(checkpoint, Call(1));
594 } 594 }
595 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 595 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
596 596
597 EXPECT_FALSE(scope.getExceptionState().hadException()); 597 EXPECT_FALSE(scope.getExceptionState().hadException());
598 598
599 webSocketScope.socket().didClose(WebSocketChannelClient::ClosingHandshakeInc omplete, 1006, ""); 599 webSocketScope.socket().didClose(WebSocketChannelClient::ClosingHandshakeInc omplete, 1006, "");
600 checkpoint.Call(1); 600 checkpoint.Call(1);
601 601
602 webSocketScope.socket().send("hello", scope.getExceptionState()); 602 webSocketScope.socket().send("hello", scope.getExceptionState());
603 603
604 EXPECT_FALSE(scope.getExceptionState().hadException()); 604 EXPECT_FALSE(scope.getExceptionState().hadException());
605 EXPECT_EQ(DOMWebSocket::CLOSED, webSocketScope.socket().readyState()); 605 EXPECT_EQ(DOMWebSocket::kClosed, webSocketScope.socket().readyState());
606 } 606 }
607 607
608 TEST(DOMWebSocketTest, sendStringSuccess) 608 TEST(DOMWebSocketTest, sendStringSuccess)
609 { 609 {
610 V8TestingScope scope; 610 V8TestingScope scope;
611 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 611 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
612 { 612 {
613 InSequence s; 613 InSequence s;
614 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 614 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
615 EXPECT_CALL(webSocketScope.channel(), send(CString("hello"))); 615 EXPECT_CALL(webSocketScope.channel(), send(CString("hello")));
616 } 616 }
617 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 617 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
618 618
619 EXPECT_FALSE(scope.getExceptionState().hadException()); 619 EXPECT_FALSE(scope.getExceptionState().hadException());
620 620
621 webSocketScope.socket().didConnect("", ""); 621 webSocketScope.socket().didConnect("", "");
622 webSocketScope.socket().send("hello", scope.getExceptionState()); 622 webSocketScope.socket().send("hello", scope.getExceptionState());
623 623
624 EXPECT_FALSE(scope.getExceptionState().hadException()); 624 EXPECT_FALSE(scope.getExceptionState().hadException());
625 EXPECT_EQ(DOMWebSocket::OPEN, webSocketScope.socket().readyState()); 625 EXPECT_EQ(DOMWebSocket::kOpen, webSocketScope.socket().readyState());
626 } 626 }
627 627
628 TEST(DOMWebSocketTest, sendNonLatin1String) 628 TEST(DOMWebSocketTest, sendNonLatin1String)
629 { 629 {
630 V8TestingScope scope; 630 V8TestingScope scope;
631 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 631 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
632 { 632 {
633 InSequence s; 633 InSequence s;
634 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 634 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
635 EXPECT_CALL(webSocketScope.channel(), send(CString("\xe7\x8b\x90\xe0\xa4 \x94"))); 635 EXPECT_CALL(webSocketScope.channel(), send(CString("\xe7\x8b\x90\xe0\xa4 \x94")));
636 } 636 }
637 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 637 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
638 638
639 EXPECT_FALSE(scope.getExceptionState().hadException()); 639 EXPECT_FALSE(scope.getExceptionState().hadException());
640 640
641 webSocketScope.socket().didConnect("", ""); 641 webSocketScope.socket().didConnect("", "");
642 UChar nonLatin1String[] = { 642 UChar nonLatin1String[] = {
643 0x72d0, 643 0x72d0,
644 0x0914, 644 0x0914,
645 0x0000 645 0x0000
646 }; 646 };
647 webSocketScope.socket().send(nonLatin1String, scope.getExceptionState()); 647 webSocketScope.socket().send(nonLatin1String, scope.getExceptionState());
648 648
649 EXPECT_FALSE(scope.getExceptionState().hadException()); 649 EXPECT_FALSE(scope.getExceptionState().hadException());
650 EXPECT_EQ(DOMWebSocket::OPEN, webSocketScope.socket().readyState()); 650 EXPECT_EQ(DOMWebSocket::kOpen, webSocketScope.socket().readyState());
651 } 651 }
652 652
653 TEST(DOMWebSocketTest, sendArrayBufferWhenConnecting) 653 TEST(DOMWebSocketTest, sendArrayBufferWhenConnecting)
654 { 654 {
655 V8TestingScope scope; 655 V8TestingScope scope;
656 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 656 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
657 DOMArrayBufferView* view = DOMUint8Array::create(8); 657 DOMArrayBufferView* view = DOMUint8Array::create(8);
658 { 658 {
659 InSequence s; 659 InSequence s;
660 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 660 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
661 } 661 }
662 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 662 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
663 663
664 EXPECT_FALSE(scope.getExceptionState().hadException()); 664 EXPECT_FALSE(scope.getExceptionState().hadException());
665 665
666 webSocketScope.socket().send(view->buffer(), scope.getExceptionState()); 666 webSocketScope.socket().send(view->buffer(), scope.getExceptionState());
667 667
668 EXPECT_TRUE(scope.getExceptionState().hadException()); 668 EXPECT_TRUE(scope.getExceptionState().hadException());
669 EXPECT_EQ(InvalidStateError, scope.getExceptionState().code()); 669 EXPECT_EQ(InvalidStateError, scope.getExceptionState().code());
670 EXPECT_EQ("Still in CONNECTING state.", scope.getExceptionState().message()) ; 670 EXPECT_EQ("Still in CONNECTING state.", scope.getExceptionState().message()) ;
671 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 671 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
672 } 672 }
673 673
674 TEST(DOMWebSocketTest, sendArrayBufferWhenClosing) 674 TEST(DOMWebSocketTest, sendArrayBufferWhenClosing)
675 { 675 {
676 V8TestingScope scope; 676 V8TestingScope scope;
677 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 677 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
678 DOMArrayBufferView* view = DOMUint8Array::create(8); 678 DOMArrayBufferView* view = DOMUint8Array::create(8);
679 { 679 {
680 InSequence s; 680 InSequence s;
681 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 681 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
682 EXPECT_CALL(webSocketScope.channel(), failMock(_, _, _)); 682 EXPECT_CALL(webSocketScope.channel(), failMock(_, _, _));
683 } 683 }
684 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 684 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
685 685
686 EXPECT_FALSE(scope.getExceptionState().hadException()); 686 EXPECT_FALSE(scope.getExceptionState().hadException());
687 687
688 webSocketScope.socket().close(scope.getExceptionState()); 688 webSocketScope.socket().close(scope.getExceptionState());
689 EXPECT_FALSE(scope.getExceptionState().hadException()); 689 EXPECT_FALSE(scope.getExceptionState().hadException());
690 690
691 webSocketScope.socket().send(view->buffer(), scope.getExceptionState()); 691 webSocketScope.socket().send(view->buffer(), scope.getExceptionState());
692 692
693 EXPECT_FALSE(scope.getExceptionState().hadException()); 693 EXPECT_FALSE(scope.getExceptionState().hadException());
694 EXPECT_EQ(DOMWebSocket::CLOSING, webSocketScope.socket().readyState()); 694 EXPECT_EQ(DOMWebSocket::kClosing, webSocketScope.socket().readyState());
695 } 695 }
696 696
697 TEST(DOMWebSocketTest, sendArrayBufferWhenClosed) 697 TEST(DOMWebSocketTest, sendArrayBufferWhenClosed)
698 { 698 {
699 V8TestingScope scope; 699 V8TestingScope scope;
700 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 700 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
701 Checkpoint checkpoint; 701 Checkpoint checkpoint;
702 DOMArrayBufferView* view = DOMUint8Array::create(8); 702 DOMArrayBufferView* view = DOMUint8Array::create(8);
703 { 703 {
704 InSequence s; 704 InSequence s;
705 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 705 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
706 EXPECT_CALL(webSocketScope.channel(), disconnect()); 706 EXPECT_CALL(webSocketScope.channel(), disconnect());
707 EXPECT_CALL(checkpoint, Call(1)); 707 EXPECT_CALL(checkpoint, Call(1));
708 } 708 }
709 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 709 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
710 710
711 EXPECT_FALSE(scope.getExceptionState().hadException()); 711 EXPECT_FALSE(scope.getExceptionState().hadException());
712 712
713 webSocketScope.socket().didClose(WebSocketChannelClient::ClosingHandshakeInc omplete, 1006, ""); 713 webSocketScope.socket().didClose(WebSocketChannelClient::ClosingHandshakeInc omplete, 1006, "");
714 checkpoint.Call(1); 714 checkpoint.Call(1);
715 715
716 webSocketScope.socket().send(view->buffer(), scope.getExceptionState()); 716 webSocketScope.socket().send(view->buffer(), scope.getExceptionState());
717 717
718 EXPECT_FALSE(scope.getExceptionState().hadException()); 718 EXPECT_FALSE(scope.getExceptionState().hadException());
719 EXPECT_EQ(DOMWebSocket::CLOSED, webSocketScope.socket().readyState()); 719 EXPECT_EQ(DOMWebSocket::kClosed, webSocketScope.socket().readyState());
720 } 720 }
721 721
722 TEST(DOMWebSocketTest, sendArrayBufferSuccess) 722 TEST(DOMWebSocketTest, sendArrayBufferSuccess)
723 { 723 {
724 V8TestingScope scope; 724 V8TestingScope scope;
725 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 725 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
726 DOMArrayBufferView* view = DOMUint8Array::create(8); 726 DOMArrayBufferView* view = DOMUint8Array::create(8);
727 { 727 {
728 InSequence s; 728 InSequence s;
729 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 729 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
730 EXPECT_CALL(webSocketScope.channel(), send(Ref(*view->buffer()), 0, 8)); 730 EXPECT_CALL(webSocketScope.channel(), send(Ref(*view->buffer()), 0, 8));
731 } 731 }
732 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 732 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
733 733
734 EXPECT_FALSE(scope.getExceptionState().hadException()); 734 EXPECT_FALSE(scope.getExceptionState().hadException());
735 735
736 webSocketScope.socket().didConnect("", ""); 736 webSocketScope.socket().didConnect("", "");
737 webSocketScope.socket().send(view->buffer(), scope.getExceptionState()); 737 webSocketScope.socket().send(view->buffer(), scope.getExceptionState());
738 738
739 EXPECT_FALSE(scope.getExceptionState().hadException()); 739 EXPECT_FALSE(scope.getExceptionState().hadException());
740 EXPECT_EQ(DOMWebSocket::OPEN, webSocketScope.socket().readyState()); 740 EXPECT_EQ(DOMWebSocket::kOpen, webSocketScope.socket().readyState());
741 } 741 }
742 742
743 // FIXME: We should have Blob tests here. 743 // FIXME: We should have Blob tests here.
744 // We can't create a Blob because the blob registration cannot be mocked yet. 744 // We can't create a Blob because the blob registration cannot be mocked yet.
745 745
746 // FIXME: We should add tests for bufferedAmount. 746 // FIXME: We should add tests for bufferedAmount.
747 747
748 // FIXME: We should add tests for data receiving. 748 // FIXME: We should add tests for data receiving.
749 749
750 TEST(DOMWebSocketTest, binaryType) 750 TEST(DOMWebSocketTest, binaryType)
(...skipping 20 matching lines...) Expand all
771 V8TestingScope scope; 771 V8TestingScope scope;
772 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 772 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
773 { 773 {
774 InSequence s; 774 InSequence s;
775 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 775 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
776 EXPECT_CALL(webSocketScope.channel(), failMock(_, _, _)); 776 EXPECT_CALL(webSocketScope.channel(), failMock(_, _, _));
777 } 777 }
778 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 778 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
779 779
780 EXPECT_FALSE(scope.getExceptionState().hadException()); 780 EXPECT_FALSE(scope.getExceptionState().hadException());
781 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 781 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
782 782
783 webSocketScope.socket().close(GetParam(), "bye", scope.getExceptionState()); 783 webSocketScope.socket().close(GetParam(), "bye", scope.getExceptionState());
784 784
785 EXPECT_FALSE(scope.getExceptionState().hadException()); 785 EXPECT_FALSE(scope.getExceptionState().hadException());
786 EXPECT_EQ(DOMWebSocket::CLOSING, webSocketScope.socket().readyState()); 786 EXPECT_EQ(DOMWebSocket::kClosing, webSocketScope.socket().readyState());
787 } 787 }
788 788
789 INSTANTIATE_TEST_CASE_P(DOMWebSocketValidClosing, DOMWebSocketValidClosingTest, ::testing::Values(1000, 3000, 3001, 4998, 4999)); 789 INSTANTIATE_TEST_CASE_P(DOMWebSocketValidClosing, DOMWebSocketValidClosingTest, ::testing::Values(1000, 3000, 3001, 4998, 4999));
790 790
791 class DOMWebSocketInvalidClosingCodeTest : public ::testing::TestWithParam<unsig ned short> {}; 791 class DOMWebSocketInvalidClosingCodeTest : public ::testing::TestWithParam<unsig ned short> {};
792 792
793 TEST_P(DOMWebSocketInvalidClosingCodeTest, test) 793 TEST_P(DOMWebSocketInvalidClosingCodeTest, test)
794 { 794 {
795 V8TestingScope scope; 795 V8TestingScope scope;
796 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext()); 796 DOMWebSocketTestScope webSocketScope(scope.getExecutionContext());
797 { 797 {
798 InSequence s; 798 InSequence s;
799 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true)); 799 EXPECT_CALL(webSocketScope.channel(), connect(KURL(KURL(), "ws://example .com/"), String())).WillOnce(Return(true));
800 } 800 }
801 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState()); 801 webSocketScope.socket().connect("ws://example.com/", Vector<String>(), scope .getExceptionState());
802 802
803 EXPECT_FALSE(scope.getExceptionState().hadException()); 803 EXPECT_FALSE(scope.getExceptionState().hadException());
804 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 804 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
805 805
806 webSocketScope.socket().close(GetParam(), "bye", scope.getExceptionState()); 806 webSocketScope.socket().close(GetParam(), "bye", scope.getExceptionState());
807 807
808 EXPECT_TRUE(scope.getExceptionState().hadException()); 808 EXPECT_TRUE(scope.getExceptionState().hadException());
809 EXPECT_EQ(InvalidAccessError, scope.getExceptionState().code()); 809 EXPECT_EQ(InvalidAccessError, scope.getExceptionState().code());
810 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and 4999. %d is neither.", GetParam()), scope.getExceptionState().message()); 810 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and 4999. %d is neither.", GetParam()), scope.getExceptionState().message());
811 EXPECT_EQ(DOMWebSocket::CONNECTING, webSocketScope.socket().readyState()); 811 EXPECT_EQ(DOMWebSocket::kConnecting, webSocketScope.socket().readyState());
812 } 812 }
813 813
814 INSTANTIATE_TEST_CASE_P(DOMWebSocketInvalidClosingCode, DOMWebSocketInvalidClosi ngCodeTest, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); 814 INSTANTIATE_TEST_CASE_P(DOMWebSocketInvalidClosingCode, DOMWebSocketInvalidClosi ngCodeTest, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535));
815 815
816 } // namespace 816 } // namespace
817 817
818 } // namespace blink 818 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698