| 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/fileapi/file_stream_write
r.h" | 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/file_stream_write
r.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 const base::FilePath& file_path) { | 47 const base::FilePath& file_path) { |
| 48 const std::string origin = std::string("chrome-extension://") + kExtensionId; | 48 const std::string origin = std::string("chrome-extension://") + kExtensionId; |
| 49 const storage::ExternalMountPoints* const mount_points = | 49 const storage::ExternalMountPoints* const mount_points = |
| 50 storage::ExternalMountPoints::GetSystemInstance(); | 50 storage::ExternalMountPoints::GetSystemInstance(); |
| 51 return mount_points->CreateCrackedFileSystemURL( | 51 return mount_points->CreateCrackedFileSystemURL( |
| 52 GURL(origin), | 52 GURL(origin), |
| 53 storage::kFileSystemTypeExternal, | 53 storage::kFileSystemTypeExternal, |
| 54 base::FilePath::FromUTF8Unsafe(mount_point_name).Append(file_path)); | 54 base::FilePath::FromUTF8Unsafe(mount_point_name).Append(file_path)); |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Creates a Service instance. Used to be able to destroy the service in | |
| 58 // TearDown(). | |
| 59 KeyedService* CreateService(content::BrowserContext* context) { | |
| 60 return new Service(Profile::FromBrowserContext(context), | |
| 61 extensions::ExtensionRegistry::Get(context)); | |
| 62 } | |
| 63 | |
| 64 } // namespace | 57 } // namespace |
| 65 | 58 |
| 66 class FileSystemProviderFileStreamWriter : public testing::Test { | 59 class FileSystemProviderFileStreamWriter : public testing::Test { |
| 67 protected: | 60 protected: |
| 68 FileSystemProviderFileStreamWriter() {} | 61 FileSystemProviderFileStreamWriter() {} |
| 69 ~FileSystemProviderFileStreamWriter() override {} | 62 ~FileSystemProviderFileStreamWriter() override {} |
| 70 | 63 |
| 71 void SetUp() override { | 64 void SetUp() override { |
| 72 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 65 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
| 73 profile_manager_.reset( | 66 profile_manager_.reset( |
| 74 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 67 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 75 ASSERT_TRUE(profile_manager_->SetUp()); | 68 ASSERT_TRUE(profile_manager_->SetUp()); |
| 76 profile_ = profile_manager_->CreateTestingProfile("testing-profile"); | 69 profile_ = profile_manager_->CreateTestingProfile("testing-profile"); |
| 77 | 70 |
| 78 ServiceFactory::GetInstance()->SetTestingFactory(profile_, &CreateService); | |
| 79 Service* service = Service::Get(profile_); // Owned by its factory. | 71 Service* service = Service::Get(profile_); // Owned by its factory. |
| 80 service->SetFileSystemFactoryForTesting( | 72 service->SetFileSystemFactoryForTesting( |
| 81 base::Bind(&FakeProvidedFileSystem::Create)); | 73 base::Bind(&FakeProvidedFileSystem::Create)); |
| 82 | 74 |
| 83 const base::File::Error result = service->MountFileSystem( | 75 const base::File::Error result = service->MountFileSystem( |
| 84 kExtensionId, MountOptions(kFileSystemId, "Testing File System")); | 76 kExtensionId, MountOptions(kFileSystemId, "Testing File System")); |
| 85 ASSERT_EQ(base::File::FILE_OK, result); | 77 ASSERT_EQ(base::File::FILE_OK, result); |
| 86 provided_file_system_ = static_cast<FakeProvidedFileSystem*>( | 78 provided_file_system_ = static_cast<FakeProvidedFileSystem*>( |
| 87 service->GetProvidedFileSystem(kExtensionId, kFileSystemId)); | 79 service->GetProvidedFileSystem(kExtensionId, kFileSystemId)); |
| 88 ASSERT_TRUE(provided_file_system_); | 80 ASSERT_TRUE(provided_file_system_); |
| 89 const ProvidedFileSystemInfo& file_system_info = | 81 const ProvidedFileSystemInfo& file_system_info = |
| 90 provided_file_system_->GetFileSystemInfo(); | 82 provided_file_system_->GetFileSystemInfo(); |
| 91 const std::string mount_point_name = | 83 const std::string mount_point_name = |
| 92 file_system_info.mount_path().BaseName().AsUTF8Unsafe(); | 84 file_system_info.mount_path().BaseName().AsUTF8Unsafe(); |
| 93 | 85 |
| 94 file_url_ = CreateFileSystemURL(mount_point_name, | 86 file_url_ = CreateFileSystemURL(mount_point_name, |
| 95 base::FilePath(kFakeFilePath + 1)); | 87 base::FilePath(kFakeFilePath + 1)); |
| 96 ASSERT_TRUE(file_url_.is_valid()); | 88 ASSERT_TRUE(file_url_.is_valid()); |
| 97 wrong_file_url_ = CreateFileSystemURL( | 89 wrong_file_url_ = CreateFileSystemURL( |
| 98 mount_point_name, base::FilePath(FILE_PATH_LITERAL("im-not-here.txt"))); | 90 mount_point_name, base::FilePath(FILE_PATH_LITERAL("im-not-here.txt"))); |
| 99 ASSERT_TRUE(wrong_file_url_.is_valid()); | 91 ASSERT_TRUE(wrong_file_url_.is_valid()); |
| 100 } | 92 } |
| 101 | 93 |
| 102 void TearDown() override { | |
| 103 // Setting the testing factory to NULL will destroy the created service | |
| 104 // associated with the testing profile. | |
| 105 ServiceFactory::GetInstance()->SetTestingFactory(profile_, NULL); | |
| 106 } | |
| 107 | |
| 108 content::TestBrowserThreadBundle thread_bundle_; | 94 content::TestBrowserThreadBundle thread_bundle_; |
| 109 base::ScopedTempDir data_dir_; | 95 base::ScopedTempDir data_dir_; |
| 110 scoped_ptr<TestingProfileManager> profile_manager_; | 96 scoped_ptr<TestingProfileManager> profile_manager_; |
| 111 TestingProfile* profile_; // Owned by TestingProfileManager. | 97 TestingProfile* profile_; // Owned by TestingProfileManager. |
| 112 FakeProvidedFileSystem* provided_file_system_; // Owned by Service. | 98 FakeProvidedFileSystem* provided_file_system_; // Owned by Service. |
| 113 storage::FileSystemURL file_url_; | 99 storage::FileSystemURL file_url_; |
| 114 storage::FileSystemURL wrong_file_url_; | 100 storage::FileSystemURL wrong_file_url_; |
| 115 }; | 101 }; |
| 116 | 102 |
| 117 TEST_F(FileSystemProviderFileStreamWriter, Write) { | 103 TEST_F(FileSystemProviderFileStreamWriter, Write) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 | 228 |
| 243 ASSERT_EQ(1u, write_log.size()); | 229 ASSERT_EQ(1u, write_log.size()); |
| 244 EXPECT_EQ(sizeof(kTextToWrite) - 1, static_cast<size_t>(write_log[0])); | 230 EXPECT_EQ(sizeof(kTextToWrite) - 1, static_cast<size_t>(write_log[0])); |
| 245 | 231 |
| 246 const std::string expected_contents = original_contents + kTextToWrite; | 232 const std::string expected_contents = original_contents + kTextToWrite; |
| 247 EXPECT_EQ(expected_contents, entry->contents); | 233 EXPECT_EQ(expected_contents, entry->contents); |
| 248 } | 234 } |
| 249 | 235 |
| 250 } // namespace file_system_provider | 236 } // namespace file_system_provider |
| 251 } // namespace chromeos | 237 } // namespace chromeos |
| OLD | NEW |