Index: net/dns/mojo_host_resolver_impl_unittest.cc |
diff --git a/net/dns/mojo_host_resolver_impl_unittest.cc b/net/dns/mojo_host_resolver_impl_unittest.cc |
index 9b7425ab0fa1da0417a390764b6e15dd8603951f..9405c71afb16d8c33d102aad9fdd443f38fc3c31 100644 |
--- a/net/dns/mojo_host_resolver_impl_unittest.cc |
+++ b/net/dns/mojo_host_resolver_impl_unittest.cc |
@@ -15,7 +15,6 @@ |
#include "net/base/address_list.h" |
#include "net/base/net_errors.h" |
#include "net/dns/mock_host_resolver.h" |
-#include "net/dns/mojo_host_type_converters.h" |
#include "net/test/gtest_util.h" |
#include "testing/gmock/include/gmock/gmock.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -40,11 +39,11 @@ class TestRequestClient : public interfaces::HostResolverRequestClient { |
void WaitForConnectionError(); |
int32_t error_; |
- interfaces::AddressListPtr results_; |
+ AddressList results_; |
private: |
// Overridden from interfaces::HostResolverRequestClient. |
- void ReportResult(int32_t error, interfaces::AddressListPtr results) override; |
+ void ReportResult(int32_t error, const AddressList& results) override; |
// Mojo error handler. |
void OnConnectionError(); |
@@ -73,13 +72,13 @@ void TestRequestClient::WaitForConnectionError() { |
} |
void TestRequestClient::ReportResult(int32_t error, |
- interfaces::AddressListPtr results) { |
+ const AddressList& results) { |
if (!run_loop_quit_closure_.is_null()) { |
run_loop_quit_closure_.Run(); |
} |
ASSERT_FALSE(done_); |
error_ = error; |
- results_ = std::move(results); |
+ results_ = results; |
done_ = true; |
} |
@@ -139,15 +138,12 @@ class MojoHostResolverImplTest : public testing::Test { |
new MojoHostResolverImpl(&mock_host_resolver_, NetLogWithSource())); |
} |
- interfaces::HostResolverRequestInfoPtr CreateRequest(const std::string& host, |
- uint16_t port, |
- bool is_my_ip_address) { |
- interfaces::HostResolverRequestInfoPtr request = |
- interfaces::HostResolverRequestInfo::New(); |
- request->host = host; |
- request->port = port; |
- request->address_family = interfaces::AddressFamily::IPV4; |
- request->is_my_ip_address = is_my_ip_address; |
+ std::unique_ptr<HostResolver::RequestInfo> |
+ CreateRequest(const std::string& host, uint16_t port, bool is_my_ip_address) { |
+ std::unique_ptr<HostResolver::RequestInfo> request = |
+ base::MakeUnique<HostResolver::RequestInfo>(HostPortPair(host, port)); |
+ request->set_is_my_ip_address(is_my_ip_address); |
+ request->set_address_family(ADDRESS_FAMILY_IPV4); |
return request; |
} |
@@ -168,13 +164,12 @@ TEST_F(MojoHostResolverImplTest, Resolve) { |
interfaces::HostResolverRequestClientPtr client_ptr; |
TestRequestClient client(mojo::GetProxy(&client_ptr)); |
- interfaces::HostResolverRequestInfoPtr request = |
- CreateRequest("example.com", 80, false); |
- resolver_service_->Resolve(std::move(request), std::move(client_ptr)); |
+ resolver_service_->Resolve(CreateRequest("example.com", 80, false), |
+ std::move(client_ptr)); |
client.WaitForResult(); |
EXPECT_THAT(client.error_, IsOk()); |
- AddressList address_list = (*client.results_).To<AddressList>(); |
+ AddressList& address_list = client.results_; |
EXPECT_EQ(1U, address_list.size()); |
EXPECT_EQ("1.2.3.4:80", address_list[0].ToString()); |
} |
@@ -185,13 +180,12 @@ TEST_F(MojoHostResolverImplTest, ResolveSynchronous) { |
mock_host_resolver_.set_synchronous_mode(true); |
- interfaces::HostResolverRequestInfoPtr request = |
- CreateRequest("example.com", 80, false); |
- resolver_service_->Resolve(std::move(request), std::move(client_ptr)); |
+ resolver_service_->Resolve(CreateRequest("example.com", 80, false), |
+ std::move(client_ptr)); |
client.WaitForResult(); |
EXPECT_THAT(client.error_, IsOk()); |
- AddressList address_list = (*client.results_).To<AddressList>(); |
+ AddressList& address_list = client.results_; |
EXPECT_EQ(1U, address_list.size()); |
EXPECT_EQ("1.2.3.4:80", address_list[0].ToString()); |
} |
@@ -204,12 +198,10 @@ TEST_F(MojoHostResolverImplTest, ResolveMultiple) { |
mock_host_resolver_.set_ondemand_mode(true); |
- interfaces::HostResolverRequestInfoPtr request1 = |
- CreateRequest("example.com", 80, false); |
- resolver_service_->Resolve(std::move(request1), std::move(client1_ptr)); |
- interfaces::HostResolverRequestInfoPtr request2 = |
- CreateRequest("chromium.org", 80, false); |
- resolver_service_->Resolve(std::move(request2), std::move(client2_ptr)); |
+ resolver_service_->Resolve(CreateRequest("example.com", 80, false), |
+ std::move(client1_ptr)); |
+ resolver_service_->Resolve(CreateRequest("chromium.org", 80, false), |
+ std::move(client2_ptr)); |
WaitForRequests(2); |
mock_host_resolver_.ResolveAllPending(); |
@@ -217,13 +209,13 @@ TEST_F(MojoHostResolverImplTest, ResolveMultiple) { |
client2.WaitForResult(); |
EXPECT_THAT(client1.error_, IsOk()); |
- AddressList address_list = (*client1.results_).To<AddressList>(); |
- EXPECT_EQ(1U, address_list.size()); |
- EXPECT_EQ("1.2.3.4:80", address_list[0].ToString()); |
+ AddressList& address_list1 = client1.results_; |
+ EXPECT_EQ(1U, address_list1.size()); |
+ EXPECT_EQ("1.2.3.4:80", address_list1[0].ToString()); |
EXPECT_THAT(client2.error_, IsOk()); |
- address_list = (*client2.results_).To<AddressList>(); |
- EXPECT_EQ(1U, address_list.size()); |
- EXPECT_EQ("8.8.8.8:80", address_list[0].ToString()); |
+ AddressList& address_list2 = client2.results_; |
+ EXPECT_EQ(1U, address_list2.size()); |
+ EXPECT_EQ("8.8.8.8:80", address_list2[0].ToString()); |
} |
TEST_F(MojoHostResolverImplTest, ResolveDuplicate) { |
@@ -234,12 +226,10 @@ TEST_F(MojoHostResolverImplTest, ResolveDuplicate) { |
mock_host_resolver_.set_ondemand_mode(true); |
- interfaces::HostResolverRequestInfoPtr request1 = |
- CreateRequest("example.com", 80, false); |
- resolver_service_->Resolve(std::move(request1), std::move(client1_ptr)); |
- interfaces::HostResolverRequestInfoPtr request2 = |
- CreateRequest("example.com", 80, false); |
- resolver_service_->Resolve(std::move(request2), std::move(client2_ptr)); |
+ resolver_service_->Resolve(CreateRequest("example.com", 80, false), |
+ std::move(client1_ptr)); |
+ resolver_service_->Resolve(CreateRequest("example.com", 80, false), |
+ std::move(client2_ptr)); |
WaitForRequests(2); |
mock_host_resolver_.ResolveAllPending(); |
@@ -247,26 +237,25 @@ TEST_F(MojoHostResolverImplTest, ResolveDuplicate) { |
client2.WaitForResult(); |
EXPECT_THAT(client1.error_, IsOk()); |
- AddressList address_list = (*client1.results_).To<AddressList>(); |
- EXPECT_EQ(1U, address_list.size()); |
- EXPECT_EQ("1.2.3.4:80", address_list[0].ToString()); |
+ AddressList& address_list1 = client1.results_; |
+ EXPECT_EQ(1U, address_list1.size()); |
+ EXPECT_EQ("1.2.3.4:80", address_list1[0].ToString()); |
EXPECT_THAT(client2.error_, IsOk()); |
- address_list = (*client2.results_).To<AddressList>(); |
- EXPECT_EQ(1U, address_list.size()); |
- EXPECT_EQ("1.2.3.4:80", address_list[0].ToString()); |
+ AddressList& address_list2 = client2.results_; |
+ EXPECT_EQ(1U, address_list2.size()); |
+ EXPECT_EQ("1.2.3.4:80", address_list2[0].ToString()); |
} |
TEST_F(MojoHostResolverImplTest, ResolveFailure) { |
interfaces::HostResolverRequestClientPtr client_ptr; |
TestRequestClient client(mojo::GetProxy(&client_ptr)); |
- interfaces::HostResolverRequestInfoPtr request = |
- CreateRequest("failure.fail", 80, false); |
- resolver_service_->Resolve(std::move(request), std::move(client_ptr)); |
+ resolver_service_->Resolve(CreateRequest("failure.fail", 80, false), |
+ std::move(client_ptr)); |
client.WaitForResult(); |
EXPECT_THAT(client.error_, IsError(net::ERR_NAME_NOT_RESOLVED)); |
- EXPECT_TRUE(client.results_.is_null()); |
+ EXPECT_TRUE(client.results_.empty()); |
} |
TEST_F(MojoHostResolverImplTest, DestroyClient) { |
@@ -276,9 +265,8 @@ TEST_F(MojoHostResolverImplTest, DestroyClient) { |
mock_host_resolver_.set_ondemand_mode(true); |
- interfaces::HostResolverRequestInfoPtr request = |
- CreateRequest("example.com", 80, false); |
- resolver_service_->Resolve(std::move(request), std::move(client_ptr)); |
+ resolver_service_->Resolve(CreateRequest("example.com", 80, false), |
+ std::move(client_ptr)); |
WaitForRequests(1); |
client.reset(); |