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 2147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2158 ASSERT_TRUE(cookie_list[0].IsExpired(Time::Now())); | 2158 ASSERT_TRUE(cookie_list[0].IsExpired(Time::Now())); |
2159 } | 2159 } |
2160 | 2160 |
2161 namespace { | 2161 namespace { |
2162 | 2162 |
2163 // Mock PersistentCookieStore that keeps track of the number of Flush() calls. | 2163 // Mock PersistentCookieStore that keeps track of the number of Flush() calls. |
2164 class FlushablePersistentStore : public CookieMonster::PersistentCookieStore { | 2164 class FlushablePersistentStore : public CookieMonster::PersistentCookieStore { |
2165 public: | 2165 public: |
2166 FlushablePersistentStore() : flush_count_(0) {} | 2166 FlushablePersistentStore() : flush_count_(0) {} |
2167 | 2167 |
2168 virtual void Load(const LoadedCallback& loaded_callback) override { | 2168 void Load(const LoadedCallback& loaded_callback) override { |
2169 std::vector<CanonicalCookie*> out_cookies; | 2169 std::vector<CanonicalCookie*> out_cookies; |
2170 base::MessageLoop::current()->PostTask( | 2170 base::MessageLoop::current()->PostTask( |
2171 FROM_HERE, | 2171 FROM_HERE, |
2172 base::Bind(&net::LoadedCallbackTask::Run, | 2172 base::Bind(&net::LoadedCallbackTask::Run, |
2173 new net::LoadedCallbackTask(loaded_callback, out_cookies))); | 2173 new net::LoadedCallbackTask(loaded_callback, out_cookies))); |
2174 } | 2174 } |
2175 | 2175 |
2176 virtual void LoadCookiesForKey( | 2176 void LoadCookiesForKey(const std::string& key, |
2177 const std::string& key, | 2177 const LoadedCallback& loaded_callback) override { |
2178 const LoadedCallback& loaded_callback) override { | |
2179 Load(loaded_callback); | 2178 Load(loaded_callback); |
2180 } | 2179 } |
2181 | 2180 |
2182 virtual void AddCookie(const CanonicalCookie&) override {} | 2181 void AddCookie(const CanonicalCookie&) override {} |
2183 virtual void UpdateCookieAccessTime(const CanonicalCookie&) override {} | 2182 void UpdateCookieAccessTime(const CanonicalCookie&) override {} |
2184 virtual void DeleteCookie(const CanonicalCookie&) override {} | 2183 void DeleteCookie(const CanonicalCookie&) override {} |
2185 virtual void SetForceKeepSessionState() override {} | 2184 void SetForceKeepSessionState() override {} |
2186 | 2185 |
2187 virtual void Flush(const base::Closure& callback) override { | 2186 void Flush(const base::Closure& callback) override { |
2188 ++flush_count_; | 2187 ++flush_count_; |
2189 if (!callback.is_null()) | 2188 if (!callback.is_null()) |
2190 callback.Run(); | 2189 callback.Run(); |
2191 } | 2190 } |
2192 | 2191 |
2193 int flush_count() { | 2192 int flush_count() { |
2194 return flush_count_; | 2193 return flush_count_; |
2195 } | 2194 } |
2196 | 2195 |
2197 private: | 2196 private: |
2198 virtual ~FlushablePersistentStore() {} | 2197 ~FlushablePersistentStore() override {} |
2199 | 2198 |
2200 volatile int flush_count_; | 2199 volatile int flush_count_; |
2201 }; | 2200 }; |
2202 | 2201 |
2203 // Counts the number of times Callback() has been run. | 2202 // Counts the number of times Callback() has been run. |
2204 class CallbackCounter : public base::RefCountedThreadSafe<CallbackCounter> { | 2203 class CallbackCounter : public base::RefCountedThreadSafe<CallbackCounter> { |
2205 public: | 2204 public: |
2206 CallbackCounter() : callback_count_(0) {} | 2205 CallbackCounter() : callback_count_(0) {} |
2207 | 2206 |
2208 void Callback() { | 2207 void Callback() { |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2732 | 2731 |
2733 // Inject our initial cookies into the mock PersistentCookieStore. | 2732 // Inject our initial cookies into the mock PersistentCookieStore. |
2734 store->SetLoadExpectation(true, initial_cookies); | 2733 store->SetLoadExpectation(true, initial_cookies); |
2735 | 2734 |
2736 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2735 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); |
2737 | 2736 |
2738 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); | 2737 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); |
2739 } | 2738 } |
2740 | 2739 |
2741 } // namespace net | 2740 } // namespace net |
OLD | NEW |