Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "net/base/cookie_monster.h" | 11 #include "net/base/cookie_monster.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // Describes a call to one of the 3 functions of PersistentCookieStore. | 16 // Describes a call to one of the 3 functions of PersistentCookieStore. |
| 17 struct CookieStoreCommand { | 17 struct CookieStoreCommand { |
| 18 enum Type { | 18 enum Type { |
| 19 ADD, | 19 ADD, |
| 20 UPDATE_ACCESS_TIME, | 20 UPDATE_ACCESS_TIME, |
| 21 REMOVE, | 21 REMOVE |
|
jochen (gone - plz use gerrit)
2010/12/02 15:09:51
please leave the ,
pastarmovj
2010/12/02 16:29:07
Done.
| |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 CookieStoreCommand(Type type, | 24 CookieStoreCommand(Type type, |
| 25 const net::CookieMonster::CanonicalCookie& cookie) | 25 const net::CookieMonster::CanonicalCookie& cookie) |
| 26 : type(type), | 26 : type(type), |
| 27 cookie(cookie) {} | 27 cookie(cookie) {} |
| 28 | 28 |
| 29 Type type; | 29 Type type; |
| 30 net::CookieMonster::CanonicalCookie cookie; | 30 net::CookieMonster::CanonicalCookie cookie; |
| 31 }; | 31 }; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 59 commands_.push_back(CookieStoreCommand( | 59 commands_.push_back(CookieStoreCommand( |
| 60 CookieStoreCommand::UPDATE_ACCESS_TIME, cookie)); | 60 CookieStoreCommand::UPDATE_ACCESS_TIME, cookie)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 virtual void DeleteCookie( | 63 virtual void DeleteCookie( |
| 64 const net::CookieMonster::CanonicalCookie& cookie) { | 64 const net::CookieMonster::CanonicalCookie& cookie) { |
| 65 commands_.push_back( | 65 commands_.push_back( |
| 66 CookieStoreCommand(CookieStoreCommand::REMOVE, cookie)); | 66 CookieStoreCommand(CookieStoreCommand::REMOVE, cookie)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // No files are created so nothing to clear either | |
| 70 virtual void SetClearLocalStateOnExit(bool clear_local_state) {} | |
| 71 | |
| 69 void SetLoadExpectation( | 72 void SetLoadExpectation( |
| 70 bool return_value, | 73 bool return_value, |
| 71 const std::vector<net::CookieMonster::CanonicalCookie*>& result) { | 74 const std::vector<net::CookieMonster::CanonicalCookie*>& result) { |
| 72 load_return_value_ = return_value; | 75 load_return_value_ = return_value; |
| 73 load_result_ = result; | 76 load_result_ = result; |
| 74 } | 77 } |
| 75 | 78 |
| 76 const CommandList& commands() const { | 79 const CommandList& commands() const { |
| 77 return commands_; | 80 return commands_; |
| 78 } | 81 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 } | 181 } |
| 179 | 182 |
| 180 virtual void DeleteCookie( | 183 virtual void DeleteCookie( |
| 181 const net::CookieMonster::CanonicalCookie& cookie) { | 184 const net::CookieMonster::CanonicalCookie& cookie) { |
| 182 int64 creation_time = cookie.CreationDate().ToInternalValue(); | 185 int64 creation_time = cookie.CreationDate().ToInternalValue(); |
| 183 CanonicalCookieMap::iterator it = cookies_.find(creation_time); | 186 CanonicalCookieMap::iterator it = cookies_.find(creation_time); |
| 184 ASSERT_TRUE(it != cookies_.end()); | 187 ASSERT_TRUE(it != cookies_.end()); |
| 185 cookies_.erase(it); | 188 cookies_.erase(it); |
| 186 } | 189 } |
| 187 | 190 |
| 191 virtual void SetClearLocalStateOnExit(bool clear_local_state) {} | |
| 192 | |
| 188 private: | 193 private: |
| 189 CanonicalCookieMap cookies_; | 194 CanonicalCookieMap cookies_; |
| 190 }; | 195 }; |
| 191 | 196 |
| 192 // Helper function for creating a CookieMonster backed by a | 197 // Helper function for creating a CookieMonster backed by a |
| 193 // MockSimplePersistentCookieStore for garbage collection testing. | 198 // MockSimplePersistentCookieStore for garbage collection testing. |
| 194 // | 199 // |
| 195 // Fill the store through import with |num_cookies| cookies, |num_old_cookies| | 200 // Fill the store through import with |num_cookies| cookies, |num_old_cookies| |
| 196 // with access time Now()-days_old, the rest with access time Now(). | 201 // with access time Now()-days_old, the rest with access time Now(). |
| 197 // Do two SetCookies(). Return whether each of the two SetCookies() took | 202 // Do two SetCookies(). Return whether each of the two SetCookies() took |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 219 "a", "1", StringPrintf("h%05d.izzle", i), "/path", false, false, | 224 "a", "1", StringPrintf("h%05d.izzle", i), "/path", false, false, |
| 220 past_creation + base::TimeDelta::FromMicroseconds(i), current, | 225 past_creation + base::TimeDelta::FromMicroseconds(i), current, |
| 221 true, current + base::TimeDelta::FromDays(30)); | 226 true, current + base::TimeDelta::FromDays(30)); |
| 222 store->AddCookie(cc); | 227 store->AddCookie(cc); |
| 223 } | 228 } |
| 224 | 229 |
| 225 return new net::CookieMonster(store, NULL); | 230 return new net::CookieMonster(store, NULL); |
| 226 } | 231 } |
| 227 | 232 |
| 228 } // namespace | 233 } // namespace |
| OLD | NEW |