| 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_reade
r.h" | 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/file_stream_reade
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" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system
.h" | 16 #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system
.h" |
| 17 #include "chrome/browser/chromeos/file_system_provider/service.h" | 17 #include "chrome/browser/chromeos/file_system_provider/service.h" |
| 18 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" | 18 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" |
| 19 #include "chrome/test/base/testing_browser_process.h" | 19 #include "chrome/test/base/testing_browser_process.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 21 #include "chrome/test/base/testing_profile_manager.h" | 21 #include "chrome/test/base/testing_profile_manager.h" |
| 22 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 23 #include "content/public/test/test_file_system_context.h" | 23 #include "content/public/test/test_file_system_context.h" |
| 24 #include "extensions/browser/extension_registry.h" | 24 #include "extensions/browser/extension_registry.h" |
| 25 #include "net/base/io_buffer.h" | 25 #include "net/base/io_buffer.h" |
| 26 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include "webkit/browser/fileapi/async_file_util.h" | 28 #include "storage/browser/fileapi/async_file_util.h" |
| 29 #include "webkit/browser/fileapi/external_mount_points.h" | 29 #include "storage/browser/fileapi/external_mount_points.h" |
| 30 #include "webkit/browser/fileapi/file_system_url.h" | 30 #include "storage/browser/fileapi/file_system_url.h" |
| 31 | 31 |
| 32 namespace chromeos { | 32 namespace chromeos { |
| 33 namespace file_system_provider { | 33 namespace file_system_provider { |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 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 | 38 |
| 39 // Logs callbacks invocations on the file stream reader. | 39 // Logs callbacks invocations on the file stream reader. |
| 40 class EventLogger { | 40 class EventLogger { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 52 const std::vector<int64>& results() const { return results_; } | 52 const std::vector<int64>& results() const { return results_; } |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 std::vector<int64> results_; | 55 std::vector<int64> results_; |
| 56 base::WeakPtrFactory<EventLogger> weak_ptr_factory_; | 56 base::WeakPtrFactory<EventLogger> weak_ptr_factory_; |
| 57 | 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(EventLogger); | 58 DISALLOW_COPY_AND_ASSIGN(EventLogger); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // Creates a cracked FileSystemURL for tests. | 61 // Creates a cracked FileSystemURL for tests. |
| 62 fileapi::FileSystemURL CreateFileSystemURL(const std::string& mount_point_name, | 62 storage::FileSystemURL CreateFileSystemURL(const std::string& mount_point_name, |
| 63 const base::FilePath& file_path) { | 63 const base::FilePath& file_path) { |
| 64 const std::string origin = std::string("chrome-extension://") + kExtensionId; | 64 const std::string origin = std::string("chrome-extension://") + kExtensionId; |
| 65 const fileapi::ExternalMountPoints* const mount_points = | 65 const storage::ExternalMountPoints* const mount_points = |
| 66 fileapi::ExternalMountPoints::GetSystemInstance(); | 66 storage::ExternalMountPoints::GetSystemInstance(); |
| 67 return mount_points->CreateCrackedFileSystemURL( | 67 return mount_points->CreateCrackedFileSystemURL( |
| 68 GURL(origin), | 68 GURL(origin), |
| 69 fileapi::kFileSystemTypeExternal, | 69 storage::kFileSystemTypeExternal, |
| 70 base::FilePath::FromUTF8Unsafe(mount_point_name).Append(file_path)); | 70 base::FilePath::FromUTF8Unsafe(mount_point_name).Append(file_path)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Creates a Service instance. Used to be able to destroy the service in | 73 // Creates a Service instance. Used to be able to destroy the service in |
| 74 // TearDown(). | 74 // TearDown(). |
| 75 KeyedService* CreateService(content::BrowserContext* context) { | 75 KeyedService* CreateService(content::BrowserContext* context) { |
| 76 return new Service(Profile::FromBrowserContext(context), | 76 return new Service(Profile::FromBrowserContext(context), |
| 77 extensions::ExtensionRegistry::Get(context)); | 77 extensions::ExtensionRegistry::Get(context)); |
| 78 } | 78 } |
| 79 | 79 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // Setting the testing factory to NULL will destroy the created service | 125 // Setting the testing factory to NULL will destroy the created service |
| 126 // associated with the testing profile. | 126 // associated with the testing profile. |
| 127 ServiceFactory::GetInstance()->SetTestingFactory(profile_, NULL); | 127 ServiceFactory::GetInstance()->SetTestingFactory(profile_, NULL); |
| 128 } | 128 } |
| 129 | 129 |
| 130 content::TestBrowserThreadBundle thread_bundle_; | 130 content::TestBrowserThreadBundle thread_bundle_; |
| 131 base::ScopedTempDir data_dir_; | 131 base::ScopedTempDir data_dir_; |
| 132 scoped_ptr<TestingProfileManager> profile_manager_; | 132 scoped_ptr<TestingProfileManager> profile_manager_; |
| 133 TestingProfile* profile_; // Owned by TestingProfileManager. | 133 TestingProfile* profile_; // Owned by TestingProfileManager. |
| 134 FakeEntry fake_file_; | 134 FakeEntry fake_file_; |
| 135 fileapi::FileSystemURL file_url_; | 135 storage::FileSystemURL file_url_; |
| 136 fileapi::FileSystemURL wrong_file_url_; | 136 storage::FileSystemURL wrong_file_url_; |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 TEST_F(FileSystemProviderFileStreamReader, Read_AllAtOnce) { | 139 TEST_F(FileSystemProviderFileStreamReader, Read_AllAtOnce) { |
| 140 EventLogger logger; | 140 EventLogger logger; |
| 141 | 141 |
| 142 const int64 initial_offset = 0; | 142 const int64 initial_offset = 0; |
| 143 FileStreamReader reader( | 143 FileStreamReader reader( |
| 144 NULL, file_url_, initial_offset, fake_file_.metadata.modification_time); | 144 NULL, file_url_, initial_offset, fake_file_.metadata.modification_time); |
| 145 scoped_refptr<net::IOBuffer> io_buffer( | 145 scoped_refptr<net::IOBuffer> io_buffer( |
| 146 new net::IOBuffer(fake_file_.metadata.size)); | 146 new net::IOBuffer(fake_file_.metadata.size)); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 EXPECT_EQ(net::ERR_IO_PENDING, result); | 363 EXPECT_EQ(net::ERR_IO_PENDING, result); |
| 364 base::RunLoop().RunUntilIdle(); | 364 base::RunLoop().RunUntilIdle(); |
| 365 | 365 |
| 366 ASSERT_EQ(1u, logger.results().size()); | 366 ASSERT_EQ(1u, logger.results().size()); |
| 367 EXPECT_LT(0, logger.results()[0]); | 367 EXPECT_LT(0, logger.results()[0]); |
| 368 EXPECT_EQ(fake_file_.metadata.size, logger.results()[0]); | 368 EXPECT_EQ(fake_file_.metadata.size, logger.results()[0]); |
| 369 } | 369 } |
| 370 | 370 |
| 371 } // namespace file_system_provider | 371 } // namespace file_system_provider |
| 372 } // namespace chromeos | 372 } // namespace chromeos |
| OLD | NEW |