Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: net/base/cookie_monster_store_test.h

Issue 8289028: Revert 105639 - The change list splits loading of cookies from DB by the domain key(eTLD+1). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/cookie_monster_perftest.cc ('k') | net/base/cookie_monster_store_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_
11 #define NET_BASE_COOKIE_MONSTER_STORE_TEST_H_ 11 #define NET_BASE_COOKIE_MONSTER_STORE_TEST_H_
12 #pragma once 12 #pragma once
13 13
14 #include <map> 14 #include <map>
15 #include <string> 15 #include <string>
16 #include <utility> 16 #include <utility>
17 #include <vector> 17 #include <vector>
18 #include "net/base/cookie_monster.h" 18 #include "net/base/cookie_monster.h"
19 19
20 namespace base { 20 namespace base {
21 class Time; 21 class Time;
22 } 22 }
23 23
24 namespace net { 24 namespace net {
25 25
26 // Wrapper class for posting a loaded callback. Since the Callback class is not
27 // reference counted, we cannot post a callback to the message loop directly,
28 // instead we post a LoadedCallbackTask.
29 class LoadedCallbackTask
30 : public base::RefCountedThreadSafe<LoadedCallbackTask> {
31 public:
32 typedef CookieMonster::PersistentCookieStore::LoadedCallback LoadedCallback;
33
34 LoadedCallbackTask(LoadedCallback loaded_callback,
35 std::vector<CookieMonster::CanonicalCookie*> cookies);
36 ~LoadedCallbackTask();
37
38 void Run() {
39 loaded_callback_.Run(cookies_);
40 }
41
42 private:
43 LoadedCallback loaded_callback_;
44 std::vector<CookieMonster::CanonicalCookie*> cookies_;
45
46 DISALLOW_COPY_AND_ASSIGN(LoadedCallbackTask);
47 }; // Wrapper class LoadedCallbackTask
48
49 // Describes a call to one of the 3 functions of PersistentCookieStore. 26 // Describes a call to one of the 3 functions of PersistentCookieStore.
50 struct CookieStoreCommand { 27 struct CookieStoreCommand {
51 enum Type { 28 enum Type {
52 ADD, 29 ADD,
53 UPDATE_ACCESS_TIME, 30 UPDATE_ACCESS_TIME,
54 REMOVE, 31 REMOVE,
55 }; 32 };
56 33
57 CookieStoreCommand(Type type, 34 CookieStoreCommand(Type type,
58 const CookieMonster::CanonicalCookie& cookie) 35 const CookieMonster::CanonicalCookie& cookie)
(...skipping 16 matching lines...) Expand all
75 virtual ~MockPersistentCookieStore(); 52 virtual ~MockPersistentCookieStore();
76 53
77 void SetLoadExpectation( 54 void SetLoadExpectation(
78 bool return_value, 55 bool return_value,
79 const std::vector<CookieMonster::CanonicalCookie*>& result); 56 const std::vector<CookieMonster::CanonicalCookie*>& result);
80 57
81 const CommandList& commands() const { 58 const CommandList& commands() const {
82 return commands_; 59 return commands_;
83 } 60 }
84 61
85 virtual void Load(const LoadedCallback& loaded_callback) OVERRIDE; 62 virtual bool Load(const LoadedCallback& loaded_callback) OVERRIDE;
86
87 virtual void LoadCookiesForKey(const std::string& key,
88 const LoadedCallback& loaded_callback) OVERRIDE;
89 63
90 virtual void AddCookie(const CookieMonster::CanonicalCookie& cookie) OVERRIDE; 64 virtual void AddCookie(const CookieMonster::CanonicalCookie& cookie) OVERRIDE;
91 65
92 virtual void UpdateCookieAccessTime( 66 virtual void UpdateCookieAccessTime(
93 const CookieMonster::CanonicalCookie& cookie) OVERRIDE; 67 const CookieMonster::CanonicalCookie& cookie) OVERRIDE;
94 68
95 virtual void DeleteCookie( 69 virtual void DeleteCookie(
96 const CookieMonster::CanonicalCookie& cookie) OVERRIDE; 70 const CookieMonster::CanonicalCookie& cookie) OVERRIDE;
97 71
98 virtual void Flush(Task* completion_task) OVERRIDE; 72 virtual void Flush(Task* completion_task) OVERRIDE;
99 73
100 // No files are created so nothing to clear either 74 // No files are created so nothing to clear either
101 virtual void SetClearLocalStateOnExit(bool clear_local_state) OVERRIDE; 75 virtual void SetClearLocalStateOnExit(bool clear_local_state) OVERRIDE;
102 76
103 private: 77 private:
104 CommandList commands_; 78 CommandList commands_;
105 79
106 // Deferred result to use when Load() is called. 80 // Deferred result to use when Load() is called.
107 bool load_return_value_; 81 bool load_return_value_;
108 std::vector<CookieMonster::CanonicalCookie*> load_result_; 82 std::vector<CookieMonster::CanonicalCookie*> load_result_;
109 // Indicates if the store has been fully loaded to avoid returning duplicate
110 // cookies.
111 bool loaded_;
112 83
113 DISALLOW_COPY_AND_ASSIGN(MockPersistentCookieStore); 84 DISALLOW_COPY_AND_ASSIGN(MockPersistentCookieStore);
114 }; 85 };
115 86
116 // Mock for CookieMonster::Delegate 87 // Mock for CookieMonster::Delegate
117 class MockCookieMonsterDelegate : public CookieMonster::Delegate { 88 class MockCookieMonsterDelegate : public CookieMonster::Delegate {
118 public: 89 public:
119 typedef std::pair<CookieMonster::CanonicalCookie, bool> 90 typedef std::pair<CookieMonster::CanonicalCookie, bool>
120 CookieNotification; 91 CookieNotification;
121 92
(...skipping 30 matching lines...) Expand all
152 std::vector<CookieMonster::CanonicalCookie*>* out_list); 123 std::vector<CookieMonster::CanonicalCookie*>* out_list);
153 124
154 // Just act like a backing database. Keep cookie information from 125 // Just act like a backing database. Keep cookie information from
155 // Add/Update/Delete and regurgitate it when Load is called. 126 // Add/Update/Delete and regurgitate it when Load is called.
156 class MockSimplePersistentCookieStore 127 class MockSimplePersistentCookieStore
157 : public CookieMonster::PersistentCookieStore { 128 : public CookieMonster::PersistentCookieStore {
158 public: 129 public:
159 MockSimplePersistentCookieStore(); 130 MockSimplePersistentCookieStore();
160 virtual ~MockSimplePersistentCookieStore(); 131 virtual ~MockSimplePersistentCookieStore();
161 132
162 virtual void Load(const LoadedCallback& loaded_callback) OVERRIDE; 133 virtual bool Load(const LoadedCallback& loaded_callback);
163
164 virtual void LoadCookiesForKey(const std::string& key,
165 const LoadedCallback& loaded_callback) OVERRIDE;
166 134
167 virtual void AddCookie( 135 virtual void AddCookie(
168 const CookieMonster::CanonicalCookie& cookie) OVERRIDE; 136 const CookieMonster::CanonicalCookie& cookie);
169 137
170 virtual void UpdateCookieAccessTime( 138 virtual void UpdateCookieAccessTime(
171 const CookieMonster::CanonicalCookie& cookie) OVERRIDE; 139 const CookieMonster::CanonicalCookie& cookie);
172 140
173 virtual void DeleteCookie( 141 virtual void DeleteCookie(
174 const CookieMonster::CanonicalCookie& cookie) OVERRIDE; 142 const CookieMonster::CanonicalCookie& cookie);
175 143
176 virtual void Flush(Task* completion_task) OVERRIDE; 144 virtual void Flush(Task* completion_task);
177 145
178 virtual void SetClearLocalStateOnExit(bool clear_local_state) OVERRIDE; 146 virtual void SetClearLocalStateOnExit(bool clear_local_state);
179 147
180 private: 148 private:
181 typedef std::map<int64, CookieMonster::CanonicalCookie> 149 typedef std::map<int64, CookieMonster::CanonicalCookie>
182 CanonicalCookieMap; 150 CanonicalCookieMap;
183 151
184 CanonicalCookieMap cookies_; 152 CanonicalCookieMap cookies_;
185
186 // Indicates if the store has been fully loaded to avoid return duplicate
187 // cookies in subsequent load requests
188 bool loaded_;
189 }; 153 };
190 154
191 // Helper function for creating a CookieMonster backed by a 155 // Helper function for creating a CookieMonster backed by a
192 // MockSimplePersistentCookieStore for garbage collection testing. 156 // MockSimplePersistentCookieStore for garbage collection testing.
193 // 157 //
194 // Fill the store through import with |num_cookies| cookies, |num_old_cookies| 158 // Fill the store through import with |num_cookies| cookies, |num_old_cookies|
195 // 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().
196 // Do two SetCookies(). Return whether each of the two SetCookies() took 160 // Do two SetCookies(). Return whether each of the two SetCookies() took
197 // 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
198 // left in the store afterwards. 162 // left in the store afterwards.
199 CookieMonster* CreateMonsterFromStoreForGC( 163 CookieMonster* CreateMonsterFromStoreForGC(
200 int num_cookies, 164 int num_cookies,
201 int num_old_cookies, 165 int num_old_cookies,
202 int days_old); 166 int days_old);
203 167
204 } // namespace net 168 } // namespace net
205 169
206 #endif // NET_BASE_COOKIE_MONSTER_STORE_TEST_H_ 170 #endif // NET_BASE_COOKIE_MONSTER_STORE_TEST_H_
OLDNEW
« no previous file with comments | « net/base/cookie_monster_perftest.cc ('k') | net/base/cookie_monster_store_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698