| 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 2137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2195 ++flush_count_; | 2198 ++flush_count_; |
| 2196 if (!callback.is_null()) | 2199 if (!callback.is_null()) |
| 2197 callback.Run(); | 2200 callback.Run(); |
| 2198 } | 2201 } |
| 2199 | 2202 |
| 2200 int flush_count() { | 2203 int flush_count() { |
| 2201 return flush_count_; | 2204 return flush_count_; |
| 2202 } | 2205 } |
| 2203 | 2206 |
| 2204 private: | 2207 private: |
| 2208 virtual ~FlushablePersistentStore() {} |
| 2209 |
| 2205 volatile int flush_count_; | 2210 volatile int flush_count_; |
| 2206 }; | 2211 }; |
| 2207 | 2212 |
| 2208 // Counts the number of times Callback() has been run. | 2213 // Counts the number of times Callback() has been run. |
| 2209 class CallbackCounter : public base::RefCountedThreadSafe<CallbackCounter> { | 2214 class CallbackCounter : public base::RefCountedThreadSafe<CallbackCounter> { |
| 2210 public: | 2215 public: |
| 2211 CallbackCounter() : callback_count_(0) {} | 2216 CallbackCounter() : callback_count_(0) {} |
| 2212 | 2217 |
| 2213 void Callback() { | 2218 void Callback() { |
| 2214 ++callback_count_; | 2219 ++callback_count_; |
| 2215 } | 2220 } |
| 2216 | 2221 |
| 2217 int callback_count() { | 2222 int callback_count() { |
| 2218 return callback_count_; | 2223 return callback_count_; |
| 2219 } | 2224 } |
| 2220 | 2225 |
| 2221 private: | 2226 private: |
| 2222 friend class base::RefCountedThreadSafe<CallbackCounter>; | 2227 friend class base::RefCountedThreadSafe<CallbackCounter>; |
| 2228 ~CallbackCounter() {} |
| 2229 |
| 2223 volatile int callback_count_; | 2230 volatile int callback_count_; |
| 2224 }; | 2231 }; |
| 2225 | 2232 |
| 2226 } // namespace | 2233 } // namespace |
| 2227 | 2234 |
| 2228 // Test that FlushStore() is forwarded to the store and callbacks are posted. | 2235 // Test that FlushStore() is forwarded to the store and callbacks are posted. |
| 2229 TEST_F(CookieMonsterTest, FlushStore) { | 2236 TEST_F(CookieMonsterTest, FlushStore) { |
| 2230 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); | 2237 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); |
| 2231 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2238 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
| 2232 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 2239 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2678 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); | 2685 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); |
| 2679 | 2686 |
| 2680 // Create some non-persistent cookies and check that they don't go to the | 2687 // Create some non-persistent cookies and check that they don't go to the |
| 2681 // persistent storage. | 2688 // persistent storage. |
| 2682 EXPECT_TRUE(SetCookie(cm, url_google_, "B=Bar")); | 2689 EXPECT_TRUE(SetCookie(cm, url_google_, "B=Bar")); |
| 2683 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm, url_google_)); | 2690 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm, url_google_)); |
| 2684 EXPECT_EQ(5u, store->commands().size()); | 2691 EXPECT_EQ(5u, store->commands().size()); |
| 2685 } | 2692 } |
| 2686 | 2693 |
| 2687 } // namespace net | 2694 } // namespace net |
| OLD | NEW |