| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <time.h> | 5 #include <time.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/platform_thread.h" | 10 #include "base/platform_thread.h" |
| 11 #include "base/ref_counted.h" |
| 11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 12 #include "base/time.h" | 13 #include "base/time.h" |
| 13 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 14 #include "net/base/cookie_monster.h" | 15 #include "net/base/cookie_monster.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 using base::Time; | 18 using base::Time; |
| 18 using base::TimeDelta; | 19 using base::TimeDelta; |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 239 |
| 239 static const char kUrlGoogle[] = "http://www.google.izzle"; | 240 static const char kUrlGoogle[] = "http://www.google.izzle"; |
| 240 static const char kUrlGoogleSecure[] = "https://www.google.izzle"; | 241 static const char kUrlGoogleSecure[] = "https://www.google.izzle"; |
| 241 static const char kUrlFtp[] = "ftp://ftp.google.izzle/"; | 242 static const char kUrlFtp[] = "ftp://ftp.google.izzle/"; |
| 242 static const char kValidCookieLine[] = "A=B; path=/"; | 243 static const char kValidCookieLine[] = "A=B; path=/"; |
| 243 static const char kValidDomainCookieLine[] = "A=B; path=/; domain=google.izzle"; | 244 static const char kValidDomainCookieLine[] = "A=B; path=/; domain=google.izzle"; |
| 244 | 245 |
| 245 TEST(CookieMonsterTest, DomainTest) { | 246 TEST(CookieMonsterTest, DomainTest) { |
| 246 GURL url_google(kUrlGoogle); | 247 GURL url_google(kUrlGoogle); |
| 247 | 248 |
| 248 net::CookieMonster cm; | 249 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 249 EXPECT_TRUE(cm.SetCookie(url_google, "A=B")); | 250 EXPECT_TRUE(cm->SetCookie(url_google, "A=B")); |
| 250 EXPECT_EQ("A=B", cm.GetCookies(url_google)); | 251 EXPECT_EQ("A=B", cm->GetCookies(url_google)); |
| 251 EXPECT_TRUE(cm.SetCookie(url_google, "C=D; domain=.google.izzle")); | 252 EXPECT_TRUE(cm->SetCookie(url_google, "C=D; domain=.google.izzle")); |
| 252 EXPECT_EQ("A=B; C=D", cm.GetCookies(url_google)); | 253 EXPECT_EQ("A=B; C=D", cm->GetCookies(url_google)); |
| 253 | 254 |
| 254 // Verify that A=B was set as a host cookie rather than a domain | 255 // Verify that A=B was set as a host cookie rather than a domain |
| 255 // cookie -- should not be accessible from a sub sub-domain. | 256 // cookie -- should not be accessible from a sub sub-domain. |
| 256 EXPECT_EQ("C=D", cm.GetCookies(GURL("http://foo.www.google.izzle"))); | 257 EXPECT_EQ("C=D", cm->GetCookies(GURL("http://foo.www.google.izzle"))); |
| 257 | 258 |
| 258 // Test and make sure we find domain cookies on the same domain. | 259 // Test and make sure we find domain cookies on the same domain. |
| 259 EXPECT_TRUE(cm.SetCookie(url_google, "E=F; domain=.www.google.izzle")); | 260 EXPECT_TRUE(cm->SetCookie(url_google, "E=F; domain=.www.google.izzle")); |
| 260 EXPECT_EQ("A=B; C=D; E=F", cm.GetCookies(url_google)); | 261 EXPECT_EQ("A=B; C=D; E=F", cm->GetCookies(url_google)); |
| 261 | 262 |
| 262 // Test setting a domain= that doesn't start w/ a dot, should | 263 // Test setting a domain= that doesn't start w/ a dot, should |
| 263 // treat it as a domain cookie, as if there was a pre-pended dot. | 264 // treat it as a domain cookie, as if there was a pre-pended dot. |
| 264 EXPECT_TRUE(cm.SetCookie(url_google, "G=H; domain=www.google.izzle")); | 265 EXPECT_TRUE(cm->SetCookie(url_google, "G=H; domain=www.google.izzle")); |
| 265 EXPECT_EQ("A=B; C=D; E=F; G=H", cm.GetCookies(url_google)); | 266 EXPECT_EQ("A=B; C=D; E=F; G=H", cm->GetCookies(url_google)); |
| 266 | 267 |
| 267 // Test domain enforcement, should fail on a sub-domain or something too deep. | 268 // Test domain enforcement, should fail on a sub-domain or something too deep. |
| 268 EXPECT_FALSE(cm.SetCookie(url_google, "I=J; domain=.izzle")); | 269 EXPECT_FALSE(cm->SetCookie(url_google, "I=J; domain=.izzle")); |
| 269 EXPECT_EQ("", cm.GetCookies(GURL("http://a.izzle"))); | 270 EXPECT_EQ("", cm->GetCookies(GURL("http://a.izzle"))); |
| 270 EXPECT_FALSE(cm.SetCookie(url_google, "K=L; domain=.bla.www.google.izzle")); | 271 EXPECT_FALSE(cm->SetCookie(url_google, "K=L; domain=.bla.www.google.izzle")); |
| 271 EXPECT_EQ("C=D; E=F; G=H", | 272 EXPECT_EQ("C=D; E=F; G=H", |
| 272 cm.GetCookies(GURL("http://bla.www.google.izzle"))); | 273 cm->GetCookies(GURL("http://bla.www.google.izzle"))); |
| 273 EXPECT_EQ("A=B; C=D; E=F; G=H", cm.GetCookies(url_google)); | 274 EXPECT_EQ("A=B; C=D; E=F; G=H", cm->GetCookies(url_google)); |
| 274 } | 275 } |
| 275 | 276 |
| 276 // FireFox recognizes domains containing trailing periods as valid. | 277 // FireFox recognizes domains containing trailing periods as valid. |
| 277 // IE and Safari do not. Assert the expected policy here. | 278 // IE and Safari do not. Assert the expected policy here. |
| 278 TEST(CookieMonsterTest, DomainWithTrailingDotTest) { | 279 TEST(CookieMonsterTest, DomainWithTrailingDotTest) { |
| 279 net::CookieMonster cm; | 280 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 280 GURL url_google("http://www.google.com"); | 281 GURL url_google("http://www.google.com"); |
| 281 | 282 |
| 282 EXPECT_FALSE(cm.SetCookie(url_google, "a=1; domain=.www.google.com.")); | 283 EXPECT_FALSE(cm->SetCookie(url_google, "a=1; domain=.www.google.com.")); |
| 283 EXPECT_FALSE(cm.SetCookie(url_google, "b=2; domain=.www.google.com..")); | 284 EXPECT_FALSE(cm->SetCookie(url_google, "b=2; domain=.www.google.com..")); |
| 284 EXPECT_EQ("", cm.GetCookies(url_google)); | 285 EXPECT_EQ("", cm->GetCookies(url_google)); |
| 285 } | 286 } |
| 286 | 287 |
| 287 // Test that cookies can bet set on higher level domains. | 288 // Test that cookies can bet set on higher level domains. |
| 288 // http://b/issue?id=896491 | 289 // http://b/issue?id=896491 |
| 289 TEST(CookieMonsterTest, ValidSubdomainTest) { | 290 TEST(CookieMonsterTest, ValidSubdomainTest) { |
| 290 net::CookieMonster cm; | 291 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 291 GURL url_abcd("http://a.b.c.d.com"); | 292 GURL url_abcd("http://a.b.c.d.com"); |
| 292 GURL url_bcd("http://b.c.d.com"); | 293 GURL url_bcd("http://b.c.d.com"); |
| 293 GURL url_cd("http://c.d.com"); | 294 GURL url_cd("http://c.d.com"); |
| 294 GURL url_d("http://d.com"); | 295 GURL url_d("http://d.com"); |
| 295 | 296 |
| 296 EXPECT_TRUE(cm.SetCookie(url_abcd, "a=1; domain=.a.b.c.d.com")); | 297 EXPECT_TRUE(cm->SetCookie(url_abcd, "a=1; domain=.a.b.c.d.com")); |
| 297 EXPECT_TRUE(cm.SetCookie(url_abcd, "b=2; domain=.b.c.d.com")); | 298 EXPECT_TRUE(cm->SetCookie(url_abcd, "b=2; domain=.b.c.d.com")); |
| 298 EXPECT_TRUE(cm.SetCookie(url_abcd, "c=3; domain=.c.d.com")); | 299 EXPECT_TRUE(cm->SetCookie(url_abcd, "c=3; domain=.c.d.com")); |
| 299 EXPECT_TRUE(cm.SetCookie(url_abcd, "d=4; domain=.d.com")); | 300 EXPECT_TRUE(cm->SetCookie(url_abcd, "d=4; domain=.d.com")); |
| 300 | 301 |
| 301 EXPECT_EQ("a=1; b=2; c=3; d=4", cm.GetCookies(url_abcd)); | 302 EXPECT_EQ("a=1; b=2; c=3; d=4", cm->GetCookies(url_abcd)); |
| 302 EXPECT_EQ("b=2; c=3; d=4", cm.GetCookies(url_bcd)); | 303 EXPECT_EQ("b=2; c=3; d=4", cm->GetCookies(url_bcd)); |
| 303 EXPECT_EQ("c=3; d=4", cm.GetCookies(url_cd)); | 304 EXPECT_EQ("c=3; d=4", cm->GetCookies(url_cd)); |
| 304 EXPECT_EQ("d=4", cm.GetCookies(url_d)); | 305 EXPECT_EQ("d=4", cm->GetCookies(url_d)); |
| 305 | 306 |
| 306 // Check that the same cookie can exist on different sub-domains. | 307 // Check that the same cookie can exist on different sub-domains. |
| 307 EXPECT_TRUE(cm.SetCookie(url_bcd, "X=bcd; domain=.b.c.d.com")); | 308 EXPECT_TRUE(cm->SetCookie(url_bcd, "X=bcd; domain=.b.c.d.com")); |
| 308 EXPECT_TRUE(cm.SetCookie(url_bcd, "X=cd; domain=.c.d.com")); | 309 EXPECT_TRUE(cm->SetCookie(url_bcd, "X=cd; domain=.c.d.com")); |
| 309 EXPECT_EQ("b=2; c=3; d=4; X=bcd; X=cd", cm.GetCookies(url_bcd)); | 310 EXPECT_EQ("b=2; c=3; d=4; X=bcd; X=cd", cm->GetCookies(url_bcd)); |
| 310 EXPECT_EQ("c=3; d=4; X=cd", cm.GetCookies(url_cd)); | 311 EXPECT_EQ("c=3; d=4; X=cd", cm->GetCookies(url_cd)); |
| 311 } | 312 } |
| 312 | 313 |
| 313 // Test that setting a cookie which specifies an invalid domain has | 314 // Test that setting a cookie which specifies an invalid domain has |
| 314 // no side-effect. An invalid domain in this context is one which does | 315 // no side-effect. An invalid domain in this context is one which does |
| 315 // not match the originating domain. | 316 // not match the originating domain. |
| 316 // http://b/issue?id=896472 | 317 // http://b/issue?id=896472 |
| 317 TEST(CookieMonsterTest, InvalidDomainTest) { | 318 TEST(CookieMonsterTest, InvalidDomainTest) { |
| 318 { | 319 { |
| 319 net::CookieMonster cm; | 320 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 320 GURL url_foobar("http://foo.bar.com"); | 321 GURL url_foobar("http://foo.bar.com"); |
| 321 | 322 |
| 322 // More specific sub-domain than allowed. | 323 // More specific sub-domain than allowed. |
| 323 EXPECT_FALSE(cm.SetCookie(url_foobar, "a=1; domain=.yo.foo.bar.com")); | 324 EXPECT_FALSE(cm->SetCookie(url_foobar, "a=1; domain=.yo.foo.bar.com")); |
| 324 | 325 |
| 325 EXPECT_FALSE(cm.SetCookie(url_foobar, "b=2; domain=.foo.com")); | 326 EXPECT_FALSE(cm->SetCookie(url_foobar, "b=2; domain=.foo.com")); |
| 326 EXPECT_FALSE(cm.SetCookie(url_foobar, "c=3; domain=.bar.foo.com")); | 327 EXPECT_FALSE(cm->SetCookie(url_foobar, "c=3; domain=.bar.foo.com")); |
| 327 | 328 |
| 328 // Different TLD, but the rest is a substring. | 329 // Different TLD, but the rest is a substring. |
| 329 EXPECT_FALSE(cm.SetCookie(url_foobar, "d=4; domain=.foo.bar.com.net")); | 330 EXPECT_FALSE(cm->SetCookie(url_foobar, "d=4; domain=.foo.bar.com.net")); |
| 330 | 331 |
| 331 // A substring that isn't really a parent domain. | 332 // A substring that isn't really a parent domain. |
| 332 EXPECT_FALSE(cm.SetCookie(url_foobar, "e=5; domain=ar.com")); | 333 EXPECT_FALSE(cm->SetCookie(url_foobar, "e=5; domain=ar.com")); |
| 333 | 334 |
| 334 // Completely invalid domains: | 335 // Completely invalid domains: |
| 335 EXPECT_FALSE(cm.SetCookie(url_foobar, "f=6; domain=.")); | 336 EXPECT_FALSE(cm->SetCookie(url_foobar, "f=6; domain=.")); |
| 336 EXPECT_FALSE(cm.SetCookie(url_foobar, "g=7; domain=/")); | 337 EXPECT_FALSE(cm->SetCookie(url_foobar, "g=7; domain=/")); |
| 337 EXPECT_FALSE(cm.SetCookie(url_foobar, "h=8; domain=http://foo.bar.com")); | 338 EXPECT_FALSE(cm->SetCookie(url_foobar, "h=8; domain=http://foo.bar.com")); |
| 338 EXPECT_FALSE(cm.SetCookie(url_foobar, "i=9; domain=..foo.bar.com")); | 339 EXPECT_FALSE(cm->SetCookie(url_foobar, "i=9; domain=..foo.bar.com")); |
| 339 EXPECT_FALSE(cm.SetCookie(url_foobar, "j=10; domain=..bar.com")); | 340 EXPECT_FALSE(cm->SetCookie(url_foobar, "j=10; domain=..bar.com")); |
| 340 | 341 |
| 341 // Make sure there isn't something quirky in the domain canonicalization | 342 // Make sure there isn't something quirky in the domain canonicalization |
| 342 // that supports full URL semantics. | 343 // that supports full URL semantics. |
| 343 EXPECT_FALSE(cm.SetCookie(url_foobar, "k=11; domain=.foo.bar.com?blah")); | 344 EXPECT_FALSE(cm->SetCookie(url_foobar, "k=11; domain=.foo.bar.com?blah")); |
| 344 EXPECT_FALSE(cm.SetCookie(url_foobar, "l=12; domain=.foo.bar.com/blah")); | 345 EXPECT_FALSE(cm->SetCookie(url_foobar, "l=12; domain=.foo.bar.com/blah")); |
| 345 EXPECT_FALSE(cm.SetCookie(url_foobar, "m=13; domain=.foo.bar.com:80")); | 346 EXPECT_FALSE(cm->SetCookie(url_foobar, "m=13; domain=.foo.bar.com:80")); |
| 346 EXPECT_FALSE(cm.SetCookie(url_foobar, "n=14; domain=.foo.bar.com:")); | 347 EXPECT_FALSE(cm->SetCookie(url_foobar, "n=14; domain=.foo.bar.com:")); |
| 347 EXPECT_FALSE(cm.SetCookie(url_foobar, "o=15; domain=.foo.bar.com#sup")); | 348 EXPECT_FALSE(cm->SetCookie(url_foobar, "o=15; domain=.foo.bar.com#sup")); |
| 348 | 349 |
| 349 EXPECT_EQ("", cm.GetCookies(url_foobar)); | 350 EXPECT_EQ("", cm->GetCookies(url_foobar)); |
| 350 } | 351 } |
| 351 | 352 |
| 352 { | 353 { |
| 353 // Make sure the cookie code hasn't gotten its subdomain string handling | 354 // Make sure the cookie code hasn't gotten its subdomain string handling |
| 354 // reversed, missed a suffix check, etc. It's important here that the two | 355 // reversed, missed a suffix check, etc. It's important here that the two |
| 355 // hosts below have the same domain + registry. | 356 // hosts below have the same domain + registry. |
| 356 net::CookieMonster cm; | 357 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 357 GURL url_foocom("http://foo.com.com"); | 358 GURL url_foocom("http://foo.com.com"); |
| 358 EXPECT_FALSE(cm.SetCookie(url_foocom, "a=1; domain=.foo.com.com.com")); | 359 EXPECT_FALSE(cm->SetCookie(url_foocom, "a=1; domain=.foo.com.com.com")); |
| 359 EXPECT_EQ("", cm.GetCookies(url_foocom)); | 360 EXPECT_EQ("", cm->GetCookies(url_foocom)); |
| 360 } | 361 } |
| 361 } | 362 } |
| 362 | 363 |
| 363 // Test the behavior of omitting dot prefix from domain, should | 364 // Test the behavior of omitting dot prefix from domain, should |
| 364 // function the same as FireFox. | 365 // function the same as FireFox. |
| 365 // http://b/issue?id=889898 | 366 // http://b/issue?id=889898 |
| 366 TEST(CookieMonsterTest, DomainWithoutLeadingDotTest) { | 367 TEST(CookieMonsterTest, DomainWithoutLeadingDotTest) { |
| 367 { // The omission of dot results in setting a domain cookie. | 368 { // The omission of dot results in setting a domain cookie. |
| 368 net::CookieMonster cm; | 369 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 369 GURL url_hosted("http://manage.hosted.filefront.com"); | 370 GURL url_hosted("http://manage.hosted.filefront.com"); |
| 370 GURL url_filefront("http://www.filefront.com"); | 371 GURL url_filefront("http://www.filefront.com"); |
| 371 EXPECT_TRUE(cm.SetCookie(url_hosted, "sawAd=1; domain=filefront.com")); | 372 EXPECT_TRUE(cm->SetCookie(url_hosted, "sawAd=1; domain=filefront.com")); |
| 372 EXPECT_EQ("sawAd=1", cm.GetCookies(url_hosted)); | 373 EXPECT_EQ("sawAd=1", cm->GetCookies(url_hosted)); |
| 373 EXPECT_EQ("sawAd=1", cm.GetCookies(url_filefront)); | 374 EXPECT_EQ("sawAd=1", cm->GetCookies(url_filefront)); |
| 374 } | 375 } |
| 375 | 376 |
| 376 { // Even when the domains match exactly, don't consider it host cookie. | 377 { // Even when the domains match exactly, don't consider it host cookie. |
| 377 net::CookieMonster cm; | 378 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 378 GURL url("http://www.google.com"); | 379 GURL url("http://www.google.com"); |
| 379 EXPECT_TRUE(cm.SetCookie(url, "a=1; domain=www.google.com")); | 380 EXPECT_TRUE(cm->SetCookie(url, "a=1; domain=www.google.com")); |
| 380 EXPECT_EQ("a=1", cm.GetCookies(url)); | 381 EXPECT_EQ("a=1", cm->GetCookies(url)); |
| 381 EXPECT_EQ("a=1", cm.GetCookies(GURL("http://sub.www.google.com"))); | 382 EXPECT_EQ("a=1", cm->GetCookies(GURL("http://sub.www.google.com"))); |
| 382 EXPECT_EQ("", cm.GetCookies(GURL("http://something-else.com"))); | 383 EXPECT_EQ("", cm->GetCookies(GURL("http://something-else.com"))); |
| 383 } | 384 } |
| 384 } | 385 } |
| 385 | 386 |
| 386 // Test that the domain specified in cookie string is treated case-insensitive | 387 // Test that the domain specified in cookie string is treated case-insensitive |
| 387 // http://b/issue?id=896475. | 388 // http://b/issue?id=896475. |
| 388 TEST(CookieMonsterTest, CaseInsensitiveDomainTest) { | 389 TEST(CookieMonsterTest, CaseInsensitiveDomainTest) { |
| 389 net::CookieMonster cm; | 390 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 390 GURL url_google("http://www.google.com"); | 391 GURL url_google("http://www.google.com"); |
| 391 EXPECT_TRUE(cm.SetCookie(url_google, "a=1; domain=.GOOGLE.COM")); | 392 EXPECT_TRUE(cm->SetCookie(url_google, "a=1; domain=.GOOGLE.COM")); |
| 392 EXPECT_TRUE(cm.SetCookie(url_google, "b=2; domain=.wWw.gOOgLE.coM")); | 393 EXPECT_TRUE(cm->SetCookie(url_google, "b=2; domain=.wWw.gOOgLE.coM")); |
| 393 EXPECT_EQ("a=1; b=2", cm.GetCookies(url_google)); | 394 EXPECT_EQ("a=1; b=2", cm->GetCookies(url_google)); |
| 394 } | 395 } |
| 395 | 396 |
| 396 TEST(CookieMonsterTest, TestIpAddress) { | 397 TEST(CookieMonsterTest, TestIpAddress) { |
| 397 GURL url_ip("http://1.2.3.4/weee"); | 398 GURL url_ip("http://1.2.3.4/weee"); |
| 398 { | 399 { |
| 399 net::CookieMonster cm; | 400 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 400 EXPECT_TRUE(cm.SetCookie(url_ip, kValidCookieLine)); | 401 EXPECT_TRUE(cm->SetCookie(url_ip, kValidCookieLine)); |
| 401 EXPECT_EQ("A=B", cm.GetCookies(url_ip)); | 402 EXPECT_EQ("A=B", cm->GetCookies(url_ip)); |
| 402 } | 403 } |
| 403 | 404 |
| 404 { // IP addresses should not be able to set domain cookies. | 405 { // IP addresses should not be able to set domain cookies. |
| 405 net::CookieMonster cm; | 406 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 406 EXPECT_FALSE(cm.SetCookie(url_ip, "b=2; domain=.1.2.3.4")); | 407 EXPECT_FALSE(cm->SetCookie(url_ip, "b=2; domain=.1.2.3.4")); |
| 407 EXPECT_FALSE(cm.SetCookie(url_ip, "c=3; domain=.3.4")); | 408 EXPECT_FALSE(cm->SetCookie(url_ip, "c=3; domain=.3.4")); |
| 408 EXPECT_EQ("", cm.GetCookies(url_ip)); | 409 EXPECT_EQ("", cm->GetCookies(url_ip)); |
| 409 // It should be allowed to set a cookie if domain= matches the IP address | 410 // It should be allowed to set a cookie if domain= matches the IP address |
| 410 // exactly. This matches IE/Firefox, even though it seems a bit wrong. | 411 // exactly. This matches IE/Firefox, even though it seems a bit wrong. |
| 411 EXPECT_FALSE(cm.SetCookie(url_ip, "b=2; domain=1.2.3.3")); | 412 EXPECT_FALSE(cm->SetCookie(url_ip, "b=2; domain=1.2.3.3")); |
| 412 EXPECT_EQ("", cm.GetCookies(url_ip)); | 413 EXPECT_EQ("", cm->GetCookies(url_ip)); |
| 413 EXPECT_TRUE(cm.SetCookie(url_ip, "b=2; domain=1.2.3.4")); | 414 EXPECT_TRUE(cm->SetCookie(url_ip, "b=2; domain=1.2.3.4")); |
| 414 EXPECT_EQ("b=2", cm.GetCookies(url_ip)); | 415 EXPECT_EQ("b=2", cm->GetCookies(url_ip)); |
| 415 } | 416 } |
| 416 } | 417 } |
| 417 | 418 |
| 418 // Test host cookies, and setting of cookies on TLD. | 419 // Test host cookies, and setting of cookies on TLD. |
| 419 TEST(CookieMonsterTest, TestNonDottedAndTLD) { | 420 TEST(CookieMonsterTest, TestNonDottedAndTLD) { |
| 420 { | 421 { |
| 421 net::CookieMonster cm; | 422 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 422 GURL url("http://com/"); | 423 GURL url("http://com/"); |
| 423 // Allow setting on "com", (but only as a host cookie). | 424 // Allow setting on "com", (but only as a host cookie). |
| 424 EXPECT_TRUE(cm.SetCookie(url, "a=1")); | 425 EXPECT_TRUE(cm->SetCookie(url, "a=1")); |
| 425 EXPECT_FALSE(cm.SetCookie(url, "b=2; domain=.com")); | 426 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.com")); |
| 426 EXPECT_FALSE(cm.SetCookie(url, "c=3; domain=com")); | 427 EXPECT_FALSE(cm->SetCookie(url, "c=3; domain=com")); |
| 427 EXPECT_EQ("a=1", cm.GetCookies(url)); | 428 EXPECT_EQ("a=1", cm->GetCookies(url)); |
| 428 // Make sure it doesn't show up for a normal .com, it should be a host | 429 // Make sure it doesn't show up for a normal .com, it should be a host |
| 429 // not a domain cookie. | 430 // not a domain cookie. |
| 430 EXPECT_EQ("", cm.GetCookies(GURL("http://hopefully-no-cookies.com/"))); | 431 EXPECT_EQ("", cm->GetCookies(GURL("http://hopefully-no-cookies.com/"))); |
| 431 EXPECT_EQ("", cm.GetCookies(GURL("http://.com/"))); | 432 EXPECT_EQ("", cm->GetCookies(GURL("http://.com/"))); |
| 432 } | 433 } |
| 433 | 434 |
| 434 { // http://com. should be treated the same as http://com. | 435 { // http://com. should be treated the same as http://com. |
| 435 net::CookieMonster cm; | 436 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 436 GURL url("http://com./index.html"); | 437 GURL url("http://com./index.html"); |
| 437 EXPECT_TRUE(cm.SetCookie(url, "a=1")); | 438 EXPECT_TRUE(cm->SetCookie(url, "a=1")); |
| 438 EXPECT_EQ("a=1", cm.GetCookies(url)); | 439 EXPECT_EQ("a=1", cm->GetCookies(url)); |
| 439 EXPECT_EQ("", cm.GetCookies(GURL("http://hopefully-no-cookies.com./"))); | 440 EXPECT_EQ("", cm->GetCookies(GURL("http://hopefully-no-cookies.com./"))); |
| 440 } | 441 } |
| 441 | 442 |
| 442 { // Should not be able to set host cookie from a subdomain. | 443 { // Should not be able to set host cookie from a subdomain. |
| 443 net::CookieMonster cm; | 444 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 444 GURL url("http://a.b"); | 445 GURL url("http://a.b"); |
| 445 EXPECT_FALSE(cm.SetCookie(url, "a=1; domain=.b")); | 446 EXPECT_FALSE(cm->SetCookie(url, "a=1; domain=.b")); |
| 446 EXPECT_FALSE(cm.SetCookie(url, "b=2; domain=b")); | 447 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=b")); |
| 447 EXPECT_EQ("", cm.GetCookies(url)); | 448 EXPECT_EQ("", cm->GetCookies(url)); |
| 448 } | 449 } |
| 449 | 450 |
| 450 { // Same test as above, but explicitly on a known TLD (com). | 451 { // Same test as above, but explicitly on a known TLD (com). |
| 451 net::CookieMonster cm; | 452 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 452 GURL url("http://google.com"); | 453 GURL url("http://google.com"); |
| 453 EXPECT_FALSE(cm.SetCookie(url, "a=1; domain=.com")); | 454 EXPECT_FALSE(cm->SetCookie(url, "a=1; domain=.com")); |
| 454 EXPECT_FALSE(cm.SetCookie(url, "b=2; domain=com")); | 455 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=com")); |
| 455 EXPECT_EQ("", cm.GetCookies(url)); | 456 EXPECT_EQ("", cm->GetCookies(url)); |
| 456 } | 457 } |
| 457 | 458 |
| 458 { // Make sure can't set cookie on TLD which is dotted. | 459 { // Make sure can't set cookie on TLD which is dotted. |
| 459 net::CookieMonster cm; | 460 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 460 GURL url("http://google.co.uk"); | 461 GURL url("http://google.co.uk"); |
| 461 EXPECT_FALSE(cm.SetCookie(url, "a=1; domain=.co.uk")); | 462 EXPECT_FALSE(cm->SetCookie(url, "a=1; domain=.co.uk")); |
| 462 EXPECT_FALSE(cm.SetCookie(url, "b=2; domain=.uk")); | 463 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.uk")); |
| 463 EXPECT_EQ("", cm.GetCookies(url)); | 464 EXPECT_EQ("", cm->GetCookies(url)); |
| 464 EXPECT_EQ("", cm.GetCookies(GURL("http://something-else.co.uk"))); | 465 EXPECT_EQ("", cm->GetCookies(GURL("http://something-else.co.uk"))); |
| 465 EXPECT_EQ("", cm.GetCookies(GURL("http://something-else.uk"))); | 466 EXPECT_EQ("", cm->GetCookies(GURL("http://something-else.uk"))); |
| 466 } | 467 } |
| 467 | 468 |
| 468 { // Intranet URLs should only be able to set host cookies. | 469 { // Intranet URLs should only be able to set host cookies. |
| 469 net::CookieMonster cm; | 470 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 470 GURL url("http://b"); | 471 GURL url("http://b"); |
| 471 EXPECT_TRUE(cm.SetCookie(url, "a=1")); | 472 EXPECT_TRUE(cm->SetCookie(url, "a=1")); |
| 472 EXPECT_FALSE(cm.SetCookie(url, "b=2; domain=.b")); | 473 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.b")); |
| 473 EXPECT_FALSE(cm.SetCookie(url, "c=3; domain=b")); | 474 EXPECT_FALSE(cm->SetCookie(url, "c=3; domain=b")); |
| 474 EXPECT_EQ("a=1", cm.GetCookies(url)); | 475 EXPECT_EQ("a=1", cm->GetCookies(url)); |
| 475 } | 476 } |
| 476 } | 477 } |
| 477 | 478 |
| 478 // Test reading/writing cookies when the domain ends with a period, | 479 // Test reading/writing cookies when the domain ends with a period, |
| 479 // as in "www.google.com." | 480 // as in "www.google.com." |
| 480 TEST(CookieMonsterTest, TestHostEndsWithDot) { | 481 TEST(CookieMonsterTest, TestHostEndsWithDot) { |
| 481 net::CookieMonster cm; | 482 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 482 GURL url("http://www.google.com"); | 483 GURL url("http://www.google.com"); |
| 483 GURL url_with_dot("http://www.google.com."); | 484 GURL url_with_dot("http://www.google.com."); |
| 484 EXPECT_TRUE(cm.SetCookie(url, "a=1")); | 485 EXPECT_TRUE(cm->SetCookie(url, "a=1")); |
| 485 EXPECT_EQ("a=1", cm.GetCookies(url)); | 486 EXPECT_EQ("a=1", cm->GetCookies(url)); |
| 486 | 487 |
| 487 // Do not share cookie space with the dot version of domain. | 488 // Do not share cookie space with the dot version of domain. |
| 488 // Note: this is not what FireFox does, but it _is_ what IE+Safari do. | 489 // Note: this is not what FireFox does, but it _is_ what IE+Safari do. |
| 489 EXPECT_FALSE(cm.SetCookie(url, "b=2; domain=.www.google.com.")); | 490 EXPECT_FALSE(cm->SetCookie(url, "b=2; domain=.www.google.com.")); |
| 490 EXPECT_EQ("a=1", cm.GetCookies(url)); | 491 EXPECT_EQ("a=1", cm->GetCookies(url)); |
| 491 | 492 |
| 492 EXPECT_TRUE(cm.SetCookie(url_with_dot, "b=2; domain=.google.com.")); | 493 EXPECT_TRUE(cm->SetCookie(url_with_dot, "b=2; domain=.google.com.")); |
| 493 EXPECT_EQ("b=2", cm.GetCookies(url_with_dot)); | 494 EXPECT_EQ("b=2", cm->GetCookies(url_with_dot)); |
| 494 | 495 |
| 495 // Make sure there weren't any side effects. | 496 // Make sure there weren't any side effects. |
| 496 EXPECT_EQ(cm.GetCookies(GURL("http://hopefully-no-cookies.com/")), ""); | 497 EXPECT_EQ(cm->GetCookies(GURL("http://hopefully-no-cookies.com/")), ""); |
| 497 EXPECT_EQ("", cm.GetCookies(GURL("http://.com/"))); | 498 EXPECT_EQ("", cm->GetCookies(GURL("http://.com/"))); |
| 498 } | 499 } |
| 499 | 500 |
| 500 TEST(CookieMonsterTest, InvalidScheme) { | 501 TEST(CookieMonsterTest, InvalidScheme) { |
| 501 net::CookieMonster cm; | 502 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 502 EXPECT_FALSE(cm.SetCookie(GURL(kUrlFtp), kValidCookieLine)); | 503 EXPECT_FALSE(cm->SetCookie(GURL(kUrlFtp), kValidCookieLine)); |
| 503 } | 504 } |
| 504 | 505 |
| 505 TEST(CookieMonsterTest, InvalidScheme_Read) { | 506 TEST(CookieMonsterTest, InvalidScheme_Read) { |
| 506 net::CookieMonster cm; | 507 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 507 EXPECT_TRUE(cm.SetCookie(GURL(kUrlGoogle), kValidDomainCookieLine)); | 508 EXPECT_TRUE(cm->SetCookie(GURL(kUrlGoogle), kValidDomainCookieLine)); |
| 508 EXPECT_EQ("", cm.GetCookies(GURL(kUrlFtp))); | 509 EXPECT_EQ("", cm->GetCookies(GURL(kUrlFtp))); |
| 509 } | 510 } |
| 510 | 511 |
| 511 TEST(CookieMonsterTest, PathTest) { | 512 TEST(CookieMonsterTest, PathTest) { |
| 512 std::string url("http://www.google.izzle"); | 513 std::string url("http://www.google.izzle"); |
| 513 net::CookieMonster cm; | 514 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 514 EXPECT_TRUE(cm.SetCookie(GURL(url), "A=B; path=/wee")); | 515 EXPECT_TRUE(cm->SetCookie(GURL(url), "A=B; path=/wee")); |
| 515 EXPECT_EQ("A=B", cm.GetCookies(GURL(url + "/wee"))); | 516 EXPECT_EQ("A=B", cm->GetCookies(GURL(url + "/wee"))); |
| 516 EXPECT_EQ("A=B", cm.GetCookies(GURL(url + "/wee/"))); | 517 EXPECT_EQ("A=B", cm->GetCookies(GURL(url + "/wee/"))); |
| 517 EXPECT_EQ("A=B", cm.GetCookies(GURL(url + "/wee/war"))); | 518 EXPECT_EQ("A=B", cm->GetCookies(GURL(url + "/wee/war"))); |
| 518 EXPECT_EQ("A=B", cm.GetCookies(GURL(url + "/wee/war/more/more"))); | 519 EXPECT_EQ("A=B", cm->GetCookies(GURL(url + "/wee/war/more/more"))); |
| 519 EXPECT_EQ("", cm.GetCookies(GURL(url + "/weehee"))); | 520 EXPECT_EQ("", cm->GetCookies(GURL(url + "/weehee"))); |
| 520 EXPECT_EQ("", cm.GetCookies(GURL(url + "/"))); | 521 EXPECT_EQ("", cm->GetCookies(GURL(url + "/"))); |
| 521 | 522 |
| 522 // If we add a 0 length path, it should default to / | 523 // If we add a 0 length path, it should default to / |
| 523 EXPECT_TRUE(cm.SetCookie(GURL(url), "A=C; path=")); | 524 EXPECT_TRUE(cm->SetCookie(GURL(url), "A=C; path=")); |
| 524 EXPECT_EQ("A=B; A=C", cm.GetCookies(GURL(url + "/wee"))); | 525 EXPECT_EQ("A=B; A=C", cm->GetCookies(GURL(url + "/wee"))); |
| 525 EXPECT_EQ("A=C", cm.GetCookies(GURL(url + "/"))); | 526 EXPECT_EQ("A=C", cm->GetCookies(GURL(url + "/"))); |
| 526 } | 527 } |
| 527 | 528 |
| 528 TEST(CookieMonsterTest, HttpOnlyTest) { | 529 TEST(CookieMonsterTest, HttpOnlyTest) { |
| 529 GURL url_google(kUrlGoogle); | 530 GURL url_google(kUrlGoogle); |
| 530 net::CookieMonster cm; | 531 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 531 net::CookieOptions options; | 532 net::CookieOptions options; |
| 532 options.set_include_httponly(); | 533 options.set_include_httponly(); |
| 533 | 534 |
| 534 // Create a httponly cookie. | 535 // Create a httponly cookie. |
| 535 EXPECT_TRUE(cm.SetCookieWithOptions(url_google, "A=B; httponly", options)); | 536 EXPECT_TRUE(cm->SetCookieWithOptions(url_google, "A=B; httponly", options)); |
| 536 | 537 |
| 537 // Check httponly read protection. | 538 // Check httponly read protection. |
| 538 EXPECT_EQ("", cm.GetCookies(url_google)); | 539 EXPECT_EQ("", cm->GetCookies(url_google)); |
| 539 EXPECT_EQ("A=B", cm.GetCookiesWithOptions(url_google, options)); | 540 EXPECT_EQ("A=B", cm->GetCookiesWithOptions(url_google, options)); |
| 540 | 541 |
| 541 // Check httponly overwrite protection. | 542 // Check httponly overwrite protection. |
| 542 EXPECT_FALSE(cm.SetCookie(url_google, "A=C")); | 543 EXPECT_FALSE(cm->SetCookie(url_google, "A=C")); |
| 543 EXPECT_EQ("", cm.GetCookies(url_google)); | 544 EXPECT_EQ("", cm->GetCookies(url_google)); |
| 544 EXPECT_EQ("A=B", cm.GetCookiesWithOptions(url_google, options)); | 545 EXPECT_EQ("A=B", cm->GetCookiesWithOptions(url_google, options)); |
| 545 EXPECT_TRUE(cm.SetCookieWithOptions(url_google, "A=C", options)); | 546 EXPECT_TRUE(cm->SetCookieWithOptions(url_google, "A=C", options)); |
| 546 EXPECT_EQ("A=C", cm.GetCookies(url_google)); | 547 EXPECT_EQ("A=C", cm->GetCookies(url_google)); |
| 547 | 548 |
| 548 // Check httponly create protection. | 549 // Check httponly create protection. |
| 549 EXPECT_FALSE(cm.SetCookie(url_google, "B=A; httponly")); | 550 EXPECT_FALSE(cm->SetCookie(url_google, "B=A; httponly")); |
| 550 EXPECT_EQ("A=C", cm.GetCookiesWithOptions(url_google, options)); | 551 EXPECT_EQ("A=C", cm->GetCookiesWithOptions(url_google, options)); |
| 551 EXPECT_TRUE(cm.SetCookieWithOptions(url_google, "B=A; httponly", options)); | 552 EXPECT_TRUE(cm->SetCookieWithOptions(url_google, "B=A; httponly", options)); |
| 552 EXPECT_EQ("A=C; B=A", cm.GetCookiesWithOptions(url_google, options)); | 553 EXPECT_EQ("A=C; B=A", cm->GetCookiesWithOptions(url_google, options)); |
| 553 EXPECT_EQ("A=C", cm.GetCookies(url_google)); | 554 EXPECT_EQ("A=C", cm->GetCookies(url_google)); |
| 554 } | 555 } |
| 555 | 556 |
| 556 namespace { | 557 namespace { |
| 557 | 558 |
| 558 struct CookieDateParsingCase { | 559 struct CookieDateParsingCase { |
| 559 const char* str; | 560 const char* str; |
| 560 const bool valid; | 561 const bool valid; |
| 561 const time_t epoch; | 562 const time_t epoch; |
| 562 }; | 563 }; |
| 563 | 564 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 EXPECT_FALSE(!parsed_time.is_null()) << tests[i].str; | 643 EXPECT_FALSE(!parsed_time.is_null()) << tests[i].str; |
| 643 continue; | 644 continue; |
| 644 } | 645 } |
| 645 EXPECT_TRUE(!parsed_time.is_null()) << tests[i].str; | 646 EXPECT_TRUE(!parsed_time.is_null()) << tests[i].str; |
| 646 EXPECT_EQ(tests[i].epoch, parsed_time.ToTimeT()) << tests[i].str; | 647 EXPECT_EQ(tests[i].epoch, parsed_time.ToTimeT()) << tests[i].str; |
| 647 } | 648 } |
| 648 } | 649 } |
| 649 | 650 |
| 650 TEST(CookieMonsterTest, TestCookieDeletion) { | 651 TEST(CookieMonsterTest, TestCookieDeletion) { |
| 651 GURL url_google(kUrlGoogle); | 652 GURL url_google(kUrlGoogle); |
| 652 net::CookieMonster cm; | 653 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 653 | 654 |
| 654 // Create a session cookie. | 655 // Create a session cookie. |
| 655 EXPECT_TRUE(cm.SetCookie(url_google, kValidCookieLine)); | 656 EXPECT_TRUE(cm->SetCookie(url_google, kValidCookieLine)); |
| 656 EXPECT_EQ("A=B", cm.GetCookies(url_google)); | 657 EXPECT_EQ("A=B", cm->GetCookies(url_google)); |
| 657 // Delete it via Max-Age. | 658 // Delete it via Max-Age. |
| 658 EXPECT_TRUE(cm.SetCookie(url_google, | 659 EXPECT_TRUE(cm->SetCookie(url_google, |
| 659 std::string(kValidCookieLine) + "; max-age=0")); | 660 std::string(kValidCookieLine) + "; max-age=0")); |
| 660 EXPECT_EQ("", cm.GetCookies(url_google)); | 661 EXPECT_EQ("", cm->GetCookies(url_google)); |
| 661 | 662 |
| 662 // Create a session cookie. | 663 // Create a session cookie. |
| 663 EXPECT_TRUE(cm.SetCookie(url_google, kValidCookieLine)); | 664 EXPECT_TRUE(cm->SetCookie(url_google, kValidCookieLine)); |
| 664 EXPECT_EQ("A=B", cm.GetCookies(url_google)); | 665 EXPECT_EQ("A=B", cm->GetCookies(url_google)); |
| 665 // Delete it via Expires. | 666 // Delete it via Expires. |
| 666 EXPECT_TRUE(cm.SetCookie(url_google, | 667 EXPECT_TRUE(cm->SetCookie(url_google, |
| 667 std::string(kValidCookieLine) + | 668 std::string(kValidCookieLine) + |
| 668 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); | 669 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); |
| 669 EXPECT_EQ("", cm.GetCookies(url_google)); | 670 EXPECT_EQ("", cm->GetCookies(url_google)); |
| 670 | 671 |
| 671 // Create a persistent cookie. | 672 // Create a persistent cookie. |
| 672 EXPECT_TRUE(cm.SetCookie(url_google, | 673 EXPECT_TRUE(cm->SetCookie(url_google, |
| 673 std::string(kValidCookieLine) + | 674 std::string(kValidCookieLine) + |
| 674 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 675 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 675 EXPECT_EQ("A=B", cm.GetCookies(url_google)); | 676 EXPECT_EQ("A=B", cm->GetCookies(url_google)); |
| 676 // Delete it via Max-Age. | 677 // Delete it via Max-Age. |
| 677 EXPECT_TRUE(cm.SetCookie(url_google, | 678 EXPECT_TRUE(cm->SetCookie(url_google, |
| 678 std::string(kValidCookieLine) + "; max-age=0")); | 679 std::string(kValidCookieLine) + "; max-age=0")); |
| 679 EXPECT_EQ("", cm.GetCookies(url_google)); | 680 EXPECT_EQ("", cm->GetCookies(url_google)); |
| 680 | 681 |
| 681 // Create a persistent cookie. | 682 // Create a persistent cookie. |
| 682 EXPECT_TRUE(cm.SetCookie(url_google, | 683 EXPECT_TRUE(cm->SetCookie(url_google, |
| 683 std::string(kValidCookieLine) + | 684 std::string(kValidCookieLine) + |
| 684 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 685 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 685 EXPECT_EQ("A=B", cm.GetCookies(url_google)); | 686 EXPECT_EQ("A=B", cm->GetCookies(url_google)); |
| 686 // Delete it via Expires. | 687 // Delete it via Expires. |
| 687 EXPECT_TRUE(cm.SetCookie(url_google, | 688 EXPECT_TRUE(cm->SetCookie(url_google, |
| 688 std::string(kValidCookieLine) + | 689 std::string(kValidCookieLine) + |
| 689 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); | 690 "; expires=Mon, 18-Apr-1977 22:50:13 GMT")); |
| 690 EXPECT_EQ("", cm.GetCookies(url_google)); | 691 EXPECT_EQ("", cm->GetCookies(url_google)); |
| 691 | 692 |
| 692 // Create a persistent cookie. | 693 // Create a persistent cookie. |
| 693 EXPECT_TRUE(cm.SetCookie(url_google, | 694 EXPECT_TRUE(cm->SetCookie(url_google, |
| 694 std::string(kValidCookieLine) + | 695 std::string(kValidCookieLine) + |
| 695 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 696 "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 696 EXPECT_EQ("A=B", cm.GetCookies(url_google)); | 697 EXPECT_EQ("A=B", cm->GetCookies(url_google)); |
| 697 // Delete it via Expires, with a unix epoch of 0. | 698 // Delete it via Expires, with a unix epoch of 0. |
| 698 EXPECT_TRUE(cm.SetCookie(url_google, | 699 EXPECT_TRUE(cm->SetCookie(url_google, |
| 699 std::string(kValidCookieLine) + | 700 std::string(kValidCookieLine) + |
| 700 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); | 701 "; expires=Thu, 1-Jan-1970 00:00:00 GMT")); |
| 701 EXPECT_EQ("", cm.GetCookies(url_google)); | 702 EXPECT_EQ("", cm->GetCookies(url_google)); |
| 702 } | 703 } |
| 703 | 704 |
| 704 TEST(CookieMonsterTest, TestCookieDeleteAll) { | 705 TEST(CookieMonsterTest, TestCookieDeleteAll) { |
| 705 GURL url_google(kUrlGoogle); | 706 GURL url_google(kUrlGoogle); |
| 706 net::CookieMonster cm; | 707 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 707 net::CookieOptions options; | 708 net::CookieOptions options; |
| 708 options.set_include_httponly(); | 709 options.set_include_httponly(); |
| 709 | 710 |
| 710 EXPECT_TRUE(cm.SetCookie(url_google, kValidCookieLine)); | 711 EXPECT_TRUE(cm->SetCookie(url_google, kValidCookieLine)); |
| 711 EXPECT_EQ("A=B", cm.GetCookies(url_google)); | 712 EXPECT_EQ("A=B", cm->GetCookies(url_google)); |
| 712 | 713 |
| 713 EXPECT_TRUE(cm.SetCookieWithOptions(url_google, "C=D; httponly", options)); | 714 EXPECT_TRUE(cm->SetCookieWithOptions(url_google, "C=D; httponly", options)); |
| 714 EXPECT_EQ("A=B; C=D", cm.GetCookiesWithOptions(url_google, options)); | 715 EXPECT_EQ("A=B; C=D", cm->GetCookiesWithOptions(url_google, options)); |
| 715 | 716 |
| 716 EXPECT_EQ(2, cm.DeleteAll(false)); | 717 EXPECT_EQ(2, cm->DeleteAll(false)); |
| 717 EXPECT_EQ("", cm.GetCookiesWithOptions(url_google, options)); | 718 EXPECT_EQ("", cm->GetCookiesWithOptions(url_google, options)); |
| 718 } | 719 } |
| 719 | 720 |
| 720 TEST(CookieMonsterTest, TestCookieDeleteAllCreatedAfterTimestamp) { | 721 TEST(CookieMonsterTest, TestCookieDeleteAllCreatedAfterTimestamp) { |
| 721 GURL url_google(kUrlGoogle); | 722 GURL url_google(kUrlGoogle); |
| 722 net::CookieMonster cm; | 723 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 723 Time now = Time::Now(); | 724 Time now = Time::Now(); |
| 724 | 725 |
| 725 // Nothing has been added so nothing should be deleted. | 726 // Nothing has been added so nothing should be deleted. |
| 726 EXPECT_EQ(0, cm.DeleteAllCreatedAfter(now - TimeDelta::FromDays(99), false)); | 727 EXPECT_EQ(0, cm->DeleteAllCreatedAfter(now - TimeDelta::FromDays(99), false)); |
| 727 | 728 |
| 728 // Create 3 cookies with creation date of today, yesterday and the day before. | 729 // Create 3 cookies with creation date of today, yesterday and the day before. |
| 729 EXPECT_TRUE(cm.SetCookieWithCreationTime(url_google, "T-0=Now", now)); | 730 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google, "T-0=Now", now)); |
| 730 EXPECT_TRUE(cm.SetCookieWithCreationTime(url_google, "T-1=Yesterday", | 731 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google, "T-1=Yesterday", |
| 731 now - TimeDelta::FromDays(1))); | 732 now - TimeDelta::FromDays(1))); |
| 732 EXPECT_TRUE(cm.SetCookieWithCreationTime(url_google, "T-2=DayBefore", | 733 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google, "T-2=DayBefore", |
| 733 now - TimeDelta::FromDays(2))); | 734 now - TimeDelta::FromDays(2))); |
| 734 | 735 |
| 735 // Try to delete everything from now onwards. | 736 // Try to delete everything from now onwards. |
| 736 EXPECT_EQ(1, cm.DeleteAllCreatedAfter(now, false)); | 737 EXPECT_EQ(1, cm->DeleteAllCreatedAfter(now, false)); |
| 737 // Now delete the one cookie created in the last day. | 738 // Now delete the one cookie created in the last day. |
| 738 EXPECT_EQ(1, cm.DeleteAllCreatedAfter(now - TimeDelta::FromDays(1), false)); | 739 EXPECT_EQ(1, cm->DeleteAllCreatedAfter(now - TimeDelta::FromDays(1), false)); |
| 739 // Now effectively delete all cookies just created (1 is remaining). | 740 // Now effectively delete all cookies just created (1 is remaining). |
| 740 EXPECT_EQ(1, cm.DeleteAllCreatedAfter(now - TimeDelta::FromDays(99), false)); | 741 EXPECT_EQ(1, cm->DeleteAllCreatedAfter(now - TimeDelta::FromDays(99), false)); |
| 741 | 742 |
| 742 // Make sure everything is gone. | 743 // Make sure everything is gone. |
| 743 EXPECT_EQ(0, cm.DeleteAllCreatedAfter(Time(), false)); | 744 EXPECT_EQ(0, cm->DeleteAllCreatedAfter(Time(), false)); |
| 744 // Really make sure everything is gone. | 745 // Really make sure everything is gone. |
| 745 EXPECT_EQ(0, cm.DeleteAll(false)); | 746 EXPECT_EQ(0, cm->DeleteAll(false)); |
| 746 } | 747 } |
| 747 | 748 |
| 748 TEST(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { | 749 TEST(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { |
| 749 GURL url_google(kUrlGoogle); | 750 GURL url_google(kUrlGoogle); |
| 750 net::CookieMonster cm; | 751 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 751 Time now = Time::Now(); | 752 Time now = Time::Now(); |
| 752 | 753 |
| 753 // Nothing has been added so nothing should be deleted. | 754 // Nothing has been added so nothing should be deleted. |
| 754 EXPECT_EQ(0, cm.DeleteAllCreatedAfter(now - TimeDelta::FromDays(99), false)); | 755 EXPECT_EQ(0, cm->DeleteAllCreatedAfter(now - TimeDelta::FromDays(99), false)); |
| 755 | 756 |
| 756 // Create 3 cookies with creation date of today, yesterday and the day before. | 757 // Create 3 cookies with creation date of today, yesterday and the day before. |
| 757 EXPECT_TRUE(cm.SetCookieWithCreationTime(url_google, "T-0=Now", now)); | 758 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google, "T-0=Now", now)); |
| 758 EXPECT_TRUE(cm.SetCookieWithCreationTime(url_google, "T-1=Yesterday", | 759 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google, "T-1=Yesterday", |
| 759 now - TimeDelta::FromDays(1))); | 760 now - TimeDelta::FromDays(1))); |
| 760 EXPECT_TRUE(cm.SetCookieWithCreationTime(url_google, "T-2=DayBefore", | 761 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google, "T-2=DayBefore", |
| 761 now - TimeDelta::FromDays(2))); | 762 now - TimeDelta::FromDays(2))); |
| 762 EXPECT_TRUE(cm.SetCookieWithCreationTime(url_google, "T-3=ThreeDays", | 763 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google, "T-3=ThreeDays", |
| 763 now - TimeDelta::FromDays(3))); | 764 now - TimeDelta::FromDays(3))); |
| 764 EXPECT_TRUE(cm.SetCookieWithCreationTime(url_google, "T-7=LastWeek", | 765 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google, "T-7=LastWeek", |
| 765 now - TimeDelta::FromDays(7))); | 766 now - TimeDelta::FromDays(7))); |
| 766 | 767 |
| 767 // Try to delete threedays and the daybefore. | 768 // Try to delete threedays and the daybefore. |
| 768 EXPECT_EQ(2, cm.DeleteAllCreatedBetween(now - TimeDelta::FromDays(3), | 769 EXPECT_EQ(2, cm->DeleteAllCreatedBetween(now - TimeDelta::FromDays(3), |
| 769 now - TimeDelta::FromDays(1), | 770 now - TimeDelta::FromDays(1), |
| 770 false)); | 771 false)); |
| 771 | 772 |
| 772 // Try to delete yesterday, also make sure that delete_end is not | 773 // Try to delete yesterday, also make sure that delete_end is not |
| 773 // inclusive. | 774 // inclusive. |
| 774 EXPECT_EQ(1, cm.DeleteAllCreatedBetween(now - TimeDelta::FromDays(2), | 775 EXPECT_EQ(1, cm->DeleteAllCreatedBetween(now - TimeDelta::FromDays(2), |
| 775 now, | 776 now, |
| 776 false)); | 777 false)); |
| 777 | 778 |
| 778 // Make sure the delete_begin is inclusive. | 779 // Make sure the delete_begin is inclusive. |
| 779 EXPECT_EQ(1, cm.DeleteAllCreatedBetween(now - TimeDelta::FromDays(7), | 780 EXPECT_EQ(1, cm->DeleteAllCreatedBetween(now - TimeDelta::FromDays(7), |
| 780 now, | 781 now, |
| 781 false)); | 782 false)); |
| 782 | 783 |
| 783 // Delete the last (now) item. | 784 // Delete the last (now) item. |
| 784 EXPECT_EQ(1, cm.DeleteAllCreatedAfter(Time(), false)); | 785 EXPECT_EQ(1, cm->DeleteAllCreatedAfter(Time(), false)); |
| 785 | 786 |
| 786 // Really make sure everything is gone. | 787 // Really make sure everything is gone. |
| 787 EXPECT_EQ(0, cm.DeleteAll(false)); | 788 EXPECT_EQ(0, cm->DeleteAll(false)); |
| 788 } | 789 } |
| 789 | 790 |
| 790 TEST(CookieMonsterTest, TestSecure) { | 791 TEST(CookieMonsterTest, TestSecure) { |
| 791 GURL url_google(kUrlGoogle); | 792 GURL url_google(kUrlGoogle); |
| 792 GURL url_google_secure(kUrlGoogleSecure); | 793 GURL url_google_secure(kUrlGoogleSecure); |
| 793 net::CookieMonster cm; | 794 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 794 | 795 |
| 795 EXPECT_TRUE(cm.SetCookie(url_google, "A=B")); | 796 EXPECT_TRUE(cm->SetCookie(url_google, "A=B")); |
| 796 EXPECT_EQ("A=B", cm.GetCookies(url_google)); | 797 EXPECT_EQ("A=B", cm->GetCookies(url_google)); |
| 797 EXPECT_EQ("A=B", cm.GetCookies(url_google_secure)); | 798 EXPECT_EQ("A=B", cm->GetCookies(url_google_secure)); |
| 798 | 799 |
| 799 EXPECT_TRUE(cm.SetCookie(url_google_secure, "A=B; secure")); | 800 EXPECT_TRUE(cm->SetCookie(url_google_secure, "A=B; secure")); |
| 800 // The secure should overwrite the non-secure. | 801 // The secure should overwrite the non-secure. |
| 801 EXPECT_EQ("", cm.GetCookies(url_google)); | 802 EXPECT_EQ("", cm->GetCookies(url_google)); |
| 802 EXPECT_EQ("A=B", cm.GetCookies(url_google_secure)); | 803 EXPECT_EQ("A=B", cm->GetCookies(url_google_secure)); |
| 803 | 804 |
| 804 EXPECT_TRUE(cm.SetCookie(url_google_secure, "D=E; secure")); | 805 EXPECT_TRUE(cm->SetCookie(url_google_secure, "D=E; secure")); |
| 805 EXPECT_EQ("", cm.GetCookies(url_google)); | 806 EXPECT_EQ("", cm->GetCookies(url_google)); |
| 806 EXPECT_EQ("A=B; D=E", cm.GetCookies(url_google_secure)); | 807 EXPECT_EQ("A=B; D=E", cm->GetCookies(url_google_secure)); |
| 807 | 808 |
| 808 EXPECT_TRUE(cm.SetCookie(url_google_secure, "A=B")); | 809 EXPECT_TRUE(cm->SetCookie(url_google_secure, "A=B")); |
| 809 // The non-secure should overwrite the secure. | 810 // The non-secure should overwrite the secure. |
| 810 EXPECT_EQ("A=B", cm.GetCookies(url_google)); | 811 EXPECT_EQ("A=B", cm->GetCookies(url_google)); |
| 811 EXPECT_EQ("D=E; A=B", cm.GetCookies(url_google_secure)); | 812 EXPECT_EQ("D=E; A=B", cm->GetCookies(url_google_secure)); |
| 812 } | 813 } |
| 813 | 814 |
| 814 static Time GetFirstCookieAccessDate(net::CookieMonster* cm) { | 815 static Time GetFirstCookieAccessDate(net::CookieMonster* cm) { |
| 815 const net::CookieMonster::CookieList all_cookies(cm->GetAllCookies()); | 816 const net::CookieMonster::CookieList all_cookies(cm->GetAllCookies()); |
| 816 return all_cookies.front().second.LastAccessDate(); | 817 return all_cookies.front().second.LastAccessDate(); |
| 817 } | 818 } |
| 818 | 819 |
| 819 static const int kLastAccessThresholdSeconds = 1; | 820 static const int kLastAccessThresholdSeconds = 1; |
| 820 | 821 |
| 821 TEST(CookieMonsterTest, TestLastAccess) { | 822 TEST(CookieMonsterTest, TestLastAccess) { |
| 822 GURL url_google(kUrlGoogle); | 823 GURL url_google(kUrlGoogle); |
| 823 net::CookieMonster cm(kLastAccessThresholdSeconds); | 824 scoped_refptr<net::CookieMonster> cm( |
| 825 new net::CookieMonster(kLastAccessThresholdSeconds)); |
| 824 | 826 |
| 825 EXPECT_TRUE(cm.SetCookie(url_google, "A=B")); | 827 EXPECT_TRUE(cm->SetCookie(url_google, "A=B")); |
| 826 const Time last_access_date(GetFirstCookieAccessDate(&cm)); | 828 const Time last_access_date(GetFirstCookieAccessDate(cm)); |
| 827 | 829 |
| 828 // Reading the cookie again immediately shouldn't update the access date, | 830 // Reading the cookie again immediately shouldn't update the access date, |
| 829 // since we're inside the threshold. | 831 // since we're inside the threshold. |
| 830 EXPECT_EQ("A=B", cm.GetCookies(url_google)); | 832 EXPECT_EQ("A=B", cm->GetCookies(url_google)); |
| 831 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(&cm)); | 833 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm)); |
| 832 | 834 |
| 833 // Reading after a short wait should update the access date. | 835 // Reading after a short wait should update the access date. |
| 834 PlatformThread::Sleep(1500); | 836 PlatformThread::Sleep(1500); |
| 835 EXPECT_EQ("A=B", cm.GetCookies(url_google)); | 837 EXPECT_EQ("A=B", cm->GetCookies(url_google)); |
| 836 EXPECT_FALSE(last_access_date == GetFirstCookieAccessDate(&cm)); | 838 EXPECT_FALSE(last_access_date == GetFirstCookieAccessDate(cm)); |
| 837 } | 839 } |
| 838 | 840 |
| 839 static int CountInString(const std::string& str, char c) { | 841 static int CountInString(const std::string& str, char c) { |
| 840 int count = 0; | 842 int count = 0; |
| 841 for (std::string::const_iterator it = str.begin(); | 843 for (std::string::const_iterator it = str.begin(); |
| 842 it != str.end(); ++it) { | 844 it != str.end(); ++it) { |
| 843 if (*it == c) | 845 if (*it == c) |
| 844 ++count; | 846 ++count; |
| 845 } | 847 } |
| 846 return count; | 848 return count; |
| 847 } | 849 } |
| 848 | 850 |
| 849 TEST(CookieMonsterTest, TestHostGarbageCollection) { | 851 TEST(CookieMonsterTest, TestHostGarbageCollection) { |
| 850 GURL url_google(kUrlGoogle); | 852 GURL url_google(kUrlGoogle); |
| 851 net::CookieMonster cm; | 853 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 852 // Add a bunch of cookies on a single host, should purge them. | 854 // Add a bunch of cookies on a single host, should purge them. |
| 853 for (int i = 0; i < 101; i++) { | 855 for (int i = 0; i < 101; i++) { |
| 854 std::string cookie = StringPrintf("a%03d=b", i); | 856 std::string cookie = StringPrintf("a%03d=b", i); |
| 855 EXPECT_TRUE(cm.SetCookie(url_google, cookie)); | 857 EXPECT_TRUE(cm->SetCookie(url_google, cookie)); |
| 856 std::string cookies = cm.GetCookies(url_google); | 858 std::string cookies = cm->GetCookies(url_google); |
| 857 // Make sure we find it in the cookies. | 859 // Make sure we find it in the cookies. |
| 858 EXPECT_TRUE(cookies.find(cookie) != std::string::npos); | 860 EXPECT_TRUE(cookies.find(cookie) != std::string::npos); |
| 859 // Count the number of cookies. | 861 // Count the number of cookies. |
| 860 EXPECT_LE(CountInString(cookies, '='), 70); | 862 EXPECT_LE(CountInString(cookies, '='), 70); |
| 861 } | 863 } |
| 862 } | 864 } |
| 863 | 865 |
| 864 TEST(CookieMonsterTest, TestTotalGarbageCollection) { | 866 TEST(CookieMonsterTest, TestTotalGarbageCollection) { |
| 865 net::CookieMonster cm(kLastAccessThresholdSeconds); | 867 scoped_refptr<net::CookieMonster> cm( |
| 868 new net::CookieMonster(kLastAccessThresholdSeconds)); |
| 869 |
| 866 // Add a bunch of cookies on a bunch of host, some should get purged. | 870 // Add a bunch of cookies on a bunch of host, some should get purged. |
| 867 const GURL sticky_cookie("http://a0000.izzle"); | 871 const GURL sticky_cookie("http://a0000.izzle"); |
| 868 for (int i = 0; i < 4000; ++i) { | 872 for (int i = 0; i < 4000; ++i) { |
| 869 GURL url(StringPrintf("http://a%04d.izzle", i)); | 873 GURL url(StringPrintf("http://a%04d.izzle", i)); |
| 870 EXPECT_TRUE(cm.SetCookie(url, "a=b")); | 874 EXPECT_TRUE(cm->SetCookie(url, "a=b")); |
| 871 EXPECT_EQ("a=b", cm.GetCookies(url)); | 875 EXPECT_EQ("a=b", cm->GetCookies(url)); |
| 872 | 876 |
| 873 // Keep touching the first cookie to ensure it's not purged (since it will | 877 // Keep touching the first cookie to ensure it's not purged (since it will |
| 874 // always have the most recent access time). | 878 // always have the most recent access time). |
| 875 if (!(i % 500)) { | 879 if (!(i % 500)) { |
| 876 PlatformThread::Sleep(1500); // Ensure the timestamps will be different | 880 PlatformThread::Sleep(1500); // Ensure the timestamps will be different |
| 877 // enough to update. | 881 // enough to update. |
| 878 EXPECT_EQ("a=b", cm.GetCookies(sticky_cookie)); | 882 EXPECT_EQ("a=b", cm->GetCookies(sticky_cookie)); |
| 879 } | 883 } |
| 880 } | 884 } |
| 881 | 885 |
| 882 // Check that cookies that still exist. | 886 // Check that cookies that still exist. |
| 883 for (int i = 0; i < 4000; ++i) { | 887 for (int i = 0; i < 4000; ++i) { |
| 884 GURL url(StringPrintf("http://a%04d.izzle", i)); | 888 GURL url(StringPrintf("http://a%04d.izzle", i)); |
| 885 if ((i == 0) || (i > 1001)) { | 889 if ((i == 0) || (i > 1001)) { |
| 886 // Cookies should still be around. | 890 // Cookies should still be around. |
| 887 EXPECT_FALSE(cm.GetCookies(url).empty()); | 891 EXPECT_FALSE(cm->GetCookies(url).empty()); |
| 888 } else if (i < 701) { | 892 } else if (i < 701) { |
| 889 // Cookies should have gotten purged. | 893 // Cookies should have gotten purged. |
| 890 EXPECT_TRUE(cm.GetCookies(url).empty()); | 894 EXPECT_TRUE(cm->GetCookies(url).empty()); |
| 891 } | 895 } |
| 892 } | 896 } |
| 893 } | 897 } |
| 894 | 898 |
| 895 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling. | 899 // Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling. |
| 896 TEST(CookieMonsterTest, NetUtilCookieTest) { | 900 TEST(CookieMonsterTest, NetUtilCookieTest) { |
| 897 const GURL test_url("http://mojo.jojo.google.izzle/"); | 901 const GURL test_url("http://mojo.jojo.google.izzle/"); |
| 898 | 902 |
| 899 net::CookieMonster cm; | 903 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 900 | 904 |
| 901 EXPECT_TRUE(cm.SetCookie(test_url, "foo=bar")); | 905 EXPECT_TRUE(cm->SetCookie(test_url, "foo=bar")); |
| 902 std::string value = cm.GetCookies(test_url); | 906 std::string value = cm->GetCookies(test_url); |
| 903 EXPECT_EQ("foo=bar", value); | 907 EXPECT_EQ("foo=bar", value); |
| 904 | 908 |
| 905 // test that we can retrieve all cookies: | 909 // test that we can retrieve all cookies: |
| 906 EXPECT_TRUE(cm.SetCookie(test_url, "x=1")); | 910 EXPECT_TRUE(cm->SetCookie(test_url, "x=1")); |
| 907 EXPECT_TRUE(cm.SetCookie(test_url, "y=2")); | 911 EXPECT_TRUE(cm->SetCookie(test_url, "y=2")); |
| 908 | 912 |
| 909 std::string result = cm.GetCookies(test_url); | 913 std::string result = cm->GetCookies(test_url); |
| 910 EXPECT_FALSE(result.empty()); | 914 EXPECT_FALSE(result.empty()); |
| 911 EXPECT_NE(result.find("x=1"), std::string::npos) << result; | 915 EXPECT_NE(result.find("x=1"), std::string::npos) << result; |
| 912 EXPECT_NE(result.find("y=2"), std::string::npos) << result; | 916 EXPECT_NE(result.find("y=2"), std::string::npos) << result; |
| 913 } | 917 } |
| 914 | 918 |
| 915 static bool FindAndDeleteCookie(net::CookieMonster& cm, | 919 static bool FindAndDeleteCookie(net::CookieMonster* cm, |
| 916 const std::string& domain, | 920 const std::string& domain, |
| 917 const std::string& name) { | 921 const std::string& name) { |
| 918 net::CookieMonster::CookieList cookies = cm.GetAllCookies(); | 922 net::CookieMonster::CookieList cookies = cm->GetAllCookies(); |
| 919 for (net::CookieMonster::CookieList::iterator it = cookies.begin(); | 923 for (net::CookieMonster::CookieList::iterator it = cookies.begin(); |
| 920 it != cookies.end(); ++it) | 924 it != cookies.end(); ++it) |
| 921 if (it->first == domain && it->second.Name() == name) | 925 if (it->first == domain && it->second.Name() == name) |
| 922 return cm.DeleteCookie(domain, it->second, false); | 926 return cm->DeleteCookie(domain, it->second, false); |
| 923 return false; | 927 return false; |
| 924 } | 928 } |
| 925 | 929 |
| 926 TEST(CookieMonsterTest, TestDeleteSingleCookie) { | 930 TEST(CookieMonsterTest, TestDeleteSingleCookie) { |
| 927 GURL url_google(kUrlGoogle); | 931 GURL url_google(kUrlGoogle); |
| 928 | 932 |
| 929 net::CookieMonster cm; | 933 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 930 EXPECT_TRUE(cm.SetCookie(url_google, "A=B")); | 934 |
| 931 EXPECT_TRUE(cm.SetCookie(url_google, "C=D")); | 935 EXPECT_TRUE(cm->SetCookie(url_google, "A=B")); |
| 932 EXPECT_TRUE(cm.SetCookie(url_google, "E=F")); | 936 EXPECT_TRUE(cm->SetCookie(url_google, "C=D")); |
| 933 EXPECT_EQ("A=B; C=D; E=F", cm.GetCookies(url_google)); | 937 EXPECT_TRUE(cm->SetCookie(url_google, "E=F")); |
| 938 EXPECT_EQ("A=B; C=D; E=F", cm->GetCookies(url_google)); |
| 934 | 939 |
| 935 EXPECT_TRUE(FindAndDeleteCookie(cm, url_google.host(), "C")); | 940 EXPECT_TRUE(FindAndDeleteCookie(cm, url_google.host(), "C")); |
| 936 EXPECT_EQ("A=B; E=F", cm.GetCookies(url_google)); | 941 EXPECT_EQ("A=B; E=F", cm->GetCookies(url_google)); |
| 937 | 942 |
| 938 EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E")); | 943 EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E")); |
| 939 EXPECT_EQ("A=B; E=F", cm.GetCookies(url_google)); | 944 EXPECT_EQ("A=B; E=F", cm->GetCookies(url_google)); |
| 940 } | 945 } |
| 941 | 946 |
| 942 TEST(CookieMonsterTest, SetCookieableSchemes) { | 947 TEST(CookieMonsterTest, SetCookieableSchemes) { |
| 943 net::CookieMonster cm; | 948 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 944 net::CookieMonster cm_foo; | 949 scoped_refptr<net::CookieMonster> cm_foo(new net::CookieMonster); |
| 945 | 950 |
| 946 // Only cm_foo should allow foo:// cookies. | 951 // Only cm_foo should allow foo:// cookies. |
| 947 const char* kSchemes[] = {"foo"}; | 952 const char* kSchemes[] = {"foo"}; |
| 948 cm_foo.SetCookieableSchemes(kSchemes, 1); | 953 cm_foo->SetCookieableSchemes(kSchemes, 1); |
| 949 | 954 |
| 950 GURL foo_url("foo://host/path"); | 955 GURL foo_url("foo://host/path"); |
| 951 GURL http_url("http://host/path"); | 956 GURL http_url("http://host/path"); |
| 952 | 957 |
| 953 EXPECT_TRUE(cm.SetCookie(http_url, "x=1")); | 958 EXPECT_TRUE(cm->SetCookie(http_url, "x=1")); |
| 954 EXPECT_FALSE(cm.SetCookie(foo_url, "x=1")); | 959 EXPECT_FALSE(cm->SetCookie(foo_url, "x=1")); |
| 955 EXPECT_TRUE(cm_foo.SetCookie(foo_url, "x=1")); | 960 EXPECT_TRUE(cm_foo->SetCookie(foo_url, "x=1")); |
| 956 EXPECT_FALSE(cm_foo.SetCookie(http_url, "x=1")); | 961 EXPECT_FALSE(cm_foo->SetCookie(http_url, "x=1")); |
| 957 } | 962 } |
| 958 | 963 |
| 959 // TODO test overwrite cookie | 964 // TODO test overwrite cookie |
| OLD | NEW |