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

Unified Diff: jingle/notifier/base/proxy_resolving_client_socket_unittest.cc

Issue 7802002: Jingle unit tests for issue 87336 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments and rebase. Created 9 years, 3 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: jingle/notifier/base/proxy_resolving_client_socket_unittest.cc
diff --git a/jingle/notifier/base/proxy_resolving_client_socket_unittest.cc b/jingle/notifier/base/proxy_resolving_client_socket_unittest.cc
index e0a46e58e4d63dcb06715acf34ae97a9a5f3b8c9..48807a64229b3fd560e09235df31d985d3ed4933 100644
--- a/jingle/notifier/base/proxy_resolving_client_socket_unittest.cc
+++ b/jingle/notifier/base/proxy_resolving_client_socket_unittest.cc
@@ -6,9 +6,11 @@
#include "base/basictypes.h"
#include "base/message_loop.h"
+#include "net/base/mock_host_resolver.h"
+#include "net/base/test_completion_callback.h"
+#include "net/socket/socket_test_util.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_test_util.h"
-#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -24,7 +26,7 @@ class TestURLRequestContextGetter : public net::URLRequestContextGetter {
// net::URLRequestContextGetter:
virtual net::URLRequestContext* GetURLRequestContext() {
if (!context_)
- context_ = new TestURLRequestContext();
+ CreateURLRequestContext();
return context_.get();
}
virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
@@ -32,6 +34,13 @@ class TestURLRequestContextGetter : public net::URLRequestContextGetter {
}
private:
+ void CreateURLRequestContext() {
+ context_ = new TestURLRequestContext();
+ context_->set_host_resolver(new net::MockHostResolver());
+ context_->set_proxy_service(net::ProxyService::CreateFixedFromPacResult(
+ "PROXY bad:99; PROXY maybe:80; DIRECT"));
+ }
+
scoped_refptr<net::URLRequestContext> context_;
scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
};
@@ -42,9 +51,7 @@ namespace notifier {
class ProxyResolvingClientSocketTest : public testing::Test {
protected:
ProxyResolvingClientSocketTest()
- : url_request_context_getter_(new TestURLRequestContextGetter()),
- connect_callback_(ALLOW_THIS_IN_INITIALIZER_LIST(this),
- &ProxyResolvingClientSocketTest::NetCallback) { }
+ : url_request_context_getter_(new TestURLRequestContextGetter()) {}
virtual ~ProxyResolvingClientSocketTest() {}
@@ -54,28 +61,71 @@ class ProxyResolvingClientSocketTest : public testing::Test {
message_loop_.RunAllPending();
}
- MOCK_METHOD1(NetCallback, void(int status));
-
// Needed by XmppConnection.
MessageLoopForIO message_loop_;
scoped_refptr<TestURLRequestContextGetter> url_request_context_getter_;
- net::CompletionCallbackImpl<ProxyResolvingClientSocketTest> connect_callback_;
};
// TODO(sanjeevr): Fix this test on Linux.
TEST_F(ProxyResolvingClientSocketTest, DISABLED_ConnectError) {
net::HostPortPair dest("0.0.0.0", 0);
ProxyResolvingClientSocket proxy_resolving_socket(
+ NULL,
url_request_context_getter_,
net::SSLConfig(),
dest);
+ TestCompletionCallback callback;
+ int status = proxy_resolving_socket.Connect(&callback);
+ // Connect always returns ERR_IO_PENDING because it is always asynchronous.
+ EXPECT_EQ(net::ERR_IO_PENDING, status);
+ status = callback.WaitForResult();
// ProxyResolvingClientSocket::Connect() will always return an error of
// ERR_ADDRESS_INVALID for a 0 IP address.
- EXPECT_CALL(*this, NetCallback(net::ERR_ADDRESS_INVALID)).Times(1);
- int status = proxy_resolving_socket.Connect(&connect_callback_);
- // Connect always returns ERR_IO_PENDING because it is always asynchronous.
- EXPECT_EQ(status, net::ERR_IO_PENDING);
- message_loop_.RunAllPending();
+ EXPECT_EQ(net::ERR_ADDRESS_INVALID, status);
+}
+
+TEST_F(ProxyResolvingClientSocketTest, ReportsBadProxies) {
+ net::HostPortPair dest("example.com", 443);
+ net::MockClientSocketFactory socket_factory;
+
+ net::StaticSocketDataProvider socket_data1;
+ socket_data1.set_connect_data(
+ net::MockConnect(true, net::ERR_ADDRESS_UNREACHABLE));
+ socket_factory.AddSocketDataProvider(&socket_data1);
+
+ net::MockRead reads[] = {
+ net::MockRead("HTTP/1.1 200 Success\r\n\r\n")
+ };
+ net::MockWrite writes[] = {
+ net::MockWrite("CONNECT example.com:443 HTTP/1.1\r\n"
+ "Host: example.com:443\r\n"
+ "Proxy-Connection: keep-alive\r\n\r\n")
+ };
+ net::StaticSocketDataProvider socket_data2(reads, arraysize(reads),
+ writes, arraysize(writes));
+ socket_data2.set_connect_data(net::MockConnect(true, net::OK));
+ socket_factory.AddSocketDataProvider(&socket_data2);
+
+ ProxyResolvingClientSocket proxy_resolving_socket(
+ &socket_factory,
+ url_request_context_getter_,
+ net::SSLConfig(),
+ dest);
+
+ TestCompletionCallback callback;
+ int status = proxy_resolving_socket.Connect(&callback);
+ EXPECT_EQ(net::ERR_IO_PENDING, status);
+ status = callback.WaitForResult();
+ EXPECT_EQ(net::OK, status);
+
+ net::URLRequestContext* context =
+ url_request_context_getter_->GetURLRequestContext();
+ const net::ProxyRetryInfoMap& retry_info =
+ context->proxy_service()->proxy_retry_info();
+
+ EXPECT_EQ(1u, retry_info.size());
+ net::ProxyRetryInfoMap::const_iterator iter = retry_info.find("bad:99");
+ EXPECT_TRUE(iter != retry_info.end());
}
// TODO(sanjeevr): Add more unit-tests.
« no previous file with comments | « jingle/notifier/base/proxy_resolving_client_socket.cc ('k') | jingle/notifier/base/xmpp_client_socket_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698