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

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

Issue 1602283002: Convert some raw CanonicalCookie ptrs to scoped_ptr<CanonicalCookie>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix missed CanonicalCookie::Create() callsite in ios/net/cookies/cookie_store_ios_unittest.mm Created 4 years, 11 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
« no previous file with comments | « net/cookies/cookie_monster.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_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 2802 matching lines...) Expand 10 before | Expand all | Expand 10 after
2813 RunOnOtherThread(task); 2813 RunOnOtherThread(task);
2814 EXPECT_TRUE(callback.did_run()); 2814 EXPECT_TRUE(callback.did_run());
2815 EXPECT_TRUE(callback.result()); 2815 EXPECT_TRUE(callback.result());
2816 } 2816 }
2817 2817
2818 // Ensure that cookies for http, https, ws, and wss all share the same storage 2818 // Ensure that cookies for http, https, ws, and wss all share the same storage
2819 // and policies when GetAllCookiesForURLAsync is used. This test is part of 2819 // and policies when GetAllCookiesForURLAsync is used. This test is part of
2820 // MultiThreadedCookieMonsterTest in order to test and use 2820 // MultiThreadedCookieMonsterTest in order to test and use
2821 // GetAllCookiesForURLAsync, but it does not use any additional threads. 2821 // GetAllCookiesForURLAsync, but it does not use any additional threads.
2822 TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) { 2822 TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) {
2823 std::vector<CanonicalCookie*> cookies; 2823 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create(
2824 http_www_google_.url(), kValidCookieLine, Time::Now(), CookieOptions()));
2825
2824 // This cookie will be freed by the CookieMonster. 2826 // This cookie will be freed by the CookieMonster.
2825 cookies.push_back(CanonicalCookie::Create( 2827 std::vector<CanonicalCookie*> cookies = {new CanonicalCookie(*cookie)};
2826 http_www_google_.url(), kValidCookieLine, Time::Now(), CookieOptions()));
2827 CanonicalCookie cookie = *cookies[0];
2828 scoped_refptr<NewMockPersistentCookieStore> store( 2828 scoped_refptr<NewMockPersistentCookieStore> store(
2829 new NewMockPersistentCookieStore); 2829 new NewMockPersistentCookieStore);
2830 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); 2830 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
2831 2831
2832 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback; 2832 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback;
2833 ::testing::StrictMock<::testing::MockFunction<void(int)>> checkpoint; 2833 ::testing::StrictMock<::testing::MockFunction<void(int)>> checkpoint;
2834 const std::string key = cookie_util::GetEffectiveDomain( 2834 const std::string key = cookie_util::GetEffectiveDomain(
2835 http_www_google_.url().scheme(), http_www_google_.url().host()); 2835 http_www_google_.url().scheme(), http_www_google_.url().host());
2836 2836
2837 ::testing::InSequence s; 2837 ::testing::InSequence s;
(...skipping 11 matching lines...) Expand all
2849 checkpoint.Call(0); 2849 checkpoint.Call(0);
2850 GetAllCookiesForURLTask(cm.get(), http_www_google_.url(), &callback); 2850 GetAllCookiesForURLTask(cm.get(), http_www_google_.url(), &callback);
2851 checkpoint.Call(1); 2851 checkpoint.Call(1);
2852 ASSERT_FALSE(callback.did_run()); 2852 ASSERT_FALSE(callback.did_run());
2853 // Pass the cookies to the CookieMonster. 2853 // Pass the cookies to the CookieMonster.
2854 loaded_callback.Run(cookies); 2854 loaded_callback.Run(cookies);
2855 // Now GetAllCookiesForURLTask is done. 2855 // Now GetAllCookiesForURLTask is done.
2856 ASSERT_TRUE(callback.did_run()); 2856 ASSERT_TRUE(callback.did_run());
2857 // See that the callback was called with the cookies. 2857 // See that the callback was called with the cookies.
2858 ASSERT_EQ(1u, callback.cookies().size()); 2858 ASSERT_EQ(1u, callback.cookies().size());
2859 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); 2859 EXPECT_TRUE(cookie->IsEquivalent(callback.cookies()[0]));
2860 2860
2861 // All urls in |urls| should share the same cookie domain. 2861 // All urls in |urls| should share the same cookie domain.
2862 const GURL kUrls[] = { 2862 const GURL kUrls[] = {
2863 http_www_google_.url(), https_www_google_.url(), ws_www_google_.url(), 2863 http_www_google_.url(), https_www_google_.url(), ws_www_google_.url(),
2864 wss_www_google_.url(), 2864 wss_www_google_.url(),
2865 }; 2865 };
2866 for (const GURL& url : kUrls) { 2866 for (const GURL& url : kUrls) {
2867 // Call the function with |url| and verify it is done synchronously without 2867 // Call the function with |url| and verify it is done synchronously without
2868 // calling LoadCookiesForKey. 2868 // calling LoadCookiesForKey.
2869 GetCookieListCallback callback; 2869 GetCookieListCallback callback;
2870 GetAllCookiesForURLTask(cm.get(), url, &callback); 2870 GetAllCookiesForURLTask(cm.get(), url, &callback);
2871 ASSERT_TRUE(callback.did_run()); 2871 ASSERT_TRUE(callback.did_run());
2872 ASSERT_EQ(1u, callback.cookies().size()); 2872 ASSERT_EQ(1u, callback.cookies().size());
2873 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); 2873 EXPECT_TRUE(cookie->IsEquivalent(callback.cookies()[0]));
2874 } 2874 }
2875 } 2875 }
2876 2876
2877 TEST_F(CookieMonsterTest, InvalidExpiryTime) { 2877 TEST_F(CookieMonsterTest, InvalidExpiryTime) {
2878 std::string cookie_line = 2878 std::string cookie_line =
2879 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; 2879 std::string(kValidCookieLine) + "; expires=Blarg arg arg";
2880 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( 2880 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create(
2881 http_www_google_.url(), cookie_line, Time::Now(), CookieOptions())); 2881 http_www_google_.url(), cookie_line, Time::Now(), CookieOptions()));
2882 ASSERT_FALSE(cookie->IsPersistent()); 2882 ASSERT_FALSE(cookie->IsPersistent());
2883 } 2883 }
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
3572 monster()->AddCallbackForCookie( 3572 monster()->AddCallbackForCookie(
3573 test_url_, "abc", 3573 test_url_, "abc",
3574 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); 3574 base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
3575 SetCookie(monster(), test_url_, "abc=def"); 3575 SetCookie(monster(), test_url_, "abc=def");
3576 base::MessageLoop::current()->RunUntilIdle(); 3576 base::MessageLoop::current()->RunUntilIdle();
3577 EXPECT_EQ(1U, cookies0.size()); 3577 EXPECT_EQ(1U, cookies0.size());
3578 EXPECT_EQ(1U, cookies0.size()); 3578 EXPECT_EQ(1U, cookies0.size());
3579 } 3579 }
3580 3580
3581 } // namespace net 3581 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698