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/cookies/cookie_store_unittest.h" | 5 #include "net/cookies/cookie_store_unittest.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 base::Time(), false, false)); | 226 base::Time(), false, false)); |
227 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_2, | 227 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_2, |
228 "dom_2", "X", ".math.harvard.edu", | 228 "dom_2", "X", ".math.harvard.edu", |
229 "/", base::Time(), false, false)); | 229 "/", base::Time(), false, false)); |
230 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_3, | 230 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_3, |
231 "dom_3", "X", | 231 "dom_3", "X", |
232 ".bourbaki.math.harvard.edu", "/", | 232 ".bourbaki.math.harvard.edu", "/", |
233 base::Time(), false, false)); | 233 base::Time(), false, false)); |
234 | 234 |
235 // Host cookies | 235 // Host cookies |
236 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_1, | 236 EXPECT_TRUE(this->SetCookieWithDetails(cm, |
237 "host_1", "X", "", "/", | 237 url_top_level_domain_plus_1, |
238 base::Time(), false, false)); | 238 "host_1", |
239 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_2, | 239 "X", |
240 "host_2", "X", "", "/", | 240 std::string(), |
241 base::Time(), false, false)); | 241 "/", |
242 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_3, | 242 base::Time(), |
243 "host_3", "X", "", "/", | 243 false, |
244 base::Time(), false, false)); | 244 false)); |
| 245 EXPECT_TRUE(this->SetCookieWithDetails(cm, |
| 246 url_top_level_domain_plus_2, |
| 247 "host_2", |
| 248 "X", |
| 249 std::string(), |
| 250 "/", |
| 251 base::Time(), |
| 252 false, |
| 253 false)); |
| 254 EXPECT_TRUE(this->SetCookieWithDetails(cm, |
| 255 url_top_level_domain_plus_3, |
| 256 "host_3", |
| 257 "X", |
| 258 std::string(), |
| 259 "/", |
| 260 base::Time(), |
| 261 false, |
| 262 false)); |
245 | 263 |
246 // Http_only cookie | 264 // Http_only cookie |
247 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_2, | 265 EXPECT_TRUE(this->SetCookieWithDetails(cm, |
248 "httpo_check", "X", "", "/", | 266 url_top_level_domain_plus_2, |
249 base::Time(), false, true)); | 267 "httpo_check", |
| 268 "X", |
| 269 std::string(), |
| 270 "/", |
| 271 base::Time(), |
| 272 false, |
| 273 true)); |
250 | 274 |
251 // Secure cookies | 275 // Secure cookies |
252 EXPECT_TRUE(this->SetCookieWithDetails(cm, | 276 EXPECT_TRUE(this->SetCookieWithDetails(cm, |
253 url_top_level_domain_plus_2_secure, | 277 url_top_level_domain_plus_2_secure, |
254 "sec_dom", "X", ".math.harvard.edu", | 278 "sec_dom", "X", ".math.harvard.edu", |
255 "/", base::Time(), true, false)); | 279 "/", base::Time(), true, false)); |
256 EXPECT_TRUE(this->SetCookieWithDetails(cm, | 280 EXPECT_TRUE(this->SetCookieWithDetails(cm, |
257 url_top_level_domain_plus_2_secure, | 281 url_top_level_domain_plus_2_secure, |
258 "sec_host", "X", "", "/", | 282 "sec_host", |
259 base::Time(), true, false)); | 283 "X", |
| 284 std::string(), |
| 285 "/", |
| 286 base::Time(), |
| 287 true, |
| 288 false)); |
260 | 289 |
261 // Domain path cookies | 290 // Domain path cookies |
262 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_2, | 291 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_2, |
263 "dom_path_1", "X", | 292 "dom_path_1", "X", |
264 ".math.harvard.edu", "/dir1", | 293 ".math.harvard.edu", "/dir1", |
265 base::Time(), false, false)); | 294 base::Time(), false, false)); |
266 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_2, | 295 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_2, |
267 "dom_path_2", "X", | 296 "dom_path_2", "X", |
268 ".math.harvard.edu", "/dir1/dir2", | 297 ".math.harvard.edu", "/dir1/dir2", |
269 base::Time(), false, false)); | 298 base::Time(), false, false)); |
270 | 299 |
271 // Host path cookies | 300 // Host path cookies |
272 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_2, | 301 EXPECT_TRUE(this->SetCookieWithDetails(cm, |
273 "host_path_1", "X", | 302 url_top_level_domain_plus_2, |
274 "", "/dir1", | 303 "host_path_1", |
275 base::Time(), false, false)); | 304 "X", |
276 EXPECT_TRUE(this->SetCookieWithDetails(cm, url_top_level_domain_plus_2, | 305 std::string(), |
277 "host_path_2", "X", | 306 "/dir1", |
278 "", "/dir1/dir2", | 307 base::Time(), |
279 base::Time(), false, false)); | 308 false, |
| 309 false)); |
| 310 EXPECT_TRUE(this->SetCookieWithDetails(cm, |
| 311 url_top_level_domain_plus_2, |
| 312 "host_path_2", |
| 313 "X", |
| 314 std::string(), |
| 315 "/dir1/dir2", |
| 316 base::Time(), |
| 317 false, |
| 318 false)); |
280 | 319 |
281 EXPECT_EQ(13U, this->GetAllCookies(cm).size()); | 320 EXPECT_EQ(13U, this->GetAllCookies(cm).size()); |
282 } | 321 } |
283 | 322 |
284 Time GetFirstCookieAccessDate(CookieMonster* cm) { | 323 Time GetFirstCookieAccessDate(CookieMonster* cm) { |
285 const CookieList all_cookies(this->GetAllCookies(cm)); | 324 const CookieList all_cookies(this->GetAllCookies(cm)); |
286 return all_cookies.front().LastAccessDate(); | 325 return all_cookies.front().LastAccessDate(); |
287 } | 326 } |
288 | 327 |
289 bool FindAndDeleteCookie(CookieMonster* cm, | 328 bool FindAndDeleteCookie(CookieMonster* cm, |
(...skipping 1908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2198 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 2237 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
2199 | 2238 |
2200 // Add a cookie. | 2239 // Add a cookie. |
2201 EXPECT_TRUE(SetCookie(cm, url_google_, | 2240 EXPECT_TRUE(SetCookie(cm, url_google_, |
2202 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 2241 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
2203 this->MatchCookieLines("A=B", GetCookies(cm, url_google_)); | 2242 this->MatchCookieLines("A=B", GetCookies(cm, url_google_)); |
2204 ASSERT_EQ(1u, store->commands().size()); | 2243 ASSERT_EQ(1u, store->commands().size()); |
2205 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 2244 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
2206 // Remove it. | 2245 // Remove it. |
2207 EXPECT_TRUE(SetCookie(cm, url_google_,"A=B; max-age=0")); | 2246 EXPECT_TRUE(SetCookie(cm, url_google_,"A=B; max-age=0")); |
2208 this->MatchCookieLines("", GetCookies(cm, url_google_)); | 2247 this->MatchCookieLines(std::string(), GetCookies(cm, url_google_)); |
2209 ASSERT_EQ(2u, store->commands().size()); | 2248 ASSERT_EQ(2u, store->commands().size()); |
2210 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 2249 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
2211 | 2250 |
2212 // Add a cookie. | 2251 // Add a cookie. |
2213 EXPECT_TRUE(SetCookie(cm, url_google_, | 2252 EXPECT_TRUE(SetCookie(cm, url_google_, |
2214 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 2253 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
2215 this->MatchCookieLines("A=B", GetCookies(cm, url_google_)); | 2254 this->MatchCookieLines("A=B", GetCookies(cm, url_google_)); |
2216 ASSERT_EQ(3u, store->commands().size()); | 2255 ASSERT_EQ(3u, store->commands().size()); |
2217 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); | 2256 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); |
2218 // Overwrite it. | 2257 // Overwrite it. |
2219 EXPECT_TRUE(SetCookie(cm, url_google_, | 2258 EXPECT_TRUE(SetCookie(cm, url_google_, |
2220 "A=Foo; expires=Mon, 18-Apr-22 22:50:14 GMT")); | 2259 "A=Foo; expires=Mon, 18-Apr-22 22:50:14 GMT")); |
2221 this->MatchCookieLines("A=Foo", GetCookies(cm, url_google_)); | 2260 this->MatchCookieLines("A=Foo", GetCookies(cm, url_google_)); |
2222 ASSERT_EQ(5u, store->commands().size()); | 2261 ASSERT_EQ(5u, store->commands().size()); |
2223 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); | 2262 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
2224 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); | 2263 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); |
2225 | 2264 |
2226 // Create some non-persistent cookies and check that they don't go to the | 2265 // Create some non-persistent cookies and check that they don't go to the |
2227 // persistent storage. | 2266 // persistent storage. |
2228 EXPECT_TRUE(SetCookie(cm, url_google_, "B=Bar")); | 2267 EXPECT_TRUE(SetCookie(cm, url_google_, "B=Bar")); |
2229 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm, url_google_)); | 2268 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm, url_google_)); |
2230 EXPECT_EQ(5u, store->commands().size()); | 2269 EXPECT_EQ(5u, store->commands().size()); |
2231 } | 2270 } |
2232 | 2271 |
2233 } // namespace net | 2272 } // namespace net |
OLD | NEW |