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

Unified Diff: remoting/host/policy_watcher_unittest.cc

Issue 891053003: Reporting a policy error after detecting mistyped policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months 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
« remoting/host/policy_watcher.cc ('K') | « remoting/host/policy_watcher.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/policy_watcher_unittest.cc
diff --git a/remoting/host/policy_watcher_unittest.cc b/remoting/host/policy_watcher_unittest.cc
index 8fee57c758d16f031081aa047750574d912061a5..f180f8cf386cd5ae1d0ca55c90b9db30654e0133 100644
--- a/remoting/host/policy_watcher_unittest.cc
+++ b/remoting/host/policy_watcher_unittest.cc
@@ -63,8 +63,6 @@ class PolicyWatcherTest : public testing::Test {
policy_watcher_ =
PolicyWatcher::CreateFromPolicyLoader(make_scoped_ptr(policy_loader_));
- schema_ = policy::Schema::Wrap(policy::GetChromeSchemaData());
-
nat_true_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, true);
nat_false_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal,
false);
@@ -173,12 +171,10 @@ class PolicyWatcherTest : public testing::Test {
base::RunLoop().RunUntilIdle();
}
- void SignalTransientErrorForTest() {
- policy_watcher_->SignalTransientPolicyError();
+ const policy::Schema* GetPolicySchema() {
+ return policy_watcher_->GetPolicySchema();
}
- const policy::Schema* GetPolicySchema() { return &schema_; }
-
const base::DictionaryValue& GetDefaultValues() {
return *(policy_watcher_->default_values_);
}
@@ -224,8 +220,6 @@ class PolicyWatcherTest : public testing::Test {
base::DictionaryValue port_range_full_;
base::DictionaryValue port_range_empty_;
- policy::Schema schema_;
-
private:
void SetDefaults(base::DictionaryValue& dict) {
dict.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, true);
@@ -281,9 +275,8 @@ TEST_F(PolicyWatcherTest, NatFalse) {
StartWatching();
}
-TEST_F(PolicyWatcherTest, NatOne) {
- EXPECT_CALL(mock_policy_callback_,
- OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_)));
+TEST_F(PolicyWatcherTest, NatWrongType) {
+ EXPECT_CALL(mock_policy_callback_, OnPolicyError());
SetPolicies(nat_one_);
StartWatching();
@@ -471,39 +464,6 @@ TEST_F(PolicyWatcherTest, UdpPortRange) {
SetPolicies(port_range_empty_);
}
-const int kMaxTransientErrorRetries = 5;
-
-TEST_F(PolicyWatcherTest, SingleTransientErrorDoesntTriggerErrorCallback) {
- EXPECT_CALL(mock_policy_callback_, OnPolicyError()).Times(0);
-
- StartWatching();
- SignalTransientErrorForTest();
-}
-
-TEST_F(PolicyWatcherTest, MultipleTransientErrorsTriggerErrorCallback) {
- EXPECT_CALL(mock_policy_callback_, OnPolicyError());
-
- StartWatching();
- for (int i = 0; i < kMaxTransientErrorRetries; i++) {
- SignalTransientErrorForTest();
- }
-}
-
-TEST_F(PolicyWatcherTest, PolicyUpdateResetsTransientErrorsCounter) {
- testing::InSequence s;
- EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(testing::_));
- EXPECT_CALL(mock_policy_callback_, OnPolicyError()).Times(0);
-
- StartWatching();
- for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) {
- SignalTransientErrorForTest();
- }
- SetPolicies(nat_true_);
- for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) {
- SignalTransientErrorForTest();
- }
-}
-
TEST_F(PolicyWatcherTest, PolicySchemaAndPolicyWatcherShouldBeInSync) {
// This test verifies that
// 1) policy schema (generated out of policy_templates.json)
@@ -545,6 +505,25 @@ TEST_F(PolicyWatcherTest, PolicySchemaAndPolicyWatcherShouldBeInSync) {
EXPECT_THAT(actual_schema_keys, testing::ContainerEq(expected_schema_keys));
}
+TEST_F(PolicyWatcherTest, SchemaTypeCheck) {
+ const policy::Schema* schema = GetPolicySchema();
+ ASSERT_TRUE(schema->valid());
+
+ // Check one, random "string" policy to see if the type propagated correctly
+ // from policy_templates.json file.
+ const policy::Schema string_schema =
+ schema->GetKnownProperty("RemoteAccessHostDomain");
+ EXPECT_TRUE(string_schema.valid());
+ EXPECT_EQ(string_schema.type(), base::Value::Type::TYPE_STRING);
+
+ // And check one, random "boolean" policy to see if the type propagated
+ // correctly from policy_templates.json file.
+ const policy::Schema boolean_schema =
+ schema->GetKnownProperty("RemoteAccessHostRequireCurtain");
+ EXPECT_TRUE(boolean_schema.valid());
+ EXPECT_EQ(boolean_schema.type(), base::Value::Type::TYPE_BOOLEAN);
+}
+
// Unit tests cannot instantiate PolicyWatcher on ChromeOS
// (as this requires running inside a browser process).
#ifndef OS_CHROMEOS
« remoting/host/policy_watcher.cc ('K') | « remoting/host/policy_watcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698