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/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/net_errors.h" | 8 #include "net/base/net_errors.h" |
9 #include "net/base/test_completion_callback.h" | 9 #include "net/base/test_completion_callback.h" |
10 #include "net/disk_cache/disk_cache.h" | 10 #include "net/disk_cache/disk_cache.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 pickle.WriteInt(flags | 1); // Version 1. | 42 pickle.WriteInt(flags | 1); // Version 1. |
43 pickle.WriteInt64(0); | 43 pickle.WriteInt64(0); |
44 pickle.WriteInt64(0); | 44 pickle.WriteInt64(0); |
45 pickle.WriteString(data); | 45 pickle.WriteString(data); |
46 | 46 |
47 scoped_refptr<WrappedIOBuffer> buf(new WrappedIOBuffer( | 47 scoped_refptr<WrappedIOBuffer> buf(new WrappedIOBuffer( |
48 reinterpret_cast<const char*>(pickle.data()))); | 48 reinterpret_cast<const char*>(pickle.data()))); |
49 int len = static_cast<int>(pickle.size()); | 49 int len = static_cast<int>(pickle.size()); |
50 | 50 |
51 net::TestCompletionCallback cb; | 51 net::TestCompletionCallback cb; |
52 int rv = entry->WriteData(0, 0, buf, len, cb.callback(), true); | 52 int rv = entry->WriteData(0, 0, buf.get(), len, cb.callback(), true); |
53 ASSERT_EQ(len, cb.GetResult(rv)); | 53 ASSERT_EQ(len, cb.GetResult(rv)); |
54 } | 54 } |
55 | 55 |
56 void WriteData(disk_cache::Entry* entry, int index, const std::string data) { | 56 void WriteData(disk_cache::Entry* entry, int index, const std::string data) { |
57 if (data.empty()) | 57 if (data.empty()) |
58 return; | 58 return; |
59 | 59 |
60 int len = data.length(); | 60 int len = data.length(); |
61 scoped_refptr<IOBuffer> buf(new IOBuffer(len)); | 61 scoped_refptr<IOBuffer> buf(new IOBuffer(len)); |
62 memcpy(buf->data(), data.data(), data.length()); | 62 memcpy(buf->data(), data.data(), data.length()); |
63 | 63 |
64 net::TestCompletionCallback cb; | 64 net::TestCompletionCallback cb; |
65 int rv = entry->WriteData(index, 0, buf, len, cb.callback(), true); | 65 int rv = entry->WriteData(index, 0, buf.get(), len, cb.callback(), true); |
66 ASSERT_EQ(len, cb.GetResult(rv)); | 66 ASSERT_EQ(len, cb.GetResult(rv)); |
67 } | 67 } |
68 | 68 |
69 void WriteToEntry(disk_cache::Backend* cache, const std::string key, | 69 void WriteToEntry(disk_cache::Backend* cache, const std::string key, |
70 const std::string data0, const std::string data1, | 70 const std::string data0, const std::string data1, |
71 const std::string data2) { | 71 const std::string data2) { |
72 net::TestCompletionCallback cb; | 72 net::TestCompletionCallback cb; |
73 disk_cache::Entry* entry; | 73 disk_cache::Entry* entry; |
74 int rv = cache->CreateEntry(key, &entry, cb.callback()); | 74 int rv = cache->CreateEntry(key, &entry, cb.callback()); |
75 rv = cb.GetResult(rv); | 75 rv = cb.GetResult(rv); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 201 |
202 std::string data; | 202 std::string data; |
203 TestCompletionCallback cb1; | 203 TestCompletionCallback cb1; |
204 rv = helper.GetEntryInfoHTML(key, &context, &data, cb1.callback()); | 204 rv = helper.GetEntryInfoHTML(key, &context, &data, cb1.callback()); |
205 EXPECT_EQ(OK, cb1.GetResult(rv)); | 205 EXPECT_EQ(OK, cb1.GetResult(rv)); |
206 | 206 |
207 EXPECT_NE(std::string::npos, data.find("RESPONSE_INFO_TRUNCATED")); | 207 EXPECT_NE(std::string::npos, data.find("RESPONSE_INFO_TRUNCATED")); |
208 } | 208 } |
209 | 209 |
210 } // namespace net | 210 } // namespace net |
OLD | NEW |