Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: chrome/browser/chromeos/file_system_provider/fileapi/provider_async_file_util_unittest.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/provider_async_fi le_util.h" 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi le_util.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 "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "webkit/browser/fileapi/async_file_util.h" 26 #include "storage/browser/fileapi/async_file_util.h"
27 #include "webkit/browser/fileapi/external_mount_points.h" 27 #include "storage/browser/fileapi/external_mount_points.h"
28 #include "webkit/browser/fileapi/file_system_context.h" 28 #include "storage/browser/fileapi/file_system_context.h"
29 #include "webkit/browser/fileapi/file_system_url.h" 29 #include "storage/browser/fileapi/file_system_url.h"
30 #include "webkit/common/blob/shareable_file_reference.h" 30 #include "storage/common/blob/shareable_file_reference.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 tested operations. 39 // Logs callbacks invocations on the tested operations.
40 // TODO(mtomasz): Store and verify more arguments, once the operations return 40 // TODO(mtomasz): Store and verify more arguments, once the operations return
(...skipping 18 matching lines...) Expand all
59 void OnEnsureFileExists(base::File::Error error, bool created) { 59 void OnEnsureFileExists(base::File::Error error, bool created) {
60 result_.reset(new base::File::Error(error)); 60 result_.reset(new base::File::Error(error));
61 } 61 }
62 62
63 void OnGetFileInfo(base::File::Error error, 63 void OnGetFileInfo(base::File::Error error,
64 const base::File::Info& file_info) { 64 const base::File::Info& file_info) {
65 result_.reset(new base::File::Error(error)); 65 result_.reset(new base::File::Error(error));
66 } 66 }
67 67
68 void OnReadDirectory(base::File::Error error, 68 void OnReadDirectory(base::File::Error error,
69 const fileapi::AsyncFileUtil::EntryList& file_list, 69 const storage::AsyncFileUtil::EntryList& file_list,
70 bool has_more) { 70 bool has_more) {
71 result_.reset(new base::File::Error(error)); 71 result_.reset(new base::File::Error(error));
72 } 72 }
73 73
74 void OnCreateSnapshotFile( 74 void OnCreateSnapshotFile(
75 base::File::Error error, 75 base::File::Error error,
76 const base::File::Info& file_info, 76 const base::File::Info& file_info,
77 const base::FilePath& platform_path, 77 const base::FilePath& platform_path,
78 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) { 78 const scoped_refptr<storage::ShareableFileReference>& file_ref) {
79 result_.reset(new base::File::Error(error)); 79 result_.reset(new base::File::Error(error));
80 } 80 }
81 81
82 void OnCopyFileProgress(int64 size) {} 82 void OnCopyFileProgress(int64 size) {}
83 83
84 base::File::Error* result() { return result_.get(); } 84 base::File::Error* result() { return result_.get(); }
85 85
86 private: 86 private:
87 scoped_ptr<base::File::Error> result_; 87 scoped_ptr<base::File::Error> result_;
88 DISALLOW_COPY_AND_ASSIGN(EventLogger); 88 DISALLOW_COPY_AND_ASSIGN(EventLogger);
89 }; 89 };
90 90
91 // Creates a cracked FileSystemURL for tests. 91 // Creates a cracked FileSystemURL for tests.
92 fileapi::FileSystemURL CreateFileSystemURL(const std::string& mount_point_name, 92 storage::FileSystemURL CreateFileSystemURL(const std::string& mount_point_name,
93 const base::FilePath& file_path) { 93 const base::FilePath& file_path) {
94 const std::string origin = std::string("chrome-extension://") + kExtensionId; 94 const std::string origin = std::string("chrome-extension://") + kExtensionId;
95 const fileapi::ExternalMountPoints* const mount_points = 95 const storage::ExternalMountPoints* const mount_points =
96 fileapi::ExternalMountPoints::GetSystemInstance(); 96 storage::ExternalMountPoints::GetSystemInstance();
97 return mount_points->CreateCrackedFileSystemURL( 97 return mount_points->CreateCrackedFileSystemURL(
98 GURL(origin), 98 GURL(origin),
99 fileapi::kFileSystemTypeExternal, 99 storage::kFileSystemTypeExternal,
100 base::FilePath::FromUTF8Unsafe(mount_point_name).Append(file_path)); 100 base::FilePath::FromUTF8Unsafe(mount_point_name).Append(file_path));
101 } 101 }
102 102
103 // Creates a Service instance. Used to be able to destroy the service in 103 // Creates a Service instance. Used to be able to destroy the service in
104 // TearDown(). 104 // TearDown().
105 KeyedService* CreateService(content::BrowserContext* context) { 105 KeyedService* CreateService(content::BrowserContext* context) {
106 return new Service(Profile::FromBrowserContext(context), 106 return new Service(Profile::FromBrowserContext(context),
107 extensions::ExtensionRegistry::Get(context)); 107 extensions::ExtensionRegistry::Get(context));
108 } 108 }
109 109
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 root_url_ = CreateFileSystemURL(mount_point_name, base::FilePath()); 157 root_url_ = CreateFileSystemURL(mount_point_name, base::FilePath());
158 ASSERT_TRUE(root_url_.is_valid()); 158 ASSERT_TRUE(root_url_.is_valid());
159 } 159 }
160 160
161 virtual void TearDown() OVERRIDE { 161 virtual void TearDown() OVERRIDE {
162 // Setting the testing factory to NULL will destroy the created service 162 // Setting the testing factory to NULL will destroy the created service
163 // associated with the testing profile. 163 // associated with the testing profile.
164 ServiceFactory::GetInstance()->SetTestingFactory(profile_, NULL); 164 ServiceFactory::GetInstance()->SetTestingFactory(profile_, NULL);
165 } 165 }
166 166
167 scoped_ptr<fileapi::FileSystemOperationContext> CreateOperationContext() { 167 scoped_ptr<storage::FileSystemOperationContext> CreateOperationContext() {
168 return make_scoped_ptr( 168 return make_scoped_ptr(
169 new fileapi::FileSystemOperationContext(file_system_context_.get())); 169 new storage::FileSystemOperationContext(file_system_context_.get()));
170 } 170 }
171 171
172 content::TestBrowserThreadBundle thread_bundle_; 172 content::TestBrowserThreadBundle thread_bundle_;
173 base::ScopedTempDir data_dir_; 173 base::ScopedTempDir data_dir_;
174 scoped_ptr<TestingProfileManager> profile_manager_; 174 scoped_ptr<TestingProfileManager> profile_manager_;
175 TestingProfile* profile_; // Owned by TestingProfileManager. 175 TestingProfile* profile_; // Owned by TestingProfileManager.
176 scoped_ptr<fileapi::AsyncFileUtil> async_file_util_; 176 scoped_ptr<storage::AsyncFileUtil> async_file_util_;
177 scoped_refptr<fileapi::FileSystemContext> file_system_context_; 177 scoped_refptr<storage::FileSystemContext> file_system_context_;
178 fileapi::FileSystemURL file_url_; 178 storage::FileSystemURL file_url_;
179 fileapi::FileSystemURL directory_url_; 179 storage::FileSystemURL directory_url_;
180 fileapi::FileSystemURL root_url_; 180 storage::FileSystemURL root_url_;
181 }; 181 };
182 182
183 TEST_F(FileSystemProviderProviderAsyncFileUtilTest, CreateOrOpen_Create) { 183 TEST_F(FileSystemProviderProviderAsyncFileUtilTest, CreateOrOpen_Create) {
184 EventLogger logger; 184 EventLogger logger;
185 185
186 async_file_util_->CreateOrOpen( 186 async_file_util_->CreateOrOpen(
187 CreateOperationContext(), 187 CreateOperationContext(),
188 file_url_, 188 file_url_,
189 base::File::FLAG_CREATE, 189 base::File::FLAG_CREATE,
190 base::Bind(&EventLogger::OnCreateOrOpen, base::Unretained(&logger))); 190 base::Bind(&EventLogger::OnCreateOrOpen, base::Unretained(&logger)));
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 EXPECT_EQ(base::File::FILE_OK, *logger.result()); 328 EXPECT_EQ(base::File::FILE_OK, *logger.result());
329 } 329 }
330 330
331 TEST_F(FileSystemProviderProviderAsyncFileUtilTest, CopyFileLocal) { 331 TEST_F(FileSystemProviderProviderAsyncFileUtilTest, CopyFileLocal) {
332 EventLogger logger; 332 EventLogger logger;
333 333
334 async_file_util_->CopyFileLocal( 334 async_file_util_->CopyFileLocal(
335 CreateOperationContext(), 335 CreateOperationContext(),
336 file_url_, // src_url 336 file_url_, // src_url
337 file_url_, // dst_url 337 file_url_, // dst_url
338 fileapi::FileSystemOperation::OPTION_NONE, 338 storage::FileSystemOperation::OPTION_NONE,
339 base::Bind(&EventLogger::OnCopyFileProgress, base::Unretained(&logger)), 339 base::Bind(&EventLogger::OnCopyFileProgress, base::Unretained(&logger)),
340 base::Bind(&EventLogger::OnStatus, base::Unretained(&logger))); 340 base::Bind(&EventLogger::OnStatus, base::Unretained(&logger)));
341 base::RunLoop().RunUntilIdle(); 341 base::RunLoop().RunUntilIdle();
342 342
343 ASSERT_TRUE(logger.result()); 343 ASSERT_TRUE(logger.result());
344 EXPECT_EQ(base::File::FILE_OK, *logger.result()); 344 EXPECT_EQ(base::File::FILE_OK, *logger.result());
345 } 345 }
346 346
347 TEST_F(FileSystemProviderProviderAsyncFileUtilTest, MoveFileLocal) { 347 TEST_F(FileSystemProviderProviderAsyncFileUtilTest, MoveFileLocal) {
348 EventLogger logger; 348 EventLogger logger;
349 349
350 async_file_util_->MoveFileLocal( 350 async_file_util_->MoveFileLocal(
351 CreateOperationContext(), 351 CreateOperationContext(),
352 file_url_, // src_url 352 file_url_, // src_url
353 file_url_, // dst_url 353 file_url_, // dst_url
354 fileapi::FileSystemOperation::OPTION_NONE, 354 storage::FileSystemOperation::OPTION_NONE,
355 base::Bind(&EventLogger::OnStatus, base::Unretained(&logger))); 355 base::Bind(&EventLogger::OnStatus, base::Unretained(&logger)));
356 base::RunLoop().RunUntilIdle(); 356 base::RunLoop().RunUntilIdle();
357 357
358 ASSERT_TRUE(logger.result()); 358 ASSERT_TRUE(logger.result());
359 EXPECT_EQ(base::File::FILE_OK, *logger.result()); 359 EXPECT_EQ(base::File::FILE_OK, *logger.result());
360 } 360 }
361 361
362 TEST_F(FileSystemProviderProviderAsyncFileUtilTest, CopyInForeignFile) { 362 TEST_F(FileSystemProviderProviderAsyncFileUtilTest, CopyInForeignFile) {
363 EventLogger logger; 363 EventLogger logger;
364 364
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 file_url_, 419 file_url_,
420 base::Bind(&EventLogger::OnCreateSnapshotFile, 420 base::Bind(&EventLogger::OnCreateSnapshotFile,
421 base::Unretained(&logger))); 421 base::Unretained(&logger)));
422 422
423 ASSERT_TRUE(logger.result()); 423 ASSERT_TRUE(logger.result());
424 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, *logger.result()); 424 EXPECT_EQ(base::File::FILE_ERROR_INVALID_OPERATION, *logger.result());
425 } 425 }
426 426
427 } // namespace file_system_provider 427 } // namespace file_system_provider
428 } // namespace chromeos 428 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698