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

Side by Side Diff: chrome/browser/sync_file_system/local/syncable_file_system_unittest.cc

Issue 492873002: Collapse fileapi, webkit_blob, webkit_database, quota, and webkit_common namespaces into single sto… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chromeos build 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 "base/stl_util.h" 5 #include "base/stl_util.h"
6 #include "base/thread_task_runner_handle.h" 6 #include "base/thread_task_runner_handle.h"
7 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h" 7 #include "chrome/browser/sync_file_system/local/canned_syncable_file_system.h"
8 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h" 8 #include "chrome/browser/sync_file_system/local/local_file_change_tracker.h"
9 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h" 9 #include "chrome/browser/sync_file_system/local/local_file_sync_context.h"
10 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" 10 #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h"
11 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" 11 #include "chrome/browser/sync_file_system/syncable_file_system_util.h"
12 #include "content/public/test/async_file_test_helper.h" 12 #include "content/public/test/async_file_test_helper.h"
13 #include "content/public/test/sandbox_file_system_test_helper.h" 13 #include "content/public/test/sandbox_file_system_test_helper.h"
14 #include "content/public/test/test_browser_thread_bundle.h" 14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h" 16 #include "third_party/leveldatabase/src/helpers/memenv/memenv.h"
17 #include "third_party/leveldatabase/src/include/leveldb/env.h" 17 #include "third_party/leveldatabase/src/include/leveldb/env.h"
18 #include "webkit/browser/fileapi/file_system_context.h" 18 #include "webkit/browser/fileapi/file_system_context.h"
19 #include "webkit/browser/fileapi/file_system_operation_context.h" 19 #include "webkit/browser/fileapi/file_system_operation_context.h"
20 #include "webkit/browser/fileapi/isolated_context.h" 20 #include "webkit/browser/fileapi/isolated_context.h"
21 #include "webkit/browser/quota/quota_manager.h" 21 #include "webkit/browser/quota/quota_manager.h"
22 #include "webkit/common/fileapi/file_system_types.h" 22 #include "webkit/common/fileapi/file_system_types.h"
23 #include "webkit/common/quota/quota_types.h" 23 #include "webkit/common/quota/quota_types.h"
24 24
25 using content::SandboxFileSystemTestHelper; 25 using content::SandboxFileSystemTestHelper;
26 using fileapi::FileSystemContext; 26 using storage::FileSystemContext;
27 using fileapi::FileSystemOperationContext; 27 using storage::FileSystemOperationContext;
28 using fileapi::FileSystemURL; 28 using storage::FileSystemURL;
29 using fileapi::FileSystemURLSet; 29 using storage::FileSystemURLSet;
30 using quota::QuotaManager; 30 using storage::QuotaManager;
31 using quota::QuotaStatusCode; 31 using storage::QuotaStatusCode;
32 32
33 namespace sync_file_system { 33 namespace sync_file_system {
34 34
35 class SyncableFileSystemTest : public testing::Test { 35 class SyncableFileSystemTest : public testing::Test {
36 public: 36 public:
37 SyncableFileSystemTest() 37 SyncableFileSystemTest()
38 : in_memory_env_(leveldb::NewMemEnv(leveldb::Env::Default())), 38 : in_memory_env_(leveldb::NewMemEnv(leveldb::Env::Default())),
39 file_system_(GURL("http://example.com/"), 39 file_system_(GURL("http://example.com/"),
40 in_memory_env_.get(), 40 in_memory_env_.get(),
41 base::ThreadTaskRunnerHandle::Get().get(), 41 base::ThreadTaskRunnerHandle::Get().get(),
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 EXPECT_EQ(base::File::FILE_OK, 121 EXPECT_EQ(base::File::FILE_OK,
122 file_system_.CreateDirectory(URL("dir"))); 122 file_system_.CreateDirectory(URL("dir")));
123 EXPECT_EQ(base::File::FILE_OK, 123 EXPECT_EQ(base::File::FILE_OK,
124 file_system_.CreateFile(URL("dir/foo"))); 124 file_system_.CreateFile(URL("dir/foo")));
125 125
126 const int64 kOriginalQuota = QuotaManager::kSyncableStorageDefaultHostQuota; 126 const int64 kOriginalQuota = QuotaManager::kSyncableStorageDefaultHostQuota;
127 127
128 const int64 kQuota = 12345 * 1024; 128 const int64 kQuota = 12345 * 1024;
129 QuotaManager::kSyncableStorageDefaultHostQuota = kQuota; 129 QuotaManager::kSyncableStorageDefaultHostQuota = kQuota;
130 int64 usage, quota; 130 int64 usage, quota;
131 EXPECT_EQ(quota::kQuotaStatusOk, 131 EXPECT_EQ(storage::kQuotaStatusOk,
132 file_system_.GetUsageAndQuota(&usage, &quota)); 132 file_system_.GetUsageAndQuota(&usage, &quota));
133 133
134 // Returned quota must be what we overrode. Usage must be greater than 0 134 // Returned quota must be what we overrode. Usage must be greater than 0
135 // as creating a file or directory consumes some space. 135 // as creating a file or directory consumes some space.
136 EXPECT_EQ(kQuota, quota); 136 EXPECT_EQ(kQuota, quota);
137 EXPECT_GT(usage, 0); 137 EXPECT_GT(usage, 0);
138 138
139 // Truncate to extend an existing file and see if the usage reflects it. 139 // Truncate to extend an existing file and see if the usage reflects it.
140 const int64 kFileSizeToExtend = 333; 140 const int64 kFileSizeToExtend = 333;
141 EXPECT_EQ(base::File::FILE_OK, 141 EXPECT_EQ(base::File::FILE_OK,
142 file_system_.CreateFile(URL("dir/foo"))); 142 file_system_.CreateFile(URL("dir/foo")));
143 143
144 EXPECT_EQ(base::File::FILE_OK, 144 EXPECT_EQ(base::File::FILE_OK,
145 file_system_.TruncateFile(URL("dir/foo"), kFileSizeToExtend)); 145 file_system_.TruncateFile(URL("dir/foo"), kFileSizeToExtend));
146 146
147 int64 new_usage; 147 int64 new_usage;
148 EXPECT_EQ(quota::kQuotaStatusOk, 148 EXPECT_EQ(storage::kQuotaStatusOk,
149 file_system_.GetUsageAndQuota(&new_usage, &quota)); 149 file_system_.GetUsageAndQuota(&new_usage, &quota));
150 EXPECT_EQ(kFileSizeToExtend, new_usage - usage); 150 EXPECT_EQ(kFileSizeToExtend, new_usage - usage);
151 151
152 // Shrink the quota to the current usage, try to extend the file further 152 // Shrink the quota to the current usage, try to extend the file further
153 // and see if it fails. 153 // and see if it fails.
154 QuotaManager::kSyncableStorageDefaultHostQuota = new_usage; 154 QuotaManager::kSyncableStorageDefaultHostQuota = new_usage;
155 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE, 155 EXPECT_EQ(base::File::FILE_ERROR_NO_SPACE,
156 file_system_.TruncateFile(URL("dir/foo"), kFileSizeToExtend + 1)); 156 file_system_.TruncateFile(URL("dir/foo"), kFileSizeToExtend + 1));
157 157
158 usage = new_usage; 158 usage = new_usage;
159 EXPECT_EQ(quota::kQuotaStatusOk, 159 EXPECT_EQ(storage::kQuotaStatusOk,
160 file_system_.GetUsageAndQuota(&new_usage, &quota)); 160 file_system_.GetUsageAndQuota(&new_usage, &quota));
161 EXPECT_EQ(usage, new_usage); 161 EXPECT_EQ(usage, new_usage);
162 162
163 // Deletes the file system. 163 // Deletes the file system.
164 EXPECT_EQ(base::File::FILE_OK, 164 EXPECT_EQ(base::File::FILE_OK,
165 file_system_.DeleteFileSystem()); 165 file_system_.DeleteFileSystem());
166 166
167 // Now the usage must be zero. 167 // Now the usage must be zero.
168 EXPECT_EQ(quota::kQuotaStatusOk, 168 EXPECT_EQ(storage::kQuotaStatusOk,
169 file_system_.GetUsageAndQuota(&usage, &quota)); 169 file_system_.GetUsageAndQuota(&usage, &quota));
170 EXPECT_EQ(0, usage); 170 EXPECT_EQ(0, usage);
171 171
172 // Restore the system default quota. 172 // Restore the system default quota.
173 QuotaManager::kSyncableStorageDefaultHostQuota = kOriginalQuota; 173 QuotaManager::kSyncableStorageDefaultHostQuota = kOriginalQuota;
174 } 174 }
175 175
176 // Combined testing with LocalFileChangeTracker. 176 // Combined testing with LocalFileChangeTracker.
177 TEST_F(SyncableFileSystemTest, ChangeTrackerSimple) { 177 TEST_F(SyncableFileSystemTest, ChangeTrackerSimple) {
178 EXPECT_EQ(base::File::FILE_OK, 178 EXPECT_EQ(base::File::FILE_OK,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); 242 sync_file_system::SYNC_FILE_TYPE_DIRECTORY));
243 VerifyAndClearChange(URL(kPath1), 243 VerifyAndClearChange(URL(kPath1),
244 FileChange(FileChange::FILE_CHANGE_DELETE, 244 FileChange(FileChange::FILE_CHANGE_DELETE,
245 sync_file_system::SYNC_FILE_TYPE_DIRECTORY)); 245 sync_file_system::SYNC_FILE_TYPE_DIRECTORY));
246 VerifyAndClearChange(URL(kPath2), 246 VerifyAndClearChange(URL(kPath2),
247 FileChange(FileChange::FILE_CHANGE_DELETE, 247 FileChange(FileChange::FILE_CHANGE_DELETE,
248 sync_file_system::SYNC_FILE_TYPE_FILE)); 248 sync_file_system::SYNC_FILE_TYPE_FILE));
249 } 249 }
250 250
251 } // namespace sync_file_system 251 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698