OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 5083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5094 // Now return 200 when validating the entry so the metadata will be lost. | 5094 // Now return 200 when validating the entry so the metadata will be lost. |
5095 MockTransaction trans2(kTypicalGET_Transaction); | 5095 MockTransaction trans2(kTypicalGET_Transaction); |
5096 trans2.load_flags = net::LOAD_VALIDATE_CACHE; | 5096 trans2.load_flags = net::LOAD_VALIDATE_CACHE; |
5097 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); | 5097 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); |
5098 EXPECT_TRUE(response.metadata.get() == NULL); | 5098 EXPECT_TRUE(response.metadata.get() == NULL); |
5099 | 5099 |
5100 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 5100 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
5101 EXPECT_EQ(4, cache.disk_cache()->open_count()); | 5101 EXPECT_EQ(4, cache.disk_cache()->open_count()); |
5102 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5102 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
5103 } | 5103 } |
| 5104 |
| 5105 // Tests that we don't mark entries as truncated when a filter detects the end |
| 5106 // of the stream. |
| 5107 TEST(HttpCache, FilterCompletion) { |
| 5108 MockHttpCache cache; |
| 5109 TestCompletionCallback callback; |
| 5110 |
| 5111 { |
| 5112 scoped_ptr<net::HttpTransaction> trans; |
| 5113 int rv = cache.http_cache()->CreateTransaction(&trans); |
| 5114 EXPECT_EQ(net::OK, rv); |
| 5115 |
| 5116 MockHttpRequest request(kSimpleGET_Transaction); |
| 5117 rv = trans->Start(&request, &callback, net::BoundNetLog()); |
| 5118 EXPECT_EQ(net::OK, callback.GetResult(rv)); |
| 5119 |
| 5120 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(256)); |
| 5121 rv = trans->Read(buf, 256, &callback); |
| 5122 EXPECT_GT(callback.GetResult(rv), 0); |
| 5123 |
| 5124 // Now make sure that the entry is preserved. |
| 5125 trans->DoneReading(); |
| 5126 } |
| 5127 |
| 5128 // Make sure that teh ActiveEntry is gone. |
| 5129 MessageLoop::current()->RunAllPending(); |
| 5130 |
| 5131 // Read from the cache. |
| 5132 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 5133 |
| 5134 EXPECT_EQ(1, cache.network_layer()->transaction_count()); |
| 5135 EXPECT_EQ(1, cache.disk_cache()->open_count()); |
| 5136 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 5137 } |
OLD | NEW |