Revert 208429 "Disable AutofillQueryXmlParserTest.ParseAutofillF..."
[chromium-blink-merge.git] / net / dns / address_sorter_unittest.cc
blob0c2be884d293a1c030160c7c6594f71e43dec5dc
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
3 // found in the LICENSE file.
5 #include "net/dns/address_sorter.h"
7 #if defined(OS_WIN)
8 #include <winsock2.h>
9 #endif
11 #include "base/bind.h"
12 #include "base/logging.h"
13 #include "net/base/address_list.h"
14 #include "net/base/net_util.h"
15 #include "net/base/test_completion_callback.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 #if defined(OS_WIN)
19 #include "net/base/winsock_init.h"
20 #endif
22 namespace net {
23 namespace {
25 IPEndPoint MakeEndPoint(const std::string& str) {
26 IPAddressNumber addr;
27 CHECK(ParseIPLiteralToNumber(str, &addr));
28 return IPEndPoint(addr, 0);
31 void OnSortComplete(AddressList* result_buf,
32 const CompletionCallback& callback,
33 bool success,
34 const AddressList& result) {
35 if (success)
36 *result_buf = result;
37 callback.Run(success ? OK : ERR_FAILED);
40 TEST(AddressSorterTest, Sort) {
41 int expected_result = OK;
42 #if defined(OS_WIN)
43 EnsureWinsockInit();
44 SOCKET sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
45 if (sock == INVALID_SOCKET) {
46 expected_result = ERR_FAILED;
47 } else {
48 closesocket(sock);
50 #endif
51 scoped_ptr<AddressSorter> sorter(AddressSorter::CreateAddressSorter());
52 AddressList list;
53 list.push_back(MakeEndPoint("10.0.0.1"));
54 list.push_back(MakeEndPoint("8.8.8.8"));
55 list.push_back(MakeEndPoint("::1"));
56 list.push_back(MakeEndPoint("2001:4860:4860::8888"));
58 AddressList result;
59 TestCompletionCallback callback;
60 sorter->Sort(list, base::Bind(&OnSortComplete, &result,
61 callback.callback()));
62 EXPECT_EQ(expected_result, callback.WaitForResult());
65 } // namespace
66 } // namespace net