| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chromeos/network/host_resolver_impl_chromeos.h" | 5 #include "chromeos/network/host_resolver_impl_chromeos.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 const chromeos::NetworkState* default_network = | 55 const chromeos::NetworkState* default_network = |
| 56 network_state_handler_->DefaultNetwork(); | 56 network_state_handler_->DefaultNetwork(); |
| 57 ASSERT_TRUE(default_network); | 57 ASSERT_TRUE(default_network); |
| 58 const chromeos::DeviceState* default_device = | 58 const chromeos::DeviceState* default_device = |
| 59 network_state_handler_->GetDeviceState(default_network->device_path()); | 59 network_state_handler_->GetDeviceState(default_network->device_path()); |
| 60 ASSERT_TRUE(default_device); | 60 ASSERT_TRUE(default_device); |
| 61 SetDefaultIPConfigs(default_device->path()); | 61 SetDefaultIPConfigs(default_device->path()); |
| 62 | 62 |
| 63 // Create the host resolver from the IO message loop. | 63 // Create the host resolver from the IO message loop. |
| 64 io_message_loop_.PostTask( | 64 io_message_loop_.task_runner()->PostTask( |
| 65 FROM_HERE, | 65 FROM_HERE, |
| 66 base::Bind(&HostResolverImplChromeOSTest::InitializeHostResolver, | 66 base::Bind(&HostResolverImplChromeOSTest::InitializeHostResolver, |
| 67 base::Unretained(this))); | 67 base::Unretained(this))); |
| 68 io_message_loop_.RunUntilIdle(); | |
| 69 | |
| 70 // Run the main message loop to create the network observer and initialize | |
| 71 // the ip address values. | |
| 72 base::RunLoop().RunUntilIdle(); | 68 base::RunLoop().RunUntilIdle(); |
| 73 } | 69 } |
| 74 | 70 |
| 75 void TearDown() override { | 71 void TearDown() override { |
| 76 network_state_handler_.reset(); | 72 network_state_handler_.reset(); |
| 77 chromeos::DBusThreadManager::Shutdown(); | 73 chromeos::DBusThreadManager::Shutdown(); |
| 78 } | 74 } |
| 79 | 75 |
| 80 protected: | 76 protected: |
| 81 // Run from main (UI) message loop, calls Resolve on IO message loop. | 77 // Run from main (UI) message loop, calls Resolve on IO message loop. |
| 82 int CallResolve(net::HostResolver::RequestInfo& info) { | 78 int CallResolve(net::HostResolver::RequestInfo& info) { |
| 83 io_message_loop_.task_runner()->PostTask( | 79 io_message_loop_.task_runner()->PostTask( |
| 84 FROM_HERE, base::Bind(&HostResolverImplChromeOSTest::Resolve, | 80 FROM_HERE, base::Bind(&HostResolverImplChromeOSTest::Resolve, |
| 85 base::Unretained(this), info)); | 81 base::Unretained(this), info)); |
| 86 io_message_loop_.RunUntilIdle(); | 82 base::RunLoop().RunUntilIdle(); |
| 87 return result_; | 83 return result_; |
| 88 } | 84 } |
| 89 | 85 |
| 90 net::AddressList addresses_; | 86 net::AddressList addresses_; |
| 91 int result_; | 87 int result_; |
| 92 | 88 |
| 93 private: | 89 private: |
| 94 // Run from IO message loop. | 90 // Run from IO message loop. |
| 95 void InitializeHostResolver() { | 91 void InitializeHostResolver() { |
| 96 net::HostResolver::Options options; | 92 net::HostResolver::Options options; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 EXPECT_EQ(expected, addresses_[0].ToString()); | 158 EXPECT_EQ(expected, addresses_[0].ToString()); |
| 163 | 159 |
| 164 info.set_address_family(net::ADDRESS_FAMILY_IPV6); | 160 info.set_address_family(net::ADDRESS_FAMILY_IPV6); |
| 165 EXPECT_EQ(net::OK, CallResolve(info)); | 161 EXPECT_EQ(net::OK, CallResolve(info)); |
| 166 ASSERT_EQ(2u, addresses_.size()); | 162 ASSERT_EQ(2u, addresses_.size()); |
| 167 expected = base::StringPrintf("[%s]:%d", kTestIPv6Address, 0); | 163 expected = base::StringPrintf("[%s]:%d", kTestIPv6Address, 0); |
| 168 EXPECT_EQ(expected, addresses_[0].ToString()); | 164 EXPECT_EQ(expected, addresses_[0].ToString()); |
| 169 expected = base::StringPrintf("%s:%d", kTestIPv4Address, 0); | 165 expected = base::StringPrintf("%s:%d", kTestIPv4Address, 0); |
| 170 EXPECT_EQ(expected, addresses_[1].ToString()); | 166 EXPECT_EQ(expected, addresses_[1].ToString()); |
| 171 } | 167 } |
| OLD | NEW |