Skip to content

Commit

Permalink
misc files R-U: Change ScopedTempDir::path() to GetPath()
Browse files Browse the repository at this point in the history
path() is being deprecated, GetPath() has better checking against wrong use.

For more context, see https://codereview.chromium.org/2275553005/.

BUG=640599
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.win:win10_chromium_x64_rel_ng

Review-Url: https://codereview.chromium.org/2317123003
Cr-Commit-Position: refs/heads/master@{#421483}
  • Loading branch information
vabr authored and Commit bot committed Sep 28, 2016
1 parent 8db1c39 commit a981982
Show file tree
Hide file tree
Showing 22 changed files with 163 additions and 164 deletions.
6 changes: 3 additions & 3 deletions remoting/host/host_config_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ class HostConfigTest : public testing::Test {
TEST_F(HostConfigTest, InvalidFile) {
ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
base::FilePath non_existent_file =
test_dir_.path().AppendASCII("non_existent.json");
test_dir_.GetPath().AppendASCII("non_existent.json");
EXPECT_FALSE(HostConfigFromJsonFile(non_existent_file));
}

TEST_F(HostConfigTest, Read) {
ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
base::FilePath test_file = test_dir_.path().AppendASCII("read.json");
base::FilePath test_file = test_dir_.GetPath().AppendASCII("read.json");
WriteTestFile(test_file);
std::unique_ptr<base::DictionaryValue> target(
HostConfigFromJsonFile(test_file));
Expand All @@ -74,7 +74,7 @@ TEST_F(HostConfigTest, Read) {
TEST_F(HostConfigTest, Write) {
ASSERT_TRUE(test_dir_.CreateUniqueTempDir());

base::FilePath test_file = test_dir_.path().AppendASCII("write.json");
base::FilePath test_file = test_dir_.GetPath().AppendASCII("write.json");
WriteTestFile(test_file);
std::unique_ptr<base::DictionaryValue> target(
HostConfigFromJsonFile(test_file));
Expand Down
2 changes: 1 addition & 1 deletion remoting/host/linux/audio_pipe_reader_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AudioPipeReaderTest : public testing::Test,

void SetUp() override {
ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
pipe_path_ = test_dir_.path().AppendASCII("test_pipe");
pipe_path_ = test_dir_.GetPath().AppendASCII("test_pipe");
audio_thread_.reset(new base::Thread("TestAudioThread"));
audio_thread_->StartWithOptions(
base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
Expand Down
4 changes: 2 additions & 2 deletions remoting/host/linux/certificate_watcher_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CertificateWatcherTest : public testing::Test {
base::Unretained(this)),
task_runner_));
watcher_->SetDelayForTests(base::TimeDelta::FromSeconds(0));
watcher_->SetWatchPathForTests(temp_dir_.path());
watcher_->SetWatchPathForTests(temp_dir_.GetPath());
}

~CertificateWatcherTest() override {
Expand Down Expand Up @@ -84,7 +84,7 @@ class CertificateWatcherTest : public testing::Test {

void TouchFileTask(const char* filename) {
std::string testWriteString = std::to_string(rand());
base::FilePath path = temp_dir_.path().AppendASCII(filename);
base::FilePath path = temp_dir_.GetPath().AppendASCII(filename);

if (base::PathExists(path)) {
EXPECT_TRUE(base::AppendToFile(path, testWriteString.c_str(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SecurityKeyAuthHandlerPosixTest : public testing::Test {
: run_loop_(new base::RunLoop()),
file_thread_("SecurityKeyAuthHandlerPosixTest_FileThread") {
EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
socket_path_ = temp_dir_.path().Append(kSocketFilename);
socket_path_ = temp_dir_.GetPath().Append(kSocketFilename);
remoting::SecurityKeyAuthHandler::SetSecurityKeySocketName(socket_path_);

EXPECT_TRUE(file_thread_.StartWithOptions(
Expand Down
4 changes: 2 additions & 2 deletions rlz/lib/rlz_lib_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,8 @@ class ReadonlyRlzDirectoryTest : public RlzLibTestNoMachineState {
void ReadonlyRlzDirectoryTest::SetUp() {
RlzLibTestNoMachineState::SetUp();
// Make the rlz directory non-writeable.
int chmod_result = chmod(m_rlz_test_helper_.temp_dir_.path().value().c_str(),
0500);
int chmod_result =
chmod(m_rlz_test_helper_.temp_dir_.GetPath().value().c_str(), 0500);
ASSERT_EQ(0, chmod_result);
}

Expand Down
2 changes: 1 addition & 1 deletion rlz/test/rlz_test_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void RlzLibTestNoMachineStateHelper::SetUp() {
#endif // defined(OS_WIN)
#if defined(OS_POSIX)
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
rlz_lib::testing::SetRlzStoreDirectory(temp_dir_.path());
rlz_lib::testing::SetRlzStoreDirectory(temp_dir_.GetPath());
#endif // defined(OS_POSIX)
}

Expand Down
2 changes: 1 addition & 1 deletion rlz/test/rlz_unittest_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main(int argc, char **argv) {
// creates and owns RlzValueStore object for its lifetime.
base::ScopedTempDir temp_dir;
if (temp_dir.CreateUniqueTempDir())
rlz_lib::testing::SetRlzStoreDirectory(temp_dir.path());
rlz_lib::testing::SetRlzStoreDirectory(temp_dir.GetPath());
#endif
rlz_lib::SupplementaryBranding branding("TEST");
ret = RUN_ALL_TESTS();
Expand Down
3 changes: 2 additions & 1 deletion sandbox/win/src/address_sanitizer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ TEST_F(AddressSanitizerTests, TestAddressSanitizer) {
base::ScopedTempDir temp_directory;
base::FilePath temp_file_name;
ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
ASSERT_TRUE(CreateTemporaryFileInDir(temp_directory.path(), &temp_file_name));
ASSERT_TRUE(
CreateTemporaryFileInDir(temp_directory.GetPath(), &temp_file_name));

SECURITY_ATTRIBUTES attrs = {};
attrs.nLength = sizeof(attrs);
Expand Down
3 changes: 2 additions & 1 deletion sandbox/win/src/handle_inheritance_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ TEST(HandleInheritanceTests, TestStdoutInheritance) {
base::ScopedTempDir temp_directory;
base::FilePath temp_file_name;
ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
ASSERT_TRUE(CreateTemporaryFileInDir(temp_directory.path(), &temp_file_name));
ASSERT_TRUE(
CreateTemporaryFileInDir(temp_directory.GetPath(), &temp_file_name));

SECURITY_ATTRIBUTES attrs = {};
attrs.nLength = sizeof(attrs);
Expand Down
2 changes: 1 addition & 1 deletion sandbox/win/src/process_mitigations_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ void TestWin10ImageLoadLowLabel(bool is_success_test) {

base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
base::FilePath new_path = temp_dir.path();
base::FilePath new_path = temp_dir.GetPath();
new_path = new_path.Append(L"lowIL_calc.exe");

// Test file will be cleaned up by the ScopedTempDir.
Expand Down
2 changes: 1 addition & 1 deletion sql/test/sql_test_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SQLTestBase::~SQLTestBase() {
}

base::FilePath SQLTestBase::db_path() {
return temp_dir_.path().AppendASCII("SQLTest.db");
return temp_dir_.GetPath().AppendASCII("SQLTest.db");
}

sql::Connection& SQLTestBase::db() {
Expand Down
6 changes: 3 additions & 3 deletions third_party/leveldatabase/env_chromium_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ TEST(ChromiumEnv, DeleteBackupTables) {

base::ScopedTempDir scoped_temp_dir;
ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir());
base::FilePath dir = scoped_temp_dir.path();
base::FilePath dir = scoped_temp_dir.GetPath();

DB* db;
Status status = DB::Open(options, dir.AsUTF8Unsafe(), &db);
Expand Down Expand Up @@ -136,7 +136,7 @@ TEST(ChromiumEnv, DeleteBackupTables) {
TEST(ChromiumEnv, GetChildrenEmptyDir) {
base::ScopedTempDir scoped_temp_dir;
ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir());
base::FilePath dir = scoped_temp_dir.path();
base::FilePath dir = scoped_temp_dir.GetPath();

Env* env = Env::Default();
std::vector<std::string> result;
Expand All @@ -148,7 +148,7 @@ TEST(ChromiumEnv, GetChildrenEmptyDir) {
TEST(ChromiumEnv, GetChildrenPriorResults) {
base::ScopedTempDir scoped_temp_dir;
ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir());
base::FilePath dir = scoped_temp_dir.path();
base::FilePath dir = scoped_temp_dir.GetPath();

base::FilePath new_file_dir = dir.Append(FPL("tmp_file"));
FILE* f = fopen(new_file_dir.AsUTF8Unsafe().c_str(), "w");
Expand Down
2 changes: 1 addition & 1 deletion third_party/zlib/google/zip_reader_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ZipReaderTest : public PlatformTest {
PlatformTest::SetUp();

ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
test_dir_ = temp_dir_.path();
test_dir_ = temp_dir_.GetPath();

ASSERT_TRUE(GetTestDataDirectory(&test_data_dir_));

Expand Down
23 changes: 11 additions & 12 deletions third_party/zlib/google/zip_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ZipTest : public PlatformTest {
PlatformTest::SetUp();

ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
test_dir_ = temp_dir_.path();
test_dir_ = temp_dir_.GetPath();

base::FilePath zip_path(test_dir_);
zip_contents_.insert(zip_path.AppendASCII("foo.txt"));
Expand Down Expand Up @@ -122,9 +122,9 @@ class ZipTest : public PlatformTest {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());

base::FilePath zip_file = temp_dir.path().AppendASCII("out.zip");
base::FilePath src_dir = temp_dir.path().AppendASCII("input");
base::FilePath out_dir = temp_dir.path().AppendASCII("output");
base::FilePath zip_file = temp_dir.GetPath().AppendASCII("out.zip");
base::FilePath src_dir = temp_dir.GetPath().AppendASCII("input");
base::FilePath out_dir = temp_dir.GetPath().AppendASCII("output");

base::FilePath src_file = src_dir.AppendASCII("test.txt");
base::FilePath out_file = out_dir.AppendASCII("test.txt");
Expand Down Expand Up @@ -220,7 +220,7 @@ TEST_F(ZipTest, Zip) {

base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
base::FilePath zip_file = temp_dir.path().AppendASCII("out.zip");
base::FilePath zip_file = temp_dir.GetPath().AppendASCII("out.zip");

EXPECT_TRUE(zip::Zip(src_dir, zip_file, true));
TestUnzipFile(zip_file, true);
Expand All @@ -233,7 +233,7 @@ TEST_F(ZipTest, ZipIgnoreHidden) {

base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
base::FilePath zip_file = temp_dir.path().AppendASCII("out.zip");
base::FilePath zip_file = temp_dir.GetPath().AppendASCII("out.zip");

EXPECT_TRUE(zip::Zip(src_dir, zip_file, false));
TestUnzipFile(zip_file, false);
Expand All @@ -247,11 +247,10 @@ TEST_F(ZipTest, ZipNonASCIIDir) {
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
// Append 'Тест' (in cyrillic).
base::FilePath src_dir_russian =
temp_dir.path().Append(base::FilePath::FromUTF8Unsafe(
"\xD0\xA2\xD0\xB5\xD1\x81\xD1\x82"));
base::FilePath src_dir_russian = temp_dir.GetPath().Append(
base::FilePath::FromUTF8Unsafe("\xD0\xA2\xD0\xB5\xD1\x81\xD1\x82"));
base::CopyDirectory(src_dir, src_dir_russian, true);
base::FilePath zip_file = temp_dir.path().AppendASCII("out_russian.zip");
base::FilePath zip_file = temp_dir.GetPath().AppendASCII("out_russian.zip");

EXPECT_TRUE(zip::Zip(src_dir_russian, zip_file, true));
TestUnzipFile(zip_file, true);
Expand Down Expand Up @@ -287,7 +286,7 @@ TEST_F(ZipTest, ZipFiles) {

base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
base::FilePath zip_name = temp_dir.path().AppendASCII("out.zip");
base::FilePath zip_name = temp_dir.GetPath().AppendASCII("out.zip");

base::File zip_file(zip_name,
base::File::FLAG_CREATE | base::File::FLAG_WRITE);
Expand Down Expand Up @@ -321,7 +320,7 @@ TEST_F(ZipTest, UnzipFilesWithIncorrectSize) {

base::ScopedTempDir scoped_temp_dir;
ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir());
const base::FilePath& temp_dir = scoped_temp_dir.path();
const base::FilePath& temp_dir = scoped_temp_dir.GetPath();

ASSERT_TRUE(zip::Unzip(test_zip_file, temp_dir));
EXPECT_TRUE(base::DirectoryExists(temp_dir.AppendASCII("d")));
Expand Down
5 changes: 3 additions & 2 deletions tools/gn/exec_process_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ bool ExecPython(const std::string& command,
std::string* std_err,
int* exit_code) {
base::ScopedTempDir temp_dir;
CHECK(temp_dir.CreateUniqueTempDir());
base::CommandLine::StringVector args;
#if defined(OS_WIN)
args.push_back(L"python");
Expand All @@ -36,8 +37,8 @@ bool ExecPython(const std::string& command,
args.push_back("-c");
args.push_back(command);
#endif
return ExecProcess(
base::CommandLine(args), temp_dir.path(), std_out, std_err, exit_code);
return ExecProcess(base::CommandLine(args), temp_dir.GetPath(), std_out,
std_err, exit_code);
}
} // namespace

Expand Down
4 changes: 2 additions & 2 deletions tools/gn/filesystem_utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ TEST(FilesystemUtils, ContentsEqual) {

std::string data = "foo";

base::FilePath file_path = temp_dir.path().AppendASCII("foo.txt");
base::FilePath file_path = temp_dir.GetPath().AppendASCII("foo.txt");
base::WriteFile(file_path, data.c_str(), static_cast<int>(data.size()));

EXPECT_TRUE(ContentsEqual(file_path, data));
Expand All @@ -602,7 +602,7 @@ TEST(FilesystemUtils, WriteFileIfChanged) {

// Write if file doesn't exist. Create also directory.
base::FilePath file_path =
temp_dir.path().AppendASCII("bar").AppendASCII("foo.txt");
temp_dir.GetPath().AppendASCII("bar").AppendASCII("foo.txt");
EXPECT_TRUE(WriteFileIfChanged(file_path, data, nullptr));

base::File::Info file_info;
Expand Down
7 changes: 4 additions & 3 deletions tools/gn/function_write_file_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TEST(WriteFile, WithData) {
// Make a real directory for writing the files.
base::ScopedTempDir temp_dir;
ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
setup.build_settings()->SetRootPath(temp_dir.path());
setup.build_settings()->SetRootPath(temp_dir.GetPath());
setup.build_settings()->SetBuildDir(SourceDir("//out/"));

Value some_string(nullptr, "some string contents");
Expand All @@ -52,8 +52,9 @@ TEST(WriteFile, WithData) {

// Should be able to write to a new dir inside the out dir.
EXPECT_TRUE(CallWriteFile(setup.scope(), "//out/foo.txt", some_string));
base::FilePath foo_name = temp_dir.path().Append(FILE_PATH_LITERAL("out"))
.Append(FILE_PATH_LITERAL("foo.txt"));
base::FilePath foo_name = temp_dir.GetPath()
.Append(FILE_PATH_LITERAL("out"))
.Append(FILE_PATH_LITERAL("foo.txt"));
std::string result_contents;
EXPECT_TRUE(base::ReadFileToString(foo_name, &result_contents));
EXPECT_EQ(some_string.string_value(), result_contents);
Expand Down
6 changes: 3 additions & 3 deletions ui/app_list/search/history_data_store_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class HistoryDataStoreTest : public testing::Test {
}

void OpenStore(const std::string& file_name) {
data_file_ = temp_dir_.path().AppendASCII(file_name);
data_file_ = temp_dir_.GetPath().AppendASCII(file_name);
store_ = new HistoryDataStore(scoped_refptr<DictionaryDataStore>(
new DictionaryDataStore(data_file_, worker_pool_owner_.pool().get())));
Load();
Expand All @@ -70,8 +70,8 @@ class HistoryDataStoreTest : public testing::Test {
}

void WriteDataFile(const std::string& file_name, const std::string& data) {
base::WriteFile(
temp_dir_.path().AppendASCII(file_name), data.c_str(), data.size());
base::WriteFile(temp_dir_.GetPath().AppendASCII(file_name), data.c_str(),
data.size());
}

HistoryDataStore* store() { return store_.get(); }
Expand Down
14 changes: 9 additions & 5 deletions ui/base/resource/data_pack_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ extern const size_t kSampleCorruptPakSize;
TEST(DataPackTest, LoadFromPath) {
base::ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
base::FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak"));
base::FilePath data_path =
dir.GetPath().Append(FILE_PATH_LITERAL("sample.pak"));

// Dump contents into the pak file.
ASSERT_EQ(base::WriteFile(data_path, kSamplePakContents, kSamplePakSize),
Expand Down Expand Up @@ -67,7 +68,8 @@ TEST(DataPackTest, LoadFromPath) {
TEST(DataPackTest, LoadFromFile) {
base::ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
base::FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak"));
base::FilePath data_path =
dir.GetPath().Append(FILE_PATH_LITERAL("sample.pak"));

// Dump contents into the pak file.
ASSERT_EQ(base::WriteFile(data_path, kSamplePakContents, kSamplePakSize),
Expand Down Expand Up @@ -102,7 +104,8 @@ TEST(DataPackTest, LoadFromFile) {
TEST(DataPackTest, LoadFromFileRegion) {
base::ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
base::FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak"));
base::FilePath data_path =
dir.GetPath().Append(FILE_PATH_LITERAL("sample.pak"));

// Construct a file which has a non page-aligned zero-filled header followed
// by the actual pak file content.
Expand Down Expand Up @@ -158,7 +161,7 @@ TEST(DataPackTest, LoadFileWithTruncatedHeader) {
TEST_P(DataPackTest, Write) {
base::ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
base::FilePath file = dir.path().Append(FILE_PATH_LITERAL("data.pak"));
base::FilePath file = dir.GetPath().Append(FILE_PATH_LITERAL("data.pak"));

std::string one("one");
std::string two("two");
Expand Down Expand Up @@ -196,7 +199,8 @@ TEST_P(DataPackTest, Write) {
TEST(DataPackTest, ModifiedWhileUsed) {
base::ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
base::FilePath data_path = dir.path().Append(FILE_PATH_LITERAL("sample.pak"));
base::FilePath data_path =
dir.GetPath().Append(FILE_PATH_LITERAL("sample.pak"));

// Dump contents into the pak file.
ASSERT_EQ(base::WriteFile(data_path, kSamplePakContents, kSamplePakSize),
Expand Down
2 changes: 1 addition & 1 deletion ui/base/resource/resource_bundle_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ class ResourceBundleImageTest : public ResourceBundleTest {
}

// Returns the path of temporary directory to write test data packs into.
const base::FilePath& dir_path() { return dir_.path(); }
const base::FilePath& dir_path() { return dir_.GetPath(); }

// Returns the number of DataPacks managed by |resource_bundle|.
size_t NumDataPacksInResourceBundle(ResourceBundle* resource_bundle) {
Expand Down
Loading

0 comments on commit a981982

Please sign in to comment.