• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
TEST(ContentUriUtilsTest,ContentUriMimeTest)14 TEST(ContentUriUtilsTest, ContentUriMimeTest) {
15   // Get the test image path.
16   FilePath data_dir;
17   ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &data_dir));
18   data_dir = data_dir.AppendASCII("file_util");
19   ASSERT_TRUE(PathExists(data_dir));
20   FilePath image_file = data_dir.Append(FILE_PATH_LITERAL("red.png"));
21 
22   // Insert the image into MediaStore. MediaStore will do some conversions, and
23   // return the content URI.
24   FilePath path = base::InsertImageIntoMediaStore(image_file);
25   EXPECT_TRUE(path.IsContentUri());
26   EXPECT_TRUE(PathExists(path));
27 
28   std::string mime = GetContentUriMimeType(path);
29   EXPECT_EQ(mime, std::string("image/png"));
30 
31   FilePath invalid_path("content://foo.bar");
32   mime = GetContentUriMimeType(invalid_path);
33   EXPECT_TRUE(mime.empty());
34 }
35 
36 }  // namespace android
37 }  // namespace base
38