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 1726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1737 // to simulate a database with 4 duplicates. Note that we need to | 1737 // to simulate a database with 4 duplicates. Note that we need to |
1738 // be careful not to have any duplicate creation times at all (as it's a | 1738 // be careful not to have any duplicate creation times at all (as it's a |
1739 // violation of a CookieMonster invariant) even if Time::Now() doesn't | 1739 // violation of a CookieMonster invariant) even if Time::Now() doesn't |
1740 // move between calls. | 1740 // move between calls. |
1741 std::vector<std::unique_ptr<CanonicalCookie>> initial_cookies; | 1741 std::vector<std::unique_ptr<CanonicalCookie>> initial_cookies; |
1742 | 1742 |
1743 // Insert 4 cookies with name "X" on path "/", with varying creation | 1743 // Insert 4 cookies with name "X" on path "/", with varying creation |
1744 // dates. We expect only the most recent one to be preserved following | 1744 // dates. We expect only the most recent one to be preserved following |
1745 // the import. | 1745 // the import. |
1746 | 1746 |
1747 AddCookieToList(GURL("http://www.google.com"), | 1747 AddCookieToList(GURL("http://www.google.izzle"), |
1748 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1748 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
1749 Time::Now() + TimeDelta::FromDays(3), &initial_cookies); | 1749 Time::Now() + TimeDelta::FromDays(3), &initial_cookies); |
1750 | 1750 |
1751 AddCookieToList(GURL("http://www.google.com"), | 1751 AddCookieToList(GURL("http://www.google.izzle"), |
1752 "X=2; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1752 "X=2; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
1753 Time::Now() + TimeDelta::FromDays(1), &initial_cookies); | 1753 Time::Now() + TimeDelta::FromDays(1), &initial_cookies); |
1754 | 1754 |
1755 // ===> This one is the WINNER (biggest creation time). <==== | 1755 // ===> This one is the WINNER (biggest creation time). <==== |
1756 AddCookieToList(GURL("http://www.google.com"), | 1756 AddCookieToList(GURL("http://www.google.izzle"), |
1757 "X=3; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1757 "X=3; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
1758 Time::Now() + TimeDelta::FromDays(4), &initial_cookies); | 1758 Time::Now() + TimeDelta::FromDays(4), &initial_cookies); |
1759 | 1759 |
1760 AddCookieToList(GURL("http://www.google.com"), | 1760 AddCookieToList(GURL("http://www.google.izzle"), |
1761 "X=4; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1761 "X=4; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
1762 Time::Now(), &initial_cookies); | 1762 Time::Now(), &initial_cookies); |
1763 | 1763 |
1764 // Insert 2 cookies with name "X" on path "/2", with varying creation | 1764 // Insert 2 cookies with name "X" on path "/2", with varying creation |
1765 // dates. We expect only the most recent one to be preserved the import. | 1765 // dates. We expect only the most recent one to be preserved the import. |
1766 | 1766 |
1767 // ===> This one is the WINNER (biggest creation time). <==== | 1767 // ===> This one is the WINNER (biggest creation time). <==== |
1768 AddCookieToList(GURL("http://www.google.com"), | 1768 AddCookieToList(GURL("http://www.google.izzle"), |
1769 "X=a1; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1769 "X=a1; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", |
1770 Time::Now() + TimeDelta::FromDays(9), &initial_cookies); | 1770 Time::Now() + TimeDelta::FromDays(9), &initial_cookies); |
1771 | 1771 |
1772 AddCookieToList(GURL("http://www.google.com"), | 1772 AddCookieToList(GURL("http://www.google.izzle"), |
1773 "X=a2; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1773 "X=a2; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", |
1774 Time::Now() + TimeDelta::FromDays(2), &initial_cookies); | 1774 Time::Now() + TimeDelta::FromDays(2), &initial_cookies); |
1775 | 1775 |
1776 // Insert 1 cookie with name "Y" on path "/". | 1776 // Insert 1 cookie with name "Y" on path "/". |
1777 AddCookieToList(GURL("http://www.google.com"), | 1777 AddCookieToList(GURL("http://www.google.izzle"), |
1778 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1778 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
1779 Time::Now() + TimeDelta::FromDays(10), &initial_cookies); | 1779 Time::Now() + TimeDelta::FromDays(10), &initial_cookies); |
1780 | 1780 |
1781 // Inject our initial cookies into the mock PersistentCookieStore. | 1781 // Inject our initial cookies into the mock PersistentCookieStore. |
1782 store->SetLoadExpectation(true, std::move(initial_cookies)); | 1782 store->SetLoadExpectation(true, std::move(initial_cookies)); |
1783 | 1783 |
1784 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 1784 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
1785 | 1785 |
1786 // Verify that duplicates were not imported for path "/". | 1786 // Verify that duplicates were not imported for path "/". |
1787 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4). | 1787 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4). |
1788 EXPECT_EQ("X=3; Y=a", GetCookies(cm.get(), GURL("http://www.google.com/"))); | 1788 EXPECT_EQ("X=3; Y=a", GetCookies(cm.get(), GURL("http://www.google.izzle/"))); |
1789 | 1789 |
1790 // Verify that same-named cookie on a different path ("/x2") didn't get | 1790 // Verify that same-named cookie on a different path ("/x2") didn't get |
1791 // messed up. | 1791 // messed up. |
1792 EXPECT_EQ("X=a1; X=3; Y=a", | 1792 EXPECT_EQ("X=a1; X=3; Y=a", |
1793 GetCookies(cm.get(), GURL("http://www.google.com/2/x"))); | 1793 GetCookies(cm.get(), GURL("http://www.google.izzle/2/x"))); |
1794 | 1794 |
1795 // Verify that the PersistentCookieStore was told to kill its 4 duplicates. | 1795 // Verify that the PersistentCookieStore was told to kill its 4 duplicates. |
1796 ASSERT_EQ(4u, store->commands().size()); | 1796 ASSERT_EQ(4u, store->commands().size()); |
1797 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[0].type); | 1797 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[0].type); |
1798 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 1798 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
1799 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type); | 1799 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type); |
1800 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); | 1800 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
1801 } | 1801 } |
1802 | 1802 |
1803 // Tests importing from a persistent cookie store that contains cookies | 1803 // Tests importing from a persistent cookie store that contains cookies |
1804 // with duplicate creation times. This situation should be handled by | 1804 // with duplicate creation times. This situation should be handled by |
1805 // dropping the cookies before insertion/visibility to user. | 1805 // dropping the cookies before insertion/visibility to user. |
1806 // | 1806 // |
1807 // This is a regression test for: http://crbug.com/43188. | 1807 // This is a regression test for: http://crbug.com/43188. |
1808 TEST_F(CookieMonsterTest, DontImportDuplicateCreationTimes) { | 1808 TEST_F(CookieMonsterTest, DontImportDuplicateCreationTimes) { |
1809 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); | 1809 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
1810 | 1810 |
1811 Time now(Time::Now()); | 1811 Time now(Time::Now()); |
1812 Time earlier(now - TimeDelta::FromDays(1)); | 1812 Time earlier(now - TimeDelta::FromDays(1)); |
1813 | 1813 |
1814 // Insert 8 cookies, four with the current time as creation times, and | 1814 // Insert 8 cookies, four with the current time as creation times, and |
1815 // four with the earlier time as creation times. We should only get | 1815 // four with the earlier time as creation times. We should only get |
1816 // two cookies remaining, but which two (other than that there should | 1816 // two cookies remaining, but which two (other than that there should |
1817 // be one from each set) will be random. | 1817 // be one from each set) will be random. |
1818 std::vector<std::unique_ptr<CanonicalCookie>> initial_cookies; | 1818 std::vector<std::unique_ptr<CanonicalCookie>> initial_cookies; |
1819 AddCookieToList(GURL("http://www.google.com"), "X=1; path=/", now, | 1819 AddCookieToList(GURL("http://www.google.izzle"), "X=1; path=/", now, |
1820 &initial_cookies); | 1820 &initial_cookies); |
1821 AddCookieToList(GURL("http://www.google.com"), "X=2; path=/", now, | 1821 AddCookieToList(GURL("http://www.google.izzle"), "X=2; path=/", now, |
1822 &initial_cookies); | 1822 &initial_cookies); |
1823 AddCookieToList(GURL("http://www.google.com"), "X=3; path=/", now, | 1823 AddCookieToList(GURL("http://www.google.izzle"), "X=3; path=/", now, |
1824 &initial_cookies); | 1824 &initial_cookies); |
1825 AddCookieToList(GURL("http://www.google.com"), "X=4; path=/", now, | 1825 AddCookieToList(GURL("http://www.google.izzle"), "X=4; path=/", now, |
1826 &initial_cookies); | 1826 &initial_cookies); |
1827 | 1827 |
1828 AddCookieToList(GURL("http://www.google.com"), "Y=1; path=/", earlier, | 1828 AddCookieToList(GURL("http://www.google.izzle"), "Y=1; path=/", earlier, |
1829 &initial_cookies); | 1829 &initial_cookies); |
1830 AddCookieToList(GURL("http://www.google.com"), "Y=2; path=/", earlier, | 1830 AddCookieToList(GURL("http://www.google.izzle"), "Y=2; path=/", earlier, |
1831 &initial_cookies); | 1831 &initial_cookies); |
1832 AddCookieToList(GURL("http://www.google.com"), "Y=3; path=/", earlier, | 1832 AddCookieToList(GURL("http://www.google.izzle"), "Y=3; path=/", earlier, |
1833 &initial_cookies); | 1833 &initial_cookies); |
1834 AddCookieToList(GURL("http://www.google.com"), "Y=4; path=/", earlier, | 1834 AddCookieToList(GURL("http://www.google.izzle"), "Y=4; path=/", earlier, |
1835 &initial_cookies); | 1835 &initial_cookies); |
1836 | 1836 |
1837 // Inject our initial cookies into the mock PersistentCookieStore. | 1837 // Inject our initial cookies into the mock PersistentCookieStore. |
1838 store->SetLoadExpectation(true, std::move(initial_cookies)); | 1838 store->SetLoadExpectation(true, std::move(initial_cookies)); |
1839 | 1839 |
1840 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 1840 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
1841 | 1841 |
1842 CookieList list(GetAllCookies(cm.get())); | 1842 CookieList list(GetAllCookies(cm.get())); |
1843 EXPECT_EQ(2U, list.size()); | 1843 EXPECT_EQ(2U, list.size()); |
1844 // Confirm that we have one of each. | 1844 // Confirm that we have one of each. |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2013 } | 2013 } |
2014 } | 2014 } |
2015 } | 2015 } |
2016 | 2016 |
2017 // Mainly a test of GetEffectiveDomain, or more specifically, of the | 2017 // Mainly a test of GetEffectiveDomain, or more specifically, of the |
2018 // expected behavior of GetEffectiveDomain within the CookieMonster. | 2018 // expected behavior of GetEffectiveDomain within the CookieMonster. |
2019 TEST_F(CookieMonsterTest, GetKey) { | 2019 TEST_F(CookieMonsterTest, GetKey) { |
2020 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 2020 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
2021 | 2021 |
2022 // This test is really only interesting if GetKey() actually does something. | 2022 // This test is really only interesting if GetKey() actually does something. |
2023 EXPECT_EQ("google.com", cm->GetKey("www.google.com")); | 2023 EXPECT_EQ("google.izzle", cm->GetKey("www.google.izzle")); |
2024 EXPECT_EQ("google.izzie", cm->GetKey("www.google.izzie")); | 2024 EXPECT_EQ("google.izzie", cm->GetKey("www.google.izzie")); |
2025 EXPECT_EQ("google.izzie", cm->GetKey(".google.izzie")); | 2025 EXPECT_EQ("google.izzie", cm->GetKey(".google.izzie")); |
2026 EXPECT_EQ("bbc.co.uk", cm->GetKey("bbc.co.uk")); | 2026 EXPECT_EQ("bbc.co.uk", cm->GetKey("bbc.co.uk")); |
2027 EXPECT_EQ("bbc.co.uk", cm->GetKey("a.b.c.d.bbc.co.uk")); | 2027 EXPECT_EQ("bbc.co.uk", cm->GetKey("a.b.c.d.bbc.co.uk")); |
2028 EXPECT_EQ("apple.com", cm->GetKey("a.b.c.d.apple.com")); | 2028 EXPECT_EQ("apple.com", cm->GetKey("a.b.c.d.apple.com")); |
2029 EXPECT_EQ("apple.izzie", cm->GetKey("a.b.c.d.apple.izzie")); | 2029 EXPECT_EQ("apple.izzie", cm->GetKey("a.b.c.d.apple.izzie")); |
2030 | 2030 |
2031 // Cases where the effective domain is null, so we use the host | 2031 // Cases where the effective domain is null, so we use the host |
2032 // as the key. | 2032 // as the key. |
2033 EXPECT_EQ("co.uk", cm->GetKey("co.uk")); | 2033 EXPECT_EQ("co.uk", cm->GetKey("co.uk")); |
2034 const std::string extension_name("iehocdgbbocmkdidlbnnfbmbinnahbae"); | 2034 const std::string extension_name("iehocdgbbocmkdidlbnnfbmbinnahbae"); |
2035 EXPECT_EQ(extension_name, cm->GetKey(extension_name)); | 2035 EXPECT_EQ(extension_name, cm->GetKey(extension_name)); |
2036 EXPECT_EQ("com", cm->GetKey("com")); | 2036 EXPECT_EQ("com", cm->GetKey("com")); |
2037 EXPECT_EQ("hostalias", cm->GetKey("hostalias")); | 2037 EXPECT_EQ("hostalias", cm->GetKey("hostalias")); |
2038 EXPECT_EQ("localhost", cm->GetKey("localhost")); | 2038 EXPECT_EQ("localhost", cm->GetKey("localhost")); |
2039 } | 2039 } |
2040 | 2040 |
2041 // Test that cookies transfer from/to the backing store correctly. | 2041 // Test that cookies transfer from/to the backing store correctly. |
2042 TEST_F(CookieMonsterTest, BackingStoreCommunication) { | 2042 TEST_F(CookieMonsterTest, BackingStoreCommunication) { |
2043 // Store details for cookies transforming through the backing store interface. | 2043 // Store details for cookies transforming through the backing store interface. |
2044 | 2044 |
2045 base::Time current(base::Time::Now()); | 2045 base::Time current(base::Time::Now()); |
2046 scoped_refptr<MockSimplePersistentCookieStore> store( | 2046 scoped_refptr<MockSimplePersistentCookieStore> store( |
2047 new MockSimplePersistentCookieStore); | 2047 new MockSimplePersistentCookieStore); |
2048 base::Time new_access_time; | 2048 base::Time new_access_time; |
2049 base::Time expires(base::Time::Now() + base::TimeDelta::FromSeconds(100)); | 2049 base::Time expires(base::Time::Now() + base::TimeDelta::FromSeconds(100)); |
2050 | 2050 |
2051 const CookiesInputInfo input_info[] = { | 2051 const CookiesInputInfo input_info[] = { |
2052 {GURL("http://a.b.google.com"), "a", "1", "", "/path/to/cookie", expires, | 2052 {GURL("http://a.b.google.izzle"), "a", "1", "", "/path/to/cookie", |
2053 false, false, CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT}, | 2053 expires, false, false, CookieSameSite::DEFAULT_MODE, |
2054 {GURL("https://www.google.com"), "b", "2", ".google.com", | 2054 COOKIE_PRIORITY_DEFAULT}, |
| 2055 {GURL("https://www.google.izzle"), "b", "2", ".google.izzle", |
2055 "/path/from/cookie", expires + TimeDelta::FromSeconds(10), true, true, | 2056 "/path/from/cookie", expires + TimeDelta::FromSeconds(10), true, true, |
2056 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT}, | 2057 CookieSameSite::DEFAULT_MODE, COOKIE_PRIORITY_DEFAULT}, |
2057 {GURL("https://google.com"), "c", "3", "", "/another/path/to/cookie", | 2058 {GURL("https://google.izzle"), "c", "3", "", "/another/path/to/cookie", |
2058 base::Time::Now() + base::TimeDelta::FromSeconds(100), true, false, | 2059 base::Time::Now() + base::TimeDelta::FromSeconds(100), true, false, |
2059 CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT}}; | 2060 CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT}}; |
2060 const int INPUT_DELETE = 1; | 2061 const int INPUT_DELETE = 1; |
2061 | 2062 |
2062 // Create new cookies and flush them to the store. | 2063 // Create new cookies and flush them to the store. |
2063 { | 2064 { |
2064 std::unique_ptr<CookieMonster> cmout( | 2065 std::unique_ptr<CookieMonster> cmout( |
2065 new CookieMonster(store.get(), nullptr)); | 2066 new CookieMonster(store.get(), nullptr)); |
2066 for (const CookiesInputInfo* p = input_info; | 2067 for (const CookiesInputInfo* p = input_info; |
2067 p < &input_info[arraysize(input_info)]; p++) { | 2068 p < &input_info[arraysize(input_info)]; p++) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2103 EXPECT_EQ(input->expiration_time.ToInternalValue(), | 2104 EXPECT_EQ(input->expiration_time.ToInternalValue(), |
2104 output->ExpiryDate().ToInternalValue()); | 2105 output->ExpiryDate().ToInternalValue()); |
2105 } | 2106 } |
2106 } | 2107 } |
2107 } | 2108 } |
2108 | 2109 |
2109 TEST_F(CookieMonsterTest, CookieListOrdering) { | 2110 TEST_F(CookieMonsterTest, CookieListOrdering) { |
2110 // Put a random set of cookies into a monster and make sure | 2111 // Put a random set of cookies into a monster and make sure |
2111 // they're returned in the right order. | 2112 // they're returned in the right order. |
2112 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 2113 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
2113 EXPECT_TRUE( | 2114 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://d.c.b.a.google.izzle/aa/x.html"), |
2114 SetCookie(cm.get(), GURL("http://d.c.b.a.google.com/aa/x.html"), "c=1")); | 2115 "c=1")); |
2115 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), | |
2116 "d=1; domain=b.a.google.com")); | |
2117 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), | |
2118 "a=4; domain=b.a.google.com")); | |
2119 EXPECT_TRUE(SetCookie(cm.get(), | 2116 EXPECT_TRUE(SetCookie(cm.get(), |
2120 GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), | 2117 GURL("http://b.a.google.izzle/aa/bb/cc/x.html"), |
2121 "e=1; domain=c.b.a.google.com")); | 2118 "d=1; domain=b.a.google.izzle")); |
2122 EXPECT_TRUE(SetCookie(cm.get(), | 2119 EXPECT_TRUE(SetCookie(cm.get(), |
2123 GURL("http://d.c.b.a.google.com/aa/bb/x.html"), "b=1")); | 2120 GURL("http://b.a.google.izzle/aa/bb/cc/x.html"), |
| 2121 "a=4; domain=b.a.google.izzle")); |
| 2122 EXPECT_TRUE(SetCookie(cm.get(), |
| 2123 GURL("http://c.b.a.google.izzle/aa/bb/cc/x.html"), |
| 2124 "e=1; domain=c.b.a.google.izzle")); |
| 2125 EXPECT_TRUE(SetCookie( |
| 2126 cm.get(), GURL("http://d.c.b.a.google.izzle/aa/bb/x.html"), "b=1")); |
2124 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://news.bbc.co.uk/midpath/x.html"), | 2127 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://news.bbc.co.uk/midpath/x.html"), |
2125 "g=10")); | 2128 "g=10")); |
2126 { | 2129 { |
2127 unsigned int i = 0; | 2130 unsigned int i = 0; |
2128 CookieList cookies(GetAllCookiesForURL( | 2131 CookieList cookies(GetAllCookiesForURL( |
2129 cm.get(), GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"))); | 2132 cm.get(), GURL("http://d.c.b.a.google.izzle/aa/bb/cc/dd"))); |
2130 ASSERT_EQ(5u, cookies.size()); | 2133 ASSERT_EQ(5u, cookies.size()); |
2131 EXPECT_EQ("d", cookies[i++].Name()); | 2134 EXPECT_EQ("d", cookies[i++].Name()); |
2132 EXPECT_EQ("a", cookies[i++].Name()); | 2135 EXPECT_EQ("a", cookies[i++].Name()); |
2133 EXPECT_EQ("e", cookies[i++].Name()); | 2136 EXPECT_EQ("e", cookies[i++].Name()); |
2134 EXPECT_EQ("b", cookies[i++].Name()); | 2137 EXPECT_EQ("b", cookies[i++].Name()); |
2135 EXPECT_EQ("c", cookies[i++].Name()); | 2138 EXPECT_EQ("c", cookies[i++].Name()); |
2136 } | 2139 } |
2137 | 2140 |
2138 { | 2141 { |
2139 unsigned int i = 0; | 2142 unsigned int i = 0; |
(...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3044 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), | 3047 EXPECT_TRUE(SetCookie(cm.get(), https_www_google_.url(), |
3045 "A=E; secure; path=/some/other/path")); | 3048 "A=E; secure; path=/some/other/path")); |
3046 histograms.ExpectTotalCount(cookie_source_histogram, 11); | 3049 histograms.ExpectTotalCount(cookie_source_histogram, 11); |
3047 histograms.ExpectBucketCount(cookie_source_histogram, | 3050 histograms.ExpectBucketCount(cookie_source_histogram, |
3048 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, | 3051 CookieMonster::COOKIE_DELETE_EQUIVALENT_ATTEMPT, |
3049 7); | 3052 7); |
3050 } | 3053 } |
3051 | 3054 |
3052 TEST_F(CookieMonsterTest, SetSecureCookies) { | 3055 TEST_F(CookieMonsterTest, SetSecureCookies) { |
3053 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 3056 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
3054 GURL http_url("http://www.google.com"); | 3057 GURL http_url("http://www.google.izzle"); |
3055 GURL http_superdomain_url("http://google.com"); | 3058 GURL http_superdomain_url("http://google.izzle"); |
3056 GURL https_url("https://www.google.com"); | 3059 GURL https_url("https://www.google.izzle"); |
3057 | 3060 |
3058 // A non-secure cookie can be created from either a URL with a secure or | 3061 // A non-secure cookie can be created from either a URL with a secure or |
3059 // insecure scheme. | 3062 // insecure scheme. |
3060 EXPECT_TRUE(SetCookie(cm.get(), http_url, "A=C;")); | 3063 EXPECT_TRUE(SetCookie(cm.get(), http_url, "A=C;")); |
3061 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B;")); | 3064 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B;")); |
3062 | 3065 |
3063 // A secure cookie cannot be created from a URL with an insecure scheme. | 3066 // A secure cookie cannot be created from a URL with an insecure scheme. |
3064 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=B; Secure")); | 3067 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=B; Secure")); |
3065 | 3068 |
3066 // A secure cookie can be created from a URL with a secure scheme. | 3069 // A secure cookie can be created from a URL with a secure scheme. |
(...skipping 27 matching lines...) Expand all Loading... |
3094 EXPECT_TRUE(SetCookie(cm.get(), http_url, "WITH_PATH=C")); | 3097 EXPECT_TRUE(SetCookie(cm.get(), http_url, "WITH_PATH=C")); |
3095 EXPECT_TRUE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/")); | 3098 EXPECT_TRUE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/")); |
3096 EXPECT_TRUE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/your/path")); | 3099 EXPECT_TRUE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/your/path")); |
3097 EXPECT_FALSE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/my/path")); | 3100 EXPECT_FALSE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/my/path")); |
3098 EXPECT_FALSE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/my/path/sub")); | 3101 EXPECT_FALSE(SetCookie(cm.get(), http_url, "WITH_PATH=C; path=/my/path/sub")); |
3099 | 3102 |
3100 // If a non-secure cookie is created from a URL with an insecure scheme, and | 3103 // If a non-secure cookie is created from a URL with an insecure scheme, and |
3101 // a secure cookie with the same name already exists, if the domain strings | 3104 // a secure cookie with the same name already exists, if the domain strings |
3102 // domain-match, do not update the cookie. | 3105 // domain-match, do not update the cookie. |
3103 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 3106 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
3104 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=C; domain=google.com")); | 3107 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=C; domain=google.izzle")); |
3105 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=C; domain=www.google.com")); | 3108 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=C; domain=www.google.izzle")); |
3106 | 3109 |
3107 // Since A=B was set above with no domain string, set a different cookie here | 3110 // Since A=B was set above with no domain string, set a different cookie here |
3108 // so the insecure examples aren't trying to overwrite the one above. | 3111 // so the insecure examples aren't trying to overwrite the one above. |
3109 EXPECT_TRUE(SetCookie(cm.get(), https_url, "B=C; Secure; domain=google.com")); | 3112 EXPECT_TRUE( |
3110 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D; domain=google.com")); | 3113 SetCookie(cm.get(), https_url, "B=C; Secure; domain=google.izzle")); |
| 3114 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D; domain=google.izzle")); |
3111 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D")); | 3115 EXPECT_FALSE(SetCookie(cm.get(), http_url, "B=D")); |
3112 EXPECT_FALSE(SetCookie(cm.get(), http_superdomain_url, "B=D")); | 3116 EXPECT_FALSE(SetCookie(cm.get(), http_superdomain_url, "B=D")); |
3113 | 3117 |
3114 // Verify that if an httponly version of the cookie exists, adding a Secure | 3118 // Verify that if an httponly version of the cookie exists, adding a Secure |
3115 // version of the cookie still does not overwrite it. | 3119 // version of the cookie still does not overwrite it. |
3116 CookieOptions include_httponly; | 3120 CookieOptions include_httponly; |
3117 include_httponly.set_include_httponly(); | 3121 include_httponly.set_include_httponly(); |
3118 EXPECT_TRUE(SetCookieWithOptions(cm.get(), https_url, "C=D; httponly", | 3122 EXPECT_TRUE(SetCookieWithOptions(cm.get(), https_url, "C=D; httponly", |
3119 include_httponly)); | 3123 include_httponly)); |
3120 // Note that the lack of an explicit options object below uses the default, | 3124 // Note that the lack of an explicit options object below uses the default, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3247 const CookiesEntry test14[] = {{1U, true}}; | 3251 const CookiesEntry test14[] = {{1U, true}}; |
3248 const AltHosts test14_alt_hosts(1500, 1800); | 3252 const AltHosts test14_alt_hosts(1500, 1800); |
3249 TestSecureCookieEviction(test14, arraysize(test14), 1501U, 1499, | 3253 TestSecureCookieEviction(test14, arraysize(test14), 1501U, 1499, |
3250 &test14_alt_hosts); | 3254 &test14_alt_hosts); |
3251 } | 3255 } |
3252 | 3256 |
3253 // Tests that strict secure cookies doesn't trip equivalent cookie checks | 3257 // Tests that strict secure cookies doesn't trip equivalent cookie checks |
3254 // accidentally. Regression test for https://crbug.com/569943. | 3258 // accidentally. Regression test for https://crbug.com/569943. |
3255 TEST_F(CookieMonsterTest, EquivalentCookies) { | 3259 TEST_F(CookieMonsterTest, EquivalentCookies) { |
3256 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 3260 std::unique_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
3257 GURL http_url("http://www.google.com"); | 3261 GURL http_url("http://www.google.izzle"); |
3258 GURL http_superdomain_url("http://google.com"); | 3262 GURL http_superdomain_url("http://google.izzle"); |
3259 GURL https_url("https://www.google.com"); | 3263 GURL https_url("https://www.google.izzle"); |
3260 | 3264 |
3261 // Tests that non-equivalent cookies because of the path attribute can be set | 3265 // Tests that non-equivalent cookies because of the path attribute can be set |
3262 // successfully. | 3266 // successfully. |
3263 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 3267 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
3264 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; path=/some/other/path")); | 3268 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; path=/some/other/path")); |
3265 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; path=/some/other/path")); | 3269 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; path=/some/other/path")); |
3266 | 3270 |
3267 // Tests that non-equivalent cookies because of the domain attribute can be | 3271 // Tests that non-equivalent cookies because of the domain attribute can be |
3268 // set successfully. | 3272 // set successfully. |
3269 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); | 3273 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=B; Secure")); |
3270 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; domain=google.com")); | 3274 EXPECT_TRUE(SetCookie(cm.get(), https_url, "A=C; domain=google.izzle")); |
3271 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; domain=google.com")); | 3275 EXPECT_FALSE(SetCookie(cm.get(), http_url, "A=D; domain=google.izzle")); |
3272 } | 3276 } |
3273 | 3277 |
3274 class CookieMonsterNotificationTest : public CookieMonsterTest { | 3278 class CookieMonsterNotificationTest : public CookieMonsterTest { |
3275 public: | 3279 public: |
3276 CookieMonsterNotificationTest() | 3280 CookieMonsterNotificationTest() |
3277 : test_url_("http://www.google.com/foo"), | 3281 : test_url_("http://www.google.izzle/foo"), |
3278 store_(new MockPersistentCookieStore), | 3282 store_(new MockPersistentCookieStore), |
3279 monster_(new CookieMonster(store_.get(), nullptr)) {} | 3283 monster_(new CookieMonster(store_.get(), nullptr)) {} |
3280 | 3284 |
3281 ~CookieMonsterNotificationTest() override {} | 3285 ~CookieMonsterNotificationTest() override {} |
3282 | 3286 |
3283 CookieMonster* monster() { return monster_.get(); } | 3287 CookieMonster* monster() { return monster_.get(); } |
3284 | 3288 |
3285 protected: | 3289 protected: |
3286 const GURL test_url_; | 3290 const GURL test_url_; |
3287 | 3291 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3421 monster()->AddCallbackForCookie( | 3425 monster()->AddCallbackForCookie( |
3422 test_url_, "abc", | 3426 test_url_, "abc", |
3423 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3427 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
3424 SetCookie(monster(), test_url_, "abc=def"); | 3428 SetCookie(monster(), test_url_, "abc=def"); |
3425 base::RunLoop().RunUntilIdle(); | 3429 base::RunLoop().RunUntilIdle(); |
3426 EXPECT_EQ(1U, cookies0.size()); | 3430 EXPECT_EQ(1U, cookies0.size()); |
3427 EXPECT_EQ(1U, cookies0.size()); | 3431 EXPECT_EQ(1U, cookies0.size()); |
3428 } | 3432 } |
3429 | 3433 |
3430 } // namespace net | 3434 } // namespace net |
OLD | NEW |