OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_system_provider/mount_path_util.h" | 5 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 storage::ExternalMountPoints::GetSystemInstance(); | 49 storage::ExternalMountPoints::GetSystemInstance(); |
50 DCHECK(mount_points); | 50 DCHECK(mount_points); |
51 DCHECK(file_path.IsAbsolute()); | 51 DCHECK(file_path.IsAbsolute()); |
52 base::FilePath relative_path(file_path.value().substr(1)); | 52 base::FilePath relative_path(file_path.value().substr(1)); |
53 return mount_points->CreateCrackedFileSystemURL( | 53 return mount_points->CreateCrackedFileSystemURL( |
54 GURL(origin), | 54 GURL(origin), |
55 storage::kFileSystemTypeExternal, | 55 storage::kFileSystemTypeExternal, |
56 base::FilePath(mount_path.BaseName().Append(relative_path))); | 56 base::FilePath(mount_path.BaseName().Append(relative_path))); |
57 } | 57 } |
58 | 58 |
59 // Creates a Service instance. Used to be able to destroy the service in | |
60 // TearDown(). | |
61 KeyedService* CreateService(content::BrowserContext* context) { | |
62 return new Service(Profile::FromBrowserContext(context), | |
63 extensions::ExtensionRegistry::Get(context)); | |
64 } | |
65 | |
66 } // namespace | 59 } // namespace |
67 | 60 |
68 class FileSystemProviderMountPathUtilTest : public testing::Test { | 61 class FileSystemProviderMountPathUtilTest : public testing::Test { |
69 protected: | 62 protected: |
70 FileSystemProviderMountPathUtilTest() {} | 63 FileSystemProviderMountPathUtilTest() {} |
71 ~FileSystemProviderMountPathUtilTest() override {} | 64 ~FileSystemProviderMountPathUtilTest() override {} |
72 | 65 |
73 void SetUp() override { | 66 void SetUp() override { |
74 profile_manager_.reset( | 67 profile_manager_.reset( |
75 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 68 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
76 ASSERT_TRUE(profile_manager_->SetUp()); | 69 ASSERT_TRUE(profile_manager_->SetUp()); |
77 profile_ = profile_manager_->CreateTestingProfile("testing-profile"); | 70 profile_ = profile_manager_->CreateTestingProfile("testing-profile"); |
78 user_manager_ = new FakeChromeUserManager(); | 71 user_manager_ = new FakeChromeUserManager(); |
79 user_manager_enabler_.reset(new ScopedUserManagerEnabler(user_manager_)); | 72 user_manager_enabler_.reset(new ScopedUserManagerEnabler(user_manager_)); |
80 user_manager_->AddUser(profile_->GetProfileUserName()); | 73 user_manager_->AddUser(profile_->GetProfileUserName()); |
81 ServiceFactory::GetInstance()->SetTestingFactory(profile_, &CreateService); | |
82 file_system_provider_service_ = Service::Get(profile_); | 74 file_system_provider_service_ = Service::Get(profile_); |
83 file_system_provider_service_->SetFileSystemFactoryForTesting( | 75 file_system_provider_service_->SetFileSystemFactoryForTesting( |
84 base::Bind(&FakeProvidedFileSystem::Create)); | 76 base::Bind(&FakeProvidedFileSystem::Create)); |
85 } | 77 } |
86 | 78 |
87 void TearDown() override { | |
88 // Setting the testing factory to NULL will destroy the created service | |
89 // associated with the testing profile. | |
90 ServiceFactory::GetInstance()->SetTestingFactory(profile_, NULL); | |
91 } | |
92 | |
93 content::TestBrowserThreadBundle thread_bundle_; | 79 content::TestBrowserThreadBundle thread_bundle_; |
94 scoped_ptr<TestingProfileManager> profile_manager_; | 80 scoped_ptr<TestingProfileManager> profile_manager_; |
95 TestingProfile* profile_; // Owned by TestingProfileManager. | 81 TestingProfile* profile_; // Owned by TestingProfileManager. |
96 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; | 82 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; |
97 FakeChromeUserManager* user_manager_; | 83 FakeChromeUserManager* user_manager_; |
98 Service* file_system_provider_service_; // Owned by its factory. | 84 Service* file_system_provider_service_; // Owned by its factory. |
99 }; | 85 }; |
100 | 86 |
101 TEST_F(FileSystemProviderMountPathUtilTest, GetMountPath) { | 87 TEST_F(FileSystemProviderMountPathUtilTest, GetMountPath) { |
102 const base::FilePath result = | 88 const base::FilePath result = |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 const base::FilePath kFilePath = | 292 const base::FilePath kFilePath = |
307 base::FilePath(FILE_PATH_LITERAL("provided/hello/world")); | 293 base::FilePath(FILE_PATH_LITERAL("provided/hello/world")); |
308 LocalPathParser parser(profile_, kFilePath); | 294 LocalPathParser parser(profile_, kFilePath); |
309 EXPECT_FALSE(parser.Parse()); | 295 EXPECT_FALSE(parser.Parse()); |
310 } | 296 } |
311 } | 297 } |
312 | 298 |
313 } // namespace util | 299 } // namespace util |
314 } // namespace file_system_provider | 300 } // namespace file_system_provider |
315 } // namespace chromeos | 301 } // namespace chromeos |
OLD | NEW |