| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a) | 50 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a) |
| 51 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a) | 51 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a) |
| 52 // * http_only cookie (w.c.b.a) | 52 // * http_only cookie (w.c.b.a) |
| 53 // * Two secure cookies (.c.b.a, w.c.b.a) | 53 // * Two secure cookies (.c.b.a, w.c.b.a) |
| 54 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) | 54 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) |
| 55 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) | 55 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) |
| 56 | 56 |
| 57 // Domain cookies | 57 // Domain cookies |
| 58 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_1, | 58 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_1, |
| 59 "dom_1", "X", ".harvard.edu", "/", | 59 "dom_1", "X", ".harvard.edu", "/", |
| 60 base::Time(), false, false)); | 60 base::Time(), false, false, false)); |
| 61 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2, | 61 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2, |
| 62 "dom_2", "X", ".math.harvard.edu", "/", | 62 "dom_2", "X", ".math.harvard.edu", "/", |
| 63 base::Time(), false, false)); | 63 base::Time(), false, false, false)); |
| 64 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_3, | 64 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_3, |
| 65 "dom_3", "X", | 65 "dom_3", "X", |
| 66 ".bourbaki.math.harvard.edu", "/", | 66 ".bourbaki.math.harvard.edu", "/", |
| 67 base::Time(), false, false)); | 67 base::Time(), false, false, false)); |
| 68 | 68 |
| 69 // Host cookies | 69 // Host cookies |
| 70 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_1, | 70 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_1, |
| 71 "host_1", "X", "", "/", | 71 "host_1", "X", "", "/", |
| 72 base::Time(), false, false)); | 72 base::Time(), false, false, false)); |
| 73 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2, | 73 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2, |
| 74 "host_2", "X", "", "/", | 74 "host_2", "X", "", "/", |
| 75 base::Time(), false, false)); | 75 base::Time(), false, false, false)); |
| 76 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_3, | 76 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_3, |
| 77 "host_3", "X", "", "/", | 77 "host_3", "X", "", "/", |
| 78 base::Time(), false, false)); | 78 base::Time(), false, false, false)); |
| 79 | 79 |
| 80 // Http_only cookie | 80 // Http_only cookie |
| 81 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2, | 81 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2, |
| 82 "httpo_check", "X", "", "/", | 82 "httpo_check", "X", "", "/", |
| 83 base::Time(), false, true)); | 83 base::Time(), false, true, false)); |
| 84 | 84 |
| 85 // Secure cookies | 85 // Secure cookies |
| 86 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2_secure, | 86 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2_secure, |
| 87 "sec_dom", "X", ".math.harvard.edu", | 87 "sec_dom", "X", ".math.harvard.edu", |
| 88 "/", base::Time(), true, false)); | 88 "/", base::Time(), true, false)); |
| 89 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2_secure, | 89 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2_secure, |
| 90 "sec_host", "X", "", "/", | 90 "sec_host", "X", "", "/", |
| 91 base::Time(), true, false)); | 91 base::Time(), true, false, false)); |
| 92 | 92 |
| 93 // Domain path cookies | 93 // Domain path cookies |
| 94 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2, | 94 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2, |
| 95 "dom_path_1", "X", | 95 "dom_path_1", "X", |
| 96 ".math.harvard.edu", "/dir1", | 96 ".math.harvard.edu", "/dir1", |
| 97 base::Time(), false, false)); | 97 base::Time(), false, false, false)); |
| 98 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2, | 98 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2, |
| 99 "dom_path_2", "X", | 99 "dom_path_2", "X", |
| 100 ".math.harvard.edu", "/dir1/dir2", | 100 ".math.harvard.edu", "/dir1/dir2", |
| 101 base::Time(), false, false)); | 101 base::Time(), false, false, false)); |
| 102 | 102 |
| 103 // Host path cookies | 103 // Host path cookies |
| 104 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2, | 104 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2, |
| 105 "host_path_1", "X", | 105 "host_path_1", "X", |
| 106 "", "/dir1", | 106 "", "/dir1", |
| 107 base::Time(), false, false)); | 107 base::Time(), false, false, false)); |
| 108 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2, | 108 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2, |
| 109 "host_path_2", "X", | 109 "host_path_2", "X", |
| 110 "", "/dir1/dir2", | 110 "", "/dir1/dir2", |
| 111 base::Time(), false, false)); | 111 base::Time(), false, false, false)); |
| 112 | 112 |
| 113 EXPECT_EQ(13U, cm->GetAllCookies().size()); | 113 EXPECT_EQ(13U, cm->GetAllCookies().size()); |
| 114 } | 114 } |
| 115 | 115 |
| 116 } // namespace | 116 } // namespace |
| 117 | 117 |
| 118 TEST(ParsedCookieTest, TestBasic) { | 118 TEST(ParsedCookieTest, TestBasic) { |
| 119 net::CookieMonster::ParsedCookie pc("a=b"); | 119 net::CookieMonster::ParsedCookie pc("a=b"); |
| 120 EXPECT_TRUE(pc.IsValid()); | 120 EXPECT_TRUE(pc.IsValid()); |
| 121 EXPECT_FALSE(pc.IsSecure()); | 121 EXPECT_FALSE(pc.IsSecure()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 149 | 149 |
| 150 for (size_t i = 0; i < arraysize(values); i += 2) { | 150 for (size_t i = 0; i < arraysize(values); i += 2) { |
| 151 std::string input(values[i]); | 151 std::string input(values[i]); |
| 152 std::string expected(values[i + 1]); | 152 std::string expected(values[i + 1]); |
| 153 | 153 |
| 154 net::CookieMonster::ParsedCookie pc( | 154 net::CookieMonster::ParsedCookie pc( |
| 155 "aBc=" + input + " ; path=\"/\" ; httponly "); | 155 "aBc=" + input + " ; path=\"/\" ; httponly "); |
| 156 EXPECT_TRUE(pc.IsValid()); | 156 EXPECT_TRUE(pc.IsValid()); |
| 157 EXPECT_FALSE(pc.IsSecure()); | 157 EXPECT_FALSE(pc.IsSecure()); |
| 158 EXPECT_TRUE(pc.IsHttpOnly()); | 158 EXPECT_TRUE(pc.IsHttpOnly()); |
| 159 EXPECT_FALSE(pc.IsOrigin()); |
| 159 EXPECT_TRUE(pc.HasPath()); | 160 EXPECT_TRUE(pc.HasPath()); |
| 160 EXPECT_EQ("aBc", pc.Name()); | 161 EXPECT_EQ("aBc", pc.Name()); |
| 161 EXPECT_EQ(expected, pc.Value()); | 162 EXPECT_EQ(expected, pc.Value()); |
| 162 | 163 |
| 163 // If a path was quoted, the path attribute keeps the quotes. This will | 164 // If a path was quoted, the path attribute keeps the quotes. This will |
| 164 // make the cookie effectively useless, but path parameters aren't supposed | 165 // make the cookie effectively useless, but path parameters aren't supposed |
| 165 // to be quoted. Bug 1261605. | 166 // to be quoted. Bug 1261605. |
| 166 EXPECT_EQ("\"/\"", pc.Path()); | 167 EXPECT_EQ("\"/\"", pc.Path()); |
| 167 } | 168 } |
| 168 } | 169 } |
| 169 | 170 |
| 170 TEST(ParsedCookieTest, TestNameless) { | 171 TEST(ParsedCookieTest, TestNameless) { |
| 171 net::CookieMonster::ParsedCookie pc("BLAHHH; path=/; secure;"); | 172 net::CookieMonster::ParsedCookie pc("BLAHHH; path=/; secure;"); |
| 172 EXPECT_TRUE(pc.IsValid()); | 173 EXPECT_TRUE(pc.IsValid()); |
| 173 EXPECT_TRUE(pc.IsSecure()); | 174 EXPECT_TRUE(pc.IsSecure()); |
| 174 EXPECT_TRUE(pc.HasPath()); | 175 EXPECT_TRUE(pc.HasPath()); |
| 175 EXPECT_EQ("/", pc.Path()); | 176 EXPECT_EQ("/", pc.Path()); |
| 176 EXPECT_EQ("", pc.Name()); | 177 EXPECT_EQ("", pc.Name()); |
| 177 EXPECT_EQ("BLAHHH", pc.Value()); | 178 EXPECT_EQ("BLAHHH", pc.Value()); |
| 178 } | 179 } |
| 179 | 180 |
| 180 TEST(ParsedCookieTest, TestAttributeCase) { | 181 TEST(ParsedCookieTest, TestAttributeCase) { |
| 181 net::CookieMonster::ParsedCookie pc("BLAHHH; Path=/; sECuRe; httpONLY"); | 182 net::CookieMonster::ParsedCookie pc("BLAHHH; Path=/; sECuRe; httpONLY"); |
| 182 EXPECT_TRUE(pc.IsValid()); | 183 EXPECT_TRUE(pc.IsValid()); |
| 183 EXPECT_TRUE(pc.IsSecure()); | 184 EXPECT_TRUE(pc.IsSecure()); |
| 184 EXPECT_TRUE(pc.IsHttpOnly()); | 185 EXPECT_TRUE(pc.IsHttpOnly()); |
| 186 EXPECT_FALSE(pc.IsOrigin()); |
| 185 EXPECT_TRUE(pc.HasPath()); | 187 EXPECT_TRUE(pc.HasPath()); |
| 186 EXPECT_EQ("/", pc.Path()); | 188 EXPECT_EQ("/", pc.Path()); |
| 187 EXPECT_EQ("", pc.Name()); | 189 EXPECT_EQ("", pc.Name()); |
| 188 EXPECT_EQ("BLAHHH", pc.Value()); | 190 EXPECT_EQ("BLAHHH", pc.Value()); |
| 189 EXPECT_EQ(3U, pc.NumberOfAttributes()); | 191 EXPECT_EQ(3U, pc.NumberOfAttributes()); |
| 190 } | 192 } |
| 191 | 193 |
| 192 TEST(ParsedCookieTest, TestDoubleQuotedNameless) { | 194 TEST(ParsedCookieTest, TestDoubleQuotedNameless) { |
| 193 net::CookieMonster::ParsedCookie pc("\"BLA\\\"HHH\"; path=/; secure;"); | 195 net::CookieMonster::ParsedCookie pc("\"BLA\\\"HHH\"; path=/; secure;"); |
| 194 EXPECT_TRUE(pc.IsValid()); | 196 EXPECT_TRUE(pc.IsValid()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 230 |
| 229 TEST(ParsedCookieTest, Whitespace) { | 231 TEST(ParsedCookieTest, Whitespace) { |
| 230 net::CookieMonster::ParsedCookie pc(" A = BC ;secure;;; httponly"); | 232 net::CookieMonster::ParsedCookie pc(" A = BC ;secure;;; httponly"); |
| 231 EXPECT_TRUE(pc.IsValid()); | 233 EXPECT_TRUE(pc.IsValid()); |
| 232 EXPECT_EQ("A", pc.Name()); | 234 EXPECT_EQ("A", pc.Name()); |
| 233 EXPECT_EQ("BC", pc.Value()); | 235 EXPECT_EQ("BC", pc.Value()); |
| 234 EXPECT_FALSE(pc.HasPath()); | 236 EXPECT_FALSE(pc.HasPath()); |
| 235 EXPECT_FALSE(pc.HasDomain()); | 237 EXPECT_FALSE(pc.HasDomain()); |
| 236 EXPECT_TRUE(pc.IsSecure()); | 238 EXPECT_TRUE(pc.IsSecure()); |
| 237 EXPECT_TRUE(pc.IsHttpOnly()); | 239 EXPECT_TRUE(pc.IsHttpOnly()); |
| 240 EXPECT_FALSE(pc.IsOrigin()); |
| 238 // We parse anything between ; as attributes, so we end up with two | 241 // We parse anything between ; as attributes, so we end up with two |
| 239 // attributes with an empty string name and value. | 242 // attributes with an empty string name and value. |
| 240 EXPECT_EQ(4U, pc.NumberOfAttributes()); | 243 EXPECT_EQ(4U, pc.NumberOfAttributes()); |
| 241 } | 244 } |
| 242 TEST(ParsedCookieTest, MultipleEquals) { | 245 TEST(ParsedCookieTest, MultipleEquals) { |
| 243 net::CookieMonster::ParsedCookie pc(" A=== BC ;secure;;; httponly"); | 246 net::CookieMonster::ParsedCookie pc(" A=== BC ;secure;;; httponly"); |
| 244 EXPECT_TRUE(pc.IsValid()); | 247 EXPECT_TRUE(pc.IsValid()); |
| 245 EXPECT_EQ("A", pc.Name()); | 248 EXPECT_EQ("A", pc.Name()); |
| 246 EXPECT_EQ("== BC", pc.Value()); | 249 EXPECT_EQ("== BC", pc.Value()); |
| 247 EXPECT_FALSE(pc.HasPath()); | 250 EXPECT_FALSE(pc.HasPath()); |
| 248 EXPECT_FALSE(pc.HasDomain()); | 251 EXPECT_FALSE(pc.HasDomain()); |
| 249 EXPECT_TRUE(pc.IsSecure()); | 252 EXPECT_TRUE(pc.IsSecure()); |
| 250 EXPECT_TRUE(pc.IsHttpOnly()); | 253 EXPECT_TRUE(pc.IsHttpOnly()); |
| 254 EXPECT_FALSE(pc.IsOrigin()); |
| 251 EXPECT_EQ(4U, pc.NumberOfAttributes()); | 255 EXPECT_EQ(4U, pc.NumberOfAttributes()); |
| 252 } | 256 } |
| 253 | 257 |
| 254 TEST(ParsedCookieTest, QuotedTrailingWhitespace) { | 258 TEST(ParsedCookieTest, QuotedTrailingWhitespace) { |
| 255 net::CookieMonster::ParsedCookie pc("ANCUUID=\"zohNumRKgI0oxyhSsV3Z7D\" ; " | 259 net::CookieMonster::ParsedCookie pc("ANCUUID=\"zohNumRKgI0oxyhSsV3Z7D\" ; " |
| 256 "expires=Sun, 18-Apr-2027 21:06:29 GMT ; " | 260 "expires=Sun, 18-Apr-2027 21:06:29 GMT ; " |
| 257 "path=/ ; "); | 261 "path=/ ; "); |
| 258 EXPECT_TRUE(pc.IsValid()); | 262 EXPECT_TRUE(pc.IsValid()); |
| 259 EXPECT_EQ("ANCUUID", pc.Name()); | 263 EXPECT_EQ("ANCUUID", pc.Name()); |
| 260 // Stripping whitespace after the quotes matches all other major browsers. | 264 // Stripping whitespace after the quotes matches all other major browsers. |
| (...skipping 1324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1585 TEST(CookieMonsterTest, SetCookieWithDetails) { | 1589 TEST(CookieMonsterTest, SetCookieWithDetails) { |
| 1586 GURL url_google(kUrlGoogle); | 1590 GURL url_google(kUrlGoogle); |
| 1587 GURL url_google_foo("http://www.google.izzle/foo"); | 1591 GURL url_google_foo("http://www.google.izzle/foo"); |
| 1588 GURL url_google_bar("http://www.google.izzle/bar"); | 1592 GURL url_google_bar("http://www.google.izzle/bar"); |
| 1589 GURL url_google_secure(kUrlGoogleSecure); | 1593 GURL url_google_secure(kUrlGoogleSecure); |
| 1590 | 1594 |
| 1591 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL)); | 1595 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL)); |
| 1592 | 1596 |
| 1593 EXPECT_TRUE(cm->SetCookieWithDetails( | 1597 EXPECT_TRUE(cm->SetCookieWithDetails( |
| 1594 url_google_foo, "A", "B", std::string(), "/foo", base::Time(), | 1598 url_google_foo, "A", "B", std::string(), "/foo", base::Time(), |
| 1595 false, false)); | 1599 false, false, false)); |
| 1596 EXPECT_TRUE(cm->SetCookieWithDetails( | 1600 EXPECT_TRUE(cm->SetCookieWithDetails( |
| 1597 url_google_bar, "C", "D", "google.izzle", "/bar", base::Time(), | 1601 url_google_bar, "C", "D", "google.izzle", "/bar", base::Time(), |
| 1598 false, true)); | 1602 false, true, false)); |
| 1599 EXPECT_TRUE(cm->SetCookieWithDetails( | 1603 EXPECT_TRUE(cm->SetCookieWithDetails( |
| 1600 url_google, "E", "F", std::string(), std::string(), base::Time(), | 1604 url_google, "E", "F", std::string(), std::string(), base::Time(), |
| 1601 true, false)); | 1605 true, false, false)); |
| 1602 | 1606 |
| 1603 // Test that malformed attributes fail to set the cookie. | 1607 // Test that malformed attributes fail to set the cookie. |
| 1604 EXPECT_FALSE(cm->SetCookieWithDetails( | 1608 EXPECT_FALSE(cm->SetCookieWithDetails( |
| 1605 url_google_foo, " A", "B", std::string(), "/foo", base::Time(), | 1609 url_google_foo, " A", "B", std::string(), "/foo", base::Time(), |
| 1606 false, false)); | 1610 false, false, false)); |
| 1607 EXPECT_FALSE(cm->SetCookieWithDetails( | 1611 EXPECT_FALSE(cm->SetCookieWithDetails( |
| 1608 url_google_foo, "A;", "B", std::string(), "/foo", base::Time(), | 1612 url_google_foo, "A;", "B", std::string(), "/foo", base::Time(), |
| 1609 false, false)); | 1613 false, false, false)); |
| 1610 EXPECT_FALSE(cm->SetCookieWithDetails( | 1614 EXPECT_FALSE(cm->SetCookieWithDetails( |
| 1611 url_google_foo, "A=", "B", std::string(), "/foo", base::Time(), | 1615 url_google_foo, "A=", "B", std::string(), "/foo", base::Time(), |
| 1612 false, false)); | 1616 false, false, false)); |
| 1613 EXPECT_FALSE(cm->SetCookieWithDetails( | 1617 EXPECT_FALSE(cm->SetCookieWithDetails( |
| 1614 url_google_foo, "A", "B", "google.ozzzzzzle", "foo", base::Time(), | 1618 url_google_foo, "A", "B", "google.ozzzzzzle", "foo", base::Time(), |
| 1615 false, false)); | 1619 false, false, false)); |
| 1616 EXPECT_FALSE(cm->SetCookieWithDetails( | 1620 EXPECT_FALSE(cm->SetCookieWithDetails( |
| 1617 url_google_foo, "A=", "B", std::string(), "foo", base::Time(), | 1621 url_google_foo, "A=", "B", std::string(), "foo", base::Time(), |
| 1618 false, false)); | 1622 false, false, false)); |
| 1619 | 1623 |
| 1620 net::CookieMonster::CookieList cookies = | 1624 net::CookieMonster::CookieList cookies = |
| 1621 cm->GetAllCookiesForURL(url_google_foo); | 1625 cm->GetAllCookiesForURL(url_google_foo); |
| 1622 net::CookieMonster::CookieList::iterator it = cookies.begin(); | 1626 net::CookieMonster::CookieList::iterator it = cookies.begin(); |
| 1623 | 1627 |
| 1624 ASSERT_TRUE(it != cookies.end()); | 1628 ASSERT_TRUE(it != cookies.end()); |
| 1625 EXPECT_EQ("A", it->Name()); | 1629 EXPECT_EQ("A", it->Name()); |
| 1626 EXPECT_EQ("B", it->Value()); | 1630 EXPECT_EQ("B", it->Value()); |
| 1627 EXPECT_EQ("www.google.izzle", it->Domain()); | 1631 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 1628 EXPECT_EQ("/foo", it->Path()); | 1632 EXPECT_EQ("/foo", it->Path()); |
| 1629 EXPECT_FALSE(it->DoesExpire()); | 1633 EXPECT_FALSE(it->DoesExpire()); |
| 1630 EXPECT_FALSE(it->IsSecure()); | 1634 EXPECT_FALSE(it->IsSecure()); |
| 1631 EXPECT_FALSE(it->IsHttpOnly()); | 1635 EXPECT_FALSE(it->IsHttpOnly()); |
| 1636 EXPECT_FALSE(it->IsOrigin()); |
| 1632 | 1637 |
| 1633 ASSERT_TRUE(++it == cookies.end()); | 1638 ASSERT_TRUE(++it == cookies.end()); |
| 1634 | 1639 |
| 1635 cookies = cm->GetAllCookiesForURL(url_google_bar); | 1640 cookies = cm->GetAllCookiesForURL(url_google_bar); |
| 1636 it = cookies.begin(); | 1641 it = cookies.begin(); |
| 1637 | 1642 |
| 1638 ASSERT_TRUE(it != cookies.end()); | 1643 ASSERT_TRUE(it != cookies.end()); |
| 1639 EXPECT_EQ("C", it->Name()); | 1644 EXPECT_EQ("C", it->Name()); |
| 1640 EXPECT_EQ("D", it->Value()); | 1645 EXPECT_EQ("D", it->Value()); |
| 1641 EXPECT_EQ(".google.izzle", it->Domain()); | 1646 EXPECT_EQ(".google.izzle", it->Domain()); |
| 1642 EXPECT_EQ("/bar", it->Path()); | 1647 EXPECT_EQ("/bar", it->Path()); |
| 1643 EXPECT_FALSE(it->IsSecure()); | 1648 EXPECT_FALSE(it->IsSecure()); |
| 1644 EXPECT_TRUE(it->IsHttpOnly()); | 1649 EXPECT_TRUE(it->IsHttpOnly()); |
| 1650 EXPECT_FALSE(it->IsOrigin()); |
| 1645 | 1651 |
| 1646 ASSERT_TRUE(++it == cookies.end()); | 1652 ASSERT_TRUE(++it == cookies.end()); |
| 1647 | 1653 |
| 1648 cookies = cm->GetAllCookiesForURL(url_google_secure); | 1654 cookies = cm->GetAllCookiesForURL(url_google_secure); |
| 1649 it = cookies.begin(); | 1655 it = cookies.begin(); |
| 1650 | 1656 |
| 1651 ASSERT_TRUE(it != cookies.end()); | 1657 ASSERT_TRUE(it != cookies.end()); |
| 1652 EXPECT_EQ("E", it->Name()); | 1658 EXPECT_EQ("E", it->Name()); |
| 1653 EXPECT_EQ("F", it->Value()); | 1659 EXPECT_EQ("F", it->Value()); |
| 1654 EXPECT_EQ("/", it->Path()); | 1660 EXPECT_EQ("/", it->Path()); |
| 1655 EXPECT_EQ("www.google.izzle", it->Domain()); | 1661 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 1656 EXPECT_TRUE(it->IsSecure()); | 1662 EXPECT_TRUE(it->IsSecure()); |
| 1657 EXPECT_FALSE(it->IsHttpOnly()); | 1663 EXPECT_FALSE(it->IsHttpOnly()); |
| 1664 EXPECT_FALSE(it->IsOrigin()); |
| 1658 | 1665 |
| 1659 ASSERT_TRUE(++it == cookies.end()); | 1666 ASSERT_TRUE(++it == cookies.end()); |
| 1660 } | 1667 } |
| 1661 | 1668 |
| 1662 TEST(CookieMonsterTest, DeleteAllForHost) { | 1669 TEST(CookieMonsterTest, DeleteAllForHost) { |
| 1663 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL)); | 1670 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL)); |
| 1664 | 1671 |
| 1665 // Test probes: | 1672 // Test probes: |
| 1666 // * Non-secure URL, mid-level (http://w.c.b.a) | 1673 // * Non-secure URL, mid-level (http://w.c.b.a) |
| 1667 // * Secure URL, mid-level (https://w.c.b.a) | 1674 // * Secure URL, mid-level (https://w.c.b.a) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1757 cookie_lines.push_back("setCookiesWithOptions3=A"); | 1764 cookie_lines.push_back("setCookiesWithOptions3=A"); |
| 1758 | 1765 |
| 1759 cm->SetCookiesWithOptions(url_google, cookie_lines, options); | 1766 cm->SetCookiesWithOptions(url_google, cookie_lines, options); |
| 1760 } | 1767 } |
| 1761 | 1768 |
| 1762 cm->SetCookieWithOptions(url_google, "setCookieWithOptions1=A", options); | 1769 cm->SetCookieWithOptions(url_google, "setCookieWithOptions1=A", options); |
| 1763 cm->SetCookieWithOptions(url_google, "setCookieWithOptions2=A", options); | 1770 cm->SetCookieWithOptions(url_google, "setCookieWithOptions2=A", options); |
| 1764 cm->SetCookieWithOptions(url_google, "setCookieWithOptions3=A", options); | 1771 cm->SetCookieWithOptions(url_google, "setCookieWithOptions3=A", options); |
| 1765 | 1772 |
| 1766 cm->SetCookieWithDetails(url_google, "setCookieWithDetails1", "A", | 1773 cm->SetCookieWithDetails(url_google, "setCookieWithDetails1", "A", |
| 1767 ".google.com", "/", Time(), false, false); | 1774 ".google.com", "/", Time(), false, false, false); |
| 1768 cm->SetCookieWithDetails(url_google, "setCookieWithDetails2", "A", | 1775 cm->SetCookieWithDetails(url_google, "setCookieWithDetails2", "A", |
| 1769 ".google.com", "/", Time(), false, false); | 1776 ".google.com", "/", Time(), false, false, false); |
| 1770 cm->SetCookieWithDetails(url_google, "setCookieWithDetails3", "A", | 1777 cm->SetCookieWithDetails(url_google, "setCookieWithDetails3", "A", |
| 1771 ".google.com", "/", Time(), false, false); | 1778 ".google.com", "/", Time(), false, false, false); |
| 1772 | 1779 |
| 1773 // Now we check | 1780 // Now we check |
| 1774 net::CookieMonster::CookieList cookie_list(cm->GetAllCookies()); | 1781 net::CookieMonster::CookieList cookie_list(cm->GetAllCookies()); |
| 1775 typedef std::map<int64, net::CookieMonster::CanonicalCookie> TimeCookieMap; | 1782 typedef std::map<int64, net::CookieMonster::CanonicalCookie> TimeCookieMap; |
| 1776 TimeCookieMap check_map; | 1783 TimeCookieMap check_map; |
| 1777 for (net::CookieMonster::CookieList::const_iterator it = cookie_list.begin(); | 1784 for (net::CookieMonster::CookieList::const_iterator it = cookie_list.begin(); |
| 1778 it != cookie_list.end(); it++) { | 1785 it != cookie_list.end(); it++) { |
| 1779 const int64 creation_date = it->CreationDate().ToInternalValue(); | 1786 const int64 creation_date = it->CreationDate().ToInternalValue(); |
| 1780 TimeCookieMap::const_iterator | 1787 TimeCookieMap::const_iterator |
| 1781 existing_cookie_it(check_map.find(creation_date)); | 1788 existing_cookie_it(check_map.find(creation_date)); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1831 | 1838 |
| 1832 struct CookiesInputInfo { | 1839 struct CookiesInputInfo { |
| 1833 std::string gurl; | 1840 std::string gurl; |
| 1834 std::string name; | 1841 std::string name; |
| 1835 std::string value; | 1842 std::string value; |
| 1836 std::string domain; | 1843 std::string domain; |
| 1837 std::string path; | 1844 std::string path; |
| 1838 base::Time expires; | 1845 base::Time expires; |
| 1839 bool secure; | 1846 bool secure; |
| 1840 bool http_only; | 1847 bool http_only; |
| 1848 bool origin; |
| 1841 }; | 1849 }; |
| 1842 const CookiesInputInfo input_info[] = { | 1850 const CookiesInputInfo input_info[] = { |
| 1843 {"http://a.b.google.com", "a", "1", "", "/path/to/cookie", expires, | 1851 {"http://a.b.google.com", "a", "1", "", "/path/to/cookie", expires, |
| 1844 false, false}, | 1852 false, false, false}, |
| 1845 {"https://www.google.com", "b", "2", ".google.com", "/path/from/cookie", | 1853 {"https://www.google.com", "b", "2", ".google.com", "/path/from/cookie", |
| 1846 expires + TimeDelta::FromSeconds(10), true, true}, | 1854 expires + TimeDelta::FromSeconds(10), true, true, false}, |
| 1847 {"https://google.com", "c", "3", "", "/another/path/to/cookie", | 1855 {"https://google.com", "c", "3", "", "/another/path/to/cookie", |
| 1848 base::Time::Now() + base::TimeDelta::FromSeconds(100), | 1856 base::Time::Now() + base::TimeDelta::FromSeconds(100), |
| 1849 true, false} | 1857 true, false, false} |
| 1850 }; | 1858 }; |
| 1851 const int INPUT_DELETE = 1; | 1859 const int INPUT_DELETE = 1; |
| 1852 | 1860 |
| 1853 // Create new cookies and flush them to the store. | 1861 // Create new cookies and flush them to the store. |
| 1854 { | 1862 { |
| 1855 scoped_refptr<net::CookieMonster> cmout(new CookieMonster(store, NULL)); | 1863 scoped_refptr<net::CookieMonster> cmout(new CookieMonster(store, NULL)); |
| 1856 for (const CookiesInputInfo* p = input_info; | 1864 for (const CookiesInputInfo* p = input_info; |
| 1857 p < &input_info[ARRAYSIZE_UNSAFE(input_info)]; p++) { | 1865 p < &input_info[ARRAYSIZE_UNSAFE(input_info)]; p++) { |
| 1858 EXPECT_TRUE(cmout->SetCookieWithDetails(GURL(p->gurl), p->name, p->value, | 1866 EXPECT_TRUE(cmout->SetCookieWithDetails(GURL(p->gurl), p->name, p->value, |
| 1859 p->domain, p->path, p->expires, | 1867 p->domain, p->path, p->expires, |
| 1860 p->secure, p->http_only)); | 1868 p->secure, p->http_only, |
| 1869 p->origin)); |
| 1861 } | 1870 } |
| 1862 cmout->DeleteCookie(GURL(std::string(input_info[INPUT_DELETE].gurl) + | 1871 cmout->DeleteCookie(GURL(std::string(input_info[INPUT_DELETE].gurl) + |
| 1863 input_info[INPUT_DELETE].path), | 1872 input_info[INPUT_DELETE].path), |
| 1864 input_info[INPUT_DELETE].name); | 1873 input_info[INPUT_DELETE].name); |
| 1865 } | 1874 } |
| 1866 | 1875 |
| 1867 // Create a new cookie monster and make sure that everything is correct | 1876 // Create a new cookie monster and make sure that everything is correct |
| 1868 { | 1877 { |
| 1869 scoped_refptr<net::CookieMonster> cmin(new CookieMonster(store, NULL)); | 1878 scoped_refptr<net::CookieMonster> cmin(new CookieMonster(store, NULL)); |
| 1870 CookieMonster::CookieList cookies(cmin->GetAllCookies()); | 1879 CookieMonster::CookieList cookies(cmin->GetAllCookies()); |
| 1871 ASSERT_EQ(2u, cookies.size()); | 1880 ASSERT_EQ(2u, cookies.size()); |
| 1872 // Ordering is path length, then creation time. So second cookie | 1881 // Ordering is path length, then creation time. So second cookie |
| 1873 // will come first, and we need to swap them. | 1882 // will come first, and we need to swap them. |
| 1874 std::swap(cookies[0], cookies[1]); | 1883 std::swap(cookies[0], cookies[1]); |
| 1875 for (int output_index = 0; output_index < 2; output_index++) { | 1884 for (int output_index = 0; output_index < 2; output_index++) { |
| 1876 int input_index = output_index * 2; | 1885 int input_index = output_index * 2; |
| 1877 const CookiesInputInfo* input = &input_info[input_index]; | 1886 const CookiesInputInfo* input = &input_info[input_index]; |
| 1878 const CookieMonster::CanonicalCookie* output = &cookies[output_index]; | 1887 const CookieMonster::CanonicalCookie* output = &cookies[output_index]; |
| 1879 | 1888 |
| 1880 EXPECT_EQ(input->name, output->Name()); | 1889 EXPECT_EQ(input->name, output->Name()); |
| 1881 EXPECT_EQ(input->value, output->Value()); | 1890 EXPECT_EQ(input->value, output->Value()); |
| 1882 EXPECT_EQ(GURL(input->gurl).host(), output->Domain()); | 1891 EXPECT_EQ(GURL(input->gurl).host(), output->Domain()); |
| 1883 EXPECT_EQ(input->path, output->Path()); | 1892 EXPECT_EQ(input->path, output->Path()); |
| 1884 EXPECT_LE(current.ToInternalValue(), | 1893 EXPECT_LE(current.ToInternalValue(), |
| 1885 output->CreationDate().ToInternalValue()); | 1894 output->CreationDate().ToInternalValue()); |
| 1886 EXPECT_EQ(input->secure, output->IsSecure()); | 1895 EXPECT_EQ(input->secure, output->IsSecure()); |
| 1887 EXPECT_EQ(input->http_only, output->IsHttpOnly()); | 1896 EXPECT_EQ(input->http_only, output->IsHttpOnly()); |
| 1897 EXPECT_EQ(input->origin, output->IsOrigin()); |
| 1888 EXPECT_TRUE(output->IsPersistent()); | 1898 EXPECT_TRUE(output->IsPersistent()); |
| 1889 EXPECT_EQ(input->expires.ToInternalValue(), | 1899 EXPECT_EQ(input->expires.ToInternalValue(), |
| 1890 output->ExpiryDate().ToInternalValue()); | 1900 output->ExpiryDate().ToInternalValue()); |
| 1891 } | 1901 } |
| 1892 } | 1902 } |
| 1893 } | 1903 } |
| 1894 | 1904 |
| 1895 TEST(CookieMonsterTest, CookieOrdering) { | 1905 TEST(CookieMonsterTest, CookieOrdering) { |
| 1896 // Put a random set of cookies into a monster and make sure | 1906 // Put a random set of cookies into a monster and make sure |
| 1897 // they're returned in the right order. | 1907 // they're returned in the right order. |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2027 // Will trigger GC | 2037 // Will trigger GC |
| 2028 cm->SetCookie(GURL("http://newdomain.com"), "b=2"); | 2038 cm->SetCookie(GURL("http://newdomain.com"), "b=2"); |
| 2029 EXPECT_EQ(test_case->expected_cookies_after_set[recent_scheme], | 2039 EXPECT_EQ(test_case->expected_cookies_after_set[recent_scheme], |
| 2030 static_cast<int>((cm->GetAllCookies().size()))) | 2040 static_cast<int>((cm->GetAllCookies().size()))) |
| 2031 << "For test case (" << ci << ", " << recent_scheme << ")"; | 2041 << "For test case (" << ci << ", " << recent_scheme << ")"; |
| 2032 } | 2042 } |
| 2033 } | 2043 } |
| 2034 } | 2044 } |
| 2035 | 2045 |
| 2036 } // namespace | 2046 } // namespace |
| OLD | NEW |