diff options
-rw-r--r-- | base/file_util_unittest.cc | 6 | ||||
-rw-r--r-- | base/files/file_path_watcher_browsertest.cc | 4 | ||||
-rw-r--r-- | base/test/run_all_unittests.cc | 2 | ||||
-rw-r--r-- | base/test/test_file_util.h | 39 | ||||
-rw-r--r-- | base/test/test_file_util_android.cc | 8 | ||||
-rw-r--r-- | base/test/test_file_util_posix.cc | 18 | ||||
-rw-r--r-- | base/test/test_file_util_win.cc | 18 | ||||
-rw-r--r-- | chrome/browser/download/download_browsertest.cc | 4 | ||||
-rw-r--r-- | chrome/browser/download/download_path_reservation_tracker_unittest.cc | 6 | ||||
-rw-r--r-- | content/browser/download/base_file_unittest.cc | 8 | ||||
-rw-r--r-- | content/browser/download/download_file_unittest.cc | 4 | ||||
-rw-r--r-- | ipc/mojo/run_all_unittests.cc | 2 | ||||
-rw-r--r-- | ipc/run_all_unittests.cc | 2 | ||||
-rw-r--r-- | net/base/file_stream_unittest.cc | 2 | ||||
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 2 | ||||
-rw-r--r-- | net/spdy/spdy_network_transaction_unittest.cc | 2 | ||||
-rw-r--r-- | net/test/run_all_unittests.cc | 2 |
17 files changed, 54 insertions, 75 deletions
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc index 239563d..eb88ba8 100644 --- a/base/file_util_unittest.cc +++ b/base/file_util_unittest.cc @@ -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 diff --git a/base/files/file_path_watcher_browsertest.cc b/base/files/file_path_watcher_browsertest.cc index 8f57cad..ff6d9d5 100644 --- a/base/files/file_path_watcher_browsertest.cc +++ b/base/files/file_path_watcher_browsertest.cc @@ -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()); } diff --git a/base/test/run_all_unittests.cc b/base/test/run_all_unittests.cc index 3b5ebfe..93cb8cb 100644 --- a/base/test/run_all_unittests.cc +++ b/base/test/run_all_unittests.cc @@ -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 diff --git a/base/test/test_file_util.h b/base/test/test_file_util.h index 295fb85..27197f2 100644 --- a/base/test/test_file_util.h +++ b/base/test/test_file_util.h @@ -47,39 +47,34 @@ 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; - -#if defined(OS_ANDROID) -// Register the ContentUriTestUrils JNI bindings. -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); -#endif // defined(OS_ANDROID) +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 PermissionRestorer { +class FilePermissionRestorer { public: - explicit PermissionRestorer(const base::FilePath& path); - ~PermissionRestorer(); + explicit FilePermissionRestorer(const FilePath& path); + ~FilePermissionRestorer(); private: - const base::FilePath path_; + const FilePath path_; void* info_; // The opaque stored permission information. size_t length_; // The length of the stored permission information. - DISALLOW_COPY_AND_ASSIGN(PermissionRestorer); + DISALLOW_COPY_AND_ASSIGN(FilePermissionRestorer); }; -} // namespace file_util +#if defined(OS_ANDROID) +// Register the ContentUriTestUrils JNI bindings. +bool RegisterContentUriTestUtils(JNIEnv* env); + +// Insert an image file into the MediaStore, and retrieve the content URI for +// testing purpose. +FilePath InsertImageIntoMediaStore(const FilePath& path); +#endif // defined(OS_ANDROID) + +} // namespace base #endif // BASE_TEST_TEST_FILE_UTIL_H_ diff --git a/base/test/test_file_util_android.cc b/base/test/test_file_util_android.cc index c17f669..b8fd50c 100644 --- a/base/test/test_file_util_android.cc +++ b/base/test/test_file_util_android.cc @@ -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 diff --git a/base/test/test_file_util_posix.cc b/base/test/test_file_util_posix.cc index 0350ccc..cbcabd6 100644 --- a/base/test/test_file_util_posix.cc +++ b/base/test/test_file_util_posix.cc @@ -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 diff --git a/base/test/test_file_util_win.cc b/base/test/test_file_util_win.cc index 0b7a0c6..2656e31 100644 --- a/base/test/test_file_util_win.cc +++ b/base/test/test_file_util_win.cc @@ -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 diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc index 91525d2..1e19c1a 100644 --- a/chrome/browser/download/download_browsertest.cc +++ b/chrome/browser/download/download_browsertest.cc @@ -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); diff --git a/chrome/browser/download/download_path_reservation_tracker_unittest.cc b/chrome/browser/download/download_path_reservation_tracker_unittest.cc index 8bb301d..45db85a 100644 --- a/chrome/browser/download/download_path_reservation_tracker_unittest.cc +++ b/chrome/browser/download/download_path_reservation_tracker_unittest.cc @@ -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 = diff --git a/content/browser/download/base_file_unittest.cc b/content/browser/download/base_file_unittest.cc index 8b45ce9..b3f2e6c 100644 --- a/content/browser/download/base_file_unittest.cc +++ b/content/browser/download/base_file_unittest.cc @@ -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, diff --git a/content/browser/download/download_file_unittest.cc b/content/browser/download/download_file_unittest.cc index 1127908..e283fa4 100644 --- a/content/browser/download/download_file_unittest.cc +++ b/content/browser/download/download_file_unittest.cc @@ -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())); diff --git a/ipc/mojo/run_all_unittests.cc b/ipc/mojo/run_all_unittests.cc index 1734e5e..3270e23 100644 --- a/ipc/mojo/run_all_unittests.cc +++ b/ipc/mojo/run_all_unittests.cc @@ -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 diff --git a/ipc/run_all_unittests.cc b/ipc/run_all_unittests.cc index d36f871..a488802 100644 --- a/ipc/run_all_unittests.cc +++ b/ipc/run_all_unittests.cc @@ -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 diff --git a/net/base/file_stream_unittest.cc b/net/base/file_stream_unittest.cc index 78ed2d5..2e308b3 100644 --- a/net/base/file_stream_unittest.cc +++ b/net/base/file_stream_unittest.cc @@ -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; diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 9c4568a..f56b6e2 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -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( diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index 0e9e64c..7d301d1 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -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( diff --git a/net/test/run_all_unittests.cc b/net/test/run_all_unittests.cc index 96e8a3c..a035057 100644 --- a/net/test/run_all_unittests.cc +++ b/net/test/run_all_unittests.cc @@ -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}, }; |