Fixes a bug that .crx can not be installed by "Could not create
directory for unzipping." in the case that the environment variable
TMP is set to a root directory of a drive such as "C:\"

TEST=Add new tests to base_unittest
BUG=23911
Review URL: http://codereview.chromium.org/257061

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28529 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index b1f9fed..073dbae 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -8,6 +8,7 @@
 #include <windows.h>
 #include <shellapi.h>
 #include <shlobj.h>
+#include <tchar.h>
 #endif
 
 #include <fstream>
@@ -773,7 +774,35 @@
   EXPECT_TRUE(file_util::PathExists(dir_name_to));
   EXPECT_TRUE(file_util::PathExists(file_name_to));
 }
-#endif
+
+TEST_F(FileUtilTest, GetTempDirTest) {
+  static const TCHAR* kTmpKey = _T("TMP");
+  static const TCHAR* kTmpValues[] = {
+    _T(""), _T("C:"), _T("C:\\"), _T("C:\\tmp"), _T("C:\\tmp\\")
+  };
+  // Save the original $TMP.
+  size_t original_tmp_size;
+  TCHAR* original_tmp;
+  ASSERT_EQ(0, ::_tdupenv_s(&original_tmp, &original_tmp_size, kTmpKey));
+  // original_tmp may be NULL.
+
+  for (unsigned int i = 0; i < arraysize(kTmpValues); ++i) {
+    FilePath path;
+    ::_tputenv_s(kTmpKey, kTmpValues[i]);
+    file_util::GetTempDir(&path);
+    EXPECT_TRUE(path.IsAbsolute()) << "$TMP=" << kTmpValues[i] <<
+        " result=" << path.value();
+  }
+
+  // Restore the original $TMP.
+  if (original_tmp) {
+    ::_tputenv_s(kTmpKey, original_tmp);
+    free(original_tmp);
+  } else {
+    ::_tputenv_s(kTmpKey, _T(""));
+  }
+}
+#endif  // OS_WIN
 
 TEST_F(FileUtilTest, CreateTemporaryFileTest) {
   FilePath temp_files[3];