OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "chrome/test/chromedriver/net/net_util.h" |
| 6 |
5 #include <string> | 7 #include <string> |
| 8 #include <utility> |
6 | 9 |
7 #include "base/bind.h" | 10 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
9 #include "base/location.h" | 12 #include "base/location.h" |
10 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
11 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
12 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
13 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
14 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
15 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
16 #include "chrome/test/chromedriver/net/net_util.h" | |
17 #include "chrome/test/chromedriver/net/url_request_context_getter.h" | 19 #include "chrome/test/chromedriver/net/url_request_context_getter.h" |
18 #include "net/base/ip_endpoint.h" | 20 #include "net/base/ip_endpoint.h" |
19 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
20 #include "net/server/http_server.h" | 22 #include "net/server/http_server.h" |
21 #include "net/server/http_server_request_info.h" | 23 #include "net/server/http_server_request_info.h" |
22 #include "net/socket/tcp_server_socket.h" | 24 #include "net/socket/tcp_server_socket.h" |
23 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
25 | 27 |
26 namespace { | 28 namespace { |
(...skipping 19 matching lines...) Expand all Loading... |
46 io_thread_.task_runner()->PostTask( | 48 io_thread_.task_runner()->PostTask( |
47 FROM_HERE, base::Bind(&FetchUrlTest::DestroyServerOnIO, | 49 FROM_HERE, base::Bind(&FetchUrlTest::DestroyServerOnIO, |
48 base::Unretained(this), &event)); | 50 base::Unretained(this), &event)); |
49 event.Wait(); | 51 event.Wait(); |
50 } | 52 } |
51 | 53 |
52 void InitOnIO(base::WaitableEvent* event) { | 54 void InitOnIO(base::WaitableEvent* event) { |
53 scoped_ptr<net::ServerSocket> server_socket( | 55 scoped_ptr<net::ServerSocket> server_socket( |
54 new net::TCPServerSocket(NULL, net::NetLog::Source())); | 56 new net::TCPServerSocket(NULL, net::NetLog::Source())); |
55 server_socket->ListenWithAddressAndPort("127.0.0.1", 0, 1); | 57 server_socket->ListenWithAddressAndPort("127.0.0.1", 0, 1); |
56 server_.reset(new net::HttpServer(server_socket.Pass(), this)); | 58 server_.reset(new net::HttpServer(std::move(server_socket), this)); |
57 net::IPEndPoint address; | 59 net::IPEndPoint address; |
58 CHECK_EQ(net::OK, server_->GetLocalAddress(&address)); | 60 CHECK_EQ(net::OK, server_->GetLocalAddress(&address)); |
59 server_url_ = base::StringPrintf("http://127.0.0.1:%d", address.port()); | 61 server_url_ = base::StringPrintf("http://127.0.0.1:%d", address.port()); |
60 event->Signal(); | 62 event->Signal(); |
61 } | 63 } |
62 | 64 |
63 void DestroyServerOnIO(base::WaitableEvent* event) { | 65 void DestroyServerOnIO(base::WaitableEvent* event) { |
64 server_.reset(NULL); | 66 server_.reset(NULL); |
65 event->Signal(); | 67 event->Signal(); |
66 } | 68 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 ASSERT_FALSE(FetchUrl(server_url_, context_getter_.get(), &response)); | 128 ASSERT_FALSE(FetchUrl(server_url_, context_getter_.get(), &response)); |
127 ASSERT_STREQ("stuff", response.c_str()); | 129 ASSERT_STREQ("stuff", response.c_str()); |
128 } | 130 } |
129 | 131 |
130 TEST_F(FetchUrlTest, NoServer) { | 132 TEST_F(FetchUrlTest, NoServer) { |
131 std::string response("stuff"); | 133 std::string response("stuff"); |
132 ASSERT_FALSE( | 134 ASSERT_FALSE( |
133 FetchUrl("http://localhost:33333", context_getter_.get(), &response)); | 135 FetchUrl("http://localhost:33333", context_getter_.get(), &response)); |
134 ASSERT_STREQ("stuff", response.c_str()); | 136 ASSERT_STREQ("stuff", response.c_str()); |
135 } | 137 } |
OLD | NEW |