AU/unittest: allow use of a parametric update completed marker

This should allow unit tests to be run in parallel. We introduce
a private constructor available only to specific test classes of
UpdateAttempter, which allows us to set a different marker.

Note that, in all unit tests that do not specifically make use of this
marker, we actually want UpdateAttempter to ignore it entirely. I'm not
entirely positive whether not ignoring would lead to interferences
between concurrently run tests, but I think it's better to err on the
safe side.  (The marker is never ignored when used with any code other
than UpdateAttempter unit testing code.)

BUG=chromium:236465
TEST=Unit tests pass incl ignore semantics when not needed

Change-Id: I30fbed2ae2c21368d79127ed44811007e2a66e77
Reviewed-on: https://gerrit.chromium.org/gerrit/63840
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/update_attempter_unittest.cc b/update_attempter_unittest.cc
index 91c6dfe..1a52095 100644
--- a/update_attempter_unittest.cc
+++ b/update_attempter_unittest.cc
@@ -40,9 +40,17 @@
 // methods.
 class UpdateAttempterUnderTest : public UpdateAttempter {
  public:
-  explicit UpdateAttempterUnderTest(MockSystemState* mock_system_state,
-                                    MockDbusGlib* dbus)
-      : UpdateAttempter(mock_system_state, dbus) {}
+  // We always feed an explicit update completed marker name; however, unless
+  // explicitly specified, we feed an empty string, which causes the
+  // UpdateAttempter class to ignore / not write the marker file.
+  UpdateAttempterUnderTest(MockSystemState* mock_system_state,
+                           MockDbusGlib* dbus)
+      : UpdateAttempter(mock_system_state, dbus, "") {}
+
+  UpdateAttempterUnderTest(MockSystemState* mock_system_state,
+                           MockDbusGlib* dbus,
+                           const string& update_completed_marker)
+      : UpdateAttempter(mock_system_state, dbus, update_completed_marker) {}
 };
 
 class UpdateAttempterTest : public ::testing::Test {
@@ -170,12 +178,16 @@
 }
 
 TEST_F(UpdateAttempterTest, RunAsRootConstructWithUpdatedMarkerTest) {
-  extern const char* kUpdateCompletedMarker;
-  const FilePath kMarker(kUpdateCompletedMarker);
-  EXPECT_EQ(0, file_util::WriteFile(kMarker, "", 0));
-  UpdateAttempterUnderTest attempter(&mock_system_state_, &dbus_);
+  string test_update_completed_marker;
+  CHECK(utils::MakeTempFile(
+          "/tmp/update_attempter_unittest-update_completed_marker-XXXXXX",
+          &test_update_completed_marker, NULL));
+  ScopedPathUnlinker completed_marker_unlinker(test_update_completed_marker);
+  const FilePath marker(test_update_completed_marker);
+  EXPECT_EQ(0, file_util::WriteFile(marker, "", 0));
+  UpdateAttempterUnderTest attempter(&mock_system_state_, &dbus_,
+                                     test_update_completed_marker);
   EXPECT_EQ(UPDATE_STATUS_UPDATED_NEED_REBOOT, attempter.status());
-  EXPECT_TRUE(file_util::Delete(kMarker, false));
 }
 
 TEST_F(UpdateAttempterTest, GetErrorCodeForActionTest) {