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

Side by Side Diff: content/browser/fileapi/file_system_operation_impl_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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "webkit/browser/fileapi/file_system_operation_impl.h" 5 #include "storage/browser/fileapi/file_system_operation_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "content/browser/fileapi/mock_file_change_observer.h" 15 #include "content/browser/fileapi/mock_file_change_observer.h"
16 #include "content/browser/quota/mock_quota_manager.h" 16 #include "content/browser/quota/mock_quota_manager.h"
17 #include "content/browser/quota/mock_quota_manager_proxy.h" 17 #include "content/browser/quota/mock_quota_manager_proxy.h"
18 #include "content/public/test/async_file_test_helper.h" 18 #include "content/public/test/async_file_test_helper.h"
19 #include "content/public/test/sandbox_file_system_test_helper.h" 19 #include "content/public/test/sandbox_file_system_test_helper.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "url/gurl.h" 21 #include "url/gurl.h"
22 #include "webkit/browser/fileapi/file_system_context.h" 22 #include "storage/browser/fileapi/file_system_context.h"
23 #include "webkit/browser/fileapi/file_system_file_util.h" 23 #include "storage/browser/fileapi/file_system_file_util.h"
24 #include "webkit/browser/fileapi/file_system_operation_context.h" 24 #include "storage/browser/fileapi/file_system_operation_context.h"
25 #include "webkit/browser/fileapi/file_system_operation_runner.h" 25 #include "storage/browser/fileapi/file_system_operation_runner.h"
26 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" 26 #include "storage/browser/fileapi/sandbox_file_system_backend.h"
27 #include "webkit/browser/quota/quota_manager.h" 27 #include "storage/browser/quota/quota_manager.h"
28 #include "webkit/browser/quota/quota_manager_proxy.h" 28 #include "storage/browser/quota/quota_manager_proxy.h"
29 #include "webkit/common/blob/shareable_file_reference.h" 29 #include "storage/common/blob/shareable_file_reference.h"
30 #include "webkit/common/fileapi/file_system_util.h" 30 #include "storage/common/fileapi/file_system_util.h"
31 31
32 using content::AsyncFileTestHelper; 32 using content::AsyncFileTestHelper;
33 using fileapi::FileSystemOperation; 33 using storage::FileSystemOperation;
34 using fileapi::FileSystemOperationContext; 34 using storage::FileSystemOperationContext;
35 using fileapi::FileSystemOperationRunner; 35 using storage::FileSystemOperationRunner;
36 using fileapi::FileSystemURL; 36 using storage::FileSystemURL;
37 using quota::QuotaManager; 37 using quota::QuotaManager;
38 using quota::QuotaManagerProxy; 38 using quota::QuotaManagerProxy;
39 using webkit_blob::ShareableFileReference; 39 using storage::ShareableFileReference;
40 40
41 namespace content { 41 namespace content {
42 42
43 namespace { 43 namespace {
44 44
45 const int kFileOperationStatusNotSet = 1; 45 const int kFileOperationStatusNotSet = 1;
46 46
47 void AssertFileErrorEq(const tracked_objects::Location& from_here, 47 void AssertFileErrorEq(const tracked_objects::Location& from_here,
48 base::File::Error expected, 48 base::File::Error expected,
49 base::File::Error actual) { 49 base::File::Error actual) {
50 ASSERT_EQ(expected, actual) << from_here.ToString(); 50 ASSERT_EQ(expected, actual) << from_here.ToString();
51 } 51 }
52 52
53 } // namespace 53 } // namespace
54 54
55 // Test class for FileSystemOperationImpl. 55 // Test class for FileSystemOperationImpl.
56 class FileSystemOperationImplTest 56 class FileSystemOperationImplTest
57 : public testing::Test { 57 : public testing::Test {
58 public: 58 public:
59 FileSystemOperationImplTest() 59 FileSystemOperationImplTest()
60 : status_(kFileOperationStatusNotSet), 60 : status_(kFileOperationStatusNotSet),
61 weak_factory_(this) {} 61 weak_factory_(this) {}
62 62
63 protected: 63 protected:
64 virtual void SetUp() OVERRIDE { 64 virtual void SetUp() OVERRIDE {
65 EXPECT_TRUE(base_.CreateUniqueTempDir()); 65 EXPECT_TRUE(base_.CreateUniqueTempDir());
66 change_observers_ = fileapi::MockFileChangeObserver::CreateList( 66 change_observers_ =
67 &change_observer_); 67 storage::MockFileChangeObserver::CreateList(&change_observer_);
68 68
69 base::FilePath base_dir = base_.path().AppendASCII("filesystem"); 69 base::FilePath base_dir = base_.path().AppendASCII("filesystem");
70 quota_manager_ = 70 quota_manager_ =
71 new MockQuotaManager(false /* is_incognito */, 71 new MockQuotaManager(false /* is_incognito */,
72 base_dir, 72 base_dir,
73 base::MessageLoopProxy::current().get(), 73 base::MessageLoopProxy::current().get(),
74 base::MessageLoopProxy::current().get(), 74 base::MessageLoopProxy::current().get(),
75 NULL /* special storage policy */); 75 NULL /* special storage policy */);
76 quota_manager_proxy_ = new MockQuotaManagerProxy( 76 quota_manager_proxy_ = new MockQuotaManagerProxy(
77 quota_manager(), base::MessageLoopProxy::current().get()); 77 quota_manager(), base::MessageLoopProxy::current().get());
78 sandbox_file_system_.SetUp(base_dir, quota_manager_proxy_.get()); 78 sandbox_file_system_.SetUp(base_dir, quota_manager_proxy_.get());
79 sandbox_file_system_.AddFileChangeObserver(&change_observer_); 79 sandbox_file_system_.AddFileChangeObserver(&change_observer_);
80 } 80 }
81 81
82 virtual void TearDown() OVERRIDE { 82 virtual void TearDown() OVERRIDE {
83 // Let the client go away before dropping a ref of the quota manager proxy. 83 // Let the client go away before dropping a ref of the quota manager proxy.
84 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); 84 quota_manager_proxy()->SimulateQuotaManagerDestroyed();
85 quota_manager_ = NULL; 85 quota_manager_ = NULL;
86 quota_manager_proxy_ = NULL; 86 quota_manager_proxy_ = NULL;
87 sandbox_file_system_.TearDown(); 87 sandbox_file_system_.TearDown();
88 } 88 }
89 89
90 FileSystemOperationRunner* operation_runner() { 90 FileSystemOperationRunner* operation_runner() {
91 return sandbox_file_system_.operation_runner(); 91 return sandbox_file_system_.operation_runner();
92 } 92 }
93 93
94 int status() const { return status_; } 94 int status() const { return status_; }
95 const base::File::Info& info() const { return info_; } 95 const base::File::Info& info() const { return info_; }
96 const base::FilePath& path() const { return path_; } 96 const base::FilePath& path() const { return path_; }
97 const std::vector<fileapi::DirectoryEntry>& entries() const { 97 const std::vector<storage::DirectoryEntry>& entries() const {
98 return entries_; 98 return entries_;
99 } 99 }
100 100
101 const ShareableFileReference* shareable_file_ref() const { 101 const ShareableFileReference* shareable_file_ref() const {
102 return shareable_file_ref_.get(); 102 return shareable_file_ref_.get();
103 } 103 }
104 104
105 MockQuotaManager* quota_manager() { 105 MockQuotaManager* quota_manager() {
106 return static_cast<MockQuotaManager*>(quota_manager_.get()); 106 return static_cast<MockQuotaManager*>(quota_manager_.get());
107 } 107 }
108 108
109 MockQuotaManagerProxy* quota_manager_proxy() { 109 MockQuotaManagerProxy* quota_manager_proxy() {
110 return static_cast<MockQuotaManagerProxy*>( 110 return static_cast<MockQuotaManagerProxy*>(
111 quota_manager_proxy_.get()); 111 quota_manager_proxy_.get());
112 } 112 }
113 113
114 fileapi::FileSystemFileUtil* file_util() { 114 storage::FileSystemFileUtil* file_util() {
115 return sandbox_file_system_.file_util(); 115 return sandbox_file_system_.file_util();
116 } 116 }
117 117
118 fileapi::MockFileChangeObserver* change_observer() { 118 storage::MockFileChangeObserver* change_observer() {
119 return &change_observer_; 119 return &change_observer_;
120 } 120 }
121 121
122 scoped_ptr<FileSystemOperationContext> NewContext() { 122 scoped_ptr<FileSystemOperationContext> NewContext() {
123 FileSystemOperationContext* context = 123 FileSystemOperationContext* context =
124 sandbox_file_system_.NewOperationContext(); 124 sandbox_file_system_.NewOperationContext();
125 // Grant enough quota for all test cases. 125 // Grant enough quota for all test cases.
126 context->set_allowed_bytes_growth(1000000); 126 context->set_allowed_bytes_growth(1000000);
127 return make_scoped_ptr(context); 127 return make_scoped_ptr(context);
128 } 128 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 190
191 FileSystemOperation::SnapshotFileCallback RecordSnapshotFileCallback() { 191 FileSystemOperation::SnapshotFileCallback RecordSnapshotFileCallback() {
192 return base::Bind(&FileSystemOperationImplTest::DidCreateSnapshotFile, 192 return base::Bind(&FileSystemOperationImplTest::DidCreateSnapshotFile,
193 weak_factory_.GetWeakPtr()); 193 weak_factory_.GetWeakPtr());
194 } 194 }
195 195
196 void DidFinish(base::File::Error status) { 196 void DidFinish(base::File::Error status) {
197 status_ = status; 197 status_ = status;
198 } 198 }
199 199
200 void DidReadDirectory( 200 void DidReadDirectory(base::File::Error status,
201 base::File::Error status, 201 const std::vector<storage::DirectoryEntry>& entries,
202 const std::vector<fileapi::DirectoryEntry>& entries, 202 bool /* has_more */) {
203 bool /* has_more */) {
204 entries_ = entries; 203 entries_ = entries;
205 status_ = status; 204 status_ = status;
206 } 205 }
207 206
208 void DidGetMetadata(base::File::Error status, 207 void DidGetMetadata(base::File::Error status,
209 const base::File::Info& info) { 208 const base::File::Info& info) {
210 info_ = info; 209 info_ = info;
211 status_ = status; 210 status_ = status;
212 } 211 }
213 212
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 283
285 // Common temp base for nondestructive uses. 284 // Common temp base for nondestructive uses.
286 base::ScopedTempDir base_; 285 base::ScopedTempDir base_;
287 286
288 SandboxFileSystemTestHelper sandbox_file_system_; 287 SandboxFileSystemTestHelper sandbox_file_system_;
289 288
290 // For post-operation status. 289 // For post-operation status.
291 int status_; 290 int status_;
292 base::File::Info info_; 291 base::File::Info info_;
293 base::FilePath path_; 292 base::FilePath path_;
294 std::vector<fileapi::DirectoryEntry> entries_; 293 std::vector<storage::DirectoryEntry> entries_;
295 scoped_refptr<ShareableFileReference> shareable_file_ref_; 294 scoped_refptr<ShareableFileReference> shareable_file_ref_;
296 295
297 fileapi::MockFileChangeObserver change_observer_; 296 storage::MockFileChangeObserver change_observer_;
298 fileapi::ChangeObserverList change_observers_; 297 storage::ChangeObserverList change_observers_;
299 298
300 base::WeakPtrFactory<FileSystemOperationImplTest> weak_factory_; 299 base::WeakPtrFactory<FileSystemOperationImplTest> weak_factory_;
301 300
302 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplTest); 301 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationImplTest);
303 }; 302 };
304 303
305 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDoesntExist) { 304 TEST_F(FileSystemOperationImplTest, TestMoveFailureSrcDoesntExist) {
306 change_observer()->ResetCount(); 305 change_observer()->ResetCount();
307 operation_runner()->Move(URLForPath("a"), URLForPath("b"), 306 operation_runner()->Move(URLForPath("a"), URLForPath("b"),
308 FileSystemOperation::OPTION_NONE, 307 FileSystemOperation::OPTION_NONE,
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 base::RunLoop().RunUntilIdle(); 1281 base::RunLoop().RunUntilIdle();
1283 1282
1284 expected_usage += grandchild_file_size + grandchild_path_cost; 1283 expected_usage += grandchild_file_size + grandchild_path_cost;
1285 usage = GetUsage(); 1284 usage = GetUsage();
1286 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size, 1285 EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size,
1287 GetDataSizeOnDisk()); 1286 GetDataSizeOnDisk());
1288 EXPECT_EQ(expected_usage, usage); 1287 EXPECT_EQ(expected_usage, usage);
1289 } 1288 }
1290 1289
1291 } // namespace content 1290 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698