OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 void FlushCacheTasks() { | 37 void FlushCacheTasks() { |
38 base::RunLoop().RunUntilIdle(); | 38 base::RunLoop().RunUntilIdle(); |
39 } | 39 } |
40 | 40 |
41 void OnComplete(int err) { | 41 void OnComplete(int err) { |
42 completion_results_.push_back(err); | 42 completion_results_.push_back(err); |
43 } | 43 } |
44 | 44 |
45 base::ScopedTempDir directory_; | 45 base::ScopedTempDir directory_; |
46 scoped_ptr<base::MessageLoop> message_loop_; | 46 std::unique_ptr<base::MessageLoop> message_loop_; |
47 scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; | 47 scoped_refptr<base::SingleThreadTaskRunner> cache_thread_; |
48 net::CompletionCallback completion_callback_; | 48 net::CompletionCallback completion_callback_; |
49 std::vector<int> completion_results_; | 49 std::vector<int> completion_results_; |
50 | 50 |
51 static const int k10MBytes = 10 * 1024 * 1024; | 51 static const int k10MBytes = 10 * 1024 * 1024; |
52 }; | 52 }; |
53 | 53 |
54 TEST_F(AppCacheDiskCacheTest, DisablePriorToInitCompletion) { | 54 TEST_F(AppCacheDiskCacheTest, DisablePriorToInitCompletion) { |
55 AppCacheDiskCache::Entry* entry = NULL; | 55 AppCacheDiskCache::Entry* entry = NULL; |
56 | 56 |
57 // Create an instance and start it initializing, queue up | 57 // Create an instance and start it initializing, queue up |
58 // one of each kind of "entry" function. | 58 // one of each kind of "entry" function. |
59 scoped_ptr<AppCacheDiskCache> disk_cache(new AppCacheDiskCache); | 59 std::unique_ptr<AppCacheDiskCache> disk_cache(new AppCacheDiskCache); |
60 EXPECT_FALSE(disk_cache->is_disabled()); | 60 EXPECT_FALSE(disk_cache->is_disabled()); |
61 disk_cache->InitWithDiskBackend( | 61 disk_cache->InitWithDiskBackend( |
62 directory_.path(), k10MBytes, false, cache_thread_, completion_callback_); | 62 directory_.path(), k10MBytes, false, cache_thread_, completion_callback_); |
63 disk_cache->CreateEntry(1, &entry, completion_callback_); | 63 disk_cache->CreateEntry(1, &entry, completion_callback_); |
64 disk_cache->OpenEntry(2, &entry, completion_callback_); | 64 disk_cache->OpenEntry(2, &entry, completion_callback_); |
65 disk_cache->DoomEntry(3, completion_callback_); | 65 disk_cache->DoomEntry(3, completion_callback_); |
66 | 66 |
67 // Pull the plug on all that. | 67 // Pull the plug on all that. |
68 EXPECT_FALSE(disk_cache->is_disabled()); | 68 EXPECT_FALSE(disk_cache->is_disabled()); |
69 disk_cache->Disable(); | 69 disk_cache->Disable(); |
(...skipping 10 matching lines...) Expand all Loading... |
80 | 80 |
81 // Ensure the directory can be deleted at this point. | 81 // Ensure the directory can be deleted at this point. |
82 EXPECT_TRUE(base::DirectoryExists(directory_.path())); | 82 EXPECT_TRUE(base::DirectoryExists(directory_.path())); |
83 EXPECT_FALSE(base::IsDirectoryEmpty(directory_.path())); | 83 EXPECT_FALSE(base::IsDirectoryEmpty(directory_.path())); |
84 EXPECT_TRUE(base::DeleteFile(directory_.path(), true)); | 84 EXPECT_TRUE(base::DeleteFile(directory_.path(), true)); |
85 EXPECT_FALSE(base::DirectoryExists(directory_.path())); | 85 EXPECT_FALSE(base::DirectoryExists(directory_.path())); |
86 } | 86 } |
87 | 87 |
88 TEST_F(AppCacheDiskCacheTest, DisableAfterInitted) { | 88 TEST_F(AppCacheDiskCacheTest, DisableAfterInitted) { |
89 // Create an instance and let it fully init. | 89 // Create an instance and let it fully init. |
90 scoped_ptr<AppCacheDiskCache> disk_cache(new AppCacheDiskCache); | 90 std::unique_ptr<AppCacheDiskCache> disk_cache(new AppCacheDiskCache); |
91 EXPECT_FALSE(disk_cache->is_disabled()); | 91 EXPECT_FALSE(disk_cache->is_disabled()); |
92 disk_cache->InitWithDiskBackend( | 92 disk_cache->InitWithDiskBackend( |
93 directory_.path(), k10MBytes, false, cache_thread_, completion_callback_); | 93 directory_.path(), k10MBytes, false, cache_thread_, completion_callback_); |
94 FlushCacheTasks(); | 94 FlushCacheTasks(); |
95 EXPECT_EQ(1u, completion_results_.size()); | 95 EXPECT_EQ(1u, completion_results_.size()); |
96 EXPECT_EQ(net::OK, completion_results_[0]); | 96 EXPECT_EQ(net::OK, completion_results_[0]); |
97 | 97 |
98 // Pull the plug | 98 // Pull the plug |
99 disk_cache->Disable(); | 99 disk_cache->Disable(); |
100 FlushCacheTasks(); | 100 FlushCacheTasks(); |
(...skipping 14 matching lines...) Expand all Loading... |
115 disk_cache->OpenEntry(2, &entry, completion_callback_)); | 115 disk_cache->OpenEntry(2, &entry, completion_callback_)); |
116 EXPECT_EQ(net::ERR_ABORTED, | 116 EXPECT_EQ(net::ERR_ABORTED, |
117 disk_cache->DoomEntry(3, completion_callback_)); | 117 disk_cache->DoomEntry(3, completion_callback_)); |
118 FlushCacheTasks(); | 118 FlushCacheTasks(); |
119 EXPECT_TRUE(completion_results_.empty()); | 119 EXPECT_TRUE(completion_results_.empty()); |
120 } | 120 } |
121 | 121 |
122 // Flaky on Android: http://crbug.com/339534 | 122 // Flaky on Android: http://crbug.com/339534 |
123 TEST_F(AppCacheDiskCacheTest, DISABLED_DisableWithEntriesOpen) { | 123 TEST_F(AppCacheDiskCacheTest, DISABLED_DisableWithEntriesOpen) { |
124 // Create an instance and let it fully init. | 124 // Create an instance and let it fully init. |
125 scoped_ptr<AppCacheDiskCache> disk_cache(new AppCacheDiskCache); | 125 std::unique_ptr<AppCacheDiskCache> disk_cache(new AppCacheDiskCache); |
126 EXPECT_FALSE(disk_cache->is_disabled()); | 126 EXPECT_FALSE(disk_cache->is_disabled()); |
127 disk_cache->InitWithDiskBackend( | 127 disk_cache->InitWithDiskBackend( |
128 directory_.path(), k10MBytes, false, cache_thread_, completion_callback_); | 128 directory_.path(), k10MBytes, false, cache_thread_, completion_callback_); |
129 FlushCacheTasks(); | 129 FlushCacheTasks(); |
130 EXPECT_EQ(1u, completion_results_.size()); | 130 EXPECT_EQ(1u, completion_results_.size()); |
131 EXPECT_EQ(net::OK, completion_results_[0]); | 131 EXPECT_EQ(net::OK, completion_results_[0]); |
132 | 132 |
133 // Note: We don't have detailed expectations of the DiskCache | 133 // Note: We don't have detailed expectations of the DiskCache |
134 // operations because on android it's really SimpleCache which | 134 // operations because on android it's really SimpleCache which |
135 // does behave differently. | 135 // does behave differently. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 EXPECT_EQ( | 175 EXPECT_EQ( |
176 net::ERR_ABORTED, | 176 net::ERR_ABORTED, |
177 entry1->Read(0, 0, read_buf.get(), kDataLen, completion_callback_)); | 177 entry1->Read(0, 0, read_buf.get(), kDataLen, completion_callback_)); |
178 entry1->Close(); | 178 entry1->Close(); |
179 entry2->Close(); | 179 entry2->Close(); |
180 | 180 |
181 FlushCacheTasks(); | 181 FlushCacheTasks(); |
182 } | 182 } |
183 | 183 |
184 } // namespace content | 184 } // namespace content |
OLD | NEW |