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

Side by Side Diff: webkit/browser/fileapi/obfuscated_file_util_unittest.cc

Issue 15810004: Cleanup: Rename LocalFileSystemTestOriginHelper (aka test_helper_) to SandboxFileSystemTestHelper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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
« no previous file with comments | « content/content_tests.gypi ('k') | webkit/browser/fileapi/sandbox_mount_point_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.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/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/platform_file.h" 15 #include "base/platform_file.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "webkit/browser/fileapi/file_system_mount_point_provider.h" 17 #include "webkit/browser/fileapi/file_system_mount_point_provider.h"
18 #include "webkit/browser/fileapi/file_system_usage_cache.h" 18 #include "webkit/browser/fileapi/file_system_usage_cache.h"
19 #include "webkit/browser/fileapi/obfuscated_file_util.h" 19 #include "webkit/browser/fileapi/obfuscated_file_util.h"
20 #include "webkit/fileapi/async_file_test_helper.h" 20 #include "webkit/fileapi/async_file_test_helper.h"
21 #include "webkit/fileapi/external_mount_points.h" 21 #include "webkit/fileapi/external_mount_points.h"
22 #include "webkit/fileapi/file_system_context.h" 22 #include "webkit/fileapi/file_system_context.h"
23 #include "webkit/fileapi/file_system_operation_context.h" 23 #include "webkit/fileapi/file_system_operation_context.h"
24 #include "webkit/fileapi/file_system_task_runners.h" 24 #include "webkit/fileapi/file_system_task_runners.h"
25 #include "webkit/fileapi/local_file_system_test_helper.h"
26 #include "webkit/fileapi/mock_file_change_observer.h" 25 #include "webkit/fileapi/mock_file_change_observer.h"
27 #include "webkit/fileapi/mock_file_system_context.h" 26 #include "webkit/fileapi/mock_file_system_context.h"
27 #include "webkit/fileapi/sandbox_file_system_test_helper.h"
28 #include "webkit/fileapi/test_file_set.h" 28 #include "webkit/fileapi/test_file_set.h"
29 #include "webkit/quota/mock_special_storage_policy.h" 29 #include "webkit/quota/mock_special_storage_policy.h"
30 #include "webkit/quota/quota_manager.h" 30 #include "webkit/quota/quota_manager.h"
31 #include "webkit/quota/quota_types.h" 31 #include "webkit/quota/quota_types.h"
32 32
33 namespace fileapi { 33 namespace fileapi {
34 34
35 namespace { 35 namespace {
36 36
37 bool FileExists(const base::FilePath& path) { 37 bool FileExists(const base::FilePath& path) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // TODO(ericu): The vast majority of this and the other FSFU subclass tests 114 // TODO(ericu): The vast majority of this and the other FSFU subclass tests
115 // could theoretically be shared. It would basically be a FSFU interface 115 // could theoretically be shared. It would basically be a FSFU interface
116 // compliance test, and only the subclass-specific bits that look into the 116 // compliance test, and only the subclass-specific bits that look into the
117 // implementation would need to be written per-subclass. 117 // implementation would need to be written per-subclass.
118 class ObfuscatedFileUtilTest : public testing::Test { 118 class ObfuscatedFileUtilTest : public testing::Test {
119 public: 119 public:
120 ObfuscatedFileUtilTest() 120 ObfuscatedFileUtilTest()
121 : origin_(GURL("http://www.example.com")), 121 : origin_(GURL("http://www.example.com")),
122 type_(kFileSystemTypeTemporary), 122 type_(kFileSystemTypeTemporary),
123 weak_factory_(this), 123 weak_factory_(this),
124 test_helper_(origin_, type_), 124 sandbox_file_system_(origin_, type_),
125 quota_status_(quota::kQuotaStatusUnknown), 125 quota_status_(quota::kQuotaStatusUnknown),
126 usage_(-1) { 126 usage_(-1) {
127 } 127 }
128 128
129 virtual void SetUp() { 129 virtual void SetUp() {
130 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); 130 ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
131 131
132 scoped_refptr<quota::SpecialStoragePolicy> storage_policy = 132 scoped_refptr<quota::SpecialStoragePolicy> storage_policy =
133 new quota::MockSpecialStoragePolicy(); 133 new quota::MockSpecialStoragePolicy();
134 134
135 quota_manager_ = new quota::QuotaManager( 135 quota_manager_ = new quota::QuotaManager(
136 false /* is_incognito */, 136 false /* is_incognito */,
137 data_dir_.path(), 137 data_dir_.path(),
138 base::MessageLoopProxy::current(), 138 base::MessageLoopProxy::current(),
139 base::MessageLoopProxy::current(), 139 base::MessageLoopProxy::current(),
140 storage_policy); 140 storage_policy);
141 141
142 // Every time we create a new helper, it creates another context, which 142 // Every time we create a new sandbox_file_system helper,
143 // creates another path manager, another sandbox_mount_point_provider, and 143 // it creates another context, which creates another path manager,
144 // another sandbox_mount_point_provider, and
144 // another OFU. We need to pass in the context to skip all that. 145 // another OFU. We need to pass in the context to skip all that.
145 file_system_context_ = CreateFileSystemContextForTesting( 146 file_system_context_ = CreateFileSystemContextForTesting(
146 quota_manager_->proxy(), 147 quota_manager_->proxy(),
147 data_dir_.path()); 148 data_dir_.path());
148 149
149 test_helper_.SetUp(file_system_context_.get()); 150 sandbox_file_system_.SetUp(file_system_context_.get());
150 151
151 change_observers_ = MockFileChangeObserver::CreateList(&change_observer_); 152 change_observers_ = MockFileChangeObserver::CreateList(&change_observer_);
152 } 153 }
153 154
154 virtual void TearDown() { 155 virtual void TearDown() {
155 quota_manager_ = NULL; 156 quota_manager_ = NULL;
156 test_helper_.TearDown(); 157 sandbox_file_system_.TearDown();
157 } 158 }
158 159
159 scoped_ptr<FileSystemOperationContext> LimitedContext( 160 scoped_ptr<FileSystemOperationContext> LimitedContext(
160 int64 allowed_bytes_growth) { 161 int64 allowed_bytes_growth) {
161 scoped_ptr<FileSystemOperationContext> context( 162 scoped_ptr<FileSystemOperationContext> context(
162 test_helper_.NewOperationContext()); 163 sandbox_file_system_.NewOperationContext());
163 context->set_allowed_bytes_growth(allowed_bytes_growth); 164 context->set_allowed_bytes_growth(allowed_bytes_growth);
164 return context.Pass(); 165 return context.Pass();
165 } 166 }
166 167
167 scoped_ptr<FileSystemOperationContext> UnlimitedContext() { 168 scoped_ptr<FileSystemOperationContext> UnlimitedContext() {
168 return LimitedContext(kint64max); 169 return LimitedContext(kint64max);
169 } 170 }
170 171
171 FileSystemOperationContext* NewContext( 172 FileSystemOperationContext* NewContext(
172 LocalFileSystemTestOriginHelper* helper) { 173 SandboxFileSystemTestHelper* file_system) {
173 change_observer()->ResetCount(); 174 change_observer()->ResetCount();
174 FileSystemOperationContext* context; 175 FileSystemOperationContext* context;
175 if (helper) 176 if (file_system)
176 context = helper->NewOperationContext(); 177 context = file_system->NewOperationContext();
177 else 178 else
178 context = test_helper_.NewOperationContext(); 179 context = sandbox_file_system_.NewOperationContext();
179 // Setting allowed_bytes_growth big enough for all tests. 180 // Setting allowed_bytes_growth big enough for all tests.
180 context->set_allowed_bytes_growth(1024 * 1024); 181 context->set_allowed_bytes_growth(1024 * 1024);
181 context->set_change_observers(change_observers()); 182 context->set_change_observers(change_observers());
182 return context; 183 return context;
183 } 184 }
184 185
185 const ChangeObserverList& change_observers() const { 186 const ChangeObserverList& change_observers() const {
186 return change_observers_; 187 return change_observers_;
187 } 188 }
188 189
189 MockFileChangeObserver* change_observer() { 190 MockFileChangeObserver* change_observer() {
190 return &change_observer_; 191 return &change_observer_;
191 } 192 }
192 193
193 // This can only be used after SetUp has run and created file_system_context_ 194 // This can only be used after SetUp has run and created file_system_context_
194 // and obfuscated_file_util_. 195 // and obfuscated_file_util_.
195 // Use this for tests which need to run in multiple origins; we need a test 196 // Use this for tests which need to run in multiple origins; we need a test
196 // helper per origin. 197 // helper per origin.
197 LocalFileSystemTestOriginHelper* NewHelper( 198 SandboxFileSystemTestHelper* NewFileSystem(
198 const GURL& origin, fileapi::FileSystemType type) { 199 const GURL& origin, fileapi::FileSystemType type) {
199 LocalFileSystemTestOriginHelper* helper = 200 SandboxFileSystemTestHelper* file_system =
200 new LocalFileSystemTestOriginHelper(origin, type); 201 new SandboxFileSystemTestHelper(origin, type);
201 202
202 helper->SetUp(file_system_context_.get()); 203 file_system->SetUp(file_system_context_.get());
203 return helper; 204 return file_system;
204 } 205 }
205 206
206 ObfuscatedFileUtil* ofu() { 207 ObfuscatedFileUtil* ofu() {
207 return static_cast<ObfuscatedFileUtil*>(test_helper_.file_util()); 208 return static_cast<ObfuscatedFileUtil*>(sandbox_file_system_.file_util());
208 } 209 }
209 210
210 const base::FilePath& test_directory() const { 211 const base::FilePath& test_directory() const {
211 return data_dir_.path(); 212 return data_dir_.path();
212 } 213 }
213 214
214 const GURL& origin() const { 215 const GURL& origin() const {
215 return origin_; 216 return origin_;
216 } 217 }
217 218
218 fileapi::FileSystemType type() const { 219 fileapi::FileSystemType type() const {
219 return type_; 220 return type_;
220 } 221 }
221 222
222 int64 ComputeTotalFileSize() { 223 int64 ComputeTotalFileSize() {
223 return test_helper_.ComputeCurrentOriginUsage() - 224 return sandbox_file_system_.ComputeCurrentOriginUsage() -
224 test_helper_.ComputeCurrentDirectoryDatabaseUsage(); 225 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage();
225 } 226 }
226 227
227 void GetUsageFromQuotaManager() { 228 void GetUsageFromQuotaManager() {
228 int64 quota = -1; 229 int64 quota = -1;
229 quota_status_ = AsyncFileTestHelper::GetUsageAndQuota( 230 quota_status_ = AsyncFileTestHelper::GetUsageAndQuota(
230 quota_manager_, origin(), test_helper_.type(), 231 quota_manager_, origin(), sandbox_file_system_.type(),
231 &usage_, &quota); 232 &usage_, &quota);
232 EXPECT_EQ(quota::kQuotaStatusOk, quota_status_); 233 EXPECT_EQ(quota::kQuotaStatusOk, quota_status_);
233 } 234 }
234 235
235 void RevokeUsageCache() { 236 void RevokeUsageCache() {
236 quota_manager_->ResetUsageTracker(test_helper_.storage_type()); 237 quota_manager_->ResetUsageTracker(sandbox_file_system_.storage_type());
237 usage_cache()->Delete(test_helper_.GetUsageCachePath()); 238 usage_cache()->Delete(sandbox_file_system_.GetUsageCachePath());
238 } 239 }
239 240
240 int64 SizeByQuotaUtil() { 241 int64 SizeByQuotaUtil() {
241 return test_helper_.GetCachedOriginUsage(); 242 return sandbox_file_system_.GetCachedOriginUsage();
242 } 243 }
243 244
244 int64 SizeInUsageFile() { 245 int64 SizeInUsageFile() {
245 base::MessageLoop::current()->RunUntilIdle(); 246 base::MessageLoop::current()->RunUntilIdle();
246 int64 usage = 0; 247 int64 usage = 0;
247 return usage_cache()->GetUsage(test_helper_.GetUsageCachePath(), &usage) ? 248 return usage_cache()->GetUsage(
248 usage : -1; 249 sandbox_file_system_.GetUsageCachePath(), &usage) ? usage : -1;
249 } 250 }
250 251
251 bool PathExists(const FileSystemURL& url) { 252 bool PathExists(const FileSystemURL& url) {
252 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 253 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
253 base::PlatformFileInfo file_info; 254 base::PlatformFileInfo file_info;
254 base::FilePath platform_path; 255 base::FilePath platform_path;
255 base::PlatformFileError error = ofu()->GetFileInfo( 256 base::PlatformFileError error = ofu()->GetFileInfo(
256 context.get(), url, &file_info, &platform_path); 257 context.get(), url, &file_info, &platform_path);
257 return error == base::PLATFORM_FILE_OK; 258 return error == base::PLATFORM_FILE_OK;
258 } 259 }
259 260
260 bool DirectoryExists(const FileSystemURL& url) { 261 bool DirectoryExists(const FileSystemURL& url) {
261 return AsyncFileTestHelper::DirectoryExists(file_system_context(), url); 262 return AsyncFileTestHelper::DirectoryExists(file_system_context(), url);
262 } 263 }
263 264
264 int64 usage() const { return usage_; } 265 int64 usage() const { return usage_; }
265 FileSystemUsageCache* usage_cache() { 266 FileSystemUsageCache* usage_cache() {
266 return test_helper_.usage_cache(); 267 return sandbox_file_system_.usage_cache();
267 } 268 }
268 269
269 FileSystemURL CreateURLFromUTF8(const std::string& path) { 270 FileSystemURL CreateURLFromUTF8(const std::string& path) {
270 return test_helper_.CreateURLFromUTF8(path); 271 return sandbox_file_system_.CreateURLFromUTF8(path);
271 } 272 }
272 273
273 int64 PathCost(const FileSystemURL& url) { 274 int64 PathCost(const FileSystemURL& url) {
274 return ObfuscatedFileUtil::ComputeFilePathCost(url.path()); 275 return ObfuscatedFileUtil::ComputeFilePathCost(url.path());
275 } 276 }
276 277
277 FileSystemURL CreateURL(const base::FilePath& path) { 278 FileSystemURL CreateURL(const base::FilePath& path) {
278 return test_helper_.CreateURL(path); 279 return sandbox_file_system_.CreateURL(path);
279 } 280 }
280 281
281 void CheckFileAndCloseHandle( 282 void CheckFileAndCloseHandle(
282 const FileSystemURL& url, base::PlatformFile file_handle) { 283 const FileSystemURL& url, base::PlatformFile file_handle) {
283 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL)); 284 scoped_ptr<FileSystemOperationContext> context(NewContext(NULL));
284 base::FilePath local_path; 285 base::FilePath local_path;
285 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath( 286 EXPECT_EQ(base::PLATFORM_FILE_OK, ofu()->GetLocalFilePath(
286 context.get(), url, &local_path)); 287 context.get(), url, &local_path));
287 288
288 base::PlatformFileInfo file_info0; 289 base::PlatformFileInfo file_info0;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 for (iter = directories.begin(); iter != directories.end(); ++iter) { 356 for (iter = directories.begin(); iter != directories.end(); ++iter) {
356 context.reset(NewContext(NULL)); 357 context.reset(NewContext(NULL));
357 EXPECT_TRUE(DirectoryExists( 358 EXPECT_TRUE(DirectoryExists(
358 FileSystemURLAppend(root_url, *iter))); 359 FileSystemURLAppend(root_url, *iter)));
359 } 360 }
360 } 361 }
361 362
362 class UsageVerifyHelper { 363 class UsageVerifyHelper {
363 public: 364 public:
364 UsageVerifyHelper(scoped_ptr<FileSystemOperationContext> context, 365 UsageVerifyHelper(scoped_ptr<FileSystemOperationContext> context,
365 LocalFileSystemTestOriginHelper* test_helper, 366 SandboxFileSystemTestHelper* file_system,
366 int64 expected_usage) 367 int64 expected_usage)
367 : context_(context.Pass()), 368 : context_(context.Pass()),
368 test_helper_(test_helper), 369 sandbox_file_system_(file_system),
369 expected_usage_(expected_usage) {} 370 expected_usage_(expected_usage) {}
370 371
371 ~UsageVerifyHelper() { 372 ~UsageVerifyHelper() {
372 base::MessageLoop::current()->RunUntilIdle(); 373 base::MessageLoop::current()->RunUntilIdle();
373 Check(); 374 Check();
374 } 375 }
375 376
376 FileSystemOperationContext* context() { 377 FileSystemOperationContext* context() {
377 return context_.get(); 378 return context_.get();
378 } 379 }
379 380
380 private: 381 private:
381 void Check() { 382 void Check() {
382 ASSERT_EQ(expected_usage_, 383 ASSERT_EQ(expected_usage_,
383 test_helper_->GetCachedOriginUsage()); 384 sandbox_file_system_->GetCachedOriginUsage());
384 } 385 }
385 386
386 scoped_ptr<FileSystemOperationContext> context_; 387 scoped_ptr<FileSystemOperationContext> context_;
387 LocalFileSystemTestOriginHelper* test_helper_; 388 SandboxFileSystemTestHelper* sandbox_file_system_;
388 int64 expected_usage_; 389 int64 expected_usage_;
389 }; 390 };
390 391
391 scoped_ptr<UsageVerifyHelper> AllowUsageIncrease(int64 requested_growth) { 392 scoped_ptr<UsageVerifyHelper> AllowUsageIncrease(int64 requested_growth) {
392 int64 usage = test_helper_.GetCachedOriginUsage(); 393 int64 usage = sandbox_file_system_.GetCachedOriginUsage();
393 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper( 394 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper(
394 LimitedContext(requested_growth), 395 LimitedContext(requested_growth),
395 &test_helper_, usage + requested_growth)); 396 &sandbox_file_system_, usage + requested_growth));
396 } 397 }
397 398
398 scoped_ptr<UsageVerifyHelper> DisallowUsageIncrease(int64 requested_growth) { 399 scoped_ptr<UsageVerifyHelper> DisallowUsageIncrease(int64 requested_growth) {
399 int64 usage = test_helper_.GetCachedOriginUsage(); 400 int64 usage = sandbox_file_system_.GetCachedOriginUsage();
400 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper( 401 return scoped_ptr<UsageVerifyHelper>(new UsageVerifyHelper(
401 LimitedContext(requested_growth - 1), &test_helper_, usage)); 402 LimitedContext(requested_growth - 1), &sandbox_file_system_, usage));
402 } 403 }
403 404
404 void FillTestDirectory( 405 void FillTestDirectory(
405 const FileSystemURL& root_url, 406 const FileSystemURL& root_url,
406 std::set<base::FilePath::StringType>* files, 407 std::set<base::FilePath::StringType>* files,
407 std::set<base::FilePath::StringType>* directories) { 408 std::set<base::FilePath::StringType>* directories) {
408 scoped_ptr<FileSystemOperationContext> context; 409 scoped_ptr<FileSystemOperationContext> context;
409 std::vector<DirectoryEntry> entries; 410 std::vector<DirectoryEntry> entries;
410 EXPECT_EQ(base::PLATFORM_FILE_OK, 411 EXPECT_EQ(base::PLATFORM_FILE_OK,
411 AsyncFileTestHelper::ReadDirectory( 412 AsyncFileTestHelper::ReadDirectory(
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 src_file_url, dest_file_url, 635 src_file_url, dest_file_url,
635 copy)); 636 copy));
636 if (copy) 637 if (copy)
637 EXPECT_EQ(base::Time(), GetModifiedTime(src_dir_url)); 638 EXPECT_EQ(base::Time(), GetModifiedTime(src_dir_url));
638 else 639 else
639 EXPECT_NE(base::Time(), GetModifiedTime(src_dir_url)); 640 EXPECT_NE(base::Time(), GetModifiedTime(src_dir_url));
640 EXPECT_NE(base::Time(), GetModifiedTime(dest_dir_url)); 641 EXPECT_NE(base::Time(), GetModifiedTime(dest_dir_url));
641 } 642 }
642 643
643 int64 ComputeCurrentUsage() { 644 int64 ComputeCurrentUsage() {
644 return test_helper_.ComputeCurrentOriginUsage() - 645 return sandbox_file_system_.ComputeCurrentOriginUsage() -
645 test_helper_.ComputeCurrentDirectoryDatabaseUsage(); 646 sandbox_file_system_.ComputeCurrentDirectoryDatabaseUsage();
646 }
647
648 const LocalFileSystemTestOriginHelper& test_helper() const {
649 return test_helper_;
650 } 647 }
651 648
652 FileSystemContext* file_system_context() { 649 FileSystemContext* file_system_context() {
653 return test_helper_.file_system_context(); 650 return sandbox_file_system_.file_system_context();
654 } 651 }
655 652
656 private: 653 private:
657 base::ScopedTempDir data_dir_; 654 base::ScopedTempDir data_dir_;
658 base::MessageLoop message_loop_; 655 base::MessageLoop message_loop_;
659 scoped_refptr<quota::QuotaManager> quota_manager_; 656 scoped_refptr<quota::QuotaManager> quota_manager_;
660 scoped_refptr<FileSystemContext> file_system_context_; 657 scoped_refptr<FileSystemContext> file_system_context_;
661 GURL origin_; 658 GURL origin_;
662 fileapi::FileSystemType type_; 659 fileapi::FileSystemType type_;
663 base::WeakPtrFactory<ObfuscatedFileUtilTest> weak_factory_; 660 base::WeakPtrFactory<ObfuscatedFileUtilTest> weak_factory_;
664 LocalFileSystemTestOriginHelper test_helper_; 661 SandboxFileSystemTestHelper sandbox_file_system_;
665 quota::QuotaStatusCode quota_status_; 662 quota::QuotaStatusCode quota_status_;
666 int64 usage_; 663 int64 usage_;
667 MockFileChangeObserver change_observer_; 664 MockFileChangeObserver change_observer_;
668 ChangeObserverList change_observers_; 665 ChangeObserverList change_observers_;
669 666
670 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilTest); 667 DISALLOW_COPY_AND_ASSIGN(ObfuscatedFileUtilTest);
671 }; 668 };
672 669
673 TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) { 670 TEST_F(ObfuscatedFileUtilTest, TestCreateAndDeleteFile) {
674 base::PlatformFile file_handle = base::kInvalidPlatformFileValue; 671 base::PlatformFile file_handle = base::kInvalidPlatformFileValue;
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 1406
1410 std::set<base::FilePath::StringType> files; 1407 std::set<base::FilePath::StringType> files;
1411 std::set<base::FilePath::StringType> directories; 1408 std::set<base::FilePath::StringType> directories;
1412 FillTestDirectory(src_url, &files, &directories); 1409 FillTestDirectory(src_url, &files, &directories);
1413 1410
1414 FileSystemURL dest_url = CreateURLFromUTF8("destination dir"); 1411 FileSystemURL dest_url = CreateURLFromUTF8("destination dir");
1415 1412
1416 EXPECT_FALSE(DirectoryExists(dest_url)); 1413 EXPECT_FALSE(DirectoryExists(dest_url));
1417 ASSERT_EQ(base::PLATFORM_FILE_OK, 1414 ASSERT_EQ(base::PLATFORM_FILE_OK,
1418 AsyncFileTestHelper::Copy( 1415 AsyncFileTestHelper::Copy(
1419 test_helper().file_system_context(), src_url, dest_url)); 1416 file_system_context(), src_url, dest_url));
1420 1417
1421 ValidateTestDirectory(dest_url, files, directories); 1418 ValidateTestDirectory(dest_url, files, directories);
1422 EXPECT_TRUE(DirectoryExists(src_url)); 1419 EXPECT_TRUE(DirectoryExists(src_url));
1423 EXPECT_TRUE(DirectoryExists(dest_url)); 1420 EXPECT_TRUE(DirectoryExists(dest_url));
1424 recursive = true; 1421 recursive = true;
1425 ASSERT_EQ(base::PLATFORM_FILE_OK, 1422 ASSERT_EQ(base::PLATFORM_FILE_OK,
1426 AsyncFileTestHelper::Remove( 1423 AsyncFileTestHelper::Remove(
1427 file_system_context(), dest_url, recursive)); 1424 file_system_context(), dest_url, recursive));
1428 EXPECT_FALSE(DirectoryExists(dest_url)); 1425 EXPECT_FALSE(DirectoryExists(dest_url));
1429 } 1426 }
(...skipping 15 matching lines...) Expand all
1445 origins_expected.insert(origin()); 1442 origins_expected.insert(origin());
1446 1443
1447 for (size_t i = 0; i < arraysize(kOriginEnumerationTestRecords); ++i) { 1444 for (size_t i = 0; i < arraysize(kOriginEnumerationTestRecords); ++i) {
1448 SCOPED_TRACE(testing::Message() << 1445 SCOPED_TRACE(testing::Message() <<
1449 "Validating kOriginEnumerationTestRecords " << i); 1446 "Validating kOriginEnumerationTestRecords " << i);
1450 const OriginEnumerationTestRecord& record = 1447 const OriginEnumerationTestRecord& record =
1451 kOriginEnumerationTestRecords[i]; 1448 kOriginEnumerationTestRecords[i];
1452 GURL origin_url(record.origin_url); 1449 GURL origin_url(record.origin_url);
1453 origins_expected.insert(origin_url); 1450 origins_expected.insert(origin_url);
1454 if (record.has_temporary) { 1451 if (record.has_temporary) {
1455 scoped_ptr<LocalFileSystemTestOriginHelper> helper( 1452 scoped_ptr<SandboxFileSystemTestHelper> file_system(
1456 NewHelper(origin_url, kFileSystemTypeTemporary)); 1453 NewFileSystem(origin_url, kFileSystemTypeTemporary));
1457 scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get())); 1454 scoped_ptr<FileSystemOperationContext> context(
1455 NewContext(file_system.get()));
1458 bool created = false; 1456 bool created = false;
1459 ASSERT_EQ(base::PLATFORM_FILE_OK, 1457 ASSERT_EQ(base::PLATFORM_FILE_OK,
1460 ofu()->EnsureFileExists( 1458 ofu()->EnsureFileExists(
1461 context.get(), 1459 context.get(),
1462 helper->CreateURLFromUTF8("file"), 1460 file_system->CreateURLFromUTF8("file"),
1463 &created)); 1461 &created));
1464 EXPECT_TRUE(created); 1462 EXPECT_TRUE(created);
1465 } 1463 }
1466 if (record.has_persistent) { 1464 if (record.has_persistent) {
1467 scoped_ptr<LocalFileSystemTestOriginHelper> helper( 1465 scoped_ptr<SandboxFileSystemTestHelper> file_system(
1468 NewHelper(origin_url, kFileSystemTypePersistent)); 1466 NewFileSystem(origin_url, kFileSystemTypePersistent));
1469 scoped_ptr<FileSystemOperationContext> context(NewContext(helper.get())); 1467 scoped_ptr<FileSystemOperationContext> context(
1468 NewContext(file_system.get()));
1470 bool created = false; 1469 bool created = false;
1471 ASSERT_EQ(base::PLATFORM_FILE_OK, 1470 ASSERT_EQ(base::PLATFORM_FILE_OK,
1472 ofu()->EnsureFileExists( 1471 ofu()->EnsureFileExists(
1473 context.get(), 1472 context.get(),
1474 helper->CreateURLFromUTF8("file"), 1473 file_system->CreateURLFromUTF8("file"),
1475 &created)); 1474 &created));
1476 EXPECT_TRUE(created); 1475 EXPECT_TRUE(created);
1477 } 1476 }
1478 } 1477 }
1479 enumerator.reset(ofu()->CreateOriginEnumerator()); 1478 enumerator.reset(ofu()->CreateOriginEnumerator());
1480 EXPECT_TRUE(enumerator.get()); 1479 EXPECT_TRUE(enumerator.get());
1481 std::set<GURL> origins_found; 1480 std::set<GURL> origins_found;
1482 GURL origin_url; 1481 GURL origin_url;
1483 while (!(origin_url = enumerator->Next()).is_empty()) { 1482 while (!(origin_url = enumerator->Next()).is_empty()) {
1484 origins_found.insert(origin_url); 1483 origins_found.insert(origin_url);
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
2244 ASSERT_EQ(base::PLATFORM_FILE_OK, 2243 ASSERT_EQ(base::PLATFORM_FILE_OK,
2245 ofu()->CreateOrOpen( 2244 ofu()->CreateOrOpen(
2246 AllowUsageIncrease(-length)->context(), file, 2245 AllowUsageIncrease(-length)->context(), file,
2247 base::PLATFORM_FILE_OPEN_TRUNCATED | base::PLATFORM_FILE_WRITE, 2246 base::PLATFORM_FILE_OPEN_TRUNCATED | base::PLATFORM_FILE_WRITE,
2248 &file_handle, &created)); 2247 &file_handle, &created));
2249 ASSERT_EQ(0, ComputeTotalFileSize()); 2248 ASSERT_EQ(0, ComputeTotalFileSize());
2250 EXPECT_TRUE(base::ClosePlatformFile(file_handle)); 2249 EXPECT_TRUE(base::ClosePlatformFile(file_handle));
2251 } 2250 }
2252 2251
2253 } // namespace fileapi 2252 } // namespace fileapi
OLDNEW
« no previous file with comments | « content/content_tests.gypi ('k') | webkit/browser/fileapi/sandbox_mount_point_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698