update_engine: UM: MockPolicy extends DefaultPolicy by default.

This affords us an easily customizable policy implementation for use
during testing.

BUG=None
TEST=Unit tests.

Change-Id: I264d4992d552539ed8a1da64e500fb7a94b6e2d0
Reviewed-on: https://chromium-review.googlesource.com/226343
Reviewed-by: Alex Deymo <deymo@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/update_engine/update_manager/mock_policy.h b/update_engine/update_manager/mock_policy.h
index 6cfac98..aff74f5 100644
--- a/update_engine/update_manager/mock_policy.h
+++ b/update_engine/update_manager/mock_policy.h
@@ -9,6 +9,7 @@
 
 #include <gmock/gmock.h>
 
+#include "update_engine/update_manager/default_policy.h"
 #include "update_engine/update_manager/policy.h"
 
 namespace chromeos_update_manager {
@@ -16,7 +17,31 @@
 // A mocked implementation of Policy.
 class MockPolicy : public Policy {
  public:
-  MockPolicy() {}
+  explicit MockPolicy(chromeos_update_engine::ClockInterface* clock)
+      : default_policy_(clock) {
+    // We defer to the corresponding DefaultPolicy methods, by default.
+    ON_CALL(*this, UpdateCheckAllowed(testing::_, testing::_, testing::_,
+                                      testing::_))
+        .WillByDefault(testing::Invoke(
+                &default_policy_, &DefaultPolicy::UpdateCheckAllowed));
+    ON_CALL(*this, UpdateCanStart(testing::_, testing::_, testing::_,
+                                  testing::_, testing::_))
+        .WillByDefault(testing::Invoke(
+                &default_policy_, &DefaultPolicy::UpdateCanStart));
+    ON_CALL(*this, UpdateDownloadAllowed(testing::_, testing::_, testing::_,
+                                         testing::_))
+        .WillByDefault(testing::Invoke(
+                &default_policy_, &DefaultPolicy::UpdateDownloadAllowed));
+    ON_CALL(*this, P2PEnabled(testing::_, testing::_, testing::_, testing::_))
+        .WillByDefault(testing::Invoke(
+                &default_policy_, &DefaultPolicy::P2PEnabled));
+    ON_CALL(*this, P2PEnabledChanged(testing::_, testing::_, testing::_,
+                                     testing::_, testing::_))
+        .WillByDefault(testing::Invoke(
+                &default_policy_, &DefaultPolicy::P2PEnabledChanged));
+  }
+
+  MockPolicy() : MockPolicy(nullptr) {}
   virtual ~MockPolicy() {}
 
   // Policy overrides.
@@ -40,7 +65,13 @@
                      EvalStatus(EvaluationContext*, State*, std::string*,
                                 bool*, bool));
 
+ protected:
+  // Policy override.
+  std::string PolicyName() const override { return "MockPolicy"; }
+
  private:
+  DefaultPolicy default_policy_;
+
   DISALLOW_COPY_AND_ASSIGN(MockPolicy);
 };