OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "net/websockets/websocket_channel.h" | 5 #include "net/websockets/websocket_channel.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <iostream> | 10 #include <iostream> |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 WebSocketMessageType, | 156 WebSocketMessageType, |
157 const std::vector<char>&)); // NOLINT | 157 const std::vector<char>&)); // NOLINT |
158 MOCK_METHOD1(OnFlowControl, ChannelState(int64)); // NOLINT | 158 MOCK_METHOD1(OnFlowControl, ChannelState(int64)); // NOLINT |
159 MOCK_METHOD0(OnClosingHandshake, ChannelState(void)); // NOLINT | 159 MOCK_METHOD0(OnClosingHandshake, ChannelState(void)); // NOLINT |
160 MOCK_METHOD1(OnFailChannel, ChannelState(const std::string&)); // NOLINT | 160 MOCK_METHOD1(OnFailChannel, ChannelState(const std::string&)); // NOLINT |
161 MOCK_METHOD3(OnDropChannel, | 161 MOCK_METHOD3(OnDropChannel, |
162 ChannelState(bool, uint16, const std::string&)); // NOLINT | 162 ChannelState(bool, uint16, const std::string&)); // NOLINT |
163 | 163 |
164 // We can't use GMock with scoped_ptr. | 164 // We can't use GMock with scoped_ptr. |
165 ChannelState OnStartOpeningHandshake( | 165 ChannelState OnStartOpeningHandshake( |
166 scoped_ptr<WebSocketHandshakeRequestInfo>) OVERRIDE { | 166 scoped_ptr<WebSocketHandshakeRequestInfo>) override { |
167 OnStartOpeningHandshakeCalled(); | 167 OnStartOpeningHandshakeCalled(); |
168 return CHANNEL_ALIVE; | 168 return CHANNEL_ALIVE; |
169 } | 169 } |
170 ChannelState OnFinishOpeningHandshake( | 170 ChannelState OnFinishOpeningHandshake( |
171 scoped_ptr<WebSocketHandshakeResponseInfo>) OVERRIDE { | 171 scoped_ptr<WebSocketHandshakeResponseInfo>) override { |
172 OnFinishOpeningHandshakeCalled(); | 172 OnFinishOpeningHandshakeCalled(); |
173 return CHANNEL_ALIVE; | 173 return CHANNEL_ALIVE; |
174 } | 174 } |
175 virtual ChannelState OnSSLCertificateError( | 175 virtual ChannelState OnSSLCertificateError( |
176 scoped_ptr<SSLErrorCallbacks> ssl_error_callbacks, | 176 scoped_ptr<SSLErrorCallbacks> ssl_error_callbacks, |
177 const GURL& url, | 177 const GURL& url, |
178 const SSLInfo& ssl_info, | 178 const SSLInfo& ssl_info, |
179 bool fatal) OVERRIDE { | 179 bool fatal) override { |
180 OnSSLCertificateErrorCalled( | 180 OnSSLCertificateErrorCalled( |
181 ssl_error_callbacks.get(), url, ssl_info, fatal); | 181 ssl_error_callbacks.get(), url, ssl_info, fatal); |
182 return CHANNEL_ALIVE; | 182 return CHANNEL_ALIVE; |
183 } | 183 } |
184 | 184 |
185 MOCK_METHOD0(OnStartOpeningHandshakeCalled, void()); // NOLINT | 185 MOCK_METHOD0(OnStartOpeningHandshakeCalled, void()); // NOLINT |
186 MOCK_METHOD0(OnFinishOpeningHandshakeCalled, void()); // NOLINT | 186 MOCK_METHOD0(OnFinishOpeningHandshakeCalled, void()); // NOLINT |
187 MOCK_METHOD4( | 187 MOCK_METHOD4( |
188 OnSSLCertificateErrorCalled, | 188 OnSSLCertificateErrorCalled, |
189 void(SSLErrorCallbacks*, const GURL&, const SSLInfo&, bool)); // NOLINT | 189 void(SSLErrorCallbacks*, const GURL&, const SSLInfo&, bool)); // NOLINT |
190 }; | 190 }; |
191 | 191 |
192 // This fake EventInterface is for tests which need a WebSocketEventInterface | 192 // This fake EventInterface is for tests which need a WebSocketEventInterface |
193 // implementation but are not verifying how it is used. | 193 // implementation but are not verifying how it is used. |
194 class FakeWebSocketEventInterface : public WebSocketEventInterface { | 194 class FakeWebSocketEventInterface : public WebSocketEventInterface { |
195 virtual ChannelState OnAddChannelResponse( | 195 virtual ChannelState OnAddChannelResponse( |
196 bool fail, | 196 bool fail, |
197 const std::string& selected_protocol, | 197 const std::string& selected_protocol, |
198 const std::string& extensions) OVERRIDE { | 198 const std::string& extensions) override { |
199 return fail ? CHANNEL_DELETED : CHANNEL_ALIVE; | 199 return fail ? CHANNEL_DELETED : CHANNEL_ALIVE; |
200 } | 200 } |
201 virtual ChannelState OnDataFrame(bool fin, | 201 virtual ChannelState OnDataFrame(bool fin, |
202 WebSocketMessageType type, | 202 WebSocketMessageType type, |
203 const std::vector<char>& data) OVERRIDE { | 203 const std::vector<char>& data) override { |
204 return CHANNEL_ALIVE; | 204 return CHANNEL_ALIVE; |
205 } | 205 } |
206 virtual ChannelState OnFlowControl(int64 quota) OVERRIDE { | 206 virtual ChannelState OnFlowControl(int64 quota) override { |
207 return CHANNEL_ALIVE; | 207 return CHANNEL_ALIVE; |
208 } | 208 } |
209 virtual ChannelState OnClosingHandshake() OVERRIDE { return CHANNEL_ALIVE; } | 209 virtual ChannelState OnClosingHandshake() override { return CHANNEL_ALIVE; } |
210 virtual ChannelState OnFailChannel(const std::string& message) OVERRIDE { | 210 virtual ChannelState OnFailChannel(const std::string& message) override { |
211 return CHANNEL_DELETED; | 211 return CHANNEL_DELETED; |
212 } | 212 } |
213 virtual ChannelState OnDropChannel(bool was_clean, | 213 virtual ChannelState OnDropChannel(bool was_clean, |
214 uint16 code, | 214 uint16 code, |
215 const std::string& reason) OVERRIDE { | 215 const std::string& reason) override { |
216 return CHANNEL_DELETED; | 216 return CHANNEL_DELETED; |
217 } | 217 } |
218 virtual ChannelState OnStartOpeningHandshake( | 218 virtual ChannelState OnStartOpeningHandshake( |
219 scoped_ptr<WebSocketHandshakeRequestInfo> request) OVERRIDE { | 219 scoped_ptr<WebSocketHandshakeRequestInfo> request) override { |
220 return CHANNEL_ALIVE; | 220 return CHANNEL_ALIVE; |
221 } | 221 } |
222 virtual ChannelState OnFinishOpeningHandshake( | 222 virtual ChannelState OnFinishOpeningHandshake( |
223 scoped_ptr<WebSocketHandshakeResponseInfo> response) OVERRIDE { | 223 scoped_ptr<WebSocketHandshakeResponseInfo> response) override { |
224 return CHANNEL_ALIVE; | 224 return CHANNEL_ALIVE; |
225 } | 225 } |
226 virtual ChannelState OnSSLCertificateError( | 226 virtual ChannelState OnSSLCertificateError( |
227 scoped_ptr<SSLErrorCallbacks> ssl_error_callbacks, | 227 scoped_ptr<SSLErrorCallbacks> ssl_error_callbacks, |
228 const GURL& url, | 228 const GURL& url, |
229 const SSLInfo& ssl_info, | 229 const SSLInfo& ssl_info, |
230 bool fatal) OVERRIDE { | 230 bool fatal) override { |
231 return CHANNEL_ALIVE; | 231 return CHANNEL_ALIVE; |
232 } | 232 } |
233 }; | 233 }; |
234 | 234 |
235 // This fake WebSocketStream is for tests that require a WebSocketStream but are | 235 // This fake WebSocketStream is for tests that require a WebSocketStream but are |
236 // not testing the way it is used. It has minimal functionality to return | 236 // not testing the way it is used. It has minimal functionality to return |
237 // the |protocol| and |extensions| that it was constructed with. | 237 // the |protocol| and |extensions| that it was constructed with. |
238 class FakeWebSocketStream : public WebSocketStream { | 238 class FakeWebSocketStream : public WebSocketStream { |
239 public: | 239 public: |
240 // Constructs with empty protocol and extensions. | 240 // Constructs with empty protocol and extensions. |
241 FakeWebSocketStream() {} | 241 FakeWebSocketStream() {} |
242 | 242 |
243 // Constructs with specified protocol and extensions. | 243 // Constructs with specified protocol and extensions. |
244 FakeWebSocketStream(const std::string& protocol, | 244 FakeWebSocketStream(const std::string& protocol, |
245 const std::string& extensions) | 245 const std::string& extensions) |
246 : protocol_(protocol), extensions_(extensions) {} | 246 : protocol_(protocol), extensions_(extensions) {} |
247 | 247 |
248 virtual int ReadFrames(ScopedVector<WebSocketFrame>* frames, | 248 virtual int ReadFrames(ScopedVector<WebSocketFrame>* frames, |
249 const CompletionCallback& callback) OVERRIDE { | 249 const CompletionCallback& callback) override { |
250 return ERR_IO_PENDING; | 250 return ERR_IO_PENDING; |
251 } | 251 } |
252 | 252 |
253 virtual int WriteFrames(ScopedVector<WebSocketFrame>* frames, | 253 virtual int WriteFrames(ScopedVector<WebSocketFrame>* frames, |
254 const CompletionCallback& callback) OVERRIDE { | 254 const CompletionCallback& callback) override { |
255 return ERR_IO_PENDING; | 255 return ERR_IO_PENDING; |
256 } | 256 } |
257 | 257 |
258 virtual void Close() OVERRIDE {} | 258 virtual void Close() override {} |
259 | 259 |
260 // Returns the string passed to the constructor. | 260 // Returns the string passed to the constructor. |
261 virtual std::string GetSubProtocol() const OVERRIDE { return protocol_; } | 261 virtual std::string GetSubProtocol() const override { return protocol_; } |
262 | 262 |
263 // Returns the string passed to the constructor. | 263 // Returns the string passed to the constructor. |
264 virtual std::string GetExtensions() const OVERRIDE { return extensions_; } | 264 virtual std::string GetExtensions() const override { return extensions_; } |
265 | 265 |
266 private: | 266 private: |
267 // The string to return from GetSubProtocol(). | 267 // The string to return from GetSubProtocol(). |
268 std::string protocol_; | 268 std::string protocol_; |
269 | 269 |
270 // The string to return from GetExtensions(). | 270 // The string to return from GetExtensions(). |
271 std::string extensions_; | 271 std::string extensions_; |
272 }; | 272 }; |
273 | 273 |
274 // To make the static initialisers easier to read, we use enums rather than | 274 // To make the static initialisers easier to read, we use enums rather than |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 responses_.push_back(new Response(async, error, frames.Pass())); | 486 responses_.push_back(new Response(async, error, frames.Pass())); |
487 } | 487 } |
488 | 488 |
489 // Prepares a fake error response (ie. there is no data). | 489 // Prepares a fake error response (ie. there is no data). |
490 void PrepareReadFramesError(IsSync async, int error) { | 490 void PrepareReadFramesError(IsSync async, int error) { |
491 responses_.push_back( | 491 responses_.push_back( |
492 new Response(async, error, ScopedVector<WebSocketFrame>())); | 492 new Response(async, error, ScopedVector<WebSocketFrame>())); |
493 } | 493 } |
494 | 494 |
495 virtual int ReadFrames(ScopedVector<WebSocketFrame>* frames, | 495 virtual int ReadFrames(ScopedVector<WebSocketFrame>* frames, |
496 const CompletionCallback& callback) OVERRIDE { | 496 const CompletionCallback& callback) override { |
497 CHECK(!read_frames_pending_); | 497 CHECK(!read_frames_pending_); |
498 if (index_ >= responses_.size()) | 498 if (index_ >= responses_.size()) |
499 return ERR_IO_PENDING; | 499 return ERR_IO_PENDING; |
500 if (responses_[index_]->async == ASYNC) { | 500 if (responses_[index_]->async == ASYNC) { |
501 read_frames_pending_ = true; | 501 read_frames_pending_ = true; |
502 base::MessageLoop::current()->PostTask( | 502 base::MessageLoop::current()->PostTask( |
503 FROM_HERE, | 503 FROM_HERE, |
504 base::Bind(&ReadableFakeWebSocketStream::DoCallback, | 504 base::Bind(&ReadableFakeWebSocketStream::DoCallback, |
505 base::Unretained(this), | 505 base::Unretained(this), |
506 frames, | 506 frames, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 // returned, ReadFrames() returns ERR_IO_PENDING but read_frames_pending_ is | 543 // returned, ReadFrames() returns ERR_IO_PENDING but read_frames_pending_ is |
544 // not set to true. | 544 // not set to true. |
545 bool read_frames_pending_; | 545 bool read_frames_pending_; |
546 }; | 546 }; |
547 | 547 |
548 // A FakeWebSocketStream where writes always complete successfully and | 548 // A FakeWebSocketStream where writes always complete successfully and |
549 // synchronously. | 549 // synchronously. |
550 class WriteableFakeWebSocketStream : public FakeWebSocketStream { | 550 class WriteableFakeWebSocketStream : public FakeWebSocketStream { |
551 public: | 551 public: |
552 virtual int WriteFrames(ScopedVector<WebSocketFrame>* frames, | 552 virtual int WriteFrames(ScopedVector<WebSocketFrame>* frames, |
553 const CompletionCallback& callback) OVERRIDE { | 553 const CompletionCallback& callback) override { |
554 return OK; | 554 return OK; |
555 } | 555 } |
556 }; | 556 }; |
557 | 557 |
558 // A FakeWebSocketStream where writes always fail. | 558 // A FakeWebSocketStream where writes always fail. |
559 class UnWriteableFakeWebSocketStream : public FakeWebSocketStream { | 559 class UnWriteableFakeWebSocketStream : public FakeWebSocketStream { |
560 public: | 560 public: |
561 virtual int WriteFrames(ScopedVector<WebSocketFrame>* frames, | 561 virtual int WriteFrames(ScopedVector<WebSocketFrame>* frames, |
562 const CompletionCallback& callback) OVERRIDE { | 562 const CompletionCallback& callback) override { |
563 return ERR_CONNECTION_RESET; | 563 return ERR_CONNECTION_RESET; |
564 } | 564 } |
565 }; | 565 }; |
566 | 566 |
567 // A FakeWebSocketStream which echoes any frames written back. Clears the | 567 // A FakeWebSocketStream which echoes any frames written back. Clears the |
568 // "masked" header bit, but makes no other checks for validity. Tests using this | 568 // "masked" header bit, but makes no other checks for validity. Tests using this |
569 // must run the MessageLoop to receive the callback(s). If a message with opcode | 569 // must run the MessageLoop to receive the callback(s). If a message with opcode |
570 // Close is echoed, then an ERR_CONNECTION_CLOSED is returned in the next | 570 // Close is echoed, then an ERR_CONNECTION_CLOSED is returned in the next |
571 // callback. The test must do something to cause WriteFrames() to be called, | 571 // callback. The test must do something to cause WriteFrames() to be called, |
572 // otherwise the ReadFrames() callback will never be called. | 572 // otherwise the ReadFrames() callback will never be called. |
573 class EchoeyFakeWebSocketStream : public FakeWebSocketStream { | 573 class EchoeyFakeWebSocketStream : public FakeWebSocketStream { |
574 public: | 574 public: |
575 EchoeyFakeWebSocketStream() : read_frames_(NULL), done_(false) {} | 575 EchoeyFakeWebSocketStream() : read_frames_(NULL), done_(false) {} |
576 | 576 |
577 virtual int WriteFrames(ScopedVector<WebSocketFrame>* frames, | 577 virtual int WriteFrames(ScopedVector<WebSocketFrame>* frames, |
578 const CompletionCallback& callback) OVERRIDE { | 578 const CompletionCallback& callback) override { |
579 // Users of WebSocketStream will not expect the ReadFrames() callback to be | 579 // Users of WebSocketStream will not expect the ReadFrames() callback to be |
580 // called from within WriteFrames(), so post it to the message loop instead. | 580 // called from within WriteFrames(), so post it to the message loop instead. |
581 stored_frames_.insert(stored_frames_.end(), frames->begin(), frames->end()); | 581 stored_frames_.insert(stored_frames_.end(), frames->begin(), frames->end()); |
582 frames->weak_clear(); | 582 frames->weak_clear(); |
583 PostCallback(); | 583 PostCallback(); |
584 return OK; | 584 return OK; |
585 } | 585 } |
586 | 586 |
587 virtual int ReadFrames(ScopedVector<WebSocketFrame>* frames, | 587 virtual int ReadFrames(ScopedVector<WebSocketFrame>* frames, |
588 const CompletionCallback& callback) OVERRIDE { | 588 const CompletionCallback& callback) override { |
589 read_callback_ = callback; | 589 read_callback_ = callback; |
590 read_frames_ = frames; | 590 read_frames_ = frames; |
591 if (done_) | 591 if (done_) |
592 PostCallback(); | 592 PostCallback(); |
593 return ERR_IO_PENDING; | 593 return ERR_IO_PENDING; |
594 } | 594 } |
595 | 595 |
596 private: | 596 private: |
597 void PostCallback() { | 597 void PostCallback() { |
598 base::MessageLoop::current()->PostTask( | 598 base::MessageLoop::current()->PostTask( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 // and triggers ReadFrames to return a reset as well. Tests using this need to | 641 // and triggers ReadFrames to return a reset as well. Tests using this need to |
642 // run the message loop. There are two tricky parts here: | 642 // run the message loop. There are two tricky parts here: |
643 // 1. Calling the write callback may call Close(), after which the read callback | 643 // 1. Calling the write callback may call Close(), after which the read callback |
644 // should not be called. | 644 // should not be called. |
645 // 2. Calling either callback may delete the stream altogether. | 645 // 2. Calling either callback may delete the stream altogether. |
646 class ResetOnWriteFakeWebSocketStream : public FakeWebSocketStream { | 646 class ResetOnWriteFakeWebSocketStream : public FakeWebSocketStream { |
647 public: | 647 public: |
648 ResetOnWriteFakeWebSocketStream() : closed_(false), weak_ptr_factory_(this) {} | 648 ResetOnWriteFakeWebSocketStream() : closed_(false), weak_ptr_factory_(this) {} |
649 | 649 |
650 virtual int WriteFrames(ScopedVector<WebSocketFrame>* frames, | 650 virtual int WriteFrames(ScopedVector<WebSocketFrame>* frames, |
651 const CompletionCallback& callback) OVERRIDE { | 651 const CompletionCallback& callback) override { |
652 base::MessageLoop::current()->PostTask( | 652 base::MessageLoop::current()->PostTask( |
653 FROM_HERE, | 653 FROM_HERE, |
654 base::Bind(&ResetOnWriteFakeWebSocketStream::CallCallbackUnlessClosed, | 654 base::Bind(&ResetOnWriteFakeWebSocketStream::CallCallbackUnlessClosed, |
655 weak_ptr_factory_.GetWeakPtr(), | 655 weak_ptr_factory_.GetWeakPtr(), |
656 callback, | 656 callback, |
657 ERR_CONNECTION_RESET)); | 657 ERR_CONNECTION_RESET)); |
658 base::MessageLoop::current()->PostTask( | 658 base::MessageLoop::current()->PostTask( |
659 FROM_HERE, | 659 FROM_HERE, |
660 base::Bind(&ResetOnWriteFakeWebSocketStream::CallCallbackUnlessClosed, | 660 base::Bind(&ResetOnWriteFakeWebSocketStream::CallCallbackUnlessClosed, |
661 weak_ptr_factory_.GetWeakPtr(), | 661 weak_ptr_factory_.GetWeakPtr(), |
662 read_callback_, | 662 read_callback_, |
663 ERR_CONNECTION_RESET)); | 663 ERR_CONNECTION_RESET)); |
664 return ERR_IO_PENDING; | 664 return ERR_IO_PENDING; |
665 } | 665 } |
666 | 666 |
667 virtual int ReadFrames(ScopedVector<WebSocketFrame>* frames, | 667 virtual int ReadFrames(ScopedVector<WebSocketFrame>* frames, |
668 const CompletionCallback& callback) OVERRIDE { | 668 const CompletionCallback& callback) override { |
669 read_callback_ = callback; | 669 read_callback_ = callback; |
670 return ERR_IO_PENDING; | 670 return ERR_IO_PENDING; |
671 } | 671 } |
672 | 672 |
673 virtual void Close() OVERRIDE { closed_ = true; } | 673 virtual void Close() override { closed_ = true; } |
674 | 674 |
675 private: | 675 private: |
676 void CallCallbackUnlessClosed(const CompletionCallback& callback, int value) { | 676 void CallCallbackUnlessClosed(const CompletionCallback& callback, int value) { |
677 if (!closed_) | 677 if (!closed_) |
678 callback.Run(value); | 678 callback.Run(value); |
679 } | 679 } |
680 | 680 |
681 CompletionCallback read_callback_; | 681 CompletionCallback read_callback_; |
682 bool closed_; | 682 bool closed_; |
683 // An IO error can result in the socket being deleted, so we use weak pointers | 683 // An IO error can result in the socket being deleted, so we use weak pointers |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 // Converts a std::string to a std::vector<char>. For test purposes, it is | 729 // Converts a std::string to a std::vector<char>. For test purposes, it is |
730 // convenient to be able to specify data as a string, but the | 730 // convenient to be able to specify data as a string, but the |
731 // WebSocketEventInterface requires the vector<char> type. | 731 // WebSocketEventInterface requires the vector<char> type. |
732 std::vector<char> AsVector(const std::string& s) { | 732 std::vector<char> AsVector(const std::string& s) { |
733 return std::vector<char>(s.begin(), s.end()); | 733 return std::vector<char>(s.begin(), s.end()); |
734 } | 734 } |
735 | 735 |
736 class FakeSSLErrorCallbacks | 736 class FakeSSLErrorCallbacks |
737 : public WebSocketEventInterface::SSLErrorCallbacks { | 737 : public WebSocketEventInterface::SSLErrorCallbacks { |
738 public: | 738 public: |
739 virtual void CancelSSLRequest(int error, const SSLInfo* ssl_info) OVERRIDE {} | 739 virtual void CancelSSLRequest(int error, const SSLInfo* ssl_info) override {} |
740 virtual void ContinueSSLRequest() OVERRIDE {} | 740 virtual void ContinueSSLRequest() override {} |
741 }; | 741 }; |
742 | 742 |
743 // Base class for all test fixtures. | 743 // Base class for all test fixtures. |
744 class WebSocketChannelTest : public ::testing::Test { | 744 class WebSocketChannelTest : public ::testing::Test { |
745 protected: | 745 protected: |
746 WebSocketChannelTest() : stream_(new FakeWebSocketStream) {} | 746 WebSocketChannelTest() : stream_(new FakeWebSocketStream) {} |
747 | 747 |
748 // Creates a new WebSocketChannel and connects it, using the settings stored | 748 // Creates a new WebSocketChannel and connects it, using the settings stored |
749 // in |connect_data_|. | 749 // in |connect_data_|. |
750 void CreateChannelAndConnect() { | 750 void CreateChannelAndConnect() { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 : deleting_(EVENT_ON_ADD_CHANNEL_RESPONSE | EVENT_ON_DATA_FRAME | | 843 : deleting_(EVENT_ON_ADD_CHANNEL_RESPONSE | EVENT_ON_DATA_FRAME | |
844 EVENT_ON_FLOW_CONTROL | | 844 EVENT_ON_FLOW_CONTROL | |
845 EVENT_ON_CLOSING_HANDSHAKE | | 845 EVENT_ON_CLOSING_HANDSHAKE | |
846 EVENT_ON_FAIL_CHANNEL | | 846 EVENT_ON_FAIL_CHANNEL | |
847 EVENT_ON_DROP_CHANNEL | | 847 EVENT_ON_DROP_CHANNEL | |
848 EVENT_ON_START_OPENING_HANDSHAKE | | 848 EVENT_ON_START_OPENING_HANDSHAKE | |
849 EVENT_ON_FINISH_OPENING_HANDSHAKE | | 849 EVENT_ON_FINISH_OPENING_HANDSHAKE | |
850 EVENT_ON_SSL_CERTIFICATE_ERROR) {} | 850 EVENT_ON_SSL_CERTIFICATE_ERROR) {} |
851 // Create a ChannelDeletingFakeWebSocketEventInterface. Defined out-of-line to | 851 // Create a ChannelDeletingFakeWebSocketEventInterface. Defined out-of-line to |
852 // avoid circular dependency. | 852 // avoid circular dependency. |
853 virtual scoped_ptr<WebSocketEventInterface> CreateEventInterface() OVERRIDE; | 853 virtual scoped_ptr<WebSocketEventInterface> CreateEventInterface() override; |
854 | 854 |
855 // Tests can set deleting_ to a bitmap of EventInterfaceCall members that they | 855 // Tests can set deleting_ to a bitmap of EventInterfaceCall members that they |
856 // want to cause Channel deletion. The default is for all calls to cause | 856 // want to cause Channel deletion. The default is for all calls to cause |
857 // deletion. | 857 // deletion. |
858 int deleting_; | 858 int deleting_; |
859 }; | 859 }; |
860 | 860 |
861 // A FakeWebSocketEventInterface that deletes the WebSocketChannel on failure to | 861 // A FakeWebSocketEventInterface that deletes the WebSocketChannel on failure to |
862 // connect. | 862 // connect. |
863 class ChannelDeletingFakeWebSocketEventInterface | 863 class ChannelDeletingFakeWebSocketEventInterface |
864 : public FakeWebSocketEventInterface { | 864 : public FakeWebSocketEventInterface { |
865 public: | 865 public: |
866 ChannelDeletingFakeWebSocketEventInterface( | 866 ChannelDeletingFakeWebSocketEventInterface( |
867 WebSocketChannelDeletingTest* fixture) | 867 WebSocketChannelDeletingTest* fixture) |
868 : fixture_(fixture) {} | 868 : fixture_(fixture) {} |
869 | 869 |
870 virtual ChannelState OnAddChannelResponse( | 870 virtual ChannelState OnAddChannelResponse( |
871 bool fail, | 871 bool fail, |
872 const std::string& selected_protocol, | 872 const std::string& selected_protocol, |
873 const std::string& extensions) OVERRIDE { | 873 const std::string& extensions) override { |
874 return fixture_->DeleteIfDeleting(EVENT_ON_ADD_CHANNEL_RESPONSE); | 874 return fixture_->DeleteIfDeleting(EVENT_ON_ADD_CHANNEL_RESPONSE); |
875 } | 875 } |
876 | 876 |
877 virtual ChannelState OnDataFrame(bool fin, | 877 virtual ChannelState OnDataFrame(bool fin, |
878 WebSocketMessageType type, | 878 WebSocketMessageType type, |
879 const std::vector<char>& data) OVERRIDE { | 879 const std::vector<char>& data) override { |
880 return fixture_->DeleteIfDeleting(EVENT_ON_DATA_FRAME); | 880 return fixture_->DeleteIfDeleting(EVENT_ON_DATA_FRAME); |
881 } | 881 } |
882 | 882 |
883 virtual ChannelState OnFlowControl(int64 quota) OVERRIDE { | 883 virtual ChannelState OnFlowControl(int64 quota) override { |
884 return fixture_->DeleteIfDeleting(EVENT_ON_FLOW_CONTROL); | 884 return fixture_->DeleteIfDeleting(EVENT_ON_FLOW_CONTROL); |
885 } | 885 } |
886 | 886 |
887 virtual ChannelState OnClosingHandshake() OVERRIDE { | 887 virtual ChannelState OnClosingHandshake() override { |
888 return fixture_->DeleteIfDeleting(EVENT_ON_CLOSING_HANDSHAKE); | 888 return fixture_->DeleteIfDeleting(EVENT_ON_CLOSING_HANDSHAKE); |
889 } | 889 } |
890 | 890 |
891 virtual ChannelState OnFailChannel(const std::string& message) OVERRIDE { | 891 virtual ChannelState OnFailChannel(const std::string& message) override { |
892 return fixture_->DeleteIfDeleting(EVENT_ON_FAIL_CHANNEL); | 892 return fixture_->DeleteIfDeleting(EVENT_ON_FAIL_CHANNEL); |
893 } | 893 } |
894 | 894 |
895 virtual ChannelState OnDropChannel(bool was_clean, | 895 virtual ChannelState OnDropChannel(bool was_clean, |
896 uint16 code, | 896 uint16 code, |
897 const std::string& reason) OVERRIDE { | 897 const std::string& reason) override { |
898 return fixture_->DeleteIfDeleting(EVENT_ON_DROP_CHANNEL); | 898 return fixture_->DeleteIfDeleting(EVENT_ON_DROP_CHANNEL); |
899 } | 899 } |
900 | 900 |
901 virtual ChannelState OnStartOpeningHandshake( | 901 virtual ChannelState OnStartOpeningHandshake( |
902 scoped_ptr<WebSocketHandshakeRequestInfo> request) OVERRIDE { | 902 scoped_ptr<WebSocketHandshakeRequestInfo> request) override { |
903 return fixture_->DeleteIfDeleting(EVENT_ON_START_OPENING_HANDSHAKE); | 903 return fixture_->DeleteIfDeleting(EVENT_ON_START_OPENING_HANDSHAKE); |
904 } | 904 } |
905 virtual ChannelState OnFinishOpeningHandshake( | 905 virtual ChannelState OnFinishOpeningHandshake( |
906 scoped_ptr<WebSocketHandshakeResponseInfo> response) OVERRIDE { | 906 scoped_ptr<WebSocketHandshakeResponseInfo> response) override { |
907 return fixture_->DeleteIfDeleting(EVENT_ON_FINISH_OPENING_HANDSHAKE); | 907 return fixture_->DeleteIfDeleting(EVENT_ON_FINISH_OPENING_HANDSHAKE); |
908 } | 908 } |
909 virtual ChannelState OnSSLCertificateError( | 909 virtual ChannelState OnSSLCertificateError( |
910 scoped_ptr<SSLErrorCallbacks> ssl_error_callbacks, | 910 scoped_ptr<SSLErrorCallbacks> ssl_error_callbacks, |
911 const GURL& url, | 911 const GURL& url, |
912 const SSLInfo& ssl_info, | 912 const SSLInfo& ssl_info, |
913 bool fatal) OVERRIDE { | 913 bool fatal) override { |
914 return fixture_->DeleteIfDeleting(EVENT_ON_SSL_CERTIFICATE_ERROR); | 914 return fixture_->DeleteIfDeleting(EVENT_ON_SSL_CERTIFICATE_ERROR); |
915 } | 915 } |
916 | 916 |
917 private: | 917 private: |
918 // A pointer to the test fixture. Owned by the test harness; this object will | 918 // A pointer to the test fixture. Owned by the test harness; this object will |
919 // be deleted before it is. | 919 // be deleted before it is. |
920 WebSocketChannelDeletingTest* fixture_; | 920 WebSocketChannelDeletingTest* fixture_; |
921 }; | 921 }; |
922 | 922 |
923 scoped_ptr<WebSocketEventInterface> | 923 scoped_ptr<WebSocketEventInterface> |
(...skipping 18 matching lines...) Expand all Loading... |
942 } | 942 } |
943 | 943 |
944 virtual ~WebSocketChannelEventInterfaceTest() { | 944 virtual ~WebSocketChannelEventInterfaceTest() { |
945 DefaultValue<ChannelState>::Clear(); | 945 DefaultValue<ChannelState>::Clear(); |
946 } | 946 } |
947 | 947 |
948 // Tests using this fixture must set expectations on the event_interface_ mock | 948 // Tests using this fixture must set expectations on the event_interface_ mock |
949 // object before calling CreateChannelAndConnect() or | 949 // object before calling CreateChannelAndConnect() or |
950 // CreateChannelAndConnectSuccessfully(). This will only work once per test | 950 // CreateChannelAndConnectSuccessfully(). This will only work once per test |
951 // case, but once should be enough. | 951 // case, but once should be enough. |
952 virtual scoped_ptr<WebSocketEventInterface> CreateEventInterface() OVERRIDE { | 952 virtual scoped_ptr<WebSocketEventInterface> CreateEventInterface() override { |
953 return scoped_ptr<WebSocketEventInterface>(event_interface_.release()); | 953 return scoped_ptr<WebSocketEventInterface>(event_interface_.release()); |
954 } | 954 } |
955 | 955 |
956 scoped_ptr<MockWebSocketEventInterface> event_interface_; | 956 scoped_ptr<MockWebSocketEventInterface> event_interface_; |
957 }; | 957 }; |
958 | 958 |
959 // Base class for tests which verify that WebSocketStream methods are called | 959 // Base class for tests which verify that WebSocketStream methods are called |
960 // appropriately by using a MockWebSocketStream. | 960 // appropriately by using a MockWebSocketStream. |
961 class WebSocketChannelStreamTest : public WebSocketChannelTest { | 961 class WebSocketChannelStreamTest : public WebSocketChannelTest { |
962 protected: | 962 protected: |
963 WebSocketChannelStreamTest() | 963 WebSocketChannelStreamTest() |
964 : mock_stream_(new StrictMock<MockWebSocketStream>) {} | 964 : mock_stream_(new StrictMock<MockWebSocketStream>) {} |
965 | 965 |
966 virtual void CreateChannelAndConnectSuccessfully() OVERRIDE { | 966 virtual void CreateChannelAndConnectSuccessfully() override { |
967 set_stream(mock_stream_.Pass()); | 967 set_stream(mock_stream_.Pass()); |
968 WebSocketChannelTest::CreateChannelAndConnectSuccessfully(); | 968 WebSocketChannelTest::CreateChannelAndConnectSuccessfully(); |
969 } | 969 } |
970 | 970 |
971 scoped_ptr<MockWebSocketStream> mock_stream_; | 971 scoped_ptr<MockWebSocketStream> mock_stream_; |
972 }; | 972 }; |
973 | 973 |
974 // Fixture for tests which test UTF-8 validation of sent Text frames via the | 974 // Fixture for tests which test UTF-8 validation of sent Text frames via the |
975 // EventInterface. | 975 // EventInterface. |
976 class WebSocketChannelSendUtf8Test | 976 class WebSocketChannelSendUtf8Test |
(...skipping 2333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3310 EXPECT_CALL(*mock_stream_, Close()); | 3310 EXPECT_CALL(*mock_stream_, Close()); |
3311 | 3311 |
3312 CreateChannelAndConnectSuccessfully(); | 3312 CreateChannelAndConnectSuccessfully(); |
3313 } | 3313 } |
3314 | 3314 |
3315 // Set the closing handshake timeout to a very tiny value before connecting. | 3315 // Set the closing handshake timeout to a very tiny value before connecting. |
3316 class WebSocketChannelStreamTimeoutTest : public WebSocketChannelStreamTest { | 3316 class WebSocketChannelStreamTimeoutTest : public WebSocketChannelStreamTest { |
3317 protected: | 3317 protected: |
3318 WebSocketChannelStreamTimeoutTest() {} | 3318 WebSocketChannelStreamTimeoutTest() {} |
3319 | 3319 |
3320 virtual void CreateChannelAndConnectSuccessfully() OVERRIDE { | 3320 virtual void CreateChannelAndConnectSuccessfully() override { |
3321 set_stream(mock_stream_.Pass()); | 3321 set_stream(mock_stream_.Pass()); |
3322 CreateChannelAndConnect(); | 3322 CreateChannelAndConnect(); |
3323 channel_->SendFlowControl(kPlentyOfQuota); | 3323 channel_->SendFlowControl(kPlentyOfQuota); |
3324 channel_->SetClosingHandshakeTimeoutForTesting( | 3324 channel_->SetClosingHandshakeTimeoutForTesting( |
3325 TimeDelta::FromMilliseconds(kVeryTinyTimeoutMillis)); | 3325 TimeDelta::FromMilliseconds(kVeryTinyTimeoutMillis)); |
3326 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); | 3326 connect_data_.creator.connect_delegate->OnSuccess(stream_.Pass()); |
3327 } | 3327 } |
3328 }; | 3328 }; |
3329 | 3329 |
3330 // In this case the server initiates the closing handshake with a Close | 3330 // In this case the server initiates the closing handshake with a Close |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3428 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); | 3428 channel_->StartClosingHandshake(kWebSocketNormalClosure, "OK"); |
3429 ASSERT_TRUE(read_frames); | 3429 ASSERT_TRUE(read_frames); |
3430 // Provide the "Close" message from the server. | 3430 // Provide the "Close" message from the server. |
3431 *read_frames = CreateFrameVector(frames); | 3431 *read_frames = CreateFrameVector(frames); |
3432 read_callback.Run(OK); | 3432 read_callback.Run(OK); |
3433 completion.WaitForResult(); | 3433 completion.WaitForResult(); |
3434 } | 3434 } |
3435 | 3435 |
3436 } // namespace | 3436 } // namespace |
3437 } // namespace net | 3437 } // namespace net |
OLD | NEW |