Don't scatter during OOBE or user-initiated update checks.

We need to add logic to disable scattering of downloads if we are in OOBE
or if we're doing a manual update check.

Scheduled checks are already disabled during OOBE, but this extra check
will ensure that any scattering policy (there's a pending work item to get
policy during OOBE) during OOBE will have no effect on the update.

Similarly manual (i.e user-initiated) update checks through
update_engine_client or through Chrome UI should not honor scattering.
That way, this can serve as a simple user-friendly workaround in case
there's any bug in scattering logic that bricks the system by any chance.

BUG=chromeos-31563: Don't scatter during OOBE or manual update checks.
TEST=Updated unit tests. Tested all code paths manually on ZGB and Kaen.
Change-Id: Ib631e560c1f620ca53db79ee59dc66efb27ea83c
Reviewed-on: https://gerrit.chromium.org/gerrit/24564
Commit-Ready: Jay Srinivasan <jaysri@chromium.org>
Reviewed-by: Jay Srinivasan <jaysri@chromium.org>
Tested-by: Jay Srinivasan <jaysri@chromium.org>
diff --git a/update_check_scheduler_unittest.cc b/update_check_scheduler_unittest.cc
index 965ce9d..2e7e62d 100644
--- a/update_check_scheduler_unittest.cc
+++ b/update_check_scheduler_unittest.cc
@@ -4,6 +4,7 @@
 
 #include <gtest/gtest.h>
 
+#include "update_engine/mock_system_state.h"
 #include "update_engine/update_attempter_mock.h"
 #include "update_engine/update_check_scheduler.h"
 
@@ -30,12 +31,13 @@
 class UpdateCheckSchedulerUnderTest : public UpdateCheckScheduler {
  public:
   UpdateCheckSchedulerUnderTest(UpdateAttempter* update_attempter)
-      : UpdateCheckScheduler(update_attempter, NULL) {}
+      : UpdateCheckScheduler(update_attempter, NULL, &mock_system_state_) {}
 
   MOCK_METHOD2(GTimeoutAddSeconds, guint(guint seconds, GSourceFunc function));
   MOCK_METHOD0(IsBootDeviceRemovable, bool());
   MOCK_METHOD0(IsOfficialBuild, bool());
-  MOCK_METHOD0(IsOOBEComplete, bool());
+
+  MockSystemState mock_system_state_;
 };
 
 class UpdateCheckSchedulerTest : public ::testing::Test {
@@ -155,11 +157,6 @@
   EXPECT_FALSE(scheduler_.UpdateCheckScheduler::IsBootDeviceRemovable());
 }
 
-TEST_F(UpdateCheckSchedulerTest, IsOOBECompleteTest) {
-  // Invokes the actual utils wrapper method rather than the subclass mock.
-  EXPECT_FALSE(scheduler_.UpdateCheckScheduler::IsOOBEComplete());
-}
-
 TEST_F(UpdateCheckSchedulerTest, IsOfficialBuildTest) {
   // Invokes the actual utils wrapper method rather than the subclass mock.
   EXPECT_TRUE(scheduler_.UpdateCheckScheduler::IsOfficialBuild());
@@ -276,8 +273,9 @@
 
 TEST_F(UpdateCheckSchedulerTest, StaticCheckOOBECompleteTest) {
   scheduler_.scheduled_ = true;
-  EXPECT_CALL(scheduler_, IsOOBEComplete()).Times(1).WillOnce(Return(true));
-  EXPECT_CALL(attempter_, Update("", "", false, false, false))
+  EXPECT_CALL(scheduler_.mock_system_state_,
+              IsOOBEComplete()).Times(1).WillOnce(Return(true));
+  EXPECT_CALL(attempter_, Update("", "", false, false, false, false))
       .Times(1)
       .WillOnce(Assign(&scheduler_.scheduled_, true));
   scheduler_.enabled_ = true;
@@ -287,8 +285,9 @@
 
 TEST_F(UpdateCheckSchedulerTest, StaticCheckOOBENotCompleteTest) {
   scheduler_.scheduled_ = true;
-  EXPECT_CALL(scheduler_, IsOOBEComplete()).Times(1).WillOnce(Return(false));
-  EXPECT_CALL(attempter_, Update("", "", _, _, _)).Times(0);
+  EXPECT_CALL(scheduler_.mock_system_state_,
+              IsOOBEComplete()).Times(1).WillOnce(Return(false));
+  EXPECT_CALL(attempter_, Update("", "", _, _, _,_)).Times(0);
   int interval_min, interval_max;
   FuzzRange(UpdateCheckScheduler::kTimeoutInitialInterval,
             UpdateCheckScheduler::kTimeoutRegularFuzz,