Index: net/proxy/proxy_script_decider_unittest.cc |
diff --git a/net/proxy/proxy_script_decider_unittest.cc b/net/proxy/proxy_script_decider_unittest.cc |
index 977bd4df642b49788221d509273671cb2b4638e2..efd87d0de04430bcb17db05c9ed281f688fb8f86 100644 |
--- a/net/proxy/proxy_script_decider_unittest.cc |
+++ b/net/proxy/proxy_script_decider_unittest.cc |
@@ -14,11 +14,13 @@ |
#include "net/base/net_log.h" |
#include "net/base/net_log_unittest.h" |
#include "net/base/test_completion_callback.h" |
+#include "net/dns/mock_host_resolver.h" |
#include "net/proxy/dhcp_proxy_script_fetcher.h" |
#include "net/proxy/proxy_config.h" |
#include "net/proxy/proxy_resolver.h" |
#include "net/proxy/proxy_script_decider.h" |
#include "net/proxy/proxy_script_fetcher.h" |
+#include "net/url_request/url_request_context.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace net { |
@@ -93,7 +95,8 @@ class Rules { |
class RuleBasedProxyScriptFetcher : public ProxyScriptFetcher { |
public: |
- explicit RuleBasedProxyScriptFetcher(const Rules* rules) : rules_(rules) {} |
+ explicit RuleBasedProxyScriptFetcher(const Rules* rules) |
+ : rules_(rules), request_context_(NULL) {} |
// ProxyScriptFetcher implementation. |
virtual int Fetch(const GURL& url, |
@@ -109,10 +112,17 @@ class RuleBasedProxyScriptFetcher : public ProxyScriptFetcher { |
virtual void Cancel() OVERRIDE {} |
- virtual URLRequestContext* GetRequestContext() const OVERRIDE { return NULL; } |
+ virtual void SetRequestContext(URLRequestContext* context) { |
szym
2013/09/11 14:06:22
nit: move this out of here, so that the "ProxyScri
Elly Fong-Jones
2013/09/11 20:20:37
Done.
|
+ request_context_ = context; |
+ } |
+ |
+ virtual URLRequestContext* GetRequestContext() const OVERRIDE { |
+ return request_context_; |
+ } |
private: |
const Rules* rules_; |
+ URLRequestContext* request_context_; |
}; |
// Succeed using custom PAC script. |
@@ -243,6 +253,81 @@ TEST(ProxyScriptDeciderTest, AutodetectSuccess) { |
EXPECT_EQ(rule.url, decider.effective_config().pac_url()); |
} |
+class ProxyScriptDeciderQuickCheckTest : public ::testing::Test { |
+ public: |
+ ProxyScriptDeciderQuickCheckTest() |
+ : rule_(rules_.AddSuccessRule("http://wpad/wpad.dat")), |
+ fetcher_(&rules_) { } |
+ |
+ virtual void SetUp() { |
szym
2013/09/11 14:06:22
OVERRIDE
Elly Fong-Jones
2013/09/11 20:20:37
Done.
|
+ request_context_.set_host_resolver(&resolver_); |
+ fetcher_.SetRequestContext(&request_context_); |
+ config_.set_auto_detect(true); |
+ decider_.reset(new ProxyScriptDecider(&fetcher_, &dhcp_fetcher_, NULL)); |
+ } |
+ |
+ virtual int StartDecider() { |
szym
2013/09/11 14:06:22
why virtual?
Elly Fong-Jones
2013/09/11 20:20:37
Habit. Removed.
|
+ return decider()->Start(config_, base::TimeDelta(), true, |
+ callback_.callback()); |
+ } |
+ |
+ Rules::Rule* rule() { return &rule_; } |
+ ProxyScriptDecider* decider() { return decider_.get(); } |
+ MockHostResolver* resolver() { return &resolver_; } |
+ |
+ private: |
szym
2013/09/11 14:06:22
I'd suggest making this protected and using direct
Elly Fong-Jones
2013/09/11 20:20:37
Done.
|
+ URLRequestContext request_context_; |
+ MockHostResolver resolver_; |
+ |
+ Rules rules_; |
+ Rules::Rule rule_; |
+ RuleBasedProxyScriptFetcher fetcher_; |
+ DoNothingDhcpProxyScriptFetcher dhcp_fetcher_; |
+ |
+ TestCompletionCallback callback_; |
+ |
+ ProxyConfig config_; |
+ |
+ scoped_ptr<ProxyScriptDecider> decider_; |
+}; |
+ |
+TEST_F(ProxyScriptDeciderQuickCheckTest, SyncSuccess) { |
+ resolver()->set_synchronous_mode(true); |
+ resolver()->rules()->AddRule("wpad", "1.2.3.4"); |
+ |
+ EXPECT_EQ(OK, StartDecider()); |
+ EXPECT_EQ(rule()->text(), decider()->script_data()->utf16()); |
+ |
+ EXPECT_TRUE(decider()->effective_config().has_pac_url()); |
+ EXPECT_EQ(rule()->url, decider()->effective_config().pac_url()); |
+} |
+ |
+TEST_F(ProxyScriptDeciderQuickCheckTest, AsyncSuccess) { |
+ resolver()->set_ondemand_mode(true); |
+ resolver()->rules()->AddRule("wpad", "1.2.3.4"); |
+ |
+ EXPECT_EQ(ERR_IO_PENDING, StartDecider()); |
+ ASSERT_TRUE(resolver()->has_pending_requests()); |
+ resolver()->ResolveAllPending(); |
+ // Let the resolutions complete. |
+ base::MessageLoop::current()->RunUntilIdle(); |
szym
2013/09/11 14:06:22
You should callback_.WaitForResult rather than Run
Elly Fong-Jones
2013/09/11 20:20:37
Oh man, I never knew about WaitForResult! This als
|
+ EXPECT_FALSE(resolver()->has_pending_requests()); |
+ EXPECT_EQ(rule()->text(), decider()->script_data()->utf16()); |
+ EXPECT_TRUE(decider()->effective_config().has_pac_url()); |
+ EXPECT_EQ(rule()->url, decider()->effective_config().pac_url()); |
+} |
+ |
+TEST_F(ProxyScriptDeciderQuickCheckTest, QuickCheckAsyncFail) { |
+ resolver()->set_ondemand_mode(true); |
+ resolver()->rules()->AddSimulatedFailure("wpad"); |
+ EXPECT_EQ(ERR_IO_PENDING, StartDecider()); |
+ // let the timer run |
szym
2013/09/11 14:06:22
I don't understand the comment. There's barely any
Elly Fong-Jones
2013/09/11 20:20:37
Done.
|
+ ASSERT_TRUE(resolver()->has_pending_requests()); |
+ resolver()->ResolveAllPending(); |
+ base::MessageLoop::current()->RunUntilIdle(); |
+ EXPECT_FALSE(decider()->effective_config().has_pac_url()); |
+} |
+ |
szym
2013/09/11 14:06:22
You need a test which exercises the quick check ti
Elly Fong-Jones
2013/09/11 20:20:37
Done.
|
// Fails at WPAD (downloading), but succeeds in choosing the custom PAC. |
TEST(ProxyScriptDeciderTest, AutodetectFailCustomSuccess1) { |
Rules rules; |