OLD | NEW |
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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "modules/websockets/WebSocket.h" | 7 #include "modules/websockets/WebSocket.h" |
8 | 8 |
9 #include "bindings/v8/ExceptionState.h" | 9 #include "bindings/v8/ExceptionState.h" |
10 #include "bindings/v8/V8Binding.h" | 10 #include "bindings/v8/V8Binding.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 { | 63 { |
64 } | 64 } |
65 }; | 65 }; |
66 | 66 |
67 class WebSocketWithMockChannel FINAL : public WebSocket { | 67 class WebSocketWithMockChannel FINAL : public WebSocket { |
68 public: | 68 public: |
69 static PassRefPtrWillBeRawPtr<WebSocketWithMockChannel> create(ExecutionCont
ext* context) | 69 static PassRefPtrWillBeRawPtr<WebSocketWithMockChannel> create(ExecutionCont
ext* context) |
70 { | 70 { |
71 RefPtrWillBeRawPtr<WebSocketWithMockChannel> websocket = adoptRefWillBeR
efCountedGarbageCollected(new WebSocketWithMockChannel(context)); | 71 RefPtrWillBeRawPtr<WebSocketWithMockChannel> websocket = adoptRefWillBeR
efCountedGarbageCollected(new WebSocketWithMockChannel(context)); |
72 websocket->suspendIfNeeded(); | 72 websocket->suspendIfNeeded(); |
73 return websocket; | 73 return websocket.release(); |
74 } | 74 } |
75 | 75 |
76 MockWebSocketChannel* channel() { return m_channel.get(); } | 76 MockWebSocketChannel* channel() { return m_channel.get(); } |
77 | 77 |
78 virtual PassRefPtrWillBeRawPtr<WebSocketChannel> createChannel(ExecutionCont
ext*, WebSocketChannelClient*) OVERRIDE | 78 virtual PassRefPtrWillBeRawPtr<WebSocketChannel> createChannel(ExecutionCont
ext*, WebSocketChannelClient*) OVERRIDE |
79 { | 79 { |
80 ASSERT(!m_hasCreatedChannel); | 80 ASSERT(!m_hasCreatedChannel); |
81 m_hasCreatedChannel = true; | 81 m_hasCreatedChannel = true; |
82 return m_channel.get(); | 82 return m_channel.get(); |
83 } | 83 } |
84 | 84 |
85 virtual void trace(Visitor* visitor) OVERRIDE | 85 virtual void trace(Visitor* visitor) OVERRIDE |
86 { | 86 { |
87 visitor->trace(m_channel); | 87 visitor->trace(m_channel); |
88 WebSocket::trace(visitor); | 88 WebSocket::trace(visitor); |
89 } | 89 } |
90 | 90 |
91 private: | 91 private: |
92 WebSocketWithMockChannel(ExecutionContext* context) | 92 WebSocketWithMockChannel(ExecutionContext* context) |
93 : WebSocket(context), m_channel(MockWebSocketChannel::create()), m_hasCr
eatedChannel(false) { } | 93 : WebSocket(context) |
| 94 , m_channel(MockWebSocketChannel::create()) |
| 95 , m_hasCreatedChannel(false) { } |
94 | 96 |
95 RefPtrWillBeMember<MockWebSocketChannel> m_channel; | 97 RefPtrWillBeMember<MockWebSocketChannel> m_channel; |
96 bool m_hasCreatedChannel; | 98 bool m_hasCreatedChannel; |
97 }; | 99 }; |
98 | 100 |
99 class WebSocketTestBase { | 101 class WebSocketTestBase { |
100 public: | 102 public: |
101 WebSocketTestBase() | 103 WebSocketTestBase() |
102 : m_pageHolder(DummyPageHolder::create()) | 104 : m_pageHolder(DummyPageHolder::create()) |
103 , m_websocket(WebSocketWithMockChannel::create(&m_pageHolder->document()
)) | 105 , m_websocket(WebSocketWithMockChannel::create(&m_pageHolder->document()
)) |
104 , m_channel(m_websocket->channel()) | |
105 , m_executionScope(v8::Isolate::GetCurrent()) | 106 , m_executionScope(v8::Isolate::GetCurrent()) |
106 , m_exceptionState(ExceptionState::ConstructionContext, "property", "int
erface", m_executionScope.scriptState()->context()->Global(), m_executionScope.i
solate()) | 107 , m_exceptionState(ExceptionState::ConstructionContext, "property", "int
erface", m_executionScope.scriptState()->context()->Global(), m_executionScope.i
solate()) |
107 { | 108 { |
108 } | 109 } |
109 | 110 |
110 virtual ~WebSocketTestBase() | 111 virtual ~WebSocketTestBase() |
111 { | 112 { |
112 if (!m_websocket) | 113 if (!m_websocket) |
113 return; | 114 return; |
114 // These statements are needed to clear WebSocket::m_channel to | 115 // These statements are needed to clear WebSocket::m_channel to |
115 // avoid ASSERTION failure on ~WebSocket. | 116 // avoid ASSERTION failure on ~WebSocket. |
116 ASSERT(m_channel); | 117 ASSERT(m_websocket->channel()); |
117 ::testing::Mock::VerifyAndClear(m_channel.get()); | 118 ::testing::Mock::VerifyAndClear(m_websocket->channel()); |
118 EXPECT_CALL(*m_channel, disconnect()).Times(AnyNumber()); | 119 EXPECT_CALL(channel(), disconnect()).Times(AnyNumber()); |
119 | 120 |
120 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncompl
ete, 1006, ""); | 121 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncompl
ete, 1006, ""); |
| 122 m_websocket.clear(); |
| 123 Heap::collectAllGarbage(); |
121 } | 124 } |
122 | 125 |
| 126 MockWebSocketChannel& channel() { return *m_websocket->channel(); } |
| 127 |
123 OwnPtr<DummyPageHolder> m_pageHolder; | 128 OwnPtr<DummyPageHolder> m_pageHolder; |
124 RefPtrWillBePersistent<WebSocketWithMockChannel> m_websocket; | 129 RefPtrWillBePersistent<WebSocketWithMockChannel> m_websocket; |
125 RefPtrWillBePersistent<MockWebSocketChannel> m_channel; | |
126 V8TestingScope m_executionScope; | 130 V8TestingScope m_executionScope; |
127 ExceptionState m_exceptionState; | 131 ExceptionState m_exceptionState; |
128 }; | 132 }; |
129 | 133 |
130 class WebSocketTest : public WebSocketTestBase, public ::testing::Test { | 134 class WebSocketTest : public WebSocketTestBase, public ::testing::Test { |
131 public: | 135 public: |
132 }; | 136 }; |
133 | 137 |
134 TEST_F(WebSocketTest, connectToBadURL) | 138 TEST_F(WebSocketTest, connectToBadURL) |
135 { | 139 { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 | 181 |
178 // FIXME: Add a test for Content Security Policy. | 182 // FIXME: Add a test for Content Security Policy. |
179 | 183 |
180 TEST_F(WebSocketTest, invalidSubprotocols) | 184 TEST_F(WebSocketTest, invalidSubprotocols) |
181 { | 185 { |
182 Vector<String> subprotocols; | 186 Vector<String> subprotocols; |
183 subprotocols.append("@subprotocol-|'\"x\x01\x02\x03x"); | 187 subprotocols.append("@subprotocol-|'\"x\x01\x02\x03x"); |
184 | 188 |
185 { | 189 { |
186 InSequence s; | 190 InSequence s; |
187 EXPECT_CALL(*m_channel, disconnect()); | 191 EXPECT_CALL(channel(), disconnect()); |
188 } | 192 } |
189 | 193 |
190 m_websocket->connect("ws://example.com/", subprotocols, m_exceptionState); | 194 m_websocket->connect("ws://example.com/", subprotocols, m_exceptionState); |
191 | 195 |
192 EXPECT_TRUE(m_exceptionState.hadException()); | 196 EXPECT_TRUE(m_exceptionState.hadException()); |
193 EXPECT_EQ(SyntaxError, m_exceptionState.code()); | 197 EXPECT_EQ(SyntaxError, m_exceptionState.code()); |
194 EXPECT_EQ("The subprotocol '@subprotocol-|'\"x\\u0001\\u0002\\u0003x' is inv
alid.", m_exceptionState.message()); | 198 EXPECT_EQ("The subprotocol '@subprotocol-|'\"x\\u0001\\u0002\\u0003x' is inv
alid.", m_exceptionState.message()); |
195 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 199 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
196 } | 200 } |
197 | 201 |
198 TEST_F(WebSocketTest, channelConnectSuccess) | 202 TEST_F(WebSocketTest, channelConnectSuccess) |
199 { | 203 { |
200 Vector<String> subprotocols; | 204 Vector<String> subprotocols; |
201 subprotocols.append("aa"); | 205 subprotocols.append("aa"); |
202 subprotocols.append("bb"); | 206 subprotocols.append("bb"); |
203 | 207 |
204 { | 208 { |
205 InSequence s; | 209 InSequence s; |
206 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/hoge"), S
tring("aa, bb"))).WillOnce(Return(true)); | 210 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/hoge"), St
ring("aa, bb"))).WillOnce(Return(true)); |
207 } | 211 } |
208 | 212 |
209 m_websocket->connect("ws://example.com/hoge", Vector<String>(subprotocols),
m_exceptionState); | 213 m_websocket->connect("ws://example.com/hoge", Vector<String>(subprotocols),
m_exceptionState); |
210 | 214 |
211 | 215 |
212 EXPECT_FALSE(m_exceptionState.hadException()); | 216 EXPECT_FALSE(m_exceptionState.hadException()); |
213 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 217 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
214 EXPECT_EQ(KURL(KURL(), "ws://example.com/hoge"), m_websocket->url()); | 218 EXPECT_EQ(KURL(KURL(), "ws://example.com/hoge"), m_websocket->url()); |
215 } | 219 } |
216 | 220 |
217 TEST_F(WebSocketTest, channelConnectFail) | 221 TEST_F(WebSocketTest, channelConnectFail) |
218 { | 222 { |
219 Vector<String> subprotocols; | 223 Vector<String> subprotocols; |
220 subprotocols.append("aa"); | 224 subprotocols.append("aa"); |
221 subprotocols.append("bb"); | 225 subprotocols.append("bb"); |
222 | 226 |
223 { | 227 { |
224 InSequence s; | 228 InSequence s; |
225 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g("aa, bb"))).WillOnce(Return(false)); | 229 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
("aa, bb"))).WillOnce(Return(false)); |
226 EXPECT_CALL(*m_channel, disconnect()); | 230 EXPECT_CALL(channel(), disconnect()); |
227 } | 231 } |
228 | 232 |
229 m_websocket->connect("ws://example.com/", Vector<String>(subprotocols), m_ex
ceptionState); | 233 m_websocket->connect("ws://example.com/", Vector<String>(subprotocols), m_ex
ceptionState); |
230 | 234 |
231 | 235 |
232 EXPECT_TRUE(m_exceptionState.hadException()); | 236 EXPECT_TRUE(m_exceptionState.hadException()); |
233 EXPECT_EQ(SecurityError, m_exceptionState.code()); | 237 EXPECT_EQ(SecurityError, m_exceptionState.code()); |
234 EXPECT_EQ("An insecure WebSocket connection may not be initiated from a page
loaded over HTTPS.", m_exceptionState.message()); | 238 EXPECT_EQ("An insecure WebSocket connection may not be initiated from a page
loaded over HTTPS.", m_exceptionState.message()); |
235 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 239 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
236 } | 240 } |
(...skipping 22 matching lines...) Expand all Loading... |
259 } | 263 } |
260 } | 264 } |
261 | 265 |
262 TEST_F(WebSocketTest, connectSuccess) | 266 TEST_F(WebSocketTest, connectSuccess) |
263 { | 267 { |
264 Vector<String> subprotocols; | 268 Vector<String> subprotocols; |
265 subprotocols.append("aa"); | 269 subprotocols.append("aa"); |
266 subprotocols.append("bb"); | 270 subprotocols.append("bb"); |
267 { | 271 { |
268 InSequence s; | 272 InSequence s; |
269 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g("aa, bb"))).WillOnce(Return(true)); | 273 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
("aa, bb"))).WillOnce(Return(true)); |
270 EXPECT_CALL(*m_channel, subprotocol()).WillOnce(Return(String("bb"))); | 274 EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String("bb"))); |
271 EXPECT_CALL(*m_channel, extensions()).WillOnce(Return(String("cc"))); | 275 EXPECT_CALL(channel(), extensions()).WillOnce(Return(String("cc"))); |
272 } | 276 } |
273 m_websocket->connect("ws://example.com/", subprotocols, m_exceptionState); | 277 m_websocket->connect("ws://example.com/", subprotocols, m_exceptionState); |
274 | 278 |
275 EXPECT_FALSE(m_exceptionState.hadException()); | 279 EXPECT_FALSE(m_exceptionState.hadException()); |
276 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 280 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
277 | 281 |
278 m_websocket->didConnect(); | 282 m_websocket->didConnect(); |
279 | 283 |
280 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); | 284 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); |
281 EXPECT_EQ("bb", m_websocket->protocol()); | 285 EXPECT_EQ("bb", m_websocket->protocol()); |
282 EXPECT_EQ("cc", m_websocket->extensions()); | 286 EXPECT_EQ("cc", m_websocket->extensions()); |
283 } | 287 } |
284 | 288 |
285 TEST_F(WebSocketTest, didClose) | 289 TEST_F(WebSocketTest, didClose) |
286 { | 290 { |
287 { | 291 { |
288 InSequence s; | 292 InSequence s; |
289 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 293 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
290 EXPECT_CALL(*m_channel, disconnect()); | 294 EXPECT_CALL(channel(), disconnect()); |
291 } | 295 } |
292 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 296 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
293 | 297 |
294 EXPECT_FALSE(m_exceptionState.hadException()); | 298 EXPECT_FALSE(m_exceptionState.hadException()); |
295 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 299 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
296 | 300 |
297 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncomplete,
1006, ""); | 301 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncomplete,
1006, ""); |
298 | 302 |
299 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 303 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
300 } | 304 } |
301 | 305 |
302 TEST_F(WebSocketTest, maximumReasonSize) | 306 TEST_F(WebSocketTest, maximumReasonSize) |
303 { | 307 { |
304 { | 308 { |
305 InSequence s; | 309 InSequence s; |
306 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 310 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
307 EXPECT_CALL(*m_channel, fail(_, _, _, _)); | 311 EXPECT_CALL(channel(), fail(_, _, _, _)); |
308 } | 312 } |
309 String reason; | 313 String reason; |
310 for (size_t i = 0; i < 123; ++i) | 314 for (size_t i = 0; i < 123; ++i) |
311 reason.append("a"); | 315 reason.append("a"); |
312 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 316 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
313 | 317 |
314 EXPECT_FALSE(m_exceptionState.hadException()); | 318 EXPECT_FALSE(m_exceptionState.hadException()); |
315 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 319 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
316 | 320 |
317 m_websocket->close(1000, reason, m_exceptionState); | 321 m_websocket->close(1000, reason, m_exceptionState); |
318 | 322 |
319 EXPECT_FALSE(m_exceptionState.hadException()); | 323 EXPECT_FALSE(m_exceptionState.hadException()); |
320 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); | 324 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); |
321 } | 325 } |
322 | 326 |
323 TEST_F(WebSocketTest, reasonSizeExceeding) | 327 TEST_F(WebSocketTest, reasonSizeExceeding) |
324 { | 328 { |
325 { | 329 { |
326 InSequence s; | 330 InSequence s; |
327 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 331 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
328 } | 332 } |
329 String reason; | 333 String reason; |
330 for (size_t i = 0; i < 124; ++i) | 334 for (size_t i = 0; i < 124; ++i) |
331 reason.append("a"); | 335 reason.append("a"); |
332 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 336 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
333 | 337 |
334 EXPECT_FALSE(m_exceptionState.hadException()); | 338 EXPECT_FALSE(m_exceptionState.hadException()); |
335 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 339 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
336 | 340 |
337 m_websocket->close(1000, reason, m_exceptionState); | 341 m_websocket->close(1000, reason, m_exceptionState); |
338 | 342 |
339 EXPECT_TRUE(m_exceptionState.hadException()); | 343 EXPECT_TRUE(m_exceptionState.hadException()); |
340 EXPECT_EQ(SyntaxError, m_exceptionState.code()); | 344 EXPECT_EQ(SyntaxError, m_exceptionState.code()); |
341 EXPECT_EQ("The message must not be greater than 123 bytes.", m_exceptionStat
e.message()); | 345 EXPECT_EQ("The message must not be greater than 123 bytes.", m_exceptionStat
e.message()); |
342 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 346 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
343 } | 347 } |
344 | 348 |
345 TEST_F(WebSocketTest, closeWhenConnecting) | 349 TEST_F(WebSocketTest, closeWhenConnecting) |
346 { | 350 { |
347 { | 351 { |
348 InSequence s; | 352 InSequence s; |
349 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 353 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
350 EXPECT_CALL(*m_channel, fail(String("WebSocket is closed before the conn
ection is established."), WarningMessageLevel, String(), 0)); | 354 EXPECT_CALL(channel(), fail(String("WebSocket is closed before the conne
ction is established."), WarningMessageLevel, String(), 0)); |
351 } | 355 } |
352 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 356 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
353 | 357 |
354 EXPECT_FALSE(m_exceptionState.hadException()); | 358 EXPECT_FALSE(m_exceptionState.hadException()); |
355 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 359 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
356 | 360 |
357 m_websocket->close(1000, "bye", m_exceptionState); | 361 m_websocket->close(1000, "bye", m_exceptionState); |
358 | 362 |
359 EXPECT_FALSE(m_exceptionState.hadException()); | 363 EXPECT_FALSE(m_exceptionState.hadException()); |
360 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); | 364 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); |
361 } | 365 } |
362 | 366 |
363 TEST_F(WebSocketTest, close) | 367 TEST_F(WebSocketTest, close) |
364 { | 368 { |
365 { | 369 { |
366 InSequence s; | 370 InSequence s; |
367 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 371 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
368 EXPECT_CALL(*m_channel, subprotocol()).WillOnce(Return(String())); | 372 EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String())); |
369 EXPECT_CALL(*m_channel, extensions()).WillOnce(Return(String())); | 373 EXPECT_CALL(channel(), extensions()).WillOnce(Return(String())); |
370 EXPECT_CALL(*m_channel, close(3005, String("bye"))); | 374 EXPECT_CALL(channel(), close(3005, String("bye"))); |
371 } | 375 } |
372 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 376 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
373 | 377 |
374 EXPECT_FALSE(m_exceptionState.hadException()); | 378 EXPECT_FALSE(m_exceptionState.hadException()); |
375 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 379 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
376 | 380 |
377 m_websocket->didConnect(); | 381 m_websocket->didConnect(); |
378 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); | 382 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); |
379 m_websocket->close(3005, "bye", m_exceptionState); | 383 m_websocket->close(3005, "bye", m_exceptionState); |
380 | 384 |
381 EXPECT_FALSE(m_exceptionState.hadException()); | 385 EXPECT_FALSE(m_exceptionState.hadException()); |
382 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); | 386 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); |
383 } | 387 } |
384 | 388 |
385 TEST_F(WebSocketTest, closeWithoutReason) | 389 TEST_F(WebSocketTest, closeWithoutReason) |
386 { | 390 { |
387 { | 391 { |
388 InSequence s; | 392 InSequence s; |
389 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 393 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
390 EXPECT_CALL(*m_channel, subprotocol()).WillOnce(Return(String())); | 394 EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String())); |
391 EXPECT_CALL(*m_channel, extensions()).WillOnce(Return(String())); | 395 EXPECT_CALL(channel(), extensions()).WillOnce(Return(String())); |
392 EXPECT_CALL(*m_channel, close(3005, String())); | 396 EXPECT_CALL(channel(), close(3005, String())); |
393 } | 397 } |
394 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 398 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
395 | 399 |
396 EXPECT_FALSE(m_exceptionState.hadException()); | 400 EXPECT_FALSE(m_exceptionState.hadException()); |
397 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 401 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
398 | 402 |
399 m_websocket->didConnect(); | 403 m_websocket->didConnect(); |
400 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); | 404 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); |
401 m_websocket->close(3005, m_exceptionState); | 405 m_websocket->close(3005, m_exceptionState); |
402 | 406 |
403 EXPECT_FALSE(m_exceptionState.hadException()); | 407 EXPECT_FALSE(m_exceptionState.hadException()); |
404 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); | 408 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); |
405 } | 409 } |
406 | 410 |
407 TEST_F(WebSocketTest, closeWithoutCodeAndReason) | 411 TEST_F(WebSocketTest, closeWithoutCodeAndReason) |
408 { | 412 { |
409 { | 413 { |
410 InSequence s; | 414 InSequence s; |
411 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 415 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
412 EXPECT_CALL(*m_channel, subprotocol()).WillOnce(Return(String())); | 416 EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String())); |
413 EXPECT_CALL(*m_channel, extensions()).WillOnce(Return(String())); | 417 EXPECT_CALL(channel(), extensions()).WillOnce(Return(String())); |
414 EXPECT_CALL(*m_channel, close(-1, String())); | 418 EXPECT_CALL(channel(), close(-1, String())); |
415 } | 419 } |
416 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 420 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
417 | 421 |
418 EXPECT_FALSE(m_exceptionState.hadException()); | 422 EXPECT_FALSE(m_exceptionState.hadException()); |
419 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 423 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
420 | 424 |
421 m_websocket->didConnect(); | 425 m_websocket->didConnect(); |
422 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); | 426 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); |
423 m_websocket->close(m_exceptionState); | 427 m_websocket->close(m_exceptionState); |
424 | 428 |
425 EXPECT_FALSE(m_exceptionState.hadException()); | 429 EXPECT_FALSE(m_exceptionState.hadException()); |
426 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); | 430 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); |
427 } | 431 } |
428 | 432 |
429 TEST_F(WebSocketTest, closeWhenClosing) | 433 TEST_F(WebSocketTest, closeWhenClosing) |
430 { | 434 { |
431 { | 435 { |
432 InSequence s; | 436 InSequence s; |
433 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 437 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
434 EXPECT_CALL(*m_channel, subprotocol()).WillOnce(Return(String())); | 438 EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String())); |
435 EXPECT_CALL(*m_channel, extensions()).WillOnce(Return(String())); | 439 EXPECT_CALL(channel(), extensions()).WillOnce(Return(String())); |
436 EXPECT_CALL(*m_channel, close(-1, String())); | 440 EXPECT_CALL(channel(), close(-1, String())); |
437 } | 441 } |
438 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 442 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
439 | 443 |
440 EXPECT_FALSE(m_exceptionState.hadException()); | 444 EXPECT_FALSE(m_exceptionState.hadException()); |
441 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 445 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
442 | 446 |
443 m_websocket->didConnect(); | 447 m_websocket->didConnect(); |
444 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); | 448 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); |
445 m_websocket->close(m_exceptionState); | 449 m_websocket->close(m_exceptionState); |
446 EXPECT_FALSE(m_exceptionState.hadException()); | 450 EXPECT_FALSE(m_exceptionState.hadException()); |
447 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); | 451 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); |
448 | 452 |
449 m_websocket->close(m_exceptionState); | 453 m_websocket->close(m_exceptionState); |
450 | 454 |
451 EXPECT_FALSE(m_exceptionState.hadException()); | 455 EXPECT_FALSE(m_exceptionState.hadException()); |
452 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); | 456 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); |
453 } | 457 } |
454 | 458 |
455 TEST_F(WebSocketTest, closeWhenClosed) | 459 TEST_F(WebSocketTest, closeWhenClosed) |
456 { | 460 { |
457 { | 461 { |
458 InSequence s; | 462 InSequence s; |
459 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 463 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
460 EXPECT_CALL(*m_channel, subprotocol()).WillOnce(Return(String())); | 464 EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String())); |
461 EXPECT_CALL(*m_channel, extensions()).WillOnce(Return(String())); | 465 EXPECT_CALL(channel(), extensions()).WillOnce(Return(String())); |
462 EXPECT_CALL(*m_channel, close(-1, String())); | 466 EXPECT_CALL(channel(), close(-1, String())); |
463 EXPECT_CALL(*m_channel, disconnect()); | 467 EXPECT_CALL(channel(), disconnect()); |
464 } | 468 } |
465 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 469 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
466 | 470 |
467 EXPECT_FALSE(m_exceptionState.hadException()); | 471 EXPECT_FALSE(m_exceptionState.hadException()); |
468 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 472 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
469 | 473 |
470 m_websocket->didConnect(); | 474 m_websocket->didConnect(); |
471 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); | 475 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); |
472 m_websocket->close(m_exceptionState); | 476 m_websocket->close(m_exceptionState); |
473 EXPECT_FALSE(m_exceptionState.hadException()); | 477 EXPECT_FALSE(m_exceptionState.hadException()); |
474 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); | 478 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); |
475 | 479 |
476 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeComplete, 1
000, String()); | 480 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeComplete, 1
000, String()); |
477 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 481 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
478 m_websocket->close(m_exceptionState); | 482 m_websocket->close(m_exceptionState); |
479 | 483 |
480 EXPECT_FALSE(m_exceptionState.hadException()); | 484 EXPECT_FALSE(m_exceptionState.hadException()); |
481 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 485 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
482 } | 486 } |
483 | 487 |
484 TEST_F(WebSocketTest, sendStringWhenConnecting) | 488 TEST_F(WebSocketTest, sendStringWhenConnecting) |
485 { | 489 { |
486 { | 490 { |
487 InSequence s; | 491 InSequence s; |
488 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 492 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
489 } | 493 } |
490 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 494 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
491 | 495 |
492 EXPECT_FALSE(m_exceptionState.hadException()); | 496 EXPECT_FALSE(m_exceptionState.hadException()); |
493 | 497 |
494 m_websocket->send("hello", m_exceptionState); | 498 m_websocket->send("hello", m_exceptionState); |
495 | 499 |
496 EXPECT_TRUE(m_exceptionState.hadException()); | 500 EXPECT_TRUE(m_exceptionState.hadException()); |
497 EXPECT_EQ(InvalidStateError, m_exceptionState.code()); | 501 EXPECT_EQ(InvalidStateError, m_exceptionState.code()); |
498 EXPECT_EQ("Still in CONNECTING state.", m_exceptionState.message()); | 502 EXPECT_EQ("Still in CONNECTING state.", m_exceptionState.message()); |
499 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 503 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
500 } | 504 } |
501 | 505 |
502 TEST_F(WebSocketTest, sendStringWhenClosing) | 506 TEST_F(WebSocketTest, sendStringWhenClosing) |
503 { | 507 { |
504 Checkpoint checkpoint; | 508 Checkpoint checkpoint; |
505 { | 509 { |
506 InSequence s; | 510 InSequence s; |
507 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 511 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
508 EXPECT_CALL(*m_channel, fail(_, _, _, _)); | 512 EXPECT_CALL(channel(), fail(_, _, _, _)); |
509 } | 513 } |
510 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 514 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
511 | 515 |
512 EXPECT_FALSE(m_exceptionState.hadException()); | 516 EXPECT_FALSE(m_exceptionState.hadException()); |
513 | 517 |
514 m_websocket->close(m_exceptionState); | 518 m_websocket->close(m_exceptionState); |
515 EXPECT_FALSE(m_exceptionState.hadException()); | 519 EXPECT_FALSE(m_exceptionState.hadException()); |
516 | 520 |
517 m_websocket->send("hello", m_exceptionState); | 521 m_websocket->send("hello", m_exceptionState); |
518 | 522 |
519 EXPECT_FALSE(m_exceptionState.hadException()); | 523 EXPECT_FALSE(m_exceptionState.hadException()); |
520 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); | 524 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); |
521 } | 525 } |
522 | 526 |
523 TEST_F(WebSocketTest, sendStringWhenClosed) | 527 TEST_F(WebSocketTest, sendStringWhenClosed) |
524 { | 528 { |
525 Checkpoint checkpoint; | 529 Checkpoint checkpoint; |
526 { | 530 { |
527 InSequence s; | 531 InSequence s; |
528 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 532 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
529 EXPECT_CALL(*m_channel, disconnect()); | 533 EXPECT_CALL(channel(), disconnect()); |
530 EXPECT_CALL(checkpoint, Call(1)); | 534 EXPECT_CALL(checkpoint, Call(1)); |
531 } | 535 } |
532 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 536 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
533 | 537 |
534 EXPECT_FALSE(m_exceptionState.hadException()); | 538 EXPECT_FALSE(m_exceptionState.hadException()); |
535 | 539 |
536 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncomplete,
1006, ""); | 540 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncomplete,
1006, ""); |
537 checkpoint.Call(1); | 541 checkpoint.Call(1); |
538 | 542 |
539 m_websocket->send("hello", m_exceptionState); | 543 m_websocket->send("hello", m_exceptionState); |
540 | 544 |
541 EXPECT_FALSE(m_exceptionState.hadException()); | 545 EXPECT_FALSE(m_exceptionState.hadException()); |
542 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 546 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
543 } | 547 } |
544 | 548 |
545 TEST_F(WebSocketTest, sendStringSuccess) | 549 TEST_F(WebSocketTest, sendStringSuccess) |
546 { | 550 { |
547 { | 551 { |
548 InSequence s; | 552 InSequence s; |
549 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 553 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
550 EXPECT_CALL(*m_channel, subprotocol()).WillOnce(Return(String())); | 554 EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String())); |
551 EXPECT_CALL(*m_channel, extensions()).WillOnce(Return(String())); | 555 EXPECT_CALL(channel(), extensions()).WillOnce(Return(String())); |
552 EXPECT_CALL(*m_channel, send(String("hello"))).WillOnce(Return(WebSocket
Channel::SendSuccess)); | 556 EXPECT_CALL(channel(), send(String("hello"))).WillOnce(Return(WebSocketC
hannel::SendSuccess)); |
553 } | 557 } |
554 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 558 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
555 | 559 |
556 EXPECT_FALSE(m_exceptionState.hadException()); | 560 EXPECT_FALSE(m_exceptionState.hadException()); |
557 | 561 |
558 m_websocket->didConnect(); | 562 m_websocket->didConnect(); |
559 m_websocket->send("hello", m_exceptionState); | 563 m_websocket->send("hello", m_exceptionState); |
560 | 564 |
561 EXPECT_FALSE(m_exceptionState.hadException()); | 565 EXPECT_FALSE(m_exceptionState.hadException()); |
562 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); | 566 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); |
563 } | 567 } |
564 | 568 |
565 TEST_F(WebSocketTest, sendStringFail) | 569 TEST_F(WebSocketTest, sendStringFail) |
566 { | 570 { |
567 { | 571 { |
568 InSequence s; | 572 InSequence s; |
569 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 573 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
570 EXPECT_CALL(*m_channel, subprotocol()).WillOnce(Return(String())); | 574 EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String())); |
571 EXPECT_CALL(*m_channel, extensions()).WillOnce(Return(String())); | 575 EXPECT_CALL(channel(), extensions()).WillOnce(Return(String())); |
572 EXPECT_CALL(*m_channel, send(String("hello"))).WillOnce(Return(WebSocket
Channel::SendFail)); | 576 EXPECT_CALL(channel(), send(String("hello"))).WillOnce(Return(WebSocketC
hannel::SendFail)); |
573 } | 577 } |
574 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 578 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
575 | 579 |
576 EXPECT_FALSE(m_exceptionState.hadException()); | 580 EXPECT_FALSE(m_exceptionState.hadException()); |
577 | 581 |
578 m_websocket->didConnect(); | 582 m_websocket->didConnect(); |
579 m_websocket->send("hello", m_exceptionState); | 583 m_websocket->send("hello", m_exceptionState); |
580 | 584 |
581 EXPECT_FALSE(m_exceptionState.hadException()); | 585 EXPECT_FALSE(m_exceptionState.hadException()); |
582 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); | 586 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); |
583 } | 587 } |
584 | 588 |
585 TEST_F(WebSocketTest, sendStringInvalidMessage) | 589 TEST_F(WebSocketTest, sendStringInvalidMessage) |
586 { | 590 { |
587 { | 591 { |
588 InSequence s; | 592 InSequence s; |
589 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 593 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
590 EXPECT_CALL(*m_channel, subprotocol()).WillOnce(Return(String())); | 594 EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String())); |
591 EXPECT_CALL(*m_channel, extensions()).WillOnce(Return(String())); | 595 EXPECT_CALL(channel(), extensions()).WillOnce(Return(String())); |
592 EXPECT_CALL(*m_channel, send(String("hello"))).WillOnce(Return(WebSocket
Channel::InvalidMessage)); | 596 EXPECT_CALL(channel(), send(String("hello"))).WillOnce(Return(WebSocketC
hannel::InvalidMessage)); |
593 } | 597 } |
594 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 598 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
595 | 599 |
596 EXPECT_FALSE(m_exceptionState.hadException()); | 600 EXPECT_FALSE(m_exceptionState.hadException()); |
597 | 601 |
598 m_websocket->didConnect(); | 602 m_websocket->didConnect(); |
599 m_websocket->send("hello", m_exceptionState); | 603 m_websocket->send("hello", m_exceptionState); |
600 | 604 |
601 EXPECT_TRUE(m_exceptionState.hadException()); | 605 EXPECT_TRUE(m_exceptionState.hadException()); |
602 EXPECT_EQ(SyntaxError, m_exceptionState.code()); | 606 EXPECT_EQ(SyntaxError, m_exceptionState.code()); |
603 EXPECT_EQ("The message contains invalid characters.", m_exceptionState.messa
ge()); | 607 EXPECT_EQ("The message contains invalid characters.", m_exceptionState.messa
ge()); |
604 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); | 608 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); |
605 } | 609 } |
606 | 610 |
607 TEST_F(WebSocketTest, sendArrayBufferWhenConnecting) | 611 TEST_F(WebSocketTest, sendArrayBufferWhenConnecting) |
608 { | 612 { |
609 RefPtr<ArrayBufferView> view = Uint8Array::create(8); | 613 RefPtr<ArrayBufferView> view = Uint8Array::create(8); |
610 { | 614 { |
611 InSequence s; | 615 InSequence s; |
612 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 616 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
613 } | 617 } |
614 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 618 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
615 | 619 |
616 EXPECT_FALSE(m_exceptionState.hadException()); | 620 EXPECT_FALSE(m_exceptionState.hadException()); |
617 | 621 |
618 m_websocket->send(view->buffer().get(), m_exceptionState); | 622 m_websocket->send(view->buffer().get(), m_exceptionState); |
619 | 623 |
620 EXPECT_TRUE(m_exceptionState.hadException()); | 624 EXPECT_TRUE(m_exceptionState.hadException()); |
621 EXPECT_EQ(InvalidStateError, m_exceptionState.code()); | 625 EXPECT_EQ(InvalidStateError, m_exceptionState.code()); |
622 EXPECT_EQ("Still in CONNECTING state.", m_exceptionState.message()); | 626 EXPECT_EQ("Still in CONNECTING state.", m_exceptionState.message()); |
623 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 627 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
624 } | 628 } |
625 | 629 |
626 TEST_F(WebSocketTest, sendArrayBufferWhenClosing) | 630 TEST_F(WebSocketTest, sendArrayBufferWhenClosing) |
627 { | 631 { |
628 RefPtr<ArrayBufferView> view = Uint8Array::create(8); | 632 RefPtr<ArrayBufferView> view = Uint8Array::create(8); |
629 { | 633 { |
630 InSequence s; | 634 InSequence s; |
631 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 635 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
632 EXPECT_CALL(*m_channel, fail(_, _, _, _)); | 636 EXPECT_CALL(channel(), fail(_, _, _, _)); |
633 } | 637 } |
634 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 638 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
635 | 639 |
636 EXPECT_FALSE(m_exceptionState.hadException()); | 640 EXPECT_FALSE(m_exceptionState.hadException()); |
637 | 641 |
638 m_websocket->close(m_exceptionState); | 642 m_websocket->close(m_exceptionState); |
639 EXPECT_FALSE(m_exceptionState.hadException()); | 643 EXPECT_FALSE(m_exceptionState.hadException()); |
640 | 644 |
641 m_websocket->send(view->buffer().get(), m_exceptionState); | 645 m_websocket->send(view->buffer().get(), m_exceptionState); |
642 | 646 |
643 EXPECT_FALSE(m_exceptionState.hadException()); | 647 EXPECT_FALSE(m_exceptionState.hadException()); |
644 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); | 648 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); |
645 } | 649 } |
646 | 650 |
647 TEST_F(WebSocketTest, sendArrayBufferWhenClosed) | 651 TEST_F(WebSocketTest, sendArrayBufferWhenClosed) |
648 { | 652 { |
649 Checkpoint checkpoint; | 653 Checkpoint checkpoint; |
650 RefPtr<ArrayBufferView> view = Uint8Array::create(8); | 654 RefPtr<ArrayBufferView> view = Uint8Array::create(8); |
651 { | 655 { |
652 InSequence s; | 656 InSequence s; |
653 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 657 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
654 EXPECT_CALL(*m_channel, disconnect()); | 658 EXPECT_CALL(channel(), disconnect()); |
655 EXPECT_CALL(checkpoint, Call(1)); | 659 EXPECT_CALL(checkpoint, Call(1)); |
656 } | 660 } |
657 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 661 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
658 | 662 |
659 EXPECT_FALSE(m_exceptionState.hadException()); | 663 EXPECT_FALSE(m_exceptionState.hadException()); |
660 | 664 |
661 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncomplete,
1006, ""); | 665 m_websocket->didClose(0, WebSocketChannelClient::ClosingHandshakeIncomplete,
1006, ""); |
662 checkpoint.Call(1); | 666 checkpoint.Call(1); |
663 | 667 |
664 m_websocket->send(view->buffer().get(), m_exceptionState); | 668 m_websocket->send(view->buffer().get(), m_exceptionState); |
665 | 669 |
666 EXPECT_FALSE(m_exceptionState.hadException()); | 670 EXPECT_FALSE(m_exceptionState.hadException()); |
667 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); | 671 EXPECT_EQ(WebSocket::CLOSED, m_websocket->readyState()); |
668 } | 672 } |
669 | 673 |
670 TEST_F(WebSocketTest, sendArrayBufferSuccess) | 674 TEST_F(WebSocketTest, sendArrayBufferSuccess) |
671 { | 675 { |
672 RefPtr<ArrayBufferView> view = Uint8Array::create(8); | 676 RefPtr<ArrayBufferView> view = Uint8Array::create(8); |
673 { | 677 { |
674 InSequence s; | 678 InSequence s; |
675 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 679 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
676 EXPECT_CALL(*m_channel, subprotocol()).WillOnce(Return(String())); | 680 EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String())); |
677 EXPECT_CALL(*m_channel, extensions()).WillOnce(Return(String())); | 681 EXPECT_CALL(channel(), extensions()).WillOnce(Return(String())); |
678 EXPECT_CALL(*m_channel, send(Ref(*view->buffer()), 0, 8)).WillOnce(Retur
n(WebSocketChannel::SendSuccess)); | 682 EXPECT_CALL(channel(), send(Ref(*view->buffer()), 0, 8)).WillOnce(Return
(WebSocketChannel::SendSuccess)); |
679 } | 683 } |
680 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 684 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
681 | 685 |
682 EXPECT_FALSE(m_exceptionState.hadException()); | 686 EXPECT_FALSE(m_exceptionState.hadException()); |
683 | 687 |
684 m_websocket->didConnect(); | 688 m_websocket->didConnect(); |
685 m_websocket->send(view->buffer().get(), m_exceptionState); | 689 m_websocket->send(view->buffer().get(), m_exceptionState); |
686 | 690 |
687 EXPECT_FALSE(m_exceptionState.hadException()); | 691 EXPECT_FALSE(m_exceptionState.hadException()); |
688 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); | 692 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); |
689 } | 693 } |
690 | 694 |
691 TEST_F(WebSocketTest, sendArrayBufferFail) | 695 TEST_F(WebSocketTest, sendArrayBufferFail) |
692 { | 696 { |
693 RefPtr<ArrayBufferView> view = Uint8Array::create(8); | 697 RefPtr<ArrayBufferView> view = Uint8Array::create(8); |
694 { | 698 { |
695 InSequence s; | 699 InSequence s; |
696 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 700 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
697 EXPECT_CALL(*m_channel, subprotocol()).WillOnce(Return(String())); | 701 EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String())); |
698 EXPECT_CALL(*m_channel, extensions()).WillOnce(Return(String())); | 702 EXPECT_CALL(channel(), extensions()).WillOnce(Return(String())); |
699 EXPECT_CALL(*m_channel, send(Ref(*view->buffer()), 0, 8)).WillOnce(Retur
n(WebSocketChannel::SendFail)); | 703 EXPECT_CALL(channel(), send(Ref(*view->buffer()), 0, 8)).WillOnce(Return
(WebSocketChannel::SendFail)); |
700 } | 704 } |
701 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 705 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
702 | 706 |
703 EXPECT_FALSE(m_exceptionState.hadException()); | 707 EXPECT_FALSE(m_exceptionState.hadException()); |
704 | 708 |
705 m_websocket->didConnect(); | 709 m_websocket->didConnect(); |
706 m_websocket->send(view->buffer().get(), m_exceptionState); | 710 m_websocket->send(view->buffer().get(), m_exceptionState); |
707 | 711 |
708 EXPECT_FALSE(m_exceptionState.hadException()); | 712 EXPECT_FALSE(m_exceptionState.hadException()); |
709 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); | 713 EXPECT_EQ(WebSocket::OPEN, m_websocket->readyState()); |
710 } | 714 } |
711 | 715 |
712 TEST_F(WebSocketTest, sendArrayBufferInvalidMessage) | 716 TEST_F(WebSocketTest, sendArrayBufferInvalidMessage) |
713 { | 717 { |
714 RefPtr<ArrayBufferView> view = Uint8Array::create(8); | 718 RefPtr<ArrayBufferView> view = Uint8Array::create(8); |
715 { | 719 { |
716 InSequence s; | 720 InSequence s; |
717 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 721 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
718 EXPECT_CALL(*m_channel, subprotocol()).WillOnce(Return(String())); | 722 EXPECT_CALL(channel(), subprotocol()).WillOnce(Return(String())); |
719 EXPECT_CALL(*m_channel, extensions()).WillOnce(Return(String())); | 723 EXPECT_CALL(channel(), extensions()).WillOnce(Return(String())); |
720 EXPECT_CALL(*m_channel, send(Ref(*view->buffer()), 0, 8)).WillOnce(Retur
n(WebSocketChannel::InvalidMessage)); | 724 EXPECT_CALL(channel(), send(Ref(*view->buffer()), 0, 8)).WillOnce(Return
(WebSocketChannel::InvalidMessage)); |
721 } | 725 } |
722 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 726 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
723 | 727 |
724 EXPECT_FALSE(m_exceptionState.hadException()); | 728 EXPECT_FALSE(m_exceptionState.hadException()); |
725 | 729 |
726 m_websocket->didConnect(); | 730 m_websocket->didConnect(); |
727 m_websocket->send(view->buffer().get(), m_exceptionState); | 731 m_websocket->send(view->buffer().get(), m_exceptionState); |
728 | 732 |
729 EXPECT_TRUE(m_exceptionState.hadException()); | 733 EXPECT_TRUE(m_exceptionState.hadException()); |
730 EXPECT_EQ(SyntaxError, m_exceptionState.code()); | 734 EXPECT_EQ(SyntaxError, m_exceptionState.code()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 // FIXME: We should add tests for suspend / resume. | 767 // FIXME: We should add tests for suspend / resume. |
764 | 768 |
765 class WebSocketValidClosingCodeTest : public WebSocketTestBase, public ::testing
::TestWithParam<unsigned short> { | 769 class WebSocketValidClosingCodeTest : public WebSocketTestBase, public ::testing
::TestWithParam<unsigned short> { |
766 public: | 770 public: |
767 }; | 771 }; |
768 | 772 |
769 TEST_P(WebSocketValidClosingCodeTest, test) | 773 TEST_P(WebSocketValidClosingCodeTest, test) |
770 { | 774 { |
771 { | 775 { |
772 InSequence s; | 776 InSequence s; |
773 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 777 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
774 EXPECT_CALL(*m_channel, fail(_, _, _, _)); | 778 EXPECT_CALL(channel(), fail(_, _, _, _)); |
775 } | 779 } |
776 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 780 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
777 | 781 |
778 EXPECT_FALSE(m_exceptionState.hadException()); | 782 EXPECT_FALSE(m_exceptionState.hadException()); |
779 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 783 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
780 | 784 |
781 m_websocket->close(GetParam(), "bye", m_exceptionState); | 785 m_websocket->close(GetParam(), "bye", m_exceptionState); |
782 | 786 |
783 EXPECT_FALSE(m_exceptionState.hadException()); | 787 EXPECT_FALSE(m_exceptionState.hadException()); |
784 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); | 788 EXPECT_EQ(WebSocket::CLOSING, m_websocket->readyState()); |
785 } | 789 } |
786 | 790 |
787 INSTANTIATE_TEST_CASE_P(WebSocketValidClosingCode, WebSocketValidClosingCodeTest
, ::testing::Values(1000, 3000, 3001, 4998, 4999)); | 791 INSTANTIATE_TEST_CASE_P(WebSocketValidClosingCode, WebSocketValidClosingCodeTest
, ::testing::Values(1000, 3000, 3001, 4998, 4999)); |
788 | 792 |
789 class WebSocketInvalidClosingCodeTest : public WebSocketTestBase, public ::testi
ng::TestWithParam<unsigned short> { | 793 class WebSocketInvalidClosingCodeTest : public WebSocketTestBase, public ::testi
ng::TestWithParam<unsigned short> { |
790 public: | 794 public: |
791 }; | 795 }; |
792 | 796 |
793 TEST_P(WebSocketInvalidClosingCodeTest, test) | 797 TEST_P(WebSocketInvalidClosingCodeTest, test) |
794 { | 798 { |
795 { | 799 { |
796 InSequence s; | 800 InSequence s; |
797 EXPECT_CALL(*m_channel, connect(KURL(KURL(), "ws://example.com/"), Strin
g())).WillOnce(Return(true)); | 801 EXPECT_CALL(channel(), connect(KURL(KURL(), "ws://example.com/"), String
())).WillOnce(Return(true)); |
798 } | 802 } |
799 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); | 803 m_websocket->connect("ws://example.com/", Vector<String>(), m_exceptionState
); |
800 | 804 |
801 EXPECT_FALSE(m_exceptionState.hadException()); | 805 EXPECT_FALSE(m_exceptionState.hadException()); |
802 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 806 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
803 | 807 |
804 m_websocket->close(GetParam(), "bye", m_exceptionState); | 808 m_websocket->close(GetParam(), "bye", m_exceptionState); |
805 | 809 |
806 EXPECT_TRUE(m_exceptionState.hadException()); | 810 EXPECT_TRUE(m_exceptionState.hadException()); |
807 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); | 811 EXPECT_EQ(InvalidAccessError, m_exceptionState.code()); |
808 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and
4999. %d is neither.", GetParam()), m_exceptionState.message()); | 812 EXPECT_EQ(String::format("The code must be either 1000, or between 3000 and
4999. %d is neither.", GetParam()), m_exceptionState.message()); |
809 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); | 813 EXPECT_EQ(WebSocket::CONNECTING, m_websocket->readyState()); |
810 } | 814 } |
811 | 815 |
812 INSTANTIATE_TEST_CASE_P(WebSocketInvalidClosingCode, WebSocketInvalidClosingCode
Test, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); | 816 INSTANTIATE_TEST_CASE_P(WebSocketInvalidClosingCode, WebSocketInvalidClosingCode
Test, ::testing::Values(0, 1, 998, 999, 1001, 2999, 5000, 9999, 65535)); |
813 | 817 |
814 } // namespace | 818 } // namespace |
815 | 819 |
816 } // namespace WebCore | 820 } // namespace WebCore |
OLD | NEW |