Chromium Code Reviews| 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 3062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3073 EXPECT_EQ(2, cache.disk_cache()->create_count()); | 3073 EXPECT_EQ(2, cache.disk_cache()->create_count()); |
| 3074 | 3074 |
| 3075 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); | 3075 RunTransactionTestWithRequest(cache.http_cache(), transaction, req1, NULL); |
| 3076 | 3076 |
| 3077 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 3077 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 3078 EXPECT_EQ(0, cache.disk_cache()->open_count()); | 3078 EXPECT_EQ(0, cache.disk_cache()->open_count()); |
| 3079 EXPECT_EQ(3, cache.disk_cache()->create_count()); | 3079 EXPECT_EQ(3, cache.disk_cache()->create_count()); |
| 3080 RemoveMockTransaction(&transaction); | 3080 RemoveMockTransaction(&transaction); |
| 3081 } | 3081 } |
| 3082 | 3082 |
| 3083 // Tests that a successful POST invalidates the url given in the | |
| 3084 // Content-Location header. | |
| 3085 TEST(HttpCache, SimplePOST_Invalidate_content_location) { | |
|
Adam Rice
2015/04/24 13:19:21
This file is full of strangely-named tests, especi
haavardm
2015/04/27 10:48:36
Yeah, I tend to follow the styles in the files I e
| |
| 3086 MockHttpCache cache; | |
| 3087 | |
| 3088 MockTransaction transaction1(kTypicalGET_Transaction); | |
|
Adam Rice
2015/04/24 13:19:21
There is no need to create the transaction1 and re
haavardm
2015/04/27 10:48:36
Done.
| |
| 3089 AddMockTransaction(&transaction1); | |
| 3090 MockHttpRequest req1(transaction1); | |
| 3091 | |
| 3092 // Attempt to populate the cache. | |
| 3093 RunTransactionTestWithRequest(cache.http_cache(), transaction1, req1, NULL); | |
| 3094 | |
| 3095 EXPECT_EQ(1, cache.network_layer()->transaction_count()); | |
| 3096 EXPECT_EQ(0, cache.disk_cache()->open_count()); | |
| 3097 EXPECT_EQ(1, cache.disk_cache()->create_count()); | |
| 3098 | |
| 3099 ScopedVector<net::UploadElementReader> element_readers; | |
| 3100 element_readers.push_back(new net::UploadBytesElementReader("hello", 5)); | |
| 3101 net::ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 1); | |
| 3102 | |
| 3103 // Send a post request with url of kTypicalGET_Transaction set in the | |
| 3104 // Content-Location header | |
| 3105 MockTransaction transaction2(kContentLocationPOST_Transaction); | |
|
Adam Rice
2015/04/24 13:19:21
If you use ScopedMockTransaction, then you don't n
haavardm
2015/04/27 10:48:36
Done.
| |
| 3106 AddMockTransaction(&transaction2); | |
| 3107 | |
| 3108 MockHttpRequest req2(transaction2); | |
| 3109 req2.upload_data_stream = &upload_data_stream; | |
| 3110 | |
| 3111 RunTransactionTestWithRequest(cache.http_cache(), transaction2, req2, NULL); | |
| 3112 | |
| 3113 EXPECT_EQ(2, cache.network_layer()->transaction_count()); | |
| 3114 EXPECT_EQ(0, cache.disk_cache()->open_count()); | |
| 3115 EXPECT_EQ(2, cache.disk_cache()->create_count()); | |
| 3116 | |
| 3117 RemoveMockTransaction(&transaction2); | |
| 3118 | |
| 3119 // Check that the cache entry from kTypicalGET_Transaction is invalidated. | |
| 3120 RunTransactionTestWithRequest(cache.http_cache(), transaction1, req1, NULL); | |
| 3121 | |
| 3122 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | |
| 3123 EXPECT_EQ(0, cache.disk_cache()->open_count()); | |
| 3124 EXPECT_EQ(3, cache.disk_cache()->create_count()); | |
| 3125 RemoveMockTransaction(&transaction1); | |
| 3126 } | |
| 3127 | |
| 3083 // Tests that a successful POST invalidates a previously cached GET, even when | 3128 // Tests that a successful POST invalidates a previously cached GET, even when |
| 3084 // there is no upload identifier. | 3129 // there is no upload identifier. |
| 3085 TEST(HttpCache, SimplePOST_NoUploadId_Invalidate_205) { | 3130 TEST(HttpCache, SimplePOST_NoUploadId_Invalidate_205) { |
| 3086 MockHttpCache cache; | 3131 MockHttpCache cache; |
| 3087 | 3132 |
| 3088 MockTransaction transaction(kSimpleGET_Transaction); | 3133 MockTransaction transaction(kSimpleGET_Transaction); |
| 3089 AddMockTransaction(&transaction); | 3134 AddMockTransaction(&transaction); |
| 3090 MockHttpRequest req1(transaction); | 3135 MockHttpRequest req1(transaction); |
| 3091 | 3136 |
| 3092 // Attempt to populate the cache. | 3137 // Attempt to populate the cache. |
| (...skipping 4824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7917 | 7962 |
| 7918 // Here the second transaction proceeds without reading the first body. | 7963 // Here the second transaction proceeds without reading the first body. |
| 7919 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); | 7964 EXPECT_EQ(net::LOAD_STATE_WAITING_FOR_CACHE, second->trans->GetLoadState()); |
| 7920 base::MessageLoop::current()->RunUntilIdle(); | 7965 base::MessageLoop::current()->RunUntilIdle(); |
| 7921 EXPECT_EQ(net::LOAD_STATE_IDLE, second->trans->GetLoadState()); | 7966 EXPECT_EQ(net::LOAD_STATE_IDLE, second->trans->GetLoadState()); |
| 7922 ASSERT_TRUE(second->trans->GetResponseInfo()); | 7967 ASSERT_TRUE(second->trans->GetResponseInfo()); |
| 7923 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( | 7968 EXPECT_TRUE(second->trans->GetResponseInfo()->headers->HasHeaderValue( |
| 7924 "Cache-Control", "no-store")); | 7969 "Cache-Control", "no-store")); |
| 7925 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); | 7970 ReadAndVerifyTransaction(second->trans.get(), kSimpleGET_Transaction); |
| 7926 } | 7971 } |
| OLD | NEW |