| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
| 9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 10 #include "net/base/cookie_policy.h" | 10 #include "net/base/cookie_policy.h" |
| 11 #include "net/base/cookie_store.h" | 11 #include "net/base/cookie_store.h" |
| 12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 13 #include "net/base/sys_addrinfo.h" |
| 13 #include "net/socket_stream/socket_stream.h" | 14 #include "net/socket_stream/socket_stream.h" |
| 14 #include "net/url_request/url_request_context.h" | 15 #include "net/url_request/url_request_context.h" |
| 15 #include "net/websockets/websocket_job.h" | 16 #include "net/websockets/websocket_job.h" |
| 17 #include "net/websockets/websocket_throttle.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/platform_test.h" | 20 #include "testing/platform_test.h" |
| 19 | 21 |
| 20 namespace net { | 22 namespace net { |
| 21 | 23 |
| 22 class MockSocketStream : public SocketStream { | 24 class MockSocketStream : public SocketStream { |
| 23 public: | 25 public: |
| 24 MockSocketStream(const GURL& url, SocketStream::Delegate* delegate) | 26 MockSocketStream(const GURL& url, SocketStream::Delegate* delegate) |
| 25 : SocketStream(url, delegate) {} | 27 : SocketStream(url, delegate) {} |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 cookie_policy_ = NULL; | 201 cookie_policy_ = NULL; |
| 200 context_ = NULL; | 202 context_ = NULL; |
| 201 websocket_ = NULL; | 203 websocket_ = NULL; |
| 202 socket_ = NULL; | 204 socket_ = NULL; |
| 203 } | 205 } |
| 204 protected: | 206 protected: |
| 205 void InitWebSocketJob(const GURL& url, MockSocketStreamDelegate* delegate) { | 207 void InitWebSocketJob(const GURL& url, MockSocketStreamDelegate* delegate) { |
| 206 websocket_ = new WebSocketJob(delegate); | 208 websocket_ = new WebSocketJob(delegate); |
| 207 socket_ = new MockSocketStream(url, websocket_.get()); | 209 socket_ = new MockSocketStream(url, websocket_.get()); |
| 208 websocket_->InitSocketStream(socket_.get()); | 210 websocket_->InitSocketStream(socket_.get()); |
| 211 websocket_->set_context(context_.get()); |
| 209 websocket_->state_ = WebSocketJob::CONNECTING; | 212 websocket_->state_ = WebSocketJob::CONNECTING; |
| 210 websocket_->set_context(context_.get()); | 213 struct addrinfo addr; |
| 214 memset(&addr, 0, sizeof(struct addrinfo)); |
| 215 addr.ai_family = AF_INET; |
| 216 addr.ai_addrlen = sizeof(struct sockaddr_in); |
| 217 struct sockaddr_in sa_in; |
| 218 memset(&sa_in, 0, sizeof(struct sockaddr_in)); |
| 219 memcpy(&sa_in.sin_addr, "\x7f\0\0\1", 4); |
| 220 addr.ai_addr = reinterpret_cast<sockaddr*>(&sa_in); |
| 221 addr.ai_next = NULL; |
| 222 websocket_->addresses_.Copy(&addr, true); |
| 223 Singleton<WebSocketThrottle>::get()->PutInQueue(websocket_); |
| 211 } | 224 } |
| 212 WebSocketJob::State GetWebSocketJobState() { | 225 WebSocketJob::State GetWebSocketJobState() { |
| 213 return websocket_->state_; | 226 return websocket_->state_; |
| 214 } | 227 } |
| 215 void CloseWebSocketJob() { | 228 void CloseWebSocketJob() { |
| 216 if (websocket_->socket_) | 229 if (websocket_->socket_) { |
| 217 websocket_->socket_->DetachDelegate(); | 230 websocket_->socket_->DetachDelegate(); |
| 231 Singleton<WebSocketThrottle>::get()->RemoveFromQueue(websocket_); |
| 232 } |
| 218 websocket_->state_ = WebSocketJob::CLOSED; | 233 websocket_->state_ = WebSocketJob::CLOSED; |
| 219 websocket_->delegate_ = NULL; | 234 websocket_->delegate_ = NULL; |
| 220 websocket_->socket_ = NULL; | 235 websocket_->socket_ = NULL; |
| 221 } | 236 } |
| 222 | 237 |
| 223 scoped_refptr<MockCookieStore> cookie_store_; | 238 scoped_refptr<MockCookieStore> cookie_store_; |
| 224 scoped_refptr<MockCookiePolicy> cookie_policy_; | 239 scoped_refptr<MockCookiePolicy> cookie_policy_; |
| 225 scoped_refptr<MockURLRequestContext> context_; | 240 scoped_refptr<MockURLRequestContext> context_; |
| 226 scoped_refptr<WebSocketJob> websocket_; | 241 scoped_refptr<WebSocketJob> websocket_; |
| 227 scoped_refptr<MockSocketStream> socket_; | 242 scoped_refptr<MockSocketStream> socket_; |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 EXPECT_EQ(2U, cookie_store_->entries().size()); | 501 EXPECT_EQ(2U, cookie_store_->entries().size()); |
| 487 EXPECT_EQ(cookieUrl, cookie_store_->entries()[0].url); | 502 EXPECT_EQ(cookieUrl, cookie_store_->entries()[0].url); |
| 488 EXPECT_EQ("CR-test=1", cookie_store_->entries()[0].cookie_line); | 503 EXPECT_EQ("CR-test=1", cookie_store_->entries()[0].cookie_line); |
| 489 EXPECT_EQ(cookieUrl, cookie_store_->entries()[1].url); | 504 EXPECT_EQ(cookieUrl, cookie_store_->entries()[1].url); |
| 490 EXPECT_EQ("CR-test-httponly=1", cookie_store_->entries()[1].cookie_line); | 505 EXPECT_EQ("CR-test-httponly=1", cookie_store_->entries()[1].cookie_line); |
| 491 | 506 |
| 492 CloseWebSocketJob(); | 507 CloseWebSocketJob(); |
| 493 } | 508 } |
| 494 | 509 |
| 495 } // namespace net | 510 } // namespace net |
| OLD | NEW |