| OLD | NEW |
| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 145 |
| 146 bool SetCookieWithDetails(CookieMonster* cm, | 146 bool SetCookieWithDetails(CookieMonster* cm, |
| 147 const GURL& url, | 147 const GURL& url, |
| 148 const std::string& name, | 148 const std::string& name, |
| 149 const std::string& value, | 149 const std::string& value, |
| 150 const std::string& domain, | 150 const std::string& domain, |
| 151 const std::string& path, | 151 const std::string& path, |
| 152 const base::Time& expiration_time, | 152 const base::Time& expiration_time, |
| 153 bool secure, | 153 bool secure, |
| 154 bool http_only, | 154 bool http_only, |
| 155 bool first_party_only, |
| 155 CookiePriority priority) { | 156 CookiePriority priority) { |
| 156 DCHECK(cm); | 157 DCHECK(cm); |
| 157 ResultSavingCookieCallback<bool> callback; | 158 ResultSavingCookieCallback<bool> callback; |
| 158 cm->SetCookieWithDetailsAsync( | 159 cm->SetCookieWithDetailsAsync( |
| 159 url, name, value, domain, path, expiration_time, secure, http_only, | 160 url, name, value, domain, path, expiration_time, secure, http_only, |
| 160 priority, base::Bind(&ResultSavingCookieCallback<bool>::Run, | 161 first_party_only, priority, |
| 161 base::Unretained(&callback))); | 162 base::Bind(&ResultSavingCookieCallback<bool>::Run, |
| 163 base::Unretained(&callback))); |
| 162 RunFor(kTimeout); | 164 RunFor(kTimeout); |
| 163 EXPECT_TRUE(callback.did_run()); | 165 EXPECT_TRUE(callback.did_run()); |
| 164 return callback.result(); | 166 return callback.result(); |
| 165 } | 167 } |
| 166 | 168 |
| 167 int DeleteAll(CookieMonster* cm) { | 169 int DeleteAll(CookieMonster* cm) { |
| 168 DCHECK(cm); | 170 DCHECK(cm); |
| 169 ResultSavingCookieCallback<int> callback; | 171 ResultSavingCookieCallback<int> callback; |
| 170 cm->DeleteAllAsync(base::Bind(&ResultSavingCookieCallback<int>::Run, | 172 cm->DeleteAllAsync(base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 171 base::Unretained(&callback))); | 173 base::Unretained(&callback))); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); | 235 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); |
| 234 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); | 236 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); |
| 235 GURL url_other(kOtherDomain); | 237 GURL url_other(kOtherDomain); |
| 236 | 238 |
| 237 DeleteAll(cm.get()); | 239 DeleteAll(cm.get()); |
| 238 | 240 |
| 239 // Static population for probe: | 241 // Static population for probe: |
| 240 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a) | 242 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a) |
| 241 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a) | 243 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a) |
| 242 // * http_only cookie (w.c.b.a) | 244 // * http_only cookie (w.c.b.a) |
| 245 // * first-party cookie (w.c.b.a) |
| 243 // * Two secure cookies (.c.b.a, w.c.b.a) | 246 // * Two secure cookies (.c.b.a, w.c.b.a) |
| 244 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) | 247 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) |
| 245 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) | 248 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) |
| 246 | 249 |
| 247 // Domain cookies | 250 // Domain cookies |
| 248 EXPECT_TRUE(this->SetCookieWithDetails( | 251 EXPECT_TRUE(this->SetCookieWithDetails( |
| 249 cm.get(), url_top_level_domain_plus_1, "dom_1", "X", ".harvard.edu", | 252 cm.get(), url_top_level_domain_plus_1, "dom_1", "X", ".harvard.edu", |
| 250 "/", base::Time(), false, false, COOKIE_PRIORITY_DEFAULT)); | 253 "/", base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); |
| 251 EXPECT_TRUE(this->SetCookieWithDetails( | 254 EXPECT_TRUE(this->SetCookieWithDetails( |
| 252 cm.get(), url_top_level_domain_plus_2, "dom_2", "X", | 255 cm.get(), url_top_level_domain_plus_2, "dom_2", "X", |
| 253 ".math.harvard.edu", "/", base::Time(), false, false, | 256 ".math.harvard.edu", "/", base::Time(), false, false, false, |
| 254 COOKIE_PRIORITY_DEFAULT)); | 257 COOKIE_PRIORITY_DEFAULT)); |
| 255 EXPECT_TRUE(this->SetCookieWithDetails( | 258 EXPECT_TRUE(this->SetCookieWithDetails( |
| 256 cm.get(), url_top_level_domain_plus_3, "dom_3", "X", | 259 cm.get(), url_top_level_domain_plus_3, "dom_3", "X", |
| 257 ".bourbaki.math.harvard.edu", "/", base::Time(), false, false, | 260 ".bourbaki.math.harvard.edu", "/", base::Time(), false, false, false, |
| 258 COOKIE_PRIORITY_DEFAULT)); | 261 COOKIE_PRIORITY_DEFAULT)); |
| 259 | 262 |
| 260 // Host cookies | 263 // Host cookies |
| 261 EXPECT_TRUE(this->SetCookieWithDetails( | 264 EXPECT_TRUE(this->SetCookieWithDetails( |
| 262 cm.get(), url_top_level_domain_plus_1, "host_1", "X", std::string(), | 265 cm.get(), url_top_level_domain_plus_1, "host_1", "X", std::string(), |
| 263 "/", base::Time(), false, false, COOKIE_PRIORITY_DEFAULT)); | 266 "/", base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); |
| 264 EXPECT_TRUE(this->SetCookieWithDetails( | 267 EXPECT_TRUE(this->SetCookieWithDetails( |
| 265 cm.get(), url_top_level_domain_plus_2, "host_2", "X", std::string(), | 268 cm.get(), url_top_level_domain_plus_2, "host_2", "X", std::string(), |
| 266 "/", base::Time(), false, false, COOKIE_PRIORITY_DEFAULT)); | 269 "/", base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); |
| 267 EXPECT_TRUE(this->SetCookieWithDetails( | 270 EXPECT_TRUE(this->SetCookieWithDetails( |
| 268 cm.get(), url_top_level_domain_plus_3, "host_3", "X", std::string(), | 271 cm.get(), url_top_level_domain_plus_3, "host_3", "X", std::string(), |
| 269 "/", base::Time(), false, false, COOKIE_PRIORITY_DEFAULT)); | 272 "/", base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); |
| 270 | 273 |
| 271 // Http_only cookie | 274 // http_only cookie |
| 272 EXPECT_TRUE(this->SetCookieWithDetails( | 275 EXPECT_TRUE(this->SetCookieWithDetails( |
| 273 cm.get(), url_top_level_domain_plus_2, "httpo_check", "X", | 276 cm.get(), url_top_level_domain_plus_2, "httpo_check", "x", |
| 274 std::string(), "/", base::Time(), false, true, | 277 std::string(), "/", base::Time(), false, true, false, |
| 278 COOKIE_PRIORITY_DEFAULT)); |
| 279 |
| 280 // first-party cookie |
| 281 EXPECT_TRUE(this->SetCookieWithDetails( |
| 282 cm.get(), url_top_level_domain_plus_2, "firstp_check", "x", |
| 283 std::string(), "/", base::Time(), false, false, true, |
| 275 COOKIE_PRIORITY_DEFAULT)); | 284 COOKIE_PRIORITY_DEFAULT)); |
| 276 | 285 |
| 277 // Secure cookies | 286 // Secure cookies |
| 278 EXPECT_TRUE(this->SetCookieWithDetails( | 287 EXPECT_TRUE(this->SetCookieWithDetails( |
| 279 cm.get(), url_top_level_domain_plus_2_secure, "sec_dom", "X", | 288 cm.get(), url_top_level_domain_plus_2_secure, "sec_dom", "X", |
| 280 ".math.harvard.edu", "/", base::Time(), true, false, | 289 ".math.harvard.edu", "/", base::Time(), true, false, false, |
| 281 COOKIE_PRIORITY_DEFAULT)); | 290 COOKIE_PRIORITY_DEFAULT)); |
| 282 EXPECT_TRUE(this->SetCookieWithDetails( | 291 EXPECT_TRUE(this->SetCookieWithDetails( |
| 283 cm.get(), url_top_level_domain_plus_2_secure, "sec_host", "X", | 292 cm.get(), url_top_level_domain_plus_2_secure, "sec_host", "X", |
| 284 std::string(), "/", base::Time(), true, false, | 293 std::string(), "/", base::Time(), true, false, false, |
| 285 COOKIE_PRIORITY_DEFAULT)); | 294 COOKIE_PRIORITY_DEFAULT)); |
| 286 | 295 |
| 287 // Domain path cookies | 296 // Domain path cookies |
| 288 EXPECT_TRUE(this->SetCookieWithDetails( | 297 EXPECT_TRUE(this->SetCookieWithDetails( |
| 289 cm.get(), url_top_level_domain_plus_2, "dom_path_1", "X", | 298 cm.get(), url_top_level_domain_plus_2, "dom_path_1", "X", |
| 290 ".math.harvard.edu", "/dir1", base::Time(), false, false, | 299 ".math.harvard.edu", "/dir1", base::Time(), false, false, false, |
| 291 COOKIE_PRIORITY_DEFAULT)); | 300 COOKIE_PRIORITY_DEFAULT)); |
| 292 EXPECT_TRUE(this->SetCookieWithDetails( | 301 EXPECT_TRUE(this->SetCookieWithDetails( |
| 293 cm.get(), url_top_level_domain_plus_2, "dom_path_2", "X", | 302 cm.get(), url_top_level_domain_plus_2, "dom_path_2", "X", |
| 294 ".math.harvard.edu", "/dir1/dir2", base::Time(), false, false, | 303 ".math.harvard.edu", "/dir1/dir2", base::Time(), false, false, false, |
| 295 COOKIE_PRIORITY_DEFAULT)); | 304 COOKIE_PRIORITY_DEFAULT)); |
| 296 | 305 |
| 297 // Host path cookies | 306 // Host path cookies |
| 298 EXPECT_TRUE(this->SetCookieWithDetails( | 307 EXPECT_TRUE(this->SetCookieWithDetails( |
| 299 cm.get(), url_top_level_domain_plus_2, "host_path_1", "X", | 308 cm.get(), url_top_level_domain_plus_2, "host_path_1", "X", |
| 300 std::string(), "/dir1", base::Time(), false, false, | 309 std::string(), "/dir1", base::Time(), false, false, false, |
| 301 COOKIE_PRIORITY_DEFAULT)); | 310 COOKIE_PRIORITY_DEFAULT)); |
| 302 EXPECT_TRUE(this->SetCookieWithDetails( | 311 EXPECT_TRUE(this->SetCookieWithDetails( |
| 303 cm.get(), url_top_level_domain_plus_2, "host_path_2", "X", | 312 cm.get(), url_top_level_domain_plus_2, "host_path_2", "X", |
| 304 std::string(), "/dir1/dir2", base::Time(), false, false, | 313 std::string(), "/dir1/dir2", base::Time(), false, false, false, |
| 305 COOKIE_PRIORITY_DEFAULT)); | 314 COOKIE_PRIORITY_DEFAULT)); |
| 306 | 315 |
| 307 EXPECT_EQ(13U, this->GetAllCookies(cm.get()).size()); | 316 EXPECT_EQ(14U, this->GetAllCookies(cm.get()).size()); |
| 308 } | 317 } |
| 309 | 318 |
| 310 Time GetFirstCookieAccessDate(CookieMonster* cm) { | 319 Time GetFirstCookieAccessDate(CookieMonster* cm) { |
| 311 const CookieList all_cookies(this->GetAllCookies(cm)); | 320 const CookieList all_cookies(this->GetAllCookies(cm)); |
| 312 return all_cookies.front().LastAccessDate(); | 321 return all_cookies.front().LastAccessDate(); |
| 313 } | 322 } |
| 314 | 323 |
| 315 bool FindAndDeleteCookie(CookieMonster* cm, | 324 bool FindAndDeleteCookie(CookieMonster* cm, |
| 316 const std::string& domain, | 325 const std::string& domain, |
| 317 const std::string& name) { | 326 const std::string& name) { |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 | 596 |
| 588 struct CookiesInputInfo { | 597 struct CookiesInputInfo { |
| 589 const GURL url; | 598 const GURL url; |
| 590 const std::string name; | 599 const std::string name; |
| 591 const std::string value; | 600 const std::string value; |
| 592 const std::string domain; | 601 const std::string domain; |
| 593 const std::string path; | 602 const std::string path; |
| 594 const base::Time expiration_time; | 603 const base::Time expiration_time; |
| 595 bool secure; | 604 bool secure; |
| 596 bool http_only; | 605 bool http_only; |
| 606 bool first_party_only; |
| 597 CookiePriority priority; | 607 CookiePriority priority; |
| 598 }; | 608 }; |
| 599 | 609 |
| 600 ACTION(QuitCurrentMessageLoop) { | 610 ACTION(QuitCurrentMessageLoop) { |
| 601 base::MessageLoop::current()->PostTask(FROM_HERE, | 611 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 602 base::MessageLoop::QuitClosure()); | 612 base::MessageLoop::QuitClosure()); |
| 603 } | 613 } |
| 604 | 614 |
| 605 // TODO(erikwright): When the synchronous helpers 'GetCookies' etc. are removed, | 615 // TODO(erikwright): When the synchronous helpers 'GetCookies' etc. are removed, |
| 606 // rename these, removing the 'Action' suffix. | 616 // rename these, removing the 'Action' suffix. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 619 cookie_monster, | 629 cookie_monster, |
| 620 delete_begin, | 630 delete_begin, |
| 621 delete_end, | 631 delete_end, |
| 622 callback) { | 632 callback) { |
| 623 cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, | 633 cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, |
| 624 callback->AsCallback()); | 634 callback->AsCallback()); |
| 625 } | 635 } |
| 626 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { | 636 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { |
| 627 cookie_monster->SetCookieWithDetailsAsync( | 637 cookie_monster->SetCookieWithDetailsAsync( |
| 628 cc.url, cc.name, cc.value, cc.domain, cc.path, cc.expiration_time, | 638 cc.url, cc.name, cc.value, cc.domain, cc.path, cc.expiration_time, |
| 629 cc.secure, cc.http_only, cc.priority, callback->AsCallback()); | 639 cc.secure, cc.http_only, cc.first_party_only, cc.priority, |
| 640 callback->AsCallback()); |
| 630 } | 641 } |
| 631 | 642 |
| 632 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { | 643 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { |
| 633 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); | 644 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); |
| 634 } | 645 } |
| 635 | 646 |
| 636 ACTION_P3(DeleteAllForHostAction, cookie_monster, url, callback) { | 647 ACTION_P3(DeleteAllForHostAction, cookie_monster, url, callback) { |
| 637 cookie_monster->DeleteAllForHostAsync(url, callback->AsCallback()); | 648 cookie_monster->DeleteAllForHostAsync(url, callback->AsCallback()); |
| 638 } | 649 } |
| 639 | 650 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 MockSetCookiesCallback set_cookies_callback; | 846 MockSetCookiesCallback set_cookies_callback; |
| 836 | 847 |
| 837 CookiesInputInfo cookie_info = {url_google_foo_, | 848 CookiesInputInfo cookie_info = {url_google_foo_, |
| 838 "A", | 849 "A", |
| 839 "B", | 850 "B", |
| 840 std::string(), | 851 std::string(), |
| 841 "/foo", | 852 "/foo", |
| 842 base::Time(), | 853 base::Time(), |
| 843 false, | 854 false, |
| 844 false, | 855 false, |
| 856 false, |
| 845 COOKIE_PRIORITY_DEFAULT}; | 857 COOKIE_PRIORITY_DEFAULT}; |
| 846 BeginWithForDomainKey( | 858 BeginWithForDomainKey( |
| 847 "google.izzle", SetCookieWithDetailsAction(&cookie_monster(), cookie_info, | 859 "google.izzle", SetCookieWithDetailsAction(&cookie_monster(), cookie_info, |
| 848 &set_cookies_callback)); | 860 &set_cookies_callback)); |
| 849 | 861 |
| 850 WaitForLoadCall(); | 862 WaitForLoadCall(); |
| 851 | 863 |
| 852 CookiesInputInfo cookie_info_exp = {url_google_foo_, | 864 CookiesInputInfo cookie_info_exp = {url_google_foo_, |
| 853 "A", | 865 "A", |
| 854 "B", | 866 "B", |
| 855 std::string(), | 867 std::string(), |
| 856 "/foo", | 868 "/foo", |
| 857 base::Time(), | 869 base::Time(), |
| 858 false, | 870 false, |
| 859 false, | 871 false, |
| 872 false, |
| 860 COOKIE_PRIORITY_DEFAULT}; | 873 COOKIE_PRIORITY_DEFAULT}; |
| 861 EXPECT_CALL(set_cookies_callback, Invoke(true)) | 874 EXPECT_CALL(set_cookies_callback, Invoke(true)) |
| 862 .WillOnce(SetCookieWithDetailsAction(&cookie_monster(), cookie_info_exp, | 875 .WillOnce(SetCookieWithDetailsAction(&cookie_monster(), cookie_info_exp, |
| 863 &set_cookies_callback)); | 876 &set_cookies_callback)); |
| 864 EXPECT_CALL(set_cookies_callback, Invoke(true)) | 877 EXPECT_CALL(set_cookies_callback, Invoke(true)) |
| 865 .WillOnce(QuitCurrentMessageLoop()); | 878 .WillOnce(QuitCurrentMessageLoop()); |
| 866 | 879 |
| 867 CompleteLoadingAndWait(); | 880 CompleteLoadingAndWait(); |
| 868 } | 881 } |
| 869 | 882 |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1530 EXPECT_EQ("a", delegate->changes()[1].first.Name()); | 1543 EXPECT_EQ("a", delegate->changes()[1].first.Name()); |
| 1531 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); | 1544 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); |
| 1532 delegate->reset(); | 1545 delegate->reset(); |
| 1533 } | 1546 } |
| 1534 | 1547 |
| 1535 TEST_F(CookieMonsterTest, SetCookieWithDetails) { | 1548 TEST_F(CookieMonsterTest, SetCookieWithDetails) { |
| 1536 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1549 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1537 | 1550 |
| 1538 EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_foo_, "A", "B", | 1551 EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_foo_, "A", "B", |
| 1539 std::string(), "/foo", base::Time(), false, | 1552 std::string(), "/foo", base::Time(), false, |
| 1540 false, COOKIE_PRIORITY_DEFAULT)); | 1553 false, false, COOKIE_PRIORITY_DEFAULT)); |
| 1541 EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_bar_, "C", "D", | 1554 EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_bar_, "C", "D", |
| 1542 "google.izzle", "/bar", base::Time(), false, | 1555 "google.izzle", "/bar", base::Time(), false, |
| 1543 true, COOKIE_PRIORITY_DEFAULT)); | |
| 1544 EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_, "E", "F", | |
| 1545 std::string(), std::string(), base::Time(), | |
| 1546 true, false, COOKIE_PRIORITY_DEFAULT)); | 1556 true, false, COOKIE_PRIORITY_DEFAULT)); |
| 1557 EXPECT_TRUE(SetCookieWithDetails( |
| 1558 cm.get(), url_google_, "E", "F", std::string(), std::string(), |
| 1559 base::Time(), true, false, false, COOKIE_PRIORITY_DEFAULT)); |
| 1547 | 1560 |
| 1548 // Test that malformed attributes fail to set the cookie. | 1561 // Test that malformed attributes fail to set the cookie. |
| 1549 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, " A", "B", | 1562 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, " A", "B", |
| 1550 std::string(), "/foo", base::Time(), false, | 1563 std::string(), "/foo", base::Time(), false, |
| 1551 false, COOKIE_PRIORITY_DEFAULT)); | 1564 false, false, COOKIE_PRIORITY_DEFAULT)); |
| 1552 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A;", "B", | 1565 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A;", "B", |
| 1553 std::string(), "/foo", base::Time(), false, | 1566 std::string(), "/foo", base::Time(), false, |
| 1554 false, COOKIE_PRIORITY_DEFAULT)); | 1567 false, false, COOKIE_PRIORITY_DEFAULT)); |
| 1555 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A=", "B", | 1568 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A=", "B", |
| 1556 std::string(), "/foo", base::Time(), false, | 1569 std::string(), "/foo", base::Time(), false, |
| 1557 false, COOKIE_PRIORITY_DEFAULT)); | |
| 1558 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A", "B", | |
| 1559 "google.ozzzzzzle", "foo", base::Time(), | |
| 1560 false, false, COOKIE_PRIORITY_DEFAULT)); | 1570 false, false, COOKIE_PRIORITY_DEFAULT)); |
| 1571 EXPECT_FALSE(SetCookieWithDetails( |
| 1572 cm.get(), url_google_foo_, "A", "B", "google.ozzzzzzle", "foo", |
| 1573 base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); |
| 1561 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A=", "B", | 1574 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A=", "B", |
| 1562 std::string(), "foo", base::Time(), false, | 1575 std::string(), "foo", base::Time(), false, |
| 1563 false, COOKIE_PRIORITY_DEFAULT)); | 1576 false, false, COOKIE_PRIORITY_DEFAULT)); |
| 1564 | 1577 |
| 1565 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_foo_); | 1578 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_foo_); |
| 1566 CookieList::iterator it = cookies.begin(); | 1579 CookieList::iterator it = cookies.begin(); |
| 1567 | 1580 |
| 1568 ASSERT_TRUE(it != cookies.end()); | 1581 ASSERT_TRUE(it != cookies.end()); |
| 1569 EXPECT_EQ("A", it->Name()); | 1582 EXPECT_EQ("A", it->Name()); |
| 1570 EXPECT_EQ("B", it->Value()); | 1583 EXPECT_EQ("B", it->Value()); |
| 1571 EXPECT_EQ("www.google.izzle", it->Domain()); | 1584 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 1572 EXPECT_EQ("/foo", it->Path()); | 1585 EXPECT_EQ("/foo", it->Path()); |
| 1573 EXPECT_FALSE(it->IsPersistent()); | 1586 EXPECT_FALSE(it->IsPersistent()); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1620 EXPECT_EQ("dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", | 1633 EXPECT_EQ("dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", |
| 1621 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1634 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1622 EXPECT_EQ("dom_1=X; host_1=X", | 1635 EXPECT_EQ("dom_1=X; host_1=X", |
| 1623 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1636 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1624 EXPECT_EQ( | 1637 EXPECT_EQ( |
| 1625 "dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; " | 1638 "dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; " |
| 1626 "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", | 1639 "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", |
| 1627 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + | 1640 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1628 std::string("/dir1/dir2/xxx")))); | 1641 std::string("/dir1/dir2/xxx")))); |
| 1629 | 1642 |
| 1630 EXPECT_EQ(5, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2))); | 1643 EXPECT_EQ(6, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2))); |
| 1631 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); | 1644 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); |
| 1632 | 1645 |
| 1633 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1646 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
| 1634 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1647 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1635 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", | 1648 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", |
| 1636 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1649 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1637 EXPECT_EQ("dom_1=X; host_1=X", | 1650 EXPECT_EQ("dom_1=X; host_1=X", |
| 1638 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1651 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1639 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", | 1652 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", |
| 1640 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + | 1653 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1641 std::string("/dir1/dir2/xxx")))); | 1654 std::string("/dir1/dir2/xxx")))); |
| 1642 | 1655 |
| 1643 PopulateCmForDeleteAllForHost(cm); | 1656 PopulateCmForDeleteAllForHost(cm); |
| 1644 EXPECT_EQ(5, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1657 EXPECT_EQ(6, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1645 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); | 1658 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); |
| 1646 | 1659 |
| 1647 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1660 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
| 1648 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1661 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1649 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", | 1662 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", |
| 1650 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1663 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1651 EXPECT_EQ("dom_1=X; host_1=X", | 1664 EXPECT_EQ("dom_1=X; host_1=X", |
| 1652 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1665 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1653 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", | 1666 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", |
| 1654 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + | 1667 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1655 std::string("/dir1/dir2/xxx")))); | 1668 std::string("/dir1/dir2/xxx")))); |
| 1656 | 1669 |
| 1657 PopulateCmForDeleteAllForHost(cm); | 1670 PopulateCmForDeleteAllForHost(cm); |
| 1658 EXPECT_EQ(5, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2Secure + | 1671 EXPECT_EQ(6, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1659 std::string("/dir1/xxx")))); | 1672 std::string("/dir1/xxx")))); |
| 1660 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); | 1673 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); |
| 1661 | 1674 |
| 1662 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1675 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
| 1663 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1676 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1664 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", | 1677 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", |
| 1665 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1678 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1666 EXPECT_EQ("dom_1=X; host_1=X", | 1679 EXPECT_EQ("dom_1=X; host_1=X", |
| 1667 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1680 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1668 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", | 1681 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1689 SetCookie(cm.get(), url_google_, "SetCookie3=A"); | 1702 SetCookie(cm.get(), url_google_, "SetCookie3=A"); |
| 1690 | 1703 |
| 1691 SetCookieWithOptions(cm.get(), url_google_, "setCookieWithOptions1=A", | 1704 SetCookieWithOptions(cm.get(), url_google_, "setCookieWithOptions1=A", |
| 1692 options); | 1705 options); |
| 1693 SetCookieWithOptions(cm.get(), url_google_, "setCookieWithOptions2=A", | 1706 SetCookieWithOptions(cm.get(), url_google_, "setCookieWithOptions2=A", |
| 1694 options); | 1707 options); |
| 1695 SetCookieWithOptions(cm.get(), url_google_, "setCookieWithOptions3=A", | 1708 SetCookieWithOptions(cm.get(), url_google_, "setCookieWithOptions3=A", |
| 1696 options); | 1709 options); |
| 1697 | 1710 |
| 1698 SetCookieWithDetails(cm.get(), url_google_, "setCookieWithDetails1", "A", | 1711 SetCookieWithDetails(cm.get(), url_google_, "setCookieWithDetails1", "A", |
| 1699 ".google.com", "/", Time(), false, false, | 1712 ".google.com", "/", Time(), false, false, false, |
| 1700 COOKIE_PRIORITY_DEFAULT); | 1713 COOKIE_PRIORITY_DEFAULT); |
| 1701 SetCookieWithDetails(cm.get(), url_google_, "setCookieWithDetails2", "A", | 1714 SetCookieWithDetails(cm.get(), url_google_, "setCookieWithDetails2", "A", |
| 1702 ".google.com", "/", Time(), false, false, | 1715 ".google.com", "/", Time(), false, false, false, |
| 1703 COOKIE_PRIORITY_DEFAULT); | 1716 COOKIE_PRIORITY_DEFAULT); |
| 1704 SetCookieWithDetails(cm.get(), url_google_, "setCookieWithDetails3", "A", | 1717 SetCookieWithDetails(cm.get(), url_google_, "setCookieWithDetails3", "A", |
| 1705 ".google.com", "/", Time(), false, false, | 1718 ".google.com", "/", Time(), false, false, false, |
| 1706 COOKIE_PRIORITY_DEFAULT); | 1719 COOKIE_PRIORITY_DEFAULT); |
| 1707 | 1720 |
| 1708 // Now we check | 1721 // Now we check |
| 1709 CookieList cookie_list(GetAllCookies(cm.get())); | 1722 CookieList cookie_list(GetAllCookies(cm.get())); |
| 1710 typedef std::map<int64, CanonicalCookie> TimeCookieMap; | 1723 typedef std::map<int64, CanonicalCookie> TimeCookieMap; |
| 1711 TimeCookieMap check_map; | 1724 TimeCookieMap check_map; |
| 1712 for (CookieList::const_iterator it = cookie_list.begin(); | 1725 for (CookieList::const_iterator it = cookie_list.begin(); |
| 1713 it != cookie_list.end(); it++) { | 1726 it != cookie_list.end(); it++) { |
| 1714 const int64 creation_date = it->CreationDate().ToInternalValue(); | 1727 const int64 creation_date = it->CreationDate().ToInternalValue(); |
| 1715 TimeCookieMap::const_iterator existing_cookie_it( | 1728 TimeCookieMap::const_iterator existing_cookie_it( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1763 | 1776 |
| 1764 const CookiesInputInfo input_info[] = { | 1777 const CookiesInputInfo input_info[] = { |
| 1765 {GURL("http://a.b.google.com"), | 1778 {GURL("http://a.b.google.com"), |
| 1766 "a", | 1779 "a", |
| 1767 "1", | 1780 "1", |
| 1768 "", | 1781 "", |
| 1769 "/path/to/cookie", | 1782 "/path/to/cookie", |
| 1770 expires, | 1783 expires, |
| 1771 false, | 1784 false, |
| 1772 false, | 1785 false, |
| 1786 false, |
| 1773 COOKIE_PRIORITY_DEFAULT}, | 1787 COOKIE_PRIORITY_DEFAULT}, |
| 1774 {GURL("https://www.google.com"), | 1788 {GURL("https://www.google.com"), |
| 1775 "b", | 1789 "b", |
| 1776 "2", | 1790 "2", |
| 1777 ".google.com", | 1791 ".google.com", |
| 1778 "/path/from/cookie", | 1792 "/path/from/cookie", |
| 1779 expires + TimeDelta::FromSeconds(10), | 1793 expires + TimeDelta::FromSeconds(10), |
| 1780 true, | 1794 true, |
| 1781 true, | 1795 true, |
| 1796 false, |
| 1782 COOKIE_PRIORITY_DEFAULT}, | 1797 COOKIE_PRIORITY_DEFAULT}, |
| 1783 {GURL("https://google.com"), | 1798 {GURL("https://google.com"), |
| 1784 "c", | 1799 "c", |
| 1785 "3", | 1800 "3", |
| 1786 "", | 1801 "", |
| 1787 "/another/path/to/cookie", | 1802 "/another/path/to/cookie", |
| 1788 base::Time::Now() + base::TimeDelta::FromSeconds(100), | 1803 base::Time::Now() + base::TimeDelta::FromSeconds(100), |
| 1789 true, | 1804 true, |
| 1790 false, | 1805 false, |
| 1806 true, |
| 1791 COOKIE_PRIORITY_DEFAULT}}; | 1807 COOKIE_PRIORITY_DEFAULT}}; |
| 1792 const int INPUT_DELETE = 1; | 1808 const int INPUT_DELETE = 1; |
| 1793 | 1809 |
| 1794 // Create new cookies and flush them to the store. | 1810 // Create new cookies and flush them to the store. |
| 1795 { | 1811 { |
| 1796 scoped_refptr<CookieMonster> cmout(new CookieMonster(store.get(), NULL)); | 1812 scoped_refptr<CookieMonster> cmout(new CookieMonster(store.get(), NULL)); |
| 1797 for (const CookiesInputInfo* p = input_info; | 1813 for (const CookiesInputInfo* p = input_info; |
| 1798 p < &input_info[arraysize(input_info)]; p++) { | 1814 p < &input_info[arraysize(input_info)]; p++) { |
| 1799 EXPECT_TRUE(SetCookieWithDetails(cmout.get(), p->url, p->name, p->value, | 1815 EXPECT_TRUE(SetCookieWithDetails(cmout.get(), p->url, p->name, p->value, |
| 1800 p->domain, p->path, p->expiration_time, | 1816 p->domain, p->path, p->expiration_time, |
| 1801 p->secure, p->http_only, p->priority)); | 1817 p->secure, p->http_only, |
| 1818 p->first_party_only, p->priority)); |
| 1802 } | 1819 } |
| 1803 GURL del_url(input_info[INPUT_DELETE] | 1820 GURL del_url(input_info[INPUT_DELETE] |
| 1804 .url.Resolve(input_info[INPUT_DELETE].path) | 1821 .url.Resolve(input_info[INPUT_DELETE].path) |
| 1805 .spec()); | 1822 .spec()); |
| 1806 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name); | 1823 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name); |
| 1807 } | 1824 } |
| 1808 | 1825 |
| 1809 // Create a new cookie monster and make sure that everything is correct | 1826 // Create a new cookie monster and make sure that everything is correct |
| 1810 { | 1827 { |
| 1811 scoped_refptr<CookieMonster> cmin(new CookieMonster(store.get(), NULL)); | 1828 scoped_refptr<CookieMonster> cmin(new CookieMonster(store.get(), NULL)); |
| 1812 CookieList cookies(GetAllCookies(cmin.get())); | 1829 CookieList cookies(GetAllCookies(cmin.get())); |
| 1813 ASSERT_EQ(2u, cookies.size()); | 1830 ASSERT_EQ(2u, cookies.size()); |
| 1814 // Ordering is path length, then creation time. So second cookie | 1831 // Ordering is path length, then creation time. So second cookie |
| 1815 // will come first, and we need to swap them. | 1832 // will come first, and we need to swap them. |
| 1816 std::swap(cookies[0], cookies[1]); | 1833 std::swap(cookies[0], cookies[1]); |
| 1817 for (int output_index = 0; output_index < 2; output_index++) { | 1834 for (int output_index = 0; output_index < 2; output_index++) { |
| 1818 int input_index = output_index * 2; | 1835 int input_index = output_index * 2; |
| 1819 const CookiesInputInfo* input = &input_info[input_index]; | 1836 const CookiesInputInfo* input = &input_info[input_index]; |
| 1820 const CanonicalCookie* output = &cookies[output_index]; | 1837 const CanonicalCookie* output = &cookies[output_index]; |
| 1821 | 1838 |
| 1822 EXPECT_EQ(input->name, output->Name()); | 1839 EXPECT_EQ(input->name, output->Name()); |
| 1823 EXPECT_EQ(input->value, output->Value()); | 1840 EXPECT_EQ(input->value, output->Value()); |
| 1824 EXPECT_EQ(input->url.host(), output->Domain()); | 1841 EXPECT_EQ(input->url.host(), output->Domain()); |
| 1825 EXPECT_EQ(input->path, output->Path()); | 1842 EXPECT_EQ(input->path, output->Path()); |
| 1826 EXPECT_LE(current.ToInternalValue(), | 1843 EXPECT_LE(current.ToInternalValue(), |
| 1827 output->CreationDate().ToInternalValue()); | 1844 output->CreationDate().ToInternalValue()); |
| 1828 EXPECT_EQ(input->secure, output->IsSecure()); | 1845 EXPECT_EQ(input->secure, output->IsSecure()); |
| 1829 EXPECT_EQ(input->http_only, output->IsHttpOnly()); | 1846 EXPECT_EQ(input->http_only, output->IsHttpOnly()); |
| 1847 EXPECT_EQ(input->first_party_only, output->IsFirstPartyOnly()); |
| 1830 EXPECT_TRUE(output->IsPersistent()); | 1848 EXPECT_TRUE(output->IsPersistent()); |
| 1831 EXPECT_EQ(input->expiration_time.ToInternalValue(), | 1849 EXPECT_EQ(input->expiration_time.ToInternalValue(), |
| 1832 output->ExpiryDate().ToInternalValue()); | 1850 output->ExpiryDate().ToInternalValue()); |
| 1833 } | 1851 } |
| 1834 } | 1852 } |
| 1835 } | 1853 } |
| 1836 | 1854 |
| 1837 TEST_F(CookieMonsterTest, CookieListOrdering) { | 1855 TEST_F(CookieMonsterTest, CookieListOrdering) { |
| 1838 // Put a random set of cookies into a monster and make sure | 1856 // Put a random set of cookies into a monster and make sure |
| 1839 // they're returned in the right order. | 1857 // they're returned in the right order. |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2094 // since the histogram should have been initialized by the CM construction | 2112 // since the histogram should have been initialized by the CM construction |
| 2095 // above. | 2113 // above. |
| 2096 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( | 2114 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( |
| 2097 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, | 2115 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, |
| 2098 base::Histogram::kUmaTargetedHistogramFlag); | 2116 base::Histogram::kUmaTargetedHistogramFlag); |
| 2099 | 2117 |
| 2100 scoped_ptr<base::HistogramSamples> samples1( | 2118 scoped_ptr<base::HistogramSamples> samples1( |
| 2101 expired_histogram->SnapshotSamples()); | 2119 expired_histogram->SnapshotSamples()); |
| 2102 ASSERT_TRUE(SetCookieWithDetails( | 2120 ASSERT_TRUE(SetCookieWithDetails( |
| 2103 cm.get(), GURL("http://fake.a.url"), "a", "b", "a.url", "/", | 2121 cm.get(), GURL("http://fake.a.url"), "a", "b", "a.url", "/", |
| 2104 base::Time::Now() + base::TimeDelta::FromMinutes(59), false, false, | 2122 base::Time::Now() + base::TimeDelta::FromMinutes(59), false, false, false, |
| 2105 COOKIE_PRIORITY_DEFAULT)); | 2123 COOKIE_PRIORITY_DEFAULT)); |
| 2106 | 2124 |
| 2107 scoped_ptr<base::HistogramSamples> samples2( | 2125 scoped_ptr<base::HistogramSamples> samples2( |
| 2108 expired_histogram->SnapshotSamples()); | 2126 expired_histogram->SnapshotSamples()); |
| 2109 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); | 2127 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); |
| 2110 | 2128 |
| 2111 // kValidCookieLine creates a session cookie. | 2129 // kValidCookieLine creates a session cookie. |
| 2112 ASSERT_TRUE(SetCookie(cm.get(), url_google_, kValidCookieLine)); | 2130 ASSERT_TRUE(SetCookie(cm.get(), url_google_, kValidCookieLine)); |
| 2113 | 2131 |
| 2114 scoped_ptr<base::HistogramSamples> samples3( | 2132 scoped_ptr<base::HistogramSamples> samples3( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2151 ResultSavingCookieCallback<bool>* callback) { | 2169 ResultSavingCookieCallback<bool>* callback) { |
| 2152 // Define the parameters here instead of in the calling fucntion. | 2170 // Define the parameters here instead of in the calling fucntion. |
| 2153 // The maximum number of parameters for Bind function is 6. | 2171 // The maximum number of parameters for Bind function is 6. |
| 2154 std::string name = "A"; | 2172 std::string name = "A"; |
| 2155 std::string value = "B"; | 2173 std::string value = "B"; |
| 2156 std::string domain = std::string(); | 2174 std::string domain = std::string(); |
| 2157 std::string path = "/foo"; | 2175 std::string path = "/foo"; |
| 2158 base::Time expiration_time = base::Time(); | 2176 base::Time expiration_time = base::Time(); |
| 2159 bool secure = false; | 2177 bool secure = false; |
| 2160 bool http_only = false; | 2178 bool http_only = false; |
| 2179 bool first_party_only = false; |
| 2161 CookiePriority priority = COOKIE_PRIORITY_DEFAULT; | 2180 CookiePriority priority = COOKIE_PRIORITY_DEFAULT; |
| 2162 cm->SetCookieWithDetailsAsync( | 2181 cm->SetCookieWithDetailsAsync( |
| 2163 url, name, value, domain, path, expiration_time, secure, http_only, | 2182 url, name, value, domain, path, expiration_time, secure, http_only, |
| 2164 priority, base::Bind(&ResultSavingCookieCallback<bool>::Run, | 2183 first_party_only, priority, |
| 2165 base::Unretained(callback))); | 2184 base::Bind(&ResultSavingCookieCallback<bool>::Run, |
| 2185 base::Unretained(callback))); |
| 2166 } | 2186 } |
| 2167 | 2187 |
| 2168 void DeleteAllCreatedBetweenTask(CookieMonster* cm, | 2188 void DeleteAllCreatedBetweenTask(CookieMonster* cm, |
| 2169 const base::Time& delete_begin, | 2189 const base::Time& delete_begin, |
| 2170 const base::Time& delete_end, | 2190 const base::Time& delete_end, |
| 2171 ResultSavingCookieCallback<int>* callback) { | 2191 ResultSavingCookieCallback<int>* callback) { |
| 2172 cm->DeleteAllCreatedBetweenAsync( | 2192 cm->DeleteAllCreatedBetweenAsync( |
| 2173 delete_begin, delete_end, | 2193 delete_begin, delete_end, |
| 2174 base::Bind(&ResultSavingCookieCallback<int>::Run, | 2194 base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 2175 base::Unretained(callback))); | 2195 base::Unretained(callback))); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2281 ASSERT_TRUE(it != callback.cookies().end()); | 2301 ASSERT_TRUE(it != callback.cookies().end()); |
| 2282 EXPECT_EQ("www.google.izzle", it->Domain()); | 2302 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2283 EXPECT_EQ("A", it->Name()); | 2303 EXPECT_EQ("A", it->Name()); |
| 2284 ASSERT_TRUE(++it == callback.cookies().end()); | 2304 ASSERT_TRUE(++it == callback.cookies().end()); |
| 2285 } | 2305 } |
| 2286 | 2306 |
| 2287 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) { | 2307 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) { |
| 2288 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2308 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2289 EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_foo_, "A", "B", | 2309 EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_foo_, "A", "B", |
| 2290 std::string(), "/foo", base::Time(), false, | 2310 std::string(), "/foo", base::Time(), false, |
| 2291 false, COOKIE_PRIORITY_DEFAULT)); | 2311 false, false, COOKIE_PRIORITY_DEFAULT)); |
| 2292 ResultSavingCookieCallback<bool> callback(&other_thread_); | 2312 ResultSavingCookieCallback<bool> callback(&other_thread_); |
| 2293 base::Closure task = | 2313 base::Closure task = |
| 2294 base::Bind(&net::MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask, | 2314 base::Bind(&net::MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask, |
| 2295 base::Unretained(this), cm, url_google_foo_, &callback); | 2315 base::Unretained(this), cm, url_google_foo_, &callback); |
| 2296 RunOnOtherThread(task); | 2316 RunOnOtherThread(task); |
| 2297 EXPECT_TRUE(callback.did_run()); | 2317 EXPECT_TRUE(callback.did_run()); |
| 2298 EXPECT_TRUE(callback.result()); | 2318 EXPECT_TRUE(callback.result()); |
| 2299 } | 2319 } |
| 2300 | 2320 |
| 2301 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) { | 2321 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) { |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2548 const std::string path("/path"); | 2568 const std::string path("/path"); |
| 2549 | 2569 |
| 2550 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2570 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2551 | 2571 |
| 2552 std::vector<CanonicalCookie*> initial_cookies; | 2572 std::vector<CanonicalCookie*> initial_cookies; |
| 2553 | 2573 |
| 2554 AddCookieToList(domain, "foo=bar; path=" + path, now1, &initial_cookies); | 2574 AddCookieToList(domain, "foo=bar; path=" + path, now1, &initial_cookies); |
| 2555 | 2575 |
| 2556 // We have to manually build this cookie because it contains a control | 2576 // We have to manually build this cookie because it contains a control |
| 2557 // character, and our cookie line parser rejects control characters. | 2577 // character, and our cookie line parser rejects control characters. |
| 2558 CanonicalCookie* cc = new CanonicalCookie( | 2578 CanonicalCookie* cc = |
| 2559 url, "baz", | 2579 new CanonicalCookie(url, "baz", |
| 2560 "\x05" | 2580 "\x05" |
| 2561 "boo", | 2581 "boo", |
| 2562 domain, path, now2, later, now2, false, false, COOKIE_PRIORITY_DEFAULT); | 2582 domain, path, now2, later, now2, false, false, false, |
| 2583 COOKIE_PRIORITY_DEFAULT); |
| 2563 initial_cookies.push_back(cc); | 2584 initial_cookies.push_back(cc); |
| 2564 | 2585 |
| 2565 AddCookieToList(domain, "hello=world; path=" + path, now3, &initial_cookies); | 2586 AddCookieToList(domain, "hello=world; path=" + path, now3, &initial_cookies); |
| 2566 | 2587 |
| 2567 // Inject our initial cookies into the mock PersistentCookieStore. | 2588 // Inject our initial cookies into the mock PersistentCookieStore. |
| 2568 store->SetLoadExpectation(true, initial_cookies); | 2589 store->SetLoadExpectation(true, initial_cookies); |
| 2569 | 2590 |
| 2570 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2591 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); |
| 2571 | 2592 |
| 2572 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); | 2593 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2722 monster()->AddCallbackForCookie( | 2743 monster()->AddCallbackForCookie( |
| 2723 test_url_, "abc", | 2744 test_url_, "abc", |
| 2724 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 2745 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
| 2725 SetCookie(monster(), test_url_, "abc=def"); | 2746 SetCookie(monster(), test_url_, "abc=def"); |
| 2726 base::MessageLoop::current()->RunUntilIdle(); | 2747 base::MessageLoop::current()->RunUntilIdle(); |
| 2727 EXPECT_EQ(1U, cookies0.size()); | 2748 EXPECT_EQ(1U, cookies0.size()); |
| 2728 EXPECT_EQ(1U, cookies0.size()); | 2749 EXPECT_EQ(1U, cookies0.size()); |
| 2729 } | 2750 } |
| 2730 | 2751 |
| 2731 } // namespace net | 2752 } // namespace net |
| OLD | NEW |