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

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

Issue 3016006: Http Cache: Don't delete the callback that is waiting for... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_cache.cc ('k') | 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 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 if (!fail_) 660 if (!fail_)
661 *backend_ = new MockDiskCache(); 661 *backend_ = new MockDiskCache();
662 net::CompletionCallback* cb = callback_; 662 net::CompletionCallback* cb = callback_;
663 callback_ = NULL; 663 callback_ = NULL;
664 cb->Run(Result()); // This object can be deleted here. 664 cb->Run(Result()); // This object can be deleted here.
665 } 665 }
666 } 666 }
667 667
668 void set_fail(bool fail) { fail_ = fail; } 668 void set_fail(bool fail) { fail_ = fail; }
669 669
670 net::CompletionCallback* callback() { return callback_; }
671
670 private: 672 private:
671 int Result() { return fail_ ? net::ERR_FAILED : net::OK; } 673 int Result() { return fail_ ? net::ERR_FAILED : net::OK; }
672 674
673 disk_cache::Backend** backend_; 675 disk_cache::Backend** backend_;
674 net::CompletionCallback* callback_; 676 net::CompletionCallback* callback_;
675 bool block_; 677 bool block_;
676 bool fail_; 678 bool fail_;
677 }; 679 };
678 680
679 //----------------------------------------------------------------------------- 681 //-----------------------------------------------------------------------------
(...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1972 context_list[2]->result = 1974 context_list[2]->result =
1973 context_list[2]->callback.GetResult(context_list[2]->result); 1975 context_list[2]->callback.GetResult(context_list[2]->result);
1974 ReadAndVerifyTransaction(context_list[2]->trans.get(), kETagGET_Transaction); 1976 ReadAndVerifyTransaction(context_list[2]->trans.get(), kETagGET_Transaction);
1975 1977
1976 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1978 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1977 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1979 EXPECT_EQ(1, cache.disk_cache()->create_count());
1978 1980
1979 delete context_list[2]; 1981 delete context_list[2];
1980 } 1982 }
1981 1983
1984 // Tests that we can delete the cache while creating the backend.
1985 TEST(HttpCache, DeleteCacheWaitingForBackend) {
1986 MockBlockingBackendFactory* factory = new MockBlockingBackendFactory();
1987 MockHttpCache* cache = new MockHttpCache(factory);
1988
1989 MockHttpRequest request(kSimpleGET_Transaction);
1990
1991 Context* c = new Context();
1992 c->result = cache->http_cache()->CreateTransaction(&c->trans);
1993 EXPECT_EQ(net::OK, c->result);
1994
1995 c->trans->Start(&request, &c->callback, net::BoundNetLog());
1996
1997 // Just to make sure that everything is still pending.
1998 MessageLoop::current()->RunAllPending();
1999
2000 // The request should be creating the disk cache.
2001 EXPECT_FALSE(c->callback.have_result());
2002
2003 // We cannot call FinishCreation because the factory itself will go away with
2004 // the cache, so grab the callback and attempt to use it.
2005 net::CompletionCallback* callback = factory->callback();
2006
2007 delete cache;
Paweł Hajdan Jr. 2010/07/16 21:45:51 nit: How about using scoped pointers to make it mu
2008 MessageLoop::current()->RunAllPending();
2009
2010 callback->Run(net::ERR_ABORTED);
2011 delete c;
Paweł Hajdan Jr. 2010/07/16 21:45:51 Similarly here.
2012 }
2013
1982 TEST(HttpCache, TypicalGET_ConditionalRequest) { 2014 TEST(HttpCache, TypicalGET_ConditionalRequest) {
1983 MockHttpCache cache; 2015 MockHttpCache cache;
1984 2016
1985 // write to the cache 2017 // write to the cache
1986 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction); 2018 RunTransactionTest(cache.http_cache(), kTypicalGET_Transaction);
1987 2019
1988 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 2020 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1989 EXPECT_EQ(0, cache.disk_cache()->open_count()); 2021 EXPECT_EQ(0, cache.disk_cache()->open_count());
1990 EXPECT_EQ(1, cache.disk_cache()->create_count()); 2022 EXPECT_EQ(1, cache.disk_cache()->create_count());
1991 2023
(...skipping 2732 matching lines...) Expand 10 before | Expand all | Expand 10 after
4724 // Now return 200 when validating the entry so the metadata will be lost. 4756 // Now return 200 when validating the entry so the metadata will be lost.
4725 MockTransaction trans2(kTypicalGET_Transaction); 4757 MockTransaction trans2(kTypicalGET_Transaction);
4726 trans2.load_flags = net::LOAD_VALIDATE_CACHE; 4758 trans2.load_flags = net::LOAD_VALIDATE_CACHE;
4727 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); 4759 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response);
4728 EXPECT_TRUE(response.metadata.get() == NULL); 4760 EXPECT_TRUE(response.metadata.get() == NULL);
4729 4761
4730 EXPECT_EQ(3, cache.network_layer()->transaction_count()); 4762 EXPECT_EQ(3, cache.network_layer()->transaction_count());
4731 EXPECT_EQ(4, cache.disk_cache()->open_count()); 4763 EXPECT_EQ(4, cache.disk_cache()->open_count());
4732 EXPECT_EQ(1, cache.disk_cache()->create_count()); 4764 EXPECT_EQ(1, cache.disk_cache()->create_count());
4733 } 4765 }
OLDNEW
« no previous file with comments | « net/http/http_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698