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

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

Issue 10382089: Http cache: Don't attempt to doom the same entry multiple times (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 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
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/http/http_cache.h" 5 #include "net/http/http_cache.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 3953 matching lines...) Expand 10 before | Expand all | Expand 10 after
3964 EXPECT_EQ(80, entry->GetDataSize(1)); 3964 EXPECT_EQ(80, entry->GetDataSize(1));
3965 bool truncated = true; 3965 bool truncated = true;
3966 net::HttpResponseInfo response; 3966 net::HttpResponseInfo response;
3967 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); 3967 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated));
3968 EXPECT_FALSE(truncated); 3968 EXPECT_FALSE(truncated);
3969 entry->Close(); 3969 entry->Close();
3970 3970
3971 RemoveMockTransaction(&kRangeGET_TransactionOK); 3971 RemoveMockTransaction(&kRangeGET_TransactionOK);
3972 } 3972 }
3973 3973
3974 // Tests the handling of no-store when revalidating a truncated entry.
3975 TEST(HttpCache, GET_IncompleteResource_NoStore) {
3976 MockHttpCache cache;
3977 AddMockTransaction(&kRangeGET_TransactionOK);
3978
3979 std::string raw_headers("HTTP/1.1 200 OK\n"
3980 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
3981 "ETag: \"foo\"\n"
3982 "Accept-Ranges: bytes\n"
3983 "Content-Length: 80\n");
3984 CreateTruncatedEntry(raw_headers, &cache);
3985 RemoveMockTransaction(&kRangeGET_TransactionOK);
3986
3987 // Now make a regular request.
3988 MockTransaction transaction(kRangeGET_TransactionOK);
3989 transaction.request_headers = EXTRA_HEADER;
3990 std::string response_headers(transaction.response_headers);
3991 response_headers += ("Cache-Control: no-store\n");
3992 transaction.response_headers = response_headers.c_str();
3993 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 "
3994 "rg: 50-59 rg: 60-69 rg: 70-79 ";
3995 AddMockTransaction(&transaction);
3996
3997 std::string headers;
3998 RunTransactionTestWithResponse(cache.http_cache(), transaction, &headers);
3999
4000 // We update the headers with the ones received while revalidating.
4001 std::string expected_headers(
4002 "HTTP/1.1 200 OK\n"
4003 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
4004 "Accept-Ranges: bytes\n"
4005 "Cache-Control: no-store\n"
4006 "ETag: \"foo\"\n"
4007 "Content-Length: 80\n");
4008
4009 EXPECT_EQ(expected_headers, headers);
4010 EXPECT_EQ(2, cache.network_layer()->transaction_count());
4011 EXPECT_EQ(1, cache.disk_cache()->open_count());
4012 EXPECT_EQ(1, cache.disk_cache()->create_count());
4013
4014 // Verify that the disk entry was deleted.
4015 disk_cache::Entry* entry;
4016 EXPECT_FALSE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry));
4017 RemoveMockTransaction(&transaction);
4018 }
4019
4020 // Tests cancelling a request after the server sent no-store.
4021 TEST(HttpCache, GET_IncompleteResource_Cancel) {
4022 MockHttpCache cache;
4023 AddMockTransaction(&kRangeGET_TransactionOK);
4024
4025 std::string raw_headers("HTTP/1.1 200 OK\n"
4026 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
4027 "ETag: \"foo\"\n"
4028 "Accept-Ranges: bytes\n"
4029 "Content-Length: 80\n");
4030 CreateTruncatedEntry(raw_headers, &cache);
4031 RemoveMockTransaction(&kRangeGET_TransactionOK);
4032
4033 // Now make a regular request.
4034 MockTransaction transaction(kRangeGET_TransactionOK);
4035 transaction.request_headers = EXTRA_HEADER;
4036 std::string response_headers(transaction.response_headers);
4037 response_headers += ("Cache-Control: no-store\n");
4038 transaction.response_headers = response_headers.c_str();
4039 transaction.data = "rg: 00-09 rg: 10-19 rg: 20-29 rg: 30-39 rg: 40-49 "
4040 "rg: 50-59 rg: 60-69 rg: 70-79 ";
4041 AddMockTransaction(&transaction);
4042
4043 MockHttpRequest request(transaction);
4044 Context* c = new Context();
4045
4046 int rv = cache.http_cache()->CreateTransaction(&c->trans);
4047 EXPECT_EQ(net::OK, rv);
4048
4049 rv = c->trans->Start(&request, c->callback.callback(), net::BoundNetLog());
4050 EXPECT_EQ(net::OK, c->callback.GetResult(rv));
4051
4052 // Make sure that the entry has some data stored.
4053 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(5));
4054 rv = c->trans->Read(buf, buf->size(), c->callback.callback());
4055 EXPECT_EQ(5, c->callback.GetResult(rv));
4056
4057 // Cancel the request.
4058 delete c;
4059
4060 EXPECT_EQ(1, cache.network_layer()->transaction_count());
4061 EXPECT_EQ(1, cache.disk_cache()->open_count());
4062 EXPECT_EQ(1, cache.disk_cache()->create_count());
4063
4064 // Verify that the disk entry was deleted.
4065 disk_cache::Entry* entry;
4066 EXPECT_FALSE(cache.OpenBackendEntry(kRangeGET_TransactionOK.url, &entry));
4067 MessageLoop::current()->RunAllPending();
4068 RemoveMockTransaction(&transaction);
4069 }
4070
3974 // Tests that we delete truncated entries if the server changes its mind midway. 4071 // Tests that we delete truncated entries if the server changes its mind midway.
3975 TEST(HttpCache, GET_IncompleteResource2) { 4072 TEST(HttpCache, GET_IncompleteResource2) {
3976 MockHttpCache cache; 4073 MockHttpCache cache;
3977 AddMockTransaction(&kRangeGET_TransactionOK); 4074 AddMockTransaction(&kRangeGET_TransactionOK);
3978 4075
3979 // Content-length will be intentionally bad. 4076 // Content-length will be intentionally bad.
3980 std::string raw_headers("HTTP/1.1 200 OK\n" 4077 std::string raw_headers("HTTP/1.1 200 OK\n"
3981 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n" 4078 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
3982 "ETag: \"foo\"\n" 4079 "ETag: \"foo\"\n"
3983 "Accept-Ranges: bytes\n" 4080 "Accept-Ranges: bytes\n"
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
4837 4934
4838 // Verify that the entry is marked as incomplete. 4935 // Verify that the entry is marked as incomplete.
4839 disk_cache::Entry* entry; 4936 disk_cache::Entry* entry;
4840 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry)); 4937 ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry));
4841 net::HttpResponseInfo response; 4938 net::HttpResponseInfo response;
4842 bool truncated = false; 4939 bool truncated = false;
4843 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated)); 4940 EXPECT_TRUE(MockHttpCache::ReadResponseInfo(entry, &response, &truncated));
4844 EXPECT_TRUE(truncated); 4941 EXPECT_TRUE(truncated);
4845 entry->Close(); 4942 entry->Close();
4846 } 4943 }
OLDNEW
« net/http/http_cache_transaction.h ('K') | « net/http/http_cache_transaction.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698