Move the rest of test_file_util to base namespace.
R=rvargas@chromium.org Review URL: https://codereview.chromium.org/444163003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288158 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@ -528,8 +528,8 @@ TEST_F(FileUtilTest, CreateTemporaryFileInDirLongPathTest) {
|
||||
// network file systems. E.g. AFS).
|
||||
FilePath access_test_dir = long_test_dir.Append(kTestSubDirName);
|
||||
ASSERT_TRUE(CreateDirectory(access_test_dir));
|
||||
file_util::PermissionRestorer long_test_dir_restorer(long_test_dir);
|
||||
ASSERT_TRUE(file_util::MakeFileUnreadable(long_test_dir));
|
||||
base::FilePermissionRestorer long_test_dir_restorer(long_test_dir);
|
||||
ASSERT_TRUE(base::MakeFileUnreadable(long_test_dir));
|
||||
|
||||
// Use the short form of the directory to create a temporary filename.
|
||||
ASSERT_TRUE(CreateTemporaryFileInDir(
|
||||
@ -2521,7 +2521,7 @@ TEST_F(FileUtilTest, ValidContentUriTest) {
|
||||
|
||||
// Insert the image into MediaStore. MediaStore will do some conversions, and
|
||||
// return the content URI.
|
||||
FilePath path = file_util::InsertImageIntoMediaStore(image_file);
|
||||
FilePath path = base::InsertImageIntoMediaStore(image_file);
|
||||
EXPECT_TRUE(path.IsContentUri());
|
||||
EXPECT_TRUE(PathExists(path));
|
||||
// The file size may not equal to the input image as MediaStore may convert
|
||||
|
@ -528,7 +528,7 @@ TEST_F(FilePathWatcherTest, RecursiveWatch) {
|
||||
ASSERT_TRUE(WaitForEvents());
|
||||
|
||||
// Modify "$dir/subdir/subdir_child_dir/child_dir_file1" attributes.
|
||||
ASSERT_TRUE(file_util::MakeFileUnreadable(child_dir_file1));
|
||||
ASSERT_TRUE(base::MakeFileUnreadable(child_dir_file1));
|
||||
ASSERT_TRUE(WaitForEvents());
|
||||
|
||||
// Delete "$dir/subdir/subdir_file1".
|
||||
@ -618,7 +618,7 @@ TEST_F(FilePathWatcherTest, FileAttributesChanged) {
|
||||
ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false));
|
||||
|
||||
// Now make sure we get notified if the file is modified.
|
||||
ASSERT_TRUE(file_util::MakeFileUnreadable(test_file()));
|
||||
ASSERT_TRUE(base::MakeFileUnreadable(test_file()));
|
||||
ASSERT_TRUE(WaitForEvents());
|
||||
DeleteDelegateOnFileThread(delegate.release());
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ int RunTestSuite(int argc, char** argv) {
|
||||
int main(int argc, char** argv) {
|
||||
#if defined(OS_ANDROID)
|
||||
JNIEnv* env = base::android::AttachCurrentThread();
|
||||
file_util::RegisterContentUriTestUtils(env);
|
||||
base::RegisterContentUriTestUtils(env);
|
||||
#else
|
||||
base::AtExitManager at_exit;
|
||||
#endif
|
||||
|
@ -47,15 +47,24 @@ bool VolumeSupportsADS(const FilePath& path);
|
||||
bool HasInternetZoneIdentifier(const FilePath& full_path);
|
||||
#endif // defined(OS_WIN)
|
||||
|
||||
} // namespace base
|
||||
|
||||
// TODO(brettw) move all of this to the base namespace.
|
||||
namespace file_util {
|
||||
|
||||
// For testing, make the file unreadable or unwritable.
|
||||
// In POSIX, this does not apply to the root user.
|
||||
bool MakeFileUnreadable(const base::FilePath& path) WARN_UNUSED_RESULT;
|
||||
bool MakeFileUnwritable(const base::FilePath& path) WARN_UNUSED_RESULT;
|
||||
bool MakeFileUnreadable(const FilePath& path) WARN_UNUSED_RESULT;
|
||||
bool MakeFileUnwritable(const FilePath& path) WARN_UNUSED_RESULT;
|
||||
|
||||
// Saves the current permissions for a path, and restores it on destruction.
|
||||
class FilePermissionRestorer {
|
||||
public:
|
||||
explicit FilePermissionRestorer(const FilePath& path);
|
||||
~FilePermissionRestorer();
|
||||
|
||||
private:
|
||||
const FilePath path_;
|
||||
void* info_; // The opaque stored permission information.
|
||||
size_t length_; // The length of the stored permission information.
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(FilePermissionRestorer);
|
||||
};
|
||||
|
||||
#if defined(OS_ANDROID)
|
||||
// Register the ContentUriTestUrils JNI bindings.
|
||||
@ -63,23 +72,9 @@ bool RegisterContentUriTestUtils(JNIEnv* env);
|
||||
|
||||
// Insert an image file into the MediaStore, and retrieve the content URI for
|
||||
// testing purpose.
|
||||
base::FilePath InsertImageIntoMediaStore(const base::FilePath& path);
|
||||
FilePath InsertImageIntoMediaStore(const FilePath& path);
|
||||
#endif // defined(OS_ANDROID)
|
||||
|
||||
// Saves the current permissions for a path, and restores it on destruction.
|
||||
class PermissionRestorer {
|
||||
public:
|
||||
explicit PermissionRestorer(const base::FilePath& path);
|
||||
~PermissionRestorer();
|
||||
|
||||
private:
|
||||
const base::FilePath path_;
|
||||
void* info_; // The opaque stored permission information.
|
||||
size_t length_; // The length of the stored permission information.
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(PermissionRestorer);
|
||||
};
|
||||
|
||||
} // namespace file_util
|
||||
} // namespace base
|
||||
|
||||
#endif // BASE_TEST_TEST_FILE_UTIL_H_
|
||||
|
@ -9,13 +9,13 @@
|
||||
#include "base/files/file_path.h"
|
||||
#include "jni/ContentUriTestUtils_jni.h"
|
||||
|
||||
namespace file_util {
|
||||
namespace base {
|
||||
|
||||
bool RegisterContentUriTestUtils(JNIEnv* env) {
|
||||
return RegisterNativesImpl(env);
|
||||
}
|
||||
|
||||
base::FilePath InsertImageIntoMediaStore(const base::FilePath& path) {
|
||||
FilePath InsertImageIntoMediaStore(const FilePath& path) {
|
||||
JNIEnv* env = base::android::AttachCurrentThread();
|
||||
ScopedJavaLocalRef<jstring> j_path =
|
||||
base::android::ConvertUTF8ToJavaString(env, path.value());
|
||||
@ -23,7 +23,7 @@ base::FilePath InsertImageIntoMediaStore(const base::FilePath& path) {
|
||||
Java_ContentUriTestUtils_insertImageIntoMediaStore(
|
||||
env, base::android::GetApplicationContext(), j_path.obj());
|
||||
std::string uri = base::android::ConvertJavaStringToUTF8(j_uri);
|
||||
return base::FilePath(uri);
|
||||
return FilePath(uri);
|
||||
}
|
||||
|
||||
} // namespace file_util
|
||||
} // namespace base
|
||||
|
@ -85,32 +85,24 @@ bool EvictFileFromSystemCache(const FilePath& file) {
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace base
|
||||
|
||||
namespace file_util {
|
||||
|
||||
using base::DenyFilePermission;
|
||||
using base::GetPermissionInfo;
|
||||
using base::RestorePermissionInfo;
|
||||
|
||||
bool MakeFileUnreadable(const base::FilePath& path) {
|
||||
bool MakeFileUnreadable(const FilePath& path) {
|
||||
return DenyFilePermission(path, S_IRUSR | S_IRGRP | S_IROTH);
|
||||
}
|
||||
|
||||
bool MakeFileUnwritable(const base::FilePath& path) {
|
||||
bool MakeFileUnwritable(const FilePath& path) {
|
||||
return DenyFilePermission(path, S_IWUSR | S_IWGRP | S_IWOTH);
|
||||
}
|
||||
|
||||
PermissionRestorer::PermissionRestorer(const base::FilePath& path)
|
||||
FilePermissionRestorer::FilePermissionRestorer(const FilePath& path)
|
||||
: path_(path), info_(NULL), length_(0) {
|
||||
info_ = GetPermissionInfo(path_, &length_);
|
||||
DCHECK(info_ != NULL);
|
||||
DCHECK_NE(0u, length_);
|
||||
}
|
||||
|
||||
PermissionRestorer::~PermissionRestorer() {
|
||||
FilePermissionRestorer::~FilePermissionRestorer() {
|
||||
if (!RestorePermissionInfo(path_, info_, length_))
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
} // namespace file_util
|
||||
} // namespace base
|
||||
|
@ -259,32 +259,24 @@ bool HasInternetZoneIdentifier(const FilePath& full_path) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
|
||||
namespace file_util {
|
||||
|
||||
using base::DenyFilePermission;
|
||||
using base::GetPermissionInfo;
|
||||
using base::RestorePermissionInfo;
|
||||
|
||||
bool MakeFileUnreadable(const base::FilePath& path) {
|
||||
bool MakeFileUnreadable(const FilePath& path) {
|
||||
return DenyFilePermission(path, GENERIC_READ);
|
||||
}
|
||||
|
||||
bool MakeFileUnwritable(const base::FilePath& path) {
|
||||
bool MakeFileUnwritable(const FilePath& path) {
|
||||
return DenyFilePermission(path, GENERIC_WRITE);
|
||||
}
|
||||
|
||||
PermissionRestorer::PermissionRestorer(const base::FilePath& path)
|
||||
FilePermissionRestorer::FilePermissionRestorer(const FilePath& path)
|
||||
: path_(path), info_(NULL), length_(0) {
|
||||
info_ = GetPermissionInfo(path_, &length_);
|
||||
DCHECK(info_ != NULL);
|
||||
DCHECK_NE(0u, length_);
|
||||
}
|
||||
|
||||
PermissionRestorer::~PermissionRestorer() {
|
||||
FilePermissionRestorer::~FilePermissionRestorer() {
|
||||
if (!RestorePermissionInfo(path_, info_, length_))
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
} // namespace file_util
|
||||
} // namespace base
|
||||
|
@ -1041,8 +1041,8 @@ class DownloadTest : public InProcessBrowserTest {
|
||||
base::FilePath destination_folder = GetDownloadDirectory(browser());
|
||||
DVLOG(1) << " " << __FUNCTION__ << "()"
|
||||
<< " folder = '" << destination_folder.value() << "'";
|
||||
file_util::PermissionRestorer permission_restorer(destination_folder);
|
||||
EXPECT_TRUE(file_util::MakeFileUnwritable(destination_folder));
|
||||
base::FilePermissionRestorer permission_restorer(destination_folder);
|
||||
EXPECT_TRUE(base::MakeFileUnwritable(destination_folder));
|
||||
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
DownloadFilesCheckErrorsLoopBody(download_info[i], i);
|
||||
|
@ -446,9 +446,9 @@ TEST_F(DownloadPathReservationTrackerTest, UnwriteableDirectory) {
|
||||
ASSERT_FALSE(IsPathInUse(path));
|
||||
|
||||
{
|
||||
// Scope for PermissionRestorer
|
||||
file_util::PermissionRestorer restorer(dir);
|
||||
EXPECT_TRUE(file_util::MakeFileUnwritable(dir));
|
||||
// Scope for FilePermissionRestorer
|
||||
base::FilePermissionRestorer restorer(dir);
|
||||
EXPECT_TRUE(base::MakeFileUnwritable(dir));
|
||||
base::FilePath reserved_path;
|
||||
bool verified = true;
|
||||
DownloadPathReservationTracker::FilenameConflictAction conflict_action =
|
||||
|
@ -467,8 +467,8 @@ TEST_F(BaseFileTest, RenameWithError) {
|
||||
EXPECT_FALSE(base::PathExists(new_path));
|
||||
|
||||
{
|
||||
file_util::PermissionRestorer restore_permissions_for(test_dir);
|
||||
ASSERT_TRUE(file_util::MakeFileUnwritable(test_dir));
|
||||
base::FilePermissionRestorer restore_permissions_for(test_dir);
|
||||
ASSERT_TRUE(base::MakeFileUnwritable(test_dir));
|
||||
EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED,
|
||||
base_file_->Rename(new_path));
|
||||
}
|
||||
@ -558,10 +558,10 @@ TEST_F(BaseFileTest, ReadonlyBaseFile) {
|
||||
base::FilePath readonly_file_name = CreateTestFile();
|
||||
|
||||
// Restore permissions to the file when we are done with this test.
|
||||
file_util::PermissionRestorer restore_permissions(readonly_file_name);
|
||||
base::FilePermissionRestorer restore_permissions(readonly_file_name);
|
||||
|
||||
// Make it read-only.
|
||||
EXPECT_TRUE(file_util::MakeFileUnwritable(readonly_file_name));
|
||||
EXPECT_TRUE(base::MakeFileUnwritable(readonly_file_name));
|
||||
|
||||
// Try to overwrite it.
|
||||
base_file_.reset(new BaseFile(readonly_file_name,
|
||||
|
@ -470,8 +470,8 @@ TEST_F(DownloadFileTest, RenameError) {
|
||||
|
||||
// Make the directory unwritable and try to rename within it.
|
||||
{
|
||||
file_util::PermissionRestorer restorer(tempdir);
|
||||
ASSERT_TRUE(file_util::MakeFileUnwritable(tempdir));
|
||||
base::FilePermissionRestorer restorer(tempdir);
|
||||
ASSERT_TRUE(base::MakeFileUnwritable(tempdir));
|
||||
|
||||
// Expect nulling out of further processing.
|
||||
EXPECT_CALL(*input_stream_, RegisterCallback(IsNullCallback()));
|
||||
|
@ -32,7 +32,7 @@ int main(int argc, char** argv) {
|
||||
mojo::embedder::Init();
|
||||
#if defined(OS_ANDROID)
|
||||
JNIEnv* env = base::android::AttachCurrentThread();
|
||||
file_util::RegisterContentUriTestUtils(env);
|
||||
base::RegisterContentUriTestUtils(env);
|
||||
#else
|
||||
base::AtExitManager at_exit;
|
||||
#endif
|
||||
|
@ -30,7 +30,7 @@ int RunTestSuite(int argc, char** argv) {
|
||||
int main(int argc, char** argv) {
|
||||
#if defined(OS_ANDROID)
|
||||
JNIEnv* env = base::android::AttachCurrentThread();
|
||||
file_util::RegisterContentUriTestUtils(env);
|
||||
base::RegisterContentUriTestUtils(env);
|
||||
#else
|
||||
base::AtExitManager at_exit;
|
||||
#endif
|
||||
|
@ -845,7 +845,7 @@ TEST_F(FileStreamTest, ContentUriRead) {
|
||||
|
||||
// Insert the image into MediaStore. MediaStore will do some conversions, and
|
||||
// return the content URI.
|
||||
base::FilePath path = file_util::InsertImageIntoMediaStore(image_file);
|
||||
base::FilePath path = base::InsertImageIntoMediaStore(image_file);
|
||||
EXPECT_TRUE(path.IsContentUri());
|
||||
EXPECT_TRUE(base::PathExists(path));
|
||||
int64 file_size;
|
||||
|
@ -8150,7 +8150,7 @@ TEST_P(HttpNetworkTransactionTest, UploadUnreadableFile) {
|
||||
std::string temp_file_content("Unreadable file.");
|
||||
ASSERT_TRUE(base::WriteFile(temp_file, temp_file_content.c_str(),
|
||||
temp_file_content.length()));
|
||||
ASSERT_TRUE(file_util::MakeFileUnreadable(temp_file));
|
||||
ASSERT_TRUE(base::MakeFileUnreadable(temp_file));
|
||||
|
||||
ScopedVector<UploadElementReader> element_readers;
|
||||
element_readers.push_back(
|
||||
|
@ -499,7 +499,7 @@ class SpdyNetworkTransactionTest
|
||||
CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path));
|
||||
CHECK_EQ(static_cast<int>(kUploadDataSize),
|
||||
base::WriteFile(file_path, kUploadData, kUploadDataSize));
|
||||
CHECK(file_util::MakeFileUnreadable(file_path));
|
||||
CHECK(base::MakeFileUnreadable(file_path));
|
||||
|
||||
ScopedVector<UploadElementReader> element_readers;
|
||||
element_readers.push_back(
|
||||
|
@ -33,7 +33,7 @@ int main(int argc, char** argv) {
|
||||
#if defined(OS_ANDROID)
|
||||
const base::android::RegistrationMethod kNetTestRegisteredMethods[] = {
|
||||
{"NetAndroid", net::android::RegisterJni},
|
||||
{"TestFileUtil", file_util::RegisterContentUriTestUtils},
|
||||
{"TestFileUtil", base::RegisterContentUriTestUtils},
|
||||
{"UrlAndroid", url::android::RegisterJni},
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user