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

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

Issue 2109503009: Refactor net tests to use GMock matchers for checking net::Error results (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert changes to contents.txt files Created 4 years, 5 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
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | net/disk_cache/entry_unittest.cc » ('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 "net/disk_cache/disk_cache_test_base.h" 5 #include "net/disk_cache/disk_cache_test_base.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "net/base/io_buffer.h" 15 #include "net/base/io_buffer.h"
16 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
17 #include "net/base/test_completion_callback.h" 17 #include "net/base/test_completion_callback.h"
18 #include "net/disk_cache/blockfile/backend_impl.h" 18 #include "net/disk_cache/blockfile/backend_impl.h"
19 #include "net/disk_cache/cache_util.h" 19 #include "net/disk_cache/cache_util.h"
20 #include "net/disk_cache/disk_cache.h" 20 #include "net/disk_cache/disk_cache.h"
21 #include "net/disk_cache/disk_cache_test_util.h" 21 #include "net/disk_cache/disk_cache_test_util.h"
22 #include "net/disk_cache/memory/mem_backend_impl.h" 22 #include "net/disk_cache/memory/mem_backend_impl.h"
23 #include "net/disk_cache/simple/simple_backend_impl.h" 23 #include "net/disk_cache/simple/simple_backend_impl.h"
24 #include "net/disk_cache/simple/simple_index.h" 24 #include "net/disk_cache/simple/simple_index.h"
25 #include "net/test/gtest_util.h"
26 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28
29 using net::test::IsOk;
25 30
26 DiskCacheTest::DiskCacheTest() { 31 DiskCacheTest::DiskCacheTest() {
27 CHECK(temp_dir_.CreateUniqueTempDir()); 32 CHECK(temp_dir_.CreateUniqueTempDir());
28 cache_path_ = temp_dir_.path(); 33 cache_path_ = temp_dir_.path();
29 if (!base::MessageLoop::current()) 34 if (!base::MessageLoop::current())
30 message_loop_.reset(new base::MessageLoopForIO()); 35 message_loop_.reset(new base::MessageLoopForIO());
31 } 36 }
32 37
33 DiskCacheTest::~DiskCacheTest() { 38 DiskCacheTest::~DiskCacheTest() {
34 } 39 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 ASSERT_TRUE(NULL != cache_); 101 ASSERT_TRUE(NULL != cache_);
97 if (first_cleanup_) 102 if (first_cleanup_)
98 ASSERT_EQ(0, cache_->GetEntryCount()); 103 ASSERT_EQ(0, cache_->GetEntryCount());
99 } 104 }
100 105
101 // We are expected to leak memory when simulating crashes. 106 // We are expected to leak memory when simulating crashes.
102 void DiskCacheTestWithCache::SimulateCrash() { 107 void DiskCacheTestWithCache::SimulateCrash() {
103 ASSERT_TRUE(!memory_only_); 108 ASSERT_TRUE(!memory_only_);
104 net::TestCompletionCallback cb; 109 net::TestCompletionCallback cb;
105 int rv = cache_impl_->FlushQueueForTest(cb.callback()); 110 int rv = cache_impl_->FlushQueueForTest(cb.callback());
106 ASSERT_EQ(net::OK, cb.GetResult(rv)); 111 ASSERT_THAT(cb.GetResult(rv), IsOk());
107 cache_impl_->ClearRefCountForTest(); 112 cache_impl_->ClearRefCountForTest();
108 113
109 cache_.reset(); 114 cache_.reset();
110 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_)); 115 EXPECT_TRUE(CheckCacheIntegrity(cache_path_, new_eviction_, mask_));
111 116
112 CreateBackend(disk_cache::kNoRandom, &cache_thread_); 117 CreateBackend(disk_cache::kNoRandom, &cache_thread_);
113 } 118 }
114 119
115 void DiskCacheTestWithCache::SetTestMode() { 120 void DiskCacheTestWithCache::SetTestMode() {
116 ASSERT_TRUE(!memory_only_); 121 ASSERT_TRUE(!memory_only_);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 return std::unique_ptr<TestIterator>( 184 return std::unique_ptr<TestIterator>(
180 new TestIterator(cache_->CreateIterator())); 185 new TestIterator(cache_->CreateIterator()));
181 } 186 }
182 187
183 void DiskCacheTestWithCache::FlushQueueForTest() { 188 void DiskCacheTestWithCache::FlushQueueForTest() {
184 if (memory_only_ || !cache_impl_) 189 if (memory_only_ || !cache_impl_)
185 return; 190 return;
186 191
187 net::TestCompletionCallback cb; 192 net::TestCompletionCallback cb;
188 int rv = cache_impl_->FlushQueueForTest(cb.callback()); 193 int rv = cache_impl_->FlushQueueForTest(cb.callback());
189 EXPECT_EQ(net::OK, cb.GetResult(rv)); 194 EXPECT_THAT(cb.GetResult(rv), IsOk());
190 } 195 }
191 196
192 void DiskCacheTestWithCache::RunTaskForTest(const base::Closure& closure) { 197 void DiskCacheTestWithCache::RunTaskForTest(const base::Closure& closure) {
193 if (memory_only_ || !cache_impl_) { 198 if (memory_only_ || !cache_impl_) {
194 closure.Run(); 199 closure.Run();
195 return; 200 return;
196 } 201 }
197 202
198 net::TestCompletionCallback cb; 203 net::TestCompletionCallback cb;
199 int rv = cache_impl_->RunTaskForTest(closure, cb.callback()); 204 int rv = cache_impl_->RunTaskForTest(closure, cb.callback());
200 EXPECT_EQ(net::OK, cb.GetResult(rv)); 205 EXPECT_THAT(cb.GetResult(rv), IsOk());
201 } 206 }
202 207
203 int DiskCacheTestWithCache::ReadData(disk_cache::Entry* entry, int index, 208 int DiskCacheTestWithCache::ReadData(disk_cache::Entry* entry, int index,
204 int offset, net::IOBuffer* buf, int len) { 209 int offset, net::IOBuffer* buf, int len) {
205 net::TestCompletionCallback cb; 210 net::TestCompletionCallback cb;
206 int rv = entry->ReadData(index, offset, buf, len, cb.callback()); 211 int rv = entry->ReadData(index, offset, buf, len, cb.callback());
207 return cb.GetResult(rv); 212 return cb.GetResult(rv);
208 } 213 }
209 214
210 int DiskCacheTestWithCache::WriteData(disk_cache::Entry* entry, int index, 215 int DiskCacheTestWithCache::WriteData(disk_cache::Entry* entry, int index,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 runner = base::ThreadTaskRunnerHandle::Get(); 315 runner = base::ThreadTaskRunnerHandle::Get();
311 else 316 else
312 runner = thread->task_runner(); 317 runner = thread->task_runner();
313 318
314 if (simple_cache_mode_) { 319 if (simple_cache_mode_) {
315 net::TestCompletionCallback cb; 320 net::TestCompletionCallback cb;
316 std::unique_ptr<disk_cache::SimpleBackendImpl> simple_backend( 321 std::unique_ptr<disk_cache::SimpleBackendImpl> simple_backend(
317 new disk_cache::SimpleBackendImpl(cache_path_, size_, type_, runner, 322 new disk_cache::SimpleBackendImpl(cache_path_, size_, type_, runner,
318 NULL)); 323 NULL));
319 int rv = simple_backend->Init(cb.callback()); 324 int rv = simple_backend->Init(cb.callback());
320 ASSERT_EQ(net::OK, cb.GetResult(rv)); 325 ASSERT_THAT(cb.GetResult(rv), IsOk());
321 simple_cache_impl_ = simple_backend.get(); 326 simple_cache_impl_ = simple_backend.get();
322 cache_ = std::move(simple_backend); 327 cache_ = std::move(simple_backend);
323 if (simple_cache_wait_for_index_) { 328 if (simple_cache_wait_for_index_) {
324 net::TestCompletionCallback wait_for_index_cb; 329 net::TestCompletionCallback wait_for_index_cb;
325 rv = simple_cache_impl_->index()->ExecuteWhenReady( 330 rv = simple_cache_impl_->index()->ExecuteWhenReady(
326 wait_for_index_cb.callback()); 331 wait_for_index_cb.callback());
327 ASSERT_EQ(net::OK, wait_for_index_cb.GetResult(rv)); 332 ASSERT_THAT(wait_for_index_cb.GetResult(rv), IsOk());
328 } 333 }
329 return; 334 return;
330 } 335 }
331 336
332 if (mask_) 337 if (mask_)
333 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, runner, NULL); 338 cache_impl_ = new disk_cache::BackendImpl(cache_path_, mask_, runner, NULL);
334 else 339 else
335 cache_impl_ = new disk_cache::BackendImpl(cache_path_, runner, NULL); 340 cache_impl_ = new disk_cache::BackendImpl(cache_path_, runner, NULL);
336 cache_.reset(cache_impl_); 341 cache_.reset(cache_impl_);
337 ASSERT_TRUE(cache_); 342 ASSERT_TRUE(cache_);
338 if (size_) 343 if (size_)
339 EXPECT_TRUE(cache_impl_->SetMaxSize(size_)); 344 EXPECT_TRUE(cache_impl_->SetMaxSize(size_));
340 if (new_eviction_) 345 if (new_eviction_)
341 cache_impl_->SetNewEviction(); 346 cache_impl_->SetNewEviction();
342 cache_impl_->SetType(type_); 347 cache_impl_->SetType(type_);
343 cache_impl_->SetFlags(flags); 348 cache_impl_->SetFlags(flags);
344 net::TestCompletionCallback cb; 349 net::TestCompletionCallback cb;
345 int rv = cache_impl_->Init(cb.callback()); 350 int rv = cache_impl_->Init(cb.callback());
346 ASSERT_EQ(net::OK, cb.GetResult(rv)); 351 ASSERT_THAT(cb.GetResult(rv), IsOk());
347 } 352 }
OLDNEW
« no previous file with comments | « net/disk_cache/backend_unittest.cc ('k') | net/disk_cache/entry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698