| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 using base::TimeDelta; | 39 using base::TimeDelta; |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 // TODO(erikwright): Replace the pre-existing MockPersistentCookieStore (and | 43 // TODO(erikwright): Replace the pre-existing MockPersistentCookieStore (and |
| 44 // brethren) with this one, and remove the 'New' prefix. | 44 // brethren) with this one, and remove the 'New' prefix. |
| 45 class NewMockPersistentCookieStore | 45 class NewMockPersistentCookieStore |
| 46 : public CookieMonster::PersistentCookieStore { | 46 : public CookieMonster::PersistentCookieStore { |
| 47 public: | 47 public: |
| 48 MOCK_METHOD1(Load, void(const LoadedCallback& loaded_callback)); | 48 MOCK_METHOD1(Load, void(const LoadedCallback& loaded_callback)); |
| 49 MOCK_METHOD2(LoadCookiesForKey, void(const std::string& key, | 49 MOCK_METHOD2(LoadCookiesForKey, |
| 50 const LoadedCallback& loaded_callback)); | 50 void(const std::string& key, |
| 51 const LoadedCallback& loaded_callback)); |
| 51 MOCK_METHOD1(AddCookie, void(const CanonicalCookie& cc)); | 52 MOCK_METHOD1(AddCookie, void(const CanonicalCookie& cc)); |
| 52 MOCK_METHOD1(UpdateCookieAccessTime, void(const CanonicalCookie& cc)); | 53 MOCK_METHOD1(UpdateCookieAccessTime, void(const CanonicalCookie& cc)); |
| 53 MOCK_METHOD1(DeleteCookie, void(const CanonicalCookie& cc)); | 54 MOCK_METHOD1(DeleteCookie, void(const CanonicalCookie& cc)); |
| 54 virtual void Flush(const base::Closure& callback) { | 55 virtual void Flush(const base::Closure& callback) { |
| 55 if (!callback.is_null()) | 56 if (!callback.is_null()) |
| 56 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 57 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 57 } | 58 } |
| 58 MOCK_METHOD0(SetForceKeepSessionState, void()); | 59 MOCK_METHOD0(SetForceKeepSessionState, void()); |
| 59 | 60 |
| 60 private: | 61 private: |
| 61 virtual ~NewMockPersistentCookieStore() {} | 62 virtual ~NewMockPersistentCookieStore() {} |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 const char kTopLevelDomainPlus1[] = "http://www.harvard.edu"; | 65 const char kTopLevelDomainPlus1[] = "http://www.harvard.edu"; |
| 65 const char kTopLevelDomainPlus2[] = "http://www.math.harvard.edu"; | 66 const char kTopLevelDomainPlus2[] = "http://www.math.harvard.edu"; |
| 66 const char kTopLevelDomainPlus2Secure[] = "https://www.math.harvard.edu"; | 67 const char kTopLevelDomainPlus2Secure[] = "https://www.math.harvard.edu"; |
| 67 const char kTopLevelDomainPlus3[] = | 68 const char kTopLevelDomainPlus3[] = "http://www.bourbaki.math.harvard.edu"; |
| 68 "http://www.bourbaki.math.harvard.edu"; | |
| 69 const char kOtherDomain[] = "http://www.mit.edu"; | 69 const char kOtherDomain[] = "http://www.mit.edu"; |
| 70 const char kUrlGoogleSpecific[] = "http://www.gmail.google.izzle"; | 70 const char kUrlGoogleSpecific[] = "http://www.gmail.google.izzle"; |
| 71 | 71 |
| 72 class GetCookieListCallback : public CookieCallback { | 72 class GetCookieListCallback : public CookieCallback { |
| 73 public: | 73 public: |
| 74 GetCookieListCallback() {} | 74 GetCookieListCallback() {} |
| 75 explicit GetCookieListCallback(Thread* run_in_thread) | 75 explicit GetCookieListCallback(Thread* run_in_thread) |
| 76 : CookieCallback(run_in_thread) {} | 76 : CookieCallback(run_in_thread) {} |
| 77 | 77 |
| 78 void Run(const CookieList& cookies) { | 78 void Run(const CookieList& cookies) { |
| 79 cookies_ = cookies; | 79 cookies_ = cookies; |
| 80 CallbackEpilogue(); | 80 CallbackEpilogue(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 const CookieList& cookies() { return cookies_; } | 83 const CookieList& cookies() { return cookies_; } |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 CookieList cookies_; | 86 CookieList cookies_; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 struct CookieMonsterTestTraits { | 89 struct CookieMonsterTestTraits { |
| 90 static scoped_refptr<CookieStore> Create() { | 90 static scoped_refptr<CookieStore> Create() { |
| 91 return new CookieMonster(NULL, NULL); | 91 return new CookieMonster(NULL, NULL); |
| 92 } | 92 } |
| 93 | 93 |
| 94 static const bool is_cookie_monster = true; | 94 static const bool is_cookie_monster = true; |
| 95 static const bool supports_http_only = true; | 95 static const bool supports_http_only = true; |
| 96 static const bool supports_non_dotted_domains = true; | 96 static const bool supports_non_dotted_domains = true; |
| 97 static const bool supports_trailing_dots = true; | 97 static const bool supports_trailing_dots = true; |
| 98 static const bool filters_schemes = true; | 98 static const bool filters_schemes = true; |
| 99 static const bool has_path_prefix_bug = false; | 99 static const bool has_path_prefix_bug = false; |
| 100 static const int creation_time_granularity_in_ms = 0; | 100 static const int creation_time_granularity_in_ms = 0; |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, | 103 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, |
| 104 CookieStoreTest, | 104 CookieStoreTest, |
| 105 CookieMonsterTestTraits); | 105 CookieMonsterTestTraits); |
| 106 | 106 |
| 107 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, | 107 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, |
| 108 MultiThreadedCookieStoreTest, | 108 MultiThreadedCookieStoreTest, |
| 109 CookieMonsterTestTraits); | 109 CookieMonsterTestTraits); |
| 110 | 110 |
| 111 class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> { | 111 class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> { |
| 112 protected: | 112 protected: |
| 113 | |
| 114 CookieList GetAllCookies(CookieMonster* cm) { | 113 CookieList GetAllCookies(CookieMonster* cm) { |
| 115 DCHECK(cm); | 114 DCHECK(cm); |
| 116 GetCookieListCallback callback; | 115 GetCookieListCallback callback; |
| 117 cm->GetAllCookiesAsync( | 116 cm->GetAllCookiesAsync( |
| 118 base::Bind(&GetCookieListCallback::Run, | 117 base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback))); |
| 119 base::Unretained(&callback))); | |
| 120 RunFor(kTimeout); | 118 RunFor(kTimeout); |
| 121 EXPECT_TRUE(callback.did_run()); | 119 EXPECT_TRUE(callback.did_run()); |
| 122 return callback.cookies(); | 120 return callback.cookies(); |
| 123 } | 121 } |
| 124 | 122 |
| 125 CookieList GetAllCookiesForURL(CookieMonster* cm, | 123 CookieList GetAllCookiesForURL(CookieMonster* cm, const GURL& url) { |
| 126 const GURL& url) { | |
| 127 DCHECK(cm); | 124 DCHECK(cm); |
| 128 GetCookieListCallback callback; | 125 GetCookieListCallback callback; |
| 129 cm->GetAllCookiesForURLAsync( | 126 cm->GetAllCookiesForURLAsync(url, base::Bind(&GetCookieListCallback::Run, |
| 130 url, base::Bind(&GetCookieListCallback::Run, | 127 base::Unretained(&callback))); |
| 131 base::Unretained(&callback))); | |
| 132 RunFor(kTimeout); | 128 RunFor(kTimeout); |
| 133 EXPECT_TRUE(callback.did_run()); | 129 EXPECT_TRUE(callback.did_run()); |
| 134 return callback.cookies(); | 130 return callback.cookies(); |
| 135 } | 131 } |
| 136 | 132 |
| 137 CookieList GetAllCookiesForURLWithOptions(CookieMonster* cm, | 133 CookieList GetAllCookiesForURLWithOptions(CookieMonster* cm, |
| 138 const GURL& url, | 134 const GURL& url, |
| 139 const CookieOptions& options) { | 135 const CookieOptions& options) { |
| 140 DCHECK(cm); | 136 DCHECK(cm); |
| 141 GetCookieListCallback callback; | 137 GetCookieListCallback callback; |
| 142 cm->GetAllCookiesForURLWithOptionsAsync( | 138 cm->GetAllCookiesForURLWithOptionsAsync( |
| 143 url, options, base::Bind(&GetCookieListCallback::Run, | 139 url, options, |
| 144 base::Unretained(&callback))); | 140 base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback))); |
| 145 RunFor(kTimeout); | 141 RunFor(kTimeout); |
| 146 EXPECT_TRUE(callback.did_run()); | 142 EXPECT_TRUE(callback.did_run()); |
| 147 return callback.cookies(); | 143 return callback.cookies(); |
| 148 } | 144 } |
| 149 | 145 |
| 150 bool SetCookieWithDetails(CookieMonster* cm, | 146 bool SetCookieWithDetails(CookieMonster* cm, |
| 151 const GURL& url, | 147 const GURL& url, |
| 152 const std::string& name, | 148 const std::string& name, |
| 153 const std::string& value, | 149 const std::string& value, |
| 154 const std::string& domain, | 150 const std::string& domain, |
| 155 const std::string& path, | 151 const std::string& path, |
| 156 const base::Time& expiration_time, | 152 const base::Time& expiration_time, |
| 157 bool secure, | 153 bool secure, |
| 158 bool http_only, | 154 bool http_only, |
| 159 CookiePriority priority) { | 155 CookiePriority priority) { |
| 160 DCHECK(cm); | 156 DCHECK(cm); |
| 161 ResultSavingCookieCallback<bool> callback; | 157 ResultSavingCookieCallback<bool> callback; |
| 162 cm->SetCookieWithDetailsAsync( | 158 cm->SetCookieWithDetailsAsync( |
| 163 url, name, value, domain, path, expiration_time, secure, http_only, | 159 url, name, value, domain, path, expiration_time, secure, http_only, |
| 164 priority, | 160 priority, base::Bind(&ResultSavingCookieCallback<bool>::Run, |
| 165 base::Bind( | 161 base::Unretained(&callback))); |
| 166 &ResultSavingCookieCallback<bool>::Run, | |
| 167 base::Unretained(&callback))); | |
| 168 RunFor(kTimeout); | 162 RunFor(kTimeout); |
| 169 EXPECT_TRUE(callback.did_run()); | 163 EXPECT_TRUE(callback.did_run()); |
| 170 return callback.result(); | 164 return callback.result(); |
| 171 } | 165 } |
| 172 | 166 |
| 173 int DeleteAll(CookieMonster*cm) { | 167 int DeleteAll(CookieMonster* cm) { |
| 174 DCHECK(cm); | 168 DCHECK(cm); |
| 175 ResultSavingCookieCallback<int> callback; | 169 ResultSavingCookieCallback<int> callback; |
| 176 cm->DeleteAllAsync( | 170 cm->DeleteAllAsync(base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 177 base::Bind( | 171 base::Unretained(&callback))); |
| 178 &ResultSavingCookieCallback<int>::Run, | |
| 179 base::Unretained(&callback))); | |
| 180 RunFor(kTimeout); | 172 RunFor(kTimeout); |
| 181 EXPECT_TRUE(callback.did_run()); | 173 EXPECT_TRUE(callback.did_run()); |
| 182 return callback.result(); | 174 return callback.result(); |
| 183 } | 175 } |
| 184 | 176 |
| 185 int DeleteAllCreatedBetween(CookieMonster*cm, | 177 int DeleteAllCreatedBetween(CookieMonster* cm, |
| 186 const base::Time& delete_begin, | 178 const base::Time& delete_begin, |
| 187 const base::Time& delete_end) { | 179 const base::Time& delete_end) { |
| 188 DCHECK(cm); | 180 DCHECK(cm); |
| 189 ResultSavingCookieCallback<int> callback; | 181 ResultSavingCookieCallback<int> callback; |
| 190 cm->DeleteAllCreatedBetweenAsync( | 182 cm->DeleteAllCreatedBetweenAsync( |
| 191 delete_begin, delete_end, | 183 delete_begin, delete_end, |
| 192 base::Bind( | 184 base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 193 &ResultSavingCookieCallback<int>::Run, | 185 base::Unretained(&callback))); |
| 194 base::Unretained(&callback))); | |
| 195 RunFor(kTimeout); | 186 RunFor(kTimeout); |
| 196 EXPECT_TRUE(callback.did_run()); | 187 EXPECT_TRUE(callback.did_run()); |
| 197 return callback.result(); | 188 return callback.result(); |
| 198 } | 189 } |
| 199 | 190 |
| 200 int DeleteAllCreatedBetweenForHost(CookieMonster* cm, | 191 int DeleteAllCreatedBetweenForHost(CookieMonster* cm, |
| 201 const base::Time delete_begin, | 192 const base::Time delete_begin, |
| 202 const base::Time delete_end, | 193 const base::Time delete_end, |
| 203 const GURL& url) { | 194 const GURL& url) { |
| 204 DCHECK(cm); | 195 DCHECK(cm); |
| 205 ResultSavingCookieCallback<int> callback; | 196 ResultSavingCookieCallback<int> callback; |
| 206 cm->DeleteAllCreatedBetweenForHostAsync( | 197 cm->DeleteAllCreatedBetweenForHostAsync( |
| 207 delete_begin, delete_end, url, | 198 delete_begin, delete_end, url, |
| 208 base::Bind( | 199 base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 209 &ResultSavingCookieCallback<int>::Run, | 200 base::Unretained(&callback))); |
| 210 base::Unretained(&callback))); | |
| 211 RunFor(kTimeout); | 201 RunFor(kTimeout); |
| 212 EXPECT_TRUE(callback.did_run()); | 202 EXPECT_TRUE(callback.did_run()); |
| 213 return callback.result(); | 203 return callback.result(); |
| 214 } | 204 } |
| 215 | 205 |
| 216 int DeleteAllForHost(CookieMonster* cm, | 206 int DeleteAllForHost(CookieMonster* cm, const GURL& url) { |
| 217 const GURL& url) { | |
| 218 DCHECK(cm); | 207 DCHECK(cm); |
| 219 ResultSavingCookieCallback<int> callback; | 208 ResultSavingCookieCallback<int> callback; |
| 220 cm->DeleteAllForHostAsync( | 209 cm->DeleteAllForHostAsync(url, |
| 221 url, base::Bind(&ResultSavingCookieCallback<int>::Run, | 210 base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 222 base::Unretained(&callback))); | 211 base::Unretained(&callback))); |
| 223 RunFor(kTimeout); | 212 RunFor(kTimeout); |
| 224 EXPECT_TRUE(callback.did_run()); | 213 EXPECT_TRUE(callback.did_run()); |
| 225 return callback.result(); | 214 return callback.result(); |
| 226 } | 215 } |
| 227 | 216 |
| 228 bool DeleteCanonicalCookie(CookieMonster* cm, const CanonicalCookie& cookie) { | 217 bool DeleteCanonicalCookie(CookieMonster* cm, const CanonicalCookie& cookie) { |
| 229 DCHECK(cm); | 218 DCHECK(cm); |
| 230 ResultSavingCookieCallback<bool> callback; | 219 ResultSavingCookieCallback<bool> callback; |
| 231 cm->DeleteCanonicalCookieAsync( | 220 cm->DeleteCanonicalCookieAsync( |
| 232 cookie, | 221 cookie, base::Bind(&ResultSavingCookieCallback<bool>::Run, |
| 233 base::Bind(&ResultSavingCookieCallback<bool>::Run, | 222 base::Unretained(&callback))); |
| 234 base::Unretained(&callback))); | |
| 235 RunFor(kTimeout); | 223 RunFor(kTimeout); |
| 236 EXPECT_TRUE(callback.did_run()); | 224 EXPECT_TRUE(callback.did_run()); |
| 237 return callback.result(); | 225 return callback.result(); |
| 238 } | 226 } |
| 239 | 227 |
| 240 // Helper for DeleteAllForHost test; repopulates CM with same layout | 228 // Helper for DeleteAllForHost test; repopulates CM with same layout |
| 241 // each time. | 229 // each time. |
| 242 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) { | 230 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) { |
| 243 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); | 231 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); |
| 244 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2); | 232 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2); |
| 245 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); | 233 GURL url_top_level_domain_plus_2_secure(kTopLevelDomainPlus2Secure); |
| 246 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); | 234 GURL url_top_level_domain_plus_3(kTopLevelDomainPlus3); |
| 247 GURL url_other(kOtherDomain); | 235 GURL url_other(kOtherDomain); |
| 248 | 236 |
| 249 DeleteAll(cm.get()); | 237 DeleteAll(cm.get()); |
| 250 | 238 |
| 251 // Static population for probe: | 239 // Static population for probe: |
| 252 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a) | 240 // * Three levels of domain cookie (.b.a, .c.b.a, .d.c.b.a) |
| 253 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a) | 241 // * Three levels of host cookie (w.b.a, w.c.b.a, w.d.c.b.a) |
| 254 // * http_only cookie (w.c.b.a) | 242 // * http_only cookie (w.c.b.a) |
| 255 // * Two secure cookies (.c.b.a, w.c.b.a) | 243 // * Two secure cookies (.c.b.a, w.c.b.a) |
| 256 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) | 244 // * Two domain path cookies (.c.b.a/dir1, .c.b.a/dir1/dir2) |
| 257 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) | 245 // * Two host path cookies (w.c.b.a/dir1, w.c.b.a/dir1/dir2) |
| 258 | 246 |
| 259 // Domain cookies | 247 // Domain cookies |
| 260 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(), | 248 EXPECT_TRUE(this->SetCookieWithDetails( |
| 261 url_top_level_domain_plus_1, | 249 cm.get(), url_top_level_domain_plus_1, "dom_1", "X", ".harvard.edu", |
| 262 "dom_1", | 250 "/", base::Time(), false, false, COOKIE_PRIORITY_DEFAULT)); |
| 263 "X", | 251 EXPECT_TRUE(this->SetCookieWithDetails( |
| 264 ".harvard.edu", | 252 cm.get(), url_top_level_domain_plus_2, "dom_2", "X", |
| 265 "/", | 253 ".math.harvard.edu", "/", base::Time(), false, false, |
| 266 base::Time(), | 254 COOKIE_PRIORITY_DEFAULT)); |
| 267 false, | 255 EXPECT_TRUE(this->SetCookieWithDetails( |
| 268 false, | 256 cm.get(), url_top_level_domain_plus_3, "dom_3", "X", |
| 269 COOKIE_PRIORITY_DEFAULT)); | 257 ".bourbaki.math.harvard.edu", "/", base::Time(), false, false, |
| 270 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(), | 258 COOKIE_PRIORITY_DEFAULT)); |
| 271 url_top_level_domain_plus_2, | |
| 272 "dom_2", | |
| 273 "X", | |
| 274 ".math.harvard.edu", | |
| 275 "/", | |
| 276 base::Time(), | |
| 277 false, | |
| 278 false, | |
| 279 COOKIE_PRIORITY_DEFAULT)); | |
| 280 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(), | |
| 281 url_top_level_domain_plus_3, | |
| 282 "dom_3", | |
| 283 "X", | |
| 284 ".bourbaki.math.harvard.edu", | |
| 285 "/", | |
| 286 base::Time(), | |
| 287 false, | |
| 288 false, | |
| 289 COOKIE_PRIORITY_DEFAULT)); | |
| 290 | 259 |
| 291 // Host cookies | 260 // Host cookies |
| 292 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(), | 261 EXPECT_TRUE(this->SetCookieWithDetails( |
| 293 url_top_level_domain_plus_1, | 262 cm.get(), url_top_level_domain_plus_1, "host_1", "X", std::string(), |
| 294 "host_1", | 263 "/", base::Time(), false, false, COOKIE_PRIORITY_DEFAULT)); |
| 295 "X", | 264 EXPECT_TRUE(this->SetCookieWithDetails( |
| 296 std::string(), | 265 cm.get(), url_top_level_domain_plus_2, "host_2", "X", std::string(), |
| 297 "/", | 266 "/", base::Time(), false, false, COOKIE_PRIORITY_DEFAULT)); |
| 298 base::Time(), | 267 EXPECT_TRUE(this->SetCookieWithDetails( |
| 299 false, | 268 cm.get(), url_top_level_domain_plus_3, "host_3", "X", std::string(), |
| 300 false, | 269 "/", base::Time(), false, false, COOKIE_PRIORITY_DEFAULT)); |
| 301 COOKIE_PRIORITY_DEFAULT)); | |
| 302 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(), | |
| 303 url_top_level_domain_plus_2, | |
| 304 "host_2", | |
| 305 "X", | |
| 306 std::string(), | |
| 307 "/", | |
| 308 base::Time(), | |
| 309 false, | |
| 310 false, | |
| 311 COOKIE_PRIORITY_DEFAULT)); | |
| 312 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(), | |
| 313 url_top_level_domain_plus_3, | |
| 314 "host_3", | |
| 315 "X", | |
| 316 std::string(), | |
| 317 "/", | |
| 318 base::Time(), | |
| 319 false, | |
| 320 false, | |
| 321 COOKIE_PRIORITY_DEFAULT)); | |
| 322 | 270 |
| 323 // Http_only cookie | 271 // Http_only cookie |
| 324 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(), | 272 EXPECT_TRUE(this->SetCookieWithDetails( |
| 325 url_top_level_domain_plus_2, | 273 cm.get(), url_top_level_domain_plus_2, "httpo_check", "X", |
| 326 "httpo_check", | 274 std::string(), "/", base::Time(), false, true, |
| 327 "X", | 275 COOKIE_PRIORITY_DEFAULT)); |
| 328 std::string(), | |
| 329 "/", | |
| 330 base::Time(), | |
| 331 false, | |
| 332 true, | |
| 333 COOKIE_PRIORITY_DEFAULT)); | |
| 334 | 276 |
| 335 // Secure cookies | 277 // Secure cookies |
| 336 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(), | 278 EXPECT_TRUE(this->SetCookieWithDetails( |
| 337 url_top_level_domain_plus_2_secure, | 279 cm.get(), url_top_level_domain_plus_2_secure, "sec_dom", "X", |
| 338 "sec_dom", | 280 ".math.harvard.edu", "/", base::Time(), true, false, |
| 339 "X", | 281 COOKIE_PRIORITY_DEFAULT)); |
| 340 ".math.harvard.edu", | 282 EXPECT_TRUE(this->SetCookieWithDetails( |
| 341 "/", | 283 cm.get(), url_top_level_domain_plus_2_secure, "sec_host", "X", |
| 342 base::Time(), | 284 std::string(), "/", base::Time(), true, false, |
| 343 true, | 285 COOKIE_PRIORITY_DEFAULT)); |
| 344 false, | |
| 345 COOKIE_PRIORITY_DEFAULT)); | |
| 346 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(), | |
| 347 url_top_level_domain_plus_2_secure, | |
| 348 "sec_host", | |
| 349 "X", | |
| 350 std::string(), | |
| 351 "/", | |
| 352 base::Time(), | |
| 353 true, | |
| 354 false, | |
| 355 COOKIE_PRIORITY_DEFAULT)); | |
| 356 | 286 |
| 357 // Domain path cookies | 287 // Domain path cookies |
| 358 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(), | 288 EXPECT_TRUE(this->SetCookieWithDetails( |
| 359 url_top_level_domain_plus_2, | 289 cm.get(), url_top_level_domain_plus_2, "dom_path_1", "X", |
| 360 "dom_path_1", | 290 ".math.harvard.edu", "/dir1", base::Time(), false, false, |
| 361 "X", | 291 COOKIE_PRIORITY_DEFAULT)); |
| 362 ".math.harvard.edu", | 292 EXPECT_TRUE(this->SetCookieWithDetails( |
| 363 "/dir1", | 293 cm.get(), url_top_level_domain_plus_2, "dom_path_2", "X", |
| 364 base::Time(), | 294 ".math.harvard.edu", "/dir1/dir2", base::Time(), false, false, |
| 365 false, | 295 COOKIE_PRIORITY_DEFAULT)); |
| 366 false, | |
| 367 COOKIE_PRIORITY_DEFAULT)); | |
| 368 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(), | |
| 369 url_top_level_domain_plus_2, | |
| 370 "dom_path_2", | |
| 371 "X", | |
| 372 ".math.harvard.edu", | |
| 373 "/dir1/dir2", | |
| 374 base::Time(), | |
| 375 false, | |
| 376 false, | |
| 377 COOKIE_PRIORITY_DEFAULT)); | |
| 378 | 296 |
| 379 // Host path cookies | 297 // Host path cookies |
| 380 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(), | 298 EXPECT_TRUE(this->SetCookieWithDetails( |
| 381 url_top_level_domain_plus_2, | 299 cm.get(), url_top_level_domain_plus_2, "host_path_1", "X", |
| 382 "host_path_1", | 300 std::string(), "/dir1", base::Time(), false, false, |
| 383 "X", | 301 COOKIE_PRIORITY_DEFAULT)); |
| 384 std::string(), | 302 EXPECT_TRUE(this->SetCookieWithDetails( |
| 385 "/dir1", | 303 cm.get(), url_top_level_domain_plus_2, "host_path_2", "X", |
| 386 base::Time(), | 304 std::string(), "/dir1/dir2", base::Time(), false, false, |
| 387 false, | 305 COOKIE_PRIORITY_DEFAULT)); |
| 388 false, | |
| 389 COOKIE_PRIORITY_DEFAULT)); | |
| 390 EXPECT_TRUE(this->SetCookieWithDetails(cm.get(), | |
| 391 url_top_level_domain_plus_2, | |
| 392 "host_path_2", | |
| 393 "X", | |
| 394 std::string(), | |
| 395 "/dir1/dir2", | |
| 396 base::Time(), | |
| 397 false, | |
| 398 false, | |
| 399 COOKIE_PRIORITY_DEFAULT)); | |
| 400 | 306 |
| 401 EXPECT_EQ(13U, this->GetAllCookies(cm.get()).size()); | 307 EXPECT_EQ(13U, this->GetAllCookies(cm.get()).size()); |
| 402 } | 308 } |
| 403 | 309 |
| 404 Time GetFirstCookieAccessDate(CookieMonster* cm) { | 310 Time GetFirstCookieAccessDate(CookieMonster* cm) { |
| 405 const CookieList all_cookies(this->GetAllCookies(cm)); | 311 const CookieList all_cookies(this->GetAllCookies(cm)); |
| 406 return all_cookies.front().LastAccessDate(); | 312 return all_cookies.front().LastAccessDate(); |
| 407 } | 313 } |
| 408 | 314 |
| 409 bool FindAndDeleteCookie(CookieMonster* cm, | 315 bool FindAndDeleteCookie(CookieMonster* cm, |
| 410 const std::string& domain, | 316 const std::string& domain, |
| 411 const std::string& name) { | 317 const std::string& name) { |
| 412 CookieList cookies = this->GetAllCookies(cm); | 318 CookieList cookies = this->GetAllCookies(cm); |
| 413 for (CookieList::iterator it = cookies.begin(); | 319 for (CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it) |
| 414 it != cookies.end(); ++it) | |
| 415 if (it->Domain() == domain && it->Name() == name) | 320 if (it->Domain() == domain && it->Name() == name) |
| 416 return this->DeleteCanonicalCookie(cm, *it); | 321 return this->DeleteCanonicalCookie(cm, *it); |
| 417 return false; | 322 return false; |
| 418 } | 323 } |
| 419 | 324 |
| 420 int CountInString(const std::string& str, char c) { | 325 int CountInString(const std::string& str, char c) { |
| 421 return std::count(str.begin(), str.end(), c); | 326 return std::count(str.begin(), str.end(), c); |
| 422 } | 327 } |
| 423 | 328 |
| 424 void TestHostGarbageCollectHelper() { | 329 void TestHostGarbageCollectHelper() { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 bool result = base::StringToInt( | 452 bool result = base::StringToInt( |
| 548 base::StringPiece(it->begin() + 1, it->end() - 2), &id); | 453 base::StringPiece(it->begin() + 1, it->end() - 2), &id); |
| 549 DCHECK(result); | 454 DCHECK(result); |
| 550 DCHECK_GE(id, 0); | 455 DCHECK_GE(id, 0); |
| 551 DCHECK_LT(id, num_cookies); | 456 DCHECK_LT(id, num_cookies); |
| 552 surviving_id_list[priority_list[id]].push_back(id); | 457 surviving_id_list[priority_list[id]].push_back(id); |
| 553 } | 458 } |
| 554 | 459 |
| 555 // Validate each priority. | 460 // Validate each priority. |
| 556 size_t expected_count[3] = { | 461 size_t expected_count[3] = { |
| 557 expected_low_count, expected_medium_count, expected_high_count | 462 expected_low_count, expected_medium_count, expected_high_count}; |
| 558 }; | |
| 559 for (int i = 0; i < 3; ++i) { | 463 for (int i = 0; i < 3; ++i) { |
| 560 DCHECK_LE(surviving_id_list[i].size(), id_list[i].size()); | 464 DCHECK_LE(surviving_id_list[i].size(), id_list[i].size()); |
| 561 EXPECT_EQ(expected_count[i], surviving_id_list[i].size()); | 465 EXPECT_EQ(expected_count[i], surviving_id_list[i].size()); |
| 562 // Verify that the remaining cookies are the most recent among those | 466 // Verify that the remaining cookies are the most recent among those |
| 563 // with the same priorities. | 467 // with the same priorities. |
| 564 if (expected_count[i] == surviving_id_list[i].size()) { | 468 if (expected_count[i] == surviving_id_list[i].size()) { |
| 565 std::sort(surviving_id_list[i].begin(), surviving_id_list[i].end()); | 469 std::sort(surviving_id_list[i].begin(), surviving_id_list[i].end()); |
| 566 EXPECT_TRUE(std::equal(surviving_id_list[i].begin(), | 470 EXPECT_TRUE(std::equal(surviving_id_list[i].begin(), |
| 567 surviving_id_list[i].end(), | 471 surviving_id_list[i].end(), |
| 568 id_list[i].end() - expected_count[i])); | 472 id_list[i].end() - expected_count[i])); |
| 569 } | 473 } |
| 570 } | 474 } |
| 571 } | 475 } |
| 572 | 476 |
| 573 void TestPriorityAwareGarbageCollectHelper() { | 477 void TestPriorityAwareGarbageCollectHelper() { |
| 574 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. | 478 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. |
| 575 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); | 479 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); |
| 576 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - | 480 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - |
| 577 CookieMonster::kDomainPurgeCookies); | 481 CookieMonster::kDomainPurgeCookies); |
| 578 DCHECK_EQ(30U, CookieMonster::kDomainCookiesQuotaLow); | 482 DCHECK_EQ(30U, CookieMonster::kDomainCookiesQuotaLow); |
| 579 DCHECK_EQ(50U, CookieMonster::kDomainCookiesQuotaMedium); | 483 DCHECK_EQ(50U, CookieMonster::kDomainCookiesQuotaMedium); |
| 580 DCHECK_EQ(70U, CookieMonster::kDomainCookiesQuotaHigh); | 484 DCHECK_EQ(70U, CookieMonster::kDomainCookiesQuotaHigh); |
| 581 | 485 |
| 582 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 486 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 583 | 487 |
| 584 // Each test case adds 181 cookies, so 31 cookies are evicted. | 488 // Each test case adds 181 cookies, so 31 cookies are evicted. |
| 585 // Cookie same priority, repeated for each priority. | 489 // Cookie same priority, repeated for each priority. |
| 586 TestPriorityCookieCase(cm.get(), "181L", 150U, 0U, 0U); | 490 TestPriorityCookieCase(cm.get(), "181L", 150U, 0U, 0U); |
| 587 TestPriorityCookieCase(cm.get(), "181M", 0U, 150U, 0U); | 491 TestPriorityCookieCase(cm.get(), "181M", 0U, 150U, 0U); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 603 // Round 1 => none; round 2 => none; round3 => 31H. | 507 // Round 1 => none; round 2 => none; round3 => 31H. |
| 604 TestPriorityCookieCase(cm.get(), "101H 50M 30L", 30U, 50U, 70U); | 508 TestPriorityCookieCase(cm.get(), "101H 50M 30L", 30U, 50U, 70U); |
| 605 | 509 |
| 606 // Round 1 => 10L; round 2 => 10M; round3 => 11H. | 510 // Round 1 => 10L; round 2 => 10M; round3 => 11H. |
| 607 TestPriorityCookieCase(cm.get(), "81H 60M 40L", 30U, 50U, 70U); | 511 TestPriorityCookieCase(cm.get(), "81H 60M 40L", 30U, 50U, 70U); |
| 608 | 512 |
| 609 // More complex scenarios. | 513 // More complex scenarios. |
| 610 // Round 1 => 10L; round 2 => 10M; round 3 => 11H. | 514 // Round 1 => 10L; round 2 => 10M; round 3 => 11H. |
| 611 TestPriorityCookieCase(cm.get(), "21H 60M 40L 60H", 30U, 50U, 70U); | 515 TestPriorityCookieCase(cm.get(), "21H 60M 40L 60H", 30U, 50U, 70U); |
| 612 // Round 1 => 10L; round 2 => 11M, 10L; round 3 => none. | 516 // Round 1 => 10L; round 2 => 11M, 10L; round 3 => none. |
| 613 TestPriorityCookieCase( | 517 TestPriorityCookieCase(cm.get(), "11H 10M 20L 110M 20L 10H", 20U, 109U, |
| 614 cm.get(), "11H 10M 20L 110M 20L 10H", 20U, 109U, 21U); | 518 21U); |
| 615 // Round 1 => none; round 2 => none; round 3 => 11L, 10M, 10H. | 519 // Round 1 => none; round 2 => none; round 3 => 11L, 10M, 10H. |
| 616 TestPriorityCookieCase(cm.get(), "11L 10M 140H 10M 10L", 10U, 10U, 130U); | 520 TestPriorityCookieCase(cm.get(), "11L 10M 140H 10M 10L", 10U, 10U, 130U); |
| 617 // Round 1 => none; round 2 => 1M; round 3 => 10L, 10M, 10H. | 521 // Round 1 => none; round 2 => 1M; round 3 => 10L, 10M, 10H. |
| 618 TestPriorityCookieCase(cm.get(), "11M 10H 10L 60M 90H", 0U, 60U, 90U); | 522 TestPriorityCookieCase(cm.get(), "11M 10H 10L 60M 90H", 0U, 60U, 90U); |
| 619 // Round 1 => none; round 2 => 10L, 21M; round 3 => none. | 523 // Round 1 => none; round 2 => 10L, 21M; round 3 => none. |
| 620 TestPriorityCookieCase(cm.get(), "11M 10H 10L 90M 60H", 0U, 80U, 70U); | 524 TestPriorityCookieCase(cm.get(), "11M 10H 10L 90M 60H", 0U, 80U, 70U); |
| 621 } | 525 } |
| 622 | 526 |
| 623 // Function for creating a CM with a number of cookies in it, | 527 // Function for creating a CM with a number of cookies in it, |
| 624 // no store (and hence no ability to affect access time). | 528 // no store (and hence no ability to affect access time). |
| 625 CookieMonster* CreateMonsterForGC(int num_cookies) { | 529 CookieMonster* CreateMonsterForGC(int num_cookies) { |
| 626 CookieMonster* cm(new CookieMonster(NULL, NULL)); | 530 CookieMonster* cm(new CookieMonster(NULL, NULL)); |
| 627 for (int i = 0; i < num_cookies; i++) { | 531 for (int i = 0; i < num_cookies; i++) { |
| 628 SetCookie(cm, GURL(base::StringPrintf("http://h%05d.izzle", i)), "a=1"); | 532 SetCookie(cm, GURL(base::StringPrintf("http://h%05d.izzle", i)), "a=1"); |
| 629 } | 533 } |
| 630 return cm; | 534 return cm; |
| 631 } | 535 } |
| 632 }; | 536 }; |
| 633 | 537 |
| 634 // TODO(erikwright): Replace the other callbacks and synchronous helper methods | 538 // TODO(erikwright): Replace the other callbacks and synchronous helper methods |
| 635 // in this test suite with these Mocks. | 539 // in this test suite with these Mocks. |
| 636 template<typename T, typename C> class MockCookieCallback { | 540 template <typename T, typename C> |
| 541 class MockCookieCallback { |
| 637 public: | 542 public: |
| 638 C AsCallback() { | 543 C AsCallback() { |
| 639 return base::Bind(&T::Invoke, base::Unretained(static_cast<T*>(this))); | 544 return base::Bind(&T::Invoke, base::Unretained(static_cast<T*>(this))); |
| 640 } | 545 } |
| 641 }; | 546 }; |
| 642 | 547 |
| 643 class MockGetCookiesCallback | 548 class MockGetCookiesCallback |
| 644 : public MockCookieCallback<MockGetCookiesCallback, | 549 : public MockCookieCallback<MockGetCookiesCallback, |
| 645 CookieStore::GetCookiesCallback> { | 550 CookieStore::GetCookiesCallback> { |
| 646 public: | 551 public: |
| 647 MOCK_METHOD1(Invoke, void(const std::string& cookies)); | 552 MOCK_METHOD1(Invoke, void(const std::string& cookies)); |
| 648 }; | 553 }; |
| 649 | 554 |
| 650 class MockSetCookiesCallback | 555 class MockSetCookiesCallback |
| 651 : public MockCookieCallback<MockSetCookiesCallback, | 556 : public MockCookieCallback<MockSetCookiesCallback, |
| 652 CookieStore::SetCookiesCallback> { | 557 CookieStore::SetCookiesCallback> { |
| 653 public: | 558 public: |
| 654 MOCK_METHOD1(Invoke, void(bool success)); | 559 MOCK_METHOD1(Invoke, void(bool success)); |
| 655 }; | 560 }; |
| 656 | 561 |
| 657 class MockClosure | 562 class MockClosure : public MockCookieCallback<MockClosure, base::Closure> { |
| 658 : public MockCookieCallback<MockClosure, base::Closure> { | |
| 659 public: | 563 public: |
| 660 MOCK_METHOD0(Invoke, void(void)); | 564 MOCK_METHOD0(Invoke, void(void)); |
| 661 }; | 565 }; |
| 662 | 566 |
| 663 class MockGetCookieListCallback | 567 class MockGetCookieListCallback |
| 664 : public MockCookieCallback<MockGetCookieListCallback, | 568 : public MockCookieCallback<MockGetCookieListCallback, |
| 665 CookieMonster::GetCookieListCallback> { | 569 CookieMonster::GetCookieListCallback> { |
| 666 public: | 570 public: |
| 667 MOCK_METHOD1(Invoke, void(const CookieList& cookies)); | 571 MOCK_METHOD1(Invoke, void(const CookieList& cookies)); |
| 668 }; | 572 }; |
| 669 | 573 |
| 670 class MockDeleteCallback | 574 class MockDeleteCallback |
| 671 : public MockCookieCallback<MockDeleteCallback, | 575 : public MockCookieCallback<MockDeleteCallback, |
| 672 CookieMonster::DeleteCallback> { | 576 CookieMonster::DeleteCallback> { |
| 673 public: | 577 public: |
| 674 MOCK_METHOD1(Invoke, void(int num_deleted)); | 578 MOCK_METHOD1(Invoke, void(int num_deleted)); |
| 675 }; | 579 }; |
| 676 | 580 |
| 677 class MockDeleteCookieCallback | 581 class MockDeleteCookieCallback |
| 678 : public MockCookieCallback<MockDeleteCookieCallback, | 582 : public MockCookieCallback<MockDeleteCookieCallback, |
| 679 CookieMonster::DeleteCookieCallback> { | 583 CookieMonster::DeleteCookieCallback> { |
| 680 public: | 584 public: |
| 681 MOCK_METHOD1(Invoke, void(bool success)); | 585 MOCK_METHOD1(Invoke, void(bool success)); |
| 682 }; | 586 }; |
| 683 | 587 |
| 684 struct CookiesInputInfo { | 588 struct CookiesInputInfo { |
| 685 const GURL url; | 589 const GURL url; |
| 686 const std::string name; | 590 const std::string name; |
| 687 const std::string value; | 591 const std::string value; |
| 688 const std::string domain; | 592 const std::string domain; |
| 689 const std::string path; | 593 const std::string path; |
| 690 const base::Time expiration_time; | 594 const base::Time expiration_time; |
| 691 bool secure; | 595 bool secure; |
| 692 bool http_only; | 596 bool http_only; |
| 693 CookiePriority priority; | 597 CookiePriority priority; |
| 694 }; | 598 }; |
| 695 | 599 |
| 696 ACTION(QuitCurrentMessageLoop) { | 600 ACTION(QuitCurrentMessageLoop) { |
| 697 base::MessageLoop::current()->PostTask(FROM_HERE, | 601 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 698 base::MessageLoop::QuitClosure()); | 602 base::MessageLoop::QuitClosure()); |
| 699 } | 603 } |
| 700 | 604 |
| 701 // TODO(erikwright): When the synchronous helpers 'GetCookies' etc. are removed, | 605 // TODO(erikwright): When the synchronous helpers 'GetCookies' etc. are removed, |
| 702 // rename these, removing the 'Action' suffix. | 606 // rename these, removing the 'Action' suffix. |
| 703 ACTION_P4(DeleteCookieAction, cookie_monster, url, name, callback) { | 607 ACTION_P4(DeleteCookieAction, cookie_monster, url, name, callback) { |
| 704 cookie_monster->DeleteCookieAsync(url, name, callback->AsCallback()); | 608 cookie_monster->DeleteCookieAsync(url, name, callback->AsCallback()); |
| 705 } | 609 } |
| 706 ACTION_P3(GetCookiesAction, cookie_monster, url, callback) { | 610 ACTION_P3(GetCookiesAction, cookie_monster, url, callback) { |
| 707 cookie_monster->GetCookiesWithOptionsAsync( | 611 cookie_monster->GetCookiesWithOptionsAsync(url, CookieOptions(), |
| 708 url, CookieOptions(), callback->AsCallback()); | 612 callback->AsCallback()); |
| 709 } | 613 } |
| 710 ACTION_P4(SetCookieAction, cookie_monster, url, cookie_line, callback) { | 614 ACTION_P4(SetCookieAction, cookie_monster, url, cookie_line, callback) { |
| 711 cookie_monster->SetCookieWithOptionsAsync( | 615 cookie_monster->SetCookieWithOptionsAsync(url, cookie_line, CookieOptions(), |
| 712 url, cookie_line, CookieOptions(), callback->AsCallback()); | 616 callback->AsCallback()); |
| 713 } | 617 } |
| 714 ACTION_P4(DeleteAllCreatedBetweenAction, | 618 ACTION_P4(DeleteAllCreatedBetweenAction, |
| 715 cookie_monster, delete_begin, delete_end, callback) { | 619 cookie_monster, |
| 716 cookie_monster->DeleteAllCreatedBetweenAsync( | 620 delete_begin, |
| 717 delete_begin, delete_end, callback->AsCallback()); | 621 delete_end, |
| 622 callback) { |
| 623 cookie_monster->DeleteAllCreatedBetweenAsync(delete_begin, delete_end, |
| 624 callback->AsCallback()); |
| 718 } | 625 } |
| 719 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { | 626 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { |
| 720 cookie_monster->SetCookieWithDetailsAsync( | 627 cookie_monster->SetCookieWithDetailsAsync( |
| 721 cc.url, cc.name, cc.value, cc.domain, cc.path, cc.expiration_time, | 628 cc.url, cc.name, cc.value, cc.domain, cc.path, cc.expiration_time, |
| 722 cc.secure, cc.http_only, cc.priority, | 629 cc.secure, cc.http_only, cc.priority, callback->AsCallback()); |
| 723 callback->AsCallback()); | |
| 724 } | 630 } |
| 725 | 631 |
| 726 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { | 632 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { |
| 727 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); | 633 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); |
| 728 } | 634 } |
| 729 | 635 |
| 730 ACTION_P3(DeleteAllForHostAction, cookie_monster, url, callback) { | 636 ACTION_P3(DeleteAllForHostAction, cookie_monster, url, callback) { |
| 731 cookie_monster->DeleteAllForHostAsync(url, callback->AsCallback()); | 637 cookie_monster->DeleteAllForHostAsync(url, callback->AsCallback()); |
| 732 } | 638 } |
| 733 | 639 |
| 734 ACTION_P3(DeleteCanonicalCookieAction, cookie_monster, cookie, callback) { | 640 ACTION_P3(DeleteCanonicalCookieAction, cookie_monster, cookie, callback) { |
| 735 cookie_monster->DeleteCanonicalCookieAsync(cookie, callback->AsCallback()); | 641 cookie_monster->DeleteCanonicalCookieAsync(cookie, callback->AsCallback()); |
| 736 } | 642 } |
| 737 | 643 |
| 738 ACTION_P2(DeleteAllAction, cookie_monster, callback) { | 644 ACTION_P2(DeleteAllAction, cookie_monster, callback) { |
| 739 cookie_monster->DeleteAllAsync(callback->AsCallback()); | 645 cookie_monster->DeleteAllAsync(callback->AsCallback()); |
| 740 } | 646 } |
| 741 | 647 |
| 742 ACTION_P3(GetAllCookiesForUrlWithOptionsAction, cookie_monster, url, callback) { | 648 ACTION_P3(GetAllCookiesForUrlWithOptionsAction, cookie_monster, url, callback) { |
| 743 cookie_monster->GetAllCookiesForURLWithOptionsAsync( | 649 cookie_monster->GetAllCookiesForURLWithOptionsAsync(url, CookieOptions(), |
| 744 url, CookieOptions(), callback->AsCallback()); | 650 callback->AsCallback()); |
| 745 } | 651 } |
| 746 | 652 |
| 747 ACTION_P3(GetAllCookiesForUrlAction, cookie_monster, url, callback) { | 653 ACTION_P3(GetAllCookiesForUrlAction, cookie_monster, url, callback) { |
| 748 cookie_monster->GetAllCookiesForURLAsync(url, callback->AsCallback()); | 654 cookie_monster->GetAllCookiesForURLAsync(url, callback->AsCallback()); |
| 749 } | 655 } |
| 750 | 656 |
| 751 ACTION_P(PushCallbackAction, callback_vector) { | 657 ACTION_P(PushCallbackAction, callback_vector) { |
| 752 callback_vector->push(arg1); | 658 callback_vector->push(arg1); |
| 753 } | 659 } |
| 754 | 660 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 QuitCurrentMessageLoop())); | 733 QuitCurrentMessageLoop())); |
| 828 } | 734 } |
| 829 | 735 |
| 830 // Declares an expectation that PersistentCookieStore::LoadCookiesForKey | 736 // Declares an expectation that PersistentCookieStore::LoadCookiesForKey |
| 831 // will be called, saving the provided callback and sending a quit to the | 737 // will be called, saving the provided callback and sending a quit to the |
| 832 // message loop. | 738 // message loop. |
| 833 void ExpectLoadForKeyCall(std::string key, bool quit_queue) { | 739 void ExpectLoadForKeyCall(std::string key, bool quit_queue) { |
| 834 if (quit_queue) | 740 if (quit_queue) |
| 835 EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_)) | 741 EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_)) |
| 836 .WillOnce( | 742 .WillOnce( |
| 837 testing::DoAll(PushCallbackAction(&loaded_for_key_callbacks_), | 743 testing::DoAll(PushCallbackAction(&loaded_for_key_callbacks_), |
| 838 QuitCurrentMessageLoop())); | 744 QuitCurrentMessageLoop())); |
| 839 else | 745 else |
| 840 EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_)) | 746 EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_)) |
| 841 .WillOnce(PushCallbackAction(&loaded_for_key_callbacks_)); | 747 .WillOnce(PushCallbackAction(&loaded_for_key_callbacks_)); |
| 842 } | 748 } |
| 843 | 749 |
| 844 // Invokes the initial action. | 750 // Invokes the initial action. |
| 845 MOCK_METHOD0(Begin, void(void)); | 751 MOCK_METHOD0(Begin, void(void)); |
| 846 | 752 |
| 847 // Returns the CookieMonster instance under test. | 753 // Returns the CookieMonster instance under test. |
| 848 CookieMonster& cookie_monster() { return *cookie_monster_.get(); } | 754 CookieMonster& cookie_monster() { return *cookie_monster_.get(); } |
| 849 | 755 |
| 850 private: | 756 private: |
| 851 // Declares that mock expectations in this test suite are strictly ordered. | 757 // Declares that mock expectations in this test suite are strictly ordered. |
| 852 testing::InSequence in_sequence_; | 758 testing::InSequence in_sequence_; |
| 853 // Holds cookies to be returned from PersistentCookieStore::Load or | 759 // Holds cookies to be returned from PersistentCookieStore::Load or |
| 854 // PersistentCookieStore::LoadCookiesForKey. | 760 // PersistentCookieStore::LoadCookiesForKey. |
| 855 std::vector<CanonicalCookie*> loaded_cookies_; | 761 std::vector<CanonicalCookie*> loaded_cookies_; |
| 856 // Stores the callback passed from the CookieMonster to the | 762 // Stores the callback passed from the CookieMonster to the |
| 857 // PersistentCookieStore::Load | 763 // PersistentCookieStore::Load |
| 858 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; | 764 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; |
| 859 // Stores the callback passed from the CookieMonster to the | 765 // Stores the callback passed from the CookieMonster to the |
| 860 // PersistentCookieStore::LoadCookiesForKey | 766 // PersistentCookieStore::LoadCookiesForKey |
| 861 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback> | 767 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback> |
| 862 loaded_for_key_callbacks_; | 768 loaded_for_key_callbacks_; |
| 863 | 769 |
| 864 // Stores the CookieMonster under test. | 770 // Stores the CookieMonster under test. |
| 865 scoped_refptr<CookieMonster> cookie_monster_; | 771 scoped_refptr<CookieMonster> cookie_monster_; |
| 866 // Stores the mock PersistentCookieStore. | 772 // Stores the mock PersistentCookieStore. |
| 867 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; | 773 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; |
| 868 }; | 774 }; |
| 869 | 775 |
| 870 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { | 776 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { |
| 871 DeclareLoadedCookie("www.google.izzle", | 777 DeclareLoadedCookie("www.google.izzle", |
| 872 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 778 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 873 Time::Now() + TimeDelta::FromDays(3)); | 779 Time::Now() + TimeDelta::FromDays(3)); |
| 874 | 780 |
| 875 MockGetCookiesCallback get_cookies_callback; | 781 MockGetCookiesCallback get_cookies_callback; |
| 876 | 782 |
| 877 BeginWithForDomainKey("google.izzle", GetCookiesAction( | 783 BeginWithForDomainKey( |
| 878 &cookie_monster(), url_google_, &get_cookies_callback)); | 784 "google.izzle", |
| 785 GetCookiesAction(&cookie_monster(), url_google_, &get_cookies_callback)); |
| 879 | 786 |
| 880 WaitForLoadCall(); | 787 WaitForLoadCall(); |
| 881 | 788 |
| 882 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( | 789 EXPECT_CALL(get_cookies_callback, Invoke("X=1")) |
| 883 GetCookiesAction(&cookie_monster(), url_google_, &get_cookies_callback)); | 790 .WillOnce(GetCookiesAction(&cookie_monster(), url_google_, |
| 884 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( | 791 &get_cookies_callback)); |
| 885 QuitCurrentMessageLoop()); | 792 EXPECT_CALL(get_cookies_callback, Invoke("X=1")) |
| 793 .WillOnce(QuitCurrentMessageLoop()); |
| 886 | 794 |
| 887 CompleteLoadingAndWait(); | 795 CompleteLoadingAndWait(); |
| 888 } | 796 } |
| 889 | 797 |
| 890 TEST_F(DeferredCookieTaskTest, DeferredSetCookie) { | 798 TEST_F(DeferredCookieTaskTest, DeferredSetCookie) { |
| 891 MockSetCookiesCallback set_cookies_callback; | 799 MockSetCookiesCallback set_cookies_callback; |
| 892 | 800 |
| 893 BeginWithForDomainKey("google.izzle", SetCookieAction( | 801 BeginWithForDomainKey("google.izzle", |
| 894 &cookie_monster(), url_google_, "A=B", &set_cookies_callback)); | 802 SetCookieAction(&cookie_monster(), url_google_, "A=B", |
| 803 &set_cookies_callback)); |
| 895 | 804 |
| 896 WaitForLoadCall(); | 805 WaitForLoadCall(); |
| 897 | 806 |
| 898 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( | 807 EXPECT_CALL(set_cookies_callback, Invoke(true)) |
| 899 SetCookieAction( | 808 .WillOnce(SetCookieAction(&cookie_monster(), url_google_, "X=Y", |
| 900 &cookie_monster(), url_google_, "X=Y", &set_cookies_callback)); | 809 &set_cookies_callback)); |
| 901 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( | 810 EXPECT_CALL(set_cookies_callback, Invoke(true)) |
| 902 QuitCurrentMessageLoop()); | 811 .WillOnce(QuitCurrentMessageLoop()); |
| 903 | 812 |
| 904 CompleteLoadingAndWait(); | 813 CompleteLoadingAndWait(); |
| 905 } | 814 } |
| 906 | 815 |
| 907 TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) { | 816 TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) { |
| 908 MockClosure delete_cookie_callback; | 817 MockClosure delete_cookie_callback; |
| 909 | 818 |
| 910 BeginWithForDomainKey("google.izzle", DeleteCookieAction( | 819 BeginWithForDomainKey("google.izzle", |
| 911 &cookie_monster(), url_google_, "A", &delete_cookie_callback)); | 820 DeleteCookieAction(&cookie_monster(), url_google_, "A", |
| 821 &delete_cookie_callback)); |
| 912 | 822 |
| 913 WaitForLoadCall(); | 823 WaitForLoadCall(); |
| 914 | 824 |
| 915 EXPECT_CALL(delete_cookie_callback, Invoke()).WillOnce( | 825 EXPECT_CALL(delete_cookie_callback, Invoke()) |
| 916 DeleteCookieAction( | 826 .WillOnce(DeleteCookieAction(&cookie_monster(), url_google_, "X", |
| 917 &cookie_monster(), url_google_, "X", &delete_cookie_callback)); | 827 &delete_cookie_callback)); |
| 918 EXPECT_CALL(delete_cookie_callback, Invoke()).WillOnce( | 828 EXPECT_CALL(delete_cookie_callback, Invoke()) |
| 919 QuitCurrentMessageLoop()); | 829 .WillOnce(QuitCurrentMessageLoop()); |
| 920 | 830 |
| 921 CompleteLoadingAndWait(); | 831 CompleteLoadingAndWait(); |
| 922 } | 832 } |
| 923 | 833 |
| 924 TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) { | 834 TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) { |
| 925 MockSetCookiesCallback set_cookies_callback; | 835 MockSetCookiesCallback set_cookies_callback; |
| 926 | 836 |
| 927 CookiesInputInfo cookie_info = { | 837 CookiesInputInfo cookie_info = {url_google_foo_, |
| 928 url_google_foo_, "A", "B", std::string(), "/foo", | 838 "A", |
| 929 base::Time(), false, false, COOKIE_PRIORITY_DEFAULT | 839 "B", |
| 930 }; | 840 std::string(), |
| 931 BeginWithForDomainKey("google.izzle", SetCookieWithDetailsAction( | 841 "/foo", |
| 932 &cookie_monster(), cookie_info, &set_cookies_callback)); | 842 base::Time(), |
| 843 false, |
| 844 false, |
| 845 COOKIE_PRIORITY_DEFAULT}; |
| 846 BeginWithForDomainKey( |
| 847 "google.izzle", SetCookieWithDetailsAction(&cookie_monster(), cookie_info, |
| 848 &set_cookies_callback)); |
| 933 | 849 |
| 934 WaitForLoadCall(); | 850 WaitForLoadCall(); |
| 935 | 851 |
| 936 CookiesInputInfo cookie_info_exp = { | 852 CookiesInputInfo cookie_info_exp = {url_google_foo_, |
| 937 url_google_foo_, "A", "B", std::string(), "/foo", | 853 "A", |
| 938 base::Time(), false, false, COOKIE_PRIORITY_DEFAULT | 854 "B", |
| 939 }; | 855 std::string(), |
| 940 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( | 856 "/foo", |
| 941 SetCookieWithDetailsAction( | 857 base::Time(), |
| 942 &cookie_monster(), cookie_info_exp, &set_cookies_callback)); | 858 false, |
| 943 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( | 859 false, |
| 944 QuitCurrentMessageLoop()); | 860 COOKIE_PRIORITY_DEFAULT}; |
| 861 EXPECT_CALL(set_cookies_callback, Invoke(true)) |
| 862 .WillOnce(SetCookieWithDetailsAction(&cookie_monster(), cookie_info_exp, |
| 863 &set_cookies_callback)); |
| 864 EXPECT_CALL(set_cookies_callback, Invoke(true)) |
| 865 .WillOnce(QuitCurrentMessageLoop()); |
| 945 | 866 |
| 946 CompleteLoadingAndWait(); | 867 CompleteLoadingAndWait(); |
| 947 } | 868 } |
| 948 | 869 |
| 949 TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) { | 870 TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) { |
| 950 DeclareLoadedCookie("www.google.izzle", | 871 DeclareLoadedCookie("www.google.izzle", |
| 951 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 872 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 952 Time::Now() + TimeDelta::FromDays(3)); | 873 Time::Now() + TimeDelta::FromDays(3)); |
| 953 | 874 |
| 954 MockGetCookieListCallback get_cookie_list_callback; | 875 MockGetCookieListCallback get_cookie_list_callback; |
| 955 | 876 |
| 956 BeginWith(GetAllCookiesAction( | 877 BeginWith(GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback)); |
| 957 &cookie_monster(), &get_cookie_list_callback)); | |
| 958 | 878 |
| 959 WaitForLoadCall(); | 879 WaitForLoadCall(); |
| 960 | 880 |
| 961 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 881 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) |
| 962 GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback)); | 882 .WillOnce( |
| 963 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 883 GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback)); |
| 964 QuitCurrentMessageLoop()); | 884 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) |
| 885 .WillOnce(QuitCurrentMessageLoop()); |
| 965 | 886 |
| 966 CompleteLoadingAndWait(); | 887 CompleteLoadingAndWait(); |
| 967 } | 888 } |
| 968 | 889 |
| 969 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) { | 890 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) { |
| 970 DeclareLoadedCookie("www.google.izzle", | 891 DeclareLoadedCookie("www.google.izzle", |
| 971 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 892 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 972 Time::Now() + TimeDelta::FromDays(3)); | 893 Time::Now() + TimeDelta::FromDays(3)); |
| 973 | 894 |
| 974 MockGetCookieListCallback get_cookie_list_callback; | 895 MockGetCookieListCallback get_cookie_list_callback; |
| 975 | 896 |
| 976 BeginWithForDomainKey("google.izzle", GetAllCookiesForUrlAction( | 897 BeginWithForDomainKey( |
| 977 &cookie_monster(), url_google_, &get_cookie_list_callback)); | 898 "google.izzle", GetAllCookiesForUrlAction(&cookie_monster(), url_google_, |
| 899 &get_cookie_list_callback)); |
| 978 | 900 |
| 979 WaitForLoadCall(); | 901 WaitForLoadCall(); |
| 980 | 902 |
| 981 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 903 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) |
| 982 GetAllCookiesForUrlAction( | 904 .WillOnce(GetAllCookiesForUrlAction(&cookie_monster(), url_google_, |
| 983 &cookie_monster(), url_google_, &get_cookie_list_callback)); | 905 &get_cookie_list_callback)); |
| 984 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 906 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) |
| 985 QuitCurrentMessageLoop()); | 907 .WillOnce(QuitCurrentMessageLoop()); |
| 986 | 908 |
| 987 CompleteLoadingAndWait(); | 909 CompleteLoadingAndWait(); |
| 988 } | 910 } |
| 989 | 911 |
| 990 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) { | 912 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) { |
| 991 DeclareLoadedCookie("www.google.izzle", | 913 DeclareLoadedCookie("www.google.izzle", |
| 992 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 914 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 993 Time::Now() + TimeDelta::FromDays(3)); | 915 Time::Now() + TimeDelta::FromDays(3)); |
| 994 | 916 |
| 995 MockGetCookieListCallback get_cookie_list_callback; | 917 MockGetCookieListCallback get_cookie_list_callback; |
| 996 | 918 |
| 997 BeginWithForDomainKey("google.izzle", GetAllCookiesForUrlWithOptionsAction( | 919 BeginWithForDomainKey("google.izzle", GetAllCookiesForUrlWithOptionsAction( |
| 998 &cookie_monster(), url_google_, &get_cookie_list_callback)); | 920 &cookie_monster(), url_google_, |
| 921 &get_cookie_list_callback)); |
| 999 | 922 |
| 1000 WaitForLoadCall(); | 923 WaitForLoadCall(); |
| 1001 | 924 |
| 1002 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 925 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) |
| 1003 GetAllCookiesForUrlWithOptionsAction( | 926 .WillOnce(GetAllCookiesForUrlWithOptionsAction( |
| 1004 &cookie_monster(), url_google_, &get_cookie_list_callback)); | 927 &cookie_monster(), url_google_, &get_cookie_list_callback)); |
| 1005 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 928 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) |
| 1006 QuitCurrentMessageLoop()); | 929 .WillOnce(QuitCurrentMessageLoop()); |
| 1007 | 930 |
| 1008 CompleteLoadingAndWait(); | 931 CompleteLoadingAndWait(); |
| 1009 } | 932 } |
| 1010 | 933 |
| 1011 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCookies) { | 934 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCookies) { |
| 1012 MockDeleteCallback delete_callback; | 935 MockDeleteCallback delete_callback; |
| 1013 | 936 |
| 1014 BeginWith(DeleteAllAction( | 937 BeginWith(DeleteAllAction(&cookie_monster(), &delete_callback)); |
| 1015 &cookie_monster(), &delete_callback)); | |
| 1016 | 938 |
| 1017 WaitForLoadCall(); | 939 WaitForLoadCall(); |
| 1018 | 940 |
| 1019 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 941 EXPECT_CALL(delete_callback, Invoke(false)) |
| 1020 DeleteAllAction(&cookie_monster(), &delete_callback)); | 942 .WillOnce(DeleteAllAction(&cookie_monster(), &delete_callback)); |
| 1021 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 943 EXPECT_CALL(delete_callback, Invoke(false)) |
| 1022 QuitCurrentMessageLoop()); | 944 .WillOnce(QuitCurrentMessageLoop()); |
| 1023 | 945 |
| 1024 CompleteLoadingAndWait(); | 946 CompleteLoadingAndWait(); |
| 1025 } | 947 } |
| 1026 | 948 |
| 1027 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCreatedBetweenCookies) { | 949 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCreatedBetweenCookies) { |
| 1028 MockDeleteCallback delete_callback; | 950 MockDeleteCallback delete_callback; |
| 1029 | 951 |
| 1030 BeginWith(DeleteAllCreatedBetweenAction( | 952 BeginWith(DeleteAllCreatedBetweenAction(&cookie_monster(), base::Time(), |
| 1031 &cookie_monster(), base::Time(), base::Time::Now(), &delete_callback)); | 953 base::Time::Now(), &delete_callback)); |
| 1032 | 954 |
| 1033 WaitForLoadCall(); | 955 WaitForLoadCall(); |
| 1034 | 956 |
| 1035 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 957 EXPECT_CALL(delete_callback, Invoke(false)) |
| 1036 DeleteAllCreatedBetweenAction( | 958 .WillOnce(DeleteAllCreatedBetweenAction(&cookie_monster(), base::Time(), |
| 1037 &cookie_monster(), base::Time(), base::Time::Now(), | 959 base::Time::Now(), |
| 1038 &delete_callback)); | 960 &delete_callback)); |
| 1039 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 961 EXPECT_CALL(delete_callback, Invoke(false)) |
| 1040 QuitCurrentMessageLoop()); | 962 .WillOnce(QuitCurrentMessageLoop()); |
| 1041 | 963 |
| 1042 CompleteLoadingAndWait(); | 964 CompleteLoadingAndWait(); |
| 1043 } | 965 } |
| 1044 | 966 |
| 1045 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCookies) { | 967 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCookies) { |
| 1046 MockDeleteCallback delete_callback; | 968 MockDeleteCallback delete_callback; |
| 1047 | 969 |
| 1048 BeginWithForDomainKey("google.izzle", DeleteAllForHostAction( | 970 BeginWithForDomainKey( |
| 1049 &cookie_monster(), url_google_, &delete_callback)); | 971 "google.izzle", |
| 972 DeleteAllForHostAction(&cookie_monster(), url_google_, &delete_callback)); |
| 1050 | 973 |
| 1051 WaitForLoadCall(); | 974 WaitForLoadCall(); |
| 1052 | 975 |
| 1053 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 976 EXPECT_CALL(delete_callback, Invoke(false)) |
| 1054 DeleteAllForHostAction( | 977 .WillOnce(DeleteAllForHostAction(&cookie_monster(), url_google_, |
| 1055 &cookie_monster(), url_google_, &delete_callback)); | 978 &delete_callback)); |
| 1056 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 979 EXPECT_CALL(delete_callback, Invoke(false)) |
| 1057 QuitCurrentMessageLoop()); | 980 .WillOnce(QuitCurrentMessageLoop()); |
| 1058 | 981 |
| 1059 CompleteLoadingAndWait(); | 982 CompleteLoadingAndWait(); |
| 1060 } | 983 } |
| 1061 | 984 |
| 1062 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { | 985 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { |
| 1063 std::vector<CanonicalCookie*> cookies; | 986 std::vector<CanonicalCookie*> cookies; |
| 1064 CanonicalCookie cookie = BuildCanonicalCookie( | 987 CanonicalCookie cookie = |
| 1065 "www.google.com", "X=1; path=/", base::Time::Now()); | 988 BuildCanonicalCookie("www.google.com", "X=1; path=/", base::Time::Now()); |
| 1066 | 989 |
| 1067 MockDeleteCookieCallback delete_cookie_callback; | 990 MockDeleteCookieCallback delete_cookie_callback; |
| 1068 | 991 |
| 1069 BeginWith(DeleteCanonicalCookieAction( | 992 BeginWith(DeleteCanonicalCookieAction(&cookie_monster(), cookie, |
| 1070 &cookie_monster(), cookie, &delete_cookie_callback)); | 993 &delete_cookie_callback)); |
| 1071 | 994 |
| 1072 WaitForLoadCall(); | 995 WaitForLoadCall(); |
| 1073 | 996 |
| 1074 EXPECT_CALL(delete_cookie_callback, Invoke(false)).WillOnce( | 997 EXPECT_CALL(delete_cookie_callback, Invoke(false)) |
| 1075 DeleteCanonicalCookieAction( | 998 .WillOnce(DeleteCanonicalCookieAction(&cookie_monster(), cookie, |
| 1076 &cookie_monster(), cookie, &delete_cookie_callback)); | 999 &delete_cookie_callback)); |
| 1077 EXPECT_CALL(delete_cookie_callback, Invoke(false)).WillOnce( | 1000 EXPECT_CALL(delete_cookie_callback, Invoke(false)) |
| 1078 QuitCurrentMessageLoop()); | 1001 .WillOnce(QuitCurrentMessageLoop()); |
| 1079 | 1002 |
| 1080 CompleteLoadingAndWait(); | 1003 CompleteLoadingAndWait(); |
| 1081 } | 1004 } |
| 1082 | 1005 |
| 1083 TEST_F(DeferredCookieTaskTest, DeferredDeleteSessionCookies) { | 1006 TEST_F(DeferredCookieTaskTest, DeferredDeleteSessionCookies) { |
| 1084 MockDeleteCallback delete_callback; | 1007 MockDeleteCallback delete_callback; |
| 1085 | 1008 |
| 1086 BeginWith(DeleteSessionCookiesAction( | 1009 BeginWith(DeleteSessionCookiesAction(&cookie_monster(), &delete_callback)); |
| 1087 &cookie_monster(), &delete_callback)); | |
| 1088 | 1010 |
| 1089 WaitForLoadCall(); | 1011 WaitForLoadCall(); |
| 1090 | 1012 |
| 1091 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 1013 EXPECT_CALL(delete_callback, Invoke(false)) |
| 1092 DeleteSessionCookiesAction(&cookie_monster(), &delete_callback)); | 1014 .WillOnce( |
| 1093 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 1015 DeleteSessionCookiesAction(&cookie_monster(), &delete_callback)); |
| 1094 QuitCurrentMessageLoop()); | 1016 EXPECT_CALL(delete_callback, Invoke(false)) |
| 1017 .WillOnce(QuitCurrentMessageLoop()); |
| 1095 | 1018 |
| 1096 CompleteLoadingAndWait(); | 1019 CompleteLoadingAndWait(); |
| 1097 } | 1020 } |
| 1098 | 1021 |
| 1099 // Verify that a series of queued tasks are executed in order upon loading of | 1022 // Verify that a series of queued tasks are executed in order upon loading of |
| 1100 // the backing store and that new tasks received while the queued tasks are | 1023 // the backing store and that new tasks received while the queued tasks are |
| 1101 // being dispatched go to the end of the queue. | 1024 // being dispatched go to the end of the queue. |
| 1102 TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) { | 1025 TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) { |
| 1103 DeclareLoadedCookie("www.google.izzle", | 1026 DeclareLoadedCookie("www.google.izzle", |
| 1104 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1027 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1105 Time::Now() + TimeDelta::FromDays(3)); | 1028 Time::Now() + TimeDelta::FromDays(3)); |
| 1106 | 1029 |
| 1107 MockGetCookiesCallback get_cookies_callback; | 1030 MockGetCookiesCallback get_cookies_callback; |
| 1108 MockSetCookiesCallback set_cookies_callback; | 1031 MockSetCookiesCallback set_cookies_callback; |
| 1109 MockGetCookiesCallback get_cookies_callback_deferred; | 1032 MockGetCookiesCallback get_cookies_callback_deferred; |
| 1110 | 1033 |
| 1111 EXPECT_CALL(*this, Begin()).WillOnce(testing::DoAll( | 1034 EXPECT_CALL(*this, Begin()) |
| 1112 GetCookiesAction( | 1035 .WillOnce(testing::DoAll(GetCookiesAction(&cookie_monster(), url_google_, |
| 1113 &cookie_monster(), url_google_, &get_cookies_callback), | 1036 &get_cookies_callback), |
| 1114 SetCookieAction( | 1037 SetCookieAction(&cookie_monster(), url_google_, |
| 1115 &cookie_monster(), url_google_, "A=B", &set_cookies_callback))); | 1038 "A=B", &set_cookies_callback))); |
| 1116 ExpectLoadCall(); | 1039 ExpectLoadCall(); |
| 1117 ExpectLoadForKeyCall("google.izzle", false); | 1040 ExpectLoadForKeyCall("google.izzle", false); |
| 1118 Begin(); | 1041 Begin(); |
| 1119 | 1042 |
| 1120 WaitForLoadCall(); | 1043 WaitForLoadCall(); |
| 1121 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( | 1044 EXPECT_CALL(get_cookies_callback, Invoke("X=1")) |
| 1122 GetCookiesAction( | 1045 .WillOnce(GetCookiesAction(&cookie_monster(), url_google_, |
| 1123 &cookie_monster(), url_google_, &get_cookies_callback_deferred)); | 1046 &get_cookies_callback_deferred)); |
| 1124 EXPECT_CALL(set_cookies_callback, Invoke(true)); | 1047 EXPECT_CALL(set_cookies_callback, Invoke(true)); |
| 1125 EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1")).WillOnce( | 1048 EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1")) |
| 1126 QuitCurrentMessageLoop()); | 1049 .WillOnce(QuitCurrentMessageLoop()); |
| 1127 | 1050 |
| 1128 CompleteLoadingAndWait(); | 1051 CompleteLoadingAndWait(); |
| 1129 } | 1052 } |
| 1130 | 1053 |
| 1131 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { | 1054 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { |
| 1132 scoped_refptr<MockPersistentCookieStore> store( | 1055 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 1133 new MockPersistentCookieStore); | |
| 1134 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 1056 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); |
| 1135 CookieOptions options; | 1057 CookieOptions options; |
| 1136 options.set_include_httponly(); | 1058 options.set_include_httponly(); |
| 1137 | 1059 |
| 1138 EXPECT_TRUE(SetCookie(cm.get(), url_google_, kValidCookieLine)); | 1060 EXPECT_TRUE(SetCookie(cm.get(), url_google_, kValidCookieLine)); |
| 1139 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_)); | 1061 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_)); |
| 1140 | 1062 |
| 1141 EXPECT_TRUE( | 1063 EXPECT_TRUE( |
| 1142 SetCookieWithOptions(cm.get(), url_google_, "C=D; httponly", options)); | 1064 SetCookieWithOptions(cm.get(), url_google_, "C=D; httponly", options)); |
| 1143 EXPECT_EQ("A=B; C=D", GetCookiesWithOptions(cm.get(), url_google_, options)); | 1065 EXPECT_EQ("A=B; C=D", GetCookiesWithOptions(cm.get(), url_google_, options)); |
| 1144 | 1066 |
| 1145 EXPECT_EQ(2, DeleteAll(cm.get())); | 1067 EXPECT_EQ(2, DeleteAll(cm.get())); |
| 1146 EXPECT_EQ("", GetCookiesWithOptions(cm.get(), url_google_, options)); | 1068 EXPECT_EQ("", GetCookiesWithOptions(cm.get(), url_google_, options)); |
| 1147 EXPECT_EQ(0u, store->commands().size()); | 1069 EXPECT_EQ(0u, store->commands().size()); |
| 1148 | 1070 |
| 1149 // Create a persistent cookie. | 1071 // Create a persistent cookie. |
| 1150 EXPECT_TRUE(SetCookie( | 1072 EXPECT_TRUE(SetCookie( |
| 1151 cm.get(), | 1073 cm.get(), url_google_, |
| 1152 url_google_, | |
| 1153 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1074 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1154 ASSERT_EQ(1u, store->commands().size()); | 1075 ASSERT_EQ(1u, store->commands().size()); |
| 1155 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 1076 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 1156 | 1077 |
| 1157 EXPECT_EQ(1, DeleteAll(cm.get())); // sync_to_store = true. | 1078 EXPECT_EQ(1, DeleteAll(cm.get())); // sync_to_store = true. |
| 1158 ASSERT_EQ(2u, store->commands().size()); | 1079 ASSERT_EQ(2u, store->commands().size()); |
| 1159 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 1080 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 1160 | 1081 |
| 1161 EXPECT_EQ("", GetCookiesWithOptions(cm.get(), url_google_, options)); | 1082 EXPECT_EQ("", GetCookiesWithOptions(cm.get(), url_google_, options)); |
| 1162 } | 1083 } |
| 1163 | 1084 |
| 1164 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { | 1085 TEST_F(CookieMonsterTest, TestCookieDeleteAllCreatedBetweenTimestamps) { |
| 1165 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1086 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1166 Time now = Time::Now(); | 1087 Time now = Time::Now(); |
| 1167 | 1088 |
| 1168 // Nothing has been added so nothing should be deleted. | 1089 // Nothing has been added so nothing should be deleted. |
| 1169 EXPECT_EQ( | 1090 EXPECT_EQ(0, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), |
| 1170 0, | 1091 Time())); |
| 1171 DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), Time())); | |
| 1172 | 1092 |
| 1173 // Create 3 cookies with creation date of today, yesterday and the day before. | 1093 // Create 3 cookies with creation date of today, yesterday and the day before. |
| 1174 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-0=Now", now)); | 1094 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-0=Now", now)); |
| 1175 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-1=Yesterday", | 1095 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-1=Yesterday", |
| 1176 now - TimeDelta::FromDays(1))); | 1096 now - TimeDelta::FromDays(1))); |
| 1177 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-2=DayBefore", | 1097 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-2=DayBefore", |
| 1178 now - TimeDelta::FromDays(2))); | 1098 now - TimeDelta::FromDays(2))); |
| 1179 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-3=ThreeDays", | 1099 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-3=ThreeDays", |
| 1180 now - TimeDelta::FromDays(3))); | 1100 now - TimeDelta::FromDays(3))); |
| 1181 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-7=LastWeek", | 1101 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-7=LastWeek", |
| 1182 now - TimeDelta::FromDays(7))); | 1102 now - TimeDelta::FromDays(7))); |
| 1183 | 1103 |
| 1184 // Try to delete threedays and the daybefore. | 1104 // Try to delete threedays and the daybefore. |
| 1185 EXPECT_EQ(2, | 1105 EXPECT_EQ(2, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(3), |
| 1186 DeleteAllCreatedBetween(cm.get(), | 1106 now - TimeDelta::FromDays(1))); |
| 1187 now - TimeDelta::FromDays(3), | |
| 1188 now - TimeDelta::FromDays(1))); | |
| 1189 | 1107 |
| 1190 // Try to delete yesterday, also make sure that delete_end is not | 1108 // Try to delete yesterday, also make sure that delete_end is not |
| 1191 // inclusive. | 1109 // inclusive. |
| 1192 EXPECT_EQ( | 1110 EXPECT_EQ( |
| 1193 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(2), now)); | 1111 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(2), now)); |
| 1194 | 1112 |
| 1195 // Make sure the delete_begin is inclusive. | 1113 // Make sure the delete_begin is inclusive. |
| 1196 EXPECT_EQ( | 1114 EXPECT_EQ( |
| 1197 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(7), now)); | 1115 1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(7), now)); |
| 1198 | 1116 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { | 1185 TEST_F(CookieMonsterTest, GetAllCookiesForURL) { |
| 1268 scoped_refptr<CookieMonster> cm( | 1186 scoped_refptr<CookieMonster> cm( |
| 1269 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); | 1187 new CookieMonster(NULL, NULL, kLastAccessThresholdMilliseconds)); |
| 1270 | 1188 |
| 1271 // Create an httponly cookie. | 1189 // Create an httponly cookie. |
| 1272 CookieOptions options; | 1190 CookieOptions options; |
| 1273 options.set_include_httponly(); | 1191 options.set_include_httponly(); |
| 1274 | 1192 |
| 1275 EXPECT_TRUE( | 1193 EXPECT_TRUE( |
| 1276 SetCookieWithOptions(cm.get(), url_google_, "A=B; httponly", options)); | 1194 SetCookieWithOptions(cm.get(), url_google_, "A=B; httponly", options)); |
| 1277 EXPECT_TRUE(SetCookieWithOptions( | 1195 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, |
| 1278 cm.get(), url_google_, "C=D; domain=.google.izzle", options)); | 1196 "C=D; domain=.google.izzle", options)); |
| 1279 EXPECT_TRUE(SetCookieWithOptions(cm.get(), | 1197 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_secure_, |
| 1280 url_google_secure_, | |
| 1281 "E=F; domain=.google.izzle; secure", | 1198 "E=F; domain=.google.izzle; secure", |
| 1282 options)); | 1199 options)); |
| 1283 | 1200 |
| 1284 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); | 1201 const Time last_access_date(GetFirstCookieAccessDate(cm.get())); |
| 1285 | 1202 |
| 1286 base::PlatformThread::Sleep( | 1203 base::PlatformThread::Sleep( |
| 1287 base::TimeDelta::FromMilliseconds(kAccessDelayMs)); | 1204 base::TimeDelta::FromMilliseconds(kAccessDelayMs)); |
| 1288 | 1205 |
| 1289 // Check cookies for url. | 1206 // Check cookies for url. |
| 1290 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_); | 1207 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 ASSERT_TRUE(++it == cookies.end()); | 1247 ASSERT_TRUE(++it == cookies.end()); |
| 1331 | 1248 |
| 1332 // Reading after a short wait should not update the access date. | 1249 // Reading after a short wait should not update the access date. |
| 1333 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm.get())); | 1250 EXPECT_TRUE(last_access_date == GetFirstCookieAccessDate(cm.get())); |
| 1334 } | 1251 } |
| 1335 | 1252 |
| 1336 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { | 1253 TEST_F(CookieMonsterTest, GetAllCookiesForURLPathMatching) { |
| 1337 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1254 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1338 CookieOptions options; | 1255 CookieOptions options; |
| 1339 | 1256 |
| 1340 EXPECT_TRUE(SetCookieWithOptions( | 1257 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_foo_, "A=B; path=/foo;", |
| 1341 cm.get(), url_google_foo_, "A=B; path=/foo;", options)); | 1258 options)); |
| 1342 EXPECT_TRUE(SetCookieWithOptions( | 1259 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_bar_, "C=D; path=/bar;", |
| 1343 cm.get(), url_google_bar_, "C=D; path=/bar;", options)); | 1260 options)); |
| 1344 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "E=F;", options)); | 1261 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "E=F;", options)); |
| 1345 | 1262 |
| 1346 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_foo_); | 1263 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_foo_); |
| 1347 CookieList::iterator it = cookies.begin(); | 1264 CookieList::iterator it = cookies.begin(); |
| 1348 | 1265 |
| 1349 ASSERT_TRUE(it != cookies.end()); | 1266 ASSERT_TRUE(it != cookies.end()); |
| 1350 EXPECT_EQ("A", it->Name()); | 1267 EXPECT_EQ("A", it->Name()); |
| 1351 EXPECT_EQ("/foo", it->Path()); | 1268 EXPECT_EQ("/foo", it->Path()); |
| 1352 | 1269 |
| 1353 ASSERT_TRUE(++it != cookies.end()); | 1270 ASSERT_TRUE(++it != cookies.end()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1378 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A3; path=/bar")); | 1295 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A3; path=/bar")); |
| 1379 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B1; path=/")); | 1296 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B1; path=/")); |
| 1380 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B2; path=/foo")); | 1297 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B2; path=/foo")); |
| 1381 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B3; path=/bar")); | 1298 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B3; path=/bar")); |
| 1382 | 1299 |
| 1383 DeleteCookie(cm.get(), GURL(std::string(kUrlGoogle) + "/foo/bar"), "A"); | 1300 DeleteCookie(cm.get(), GURL(std::string(kUrlGoogle) + "/foo/bar"), "A"); |
| 1384 | 1301 |
| 1385 CookieList cookies = GetAllCookies(cm.get()); | 1302 CookieList cookies = GetAllCookies(cm.get()); |
| 1386 size_t expected_size = 4; | 1303 size_t expected_size = 4; |
| 1387 EXPECT_EQ(expected_size, cookies.size()); | 1304 EXPECT_EQ(expected_size, cookies.size()); |
| 1388 for (CookieList::iterator it = cookies.begin(); | 1305 for (CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it) { |
| 1389 it != cookies.end(); ++it) { | |
| 1390 EXPECT_NE("A1", it->Value()); | 1306 EXPECT_NE("A1", it->Value()); |
| 1391 EXPECT_NE("A2", it->Value()); | 1307 EXPECT_NE("A2", it->Value()); |
| 1392 } | 1308 } |
| 1393 } | 1309 } |
| 1394 | 1310 |
| 1395 TEST_F(CookieMonsterTest, ImportCookiesFromCookieMonster) { | 1311 TEST_F(CookieMonsterTest, ImportCookiesFromCookieMonster) { |
| 1396 scoped_refptr<CookieMonster> cm_1(new CookieMonster(NULL, NULL)); | 1312 scoped_refptr<CookieMonster> cm_1(new CookieMonster(NULL, NULL)); |
| 1397 CookieOptions options; | 1313 CookieOptions options; |
| 1398 | 1314 |
| 1399 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_foo_, | 1315 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_foo_, |
| 1400 "A1=B; path=/foo;", | 1316 "A1=B; path=/foo;", options)); |
| 1401 options)); | |
| 1402 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_bar_, | 1317 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_bar_, |
| 1403 "A2=D; path=/bar;", | 1318 "A2=D; path=/bar;", options)); |
| 1404 options)); | 1319 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_, "A3=F;", options)); |
| 1405 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_, | |
| 1406 "A3=F;", | |
| 1407 options)); | |
| 1408 | 1320 |
| 1409 CookieList cookies_1 = GetAllCookies(cm_1.get()); | 1321 CookieList cookies_1 = GetAllCookies(cm_1.get()); |
| 1410 scoped_refptr<CookieMonster> cm_2(new CookieMonster(NULL, NULL)); | 1322 scoped_refptr<CookieMonster> cm_2(new CookieMonster(NULL, NULL)); |
| 1411 ASSERT_TRUE(cm_2->ImportCookies(cookies_1)); | 1323 ASSERT_TRUE(cm_2->ImportCookies(cookies_1)); |
| 1412 CookieList cookies_2 = GetAllCookies(cm_2.get()); | 1324 CookieList cookies_2 = GetAllCookies(cm_2.get()); |
| 1413 | 1325 |
| 1414 size_t expected_size = 3; | 1326 size_t expected_size = 3; |
| 1415 EXPECT_EQ(expected_size, cookies_2.size()); | 1327 EXPECT_EQ(expected_size, cookies_2.size()); |
| 1416 | 1328 |
| 1417 CookieList::iterator it = cookies_2.begin(); | 1329 CookieList::iterator it = cookies_2.begin(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1428 EXPECT_EQ("A3", it->Name()); | 1340 EXPECT_EQ("A3", it->Name()); |
| 1429 EXPECT_EQ("/", it->Path()); | 1341 EXPECT_EQ("/", it->Path()); |
| 1430 } | 1342 } |
| 1431 | 1343 |
| 1432 // Tests importing from a persistent cookie store that contains duplicate | 1344 // Tests importing from a persistent cookie store that contains duplicate |
| 1433 // equivalent cookies. This situation should be handled by removing the | 1345 // equivalent cookies. This situation should be handled by removing the |
| 1434 // duplicate cookie (both from the in-memory cache, and from the backing store). | 1346 // duplicate cookie (both from the in-memory cache, and from the backing store). |
| 1435 // | 1347 // |
| 1436 // This is a regression test for: http://crbug.com/17855. | 1348 // This is a regression test for: http://crbug.com/17855. |
| 1437 TEST_F(CookieMonsterTest, DontImportDuplicateCookies) { | 1349 TEST_F(CookieMonsterTest, DontImportDuplicateCookies) { |
| 1438 scoped_refptr<MockPersistentCookieStore> store( | 1350 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 1439 new MockPersistentCookieStore); | |
| 1440 | 1351 |
| 1441 // We will fill some initial cookies into the PersistentCookieStore, | 1352 // We will fill some initial cookies into the PersistentCookieStore, |
| 1442 // to simulate a database with 4 duplicates. Note that we need to | 1353 // to simulate a database with 4 duplicates. Note that we need to |
| 1443 // be careful not to have any duplicate creation times at all (as it's a | 1354 // be careful not to have any duplicate creation times at all (as it's a |
| 1444 // violation of a CookieMonster invariant) even if Time::Now() doesn't | 1355 // violation of a CookieMonster invariant) even if Time::Now() doesn't |
| 1445 // move between calls. | 1356 // move between calls. |
| 1446 std::vector<CanonicalCookie*> initial_cookies; | 1357 std::vector<CanonicalCookie*> initial_cookies; |
| 1447 | 1358 |
| 1448 // Insert 4 cookies with name "X" on path "/", with varying creation | 1359 // Insert 4 cookies with name "X" on path "/", with varying creation |
| 1449 // dates. We expect only the most recent one to be preserved following | 1360 // dates. We expect only the most recent one to be preserved following |
| 1450 // the import. | 1361 // the import. |
| 1451 | 1362 |
| 1452 AddCookieToList("www.google.com", | 1363 AddCookieToList("www.google.com", |
| 1453 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1364 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1454 Time::Now() + TimeDelta::FromDays(3), | 1365 Time::Now() + TimeDelta::FromDays(3), &initial_cookies); |
| 1455 &initial_cookies); | |
| 1456 | 1366 |
| 1457 AddCookieToList("www.google.com", | 1367 AddCookieToList("www.google.com", |
| 1458 "X=2; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1368 "X=2; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1459 Time::Now() + TimeDelta::FromDays(1), | 1369 Time::Now() + TimeDelta::FromDays(1), &initial_cookies); |
| 1460 &initial_cookies); | |
| 1461 | 1370 |
| 1462 // ===> This one is the WINNER (biggest creation time). <==== | 1371 // ===> This one is the WINNER (biggest creation time). <==== |
| 1463 AddCookieToList("www.google.com", | 1372 AddCookieToList("www.google.com", |
| 1464 "X=3; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1373 "X=3; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1465 Time::Now() + TimeDelta::FromDays(4), | 1374 Time::Now() + TimeDelta::FromDays(4), &initial_cookies); |
| 1466 &initial_cookies); | |
| 1467 | 1375 |
| 1468 AddCookieToList("www.google.com", | 1376 AddCookieToList("www.google.com", |
| 1469 "X=4; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1377 "X=4; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1470 Time::Now(), | 1378 Time::Now(), &initial_cookies); |
| 1471 &initial_cookies); | |
| 1472 | 1379 |
| 1473 // Insert 2 cookies with name "X" on path "/2", with varying creation | 1380 // Insert 2 cookies with name "X" on path "/2", with varying creation |
| 1474 // dates. We expect only the most recent one to be preserved the import. | 1381 // dates. We expect only the most recent one to be preserved the import. |
| 1475 | 1382 |
| 1476 // ===> This one is the WINNER (biggest creation time). <==== | 1383 // ===> This one is the WINNER (biggest creation time). <==== |
| 1477 AddCookieToList("www.google.com", | 1384 AddCookieToList("www.google.com", |
| 1478 "X=a1; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1385 "X=a1; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1479 Time::Now() + TimeDelta::FromDays(9), | 1386 Time::Now() + TimeDelta::FromDays(9), &initial_cookies); |
| 1480 &initial_cookies); | |
| 1481 | 1387 |
| 1482 AddCookieToList("www.google.com", | 1388 AddCookieToList("www.google.com", |
| 1483 "X=a2; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1389 "X=a2; path=/2; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1484 Time::Now() + TimeDelta::FromDays(2), | 1390 Time::Now() + TimeDelta::FromDays(2), &initial_cookies); |
| 1485 &initial_cookies); | |
| 1486 | 1391 |
| 1487 // Insert 1 cookie with name "Y" on path "/". | 1392 // Insert 1 cookie with name "Y" on path "/". |
| 1488 AddCookieToList("www.google.com", | 1393 AddCookieToList("www.google.com", |
| 1489 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1394 "Y=a; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1490 Time::Now() + TimeDelta::FromDays(10), | 1395 Time::Now() + TimeDelta::FromDays(10), &initial_cookies); |
| 1491 &initial_cookies); | |
| 1492 | 1396 |
| 1493 // Inject our initial cookies into the mock PersistentCookieStore. | 1397 // Inject our initial cookies into the mock PersistentCookieStore. |
| 1494 store->SetLoadExpectation(true, initial_cookies); | 1398 store->SetLoadExpectation(true, initial_cookies); |
| 1495 | 1399 |
| 1496 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 1400 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); |
| 1497 | 1401 |
| 1498 // Verify that duplicates were not imported for path "/". | 1402 // Verify that duplicates were not imported for path "/". |
| 1499 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4). | 1403 // (If this had failed, GetCookies() would have also returned X=1, X=2, X=4). |
| 1500 EXPECT_EQ("X=3; Y=a", GetCookies(cm.get(), GURL("http://www.google.com/"))); | 1404 EXPECT_EQ("X=3; Y=a", GetCookies(cm.get(), GURL("http://www.google.com/"))); |
| 1501 | 1405 |
| 1502 // Verify that same-named cookie on a different path ("/x2") didn't get | 1406 // Verify that same-named cookie on a different path ("/x2") didn't get |
| 1503 // messed up. | 1407 // messed up. |
| 1504 EXPECT_EQ("X=a1; X=3; Y=a", | 1408 EXPECT_EQ("X=a1; X=3; Y=a", |
| 1505 GetCookies(cm.get(), GURL("http://www.google.com/2/x"))); | 1409 GetCookies(cm.get(), GURL("http://www.google.com/2/x"))); |
| 1506 | 1410 |
| 1507 // Verify that the PersistentCookieStore was told to kill its 4 duplicates. | 1411 // Verify that the PersistentCookieStore was told to kill its 4 duplicates. |
| 1508 ASSERT_EQ(4u, store->commands().size()); | 1412 ASSERT_EQ(4u, store->commands().size()); |
| 1509 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[0].type); | 1413 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[0].type); |
| 1510 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 1414 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 1511 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type); | 1415 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type); |
| 1512 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); | 1416 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
| 1513 } | 1417 } |
| 1514 | 1418 |
| 1515 // Tests importing from a persistent cookie store that contains cookies | 1419 // Tests importing from a persistent cookie store that contains cookies |
| 1516 // with duplicate creation times. This situation should be handled by | 1420 // with duplicate creation times. This situation should be handled by |
| 1517 // dropping the cookies before insertion/visibility to user. | 1421 // dropping the cookies before insertion/visibility to user. |
| 1518 // | 1422 // |
| 1519 // This is a regression test for: http://crbug.com/43188. | 1423 // This is a regression test for: http://crbug.com/43188. |
| 1520 TEST_F(CookieMonsterTest, DontImportDuplicateCreationTimes) { | 1424 TEST_F(CookieMonsterTest, DontImportDuplicateCreationTimes) { |
| 1521 scoped_refptr<MockPersistentCookieStore> store( | 1425 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 1522 new MockPersistentCookieStore); | |
| 1523 | 1426 |
| 1524 Time now(Time::Now()); | 1427 Time now(Time::Now()); |
| 1525 Time earlier(now - TimeDelta::FromDays(1)); | 1428 Time earlier(now - TimeDelta::FromDays(1)); |
| 1526 | 1429 |
| 1527 // Insert 8 cookies, four with the current time as creation times, and | 1430 // Insert 8 cookies, four with the current time as creation times, and |
| 1528 // four with the earlier time as creation times. We should only get | 1431 // four with the earlier time as creation times. We should only get |
| 1529 // two cookies remaining, but which two (other than that there should | 1432 // two cookies remaining, but which two (other than that there should |
| 1530 // be one from each set) will be random. | 1433 // be one from each set) will be random. |
| 1531 std::vector<CanonicalCookie*> initial_cookies; | 1434 std::vector<CanonicalCookie*> initial_cookies; |
| 1532 AddCookieToList("www.google.com", "X=1; path=/", now, &initial_cookies); | 1435 AddCookieToList("www.google.com", "X=1; path=/", now, &initial_cookies); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1548 EXPECT_EQ(2U, list.size()); | 1451 EXPECT_EQ(2U, list.size()); |
| 1549 // Confirm that we have one of each. | 1452 // Confirm that we have one of each. |
| 1550 std::string name1(list[0].Name()); | 1453 std::string name1(list[0].Name()); |
| 1551 std::string name2(list[1].Name()); | 1454 std::string name2(list[1].Name()); |
| 1552 EXPECT_TRUE(name1 == "X" || name2 == "X"); | 1455 EXPECT_TRUE(name1 == "X" || name2 == "X"); |
| 1553 EXPECT_TRUE(name1 == "Y" || name2 == "Y"); | 1456 EXPECT_TRUE(name1 == "Y" || name2 == "Y"); |
| 1554 EXPECT_NE(name1, name2); | 1457 EXPECT_NE(name1, name2); |
| 1555 } | 1458 } |
| 1556 | 1459 |
| 1557 TEST_F(CookieMonsterTest, CookieMonsterDelegate) { | 1460 TEST_F(CookieMonsterTest, CookieMonsterDelegate) { |
| 1558 scoped_refptr<MockPersistentCookieStore> store( | 1461 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 1559 new MockPersistentCookieStore); | |
| 1560 scoped_refptr<MockCookieMonsterDelegate> delegate( | 1462 scoped_refptr<MockCookieMonsterDelegate> delegate( |
| 1561 new MockCookieMonsterDelegate); | 1463 new MockCookieMonsterDelegate); |
| 1562 scoped_refptr<CookieMonster> cm( | 1464 scoped_refptr<CookieMonster> cm( |
| 1563 new CookieMonster(store.get(), delegate.get())); | 1465 new CookieMonster(store.get(), delegate.get())); |
| 1564 | 1466 |
| 1565 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); | 1467 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); |
| 1566 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "C=D")); | 1468 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "C=D")); |
| 1567 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "E=F")); | 1469 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "E=F")); |
| 1568 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), url_google_)); | 1470 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), url_google_)); |
| 1569 ASSERT_EQ(3u, delegate->changes().size()); | 1471 ASSERT_EQ(3u, delegate->changes().size()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1588 EXPECT_TRUE(delegate->changes()[0].second); | 1490 EXPECT_TRUE(delegate->changes()[0].second); |
| 1589 EXPECT_EQ("C", delegate->changes()[0].first.Name()); | 1491 EXPECT_EQ("C", delegate->changes()[0].first.Name()); |
| 1590 EXPECT_EQ("D", delegate->changes()[0].first.Value()); | 1492 EXPECT_EQ("D", delegate->changes()[0].first.Value()); |
| 1591 delegate->reset(); | 1493 delegate->reset(); |
| 1592 | 1494 |
| 1593 EXPECT_FALSE(FindAndDeleteCookie(cm.get(), "random.host", "E")); | 1495 EXPECT_FALSE(FindAndDeleteCookie(cm.get(), "random.host", "E")); |
| 1594 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), url_google_)); | 1496 EXPECT_EQ("A=B; E=F", GetCookies(cm.get(), url_google_)); |
| 1595 EXPECT_EQ(0u, delegate->changes().size()); | 1497 EXPECT_EQ(0u, delegate->changes().size()); |
| 1596 | 1498 |
| 1597 // Insert a cookie "a" for path "/path1" | 1499 // Insert a cookie "a" for path "/path1" |
| 1598 EXPECT_TRUE(SetCookie(cm.get(), | 1500 EXPECT_TRUE(SetCookie(cm.get(), url_google_, |
| 1599 url_google_, | |
| 1600 "a=val1; path=/path1; " | 1501 "a=val1; path=/path1; " |
| 1601 "expires=Mon, 18-Apr-22 22:50:13 GMT")); | 1502 "expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 1602 ASSERT_EQ(1u, store->commands().size()); | 1503 ASSERT_EQ(1u, store->commands().size()); |
| 1603 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 1504 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 1604 ASSERT_EQ(1u, delegate->changes().size()); | 1505 ASSERT_EQ(1u, delegate->changes().size()); |
| 1605 EXPECT_FALSE(delegate->changes()[0].second); | 1506 EXPECT_FALSE(delegate->changes()[0].second); |
| 1606 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); | 1507 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); |
| 1607 EXPECT_EQ("a", delegate->changes()[0].first.Name()); | 1508 EXPECT_EQ("a", delegate->changes()[0].first.Name()); |
| 1608 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); | 1509 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); |
| 1609 delegate->reset(); | 1510 delegate->reset(); |
| 1610 | 1511 |
| 1611 // Insert a cookie "a" for path "/path1", that is httponly. This should | 1512 // Insert a cookie "a" for path "/path1", that is httponly. This should |
| 1612 // overwrite the non-http-only version. | 1513 // overwrite the non-http-only version. |
| 1613 CookieOptions allow_httponly; | 1514 CookieOptions allow_httponly; |
| 1614 allow_httponly.set_include_httponly(); | 1515 allow_httponly.set_include_httponly(); |
| 1615 EXPECT_TRUE(SetCookieWithOptions(cm.get(), | 1516 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, |
| 1616 url_google_, | |
| 1617 "a=val2; path=/path1; httponly; " | 1517 "a=val2; path=/path1; httponly; " |
| 1618 "expires=Mon, 18-Apr-22 22:50:14 GMT", | 1518 "expires=Mon, 18-Apr-22 22:50:14 GMT", |
| 1619 allow_httponly)); | 1519 allow_httponly)); |
| 1620 ASSERT_EQ(3u, store->commands().size()); | 1520 ASSERT_EQ(3u, store->commands().size()); |
| 1621 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 1521 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 1622 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); | 1522 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); |
| 1623 ASSERT_EQ(2u, delegate->changes().size()); | 1523 ASSERT_EQ(2u, delegate->changes().size()); |
| 1624 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); | 1524 EXPECT_EQ(url_google_.host(), delegate->changes()[0].first.Domain()); |
| 1625 EXPECT_TRUE(delegate->changes()[0].second); | 1525 EXPECT_TRUE(delegate->changes()[0].second); |
| 1626 EXPECT_EQ("a", delegate->changes()[0].first.Name()); | 1526 EXPECT_EQ("a", delegate->changes()[0].first.Name()); |
| 1627 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); | 1527 EXPECT_EQ("val1", delegate->changes()[0].first.Value()); |
| 1628 EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain()); | 1528 EXPECT_EQ(url_google_.host(), delegate->changes()[1].first.Domain()); |
| 1629 EXPECT_FALSE(delegate->changes()[1].second); | 1529 EXPECT_FALSE(delegate->changes()[1].second); |
| 1630 EXPECT_EQ("a", delegate->changes()[1].first.Name()); | 1530 EXPECT_EQ("a", delegate->changes()[1].first.Name()); |
| 1631 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); | 1531 EXPECT_EQ("val2", delegate->changes()[1].first.Value()); |
| 1632 delegate->reset(); | 1532 delegate->reset(); |
| 1633 } | 1533 } |
| 1634 | 1534 |
| 1635 TEST_F(CookieMonsterTest, SetCookieWithDetails) { | 1535 TEST_F(CookieMonsterTest, SetCookieWithDetails) { |
| 1636 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1536 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1637 | 1537 |
| 1638 EXPECT_TRUE(SetCookieWithDetails(cm.get(), | 1538 EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_foo_, "A", "B", |
| 1639 url_google_foo_, | 1539 std::string(), "/foo", base::Time(), false, |
| 1640 "A", | 1540 false, COOKIE_PRIORITY_DEFAULT)); |
| 1641 "B", | 1541 EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_bar_, "C", "D", |
| 1642 std::string(), | 1542 "google.izzle", "/bar", base::Time(), false, |
| 1643 "/foo", | 1543 true, COOKIE_PRIORITY_DEFAULT)); |
| 1644 base::Time(), | 1544 EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_, "E", "F", |
| 1645 false, | 1545 std::string(), std::string(), base::Time(), |
| 1646 false, | 1546 true, false, COOKIE_PRIORITY_DEFAULT)); |
| 1647 COOKIE_PRIORITY_DEFAULT)); | |
| 1648 EXPECT_TRUE(SetCookieWithDetails(cm.get(), | |
| 1649 url_google_bar_, | |
| 1650 "C", | |
| 1651 "D", | |
| 1652 "google.izzle", | |
| 1653 "/bar", | |
| 1654 base::Time(), | |
| 1655 false, | |
| 1656 true, | |
| 1657 COOKIE_PRIORITY_DEFAULT)); | |
| 1658 EXPECT_TRUE(SetCookieWithDetails(cm.get(), | |
| 1659 url_google_, | |
| 1660 "E", | |
| 1661 "F", | |
| 1662 std::string(), | |
| 1663 std::string(), | |
| 1664 base::Time(), | |
| 1665 true, | |
| 1666 false, | |
| 1667 COOKIE_PRIORITY_DEFAULT)); | |
| 1668 | 1547 |
| 1669 // Test that malformed attributes fail to set the cookie. | 1548 // Test that malformed attributes fail to set the cookie. |
| 1670 EXPECT_FALSE(SetCookieWithDetails(cm.get(), | 1549 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, " A", "B", |
| 1671 url_google_foo_, | 1550 std::string(), "/foo", base::Time(), false, |
| 1672 " A", | 1551 false, COOKIE_PRIORITY_DEFAULT)); |
| 1673 "B", | 1552 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A;", "B", |
| 1674 std::string(), | 1553 std::string(), "/foo", base::Time(), false, |
| 1675 "/foo", | 1554 false, COOKIE_PRIORITY_DEFAULT)); |
| 1676 base::Time(), | 1555 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A=", "B", |
| 1677 false, | 1556 std::string(), "/foo", base::Time(), false, |
| 1678 false, | 1557 false, COOKIE_PRIORITY_DEFAULT)); |
| 1679 COOKIE_PRIORITY_DEFAULT)); | 1558 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A", "B", |
| 1680 EXPECT_FALSE(SetCookieWithDetails(cm.get(), | 1559 "google.ozzzzzzle", "foo", base::Time(), |
| 1681 url_google_foo_, | 1560 false, false, COOKIE_PRIORITY_DEFAULT)); |
| 1682 "A;", | 1561 EXPECT_FALSE(SetCookieWithDetails(cm.get(), url_google_foo_, "A=", "B", |
| 1683 "B", | 1562 std::string(), "foo", base::Time(), false, |
| 1684 std::string(), | 1563 false, COOKIE_PRIORITY_DEFAULT)); |
| 1685 "/foo", | |
| 1686 base::Time(), | |
| 1687 false, | |
| 1688 false, | |
| 1689 COOKIE_PRIORITY_DEFAULT)); | |
| 1690 EXPECT_FALSE(SetCookieWithDetails(cm.get(), | |
| 1691 url_google_foo_, | |
| 1692 "A=", | |
| 1693 "B", | |
| 1694 std::string(), | |
| 1695 "/foo", | |
| 1696 base::Time(), | |
| 1697 false, | |
| 1698 false, | |
| 1699 COOKIE_PRIORITY_DEFAULT)); | |
| 1700 EXPECT_FALSE(SetCookieWithDetails(cm.get(), | |
| 1701 url_google_foo_, | |
| 1702 "A", | |
| 1703 "B", | |
| 1704 "google.ozzzzzzle", | |
| 1705 "foo", | |
| 1706 base::Time(), | |
| 1707 false, | |
| 1708 false, | |
| 1709 COOKIE_PRIORITY_DEFAULT)); | |
| 1710 EXPECT_FALSE(SetCookieWithDetails(cm.get(), | |
| 1711 url_google_foo_, | |
| 1712 "A=", | |
| 1713 "B", | |
| 1714 std::string(), | |
| 1715 "foo", | |
| 1716 base::Time(), | |
| 1717 false, | |
| 1718 false, | |
| 1719 COOKIE_PRIORITY_DEFAULT)); | |
| 1720 | 1564 |
| 1721 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_foo_); | 1565 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_foo_); |
| 1722 CookieList::iterator it = cookies.begin(); | 1566 CookieList::iterator it = cookies.begin(); |
| 1723 | 1567 |
| 1724 ASSERT_TRUE(it != cookies.end()); | 1568 ASSERT_TRUE(it != cookies.end()); |
| 1725 EXPECT_EQ("A", it->Name()); | 1569 EXPECT_EQ("A", it->Name()); |
| 1726 EXPECT_EQ("B", it->Value()); | 1570 EXPECT_EQ("B", it->Value()); |
| 1727 EXPECT_EQ("www.google.izzle", it->Domain()); | 1571 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 1728 EXPECT_EQ("/foo", it->Path()); | 1572 EXPECT_EQ("/foo", it->Path()); |
| 1729 EXPECT_FALSE(it->IsPersistent()); | 1573 EXPECT_FALSE(it->IsPersistent()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1770 // the http_only cookie, the host secure cookie, and the two host | 1614 // the http_only cookie, the host secure cookie, and the two host |
| 1771 // path cookies. http_only, secure, and paths are ignored by | 1615 // path cookies. http_only, secure, and paths are ignored by |
| 1772 // this call, and domain cookies arent touched. | 1616 // this call, and domain cookies arent touched. |
| 1773 PopulateCmForDeleteAllForHost(cm); | 1617 PopulateCmForDeleteAllForHost(cm); |
| 1774 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1618 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
| 1775 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1619 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1776 EXPECT_EQ("dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", | 1620 EXPECT_EQ("dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", |
| 1777 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1621 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1778 EXPECT_EQ("dom_1=X; host_1=X", | 1622 EXPECT_EQ("dom_1=X; host_1=X", |
| 1779 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1623 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1780 EXPECT_EQ("dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; " | 1624 EXPECT_EQ( |
| 1781 "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", | 1625 "dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; " |
| 1782 GetCookies(cm.get(), | 1626 "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", |
| 1783 GURL(kTopLevelDomainPlus2Secure + | 1627 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1784 std::string("/dir1/dir2/xxx")))); | 1628 std::string("/dir1/dir2/xxx")))); |
| 1785 | 1629 |
| 1786 EXPECT_EQ(5, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2))); | 1630 EXPECT_EQ(5, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2))); |
| 1787 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); | 1631 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); |
| 1788 | 1632 |
| 1789 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1633 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
| 1790 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1634 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1791 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", | 1635 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", |
| 1792 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1636 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1793 EXPECT_EQ("dom_1=X; host_1=X", | 1637 EXPECT_EQ("dom_1=X; host_1=X", |
| 1794 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1638 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1795 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", | 1639 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", |
| 1796 GetCookies(cm.get(), | 1640 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1797 GURL(kTopLevelDomainPlus2Secure + | 1641 std::string("/dir1/dir2/xxx")))); |
| 1798 std::string("/dir1/dir2/xxx")))); | |
| 1799 | 1642 |
| 1800 PopulateCmForDeleteAllForHost(cm); | 1643 PopulateCmForDeleteAllForHost(cm); |
| 1801 EXPECT_EQ(5, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1644 EXPECT_EQ(5, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1802 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); | 1645 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); |
| 1803 | 1646 |
| 1804 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1647 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
| 1805 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1648 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1806 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", | 1649 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", |
| 1807 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1650 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1808 EXPECT_EQ("dom_1=X; host_1=X", | 1651 EXPECT_EQ("dom_1=X; host_1=X", |
| 1809 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1652 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1810 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", | 1653 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", |
| 1811 GetCookies(cm.get(), | 1654 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1812 GURL(kTopLevelDomainPlus2Secure + | 1655 std::string("/dir1/dir2/xxx")))); |
| 1813 std::string("/dir1/dir2/xxx")))); | |
| 1814 | 1656 |
| 1815 PopulateCmForDeleteAllForHost(cm); | 1657 PopulateCmForDeleteAllForHost(cm); |
| 1816 EXPECT_EQ(5, | 1658 EXPECT_EQ(5, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1817 DeleteAllForHost( | 1659 std::string("/dir1/xxx")))); |
| 1818 cm.get(), | |
| 1819 GURL(kTopLevelDomainPlus2Secure + std::string("/dir1/xxx")))); | |
| 1820 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); | 1660 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); |
| 1821 | 1661 |
| 1822 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1662 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
| 1823 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1663 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
| 1824 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", | 1664 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", |
| 1825 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1665 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
| 1826 EXPECT_EQ("dom_1=X; host_1=X", | 1666 EXPECT_EQ("dom_1=X; host_1=X", |
| 1827 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1667 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
| 1828 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", | 1668 EXPECT_EQ("dom_path_2=X; dom_path_1=X; dom_1=X; dom_2=X; sec_dom=X", |
| 1829 GetCookies(cm.get(), | 1669 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure + |
| 1830 GURL(kTopLevelDomainPlus2Secure + | 1670 std::string("/dir1/dir2/xxx")))); |
| 1831 std::string("/dir1/dir2/xxx")))); | |
| 1832 } | 1671 } |
| 1833 | 1672 |
| 1834 TEST_F(CookieMonsterTest, UniqueCreationTime) { | 1673 TEST_F(CookieMonsterTest, UniqueCreationTime) { |
| 1835 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1674 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1836 CookieOptions options; | 1675 CookieOptions options; |
| 1837 | 1676 |
| 1838 // Add in three cookies through every public interface to the | 1677 // Add in three cookies through every public interface to the |
| 1839 // CookieMonster and confirm that none of them have duplicate | 1678 // CookieMonster and confirm that none of them have duplicate |
| 1840 // creation times. | 1679 // creation times. |
| 1841 | 1680 |
| 1842 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions | 1681 // SetCookieWithCreationTime and SetCookieWithCreationTimeAndOptions |
| 1843 // are not included as they aren't going to be public for very much | 1682 // are not included as they aren't going to be public for very much |
| 1844 // longer. | 1683 // longer. |
| 1845 | 1684 |
| 1846 // SetCookie, SetCookieWithOptions, SetCookieWithDetails | 1685 // SetCookie, SetCookieWithOptions, SetCookieWithDetails |
| 1847 | 1686 |
| 1848 SetCookie(cm.get(), url_google_, "SetCookie1=A"); | 1687 SetCookie(cm.get(), url_google_, "SetCookie1=A"); |
| 1849 SetCookie(cm.get(), url_google_, "SetCookie2=A"); | 1688 SetCookie(cm.get(), url_google_, "SetCookie2=A"); |
| 1850 SetCookie(cm.get(), url_google_, "SetCookie3=A"); | 1689 SetCookie(cm.get(), url_google_, "SetCookie3=A"); |
| 1851 | 1690 |
| 1852 SetCookieWithOptions( | 1691 SetCookieWithOptions(cm.get(), url_google_, "setCookieWithOptions1=A", |
| 1853 cm.get(), url_google_, "setCookieWithOptions1=A", options); | 1692 options); |
| 1854 SetCookieWithOptions( | 1693 SetCookieWithOptions(cm.get(), url_google_, "setCookieWithOptions2=A", |
| 1855 cm.get(), url_google_, "setCookieWithOptions2=A", options); | 1694 options); |
| 1856 SetCookieWithOptions( | 1695 SetCookieWithOptions(cm.get(), url_google_, "setCookieWithOptions3=A", |
| 1857 cm.get(), url_google_, "setCookieWithOptions3=A", options); | 1696 options); |
| 1858 | 1697 |
| 1859 SetCookieWithDetails(cm.get(), | 1698 SetCookieWithDetails(cm.get(), url_google_, "setCookieWithDetails1", "A", |
| 1860 url_google_, | 1699 ".google.com", "/", Time(), false, false, |
| 1861 "setCookieWithDetails1", | |
| 1862 "A", | |
| 1863 ".google.com", | |
| 1864 "/", | |
| 1865 Time(), | |
| 1866 false, | |
| 1867 false, | |
| 1868 COOKIE_PRIORITY_DEFAULT); | 1700 COOKIE_PRIORITY_DEFAULT); |
| 1869 SetCookieWithDetails(cm.get(), | 1701 SetCookieWithDetails(cm.get(), url_google_, "setCookieWithDetails2", "A", |
| 1870 url_google_, | 1702 ".google.com", "/", Time(), false, false, |
| 1871 "setCookieWithDetails2", | |
| 1872 "A", | |
| 1873 ".google.com", | |
| 1874 "/", | |
| 1875 Time(), | |
| 1876 false, | |
| 1877 false, | |
| 1878 COOKIE_PRIORITY_DEFAULT); | 1703 COOKIE_PRIORITY_DEFAULT); |
| 1879 SetCookieWithDetails(cm.get(), | 1704 SetCookieWithDetails(cm.get(), url_google_, "setCookieWithDetails3", "A", |
| 1880 url_google_, | 1705 ".google.com", "/", Time(), false, false, |
| 1881 "setCookieWithDetails3", | |
| 1882 "A", | |
| 1883 ".google.com", | |
| 1884 "/", | |
| 1885 Time(), | |
| 1886 false, | |
| 1887 false, | |
| 1888 COOKIE_PRIORITY_DEFAULT); | 1706 COOKIE_PRIORITY_DEFAULT); |
| 1889 | 1707 |
| 1890 // Now we check | 1708 // Now we check |
| 1891 CookieList cookie_list(GetAllCookies(cm.get())); | 1709 CookieList cookie_list(GetAllCookies(cm.get())); |
| 1892 typedef std::map<int64, CanonicalCookie> TimeCookieMap; | 1710 typedef std::map<int64, CanonicalCookie> TimeCookieMap; |
| 1893 TimeCookieMap check_map; | 1711 TimeCookieMap check_map; |
| 1894 for (CookieList::const_iterator it = cookie_list.begin(); | 1712 for (CookieList::const_iterator it = cookie_list.begin(); |
| 1895 it != cookie_list.end(); it++) { | 1713 it != cookie_list.end(); it++) { |
| 1896 const int64 creation_date = it->CreationDate().ToInternalValue(); | 1714 const int64 creation_date = it->CreationDate().ToInternalValue(); |
| 1897 TimeCookieMap::const_iterator | 1715 TimeCookieMap::const_iterator existing_cookie_it( |
| 1898 existing_cookie_it(check_map.find(creation_date)); | 1716 check_map.find(creation_date)); |
| 1899 EXPECT_TRUE(existing_cookie_it == check_map.end()) | 1717 EXPECT_TRUE(existing_cookie_it == check_map.end()) |
| 1900 << "Cookie " << it->Name() << " has same creation date (" | 1718 << "Cookie " << it->Name() << " has same creation date (" |
| 1901 << it->CreationDate().ToInternalValue() | 1719 << it->CreationDate().ToInternalValue() |
| 1902 << ") as previously entered cookie " | 1720 << ") as previously entered cookie " |
| 1903 << existing_cookie_it->second.Name(); | 1721 << existing_cookie_it->second.Name(); |
| 1904 | 1722 |
| 1905 if (existing_cookie_it == check_map.end()) { | 1723 if (existing_cookie_it == check_map.end()) { |
| 1906 check_map.insert(TimeCookieMap::value_type( | 1724 check_map.insert( |
| 1907 it->CreationDate().ToInternalValue(), *it)); | 1725 TimeCookieMap::value_type(it->CreationDate().ToInternalValue(), *it)); |
| 1908 } | 1726 } |
| 1909 } | 1727 } |
| 1910 } | 1728 } |
| 1911 | 1729 |
| 1912 // Mainly a test of GetEffectiveDomain, or more specifically, of the | 1730 // Mainly a test of GetEffectiveDomain, or more specifically, of the |
| 1913 // expected behavior of GetEffectiveDomain within the CookieMonster. | 1731 // expected behavior of GetEffectiveDomain within the CookieMonster. |
| 1914 TEST_F(CookieMonsterTest, GetKey) { | 1732 TEST_F(CookieMonsterTest, GetKey) { |
| 1915 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1733 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 1916 | 1734 |
| 1917 // This test is really only interesting if GetKey() actually does something. | 1735 // This test is really only interesting if GetKey() actually does something. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1937 TEST_F(CookieMonsterTest, BackingStoreCommunication) { | 1755 TEST_F(CookieMonsterTest, BackingStoreCommunication) { |
| 1938 // Store details for cookies transforming through the backing store interface. | 1756 // Store details for cookies transforming through the backing store interface. |
| 1939 | 1757 |
| 1940 base::Time current(base::Time::Now()); | 1758 base::Time current(base::Time::Now()); |
| 1941 scoped_refptr<MockSimplePersistentCookieStore> store( | 1759 scoped_refptr<MockSimplePersistentCookieStore> store( |
| 1942 new MockSimplePersistentCookieStore); | 1760 new MockSimplePersistentCookieStore); |
| 1943 base::Time new_access_time; | 1761 base::Time new_access_time; |
| 1944 base::Time expires(base::Time::Now() + base::TimeDelta::FromSeconds(100)); | 1762 base::Time expires(base::Time::Now() + base::TimeDelta::FromSeconds(100)); |
| 1945 | 1763 |
| 1946 const CookiesInputInfo input_info[] = { | 1764 const CookiesInputInfo input_info[] = { |
| 1947 {GURL("http://a.b.google.com"), "a", "1", "", "/path/to/cookie", expires, | 1765 {GURL("http://a.b.google.com"), |
| 1948 false, false, COOKIE_PRIORITY_DEFAULT}, | 1766 "a", |
| 1949 {GURL("https://www.google.com"), "b", "2", ".google.com", | 1767 "1", |
| 1950 "/path/from/cookie", expires + TimeDelta::FromSeconds(10), | 1768 "", |
| 1951 true, true, COOKIE_PRIORITY_DEFAULT}, | 1769 "/path/to/cookie", |
| 1952 {GURL("https://google.com"), "c", "3", "", "/another/path/to/cookie", | 1770 expires, |
| 1953 base::Time::Now() + base::TimeDelta::FromSeconds(100), | 1771 false, |
| 1954 true, false, COOKIE_PRIORITY_DEFAULT} | 1772 false, |
| 1955 }; | 1773 COOKIE_PRIORITY_DEFAULT}, |
| 1774 {GURL("https://www.google.com"), |
| 1775 "b", |
| 1776 "2", |
| 1777 ".google.com", |
| 1778 "/path/from/cookie", |
| 1779 expires + TimeDelta::FromSeconds(10), |
| 1780 true, |
| 1781 true, |
| 1782 COOKIE_PRIORITY_DEFAULT}, |
| 1783 {GURL("https://google.com"), |
| 1784 "c", |
| 1785 "3", |
| 1786 "", |
| 1787 "/another/path/to/cookie", |
| 1788 base::Time::Now() + base::TimeDelta::FromSeconds(100), |
| 1789 true, |
| 1790 false, |
| 1791 COOKIE_PRIORITY_DEFAULT}}; |
| 1956 const int INPUT_DELETE = 1; | 1792 const int INPUT_DELETE = 1; |
| 1957 | 1793 |
| 1958 // Create new cookies and flush them to the store. | 1794 // Create new cookies and flush them to the store. |
| 1959 { | 1795 { |
| 1960 scoped_refptr<CookieMonster> cmout(new CookieMonster(store.get(), NULL)); | 1796 scoped_refptr<CookieMonster> cmout(new CookieMonster(store.get(), NULL)); |
| 1961 for (const CookiesInputInfo* p = input_info; | 1797 for (const CookiesInputInfo* p = input_info; |
| 1962 p < &input_info[arraysize(input_info)]; | 1798 p < &input_info[arraysize(input_info)]; p++) { |
| 1963 p++) { | 1799 EXPECT_TRUE(SetCookieWithDetails(cmout.get(), p->url, p->name, p->value, |
| 1964 EXPECT_TRUE(SetCookieWithDetails(cmout.get(), | 1800 p->domain, p->path, p->expiration_time, |
| 1965 p->url, | 1801 p->secure, p->http_only, p->priority)); |
| 1966 p->name, | |
| 1967 p->value, | |
| 1968 p->domain, | |
| 1969 p->path, | |
| 1970 p->expiration_time, | |
| 1971 p->secure, | |
| 1972 p->http_only, | |
| 1973 p->priority)); | |
| 1974 } | 1802 } |
| 1975 GURL del_url(input_info[INPUT_DELETE].url.Resolve( | 1803 GURL del_url(input_info[INPUT_DELETE] |
| 1976 input_info[INPUT_DELETE].path).spec()); | 1804 .url.Resolve(input_info[INPUT_DELETE].path) |
| 1805 .spec()); |
| 1977 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name); | 1806 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name); |
| 1978 } | 1807 } |
| 1979 | 1808 |
| 1980 // Create a new cookie monster and make sure that everything is correct | 1809 // Create a new cookie monster and make sure that everything is correct |
| 1981 { | 1810 { |
| 1982 scoped_refptr<CookieMonster> cmin(new CookieMonster(store.get(), NULL)); | 1811 scoped_refptr<CookieMonster> cmin(new CookieMonster(store.get(), NULL)); |
| 1983 CookieList cookies(GetAllCookies(cmin.get())); | 1812 CookieList cookies(GetAllCookies(cmin.get())); |
| 1984 ASSERT_EQ(2u, cookies.size()); | 1813 ASSERT_EQ(2u, cookies.size()); |
| 1985 // Ordering is path length, then creation time. So second cookie | 1814 // Ordering is path length, then creation time. So second cookie |
| 1986 // will come first, and we need to swap them. | 1815 // will come first, and we need to swap them. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2004 } | 1833 } |
| 2005 } | 1834 } |
| 2006 } | 1835 } |
| 2007 | 1836 |
| 2008 TEST_F(CookieMonsterTest, CookieListOrdering) { | 1837 TEST_F(CookieMonsterTest, CookieListOrdering) { |
| 2009 // Put a random set of cookies into a monster and make sure | 1838 // Put a random set of cookies into a monster and make sure |
| 2010 // they're returned in the right order. | 1839 // they're returned in the right order. |
| 2011 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1840 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2012 EXPECT_TRUE( | 1841 EXPECT_TRUE( |
| 2013 SetCookie(cm.get(), GURL("http://d.c.b.a.google.com/aa/x.html"), "c=1")); | 1842 SetCookie(cm.get(), GURL("http://d.c.b.a.google.com/aa/x.html"), "c=1")); |
| 2014 EXPECT_TRUE(SetCookie(cm.get(), | 1843 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), |
| 2015 GURL("http://b.a.google.com/aa/bb/cc/x.html"), | |
| 2016 "d=1; domain=b.a.google.com")); | 1844 "d=1; domain=b.a.google.com")); |
| 2017 EXPECT_TRUE(SetCookie(cm.get(), | 1845 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://b.a.google.com/aa/bb/cc/x.html"), |
| 2018 GURL("http://b.a.google.com/aa/bb/cc/x.html"), | |
| 2019 "a=4; domain=b.a.google.com")); | 1846 "a=4; domain=b.a.google.com")); |
| 2020 EXPECT_TRUE(SetCookie(cm.get(), | 1847 EXPECT_TRUE(SetCookie(cm.get(), |
| 2021 GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), | 1848 GURL("http://c.b.a.google.com/aa/bb/cc/x.html"), |
| 2022 "e=1; domain=c.b.a.google.com")); | 1849 "e=1; domain=c.b.a.google.com")); |
| 2023 EXPECT_TRUE(SetCookie( | 1850 EXPECT_TRUE(SetCookie(cm.get(), |
| 2024 cm.get(), GURL("http://d.c.b.a.google.com/aa/bb/x.html"), "b=1")); | 1851 GURL("http://d.c.b.a.google.com/aa/bb/x.html"), "b=1")); |
| 2025 EXPECT_TRUE(SetCookie( | 1852 EXPECT_TRUE(SetCookie(cm.get(), GURL("http://news.bbc.co.uk/midpath/x.html"), |
| 2026 cm.get(), GURL("http://news.bbc.co.uk/midpath/x.html"), "g=10")); | 1853 "g=10")); |
| 2027 { | 1854 { |
| 2028 unsigned int i = 0; | 1855 unsigned int i = 0; |
| 2029 CookieList cookies(GetAllCookiesForURL( | 1856 CookieList cookies(GetAllCookiesForURL( |
| 2030 cm.get(), GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"))); | 1857 cm.get(), GURL("http://d.c.b.a.google.com/aa/bb/cc/dd"))); |
| 2031 ASSERT_EQ(5u, cookies.size()); | 1858 ASSERT_EQ(5u, cookies.size()); |
| 2032 EXPECT_EQ("d", cookies[i++].Name()); | 1859 EXPECT_EQ("d", cookies[i++].Name()); |
| 2033 EXPECT_EQ("a", cookies[i++].Name()); | 1860 EXPECT_EQ("a", cookies[i++].Name()); |
| 2034 EXPECT_EQ("e", cookies[i++].Name()); | 1861 EXPECT_EQ("e", cookies[i++].Name()); |
| 2035 EXPECT_EQ("b", cookies[i++].Name()); | 1862 EXPECT_EQ("b", cookies[i++].Name()); |
| 2036 EXPECT_EQ("c", cookies[i++].Name()); | 1863 EXPECT_EQ("c", cookies[i++].Name()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2078 // Now we explore a series of relationships between cookie last access | 1905 // Now we explore a series of relationships between cookie last access |
| 2079 // time and size of store to make sure we only get rid of cookies when | 1906 // time and size of store to make sure we only get rid of cookies when |
| 2080 // we really should. | 1907 // we really should. |
| 2081 const struct TestCase { | 1908 const struct TestCase { |
| 2082 size_t num_cookies; | 1909 size_t num_cookies; |
| 2083 size_t num_old_cookies; | 1910 size_t num_old_cookies; |
| 2084 size_t expected_initial_cookies; | 1911 size_t expected_initial_cookies; |
| 2085 // Indexed by ExpiryAndKeyScheme | 1912 // Indexed by ExpiryAndKeyScheme |
| 2086 size_t expected_cookies_after_set; | 1913 size_t expected_cookies_after_set; |
| 2087 } test_cases[] = { | 1914 } test_cases[] = { |
| 2088 { | 1915 {// A whole lot of recent cookies; gc shouldn't happen. |
| 2089 // A whole lot of recent cookies; gc shouldn't happen. | 1916 CookieMonster::kMaxCookies * 2, |
| 2090 CookieMonster::kMaxCookies * 2, | 1917 0, |
| 2091 0, | 1918 CookieMonster::kMaxCookies * 2, |
| 2092 CookieMonster::kMaxCookies * 2, | 1919 CookieMonster::kMaxCookies * 2 + 1}, |
| 2093 CookieMonster::kMaxCookies * 2 + 1 | 1920 {// Some old cookies, but still overflowing max. |
| 2094 }, { | 1921 CookieMonster::kMaxCookies * 2, |
| 2095 // Some old cookies, but still overflowing max. | 1922 CookieMonster::kMaxCookies / 2, |
| 2096 CookieMonster::kMaxCookies * 2, | 1923 CookieMonster::kMaxCookies * 2, |
| 2097 CookieMonster::kMaxCookies / 2, | 1924 CookieMonster::kMaxCookies * 2 - CookieMonster::kMaxCookies / 2 + 1}, |
| 2098 CookieMonster::kMaxCookies * 2, | 1925 {// Old cookies enough to bring us right down to our purge line. |
| 2099 CookieMonster::kMaxCookies * 2 - CookieMonster::kMaxCookies / 2 + 1 | 1926 CookieMonster::kMaxCookies * 2, |
| 2100 }, { | 1927 CookieMonster::kMaxCookies + CookieMonster::kPurgeCookies + 1, |
| 2101 // Old cookies enough to bring us right down to our purge line. | 1928 CookieMonster::kMaxCookies * 2, |
| 2102 CookieMonster::kMaxCookies * 2, | 1929 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}, |
| 2103 CookieMonster::kMaxCookies + CookieMonster::kPurgeCookies + 1, | 1930 {// Old cookies enough to bring below our purge line (which we |
| 2104 CookieMonster::kMaxCookies * 2, | 1931 // shouldn't do). |
| 2105 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies | 1932 CookieMonster::kMaxCookies * 2, |
| 2106 }, { | 1933 CookieMonster::kMaxCookies * 3 / 2, |
| 2107 // Old cookies enough to bring below our purge line (which we | 1934 CookieMonster::kMaxCookies * 2, |
| 2108 // shouldn't do). | 1935 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}}; |
| 2109 CookieMonster::kMaxCookies * 2, | |
| 2110 CookieMonster::kMaxCookies * 3 / 2, | |
| 2111 CookieMonster::kMaxCookies * 2, | |
| 2112 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies | |
| 2113 } | |
| 2114 }; | |
| 2115 | 1936 |
| 2116 for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) { | 1937 for (int ci = 0; ci < static_cast<int>(arraysize(test_cases)); ++ci) { |
| 2117 const TestCase *test_case = &test_cases[ci]; | 1938 const TestCase* test_case = &test_cases[ci]; |
| 2118 scoped_refptr<CookieMonster> cm( | 1939 scoped_refptr<CookieMonster> cm(CreateMonsterFromStoreForGC( |
| 2119 CreateMonsterFromStoreForGC( | 1940 test_case->num_cookies, test_case->num_old_cookies, |
| 2120 test_case->num_cookies, test_case->num_old_cookies, | 1941 CookieMonster::kSafeFromGlobalPurgeDays * 2)); |
| 2121 CookieMonster::kSafeFromGlobalPurgeDays * 2)); | |
| 2122 EXPECT_EQ(test_case->expected_initial_cookies, | 1942 EXPECT_EQ(test_case->expected_initial_cookies, |
| 2123 GetAllCookies(cm.get()).size()) << "For test case " << ci; | 1943 GetAllCookies(cm.get()).size()) |
| 1944 << "For test case " << ci; |
| 2124 // Will trigger GC | 1945 // Will trigger GC |
| 2125 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); | 1946 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); |
| 2126 EXPECT_EQ(test_case->expected_cookies_after_set, | 1947 EXPECT_EQ(test_case->expected_cookies_after_set, |
| 2127 GetAllCookies(cm.get()).size()) << "For test case " << ci; | 1948 GetAllCookies(cm.get()).size()) |
| 1949 << "For test case " << ci; |
| 2128 } | 1950 } |
| 2129 } | 1951 } |
| 2130 | 1952 |
| 2131 // This test checks that keep expired cookies flag is working. | 1953 // This test checks that keep expired cookies flag is working. |
| 2132 TEST_F(CookieMonsterTest, KeepExpiredCookies) { | 1954 TEST_F(CookieMonsterTest, KeepExpiredCookies) { |
| 2133 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1955 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2134 cm->SetKeepExpiredCookies(); | 1956 cm->SetKeepExpiredCookies(); |
| 2135 CookieOptions options; | 1957 CookieOptions options; |
| 2136 | 1958 |
| 2137 // Set a persistent cookie. | 1959 // Set a persistent cookie. |
| 2138 ASSERT_TRUE(SetCookieWithOptions( | 1960 ASSERT_TRUE(SetCookieWithOptions( |
| 2139 cm.get(), | 1961 cm.get(), url_google_, |
| 2140 url_google_, | |
| 2141 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT", | 1962 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT", |
| 2142 options)); | 1963 options)); |
| 2143 | 1964 |
| 2144 // Get the canonical cookie. | 1965 // Get the canonical cookie. |
| 2145 CookieList cookie_list = GetAllCookies(cm.get()); | 1966 CookieList cookie_list = GetAllCookies(cm.get()); |
| 2146 ASSERT_EQ(1U, cookie_list.size()); | 1967 ASSERT_EQ(1U, cookie_list.size()); |
| 2147 | 1968 |
| 2148 // Use a past expiry date to delete the cookie. | 1969 // Use a past expiry date to delete the cookie. |
| 2149 ASSERT_TRUE(SetCookieWithOptions( | 1970 ASSERT_TRUE(SetCookieWithOptions( |
| 2150 cm.get(), | 1971 cm.get(), url_google_, |
| 2151 url_google_, | |
| 2152 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT", | 1972 std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT", |
| 2153 options)); | 1973 options)); |
| 2154 | 1974 |
| 2155 // Check that the cookie with the past expiry date is still there. | 1975 // Check that the cookie with the past expiry date is still there. |
| 2156 // GetAllCookies() also triggers garbage collection. | 1976 // GetAllCookies() also triggers garbage collection. |
| 2157 cookie_list = GetAllCookies(cm.get()); | 1977 cookie_list = GetAllCookies(cm.get()); |
| 2158 ASSERT_EQ(1U, cookie_list.size()); | 1978 ASSERT_EQ(1U, cookie_list.size()); |
| 2159 ASSERT_TRUE(cookie_list[0].IsExpired(Time::Now())); | 1979 ASSERT_TRUE(cookie_list[0].IsExpired(Time::Now())); |
| 2160 } | 1980 } |
| 2161 | 1981 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2183 void UpdateCookieAccessTime(const CanonicalCookie&) override {} | 2003 void UpdateCookieAccessTime(const CanonicalCookie&) override {} |
| 2184 void DeleteCookie(const CanonicalCookie&) override {} | 2004 void DeleteCookie(const CanonicalCookie&) override {} |
| 2185 void SetForceKeepSessionState() override {} | 2005 void SetForceKeepSessionState() override {} |
| 2186 | 2006 |
| 2187 void Flush(const base::Closure& callback) override { | 2007 void Flush(const base::Closure& callback) override { |
| 2188 ++flush_count_; | 2008 ++flush_count_; |
| 2189 if (!callback.is_null()) | 2009 if (!callback.is_null()) |
| 2190 callback.Run(); | 2010 callback.Run(); |
| 2191 } | 2011 } |
| 2192 | 2012 |
| 2193 int flush_count() { | 2013 int flush_count() { return flush_count_; } |
| 2194 return flush_count_; | |
| 2195 } | |
| 2196 | 2014 |
| 2197 private: | 2015 private: |
| 2198 ~FlushablePersistentStore() override {} | 2016 ~FlushablePersistentStore() override {} |
| 2199 | 2017 |
| 2200 volatile int flush_count_; | 2018 volatile int flush_count_; |
| 2201 }; | 2019 }; |
| 2202 | 2020 |
| 2203 // Counts the number of times Callback() has been run. | 2021 // Counts the number of times Callback() has been run. |
| 2204 class CallbackCounter : public base::RefCountedThreadSafe<CallbackCounter> { | 2022 class CallbackCounter : public base::RefCountedThreadSafe<CallbackCounter> { |
| 2205 public: | 2023 public: |
| 2206 CallbackCounter() : callback_count_(0) {} | 2024 CallbackCounter() : callback_count_(0) {} |
| 2207 | 2025 |
| 2208 void Callback() { | 2026 void Callback() { ++callback_count_; } |
| 2209 ++callback_count_; | |
| 2210 } | |
| 2211 | 2027 |
| 2212 int callback_count() { | 2028 int callback_count() { return callback_count_; } |
| 2213 return callback_count_; | |
| 2214 } | |
| 2215 | 2029 |
| 2216 private: | 2030 private: |
| 2217 friend class base::RefCountedThreadSafe<CallbackCounter>; | 2031 friend class base::RefCountedThreadSafe<CallbackCounter>; |
| 2218 ~CallbackCounter() {} | 2032 ~CallbackCounter() {} |
| 2219 | 2033 |
| 2220 volatile int callback_count_; | 2034 volatile int callback_count_; |
| 2221 }; | 2035 }; |
| 2222 | 2036 |
| 2223 } // namespace | 2037 } // namespace |
| 2224 | 2038 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2272 base::MessageLoop::current()->RunUntilIdle(); | 2086 base::MessageLoop::current()->RunUntilIdle(); |
| 2273 | 2087 |
| 2274 ASSERT_EQ(3, counter->callback_count()); | 2088 ASSERT_EQ(3, counter->callback_count()); |
| 2275 } | 2089 } |
| 2276 | 2090 |
| 2277 TEST_F(CookieMonsterTest, HistogramCheck) { | 2091 TEST_F(CookieMonsterTest, HistogramCheck) { |
| 2278 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2092 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2279 // Should match call in InitializeHistograms, but doesn't really matter | 2093 // Should match call in InitializeHistograms, but doesn't really matter |
| 2280 // since the histogram should have been initialized by the CM construction | 2094 // since the histogram should have been initialized by the CM construction |
| 2281 // above. | 2095 // above. |
| 2282 base::HistogramBase* expired_histogram = | 2096 base::HistogramBase* expired_histogram = base::Histogram::FactoryGet( |
| 2283 base::Histogram::FactoryGet( | 2097 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, |
| 2284 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, | 2098 base::Histogram::kUmaTargetedHistogramFlag); |
| 2285 base::Histogram::kUmaTargetedHistogramFlag); | |
| 2286 | 2099 |
| 2287 scoped_ptr<base::HistogramSamples> samples1( | 2100 scoped_ptr<base::HistogramSamples> samples1( |
| 2288 expired_histogram->SnapshotSamples()); | 2101 expired_histogram->SnapshotSamples()); |
| 2289 ASSERT_TRUE( | 2102 ASSERT_TRUE(SetCookieWithDetails( |
| 2290 SetCookieWithDetails(cm.get(), | 2103 cm.get(), GURL("http://fake.a.url"), "a", "b", "a.url", "/", |
| 2291 GURL("http://fake.a.url"), | 2104 base::Time::Now() + base::TimeDelta::FromMinutes(59), false, false, |
| 2292 "a", | 2105 COOKIE_PRIORITY_DEFAULT)); |
| 2293 "b", | |
| 2294 "a.url", | |
| 2295 "/", | |
| 2296 base::Time::Now() + base::TimeDelta::FromMinutes(59), | |
| 2297 false, | |
| 2298 false, | |
| 2299 COOKIE_PRIORITY_DEFAULT)); | |
| 2300 | 2106 |
| 2301 scoped_ptr<base::HistogramSamples> samples2( | 2107 scoped_ptr<base::HistogramSamples> samples2( |
| 2302 expired_histogram->SnapshotSamples()); | 2108 expired_histogram->SnapshotSamples()); |
| 2303 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); | 2109 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); |
| 2304 | 2110 |
| 2305 // kValidCookieLine creates a session cookie. | 2111 // kValidCookieLine creates a session cookie. |
| 2306 ASSERT_TRUE(SetCookie(cm.get(), url_google_, kValidCookieLine)); | 2112 ASSERT_TRUE(SetCookie(cm.get(), url_google_, kValidCookieLine)); |
| 2307 | 2113 |
| 2308 scoped_ptr<base::HistogramSamples> samples3( | 2114 scoped_ptr<base::HistogramSamples> samples3( |
| 2309 expired_histogram->SnapshotSamples()); | 2115 expired_histogram->SnapshotSamples()); |
| 2310 EXPECT_EQ(samples2->TotalCount(), samples3->TotalCount()); | 2116 EXPECT_EQ(samples2->TotalCount(), samples3->TotalCount()); |
| 2311 } | 2117 } |
| 2312 | 2118 |
| 2313 namespace { | 2119 namespace { |
| 2314 | 2120 |
| 2315 class MultiThreadedCookieMonsterTest : public CookieMonsterTest { | 2121 class MultiThreadedCookieMonsterTest : public CookieMonsterTest { |
| 2316 public: | 2122 public: |
| 2317 MultiThreadedCookieMonsterTest() : other_thread_("CMTthread") {} | 2123 MultiThreadedCookieMonsterTest() : other_thread_("CMTthread") {} |
| 2318 | 2124 |
| 2319 // Helper methods for calling the asynchronous CookieMonster methods | 2125 // Helper methods for calling the asynchronous CookieMonster methods |
| 2320 // from a different thread. | 2126 // from a different thread. |
| 2321 | 2127 |
| 2322 void GetAllCookiesTask(CookieMonster* cm, | 2128 void GetAllCookiesTask(CookieMonster* cm, GetCookieListCallback* callback) { |
| 2323 GetCookieListCallback* callback) { | |
| 2324 cm->GetAllCookiesAsync( | 2129 cm->GetAllCookiesAsync( |
| 2325 base::Bind(&GetCookieListCallback::Run, base::Unretained(callback))); | 2130 base::Bind(&GetCookieListCallback::Run, base::Unretained(callback))); |
| 2326 } | 2131 } |
| 2327 | 2132 |
| 2328 void GetAllCookiesForURLTask(CookieMonster* cm, | 2133 void GetAllCookiesForURLTask(CookieMonster* cm, |
| 2329 const GURL& url, | 2134 const GURL& url, |
| 2330 GetCookieListCallback* callback) { | 2135 GetCookieListCallback* callback) { |
| 2331 cm->GetAllCookiesForURLAsync( | 2136 cm->GetAllCookiesForURLAsync(url, base::Bind(&GetCookieListCallback::Run, |
| 2332 url, | 2137 base::Unretained(callback))); |
| 2333 base::Bind(&GetCookieListCallback::Run, base::Unretained(callback))); | |
| 2334 } | 2138 } |
| 2335 | 2139 |
| 2336 void GetAllCookiesForURLWithOptionsTask(CookieMonster* cm, | 2140 void GetAllCookiesForURLWithOptionsTask(CookieMonster* cm, |
| 2337 const GURL& url, | 2141 const GURL& url, |
| 2338 const CookieOptions& options, | 2142 const CookieOptions& options, |
| 2339 GetCookieListCallback* callback) { | 2143 GetCookieListCallback* callback) { |
| 2340 cm->GetAllCookiesForURLWithOptionsAsync( | 2144 cm->GetAllCookiesForURLWithOptionsAsync( |
| 2341 url, options, | 2145 url, options, |
| 2342 base::Bind(&GetCookieListCallback::Run, base::Unretained(callback))); | 2146 base::Bind(&GetCookieListCallback::Run, base::Unretained(callback))); |
| 2343 } | 2147 } |
| 2344 | 2148 |
| 2345 void SetCookieWithDetailsTask(CookieMonster* cm, const GURL& url, | 2149 void SetCookieWithDetailsTask(CookieMonster* cm, |
| 2150 const GURL& url, |
| 2346 ResultSavingCookieCallback<bool>* callback) { | 2151 ResultSavingCookieCallback<bool>* callback) { |
| 2347 // Define the parameters here instead of in the calling fucntion. | 2152 // Define the parameters here instead of in the calling fucntion. |
| 2348 // The maximum number of parameters for Bind function is 6. | 2153 // The maximum number of parameters for Bind function is 6. |
| 2349 std::string name = "A"; | 2154 std::string name = "A"; |
| 2350 std::string value = "B"; | 2155 std::string value = "B"; |
| 2351 std::string domain = std::string(); | 2156 std::string domain = std::string(); |
| 2352 std::string path = "/foo"; | 2157 std::string path = "/foo"; |
| 2353 base::Time expiration_time = base::Time(); | 2158 base::Time expiration_time = base::Time(); |
| 2354 bool secure = false; | 2159 bool secure = false; |
| 2355 bool http_only = false; | 2160 bool http_only = false; |
| 2356 CookiePriority priority = COOKIE_PRIORITY_DEFAULT; | 2161 CookiePriority priority = COOKIE_PRIORITY_DEFAULT; |
| 2357 cm->SetCookieWithDetailsAsync( | 2162 cm->SetCookieWithDetailsAsync( |
| 2358 url, name, value, domain, path, expiration_time, secure, http_only, | 2163 url, name, value, domain, path, expiration_time, secure, http_only, |
| 2359 priority, | 2164 priority, base::Bind(&ResultSavingCookieCallback<bool>::Run, |
| 2360 base::Bind( | 2165 base::Unretained(callback))); |
| 2361 &ResultSavingCookieCallback<bool>::Run, | |
| 2362 base::Unretained(callback))); | |
| 2363 } | 2166 } |
| 2364 | 2167 |
| 2365 void DeleteAllCreatedBetweenTask(CookieMonster* cm, | 2168 void DeleteAllCreatedBetweenTask(CookieMonster* cm, |
| 2366 const base::Time& delete_begin, | 2169 const base::Time& delete_begin, |
| 2367 const base::Time& delete_end, | 2170 const base::Time& delete_end, |
| 2368 ResultSavingCookieCallback<int>* callback) { | 2171 ResultSavingCookieCallback<int>* callback) { |
| 2369 cm->DeleteAllCreatedBetweenAsync( | 2172 cm->DeleteAllCreatedBetweenAsync( |
| 2370 delete_begin, delete_end, | 2173 delete_begin, delete_end, |
| 2371 base::Bind( | 2174 base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 2372 &ResultSavingCookieCallback<int>::Run, base::Unretained(callback))); | 2175 base::Unretained(callback))); |
| 2373 } | 2176 } |
| 2374 | 2177 |
| 2375 void DeleteAllForHostTask(CookieMonster* cm, | 2178 void DeleteAllForHostTask(CookieMonster* cm, |
| 2376 const GURL& url, | 2179 const GURL& url, |
| 2377 ResultSavingCookieCallback<int>* callback) { | 2180 ResultSavingCookieCallback<int>* callback) { |
| 2378 cm->DeleteAllForHostAsync( | 2181 cm->DeleteAllForHostAsync(url, |
| 2379 url, | 2182 base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 2380 base::Bind( | 2183 base::Unretained(callback))); |
| 2381 &ResultSavingCookieCallback<int>::Run, base::Unretained(callback))); | |
| 2382 } | 2184 } |
| 2383 | 2185 |
| 2384 void DeleteAllCreatedBetweenForHostTask( | 2186 void DeleteAllCreatedBetweenForHostTask( |
| 2385 CookieMonster* cm, | 2187 CookieMonster* cm, |
| 2386 const base::Time delete_begin, | 2188 const base::Time delete_begin, |
| 2387 const base::Time delete_end, | 2189 const base::Time delete_end, |
| 2388 const GURL& url, | 2190 const GURL& url, |
| 2389 ResultSavingCookieCallback<int>* callback) { | 2191 ResultSavingCookieCallback<int>* callback) { |
| 2390 cm->DeleteAllCreatedBetweenForHostAsync( | 2192 cm->DeleteAllCreatedBetweenForHostAsync( |
| 2391 delete_begin, delete_end, url, | 2193 delete_begin, delete_end, url, |
| 2392 base::Bind( | 2194 base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 2393 &ResultSavingCookieCallback<int>::Run, | 2195 base::Unretained(callback))); |
| 2394 base::Unretained(callback))); | |
| 2395 } | 2196 } |
| 2396 | 2197 |
| 2397 void DeleteCanonicalCookieTask(CookieMonster* cm, | 2198 void DeleteCanonicalCookieTask(CookieMonster* cm, |
| 2398 const CanonicalCookie& cookie, | 2199 const CanonicalCookie& cookie, |
| 2399 ResultSavingCookieCallback<bool>* callback) { | 2200 ResultSavingCookieCallback<bool>* callback) { |
| 2400 cm->DeleteCanonicalCookieAsync( | 2201 cm->DeleteCanonicalCookieAsync( |
| 2401 cookie, | 2202 cookie, base::Bind(&ResultSavingCookieCallback<bool>::Run, |
| 2402 base::Bind( | 2203 base::Unretained(callback))); |
| 2403 &ResultSavingCookieCallback<bool>::Run, | |
| 2404 base::Unretained(callback))); | |
| 2405 } | 2204 } |
| 2406 | 2205 |
| 2407 protected: | 2206 protected: |
| 2408 void RunOnOtherThread(const base::Closure& task) { | 2207 void RunOnOtherThread(const base::Closure& task) { |
| 2409 other_thread_.Start(); | 2208 other_thread_.Start(); |
| 2410 other_thread_.message_loop()->PostTask(FROM_HERE, task); | 2209 other_thread_.message_loop()->PostTask(FROM_HERE, task); |
| 2411 RunFor(kTimeout); | 2210 RunFor(kTimeout); |
| 2412 other_thread_.Stop(); | 2211 other_thread_.Stop(); |
| 2413 } | 2212 } |
| 2414 | 2213 |
| 2415 Thread other_thread_; | 2214 Thread other_thread_; |
| 2416 }; | 2215 }; |
| 2417 | 2216 |
| 2418 } // namespace | 2217 } // namespace |
| 2419 | 2218 |
| 2420 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) { | 2219 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) { |
| 2421 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2220 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2422 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); | 2221 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); |
| 2423 CookieList cookies = GetAllCookies(cm.get()); | 2222 CookieList cookies = GetAllCookies(cm.get()); |
| 2424 CookieList::const_iterator it = cookies.begin(); | 2223 CookieList::const_iterator it = cookies.begin(); |
| 2425 ASSERT_TRUE(it != cookies.end()); | 2224 ASSERT_TRUE(it != cookies.end()); |
| 2426 EXPECT_EQ("www.google.izzle", it->Domain()); | 2225 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2427 EXPECT_EQ("A", it->Name()); | 2226 EXPECT_EQ("A", it->Name()); |
| 2428 ASSERT_TRUE(++it == cookies.end()); | 2227 ASSERT_TRUE(++it == cookies.end()); |
| 2429 GetCookieListCallback callback(&other_thread_); | 2228 GetCookieListCallback callback(&other_thread_); |
| 2430 base::Closure task = | 2229 base::Closure task = |
| 2431 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesTask, | 2230 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesTask, |
| 2432 base::Unretained(this), | 2231 base::Unretained(this), cm, &callback); |
| 2433 cm, &callback); | |
| 2434 RunOnOtherThread(task); | 2232 RunOnOtherThread(task); |
| 2435 EXPECT_TRUE(callback.did_run()); | 2233 EXPECT_TRUE(callback.did_run()); |
| 2436 it = callback.cookies().begin(); | 2234 it = callback.cookies().begin(); |
| 2437 ASSERT_TRUE(it != callback.cookies().end()); | 2235 ASSERT_TRUE(it != callback.cookies().end()); |
| 2438 EXPECT_EQ("www.google.izzle", it->Domain()); | 2236 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2439 EXPECT_EQ("A", it->Name()); | 2237 EXPECT_EQ("A", it->Name()); |
| 2440 ASSERT_TRUE(++it == callback.cookies().end()); | 2238 ASSERT_TRUE(++it == callback.cookies().end()); |
| 2441 } | 2239 } |
| 2442 | 2240 |
| 2443 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) { | 2241 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) { |
| 2444 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2242 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2445 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); | 2243 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); |
| 2446 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_); | 2244 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_); |
| 2447 CookieList::const_iterator it = cookies.begin(); | 2245 CookieList::const_iterator it = cookies.begin(); |
| 2448 ASSERT_TRUE(it != cookies.end()); | 2246 ASSERT_TRUE(it != cookies.end()); |
| 2449 EXPECT_EQ("www.google.izzle", it->Domain()); | 2247 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2450 EXPECT_EQ("A", it->Name()); | 2248 EXPECT_EQ("A", it->Name()); |
| 2451 ASSERT_TRUE(++it == cookies.end()); | 2249 ASSERT_TRUE(++it == cookies.end()); |
| 2452 GetCookieListCallback callback(&other_thread_); | 2250 GetCookieListCallback callback(&other_thread_); |
| 2453 base::Closure task = | 2251 base::Closure task = |
| 2454 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask, | 2252 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask, |
| 2455 base::Unretained(this), | 2253 base::Unretained(this), cm, url_google_, &callback); |
| 2456 cm, url_google_, &callback); | |
| 2457 RunOnOtherThread(task); | 2254 RunOnOtherThread(task); |
| 2458 EXPECT_TRUE(callback.did_run()); | 2255 EXPECT_TRUE(callback.did_run()); |
| 2459 it = callback.cookies().begin(); | 2256 it = callback.cookies().begin(); |
| 2460 ASSERT_TRUE(it != callback.cookies().end()); | 2257 ASSERT_TRUE(it != callback.cookies().end()); |
| 2461 EXPECT_EQ("www.google.izzle", it->Domain()); | 2258 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2462 EXPECT_EQ("A", it->Name()); | 2259 EXPECT_EQ("A", it->Name()); |
| 2463 ASSERT_TRUE(++it == callback.cookies().end()); | 2260 ASSERT_TRUE(++it == callback.cookies().end()); |
| 2464 } | 2261 } |
| 2465 | 2262 |
| 2466 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) { | 2263 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) { |
| 2467 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2264 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2468 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); | 2265 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); |
| 2469 CookieOptions options; | 2266 CookieOptions options; |
| 2470 CookieList cookies = | 2267 CookieList cookies = |
| 2471 GetAllCookiesForURLWithOptions(cm.get(), url_google_, options); | 2268 GetAllCookiesForURLWithOptions(cm.get(), url_google_, options); |
| 2472 CookieList::const_iterator it = cookies.begin(); | 2269 CookieList::const_iterator it = cookies.begin(); |
| 2473 ASSERT_TRUE(it != cookies.end()); | 2270 ASSERT_TRUE(it != cookies.end()); |
| 2474 EXPECT_EQ("www.google.izzle", it->Domain()); | 2271 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2475 EXPECT_EQ("A", it->Name()); | 2272 EXPECT_EQ("A", it->Name()); |
| 2476 ASSERT_TRUE(++it == cookies.end()); | 2273 ASSERT_TRUE(++it == cookies.end()); |
| 2477 GetCookieListCallback callback(&other_thread_); | 2274 GetCookieListCallback callback(&other_thread_); |
| 2478 base::Closure task = base::Bind( | 2275 base::Closure task = base::Bind( |
| 2479 &net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLWithOptionsTask, | 2276 &net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLWithOptionsTask, |
| 2480 base::Unretained(this), | 2277 base::Unretained(this), cm, url_google_, options, &callback); |
| 2481 cm, url_google_, options, &callback); | |
| 2482 RunOnOtherThread(task); | 2278 RunOnOtherThread(task); |
| 2483 EXPECT_TRUE(callback.did_run()); | 2279 EXPECT_TRUE(callback.did_run()); |
| 2484 it = callback.cookies().begin(); | 2280 it = callback.cookies().begin(); |
| 2485 ASSERT_TRUE(it != callback.cookies().end()); | 2281 ASSERT_TRUE(it != callback.cookies().end()); |
| 2486 EXPECT_EQ("www.google.izzle", it->Domain()); | 2282 EXPECT_EQ("www.google.izzle", it->Domain()); |
| 2487 EXPECT_EQ("A", it->Name()); | 2283 EXPECT_EQ("A", it->Name()); |
| 2488 ASSERT_TRUE(++it == callback.cookies().end()); | 2284 ASSERT_TRUE(++it == callback.cookies().end()); |
| 2489 } | 2285 } |
| 2490 | 2286 |
| 2491 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) { | 2287 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) { |
| 2492 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2288 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2493 EXPECT_TRUE(SetCookieWithDetails(cm.get(), | 2289 EXPECT_TRUE(SetCookieWithDetails(cm.get(), url_google_foo_, "A", "B", |
| 2494 url_google_foo_, | 2290 std::string(), "/foo", base::Time(), false, |
| 2495 "A", | 2291 false, COOKIE_PRIORITY_DEFAULT)); |
| 2496 "B", | |
| 2497 std::string(), | |
| 2498 "/foo", | |
| 2499 base::Time(), | |
| 2500 false, | |
| 2501 false, | |
| 2502 COOKIE_PRIORITY_DEFAULT)); | |
| 2503 ResultSavingCookieCallback<bool> callback(&other_thread_); | 2292 ResultSavingCookieCallback<bool> callback(&other_thread_); |
| 2504 base::Closure task = base::Bind( | 2293 base::Closure task = |
| 2505 &net::MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask, | 2294 base::Bind(&net::MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask, |
| 2506 base::Unretained(this), | 2295 base::Unretained(this), cm, url_google_foo_, &callback); |
| 2507 cm, url_google_foo_, &callback); | |
| 2508 RunOnOtherThread(task); | 2296 RunOnOtherThread(task); |
| 2509 EXPECT_TRUE(callback.did_run()); | 2297 EXPECT_TRUE(callback.did_run()); |
| 2510 EXPECT_TRUE(callback.result()); | 2298 EXPECT_TRUE(callback.result()); |
| 2511 } | 2299 } |
| 2512 | 2300 |
| 2513 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) { | 2301 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) { |
| 2514 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2302 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2515 CookieOptions options; | 2303 CookieOptions options; |
| 2516 Time now = Time::Now(); | 2304 Time now = Time::Now(); |
| 2517 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); | 2305 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); |
| 2518 EXPECT_EQ( | 2306 EXPECT_EQ(1, DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), |
| 2519 1, | 2307 Time())); |
| 2520 DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), Time())); | |
| 2521 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); | 2308 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); |
| 2522 ResultSavingCookieCallback<int> callback(&other_thread_); | 2309 ResultSavingCookieCallback<int> callback(&other_thread_); |
| 2523 base::Closure task = base::Bind( | 2310 base::Closure task = base::Bind( |
| 2524 &net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask, | 2311 &net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask, |
| 2525 base::Unretained(this), | 2312 base::Unretained(this), cm, now - TimeDelta::FromDays(99), Time(), |
| 2526 cm, now - TimeDelta::FromDays(99), | 2313 &callback); |
| 2527 Time(), &callback); | |
| 2528 RunOnOtherThread(task); | 2314 RunOnOtherThread(task); |
| 2529 EXPECT_TRUE(callback.did_run()); | 2315 EXPECT_TRUE(callback.did_run()); |
| 2530 EXPECT_EQ(1, callback.result()); | 2316 EXPECT_EQ(1, callback.result()); |
| 2531 } | 2317 } |
| 2532 | 2318 |
| 2533 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) { | 2319 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) { |
| 2534 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2320 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2535 CookieOptions options; | 2321 CookieOptions options; |
| 2536 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); | 2322 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); |
| 2537 EXPECT_EQ(1, DeleteAllForHost(cm.get(), url_google_)); | 2323 EXPECT_EQ(1, DeleteAllForHost(cm.get(), url_google_)); |
| 2538 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); | 2324 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); |
| 2539 ResultSavingCookieCallback<int> callback(&other_thread_); | 2325 ResultSavingCookieCallback<int> callback(&other_thread_); |
| 2540 base::Closure task = base::Bind( | 2326 base::Closure task = |
| 2541 &net::MultiThreadedCookieMonsterTest::DeleteAllForHostTask, | 2327 base::Bind(&net::MultiThreadedCookieMonsterTest::DeleteAllForHostTask, |
| 2542 base::Unretained(this), | 2328 base::Unretained(this), cm, url_google_, &callback); |
| 2543 cm, url_google_, &callback); | |
| 2544 RunOnOtherThread(task); | 2329 RunOnOtherThread(task); |
| 2545 EXPECT_TRUE(callback.did_run()); | 2330 EXPECT_TRUE(callback.did_run()); |
| 2546 EXPECT_EQ(1, callback.result()); | 2331 EXPECT_EQ(1, callback.result()); |
| 2547 } | 2332 } |
| 2548 | 2333 |
| 2549 TEST_F(MultiThreadedCookieMonsterTest, | 2334 TEST_F(MultiThreadedCookieMonsterTest, |
| 2550 ThreadCheckDeleteAllCreatedBetweenForHost) { | 2335 ThreadCheckDeleteAllCreatedBetweenForHost) { |
| 2551 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2336 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2552 GURL url_not_google("http://www.notgoogle.com"); | 2337 GURL url_not_google("http://www.notgoogle.com"); |
| 2553 | 2338 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2566 // This cookie does not match host. | 2351 // This cookie does not match host. |
| 2567 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_not_google, "E=F", options)); | 2352 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_not_google, "E=F", options)); |
| 2568 | 2353 |
| 2569 // This cookie does not match time range: [ago3, inf], for first deletion, but | 2354 // This cookie does not match time range: [ago3, inf], for first deletion, but |
| 2570 // matches for the second deletion. | 2355 // matches for the second deletion. |
| 2571 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "G=H", ago2)); | 2356 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "G=H", ago2)); |
| 2572 | 2357 |
| 2573 // 1. First set of deletions. | 2358 // 1. First set of deletions. |
| 2574 EXPECT_EQ( | 2359 EXPECT_EQ( |
| 2575 3, // Deletes A=B, C=D, Y=Z | 2360 3, // Deletes A=B, C=D, Y=Z |
| 2576 DeleteAllCreatedBetweenForHost( | 2361 DeleteAllCreatedBetweenForHost(cm.get(), ago3, Time::Max(), url_google_)); |
| 2577 cm.get(), ago3, Time::Max(), url_google_)); | |
| 2578 | 2362 |
| 2579 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); | 2363 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); |
| 2580 ResultSavingCookieCallback<int> callback(&other_thread_); | 2364 ResultSavingCookieCallback<int> callback(&other_thread_); |
| 2581 | 2365 |
| 2582 // 2. Second set of deletions. | 2366 // 2. Second set of deletions. |
| 2583 base::Closure task = base::Bind( | 2367 base::Closure task = base::Bind( |
| 2584 &net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenForHostTask, | 2368 &net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenForHostTask, |
| 2585 base::Unretained(this), | 2369 base::Unretained(this), cm, ago1, Time(), url_google_, &callback); |
| 2586 cm, ago1, Time(), url_google_, | |
| 2587 &callback); | |
| 2588 RunOnOtherThread(task); | 2370 RunOnOtherThread(task); |
| 2589 EXPECT_TRUE(callback.did_run()); | 2371 EXPECT_TRUE(callback.did_run()); |
| 2590 EXPECT_EQ(2, callback.result()); // Deletes A=B, G=H. | 2372 EXPECT_EQ(2, callback.result()); // Deletes A=B, G=H. |
| 2591 } | 2373 } |
| 2592 | 2374 |
| 2593 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) { | 2375 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) { |
| 2594 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2376 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
| 2595 CookieOptions options; | 2377 CookieOptions options; |
| 2596 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); | 2378 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); |
| 2597 CookieList cookies = GetAllCookies(cm.get()); | 2379 CookieList cookies = GetAllCookies(cm.get()); |
| 2598 CookieList::iterator it = cookies.begin(); | 2380 CookieList::iterator it = cookies.begin(); |
| 2599 EXPECT_TRUE(DeleteCanonicalCookie(cm.get(), *it)); | 2381 EXPECT_TRUE(DeleteCanonicalCookie(cm.get(), *it)); |
| 2600 | 2382 |
| 2601 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); | 2383 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); |
| 2602 ResultSavingCookieCallback<bool> callback(&other_thread_); | 2384 ResultSavingCookieCallback<bool> callback(&other_thread_); |
| 2603 cookies = GetAllCookies(cm.get()); | 2385 cookies = GetAllCookies(cm.get()); |
| 2604 it = cookies.begin(); | 2386 it = cookies.begin(); |
| 2605 base::Closure task = base::Bind( | 2387 base::Closure task = base::Bind( |
| 2606 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, | 2388 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, |
| 2607 base::Unretained(this), | 2389 base::Unretained(this), cm, *it, &callback); |
| 2608 cm, *it, &callback); | |
| 2609 RunOnOtherThread(task); | 2390 RunOnOtherThread(task); |
| 2610 EXPECT_TRUE(callback.did_run()); | 2391 EXPECT_TRUE(callback.did_run()); |
| 2611 EXPECT_TRUE(callback.result()); | 2392 EXPECT_TRUE(callback.result()); |
| 2612 } | 2393 } |
| 2613 | 2394 |
| 2614 // Ensure that cookies for http, https, ws, and wss all share the same storage | 2395 // Ensure that cookies for http, https, ws, and wss all share the same storage |
| 2615 // and policies when GetAllCookiesForURLAsync is used. This test is part of | 2396 // and policies when GetAllCookiesForURLAsync is used. This test is part of |
| 2616 // MultiThreadedCookieMonsterTest in order to test and use | 2397 // MultiThreadedCookieMonsterTest in order to test and use |
| 2617 // GetAllCookiesForURLAsync, but it does not use any additional threads. | 2398 // GetAllCookiesForURLAsync, but it does not use any additional threads. |
| 2618 TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) { | 2399 TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2668 GetAllCookiesForURLTask(cm.get(), url, &callback); | 2449 GetAllCookiesForURLTask(cm.get(), url, &callback); |
| 2669 ASSERT_TRUE(callback.did_run()); | 2450 ASSERT_TRUE(callback.did_run()); |
| 2670 ASSERT_EQ(1u, callback.cookies().size()); | 2451 ASSERT_EQ(1u, callback.cookies().size()); |
| 2671 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); | 2452 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); |
| 2672 } | 2453 } |
| 2673 } | 2454 } |
| 2674 | 2455 |
| 2675 TEST_F(CookieMonsterTest, InvalidExpiryTime) { | 2456 TEST_F(CookieMonsterTest, InvalidExpiryTime) { |
| 2676 std::string cookie_line = | 2457 std::string cookie_line = |
| 2677 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; | 2458 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; |
| 2678 scoped_ptr<CanonicalCookie> cookie( | 2459 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( |
| 2679 CanonicalCookie::Create(url_google_, cookie_line, Time::Now(), | 2460 url_google_, cookie_line, Time::Now(), CookieOptions())); |
| 2680 CookieOptions())); | |
| 2681 ASSERT_FALSE(cookie->IsPersistent()); | 2461 ASSERT_FALSE(cookie->IsPersistent()); |
| 2682 } | 2462 } |
| 2683 | 2463 |
| 2684 // Test that CookieMonster writes session cookies into the underlying | 2464 // Test that CookieMonster writes session cookies into the underlying |
| 2685 // CookieStore if the "persist session cookies" option is on. | 2465 // CookieStore if the "persist session cookies" option is on. |
| 2686 TEST_F(CookieMonsterTest, PersistSessionCookies) { | 2466 TEST_F(CookieMonsterTest, PersistSessionCookies) { |
| 2687 scoped_refptr<MockPersistentCookieStore> store( | 2467 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2688 new MockPersistentCookieStore); | |
| 2689 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2468 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); |
| 2690 cm->SetPersistSessionCookies(true); | 2469 cm->SetPersistSessionCookies(true); |
| 2691 | 2470 |
| 2692 // All cookies set with SetCookie are session cookies. | 2471 // All cookies set with SetCookie are session cookies. |
| 2693 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); | 2472 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); |
| 2694 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_)); | 2473 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_)); |
| 2695 | 2474 |
| 2696 // The cookie was written to the backing store. | 2475 // The cookie was written to the backing store. |
| 2697 EXPECT_EQ(1u, store->commands().size()); | 2476 EXPECT_EQ(1u, store->commands().size()); |
| 2698 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 2477 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2714 DeleteCookie(cm.get(), url_google_, "A"); | 2493 DeleteCookie(cm.get(), url_google_, "A"); |
| 2715 EXPECT_EQ("", GetCookies(cm.get(), url_google_)); | 2494 EXPECT_EQ("", GetCookies(cm.get(), url_google_)); |
| 2716 EXPECT_EQ(4u, store->commands().size()); | 2495 EXPECT_EQ(4u, store->commands().size()); |
| 2717 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); | 2496 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
| 2718 EXPECT_EQ("A", store->commands()[3].cookie.Name()); | 2497 EXPECT_EQ("A", store->commands()[3].cookie.Name()); |
| 2719 EXPECT_EQ("C", store->commands()[3].cookie.Value()); | 2498 EXPECT_EQ("C", store->commands()[3].cookie.Value()); |
| 2720 } | 2499 } |
| 2721 | 2500 |
| 2722 // Test the commands sent to the persistent cookie store. | 2501 // Test the commands sent to the persistent cookie store. |
| 2723 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) { | 2502 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) { |
| 2724 scoped_refptr<MockPersistentCookieStore> store( | 2503 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2725 new MockPersistentCookieStore); | |
| 2726 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2504 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); |
| 2727 | 2505 |
| 2728 // Add a cookie. | 2506 // Add a cookie. |
| 2729 EXPECT_TRUE(SetCookie( | 2507 EXPECT_TRUE(SetCookie(cm.get(), url_google_, |
| 2730 cm.get(), url_google_, "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 2508 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 2731 this->MatchCookieLines("A=B", GetCookies(cm.get(), url_google_)); | 2509 this->MatchCookieLines("A=B", GetCookies(cm.get(), url_google_)); |
| 2732 ASSERT_EQ(1u, store->commands().size()); | 2510 ASSERT_EQ(1u, store->commands().size()); |
| 2733 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 2511 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 2734 // Remove it. | 2512 // Remove it. |
| 2735 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B; max-age=0")); | 2513 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B; max-age=0")); |
| 2736 this->MatchCookieLines(std::string(), GetCookies(cm.get(), url_google_)); | 2514 this->MatchCookieLines(std::string(), GetCookies(cm.get(), url_google_)); |
| 2737 ASSERT_EQ(2u, store->commands().size()); | 2515 ASSERT_EQ(2u, store->commands().size()); |
| 2738 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); | 2516 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 2739 | 2517 |
| 2740 // Add a cookie. | 2518 // Add a cookie. |
| 2741 EXPECT_TRUE(SetCookie( | 2519 EXPECT_TRUE(SetCookie(cm.get(), url_google_, |
| 2742 cm.get(), url_google_, "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 2520 "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
| 2743 this->MatchCookieLines("A=B", GetCookies(cm.get(), url_google_)); | 2521 this->MatchCookieLines("A=B", GetCookies(cm.get(), url_google_)); |
| 2744 ASSERT_EQ(3u, store->commands().size()); | 2522 ASSERT_EQ(3u, store->commands().size()); |
| 2745 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); | 2523 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); |
| 2746 // Overwrite it. | 2524 // Overwrite it. |
| 2747 EXPECT_TRUE(SetCookie( | 2525 EXPECT_TRUE(SetCookie(cm.get(), url_google_, |
| 2748 cm.get(), url_google_, "A=Foo; expires=Mon, 18-Apr-22 22:50:14 GMT")); | 2526 "A=Foo; expires=Mon, 18-Apr-22 22:50:14 GMT")); |
| 2749 this->MatchCookieLines("A=Foo", GetCookies(cm.get(), url_google_)); | 2527 this->MatchCookieLines("A=Foo", GetCookies(cm.get(), url_google_)); |
| 2750 ASSERT_EQ(5u, store->commands().size()); | 2528 ASSERT_EQ(5u, store->commands().size()); |
| 2751 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); | 2529 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
| 2752 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); | 2530 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); |
| 2753 | 2531 |
| 2754 // Create some non-persistent cookies and check that they don't go to the | 2532 // Create some non-persistent cookies and check that they don't go to the |
| 2755 // persistent storage. | 2533 // persistent storage. |
| 2756 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=Bar")); | 2534 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=Bar")); |
| 2757 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm.get(), url_google_)); | 2535 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm.get(), url_google_)); |
| 2758 EXPECT_EQ(5u, store->commands().size()); | 2536 EXPECT_EQ(5u, store->commands().size()); |
| 2759 } | 2537 } |
| 2760 | 2538 |
| 2761 // Test to assure that cookies with control characters are purged appropriately. | 2539 // Test to assure that cookies with control characters are purged appropriately. |
| 2762 // See http://crbug.com/238041 for background. | 2540 // See http://crbug.com/238041 for background. |
| 2763 TEST_F(CookieMonsterTest, ControlCharacterPurge) { | 2541 TEST_F(CookieMonsterTest, ControlCharacterPurge) { |
| 2764 const Time now1(Time::Now()); | 2542 const Time now1(Time::Now()); |
| 2765 const Time now2(Time::Now() + TimeDelta::FromSeconds(1)); | 2543 const Time now2(Time::Now() + TimeDelta::FromSeconds(1)); |
| 2766 const Time now3(Time::Now() + TimeDelta::FromSeconds(2)); | 2544 const Time now3(Time::Now() + TimeDelta::FromSeconds(2)); |
| 2767 const Time later(now1 + TimeDelta::FromDays(1)); | 2545 const Time later(now1 + TimeDelta::FromDays(1)); |
| 2768 const GURL url("http://host/path"); | 2546 const GURL url("http://host/path"); |
| 2769 const std::string domain("host"); | 2547 const std::string domain("host"); |
| 2770 const std::string path("/path"); | 2548 const std::string path("/path"); |
| 2771 | 2549 |
| 2772 scoped_refptr<MockPersistentCookieStore> store( | 2550 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
| 2773 new MockPersistentCookieStore); | |
| 2774 | 2551 |
| 2775 std::vector<CanonicalCookie*> initial_cookies; | 2552 std::vector<CanonicalCookie*> initial_cookies; |
| 2776 | 2553 |
| 2777 AddCookieToList(domain, | 2554 AddCookieToList(domain, "foo=bar; path=" + path, now1, &initial_cookies); |
| 2778 "foo=bar; path=" + path, | |
| 2779 now1, | |
| 2780 &initial_cookies); | |
| 2781 | 2555 |
| 2782 // We have to manually build this cookie because it contains a control | 2556 // We have to manually build this cookie because it contains a control |
| 2783 // character, and our cookie line parser rejects control characters. | 2557 // character, and our cookie line parser rejects control characters. |
| 2784 CanonicalCookie *cc = new CanonicalCookie(url, "baz", "\x05" "boo", domain, | 2558 CanonicalCookie* cc = new CanonicalCookie( |
| 2785 path, now2, later, now2, false, | 2559 url, "baz", |
| 2786 false, COOKIE_PRIORITY_DEFAULT); | 2560 "\x05" |
| 2561 "boo", |
| 2562 domain, path, now2, later, now2, false, false, COOKIE_PRIORITY_DEFAULT); |
| 2787 initial_cookies.push_back(cc); | 2563 initial_cookies.push_back(cc); |
| 2788 | 2564 |
| 2789 AddCookieToList(domain, | 2565 AddCookieToList(domain, "hello=world; path=" + path, now3, &initial_cookies); |
| 2790 "hello=world; path=" + path, | |
| 2791 now3, | |
| 2792 &initial_cookies); | |
| 2793 | 2566 |
| 2794 // Inject our initial cookies into the mock PersistentCookieStore. | 2567 // Inject our initial cookies into the mock PersistentCookieStore. |
| 2795 store->SetLoadExpectation(true, initial_cookies); | 2568 store->SetLoadExpectation(true, initial_cookies); |
| 2796 | 2569 |
| 2797 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2570 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); |
| 2798 | 2571 |
| 2799 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); | 2572 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); |
| 2800 } | 2573 } |
| 2801 | 2574 |
| 2802 class CookieMonsterNotificationTest : public CookieMonsterTest { | 2575 class CookieMonsterNotificationTest : public CookieMonsterTest { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2824 bool removed) { | 2597 bool removed) { |
| 2825 DCHECK(out_cookies); | 2598 DCHECK(out_cookies); |
| 2826 out_cookies->push_back(cookie); | 2599 out_cookies->push_back(cookie); |
| 2827 if (out_removes) | 2600 if (out_removes) |
| 2828 out_removes->push_back(removed); | 2601 out_removes->push_back(removed); |
| 2829 } | 2602 } |
| 2830 | 2603 |
| 2831 TEST_F(CookieMonsterNotificationTest, NoNotifyWithNoCookie) { | 2604 TEST_F(CookieMonsterNotificationTest, NoNotifyWithNoCookie) { |
| 2832 std::vector<net::CanonicalCookie> cookies; | 2605 std::vector<net::CanonicalCookie> cookies; |
| 2833 scoped_ptr<CookieStore::CookieChangedSubscription> sub( | 2606 scoped_ptr<CookieStore::CookieChangedSubscription> sub( |
| 2834 monster()->AddCallbackForCookie(test_url_, "abc", | 2607 monster()->AddCallbackForCookie( |
| 2608 test_url_, "abc", |
| 2835 base::Bind(&RecordCookieChanges, &cookies, nullptr))); | 2609 base::Bind(&RecordCookieChanges, &cookies, nullptr))); |
| 2836 base::MessageLoop::current()->RunUntilIdle(); | 2610 base::MessageLoop::current()->RunUntilIdle(); |
| 2837 EXPECT_EQ(0U, cookies.size()); | 2611 EXPECT_EQ(0U, cookies.size()); |
| 2838 } | 2612 } |
| 2839 | 2613 |
| 2840 TEST_F(CookieMonsterNotificationTest, NoNotifyWithInitialCookie) { | 2614 TEST_F(CookieMonsterNotificationTest, NoNotifyWithInitialCookie) { |
| 2841 std::vector<net::CanonicalCookie> cookies; | 2615 std::vector<net::CanonicalCookie> cookies; |
| 2842 SetCookie(monster(), test_url_, "abc=def"); | 2616 SetCookie(monster(), test_url_, "abc=def"); |
| 2843 base::MessageLoop::current()->RunUntilIdle(); | 2617 base::MessageLoop::current()->RunUntilIdle(); |
| 2844 scoped_ptr<CookieStore::CookieChangedSubscription> sub( | 2618 scoped_ptr<CookieStore::CookieChangedSubscription> sub( |
| 2845 monster()->AddCallbackForCookie(test_url_, "abc", | 2619 monster()->AddCallbackForCookie( |
| 2620 test_url_, "abc", |
| 2846 base::Bind(&RecordCookieChanges, &cookies, nullptr))); | 2621 base::Bind(&RecordCookieChanges, &cookies, nullptr))); |
| 2847 base::MessageLoop::current()->RunUntilIdle(); | 2622 base::MessageLoop::current()->RunUntilIdle(); |
| 2848 EXPECT_EQ(0U, cookies.size()); | 2623 EXPECT_EQ(0U, cookies.size()); |
| 2849 } | 2624 } |
| 2850 | 2625 |
| 2851 TEST_F(CookieMonsterNotificationTest, NotifyOnSet) { | 2626 TEST_F(CookieMonsterNotificationTest, NotifyOnSet) { |
| 2852 std::vector<net::CanonicalCookie> cookies; | 2627 std::vector<net::CanonicalCookie> cookies; |
| 2853 std::vector<bool> removes; | 2628 std::vector<bool> removes; |
| 2854 scoped_ptr<CookieStore::CookieChangedSubscription> sub( | 2629 scoped_ptr<CookieStore::CookieChangedSubscription> sub( |
| 2855 monster()->AddCallbackForCookie(test_url_, "abc", | 2630 monster()->AddCallbackForCookie( |
| 2631 test_url_, "abc", |
| 2856 base::Bind(&RecordCookieChanges, &cookies, &removes))); | 2632 base::Bind(&RecordCookieChanges, &cookies, &removes))); |
| 2857 SetCookie(monster(), test_url_, "abc=def"); | 2633 SetCookie(monster(), test_url_, "abc=def"); |
| 2858 base::MessageLoop::current()->RunUntilIdle(); | 2634 base::MessageLoop::current()->RunUntilIdle(); |
| 2859 EXPECT_EQ(1U, cookies.size()); | 2635 EXPECT_EQ(1U, cookies.size()); |
| 2860 EXPECT_EQ(1U, removes.size()); | 2636 EXPECT_EQ(1U, removes.size()); |
| 2861 | 2637 |
| 2862 EXPECT_EQ("abc", cookies[0].Name()); | 2638 EXPECT_EQ("abc", cookies[0].Name()); |
| 2863 EXPECT_EQ("def", cookies[0].Value()); | 2639 EXPECT_EQ("def", cookies[0].Value()); |
| 2864 EXPECT_FALSE(removes[0]); | 2640 EXPECT_FALSE(removes[0]); |
| 2865 } | 2641 } |
| 2866 | 2642 |
| 2867 TEST_F(CookieMonsterNotificationTest, NotifyOnDelete) { | 2643 TEST_F(CookieMonsterNotificationTest, NotifyOnDelete) { |
| 2868 std::vector<net::CanonicalCookie> cookies; | 2644 std::vector<net::CanonicalCookie> cookies; |
| 2869 std::vector<bool> removes; | 2645 std::vector<bool> removes; |
| 2870 scoped_ptr<CookieStore::CookieChangedSubscription> sub( | 2646 scoped_ptr<CookieStore::CookieChangedSubscription> sub( |
| 2871 monster()->AddCallbackForCookie(test_url_, "abc", | 2647 monster()->AddCallbackForCookie( |
| 2648 test_url_, "abc", |
| 2872 base::Bind(&RecordCookieChanges, &cookies, &removes))); | 2649 base::Bind(&RecordCookieChanges, &cookies, &removes))); |
| 2873 SetCookie(monster(), test_url_, "abc=def"); | 2650 SetCookie(monster(), test_url_, "abc=def"); |
| 2874 base::MessageLoop::current()->RunUntilIdle(); | 2651 base::MessageLoop::current()->RunUntilIdle(); |
| 2875 EXPECT_EQ(1U, cookies.size()); | 2652 EXPECT_EQ(1U, cookies.size()); |
| 2876 EXPECT_EQ(1U, removes.size()); | 2653 EXPECT_EQ(1U, removes.size()); |
| 2877 | 2654 |
| 2878 DeleteCookie(monster(), test_url_, "abc"); | 2655 DeleteCookie(monster(), test_url_, "abc"); |
| 2879 base::MessageLoop::current()->RunUntilIdle(); | 2656 base::MessageLoop::current()->RunUntilIdle(); |
| 2880 EXPECT_EQ(2U, cookies.size()); | 2657 EXPECT_EQ(2U, cookies.size()); |
| 2881 EXPECT_EQ(2U, removes.size()); | 2658 EXPECT_EQ(2U, removes.size()); |
| 2882 | 2659 |
| 2883 EXPECT_EQ("abc", cookies[1].Name()); | 2660 EXPECT_EQ("abc", cookies[1].Name()); |
| 2884 EXPECT_EQ("def", cookies[1].Value()); | 2661 EXPECT_EQ("def", cookies[1].Value()); |
| 2885 EXPECT_TRUE(removes[1]); | 2662 EXPECT_TRUE(removes[1]); |
| 2886 } | 2663 } |
| 2887 | 2664 |
| 2888 TEST_F(CookieMonsterNotificationTest, NotifyOnUpdate) { | 2665 TEST_F(CookieMonsterNotificationTest, NotifyOnUpdate) { |
| 2889 std::vector<net::CanonicalCookie> cookies; | 2666 std::vector<net::CanonicalCookie> cookies; |
| 2890 std::vector<bool> removes; | 2667 std::vector<bool> removes; |
| 2891 scoped_ptr<CookieStore::CookieChangedSubscription> sub( | 2668 scoped_ptr<CookieStore::CookieChangedSubscription> sub( |
| 2892 monster()->AddCallbackForCookie(test_url_, "abc", | 2669 monster()->AddCallbackForCookie( |
| 2670 test_url_, "abc", |
| 2893 base::Bind(&RecordCookieChanges, &cookies, &removes))); | 2671 base::Bind(&RecordCookieChanges, &cookies, &removes))); |
| 2894 SetCookie(monster(), test_url_, "abc=def"); | 2672 SetCookie(monster(), test_url_, "abc=def"); |
| 2895 base::MessageLoop::current()->RunUntilIdle(); | 2673 base::MessageLoop::current()->RunUntilIdle(); |
| 2896 EXPECT_EQ(1U, cookies.size()); | 2674 EXPECT_EQ(1U, cookies.size()); |
| 2897 | 2675 |
| 2898 // Replacing an existing cookie is actually a two-phase delete + set | 2676 // Replacing an existing cookie is actually a two-phase delete + set |
| 2899 // operation, so we get an extra notification. | 2677 // operation, so we get an extra notification. |
| 2900 SetCookie(monster(), test_url_, "abc=ghi"); | 2678 SetCookie(monster(), test_url_, "abc=ghi"); |
| 2901 base::MessageLoop::current()->RunUntilIdle(); | 2679 base::MessageLoop::current()->RunUntilIdle(); |
| 2902 | 2680 |
| 2903 EXPECT_EQ(3U, cookies.size()); | 2681 EXPECT_EQ(3U, cookies.size()); |
| 2904 EXPECT_EQ(3U, removes.size()); | 2682 EXPECT_EQ(3U, removes.size()); |
| 2905 | 2683 |
| 2906 EXPECT_EQ("abc", cookies[1].Name()); | 2684 EXPECT_EQ("abc", cookies[1].Name()); |
| 2907 EXPECT_EQ("def", cookies[1].Value()); | 2685 EXPECT_EQ("def", cookies[1].Value()); |
| 2908 EXPECT_TRUE(removes[1]); | 2686 EXPECT_TRUE(removes[1]); |
| 2909 | 2687 |
| 2910 EXPECT_EQ("abc", cookies[2].Name()); | 2688 EXPECT_EQ("abc", cookies[2].Name()); |
| 2911 EXPECT_EQ("ghi", cookies[2].Value()); | 2689 EXPECT_EQ("ghi", cookies[2].Value()); |
| 2912 EXPECT_FALSE(removes[2]); | 2690 EXPECT_FALSE(removes[2]); |
| 2913 } | 2691 } |
| 2914 | 2692 |
| 2915 TEST_F(CookieMonsterNotificationTest, MultipleNotifies) { | 2693 TEST_F(CookieMonsterNotificationTest, MultipleNotifies) { |
| 2916 std::vector<net::CanonicalCookie> cookies0; | 2694 std::vector<net::CanonicalCookie> cookies0; |
| 2917 std::vector<net::CanonicalCookie> cookies1; | 2695 std::vector<net::CanonicalCookie> cookies1; |
| 2918 scoped_ptr<CookieStore::CookieChangedSubscription> sub0( | 2696 scoped_ptr<CookieStore::CookieChangedSubscription> sub0( |
| 2919 monster()->AddCallbackForCookie(test_url_, "abc", | 2697 monster()->AddCallbackForCookie( |
| 2698 test_url_, "abc", |
| 2920 base::Bind(&RecordCookieChanges, &cookies0, nullptr))); | 2699 base::Bind(&RecordCookieChanges, &cookies0, nullptr))); |
| 2921 scoped_ptr<CookieStore::CookieChangedSubscription> sub1( | 2700 scoped_ptr<CookieStore::CookieChangedSubscription> sub1( |
| 2922 monster()->AddCallbackForCookie(test_url_, "def", | 2701 monster()->AddCallbackForCookie( |
| 2702 test_url_, "def", |
| 2923 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 2703 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
| 2924 SetCookie(monster(), test_url_, "abc=def"); | 2704 SetCookie(monster(), test_url_, "abc=def"); |
| 2925 base::MessageLoop::current()->RunUntilIdle(); | 2705 base::MessageLoop::current()->RunUntilIdle(); |
| 2926 EXPECT_EQ(1U, cookies0.size()); | 2706 EXPECT_EQ(1U, cookies0.size()); |
| 2927 EXPECT_EQ(0U, cookies1.size()); | 2707 EXPECT_EQ(0U, cookies1.size()); |
| 2928 SetCookie(monster(), test_url_, "def=abc"); | 2708 SetCookie(monster(), test_url_, "def=abc"); |
| 2929 base::MessageLoop::current()->RunUntilIdle(); | 2709 base::MessageLoop::current()->RunUntilIdle(); |
| 2930 EXPECT_EQ(1U, cookies0.size()); | 2710 EXPECT_EQ(1U, cookies0.size()); |
| 2931 EXPECT_EQ(1U, cookies1.size()); | 2711 EXPECT_EQ(1U, cookies1.size()); |
| 2932 } | 2712 } |
| 2933 | 2713 |
| 2934 TEST_F(CookieMonsterNotificationTest, MultipleSameNotifies) { | 2714 TEST_F(CookieMonsterNotificationTest, MultipleSameNotifies) { |
| 2935 std::vector<net::CanonicalCookie> cookies0; | 2715 std::vector<net::CanonicalCookie> cookies0; |
| 2936 std::vector<net::CanonicalCookie> cookies1; | 2716 std::vector<net::CanonicalCookie> cookies1; |
| 2937 scoped_ptr<CookieStore::CookieChangedSubscription> sub0( | 2717 scoped_ptr<CookieStore::CookieChangedSubscription> sub0( |
| 2938 monster()->AddCallbackForCookie(test_url_, "abc", | 2718 monster()->AddCallbackForCookie( |
| 2719 test_url_, "abc", |
| 2939 base::Bind(&RecordCookieChanges, &cookies0, nullptr))); | 2720 base::Bind(&RecordCookieChanges, &cookies0, nullptr))); |
| 2940 scoped_ptr<CookieStore::CookieChangedSubscription> sub1( | 2721 scoped_ptr<CookieStore::CookieChangedSubscription> sub1( |
| 2941 monster()->AddCallbackForCookie(test_url_, "abc", | 2722 monster()->AddCallbackForCookie( |
| 2723 test_url_, "abc", |
| 2942 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 2724 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
| 2943 SetCookie(monster(), test_url_, "abc=def"); | 2725 SetCookie(monster(), test_url_, "abc=def"); |
| 2944 base::MessageLoop::current()->RunUntilIdle(); | 2726 base::MessageLoop::current()->RunUntilIdle(); |
| 2945 EXPECT_EQ(1U, cookies0.size()); | 2727 EXPECT_EQ(1U, cookies0.size()); |
| 2946 EXPECT_EQ(1U, cookies0.size()); | 2728 EXPECT_EQ(1U, cookies0.size()); |
| 2947 } | 2729 } |
| 2948 | 2730 |
| 2949 } // namespace net | 2731 } // namespace net |
| OLD | NEW |