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

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

Issue 22926031: Sparse IO: Allow failover to network in debug builds (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 3 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/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 "Accept-Ranges: bytes\n" 494 "Accept-Ranges: bytes\n"
495 "Content-Length: 10\n", 495 "Content-Length: 10\n",
496 base::Time(), 496 base::Time(),
497 "rg: 40-49 ", 497 "rg: 40-49 ",
498 TEST_MODE_NORMAL, 498 TEST_MODE_NORMAL,
499 &RangeTransactionServer::RangeHandler, 499 &RangeTransactionServer::RangeHandler,
500 0, 500 0,
501 net::OK 501 net::OK
502 }; 502 };
503 503
504 const MockTransaction kRangeGET_NotReallyARange = {
505 "http://www.google.com/range",
506 "GET",
507 base::Time(),
508 EXTRA_HEADER,
509 net::LOAD_NORMAL,
510 "HTTP/1.1 200 OK",
511 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
512 "ETag: \"foo\"\n"
513 "Accept-Ranges: bytes\n"
514 "Content-Length: 10\n"
515 "Cache-Control: max-age=10000\n",
516 base::Time(),
517 "Not a range",
518 TEST_MODE_NORMAL,
519 &FastTransactionServer::FastNoStoreHandler,
520 0,
521 net::OK
522 };
523
504 // Verifies the response headers (|response|) match a partial content 524 // Verifies the response headers (|response|) match a partial content
505 // response for the range starting at |start| and ending at |end|. 525 // response for the range starting at |start| and ending at |end|.
506 void Verify206Response(std::string response, int start, int end) { 526 void Verify206Response(std::string response, int start, int end) {
507 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(), 527 std::string raw_headers(net::HttpUtil::AssembleRawHeaders(response.data(),
508 response.size())); 528 response.size()));
509 scoped_refptr<net::HttpResponseHeaders> headers( 529 scoped_refptr<net::HttpResponseHeaders> headers(
510 new net::HttpResponseHeaders(raw_headers)); 530 new net::HttpResponseHeaders(raw_headers));
511 531
512 ASSERT_EQ(206, headers->response_code()); 532 ASSERT_EQ(206, headers->response_code());
513 533
(...skipping 2873 matching lines...) Expand 10 before | Expand all | Expand 10 after
3387 3407
3388 Verify206Response(headers, 20, 59); 3408 Verify206Response(headers, 20, 59);
3389 EXPECT_EQ(4, cache.network_layer()->transaction_count()); 3409 EXPECT_EQ(4, cache.network_layer()->transaction_count());
3390 EXPECT_EQ(3, cache.disk_cache()->open_count()); 3410 EXPECT_EQ(3, cache.disk_cache()->open_count());
3391 EXPECT_EQ(1, cache.disk_cache()->create_count()); 3411 EXPECT_EQ(1, cache.disk_cache()->create_count());
3392 TestLoadTimingNetworkRequest(load_timing_info); 3412 TestLoadTimingNetworkRequest(load_timing_info);
3393 3413
3394 RemoveMockTransaction(&kRangeGET_TransactionOK); 3414 RemoveMockTransaction(&kRangeGET_TransactionOK);
3395 } 3415 }
3396 3416
3417 #if defined(OS_ANDROID)
3418
3419 // Tests that with a cache backend that does not implement Sparse IO the cache
3420 // entry would be re-created on each transaction.
3421 // TODO(pasko): remove when the SimpleBackendImpl implements Sparse IO.
3422 TEST(HttpCache, RangeGET_SparseNotImplemented) {
3423 MockHttpCache cache;
3424 cache.disk_cache()->set_fail_sparse_requests();
3425 AddMockTransaction(&kRangeGET_TransactionOK);
3426 std::string headers;
3427
3428 // Run a cacheable request to prime the cache.
3429 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_NotReallyARange,
rvargas (doing something else) 2013/08/28 21:35:47 I would actually prefer following HttpCache.RangeG
pasko 2013/08/28 21:56:28 Done.
pasko 2013/08/28 22:01:43 huh, misunderstood you here. I thought you suggest
rvargas (doing something else) 2013/08/28 22:33:40 Not really following the whole pattern of that tes
3430 &headers);
3431
3432 EXPECT_EQ(1, cache.network_layer()->transaction_count());
3433 EXPECT_EQ(0, cache.disk_cache()->open_count());
3434 EXPECT_EQ(1, cache.disk_cache()->create_count());
3435 EXPECT_EQ(0, cache.disk_cache()->sparse_count());
3436
3437 // Write to the cache (40-49).
3438 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK,
3439 &headers);
3440
3441 Verify206Response(headers, 40, 49);
3442 EXPECT_EQ(2, cache.network_layer()->transaction_count());
3443 EXPECT_EQ(1, cache.disk_cache()->open_count());
3444 EXPECT_EQ(2, cache.disk_cache()->create_count());
3445
3446 // Two sparse operations are expected: ReadyForSparseIO() and
3447 // WriteSparseData().
3448 EXPECT_EQ(2, cache.disk_cache()->sparse_count());
3449
3450 // Run the transaction again.
3451 RunTransactionTestWithResponse(cache.http_cache(), kRangeGET_TransactionOK,
3452 &headers);
3453
3454 Verify206Response(headers, 40, 49);
3455 EXPECT_EQ(3, cache.network_layer()->transaction_count());
3456 EXPECT_EQ(1, cache.disk_cache()->open_count());
3457 EXPECT_EQ(3, cache.disk_cache()->create_count());
3458
3459 // WriteSparseData() must be invoked.
3460 EXPECT_EQ(3, cache.disk_cache()->sparse_count());
3461
3462 RemoveMockTransaction(&kRangeGET_TransactionOK);
3463 }
3464
3465 #endif // OS_ANDROID
3466
3397 // Tests that we can cache range requests and fetch random blocks from the 3467 // Tests that we can cache range requests and fetch random blocks from the
3398 // cache and the network, with synchronous responses. 3468 // cache and the network, with synchronous responses.
3399 TEST(HttpCache, RangeGET_SyncOK) { 3469 TEST(HttpCache, RangeGET_SyncOK) {
3400 MockHttpCache cache; 3470 MockHttpCache cache;
3401 3471
3402 MockTransaction transaction(kRangeGET_TransactionOK); 3472 MockTransaction transaction(kRangeGET_TransactionOK);
3403 transaction.test_mode = TEST_MODE_SYNC_ALL; 3473 transaction.test_mode = TEST_MODE_SYNC_ALL;
3404 AddMockTransaction(&transaction); 3474 AddMockTransaction(&transaction);
3405 3475
3406 // Write to the cache (40-49). 3476 // Write to the cache (40-49).
(...skipping 2642 matching lines...) Expand 10 before | Expand all | Expand 10 after
6049 trans->SetPriority(net::HIGHEST); 6119 trans->SetPriority(net::HIGHEST);
6050 // Should trigger a new network transaction and pick up the new 6120 // Should trigger a new network transaction and pick up the new
6051 // priority. 6121 // priority.
6052 ReadAndVerifyTransaction(trans.get(), transaction); 6122 ReadAndVerifyTransaction(trans.get(), transaction);
6053 6123
6054 EXPECT_EQ(net::HIGHEST, 6124 EXPECT_EQ(net::HIGHEST,
6055 cache.network_layer()->last_create_transaction_priority()); 6125 cache.network_layer()->last_create_transaction_priority());
6056 6126
6057 RemoveMockTransaction(&kRangeGET_TransactionOK); 6127 RemoveMockTransaction(&kRangeGET_TransactionOK);
6058 } 6128 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698