diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-26 05:12:47 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-26 05:12:47 +0000 |
commit | 1b8740fcc945425012ecc755987286dd22a098f6 (patch) | |
tree | 263ebd87b1ac8b50af8303085043f4bd930bd42f /net/proxy/init_proxy_resolver_unittest.cc | |
parent | 924cad8b1c5bccdd34dd02d9391e57e5ed8a0f06 (diff) | |
download | chromium_src-1b8740fcc945425012ecc755987286dd22a098f6.zip chromium_src-1b8740fcc945425012ecc755987286dd22a098f6.tar.gz chromium_src-1b8740fcc945425012ecc755987286dd22a098f6.tar.bz2 |
Introduce an artificial 2 second delay after network IP address changes before re-running proxy auto-config.
During this time network requests will be stalled.
This is to work around a problem where DNS gives transient failures shortly after IP address changes.
BUG=50779
TEST=On a linux laptop switch between wireless networks while using auto-detect. When you switch to a network that contains the host 'wpad' verify that when InitProxyResolver runs it does not get a DNS error resolving 'wpad'. (Use about:net-internals to view this information).
Review URL: http://codereview.chromium.org/3151040
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57471 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/init_proxy_resolver_unittest.cc')
-rw-r--r-- | net/proxy/init_proxy_resolver_unittest.cc | 93 |
1 files changed, 83 insertions, 10 deletions
diff --git a/net/proxy/init_proxy_resolver_unittest.cc b/net/proxy/init_proxy_resolver_unittest.cc index 458cc53..11d7c5f 100644 --- a/net/proxy/init_proxy_resolver_unittest.cc +++ b/net/proxy/init_proxy_resolver_unittest.cc @@ -177,7 +177,7 @@ TEST(InitProxyResolverTest, CustomPacSucceeds) { TestCompletionCallback callback; CapturingNetLog log(CapturingNetLog::kUnbounded); InitProxyResolver init(&resolver, &fetcher, &log); - EXPECT_EQ(OK, init.Init(config, &callback)); + EXPECT_EQ(OK, init.Init(config, base::TimeDelta(), &callback)); EXPECT_EQ(rule.text(), resolver.script_data()->utf16()); // Check the NetLog was filled correctly. @@ -210,7 +210,8 @@ TEST(InitProxyResolverTest, CustomPacFails1) { TestCompletionCallback callback; CapturingNetLog log(CapturingNetLog::kUnbounded); InitProxyResolver init(&resolver, &fetcher, &log); - EXPECT_EQ(kFailedDownloading, init.Init(config, &callback)); + EXPECT_EQ(kFailedDownloading, + init.Init(config, base::TimeDelta(), &callback)); EXPECT_EQ(NULL, resolver.script_data()); // Check the NetLog was filled correctly. @@ -238,7 +239,7 @@ TEST(InitProxyResolverTest, CustomPacFails2) { TestCompletionCallback callback; InitProxyResolver init(&resolver, &fetcher, NULL); - EXPECT_EQ(kFailedParsing, init.Init(config, &callback)); + EXPECT_EQ(kFailedParsing, init.Init(config, base::TimeDelta(), &callback)); EXPECT_EQ(NULL, resolver.script_data()); } @@ -252,7 +253,7 @@ TEST(InitProxyResolverTest, HasNullProxyScriptFetcher) { TestCompletionCallback callback; InitProxyResolver init(&resolver, NULL, NULL); - EXPECT_EQ(ERR_UNEXPECTED, init.Init(config, &callback)); + EXPECT_EQ(ERR_UNEXPECTED, init.Init(config, base::TimeDelta(), &callback)); EXPECT_EQ(NULL, resolver.script_data()); } @@ -269,7 +270,7 @@ TEST(InitProxyResolverTest, AutodetectSuccess) { TestCompletionCallback callback; InitProxyResolver init(&resolver, &fetcher, NULL); - EXPECT_EQ(OK, init.Init(config, &callback)); + EXPECT_EQ(OK, init.Init(config, base::TimeDelta(), &callback)); EXPECT_EQ(rule.text(), resolver.script_data()->utf16()); } @@ -288,7 +289,7 @@ TEST(InitProxyResolverTest, AutodetectFailCustomSuccess1) { TestCompletionCallback callback; InitProxyResolver init(&resolver, &fetcher, NULL); - EXPECT_EQ(OK, init.Init(config, &callback)); + EXPECT_EQ(OK, init.Init(config, base::TimeDelta(), &callback)); EXPECT_EQ(rule.text(), resolver.script_data()->utf16()); } @@ -308,7 +309,7 @@ TEST(InitProxyResolverTest, AutodetectFailCustomSuccess2) { TestCompletionCallback callback; CapturingNetLog log(CapturingNetLog::kUnbounded); InitProxyResolver init(&resolver, &fetcher, &log); - EXPECT_EQ(OK, init.Init(config, &callback)); + EXPECT_EQ(OK, init.Init(config, base::TimeDelta(), &callback)); EXPECT_EQ(rule.text(), resolver.script_data()->utf16()); // Check the NetLog was filled correctly. @@ -356,7 +357,8 @@ TEST(InitProxyResolverTest, AutodetectFailCustomFails1) { TestCompletionCallback callback; InitProxyResolver init(&resolver, &fetcher, NULL); - EXPECT_EQ(kFailedDownloading, init.Init(config, &callback)); + EXPECT_EQ(kFailedDownloading, + init.Init(config, base::TimeDelta(), &callback)); EXPECT_EQ(NULL, resolver.script_data()); } @@ -375,7 +377,7 @@ TEST(InitProxyResolverTest, AutodetectFailCustomFails2) { TestCompletionCallback callback; InitProxyResolver init(&resolver, &fetcher, NULL); - EXPECT_EQ(kFailedParsing, init.Init(config, &callback)); + EXPECT_EQ(kFailedParsing, init.Init(config, base::TimeDelta(), &callback)); EXPECT_EQ(NULL, resolver.script_data()); } @@ -396,9 +398,80 @@ TEST(InitProxyResolverTest, AutodetectFailCustomSuccess2_NoFetch) { TestCompletionCallback callback; InitProxyResolver init(&resolver, &fetcher, NULL); - EXPECT_EQ(OK, init.Init(config, &callback)); + EXPECT_EQ(OK, init.Init(config, base::TimeDelta(), &callback)); EXPECT_EQ(rule.url, resolver.script_data()->url()); } +// This is a copy-paste of CustomPacFails1, with the exception that we give it +// a 1 millisecond delay. This means it will now complete asynchronously. +// Moreover, we test the NetLog to make sure it logged the pause. +TEST(InitProxyResolverTest, CustomPacFails1_WithPositiveDelay) { + Rules rules; + RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); + RuleBasedProxyScriptFetcher fetcher(&rules); + + ProxyConfig config; + config.set_pac_url(GURL("http://custom/proxy.pac")); + + rules.AddFailDownloadRule("http://custom/proxy.pac"); + + TestCompletionCallback callback; + CapturingNetLog log(CapturingNetLog::kUnbounded); + InitProxyResolver init(&resolver, &fetcher, &log); + EXPECT_EQ(ERR_IO_PENDING, + init.Init(config, base::TimeDelta::FromMilliseconds(1), + &callback)); + + EXPECT_EQ(kFailedDownloading, callback.WaitForResult()); + EXPECT_EQ(NULL, resolver.script_data()); + + // Check the NetLog was filled correctly. + EXPECT_EQ(6u, log.entries().size()); + EXPECT_TRUE(LogContainsBeginEvent( + log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); + EXPECT_TRUE(LogContainsBeginEvent( + log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_WAIT)); + EXPECT_TRUE(LogContainsEndEvent( + log.entries(), 2, NetLog::TYPE_INIT_PROXY_RESOLVER_WAIT)); + EXPECT_TRUE(LogContainsBeginEvent( + log.entries(), 3, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); + EXPECT_TRUE(LogContainsEndEvent( + log.entries(), 4, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); + EXPECT_TRUE(LogContainsEndEvent( + log.entries(), 5, NetLog::TYPE_INIT_PROXY_RESOLVER)); +} + +// This is a copy-paste of CustomPacFails1, with the exception that we give it +// a -5 second delay instead of a 0 ms delay. This change should have no effect +// so the rest of the test is unchanged. +TEST(InitProxyResolverTest, CustomPacFails1_WithNegativeDelay) { + Rules rules; + RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/); + RuleBasedProxyScriptFetcher fetcher(&rules); + + ProxyConfig config; + config.set_pac_url(GURL("http://custom/proxy.pac")); + + rules.AddFailDownloadRule("http://custom/proxy.pac"); + + TestCompletionCallback callback; + CapturingNetLog log(CapturingNetLog::kUnbounded); + InitProxyResolver init(&resolver, &fetcher, &log); + EXPECT_EQ(kFailedDownloading, + init.Init(config, base::TimeDelta::FromSeconds(-5), &callback)); + EXPECT_EQ(NULL, resolver.script_data()); + + // Check the NetLog was filled correctly. + EXPECT_EQ(4u, log.entries().size()); + EXPECT_TRUE(LogContainsBeginEvent( + log.entries(), 0, NetLog::TYPE_INIT_PROXY_RESOLVER)); + EXPECT_TRUE(LogContainsBeginEvent( + log.entries(), 1, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); + EXPECT_TRUE(LogContainsEndEvent( + log.entries(), 2, NetLog::TYPE_INIT_PROXY_RESOLVER_FETCH_PAC_SCRIPT)); + EXPECT_TRUE(LogContainsEndEvent( + log.entries(), 3, NetLog::TYPE_INIT_PROXY_RESOLVER)); +} + } // namespace } // namespace net |