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

Side by Side Diff: net/http/http_cache_unittest.cc

Issue 3167032: HTTP cache: Move DeleteCacheCompletionCallback to the anonymous namespace... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 2006-2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2010 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/http/http_cache.h" 5 #include "net/http/http_cache.h"
6 6
7 #include "base/hash_tables.h" 7 #include "base/hash_tables.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/scoped_vector.h" 9 #include "base/scoped_vector.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 673
674 private: 674 private:
675 int Result() { return fail_ ? net::ERR_FAILED : net::OK; } 675 int Result() { return fail_ ? net::ERR_FAILED : net::OK; }
676 676
677 disk_cache::Backend** backend_; 677 disk_cache::Backend** backend_;
678 net::CompletionCallback* callback_; 678 net::CompletionCallback* callback_;
679 bool block_; 679 bool block_;
680 bool fail_; 680 bool fail_;
681 }; 681 };
682 682
683 class DeleteCacheCompletionCallback : public TestCompletionCallback {
684 public:
685 explicit DeleteCacheCompletionCallback(MockHttpCache* cache)
686 : cache_(cache) {}
687
688 virtual void RunWithParams(const Tuple1<int>& params) {
689 delete cache_;
690 TestCompletionCallback::RunWithParams(params);
691 }
692
693 private:
694 MockHttpCache* cache_;
695 };
696
683 //----------------------------------------------------------------------------- 697 //-----------------------------------------------------------------------------
684 // helpers 698 // helpers
685 699
686 void ReadAndVerifyTransaction(net::HttpTransaction* trans, 700 void ReadAndVerifyTransaction(net::HttpTransaction* trans,
687 const MockTransaction& trans_info) { 701 const MockTransaction& trans_info) {
688 std::string content; 702 std::string content;
689 int rv = ReadTransaction(trans, &content); 703 int rv = ReadTransaction(trans, &content);
690 704
691 EXPECT_EQ(net::OK, rv); 705 EXPECT_EQ(net::OK, rv);
692 std::string expected(trans_info.data); 706 std::string expected(trans_info.data);
(...skipping 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after
2005 // We cannot call FinishCreation because the factory itself will go away with 2019 // We cannot call FinishCreation because the factory itself will go away with
2006 // the cache, so grab the callback and attempt to use it. 2020 // the cache, so grab the callback and attempt to use it.
2007 net::CompletionCallback* callback = factory->callback(); 2021 net::CompletionCallback* callback = factory->callback();
2008 2022
2009 cache.reset(); 2023 cache.reset();
2010 MessageLoop::current()->RunAllPending(); 2024 MessageLoop::current()->RunAllPending();
2011 2025
2012 callback->Run(net::ERR_ABORTED); 2026 callback->Run(net::ERR_ABORTED);
2013 } 2027 }
2014 2028
2015 class DeleteCacheCompletionCallback : public TestCompletionCallback {
2016 public:
2017 explicit DeleteCacheCompletionCallback(MockHttpCache* cache)
2018 : cache_(cache) {}
2019
2020 virtual void RunWithParams(const Tuple1<int>& params) {
2021 delete cache_;
2022 TestCompletionCallback::RunWithParams(params);
2023 }
2024
2025 private:
2026 MockHttpCache* cache_;
2027 };
2028
2029 // Tests that we can delete the cache while creating the backend, from within 2029 // Tests that we can delete the cache while creating the backend, from within
2030 // one of the callbacks. 2030 // one of the callbacks.
2031 TEST(HttpCache, DeleteCacheWaitingForBackend2) { 2031 TEST(HttpCache, DeleteCacheWaitingForBackend2) {
2032 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory(); 2032 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
2033 MockHttpCache* cache = new MockHttpCache(factory); 2033 MockHttpCache* cache = new MockHttpCache(factory);
2034 2034
2035 DeleteCacheCompletionCallback cb(cache); 2035 DeleteCacheCompletionCallback cb(cache);
2036 disk_cache::Backend* backend; 2036 disk_cache::Backend* backend;
2037 int rv = cache->http_cache()->GetBackend(&backend, &cb); 2037 int rv = cache->http_cache()->GetBackend(&backend, &cb);
2038 EXPECT_EQ(net::ERR_IO_PENDING, rv); 2038 EXPECT_EQ(net::ERR_IO_PENDING, rv);
(...skipping 2773 matching lines...) Expand 10 before | Expand all | Expand 10 after
4812 // Now return 200 when validating the entry so the metadata will be lost. 4812 // Now return 200 when validating the entry so the metadata will be lost.
4813 MockTransaction trans2(kTypicalGET_Transaction); 4813 MockTransaction trans2(kTypicalGET_Transaction);
4814 trans2.load_flags = net::LOAD_VALIDATE_CACHE; 4814 trans2.load_flags = net::LOAD_VALIDATE_CACHE;
4815 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); 4815 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response);
4816 EXPECT_TRUE(response.metadata.get() == NULL); 4816 EXPECT_TRUE(response.metadata.get() == NULL);
4817 4817
4818 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 4818 EXPECT_EQ(3, cache.network_layer()->transaction_count());
4819 EXPECT_EQ(4, cache.disk_cache()->open_count()); 4819 EXPECT_EQ(4, cache.disk_cache()->open_count());
4820 EXPECT_EQ(1, cache.disk_cache()->create_count()); 4820 EXPECT_EQ(1, cache.disk_cache()->create_count());
4821 } 4821 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698