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/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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 WriteToEntry(cache, "second", "only hex_dumped", "same", "kind"); | 96 WriteToEntry(cache, "second", "only hex_dumped", "same", "kind"); |
97 WriteToEntry(cache, "third", empty, "another", "thing"); | 97 WriteToEntry(cache, "third", empty, "another", "thing"); |
98 } | 98 } |
99 | 99 |
100 } // namespace. | 100 } // namespace. |
101 | 101 |
102 TEST(ViewCacheHelper, EmptyCache) { | 102 TEST(ViewCacheHelper, EmptyCache) { |
103 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 103 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
104 ViewCacheHelper helper; | 104 ViewCacheHelper helper; |
105 | 105 |
106 TestOldCompletionCallback cb; | 106 TestCompletionCallback cb; |
107 std::string prefix, data; | 107 std::string prefix, data; |
108 int rv = helper.GetContentsHTML(context, prefix, &data, &cb); | 108 int rv = helper.GetContentsHTML(context, prefix, &data, cb.callback()); |
109 EXPECT_EQ(OK, cb.GetResult(rv)); | 109 EXPECT_EQ(OK, cb.GetResult(rv)); |
110 EXPECT_FALSE(data.empty()); | 110 EXPECT_FALSE(data.empty()); |
111 } | 111 } |
112 | 112 |
113 TEST(ViewCacheHelper, ListContents) { | 113 TEST(ViewCacheHelper, ListContents) { |
114 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 114 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
115 ViewCacheHelper helper; | 115 ViewCacheHelper helper; |
116 | 116 |
117 FillCache(context); | 117 FillCache(context); |
118 | 118 |
119 std::string prefix, data; | 119 std::string prefix, data; |
120 TestOldCompletionCallback cb; | 120 TestCompletionCallback cb; |
121 int rv = helper.GetContentsHTML(context, prefix, &data, &cb); | 121 int rv = helper.GetContentsHTML(context, prefix, &data, cb.callback()); |
122 EXPECT_EQ(OK, cb.GetResult(rv)); | 122 EXPECT_EQ(OK, cb.GetResult(rv)); |
123 | 123 |
124 EXPECT_EQ(0U, data.find("<html>")); | 124 EXPECT_EQ(0U, data.find("<html>")); |
125 EXPECT_NE(std::string::npos, data.find("</html>")); | 125 EXPECT_NE(std::string::npos, data.find("</html>")); |
126 EXPECT_NE(std::string::npos, data.find("first")); | 126 EXPECT_NE(std::string::npos, data.find("first")); |
127 EXPECT_NE(std::string::npos, data.find("second")); | 127 EXPECT_NE(std::string::npos, data.find("second")); |
128 EXPECT_NE(std::string::npos, data.find("third")); | 128 EXPECT_NE(std::string::npos, data.find("third")); |
129 | 129 |
130 EXPECT_EQ(std::string::npos, data.find("some")); | 130 EXPECT_EQ(std::string::npos, data.find("some")); |
131 EXPECT_EQ(std::string::npos, data.find("same")); | 131 EXPECT_EQ(std::string::npos, data.find("same")); |
132 EXPECT_EQ(std::string::npos, data.find("thing")); | 132 EXPECT_EQ(std::string::npos, data.find("thing")); |
133 } | 133 } |
134 | 134 |
135 TEST(ViewCacheHelper, DumpEntry) { | 135 TEST(ViewCacheHelper, DumpEntry) { |
136 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 136 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
137 ViewCacheHelper helper; | 137 ViewCacheHelper helper; |
138 | 138 |
139 FillCache(context); | 139 FillCache(context); |
140 | 140 |
141 std::string data; | 141 std::string data; |
142 TestOldCompletionCallback cb; | 142 TestCompletionCallback cb; |
143 int rv = helper.GetEntryInfoHTML("second", context, &data, &cb); | 143 int rv = helper.GetEntryInfoHTML("second", context, &data, cb.callback()); |
144 EXPECT_EQ(OK, cb.GetResult(rv)); | 144 EXPECT_EQ(OK, cb.GetResult(rv)); |
145 | 145 |
146 EXPECT_EQ(0U, data.find("<html>")); | 146 EXPECT_EQ(0U, data.find("<html>")); |
147 EXPECT_NE(std::string::npos, data.find("</html>")); | 147 EXPECT_NE(std::string::npos, data.find("</html>")); |
148 | 148 |
149 EXPECT_NE(std::string::npos, data.find("hex_dumped")); | 149 EXPECT_NE(std::string::npos, data.find("hex_dumped")); |
150 EXPECT_NE(std::string::npos, data.find("same")); | 150 EXPECT_NE(std::string::npos, data.find("same")); |
151 EXPECT_NE(std::string::npos, data.find("kind")); | 151 EXPECT_NE(std::string::npos, data.find("kind")); |
152 | 152 |
153 EXPECT_EQ(std::string::npos, data.find("first")); | 153 EXPECT_EQ(std::string::npos, data.find("first")); |
154 EXPECT_EQ(std::string::npos, data.find("third")); | 154 EXPECT_EQ(std::string::npos, data.find("third")); |
155 EXPECT_EQ(std::string::npos, data.find("some")); | 155 EXPECT_EQ(std::string::npos, data.find("some")); |
156 EXPECT_EQ(std::string::npos, data.find("another")); | 156 EXPECT_EQ(std::string::npos, data.find("another")); |
157 } | 157 } |
158 | 158 |
159 // Makes sure the links are correct. | 159 // Makes sure the links are correct. |
160 TEST(ViewCacheHelper, Prefix) { | 160 TEST(ViewCacheHelper, Prefix) { |
161 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); | 161 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext()); |
162 ViewCacheHelper helper; | 162 ViewCacheHelper helper; |
163 | 163 |
164 FillCache(context); | 164 FillCache(context); |
165 | 165 |
166 std::string key, data; | 166 std::string key, data; |
167 std::string prefix("prefix:"); | 167 std::string prefix("prefix:"); |
168 TestOldCompletionCallback cb; | 168 TestCompletionCallback cb; |
169 int rv = helper.GetContentsHTML(context, prefix, &data, &cb); | 169 int rv = helper.GetContentsHTML(context, prefix, &data, cb.callback()); |
170 EXPECT_EQ(OK, cb.GetResult(rv)); | 170 EXPECT_EQ(OK, cb.GetResult(rv)); |
171 | 171 |
172 EXPECT_EQ(0U, data.find("<html>")); | 172 EXPECT_EQ(0U, data.find("<html>")); |
173 EXPECT_NE(std::string::npos, data.find("</html>")); | 173 EXPECT_NE(std::string::npos, data.find("</html>")); |
174 EXPECT_NE(std::string::npos, data.find("<a href=\"prefix:first\">")); | 174 EXPECT_NE(std::string::npos, data.find("<a href=\"prefix:first\">")); |
175 EXPECT_NE(std::string::npos, data.find("<a href=\"prefix:second\">")); | 175 EXPECT_NE(std::string::npos, data.find("<a href=\"prefix:second\">")); |
176 EXPECT_NE(std::string::npos, data.find("<a href=\"prefix:third\">")); | 176 EXPECT_NE(std::string::npos, data.find("<a href=\"prefix:third\">")); |
177 } | 177 } |
178 | 178 |
179 TEST(ViewCacheHelper, TruncatedFlag) { | 179 TEST(ViewCacheHelper, TruncatedFlag) { |
(...skipping 10 matching lines...) Expand all Loading... |
190 disk_cache::Entry* entry; | 190 disk_cache::Entry* entry; |
191 rv = cache->CreateEntry(key, &entry, &cb); | 191 rv = cache->CreateEntry(key, &entry, &cb); |
192 ASSERT_EQ(OK, cb.GetResult(rv)); | 192 ASSERT_EQ(OK, cb.GetResult(rv)); |
193 | 193 |
194 // RESPONSE_INFO_TRUNCATED defined on response_info.cc | 194 // RESPONSE_INFO_TRUNCATED defined on response_info.cc |
195 int flags = 1 << 12; | 195 int flags = 1 << 12; |
196 WriteHeaders(entry, flags, "something"); | 196 WriteHeaders(entry, flags, "something"); |
197 entry->Close(); | 197 entry->Close(); |
198 | 198 |
199 std::string data; | 199 std::string data; |
200 rv = helper.GetEntryInfoHTML(key, context, &data, &cb); | 200 TestCompletionCallback cb1; |
201 EXPECT_EQ(OK, cb.GetResult(rv)); | 201 rv = helper.GetEntryInfoHTML(key, context, &data, cb1.callback()); |
| 202 EXPECT_EQ(OK, cb1.GetResult(rv)); |
202 | 203 |
203 EXPECT_NE(std::string::npos, data.find("RESPONSE_INFO_TRUNCATED")); | 204 EXPECT_NE(std::string::npos, data.find("RESPONSE_INFO_TRUNCATED")); |
204 } | 205 } |
205 | 206 |
206 } // namespace net | 207 } // namespace net |
OLD | NEW |