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

Side by Side Diff: net/cookies/cookie_monster_unittest.cc

Issue 2383393002: Remove stl_util's deletion functions from net/cookies/ and net/extras/. (Closed)
Patch Set: removing Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/cookies/cookie_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 956 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 load_run_loop_.Run(); 967 load_run_loop_.Run();
968 968
969 // Verify that PeristentStore::Load was called. 969 // Verify that PeristentStore::Load was called.
970 testing::Mock::VerifyAndClear(persistent_store_.get()); 970 testing::Mock::VerifyAndClear(persistent_store_.get());
971 } 971 }
972 972
973 // Invokes the PersistentCookieStore::LoadCookiesForKey completion callbacks 973 // Invokes the PersistentCookieStore::LoadCookiesForKey completion callbacks
974 // and PersistentCookieStore::Load completion callback. 974 // and PersistentCookieStore::Load completion callback.
975 void CompleteLoading() { 975 void CompleteLoading() {
976 while (!loaded_for_key_callbacks_.empty()) { 976 while (!loaded_for_key_callbacks_.empty()) {
977 loaded_for_key_callbacks_.front().Run(loaded_cookies_); 977 loaded_for_key_callbacks_.front().Run(std::move(loaded_cookies_));
978 loaded_cookies_.clear(); 978 loaded_cookies_.clear();
979 loaded_for_key_callbacks_.pop(); 979 loaded_for_key_callbacks_.pop();
980 } 980 }
981 loaded_callback_.Run(loaded_cookies_); 981 loaded_callback_.Run(std::move(loaded_cookies_));
982 } 982 }
983 983
984 // Performs the provided action, expecting it to cause a call to 984 // Performs the provided action, expecting it to cause a call to
985 // PersistentCookieStore::Load. Call WaitForLoadCall to verify the load call 985 // PersistentCookieStore::Load. Call WaitForLoadCall to verify the load call
986 // is received. 986 // is received.
987 void BeginWith(testing::Action<void(void)> action) { 987 void BeginWith(testing::Action<void(void)> action) {
988 EXPECT_CALL(*this, Begin()).WillOnce(action); 988 EXPECT_CALL(*this, Begin()).WillOnce(action);
989 ExpectLoadCall(); 989 ExpectLoadCall();
990 Begin(); 990 Begin();
991 } 991 }
(...skipping 28 matching lines...) Expand all
1020 MOCK_METHOD0(Begin, void(void)); 1020 MOCK_METHOD0(Begin, void(void));
1021 1021
1022 // Returns the CookieMonster instance under test. 1022 // Returns the CookieMonster instance under test.
1023 CookieMonster& cookie_monster() { return *cookie_monster_.get(); } 1023 CookieMonster& cookie_monster() { return *cookie_monster_.get(); }
1024 1024
1025 private: 1025 private:
1026 // Declares that mock expectations in this test suite are strictly ordered. 1026 // Declares that mock expectations in this test suite are strictly ordered.
1027 testing::InSequence in_sequence_; 1027 testing::InSequence in_sequence_;
1028 // Holds cookies to be returned from PersistentCookieStore::Load or 1028 // Holds cookies to be returned from PersistentCookieStore::Load or
1029 // PersistentCookieStore::LoadCookiesForKey. 1029 // PersistentCookieStore::LoadCookiesForKey.
1030 std::vector<CanonicalCookie*> loaded_cookies_; 1030 std::vector<std::unique_ptr<CanonicalCookie>> loaded_cookies_;
1031 // Stores the callback passed from the CookieMonster to the 1031 // Stores the callback passed from the CookieMonster to the
1032 // PersistentCookieStore::Load 1032 // PersistentCookieStore::Load
1033 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; 1033 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_;
1034 // Stores the callback passed from the CookieMonster to the 1034 // Stores the callback passed from the CookieMonster to the
1035 // PersistentCookieStore::LoadCookiesForKey 1035 // PersistentCookieStore::LoadCookiesForKey
1036 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback> 1036 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback>
1037 loaded_for_key_callbacks_; 1037 loaded_for_key_callbacks_;
1038 // base::RunLoop used to wait for PersistentCookieStore::Load to be called. 1038 // base::RunLoop used to wait for PersistentCookieStore::Load to be called.
1039 base::RunLoop load_run_loop_; 1039 base::RunLoop load_run_loop_;
1040 // Indicates whether ExpectLoadCall() has been called. 1040 // Indicates whether ExpectLoadCall() has been called.
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 &cookie_monster(), base::Time(), base::Time::Now(), predicate, 1303 &cookie_monster(), base::Time(), base::Time::Now(), predicate,
1304 &delete_callback)); 1304 &delete_callback));
1305 base::RunLoop loop; 1305 base::RunLoop loop;
1306 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(QuitRunLoop(&loop)); 1306 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce(QuitRunLoop(&loop));
1307 1307
1308 CompleteLoading(); 1308 CompleteLoading();
1309 loop.Run(); 1309 loop.Run();
1310 } 1310 }
1311 1311
1312 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { 1312 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) {
1313 std::vector<CanonicalCookie*> cookies; 1313 std::vector<std::unique_ptr<CanonicalCookie>> cookies;
1314 std::unique_ptr<CanonicalCookie> cookie = BuildCanonicalCookie( 1314 std::unique_ptr<CanonicalCookie> cookie = BuildCanonicalCookie(
1315 http_www_google_.url(), "X=1; path=/", base::Time::Now()); 1315 http_www_google_.url(), "X=1; path=/", base::Time::Now());
1316 1316
1317 MockDeleteCallback delete_cookie_callback; 1317 MockDeleteCallback delete_cookie_callback;
1318 1318
1319 BeginWith(DeleteCanonicalCookieAction(&cookie_monster(), *cookie, 1319 BeginWith(DeleteCanonicalCookieAction(&cookie_monster(), *cookie,
1320 &delete_cookie_callback)); 1320 &delete_cookie_callback));
1321 1321
1322 WaitForLoadCall(); 1322 WaitForLoadCall();
1323 1323
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1782 // 1782 //
1783 // This is a regression test for: http://crbug.com/17855. 1783 // This is a regression test for: http://crbug.com/17855.
1784 TEST_F(CookieMonsterTest, DontImportDuplicateCookies) { 1784 TEST_F(CookieMonsterTest, DontImportDuplicateCookies) {
1785 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); 1785 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
1786 1786
1787 // We will fill some initial cookies into the PersistentCookieStore, 1787 // We will fill some initial cookies into the PersistentCookieStore,
1788 // to simulate a database with 4 duplicates. Note that we need to 1788 // to simulate a database with 4 duplicates. Note that we need to
1789 // be careful not to have any duplicate creation times at all (as it's a 1789 // be careful not to have any duplicate creation times at all (as it's a
1790 // violation of a CookieMonster invariant) even if Time::Now() doesn't 1790 // violation of a CookieMonster invariant) even if Time::Now() doesn't
1791 // move between calls. 1791 // move between calls.
1792 std::vector<CanonicalCookie*> initial_cookies; 1792 std::vector<std::unique_ptr<CanonicalCookie>> initial_cookies;
1793 1793
1794 // Insert 4 cookies with name "X" on path "/", with varying creation 1794 // Insert 4 cookies with name "X" on path "/", with varying creation
1795 // dates. We expect only the most recent one to be preserved following 1795 // dates. We expect only the most recent one to be preserved following
1796 // the import. 1796 // the import.
1797 1797
1798 AddCookieToList(GURL("http://www.google.com"), 1798 AddCookieToList(GURL("http://www.google.com"),
1799 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 1799 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
1800 Time::Now() + TimeDelta::FromDays(3), &initial_cookies); 1800 Time::Now() + TimeDelta::FromDays(3), &initial_cookies);
1801 1801
1802 AddCookieToList(GURL("http://www.google.com"), 1802 AddCookieToList(GURL("http://www.google.com"),
(...skipping 20 matching lines...) Expand all
1823 AddCookieToList(GURL("http://www.google.com"), 1823 AddCookieToList(GURL("http://www.google.com"),
1824 "X=a2; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", 1824 "X=a2; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT",
1825 Time::Now() + TimeDelta::FromDays(2), &initial_cookies); 1825 Time::Now() + TimeDelta::FromDays(2), &initial_cookies);
1826 1826
1827 // Insert 1 cookie with name "Y" on path "/". 1827 // Insert 1 cookie with name "Y" on path "/".
1828 AddCookieToList(GURL("http://www.google.com"), 1828 AddCookieToList(GURL("http://www.google.com"),
1829 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", 1829 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
1830 Time::Now() + TimeDelta::FromDays(10), &initial_cookies); 1830 Time::Now() + TimeDelta::FromDays(10), &initial_cookies);
1831 1831
1832 // Inject our initial cookies into the mock PersistentCookieStore. 1832 // Inject our initial cookies into the mock PersistentCookieStore.
1833 store->SetLoadExpectation(true, initial_cookies); 1833 store->SetLoadExpectation(true, std::move(initial_cookies));
1834 1834
1835 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); 1835 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr));
1836 1836
1837 // Verify that duplicates were not imported for path "/". 1837 // Verify that duplicates were not imported for path "/".
1838 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4). 1838 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4).
1839 EXPECT_EQ("X=3; Y=a", GetCookies(cm.get(), GURL("http://www.google.com/"))); 1839 EXPECT_EQ("X=3; Y=a", GetCookies(cm.get(), GURL("http://www.google.com/")));
1840 1840
1841 // Verify that same-named cookie on a different path ("/x2") didn't get 1841 // Verify that same-named cookie on a different path ("/x2") didn't get
1842 // messed up. 1842 // messed up.
1843 EXPECT_EQ("X=a1; X=3; Y=a", 1843 EXPECT_EQ("X=a1; X=3; Y=a",
(...skipping 15 matching lines...) Expand all
1859 TEST_F(CookieMonsterTest, DontImportDuplicateCreationTimes) { 1859 TEST_F(CookieMonsterTest, DontImportDuplicateCreationTimes) {
1860 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); 1860 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
1861 1861
1862 Time now(Time::Now()); 1862 Time now(Time::Now());
1863 Time earlier(now - TimeDelta::FromDays(1)); 1863 Time earlier(now - TimeDelta::FromDays(1));
1864 1864
1865 // Insert 8 cookies, four with the current time as creation times, and 1865 // Insert 8 cookies, four with the current time as creation times, and
1866 // four with the earlier time as creation times. We should only get 1866 // four with the earlier time as creation times. We should only get
1867 // two cookies remaining, but which two (other than that there should 1867 // two cookies remaining, but which two (other than that there should
1868 // be one from each set) will be random. 1868 // be one from each set) will be random.
1869 std::vector<CanonicalCookie*> initial_cookies; 1869 std::vector<std::unique_ptr<CanonicalCookie>> initial_cookies;
1870 AddCookieToList(GURL("http://www.google.com"), "X=1; path=/", now, 1870 AddCookieToList(GURL("http://www.google.com"), "X=1; path=/", now,
1871 &initial_cookies); 1871 &initial_cookies);
1872 AddCookieToList(GURL("http://www.google.com"), "X=2; path=/", now, 1872 AddCookieToList(GURL("http://www.google.com"), "X=2; path=/", now,
1873 &initial_cookies); 1873 &initial_cookies);
1874 AddCookieToList(GURL("http://www.google.com"), "X=3; path=/", now, 1874 AddCookieToList(GURL("http://www.google.com"), "X=3; path=/", now,
1875 &initial_cookies); 1875 &initial_cookies);
1876 AddCookieToList(GURL("http://www.google.com"), "X=4; path=/", now, 1876 AddCookieToList(GURL("http://www.google.com"), "X=4; path=/", now,
1877 &initial_cookies); 1877 &initial_cookies);
1878 1878
1879 AddCookieToList(GURL("http://www.google.com"), "Y=1; path=/", earlier, 1879 AddCookieToList(GURL("http://www.google.com"), "Y=1; path=/", earlier,
1880 &initial_cookies); 1880 &initial_cookies);
1881 AddCookieToList(GURL("http://www.google.com"), "Y=2; path=/", earlier, 1881 AddCookieToList(GURL("http://www.google.com"), "Y=2; path=/", earlier,
1882 &initial_cookies); 1882 &initial_cookies);
1883 AddCookieToList(GURL("http://www.google.com"), "Y=3; path=/", earlier, 1883 AddCookieToList(GURL("http://www.google.com"), "Y=3; path=/", earlier,
1884 &initial_cookies); 1884 &initial_cookies);
1885 AddCookieToList(GURL("http://www.google.com"), "Y=4; path=/", earlier, 1885 AddCookieToList(GURL("http://www.google.com"), "Y=4; path=/", earlier,
1886 &initial_cookies); 1886 &initial_cookies);
1887 1887
1888 // Inject our initial cookies into the mock PersistentCookieStore. 1888 // Inject our initial cookies into the mock PersistentCookieStore.
1889 store->SetLoadExpectation(true, initial_cookies); 1889 store->SetLoadExpectation(true, std::move(initial_cookies));
1890 1890
1891 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); 1891 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr));
1892 1892
1893 CookieList list(GetAllCookies(cm.get())); 1893 CookieList list(GetAllCookies(cm.get()));
1894 EXPECT_EQ(2U, list.size()); 1894 EXPECT_EQ(2U, list.size());
1895 // Confirm that we have one of each. 1895 // Confirm that we have one of each.
1896 std::string name1(list[0].Name()); 1896 std::string name1(list[0].Name());
1897 std::string name2(list[1].Name()); 1897 std::string name2(list[1].Name());
1898 EXPECT_TRUE(name1 == "X" || name2 == "X"); 1898 EXPECT_TRUE(name1 == "X" || name2 == "X");
1899 EXPECT_TRUE(name1 == "Y" || name2 == "Y"); 1899 EXPECT_TRUE(name1 == "Y" || name2 == "Y");
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
2294 base::Bind(&GetCookieListCallback::Run, 2294 base::Bind(&GetCookieListCallback::Run,
2295 base::Unretained(&get_cookie_list_callback1))); 2295 base::Unretained(&get_cookie_list_callback1)));
2296 2296
2297 // Two load events should have been queued. 2297 // Two load events should have been queued.
2298 ASSERT_EQ(2u, store->commands().size()); 2298 ASSERT_EQ(2u, store->commands().size());
2299 ASSERT_EQ(CookieStoreCommand::LOAD, store->commands()[0].type); 2299 ASSERT_EQ(CookieStoreCommand::LOAD, store->commands()[0].type);
2300 ASSERT_EQ(CookieStoreCommand::LOAD_COOKIES_FOR_KEY, 2300 ASSERT_EQ(CookieStoreCommand::LOAD_COOKIES_FOR_KEY,
2301 store->commands()[1].type); 2301 store->commands()[1].type);
2302 2302
2303 // The main load completes first (With no cookies). 2303 // The main load completes first (With no cookies).
2304 store->commands()[0].loaded_callback.Run(std::vector<CanonicalCookie*>()); 2304 store->commands()[0].loaded_callback.Run(
2305 std::vector<std::unique_ptr<CanonicalCookie>>());
2305 2306
2306 // The tasks should run in order, and the get should see the cookies. 2307 // The tasks should run in order, and the get should see the cookies.
2307 2308
2308 set_cookie_callback.WaitUntilDone(); 2309 set_cookie_callback.WaitUntilDone();
2309 EXPECT_TRUE(set_cookie_callback.result()); 2310 EXPECT_TRUE(set_cookie_callback.result());
2310 2311
2311 get_cookie_list_callback1.WaitUntilDone(); 2312 get_cookie_list_callback1.WaitUntilDone();
2312 EXPECT_EQ(1u, get_cookie_list_callback1.cookies().size()); 2313 EXPECT_EQ(1u, get_cookie_list_callback1.cookies().size());
2313 2314
2314 // The loaded for key event completes late, with not cookies (Since they 2315 // The loaded for key event completes late, with not cookies (Since they
2315 // were already loaded). 2316 // were already loaded).
2316 store->commands()[1].loaded_callback.Run(std::vector<CanonicalCookie*>()); 2317 store->commands()[1].loaded_callback.Run(
2318 std::vector<std::unique_ptr<CanonicalCookie>>());
2317 2319
2318 // The just set cookie should still be in the store. 2320 // The just set cookie should still be in the store.
2319 GetCookieListCallback get_cookie_list_callback2; 2321 GetCookieListCallback get_cookie_list_callback2;
2320 cm->GetAllCookiesAsync( 2322 cm->GetAllCookiesAsync(
2321 base::Bind(&GetCookieListCallback::Run, 2323 base::Bind(&GetCookieListCallback::Run,
2322 base::Unretained(&get_cookie_list_callback2))); 2324 base::Unretained(&get_cookie_list_callback2)));
2323 get_cookie_list_callback2.WaitUntilDone(); 2325 get_cookie_list_callback2.WaitUntilDone();
2324 EXPECT_EQ(1u, get_cookie_list_callback2.cookies().size()); 2326 EXPECT_EQ(1u, get_cookie_list_callback2.cookies().size());
2325 } 2327 }
2326 2328
(...skipping 14 matching lines...) Expand all
2341 GetCookieListCallback get_cookie_list_callback; 2343 GetCookieListCallback get_cookie_list_callback;
2342 cm->GetCookieListWithOptionsAsync( 2344 cm->GetCookieListWithOptionsAsync(
2343 kUrl, CookieOptions(), 2345 kUrl, CookieOptions(),
2344 base::Bind(&GetCookieListCallback::Run, 2346 base::Bind(&GetCookieListCallback::Run,
2345 base::Unretained(&get_cookie_list_callback))); 2347 base::Unretained(&get_cookie_list_callback)));
2346 2348
2347 // Only the main load should have been queued. 2349 // Only the main load should have been queued.
2348 ASSERT_EQ(1u, store->commands().size()); 2350 ASSERT_EQ(1u, store->commands().size());
2349 ASSERT_EQ(CookieStoreCommand::LOAD, store->commands()[0].type); 2351 ASSERT_EQ(CookieStoreCommand::LOAD, store->commands()[0].type);
2350 2352
2351 std::vector<CanonicalCookie*> cookies; 2353 std::vector<std::unique_ptr<CanonicalCookie>> cookies;
2352 // When passed to the CookieMonster, it takes ownership of the pointed to 2354 // When passed to the CookieMonster, it takes ownership of the pointed to
2353 // cookies. 2355 // cookies.
2354 cookies.push_back( 2356 cookies.push_back(
2355 CanonicalCookie::Create(kUrl, "a=b", base::Time(), CookieOptions()) 2357 CanonicalCookie::Create(kUrl, "a=b", base::Time(), CookieOptions()));
2356 .release());
2357 ASSERT_TRUE(cookies[0]); 2358 ASSERT_TRUE(cookies[0]);
2358 store->commands()[0].loaded_callback.Run(cookies); 2359 store->commands()[0].loaded_callback.Run(std::move(cookies));
2359 2360
2360 delete_callback.WaitUntilDone(); 2361 delete_callback.WaitUntilDone();
2361 EXPECT_EQ(1, delete_callback.result()); 2362 EXPECT_EQ(1, delete_callback.result());
2362 2363
2363 get_cookie_list_callback.WaitUntilDone(); 2364 get_cookie_list_callback.WaitUntilDone();
2364 EXPECT_EQ(0u, get_cookie_list_callback.cookies().size()); 2365 EXPECT_EQ(0u, get_cookie_list_callback.cookies().size());
2365 } 2366 }
2366 2367
2367 // Tests that a set cookie call sandwiched between two get all cookies, all 2368 // Tests that a set cookie call sandwiched between two get all cookies, all
2368 // before load completes, affects the first but not the second. The set should 2369 // before load completes, affects the first but not the second. The set should
(...skipping 20 matching lines...) Expand all
2389 GetCookieListCallback get_cookie_list_callback2; 2390 GetCookieListCallback get_cookie_list_callback2;
2390 cm->GetAllCookiesAsync( 2391 cm->GetAllCookiesAsync(
2391 base::Bind(&GetCookieListCallback::Run, 2392 base::Bind(&GetCookieListCallback::Run,
2392 base::Unretained(&get_cookie_list_callback2))); 2393 base::Unretained(&get_cookie_list_callback2)));
2393 2394
2394 // Only the main load should have been queued. 2395 // Only the main load should have been queued.
2395 ASSERT_EQ(1u, store->commands().size()); 2396 ASSERT_EQ(1u, store->commands().size());
2396 ASSERT_EQ(CookieStoreCommand::LOAD, store->commands()[0].type); 2397 ASSERT_EQ(CookieStoreCommand::LOAD, store->commands()[0].type);
2397 2398
2398 // The load completes (With no cookies). 2399 // The load completes (With no cookies).
2399 store->commands()[0].loaded_callback.Run(std::vector<CanonicalCookie*>()); 2400 store->commands()[0].loaded_callback.Run(
2401 std::vector<std::unique_ptr<CanonicalCookie>>());
2400 2402
2401 get_cookie_list_callback1.WaitUntilDone(); 2403 get_cookie_list_callback1.WaitUntilDone();
2402 EXPECT_EQ(0u, get_cookie_list_callback1.cookies().size()); 2404 EXPECT_EQ(0u, get_cookie_list_callback1.cookies().size());
2403 2405
2404 set_cookie_callback.WaitUntilDone(); 2406 set_cookie_callback.WaitUntilDone();
2405 EXPECT_TRUE(set_cookie_callback.result()); 2407 EXPECT_TRUE(set_cookie_callback.result());
2406 2408
2407 get_cookie_list_callback2.WaitUntilDone(); 2409 get_cookie_list_callback2.WaitUntilDone();
2408 EXPECT_EQ(1u, get_cookie_list_callback2.cookies().size()); 2410 EXPECT_EQ(1u, get_cookie_list_callback2.cookies().size());
2409 } 2411 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2441 GetCookieListCallback get_cookie_list_callback1; 2443 GetCookieListCallback get_cookie_list_callback1;
2442 cm->GetAllCookiesAsync( 2444 cm->GetAllCookiesAsync(
2443 base::Bind(&GetCookieListCallback::Run, 2445 base::Bind(&GetCookieListCallback::Run,
2444 base::Unretained(&get_cookie_list_callback1))); 2446 base::Unretained(&get_cookie_list_callback1)));
2445 2447
2446 // Only the main load should have been queued. 2448 // Only the main load should have been queued.
2447 ASSERT_EQ(1u, store->commands().size()); 2449 ASSERT_EQ(1u, store->commands().size());
2448 ASSERT_EQ(CookieStoreCommand::LOAD, store->commands()[0].type); 2450 ASSERT_EQ(CookieStoreCommand::LOAD, store->commands()[0].type);
2449 2451
2450 // The load completes. 2452 // The load completes.
2451 store->commands()[0].loaded_callback.Run(std::vector<CanonicalCookie*>()); 2453 store->commands()[0].loaded_callback.Run(
2454 std::vector<std::unique_ptr<CanonicalCookie>>());
2452 2455
2453 // The get cookies call should see no cookies set. 2456 // The get cookies call should see no cookies set.
2454 get_cookie_list_callback1.WaitUntilDone(); 2457 get_cookie_list_callback1.WaitUntilDone();
2455 EXPECT_EQ(0u, get_cookie_list_callback1.cookies().size()); 2458 EXPECT_EQ(0u, get_cookie_list_callback1.cookies().size());
2456 2459
2457 set_cookie_callback.WaitUntilDone(); 2460 set_cookie_callback.WaitUntilDone();
2458 EXPECT_TRUE(set_cookie_callback.result()); 2461 EXPECT_TRUE(set_cookie_callback.result());
2459 2462
2460 // A subsequent get cookies call should see the new cookie. 2463 // A subsequent get cookies call should see the new cookie.
2461 GetCookieListCallback get_cookie_list_callback2; 2464 GetCookieListCallback get_cookie_list_callback2;
2462 cm->GetAllCookiesAsync( 2465 cm->GetAllCookiesAsync(
2463 base::Bind(&GetCookieListCallback::Run, 2466 base::Bind(&GetCookieListCallback::Run,
2464 base::Unretained(&get_cookie_list_callback2))); 2467 base::Unretained(&get_cookie_list_callback2)));
2465 get_cookie_list_callback2.WaitUntilDone(); 2468 get_cookie_list_callback2.WaitUntilDone();
2466 EXPECT_EQ(1u, get_cookie_list_callback2.cookies().size()); 2469 EXPECT_EQ(1u, get_cookie_list_callback2.cookies().size());
2467 } 2470 }
2468 2471
2469 namespace { 2472 namespace {
2470 2473
2471 // Mock PersistentCookieStore that keeps track of the number of Flush() calls. 2474 // Mock PersistentCookieStore that keeps track of the number of Flush() calls.
2472 class FlushablePersistentStore : public CookieMonster::PersistentCookieStore { 2475 class FlushablePersistentStore : public CookieMonster::PersistentCookieStore {
2473 public: 2476 public:
2474 FlushablePersistentStore() : flush_count_(0) {} 2477 FlushablePersistentStore() : flush_count_(0) {}
2475 2478
2476 void Load(const LoadedCallback& loaded_callback) override { 2479 void Load(const LoadedCallback& loaded_callback) override {
2477 std::vector<CanonicalCookie*> out_cookies; 2480 std::vector<std::unique_ptr<CanonicalCookie>> out_cookies;
2478 base::ThreadTaskRunnerHandle::Get()->PostTask( 2481 base::ThreadTaskRunnerHandle::Get()->PostTask(
2479 FROM_HERE, 2482 FROM_HERE, base::Bind(loaded_callback, base::Passed(&out_cookies)));
2480 base::Bind(&LoadedCallbackTask::Run,
2481 new LoadedCallbackTask(loaded_callback, out_cookies)));
2482 } 2483 }
2483 2484
2484 void LoadCookiesForKey(const std::string& key, 2485 void LoadCookiesForKey(const std::string& key,
2485 const LoadedCallback& loaded_callback) override { 2486 const LoadedCallback& loaded_callback) override {
2486 Load(loaded_callback); 2487 Load(loaded_callback);
2487 } 2488 }
2488 2489
2489 void AddCookie(const CanonicalCookie&) override {} 2490 void AddCookie(const CanonicalCookie&) override {}
2490 void UpdateCookieAccessTime(const CanonicalCookie&) override {} 2491 void UpdateCookieAccessTime(const CanonicalCookie&) override {}
2491 void DeleteCookie(const CanonicalCookie&) override {} 2492 void DeleteCookie(const CanonicalCookie&) override {}
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
2874 const Time now1(Time::Now()); 2875 const Time now1(Time::Now());
2875 const Time now2(Time::Now() + TimeDelta::FromSeconds(1)); 2876 const Time now2(Time::Now() + TimeDelta::FromSeconds(1));
2876 const Time now3(Time::Now() + TimeDelta::FromSeconds(2)); 2877 const Time now3(Time::Now() + TimeDelta::FromSeconds(2));
2877 const Time later(now1 + TimeDelta::FromDays(1)); 2878 const Time later(now1 + TimeDelta::FromDays(1));
2878 const GURL url("http://host/path"); 2879 const GURL url("http://host/path");
2879 const std::string domain("host"); 2880 const std::string domain("host");
2880 const std::string path("/path"); 2881 const std::string path("/path");
2881 2882
2882 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); 2883 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore);
2883 2884
2884 std::vector<CanonicalCookie*> initial_cookies; 2885 std::vector<std::unique_ptr<CanonicalCookie>> initial_cookies;
2885 2886
2886 AddCookieToList(url, "foo=bar; path=" + path, now1, &initial_cookies); 2887 AddCookieToList(url, "foo=bar; path=" + path, now1, &initial_cookies);
2887 2888
2888 // We have to manually build this cookie because it contains a control 2889 // We have to manually build this cookie because it contains a control
2889 // character, and our cookie line parser rejects control characters. 2890 // character, and our cookie line parser rejects control characters.
2890 std::unique_ptr<CanonicalCookie> cc = CanonicalCookie::Create( 2891 std::unique_ptr<CanonicalCookie> cc = CanonicalCookie::Create(
2891 url, "baz", 2892 url, "baz",
2892 "\x05" 2893 "\x05"
2893 "boo", 2894 "boo",
2894 domain, path, now2, later, false, false, CookieSameSite::DEFAULT_MODE, 2895 domain, path, now2, later, false, false, CookieSameSite::DEFAULT_MODE,
2895 false, COOKIE_PRIORITY_DEFAULT); 2896 false, COOKIE_PRIORITY_DEFAULT);
2896 initial_cookies.push_back(cc.release()); 2897 initial_cookies.push_back(std::move(cc));
2897 2898
2898 AddCookieToList(url, "hello=world; path=" + path, now3, &initial_cookies); 2899 AddCookieToList(url, "hello=world; path=" + path, now3, &initial_cookies);
2899 2900
2900 // Inject our initial cookies into the mock PersistentCookieStore. 2901 // Inject our initial cookies into the mock PersistentCookieStore.
2901 store->SetLoadExpectation(true, initial_cookies); 2902 store->SetLoadExpectation(true, std::move(initial_cookies));
2902 2903
2903 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); 2904 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr));
2904 2905
2905 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); 2906 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url));
2906 } 2907 }
2907 2908
2908 // Test that cookie source schemes are histogrammed correctly. 2909 // Test that cookie source schemes are histogrammed correctly.
2909 TEST_F(CookieMonsterTest, CookieSourceHistogram) { 2910 TEST_F(CookieMonsterTest, CookieSourceHistogram) {
2910 base::HistogramTester histograms; 2911 base::HistogramTester histograms;
2911 const std::string cookie_source_histogram = "Cookie.CookieSourceScheme"; 2912 const std::string cookie_source_histogram = "Cookie.CookieSourceScheme";
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after
3492 monster()->AddCallbackForCookie( 3493 monster()->AddCallbackForCookie(
3493 test_url_, "abc", 3494 test_url_, "abc",
3494 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); 3495 base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
3495 SetCookie(monster(), test_url_, "abc=def"); 3496 SetCookie(monster(), test_url_, "abc=def");
3496 base::RunLoop().RunUntilIdle(); 3497 base::RunLoop().RunUntilIdle();
3497 EXPECT_EQ(1U, cookies0.size()); 3498 EXPECT_EQ(1U, cookies0.size());
3498 EXPECT_EQ(1U, cookies0.size()); 3499 EXPECT_EQ(1U, cookies0.size());
3499 } 3500 }
3500 3501
3501 } // namespace net 3502 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster_store_test.cc ('k') | net/extras/sqlite/sqlite_persistent_cookie_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698