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

Unified Diff: base/file_util_unittest.cc

Issue 46303005: Fix chrome upload with content uri (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 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
« no previous file with comments | « base/file_util_posix.cc ('k') | base/files/file_path.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_unittest.cc
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index 1ca70b4f899d45e4b9db03d64bbafc6f0cc408e1..3594749b4b1fe7c8ff6f73c4d79c9fba641d028d 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -33,6 +33,10 @@
#include "base/win/windows_version.h"
#endif
+#if defined(OS_ANDROID)
+#include "base/android/content_uri_utils.h"
+#endif
+
// This macro helps avoid wrapped lines in the test structs.
#define FPL(x) FILE_PATH_LITERAL(x)
@@ -2319,6 +2323,52 @@ TEST_F(VerifyPathControlledByUserTest, WriteBitChecks) {
sub_dir_, text_file_, uid_, ok_gids_));
}
+#if defined(OS_ANDROID)
+TEST_F(FileUtilTest, ValidContentUriTest) {
+ // Get the test image path.
+ FilePath data_dir;
+ ASSERT_TRUE(PathService::Get(base::DIR_TEST_DATA, &data_dir));
+ data_dir = data_dir.AppendASCII("file_util");
+ ASSERT_TRUE(base::PathExists(data_dir));
+ FilePath image_file = data_dir.Append(FILE_PATH_LITERAL("red.png"));
+ int64 image_size;
+ file_util::GetFileSize(image_file, &image_size);
+ EXPECT_LT(0, image_size);
+
+ // Insert the image into MediaStore. MediaStore will do some conversions, and
+ // return the content URI.
+ base::FilePath path = file_util::InsertImageIntoMediaStore(image_file);
+ EXPECT_TRUE(path.IsContentUri());
+ EXPECT_TRUE(base::PathExists(path));
+ // The file size may not equal to the input image as MediaStore may convert
+ // the image.
+ int64 content_uri_size;
+ file_util::GetFileSize(path, &content_uri_size);
+ EXPECT_EQ(image_size, content_uri_size);
+
+ // We should be able to read the file.
+ char* buffer = new char[image_size];
+ int fd = base::OpenContentUriForRead(path);
+ EXPECT_LT(0, fd);
+ EXPECT_TRUE(file_util::ReadFromFD(fd, buffer, image_size));
+ delete[] buffer;
+}
+
+TEST_F(FileUtilTest, NonExistentContentUriTest) {
+ base::FilePath path("content://foo.bar");
+ EXPECT_TRUE(path.IsContentUri());
+ EXPECT_FALSE(base::PathExists(path));
+ // Size should be smaller than 0.
+ int64 size;
+ file_util::GetFileSize(path, &size);
+ EXPECT_GT(0, size);
+
+ // We should not be able to read the file.
+ int fd = base::OpenContentUriForRead(path);
+ EXPECT_EQ(-1, fd);
+}
+#endif
+
#endif // defined(OS_POSIX)
} // namespace
« no previous file with comments | « base/file_util_posix.cc ('k') | base/files/file_path.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698