AU/unittest: eliminate use of fixed named test directories

This fixes race conditions when tests are run in parallel.

Note that integration_unittest.cc is currently not (never was?) being
compiled, so all changes are lexically oriented and visually verified
only.

BUG=chromium:236465
TEST=Tests successful

Change-Id: I6181a2cc0c10f6fcf8f982fc263c7a02e5082eeb
Reviewed-on: https://gerrit.chromium.org/gerrit/62954
Tested-by: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Commit-Queue: Gilad Arnold <garnold@chromium.org>
diff --git a/update_attempter_unittest.cc b/update_attempter_unittest.cc
index b5df68c..91c6dfe 100644
--- a/update_attempter_unittest.cc
+++ b/update_attempter_unittest.cc
@@ -21,6 +21,7 @@
 #include "update_engine/test_utils.h"
 #include "update_engine/update_attempter.h"
 #include "update_engine/update_check_scheduler.h"
+#include "update_engine/utils.h"
 
 using std::string;
 using testing::_;
@@ -52,7 +53,10 @@
         loop_(NULL) {
     mock_system_state_.set_connection_manager(&mock_connection_manager);
   }
+
   virtual void SetUp() {
+    CHECK(utils::MakeTempDirectory("UpdateAttempterTest-XXXXXX", &test_dir_));
+
     EXPECT_EQ(NULL, attempter_.dbus_service_);
     EXPECT_TRUE(attempter_.system_state_ != NULL);
     EXPECT_EQ(NULL, attempter_.update_check_scheduler_);
@@ -70,6 +74,10 @@
     prefs_ = mock_system_state_.mock_prefs();
   }
 
+  virtual void TearDown() {
+    utils::RecursiveUnlinkDir(test_dir_);
+  }
+
   void QuitMainLoop();
   static gboolean StaticQuitMainLoop(gpointer data);
 
@@ -116,6 +124,8 @@
   NiceMock<PrefsMock>* prefs_; // shortcut to mock_system_state_->mock_prefs()
   NiceMock<MockConnectionManager> mock_connection_manager;
   GMainLoop* loop_;
+
+  string test_dir_;
 };
 
 TEST_F(UpdateAttempterTest, ActionCompletedDownloadTest) {
@@ -612,7 +622,8 @@
       DoAll(SetArgumentPointee<0>(std::string("beta-channel")),
       Return(true)));
 
-  attempter_.omaha_request_params_->set_root("./UpdateAttempterTest");
+  ASSERT_FALSE(test_dir_.empty());
+  attempter_.omaha_request_params_->set_root(test_dir_);
   attempter_.Update("", "", false, false, false);
   EXPECT_EQ("beta-channel",
             attempter_.omaha_request_params_->target_channel());