Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: net/dns/address_sorter_unittest.cc

Issue 2607283002: Use TaskScheduler instead of WorkerPool in address_sorter_win.cc. (Closed)
Patch Set: Add ScopedTaskScheduler. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/dns/address_sorter_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/dns/address_sorter.h" 5 #include "net/dns/address_sorter.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <winsock2.h> 8 #include <winsock2.h>
9 #endif 9 #endif
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/test/scoped_task_scheduler.h"
13 #include "net/base/address_list.h" 15 #include "net/base/address_list.h"
14 #include "net/base/ip_address.h" 16 #include "net/base/ip_address.h"
15 #include "net/base/test_completion_callback.h" 17 #include "net/base/test_completion_callback.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
17 19
18 #if defined(OS_WIN) 20 #if defined(OS_WIN)
19 #include "net/base/winsock_init.h" 21 #include "net/base/winsock_init.h"
20 #endif 22 #endif
21 23
22 namespace net { 24 namespace net {
23 namespace { 25 namespace {
24 26
25 IPEndPoint MakeEndPoint(const std::string& str) { 27 IPEndPoint MakeEndPoint(const std::string& str) {
26 IPAddress addr; 28 IPAddress addr;
27 CHECK(addr.AssignFromIPLiteral(str)); 29 CHECK(addr.AssignFromIPLiteral(str));
28 return IPEndPoint(addr, 0); 30 return IPEndPoint(addr, 0);
29 } 31 }
30 32
31 void OnSortComplete(AddressList* result_buf, 33 void OnSortComplete(AddressList* result_buf,
32 const CompletionCallback& callback, 34 const CompletionCallback& callback,
33 bool success, 35 bool success,
34 const AddressList& result) { 36 const AddressList& result) {
35 if (success) 37 if (success)
36 *result_buf = result; 38 *result_buf = result;
37 callback.Run(success ? OK : ERR_FAILED); 39 callback.Run(success ? OK : ERR_FAILED);
38 } 40 }
39 41
40 TEST(AddressSorterTest, Sort) { 42 TEST(AddressSorterTest, Sort) {
43 base::test::ScopedTaskScheduler scoped_task_scheduler(
44 base::MessageLoop::current());
41 int expected_result = OK; 45 int expected_result = OK;
42 #if defined(OS_WIN) 46 #if defined(OS_WIN)
43 EnsureWinsockInit(); 47 EnsureWinsockInit();
44 SOCKET sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); 48 SOCKET sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
45 if (sock == INVALID_SOCKET) { 49 if (sock == INVALID_SOCKET) {
46 expected_result = ERR_FAILED; 50 expected_result = ERR_FAILED;
47 } else { 51 } else {
48 closesocket(sock); 52 closesocket(sock);
49 } 53 }
50 #endif 54 #endif
51 std::unique_ptr<AddressSorter> sorter(AddressSorter::CreateAddressSorter()); 55 std::unique_ptr<AddressSorter> sorter(AddressSorter::CreateAddressSorter());
52 AddressList list; 56 AddressList list;
53 list.push_back(MakeEndPoint("10.0.0.1")); 57 list.push_back(MakeEndPoint("10.0.0.1"));
54 list.push_back(MakeEndPoint("8.8.8.8")); 58 list.push_back(MakeEndPoint("8.8.8.8"));
55 list.push_back(MakeEndPoint("::1")); 59 list.push_back(MakeEndPoint("::1"));
56 list.push_back(MakeEndPoint("2001:4860:4860::8888")); 60 list.push_back(MakeEndPoint("2001:4860:4860::8888"));
57 61
58 AddressList result; 62 AddressList result;
59 TestCompletionCallback callback; 63 TestCompletionCallback callback;
60 sorter->Sort(list, base::Bind(&OnSortComplete, &result, 64 sorter->Sort(list, base::Bind(&OnSortComplete, &result,
61 callback.callback())); 65 callback.callback()));
62 EXPECT_EQ(expected_result, callback.WaitForResult()); 66 EXPECT_EQ(expected_result, callback.WaitForResult());
63 } 67 }
64 68
65 } // namespace 69 } // namespace
66 } // namespace net 70 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/dns/address_sorter_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698