Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Unified Diff: remoting/host/policy_hack/policy_watcher_unittest.cc

Issue 722743003: Reporting of policy errors via host-offline-reason: part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed feedback from Kelvin. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/host/policy_hack/policy_watcher_linux.cc ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « remoting/host/policy_hack/policy_watcher_linux.cc ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698