PM: New (stub) policy for whether an update can be applied.

There's no implementation for this policy yet, and so it always returns
true.

BUG=chromium:358323
TEST=Unit tests.

Change-Id: Id3a0d13cf8c2e9061b800b114d8476c11f998df0
Reviewed-on: https://chromium-review.googlesource.com/197376
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
diff --git a/policy_manager/chromeos_policy.cc b/policy_manager/chromeos_policy.cc
index cd10918..4a9f601 100644
--- a/policy_manager/chromeos_policy.cc
+++ b/policy_manager/chromeos_policy.cc
@@ -18,4 +18,13 @@
   return EvalStatus::kSucceeded;
 }
 
+EvalStatus ChromeOSPolicy::UpdateDownloadAndApplyAllowed(EvaluationContext* ec,
+                                                         State* state,
+                                                         string* error,
+                                                         bool* result) const {
+  // TODO(garnold): Write this policy implementation with the actual policy.
+  *result = true;
+  return EvalStatus::kSucceeded;
+}
+
 }  // namespace chromeos_policy_manager
diff --git a/policy_manager/chromeos_policy.h b/policy_manager/chromeos_policy.h
index 93d3723..3ade8d0 100644
--- a/policy_manager/chromeos_policy.h
+++ b/policy_manager/chromeos_policy.h
@@ -18,7 +18,12 @@
   // Policy overrides.
   virtual EvalStatus UpdateCheckAllowed(EvaluationContext* ec, State* state,
                                         std::string* error,
-                                        bool* result) const;
+                                        bool* result) const override;
+
+  virtual EvalStatus UpdateDownloadAndApplyAllowed(EvaluationContext* ec,
+                                                   State* state,
+                                                   std::string* error,
+                                                   bool* result) const override;
 
  private:
   DISALLOW_COPY_AND_ASSIGN(ChromeOSPolicy);
diff --git a/policy_manager/default_policy.h b/policy_manager/default_policy.h
index 63b674e..1eeb54b 100644
--- a/policy_manager/default_policy.h
+++ b/policy_manager/default_policy.h
@@ -20,7 +20,14 @@
   // Policy overrides.
   virtual EvalStatus UpdateCheckAllowed(EvaluationContext* ec, State* state,
                                         std::string* error,
-                                        bool* result) const {
+                                        bool* result) const override {
+    *result = true;
+    return EvalStatus::kSucceeded;
+  }
+
+  virtual EvalStatus UpdateDownloadAndApplyAllowed(
+      EvaluationContext* ec, State* state, std::string* error,
+      bool* result) const override {
     *result = true;
     return EvalStatus::kSucceeded;
   }
diff --git a/policy_manager/mock_policy.h b/policy_manager/mock_policy.h
index e46b5bf..118a24b 100644
--- a/policy_manager/mock_policy.h
+++ b/policy_manager/mock_policy.h
@@ -22,6 +22,10 @@
                      EvalStatus(EvaluationContext*, State*, std::string*,
                                 bool*));
 
+  MOCK_CONST_METHOD4(UpdateDownloadAndApplyAllowed,
+                     EvalStatus(EvaluationContext*, State*, std::string*,
+                                bool*));
+
 private:
   DISALLOW_COPY_AND_ASSIGN(MockPolicy);
 };
diff --git a/policy_manager/policy.h b/policy_manager/policy.h
index 5896fe7..7c7ec0c 100644
--- a/policy_manager/policy.h
+++ b/policy_manager/policy.h
@@ -40,6 +40,12 @@
                                         std::string* error,
                                         bool* result) const = 0;
 
+  // Returns whether an update can be downloaded/applied.
+  virtual EvalStatus UpdateDownloadAndApplyAllowed(EvaluationContext* ec,
+                                                   State* state,
+                                                   std::string* error,
+                                                   bool* result) const = 0;
+
  protected:
   Policy() {}
 
diff --git a/policy_manager/policy_manager_unittest.cc b/policy_manager/policy_manager_unittest.cc
index b1f5562..15553a5 100644
--- a/policy_manager/policy_manager_unittest.cc
+++ b/policy_manager/policy_manager_unittest.cc
@@ -75,24 +75,41 @@
   acc->push_back(std::make_pair(status, result));
 }
 
-TEST_F(PmPolicyManagerTest, PolicyRequestCall) {
+TEST_F(PmPolicyManagerTest, PolicyRequestCallReturnsSuccess) {
   bool result;
-  EvalStatus status = pmut_->PolicyRequest(
-      &Policy::UpdateCheckAllowed, &result);
-  EXPECT_EQ(status, EvalStatus::kSucceeded);
+  EvalStatus status;
+
+  // Tests that policy requests are completed successfully. It is important that
+  // this test covers all policy requests as defined in Policy.
+  //
+  // TODO(garnold) We may need to adapt this test as the Chrome OS policy grows
+  // beyond the stub implementation.
+  status = pmut_->PolicyRequest(&Policy::UpdateCheckAllowed, &result);
+  EXPECT_EQ(EvalStatus::kSucceeded, status);
+  status = pmut_->PolicyRequest(&Policy::UpdateDownloadAndApplyAllowed,
+                                &result);
+  EXPECT_EQ(EvalStatus::kSucceeded, status);
 }
 
 TEST_F(PmPolicyManagerTest, PolicyRequestCallsPolicy) {
   StrictMock<MockPolicy>* policy = new StrictMock<MockPolicy>();
   pmut_->set_policy(policy);
   bool result;
+  EvalStatus status;
 
-  // Tests that the method is called on the policy_ instance.
+  // Tests that the policy methods are actually called on the policy instance.
+  // It is important that this test covers all policy requests as defined in
+  // Policy.
   EXPECT_CALL(*policy, UpdateCheckAllowed(_, _, _, _))
       .WillOnce(Return(EvalStatus::kSucceeded));
-  EvalStatus status = pmut_->PolicyRequest(
-      &Policy::UpdateCheckAllowed, &result);
-  EXPECT_EQ(status, EvalStatus::kSucceeded);
+  status = pmut_->PolicyRequest(&Policy::UpdateCheckAllowed, &result);
+  EXPECT_EQ(EvalStatus::kSucceeded, status);
+
+  EXPECT_CALL(*policy, UpdateDownloadAndApplyAllowed(_, _, _, _))
+      .WillOnce(Return(EvalStatus::kSucceeded));
+  status = pmut_->PolicyRequest(&Policy::UpdateDownloadAndApplyAllowed,
+                                &result);
+  EXPECT_EQ(EvalStatus::kSucceeded, status);
 }
 
 TEST_F(PmPolicyManagerTest, PolicyRequestCallsDefaultOnError) {
@@ -103,7 +120,7 @@
   bool result = false;
   EvalStatus status = pmut_->PolicyRequest(
       &Policy::UpdateCheckAllowed, &result);
-  EXPECT_EQ(status, EvalStatus::kSucceeded);
+  EXPECT_EQ(EvalStatus::kSucceeded, status);
   EXPECT_TRUE(result);
 }
 
@@ -113,7 +130,7 @@
 
   EvalStatus status = pmut_->PolicyRequest(
       &Policy::UpdateCheckAllowed, &result);
-  EXPECT_EQ(status, EvalStatus::kAskMeAgainLater);
+  EXPECT_EQ(EvalStatus::kAskMeAgainLater, status);
 }
 
 TEST_F(PmPolicyManagerTest, AsyncPolicyRequestDelaysEvaluation) {