1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/android/content_uri_utils.h" 6 #include "base/files/file_util.h" 7 #include "base/path_service.h" 8 #include "base/test/test_file_util.h" 9 #include "testing/gtest/include/gtest/gtest.h" 10 11 namespace base { 12 namespace android { 13 14 // Disable on Android ASAN bot due to consistent failures: crbug.com/807080. 15 #if !defined(ADDRESS_SANITIZER) TEST(ContentUriUtilsTest,ContentUriMimeTest)16TEST(ContentUriUtilsTest, ContentUriMimeTest) { 17 // Get the test image path. 18 FilePath data_dir; 19 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &data_dir)); 20 data_dir = data_dir.AppendASCII("file_util"); 21 ASSERT_TRUE(PathExists(data_dir)); 22 FilePath image_file = data_dir.Append(FILE_PATH_LITERAL("red.png")); 23 24 // Insert the image into MediaStore. MediaStore will do some conversions, and 25 // return the content URI. 26 FilePath path = base::InsertImageIntoMediaStore(image_file); 27 EXPECT_TRUE(path.IsContentUri()); 28 EXPECT_TRUE(PathExists(path)); 29 30 std::string mime = GetContentUriMimeType(path); 31 EXPECT_EQ(mime, std::string("image/png")); 32 33 FilePath invalid_path("content://foo.bar"); 34 mime = GetContentUriMimeType(invalid_path); 35 EXPECT_TRUE(mime.empty()); 36 } 37 #endif 38 39 } // namespace android 40 } // namespace base 41