Chromium Code Reviews| Index: chrome/browser/net/pref_proxy_config_service_unittest.cc |
| diff --git a/chrome/browser/net/pref_proxy_config_service_unittest.cc b/chrome/browser/net/pref_proxy_config_service_unittest.cc |
| index 75b6f82e09824025835b9319c59d6dcac0007b38..632244784e401e151acc11b52c7e1edcdb634cf8 100644 |
| --- a/chrome/browser/net/pref_proxy_config_service_unittest.cc |
| +++ b/chrome/browser/net/pref_proxy_config_service_unittest.cc |
| @@ -26,14 +26,17 @@ const char kFixedPacUrl[] = "http://chromium.org/fixed_pac_url"; |
| // Testing proxy config service that allows us to fire notifications at will. |
| class TestProxyConfigService : public net::ProxyConfigService { |
| public: |
| - explicit TestProxyConfigService(const net::ProxyConfig& config) |
| - : config_(config) { |
| - } |
| + explicit TestProxyConfigService(const net::ProxyConfig& config, |
|
eroman
2011/03/30 21:42:31
nit: remove "explicit"
Mattias Nissler (ping if slow)
2011/03/31 14:04:47
Done.
|
| + ConfigAvailability availability) |
| + : config_(config), |
| + availability_(availability) {} |
| - void SetProxyConfig(const net::ProxyConfig config) { |
| + void SetProxyConfig(const net::ProxyConfig config, |
| + ConfigAvailability availability) { |
| config_ = config; |
| + availability_ = availability; |
| FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_, |
| - OnProxyConfigChanged(config_)); |
| + OnProxyConfigChanged(config, availability)); |
| } |
| private: |
| @@ -45,19 +48,23 @@ class TestProxyConfigService : public net::ProxyConfigService { |
| observers_.RemoveObserver(observer); |
| } |
| - virtual bool GetLatestProxyConfig(net::ProxyConfig* config) { |
| + virtual net::ProxyConfigService::ConfigAvailability GetLatestProxyConfig( |
| + net::ProxyConfig* config) { |
| *config = config_; |
| - return true; |
| + return availability_; |
| } |
| net::ProxyConfig config_; |
| + ConfigAvailability availability_; |
| ObserverList<net::ProxyConfigService::Observer, true> observers_; |
| }; |
| // A mock observer for capturing callbacks. |
| class MockObserver : public net::ProxyConfigService::Observer { |
| public: |
| - MOCK_METHOD1(OnProxyConfigChanged, void(const net::ProxyConfig&)); |
| + MOCK_METHOD2(OnProxyConfigChanged, |
| + void(const net::ProxyConfig&, |
| + net::ProxyConfigService::ConfigAvailability)); |
| }; |
| template<typename TESTBASE> |
| @@ -71,7 +78,9 @@ class PrefProxyConfigServiceTestBase : public TESTBASE { |
| ASSERT_TRUE(pref_service); |
| PrefProxyConfigService::RegisterPrefs(pref_service); |
| fixed_config_.set_pac_url(GURL(kFixedPacUrl)); |
| - delegate_service_ = new TestProxyConfigService(fixed_config_); |
| + delegate_service_ = |
| + new TestProxyConfigService(fixed_config_, |
| + net::ProxyConfigService::CONFIG_VALID); |
| proxy_config_tracker_ = new PrefProxyConfigTracker(pref_service); |
| proxy_config_service_.reset( |
| new PrefProxyConfigService(proxy_config_tracker_.get(), |
| @@ -108,7 +117,8 @@ class PrefProxyConfigServiceTest |
| TEST_F(PrefProxyConfigServiceTest, BaseConfiguration) { |
| net::ProxyConfig actual_config; |
| - proxy_config_service_->GetLatestProxyConfig(&actual_config); |
| + EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, |
| + proxy_config_service_->GetLatestProxyConfig(&actual_config)); |
| EXPECT_EQ(GURL(kFixedPacUrl), actual_config.pac_url()); |
| } |
| @@ -119,7 +129,8 @@ TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) { |
| loop_.RunAllPending(); |
| net::ProxyConfig actual_config; |
| - proxy_config_service_->GetLatestProxyConfig(&actual_config); |
| + EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, |
| + proxy_config_service_->GetLatestProxyConfig(&actual_config)); |
| EXPECT_FALSE(actual_config.auto_detect()); |
| EXPECT_EQ(net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, |
| actual_config.proxy_rules().type); |
| @@ -131,7 +142,8 @@ TEST_F(PrefProxyConfigServiceTest, DynamicPrefOverrides) { |
| ProxyConfigDictionary::CreateAutoDetect()); |
| loop_.RunAllPending(); |
| - proxy_config_service_->GetLatestProxyConfig(&actual_config); |
| + EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, |
| + proxy_config_service_->GetLatestProxyConfig(&actual_config)); |
| EXPECT_TRUE(actual_config.auto_detect()); |
| } |
| @@ -143,15 +155,17 @@ MATCHER_P(ProxyConfigMatches, config, "") { |
| } |
| TEST_F(PrefProxyConfigServiceTest, Observers) { |
| + const net::ProxyConfigService::ConfigAvailability CONFIG_VALID = |
| + net::ProxyConfigService::CONFIG_VALID; |
| MockObserver observer; |
| proxy_config_service_->AddObserver(&observer); |
| // Firing the observers in the delegate should trigger a notification. |
| net::ProxyConfig config2; |
| config2.set_auto_detect(true); |
| - EXPECT_CALL(observer, |
| - OnProxyConfigChanged(ProxyConfigMatches(config2))).Times(1); |
| - delegate_service_->SetProxyConfig(config2); |
| + EXPECT_CALL(observer, OnProxyConfigChanged(ProxyConfigMatches(config2), |
| + CONFIG_VALID)).Times(1); |
| + delegate_service_->SetProxyConfig(config2, CONFIG_VALID); |
| loop_.RunAllPending(); |
| Mock::VerifyAndClearExpectations(&observer); |
| @@ -159,8 +173,8 @@ TEST_F(PrefProxyConfigServiceTest, Observers) { |
| net::ProxyConfig pref_config; |
| pref_config.set_pac_url(GURL(kFixedPacUrl)); |
| - EXPECT_CALL(observer, |
| - OnProxyConfigChanged(ProxyConfigMatches(pref_config))).Times(1); |
| + EXPECT_CALL(observer, OnProxyConfigChanged(ProxyConfigMatches(pref_config), |
| + CONFIG_VALID)).Times(1); |
| pref_service_->SetManagedPref( |
| prefs::kProxy, |
| ProxyConfigDictionary::CreatePacScript(kFixedPacUrl)); |
| @@ -170,15 +184,15 @@ TEST_F(PrefProxyConfigServiceTest, Observers) { |
| // Since there are pref overrides, delegate changes should be ignored. |
| net::ProxyConfig config3; |
| config3.proxy_rules().ParseFromString("http=config3:80"); |
| - EXPECT_CALL(observer, OnProxyConfigChanged(_)).Times(0); |
| + EXPECT_CALL(observer, OnProxyConfigChanged(_, _)).Times(0); |
| fixed_config_.set_auto_detect(true); |
| - delegate_service_->SetProxyConfig(config3); |
| + delegate_service_->SetProxyConfig(config3, CONFIG_VALID); |
| loop_.RunAllPending(); |
| Mock::VerifyAndClearExpectations(&observer); |
| // Clear the override should switch back to the fixed configuration. |
| - EXPECT_CALL(observer, |
| - OnProxyConfigChanged(ProxyConfigMatches(config3))).Times(1); |
| + EXPECT_CALL(observer, OnProxyConfigChanged(ProxyConfigMatches(config3), |
| + CONFIG_VALID)).Times(1); |
| pref_service_->RemoveManagedPref(prefs::kProxy); |
| loop_.RunAllPending(); |
| Mock::VerifyAndClearExpectations(&observer); |
| @@ -186,11 +200,65 @@ TEST_F(PrefProxyConfigServiceTest, Observers) { |
| // Delegate service notifications should show up again. |
| net::ProxyConfig config4; |
| config4.proxy_rules().ParseFromString("socks:config4"); |
| + EXPECT_CALL(observer, OnProxyConfigChanged(ProxyConfigMatches(config4), |
| + CONFIG_VALID)).Times(1); |
| + delegate_service_->SetProxyConfig(config4, CONFIG_VALID); |
| + loop_.RunAllPending(); |
| + Mock::VerifyAndClearExpectations(&observer); |
| + |
| + proxy_config_service_->RemoveObserver(&observer); |
| +} |
| + |
| +TEST_F(PrefProxyConfigServiceTest, Fallback) { |
| + const net::ProxyConfigService::ConfigAvailability CONFIG_VALID = |
| + net::ProxyConfigService::CONFIG_VALID; |
| + MockObserver observer; |
| + net::ProxyConfig actual_config; |
| + delegate_service_->SetProxyConfig(net::ProxyConfig::CreateDirect(), |
| + net::ProxyConfigService::CONFIG_UNSET); |
| + proxy_config_service_->AddObserver(&observer); |
| + |
| + // Prepare test data. |
| + net::ProxyConfig recommended_config = net::ProxyConfig::CreateAutoDetect(); |
| + net::ProxyConfig user_config = |
| + net::ProxyConfig::CreateFromCustomPacURL(GURL(kFixedPacUrl)); |
| + |
| + // Set a recommended pref. |
| + EXPECT_CALL(observer, |
| + OnProxyConfigChanged(ProxyConfigMatches(recommended_config), |
| + CONFIG_VALID)).Times(1); |
| + pref_service_->SetRecommendedPref( |
| + prefs::kProxy, |
| + ProxyConfigDictionary::CreateAutoDetect()); |
| + loop_.RunAllPending(); |
| + Mock::VerifyAndClearExpectations(&observer); |
| + EXPECT_EQ(CONFIG_VALID, |
| + proxy_config_service_->GetLatestProxyConfig(&actual_config)); |
| + EXPECT_THAT(actual_config, ProxyConfigMatches(recommended_config)); |
| + |
| + // Override in user prefs. |
| + EXPECT_CALL(observer, |
| + OnProxyConfigChanged(ProxyConfigMatches(user_config), |
| + CONFIG_VALID)).Times(1); |
| + pref_service_->SetManagedPref( |
| + prefs::kProxy, |
| + ProxyConfigDictionary::CreatePacScript(kFixedPacUrl)); |
| + loop_.RunAllPending(); |
| + Mock::VerifyAndClearExpectations(&observer); |
| + EXPECT_EQ(CONFIG_VALID, |
| + proxy_config_service_->GetLatestProxyConfig(&actual_config)); |
| + EXPECT_THAT(actual_config, ProxyConfigMatches(user_config)); |
| + |
| + // Go back to recommended pref. |
| EXPECT_CALL(observer, |
| - OnProxyConfigChanged(ProxyConfigMatches(config4))).Times(1); |
| - delegate_service_->SetProxyConfig(config4); |
| + OnProxyConfigChanged(ProxyConfigMatches(recommended_config), |
| + CONFIG_VALID)).Times(1); |
| + pref_service_->RemoveManagedPref(prefs::kProxy); |
| loop_.RunAllPending(); |
| Mock::VerifyAndClearExpectations(&observer); |
| + EXPECT_EQ(CONFIG_VALID, |
| + proxy_config_service_->GetLatestProxyConfig(&actual_config)); |
| + EXPECT_THAT(actual_config, ProxyConfigMatches(recommended_config)); |
| proxy_config_service_->RemoveObserver(&observer); |
| } |
| @@ -257,7 +325,8 @@ class PrefProxyConfigServiceCommandLineTest |
| TEST_P(PrefProxyConfigServiceCommandLineTest, CommandLine) { |
| net::ProxyConfig config; |
| - proxy_config_service_->GetLatestProxyConfig(&config); |
| + EXPECT_EQ(net::ProxyConfigService::CONFIG_VALID, |
| + proxy_config_service_->GetLatestProxyConfig(&config)); |
| if (GetParam().is_null) { |
| EXPECT_EQ(GURL(kFixedPacUrl), config.pac_url()); |