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

Side by Side Diff: jingle/notifier/base/proxy_resolving_client_socket_unittest.cc

Issue 10817013: Move ChromeAsyncSocket to jingle/glue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "jingle/notifier/base/proxy_resolving_client_socket.h"
6
7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h"
9 #include "base/message_loop.h"
10 #include "net/base/mock_host_resolver.h"
11 #include "net/base/test_completion_callback.h"
12 #include "net/proxy/proxy_service.h"
13 #include "net/socket/socket_test_util.h"
14 #include "net/url_request/url_request_context_getter.h"
15 #include "net/url_request/url_request_test_util.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace {
19
20 class MyTestURLRequestContext : public TestURLRequestContext {
21 public:
22 MyTestURLRequestContext() : TestURLRequestContext(true) {
23 context_storage_.set_proxy_service(
24 net::ProxyService::CreateFixedFromPacResult(
25 "PROXY bad:99; PROXY maybe:80; DIRECT"));
26 Init();
27 }
28 virtual ~MyTestURLRequestContext() {}
29 };
30
31 } // namespace
32
33 namespace notifier {
34
35 class ProxyResolvingClientSocketTest : public testing::Test {
36 protected:
37 ProxyResolvingClientSocketTest()
38 : url_request_context_getter_(new TestURLRequestContextGetter(
39 base::MessageLoopProxy::current(),
40 scoped_ptr<TestURLRequestContext>(new MyTestURLRequestContext))) {}
41
42 virtual ~ProxyResolvingClientSocketTest() {}
43
44 virtual void TearDown() {
45 // Clear out any messages posted by ProxyResolvingClientSocket's
46 // destructor.
47 message_loop_.RunAllPending();
48 }
49
50 MessageLoop message_loop_;
51 scoped_refptr<TestURLRequestContextGetter> url_request_context_getter_;
52 };
53
54 // TODO(sanjeevr): Fix this test on Linux.
55 TEST_F(ProxyResolvingClientSocketTest, DISABLED_ConnectError) {
56 net::HostPortPair dest("0.0.0.0", 0);
57 ProxyResolvingClientSocket proxy_resolving_socket(
58 NULL,
59 url_request_context_getter_,
60 net::SSLConfig(),
61 dest);
62 net::TestCompletionCallback callback;
63 int status = proxy_resolving_socket.Connect(callback.callback());
64 // Connect always returns ERR_IO_PENDING because it is always asynchronous.
65 EXPECT_EQ(net::ERR_IO_PENDING, status);
66 status = callback.WaitForResult();
67 // ProxyResolvingClientSocket::Connect() will always return an error of
68 // ERR_ADDRESS_INVALID for a 0 IP address.
69 EXPECT_EQ(net::ERR_ADDRESS_INVALID, status);
70 }
71
72 TEST_F(ProxyResolvingClientSocketTest, ReportsBadProxies) {
73 net::HostPortPair dest("example.com", 443);
74 net::MockClientSocketFactory socket_factory;
75
76 net::StaticSocketDataProvider socket_data1;
77 socket_data1.set_connect_data(
78 net::MockConnect(net::ASYNC, net::ERR_ADDRESS_UNREACHABLE));
79 socket_factory.AddSocketDataProvider(&socket_data1);
80
81 net::MockRead reads[] = {
82 net::MockRead("HTTP/1.1 200 Success\r\n\r\n")
83 };
84 net::MockWrite writes[] = {
85 net::MockWrite("CONNECT example.com:443 HTTP/1.1\r\n"
86 "Host: example.com:443\r\n"
87 "Proxy-Connection: keep-alive\r\n\r\n")
88 };
89 net::StaticSocketDataProvider socket_data2(reads, arraysize(reads),
90 writes, arraysize(writes));
91 socket_data2.set_connect_data(net::MockConnect(net::ASYNC, net::OK));
92 socket_factory.AddSocketDataProvider(&socket_data2);
93
94 ProxyResolvingClientSocket proxy_resolving_socket(
95 &socket_factory,
96 url_request_context_getter_,
97 net::SSLConfig(),
98 dest);
99
100 net::TestCompletionCallback callback;
101 int status = proxy_resolving_socket.Connect(callback.callback());
102 EXPECT_EQ(net::ERR_IO_PENDING, status);
103 status = callback.WaitForResult();
104 EXPECT_EQ(net::OK, status);
105
106 net::URLRequestContext* context =
107 url_request_context_getter_->GetURLRequestContext();
108 const net::ProxyRetryInfoMap& retry_info =
109 context->proxy_service()->proxy_retry_info();
110
111 EXPECT_EQ(1u, retry_info.size());
112 net::ProxyRetryInfoMap::const_iterator iter = retry_info.find("bad:99");
113 EXPECT_TRUE(iter != retry_info.end());
114 }
115
116 // TODO(sanjeevr): Add more unit-tests.
117 } // namespace notifier
OLDNEW
« no previous file with comments | « jingle/notifier/base/proxy_resolving_client_socket.cc ('k') | jingle/notifier/base/resolving_client_socket_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698