From a677f2b546d2034b459d40e6d0f24977e9b9ade3 Mon Sep 17 00:00:00 2001 From: "willchan@chromium.org" Date: Sun, 22 Nov 2009 00:43:00 +0000 Subject: Flip: Merge FlipStreamParser and FlipStream. Eliminate FlipDelegate. FlipStream now conceptually contains everything associated with a single Flip stream. This primarily consists of 2 things: (1) FlipStream as a consumer of network events from FlipSession (2) FlipStream as a network provider to consumers (such as FlipNetworkTransaction). Conceptually, FlipStream also should be agnostic of wire level protocol framing details, only dealing with HTTP style headers and responses. Anything wire level has been moved out of FlipStream into FlipSession. FlipStream is now reference counted since it is referenced by both the FlipSession and the consumer (only FlipNetworkTransaction currently). FlipNetworkTransaction can be cancelled prior to all network events finishing up, therefore the code needs to handle this gracefully. FlipStream supports a Cancel() function for this reason. FlipStream now communicates with consumers via CompletionCallbacks rather than using FlipDelegates. Review URL: http://codereview.chromium.org/410006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32765 0039d316-1c4b-4281-b951-d872f2087c98 --- net/flip/flip_stream_unittest.cc | 98 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 net/flip/flip_stream_unittest.cc (limited to 'net/flip/flip_stream_unittest.cc') diff --git a/net/flip/flip_stream_unittest.cc b/net/flip/flip_stream_unittest.cc new file mode 100644 index 0000000..bb661c0 --- /dev/null +++ b/net/flip/flip_stream_unittest.cc @@ -0,0 +1,98 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/flip/flip_stream.h" +#include "base/ref_counted.h" +#include "net/base/mock_host_resolver.h" +#include "net/base/net_errors.h" +#include "net/base/ssl_config_service.h" +#include "net/base/ssl_config_service_defaults.h" +#include "net/base/test_completion_callback.h" +#include "net/flip/flip_session.h" +#include "net/flip/flip_session_pool.h" +#include "net/http/http_network_session.h" +#include "net/http/http_request_info.h" +#include "net/proxy/proxy_service.h" +#include "net/socket/socket_test_util.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace net { + +namespace { + +// Create a proxy service which fails on all requests (falls back to direct). +ProxyService* CreateNullProxyService() { + return ProxyService::CreateNull(); +} + +// Helper to manage the lifetimes of the dependencies for a +// FlipNetworkTransaction. +class SessionDependencies { + public: + // Default set of dependencies -- "null" proxy service. + SessionDependencies() + : host_resolver(new MockHostResolver), + proxy_service(CreateNullProxyService()), + ssl_config_service(new SSLConfigServiceDefaults), + flip_session_pool(new FlipSessionPool) {} + + // Custom proxy service dependency. + explicit SessionDependencies(ProxyService* proxy_service) + : host_resolver(new MockHostResolver), + proxy_service(proxy_service), + ssl_config_service(new SSLConfigServiceDefaults), + flip_session_pool(new FlipSessionPool) {} + + scoped_refptr host_resolver; + scoped_refptr proxy_service; + scoped_refptr ssl_config_service; + MockClientSocketFactory socket_factory; + scoped_refptr flip_session_pool; +}; + +HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { + return new HttpNetworkSession(session_deps->host_resolver, + session_deps->proxy_service, + &session_deps->socket_factory, + session_deps->ssl_config_service, + session_deps->flip_session_pool); +} + +class FlipStreamTest : public testing::Test { + protected: + FlipStreamTest() + : session_(CreateSession(&session_deps_)) {} + + scoped_refptr CreateFlipSession() { + HostResolver::RequestInfo resolve_info("www.google.com", 80); + scoped_refptr session( + session_->flip_session_pool()->Get(resolve_info, session_)); + return session; + } + + virtual void TearDown() { + MessageLoop::current()->RunAllPending(); + } + + SessionDependencies session_deps_; + scoped_refptr session_; +}; + +TEST_F(FlipStreamTest, SendRequest) { + scoped_refptr session(CreateFlipSession()); + HttpRequestInfo request; + request.method = "GET"; + request.url = GURL("http://www.google.com/"); + TestCompletionCallback callback; + + scoped_refptr stream(new FlipStream(session, 1, false)); + EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(NULL, &callback)); +} + +// TODO(willchan): Write a longer test for FlipStream that exercises all +// methods. + +} // namespace + +} // namespace net -- cgit v1.1