OLD | NEW |
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 2305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2316 // (4) loads |kUrl| from cache only -- expects |cached_response_2| to be | 2316 // (4) loads |kUrl| from cache only -- expects |cached_response_2| to be |
2317 // returned. | 2317 // returned. |
2318 static void ConditionalizedRequestUpdatesCacheHelper( | 2318 static void ConditionalizedRequestUpdatesCacheHelper( |
2319 const Response& net_response_1, | 2319 const Response& net_response_1, |
2320 const Response& net_response_2, | 2320 const Response& net_response_2, |
2321 const Response& cached_response_2, | 2321 const Response& cached_response_2, |
2322 const char* extra_request_headers) { | 2322 const char* extra_request_headers) { |
2323 MockHttpCache cache; | 2323 MockHttpCache cache; |
2324 | 2324 |
2325 // The URL we will be requesting. | 2325 // The URL we will be requesting. |
2326 const char* kUrl = "http://foobar.com/main.css"; | 2326 const char kUrl[] = "http://foobar.com/main.css"; |
2327 | 2327 |
2328 // Junk network response. | 2328 // Junk network response. |
2329 static const Response kUnexpectedResponse = { | 2329 static const Response kUnexpectedResponse = { |
2330 "HTTP/1.1 500 Unexpected", | 2330 "HTTP/1.1 500 Unexpected", |
2331 "Server: unexpected_header", | 2331 "Server: unexpected_header", |
2332 "unexpected body" | 2332 "unexpected body" |
2333 }; | 2333 }; |
2334 | 2334 |
2335 // We will control the network layer's responses for |kUrl| using | 2335 // We will control the network layer's responses for |kUrl| using |
2336 // |mock_network_response|. | 2336 // |mock_network_response|. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2427 }; | 2427 }; |
2428 | 2428 |
2429 // Second network response for |kUrl|. | 2429 // Second network response for |kUrl|. |
2430 static const Response kNetResponse2 = { | 2430 static const Response kNetResponse2 = { |
2431 "HTTP/1.1 200 OK", | 2431 "HTTP/1.1 200 OK", |
2432 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2432 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2433 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", | 2433 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", |
2434 "body2" | 2434 "body2" |
2435 }; | 2435 }; |
2436 | 2436 |
2437 const char* extra_headers = | 2437 const char extra_headers[] = |
2438 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; | 2438 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; |
2439 | 2439 |
2440 ConditionalizedRequestUpdatesCacheHelper( | 2440 ConditionalizedRequestUpdatesCacheHelper( |
2441 kNetResponse1, kNetResponse2, kNetResponse2, extra_headers); | 2441 kNetResponse1, kNetResponse2, kNetResponse2, extra_headers); |
2442 } | 2442 } |
2443 | 2443 |
2444 // Check that when an "if-none-match" header is attached | 2444 // Check that when an "if-none-match" header is attached |
2445 // to the request, the result updates the cached entry. | 2445 // to the request, the result updates the cached entry. |
2446 TEST(HttpCache, ConditionalizedRequestUpdatesCache2) { | 2446 TEST(HttpCache, ConditionalizedRequestUpdatesCache2) { |
2447 // First network response for |kUrl|. | 2447 // First network response for |kUrl|. |
2448 static const Response kNetResponse1 = { | 2448 static const Response kNetResponse1 = { |
2449 "HTTP/1.1 200 OK", | 2449 "HTTP/1.1 200 OK", |
2450 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2450 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2451 "Etag: \"ETAG1\"\n" | 2451 "Etag: \"ETAG1\"\n" |
2452 "Expires: Wed, 7 Sep 2033 21:46:42 GMT\n", // Should never expire. | 2452 "Expires: Wed, 7 Sep 2033 21:46:42 GMT\n", // Should never expire. |
2453 "body1" | 2453 "body1" |
2454 }; | 2454 }; |
2455 | 2455 |
2456 // Second network response for |kUrl|. | 2456 // Second network response for |kUrl|. |
2457 static const Response kNetResponse2 = { | 2457 static const Response kNetResponse2 = { |
2458 "HTTP/1.1 200 OK", | 2458 "HTTP/1.1 200 OK", |
2459 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2459 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2460 "Etag: \"ETAG2\"\n" | 2460 "Etag: \"ETAG2\"\n" |
2461 "Expires: Wed, 7 Sep 2033 21:46:42 GMT\n", // Should never expire. | 2461 "Expires: Wed, 7 Sep 2033 21:46:42 GMT\n", // Should never expire. |
2462 "body2" | 2462 "body2" |
2463 }; | 2463 }; |
2464 | 2464 |
2465 const char* extra_headers = "If-None-Match: \"ETAG1\"\r\n"; | 2465 const char extra_headers[] = "If-None-Match: \"ETAG1\"\r\n"; |
2466 | 2466 |
2467 ConditionalizedRequestUpdatesCacheHelper( | 2467 ConditionalizedRequestUpdatesCacheHelper( |
2468 kNetResponse1, kNetResponse2, kNetResponse2, extra_headers); | 2468 kNetResponse1, kNetResponse2, kNetResponse2, extra_headers); |
2469 } | 2469 } |
2470 | 2470 |
2471 // Check that when an "if-modified-since" header is attached | 2471 // Check that when an "if-modified-since" header is attached |
2472 // to a request, the 304 (not modified result) result updates the cached | 2472 // to a request, the 304 (not modified result) result updates the cached |
2473 // headers, and the 304 response is returned rather than the cached response. | 2473 // headers, and the 304 response is returned rather than the cached response. |
2474 TEST(HttpCache, ConditionalizedRequestUpdatesCache3) { | 2474 TEST(HttpCache, ConditionalizedRequestUpdatesCache3) { |
2475 // First network response for |kUrl|. | 2475 // First network response for |kUrl|. |
(...skipping 15 matching lines...) Expand all Loading... |
2491 }; | 2491 }; |
2492 | 2492 |
2493 static const Response kCachedResponse2 = { | 2493 static const Response kCachedResponse2 = { |
2494 "HTTP/1.1 200 OK", | 2494 "HTTP/1.1 200 OK", |
2495 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2495 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2496 "Server: server2\n" | 2496 "Server: server2\n" |
2497 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2497 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2498 "body1" | 2498 "body1" |
2499 }; | 2499 }; |
2500 | 2500 |
2501 const char* extra_headers = | 2501 const char extra_headers[] = |
2502 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; | 2502 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; |
2503 | 2503 |
2504 ConditionalizedRequestUpdatesCacheHelper( | 2504 ConditionalizedRequestUpdatesCacheHelper( |
2505 kNetResponse1, kNetResponse2, kCachedResponse2, extra_headers); | 2505 kNetResponse1, kNetResponse2, kCachedResponse2, extra_headers); |
2506 } | 2506 } |
2507 | 2507 |
2508 // Test that when doing an externally conditionalized if-modified-since | 2508 // Test that when doing an externally conditionalized if-modified-since |
2509 // and there is no corresponding cache entry, a new cache entry is NOT | 2509 // and there is no corresponding cache entry, a new cache entry is NOT |
2510 // created (304 response). | 2510 // created (304 response). |
2511 TEST(HttpCache, ConditionalizedRequestUpdatesCache4) { | 2511 TEST(HttpCache, ConditionalizedRequestUpdatesCache4) { |
2512 MockHttpCache cache; | 2512 MockHttpCache cache; |
2513 | 2513 |
2514 const char* kUrl = "http://foobar.com/main.css"; | 2514 const char kUrl[] = "http://foobar.com/main.css"; |
2515 | 2515 |
2516 static const Response kNetResponse = { | 2516 static const Response kNetResponse = { |
2517 "HTTP/1.1 304 Not Modified", | 2517 "HTTP/1.1 304 Not Modified", |
2518 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2518 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2519 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2519 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2520 "" | 2520 "" |
2521 }; | 2521 }; |
2522 | 2522 |
2523 const char* kExtraRequestHeaders = | 2523 const char kExtraRequestHeaders[] = |
2524 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; | 2524 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; |
2525 | 2525 |
2526 // We will control the network layer's responses for |kUrl| using | 2526 // We will control the network layer's responses for |kUrl| using |
2527 // |mock_network_response|. | 2527 // |mock_network_response|. |
2528 MockTransaction mock_network_response = { 0 }; | 2528 MockTransaction mock_network_response = { 0 }; |
2529 mock_network_response.url = kUrl; | 2529 mock_network_response.url = kUrl; |
2530 AddMockTransaction(&mock_network_response); | 2530 AddMockTransaction(&mock_network_response); |
2531 | 2531 |
2532 MockTransaction request = { 0 }; | 2532 MockTransaction request = { 0 }; |
2533 request.url = kUrl; | 2533 request.url = kUrl; |
(...skipping 14 matching lines...) Expand all Loading... |
2548 | 2548 |
2549 RemoveMockTransaction(&mock_network_response); | 2549 RemoveMockTransaction(&mock_network_response); |
2550 } | 2550 } |
2551 | 2551 |
2552 // Test that when doing an externally conditionalized if-modified-since | 2552 // Test that when doing an externally conditionalized if-modified-since |
2553 // and there is no corresponding cache entry, a new cache entry is NOT | 2553 // and there is no corresponding cache entry, a new cache entry is NOT |
2554 // created (200 response). | 2554 // created (200 response). |
2555 TEST(HttpCache, ConditionalizedRequestUpdatesCache5) { | 2555 TEST(HttpCache, ConditionalizedRequestUpdatesCache5) { |
2556 MockHttpCache cache; | 2556 MockHttpCache cache; |
2557 | 2557 |
2558 const char* kUrl = "http://foobar.com/main.css"; | 2558 const char kUrl[] = "http://foobar.com/main.css"; |
2559 | 2559 |
2560 static const Response kNetResponse = { | 2560 static const Response kNetResponse = { |
2561 "HTTP/1.1 200 OK", | 2561 "HTTP/1.1 200 OK", |
2562 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2562 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2563 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2563 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2564 "foobar!!!" | 2564 "foobar!!!" |
2565 }; | 2565 }; |
2566 | 2566 |
2567 const char* kExtraRequestHeaders = | 2567 const char kExtraRequestHeaders[] = |
2568 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; | 2568 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n"; |
2569 | 2569 |
2570 // We will control the network layer's responses for |kUrl| using | 2570 // We will control the network layer's responses for |kUrl| using |
2571 // |mock_network_response|. | 2571 // |mock_network_response|. |
2572 MockTransaction mock_network_response = { 0 }; | 2572 MockTransaction mock_network_response = { 0 }; |
2573 mock_network_response.url = kUrl; | 2573 mock_network_response.url = kUrl; |
2574 AddMockTransaction(&mock_network_response); | 2574 AddMockTransaction(&mock_network_response); |
2575 | 2575 |
2576 MockTransaction request = { 0 }; | 2576 MockTransaction request = { 0 }; |
2577 request.url = kUrl; | 2577 request.url = kUrl; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2610 static const Response kNetResponse2 = { | 2610 static const Response kNetResponse2 = { |
2611 "HTTP/1.1 304 Not Modified", | 2611 "HTTP/1.1 304 Not Modified", |
2612 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2612 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2613 "Server: server2\n" | 2613 "Server: server2\n" |
2614 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2614 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2615 "" | 2615 "" |
2616 }; | 2616 }; |
2617 | 2617 |
2618 // This is two days in the future from the original response's last-modified | 2618 // This is two days in the future from the original response's last-modified |
2619 // date! | 2619 // date! |
2620 const char* kExtraRequestHeaders = | 2620 const char kExtraRequestHeaders[] = |
2621 "If-Modified-Since: Fri, 08 Feb 2008 22:38:21 GMT\r\n"; | 2621 "If-Modified-Since: Fri, 08 Feb 2008 22:38:21 GMT\r\n"; |
2622 | 2622 |
2623 ConditionalizedRequestUpdatesCacheHelper( | 2623 ConditionalizedRequestUpdatesCacheHelper( |
2624 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); | 2624 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); |
2625 } | 2625 } |
2626 | 2626 |
2627 // Test that when doing an externally conditionalized if-none-match | 2627 // Test that when doing an externally conditionalized if-none-match |
2628 // if the etag does not match the cache entry's etag, then we do not use the | 2628 // if the etag does not match the cache entry's etag, then we do not use the |
2629 // response (304) to update the cache. | 2629 // response (304) to update the cache. |
2630 TEST(HttpCache, ConditionalizedRequestUpdatesCache7) { | 2630 TEST(HttpCache, ConditionalizedRequestUpdatesCache7) { |
2631 static const Response kNetResponse1 = { | 2631 static const Response kNetResponse1 = { |
2632 "HTTP/1.1 200 OK", | 2632 "HTTP/1.1 200 OK", |
2633 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2633 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2634 "Etag: \"Foo1\"\n" | 2634 "Etag: \"Foo1\"\n" |
2635 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2635 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2636 "body1" | 2636 "body1" |
2637 }; | 2637 }; |
2638 | 2638 |
2639 // Second network response for |kUrl|. | 2639 // Second network response for |kUrl|. |
2640 static const Response kNetResponse2 = { | 2640 static const Response kNetResponse2 = { |
2641 "HTTP/1.1 304 Not Modified", | 2641 "HTTP/1.1 304 Not Modified", |
2642 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2642 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2643 "Etag: \"Foo2\"\n" | 2643 "Etag: \"Foo2\"\n" |
2644 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2644 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2645 "" | 2645 "" |
2646 }; | 2646 }; |
2647 | 2647 |
2648 // Different etag from original response. | 2648 // Different etag from original response. |
2649 const char* kExtraRequestHeaders = "If-None-Match: \"Foo2\"\r\n"; | 2649 const char kExtraRequestHeaders[] = "If-None-Match: \"Foo2\"\r\n"; |
2650 | 2650 |
2651 ConditionalizedRequestUpdatesCacheHelper( | 2651 ConditionalizedRequestUpdatesCacheHelper( |
2652 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); | 2652 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); |
2653 } | 2653 } |
2654 | 2654 |
2655 // Test that doing an externally conditionalized request with both if-none-match | 2655 // Test that doing an externally conditionalized request with both if-none-match |
2656 // and if-modified-since updates the cache. | 2656 // and if-modified-since updates the cache. |
2657 TEST(HttpCache, ConditionalizedRequestUpdatesCache8) { | 2657 TEST(HttpCache, ConditionalizedRequestUpdatesCache8) { |
2658 static const Response kNetResponse1 = { | 2658 static const Response kNetResponse1 = { |
2659 "HTTP/1.1 200 OK", | 2659 "HTTP/1.1 200 OK", |
2660 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2660 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2661 "Etag: \"Foo1\"\n" | 2661 "Etag: \"Foo1\"\n" |
2662 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2662 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2663 "body1" | 2663 "body1" |
2664 }; | 2664 }; |
2665 | 2665 |
2666 // Second network response for |kUrl|. | 2666 // Second network response for |kUrl|. |
2667 static const Response kNetResponse2 = { | 2667 static const Response kNetResponse2 = { |
2668 "HTTP/1.1 200 OK", | 2668 "HTTP/1.1 200 OK", |
2669 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2669 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2670 "Etag: \"Foo2\"\n" | 2670 "Etag: \"Foo2\"\n" |
2671 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", | 2671 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", |
2672 "body2" | 2672 "body2" |
2673 }; | 2673 }; |
2674 | 2674 |
2675 const char* kExtraRequestHeaders = | 2675 const char kExtraRequestHeaders[] = |
2676 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n" | 2676 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n" |
2677 "If-None-Match: \"Foo1\"\r\n"; | 2677 "If-None-Match: \"Foo1\"\r\n"; |
2678 | 2678 |
2679 ConditionalizedRequestUpdatesCacheHelper( | 2679 ConditionalizedRequestUpdatesCacheHelper( |
2680 kNetResponse1, kNetResponse2, kNetResponse2, kExtraRequestHeaders); | 2680 kNetResponse1, kNetResponse2, kNetResponse2, kExtraRequestHeaders); |
2681 } | 2681 } |
2682 | 2682 |
2683 // Test that doing an externally conditionalized request with both if-none-match | 2683 // Test that doing an externally conditionalized request with both if-none-match |
2684 // and if-modified-since does not update the cache with only one match. | 2684 // and if-modified-since does not update the cache with only one match. |
2685 TEST(HttpCache, ConditionalizedRequestUpdatesCache9) { | 2685 TEST(HttpCache, ConditionalizedRequestUpdatesCache9) { |
2686 static const Response kNetResponse1 = { | 2686 static const Response kNetResponse1 = { |
2687 "HTTP/1.1 200 OK", | 2687 "HTTP/1.1 200 OK", |
2688 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2688 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2689 "Etag: \"Foo1\"\n" | 2689 "Etag: \"Foo1\"\n" |
2690 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2690 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2691 "body1" | 2691 "body1" |
2692 }; | 2692 }; |
2693 | 2693 |
2694 // Second network response for |kUrl|. | 2694 // Second network response for |kUrl|. |
2695 static const Response kNetResponse2 = { | 2695 static const Response kNetResponse2 = { |
2696 "HTTP/1.1 200 OK", | 2696 "HTTP/1.1 200 OK", |
2697 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2697 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2698 "Etag: \"Foo2\"\n" | 2698 "Etag: \"Foo2\"\n" |
2699 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", | 2699 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", |
2700 "body2" | 2700 "body2" |
2701 }; | 2701 }; |
2702 | 2702 |
2703 // The etag doesn't match what we have stored. | 2703 // The etag doesn't match what we have stored. |
2704 const char* kExtraRequestHeaders = | 2704 const char kExtraRequestHeaders[] = |
2705 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n" | 2705 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\r\n" |
2706 "If-None-Match: \"Foo2\"\r\n"; | 2706 "If-None-Match: \"Foo2\"\r\n"; |
2707 | 2707 |
2708 ConditionalizedRequestUpdatesCacheHelper( | 2708 ConditionalizedRequestUpdatesCacheHelper( |
2709 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); | 2709 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); |
2710 } | 2710 } |
2711 | 2711 |
2712 // Test that doing an externally conditionalized request with both if-none-match | 2712 // Test that doing an externally conditionalized request with both if-none-match |
2713 // and if-modified-since does not update the cache with only one match. | 2713 // and if-modified-since does not update the cache with only one match. |
2714 TEST(HttpCache, ConditionalizedRequestUpdatesCache10) { | 2714 TEST(HttpCache, ConditionalizedRequestUpdatesCache10) { |
2715 static const Response kNetResponse1 = { | 2715 static const Response kNetResponse1 = { |
2716 "HTTP/1.1 200 OK", | 2716 "HTTP/1.1 200 OK", |
2717 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" | 2717 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n" |
2718 "Etag: \"Foo1\"\n" | 2718 "Etag: \"Foo1\"\n" |
2719 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", | 2719 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", |
2720 "body1" | 2720 "body1" |
2721 }; | 2721 }; |
2722 | 2722 |
2723 // Second network response for |kUrl|. | 2723 // Second network response for |kUrl|. |
2724 static const Response kNetResponse2 = { | 2724 static const Response kNetResponse2 = { |
2725 "HTTP/1.1 200 OK", | 2725 "HTTP/1.1 200 OK", |
2726 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" | 2726 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" |
2727 "Etag: \"Foo2\"\n" | 2727 "Etag: \"Foo2\"\n" |
2728 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", | 2728 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n", |
2729 "body2" | 2729 "body2" |
2730 }; | 2730 }; |
2731 | 2731 |
2732 // The modification date doesn't match what we have stored. | 2732 // The modification date doesn't match what we have stored. |
2733 const char* kExtraRequestHeaders = | 2733 const char kExtraRequestHeaders[] = |
2734 "If-Modified-Since: Fri, 08 Feb 2008 22:38:21 GMT\r\n" | 2734 "If-Modified-Since: Fri, 08 Feb 2008 22:38:21 GMT\r\n" |
2735 "If-None-Match: \"Foo1\"\r\n"; | 2735 "If-None-Match: \"Foo1\"\r\n"; |
2736 | 2736 |
2737 ConditionalizedRequestUpdatesCacheHelper( | 2737 ConditionalizedRequestUpdatesCacheHelper( |
2738 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); | 2738 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); |
2739 } | 2739 } |
2740 | 2740 |
2741 TEST(HttpCache, UrlContainingHash) { | 2741 TEST(HttpCache, UrlContainingHash) { |
2742 MockHttpCache cache; | 2742 MockHttpCache cache; |
2743 | 2743 |
(...skipping 3615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6359 } | 6359 } |
6360 | 6360 |
6361 // Other tests check that the response headers of the cached response | 6361 // Other tests check that the response headers of the cached response |
6362 // get updated on 304. Here we specifically check that the | 6362 // get updated on 304. Here we specifically check that the |
6363 // HttpResponseHeaders::request_time and HttpResponseHeaders::response_time | 6363 // HttpResponseHeaders::request_time and HttpResponseHeaders::response_time |
6364 // fields also gets updated. | 6364 // fields also gets updated. |
6365 // http://crbug.com/20594. | 6365 // http://crbug.com/20594. |
6366 TEST(HttpCache, UpdatesRequestResponseTimeOn304) { | 6366 TEST(HttpCache, UpdatesRequestResponseTimeOn304) { |
6367 MockHttpCache cache; | 6367 MockHttpCache cache; |
6368 | 6368 |
6369 const char* kUrl = "http://foobar"; | 6369 const char kUrl[] = "http://foobar"; |
6370 const char* kData = "body"; | 6370 const char kData[] = "body"; |
6371 | 6371 |
6372 MockTransaction mock_network_response = { 0 }; | 6372 MockTransaction mock_network_response = { 0 }; |
6373 mock_network_response.url = kUrl; | 6373 mock_network_response.url = kUrl; |
6374 | 6374 |
6375 AddMockTransaction(&mock_network_response); | 6375 AddMockTransaction(&mock_network_response); |
6376 | 6376 |
6377 // Request |kUrl|, causing |kNetResponse1| to be written to the cache. | 6377 // Request |kUrl|, causing |kNetResponse1| to be written to the cache. |
6378 | 6378 |
6379 MockTransaction request = { 0 }; | 6379 MockTransaction request = { 0 }; |
6380 request.url = kUrl; | 6380 request.url = kUrl; |
(...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7775 | 7775 |
7776 // Here the second transaction proceeds without reading the first body. | 7776 // Here the second transaction proceeds without reading the first body. |
7777 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); | 7777 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); |
7778 base::MessageLoop::current()->RunUntilIdle(); | 7778 base::MessageLoop::current()->RunUntilIdle(); |
7779 EXPECT_EQ(net::LOAD_STATE_IDLE, second->trans->GetLoadState()); | 7779 EXPECT_EQ(net::LOAD_STATE_IDLE, second->trans->GetLoadState()); |
7780 ASSERT_TRUE(second->trans->GetResponseInfo()); | 7780 ASSERT_TRUE(second->trans->GetResponseInfo()); |
7781 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( | 7781 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( |
7782 "Cache-Control", "no-store")); | 7782 "Cache-Control", "no-store")); |
7783 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); | 7783 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); |
7784 } | 7784 } |
OLD | NEW |