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/url_request/view_cache_helper.h" | 5 #include "net/url_request/view_cache_helper.h" |
6 | 6 |
7 #include "base/pickle.h" | 7 #include "base/pickle.h" |
| 8 #include "net/base/completion_callback.h" |
8 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
9 #include "net/base/test_completion_callback.h" | 10 #include "net/base/test_completion_callback.h" |
10 #include "net/disk_cache/disk_cache.h" | 11 #include "net/disk_cache/disk_cache.h" |
11 #include "net/http/http_cache.h" | 12 #include "net/http/http_cache.h" |
12 #include "net/url_request/url_request_context.h" | 13 #include "net/url_request/url_request_context.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace net { | 16 namespace net { |
16 | 17 |
17 namespace { | 18 namespace { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 } | 79 } |
79 | 80 |
80 WriteHeaders(entry, 0, data0); | 81 WriteHeaders(entry, 0, data0); |
81 WriteData(entry, 1, data1); | 82 WriteData(entry, 1, data1); |
82 WriteData(entry, 2, data2); | 83 WriteData(entry, 2, data2); |
83 | 84 |
84 entry->Close(); | 85 entry->Close(); |
85 } | 86 } |
86 | 87 |
87 void FillCache(URLRequestContext* context) { | 88 void FillCache(URLRequestContext* context) { |
88 TestOldCompletionCallback cb; | 89 TestCompletionCallback cb; |
89 disk_cache::Backend* cache; | 90 disk_cache::Backend* cache; |
90 int rv = | 91 int rv = context->http_transaction_factory()->GetCache()->GetBackend( |
91 context->http_transaction_factory()->GetCache()->GetBackend(&cache, &cb); | 92 &cache, cb.callback()); |
92 ASSERT_EQ(OK, cb.GetResult(rv)); | 93 ASSERT_EQ(OK, cb.GetResult(rv)); |
93 | 94 |
94 std::string empty; | 95 std::string empty; |
95 WriteToEntry(cache, "first", "some", empty, empty); | 96 WriteToEntry(cache, "first", "some", empty, empty); |
96 WriteToEntry(cache, "second", "only hex_dumped", "same", "kind"); | 97 WriteToEntry(cache, "second", "only hex_dumped", "same", "kind"); |
97 WriteToEntry(cache, "third", empty, "another", "thing"); | 98 WriteToEntry(cache, "third", empty, "another", "thing"); |
98 } | 99 } |
99 | 100 |
100 } // namespace. | 101 } // namespace. |
101 | 102 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 EXPECT_NE(std::string::npos, data.find("</html>")); | 174 EXPECT_NE(std::string::npos, data.find("</html>")); |
174 EXPECT_NE(std::string::npos, data.find("<a href=\"prefix:first\">")); | 175 EXPECT_NE(std::string::npos, data.find("<a href=\"prefix:first\">")); |
175 EXPECT_NE(std::string::npos, data.find("<a href=\"prefix:second\">")); | 176 EXPECT_NE(std::string::npos, data.find("<a href=\"prefix:second\">")); |
176 EXPECT_NE(std::string::npos, data.find("<a href=\"prefix:third\">")); | 177 EXPECT_NE(std::string::npos, data.find("<a href=\"prefix:third\">")); |
177 } | 178 } |
178 | 179 |
179 TEST(ViewCacheHelper, TruncatedFlag) { | 180 TEST(ViewCacheHelper, TruncatedFlag) { |
180 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 181 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
181 ViewCacheHelper helper; | 182 ViewCacheHelper helper; |
182 | 183 |
183 TestOldCompletionCallback cb; | 184 TestCompletionCallback cb; |
184 disk_cache::Backend* cache; | 185 disk_cache::Backend* cache; |
185 int rv = | 186 int rv = context->http_transaction_factory()->GetCache()->GetBackend( |
186 context->http_transaction_factory()->GetCache()->GetBackend(&cache, &cb); | 187 &cache, cb.callback()); |
187 ASSERT_EQ(OK, cb.GetResult(rv)); | 188 ASSERT_EQ(OK, cb.GetResult(rv)); |
188 | 189 |
189 std::string key("the key"); | 190 std::string key("the key"); |
190 disk_cache::Entry* entry; | 191 disk_cache::Entry* entry; |
191 rv = cache->CreateEntry(key, &entry, &cb); | 192 TestOldCompletionCallback cb2; |
| 193 rv = cache->CreateEntry(key, &entry, &cb2); |
192 ASSERT_EQ(OK, cb.GetResult(rv)); | 194 ASSERT_EQ(OK, cb.GetResult(rv)); |
193 | 195 |
194 // RESPONSE_INFO_TRUNCATED defined on response_info.cc | 196 // RESPONSE_INFO_TRUNCATED defined on response_info.cc |
195 int flags = 1 << 12; | 197 int flags = 1 << 12; |
196 WriteHeaders(entry, flags, "something"); | 198 WriteHeaders(entry, flags, "something"); |
197 entry->Close(); | 199 entry->Close(); |
198 | 200 |
199 std::string data; | 201 std::string data; |
200 TestCompletionCallback cb1; | 202 TestCompletionCallback cb1; |
201 rv = helper.GetEntryInfoHTML(key, context, &data, cb1.callback()); | 203 rv = helper.GetEntryInfoHTML(key, context, &data, cb1.callback()); |
202 EXPECT_EQ(OK, cb1.GetResult(rv)); | 204 EXPECT_EQ(OK, cb1.GetResult(rv)); |
203 | 205 |
204 EXPECT_NE(std::string::npos, data.find("RESPONSE_INFO_TRUNCATED")); | 206 EXPECT_NE(std::string::npos, data.find("RESPONSE_INFO_TRUNCATED")); |
205 } | 207 } |
206 | 208 |
207 } // namespace net | 209 } // namespace net |
OLD | NEW |