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

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

Issue 1615773005: Rename first-party-only cookies to same-site cookies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tests. Created 4 years, 10 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/cookies/cookie_monster_store_test.cc ('k') | net/cookies/cookie_options.h » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/cookies/cookie_store_unittest.h" 5 #include "net/cookies/cookie_store_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 bool SetCookieWithDetails(CookieMonster* cm, 148 bool SetCookieWithDetails(CookieMonster* cm,
149 const GURL& url, 149 const GURL& url,
150 const std::string& name, 150 const std::string& name,
151 const std::string& value, 151 const std::string& value,
152 const std::string& domain, 152 const std::string& domain,
153 const std::string& path, 153 const std::string& path,
154 const base::Time& expiration_time, 154 const base::Time& expiration_time,
155 bool secure, 155 bool secure,
156 bool http_only, 156 bool http_only,
157 bool first_party_only, 157 bool same_site,
158 CookiePriority priority) { 158 CookiePriority priority) {
159 DCHECK(cm); 159 DCHECK(cm);
160 ResultSavingCookieCallback<bool> callback; 160 ResultSavingCookieCallback<bool> callback;
161 cm->SetCookieWithDetailsAsync( 161 cm->SetCookieWithDetailsAsync(
162 url, name, value, domain, path, expiration_time, secure, http_only, 162 url, name, value, domain, path, expiration_time, secure, http_only,
163 first_party_only, false /* enforce prefixes */, 163 same_site, false /* enforce prefixes */,
164 false /* enforces strict secure cookies */, priority, 164 false /* enforces strict secure cookies */, priority,
165 base::Bind(&ResultSavingCookieCallback<bool>::Run, 165 base::Bind(&ResultSavingCookieCallback<bool>::Run,
166 base::Unretained(&callback))); 166 base::Unretained(&callback)));
167 RunFor(kTimeout); 167 RunFor(kTimeout);
168 EXPECT_TRUE(callback.did_run()); 168 EXPECT_TRUE(callback.did_run());
169 return callback.result(); 169 return callback.result();
170 } 170 }
171 171
172 bool SetAllCookies(CookieMonster* cm, const CookieList& list) { 172 bool SetAllCookies(CookieMonster* cm, const CookieList& list) {
173 DCHECK(cm); 173 DCHECK(cm);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); 249 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure);
250 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); 250 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3);
251 GURL url_other(kOtherDomain); 251 GURL url_other(kOtherDomain);
252 252
253 DeleteAll(cm.get()); 253 DeleteAll(cm.get());
254 254
255 // Static population for probe: 255 // Static population for probe:
256 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a) 256 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a)
257 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a) 257 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a)
258 // * http_only cookie (w.c.b.a) 258 // * http_only cookie (w.c.b.a)
259 // * first-party cookie (w.c.b.a) 259 // * same_site cookie (w.c.b.a)
260 // * Two secure cookies (.c.b.a, w.c.b.a) 260 // * Two secure cookies (.c.b.a, w.c.b.a)
261 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) 261 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2)
262 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) 262 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2)
263 263
264 // Domain cookies 264 // Domain cookies
265 EXPECT_TRUE(this->SetCookieWithDetails( 265 EXPECT_TRUE(this->SetCookieWithDetails(
266 cm.get(), url_top_level_domain_plus_1, "dom_1", "X", ".harvard.edu", 266 cm.get(), url_top_level_domain_plus_1, "dom_1", "X", ".harvard.edu",
267 "/", base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); 267 "/", base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT));
268 EXPECT_TRUE(this->SetCookieWithDetails( 268 EXPECT_TRUE(this->SetCookieWithDetails(
269 cm.get(), url_top_level_domain_plus_2, "dom_2", "X", 269 cm.get(), url_top_level_domain_plus_2, "dom_2", "X",
(...skipping 14 matching lines...) Expand all
284 EXPECT_TRUE(this->SetCookieWithDetails( 284 EXPECT_TRUE(this->SetCookieWithDetails(
285 cm.get(), url_top_level_domain_plus_3, "host_3", "X", std::string(), 285 cm.get(), url_top_level_domain_plus_3, "host_3", "X", std::string(),
286 "/", base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); 286 "/", base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT));
287 287
288 // http_only cookie 288 // http_only cookie
289 EXPECT_TRUE(this->SetCookieWithDetails( 289 EXPECT_TRUE(this->SetCookieWithDetails(
290 cm.get(), url_top_level_domain_plus_2, "httpo_check", "x", 290 cm.get(), url_top_level_domain_plus_2, "httpo_check", "x",
291 std::string(), "/", base::Time(), false, true, false, 291 std::string(), "/", base::Time(), false, true, false,
292 COOKIE_PRIORITY_DEFAULT)); 292 COOKIE_PRIORITY_DEFAULT));
293 293
294 // first-party cookie 294 // same-site cookie
295 EXPECT_TRUE(this->SetCookieWithDetails( 295 EXPECT_TRUE(this->SetCookieWithDetails(
296 cm.get(), url_top_level_domain_plus_2, "firstp_check", "x", 296 cm.get(), url_top_level_domain_plus_2, "sames_check", "x",
297 std::string(), "/", base::Time(), false, false, true, 297 std::string(), "/", base::Time(), false, false, true,
298 COOKIE_PRIORITY_DEFAULT)); 298 COOKIE_PRIORITY_DEFAULT));
299 299
300 // Secure cookies 300 // Secure cookies
301 EXPECT_TRUE(this->SetCookieWithDetails( 301 EXPECT_TRUE(this->SetCookieWithDetails(
302 cm.get(), url_top_level_domain_plus_2_secure, "sec_dom", "X", 302 cm.get(), url_top_level_domain_plus_2_secure, "sec_dom", "X",
303 ".math.harvard.edu", "/", base::Time(), true, false, false, 303 ".math.harvard.edu", "/", base::Time(), true, false, false,
304 COOKIE_PRIORITY_DEFAULT)); 304 COOKIE_PRIORITY_DEFAULT));
305 EXPECT_TRUE(this->SetCookieWithDetails( 305 EXPECT_TRUE(this->SetCookieWithDetails(
306 cm.get(), url_top_level_domain_plus_2_secure, "sec_host", "X", 306 cm.get(), url_top_level_domain_plus_2_secure, "sec_host", "X",
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 694
695 struct CookiesInputInfo { 695 struct CookiesInputInfo {
696 const GURL url; 696 const GURL url;
697 const std::string name; 697 const std::string name;
698 const std::string value; 698 const std::string value;
699 const std::string domain; 699 const std::string domain;
700 const std::string path; 700 const std::string path;
701 const base::Time expiration_time; 701 const base::Time expiration_time;
702 bool secure; 702 bool secure;
703 bool http_only; 703 bool http_only;
704 bool first_party_only; 704 bool same_site;
705 CookiePriority priority; 705 CookiePriority priority;
706 }; 706 };
707 707
708 ACTION(QuitCurrentMessageLoop) { 708 ACTION(QuitCurrentMessageLoop) {
709 base::ThreadTaskRunnerHandle::Get()->PostTask( 709 base::ThreadTaskRunnerHandle::Get()->PostTask(
710 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 710 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
711 } 711 }
712 712
713 // TODO(erikwright): When the synchronous helpers 'GetCookies' etc. are removed, 713 // TODO(erikwright): When the synchronous helpers 'GetCookies' etc. are removed,
714 // rename these, removing the 'Action' suffix. 714 // rename these, removing the 'Action' suffix.
(...skipping 15 matching lines...) Expand all
730 cookie_monster, 730 cookie_monster,
731 delete_begin, 731 delete_begin,
732 delete_end, 732 delete_end,
733 callback) { 733 callback) {
734 cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, 734 cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end,
735 callback->AsCallback()); 735 callback->AsCallback());
736 } 736 }
737 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { 737 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) {
738 cookie_monster->SetCookieWithDetailsAsync( 738 cookie_monster->SetCookieWithDetailsAsync(
739 cc.url, cc.name, cc.value, cc.domain, cc.path, cc.expiration_time, 739 cc.url, cc.name, cc.value, cc.domain, cc.path, cc.expiration_time,
740 cc.secure, cc.http_only, cc.first_party_only, 740 cc.secure, cc.http_only, cc.same_site, false /* enforce prefixes */,
741 false /* enforce prefixes */, false /* enforces strict secure cookies */, 741 false /* enforces strict secure cookies */, cc.priority,
742 cc.priority, callback->AsCallback()); 742 callback->AsCallback());
743 } 743 }
744 744
745 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { 745 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) {
746 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); 746 cookie_monster->GetAllCookiesAsync(callback->AsCallback());
747 } 747 }
748 748
749 ACTION_P3(DeleteAllForHostAction, cookie_monster, url, callback) { 749 ACTION_P3(DeleteAllForHostAction, cookie_monster, url, callback) {
750 cookie_monster->DeleteAllForHostAsync(url, callback->AsCallback()); 750 cookie_monster->DeleteAllForHostAsync(url, callback->AsCallback());
751 } 751 }
752 752
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1995 COOKIE_PRIORITY_DEFAULT}}; 1995 COOKIE_PRIORITY_DEFAULT}};
1996 const int INPUT_DELETE = 1; 1996 const int INPUT_DELETE = 1;
1997 1997
1998 // Create new cookies and flush them to the store. 1998 // Create new cookies and flush them to the store.
1999 { 1999 {
2000 scoped_refptr<CookieMonster> cmout(new CookieMonster(store.get(), NULL)); 2000 scoped_refptr<CookieMonster> cmout(new CookieMonster(store.get(), NULL));
2001 for (const CookiesInputInfo* p = input_info; 2001 for (const CookiesInputInfo* p = input_info;
2002 p < &input_info[arraysize(input_info)]; p++) { 2002 p < &input_info[arraysize(input_info)]; p++) {
2003 EXPECT_TRUE(SetCookieWithDetails(cmout.get(), p->url, p->name, p->value, 2003 EXPECT_TRUE(SetCookieWithDetails(cmout.get(), p->url, p->name, p->value,
2004 p->domain, p->path, p->expiration_time, 2004 p->domain, p->path, p->expiration_time,
2005 p->secure, p->http_only, 2005 p->secure, p->http_only, p->same_site,
2006 p->first_party_only, p->priority)); 2006 p->priority));
2007 } 2007 }
2008 GURL del_url(input_info[INPUT_DELETE] 2008 GURL del_url(input_info[INPUT_DELETE]
2009 .url.Resolve(input_info[INPUT_DELETE].path) 2009 .url.Resolve(input_info[INPUT_DELETE].path)
2010 .spec()); 2010 .spec());
2011 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name); 2011 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name);
2012 } 2012 }
2013 2013
2014 // Create a new cookie monster and make sure that everything is correct 2014 // Create a new cookie monster and make sure that everything is correct
2015 { 2015 {
2016 scoped_refptr<CookieMonster> cmin(new CookieMonster(store.get(), NULL)); 2016 scoped_refptr<CookieMonster> cmin(new CookieMonster(store.get(), NULL));
2017 CookieList cookies(GetAllCookies(cmin.get())); 2017 CookieList cookies(GetAllCookies(cmin.get()));
2018 ASSERT_EQ(2u, cookies.size()); 2018 ASSERT_EQ(2u, cookies.size());
2019 // Ordering is path length, then creation time. So second cookie 2019 // Ordering is path length, then creation time. So second cookie
2020 // will come first, and we need to swap them. 2020 // will come first, and we need to swap them.
2021 std::swap(cookies[0], cookies[1]); 2021 std::swap(cookies[0], cookies[1]);
2022 for (int output_index = 0; output_index < 2; output_index++) { 2022 for (int output_index = 0; output_index < 2; output_index++) {
2023 int input_index = output_index * 2; 2023 int input_index = output_index * 2;
2024 const CookiesInputInfo* input = &input_info[input_index]; 2024 const CookiesInputInfo* input = &input_info[input_index];
2025 const CanonicalCookie* output = &cookies[output_index]; 2025 const CanonicalCookie* output = &cookies[output_index];
2026 2026
2027 EXPECT_EQ(input->name, output->Name()); 2027 EXPECT_EQ(input->name, output->Name());
2028 EXPECT_EQ(input->value, output->Value()); 2028 EXPECT_EQ(input->value, output->Value());
2029 EXPECT_EQ(input->url.host(), output->Domain()); 2029 EXPECT_EQ(input->url.host(), output->Domain());
2030 EXPECT_EQ(input->path, output->Path()); 2030 EXPECT_EQ(input->path, output->Path());
2031 EXPECT_LE(current.ToInternalValue(), 2031 EXPECT_LE(current.ToInternalValue(),
2032 output->CreationDate().ToInternalValue()); 2032 output->CreationDate().ToInternalValue());
2033 EXPECT_EQ(input->secure, output->IsSecure()); 2033 EXPECT_EQ(input->secure, output->IsSecure());
2034 EXPECT_EQ(input->http_only, output->IsHttpOnly()); 2034 EXPECT_EQ(input->http_only, output->IsHttpOnly());
2035 EXPECT_EQ(input->first_party_only, output->IsFirstPartyOnly()); 2035 EXPECT_EQ(input->same_site, output->IsSameSite());
2036 EXPECT_TRUE(output->IsPersistent()); 2036 EXPECT_TRUE(output->IsPersistent());
2037 EXPECT_EQ(input->expiration_time.ToInternalValue(), 2037 EXPECT_EQ(input->expiration_time.ToInternalValue(),
2038 output->ExpiryDate().ToInternalValue()); 2038 output->ExpiryDate().ToInternalValue());
2039 } 2039 }
2040 } 2040 }
2041 } 2041 }
2042 2042
2043 TEST_F(CookieMonsterTest, CookieListOrdering) { 2043 TEST_F(CookieMonsterTest, CookieListOrdering) {
2044 // Put a random set of cookies into a monster and make sure 2044 // Put a random set of cookies into a monster and make sure
2045 // they're returned in the right order. 2045 // they're returned in the right order.
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
2532 ResultSavingCookieCallback<bool>* callback) { 2532 ResultSavingCookieCallback<bool>* callback) {
2533 // Define the parameters here instead of in the calling fucntion. 2533 // Define the parameters here instead of in the calling fucntion.
2534 // The maximum number of parameters for Bind function is 6. 2534 // The maximum number of parameters for Bind function is 6.
2535 std::string name = "A"; 2535 std::string name = "A";
2536 std::string value = "B"; 2536 std::string value = "B";
2537 std::string domain = std::string(); 2537 std::string domain = std::string();
2538 std::string path = "/foo"; 2538 std::string path = "/foo";
2539 base::Time expiration_time = base::Time(); 2539 base::Time expiration_time = base::Time();
2540 bool secure = false; 2540 bool secure = false;
2541 bool http_only = false; 2541 bool http_only = false;
2542 bool first_party_only = false; 2542 bool same_site = false;
2543 CookiePriority priority = COOKIE_PRIORITY_DEFAULT; 2543 CookiePriority priority = COOKIE_PRIORITY_DEFAULT;
2544 cm->SetCookieWithDetailsAsync( 2544 cm->SetCookieWithDetailsAsync(
2545 url, name, value, domain, path, expiration_time, secure, http_only, 2545 url, name, value, domain, path, expiration_time, secure, http_only,
2546 first_party_only, false /* enforce prefixes */, 2546 same_site, false /* enforce prefixes */,
2547 false /* enforces strict secure cookies */, priority, 2547 false /* enforces strict secure cookies */, priority,
2548 base::Bind(&ResultSavingCookieCallback<bool>::Run, 2548 base::Bind(&ResultSavingCookieCallback<bool>::Run,
2549 base::Unretained(callback))); 2549 base::Unretained(callback)));
2550 } 2550 }
2551 2551
2552 void DeleteAllCreatedBetweenTask(CookieMonster* cm, 2552 void DeleteAllCreatedBetweenTask(CookieMonster* cm,
2553 const base::Time& delete_begin, 2553 const base::Time& delete_begin,
2554 const base::Time& delete_end, 2554 const base::Time& delete_end,
2555 ResultSavingCookieCallback<int>* callback) { 2555 ResultSavingCookieCallback<int>* callback) {
2556 cm->DeleteAllCreatedBetweenAsync( 2556 cm->DeleteAllCreatedBetweenAsync(
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
3545 monster()->AddCallbackForCookie( 3545 monster()->AddCallbackForCookie(
3546 test_url_, "abc", 3546 test_url_, "abc",
3547 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); 3547 base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
3548 SetCookie(monster(), test_url_, "abc=def"); 3548 SetCookie(monster(), test_url_, "abc=def");
3549 base::MessageLoop::current()->RunUntilIdle(); 3549 base::MessageLoop::current()->RunUntilIdle();
3550 EXPECT_EQ(1U, cookies0.size()); 3550 EXPECT_EQ(1U, cookies0.size());
3551 EXPECT_EQ(1U, cookies0.size()); 3551 EXPECT_EQ(1U, cookies0.size());
3552 } 3552 }
3553 3553
3554 } // namespace net 3554 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster_store_test.cc ('k') | net/cookies/cookie_options.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698