| 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 25 matching lines...) Expand all Loading... |
| 36 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; | 36 const char kExtensionId[] = "mbflcebpggnecokmikipoihdbecnjfoj"; |
| 37 const char kFileSystemId[] = "testing-file-system"; | 37 const char kFileSystemId[] = "testing-file-system"; |
| 38 const char kTextToWrite[] = "This is a test of FileStreamWriter."; | 38 const char kTextToWrite[] = "This is a test of FileStreamWriter."; |
| 39 | 39 |
| 40 // Pushes a value to the passed log vector. | 40 // Pushes a value to the passed log vector. |
| 41 void LogValue(std::vector<int>* log, int value) { | 41 void LogValue(std::vector<int>* log, int value) { |
| 42 log->push_back(value); | 42 log->push_back(value); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Creates a cracked FileSystemURL for tests. | 45 // Creates a cracked FileSystemURL for tests. |
| 46 fileapi::FileSystemURL CreateFileSystemURL(const std::string& mount_point_name, | 46 storage::FileSystemURL CreateFileSystemURL(const std::string& mount_point_name, |
| 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 fileapi::ExternalMountPoints* const mount_points = | 49 const storage::ExternalMountPoints* const mount_points = |
| 50 fileapi::ExternalMountPoints::GetSystemInstance(); | 50 storage::ExternalMountPoints::GetSystemInstance(); |
| 51 return mount_points->CreateCrackedFileSystemURL( | 51 return mount_points->CreateCrackedFileSystemURL( |
| 52 GURL(origin), | 52 GURL(origin), |
| 53 fileapi::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 | 57 // Creates a Service instance. Used to be able to destroy the service in |
| 58 // TearDown(). | 58 // TearDown(). |
| 59 KeyedService* CreateService(content::BrowserContext* context) { | 59 KeyedService* CreateService(content::BrowserContext* context) { |
| 60 return new Service(Profile::FromBrowserContext(context), | 60 return new Service(Profile::FromBrowserContext(context), |
| 61 extensions::ExtensionRegistry::Get(context)); | 61 extensions::ExtensionRegistry::Get(context)); |
| 62 } | 62 } |
| 63 | 63 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 // Setting the testing factory to NULL will destroy the created service | 105 // Setting the testing factory to NULL will destroy the created service |
| 106 // associated with the testing profile. | 106 // associated with the testing profile. |
| 107 ServiceFactory::GetInstance()->SetTestingFactory(profile_, NULL); | 107 ServiceFactory::GetInstance()->SetTestingFactory(profile_, NULL); |
| 108 } | 108 } |
| 109 | 109 |
| 110 content::TestBrowserThreadBundle thread_bundle_; | 110 content::TestBrowserThreadBundle thread_bundle_; |
| 111 base::ScopedTempDir data_dir_; | 111 base::ScopedTempDir data_dir_; |
| 112 scoped_ptr<TestingProfileManager> profile_manager_; | 112 scoped_ptr<TestingProfileManager> profile_manager_; |
| 113 TestingProfile* profile_; // Owned by TestingProfileManager. | 113 TestingProfile* profile_; // Owned by TestingProfileManager. |
| 114 FakeProvidedFileSystem* provided_file_system_; // Owned by Service. | 114 FakeProvidedFileSystem* provided_file_system_; // Owned by Service. |
| 115 fileapi::FileSystemURL file_url_; | 115 storage::FileSystemURL file_url_; |
| 116 fileapi::FileSystemURL wrong_file_url_; | 116 storage::FileSystemURL wrong_file_url_; |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 TEST_F(FileSystemProviderFileStreamWriter, Write) { | 119 TEST_F(FileSystemProviderFileStreamWriter, Write) { |
| 120 std::vector<int> write_log; | 120 std::vector<int> write_log; |
| 121 | 121 |
| 122 const int64 initial_offset = 0; | 122 const int64 initial_offset = 0; |
| 123 FileStreamWriter writer(file_url_, initial_offset); | 123 FileStreamWriter writer(file_url_, initial_offset); |
| 124 scoped_refptr<net::IOBuffer> io_buffer(new net::StringIOBuffer(kTextToWrite)); | 124 scoped_refptr<net::IOBuffer> io_buffer(new net::StringIOBuffer(kTextToWrite)); |
| 125 | 125 |
| 126 { | 126 { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 228 |
| 229 FakeEntry entry_after; | 229 FakeEntry entry_after; |
| 230 ASSERT_TRUE(provided_file_system_->GetEntry( | 230 ASSERT_TRUE(provided_file_system_->GetEntry( |
| 231 base::FilePath::FromUTF8Unsafe(kFakeFilePath), &entry_after)); | 231 base::FilePath::FromUTF8Unsafe(kFakeFilePath), &entry_after)); |
| 232 const std::string expected_contents = entry_before.contents + kTextToWrite; | 232 const std::string expected_contents = entry_before.contents + kTextToWrite; |
| 233 EXPECT_EQ(expected_contents, entry_after.contents); | 233 EXPECT_EQ(expected_contents, entry_after.contents); |
| 234 } | 234 } |
| 235 | 235 |
| 236 } // namespace file_system_provider | 236 } // namespace file_system_provider |
| 237 } // namespace chromeos | 237 } // namespace chromeos |
| OLD | NEW |