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

Side by Side Diff: chrome/browser/net/dns_probe_runner_unittest.cc

Issue 13270005: Display DNS probe results. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Tweak things, clean up unit tests Created 7 years, 6 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
OLDNEW
(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 const DnsProbeRunner::ProbeCallback& callback() const;
szym 2013/06/13 20:50:48 Put the accessor code inline.
Deprecated (see juliatuttle) 2013/06/18 19:36:37 Done.
28 bool called() const;
29 DnsProbeRunner::Result result() const;
30
31 private:
32 void OnCalled(DnsProbeRunner::Result result);
33
34 DnsProbeRunner::ProbeCallback callback_;
35 bool called_;
36 DnsProbeRunner::Result result_;
37 };
38
39 TestDnsProbeRunnerCallback::TestDnsProbeRunnerCallback()
40 : callback_(base::Bind(&TestDnsProbeRunnerCallback::OnCalled,
41 base::Unretained(this))),
42 called_(false),
43 result_(DnsProbeRunner::UNKNOWN) {}
44
45 const DnsProbeRunner::ProbeCallback&
46 TestDnsProbeRunnerCallback::callback() const {
47 return callback_;
48 }
49
50 bool TestDnsProbeRunnerCallback::called() const {
51 return called_;
52 }
53
54 DnsProbeRunner::Result TestDnsProbeRunnerCallback::result() const {
55 DCHECK(called_);
56 return result_;
57 }
58
59 void TestDnsProbeRunnerCallback::OnCalled(DnsProbeRunner::Result result) {
60 DCHECK(!called_);
61 called_ = true;
62 result_ = result;
63 }
64
65 class DnsProbeRunnerTest : public testing::Test {
66 protected:
67 void RunTest(MockDnsClientRule::Result good_query_result,
68 DnsProbeRunner::Result expected_probe_result);
69
70 TestBrowserThreadBundle bundle_;
71 DnsProbeRunner runner_;
72 };
73
74 void DnsProbeRunnerTest::RunTest(
75 MockDnsClientRule::Result good_query_result,
76 DnsProbeRunner::Result expected_probe_result) {
77 TestDnsProbeRunnerCallback callback;
78
79 runner_.SetClient(CreateMockDnsClientForProbes(good_query_result));
80 runner_.RunProbe(callback.callback());
81 if (good_query_result != MockDnsClientRule::FAIL_SYNC)
82 EXPECT_TRUE(runner_.IsRunning());
83
84 RunLoop().RunUntilIdle();
85 EXPECT_FALSE(runner_.IsRunning());
86 EXPECT_TRUE(callback.called());
87 EXPECT_EQ(expected_probe_result, callback.result());
88 }
89
90 TEST_F(DnsProbeRunnerTest, Null) {
szym 2013/06/13 20:50:48 All it does is test constructor+destructor. If tha
Deprecated (see juliatuttle) 2013/06/18 19:36:37 Done.
91 }
92
93 TEST_F(DnsProbeRunnerTest, Probe_OK) {
94 RunTest(MockDnsClientRule::OK, DnsProbeRunner::CORRECT);
95 }
96
97 TEST_F(DnsProbeRunnerTest, Probe_EMPTY) {
98 RunTest(MockDnsClientRule::EMPTY, DnsProbeRunner::INCORRECT);
99 }
100
101 TEST_F(DnsProbeRunnerTest, Probe_TIMEOUT) {
102 RunTest(MockDnsClientRule::TIMEOUT, DnsProbeRunner::UNREACHABLE);
103 }
104
105 TEST_F(DnsProbeRunnerTest, Probe_FAIL_ASYNC) {
106 RunTest(MockDnsClientRule::FAIL_ASYNC, DnsProbeRunner::INCORRECT);
szym 2013/06/13 20:50:48 Consider (perhaps in a future CL) adding new MockD
Deprecated (see juliatuttle) 2013/06/18 19:36:37 Yeah, it'd be useful to be able to specify an erro
107 }
108
109 TEST_F(DnsProbeRunnerTest, Probe_FAIL_SYNC) {
110 RunTest(MockDnsClientRule::FAIL_SYNC, DnsProbeRunner::INCORRECT);
111 }
112
113 TEST_F(DnsProbeRunnerTest, TwoProbes) {
114 RunTest(MockDnsClientRule::OK, DnsProbeRunner::CORRECT);
115 RunTest(MockDnsClientRule::EMPTY, DnsProbeRunner::INCORRECT);
116 }
117
118 } // namespace
119
120 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698