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

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

Issue 1039263002: //net changes for stale-while-revalidate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@s-w-r-remove-old-impl
Patch Set: Rebase. Created 5 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
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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 7359 matching lines...) Expand 10 before | Expand all | Expand 10 after
7370 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 7370 EXPECT_EQ(1, cache.network_layer()->transaction_count());
7371 7371
7372 // Send the request again and check that Resource-Freshness header is absent. 7372 // Send the request again and check that Resource-Freshness header is absent.
7373 stale_while_revalidate_transaction.handler = CheckResourceFreshnessAbsent; 7373 stale_while_revalidate_transaction.handler = CheckResourceFreshnessAbsent;
7374 7374
7375 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction); 7375 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
7376 7376
7377 EXPECT_EQ(2, cache.network_layer()->transaction_count()); 7377 EXPECT_EQ(2, cache.network_layer()->transaction_count());
7378 } 7378 }
7379 7379
7380 TEST(HttpCache, StaleContentNotUsedWhenLoadFlagNotSet) {
7381 MockHttpCache cache;
7382
7383 ScopedMockTransaction stale_while_revalidate_transaction(
7384 kSimpleGET_Transaction);
7385
7386 stale_while_revalidate_transaction.response_headers =
7387 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
7388 "Age: 10801\n"
7389 "Cache-Control: max-age=0,stale-while-revalidate=86400\n";
7390
7391 // Write to the cache.
7392 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
7393
7394 EXPECT_EQ(1, cache.network_layer()->transaction_count());
7395
7396 // Send the request again and check that it is sent to the network again.
7397 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
rvargas (doing something else) 2015/08/20 22:26:29 We should check the response flag instead of writi
Adam Rice 2015/08/21 15:01:46 Done.
7398
7399 EXPECT_EQ(2, cache.network_layer()->transaction_count());
7400 }
7401
7402 TEST(HttpCache, StaleContentUsedWhenLoadFlagSetAndUsable) {
7403 MockHttpCache cache;
7404
7405 ScopedMockTransaction stale_while_revalidate_transaction(
7406 kSimpleGET_Transaction);
7407 stale_while_revalidate_transaction.load_flags |=
7408 LOAD_SUPPORT_ASYNC_REVALIDATION;
7409 stale_while_revalidate_transaction.response_headers =
7410 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
7411 "Age: 10801\n"
7412 "Cache-Control: max-age=0,stale-while-revalidate=86400\n";
7413
7414 // Write to the cache.
7415 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
7416
7417 EXPECT_EQ(1, cache.network_layer()->transaction_count());
7418
7419 // Send the request again and check that it is not sent to the network again.
7420 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
7421
7422 EXPECT_EQ(1, cache.network_layer()->transaction_count());
7423 }
7424
7425 TEST(HttpCache, StaleContentNotUsedWhenUnusable) {
7426 MockHttpCache cache;
7427
7428 ScopedMockTransaction stale_while_revalidate_transaction(
7429 kSimpleGET_Transaction);
7430 stale_while_revalidate_transaction.load_flags |=
7431 LOAD_SUPPORT_ASYNC_REVALIDATION;
7432 stale_while_revalidate_transaction.response_headers =
7433 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
7434 "Age: 10801\n"
7435 "Cache-Control: max-age=0,stale-while-revalidate=1800\n";
7436
7437 // Write to the cache.
7438 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
7439
7440 EXPECT_EQ(1, cache.network_layer()->transaction_count());
7441
7442 // Send the request again and check that it is sent to the network again.
7443 RunTransactionTest(cache.http_cache(), stale_while_revalidate_transaction);
7444
7445 EXPECT_EQ(2, cache.network_layer()->transaction_count());
7446 }
7447
7448 TEST(HttpCache, AsyncRevalidationRequiredWhenLoadFlagSetAndUsable) {
7449 MockHttpCache cache;
7450
7451 ScopedMockTransaction stale_while_revalidate_transaction(
7452 kSimpleGET_Transaction);
7453 stale_while_revalidate_transaction.load_flags |=
7454 LOAD_SUPPORT_ASYNC_REVALIDATION;
7455 stale_while_revalidate_transaction.response_headers =
7456 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
7457 "Age: 10801\n"
7458 "Cache-Control: max-age=0,stale-while-revalidate=86400\n";
7459
7460 // Write to the cache.
7461 HttpResponseInfo response_info;
7462 RunTransactionTestWithResponseInfo(
7463 cache.http_cache(), stale_while_revalidate_transaction, &response_info);
7464
7465 EXPECT_FALSE(response_info.async_revalidation_required);
7466
7467 // Send the request again and check that the async_revalidation_required flag
7468 // is set.
7469 RunTransactionTestWithResponseInfo(
7470 cache.http_cache(), stale_while_revalidate_transaction, &response_info);
7471
7472 EXPECT_TRUE(response_info.async_revalidation_required);
7473 }
7474
7475 TEST(HttpCache, AsyncRevalidationNotRequiredWhenLoadFlagNotSet) {
7476 MockHttpCache cache;
7477
7478 ScopedMockTransaction stale_while_revalidate_transaction(
7479 kSimpleGET_Transaction);
7480 stale_while_revalidate_transaction.response_headers =
7481 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
7482 "Age: 10801\n"
7483 "Cache-Control: max-age=0,stale-while-revalidate=86400\n";
7484
7485 // Write to the cache.
7486 HttpResponseInfo response_info;
7487 RunTransactionTestWithResponseInfo(
7488 cache.http_cache(), stale_while_revalidate_transaction, &response_info);
7489
7490 // Send the request again and check that the async_revalidation_required flag
7491 // is not set.
7492 RunTransactionTestWithResponseInfo(
7493 cache.http_cache(), stale_while_revalidate_transaction, &response_info);
7494
7495 EXPECT_FALSE(response_info.async_revalidation_required);
7496 }
7497
7498 TEST(HttpCache, AsyncRevalidationNotRequiredWhenNotUsable) {
7499 MockHttpCache cache;
7500
7501 ScopedMockTransaction stale_while_revalidate_transaction(
7502 kSimpleGET_Transaction);
7503 stale_while_revalidate_transaction.load_flags |=
7504 LOAD_SUPPORT_ASYNC_REVALIDATION;
7505 stale_while_revalidate_transaction.response_headers =
7506 "Last-Modified: Sat, 18 Apr 2007 01:10:43 GMT\n"
7507 "Age: 10801\n"
7508 "Cache-Control: max-age=0,stale-while-revalidate=1800\n";
7509
7510 // Write to the cache.
7511 HttpResponseInfo response_info;
7512 RunTransactionTestWithResponseInfo(
7513 cache.http_cache(), stale_while_revalidate_transaction, &response_info);
7514
7515 // Send the request again and check that the async_revalidation_required flag
7516 // is not set.
7517 RunTransactionTestWithResponseInfo(
7518 cache.http_cache(), stale_while_revalidate_transaction, &response_info);
7519
7520 EXPECT_FALSE(response_info.async_revalidation_required);
7521 }
7522
7380 // Tests that we allow multiple simultaneous, non-overlapping transactions to 7523 // Tests that we allow multiple simultaneous, non-overlapping transactions to
7381 // take place on a sparse entry. 7524 // take place on a sparse entry.
7382 TEST(HttpCache, RangeGET_MultipleRequests) { 7525 TEST(HttpCache, RangeGET_MultipleRequests) {
7383 MockHttpCache cache; 7526 MockHttpCache cache;
7384 7527
7385 // Create a transaction for bytes 0-9. 7528 // Create a transaction for bytes 0-9.
7386 MockHttpRequest request(kRangeGET_TransactionOK); 7529 MockHttpRequest request(kRangeGET_TransactionOK);
7387 MockTransaction transaction(kRangeGET_TransactionOK); 7530 MockTransaction transaction(kRangeGET_TransactionOK);
7388 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER; 7531 transaction.request_headers = "Range: bytes = 0-9\r\n" EXTRA_HEADER;
7389 transaction.data = "rg: 00-09 "; 7532 transaction.data = "rg: 00-09 ";
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
7554 EXPECT_EQ(1, cache.disk_cache()->open_count()); 7697 EXPECT_EQ(1, cache.disk_cache()->open_count());
7555 EXPECT_EQ(1, cache.disk_cache()->create_count()); 7698 EXPECT_EQ(1, cache.disk_cache()->create_count());
7556 EXPECT_TRUE(response_info.was_cached); 7699 EXPECT_TRUE(response_info.was_cached);
7557 7700
7558 // The new SSL state is reported. 7701 // The new SSL state is reported.
7559 EXPECT_EQ(status2, response_info.ssl_info.connection_status); 7702 EXPECT_EQ(status2, response_info.ssl_info.connection_status);
7560 EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get())); 7703 EXPECT_TRUE(cert2->Equals(response_info.ssl_info.cert.get()));
7561 } 7704 }
7562 7705
7563 } // namespace net 7706 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698