| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_util.h" | 5 #include "net/disk_cache/disk_cache_test_util.h" |
| 6 | 6 |
| 7 #include "base/logging.h" |
| 7 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 9 #include "net/disk_cache/backend_impl.h" | 10 #include "net/disk_cache/backend_impl.h" |
| 10 #include "net/disk_cache/cache_util.h" | 11 #include "net/disk_cache/cache_util.h" |
| 11 #include "net/disk_cache/file.h" | 12 #include "net/disk_cache/file.h" |
| 12 | 13 |
| 13 using base::Time; | 14 using base::Time; |
| 14 using base::TimeDelta; | 15 using base::TimeDelta; |
| 15 | 16 |
| 16 std::string GenerateKey(bool same_length) { | 17 std::string GenerateKey(bool same_length) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 71 |
| 71 bool CheckCacheIntegrity(const std::wstring& path) { | 72 bool CheckCacheIntegrity(const std::wstring& path) { |
| 72 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl(path)); | 73 scoped_ptr<disk_cache::BackendImpl> cache(new disk_cache::BackendImpl(path)); |
| 73 if (!cache.get()) | 74 if (!cache.get()) |
| 74 return false; | 75 return false; |
| 75 if (!cache->Init()) | 76 if (!cache->Init()) |
| 76 return false; | 77 return false; |
| 77 return cache->SelfCheck() >= 0; | 78 return cache->SelfCheck() >= 0; |
| 78 } | 79 } |
| 79 | 80 |
| 81 ScopedTestCache::ScopedTestCache() : path_(GetCachePath()) { |
| 82 bool result = DeleteCache(path_.c_str()); |
| 83 DCHECK(result); |
| 84 } |
| 85 |
| 86 ScopedTestCache::~ScopedTestCache() { |
| 87 file_util::Delete(path(), true); |
| 88 } |
| 89 |
| 80 // ----------------------------------------------------------------------- | 90 // ----------------------------------------------------------------------- |
| 81 | 91 |
| 82 int g_cache_tests_max_id = 0; | 92 int g_cache_tests_max_id = 0; |
| 83 volatile int g_cache_tests_received = 0; | 93 volatile int g_cache_tests_received = 0; |
| 84 volatile bool g_cache_tests_error = 0; | 94 volatile bool g_cache_tests_error = 0; |
| 85 | 95 |
| 86 // On the actual callback, increase the number of tests received and check for | 96 // On the actual callback, increase the number of tests received and check for |
| 87 // errors (an unexpected test received) | 97 // errors (an unexpected test received) |
| 88 void CallbackTest::RunWithParams(const Tuple1<int>& params) { | 98 void CallbackTest::RunWithParams(const Tuple1<int>& params) { |
| 89 if (id_ > g_cache_tests_max_id) { | 99 if (id_ > g_cache_tests_max_id) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 } else { | 141 } else { |
| 132 // Not finished yet. See if we have to abort. | 142 // Not finished yet. See if we have to abort. |
| 133 if (last_ == g_cache_tests_received) | 143 if (last_ == g_cache_tests_received) |
| 134 num_iterations_++; | 144 num_iterations_++; |
| 135 else | 145 else |
| 136 last_ = g_cache_tests_received; | 146 last_ = g_cache_tests_received; |
| 137 if (40 == num_iterations_) | 147 if (40 == num_iterations_) |
| 138 MessageLoop::current()->Quit(); | 148 MessageLoop::current()->Quit(); |
| 139 } | 149 } |
| 140 } | 150 } |
| OLD | NEW |