Index: chrome/browser/policy/device_management_policy_provider_unittest.cc |
diff --git a/chrome/browser/policy/device_management_policy_provider_unittest.cc b/chrome/browser/policy/device_management_policy_provider_unittest.cc |
index bd27e48683303cf27c7586b1e473ab355384f0af..d5038000b31f000d1c6f04b7c103affc8252070e 100644 |
--- a/chrome/browser/policy/device_management_policy_provider_unittest.cc |
+++ b/chrome/browser/policy/device_management_policy_provider_unittest.cc |
@@ -76,7 +76,6 @@ class DeviceManagementPolicyProviderTest : public testing::Test { |
loop_.RunAllPending(); |
} |
- protected: |
MockDeviceManagementBackend* backend_; // weak |
scoped_ptr<DeviceManagementPolicyProvider> provider_; |
@@ -127,13 +126,23 @@ TEST_F(DeviceManagementPolicyProviderTest, SecondProvide) { |
SimulateSuccessfulInitialPolicyFetch(); |
// Simulate a app relaunch by constructing a new provider. Policy should be |
- // immediately provided and no refresh should be triggered. |
+ // refreshed (since that might be the purpose of the app relaunch). |
CreateNewBackend(); |
- EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(0); |
+ EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(1); |
CreateNewProvider(); |
+ Mock::VerifyAndClearExpectations(backend_); |
+ |
+ // Simulate another app relaunch, this time against a failing backend. |
+ // Cached policy should still be available. |
+ CreateNewBackend(); |
+ backend_->AllShouldFail(); |
MockConfigurationPolicyStore store; |
+ EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(1); |
+ CreateNewProvider(); |
+ SimulateSuccessfulLoginAndRunPending(); |
EXPECT_CALL(store, Apply(kPolicyDisableSpdy, _)).Times(1); |
provider_->Provide(&store); |
+ ASSERT_EQ(1U, store.policy_map().size()); |
} |
// When policy is successfully fetched from the device management server, it |
@@ -144,9 +153,29 @@ TEST_F(DeviceManagementPolicyProviderTest, FetchTriggersRefresh) { |
registrar.Add(&observer, |
NotificationType::POLICY_CHANGED, |
NotificationService::AllSources()); |
- EXPECT_CALL(observer, |
- Observe(_, _, _)).Times(1); |
+ EXPECT_CALL(observer, Observe(_, _, _)).Times(1); |
SimulateSuccessfulInitialPolicyFetch(); |
} |
+TEST_F(DeviceManagementPolicyProviderTest, ErrorCausesNewRequest) { |
+ backend_->RegisterFailsOncePolicyFailsTwice(); |
+ provider_->set_policy_refresh_rate_ms(1000 * 1000); |
+ provider_->set_policy_refresh_max_earlier_ms(0); |
+ provider_->set_policy_refresh_error_delay_ms(0); |
+ provider_->set_token_fetch_error_delay_ms(0); |
+ EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(2); |
+ EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(3); |
+ SimulateSuccessfulLoginAndRunPending(); |
+} |
+ |
+TEST_F(DeviceManagementPolicyProviderTest, RefreshPolicies) { |
+ backend_->AllWorksFirstPolicyFailsLater(); |
+ provider_->set_policy_refresh_rate_ms(0); |
+ provider_->set_policy_refresh_max_earlier_ms(0); |
+ provider_->set_policy_refresh_error_delay_ms(1000 * 1000); |
+ EXPECT_CALL(*backend_, ProcessRegisterRequest(_, _, _, _)).Times(1); |
+ EXPECT_CALL(*backend_, ProcessPolicyRequest(_, _, _)).Times(4); |
+ SimulateSuccessfulLoginAndRunPending(); |
} |
+ |
+} // namespace policy |