OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "net/disk_cache/blockfile/file_block.h" | 8 #include "net/disk_cache/blockfile/file_block.h" |
9 #include "net/disk_cache/blockfile/mapped_file.h" | 9 #include "net/disk_cache/blockfile/mapped_file.h" |
10 #include "net/disk_cache/disk_cache_test_base.h" | 10 #include "net/disk_cache/disk_cache_test_base.h" |
11 #include "net/disk_cache/disk_cache_test_util.h" | 11 #include "net/disk_cache/disk_cache_test_util.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Implementation of FileIOCallback for the tests. | 16 // Implementation of FileIOCallback for the tests. |
17 class FileCallbackTest: public disk_cache::FileIOCallback { | 17 class FileCallbackTest: public disk_cache::FileIOCallback { |
18 public: | 18 public: |
19 FileCallbackTest(int id, MessageLoopHelper* helper, int* max_id) | 19 FileCallbackTest(int id, MessageLoopHelper* helper, int* max_id) |
20 : id_(id), | 20 : id_(id), |
21 helper_(helper), | 21 helper_(helper), |
22 max_id_(max_id) { | 22 max_id_(max_id) { |
23 } | 23 } |
24 virtual ~FileCallbackTest() {} | 24 ~FileCallbackTest() override {} |
25 | 25 |
26 virtual void OnFileIOComplete(int bytes_copied) override; | 26 void OnFileIOComplete(int bytes_copied) override; |
27 | 27 |
28 private: | 28 private: |
29 int id_; | 29 int id_; |
30 MessageLoopHelper* helper_; | 30 MessageLoopHelper* helper_; |
31 int* max_id_; | 31 int* max_id_; |
32 }; | 32 }; |
33 | 33 |
34 void FileCallbackTest::OnFileIOComplete(int bytes_copied) { | 34 void FileCallbackTest::OnFileIOComplete(int bytes_copied) { |
35 if (id_ > *max_id_) { | 35 if (id_ > *max_id_) { |
36 NOTREACHED(); | 36 NOTREACHED(); |
37 helper_->set_callback_reused_error(true); | 37 helper_->set_callback_reused_error(true); |
38 } | 38 } |
39 | 39 |
40 helper_->CallbackWasCalled(); | 40 helper_->CallbackWasCalled(); |
41 } | 41 } |
42 | 42 |
43 class TestFileBlock : public disk_cache::FileBlock { | 43 class TestFileBlock : public disk_cache::FileBlock { |
44 public: | 44 public: |
45 TestFileBlock() { | 45 TestFileBlock() { |
46 CacheTestFillBuffer(buffer_, sizeof(buffer_), false); | 46 CacheTestFillBuffer(buffer_, sizeof(buffer_), false); |
47 } | 47 } |
48 virtual ~TestFileBlock() {} | 48 ~TestFileBlock() override {} |
49 | 49 |
50 // FileBlock interface. | 50 // FileBlock interface. |
51 virtual void* buffer() const override { return const_cast<char*>(buffer_); } | 51 void* buffer() const override { return const_cast<char*>(buffer_); } |
52 virtual size_t size() const override { return sizeof(buffer_); } | 52 size_t size() const override { return sizeof(buffer_); } |
53 virtual int offset() const override { return 1024; } | 53 int offset() const override { return 1024; } |
54 | 54 |
55 private: | 55 private: |
56 char buffer_[20]; | 56 char buffer_[20]; |
57 }; | 57 }; |
58 | 58 |
59 } // namespace | 59 } // namespace |
60 | 60 |
61 TEST_F(DiskCacheTest, MappedFile_SyncIO) { | 61 TEST_F(DiskCacheTest, MappedFile_SyncIO) { |
62 base::FilePath filename = cache_path_.AppendASCII("a_test"); | 62 base::FilePath filename = cache_path_.AppendASCII("a_test"); |
63 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); | 63 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 if (!completed) | 132 if (!completed) |
133 expected++; | 133 expected++; |
134 | 134 |
135 helper.WaitUntilCacheIoFinished(expected); | 135 helper.WaitUntilCacheIoFinished(expected); |
136 | 136 |
137 EXPECT_EQ(expected, helper.callbacks_called()); | 137 EXPECT_EQ(expected, helper.callbacks_called()); |
138 EXPECT_FALSE(helper.callback_reused_error()); | 138 EXPECT_FALSE(helper.callback_reused_error()); |
139 EXPECT_STREQ(static_cast<char*>(file_block1.buffer()), | 139 EXPECT_STREQ(static_cast<char*>(file_block1.buffer()), |
140 static_cast<char*>(file_block2.buffer())); | 140 static_cast<char*>(file_block2.buffer())); |
141 } | 141 } |
OLD | NEW |