OLD | NEW |
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 "chrome/browser/net/dns_probe_service.h" | 5 #include "chrome/browser/net/dns_probe_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "chrome/browser/net/dns_probe_job.h" | 12 #include "chrome/browser/net/dns_probe_job.h" |
13 #include "chrome/common/net/net_error_info.h" | 13 #include "chrome/common/net/net_error_info.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using chrome_common_net::DnsProbeResult; | 16 using chrome_common_net::DnsProbeResult; |
17 | 17 |
18 namespace chrome_browser_net { | 18 namespace chrome_browser_net { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 class MockDnsProbeJob : public DnsProbeJob { | 22 class MockDnsProbeJob : public DnsProbeJob { |
23 public: | 23 public: |
24 MockDnsProbeJob(const CallbackType& callback, | 24 MockDnsProbeJob(const CallbackType& callback, |
25 DnsProbeJob::Result result) | 25 DnsProbeJob::Result result) |
26 : weak_factory_(this) { | 26 : weak_factory_(this) { |
27 MessageLoop::current()->PostTask( | 27 base::MessageLoop::current()->PostTask( |
28 FROM_HERE, | 28 FROM_HERE, |
29 base::Bind(&MockDnsProbeJob::CallCallback, | 29 base::Bind(&MockDnsProbeJob::CallCallback, |
30 weak_factory_.GetWeakPtr(), | 30 weak_factory_.GetWeakPtr(), |
31 callback, | 31 callback, |
32 result)); | 32 result)); |
33 } | 33 } |
34 | 34 |
35 virtual ~MockDnsProbeJob() { } | 35 virtual ~MockDnsProbeJob() { } |
36 | 36 |
37 private: | 37 private: |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 void RunUntilIdle() { | 124 void RunUntilIdle() { |
125 base::RunLoop run_loop; | 125 base::RunLoop run_loop; |
126 run_loop.RunUntilIdle(); | 126 run_loop.RunUntilIdle(); |
127 } | 127 } |
128 | 128 |
129 void Reset() { | 129 void Reset() { |
130 service_.ResetJobsCreated(); | 130 service_.ResetJobsCreated(); |
131 callback_called_ = false; | 131 callback_called_ = false; |
132 } | 132 } |
133 | 133 |
134 MessageLoopForIO message_loop_; | 134 base::MessageLoopForIO message_loop_; |
135 TestDnsProbeService service_; | 135 TestDnsProbeService service_; |
136 bool callback_called_; | 136 bool callback_called_; |
137 DnsProbeResult callback_result_; | 137 DnsProbeResult callback_result_; |
138 | 138 |
139 private: | 139 private: |
140 void ProbeCallback(DnsProbeResult result) { | 140 void ProbeCallback(DnsProbeResult result) { |
141 callback_called_ = true; | 141 callback_called_ = true; |
142 callback_result_ = result; | 142 callback_result_ = result; |
143 } | 143 } |
144 }; | 144 }; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 211 |
212 Reset(); | 212 Reset(); |
213 | 213 |
214 RunUntilIdle(); | 214 RunUntilIdle(); |
215 EXPECT_FALSE(callback_called_); | 215 EXPECT_FALSE(callback_called_); |
216 } | 216 } |
217 | 217 |
218 } // namespace | 218 } // namespace |
219 | 219 |
220 } // namespace chrome_browser_net | 220 } // namespace chrome_browser_net |
OLD | NEW |