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 "net/disk_cache/simple/simple_index_file.h" | 5 #include "net/disk_cache/simple/simple_index_file.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "net/base/cache_type.h" | 22 #include "net/base/cache_type.h" |
23 #include "net/base/test_completion_callback.h" | 23 #include "net/base/test_completion_callback.h" |
24 #include "net/disk_cache/disk_cache_test_util.h" | 24 #include "net/disk_cache/disk_cache_test_util.h" |
25 #include "net/disk_cache/simple/simple_backend_impl.h" | 25 #include "net/disk_cache/simple/simple_backend_impl.h" |
26 #include "net/disk_cache/simple/simple_backend_version.h" | 26 #include "net/disk_cache/simple/simple_backend_version.h" |
27 #include "net/disk_cache/simple/simple_entry_format.h" | 27 #include "net/disk_cache/simple/simple_entry_format.h" |
28 #include "net/disk_cache/simple/simple_index.h" | 28 #include "net/disk_cache/simple/simple_index.h" |
29 #include "net/disk_cache/simple/simple_util.h" | 29 #include "net/disk_cache/simple/simple_util.h" |
30 #include "net/disk_cache/simple/simple_version_upgrade.h" | 30 #include "net/disk_cache/simple/simple_version_upgrade.h" |
| 31 #include "net/test/gtest_util.h" |
| 32 #include "testing/gmock/include/gmock/gmock.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
32 | 34 |
| 35 using net::test::IsOk; |
| 36 |
33 using base::Time; | 37 using base::Time; |
34 using disk_cache::SimpleIndexFile; | 38 using disk_cache::SimpleIndexFile; |
35 using disk_cache::SimpleIndex; | 39 using disk_cache::SimpleIndex; |
36 | 40 |
37 namespace disk_cache { | 41 namespace disk_cache { |
38 | 42 |
39 // The Simple Cache backend requires a few guarantees from the filesystem like | 43 // The Simple Cache backend requires a few guarantees from the filesystem like |
40 // atomic renaming of recently open files. Those guarantees are not provided in | 44 // atomic renaming of recently open files. Those guarantees are not provided in |
41 // general on Windows. | 45 // general on Windows. |
42 #if defined(OS_POSIX) | 46 #if defined(OS_POSIX) |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 | 330 |
327 // Create the backend and initiate index flush by destroying the backend. | 331 // Create the backend and initiate index flush by destroying the backend. |
328 base::Thread cache_thread("CacheThread"); | 332 base::Thread cache_thread("CacheThread"); |
329 ASSERT_TRUE(cache_thread.StartWithOptions( | 333 ASSERT_TRUE(cache_thread.StartWithOptions( |
330 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); | 334 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); |
331 disk_cache::SimpleBackendImpl* simple_cache = | 335 disk_cache::SimpleBackendImpl* simple_cache = |
332 new disk_cache::SimpleBackendImpl(cache_path, 0, net::DISK_CACHE, | 336 new disk_cache::SimpleBackendImpl(cache_path, 0, net::DISK_CACHE, |
333 cache_thread.task_runner().get(), NULL); | 337 cache_thread.task_runner().get(), NULL); |
334 net::TestCompletionCallback cb; | 338 net::TestCompletionCallback cb; |
335 int rv = simple_cache->Init(cb.callback()); | 339 int rv = simple_cache->Init(cb.callback()); |
336 EXPECT_EQ(net::OK, cb.GetResult(rv)); | 340 EXPECT_THAT(cb.GetResult(rv), IsOk()); |
337 rv = simple_cache->index()->ExecuteWhenReady(cb.callback()); | 341 rv = simple_cache->index()->ExecuteWhenReady(cb.callback()); |
338 EXPECT_EQ(net::OK, cb.GetResult(rv)); | 342 EXPECT_THAT(cb.GetResult(rv), IsOk()); |
339 delete simple_cache; | 343 delete simple_cache; |
340 | 344 |
341 // The backend flushes the index on destruction and does so on the cache | 345 // The backend flushes the index on destruction and does so on the cache |
342 // thread, wait for the flushing to finish by posting a callback to the cache | 346 // thread, wait for the flushing to finish by posting a callback to the cache |
343 // thread after that. | 347 // thread after that. |
344 MessageLoopHelper helper; | 348 MessageLoopHelper helper; |
345 CallbackTest cb_shutdown(&helper, false); | 349 CallbackTest cb_shutdown(&helper, false); |
346 cache_thread.task_runner()->PostTaskAndReply( | 350 cache_thread.task_runner()->PostTaskAndReply( |
347 FROM_HERE, base::Bind(&base::DoNothing), | 351 FROM_HERE, base::Bind(&base::DoNothing), |
348 base::Bind(&CallbackTest::Run, base::Unretained(&cb_shutdown), net::OK)); | 352 base::Bind(&CallbackTest::Run, base::Unretained(&cb_shutdown), net::OK)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 closure.WaitForResult(); | 395 closure.WaitForResult(); |
392 | 396 |
393 // Check that the temporary file was deleted and the index file was created. | 397 // Check that the temporary file was deleted and the index file was created. |
394 EXPECT_FALSE(base::PathExists(simple_index_file.GetTempIndexFilePath())); | 398 EXPECT_FALSE(base::PathExists(simple_index_file.GetTempIndexFilePath())); |
395 EXPECT_TRUE(base::PathExists(simple_index_file.GetIndexFilePath())); | 399 EXPECT_TRUE(base::PathExists(simple_index_file.GetIndexFilePath())); |
396 } | 400 } |
397 | 401 |
398 #endif // defined(OS_POSIX) | 402 #endif // defined(OS_POSIX) |
399 | 403 |
400 } // namespace disk_cache | 404 } // namespace disk_cache |
OLD | NEW |