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" |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 net::CookieMonster cm; | 399 net::CookieMonster cm; |
400 EXPECT_TRUE(cm.SetCookie(url_ip, kValidCookieLine)); | 400 EXPECT_TRUE(cm.SetCookie(url_ip, kValidCookieLine)); |
401 EXPECT_EQ("A=B", cm.GetCookies(url_ip)); | 401 EXPECT_EQ("A=B", cm.GetCookies(url_ip)); |
402 } | 402 } |
403 | 403 |
404 { // IP addresses should not be able to set domain cookies. | 404 { // IP addresses should not be able to set domain cookies. |
405 net::CookieMonster cm; | 405 net::CookieMonster cm; |
406 EXPECT_FALSE(cm.SetCookie(url_ip, "b=2; domain=.1.2.3.4")); | 406 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")); | 407 EXPECT_FALSE(cm.SetCookie(url_ip, "c=3; domain=.3.4")); |
408 EXPECT_EQ("", cm.GetCookies(url_ip)); | 408 EXPECT_EQ("", cm.GetCookies(url_ip)); |
| 409 // 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 EXPECT_FALSE(cm.SetCookie(url_ip, "b=2; domain=1.2.3.3")); |
| 412 EXPECT_EQ("", cm.GetCookies(url_ip)); |
| 413 EXPECT_TRUE(cm.SetCookie(url_ip, "b=2; domain=1.2.3.4")); |
| 414 EXPECT_EQ("b=2", cm.GetCookies(url_ip)); |
409 } | 415 } |
410 } | 416 } |
411 | 417 |
412 // Test host cookies, and setting of cookies on TLD. | 418 // Test host cookies, and setting of cookies on TLD. |
413 TEST(CookieMonsterTest, TestNonDottedAndTLD) { | 419 TEST(CookieMonsterTest, TestNonDottedAndTLD) { |
414 { | 420 { |
415 net::CookieMonster cm; | 421 net::CookieMonster cm; |
416 GURL url("http://com/"); | 422 GURL url("http://com/"); |
417 // Allow setting on "com", (but only as a host cookie). | 423 // Allow setting on "com", (but only as a host cookie). |
418 EXPECT_TRUE(cm.SetCookie(url, "a=1")); | 424 EXPECT_TRUE(cm.SetCookie(url, "a=1")); |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 | 923 |
918 EXPECT_TRUE(FindAndDeleteCookie(cm, url_google.host(), "C")); | 924 EXPECT_TRUE(FindAndDeleteCookie(cm, url_google.host(), "C")); |
919 EXPECT_EQ("A=B; E=F", cm.GetCookies(url_google)); | 925 EXPECT_EQ("A=B; E=F", cm.GetCookies(url_google)); |
920 | 926 |
921 EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E")); | 927 EXPECT_FALSE(FindAndDeleteCookie(cm, "random.host", "E")); |
922 EXPECT_EQ("A=B; E=F", cm.GetCookies(url_google)); | 928 EXPECT_EQ("A=B; E=F", cm.GetCookies(url_google)); |
923 } | 929 } |
924 | 930 |
925 // TODO test overwrite cookie | 931 // TODO test overwrite cookie |
926 | 932 |
OLD | NEW |