| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/file_manager/path_util.h" | 5 #include "chrome/browser/chromeos/file_manager/path_util.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" |
| 9 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 10 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 8 #include "chrome/browser/download/download_prefs.h" | 11 #include "chrome/browser/download/download_prefs.h" |
| 12 #include "chrome/test/base/testing_browser_process.h" |
| 9 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 14 #include "chrome/test/base/testing_profile_manager.h" |
| 15 #include "components/signin/core/account_id/account_id.h" |
| 10 #include "content/public/test/test_browser_thread_bundle.h" | 16 #include "content/public/test/test_browser_thread_bundle.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 18 |
| 13 namespace file_manager { | 19 namespace file_manager { |
| 14 namespace util { | 20 namespace util { |
| 15 namespace { | 21 namespace { |
| 16 | 22 |
| 17 TEST(FileManagerPathUtilTest, MultiProfileDownloadsFolderMigration) { | 23 TEST(FileManagerPathUtilTest, MultiProfileDownloadsFolderMigration) { |
| 18 content::TestBrowserThreadBundle thread_bundle; | 24 content::TestBrowserThreadBundle thread_bundle; |
| 19 TestingProfile profile; | 25 TestingProfile profile; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 41 kDownloads.AppendASCII("a/b"), | 47 kDownloads.AppendASCII("a/b"), |
| 42 &path)); | 48 &path)); |
| 43 | 49 |
| 44 // Only the "Downloads" path is converted. | 50 // Only the "Downloads" path is converted. |
| 45 EXPECT_FALSE(MigratePathFromOldFormat( | 51 EXPECT_FALSE(MigratePathFromOldFormat( |
| 46 &profile, | 52 &profile, |
| 47 base::FilePath::FromUTF8Unsafe("/home/chronos/user/dl"), | 53 base::FilePath::FromUTF8Unsafe("/home/chronos/user/dl"), |
| 48 &path)); | 54 &path)); |
| 49 } | 55 } |
| 50 | 56 |
| 57 TEST(FileManagerPathUtilTest, ConvertPathToArcUrl) { |
| 58 content::TestBrowserThreadBundle thread_bundle; |
| 59 |
| 60 // Test SetUp -- add two user-profile pairs and their fake managers. |
| 61 TestingProfileManager testing_profile_manager( |
| 62 TestingBrowserProcess::GetGlobal()); |
| 63 ASSERT_TRUE(testing_profile_manager.SetUp()); |
| 64 |
| 65 chromeos::FakeChromeUserManager* const fake_user_manager = |
| 66 new chromeos::FakeChromeUserManager; |
| 67 chromeos::ScopedUserManagerEnabler user_manager_enabler(fake_user_manager); |
| 68 |
| 69 const AccountId account_id( |
| 70 AccountId::FromUserEmailGaiaId("user@gmail.com", "1111111111")); |
| 71 const AccountId account_id_2( |
| 72 AccountId::FromUserEmailGaiaId("user2@gmail.com", "2222222222")); |
| 73 fake_user_manager->AddUser(account_id); |
| 74 fake_user_manager->LoginUser(account_id); |
| 75 fake_user_manager->AddUser(account_id_2); |
| 76 fake_user_manager->LoginUser(account_id_2); |
| 77 ASSERT_TRUE(testing_profile_manager.CreateTestingProfile("user@gmail.com")); |
| 78 ASSERT_TRUE(testing_profile_manager.CreateTestingProfile("user2@gmail.com")); |
| 79 |
| 80 GURL url; |
| 81 |
| 82 // Conversion of paths for removable storages. |
| 83 EXPECT_TRUE(ConvertPathToArcUrl( |
| 84 base::FilePath::FromUTF8Unsafe("/media/removable/a/b/c"), &url)); |
| 85 EXPECT_EQ(GURL("content://org.chromium.arc.removablemediaprovider/a/b/c"), |
| 86 url); |
| 87 |
| 88 EXPECT_FALSE(ConvertPathToArcUrl( |
| 89 base::FilePath::FromUTF8Unsafe("/media/removable_foobar"), &url)); |
| 90 |
| 91 // Conversion of paths under the primary profile's downloads folder. |
| 92 const base::FilePath downloads = GetDownloadsFolderForProfile( |
| 93 chromeos::ProfileHelper::Get()->GetProfileByUserIdHash( |
| 94 "user@gmail.com-hash")); |
| 95 EXPECT_TRUE(ConvertPathToArcUrl(downloads.AppendASCII("a/b/c"), &url)); |
| 96 EXPECT_EQ(GURL("file:///sdcard/Download/a/b/c"), url); |
| 97 |
| 98 // Non-primary profile's downloads folder is not supported for ARC yet. |
| 99 const base::FilePath downloads2 = GetDownloadsFolderForProfile( |
| 100 chromeos::ProfileHelper::Get()->GetProfileByUserIdHash( |
| 101 "user2@gmail.com-hash")); |
| 102 EXPECT_FALSE(ConvertPathToArcUrl(downloads2.AppendASCII("a/b/c"), &url)); |
| 103 } |
| 104 |
| 51 } // namespace | 105 } // namespace |
| 52 } // namespace util | 106 } // namespace util |
| 53 } // namespace file_manager | 107 } // namespace file_manager |
| OLD | NEW |