diff options
author | ttuttle@chromium.org <ttuttle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-17 05:23:13 +0000 |
---|---|---|
committer | ttuttle@chromium.org <ttuttle@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-17 05:23:13 +0000 |
commit | 2ea1efe9660ee70c8eefb98dde76caac1c918005 (patch) | |
tree | b5b7e0ea619ae3df960f25d3c4ce23cbba335e2c /chrome/browser/net/dns_probe_runner_unittest.cc | |
parent | 3793b5f264db5e0ce9950d0e28e8748e5b8c56ff (diff) | |
download | chromium_src-2ea1efe9660ee70c8eefb98dde76caac1c918005.zip chromium_src-2ea1efe9660ee70c8eefb98dde76caac1c918005.tar.gz chromium_src-2ea1efe9660ee70c8eefb98dde76caac1c918005.tar.bz2 |
Display DNS probe results.
1. Modify the browser-side NetErrorTabHelper to send extra messages when it
starts or declines to start a DNS probe.
2. Create a new error domain, "dnsprobe", with errors for "might run a DNS
probe", "currently running a DNS probe", and all of the possible probe
results.
3. Modify ChromeContentRendererClient to give the renderer-side NetErrorHelper
a chance to choose the error strings before we call LocalizedError directly.
4. Catch DNS errors and provide the strings for the "might run a DNS probe"
pseudo-error instead.
5. Add a function to neterror.html that lets us re-render the template with a
new set of strings.
6. When we get a "probe started" message, replace the strings with those for
the "currently running a DNS probe" pseudo-error.
7. When we get a "probe finished" message, replace the strings with those for
the probe result.
8. When we get a "probe not run" message, replace the strings with those for
the original error we received.
BUG=156415
TEST=DnsProbeBrowserTest
Review URL: https://chromiumcodereview.appspot.com/13270005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211950 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net/dns_probe_runner_unittest.cc')
-rw-r--r-- | chrome/browser/net/dns_probe_runner_unittest.cc | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/chrome/browser/net/dns_probe_runner_unittest.cc b/chrome/browser/net/dns_probe_runner_unittest.cc new file mode 100644 index 0000000..5519da2 --- /dev/null +++ b/chrome/browser/net/dns_probe_runner_unittest.cc @@ -0,0 +1,95 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/bind.h" +#include "base/memory/weak_ptr.h" +#include "base/message_loop.h" +#include "base/run_loop.h" +#include "chrome/browser/net/dns_probe_runner.h" +#include "chrome/browser/net/dns_probe_test_util.h" +#include "content/public/test/test_browser_thread_bundle.h" +#include "net/dns/dns_client.h" +#include "testing/gtest/include/gtest/gtest.h" + +using base::MessageLoopForIO; +using base::RunLoop; +using content::TestBrowserThreadBundle; +using net::MockDnsClientRule; + +namespace chrome_browser_net { + +namespace { + +class TestDnsProbeRunnerCallback { + public: + TestDnsProbeRunnerCallback() + : callback_(base::Bind(&TestDnsProbeRunnerCallback::OnCalled, + base::Unretained(this))), + called_(false) {} + + const base::Closure& callback() const { return callback_; } + bool called() const { return called_; } + + private: + void OnCalled() { + EXPECT_FALSE(called_); + called_ = true; + } + + base::Closure callback_; + bool called_; +}; + +class DnsProbeRunnerTest : public testing::Test { + protected: + void RunTest(MockDnsClientRule::Result query_result, + DnsProbeRunner::Result expected_probe_result); + + TestBrowserThreadBundle bundle_; + DnsProbeRunner runner_; +}; + +void DnsProbeRunnerTest::RunTest( + MockDnsClientRule::Result query_result, + DnsProbeRunner::Result expected_probe_result) { + TestDnsProbeRunnerCallback callback; + + runner_.SetClient(CreateMockDnsClientForProbes(query_result)); + runner_.RunProbe(callback.callback()); + EXPECT_TRUE(runner_.IsRunning()); + + RunLoop().RunUntilIdle(); + EXPECT_FALSE(runner_.IsRunning()); + EXPECT_TRUE(callback.called()); + EXPECT_EQ(expected_probe_result, runner_.result()); +} + +TEST_F(DnsProbeRunnerTest, Probe_OK) { + RunTest(MockDnsClientRule::OK, DnsProbeRunner::CORRECT); +} + +TEST_F(DnsProbeRunnerTest, Probe_EMPTY) { + RunTest(MockDnsClientRule::EMPTY, DnsProbeRunner::INCORRECT); +} + +TEST_F(DnsProbeRunnerTest, Probe_TIMEOUT) { + RunTest(MockDnsClientRule::TIMEOUT, DnsProbeRunner::UNREACHABLE); +} + +TEST_F(DnsProbeRunnerTest, Probe_FAIL_ASYNC) { + RunTest(MockDnsClientRule::FAIL_ASYNC, DnsProbeRunner::INCORRECT); +} + +TEST_F(DnsProbeRunnerTest, Probe_FAIL_SYNC) { + RunTest(MockDnsClientRule::FAIL_SYNC, DnsProbeRunner::INCORRECT); +} + +TEST_F(DnsProbeRunnerTest, TwoProbes) { + RunTest(MockDnsClientRule::OK, DnsProbeRunner::CORRECT); + RunTest(MockDnsClientRule::EMPTY, DnsProbeRunner::INCORRECT); +} + +} // namespace + +} // namespace chrome_browser_net |