Index: remoting/host/policy_hack/policy_watcher_unittest.cc |
diff --git a/remoting/host/policy_hack/policy_watcher_unittest.cc b/remoting/host/policy_hack/policy_watcher_unittest.cc |
index b19d92f4a3bd224e08a71894d4ed6273a88b42fe..0dbec33a813a7d103ee3b8216eeab4c52130784c 100644 |
--- a/remoting/host/policy_hack/policy_watcher_unittest.cc |
+++ b/remoting/host/policy_hack/policy_watcher_unittest.cc |
@@ -24,7 +24,9 @@ class PolicyWatcherTest : public testing::Test { |
virtual void SetUp() override { |
message_loop_proxy_ = base::MessageLoopProxy::current(); |
- policy_callback_ = base::Bind(&MockPolicyCallback::OnPolicyUpdate, |
+ policy_updated_callback_ = base::Bind(&MockPolicyCallback::OnPolicyUpdate, |
+ base::Unretained(&mock_policy_callback_)); |
Lambros
2014/11/14 01:42:47
nit: Wrong indentation. Should line up with first
Łukasz Anforowicz
2014/11/14 03:17:18
Ah, right. I was doing a search & replace of poli
|
+ policy_error_callback_ = base::Bind(&MockPolicyCallback::OnPolicyError, |
base::Unretained(&mock_policy_callback_)); |
policy_watcher_.reset(new FakePolicyWatcher(message_loop_proxy_)); |
nat_true_.SetBoolean(PolicyWatcher::kNatPolicyName, true); |
@@ -94,7 +96,9 @@ class PolicyWatcherTest : public testing::Test { |
protected: |
void StartWatching() { |
- policy_watcher_->StartWatching(policy_callback_); |
+ policy_watcher_->StartWatching( |
+ policy_updated_callback_, |
+ policy_error_callback_); |
base::RunLoop().RunUntilIdle(); |
} |
@@ -110,7 +114,8 @@ class PolicyWatcherTest : public testing::Test { |
base::MessageLoop message_loop_; |
scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
MockPolicyCallback mock_policy_callback_; |
- PolicyWatcher::PolicyCallback policy_callback_; |
+ PolicyWatcher::PolicyUpdatedCallback policy_updated_callback_; |
+ PolicyWatcher::PolicyErrorCallback policy_error_callback_; |
scoped_ptr<FakePolicyWatcher> policy_watcher_; |
base::DictionaryValue empty_; |
base::DictionaryValue nat_true_; |
@@ -402,5 +407,42 @@ TEST_F(PolicyWatcherTest, UdpPortRange) { |
StopWatching(); |
} |
+const int kMaxTransientErrorRetries = 5; |
+ |
+TEST_F(PolicyWatcherTest, SingleTransientErrorDoesntTriggerErrorCallback) { |
+ EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0); |
+ |
+ StartWatching(); |
+ policy_watcher_->SignalTransientErrorForTest(); |
+ StopWatching(); |
+} |
+ |
+TEST_F(PolicyWatcherTest, MultipleTransientErrorsTriggerErrorCallback) { |
+ EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()); |
+ |
+ StartWatching(); |
+ for (int i = 0; i < kMaxTransientErrorRetries; i++) { |
+ policy_watcher_->SignalTransientErrorForTest(); |
+ } |
+ StopWatching(); |
+} |
+ |
+TEST_F(PolicyWatcherTest, PolicyUpdateResetsTransientErrorsCounter) { |
+ testing::InSequence s; |
+ EXPECT_CALL(mock_policy_callback_, |
+ OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); |
+ EXPECT_CALL(mock_policy_callback_, OnPolicyErrorPtr()).Times(0); |
+ |
+ StartWatching(); |
+ for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) { |
+ policy_watcher_->SignalTransientErrorForTest(); |
+ } |
+ policy_watcher_->SetPolicies(&nat_true_); |
+ for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) { |
+ policy_watcher_->SignalTransientErrorForTest(); |
+ } |
+ StopWatching(); |
+} |
+ |
} // namespace policy_hack |
} // namespace remoting |