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

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

Issue 428003: Merge 32707 - Http cache: Make sure that when we cancel a request for... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/249/src/
Patch Set: Created 11 years, 1 month 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_transaction.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-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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 3206 matching lines...) Expand 10 before | Expand all | Expand 10 after
3217 RemoveMockTransaction(&kRangeGET_TransactionOK); 3217 RemoveMockTransaction(&kRangeGET_TransactionOK);
3218 3218
3219 // Verify that the disk entry was updated. 3219 // Verify that the disk entry was updated.
3220 EXPECT_EQ(80, entry->GetDataSize(1)); 3220 EXPECT_EQ(80, entry->GetDataSize(1));
3221 bool truncated = true; 3221 bool truncated = true;
3222 EXPECT_TRUE(net::HttpCache::ReadResponseInfo(entry, &response, &truncated)); 3222 EXPECT_TRUE(net::HttpCache::ReadResponseInfo(entry, &response, &truncated));
3223 EXPECT_FALSE(truncated); 3223 EXPECT_FALSE(truncated);
3224 entry->Close(); 3224 entry->Close();
3225 } 3225 }
3226 3226
3227 // Tests that when we cancel a request that was interrupted, we mark it again
3228 // as truncated.
3229 TEST(HttpCache, GET_CancelIncompleteResource) {
3230 MockHttpCache cache;
3231 cache.http_cache()->set_enable_range_support(true);
3232 AddMockTransaction(&kRangeGET_TransactionOK);
3233
3234 // Create a disk cache entry that stores an incomplete resource.
3235 disk_cache::Entry* entry;
3236 ASSERT_TRUE(cache.disk_cache()->CreateEntry(kRangeGET_TransactionOK.url,
3237 &entry));
3238
3239 // Content-length will be intentionally bogus.
3240 std::string raw_headers("HTTP/1.1 200 OK\n"
3241 "Last-Modified: something\n"
3242 "ETag: \"foo\"\n"
3243 "Accept-Ranges: bytes\n"
3244 "Content-Length: 10\n");
3245 raw_headers = net::HttpUtil::AssembleRawHeaders(raw_headers.data(),
3246 raw_headers.size());
3247
3248 net::HttpResponseInfo response;
3249 response.headers = new net::HttpResponseHeaders(raw_headers);
3250
3251 // Set the last argument for this to be an incomplete request.
3252 EXPECT_TRUE(net::HttpCache::WriteResponseInfo(entry, &response, true, true));
3253
3254 scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(100));
3255 int len = static_cast<int>(base::strlcpy(buf->data(), "rg: 00-09 rg: 10-19 ",
3256 buf->size()));
3257 EXPECT_EQ(len, entry->WriteData(1, 0, buf, len, NULL, true));
3258
3259 // Now make a regular request.
3260 MockTransaction transaction(kRangeGET_TransactionOK);
3261 transaction.request_headers = EXTRA_HEADER;
3262
3263 MockHttpRequest request(transaction);
3264 Context* c = new Context();
3265 EXPECT_EQ(net::OK, cache.http_cache()->CreateTransaction(&c->trans));
3266
3267 EXPECT_EQ(net::ERR_IO_PENDING, c->trans->Start(&request, &c->callback, NULL));
3268 EXPECT_EQ(net::OK, c->callback.WaitForResult());
3269
3270 // Read 20 bytes from the cache, and 10 from the net.
3271 EXPECT_EQ(net::ERR_IO_PENDING, c->trans->Read(buf, len, &c->callback));
3272 EXPECT_EQ(len, c->callback.WaitForResult());
3273 EXPECT_EQ(net::ERR_IO_PENDING, c->trans->Read(buf, 10, &c->callback));
3274 EXPECT_EQ(10, c->callback.WaitForResult());
3275
3276 // At this point, we are already reading so canceling the request should leave
3277 // a truncated one.
3278 delete c;
3279
3280 RemoveMockTransaction(&kRangeGET_TransactionOK);
3281
3282 EXPECT_EQ(2, cache.network_layer()->transaction_count());
3283 EXPECT_EQ(1, cache.disk_cache()->open_count());
3284 EXPECT_EQ(1, cache.disk_cache()->create_count());
3285
3286 // Verify that the disk entry was updated: now we have 30 bytes.
3287 EXPECT_EQ(30, entry->GetDataSize(1));
3288 bool truncated = false;
3289 EXPECT_TRUE(net::HttpCache::ReadResponseInfo(entry, &response, &truncated));
3290 EXPECT_TRUE(truncated);
3291 entry->Close();
3292 }
3293
3227 // Tests that we can handle range requests when we have a truncated entry. 3294 // Tests that we can handle range requests when we have a truncated entry.
3228 TEST(HttpCache, RangeGET_IncompleteResource) { 3295 TEST(HttpCache, RangeGET_IncompleteResource) {
3229 MockHttpCache cache; 3296 MockHttpCache cache;
3230 cache.http_cache()->set_enable_range_support(true); 3297 cache.http_cache()->set_enable_range_support(true);
3231 AddMockTransaction(&kRangeGET_TransactionOK); 3298 AddMockTransaction(&kRangeGET_TransactionOK);
3232 3299
3233 // Create a disk cache entry that stores an incomplete resource. 3300 // Create a disk cache entry that stores an incomplete resource.
3234 disk_cache::Entry* entry; 3301 disk_cache::Entry* entry;
3235 ASSERT_TRUE(cache.disk_cache()->CreateEntry(kRangeGET_TransactionOK.url, 3302 ASSERT_TRUE(cache.disk_cache()->CreateEntry(kRangeGET_TransactionOK.url,
3236 &entry)); 3303 &entry));
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
3601 std::string headers; 3668 std::string headers;
3602 response.headers->GetNormalizedHeaders(&headers); 3669 response.headers->GetNormalizedHeaders(&headers);
3603 3670
3604 EXPECT_EQ("HTTP/1.1 200 OK\n" 3671 EXPECT_EQ("HTTP/1.1 200 OK\n"
3605 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" 3672 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n"
3606 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", 3673 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n",
3607 headers); 3674 headers);
3608 3675
3609 RemoveMockTransaction(&mock_network_response); 3676 RemoveMockTransaction(&mock_network_response);
3610 } 3677 }
OLDNEW
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698