| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // This file contains test infrastructure for multiple files | 5 // This file contains test infrastructure for multiple files |
| 6 // (current cookie_monster_unittest.cc and cookie_monster_perftest.cc) | 6 // (current cookie_monster_unittest.cc and cookie_monster_perftest.cc) |
| 7 // that need to test out CookieMonster interactions with the backing store. | 7 // that need to test out CookieMonster interactions with the backing store. |
| 8 // It should only be included by test code. | 8 // It should only be included by test code. |
| 9 | 9 |
| 10 #ifndef NET_BASE_COOKIE_MONSTER_STORE_TEST_H_ | 10 #ifndef NET_BASE_COOKIE_MONSTER_STORE_TEST_H_ |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 virtual ~MockPersistentCookieStore(); | 52 virtual ~MockPersistentCookieStore(); |
| 53 | 53 |
| 54 void SetLoadExpectation( | 54 void SetLoadExpectation( |
| 55 bool return_value, | 55 bool return_value, |
| 56 const std::vector<CookieMonster::CanonicalCookie*>& result); | 56 const std::vector<CookieMonster::CanonicalCookie*>& result); |
| 57 | 57 |
| 58 const CommandList& commands() const { | 58 const CommandList& commands() const { |
| 59 return commands_; | 59 return commands_; |
| 60 } | 60 } |
| 61 | 61 |
| 62 virtual bool Load(const LoadedCallback& loaded_callback) OVERRIDE; | 62 virtual void Load(const LoadedCallback& loaded_callback) OVERRIDE; |
| 63 |
| 64 virtual void LoadCookiesForKey(const std::string& key, |
| 65 const LoadedCallback& loaded_callback) OVERRIDE; |
| 63 | 66 |
| 64 virtual void AddCookie(const CookieMonster::CanonicalCookie& cookie) OVERRIDE; | 67 virtual void AddCookie(const CookieMonster::CanonicalCookie& cookie) OVERRIDE; |
| 65 | 68 |
| 66 virtual void UpdateCookieAccessTime( | 69 virtual void UpdateCookieAccessTime( |
| 67 const CookieMonster::CanonicalCookie& cookie) OVERRIDE; | 70 const CookieMonster::CanonicalCookie& cookie) OVERRIDE; |
| 68 | 71 |
| 69 virtual void DeleteCookie( | 72 virtual void DeleteCookie( |
| 70 const CookieMonster::CanonicalCookie& cookie) OVERRIDE; | 73 const CookieMonster::CanonicalCookie& cookie) OVERRIDE; |
| 71 | 74 |
| 72 virtual void Flush(Task* completion_task) OVERRIDE; | 75 virtual void Flush(Task* completion_task) OVERRIDE; |
| 73 | 76 |
| 74 // No files are created so nothing to clear either | 77 // No files are created so nothing to clear either |
| 75 virtual void SetClearLocalStateOnExit(bool clear_local_state) OVERRIDE; | 78 virtual void SetClearLocalStateOnExit(bool clear_local_state) OVERRIDE; |
| 76 | 79 |
| 77 private: | 80 private: |
| 78 CommandList commands_; | 81 CommandList commands_; |
| 79 | 82 |
| 80 // Deferred result to use when Load() is called. | 83 // Deferred result to use when Load() is called. |
| 81 bool load_return_value_; | 84 bool load_return_value_; |
| 82 std::vector<CookieMonster::CanonicalCookie*> load_result_; | 85 std::vector<CookieMonster::CanonicalCookie*> load_result_; |
| 86 // Indicates if the store has been fully loaded to avoid returning duplicate |
| 87 // cookies. |
| 88 bool loaded_; |
| 83 | 89 |
| 84 DISALLOW_COPY_AND_ASSIGN(MockPersistentCookieStore); | 90 DISALLOW_COPY_AND_ASSIGN(MockPersistentCookieStore); |
| 85 }; | 91 }; |
| 86 | 92 |
| 87 // Mock for CookieMonster::Delegate | 93 // Mock for CookieMonster::Delegate |
| 88 class MockCookieMonsterDelegate : public CookieMonster::Delegate { | 94 class MockCookieMonsterDelegate : public CookieMonster::Delegate { |
| 89 public: | 95 public: |
| 90 typedef std::pair<CookieMonster::CanonicalCookie, bool> | 96 typedef std::pair<CookieMonster::CanonicalCookie, bool> |
| 91 CookieNotification; | 97 CookieNotification; |
| 92 | 98 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 123 std::vector<CookieMonster::CanonicalCookie*>* out_list); | 129 std::vector<CookieMonster::CanonicalCookie*>* out_list); |
| 124 | 130 |
| 125 // Just act like a backing database. Keep cookie information from | 131 // Just act like a backing database. Keep cookie information from |
| 126 // Add/Update/Delete and regurgitate it when Load is called. | 132 // Add/Update/Delete and regurgitate it when Load is called. |
| 127 class MockSimplePersistentCookieStore | 133 class MockSimplePersistentCookieStore |
| 128 : public CookieMonster::PersistentCookieStore { | 134 : public CookieMonster::PersistentCookieStore { |
| 129 public: | 135 public: |
| 130 MockSimplePersistentCookieStore(); | 136 MockSimplePersistentCookieStore(); |
| 131 virtual ~MockSimplePersistentCookieStore(); | 137 virtual ~MockSimplePersistentCookieStore(); |
| 132 | 138 |
| 133 virtual bool Load(const LoadedCallback& loaded_callback); | 139 virtual void Load(const LoadedCallback& loaded_callback) OVERRIDE; |
| 140 |
| 141 virtual void LoadCookiesForKey(const std::string& key, |
| 142 const LoadedCallback& loaded_callback) OVERRIDE; |
| 134 | 143 |
| 135 virtual void AddCookie( | 144 virtual void AddCookie( |
| 136 const CookieMonster::CanonicalCookie& cookie); | 145 const CookieMonster::CanonicalCookie& cookie) OVERRIDE; |
| 137 | 146 |
| 138 virtual void UpdateCookieAccessTime( | 147 virtual void UpdateCookieAccessTime( |
| 139 const CookieMonster::CanonicalCookie& cookie); | 148 const CookieMonster::CanonicalCookie& cookie) OVERRIDE; |
| 140 | 149 |
| 141 virtual void DeleteCookie( | 150 virtual void DeleteCookie( |
| 142 const CookieMonster::CanonicalCookie& cookie); | 151 const CookieMonster::CanonicalCookie& cookie) OVERRIDE; |
| 143 | 152 |
| 144 virtual void Flush(Task* completion_task); | 153 virtual void Flush(Task* completion_task) OVERRIDE; |
| 145 | 154 |
| 146 virtual void SetClearLocalStateOnExit(bool clear_local_state); | 155 virtual void SetClearLocalStateOnExit(bool clear_local_state) OVERRIDE; |
| 147 | 156 |
| 148 private: | 157 private: |
| 149 typedef std::map<int64, CookieMonster::CanonicalCookie> | 158 typedef std::map<int64, CookieMonster::CanonicalCookie> |
| 150 CanonicalCookieMap; | 159 CanonicalCookieMap; |
| 151 | 160 |
| 152 CanonicalCookieMap cookies_; | 161 CanonicalCookieMap cookies_; |
| 162 |
| 163 // Indicates if the store has been fully loaded to avoid return duplicate |
| 164 // cookies in subsequent load requests |
| 165 bool loaded_; |
| 153 }; | 166 }; |
| 154 | 167 |
| 155 // Helper function for creating a CookieMonster backed by a | 168 // Helper function for creating a CookieMonster backed by a |
| 156 // MockSimplePersistentCookieStore for garbage collection testing. | 169 // MockSimplePersistentCookieStore for garbage collection testing. |
| 157 // | 170 // |
| 158 // Fill the store through import with |num_cookies| cookies, |num_old_cookies| | 171 // Fill the store through import with |num_cookies| cookies, |num_old_cookies| |
| 159 // with access time Now()-days_old, the rest with access time Now(). | 172 // with access time Now()-days_old, the rest with access time Now(). |
| 160 // Do two SetCookies(). Return whether each of the two SetCookies() took | 173 // Do two SetCookies(). Return whether each of the two SetCookies() took |
| 161 // longer than |gc_perf_micros| to complete, and how many cookie were | 174 // longer than |gc_perf_micros| to complete, and how many cookie were |
| 162 // left in the store afterwards. | 175 // left in the store afterwards. |
| 163 CookieMonster* CreateMonsterFromStoreForGC( | 176 CookieMonster* CreateMonsterFromStoreForGC( |
| 164 int num_cookies, | 177 int num_cookies, |
| 165 int num_old_cookies, | 178 int num_old_cookies, |
| 166 int days_old); | 179 int days_old); |
| 167 | 180 |
| 168 } // namespace net | 181 } // namespace net |
| 169 | 182 |
| 170 #endif // NET_BASE_COOKIE_MONSTER_STORE_TEST_H_ | 183 #endif // NET_BASE_COOKIE_MONSTER_STORE_TEST_H_ |
| OLD | NEW |