Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1040)

Unified Diff: chromecast/base/error_codes_unittest.cc

Issue 1484713003: [Chromecast] Use ScopedTemp[File|Dir] in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Style Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chromecast/base/error_codes_unittest.cc
diff --git a/chromecast/base/error_codes_unittest.cc b/chromecast/base/error_codes_unittest.cc
index 293d8952f77d5d371c4515e50c46562d979cd90e..ef9c1924f8572391e30b8249e6347c92fc16b30f 100644
--- a/chromecast/base/error_codes_unittest.cc
+++ b/chromecast/base/error_codes_unittest.cc
@@ -5,6 +5,7 @@
#include "base/base_paths.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
+#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_ptr.h"
#include "base/test/scoped_path_override.h"
#include "chromecast/base/error_codes.h"
@@ -19,12 +20,15 @@ class ErrorCodesTest : public testing::Test {
void SetUp() override {
// Set up a temporary directory which will be used as our fake home dir.
- ASSERT_TRUE(base::CreateNewTempDirectory("", &fake_home_dir_));
+ ASSERT_TRUE(fake_home_dir_.CreateUniqueTempDir());
path_override_.reset(
- new base::ScopedPathOverride(base::DIR_HOME, fake_home_dir_));
+ new base::ScopedPathOverride(base::DIR_HOME, fake_home_dir_.path()));
}
- base::FilePath fake_home_dir_;
+ base::FilePath home_path() const { return fake_home_dir_.path(); }
+
+ private:
+ base::ScopedTempDir fake_home_dir_;
scoped_ptr<base::ScopedPathOverride> path_override_;
};
@@ -36,29 +40,29 @@ TEST_F(ErrorCodesTest, SetInitialErrorCodeSucceedsWithNoError) {
ASSERT_TRUE(SetInitialErrorCode(NO_ERROR));
// File should not be written.
- ASSERT_FALSE(base::PathExists(fake_home_dir_.Append("initial_error")));
+ ASSERT_FALSE(base::PathExists(home_path().Append("initial_error")));
EXPECT_EQ(NO_ERROR, GetInitialErrorCode());
}
TEST_F(ErrorCodesTest, SetInitialErrorCodeSucceedsWithValidErrors) {
// Write initial error and read it from the file.
EXPECT_TRUE(SetInitialErrorCode(ERROR_WEB_CONTENT_RENDER_VIEW_GONE));
- EXPECT_TRUE(base::PathExists(fake_home_dir_.Append("initial_error")));
+ EXPECT_TRUE(base::PathExists(home_path().Append("initial_error")));
EXPECT_EQ(ERROR_WEB_CONTENT_RENDER_VIEW_GONE, GetInitialErrorCode());
// File should be updated with most recent error.
EXPECT_TRUE(SetInitialErrorCode(ERROR_UNKNOWN));
- EXPECT_TRUE(base::PathExists(fake_home_dir_.Append("initial_error")));
+ EXPECT_TRUE(base::PathExists(home_path().Append("initial_error")));
EXPECT_EQ(ERROR_UNKNOWN, GetInitialErrorCode());
// File should be updated with most recent error.
EXPECT_TRUE(SetInitialErrorCode(ERROR_WEB_CONTENT_NAME_NOT_RESOLVED));
- EXPECT_TRUE(base::PathExists(fake_home_dir_.Append("initial_error")));
+ EXPECT_TRUE(base::PathExists(home_path().Append("initial_error")));
EXPECT_EQ(ERROR_WEB_CONTENT_NAME_NOT_RESOLVED, GetInitialErrorCode());
// File should be removed after writing NO_ERROR.
EXPECT_TRUE(SetInitialErrorCode(NO_ERROR));
- EXPECT_FALSE(base::PathExists(fake_home_dir_.Append("initial_error")));
+ EXPECT_FALSE(base::PathExists(home_path().Append("initial_error")));
EXPECT_EQ(NO_ERROR, GetInitialErrorCode());
}

Powered by Google App Engine
This is Rietveld 408576698