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 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 | 954 |
955 GURL foo_url("foo://host/path"); | 955 GURL foo_url("foo://host/path"); |
956 GURL http_url("http://host/path"); | 956 GURL http_url("http://host/path"); |
957 | 957 |
958 EXPECT_TRUE(cm->SetCookie(http_url, "x=1")); | 958 EXPECT_TRUE(cm->SetCookie(http_url, "x=1")); |
959 EXPECT_FALSE(cm->SetCookie(foo_url, "x=1")); | 959 EXPECT_FALSE(cm->SetCookie(foo_url, "x=1")); |
960 EXPECT_TRUE(cm_foo->SetCookie(foo_url, "x=1")); | 960 EXPECT_TRUE(cm_foo->SetCookie(foo_url, "x=1")); |
961 EXPECT_FALSE(cm_foo->SetCookie(http_url, "x=1")); | 961 EXPECT_FALSE(cm_foo->SetCookie(http_url, "x=1")); |
962 } | 962 } |
963 | 963 |
| 964 TEST(CookieMonsterTest, GetRawCookies) { |
| 965 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 966 GURL url_google(kUrlGoogle); |
| 967 |
| 968 net::CookieOptions options; |
| 969 options.set_include_httponly(); |
| 970 |
| 971 // Create a httponly cookie. |
| 972 EXPECT_TRUE(cm->SetCookieWithOptions(url_google, "A=B; httponly", options)); |
| 973 |
| 974 // Get raw cookies. |
| 975 std::vector<net::CookieMonster::CanonicalCookie> raw_cookies; |
| 976 cm->GetRawCookies(url_google, &raw_cookies); |
| 977 EXPECT_TRUE(raw_cookies.begin() != raw_cookies.end()); |
| 978 net::CookieMonster::CanonicalCookie cookie = *raw_cookies.begin(); |
| 979 EXPECT_EQ("A", cookie.Name()); |
| 980 } |
| 981 |
| 982 TEST(CookieMonsterTest, DeleteCookieByName) { |
| 983 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster); |
| 984 GURL url_google(kUrlGoogle); |
| 985 |
| 986 EXPECT_TRUE(cm->SetCookie(url_google, "A=A1; path=/")); |
| 987 EXPECT_TRUE(cm->SetCookie(url_google, "A=A2; path=/foo")); |
| 988 EXPECT_TRUE(cm->SetCookie(url_google, "A=A3; path=/bar")); |
| 989 EXPECT_TRUE(cm->SetCookie(url_google, "B=B1; path=/")); |
| 990 EXPECT_TRUE(cm->SetCookie(url_google, "B=B2; path=/foo")); |
| 991 EXPECT_TRUE(cm->SetCookie(url_google, "B=B3; path=/bar")); |
| 992 |
| 993 cm->DeleteCookie(GURL(std::string(kUrlGoogle) + "/foo/bar"), "A"); |
| 994 |
| 995 net::CookieMonster::CookieList cookies = cm->GetAllCookies(); |
| 996 size_t expected_size = 4; |
| 997 EXPECT_EQ(expected_size, cookies.size()); |
| 998 for (net::CookieMonster::CookieList::iterator it = cookies.begin(); |
| 999 it != cookies.end(); ++it) { |
| 1000 EXPECT_NE("A1", it->second.Value()); |
| 1001 EXPECT_NE("A2", it->second.Value()); |
| 1002 } |
| 1003 } |
| 1004 |
964 // TODO test overwrite cookie | 1005 // TODO test overwrite cookie |
OLD | NEW |