update_engine: Use FakePrefs instead of the real Prefs in unittests.

Several unittests were using the real Prefs class on a temporary
directory that was removed at the end of the test. On
UpdateAttempterTest.DecrementUpdateCheckCountTest this directory was
leaked due to the use of the ScopedDirRemover which only works on
empty dirs, used elsewhere to remove mount points.

This patch replaces all the uses of a real Prefs class initialized
on a temp directory with a FakePrefs instance, which provides the
same functionality and simplifies the initialization.

p2p_manager_unittest.cc is left out of this patch since its usage of
Prefs is being removed in a different CL.

BUG=chromium:356906
TEST=All unittests still pass.

Change-Id: Ieba6b924fcbda9e1787becba334792aabe0f395a
Reviewed-on: https://chromium-review.googlesource.com/227444
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/utils_unittest.cc b/utils_unittest.cc
index 832c2af..44d1b87 100644
--- a/utils_unittest.cc
+++ b/utils_unittest.cc
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
+#include "update_engine/utils.h"
+
 #include <errno.h>
 #include <stdint.h>
 #include <sys/stat.h>
@@ -11,17 +13,17 @@
 #include <string>
 #include <vector>
 
-#include <base/files/file_util.h>
 #include <base/files/file_path.h>
+#include <base/files/file_util.h>
 #include <base/strings/string_util.h>
 #include <base/strings/stringprintf.h>
 #include <gtest/gtest.h>
 
 #include "update_engine/fake_clock.h"
+#include "update_engine/fake_prefs.h"
 #include "update_engine/fake_system_state.h"
 #include "update_engine/prefs.h"
 #include "update_engine/test_utils.h"
-#include "update_engine/utils.h"
 
 using std::map;
 using std::string;
@@ -571,11 +573,7 @@
   FakeClock fake_clock;
   base::TimeDelta duration;
   string state_variable_key = "test-prefs";
-  string temp_dir;
-  Prefs fake_prefs;
-
-  EXPECT_TRUE(utils::MakeTempDirectory("DurationPrefs.XXXXXX", &temp_dir));
-  fake_prefs.Init(base::FilePath(temp_dir));
+  FakePrefs fake_prefs;
 
   fake_system_state.set_clock(&fake_clock);
   fake_system_state.set_prefs(&fake_prefs);
@@ -640,8 +638,6 @@
                                              state_variable_key,
                                              &duration));
   EXPECT_EQ(duration.InSeconds(), 1);
-
-  EXPECT_TRUE(utils::RecursiveUnlinkDir(temp_dir));
 }
 
 TEST(UtilsTest, MonotonicDurationHelper) {