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

Side by Side Diff: content/browser/fileapi/file_system_operation_impl_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698