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

Unified Diff: net/websockets/websocket_job_test.cc

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: net/websockets/websocket_job_test.cc
diff --git a/net/websockets/websocket_job_test.cc b/net/websockets/websocket_job_test.cc
index 22fd6e732ada9a9b7833ecd9596c8184f41d9e73..e8db1ffc8fd4cbfdafdcb15ae1d03240e7418112 100644
--- a/net/websockets/websocket_job_test.cc
+++ b/net/websockets/websocket_job_test.cc
@@ -41,8 +41,10 @@ namespace {
class MockSocketStream : public SocketStream {
public:
- MockSocketStream(const GURL& url, SocketStream::Delegate* delegate,
- URLRequestContext* context, CookieStore* cookie_store)
+ MockSocketStream(const GURL& url,
+ SocketStream::Delegate* delegate,
+ URLRequestContext* context,
+ CookieStore* cookie_store)
: SocketStream(url, delegate, context, cookie_store) {}
virtual void Connect() OVERRIDE {}
@@ -52,17 +54,11 @@ class MockSocketStream : public SocketStream {
}
virtual void Close() OVERRIDE {}
- virtual void RestartWithAuth(
- const AuthCredentials& credentials) OVERRIDE {
- }
+ virtual void RestartWithAuth(const AuthCredentials& credentials) OVERRIDE {}
- virtual void DetachDelegate() OVERRIDE {
- delegate_ = NULL;
- }
+ virtual void DetachDelegate() OVERRIDE { delegate_ = NULL; }
- const std::string& sent_data() const {
- return sent_data_;
- }
+ const std::string& sent_data() const { return sent_data_; }
protected:
virtual ~MockSocketStream() {}
@@ -73,8 +69,7 @@ class MockSocketStream : public SocketStream {
class MockSocketStreamDelegate : public SocketStream::Delegate {
public:
- MockSocketStreamDelegate()
- : amount_sent_(0), allow_all_cookies_(true) {}
+ MockSocketStreamDelegate() : amount_sent_(0), allow_all_cookies_(true) {}
void set_allow_all_cookies(bool allow_all_cookies) {
allow_all_cookies_ = allow_all_cookies;
}
@@ -92,9 +87,7 @@ class MockSocketStreamDelegate : public SocketStream::Delegate {
void SetOnReceivedData(const base::Closure& callback) {
on_received_data_ = callback;
}
- void SetOnClose(const base::Closure& callback) {
- on_close_ = callback;
- }
+ void SetOnClose(const base::Closure& callback) { on_close_ = callback; }
virtual int OnStartOpenConnection(
SocketStream* socket,
@@ -108,14 +101,14 @@ class MockSocketStreamDelegate : public SocketStream::Delegate {
if (!on_connected_.is_null())
on_connected_.Run();
}
- virtual void OnSentData(SocketStream* socket,
- int amount_sent) OVERRIDE {
+ virtual void OnSentData(SocketStream* socket, int amount_sent) OVERRIDE {
amount_sent_ += amount_sent;
if (!on_sent_data_.is_null())
on_sent_data_.Run();
}
virtual void OnReceivedData(SocketStream* socket,
- const char* data, int len) OVERRIDE {
+ const char* data,
+ int len) OVERRIDE {
received_data_ += std::string(data, len);
if (!on_received_data_.is_null())
on_received_data_.Run();
@@ -124,8 +117,7 @@ class MockSocketStreamDelegate : public SocketStream::Delegate {
if (!on_close_.is_null())
on_close_.Run();
}
- virtual bool CanGetCookies(SocketStream* socket,
- const GURL& url) OVERRIDE {
+ virtual bool CanGetCookies(SocketStream* socket, const GURL& url) OVERRIDE {
return allow_all_cookies_;
}
virtual bool CanSetCookie(SocketStream* request,
@@ -262,8 +254,8 @@ class MockURLRequestContext : public URLRequestContext {
set_transport_security_state(&transport_security_state_);
base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000);
bool include_subdomains = false;
- transport_security_state_.AddHSTS("upgrademe.com", expiry,
- include_subdomains);
+ transport_security_state_.AddHSTS(
+ "upgrademe.com", expiry, include_subdomains);
}
virtual ~MockURLRequestContext() {}
@@ -284,16 +276,14 @@ class MockHttpTransactionFactory : public HttpTransactionFactory {
SpdySessionDependencies::SpdyCreateSession(session_deps_.get());
host_port_pair_.set_host("example.com");
host_port_pair_.set_port(80);
- spdy_session_key_ = SpdySessionKey(host_port_pair_,
- ProxyServer::Direct(),
- PRIVACY_MODE_DISABLED);
+ spdy_session_key_ = SpdySessionKey(
+ host_port_pair_, ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
session_ = CreateInsecureSpdySession(
http_session_, spdy_session_key_, BoundNetLog());
}
- virtual int CreateTransaction(
- RequestPriority priority,
- scoped_ptr<HttpTransaction>* trans) OVERRIDE {
+ virtual int CreateTransaction(RequestPriority priority,
+ scoped_ptr<HttpTransaction>* trans) OVERRIDE {
NOTREACHED();
return ERR_UNEXPECTED;
}
@@ -318,8 +308,7 @@ class MockHttpTransactionFactory : public HttpTransactionFactory {
class DeletingSocketStreamDelegate : public SocketStream::Delegate {
public:
- DeletingSocketStreamDelegate()
- : delete_next_(false) {}
+ DeletingSocketStreamDelegate() : delete_next_(false) {}
// Since this class needs to be able to delete |job_|, it must be the only
// reference holder (except for temporary references). Provide access to the
@@ -410,12 +399,9 @@ class WebSocketJobTest : public PlatformTest,
if (received_data().size() == kHandshakeResponseWithoutCookieLength)
websocket_->SendData(kDataHello, kDataHelloLength);
}
- void DoSync() {
- sync_test_callback_.callback().Run(OK);
- }
- int WaitForResult() {
- return sync_test_callback_.WaitForResult();
- }
+ void DoSync() { sync_test_callback_.callback().Run(OK); }
+ int WaitForResult() { return sync_test_callback_.WaitForResult(); }
+
protected:
enum StreamType {
STREAM_INVALID,
@@ -439,8 +425,8 @@ class WebSocketJobTest : public PlatformTest,
websocket_ = new WebSocketJob(delegate);
if (stream_type == STREAM_MOCK_SOCKET)
- socket_ = new MockSocketStream(url, websocket_.get(), context_.get(),
- NULL);
+ socket_ =
+ new MockSocketStream(url, websocket_.get(), context_.get(), NULL);
if (stream_type == STREAM_SOCKET || stream_type == STREAM_SPDY_WEBSOCKET) {
if (stream_type == STREAM_SPDY_WEBSOCKET) {
@@ -476,9 +462,7 @@ class WebSocketJobTest : public PlatformTest,
websocket_->state_ = WebSocketJob::CONNECTING;
ASSERT_TRUE(WebSocketThrottle::GetInstance()->PutInQueue(websocket_.get()));
}
- WebSocketJob::State GetWebSocketJobState() {
- return websocket_->state_;
- }
+ WebSocketJob::State GetWebSocketJobState() { return websocket_->state_; }
void CloseWebSocketJob() {
if (websocket_->socket_.get()) {
websocket_->socket_->DetachDelegate();
@@ -488,13 +472,10 @@ class WebSocketJobTest : public PlatformTest,
websocket_->delegate_ = NULL;
websocket_->socket_ = NULL;
}
- SocketStream* GetSocket(SocketStreamJob* job) {
- return job->socket_.get();
- }
+ SocketStream* GetSocket(SocketStreamJob* job) { return job->socket_.get(); }
const std::string& sent_data() const {
DCHECK_EQ(STREAM_MOCK_SOCKET, stream_type_);
- MockSocketStream* socket =
- static_cast<MockSocketStream*>(socket_.get());
+ MockSocketStream* socket = static_cast<MockSocketStream*>(socket_.get());
DCHECK(socket);
return socket->sent_data();
}
@@ -642,10 +623,8 @@ const size_t WebSocketJobTest::kHandshakeResponseWithoutCookieLength =
arraysize(kHandshakeResponseWithoutCookie) - 1;
const size_t WebSocketJobTest::kHandshakeResponseWithCookieLength =
arraysize(kHandshakeResponseWithCookie) - 1;
-const size_t WebSocketJobTest::kDataHelloLength =
- arraysize(kDataHello) - 1;
-const size_t WebSocketJobTest::kDataWorldLength =
- arraysize(kDataWorld) - 1;
+const size_t WebSocketJobTest::kDataHelloLength = arraysize(kDataHello) - 1;
+const size_t WebSocketJobTest::kDataWorldLength = arraysize(kDataWorld) - 1;
void WebSocketJobTest::TestSimpleHandshake() {
GURL url("ws://example.com/demo");
@@ -657,8 +636,7 @@ void WebSocketJobTest::TestSimpleHandshake() {
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(kHandshakeRequestWithoutCookie, sent_data());
EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
- websocket_->OnSentData(socket_.get(),
- kHandshakeRequestWithoutCookieLength);
+ websocket_->OnSentData(socket_.get(), kHandshakeRequestWithoutCookieLength);
EXPECT_EQ(kHandshakeRequestWithoutCookieLength, delegate.amount_sent());
websocket_->OnReceivedData(socket_.get(),
@@ -682,8 +660,7 @@ void WebSocketJobTest::TestSlowHandshake() {
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(kHandshakeRequestWithoutCookie, sent_data());
EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
- websocket_->OnSentData(socket_.get(),
- kHandshakeRequestWithoutCookieLength);
+ websocket_->OnSentData(socket_.get(), kHandshakeRequestWithoutCookieLength);
EXPECT_EQ(kHandshakeRequestWithoutCookieLength, delegate.amount_sent());
std::vector<std::string> lines;
@@ -704,11 +681,12 @@ void WebSocketJobTest::TestSlowHandshake() {
CloseWebSocketJob();
}
-INSTANTIATE_TEST_CASE_P(
- NextProto,
- WebSocketJobTest,
- testing::Values(kProtoDeprecatedSPDY2,
- kProtoSPDY3, kProtoSPDY31, kProtoSPDY4));
+INSTANTIATE_TEST_CASE_P(NextProto,
+ WebSocketJobTest,
+ testing::Values(kProtoDeprecatedSPDY2,
+ kProtoSPDY3,
+ kProtoSPDY31,
+ kProtoSPDY4));
TEST_P(WebSocketJobTest, DelayedCookies) {
WebSocketJob::set_websocket_over_spdy_enabled(true);
@@ -722,9 +700,10 @@ TEST_P(WebSocketJobTest, DelayedCookies) {
cookie_options,
CookieMonster::SetCookiesCallback());
cookie_options.set_include_httponly();
- cookie_store->SetCookieWithOptionsAsync(
- cookieUrl, "CR-test-httponly=1", cookie_options,
- CookieMonster::SetCookiesCallback());
+ cookie_store->SetCookieWithOptionsAsync(cookieUrl,
+ "CR-test-httponly=1",
+ cookie_options,
+ CookieMonster::SetCookiesCallback());
MockSocketStreamDelegate delegate;
InitWebSocketJob(url, &delegate, STREAM_MOCK_SOCKET);
@@ -738,8 +717,7 @@ TEST_P(WebSocketJobTest, DelayedCookies) {
EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
websocket_->OnSentData(socket_.get(),
kHandshakeRequestWithFilteredCookieLength);
- EXPECT_EQ(kHandshakeRequestWithCookieLength,
- delegate.amount_sent());
+ EXPECT_EQ(kHandshakeRequestWithCookieLength, delegate.amount_sent());
websocket_->OnReceivedData(socket_.get(),
kHandshakeResponseWithCookie,
@@ -755,8 +733,7 @@ void WebSocketJobTest::TestHandshakeWithCookie() {
GURL url("ws://example.com/demo");
GURL cookieUrl("http://example.com/demo");
CookieOptions cookie_options;
- cookie_store_->SetCookieWithOptions(
- cookieUrl, "CR-test=1", cookie_options);
+ cookie_store_->SetCookieWithOptions(cookieUrl, "CR-test=1", cookie_options);
cookie_options.set_include_httponly();
cookie_store_->SetCookieWithOptions(
cookieUrl, "CR-test-httponly=1", cookie_options);
@@ -773,8 +750,7 @@ void WebSocketJobTest::TestHandshakeWithCookie() {
EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
websocket_->OnSentData(socket_.get(),
kHandshakeRequestWithFilteredCookieLength);
- EXPECT_EQ(kHandshakeRequestWithCookieLength,
- delegate.amount_sent());
+ EXPECT_EQ(kHandshakeRequestWithCookieLength, delegate.amount_sent());
websocket_->OnReceivedData(socket_.get(),
kHandshakeResponseWithCookie,
@@ -798,8 +774,7 @@ void WebSocketJobTest::TestHandshakeWithCookieButNotAllowed() {
GURL url("ws://example.com/demo");
GURL cookieUrl("http://example.com/demo");
CookieOptions cookie_options;
- cookie_store_->SetCookieWithOptions(
- cookieUrl, "CR-test=1", cookie_options);
+ cookie_store_->SetCookieWithOptions(cookieUrl, "CR-test=1", cookie_options);
cookie_options.set_include_httponly();
cookie_store_->SetCookieWithOptions(
cookieUrl, "CR-test-httponly=1", cookie_options);
@@ -837,17 +812,24 @@ void WebSocketJobTest::TestHandshakeWithCookieButNotAllowed() {
void WebSocketJobTest::TestHSTSUpgrade() {
GURL url("ws://upgrademe.com/");
MockSocketStreamDelegate delegate;
- scoped_refptr<SocketStreamJob> job =
- SocketStreamJob::CreateSocketStreamJob(
- url, &delegate, context_->transport_security_state(),
- context_->ssl_config_service(), NULL, NULL);
+ scoped_refptr<SocketStreamJob> job = SocketStreamJob::CreateSocketStreamJob(
+ url,
+ &delegate,
+ context_->transport_security_state(),
+ context_->ssl_config_service(),
+ NULL,
+ NULL);
EXPECT_TRUE(GetSocket(job.get())->is_secure());
job->DetachDelegate();
url = GURL("ws://donotupgrademe.com/");
job = SocketStreamJob::CreateSocketStreamJob(
- url, &delegate, context_->transport_security_state(),
- context_->ssl_config_service(), NULL, NULL);
+ url,
+ &delegate,
+ context_->transport_security_state(),
+ context_->ssl_config_service(),
+ NULL,
+ NULL);
EXPECT_FALSE(GetSocket(job.get())->is_secure());
job->DetachDelegate();
}
@@ -864,8 +846,7 @@ void WebSocketJobTest::TestInvalidSendData() {
base::MessageLoop::current()->RunUntilIdle();
EXPECT_EQ(kHandshakeRequestWithoutCookie, sent_data());
EXPECT_EQ(WebSocketJob::CONNECTING, GetWebSocketJobState());
- websocket_->OnSentData(socket_.get(),
- kHandshakeRequestWithoutCookieLength);
+ websocket_->OnSentData(socket_.get(), kHandshakeRequestWithoutCookieLength);
EXPECT_EQ(kHandshakeRequestWithoutCookieLength, delegate.amount_sent());
// We could not send any data until connection is established.
@@ -883,32 +864,23 @@ void WebSocketJobTest::TestInvalidSendData() {
// packets in comparison with the MockWrite array and emulating in-coming
// packets with MockRead array.
-void WebSocketJobTest::TestConnectByWebSocket(
- ThrottlingOption throttling) {
+void WebSocketJobTest::TestConnectByWebSocket(ThrottlingOption throttling) {
// This is a test for verifying cooperation between WebSocketJob and
// SocketStream. If |throttling| was |THROTTLING_OFF|, it test basic
// situation. If |throttling| was |THROTTLING_ON|, throttling limits the
// latter connection.
- MockWrite writes[] = {
- MockWrite(ASYNC,
- kHandshakeRequestWithoutCookie,
- kHandshakeRequestWithoutCookieLength,
- 1),
- MockWrite(ASYNC,
- kDataHello,
- kDataHelloLength,
- 3)
- };
+ MockWrite writes[] = {MockWrite(ASYNC,
+ kHandshakeRequestWithoutCookie,
+ kHandshakeRequestWithoutCookieLength,
+ 1),
+ MockWrite(ASYNC, kDataHello, kDataHelloLength, 3)};
MockRead reads[] = {
- MockRead(ASYNC,
- kHandshakeResponseWithoutCookie,
- kHandshakeResponseWithoutCookieLength,
- 2),
- MockRead(ASYNC,
- kDataWorld,
- kDataWorldLength,
- 4),
- MockRead(SYNCHRONOUS, 0, 5) // EOF
+ MockRead(ASYNC,
+ kHandshakeResponseWithoutCookie,
+ kHandshakeResponseWithoutCookieLength,
+ 2),
+ MockRead(ASYNC, kDataWorld, kDataWorldLength, 4),
+ MockRead(SYNCHRONOUS, 0, 5) // EOF
};
data_.reset(new OrderedSocketData(
reads, arraysize(reads), writes, arraysize(writes)));
@@ -920,8 +892,7 @@ void WebSocketJobTest::TestConnectByWebSocket(
delegate.SetOnStartOpenConnection(
base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test)));
delegate.SetOnConnected(
- base::Bind(&WebSocketJobTest::DoSendRequest,
- base::Unretained(test)));
+ base::Bind(&WebSocketJobTest::DoSendRequest, base::Unretained(test)));
delegate.SetOnReceivedData(
base::Bind(&WebSocketJobTest::DoSendData, base::Unretained(test)));
delegate.SetOnClose(
@@ -956,33 +927,26 @@ void WebSocketJobTest::TestConnectByWebSocket(
EXPECT_EQ(WebSocketJob::CLOSED, GetWebSocketJobState());
}
-void WebSocketJobTest::TestConnectBySpdy(
- SpdyOption spdy, ThrottlingOption throttling) {
+void WebSocketJobTest::TestConnectBySpdy(SpdyOption spdy,
+ ThrottlingOption throttling) {
// This is a test for verifying cooperation between WebSocketJob and
// SocketStream in the situation we have SPDY session to the server. If
// |throttling| was |THROTTLING_ON|, throttling limits the latter connection.
// If you enabled spdy, you should specify |spdy| as |SPDY_ON|. Expected
// results depend on its configuration.
MockWrite writes_websocket[] = {
- MockWrite(ASYNC,
- kHandshakeRequestWithoutCookie,
- kHandshakeRequestWithoutCookieLength,
- 1),
- MockWrite(ASYNC,
- kDataHello,
- kDataHelloLength,
- 3)
- };
+ MockWrite(ASYNC,
+ kHandshakeRequestWithoutCookie,
+ kHandshakeRequestWithoutCookieLength,
+ 1),
+ MockWrite(ASYNC, kDataHello, kDataHelloLength, 3)};
MockRead reads_websocket[] = {
- MockRead(ASYNC,
- kHandshakeResponseWithoutCookie,
- kHandshakeResponseWithoutCookieLength,
- 2),
- MockRead(ASYNC,
- kDataWorld,
- kDataWorldLength,
- 4),
- MockRead(SYNCHRONOUS, 0, 5) // EOF
+ MockRead(ASYNC,
+ kHandshakeResponseWithoutCookie,
+ kHandshakeResponseWithoutCookieLength,
+ 2),
+ MockRead(ASYNC, kDataWorld, kDataWorldLength, 4),
+ MockRead(SYNCHRONOUS, 0, 5) // EOF
};
scoped_ptr<SpdyHeaderBlock> request_headers(new SpdyHeaderBlock());
@@ -991,56 +955,48 @@ void WebSocketJobTest::TestConnectBySpdy(
spdy_util_.SetHeader("scheme", "ws", request_headers.get());
spdy_util_.SetHeader("host", "example.com", request_headers.get());
spdy_util_.SetHeader("origin", "http://example.com", request_headers.get());
- spdy_util_.SetHeader("sec-websocket-protocol", "sample",
- request_headers.get());
+ spdy_util_.SetHeader(
+ "sec-websocket-protocol", "sample", request_headers.get());
scoped_ptr<SpdyHeaderBlock> response_headers(new SpdyHeaderBlock());
- spdy_util_.SetHeader("status", "101 Switching Protocols",
- response_headers.get());
- spdy_util_.SetHeader("sec-websocket-protocol", "sample",
- response_headers.get());
+ spdy_util_.SetHeader(
+ "status", "101 Switching Protocols", response_headers.get());
+ spdy_util_.SetHeader(
+ "sec-websocket-protocol", "sample", response_headers.get());
const SpdyStreamId kStreamId = 1;
scoped_ptr<SpdyFrame> request_frame(
spdy_util_.ConstructSpdyWebSocketHandshakeRequestFrame(
- request_headers.Pass(),
- kStreamId,
- MEDIUM));
+ request_headers.Pass(), kStreamId, MEDIUM));
scoped_ptr<SpdyFrame> response_frame(
spdy_util_.ConstructSpdyWebSocketHandshakeResponseFrame(
- response_headers.Pass(),
- kStreamId,
- MEDIUM));
+ response_headers.Pass(), kStreamId, MEDIUM));
scoped_ptr<SpdyFrame> data_hello_frame(
spdy_util_.ConstructSpdyWebSocketDataFrame(
- kDataHello,
- kDataHelloLength,
- kStreamId,
- false));
+ kDataHello, kDataHelloLength, kStreamId, false));
scoped_ptr<SpdyFrame> data_world_frame(
spdy_util_.ConstructSpdyWebSocketDataFrame(
- kDataWorld,
- kDataWorldLength,
- kStreamId,
- false));
+ kDataWorld, kDataWorldLength, kStreamId, false));
MockWrite writes_spdy[] = {
- CreateMockWrite(*request_frame.get(), 1),
- CreateMockWrite(*data_hello_frame.get(), 3),
+ CreateMockWrite(*request_frame.get(), 1),
+ CreateMockWrite(*data_hello_frame.get(), 3),
};
MockRead reads_spdy[] = {
- CreateMockRead(*response_frame.get(), 2),
- CreateMockRead(*data_world_frame.get(), 4),
- MockRead(SYNCHRONOUS, 0, 5) // EOF
+ CreateMockRead(*response_frame.get(), 2),
+ CreateMockRead(*data_world_frame.get(), 4),
+ MockRead(SYNCHRONOUS, 0, 5) // EOF
};
if (spdy == SPDY_ON)
- data_.reset(new OrderedSocketData(
- reads_spdy, arraysize(reads_spdy),
- writes_spdy, arraysize(writes_spdy)));
+ data_.reset(new OrderedSocketData(reads_spdy,
+ arraysize(reads_spdy),
+ writes_spdy,
+ arraysize(writes_spdy)));
else
- data_.reset(new OrderedSocketData(
- reads_websocket, arraysize(reads_websocket),
- writes_websocket, arraysize(writes_websocket)));
+ data_.reset(new OrderedSocketData(reads_websocket,
+ arraysize(reads_websocket),
+ writes_websocket,
+ arraysize(writes_websocket)));
GURL url("ws://example.com/demo");
MockSocketStreamDelegate delegate;
@@ -1049,8 +1005,7 @@ void WebSocketJobTest::TestConnectBySpdy(
delegate.SetOnStartOpenConnection(
base::Bind(&WebSocketJobTest::DoSync, base::Unretained(test)));
delegate.SetOnConnected(
- base::Bind(&WebSocketJobTest::DoSendRequest,
- base::Unretained(test)));
+ base::Bind(&WebSocketJobTest::DoSendRequest, base::Unretained(test)));
delegate.SetOnReceivedData(
base::Bind(&WebSocketJobTest::DoSendData, base::Unretained(test)));
delegate.SetOnClose(

Powered by Google App Engine
This is Rietveld 408576698