Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: net/base/cookie_monster_unittest.cc

Issue 2857029: Fix bug in DeleteAllForURL; deletes entire store instead of just (Closed)
Patch Set: Incorporated comments from eroman and mnissler. Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/cookie_monster.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 pc.IsSecure(), pc.IsHttpOnly(), 156 pc.IsSecure(), pc.IsHttpOnly(),
157 creation_time, creation_time, 157 creation_time, creation_time,
158 !cookie_expires.is_null(), 158 !cookie_expires.is_null(),
159 cookie_expires)); 159 cookie_expires));
160 160
161 out_list->push_back( 161 out_list->push_back(
162 net::CookieMonster::KeyedCanonicalCookie( 162 net::CookieMonster::KeyedCanonicalCookie(
163 key, cookie.release())); 163 key, cookie.release()));
164 } 164 }
165 165
166 // Helper for DeleteAllForHost test; repopulates CM with same layout
167 // each time.
168 const char* kTopLevelDomainPlus1 = "http://www.harvard.edu";
169 const char* kTopLevelDomainPlus2 = "http://www.math.harvard.edu";
170 const char* kTopLevelDomainPlus2Secure = "https://www.math.harvard.edu";
171 const char* kTopLevelDomainPlus3 =
172 "http://www.bourbaki.math.harvard.edu";
173 const char* kOtherDomain = "http://www.mit.edu";
174
175 void PopulateCmForDeleteAllForHost(scoped_refptr<net::CookieMonster> cm) {
176 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1);
177 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2);
178 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure);
179 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3);
180 GURL url_other(kOtherDomain);
181
182 cm->DeleteAll(true);
183
184 // Static population for probe:
185 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a)
186 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a)
187 // * http_only cookie (w.c.b.a)
188 // * Two secure cookies (.c.b.a, w.c.b.a)
189 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2)
190 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2)
191
192 // Domain cookies
193 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_1,
194 "dom_1", "X", ".harvard.edu", "/",
195 base::Time(), false, false));
196 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2,
197 "dom_2", "X", ".math.harvard.edu", "/",
198 base::Time(), false, false));
199 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_3,
200 "dom_3", "X",
201 ".bourbaki.math.harvard.edu", "/",
202 base::Time(), false, false));
203
204 // Host cookies
205 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_1,
206 "host_1", "X", "", "/",
207 base::Time(), false, false));
208 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2,
209 "host_2", "X", "", "/",
210 base::Time(), false, false));
211 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_3,
212 "host_3", "X", "", "/",
213 base::Time(), false, false));
214
215 // Http_only cookie
216 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2,
217 "httpo_check", "X", "", "/",
218 base::Time(), false, true));
219
220 // Secure cookies
221 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2_secure,
222 "sec_dom", "X", ".math.harvard.edu",
223 "/", base::Time(), true, false));
224 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2_secure,
225 "sec_host", "X", "", "/",
226 base::Time(), true, false));
227
228 // Domain path cookies
229 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2,
230 "dom_path_1", "X",
231 ".math.harvard.edu", "/dir1",
232 base::Time(), false, false));
233 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2,
234 "dom_path_2", "X",
235 ".math.harvard.edu", "/dir1/dir2",
236 base::Time(), false, false));
237
238 // Host path cookies
239 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2,
240 "host_path_1", "X",
241 "", "/dir1",
242 base::Time(), false, false));
243 EXPECT_TRUE(cm->SetCookieWithDetails(url_top_level_domain_plus_2,
244 "host_path_2", "X",
245 "", "/dir1/dir2",
246 base::Time(), false, false));
247
248 EXPECT_EQ(13U, cm->GetAllCookies().size());
249 }
250
166 } // namespace 251 } // namespace
167 252
168 253
169 TEST(ParsedCookieTest, TestBasic) { 254 TEST(ParsedCookieTest, TestBasic) {
170 net::CookieMonster::ParsedCookie pc("a=b"); 255 net::CookieMonster::ParsedCookie pc("a=b");
171 EXPECT_TRUE(pc.IsValid()); 256 EXPECT_TRUE(pc.IsValid());
172 EXPECT_FALSE(pc.IsSecure()); 257 EXPECT_FALSE(pc.IsSecure());
173 EXPECT_EQ("a", pc.Name()); 258 EXPECT_EQ("a", pc.Name());
174 EXPECT_EQ("b", pc.Value()); 259 EXPECT_EQ("b", pc.Value());
175 } 260 }
(...skipping 1448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1624 1709
1625 ASSERT_TRUE(it != cookies.end()); 1710 ASSERT_TRUE(it != cookies.end());
1626 EXPECT_EQ("E", it->second.Name()); 1711 EXPECT_EQ("E", it->second.Name());
1627 EXPECT_EQ("F", it->second.Value()); 1712 EXPECT_EQ("F", it->second.Value());
1628 EXPECT_EQ("/", it->second.Path()); 1713 EXPECT_EQ("/", it->second.Path());
1629 EXPECT_TRUE(it->second.IsSecure()); 1714 EXPECT_TRUE(it->second.IsSecure());
1630 EXPECT_FALSE(it->second.IsHttpOnly()); 1715 EXPECT_FALSE(it->second.IsHttpOnly());
1631 1716
1632 ASSERT_TRUE(++it == cookies.end()); 1717 ASSERT_TRUE(++it == cookies.end());
1633 } 1718 }
1719
1720
1721
1722 TEST(CookieMonsterTest, DeleteAllForHost) {
1723 scoped_refptr<net::CookieMonster> cm(new net::CookieMonster(NULL, NULL));
1724
1725 // Test probes:
1726 // * Non-secure URL, mid-level (http://w.c.b.a)
1727 // * Secure URL, mid-level (https://w.c.b.a)
1728 // * URL with path, mid-level (https:/w.c.b.a/dir1/xx)
1729 // All three tests should nuke only the midlevel host cookie,
1730 // the http_only cookie, the host secure cookie, and the two host
1731 // path cookies. http_only, secure, and paths are ignored by
1732 // this call, and domain cookies arent touched.
1733 PopulateCmForDeleteAllForHost(cm);
1734 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X",
1735 cm->GetCookies(GURL(kTopLevelDomainPlus3)));
1736 EXPECT_EQ("dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X",
1737 cm->GetCookies(GURL(kTopLevelDomainPlus2Secure)));
1738 EXPECT_EQ("dom_1=X; host_1=X", cm->GetCookies(GURL(kTopLevelDomainPlus1)));
1739 EXPECT_EQ("dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; "
1740 "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X",
1741 cm->GetCookies(GURL(kTopLevelDomainPlus2Secure +
1742 std::string("/dir1/dir2/xxx"))));
1743
1744 EXPECT_EQ(5, cm->DeleteAllForHost(GURL(kTopLevelDomainPlus2)));
1745 EXPECT_EQ(8U, cm->GetAllCookies().size());
1746
1747 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X",
1748 cm->GetCookies(GURL(kTopLevelDomainPlus3)));
1749 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X",
1750 cm->GetCookies(GURL(kTopLevelDomainPlus2Secure)));
1751 EXPECT_EQ("dom_1=X; host_1=X", cm->GetCookies(GURL(kTopLevelDomainPlus1)));
1752 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X",
1753 cm->GetCookies(GURL(kTopLevelDomainPlus2Secure +
1754 std::string("/dir1/dir2/xxx"))));
1755
1756 PopulateCmForDeleteAllForHost(cm);
1757 EXPECT_EQ(5, cm->DeleteAllForHost(GURL(kTopLevelDomainPlus2Secure)));
1758 EXPECT_EQ(8U, cm->GetAllCookies().size());
1759
1760 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X",
1761 cm->GetCookies(GURL(kTopLevelDomainPlus3)));
1762 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X",
1763 cm->GetCookies(GURL(kTopLevelDomainPlus2Secure)));
1764 EXPECT_EQ("dom_1=X; host_1=X", cm->GetCookies(GURL(kTopLevelDomainPlus1)));
1765 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X",
1766 cm->GetCookies(GURL(kTopLevelDomainPlus2Secure +
1767 std::string("/dir1/dir2/xxx"))));
1768
1769 PopulateCmForDeleteAllForHost(cm);
1770 EXPECT_EQ(5, cm->DeleteAllForHost(GURL(kTopLevelDomainPlus2Secure +
1771 std::string("/dir1/xxx"))));
1772 EXPECT_EQ(8U, cm->GetAllCookies().size());
1773
1774 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X",
1775 cm->GetCookies(GURL(kTopLevelDomainPlus3)));
1776 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X",
1777 cm->GetCookies(GURL(kTopLevelDomainPlus2Secure)));
1778 EXPECT_EQ("dom_1=X; host_1=X", cm->GetCookies(GURL(kTopLevelDomainPlus1)));
1779 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X",
1780 cm->GetCookies(GURL(kTopLevelDomainPlus2Secure +
1781 std::string("/dir1/dir2/xxx"))));
1782
1783 }
OLDNEW
« no previous file with comments | « net/base/cookie_monster.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698