summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorerikchen@google.com <erikchen@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-20 16:32:58 +0000
committererikchen@google.com <erikchen@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-20 16:32:58 +0000
commite6b068613f8f7616ba88ced54f6d15cccb51879a (patch)
treec2016764052927d0034d8f65d29f78a79817cd4b /net
parent677bd9c5d0d7e3f4cd635d19fbccb82e3469b3c9 (diff)
downloadchromium_src-e6b068613f8f7616ba88ced54f6d15cccb51879a.zip
chromium_src-e6b068613f8f7616ba88ced54f6d15cccb51879a.tar.gz
chromium_src-e6b068613f8f7616ba88ced54f6d15cccb51879a.tar.bz2
Add Spdy ConnectFailure test back into spdy network tests.
BUG=none TEST=net_unittests Review URL: http://codereview.chromium.org/3040005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53049 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/spdy/spdy_network_transaction_unittest.cc79
1 files changed, 78 insertions, 1 deletions
diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc
index 72d65bd..b71b0ce 100644
--- a/net/spdy/spdy_network_transaction_unittest.cc
+++ b/net/spdy/spdy_network_transaction_unittest.cc
@@ -237,12 +237,21 @@ class SpdyNetworkTransactionTest : public PlatformTest {
RunDefaultTest();
VerifyDataConsumed();
}
- // Only call AddData before calling RunPreTestSetup!!
+
+ // Only call AddData before calling RunPreTestSetup!! When RunPreTestSetup
+ // is run, it will add this Data Provider, and a corresponding SSL data
+ // provider.
void AddData(StaticSocketDataProvider* data) {
EXPECT_TRUE(add_data_allowed_);
data_vector_.push_back(data);
}
+ // This can only be called after RunPreTestSetup. It adds a Data Provider,
+ // but not a corresponding SSL data provider
+ void AddDataNoSSL(StaticSocketDataProvider* data) {
+ session_deps_.socket_factory.AddSocketDataProvider(data);
+ }
+
void SetSession(scoped_refptr<HttpNetworkSession>& session) {
session_ = session;
}
@@ -1893,6 +1902,74 @@ TEST_F(SpdyNetworkTransactionTest, BufferFull) {
EXPECT_EQ("goodbye world", out.response_data);
}
+TEST_F(SpdyNetworkTransactionTest, ConnectFailureFallbackToHttp) {
+ 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) {
+ scoped_ptr<spdy::SpdyFrame> req(
+ ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
+ MockWrite writes[] = {
+ CreateMockWrite(*req),
+ MockWrite(true, 0, 0) // EOF
+ };
+
+ scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
+ scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true));
+ MockRead reads[] = {
+ CreateMockRead(*resp),
+ CreateMockRead(*body),
+ MockRead(true, 0, 0) // EOF
+ };
+
+ scoped_refptr<DelayedSocketData> data(
+ new DelayedSocketData(connects[index], 1, reads, arraysize(reads),
+ writes, arraysize(writes)));
+ NormalSpdyTransactionHelper helper(CreateGetRequest(),
+ BoundNetLog());
+ helper.AddData(data.get());
+ helper.RunPreTestSetup();
+
+ // Set up http fallback data.
+ MockRead http_fallback_data[] = {
+ MockRead("HTTP/1.1 200 OK\r\n\r\n"),
+ MockRead("hello world!!!"),
+ MockRead(true, OK),
+ };
+
+ scoped_ptr<StaticSocketDataProvider> http_fallback(
+ new StaticSocketDataProvider(http_fallback_data,
+ arraysize(http_fallback_data),
+ NULL, 0));
+ helper.AddDataNoSSL(http_fallback.get());
+ HttpNetworkTransaction* trans = helper.trans();
+ TestCompletionCallback callback;
+
+ int rv = trans->Start(&helper.request(), &callback, BoundNetLog());
+ EXPECT_EQ(rv, ERR_IO_PENDING);
+ rv = callback.WaitForResult();
+ const HttpResponseInfo* response = trans->GetResponseInfo();
+ ASSERT_TRUE(response != NULL);
+ ASSERT_TRUE(response->headers != NULL);
+ EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
+ std::string response_data;
+ rv = ReadTransaction(trans, &response_data);
+ EXPECT_EQ(OK, rv);
+
+ EXPECT_TRUE(!response->was_fetched_via_spdy);
+ EXPECT_TRUE(!response->was_npn_negotiated);
+ EXPECT_TRUE(response->was_alternate_protocol_available);
+ EXPECT_TRUE(http_fallback->at_read_eof());
+ EXPECT_EQ(0u, data->read_index());
+ EXPECT_EQ(0u, data->write_index());
+ EXPECT_EQ("hello world!!!", response_data);
+ }
+}
+
// Verify that basic buffering works; when multiple data frames arrive
// at the same time, ensure that we don't notify a read completion for
// each data frame individually.