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 <time.h> | 7 #include <time.h> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 public: | 38 public: |
39 MOCK_METHOD1(Load, void(const LoadedCallback& loaded_callback)); | 39 MOCK_METHOD1(Load, void(const LoadedCallback& loaded_callback)); |
40 MOCK_METHOD2(LoadCookiesForKey, void(const std::string& key, | 40 MOCK_METHOD2(LoadCookiesForKey, void(const std::string& key, |
41 const LoadedCallback& loaded_callback)); | 41 const LoadedCallback& loaded_callback)); |
42 MOCK_METHOD1(AddCookie, void(const CookieMonster::CanonicalCookie& cc)); | 42 MOCK_METHOD1(AddCookie, void(const CookieMonster::CanonicalCookie& cc)); |
43 MOCK_METHOD1(UpdateCookieAccessTime, | 43 MOCK_METHOD1(UpdateCookieAccessTime, |
44 void(const CookieMonster::CanonicalCookie& cc)); | 44 void(const CookieMonster::CanonicalCookie& cc)); |
45 MOCK_METHOD1(DeleteCookie, void(const CookieMonster::CanonicalCookie& cc)); | 45 MOCK_METHOD1(DeleteCookie, void(const CookieMonster::CanonicalCookie& cc)); |
46 MOCK_METHOD1(SetClearLocalStateOnExit, void(bool clear_local_state)); | 46 MOCK_METHOD1(SetClearLocalStateOnExit, void(bool clear_local_state)); |
47 MOCK_METHOD1(Flush, void(const base::Closure& callback)); | 47 MOCK_METHOD1(Flush, void(const base::Closure& callback)); |
| 48 |
| 49 private: |
| 50 virtual ~NewMockPersistentCookieStore() {} |
48 }; | 51 }; |
49 | 52 |
50 const char* kTopLevelDomainPlus1 = "http://www.harvard.edu"; | 53 const char* kTopLevelDomainPlus1 = "http://www.harvard.edu"; |
51 const char* kTopLevelDomainPlus2 = "http://www.math.harvard.edu"; | 54 const char* kTopLevelDomainPlus2 = "http://www.math.harvard.edu"; |
52 const char* kTopLevelDomainPlus2Secure = "https://www.math.harvard.edu"; | 55 const char* kTopLevelDomainPlus2Secure = "https://www.math.harvard.edu"; |
53 const char* kTopLevelDomainPlus3 = | 56 const char* kTopLevelDomainPlus3 = |
54 "http://www.bourbaki.math.harvard.edu"; | 57 "http://www.bourbaki.math.harvard.edu"; |
55 const char* kOtherDomain = "http://www.mit.edu"; | 58 const char* kOtherDomain = "http://www.mit.edu"; |
56 const char kUrlGoogleSpecific[] = "http://www.gmail.google.izzle"; | 59 const char kUrlGoogleSpecific[] = "http://www.gmail.google.izzle"; |
57 | 60 |
(...skipping 2167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2225 ++flush_count_; | 2228 ++flush_count_; |
2226 if (!callback.is_null()) | 2229 if (!callback.is_null()) |
2227 callback.Run(); | 2230 callback.Run(); |
2228 } | 2231 } |
2229 | 2232 |
2230 int flush_count() { | 2233 int flush_count() { |
2231 return flush_count_; | 2234 return flush_count_; |
2232 } | 2235 } |
2233 | 2236 |
2234 private: | 2237 private: |
| 2238 virtual ~FlushablePersistentStore() {} |
| 2239 |
2235 volatile int flush_count_; | 2240 volatile int flush_count_; |
2236 }; | 2241 }; |
2237 | 2242 |
2238 // Counts the number of times Callback() has been run. | 2243 // Counts the number of times Callback() has been run. |
2239 class CallbackCounter : public base::RefCountedThreadSafe<CallbackCounter> { | 2244 class CallbackCounter : public base::RefCountedThreadSafe<CallbackCounter> { |
2240 public: | 2245 public: |
2241 CallbackCounter() : callback_count_(0) {} | 2246 CallbackCounter() : callback_count_(0) {} |
2242 | 2247 |
2243 void Callback() { | 2248 void Callback() { |
2244 ++callback_count_; | 2249 ++callback_count_; |
2245 } | 2250 } |
2246 | 2251 |
2247 int callback_count() { | 2252 int callback_count() { |
2248 return callback_count_; | 2253 return callback_count_; |
2249 } | 2254 } |
2250 | 2255 |
2251 private: | 2256 private: |
2252 friend class base::RefCountedThreadSafe<CallbackCounter>; | 2257 friend class base::RefCountedThreadSafe<CallbackCounter>; |
| 2258 ~CallbackCounter() {} |
| 2259 |
2253 volatile int callback_count_; | 2260 volatile int callback_count_; |
2254 }; | 2261 }; |
2255 | 2262 |
2256 } // namespace | 2263 } // namespace |
2257 | 2264 |
2258 // Test that FlushStore() is forwarded to the store and callbacks are posted. | 2265 // Test that FlushStore() is forwarded to the store and callbacks are posted. |
2259 TEST_F(CookieMonsterTest, FlushStore) { | 2266 TEST_F(CookieMonsterTest, FlushStore) { |
2260 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); | 2267 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); |
2261 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2268 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
2262 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 2269 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2734 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); | 2741 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); |
2735 | 2742 |
2736 // Create some non-persistent cookies and check that they don't go to the | 2743 // Create some non-persistent cookies and check that they don't go to the |
2737 // persistent storage. | 2744 // persistent storage. |
2738 EXPECT_TRUE(SetCookie(cm, url_google_, "B=Bar")); | 2745 EXPECT_TRUE(SetCookie(cm, url_google_, "B=Bar")); |
2739 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm, url_google_)); | 2746 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm, url_google_)); |
2740 EXPECT_EQ(5u, store->commands().size()); | 2747 EXPECT_EQ(5u, store->commands().size()); |
2741 } | 2748 } |
2742 | 2749 |
2743 } // namespace net | 2750 } // namespace net |
OLD | NEW |