| 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" | 5 #include "chrome/test/chromedriver/net/net_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 class FetchUrlTest : public testing::Test, | 30 class FetchUrlTest : public testing::Test, |
| 31 public net::HttpServer::Delegate { | 31 public net::HttpServer::Delegate { |
| 32 public: | 32 public: |
| 33 FetchUrlTest() | 33 FetchUrlTest() |
| 34 : io_thread_("io"), | 34 : io_thread_("io"), |
| 35 response_(kSendHello) { | 35 response_(kSendHello) { |
| 36 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); | 36 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); |
| 37 CHECK(io_thread_.StartWithOptions(options)); | 37 CHECK(io_thread_.StartWithOptions(options)); |
| 38 context_getter_ = new URLRequestContextGetter(io_thread_.task_runner()); | 38 context_getter_ = new URLRequestContextGetter(io_thread_.task_runner()); |
| 39 base::WaitableEvent event(false, false); | 39 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 40 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 40 io_thread_.task_runner()->PostTask( | 41 io_thread_.task_runner()->PostTask( |
| 41 FROM_HERE, | 42 FROM_HERE, |
| 42 base::Bind(&FetchUrlTest::InitOnIO, base::Unretained(this), &event)); | 43 base::Bind(&FetchUrlTest::InitOnIO, base::Unretained(this), &event)); |
| 43 event.Wait(); | 44 event.Wait(); |
| 44 } | 45 } |
| 45 | 46 |
| 46 ~FetchUrlTest() override { | 47 ~FetchUrlTest() override { |
| 47 base::WaitableEvent event(false, false); | 48 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 49 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 48 io_thread_.task_runner()->PostTask( | 50 io_thread_.task_runner()->PostTask( |
| 49 FROM_HERE, base::Bind(&FetchUrlTest::DestroyServerOnIO, | 51 FROM_HERE, base::Bind(&FetchUrlTest::DestroyServerOnIO, |
| 50 base::Unretained(this), &event)); | 52 base::Unretained(this), &event)); |
| 51 event.Wait(); | 53 event.Wait(); |
| 52 } | 54 } |
| 53 | 55 |
| 54 void InitOnIO(base::WaitableEvent* event) { | 56 void InitOnIO(base::WaitableEvent* event) { |
| 55 std::unique_ptr<net::ServerSocket> server_socket( | 57 std::unique_ptr<net::ServerSocket> server_socket( |
| 56 new net::TCPServerSocket(NULL, net::NetLog::Source())); | 58 new net::TCPServerSocket(NULL, net::NetLog::Source())); |
| 57 server_socket->ListenWithAddressAndPort("127.0.0.1", 0, 1); | 59 server_socket->ListenWithAddressAndPort("127.0.0.1", 0, 1); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 ASSERT_FALSE(FetchUrl(server_url_, context_getter_.get(), &response)); | 130 ASSERT_FALSE(FetchUrl(server_url_, context_getter_.get(), &response)); |
| 129 ASSERT_STREQ("stuff", response.c_str()); | 131 ASSERT_STREQ("stuff", response.c_str()); |
| 130 } | 132 } |
| 131 | 133 |
| 132 TEST_F(FetchUrlTest, NoServer) { | 134 TEST_F(FetchUrlTest, NoServer) { |
| 133 std::string response("stuff"); | 135 std::string response("stuff"); |
| 134 ASSERT_FALSE( | 136 ASSERT_FALSE( |
| 135 FetchUrl("http://localhost:33333", context_getter_.get(), &response)); | 137 FetchUrl("http://localhost:33333", context_getter_.get(), &response)); |
| 136 ASSERT_STREQ("stuff", response.c_str()); | 138 ASSERT_STREQ("stuff", response.c_str()); |
| 137 } | 139 } |
| OLD | NEW |