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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 void ResolveCompletionCallback(int result) {} | 33 void ResolveCompletionCallback(int result) {} |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 class HostResolverImplChromeOSTest : public testing::Test { | 37 class HostResolverImplChromeOSTest : public testing::Test { |
38 public: | 38 public: |
39 HostResolverImplChromeOSTest() {} | 39 HostResolverImplChromeOSTest() {} |
40 | 40 |
41 virtual ~HostResolverImplChromeOSTest() {} | 41 virtual ~HostResolverImplChromeOSTest() {} |
42 | 42 |
43 virtual void SetUp() OVERRIDE { | 43 virtual void SetUp() override { |
44 chromeos::DBusThreadManager::Initialize(); | 44 chromeos::DBusThreadManager::Initialize(); |
45 | 45 |
46 network_state_handler_.reset( | 46 network_state_handler_.reset( |
47 chromeos::NetworkStateHandler::InitializeForTest()); | 47 chromeos::NetworkStateHandler::InitializeForTest()); |
48 base::RunLoop().RunUntilIdle(); | 48 base::RunLoop().RunUntilIdle(); |
49 | 49 |
50 const chromeos::NetworkState* default_network = | 50 const chromeos::NetworkState* default_network = |
51 network_state_handler_->DefaultNetwork(); | 51 network_state_handler_->DefaultNetwork(); |
52 ASSERT_TRUE(default_network); | 52 ASSERT_TRUE(default_network); |
53 const chromeos::DeviceState* default_device = | 53 const chromeos::DeviceState* default_device = |
54 network_state_handler_->GetDeviceState(default_network->device_path()); | 54 network_state_handler_->GetDeviceState(default_network->device_path()); |
55 ASSERT_TRUE(default_device); | 55 ASSERT_TRUE(default_device); |
56 SetDefaultIPConfigs(default_device->path()); | 56 SetDefaultIPConfigs(default_device->path()); |
57 | 57 |
58 // Create the host resolver from the IO message loop. | 58 // Create the host resolver from the IO message loop. |
59 io_message_loop_.PostTask( | 59 io_message_loop_.PostTask( |
60 FROM_HERE, | 60 FROM_HERE, |
61 base::Bind(&HostResolverImplChromeOSTest::InitializeHostResolver, | 61 base::Bind(&HostResolverImplChromeOSTest::InitializeHostResolver, |
62 base::Unretained(this))); | 62 base::Unretained(this))); |
63 io_message_loop_.RunUntilIdle(); | 63 io_message_loop_.RunUntilIdle(); |
64 | 64 |
65 // Run the main message loop to create the network observer and initialize | 65 // Run the main message loop to create the network observer and initialize |
66 // the ip address values. | 66 // the ip address values. |
67 base::RunLoop().RunUntilIdle(); | 67 base::RunLoop().RunUntilIdle(); |
68 } | 68 } |
69 | 69 |
70 virtual void TearDown() OVERRIDE { | 70 virtual void TearDown() override { |
71 network_state_handler_.reset(); | 71 network_state_handler_.reset(); |
72 chromeos::DBusThreadManager::Shutdown(); | 72 chromeos::DBusThreadManager::Shutdown(); |
73 } | 73 } |
74 | 74 |
75 protected: | 75 protected: |
76 // Run from main (UI) message loop, calls Resolve on IO message loop. | 76 // Run from main (UI) message loop, calls Resolve on IO message loop. |
77 int CallResolve(net::HostResolver::RequestInfo& info) { | 77 int CallResolve(net::HostResolver::RequestInfo& info) { |
78 io_message_loop_.PostTask( | 78 io_message_loop_.PostTask( |
79 FROM_HERE, | 79 FROM_HERE, |
80 base::Bind(&HostResolverImplChromeOSTest::Resolve, | 80 base::Bind(&HostResolverImplChromeOSTest::Resolve, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 EXPECT_EQ(expected, addresses_[0].ToString()); | 163 EXPECT_EQ(expected, addresses_[0].ToString()); |
164 | 164 |
165 info.set_address_family(net::ADDRESS_FAMILY_IPV6); | 165 info.set_address_family(net::ADDRESS_FAMILY_IPV6); |
166 EXPECT_EQ(net::OK, CallResolve(info)); | 166 EXPECT_EQ(net::OK, CallResolve(info)); |
167 ASSERT_EQ(2u, addresses_.size()); | 167 ASSERT_EQ(2u, addresses_.size()); |
168 expected = base::StringPrintf("[%s]:%d", kTestIPv6Address, 0); | 168 expected = base::StringPrintf("[%s]:%d", kTestIPv6Address, 0); |
169 EXPECT_EQ(expected, addresses_[0].ToString()); | 169 EXPECT_EQ(expected, addresses_[0].ToString()); |
170 expected = base::StringPrintf("%s:%d", kTestIPv4Address, 0); | 170 expected = base::StringPrintf("%s:%d", kTestIPv4Address, 0); |
171 EXPECT_EQ(expected, addresses_[1].ToString()); | 171 EXPECT_EQ(expected, addresses_[1].ToString()); |
172 } | 172 } |
OLD | NEW |