OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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. | |
4 | |
5 #include "base/bind.h" | |
6 #include "base/memory/weak_ptr.h" | |
7 #include "base/message_loop.h" | |
8 #include "base/run_loop.h" | |
9 #include "chrome/browser/net/dns_probe_runner.h" | |
10 #include "chrome/browser/net/dns_probe_test_util.h" | |
11 #include "content/public/test/test_browser_thread_bundle.h" | |
12 #include "net/dns/dns_client.h" | |
13 #include "testing/gtest/include/gtest/gtest.h" | |
14 | |
15 using base::MessageLoopForIO; | |
16 using base::RunLoop; | |
17 using content::TestBrowserThreadBundle; | |
18 using net::MockDnsClientRule; | |
19 | |
20 namespace chrome_browser_net { | |
21 | |
22 namespace { | |
23 | |
24 class TestDnsProbeRunnerCallback { | |
25 public: | |
26 TestDnsProbeRunnerCallback() | |
27 : callback_(base::Bind(&TestDnsProbeRunnerCallback::OnCalled, | |
28 base::Unretained(this))), | |
29 called_(false) {} | |
30 | |
31 const base::Closure& callback() const { return callback_; } | |
32 bool called() const { return called_; } | |
33 | |
34 private: | |
35 void OnCalled() { | |
36 DCHECK(!called_); | |
37 called_ = true; | |
38 } | |
39 | |
40 base::Closure callback_; | |
41 bool called_; | |
42 }; | |
43 | |
44 class DnsProbeRunnerTest : public testing::Test { | |
45 protected: | |
46 void RunTest(MockDnsClientRule::Result good_query_result, | |
mmenke
2013/06/25 17:40:27
nit: We no longer do a bad query, so should get r
Deprecated (see juliatuttle)
2013/06/26 22:23:56
Done.
| |
47 DnsProbeRunner::Result expected_probe_result); | |
48 | |
49 TestBrowserThreadBundle bundle_; | |
50 DnsProbeRunner runner_; | |
51 }; | |
52 | |
53 void DnsProbeRunnerTest::RunTest( | |
54 MockDnsClientRule::Result good_query_result, | |
55 DnsProbeRunner::Result expected_probe_result) { | |
56 TestDnsProbeRunnerCallback callback; | |
57 | |
58 runner_.SetClient(CreateMockDnsClientForProbes(good_query_result)); | |
59 runner_.RunProbe(callback.callback()); | |
60 if (good_query_result != MockDnsClientRule::FAIL_SYNC) | |
61 EXPECT_TRUE(runner_.IsRunning()); | |
62 | |
63 RunLoop().RunUntilIdle(); | |
64 EXPECT_FALSE(runner_.IsRunning()); | |
65 EXPECT_TRUE(callback.called()); | |
66 EXPECT_EQ(expected_probe_result, runner_.result()); | |
67 } | |
68 | |
69 TEST_F(DnsProbeRunnerTest, Null) { | |
70 // Test that we can simply construct and destroy a DnsProbeRunner. | |
71 } | |
mmenke
2013/06/25 17:40:27
I don't think we really need this one.
Deprecated (see juliatuttle)
2013/06/26 22:23:56
I've had them crash before, but okay.
| |
72 | |
73 TEST_F(DnsProbeRunnerTest, Probe_OK) { | |
74 RunTest(MockDnsClientRule::OK, DnsProbeRunner::CORRECT); | |
75 } | |
76 | |
77 TEST_F(DnsProbeRunnerTest, Probe_EMPTY) { | |
78 RunTest(MockDnsClientRule::EMPTY, DnsProbeRunner::INCORRECT); | |
79 } | |
80 | |
81 TEST_F(DnsProbeRunnerTest, Probe_TIMEOUT) { | |
82 RunTest(MockDnsClientRule::TIMEOUT, DnsProbeRunner::UNREACHABLE); | |
83 } | |
84 | |
85 TEST_F(DnsProbeRunnerTest, Probe_FAIL_ASYNC) { | |
86 RunTest(MockDnsClientRule::FAIL_ASYNC, DnsProbeRunner::INCORRECT); | |
87 } | |
88 | |
89 TEST_F(DnsProbeRunnerTest, Probe_FAIL_SYNC) { | |
90 RunTest(MockDnsClientRule::FAIL_SYNC, DnsProbeRunner::INCORRECT); | |
91 } | |
92 | |
93 TEST_F(DnsProbeRunnerTest, TwoProbes) { | |
94 RunTest(MockDnsClientRule::OK, DnsProbeRunner::CORRECT); | |
95 RunTest(MockDnsClientRule::EMPTY, DnsProbeRunner::INCORRECT); | |
96 } | |
97 | |
98 } // namespace | |
99 | |
100 } // namespace chrome_browser_net | |
OLD | NEW |