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

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: Missed a few. Created 4 years, 11 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
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 bool SetCookieWithDetails(CookieMonster* cm, 175 bool SetCookieWithDetails(CookieMonster* cm,
176 const GURL& url, 176 const GURL& url,
177 const std::string& name, 177 const std::string& name,
178 const std::string& value, 178 const std::string& value,
179 const std::string& domain, 179 const std::string& domain,
180 const std::string& path, 180 const std::string& path,
181 const base::Time& expiration_time, 181 const base::Time& expiration_time,
182 bool secure, 182 bool secure,
183 bool http_only, 183 bool http_only,
184 bool first_party_only, 184 bool same_site,
185 CookiePriority priority) { 185 CookiePriority priority) {
186 DCHECK(cm); 186 DCHECK(cm);
187 ResultSavingCookieCallback<bool> callback; 187 ResultSavingCookieCallback<bool> callback;
188 cm->SetCookieWithDetailsAsync( 188 cm->SetCookieWithDetailsAsync(
189 url, name, value, domain, path, expiration_time, secure, http_only, 189 url, name, value, domain, path, expiration_time, secure, http_only,
190 first_party_only, false /* enforce prefixes */, 190 same_site, false /* enforce prefixes */,
191 false /* enforces strict secure cookies */, priority, 191 false /* enforces strict secure cookies */, priority,
192 base::Bind(&ResultSavingCookieCallback<bool>::Run, 192 base::Bind(&ResultSavingCookieCallback<bool>::Run,
193 base::Unretained(&callback))); 193 base::Unretained(&callback)));
194 RunFor(kTimeout); 194 RunFor(kTimeout);
195 EXPECT_TRUE(callback.did_run()); 195 EXPECT_TRUE(callback.did_run());
196 return callback.result(); 196 return callback.result();
197 } 197 }
198 198
199 bool SetAllCookies(CookieMonster* cm, const CookieList& list) { 199 bool SetAllCookies(CookieMonster* cm, const CookieList& list) {
200 DCHECK(cm); 200 DCHECK(cm);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); 276 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure);
277 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); 277 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3);
278 GURL url_other(kOtherDomain); 278 GURL url_other(kOtherDomain);
279 279
280 DeleteAll(cm.get()); 280 DeleteAll(cm.get());
281 281
282 // Static population for probe: 282 // Static population for probe:
283 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a) 283 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a)
284 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a) 284 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a)
285 // * http_only cookie (w.c.b.a) 285 // * http_only cookie (w.c.b.a)
286 // * first-party cookie (w.c.b.a) 286 // * same_site cookie (w.c.b.a)
287 // * Two secure cookies (.c.b.a, w.c.b.a) 287 // * Two secure cookies (.c.b.a, w.c.b.a)
288 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) 288 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2)
289 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) 289 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2)
290 290
291 // Domain cookies 291 // Domain cookies
292 EXPECT_TRUE(this->SetCookieWithDetails( 292 EXPECT_TRUE(this->SetCookieWithDetails(
293 cm.get(), url_top_level_domain_plus_1, "dom_1", "X", ".harvard.edu", 293 cm.get(), url_top_level_domain_plus_1, "dom_1", "X", ".harvard.edu",
294 "/", base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); 294 "/", base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT));
295 EXPECT_TRUE(this->SetCookieWithDetails( 295 EXPECT_TRUE(this->SetCookieWithDetails(
296 cm.get(), url_top_level_domain_plus_2, "dom_2", "X", 296 cm.get(), url_top_level_domain_plus_2, "dom_2", "X",
(...skipping 14 matching lines...) Expand all
311 EXPECT_TRUE(this->SetCookieWithDetails( 311 EXPECT_TRUE(this->SetCookieWithDetails(
312 cm.get(), url_top_level_domain_plus_3, "host_3", "X", std::string(), 312 cm.get(), url_top_level_domain_plus_3, "host_3", "X", std::string(),
313 "/", base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); 313 "/", base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT));
314 314
315 // http_only cookie 315 // http_only cookie
316 EXPECT_TRUE(this->SetCookieWithDetails( 316 EXPECT_TRUE(this->SetCookieWithDetails(
317 cm.get(), url_top_level_domain_plus_2, "httpo_check", "x", 317 cm.get(), url_top_level_domain_plus_2, "httpo_check", "x",
318 std::string(), "/", base::Time(), false, true, false, 318 std::string(), "/", base::Time(), false, true, false,
319 COOKIE_PRIORITY_DEFAULT)); 319 COOKIE_PRIORITY_DEFAULT));
320 320
321 // first-party cookie 321 // same-site cookie
322 EXPECT_TRUE(this->SetCookieWithDetails( 322 EXPECT_TRUE(this->SetCookieWithDetails(
323 cm.get(), url_top_level_domain_plus_2, "firstp_check", "x", 323 cm.get(), url_top_level_domain_plus_2, "sames_check", "x",
324 std::string(), "/", base::Time(), false, false, true, 324 std::string(), "/", base::Time(), false, false, true,
325 COOKIE_PRIORITY_DEFAULT)); 325 COOKIE_PRIORITY_DEFAULT));
326 326
327 // Secure cookies 327 // Secure cookies
328 EXPECT_TRUE(this->SetCookieWithDetails( 328 EXPECT_TRUE(this->SetCookieWithDetails(
329 cm.get(), url_top_level_domain_plus_2_secure, "sec_dom", "X", 329 cm.get(), url_top_level_domain_plus_2_secure, "sec_dom", "X",
330 ".math.harvard.edu", "/", base::Time(), true, false, false, 330 ".math.harvard.edu", "/", base::Time(), true, false, false,
331 COOKIE_PRIORITY_DEFAULT)); 331 COOKIE_PRIORITY_DEFAULT));
332 EXPECT_TRUE(this->SetCookieWithDetails( 332 EXPECT_TRUE(this->SetCookieWithDetails(
333 cm.get(), url_top_level_domain_plus_2_secure, "sec_host", "X", 333 cm.get(), url_top_level_domain_plus_2_secure, "sec_host", "X",
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 721
722 struct CookiesInputInfo { 722 struct CookiesInputInfo {
723 const GURL url; 723 const GURL url;
724 const std::string name; 724 const std::string name;
725 const std::string value; 725 const std::string value;
726 const std::string domain; 726 const std::string domain;
727 const std::string path; 727 const std::string path;
728 const base::Time expiration_time; 728 const base::Time expiration_time;
729 bool secure; 729 bool secure;
730 bool http_only; 730 bool http_only;
731 bool first_party_only; 731 bool same_site;
732 CookiePriority priority; 732 CookiePriority priority;
733 }; 733 };
734 734
735 ACTION(QuitCurrentMessageLoop) { 735 ACTION(QuitCurrentMessageLoop) {
736 base::ThreadTaskRunnerHandle::Get()->PostTask( 736 base::ThreadTaskRunnerHandle::Get()->PostTask(
737 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 737 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
738 } 738 }
739 739
740 // TODO(erikwright): When the synchronous helpers 'GetCookies' etc. are removed, 740 // TODO(erikwright): When the synchronous helpers 'GetCookies' etc. are removed,
741 // rename these, removing the 'Action' suffix. 741 // rename these, removing the 'Action' suffix.
(...skipping 15 matching lines...) Expand all
757 cookie_monster, 757 cookie_monster,
758 delete_begin, 758 delete_begin,
759 delete_end, 759 delete_end,
760 callback) { 760 callback) {
761 cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, 761 cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end,
762 callback->AsCallback()); 762 callback->AsCallback());
763 } 763 }
764 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { 764 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) {
765 cookie_monster->SetCookieWithDetailsAsync( 765 cookie_monster->SetCookieWithDetailsAsync(
766 cc.url, cc.name, cc.value, cc.domain, cc.path, cc.expiration_time, 766 cc.url, cc.name, cc.value, cc.domain, cc.path, cc.expiration_time,
767 cc.secure, cc.http_only, cc.first_party_only, 767 cc.secure, cc.http_only, cc.same_site, false /* enforce prefixes */,
768 false /* enforce prefixes */, false /* enforces strict secure cookies */, 768 false /* enforces strict secure cookies */, cc.priority,
769 cc.priority, callback->AsCallback()); 769 callback->AsCallback());
770 } 770 }
771 771
772 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { 772 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) {
773 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); 773 cookie_monster->GetAllCookiesAsync(callback->AsCallback());
774 } 774 }
775 775
776 ACTION_P3(DeleteAllForHostAction, cookie_monster, url, callback) { 776 ACTION_P3(DeleteAllForHostAction, cookie_monster, url, callback) {
777 cookie_monster->DeleteAllForHostAsync(url, callback->AsCallback()); 777 cookie_monster->DeleteAllForHostAsync(url, callback->AsCallback());
778 } 778 }
779 779
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 COOKIE_PRIORITY_DEFAULT}}; 2022 COOKIE_PRIORITY_DEFAULT}};
2023 const int INPUT_DELETE = 1; 2023 const int INPUT_DELETE = 1;
2024 2024
2025 // Create new cookies and flush them to the store. 2025 // Create new cookies and flush them to the store.
2026 { 2026 {
2027 scoped_refptr<CookieMonster> cmout(new CookieMonster(store.get(), NULL)); 2027 scoped_refptr<CookieMonster> cmout(new CookieMonster(store.get(), NULL));
2028 for (const CookiesInputInfo* p = input_info; 2028 for (const CookiesInputInfo* p = input_info;
2029 p < &input_info[arraysize(input_info)]; p++) { 2029 p < &input_info[arraysize(input_info)]; p++) {
2030 EXPECT_TRUE(SetCookieWithDetails(cmout.get(), p->url, p->name, p->value, 2030 EXPECT_TRUE(SetCookieWithDetails(cmout.get(), p->url, p->name, p->value,
2031 p->domain, p->path, p->expiration_time, 2031 p->domain, p->path, p->expiration_time,
2032 p->secure, p->http_only, 2032 p->secure, p->http_only, p->same_site,
2033 p->first_party_only, p->priority)); 2033 p->priority));
2034 } 2034 }
2035 GURL del_url(input_info[INPUT_DELETE] 2035 GURL del_url(input_info[INPUT_DELETE]
2036 .url.Resolve(input_info[INPUT_DELETE].path) 2036 .url.Resolve(input_info[INPUT_DELETE].path)
2037 .spec()); 2037 .spec());
2038 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name); 2038 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name);
2039 } 2039 }
2040 2040
2041 // Create a new cookie monster and make sure that everything is correct 2041 // Create a new cookie monster and make sure that everything is correct
2042 { 2042 {
2043 scoped_refptr<CookieMonster> cmin(new CookieMonster(store.get(), NULL)); 2043 scoped_refptr<CookieMonster> cmin(new CookieMonster(store.get(), NULL));
2044 CookieList cookies(GetAllCookies(cmin.get())); 2044 CookieList cookies(GetAllCookies(cmin.get()));
2045 ASSERT_EQ(2u, cookies.size()); 2045 ASSERT_EQ(2u, cookies.size());
2046 // Ordering is path length, then creation time. So second cookie 2046 // Ordering is path length, then creation time. So second cookie
2047 // will come first, and we need to swap them. 2047 // will come first, and we need to swap them.
2048 std::swap(cookies[0], cookies[1]); 2048 std::swap(cookies[0], cookies[1]);
2049 for (int output_index = 0; output_index < 2; output_index++) { 2049 for (int output_index = 0; output_index < 2; output_index++) {
2050 int input_index = output_index * 2; 2050 int input_index = output_index * 2;
2051 const CookiesInputInfo* input = &input_info[input_index]; 2051 const CookiesInputInfo* input = &input_info[input_index];
2052 const CanonicalCookie* output = &cookies[output_index]; 2052 const CanonicalCookie* output = &cookies[output_index];
2053 2053
2054 EXPECT_EQ(input->name, output->Name()); 2054 EXPECT_EQ(input->name, output->Name());
2055 EXPECT_EQ(input->value, output->Value()); 2055 EXPECT_EQ(input->value, output->Value());
2056 EXPECT_EQ(input->url.host(), output->Domain()); 2056 EXPECT_EQ(input->url.host(), output->Domain());
2057 EXPECT_EQ(input->path, output->Path()); 2057 EXPECT_EQ(input->path, output->Path());
2058 EXPECT_LE(current.ToInternalValue(), 2058 EXPECT_LE(current.ToInternalValue(),
2059 output->CreationDate().ToInternalValue()); 2059 output->CreationDate().ToInternalValue());
2060 EXPECT_EQ(input->secure, output->IsSecure()); 2060 EXPECT_EQ(input->secure, output->IsSecure());
2061 EXPECT_EQ(input->http_only, output->IsHttpOnly()); 2061 EXPECT_EQ(input->http_only, output->IsHttpOnly());
2062 EXPECT_EQ(input->first_party_only, output->IsFirstPartyOnly()); 2062 EXPECT_EQ(input->same_site, output->IsSameSite());
2063 EXPECT_TRUE(output->IsPersistent()); 2063 EXPECT_TRUE(output->IsPersistent());
2064 EXPECT_EQ(input->expiration_time.ToInternalValue(), 2064 EXPECT_EQ(input->expiration_time.ToInternalValue(),
2065 output->ExpiryDate().ToInternalValue()); 2065 output->ExpiryDate().ToInternalValue());
2066 } 2066 }
2067 } 2067 }
2068 } 2068 }
2069 2069
2070 TEST_F(CookieMonsterTest, CookieListOrdering) { 2070 TEST_F(CookieMonsterTest, CookieListOrdering) {
2071 // Put a random set of cookies into a monster and make sure 2071 // Put a random set of cookies into a monster and make sure
2072 // they're returned in the right order. 2072 // they're returned in the right order.
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
2559 ResultSavingCookieCallback<bool>* callback) { 2559 ResultSavingCookieCallback<bool>* callback) {
2560 // Define the parameters here instead of in the calling fucntion. 2560 // Define the parameters here instead of in the calling fucntion.
2561 // The maximum number of parameters for Bind function is 6. 2561 // The maximum number of parameters for Bind function is 6.
2562 std::string name = "A"; 2562 std::string name = "A";
2563 std::string value = "B"; 2563 std::string value = "B";
2564 std::string domain = std::string(); 2564 std::string domain = std::string();
2565 std::string path = "/foo"; 2565 std::string path = "/foo";
2566 base::Time expiration_time = base::Time(); 2566 base::Time expiration_time = base::Time();
2567 bool secure = false; 2567 bool secure = false;
2568 bool http_only = false; 2568 bool http_only = false;
2569 bool first_party_only = false; 2569 bool same_site = false;
2570 CookiePriority priority = COOKIE_PRIORITY_DEFAULT; 2570 CookiePriority priority = COOKIE_PRIORITY_DEFAULT;
2571 cm->SetCookieWithDetailsAsync( 2571 cm->SetCookieWithDetailsAsync(
2572 url, name, value, domain, path, expiration_time, secure, http_only, 2572 url, name, value, domain, path, expiration_time, secure, http_only,
2573 first_party_only, false /* enforce prefixes */, 2573 same_site, false /* enforce prefixes */,
2574 false /* enforces strict secure cookies */, priority, 2574 false /* enforces strict secure cookies */, priority,
2575 base::Bind(&ResultSavingCookieCallback<bool>::Run, 2575 base::Bind(&ResultSavingCookieCallback<bool>::Run,
2576 base::Unretained(callback))); 2576 base::Unretained(callback)));
2577 } 2577 }
2578 2578
2579 void DeleteAllCreatedBetweenTask(CookieMonster* cm, 2579 void DeleteAllCreatedBetweenTask(CookieMonster* cm,
2580 const base::Time& delete_begin, 2580 const base::Time& delete_begin,
2581 const base::Time& delete_end, 2581 const base::Time& delete_end,
2582 ResultSavingCookieCallback<int>* callback) { 2582 ResultSavingCookieCallback<int>* callback) {
2583 cm->DeleteAllCreatedBetweenAsync( 2583 cm->DeleteAllCreatedBetweenAsync(
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after
3572 monster()->AddCallbackForCookie( 3572 monster()->AddCallbackForCookie(
3573 test_url_, "abc", 3573 test_url_, "abc",
3574 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); 3574 base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
3575 SetCookie(monster(), test_url_, "abc=def"); 3575 SetCookie(monster(), test_url_, "abc=def");
3576 base::MessageLoop::current()->RunUntilIdle(); 3576 base::MessageLoop::current()->RunUntilIdle();
3577 EXPECT_EQ(1U, cookies0.size()); 3577 EXPECT_EQ(1U, cookies0.size());
3578 EXPECT_EQ(1U, cookies0.size()); 3578 EXPECT_EQ(1U, cookies0.size());
3579 } 3579 }
3580 3580
3581 } // namespace net 3581 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698