AU: Start an UpdateAttempter unit test suite.

This increases the UpdateAttmpter line coverage to almost 40%. More is needed
but this is a good starting point / checkpoint. Also some UpdateCheckScheduler
unit test cleanup.

BUG=6243
TEST=unit tests, gmerge on device

Change-Id: I39c80de3f18095c4a28cb36ab868bed6d7073824

Review URL: http://codereview.chromium.org/3259011
diff --git a/SConstruct b/SConstruct
index abf5253..09a6566 100644
--- a/SConstruct
+++ b/SConstruct
@@ -259,6 +259,7 @@
                             tarjan_unittest.cc
                             test_utils.cc
                             topological_sort_unittest.cc
+                            update_attempter_unittest.cc
                             update_check_scheduler_unittest.cc
                             utils_unittest.cc
                             zip_unittest.cc""")
diff --git a/action_mock.h b/action_mock.h
new file mode 100644
index 0000000..4ebafba
--- /dev/null
+++ b/action_mock.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_MOCK_H__
+#define CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_MOCK_H__
+
+#include <gmock/gmock.h>
+
+#include "update_engine/action.h"
+
+namespace chromeos_update_engine {
+
+class ActionMock;
+
+template<>
+class ActionTraits<ActionMock> {
+ public:
+  typedef NoneType OutputObjectType;
+  typedef NoneType InputObjectType;
+};
+
+class ActionMock : public Action<ActionMock> {
+ public:
+  MOCK_METHOD0(PerformAction, void());
+  MOCK_CONST_METHOD0(Type, std::string());
+};
+
+}  // namespace chromeos_update_engine
+
+#endif  // CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_MOCK_H__
diff --git a/action_processor.h b/action_processor.h
index 96e16f0..a395b3d 100644
--- a/action_processor.h
+++ b/action_processor.h
@@ -43,12 +43,12 @@
  public:
   ActionProcessor();
 
-  ~ActionProcessor();
+  virtual ~ActionProcessor();
 
   // Starts processing the first Action in the queue. If there's a delegate,
   // when all processing is complete, ProcessingDone() will be called on the
   // delegate.
-  void StartProcessing();
+  virtual void StartProcessing();
 
   // Aborts processing. If an Action is running, it will have
   // TerminateProcessing() called on it. The Action that was running
@@ -59,9 +59,10 @@
   bool IsRunning() const { return NULL != current_action_; }
 
   // Adds another Action to the end of the queue.
-  void EnqueueAction(AbstractAction* action);
+  virtual void EnqueueAction(AbstractAction* action);
 
-  // Sets the current delegate. Set to NULL to remove a delegate.
+  // Sets/gets the current delegate. Set to NULL to remove a delegate.
+  ActionProcessorDelegate* delegate() const { return delegate_; }
   void set_delegate(ActionProcessorDelegate *delegate) {
     delegate_ = delegate;
   }
diff --git a/action_processor_mock.h b/action_processor_mock.h
new file mode 100644
index 0000000..f4f1103
--- /dev/null
+++ b/action_processor_mock.h
@@ -0,0 +1,22 @@
+// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_PROCESSOR_MOCK_H__
+#define CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_PROCESSOR_MOCK_H__
+
+#include <gmock/gmock.h>
+
+#include "update_engine/action.h"
+
+namespace chromeos_update_engine {
+
+class ActionProcessorMock : public ActionProcessor {
+ public:
+  MOCK_METHOD0(StartProcessing, void());
+  MOCK_METHOD1(EnqueueAction, void(AbstractAction* action));
+};
+
+}  // namespace chromeos_update_engine
+
+#endif  // CHROMEOS_PLATFORM_UPDATE_ENGINE_ACTION_PROCESSOR_MOCK_H__
diff --git a/download_action.h b/download_action.h
index 189121b..c0c36f1 100644
--- a/download_action.h
+++ b/download_action.h
@@ -87,6 +87,7 @@
                              const char* bytes, int length);
   virtual void TransferComplete(HttpFetcher *fetcher, bool successful);
 
+  DownloadActionDelegate* delegate() const { return delegate_; }
   void set_delegate(DownloadActionDelegate* delegate) {
     delegate_ = delegate;
   }
diff --git a/update_attempter.cc b/update_attempter.cc
index 3614cad..694e774 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -87,7 +87,8 @@
 
 UpdateAttempter::UpdateAttempter(PrefsInterface* prefs,
                                  MetricsLibraryInterface* metrics_lib)
-    : dbus_service_(NULL),
+    : processor_(new ActionProcessor()),
+      dbus_service_(NULL),
       prefs_(prefs),
       metrics_lib_(metrics_lib),
       update_check_scheduler_(NULL),
@@ -124,8 +125,8 @@
     LOG(ERROR) << "Unable to initialize Omaha request device params.";
     return;
   }
-  CHECK(!processor_.IsRunning());
-  processor_.set_delegate(this);
+  CHECK(!processor_->IsRunning());
+  processor_->set_delegate(this);
 
   // Actions:
   shared_ptr<OmahaRequestAction> update_check_action(
@@ -186,7 +187,7 @@
   // Enqueue the actions
   for (vector<shared_ptr<AbstractAction> >::iterator it = actions_.begin();
        it != actions_.end(); ++it) {
-    processor_.EnqueueAction(it->get());
+    processor_->EnqueueAction(it->get());
   }
 
   // Bond them together. We have to use the leaf-types when calling
@@ -207,7 +208,7 @@
               postinstall_runner_action_postcommit.get());
 
   SetStatusAndNotify(UPDATE_STATUS_CHECKING_FOR_UPDATE);
-  processor_.StartProcessing();
+  processor_->StartProcessing();
 }
 
 void UpdateAttempter::CheckForUpdate(const std::string& app_version,
@@ -426,9 +427,9 @@
                              error_event_.release(),  // Pass ownership.
                              new LibcurlHttpFetcher));
   actions_.push_back(shared_ptr<AbstractAction>(error_event_action));
-  processor_.EnqueueAction(error_event_action.get());
+  processor_->EnqueueAction(error_event_action.get());
   SetStatusAndNotify(UPDATE_STATUS_REPORTING_ERROR_EVENT);
-  processor_.StartProcessing();
+  processor_->StartProcessing();
   return true;
 }
 
diff --git a/update_attempter.h b/update_attempter.h
index fd9bc2a..6a81ef2 100644
--- a/update_attempter.h
+++ b/update_attempter.h
@@ -12,6 +12,7 @@
 #include <vector>
 
 #include <glib.h>
+#include <gtest/gtest_prod.h>  // for FRIEND_TEST
 
 #include "base/time.h"
 #include "update_engine/action_processor.h"
@@ -104,6 +105,9 @@
   void BytesReceived(uint64_t bytes_received, uint64_t total);
 
  private:
+  friend class UpdateAttempterTest;
+  FRIEND_TEST(UpdateAttempterTest, UpdateTest);
+
   // Sets the status to the given status and notifies a status update
   // over dbus.
   void SetStatusAndNotify(UpdateStatus status);
@@ -144,7 +148,7 @@
   base::TimeTicks last_notify_time_;
 
   std::vector<std::tr1::shared_ptr<AbstractAction> > actions_;
-  ActionProcessor processor_;
+  scoped_ptr<ActionProcessor> processor_;
 
   // If non-null, this UpdateAttempter will send status updates over this
   // dbus service.
diff --git a/update_attempter_unittest.cc b/update_attempter_unittest.cc
new file mode 100644
index 0000000..0a02d1c
--- /dev/null
+++ b/update_attempter_unittest.cc
@@ -0,0 +1,156 @@
+// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <base/file_util.h>
+#include <gtest/gtest.h>
+
+#include "update_engine/action_mock.h"
+#include "update_engine/action_processor_mock.h"
+#include "update_engine/filesystem_copier_action.h"
+#include "update_engine/postinstall_runner_action.h"
+#include "update_engine/set_bootable_flag_action.h"
+#include "update_engine/update_attempter.h"
+
+using std::string;
+using testing::InSequence;
+using testing::Property;
+using testing::Return;
+
+namespace chromeos_update_engine {
+
+// Test a subclass rather than the main class directly so that we can mock out
+// methods within the class. There're explicit unit test for the mocked out
+// methods.
+class UpdateAttempterUnderTest : public UpdateAttempter {
+ public:
+  UpdateAttempterUnderTest()
+      : UpdateAttempter(NULL, NULL) {}
+};
+
+class UpdateAttempterTest : public ::testing::Test {
+ protected:
+  virtual void SetUp() {
+    EXPECT_EQ(NULL, attempter_.dbus_service_);
+    EXPECT_EQ(NULL, attempter_.prefs_);
+    EXPECT_EQ(NULL, attempter_.metrics_lib_);
+    EXPECT_EQ(NULL, attempter_.update_check_scheduler_);
+    EXPECT_EQ(0, attempter_.http_response_code_);
+    EXPECT_EQ(utils::kProcessPriorityNormal, attempter_.priority_);
+    EXPECT_EQ(NULL, attempter_.manage_priority_source_);
+    EXPECT_FALSE(attempter_.download_active_);
+    EXPECT_EQ(UPDATE_STATUS_IDLE, attempter_.status_);
+    EXPECT_EQ(0.0, attempter_.download_progress_);
+    EXPECT_EQ(0, attempter_.last_checked_time_);
+    EXPECT_EQ("0.0.0.0", attempter_.new_version_);
+    EXPECT_EQ(0, attempter_.new_size_);
+    processor_ = new ActionProcessorMock();
+    attempter_.processor_.reset(processor_);  // Transfers ownership.
+  }
+
+  UpdateAttempterUnderTest attempter_;
+  ActionProcessorMock* processor_;
+};
+
+TEST_F(UpdateAttempterTest, ConstructWithUpdatedMarkerTest) {
+  extern const char* kUpdateCompletedMarker;
+  const FilePath kMarker(kUpdateCompletedMarker);
+  EXPECT_EQ(0, file_util::WriteFile(kMarker, "", 0));
+  UpdateAttempterUnderTest attempter;
+  EXPECT_EQ(UPDATE_STATUS_UPDATED_NEED_REBOOT, attempter.status());
+  EXPECT_TRUE(file_util::Delete(kMarker, false));
+}
+
+TEST_F(UpdateAttempterTest, GetErrorCodeForActionTest) {
+  extern ActionExitCode GetErrorCodeForAction(AbstractAction* action,
+                                              ActionExitCode code);
+  EXPECT_EQ(kActionCodeSuccess,
+            GetErrorCodeForAction(NULL, kActionCodeSuccess));
+
+  OmahaRequestParams params;
+  OmahaRequestAction omaha_request_action(NULL, params, NULL, NULL);
+  EXPECT_EQ(kActionCodeOmahaRequestError,
+            GetErrorCodeForAction(&omaha_request_action, kActionCodeError));
+  OmahaResponseHandlerAction omaha_response_handler_action;
+  EXPECT_EQ(kActionCodeOmahaResponseHandlerError,
+            GetErrorCodeForAction(&omaha_response_handler_action,
+                                  kActionCodeError));
+  FilesystemCopierAction filesystem_copier_action(false);
+  EXPECT_EQ(kActionCodeFilesystemCopierError,
+            GetErrorCodeForAction(&filesystem_copier_action, kActionCodeError));
+  PostinstallRunnerAction postinstall_runner_action(true);
+  EXPECT_EQ(kActionCodePostinstallRunnerError,
+            GetErrorCodeForAction(&postinstall_runner_action,
+                                  kActionCodeError));
+  SetBootableFlagAction set_bootable_flag_action;
+  EXPECT_EQ(kActionCodeSetBootableFlagError,
+            GetErrorCodeForAction(&set_bootable_flag_action,
+                                  kActionCodeError));
+  ActionMock action_mock;
+  EXPECT_CALL(action_mock, Type()).Times(1).WillOnce(Return("ActionMock"));
+  EXPECT_EQ(kActionCodeError,
+            GetErrorCodeForAction(&action_mock, kActionCodeError));
+}
+
+TEST_F(UpdateAttempterTest, UpdateStatusToStringTest) {
+  extern const char* UpdateStatusToString(UpdateStatus);
+  EXPECT_STREQ("UPDATE_STATUS_IDLE", UpdateStatusToString(UPDATE_STATUS_IDLE));
+  EXPECT_STREQ("UPDATE_STATUS_CHECKING_FOR_UPDATE",
+               UpdateStatusToString(UPDATE_STATUS_CHECKING_FOR_UPDATE));
+  EXPECT_STREQ("UPDATE_STATUS_UPDATE_AVAILABLE",
+               UpdateStatusToString(UPDATE_STATUS_UPDATE_AVAILABLE));
+  EXPECT_STREQ("UPDATE_STATUS_DOWNLOADING",
+               UpdateStatusToString(UPDATE_STATUS_DOWNLOADING));
+  EXPECT_STREQ("UPDATE_STATUS_VERIFYING",
+               UpdateStatusToString(UPDATE_STATUS_VERIFYING));
+  EXPECT_STREQ("UPDATE_STATUS_FINALIZING",
+               UpdateStatusToString(UPDATE_STATUS_FINALIZING));
+  EXPECT_STREQ("UPDATE_STATUS_UPDATED_NEED_REBOOT",
+               UpdateStatusToString(UPDATE_STATUS_UPDATED_NEED_REBOOT));
+  EXPECT_STREQ("UPDATE_STATUS_REPORTING_ERROR_EVENT",
+               UpdateStatusToString(UPDATE_STATUS_REPORTING_ERROR_EVENT));
+  EXPECT_STREQ("unknown status",
+               UpdateStatusToString(static_cast<UpdateStatus>(-1)));
+}
+
+TEST_F(UpdateAttempterTest, UpdateTest) {
+  attempter_.set_http_response_code(200);
+  InSequence s;
+  const string kActionTypes[] = {
+    OmahaRequestAction::StaticType(),
+    OmahaResponseHandlerAction::StaticType(),
+    FilesystemCopierAction::StaticType(),
+    FilesystemCopierAction::StaticType(),
+    OmahaRequestAction::StaticType(),
+    DownloadAction::StaticType(),
+    OmahaRequestAction::StaticType(),
+    PostinstallRunnerAction::StaticType(),
+    SetBootableFlagAction::StaticType(),
+    PostinstallRunnerAction::StaticType(),
+    OmahaRequestAction::StaticType()
+  };
+  for (size_t i = 0; i < arraysize(kActionTypes); ++i) {
+    EXPECT_CALL(*processor_,
+                EnqueueAction(Property(&AbstractAction::Type,
+                                       kActionTypes[i]))).Times(1);
+  }
+  EXPECT_CALL(*processor_, StartProcessing()).Times(1);
+
+  attempter_.Update("", "");
+
+  EXPECT_EQ(0, attempter_.http_response_code());
+  EXPECT_EQ(&attempter_, processor_->delegate());
+  EXPECT_EQ(arraysize(kActionTypes), attempter_.actions_.size());
+  for (size_t i = 0; i < arraysize(kActionTypes); ++i) {
+    EXPECT_EQ(kActionTypes[i], attempter_.actions_[i]->Type());
+  }
+  EXPECT_EQ(attempter_.response_handler_action_.get(),
+            attempter_.actions_[1].get());
+  DownloadAction* download_action =
+      dynamic_cast<DownloadAction*>(attempter_.actions_[5].get());
+  ASSERT_TRUE(download_action != NULL);
+  EXPECT_EQ(&attempter_, download_action->delegate());
+  EXPECT_EQ(UPDATE_STATUS_CHECKING_FOR_UPDATE, attempter_.status());
+}
+
+}  // namespace chromeos_update_engine
diff --git a/update_check_scheduler_unittest.cc b/update_check_scheduler_unittest.cc
index 8a0ca19..413453a 100644
--- a/update_check_scheduler_unittest.cc
+++ b/update_check_scheduler_unittest.cc
@@ -37,21 +37,22 @@
 };
 
 class UpdateCheckSchedulerTest : public ::testing::Test {
+ public:
+  UpdateCheckSchedulerTest() : scheduler_(&attempter_) {}
+
  protected:
   virtual void SetUp() {
     test_ = this;
     loop_ = NULL;
-    scheduler_.reset(new UpdateCheckSchedulerUnderTest(&attempter_));
-    EXPECT_EQ(&attempter_, scheduler_->update_attempter_);
-    EXPECT_FALSE(scheduler_->enabled_);
-    EXPECT_FALSE(scheduler_->scheduled_);
-    EXPECT_EQ(0, scheduler_->last_interval_);
+    EXPECT_EQ(&attempter_, scheduler_.update_attempter_);
+    EXPECT_FALSE(scheduler_.enabled_);
+    EXPECT_FALSE(scheduler_.scheduled_);
+    EXPECT_EQ(0, scheduler_.last_interval_);
   }
 
   virtual void TearDown() {
     test_ = NULL;
     loop_ = NULL;
-    scheduler_.reset(NULL);
   }
 
   static gboolean SourceCallback(gpointer data) {
@@ -60,7 +61,7 @@
     return test_->source_callback_.Call(data);
   }
 
-  scoped_ptr<UpdateCheckSchedulerUnderTest> scheduler_;
+  UpdateCheckSchedulerUnderTest scheduler_;
   UpdateAttempterMock attempter_;
   MockFunction<gboolean(gpointer data)> source_callback_;
   GMainLoop* loop_;
@@ -70,35 +71,35 @@
 UpdateCheckSchedulerTest* UpdateCheckSchedulerTest::test_ = NULL;
 
 TEST_F(UpdateCheckSchedulerTest, CanScheduleTest) {
-  EXPECT_FALSE(scheduler_->CanSchedule());
-  scheduler_->enabled_ = true;
-  EXPECT_TRUE(scheduler_->CanSchedule());
-  scheduler_->scheduled_ = true;
-  EXPECT_FALSE(scheduler_->CanSchedule());
-  scheduler_->enabled_ = false;
-  EXPECT_FALSE(scheduler_->CanSchedule());
+  EXPECT_FALSE(scheduler_.CanSchedule());
+  scheduler_.enabled_ = true;
+  EXPECT_TRUE(scheduler_.CanSchedule());
+  scheduler_.scheduled_ = true;
+  EXPECT_FALSE(scheduler_.CanSchedule());
+  scheduler_.enabled_ = false;
+  EXPECT_FALSE(scheduler_.CanSchedule());
 }
 
 TEST_F(UpdateCheckSchedulerTest, ComputeNextIntervalAndFuzzBackoffTest) {
   int interval, fuzz;
   attempter_.set_http_response_code(500);
   int last_interval = UpdateCheckScheduler::kTimeoutPeriodic + 50;
-  scheduler_->last_interval_ = last_interval;
-  scheduler_->ComputeNextIntervalAndFuzz(&interval, &fuzz);
+  scheduler_.last_interval_ = last_interval;
+  scheduler_.ComputeNextIntervalAndFuzz(&interval, &fuzz);
   EXPECT_EQ(2 * last_interval, interval);
   EXPECT_EQ(2 * last_interval, fuzz);
 
   attempter_.set_http_response_code(503);
   last_interval = UpdateCheckScheduler::kTimeoutMaxBackoff / 2 + 1;
-  scheduler_->last_interval_ = last_interval;
-  scheduler_->ComputeNextIntervalAndFuzz(&interval, &fuzz);
+  scheduler_.last_interval_ = last_interval;
+  scheduler_.ComputeNextIntervalAndFuzz(&interval, &fuzz);
   EXPECT_EQ(UpdateCheckScheduler::kTimeoutMaxBackoff, interval);
   EXPECT_EQ(UpdateCheckScheduler::kTimeoutMaxBackoff, fuzz);
 }
 
 TEST_F(UpdateCheckSchedulerTest, ComputeNextIntervalAndFuzzTest) {
   int interval, fuzz;
-  scheduler_->ComputeNextIntervalAndFuzz(&interval, &fuzz);
+  scheduler_.ComputeNextIntervalAndFuzz(&interval, &fuzz);
   EXPECT_EQ(UpdateCheckScheduler::kTimeoutPeriodic, interval);
   EXPECT_EQ(UpdateCheckScheduler::kTimeoutRegularFuzz, fuzz);
 }
@@ -106,38 +107,38 @@
 TEST_F(UpdateCheckSchedulerTest, GTimeoutAddSecondsTest) {
   loop_ = g_main_loop_new(g_main_context_default(), FALSE);
   // Invokes the actual GLib wrapper method rather than the subclass mock.
-  scheduler_->UpdateCheckScheduler::GTimeoutAddSeconds(0, SourceCallback);
-  EXPECT_CALL(source_callback_, Call(scheduler_.get())).Times(1);
+  scheduler_.UpdateCheckScheduler::GTimeoutAddSeconds(0, SourceCallback);
+  EXPECT_CALL(source_callback_, Call(&scheduler_)).Times(1);
   g_main_loop_run(loop_);
   g_main_loop_unref(loop_);
 }
 
 TEST_F(UpdateCheckSchedulerTest, IsBootDeviceRemovableTest) {
   // Invokes the actual utils wrapper method rather than the subclass mock.
-  EXPECT_FALSE(scheduler_->UpdateCheckScheduler::IsBootDeviceRemovable());
+  EXPECT_FALSE(scheduler_.UpdateCheckScheduler::IsBootDeviceRemovable());
 }
 
 TEST_F(UpdateCheckSchedulerTest, IsOfficialBuildTest) {
   // Invokes the actual utils wrapper method rather than the subclass mock.
-  EXPECT_TRUE(scheduler_->UpdateCheckScheduler::IsOfficialBuild());
+  EXPECT_TRUE(scheduler_.UpdateCheckScheduler::IsOfficialBuild());
 }
 
 TEST_F(UpdateCheckSchedulerTest, RunBootDeviceRemovableTest) {
-  scheduler_->enabled_ = true;
-  EXPECT_CALL(*scheduler_, IsOfficialBuild()).Times(1).WillOnce(Return(true));
-  EXPECT_CALL(*scheduler_, IsBootDeviceRemovable())
+  scheduler_.enabled_ = true;
+  EXPECT_CALL(scheduler_, IsOfficialBuild()).Times(1).WillOnce(Return(true));
+  EXPECT_CALL(scheduler_, IsBootDeviceRemovable())
       .Times(1)
       .WillOnce(Return(true));
-  scheduler_->Run();
-  EXPECT_FALSE(scheduler_->enabled_);
+  scheduler_.Run();
+  EXPECT_FALSE(scheduler_.enabled_);
   EXPECT_EQ(NULL, attempter_.update_check_scheduler());
 }
 
 TEST_F(UpdateCheckSchedulerTest, RunNonOfficialBuildTest) {
-  scheduler_->enabled_ = true;
-  EXPECT_CALL(*scheduler_, IsOfficialBuild()).Times(1).WillOnce(Return(false));
-  scheduler_->Run();
-  EXPECT_FALSE(scheduler_->enabled_);
+  scheduler_.enabled_ = true;
+  EXPECT_CALL(scheduler_, IsOfficialBuild()).Times(1).WillOnce(Return(false));
+  scheduler_.Run();
+  EXPECT_FALSE(scheduler_.enabled_);
   EXPECT_EQ(NULL, attempter_.update_check_scheduler());
 }
 
@@ -147,48 +148,48 @@
             UpdateCheckScheduler::kTimeoutRegularFuzz,
             &interval_min,
             &interval_max);
-  EXPECT_CALL(*scheduler_, IsOfficialBuild()).Times(1).WillOnce(Return(true));
-  EXPECT_CALL(*scheduler_, IsBootDeviceRemovable())
+  EXPECT_CALL(scheduler_, IsOfficialBuild()).Times(1).WillOnce(Return(true));
+  EXPECT_CALL(scheduler_, IsBootDeviceRemovable())
       .Times(1)
       .WillOnce(Return(false));
-  EXPECT_CALL(*scheduler_,
+  EXPECT_CALL(scheduler_,
               GTimeoutAddSeconds(AllOf(Ge(interval_min), Le(interval_max)),
-                                 scheduler_->StaticCheck)).Times(1);
-  scheduler_->Run();
-  EXPECT_TRUE(scheduler_->enabled_);
-  EXPECT_EQ(scheduler_.get(), attempter_.update_check_scheduler());
+                                 scheduler_.StaticCheck)).Times(1);
+  scheduler_.Run();
+  EXPECT_TRUE(scheduler_.enabled_);
+  EXPECT_EQ(&scheduler_, attempter_.update_check_scheduler());
 }
 
 TEST_F(UpdateCheckSchedulerTest, ScheduleCheckDisabledTest) {
-  EXPECT_CALL(*scheduler_, GTimeoutAddSeconds(_, _)).Times(0);
-  scheduler_->ScheduleCheck(250, 30);
-  EXPECT_EQ(0, scheduler_->last_interval_);
-  EXPECT_FALSE(scheduler_->scheduled_);
+  EXPECT_CALL(scheduler_, GTimeoutAddSeconds(_, _)).Times(0);
+  scheduler_.ScheduleCheck(250, 30);
+  EXPECT_EQ(0, scheduler_.last_interval_);
+  EXPECT_FALSE(scheduler_.scheduled_);
 }
 
 TEST_F(UpdateCheckSchedulerTest, ScheduleCheckEnabledTest) {
   int interval_min, interval_max;
   FuzzRange(100, 10, &interval_min,&interval_max);
-  EXPECT_CALL(*scheduler_,
+  EXPECT_CALL(scheduler_,
               GTimeoutAddSeconds(AllOf(Ge(interval_min), Le(interval_max)),
-                                 scheduler_->StaticCheck)).Times(1);
-  scheduler_->enabled_ = true;
-  scheduler_->ScheduleCheck(100, 10);
-  EXPECT_EQ(100, scheduler_->last_interval_);
-  EXPECT_TRUE(scheduler_->scheduled_);
+                                 scheduler_.StaticCheck)).Times(1);
+  scheduler_.enabled_ = true;
+  scheduler_.ScheduleCheck(100, 10);
+  EXPECT_EQ(100, scheduler_.last_interval_);
+  EXPECT_TRUE(scheduler_.scheduled_);
 }
 
 TEST_F(UpdateCheckSchedulerTest, ScheduleCheckNegativeIntervalTest) {
-  EXPECT_CALL(*scheduler_, GTimeoutAddSeconds(0, scheduler_->StaticCheck))
+  EXPECT_CALL(scheduler_, GTimeoutAddSeconds(0, scheduler_.StaticCheck))
       .Times(1);
-  scheduler_->enabled_ = true;
-  scheduler_->ScheduleCheck(-50, 20);
-  EXPECT_TRUE(scheduler_->scheduled_);
+  scheduler_.enabled_ = true;
+  scheduler_.ScheduleCheck(-50, 20);
+  EXPECT_TRUE(scheduler_.scheduled_);
 }
 
 TEST_F(UpdateCheckSchedulerTest, ScheduleNextCheckDisabledTest) {
-  EXPECT_CALL(*scheduler_, GTimeoutAddSeconds(_, _)).Times(0);
-  scheduler_->ScheduleNextCheck();
+  EXPECT_CALL(scheduler_, GTimeoutAddSeconds(_, _)).Times(0);
+  scheduler_.ScheduleNextCheck();
 }
 
 TEST_F(UpdateCheckSchedulerTest, ScheduleNextCheckEnabledTest) {
@@ -197,16 +198,16 @@
             UpdateCheckScheduler::kTimeoutRegularFuzz,
             &interval_min,
             &interval_max);
-  EXPECT_CALL(*scheduler_,
+  EXPECT_CALL(scheduler_,
               GTimeoutAddSeconds(AllOf(Ge(interval_min), Le(interval_max)),
-                                 scheduler_->StaticCheck)).Times(1);
-  scheduler_->enabled_ = true;
-  scheduler_->ScheduleNextCheck();
+                                 scheduler_.StaticCheck)).Times(1);
+  scheduler_.enabled_ = true;
+  scheduler_.ScheduleNextCheck();
 }
 
 TEST_F(UpdateCheckSchedulerTest, SetUpdateStatusIdleDisabledTest) {
-  EXPECT_CALL(*scheduler_, GTimeoutAddSeconds(_, _)).Times(0);
-  scheduler_->SetUpdateStatus(UPDATE_STATUS_IDLE);
+  EXPECT_CALL(scheduler_, GTimeoutAddSeconds(_, _)).Times(0);
+  scheduler_.SetUpdateStatus(UPDATE_STATUS_IDLE);
 }
 
 TEST_F(UpdateCheckSchedulerTest, SetUpdateStatusIdleEnabledTest) {
@@ -215,24 +216,24 @@
             UpdateCheckScheduler::kTimeoutRegularFuzz,
             &interval_min,
             &interval_max);
-  EXPECT_CALL(*scheduler_,
+  EXPECT_CALL(scheduler_,
               GTimeoutAddSeconds(AllOf(Ge(interval_min), Le(interval_max)),
-                                 scheduler_->StaticCheck)).Times(1);
-  scheduler_->enabled_ = true;
-  scheduler_->SetUpdateStatus(UPDATE_STATUS_IDLE);
+                                 scheduler_.StaticCheck)).Times(1);
+  scheduler_.enabled_ = true;
+  scheduler_.SetUpdateStatus(UPDATE_STATUS_IDLE);
 }
 
 TEST_F(UpdateCheckSchedulerTest, SetUpdateStatusNonIdleTest) {
-  EXPECT_CALL(*scheduler_, GTimeoutAddSeconds(_, _)).Times(0);
-  scheduler_->SetUpdateStatus(UPDATE_STATUS_DOWNLOADING);
-  scheduler_->enabled_ = true;
-  scheduler_->SetUpdateStatus(UPDATE_STATUS_DOWNLOADING);
+  EXPECT_CALL(scheduler_, GTimeoutAddSeconds(_, _)).Times(0);
+  scheduler_.SetUpdateStatus(UPDATE_STATUS_DOWNLOADING);
+  scheduler_.enabled_ = true;
+  scheduler_.SetUpdateStatus(UPDATE_STATUS_DOWNLOADING);
 }
 
 TEST_F(UpdateCheckSchedulerTest, StaticCheckTest) {
-  scheduler_->scheduled_ = true;
+  scheduler_.scheduled_ = true;
   EXPECT_CALL(attempter_, Update("", "")).Times(1);
-  UpdateCheckSchedulerUnderTest::StaticCheck(scheduler_.get());
+  UpdateCheckSchedulerUnderTest::StaticCheck(&scheduler_);
 }
 
 }  // namespace chromeos_update_engine