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

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: Fix moar nits 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 : 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_);
mmenke 2013/06/26 15:48:20 Think we can just use an EXPECT here, so it trigge
Deprecated (see juliatuttle) 2013/06/26 22:23:56 Done.
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 query_result,
47 DnsProbeRunner::Result expected_probe_result);
48
49 TestBrowserThreadBundle bundle_;
50 DnsProbeRunner runner_;
51 };
52
53 void DnsProbeRunnerTest::RunTest(
54 MockDnsClientRule::Result query_result,
55 DnsProbeRunner::Result expected_probe_result) {
56 TestDnsProbeRunnerCallback callback;
57
58 runner_.SetClient(CreateMockDnsClientForProbes(query_result));
59 runner_.RunProbe(callback.callback());
60 if (query_result != MockDnsClientRule::FAIL_SYNC)
mmenke 2013/06/26 15:48:20 I don't think this conditional is needed any more.
Deprecated (see juliatuttle) 2013/06/26 22:23:56 Done.
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, Probe_OK) {
70 RunTest(MockDnsClientRule::OK, DnsProbeRunner::CORRECT);
71 }
72
73 TEST_F(DnsProbeRunnerTest, Probe_EMPTY) {
74 RunTest(MockDnsClientRule::EMPTY, DnsProbeRunner::INCORRECT);
75 }
76
77 TEST_F(DnsProbeRunnerTest, Probe_TIMEOUT) {
78 RunTest(MockDnsClientRule::TIMEOUT, DnsProbeRunner::UNREACHABLE);
79 }
80
81 TEST_F(DnsProbeRunnerTest, Probe_FAIL_ASYNC) {
82 RunTest(MockDnsClientRule::FAIL_ASYNC, DnsProbeRunner::INCORRECT);
83 }
84
85 TEST_F(DnsProbeRunnerTest, Probe_FAIL_SYNC) {
86 RunTest(MockDnsClientRule::FAIL_SYNC, DnsProbeRunner::INCORRECT);
87 }
88
89 TEST_F(DnsProbeRunnerTest, TwoProbes) {
90 RunTest(MockDnsClientRule::OK, DnsProbeRunner::CORRECT);
91 RunTest(MockDnsClientRule::EMPTY, DnsProbeRunner::INCORRECT);
92 }
93
94 } // namespace
95
96 } // namespace chrome_browser_net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698