| 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_ |
| 11 #define NET_BASE_COOKIE_MONSTER_STORE_TEST_H_ |
| 12 #pragma once |
| 13 |
| 14 #include <map> |
| 15 #include <utility> |
| 16 #include <string> |
| 17 #include <vector> |
| 10 #include "net/base/cookie_monster.h" | 18 #include "net/base/cookie_monster.h" |
| 11 | 19 |
| 12 namespace base { | 20 namespace base { |
| 13 class Time; | 21 class Time; |
| 14 } | 22 } |
| 15 | 23 |
| 16 namespace net { | 24 namespace net { |
| 17 | 25 |
| 18 // Describes a call to one of the 3 functions of PersistentCookieStore. | 26 // Describes a call to one of the 3 functions of PersistentCookieStore. |
| 19 struct CookieStoreCommand { | 27 struct CookieStoreCommand { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 44 virtual ~MockPersistentCookieStore(); | 52 virtual ~MockPersistentCookieStore(); |
| 45 | 53 |
| 46 void SetLoadExpectation( | 54 void SetLoadExpectation( |
| 47 bool return_value, | 55 bool return_value, |
| 48 const std::vector<CookieMonster::CanonicalCookie*>& result); | 56 const std::vector<CookieMonster::CanonicalCookie*>& result); |
| 49 | 57 |
| 50 const CommandList& commands() const { | 58 const CommandList& commands() const { |
| 51 return commands_; | 59 return commands_; |
| 52 } | 60 } |
| 53 | 61 |
| 54 virtual bool Load( | 62 virtual bool Load(const LoadedCallback& loaded_callback) OVERRIDE; |
| 55 std::vector<CookieMonster::CanonicalCookie*>* out_cookies); | |
| 56 | 63 |
| 57 virtual void AddCookie(const CookieMonster::CanonicalCookie& cookie); | 64 virtual void AddCookie(const CookieMonster::CanonicalCookie& cookie) OVERRIDE; |
| 58 | 65 |
| 59 virtual void UpdateCookieAccessTime( | 66 virtual void UpdateCookieAccessTime( |
| 60 const CookieMonster::CanonicalCookie& cookie); | 67 const CookieMonster::CanonicalCookie& cookie) OVERRIDE; |
| 61 | 68 |
| 62 virtual void DeleteCookie( | 69 virtual void DeleteCookie( |
| 63 const CookieMonster::CanonicalCookie& cookie); | 70 const CookieMonster::CanonicalCookie& cookie) OVERRIDE; |
| 64 | 71 |
| 65 virtual void Flush(Task* completion_task); | 72 virtual void Flush(Task* completion_task) OVERRIDE; |
| 66 | 73 |
| 67 // No files are created so nothing to clear either | 74 // No files are created so nothing to clear either |
| 68 virtual void SetClearLocalStateOnExit(bool clear_local_state); | 75 virtual void SetClearLocalStateOnExit(bool clear_local_state) OVERRIDE; |
| 69 | 76 |
| 70 private: | 77 private: |
| 71 CommandList commands_; | 78 CommandList commands_; |
| 72 | 79 |
| 73 // Deferred result to use when Load() is called. | 80 // Deferred result to use when Load() is called. |
| 74 bool load_return_value_; | 81 bool load_return_value_; |
| 75 std::vector<CookieMonster::CanonicalCookie*> load_result_; | 82 std::vector<CookieMonster::CanonicalCookie*> load_result_; |
| 76 | 83 |
| 77 DISALLOW_COPY_AND_ASSIGN(MockPersistentCookieStore); | 84 DISALLOW_COPY_AND_ASSIGN(MockPersistentCookieStore); |
| 78 }; | 85 }; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 95 CookieMonster::Delegate::ChangeCause cause); | 102 CookieMonster::Delegate::ChangeCause cause); |
| 96 | 103 |
| 97 private: | 104 private: |
| 98 virtual ~MockCookieMonsterDelegate(); | 105 virtual ~MockCookieMonsterDelegate(); |
| 99 | 106 |
| 100 std::vector<CookieNotification> changes_; | 107 std::vector<CookieNotification> changes_; |
| 101 | 108 |
| 102 DISALLOW_COPY_AND_ASSIGN(MockCookieMonsterDelegate); | 109 DISALLOW_COPY_AND_ASSIGN(MockCookieMonsterDelegate); |
| 103 }; | 110 }; |
| 104 | 111 |
| 112 // Helper to build a single CanonicalCookie. |
| 113 CookieMonster::CanonicalCookie BuildCanonicalCookie( |
| 114 const std::string& key, |
| 115 const std::string& cookie_line, |
| 116 const base::Time& creation_time); |
| 117 |
| 105 // Helper to build a list of CanonicalCookie*s. | 118 // Helper to build a list of CanonicalCookie*s. |
| 106 void AddCookieToList( | 119 void AddCookieToList( |
| 107 const std::string& key, | 120 const std::string& key, |
| 108 const std::string& cookie_line, | 121 const std::string& cookie_line, |
| 109 const base::Time& creation_time, | 122 const base::Time& creation_time, |
| 110 std::vector<CookieMonster::CanonicalCookie*>* out_list); | 123 std::vector<CookieMonster::CanonicalCookie*>* out_list); |
| 111 | 124 |
| 112 // Just act like a backing database. Keep cookie information from | 125 // Just act like a backing database. Keep cookie information from |
| 113 // Add/Update/Delete and regurgitate it when Load is called. | 126 // Add/Update/Delete and regurgitate it when Load is called. |
| 114 class MockSimplePersistentCookieStore | 127 class MockSimplePersistentCookieStore |
| 115 : public CookieMonster::PersistentCookieStore { | 128 : public CookieMonster::PersistentCookieStore { |
| 116 public: | 129 public: |
| 117 MockSimplePersistentCookieStore(); | 130 MockSimplePersistentCookieStore(); |
| 118 virtual ~MockSimplePersistentCookieStore(); | 131 virtual ~MockSimplePersistentCookieStore(); |
| 119 | 132 |
| 120 virtual bool Load( | 133 virtual bool Load(const LoadedCallback& loaded_callback); |
| 121 std::vector<CookieMonster::CanonicalCookie*>* out_cookies); | |
| 122 | 134 |
| 123 virtual void AddCookie( | 135 virtual void AddCookie( |
| 124 const CookieMonster::CanonicalCookie& cookie); | 136 const CookieMonster::CanonicalCookie& cookie); |
| 125 | 137 |
| 126 virtual void UpdateCookieAccessTime( | 138 virtual void UpdateCookieAccessTime( |
| 127 const CookieMonster::CanonicalCookie& cookie); | 139 const CookieMonster::CanonicalCookie& cookie); |
| 128 | 140 |
| 129 virtual void DeleteCookie( | 141 virtual void DeleteCookie( |
| 130 const CookieMonster::CanonicalCookie& cookie); | 142 const CookieMonster::CanonicalCookie& cookie); |
| 131 | 143 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 147 // with access time Now()-days_old, the rest with access time Now(). | 159 // with access time Now()-days_old, the rest with access time Now(). |
| 148 // Do two SetCookies(). Return whether each of the two SetCookies() took | 160 // Do two SetCookies(). Return whether each of the two SetCookies() took |
| 149 // longer than |gc_perf_micros| to complete, and how many cookie were | 161 // longer than |gc_perf_micros| to complete, and how many cookie were |
| 150 // left in the store afterwards. | 162 // left in the store afterwards. |
| 151 CookieMonster* CreateMonsterFromStoreForGC( | 163 CookieMonster* CreateMonsterFromStoreForGC( |
| 152 int num_cookies, | 164 int num_cookies, |
| 153 int num_old_cookies, | 165 int num_old_cookies, |
| 154 int days_old); | 166 int days_old); |
| 155 | 167 |
| 156 } // namespace net | 168 } // namespace net |
| 169 |
| 170 #endif // NET_BASE_COOKIE_MONSTER_STORE_TEST_H_ |
| OLD | NEW |