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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a) | 180 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a) |
181 // * http_only cookie (w.c.b.a) | 181 // * http_only cookie (w.c.b.a) |
182 // * same_site cookie (w.c.b.a) | 182 // * same_site cookie (w.c.b.a) |
183 // * Two secure cookies (.c.b.a, w.c.b.a) | 183 // * Two secure cookies (.c.b.a, w.c.b.a) |
184 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) | 184 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) |
185 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) | 185 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) |
186 | 186 |
187 // Domain cookies | 187 // Domain cookies |
188 EXPECT_TRUE(this->SetCookieWithDetails( | 188 EXPECT_TRUE(this->SetCookieWithDetails( |
189 cm, url_top_level_domain_plus_1, "dom_1", "X", ".harvard.edu", "/", | 189 cm, url_top_level_domain_plus_1, "dom_1", "X", ".harvard.edu", "/", |
190 base::Time(), base::Time(), base::Time(), false, false, false, | 190 base::Time(), base::Time(), base::Time(), false, false, |
191 COOKIE_PRIORITY_DEFAULT)); | 191 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
192 EXPECT_TRUE(this->SetCookieWithDetails( | 192 EXPECT_TRUE(this->SetCookieWithDetails( |
193 cm, url_top_level_domain_plus_2, "dom_2", "X", ".math.harvard.edu", "/", | 193 cm, url_top_level_domain_plus_2, "dom_2", "X", ".math.harvard.edu", "/", |
194 base::Time(), base::Time(), base::Time(), false, false, false, | 194 base::Time(), base::Time(), base::Time(), false, false, |
195 COOKIE_PRIORITY_DEFAULT)); | 195 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
196 EXPECT_TRUE(this->SetCookieWithDetails( | 196 EXPECT_TRUE(this->SetCookieWithDetails( |
197 cm, url_top_level_domain_plus_3, "dom_3", "X", | 197 cm, url_top_level_domain_plus_3, "dom_3", "X", |
198 ".bourbaki.math.harvard.edu", "/", base::Time(), base::Time(), | 198 ".bourbaki.math.harvard.edu", "/", base::Time(), base::Time(), |
199 base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT)); | 199 base::Time(), false, false, COOKIE_SAME_SITE_DEFAULT, |
200 COOKIE_PRIORITY_DEFAULT)); | |
200 | 201 |
201 // Host cookies | 202 // Host cookies |
202 EXPECT_TRUE(this->SetCookieWithDetails( | 203 EXPECT_TRUE(this->SetCookieWithDetails( |
203 cm, url_top_level_domain_plus_1, "host_1", "X", std::string(), "/", | 204 cm, url_top_level_domain_plus_1, "host_1", "X", std::string(), "/", |
204 base::Time(), base::Time(), base::Time(), false, false, false, | 205 base::Time(), base::Time(), base::Time(), false, false, |
205 COOKIE_PRIORITY_DEFAULT)); | 206 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
206 EXPECT_TRUE(this->SetCookieWithDetails( | 207 EXPECT_TRUE(this->SetCookieWithDetails( |
207 cm, url_top_level_domain_plus_2, "host_2", "X", std::string(), "/", | 208 cm, url_top_level_domain_plus_2, "host_2", "X", std::string(), "/", |
208 base::Time(), base::Time(), base::Time(), false, false, false, | 209 base::Time(), base::Time(), base::Time(), false, false, |
209 COOKIE_PRIORITY_DEFAULT)); | 210 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
210 EXPECT_TRUE(this->SetCookieWithDetails( | 211 EXPECT_TRUE(this->SetCookieWithDetails( |
211 cm, url_top_level_domain_plus_3, "host_3", "X", std::string(), "/", | 212 cm, url_top_level_domain_plus_3, "host_3", "X", std::string(), "/", |
212 base::Time(), base::Time(), base::Time(), false, false, false, | 213 base::Time(), base::Time(), base::Time(), false, false, |
213 COOKIE_PRIORITY_DEFAULT)); | 214 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
214 | 215 |
215 // http_only cookie | 216 // http_only cookie |
216 EXPECT_TRUE(this->SetCookieWithDetails( | 217 EXPECT_TRUE(this->SetCookieWithDetails( |
217 cm, url_top_level_domain_plus_2, "httpo_check", "x", std::string(), "/", | 218 cm, url_top_level_domain_plus_2, "httpo_check", "x", std::string(), "/", |
218 base::Time(), base::Time(), base::Time(), false, true, false, | 219 base::Time(), base::Time(), base::Time(), false, true, |
219 COOKIE_PRIORITY_DEFAULT)); | 220 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
220 | 221 |
221 // same-site cookie | 222 // same-site cookie |
222 EXPECT_TRUE(this->SetCookieWithDetails( | 223 EXPECT_TRUE(this->SetCookieWithDetails( |
223 cm, url_top_level_domain_plus_2, "firstp_check", "x", std::string(), | 224 cm, url_top_level_domain_plus_2, "firstp_check", "x", std::string(), |
224 "/", base::Time(), base::Time(), base::Time(), false, false, true, | 225 "/", base::Time(), base::Time(), base::Time(), false, false, |
225 COOKIE_PRIORITY_DEFAULT)); | 226 COOKIE_SAME_SITE_STRICT, COOKIE_PRIORITY_DEFAULT)); |
226 | 227 |
227 // Secure cookies | 228 // Secure cookies |
228 EXPECT_TRUE(this->SetCookieWithDetails( | 229 EXPECT_TRUE(this->SetCookieWithDetails( |
229 cm, url_top_level_domain_plus_2_secure, "sec_dom", "X", | 230 cm, url_top_level_domain_plus_2_secure, "sec_dom", "X", |
230 ".math.harvard.edu", "/", base::Time(), base::Time(), base::Time(), | 231 ".math.harvard.edu", "/", base::Time(), base::Time(), base::Time(), |
231 true, false, false, COOKIE_PRIORITY_DEFAULT)); | 232 true, false, COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
232 EXPECT_TRUE(this->SetCookieWithDetails( | 233 EXPECT_TRUE(this->SetCookieWithDetails( |
233 cm, url_top_level_domain_plus_2_secure, "sec_host", "X", std::string(), | 234 cm, url_top_level_domain_plus_2_secure, "sec_host", "X", std::string(), |
234 "/", base::Time(), base::Time(), base::Time(), true, false, false, | 235 "/", base::Time(), base::Time(), base::Time(), true, false, |
235 COOKIE_PRIORITY_DEFAULT)); | 236 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
236 | 237 |
237 // Domain path cookies | 238 // Domain path cookies |
238 EXPECT_TRUE(this->SetCookieWithDetails( | 239 EXPECT_TRUE(this->SetCookieWithDetails( |
239 cm, url_top_level_domain_plus_2, "dom_path_1", "X", ".math.harvard.edu", | 240 cm, url_top_level_domain_plus_2, "dom_path_1", "X", ".math.harvard.edu", |
240 "/dir1", base::Time(), base::Time(), base::Time(), false, false, false, | 241 "/dir1", base::Time(), base::Time(), base::Time(), false, false, |
241 COOKIE_PRIORITY_DEFAULT)); | 242 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
242 EXPECT_TRUE(this->SetCookieWithDetails( | 243 EXPECT_TRUE(this->SetCookieWithDetails( |
243 cm, url_top_level_domain_plus_2, "dom_path_2", "X", ".math.harvard.edu", | 244 cm, url_top_level_domain_plus_2, "dom_path_2", "X", ".math.harvard.edu", |
244 "/dir1/dir2", base::Time(), base::Time(), base::Time(), false, false, | 245 "/dir1/dir2", base::Time(), base::Time(), base::Time(), false, false, |
245 false, COOKIE_PRIORITY_DEFAULT)); | 246 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
246 | 247 |
247 // Host path cookies | 248 // Host path cookies |
248 EXPECT_TRUE(this->SetCookieWithDetails( | 249 EXPECT_TRUE(this->SetCookieWithDetails( |
249 cm, url_top_level_domain_plus_2, "host_path_1", "X", std::string(), | 250 cm, url_top_level_domain_plus_2, "host_path_1", "X", std::string(), |
250 "/dir1", base::Time(), base::Time(), base::Time(), false, false, false, | 251 "/dir1", base::Time(), base::Time(), base::Time(), false, false, |
251 COOKIE_PRIORITY_DEFAULT)); | 252 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
252 EXPECT_TRUE(this->SetCookieWithDetails( | 253 EXPECT_TRUE(this->SetCookieWithDetails( |
253 cm, url_top_level_domain_plus_2, "host_path_2", "X", std::string(), | 254 cm, url_top_level_domain_plus_2, "host_path_2", "X", std::string(), |
254 "/dir1/dir2", base::Time(), base::Time(), base::Time(), false, false, | 255 "/dir1/dir2", base::Time(), base::Time(), base::Time(), false, false, |
255 false, COOKIE_PRIORITY_DEFAULT)); | 256 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
256 | 257 |
257 EXPECT_EQ(14U, this->GetAllCookies(cm).size()); | 258 EXPECT_EQ(14U, this->GetAllCookies(cm).size()); |
258 } | 259 } |
259 | 260 |
260 Time GetFirstCookieAccessDate(CookieMonster* cm) { | 261 Time GetFirstCookieAccessDate(CookieMonster* cm) { |
261 const CookieList all_cookies(this->GetAllCookies(cm)); | 262 const CookieList all_cookies(this->GetAllCookies(cm)); |
262 return all_cookies.front().LastAccessDate(); | 263 return all_cookies.front().LastAccessDate(); |
263 } | 264 } |
264 | 265 |
265 bool FindAndDeleteCookie(CookieMonster* cm, | 266 bool FindAndDeleteCookie(CookieMonster* cm, |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
614 | 615 |
615 struct CookiesInputInfo { | 616 struct CookiesInputInfo { |
616 const GURL url; | 617 const GURL url; |
617 const std::string name; | 618 const std::string name; |
618 const std::string value; | 619 const std::string value; |
619 const std::string domain; | 620 const std::string domain; |
620 const std::string path; | 621 const std::string path; |
621 const base::Time expiration_time; | 622 const base::Time expiration_time; |
622 bool secure; | 623 bool secure; |
623 bool http_only; | 624 bool http_only; |
624 bool same_site; | 625 CookieSameSite same_site; |
625 CookiePriority priority; | 626 CookiePriority priority; |
626 }; | 627 }; |
627 | 628 |
628 ACTION_P(QuitRunLoop, run_loop) { | 629 ACTION_P(QuitRunLoop, run_loop) { |
629 run_loop->Quit(); | 630 run_loop->Quit(); |
630 } | 631 } |
631 | 632 |
632 // TODO(erikwright): When the synchronous helpers 'GetCookies' etc. are removed, | 633 // TODO(erikwright): When the synchronous helpers 'GetCookies' etc. are removed, |
633 // rename these, removing the 'Action' suffix. | 634 // rename these, removing the 'Action' suffix. |
634 ACTION_P4(DeleteCookieAction, cookie_monster, url, name, callback) { | 635 ACTION_P4(DeleteCookieAction, cookie_monster, url, name, callback) { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
847 base::RunLoop loop; | 848 base::RunLoop loop; |
848 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce(QuitRunLoop(&loop)); | 849 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce(QuitRunLoop(&loop)); |
849 | 850 |
850 CompleteLoading(); | 851 CompleteLoading(); |
851 loop.Run(); | 852 loop.Run(); |
852 } | 853 } |
853 | 854 |
854 TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) { | 855 TEST_F(DeferredCookieTaskTest, DeferredSetAllCookies) { |
855 MockSetCookiesCallback set_cookies_callback; | 856 MockSetCookiesCallback set_cookies_callback; |
856 CookieList list; | 857 CookieList list; |
857 list.push_back(CanonicalCookie(http_www_google_.url(), "A", "B", | 858 list.push_back(CanonicalCookie( |
858 http_www_google_.domain(), "/", | 859 http_www_google_.url(), "A", "B", http_www_google_.domain(), "/", |
859 base::Time::Now(), base::Time(), base::Time(), | 860 base::Time::Now(), base::Time(), base::Time(), false, true, |
860 false, true, false, COOKIE_PRIORITY_DEFAULT)); | 861 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT)); |
mmenke
2016/03/11 18:08:31
You're using NONE here, but DEFAULT above. Is the
Mike West
2016/03/14 10:18:54
No. No good reason, here or elsewhere.
| |
861 list.push_back(CanonicalCookie(http_www_google_.url(), "C", "D", | 862 list.push_back(CanonicalCookie( |
862 http_www_google_.domain(), "/", | 863 http_www_google_.url(), "C", "D", http_www_google_.domain(), "/", |
863 base::Time::Now(), base::Time(), base::Time(), | 864 base::Time::Now(), base::Time(), base::Time(), false, true, |
864 false, true, false, COOKIE_PRIORITY_DEFAULT)); | 865 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT)); |
865 | 866 |
866 BeginWith( | 867 BeginWith( |
867 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); | 868 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); |
868 | 869 |
869 WaitForLoadCall(); | 870 WaitForLoadCall(); |
870 | 871 |
871 EXPECT_CALL(set_cookies_callback, Invoke(true)) | 872 EXPECT_CALL(set_cookies_callback, Invoke(true)) |
872 .WillOnce( | 873 .WillOnce( |
873 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); | 874 SetAllCookiesAction(&cookie_monster(), list, &set_cookies_callback)); |
874 base::RunLoop loop; | 875 base::RunLoop loop; |
(...skipping 27 matching lines...) Expand all Loading... | |
902 MockSetCookiesCallback set_cookies_callback; | 903 MockSetCookiesCallback set_cookies_callback; |
903 | 904 |
904 CookiesInputInfo cookie_info = {www_google_foo_.url(), | 905 CookiesInputInfo cookie_info = {www_google_foo_.url(), |
905 "A", | 906 "A", |
906 "B", | 907 "B", |
907 std::string(), | 908 std::string(), |
908 "/foo", | 909 "/foo", |
909 base::Time(), | 910 base::Time(), |
910 false, | 911 false, |
911 false, | 912 false, |
912 false, | 913 COOKIE_SAME_SITE_DEFAULT, |
913 COOKIE_PRIORITY_DEFAULT}; | 914 COOKIE_PRIORITY_DEFAULT}; |
914 BeginWithForDomainKey( | 915 BeginWithForDomainKey( |
915 http_www_google_.domain(), | 916 http_www_google_.domain(), |
916 SetCookieWithDetailsAction(&cookie_monster(), cookie_info, | 917 SetCookieWithDetailsAction(&cookie_monster(), cookie_info, |
917 &set_cookies_callback)); | 918 &set_cookies_callback)); |
918 | 919 |
919 WaitForLoadCall(); | 920 WaitForLoadCall(); |
920 | 921 |
921 CookiesInputInfo cookie_info_exp = {www_google_foo_.url(), | 922 CookiesInputInfo cookie_info_exp = {www_google_foo_.url(), |
922 "A", | 923 "A", |
923 "B", | 924 "B", |
924 std::string(), | 925 std::string(), |
925 "/foo", | 926 "/foo", |
926 base::Time(), | 927 base::Time(), |
927 false, | 928 false, |
928 false, | 929 false, |
929 false, | 930 COOKIE_SAME_SITE_DEFAULT, |
930 COOKIE_PRIORITY_DEFAULT}; | 931 COOKIE_PRIORITY_DEFAULT}; |
931 EXPECT_CALL(set_cookies_callback, Invoke(true)) | 932 EXPECT_CALL(set_cookies_callback, Invoke(true)) |
932 .WillOnce(SetCookieWithDetailsAction(&cookie_monster(), cookie_info_exp, | 933 .WillOnce(SetCookieWithDetailsAction(&cookie_monster(), cookie_info_exp, |
933 &set_cookies_callback)); | 934 &set_cookies_callback)); |
934 base::RunLoop loop; | 935 base::RunLoop loop; |
935 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce(QuitRunLoop(&loop)); | 936 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce(QuitRunLoop(&loop)); |
936 | 937 |
937 CompleteLoading(); | 938 CompleteLoading(); |
938 loop.Run(); | 939 loop.Run(); |
939 } | 940 } |
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1735 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1736 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), |
1736 "setCookieWithOptions1=A", options)); | 1737 "setCookieWithOptions1=A", options)); |
1737 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1738 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), |
1738 "setCookieWithOptions2=A", options)); | 1739 "setCookieWithOptions2=A", options)); |
1739 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), | 1740 EXPECT_TRUE(SetCookieWithOptions(cm.get(), http_www_google_.url(), |
1740 "setCookieWithOptions3=A", options)); | 1741 "setCookieWithOptions3=A", options)); |
1741 | 1742 |
1742 EXPECT_TRUE(SetCookieWithDetails( | 1743 EXPECT_TRUE(SetCookieWithDetails( |
1743 cm.get(), http_www_google_.url(), "setCookieWithDetails1", "A", | 1744 cm.get(), http_www_google_.url(), "setCookieWithDetails1", "A", |
1744 http_www_google_.Format(".%D"), "/", Time(), Time(), Time(), false, false, | 1745 http_www_google_.Format(".%D"), "/", Time(), Time(), Time(), false, false, |
1745 false, COOKIE_PRIORITY_DEFAULT)); | 1746 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
1746 EXPECT_TRUE(SetCookieWithDetails( | 1747 EXPECT_TRUE(SetCookieWithDetails( |
1747 cm.get(), http_www_google_.url(), "setCookieWithDetails2", "A", | 1748 cm.get(), http_www_google_.url(), "setCookieWithDetails2", "A", |
1748 http_www_google_.Format(".%D"), "/", Time(), Time(), Time(), false, false, | 1749 http_www_google_.Format(".%D"), "/", Time(), Time(), Time(), false, false, |
1749 false, COOKIE_PRIORITY_DEFAULT)); | 1750 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
1750 EXPECT_TRUE(SetCookieWithDetails( | 1751 EXPECT_TRUE(SetCookieWithDetails( |
1751 cm.get(), http_www_google_.url(), "setCookieWithDetails3", "A", | 1752 cm.get(), http_www_google_.url(), "setCookieWithDetails3", "A", |
1752 http_www_google_.Format(".%D"), "/", Time(), Time(), Time(), false, false, | 1753 http_www_google_.Format(".%D"), "/", Time(), Time(), Time(), false, false, |
1753 false, COOKIE_PRIORITY_DEFAULT)); | 1754 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
1754 | 1755 |
1755 // Now we check | 1756 // Now we check |
1756 CookieList cookie_list(GetAllCookies(cm.get())); | 1757 CookieList cookie_list(GetAllCookies(cm.get())); |
1757 EXPECT_EQ(9u, cookie_list.size()); | 1758 EXPECT_EQ(9u, cookie_list.size()); |
1758 typedef std::map<int64_t, CanonicalCookie> TimeCookieMap; | 1759 typedef std::map<int64_t, CanonicalCookie> TimeCookieMap; |
1759 TimeCookieMap check_map; | 1760 TimeCookieMap check_map; |
1760 for (CookieList::const_iterator it = cookie_list.begin(); | 1761 for (CookieList::const_iterator it = cookie_list.begin(); |
1761 it != cookie_list.end(); it++) { | 1762 it != cookie_list.end(); it++) { |
1762 const int64_t creation_date = it->CreationDate().ToInternalValue(); | 1763 const int64_t creation_date = it->CreationDate().ToInternalValue(); |
1763 TimeCookieMap::const_iterator existing_cookie_it( | 1764 TimeCookieMap::const_iterator existing_cookie_it( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1803 TEST_F(CookieMonsterTest, BackingStoreCommunication) { | 1804 TEST_F(CookieMonsterTest, BackingStoreCommunication) { |
1804 // Store details for cookies transforming through the backing store interface. | 1805 // Store details for cookies transforming through the backing store interface. |
1805 | 1806 |
1806 base::Time current(base::Time::Now()); | 1807 base::Time current(base::Time::Now()); |
1807 scoped_refptr<MockSimplePersistentCookieStore> store( | 1808 scoped_refptr<MockSimplePersistentCookieStore> store( |
1808 new MockSimplePersistentCookieStore); | 1809 new MockSimplePersistentCookieStore); |
1809 base::Time new_access_time; | 1810 base::Time new_access_time; |
1810 base::Time expires(base::Time::Now() + base::TimeDelta::FromSeconds(100)); | 1811 base::Time expires(base::Time::Now() + base::TimeDelta::FromSeconds(100)); |
1811 | 1812 |
1812 const CookiesInputInfo input_info[] = { | 1813 const CookiesInputInfo input_info[] = { |
1813 {GURL("http://a.b.google.com"), | 1814 {GURL("http://a.b.google.com"), "a", "1", "", "/path/to/cookie", expires, |
1814 "a", | 1815 false, false, COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT}, |
1815 "1", | 1816 {GURL("https://www.google.com"), "b", "2", ".google.com", |
1816 "", | 1817 "/path/from/cookie", expires + TimeDelta::FromSeconds(10), true, true, |
1817 "/path/to/cookie", | 1818 COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT}, |
1818 expires, | 1819 {GURL("https://google.com"), "c", "3", "", "/another/path/to/cookie", |
1819 false, | 1820 base::Time::Now() + base::TimeDelta::FromSeconds(100), true, false, |
1820 false, | 1821 COOKIE_SAME_SITE_STRICT, COOKIE_PRIORITY_DEFAULT}}; |
1821 false, | |
1822 COOKIE_PRIORITY_DEFAULT}, | |
1823 {GURL("https://www.google.com"), | |
1824 "b", | |
1825 "2", | |
1826 ".google.com", | |
1827 "/path/from/cookie", | |
1828 expires + TimeDelta::FromSeconds(10), | |
1829 true, | |
1830 true, | |
1831 false, | |
1832 COOKIE_PRIORITY_DEFAULT}, | |
1833 {GURL("https://google.com"), | |
1834 "c", | |
1835 "3", | |
1836 "", | |
1837 "/another/path/to/cookie", | |
1838 base::Time::Now() + base::TimeDelta::FromSeconds(100), | |
1839 true, | |
1840 false, | |
1841 true, | |
1842 COOKIE_PRIORITY_DEFAULT}}; | |
1843 const int INPUT_DELETE = 1; | 1822 const int INPUT_DELETE = 1; |
1844 | 1823 |
1845 // Create new cookies and flush them to the store. | 1824 // Create new cookies and flush them to the store. |
1846 { | 1825 { |
1847 scoped_ptr<CookieMonster> cmout(new CookieMonster(store.get(), nullptr)); | 1826 scoped_ptr<CookieMonster> cmout(new CookieMonster(store.get(), nullptr)); |
1848 for (const CookiesInputInfo* p = input_info; | 1827 for (const CookiesInputInfo* p = input_info; |
1849 p < &input_info[arraysize(input_info)]; p++) { | 1828 p < &input_info[arraysize(input_info)]; p++) { |
1850 EXPECT_TRUE(SetCookieWithDetails( | 1829 EXPECT_TRUE(SetCookieWithDetails( |
1851 cmout.get(), p->url, p->name, p->value, p->domain, p->path, | 1830 cmout.get(), p->url, p->name, p->value, p->domain, p->path, |
1852 base::Time(), p->expiration_time, base::Time(), p->secure, | 1831 base::Time(), p->expiration_time, base::Time(), p->secure, |
(...skipping 19 matching lines...) Expand all Loading... | |
1872 const CanonicalCookie* output = &cookies[output_index]; | 1851 const CanonicalCookie* output = &cookies[output_index]; |
1873 | 1852 |
1874 EXPECT_EQ(input->name, output->Name()); | 1853 EXPECT_EQ(input->name, output->Name()); |
1875 EXPECT_EQ(input->value, output->Value()); | 1854 EXPECT_EQ(input->value, output->Value()); |
1876 EXPECT_EQ(input->url.host(), output->Domain()); | 1855 EXPECT_EQ(input->url.host(), output->Domain()); |
1877 EXPECT_EQ(input->path, output->Path()); | 1856 EXPECT_EQ(input->path, output->Path()); |
1878 EXPECT_LE(current.ToInternalValue(), | 1857 EXPECT_LE(current.ToInternalValue(), |
1879 output->CreationDate().ToInternalValue()); | 1858 output->CreationDate().ToInternalValue()); |
1880 EXPECT_EQ(input->secure, output->IsSecure()); | 1859 EXPECT_EQ(input->secure, output->IsSecure()); |
1881 EXPECT_EQ(input->http_only, output->IsHttpOnly()); | 1860 EXPECT_EQ(input->http_only, output->IsHttpOnly()); |
1882 EXPECT_EQ(input->same_site, output->IsSameSite()); | 1861 EXPECT_EQ(input->same_site, output->SameSite()); |
1883 EXPECT_TRUE(output->IsPersistent()); | 1862 EXPECT_TRUE(output->IsPersistent()); |
1884 EXPECT_EQ(input->expiration_time.ToInternalValue(), | 1863 EXPECT_EQ(input->expiration_time.ToInternalValue(), |
1885 output->ExpiryDate().ToInternalValue()); | 1864 output->ExpiryDate().ToInternalValue()); |
1886 } | 1865 } |
1887 } | 1866 } |
1888 } | 1867 } |
1889 | 1868 |
1890 TEST_F(CookieMonsterTest, CookieListOrdering) { | 1869 TEST_F(CookieMonsterTest, CookieListOrdering) { |
1891 // Put a random set of cookies into a monster and make sure | 1870 // Put a random set of cookies into a monster and make sure |
1892 // they're returned in the right order. | 1871 // they're returned in the right order. |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2308 TEST_F(CookieMonsterTest, SetAllCookies) { | 2287 TEST_F(CookieMonsterTest, SetAllCookies) { |
2309 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2288 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
2310 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2289 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2311 cm->SetPersistSessionCookies(true); | 2290 cm->SetPersistSessionCookies(true); |
2312 | 2291 |
2313 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); | 2292 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); |
2314 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); | 2293 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); |
2315 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); | 2294 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); |
2316 | 2295 |
2317 CookieList list; | 2296 CookieList list; |
2318 list.push_back(CanonicalCookie(http_www_google_.url(), "A", "B", | 2297 list.push_back(CanonicalCookie( |
2319 http_www_google_.url().host(), "/", | 2298 http_www_google_.url(), "A", "B", http_www_google_.url().host(), "/", |
2320 base::Time::Now(), base::Time(), base::Time(), | 2299 base::Time::Now(), base::Time(), base::Time(), false, false, |
2321 false, false, false, COOKIE_PRIORITY_DEFAULT)); | 2300 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT)); |
2322 list.push_back(CanonicalCookie(http_www_google_.url(), "W", "X", | 2301 list.push_back(CanonicalCookie( |
2323 http_www_google_.url().host(), "/bar", | 2302 http_www_google_.url(), "W", "X", http_www_google_.url().host(), "/bar", |
2324 base::Time::Now(), base::Time(), base::Time(), | 2303 base::Time::Now(), base::Time(), base::Time(), false, false, |
2325 false, false, false, COOKIE_PRIORITY_DEFAULT)); | 2304 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT)); |
2326 list.push_back(CanonicalCookie(http_www_google_.url(), "Y", "Z", | 2305 list.push_back(CanonicalCookie( |
2327 http_www_google_.url().host(), "/", | 2306 http_www_google_.url(), "Y", "Z", http_www_google_.url().host(), "/", |
2328 base::Time::Now(), base::Time(), base::Time(), | 2307 base::Time::Now(), base::Time(), base::Time(), false, false, |
2329 false, false, false, COOKIE_PRIORITY_DEFAULT)); | 2308 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT)); |
2330 | 2309 |
2331 // SetAllCookies must not flush. | 2310 // SetAllCookies must not flush. |
2332 ASSERT_EQ(0, store->flush_count()); | 2311 ASSERT_EQ(0, store->flush_count()); |
2333 EXPECT_TRUE(SetAllCookies(cm.get(), list)); | 2312 EXPECT_TRUE(SetAllCookies(cm.get(), list)); |
2334 EXPECT_EQ(0, store->flush_count()); | 2313 EXPECT_EQ(0, store->flush_count()); |
2335 | 2314 |
2336 CookieList cookies = GetAllCookies(cm.get()); | 2315 CookieList cookies = GetAllCookies(cm.get()); |
2337 size_t expected_size = 3; // "A", "W" and "Y". "U" is gone. | 2316 size_t expected_size = 3; // "A", "W" and "Y". "U" is gone. |
2338 EXPECT_EQ(expected_size, cookies.size()); | 2317 EXPECT_EQ(expected_size, cookies.size()); |
2339 CookieList::iterator it = cookies.begin(); | 2318 CookieList::iterator it = cookies.begin(); |
(...skipping 13 matching lines...) Expand all Loading... | |
2353 } | 2332 } |
2354 | 2333 |
2355 TEST_F(CookieMonsterTest, ComputeCookieDiff) { | 2334 TEST_F(CookieMonsterTest, ComputeCookieDiff) { |
2356 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); | 2335 scoped_ptr<CookieMonster> cm(new CookieMonster(nullptr, nullptr)); |
2357 | 2336 |
2358 base::Time now = base::Time::Now(); | 2337 base::Time now = base::Time::Now(); |
2359 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); | 2338 base::Time creation_time = now - base::TimeDelta::FromSeconds(1); |
2360 | 2339 |
2361 CanonicalCookie cookie1(http_www_google_.url(), "A", "B", | 2340 CanonicalCookie cookie1(http_www_google_.url(), "A", "B", |
2362 http_www_google_.url().host(), "/", creation_time, | 2341 http_www_google_.url().host(), "/", creation_time, |
2363 base::Time(), base::Time(), false, false, false, | 2342 base::Time(), base::Time(), false, false, |
2364 COOKIE_PRIORITY_DEFAULT); | 2343 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT); |
mmenke
2016/03/11 18:08:31
And now you're back to none again. Should be cons
| |
2365 CanonicalCookie cookie2(http_www_google_.url(), "C", "D", | 2344 CanonicalCookie cookie2(http_www_google_.url(), "C", "D", |
2366 http_www_google_.url().host(), "/", creation_time, | 2345 http_www_google_.url().host(), "/", creation_time, |
2367 base::Time(), base::Time(), false, false, false, | 2346 base::Time(), base::Time(), false, false, |
2368 COOKIE_PRIORITY_DEFAULT); | 2347 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT); |
2369 CanonicalCookie cookie3(http_www_google_.url(), "E", "F", | 2348 CanonicalCookie cookie3(http_www_google_.url(), "E", "F", |
2370 http_www_google_.url().host(), "/", creation_time, | 2349 http_www_google_.url().host(), "/", creation_time, |
2371 base::Time(), base::Time(), false, false, false, | 2350 base::Time(), base::Time(), false, false, |
2372 COOKIE_PRIORITY_DEFAULT); | 2351 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT); |
2373 CanonicalCookie cookie4(http_www_google_.url(), "G", "H", | 2352 CanonicalCookie cookie4(http_www_google_.url(), "G", "H", |
2374 http_www_google_.url().host(), "/", creation_time, | 2353 http_www_google_.url().host(), "/", creation_time, |
2375 base::Time(), base::Time(), false, false, false, | 2354 base::Time(), base::Time(), false, false, |
2376 COOKIE_PRIORITY_DEFAULT); | 2355 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT); |
2377 CanonicalCookie cookie4_with_new_value( | 2356 CanonicalCookie cookie4_with_new_value( |
2378 http_www_google_.url(), "G", "iamnew", http_www_google_.url().host(), "/", | 2357 http_www_google_.url(), "G", "iamnew", http_www_google_.url().host(), "/", |
2379 creation_time, base::Time(), base::Time(), false, false, false, | 2358 creation_time, base::Time(), base::Time(), false, false, |
2380 COOKIE_PRIORITY_DEFAULT); | 2359 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT); |
2381 CanonicalCookie cookie5(http_www_google_.url(), "I", "J", | 2360 CanonicalCookie cookie5(http_www_google_.url(), "I", "J", |
2382 http_www_google_.url().host(), "/", creation_time, | 2361 http_www_google_.url().host(), "/", creation_time, |
2383 base::Time(), base::Time(), false, false, false, | 2362 base::Time(), base::Time(), false, false, |
2384 COOKIE_PRIORITY_DEFAULT); | 2363 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT); |
2385 CanonicalCookie cookie5_with_new_creation_time( | 2364 CanonicalCookie cookie5_with_new_creation_time( |
2386 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", now, | 2365 http_www_google_.url(), "I", "J", http_www_google_.url().host(), "/", now, |
2387 base::Time(), base::Time(), false, false, false, COOKIE_PRIORITY_DEFAULT); | 2366 base::Time(), base::Time(), false, false, COOKIE_SAME_SITE_NONE, |
2367 COOKIE_PRIORITY_DEFAULT); | |
2388 CanonicalCookie cookie6(http_www_google_.url(), "K", "L", | 2368 CanonicalCookie cookie6(http_www_google_.url(), "K", "L", |
2389 http_www_google_.url().host(), "/foo", creation_time, | 2369 http_www_google_.url().host(), "/foo", creation_time, |
2390 base::Time(), base::Time(), false, false, false, | 2370 base::Time(), base::Time(), false, false, |
2391 COOKIE_PRIORITY_DEFAULT); | 2371 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT); |
2392 CanonicalCookie cookie6_with_new_path( | 2372 CanonicalCookie cookie6_with_new_path( |
2393 http_www_google_.url(), "K", "L", http_www_google_.url().host(), "/bar", | 2373 http_www_google_.url(), "K", "L", http_www_google_.url().host(), "/bar", |
2394 creation_time, base::Time(), base::Time(), false, false, false, | 2374 creation_time, base::Time(), base::Time(), false, false, |
2395 COOKIE_PRIORITY_DEFAULT); | 2375 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT); |
2396 CanonicalCookie cookie7(http_www_google_.url(), "M", "N", | 2376 CanonicalCookie cookie7(http_www_google_.url(), "M", "N", |
2397 http_www_google_.url().host(), "/foo", creation_time, | 2377 http_www_google_.url().host(), "/foo", creation_time, |
2398 base::Time(), base::Time(), false, false, false, | 2378 base::Time(), base::Time(), false, false, |
2399 COOKIE_PRIORITY_DEFAULT); | 2379 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT); |
2400 CanonicalCookie cookie7_with_new_path( | 2380 CanonicalCookie cookie7_with_new_path( |
2401 http_www_google_.url(), "M", "N", http_www_google_.url().host(), "/bar", | 2381 http_www_google_.url(), "M", "N", http_www_google_.url().host(), "/bar", |
2402 creation_time, base::Time(), base::Time(), false, false, false, | 2382 creation_time, base::Time(), base::Time(), false, false, |
2403 COOKIE_PRIORITY_DEFAULT); | 2383 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT); |
2404 | 2384 |
2405 CookieList old_cookies; | 2385 CookieList old_cookies; |
2406 old_cookies.push_back(cookie1); | 2386 old_cookies.push_back(cookie1); |
2407 old_cookies.push_back(cookie2); | 2387 old_cookies.push_back(cookie2); |
2408 old_cookies.push_back(cookie4); | 2388 old_cookies.push_back(cookie4); |
2409 old_cookies.push_back(cookie5); | 2389 old_cookies.push_back(cookie5); |
2410 old_cookies.push_back(cookie6); | 2390 old_cookies.push_back(cookie6); |
2411 old_cookies.push_back(cookie7); | 2391 old_cookies.push_back(cookie7); |
2412 | 2392 |
2413 CookieList new_cookies; | 2393 CookieList new_cookies; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2487 // above. | 2467 // above. |
2488 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( | 2468 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( |
2489 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, | 2469 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, |
2490 base::Histogram::kUmaTargetedHistogramFlag); | 2470 base::Histogram::kUmaTargetedHistogramFlag); |
2491 | 2471 |
2492 scoped_ptr<base::HistogramSamples> samples1( | 2472 scoped_ptr<base::HistogramSamples> samples1( |
2493 expired_histogram->SnapshotSamples()); | 2473 expired_histogram->SnapshotSamples()); |
2494 ASSERT_TRUE(SetCookieWithDetails( | 2474 ASSERT_TRUE(SetCookieWithDetails( |
2495 cm.get(), GURL("http://fake.a.url"), "a", "b", "a.url", "/", base::Time(), | 2475 cm.get(), GURL("http://fake.a.url"), "a", "b", "a.url", "/", base::Time(), |
2496 base::Time::Now() + base::TimeDelta::FromMinutes(59), base::Time(), false, | 2476 base::Time::Now() + base::TimeDelta::FromMinutes(59), base::Time(), false, |
2497 false, false, COOKIE_PRIORITY_DEFAULT)); | 2477 false, COOKIE_SAME_SITE_DEFAULT, COOKIE_PRIORITY_DEFAULT)); |
2498 | 2478 |
2499 scoped_ptr<base::HistogramSamples> samples2( | 2479 scoped_ptr<base::HistogramSamples> samples2( |
2500 expired_histogram->SnapshotSamples()); | 2480 expired_histogram->SnapshotSamples()); |
2501 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); | 2481 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); |
2502 | 2482 |
2503 // kValidCookieLine creates a session cookie. | 2483 // kValidCookieLine creates a session cookie. |
2504 ASSERT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine)); | 2484 ASSERT_TRUE(SetCookie(cm.get(), http_www_google_.url(), kValidCookieLine)); |
2505 | 2485 |
2506 scoped_ptr<base::HistogramSamples> samples3( | 2486 scoped_ptr<base::HistogramSamples> samples3( |
2507 expired_histogram->SnapshotSamples()); | 2487 expired_histogram->SnapshotSamples()); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2609 std::vector<CanonicalCookie*> initial_cookies; | 2589 std::vector<CanonicalCookie*> initial_cookies; |
2610 | 2590 |
2611 AddCookieToList(domain, "foo=bar; path=" + path, now1, &initial_cookies); | 2591 AddCookieToList(domain, "foo=bar; path=" + path, now1, &initial_cookies); |
2612 | 2592 |
2613 // We have to manually build this cookie because it contains a control | 2593 // We have to manually build this cookie because it contains a control |
2614 // character, and our cookie line parser rejects control characters. | 2594 // character, and our cookie line parser rejects control characters. |
2615 CanonicalCookie* cc = | 2595 CanonicalCookie* cc = |
2616 new CanonicalCookie(url, "baz", | 2596 new CanonicalCookie(url, "baz", |
2617 "\x05" | 2597 "\x05" |
2618 "boo", | 2598 "boo", |
2619 domain, path, now2, later, now2, false, false, false, | 2599 domain, path, now2, later, now2, false, false, |
2620 COOKIE_PRIORITY_DEFAULT); | 2600 COOKIE_SAME_SITE_NONE, COOKIE_PRIORITY_DEFAULT); |
2621 initial_cookies.push_back(cc); | 2601 initial_cookies.push_back(cc); |
2622 | 2602 |
2623 AddCookieToList(domain, "hello=world; path=" + path, now3, &initial_cookies); | 2603 AddCookieToList(domain, "hello=world; path=" + path, now3, &initial_cookies); |
2624 | 2604 |
2625 // Inject our initial cookies into the mock PersistentCookieStore. | 2605 // Inject our initial cookies into the mock PersistentCookieStore. |
2626 store->SetLoadExpectation(true, initial_cookies); | 2606 store->SetLoadExpectation(true, initial_cookies); |
2627 | 2607 |
2628 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2608 scoped_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
2629 | 2609 |
2630 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); | 2610 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3206 monster()->AddCallbackForCookie( | 3186 monster()->AddCallbackForCookie( |
3207 test_url_, "abc", | 3187 test_url_, "abc", |
3208 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3188 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
3209 SetCookie(monster(), test_url_, "abc=def"); | 3189 SetCookie(monster(), test_url_, "abc=def"); |
3210 base::MessageLoop::current()->RunUntilIdle(); | 3190 base::MessageLoop::current()->RunUntilIdle(); |
3211 EXPECT_EQ(1U, cookies0.size()); | 3191 EXPECT_EQ(1U, cookies0.size()); |
3212 EXPECT_EQ(1U, cookies0.size()); | 3192 EXPECT_EQ(1U, cookies0.size()); |
3213 } | 3193 } |
3214 | 3194 |
3215 } // namespace net | 3195 } // namespace net |
OLD | NEW |