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

Side by Side Diff: net/disk_cache/backend_unittest.cc

Issue 184563006: Move WriteFile and WriteFileDescriptor from file_util to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 (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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/metrics/field_trial.h" 7 #include "base/metrics/field_trial.h"
8 #include "base/port.h" 8 #include "base/port.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 } 475 }
476 476
477 TEST_F(DiskCacheBackendTest, ExternalFiles) { 477 TEST_F(DiskCacheBackendTest, ExternalFiles) {
478 InitCache(); 478 InitCache();
479 // First, let's create a file on the folder. 479 // First, let's create a file on the folder.
480 base::FilePath filename = cache_path_.AppendASCII("f_000001"); 480 base::FilePath filename = cache_path_.AppendASCII("f_000001");
481 481
482 const int kSize = 50; 482 const int kSize = 50;
483 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); 483 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize));
484 CacheTestFillBuffer(buffer1->data(), kSize, false); 484 CacheTestFillBuffer(buffer1->data(), kSize, false);
485 ASSERT_EQ(kSize, file_util::WriteFile(filename, buffer1->data(), kSize)); 485 ASSERT_EQ(kSize, base::WriteFile(filename, buffer1->data(), kSize));
486 486
487 // Now let's create a file with the cache. 487 // Now let's create a file with the cache.
488 disk_cache::Entry* entry; 488 disk_cache::Entry* entry;
489 ASSERT_EQ(net::OK, CreateEntry("key", &entry)); 489 ASSERT_EQ(net::OK, CreateEntry("key", &entry));
490 ASSERT_EQ(0, WriteData(entry, 0, 20000, buffer1.get(), 0, false)); 490 ASSERT_EQ(0, WriteData(entry, 0, 20000, buffer1.get(), 0, false));
491 entry->Close(); 491 entry->Close();
492 492
493 // And verify that the first file is still there. 493 // And verify that the first file is still there.
494 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize)); 494 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kSize));
495 ASSERT_EQ(kSize, base::ReadFile(filename, buffer2->data(), kSize)); 495 ASSERT_EQ(kSize, base::ReadFile(filename, buffer2->data(), kSize));
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 // The integrity test sets kNoRandom so there's a version mismatch if we don't 664 // The integrity test sets kNoRandom so there's a version mismatch if we don't
665 // force new eviction. 665 // force new eviction.
666 SetNewEviction(); 666 SetNewEviction();
667 BackendShutdownWithPendingCreate(true); 667 BackendShutdownWithPendingCreate(true);
668 } 668 }
669 #endif 669 #endif
670 670
671 TEST_F(DiskCacheTest, TruncatedIndex) { 671 TEST_F(DiskCacheTest, TruncatedIndex) {
672 ASSERT_TRUE(CleanupCacheDir()); 672 ASSERT_TRUE(CleanupCacheDir());
673 base::FilePath index = cache_path_.AppendASCII("index"); 673 base::FilePath index = cache_path_.AppendASCII("index");
674 ASSERT_EQ(5, file_util::WriteFile(index, "hello", 5)); 674 ASSERT_EQ(5, base::WriteFile(index, "hello", 5));
675 675
676 base::Thread cache_thread("CacheThread"); 676 base::Thread cache_thread("CacheThread");
677 ASSERT_TRUE(cache_thread.StartWithOptions( 677 ASSERT_TRUE(cache_thread.StartWithOptions(
678 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); 678 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
679 net::TestCompletionCallback cb; 679 net::TestCompletionCallback cb;
680 680
681 scoped_ptr<disk_cache::Backend> backend; 681 scoped_ptr<disk_cache::Backend> backend;
682 int rv = 682 int rv =
683 disk_cache::CreateCacheBackend(net::DISK_CACHE, 683 disk_cache::CreateCacheBackend(net::DISK_CACHE,
684 net::CACHE_BACKEND_BLOCKFILE, 684 net::CACHE_BACKEND_BLOCKFILE,
(...skipping 2625 matching lines...) Expand 10 before | Expand all | Expand 10 after
3310 entry = NULL; 3310 entry = NULL;
3311 3311
3312 // Write an invalid header for stream 0 and stream 1. 3312 // Write an invalid header for stream 0 and stream 1.
3313 base::FilePath entry_file1_path = cache_path_.AppendASCII( 3313 base::FilePath entry_file1_path = cache_path_.AppendASCII(
3314 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0)); 3314 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0));
3315 3315
3316 disk_cache::SimpleFileHeader header; 3316 disk_cache::SimpleFileHeader header;
3317 header.initial_magic_number = GG_UINT64_C(0xbadf00d); 3317 header.initial_magic_number = GG_UINT64_C(0xbadf00d);
3318 EXPECT_EQ( 3318 EXPECT_EQ(
3319 implicit_cast<int>(sizeof(header)), 3319 implicit_cast<int>(sizeof(header)),
3320 file_util::WriteFile(entry_file1_path, reinterpret_cast<char*>(&header), 3320 base::WriteFile(entry_file1_path, reinterpret_cast<char*>(&header),
3321 sizeof(header))); 3321 sizeof(header)));
3322 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry)); 3322 ASSERT_EQ(net::ERR_FAILED, OpenEntry(key, &entry));
3323 } 3323 }
3324 3324
3325 // Tests that the Simple Cache Backend fails to initialize with non-matching 3325 // Tests that the Simple Cache Backend fails to initialize with non-matching
3326 // file structure on disk. 3326 // file structure on disk.
3327 TEST_F(DiskCacheBackendTest, SimpleCacheOverBlockfileCache) { 3327 TEST_F(DiskCacheBackendTest, SimpleCacheOverBlockfileCache) {
3328 // Create a cache structure with the |BackendImpl|. 3328 // Create a cache structure with the |BackendImpl|.
3329 InitCache(); 3329 InitCache();
3330 disk_cache::Entry* entry; 3330 disk_cache::Entry* entry;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
3488 void* iter = NULL; 3488 void* iter = NULL;
3489 size_t count = 0; 3489 size_t count = 0;
3490 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count)); 3490 ASSERT_TRUE(EnumerateAndMatchKeys(-1, &iter, &keys_to_match, &count));
3491 cache_->EndEnumeration(&iter); 3491 cache_->EndEnumeration(&iter);
3492 3492
3493 EXPECT_EQ(key_pool.size(), count); 3493 EXPECT_EQ(key_pool.size(), count);
3494 EXPECT_TRUE(keys_to_match.empty()); 3494 EXPECT_TRUE(keys_to_match.empty());
3495 } 3495 }
3496 3496
3497 #endif // defined(OS_POSIX) 3497 #endif // defined(OS_POSIX)
OLDNEW
« no previous file with comments | « net/base/upload_file_element_reader_unittest.cc ('k') | net/disk_cache/blockfile/block_files_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698