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_monster.h" | 5 #include "net/cookies/cookie_monster.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 EXPECT_CALL(set_cookies_callback, Run(true)).WillOnce(QuitRunLoop(&loop)); | 1033 EXPECT_CALL(set_cookies_callback, Run(true)).WillOnce(QuitRunLoop(&loop)); |
1034 | 1034 |
1035 CompleteLoading(); | 1035 CompleteLoading(); |
1036 loop.Run(); | 1036 loop.Run(); |
1037 } | 1037 } |
1038 | 1038 |
1039 TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) { | 1039 TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) { |
1040 MockSetCookiesCallback set_cookies_callback; | 1040 MockSetCookiesCallback set_cookies_callback; |
1041 CookieList list; | 1041 CookieList list; |
1042 list.push_back(*CanonicalCookie::Create( | 1042 list.push_back(*CanonicalCookie::Create( |
1043 http_www_google_.url(), "A", "B", http_www_google_.domain(), "/", | 1043 "A", "B", "." + http_www_google_.domain(), "/", base::Time::Now(), |
1044 base::Time::Now(), base::Time(), false, true, | 1044 base::Time(), base::Time(), false, true, CookieSameSite::DEFAULT_MODE, |
1045 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 1045 COOKIE_PRIORITY_DEFAULT)); |
1046 list.push_back(*CanonicalCookie::Create( | 1046 list.push_back(*CanonicalCookie::Create( |
1047 http_www_google_.url(), "C", "D", http_www_google_.domain(), "/", | 1047 "C", "D", "." + http_www_google_.domain(), "/", base::Time::Now(), |
1048 base::Time::Now(), base::Time(), false, true, | 1048 base::Time(), base::Time(), false, true, CookieSameSite::DEFAULT_MODE, |
1049 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 1049 COOKIE_PRIORITY_DEFAULT)); |
1050 | 1050 |
1051 BeginWith( | 1051 BeginWith( |
1052 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); | 1052 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); |
1053 | 1053 |
1054 WaitForLoadCall(); | 1054 WaitForLoadCall(); |
1055 | 1055 |
1056 EXPECT_CALL(set_cookies_callback, Run(true)) | 1056 EXPECT_CALL(set_cookies_callback, Run(true)) |
1057 .WillOnce( | 1057 .WillOnce( |
1058 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); | 1058 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); |
1059 base::RunLoop loop; | 1059 base::RunLoop loop; |
(...skipping 1467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2527 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2527 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
2528 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2528 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2529 cm->SetPersistSessionCookies(true); | 2529 cm->SetPersistSessionCookies(true); |
2530 | 2530 |
2531 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); | 2531 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); |
2532 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); | 2532 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); |
2533 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); | 2533 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); |
2534 | 2534 |
2535 CookieList list; | 2535 CookieList list; |
2536 list.push_back(*CanonicalCookie::Create( | 2536 list.push_back(*CanonicalCookie::Create( |
2537 http_www_google_.url(), "A", "B", http_www_google_.url().host(), "/", | 2537 "A", "B", "." + http_www_google_.url().host(), "/", base::Time::Now(), |
2538 base::Time::Now(), base::Time(), false, false, | 2538 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2539 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 2539 COOKIE_PRIORITY_DEFAULT)); |
2540 list.push_back(*CanonicalCookie::Create( | 2540 list.push_back(*CanonicalCookie::Create( |
2541 http_www_google_.url(), "W", "X", http_www_google_.url().host(), "/bar", | 2541 "W", "X", "." + http_www_google_.url().host(), "/bar", base::Time::Now(), |
2542 base::Time::Now(), base::Time(), false, false, | 2542 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2543 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 2543 COOKIE_PRIORITY_DEFAULT)); |
2544 list.push_back(*CanonicalCookie::Create( | 2544 list.push_back(*CanonicalCookie::Create( |
2545 http_www_google_.url(), "Y", "Z", http_www_google_.url().host(), "/", | 2545 "Y", "Z", "." + http_www_google_.url().host(), "/", base::Time::Now(), |
2546 base::Time::Now(), base::Time(), false, false, | 2546 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2547 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 2547 COOKIE_PRIORITY_DEFAULT)); |
2548 | 2548 |
2549 // SetAllCookies must not flush. | 2549 // SetAllCookies must not flush. |
2550 ASSERT_EQ(0, store->flush_count()); | 2550 ASSERT_EQ(0, store->flush_count()); |
2551 EXPECT_TRUE(SetAllCookies(cm.get(), list)); | 2551 EXPECT_TRUE(SetAllCookies(cm.get(), list)); |
2552 EXPECT_EQ(0, store->flush_count()); | 2552 EXPECT_EQ(0, store->flush_count()); |
2553 | 2553 |
2554 CookieList cookies = GetAllCookies(cm.get()); | 2554 CookieList cookies = GetAllCookies(cm.get()); |
2555 size_t expected_size = 3; // "A", "W" and "Y". "U" is gone. | 2555 size_t expected_size = 3; // "A", "W" and "Y". "U" is gone. |
2556 EXPECT_EQ(expected_size, cookies.size()); | 2556 EXPECT_EQ(expected_size, cookies.size()); |
2557 CookieList::iterator it = cookies.begin(); | 2557 CookieList::iterator it = cookies.begin(); |
(...skipping 12 matching lines...) Expand all Loading... |
2570 EXPECT_EQ("Z", it->Value()); | 2570 EXPECT_EQ("Z", it->Value()); |
2571 } | 2571 } |
2572 | 2572 |
2573 TEST_F(CookieMonsterTest, ComputeCookieDiff) { | 2573 TEST_F(CookieMonsterTest, ComputeCookieDiff) { |
2574 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 2574 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
2575 | 2575 |
2576 base::Time now = base::Time::Now(); | 2576 base::Time now = base::Time::Now(); |
2577 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); | 2577 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); |
2578 | 2578 |
2579 std::unique_ptr<CanonicalCookie> cookie1(CanonicalCookie::Create( | 2579 std::unique_ptr<CanonicalCookie> cookie1(CanonicalCookie::Create( |
2580 http_www_google_.url(), "A", "B", http_www_google_.url().host(), "/", | 2580 "A", "B", "." + http_www_google_.url().host(), "/", creation_time, |
2581 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2581 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2582 COOKIE_PRIORITY_DEFAULT)); | 2582 COOKIE_PRIORITY_DEFAULT)); |
2583 std::unique_ptr<CanonicalCookie> cookie2(CanonicalCookie::Create( | 2583 std::unique_ptr<CanonicalCookie> cookie2(CanonicalCookie::Create( |
2584 http_www_google_.url(), "C", "D", http_www_google_.url().host(), "/", | 2584 "C", "D", "." + http_www_google_.url().host(), "/", creation_time, |
2585 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2585 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2586 COOKIE_PRIORITY_DEFAULT)); | 2586 COOKIE_PRIORITY_DEFAULT)); |
2587 std::unique_ptr<CanonicalCookie> cookie3(CanonicalCookie::Create( | 2587 std::unique_ptr<CanonicalCookie> cookie3(CanonicalCookie::Create( |
2588 http_www_google_.url(), "E", "F", http_www_google_.url().host(), "/", | 2588 "E", "F", "." + http_www_google_.url().host(), "/", creation_time, |
2589 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2589 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2590 COOKIE_PRIORITY_DEFAULT)); | 2590 COOKIE_PRIORITY_DEFAULT)); |
2591 std::unique_ptr<CanonicalCookie> cookie4(CanonicalCookie::Create( | 2591 std::unique_ptr<CanonicalCookie> cookie4(CanonicalCookie::Create( |
2592 http_www_google_.url(), "G", "H", http_www_google_.url().host(), "/", | 2592 "G", "H", "." + http_www_google_.url().host(), "/", creation_time, |
2593 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2593 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2594 COOKIE_PRIORITY_DEFAULT)); | 2594 COOKIE_PRIORITY_DEFAULT)); |
2595 std::unique_ptr<CanonicalCookie> cookie4_with_new_value( | 2595 std::unique_ptr<CanonicalCookie> cookie4_with_new_value( |
2596 CanonicalCookie::Create( | 2596 CanonicalCookie::Create( |
2597 http_www_google_.url(), "G", "iamnew", http_www_google_.url().host(), | 2597 "G", "iamnew", "." + http_www_google_.url().host(), "/", |
2598 "/", creation_time, base::Time(), false, false, | 2598 creation_time, base::Time(), base::Time(), false, false, |
2599 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 2599 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); |
2600 std::unique_ptr<CanonicalCookie> cookie5(CanonicalCookie::Create( | 2600 std::unique_ptr<CanonicalCookie> cookie5(CanonicalCookie::Create( |
2601 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", | 2601 "I", "J", "." + http_www_google_.url().host(), "/", creation_time, |
2602 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2602 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2603 COOKIE_PRIORITY_DEFAULT)); | 2603 COOKIE_PRIORITY_DEFAULT)); |
2604 std::unique_ptr<CanonicalCookie> cookie5_with_new_creation_time( | 2604 std::unique_ptr<CanonicalCookie> cookie5_with_new_creation_time( |
2605 CanonicalCookie::Create( | 2605 CanonicalCookie::Create("I", "J", "." + http_www_google_.url().host(), |
2606 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", | 2606 "/", now, base::Time(), base::Time(), false, |
2607 now, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2607 false, CookieSameSite::DEFAULT_MODE, |
2608 COOKIE_PRIORITY_DEFAULT)); | 2608 COOKIE_PRIORITY_DEFAULT)); |
2609 std::unique_ptr<CanonicalCookie> cookie6(CanonicalCookie::Create( | 2609 std::unique_ptr<CanonicalCookie> cookie6(CanonicalCookie::Create( |
2610 http_www_google_.url(), "K", "L", http_www_google_.url().host(), "/foo", | 2610 "K", "L", "." + http_www_google_.url().host(), "/foo", creation_time, |
2611 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2611 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2612 COOKIE_PRIORITY_DEFAULT)); | 2612 COOKIE_PRIORITY_DEFAULT)); |
2613 std::unique_ptr<CanonicalCookie> cookie6_with_new_path( | 2613 std::unique_ptr<CanonicalCookie> cookie6_with_new_path( |
2614 CanonicalCookie::Create( | 2614 CanonicalCookie::Create("K", "L", "." + http_www_google_.url().host(), |
2615 http_www_google_.url(), "K", "L", http_www_google_.url().host(), | 2615 "/bar", creation_time, base::Time(), base::Time(), |
2616 "/bar", creation_time, base::Time(), false, false, | 2616 false, false, CookieSameSite::DEFAULT_MODE, |
2617 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 2617 COOKIE_PRIORITY_DEFAULT)); |
2618 std::unique_ptr<CanonicalCookie> cookie7(CanonicalCookie::Create( | 2618 std::unique_ptr<CanonicalCookie> cookie7(CanonicalCookie::Create( |
2619 http_www_google_.url(), "M", "N", http_www_google_.url().host(), "/foo", | 2619 "M", "N", "." + http_www_google_.url().host(), "/foo", creation_time, |
2620 creation_time, base::Time(), false, false, CookieSameSite::DEFAULT_MODE, | 2620 base::Time(), base::Time(), false, false, CookieSameSite::DEFAULT_MODE, |
2621 COOKIE_PRIORITY_DEFAULT)); | 2621 COOKIE_PRIORITY_DEFAULT)); |
2622 std::unique_ptr<CanonicalCookie> cookie7_with_new_path( | 2622 std::unique_ptr<CanonicalCookie> cookie7_with_new_path( |
2623 CanonicalCookie::Create( | 2623 CanonicalCookie::Create("M", "N", "." + http_www_google_.url().host(), |
2624 http_www_google_.url(), "M", "N", http_www_google_.url().host(), | 2624 "/bar", creation_time, base::Time(), base::Time(), |
2625 "/bar", creation_time, base::Time(), false, false, | 2625 false, false, CookieSameSite::DEFAULT_MODE, |
2626 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT)); | 2626 COOKIE_PRIORITY_DEFAULT)); |
2627 | 2627 |
2628 CookieList old_cookies; | 2628 CookieList old_cookies; |
2629 old_cookies.push_back(*cookie1); | 2629 old_cookies.push_back(*cookie1); |
2630 old_cookies.push_back(*cookie2); | 2630 old_cookies.push_back(*cookie2); |
2631 old_cookies.push_back(*cookie4); | 2631 old_cookies.push_back(*cookie4); |
2632 old_cookies.push_back(*cookie5); | 2632 old_cookies.push_back(*cookie5); |
2633 old_cookies.push_back(*cookie6); | 2633 old_cookies.push_back(*cookie6); |
2634 old_cookies.push_back(*cookie7); | 2634 old_cookies.push_back(*cookie7); |
2635 | 2635 |
2636 CookieList new_cookies; | 2636 CookieList new_cookies; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2829 | 2829 |
2830 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 2830 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
2831 | 2831 |
2832 std::vector<std::unique_ptr<CanonicalCookie>> initial_cookies; | 2832 std::vector<std::unique_ptr<CanonicalCookie>> initial_cookies; |
2833 | 2833 |
2834 AddCookieToList(url, "foo=bar; path=" + path, now1, &initial_cookies); | 2834 AddCookieToList(url, "foo=bar; path=" + path, now1, &initial_cookies); |
2835 | 2835 |
2836 // We have to manually build this cookie because it contains a control | 2836 // We have to manually build this cookie because it contains a control |
2837 // character, and our cookie line parser rejects control characters. | 2837 // character, and our cookie line parser rejects control characters. |
2838 std::unique_ptr<CanonicalCookie> cc = CanonicalCookie::Create( | 2838 std::unique_ptr<CanonicalCookie> cc = CanonicalCookie::Create( |
2839 url, "baz", | 2839 "baz", |
2840 "\x05" | 2840 "\x05" |
2841 "boo", | 2841 "boo", |
2842 domain, path, now2, later, false, false, CookieSameSite::DEFAULT_MODE, | 2842 "." + domain, path, now2, later, base::Time(), false, false, |
2843 COOKIE_PRIORITY_DEFAULT); | 2843 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT); |
2844 initial_cookies.push_back(std::move(cc)); | 2844 initial_cookies.push_back(std::move(cc)); |
2845 | 2845 |
2846 AddCookieToList(url, "hello=world; path=" + path, now3, &initial_cookies); | 2846 AddCookieToList(url, "hello=world; path=" + path, now3, &initial_cookies); |
2847 | 2847 |
2848 // Inject our initial cookies into the mock PersistentCookieStore. | 2848 // Inject our initial cookies into the mock PersistentCookieStore. |
2849 store->SetLoadExpectation(true, std::move(initial_cookies)); | 2849 store->SetLoadExpectation(true, std::move(initial_cookies)); |
2850 | 2850 |
2851 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2851 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2852 | 2852 |
2853 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); | 2853 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3371 monster()->AddCallbackForCookie( | 3371 monster()->AddCallbackForCookie( |
3372 test_url_, "abc", | 3372 test_url_, "abc", |
3373 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3373 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
3374 SetCookie(monster(), test_url_, "abc=def"); | 3374 SetCookie(monster(), test_url_, "abc=def"); |
3375 base::RunLoop().RunUntilIdle(); | 3375 base::RunLoop().RunUntilIdle(); |
3376 EXPECT_EQ(1U, cookies0.size()); | 3376 EXPECT_EQ(1U, cookies0.size()); |
3377 EXPECT_EQ(1U, cookies0.size()); | 3377 EXPECT_EQ(1U, cookies0.size()); |
3378 } | 3378 } |
3379 | 3379 |
3380 } // namespace net | 3380 } // namespace net |
OLD | NEW |