summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-04 05:13:12 +0000
committermbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-04 05:13:12 +0000
commit6371bf471df4ae89446c22b924909f09ad034fae (patch)
tree4df5ca128ebd401fe297cd1980ed6e5ed5308d72
parentdd1e41a83fc1e11227caffcde580122588c203d2 (diff)
downloadchromium_src-6371bf471df4ae89446c22b924909f09ad034fae.zip
chromium_src-6371bf471df4ae89446c22b924909f09ad034fae.tar.gz
chromium_src-6371bf471df4ae89446c22b924909f09ad034fae.tar.bz2
Fix bug where FLIP sessions can crash if the connect fails.
Update the mocksocket so that we can test connection statuses. Verified that the test case crashes without the flip_session.cc fix. BUG=none TEST=FlipNetworkTransaction.ConnectFailure Review URL: http://codereview.chromium.org/462023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33792 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/flip/flip_network_transaction_unittest.cc51
-rw-r--r--net/flip/flip_session.cc8
-rw-r--r--net/socket/socket_test_util.h1
3 files changed, 58 insertions, 2 deletions
diff --git a/net/flip/flip_network_transaction_unittest.cc b/net/flip/flip_network_transaction_unittest.cc
index 0629a73..be0172f 100644
--- a/net/flip/flip_network_transaction_unittest.cc
+++ b/net/flip/flip_network_transaction_unittest.cc
@@ -189,6 +189,23 @@ class DelayedSocketData : public StaticSocketDataProvider,
DCHECK_GE(write_delay_, 0);
}
+ // |connect| the result for the connect phase.
+ // |reads| the list of MockRead completions.
+ // |write_delay| the number of MockWrites to complete before allowing
+ // a MockRead to complete.
+ // |writes| the list of MockWrite completions.
+ // Note: All MockReads and MockWrites must be async.
+ // Note: The MockRead and MockWrite lists musts end with a EOF
+ // e.g. a MockRead(true, 0, 0);
+ DelayedSocketData(const MockConnect& connect, MockRead* reads,
+ int write_delay, MockWrite* writes)
+ : StaticSocketDataProvider(reads, writes),
+ write_delay_(write_delay),
+ ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {
+ DCHECK_GE(write_delay_, 0);
+ set_connect_data(connect);
+ }
+
virtual MockRead GetNextRead() {
if (write_delay_)
return MockRead(true, ERR_IO_PENDING);
@@ -863,4 +880,38 @@ TEST_F(FlipNetworkTransactionTest, PartialWrite) {
EXPECT_EQ("hello!", out.response_data);
}
+TEST_F(FlipNetworkTransactionTest, ConnectFailure) {
+ MockConnect connects[] = {
+ MockConnect(true, ERR_NAME_NOT_RESOLVED),
+ MockConnect(false, ERR_NAME_NOT_RESOLVED),
+ MockConnect(true, ERR_INTERNET_DISCONNECTED),
+ MockConnect(false, ERR_INTERNET_DISCONNECTED)
+ };
+
+ for (size_t index = 0; index < arraysize(connects); ++index) {
+ MockWrite writes[] = {
+ MockWrite(true, reinterpret_cast<const char*>(kGetSyn),
+ arraysize(kGetSyn)),
+ MockWrite(true, 0, 0) // EOF
+ };
+
+ MockRead reads[] = {
+ MockRead(true, reinterpret_cast<const char*>(kGetSynReply),
+ arraysize(kGetSynReply)),
+ MockRead(true, reinterpret_cast<const char*>(kGetBodyFrame),
+ arraysize(kGetBodyFrame)),
+ MockRead(true, 0, 0) // EOF
+ };
+
+ HttpRequestInfo request;
+ request.method = "GET";
+ request.url = GURL("http://www.google.com/");
+ request.load_flags = 0;
+ scoped_refptr<DelayedSocketData> data(
+ new DelayedSocketData(connects[index], reads, 1, writes));
+ TransactionHelperResult out = TransactionHelper(request, data.get());
+ EXPECT_EQ(connects[index].result, out.rv);
+ }
+}
+
} // namespace net
diff --git a/net/flip/flip_session.cc b/net/flip/flip_session.cc
index f501b58..b3b4069 100644
--- a/net/flip/flip_session.cc
+++ b/net/flip/flip_session.cc
@@ -136,6 +136,9 @@ void CreateFlipHeadersFromHttpRequest(
}
}
+ // TODO(mbelshe): Add Proxy headers here. (See http_network_transaction.cc)
+ // TODO(mbelshe): Add authentication headers here.
+
(*headers)["method"] = info.method;
(*headers)["url"] = info.url.spec();
(*headers)["version"] = kHttpProtocolVersion;
@@ -552,8 +555,9 @@ void FlipSession::WriteSocket() {
delayed_write_pending_ = false;
// If the socket isn't connected yet, just wait; we'll get called
- // again when the socket connection completes.
- if (state_ < CONNECTED)
+ // again when the socket connection completes. If the socket is
+ // closed, just return.
+ if (state_ < CONNECTED || state_ == CLOSED)
return;
if (write_pending_) // Another write is in progress still.
diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h
index 5f17f71..22b1c80 100644
--- a/net/socket/socket_test_util.h
+++ b/net/socket/socket_test_util.h
@@ -108,6 +108,7 @@ class SocketDataProvider {
void set_socket(MockClientSocket* socket) { socket_ = socket; }
MockConnect connect_data() const { return connect_; }
+ void set_connect_data(const MockConnect& connect) { connect_ = connect; }
private:
MockConnect connect_;