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 27 matching lines...) Expand all Loading... |
38 using base::TimeDelta; | 38 using base::TimeDelta; |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 // TODO(erikwright): Replace the pre-existing MockPersistentCookieStore (and | 42 // TODO(erikwright): Replace the pre-existing MockPersistentCookieStore (and |
43 // brethren) with this one, and remove the 'New' prefix. | 43 // brethren) with this one, and remove the 'New' prefix. |
44 class NewMockPersistentCookieStore | 44 class NewMockPersistentCookieStore |
45 : public CookieMonster::PersistentCookieStore { | 45 : public CookieMonster::PersistentCookieStore { |
46 public: | 46 public: |
47 MOCK_METHOD1(Load, void(const LoadedCallback& loaded_callback)); | 47 MOCK_METHOD1(Load, void(const LoadedCallback& loaded_callback)); |
48 MOCK_METHOD2(LoadCookiesForKey, void(const std::string& key, | 48 MOCK_METHOD2(LoadCookiesForKey, |
49 const LoadedCallback& loaded_callback)); | 49 void(const std::string& key, |
| 50 const LoadedCallback& loaded_callback)); |
50 MOCK_METHOD1(AddCookie, void(const CanonicalCookie& cc)); | 51 MOCK_METHOD1(AddCookie, void(const CanonicalCookie& cc)); |
51 MOCK_METHOD1(UpdateCookieAccessTime, void(const CanonicalCookie& cc)); | 52 MOCK_METHOD1(UpdateCookieAccessTime, void(const CanonicalCookie& cc)); |
52 MOCK_METHOD1(DeleteCookie, void(const CanonicalCookie& cc)); | 53 MOCK_METHOD1(DeleteCookie, void(const CanonicalCookie& cc)); |
53 virtual void Flush(const base::Closure& callback) { | 54 virtual void Flush(const base::Closure& callback) { |
54 if (!callback.is_null()) | 55 if (!callback.is_null()) |
55 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 56 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
56 } | 57 } |
57 MOCK_METHOD0(SetForceKeepSessionState, void()); | 58 MOCK_METHOD0(SetForceKeepSessionState, void()); |
58 | 59 |
59 private: | 60 private: |
60 virtual ~NewMockPersistentCookieStore() {} | 61 virtual ~NewMockPersistentCookieStore() {} |
61 }; | 62 }; |
62 | 63 |
63 const char* kTopLevelDomainPlus1 = "http://www.harvard.edu"; | 64 const char* kTopLevelDomainPlus1 = "http://www.harvard.edu"; |
64 const char* kTopLevelDomainPlus2 = "http://www.math.harvard.edu"; | 65 const char* kTopLevelDomainPlus2 = "http://www.math.harvard.edu"; |
65 const char* kTopLevelDomainPlus2Secure = "https://www.math.harvard.edu"; | 66 const char* kTopLevelDomainPlus2Secure = "https://www.math.harvard.edu"; |
66 const char* kTopLevelDomainPlus3 = | 67 const char* kTopLevelDomainPlus3 = "http://www.bourbaki.math.harvard.edu"; |
67 "http://www.bourbaki.math.harvard.edu"; | |
68 const char* kOtherDomain = "http://www.mit.edu"; | 68 const char* kOtherDomain = "http://www.mit.edu"; |
69 const char kUrlGoogleSpecific[] = "http://www.gmail.google.izzle"; | 69 const char kUrlGoogleSpecific[] = "http://www.gmail.google.izzle"; |
70 | 70 |
71 class GetCookieListCallback : public CookieCallback { | 71 class GetCookieListCallback : public CookieCallback { |
72 public: | 72 public: |
73 GetCookieListCallback() {} | 73 GetCookieListCallback() {} |
74 explicit GetCookieListCallback(Thread* run_in_thread) | 74 explicit GetCookieListCallback(Thread* run_in_thread) |
75 : CookieCallback(run_in_thread) {} | 75 : CookieCallback(run_in_thread) {} |
76 | 76 |
77 void Run(const CookieList& cookies) { | 77 void Run(const CookieList& cookies) { |
78 cookies_ = cookies; | 78 cookies_ = cookies; |
79 CallbackEpilogue(); | 79 CallbackEpilogue(); |
80 } | 80 } |
81 | 81 |
82 const CookieList& cookies() { return cookies_; } | 82 const CookieList& cookies() { return cookies_; } |
83 | 83 |
84 private: | 84 private: |
85 CookieList cookies_; | 85 CookieList cookies_; |
86 }; | 86 }; |
87 | 87 |
88 struct CookieMonsterTestTraits { | 88 struct CookieMonsterTestTraits { |
89 static scoped_refptr<CookieStore> Create() { | 89 static scoped_refptr<CookieStore> Create() { |
90 return new CookieMonster(NULL, NULL); | 90 return new CookieMonster(NULL, NULL); |
91 } | 91 } |
92 | 92 |
93 static const bool is_cookie_monster = true; | 93 static const bool is_cookie_monster = true; |
94 static const bool supports_http_only = true; | 94 static const bool supports_http_only = true; |
95 static const bool supports_non_dotted_domains = true; | 95 static const bool supports_non_dotted_domains = true; |
96 static const bool supports_trailing_dots = true; | 96 static const bool supports_trailing_dots = true; |
97 static const bool filters_schemes = true; | 97 static const bool filters_schemes = true; |
98 static const bool has_path_prefix_bug = false; | 98 static const bool has_path_prefix_bug = false; |
99 static const int creation_time_granularity_in_ms = 0; | 99 static const int creation_time_granularity_in_ms = 0; |
100 }; | 100 }; |
101 | 101 |
102 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, | 102 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, |
103 CookieStoreTest, | 103 CookieStoreTest, |
104 CookieMonsterTestTraits); | 104 CookieMonsterTestTraits); |
105 | 105 |
106 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, | 106 INSTANTIATE_TYPED_TEST_CASE_P(CookieMonster, |
107 MultiThreadedCookieStoreTest, | 107 MultiThreadedCookieStoreTest, |
108 CookieMonsterTestTraits); | 108 CookieMonsterTestTraits); |
109 | 109 |
110 class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> { | 110 class CookieMonsterTest : public CookieStoreTest<CookieMonsterTestTraits> { |
111 protected: | 111 protected: |
112 | |
113 CookieList GetAllCookies(CookieMonster* cm) { | 112 CookieList GetAllCookies(CookieMonster* cm) { |
114 DCHECK(cm); | 113 DCHECK(cm); |
115 GetCookieListCallback callback; | 114 GetCookieListCallback callback; |
116 cm->GetAllCookiesAsync( | 115 cm->GetAllCookiesAsync( |
117 base::Bind(&GetCookieListCallback::Run, | 116 base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback))); |
118 base::Unretained(&callback))); | |
119 RunFor(kTimeout); | 117 RunFor(kTimeout); |
120 EXPECT_TRUE(callback.did_run()); | 118 EXPECT_TRUE(callback.did_run()); |
121 return callback.cookies(); | 119 return callback.cookies(); |
122 } | 120 } |
123 | 121 |
124 CookieList GetAllCookiesForURL(CookieMonster* cm, | 122 CookieList GetAllCookiesForURL(CookieMonster* cm, const GURL& url) { |
125 const GURL& url) { | |
126 DCHECK(cm); | 123 DCHECK(cm); |
127 GetCookieListCallback callback; | 124 GetCookieListCallback callback; |
128 cm->GetAllCookiesForURLAsync( | 125 cm->GetAllCookiesForURLAsync( |
129 url, base::Bind(&GetCookieListCallback::Run, | 126 url, |
130 base::Unretained(&callback))); | 127 base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback))); |
131 RunFor(kTimeout); | 128 RunFor(kTimeout); |
132 EXPECT_TRUE(callback.did_run()); | 129 EXPECT_TRUE(callback.did_run()); |
133 return callback.cookies(); | 130 return callback.cookies(); |
134 } | 131 } |
135 | 132 |
136 CookieList GetAllCookiesForURLWithOptions(CookieMonster* cm, | 133 CookieList GetAllCookiesForURLWithOptions(CookieMonster* cm, |
137 const GURL& url, | 134 const GURL& url, |
138 const CookieOptions& options) { | 135 const CookieOptions& options) { |
139 DCHECK(cm); | 136 DCHECK(cm); |
140 GetCookieListCallback callback; | 137 GetCookieListCallback callback; |
141 cm->GetAllCookiesForURLWithOptionsAsync( | 138 cm->GetAllCookiesForURLWithOptionsAsync( |
142 url, options, base::Bind(&GetCookieListCallback::Run, | 139 url, |
143 base::Unretained(&callback))); | 140 options, |
| 141 base::Bind(&GetCookieListCallback::Run, base::Unretained(&callback))); |
144 RunFor(kTimeout); | 142 RunFor(kTimeout); |
145 EXPECT_TRUE(callback.did_run()); | 143 EXPECT_TRUE(callback.did_run()); |
146 return callback.cookies(); | 144 return callback.cookies(); |
147 } | 145 } |
148 | 146 |
149 bool SetCookieWithDetails(CookieMonster* cm, | 147 bool SetCookieWithDetails(CookieMonster* cm, |
150 const GURL& url, | 148 const GURL& url, |
151 const std::string& name, | 149 const std::string& name, |
152 const std::string& value, | 150 const std::string& value, |
153 const std::string& domain, | 151 const std::string& domain, |
154 const std::string& path, | 152 const std::string& path, |
155 const base::Time& expiration_time, | 153 const base::Time& expiration_time, |
156 bool secure, | 154 bool secure, |
157 bool http_only, | 155 bool http_only, |
158 CookiePriority priority) { | 156 CookiePriority priority) { |
159 DCHECK(cm); | 157 DCHECK(cm); |
160 ResultSavingCookieCallback<bool> callback; | 158 ResultSavingCookieCallback<bool> callback; |
161 cm->SetCookieWithDetailsAsync( | 159 cm->SetCookieWithDetailsAsync( |
162 url, name, value, domain, path, expiration_time, secure, http_only, | 160 url, |
| 161 name, |
| 162 value, |
| 163 domain, |
| 164 path, |
| 165 expiration_time, |
| 166 secure, |
| 167 http_only, |
163 priority, | 168 priority, |
164 base::Bind( | 169 base::Bind(&ResultSavingCookieCallback<bool>::Run, |
165 &ResultSavingCookieCallback<bool>::Run, | 170 base::Unretained(&callback))); |
166 base::Unretained(&callback))); | |
167 RunFor(kTimeout); | 171 RunFor(kTimeout); |
168 EXPECT_TRUE(callback.did_run()); | 172 EXPECT_TRUE(callback.did_run()); |
169 return callback.result(); | 173 return callback.result(); |
170 } | 174 } |
171 | 175 |
172 int DeleteAll(CookieMonster*cm) { | 176 int DeleteAll(CookieMonster* cm) { |
173 DCHECK(cm); | 177 DCHECK(cm); |
174 ResultSavingCookieCallback<int> callback; | 178 ResultSavingCookieCallback<int> callback; |
175 cm->DeleteAllAsync( | 179 cm->DeleteAllAsync(base::Bind(&ResultSavingCookieCallback<int>::Run, |
176 base::Bind( | 180 base::Unretained(&callback))); |
177 &ResultSavingCookieCallback<int>::Run, | |
178 base::Unretained(&callback))); | |
179 RunFor(kTimeout); | 181 RunFor(kTimeout); |
180 EXPECT_TRUE(callback.did_run()); | 182 EXPECT_TRUE(callback.did_run()); |
181 return callback.result(); | 183 return callback.result(); |
182 } | 184 } |
183 | 185 |
184 int DeleteAllCreatedBetween(CookieMonster*cm, | 186 int DeleteAllCreatedBetween(CookieMonster* cm, |
185 const base::Time& delete_begin, | 187 const base::Time& delete_begin, |
186 const base::Time& delete_end) { | 188 const base::Time& delete_end) { |
187 DCHECK(cm); | 189 DCHECK(cm); |
188 ResultSavingCookieCallback<int> callback; | 190 ResultSavingCookieCallback<int> callback; |
189 cm->DeleteAllCreatedBetweenAsync( | 191 cm->DeleteAllCreatedBetweenAsync( |
190 delete_begin, delete_end, | 192 delete_begin, |
191 base::Bind( | 193 delete_end, |
192 &ResultSavingCookieCallback<int>::Run, | 194 base::Bind(&ResultSavingCookieCallback<int>::Run, |
193 base::Unretained(&callback))); | 195 base::Unretained(&callback))); |
194 RunFor(kTimeout); | 196 RunFor(kTimeout); |
195 EXPECT_TRUE(callback.did_run()); | 197 EXPECT_TRUE(callback.did_run()); |
196 return callback.result(); | 198 return callback.result(); |
197 } | 199 } |
198 | 200 |
199 int DeleteAllCreatedBetweenForHost(CookieMonster* cm, | 201 int DeleteAllCreatedBetweenForHost(CookieMonster* cm, |
200 const base::Time delete_begin, | 202 const base::Time delete_begin, |
201 const base::Time delete_end, | 203 const base::Time delete_end, |
202 const GURL& url) { | 204 const GURL& url) { |
203 DCHECK(cm); | 205 DCHECK(cm); |
204 ResultSavingCookieCallback<int> callback; | 206 ResultSavingCookieCallback<int> callback; |
205 cm->DeleteAllCreatedBetweenForHostAsync( | 207 cm->DeleteAllCreatedBetweenForHostAsync( |
206 delete_begin, delete_end, url, | 208 delete_begin, |
207 base::Bind( | 209 delete_end, |
208 &ResultSavingCookieCallback<int>::Run, | 210 url, |
209 base::Unretained(&callback))); | 211 base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 212 base::Unretained(&callback))); |
210 RunFor(kTimeout); | 213 RunFor(kTimeout); |
211 EXPECT_TRUE(callback.did_run()); | 214 EXPECT_TRUE(callback.did_run()); |
212 return callback.result(); | 215 return callback.result(); |
213 } | 216 } |
214 | 217 |
215 int DeleteAllForHost(CookieMonster* cm, | 218 int DeleteAllForHost(CookieMonster* cm, const GURL& url) { |
216 const GURL& url) { | |
217 DCHECK(cm); | 219 DCHECK(cm); |
218 ResultSavingCookieCallback<int> callback; | 220 ResultSavingCookieCallback<int> callback; |
219 cm->DeleteAllForHostAsync( | 221 cm->DeleteAllForHostAsync(url, |
220 url, base::Bind(&ResultSavingCookieCallback<int>::Run, | 222 base::Bind(&ResultSavingCookieCallback<int>::Run, |
221 base::Unretained(&callback))); | 223 base::Unretained(&callback))); |
222 RunFor(kTimeout); | 224 RunFor(kTimeout); |
223 EXPECT_TRUE(callback.did_run()); | 225 EXPECT_TRUE(callback.did_run()); |
224 return callback.result(); | 226 return callback.result(); |
225 } | 227 } |
226 | 228 |
227 bool DeleteCanonicalCookie(CookieMonster* cm, const CanonicalCookie& cookie) { | 229 bool DeleteCanonicalCookie(CookieMonster* cm, const CanonicalCookie& cookie) { |
228 DCHECK(cm); | 230 DCHECK(cm); |
229 ResultSavingCookieCallback<bool> callback; | 231 ResultSavingCookieCallback<bool> callback; |
230 cm->DeleteCanonicalCookieAsync( | 232 cm->DeleteCanonicalCookieAsync( |
231 cookie, | 233 cookie, |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 | 404 |
403 Time GetFirstCookieAccessDate(CookieMonster* cm) { | 405 Time GetFirstCookieAccessDate(CookieMonster* cm) { |
404 const CookieList all_cookies(this->GetAllCookies(cm)); | 406 const CookieList all_cookies(this->GetAllCookies(cm)); |
405 return all_cookies.front().LastAccessDate(); | 407 return all_cookies.front().LastAccessDate(); |
406 } | 408 } |
407 | 409 |
408 bool FindAndDeleteCookie(CookieMonster* cm, | 410 bool FindAndDeleteCookie(CookieMonster* cm, |
409 const std::string& domain, | 411 const std::string& domain, |
410 const std::string& name) { | 412 const std::string& name) { |
411 CookieList cookies = this->GetAllCookies(cm); | 413 CookieList cookies = this->GetAllCookies(cm); |
412 for (CookieList::iterator it = cookies.begin(); | 414 for (CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it) |
413 it != cookies.end(); ++it) | |
414 if (it->Domain() == domain && it->Name() == name) | 415 if (it->Domain() == domain && it->Name() == name) |
415 return this->DeleteCanonicalCookie(cm, *it); | 416 return this->DeleteCanonicalCookie(cm, *it); |
416 return false; | 417 return false; |
417 } | 418 } |
418 | 419 |
419 int CountInString(const std::string& str, char c) { | 420 int CountInString(const std::string& str, char c) { |
420 return std::count(str.begin(), str.end(), c); | 421 return std::count(str.begin(), str.end(), c); |
421 } | 422 } |
422 | 423 |
423 void TestHostGarbageCollectHelper() { | 424 void TestHostGarbageCollectHelper() { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 size_t expected_high_count) { | 504 size_t expected_high_count) { |
504 DeleteAll(cm); | 505 DeleteAll(cm); |
505 int next_cookie_id = 0; | 506 int next_cookie_id = 0; |
506 std::vector<CookiePriority> priority_list; | 507 std::vector<CookiePriority> priority_list; |
507 std::vector<int> id_list[3]; // Indexed by CookiePriority. | 508 std::vector<int> id_list[3]; // Indexed by CookiePriority. |
508 | 509 |
509 // Parse |coded_priority_str| and add cookies. | 510 // Parse |coded_priority_str| and add cookies. |
510 std::vector<std::string> priority_tok_list; | 511 std::vector<std::string> priority_tok_list; |
511 base::SplitString(coded_priority_str, ' ', &priority_tok_list); | 512 base::SplitString(coded_priority_str, ' ', &priority_tok_list); |
512 for (std::vector<std::string>::iterator it = priority_tok_list.begin(); | 513 for (std::vector<std::string>::iterator it = priority_tok_list.begin(); |
513 it != priority_tok_list.end(); ++it) { | 514 it != priority_tok_list.end(); |
| 515 ++it) { |
514 size_t len = it->length(); | 516 size_t len = it->length(); |
515 DCHECK_NE(len, 0U); | 517 DCHECK_NE(len, 0U); |
516 // Take last character as priority. | 518 // Take last character as priority. |
517 CookiePriority priority = CharToPriority((*it)[len - 1]); | 519 CookiePriority priority = CharToPriority((*it)[len - 1]); |
518 std::string priority_str = CookiePriorityToString(priority); | 520 std::string priority_str = CookiePriorityToString(priority); |
519 // The rest of the string (possibly empty) specifies repetition. | 521 // The rest of the string (possibly empty) specifies repetition. |
520 int rep = 1; | 522 int rep = 1; |
521 if (!it->empty()) { | 523 if (!it->empty()) { |
522 bool result = base::StringToInt( | 524 bool result = base::StringToInt( |
523 base::StringPiece(it->begin(), it->end() - 1), &rep); | 525 base::StringPiece(it->begin(), it->end() - 1), &rep); |
524 DCHECK(result); | 526 DCHECK(result); |
525 } | 527 } |
526 for (; rep > 0; --rep, ++next_cookie_id) { | 528 for (; rep > 0; --rep, ++next_cookie_id) { |
527 std::string cookie = base::StringPrintf( | 529 std::string cookie = base::StringPrintf( |
528 "a%d=b;priority=%s", next_cookie_id, priority_str.c_str()); | 530 "a%d=b;priority=%s", next_cookie_id, priority_str.c_str()); |
529 EXPECT_TRUE(SetCookie(cm, url_google_, cookie)); | 531 EXPECT_TRUE(SetCookie(cm, url_google_, cookie)); |
530 priority_list.push_back(priority); | 532 priority_list.push_back(priority); |
531 id_list[priority].push_back(next_cookie_id); | 533 id_list[priority].push_back(next_cookie_id); |
532 } | 534 } |
533 } | 535 } |
534 | 536 |
535 int num_cookies = static_cast<int>(priority_list.size()); | 537 int num_cookies = static_cast<int>(priority_list.size()); |
536 std::vector<int> surviving_id_list[3]; // Indexed by CookiePriority. | 538 std::vector<int> surviving_id_list[3]; // Indexed by CookiePriority. |
537 | 539 |
538 // Parse the list of cookies | 540 // Parse the list of cookies |
539 std::string cookie_str = this->GetCookies(cm, url_google_); | 541 std::string cookie_str = this->GetCookies(cm, url_google_); |
540 std::vector<std::string> cookie_tok_list; | 542 std::vector<std::string> cookie_tok_list; |
541 base::SplitString(cookie_str, ';', &cookie_tok_list); | 543 base::SplitString(cookie_str, ';', &cookie_tok_list); |
542 for (std::vector<std::string>::iterator it = cookie_tok_list.begin(); | 544 for (std::vector<std::string>::iterator it = cookie_tok_list.begin(); |
543 it != cookie_tok_list.end(); ++it) { | 545 it != cookie_tok_list.end(); |
| 546 ++it) { |
544 // Assuming *it is "a#=b", so extract and parse "#" portion. | 547 // Assuming *it is "a#=b", so extract and parse "#" portion. |
545 int id = -1; | 548 int id = -1; |
546 bool result = base::StringToInt( | 549 bool result = base::StringToInt( |
547 base::StringPiece(it->begin() + 1, it->end() - 2), &id); | 550 base::StringPiece(it->begin() + 1, it->end() - 2), &id); |
548 DCHECK(result); | 551 DCHECK(result); |
549 DCHECK_GE(id, 0); | 552 DCHECK_GE(id, 0); |
550 DCHECK_LT(id, num_cookies); | 553 DCHECK_LT(id, num_cookies); |
551 surviving_id_list[priority_list[id]].push_back(id); | 554 surviving_id_list[priority_list[id]].push_back(id); |
552 } | 555 } |
553 | 556 |
554 // Validate each priority. | 557 // Validate each priority. |
555 size_t expected_count[3] = { | 558 size_t expected_count[3] = {expected_low_count, expected_medium_count, |
556 expected_low_count, expected_medium_count, expected_high_count | 559 expected_high_count}; |
557 }; | |
558 for (int i = 0; i < 3; ++i) { | 560 for (int i = 0; i < 3; ++i) { |
559 DCHECK_LE(surviving_id_list[i].size(), id_list[i].size()); | 561 DCHECK_LE(surviving_id_list[i].size(), id_list[i].size()); |
560 EXPECT_EQ(expected_count[i], surviving_id_list[i].size()); | 562 EXPECT_EQ(expected_count[i], surviving_id_list[i].size()); |
561 // Verify that the remaining cookies are the most recent among those | 563 // Verify that the remaining cookies are the most recent among those |
562 // with the same priorities. | 564 // with the same priorities. |
563 if (expected_count[i] == surviving_id_list[i].size()) { | 565 if (expected_count[i] == surviving_id_list[i].size()) { |
564 std::sort(surviving_id_list[i].begin(), surviving_id_list[i].end()); | 566 std::sort(surviving_id_list[i].begin(), surviving_id_list[i].end()); |
565 EXPECT_TRUE(std::equal(surviving_id_list[i].begin(), | 567 EXPECT_TRUE(std::equal(surviving_id_list[i].begin(), |
566 surviving_id_list[i].end(), | 568 surviving_id_list[i].end(), |
567 id_list[i].end() - expected_count[i])); | 569 id_list[i].end() - expected_count[i])); |
568 } | 570 } |
569 } | 571 } |
570 } | 572 } |
571 | 573 |
572 void TestPriorityAwareGarbageCollectHelper() { | 574 void TestPriorityAwareGarbageCollectHelper() { |
573 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. | 575 // Hard-coding limits in the test, but use DCHECK_EQ to enforce constraint. |
574 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); | 576 DCHECK_EQ(180U, CookieMonster::kDomainMaxCookies); |
575 DCHECK_EQ(150U, CookieMonster::kDomainMaxCookies - | 577 DCHECK_EQ( |
576 CookieMonster::kDomainPurgeCookies); | 578 150U, |
| 579 CookieMonster::kDomainMaxCookies - CookieMonster::kDomainPurgeCookies); |
577 DCHECK_EQ(30U, CookieMonster::kDomainCookiesQuotaLow); | 580 DCHECK_EQ(30U, CookieMonster::kDomainCookiesQuotaLow); |
578 DCHECK_EQ(50U, CookieMonster::kDomainCookiesQuotaMedium); | 581 DCHECK_EQ(50U, CookieMonster::kDomainCookiesQuotaMedium); |
579 DCHECK_EQ(70U, CookieMonster::kDomainCookiesQuotaHigh); | 582 DCHECK_EQ(70U, CookieMonster::kDomainCookiesQuotaHigh); |
580 | 583 |
581 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 584 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
582 | 585 |
583 // Each test case adds 181 cookies, so 31 cookies are evicted. | 586 // Each test case adds 181 cookies, so 31 cookies are evicted. |
584 // Cookie same priority, repeated for each priority. | 587 // Cookie same priority, repeated for each priority. |
585 TestPriorityCookieCase(cm.get(), "181L", 150U, 0U, 0U); | 588 TestPriorityCookieCase(cm.get(), "181L", 150U, 0U, 0U); |
586 TestPriorityCookieCase(cm.get(), "181M", 0U, 150U, 0U); | 589 TestPriorityCookieCase(cm.get(), "181M", 0U, 150U, 0U); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 CookieMonster* cm(new CookieMonster(NULL, NULL)); | 628 CookieMonster* cm(new CookieMonster(NULL, NULL)); |
626 for (int i = 0; i < num_cookies; i++) { | 629 for (int i = 0; i < num_cookies; i++) { |
627 SetCookie(cm, GURL(base::StringPrintf("http://h%05d.izzle", i)), "a=1"); | 630 SetCookie(cm, GURL(base::StringPrintf("http://h%05d.izzle", i)), "a=1"); |
628 } | 631 } |
629 return cm; | 632 return cm; |
630 } | 633 } |
631 }; | 634 }; |
632 | 635 |
633 // TODO(erikwright): Replace the other callbacks and synchronous helper methods | 636 // TODO(erikwright): Replace the other callbacks and synchronous helper methods |
634 // in this test suite with these Mocks. | 637 // in this test suite with these Mocks. |
635 template<typename T, typename C> class MockCookieCallback { | 638 template <typename T, typename C> |
| 639 class MockCookieCallback { |
636 public: | 640 public: |
637 C AsCallback() { | 641 C AsCallback() { |
638 return base::Bind(&T::Invoke, base::Unretained(static_cast<T*>(this))); | 642 return base::Bind(&T::Invoke, base::Unretained(static_cast<T*>(this))); |
639 } | 643 } |
640 }; | 644 }; |
641 | 645 |
642 class MockGetCookiesCallback | 646 class MockGetCookiesCallback |
643 : public MockCookieCallback<MockGetCookiesCallback, | 647 : public MockCookieCallback<MockGetCookiesCallback, |
644 CookieStore::GetCookiesCallback> { | 648 CookieStore::GetCookiesCallback> { |
645 public: | 649 public: |
646 MOCK_METHOD1(Invoke, void(const std::string& cookies)); | 650 MOCK_METHOD1(Invoke, void(const std::string& cookies)); |
647 }; | 651 }; |
648 | 652 |
649 class MockSetCookiesCallback | 653 class MockSetCookiesCallback |
650 : public MockCookieCallback<MockSetCookiesCallback, | 654 : public MockCookieCallback<MockSetCookiesCallback, |
651 CookieStore::SetCookiesCallback> { | 655 CookieStore::SetCookiesCallback> { |
652 public: | 656 public: |
653 MOCK_METHOD1(Invoke, void(bool success)); | 657 MOCK_METHOD1(Invoke, void(bool success)); |
654 }; | 658 }; |
655 | 659 |
656 class MockClosure | 660 class MockClosure : public MockCookieCallback<MockClosure, base::Closure> { |
657 : public MockCookieCallback<MockClosure, base::Closure> { | |
658 public: | 661 public: |
659 MOCK_METHOD0(Invoke, void(void)); | 662 MOCK_METHOD0(Invoke, void(void)); |
660 }; | 663 }; |
661 | 664 |
662 class MockGetCookieListCallback | 665 class MockGetCookieListCallback |
663 : public MockCookieCallback<MockGetCookieListCallback, | 666 : public MockCookieCallback<MockGetCookieListCallback, |
664 CookieMonster::GetCookieListCallback> { | 667 CookieMonster::GetCookieListCallback> { |
665 public: | 668 public: |
666 MOCK_METHOD1(Invoke, void(const CookieList& cookies)); | 669 MOCK_METHOD1(Invoke, void(const CookieList& cookies)); |
667 }; | 670 }; |
668 | 671 |
669 class MockDeleteCallback | 672 class MockDeleteCallback |
670 : public MockCookieCallback<MockDeleteCallback, | 673 : public MockCookieCallback<MockDeleteCallback, |
671 CookieMonster::DeleteCallback> { | 674 CookieMonster::DeleteCallback> { |
672 public: | 675 public: |
673 MOCK_METHOD1(Invoke, void(int num_deleted)); | 676 MOCK_METHOD1(Invoke, void(int num_deleted)); |
674 }; | 677 }; |
675 | 678 |
676 class MockDeleteCookieCallback | 679 class MockDeleteCookieCallback |
677 : public MockCookieCallback<MockDeleteCookieCallback, | 680 : public MockCookieCallback<MockDeleteCookieCallback, |
678 CookieMonster::DeleteCookieCallback> { | 681 CookieMonster::DeleteCookieCallback> { |
679 public: | 682 public: |
680 MOCK_METHOD1(Invoke, void(bool success)); | 683 MOCK_METHOD1(Invoke, void(bool success)); |
681 }; | 684 }; |
682 | 685 |
683 struct CookiesInputInfo { | 686 struct CookiesInputInfo { |
684 const GURL url; | 687 const GURL url; |
685 const std::string name; | 688 const std::string name; |
686 const std::string value; | 689 const std::string value; |
687 const std::string domain; | 690 const std::string domain; |
688 const std::string path; | 691 const std::string path; |
(...skipping 15 matching lines...) Expand all Loading... |
704 } | 707 } |
705 ACTION_P3(GetCookiesAction, cookie_monster, url, callback) { | 708 ACTION_P3(GetCookiesAction, cookie_monster, url, callback) { |
706 cookie_monster->GetCookiesWithOptionsAsync( | 709 cookie_monster->GetCookiesWithOptionsAsync( |
707 url, CookieOptions(), callback->AsCallback()); | 710 url, CookieOptions(), callback->AsCallback()); |
708 } | 711 } |
709 ACTION_P4(SetCookieAction, cookie_monster, url, cookie_line, callback) { | 712 ACTION_P4(SetCookieAction, cookie_monster, url, cookie_line, callback) { |
710 cookie_monster->SetCookieWithOptionsAsync( | 713 cookie_monster->SetCookieWithOptionsAsync( |
711 url, cookie_line, CookieOptions(), callback->AsCallback()); | 714 url, cookie_line, CookieOptions(), callback->AsCallback()); |
712 } | 715 } |
713 ACTION_P4(DeleteAllCreatedBetweenAction, | 716 ACTION_P4(DeleteAllCreatedBetweenAction, |
714 cookie_monster, delete_begin, delete_end, callback) { | 717 cookie_monster, |
| 718 delete_begin, |
| 719 delete_end, |
| 720 callback) { |
715 cookie_monster->DeleteAllCreatedBetweenAsync( | 721 cookie_monster->DeleteAllCreatedBetweenAsync( |
716 delete_begin, delete_end, callback->AsCallback()); | 722 delete_begin, delete_end, callback->AsCallback()); |
717 } | 723 } |
718 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { | 724 ACTION_P3(SetCookieWithDetailsAction, cookie_monster, cc, callback) { |
719 cookie_monster->SetCookieWithDetailsAsync( | 725 cookie_monster->SetCookieWithDetailsAsync(cc.url, |
720 cc.url, cc.name, cc.value, cc.domain, cc.path, cc.expiration_time, | 726 cc.name, |
721 cc.secure, cc.http_only, cc.priority, | 727 cc.value, |
722 callback->AsCallback()); | 728 cc.domain, |
| 729 cc.path, |
| 730 cc.expiration_time, |
| 731 cc.secure, |
| 732 cc.http_only, |
| 733 cc.priority, |
| 734 callback->AsCallback()); |
723 } | 735 } |
724 | 736 |
725 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { | 737 ACTION_P2(GetAllCookiesAction, cookie_monster, callback) { |
726 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); | 738 cookie_monster->GetAllCookiesAsync(callback->AsCallback()); |
727 } | 739 } |
728 | 740 |
729 ACTION_P3(DeleteAllForHostAction, cookie_monster, url, callback) { | 741 ACTION_P3(DeleteAllForHostAction, cookie_monster, url, callback) { |
730 cookie_monster->DeleteAllForHostAsync(url, callback->AsCallback()); | 742 cookie_monster->DeleteAllForHostAsync(url, callback->AsCallback()); |
731 } | 743 } |
732 | 744 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 QuitCurrentMessageLoop())); | 838 QuitCurrentMessageLoop())); |
827 } | 839 } |
828 | 840 |
829 // Declares an expectation that PersistentCookieStore::LoadCookiesForKey | 841 // Declares an expectation that PersistentCookieStore::LoadCookiesForKey |
830 // will be called, saving the provided callback and sending a quit to the | 842 // will be called, saving the provided callback and sending a quit to the |
831 // message loop. | 843 // message loop. |
832 void ExpectLoadForKeyCall(std::string key, bool quit_queue) { | 844 void ExpectLoadForKeyCall(std::string key, bool quit_queue) { |
833 if (quit_queue) | 845 if (quit_queue) |
834 EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_)) | 846 EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_)) |
835 .WillOnce( | 847 .WillOnce( |
836 testing::DoAll(PushCallbackAction(&loaded_for_key_callbacks_), | 848 testing::DoAll(PushCallbackAction(&loaded_for_key_callbacks_), |
837 QuitCurrentMessageLoop())); | 849 QuitCurrentMessageLoop())); |
838 else | 850 else |
839 EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_)) | 851 EXPECT_CALL(*persistent_store_.get(), LoadCookiesForKey(key, testing::_)) |
840 .WillOnce(PushCallbackAction(&loaded_for_key_callbacks_)); | 852 .WillOnce(PushCallbackAction(&loaded_for_key_callbacks_)); |
841 } | 853 } |
842 | 854 |
843 // Invokes the initial action. | 855 // Invokes the initial action. |
844 MOCK_METHOD0(Begin, void(void)); | 856 MOCK_METHOD0(Begin, void(void)); |
845 | 857 |
846 // Returns the CookieMonster instance under test. | 858 // Returns the CookieMonster instance under test. |
847 CookieMonster& cookie_monster() { return *cookie_monster_.get(); } | 859 CookieMonster& cookie_monster() { return *cookie_monster_.get(); } |
848 | 860 |
849 private: | 861 private: |
850 // Declares that mock expectations in this test suite are strictly ordered. | 862 // Declares that mock expectations in this test suite are strictly ordered. |
851 testing::InSequence in_sequence_; | 863 testing::InSequence in_sequence_; |
852 // Holds cookies to be returned from PersistentCookieStore::Load or | 864 // Holds cookies to be returned from PersistentCookieStore::Load or |
853 // PersistentCookieStore::LoadCookiesForKey. | 865 // PersistentCookieStore::LoadCookiesForKey. |
854 std::vector<CanonicalCookie*> loaded_cookies_; | 866 std::vector<CanonicalCookie*> loaded_cookies_; |
855 // Stores the callback passed from the CookieMonster to the | 867 // Stores the callback passed from the CookieMonster to the |
856 // PersistentCookieStore::Load | 868 // PersistentCookieStore::Load |
857 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; | 869 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; |
858 // Stores the callback passed from the CookieMonster to the | 870 // Stores the callback passed from the CookieMonster to the |
859 // PersistentCookieStore::LoadCookiesForKey | 871 // PersistentCookieStore::LoadCookiesForKey |
860 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback> | 872 std::queue<CookieMonster::PersistentCookieStore::LoadedCallback> |
861 loaded_for_key_callbacks_; | 873 loaded_for_key_callbacks_; |
862 | 874 |
863 // Stores the CookieMonster under test. | 875 // Stores the CookieMonster under test. |
864 scoped_refptr<CookieMonster> cookie_monster_; | 876 scoped_refptr<CookieMonster> cookie_monster_; |
865 // Stores the mock PersistentCookieStore. | 877 // Stores the mock PersistentCookieStore. |
866 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; | 878 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; |
867 }; | 879 }; |
868 | 880 |
869 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { | 881 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { |
870 DeclareLoadedCookie("www.google.izzle", | 882 DeclareLoadedCookie("www.google.izzle", |
871 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 883 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
872 Time::Now() + TimeDelta::FromDays(3)); | 884 Time::Now() + TimeDelta::FromDays(3)); |
873 | 885 |
874 MockGetCookiesCallback get_cookies_callback; | 886 MockGetCookiesCallback get_cookies_callback; |
875 | 887 |
876 BeginWithForDomainKey("google.izzle", GetCookiesAction( | 888 BeginWithForDomainKey( |
877 &cookie_monster(), url_google_, &get_cookies_callback)); | 889 "google.izzle", |
| 890 GetCookiesAction(&cookie_monster(), url_google_, &get_cookies_callback)); |
878 | 891 |
879 WaitForLoadCall(); | 892 WaitForLoadCall(); |
880 | 893 |
881 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( | 894 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( |
882 GetCookiesAction(&cookie_monster(), url_google_, &get_cookies_callback)); | 895 GetCookiesAction(&cookie_monster(), url_google_, &get_cookies_callback)); |
883 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( | 896 EXPECT_CALL(get_cookies_callback, Invoke("X=1")) |
884 QuitCurrentMessageLoop()); | 897 .WillOnce(QuitCurrentMessageLoop()); |
885 | 898 |
886 CompleteLoadingAndWait(); | 899 CompleteLoadingAndWait(); |
887 } | 900 } |
888 | 901 |
889 TEST_F(DeferredCookieTaskTest, DeferredSetCookie) { | 902 TEST_F(DeferredCookieTaskTest, DeferredSetCookie) { |
890 MockSetCookiesCallback set_cookies_callback; | 903 MockSetCookiesCallback set_cookies_callback; |
891 | 904 |
892 BeginWithForDomainKey("google.izzle", SetCookieAction( | 905 BeginWithForDomainKey( |
893 &cookie_monster(), url_google_, "A=B", &set_cookies_callback)); | 906 "google.izzle", |
| 907 SetCookieAction( |
| 908 &cookie_monster(), url_google_, "A=B", &set_cookies_callback)); |
894 | 909 |
895 WaitForLoadCall(); | 910 WaitForLoadCall(); |
896 | 911 |
897 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( | 912 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce(SetCookieAction( |
898 SetCookieAction( | 913 &cookie_monster(), url_google_, "X=Y", &set_cookies_callback)); |
899 &cookie_monster(), url_google_, "X=Y", &set_cookies_callback)); | 914 EXPECT_CALL(set_cookies_callback, Invoke(true)) |
900 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( | 915 .WillOnce(QuitCurrentMessageLoop()); |
901 QuitCurrentMessageLoop()); | |
902 | 916 |
903 CompleteLoadingAndWait(); | 917 CompleteLoadingAndWait(); |
904 } | 918 } |
905 | 919 |
906 TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) { | 920 TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) { |
907 MockClosure delete_cookie_callback; | 921 MockClosure delete_cookie_callback; |
908 | 922 |
909 BeginWithForDomainKey("google.izzle", DeleteCookieAction( | 923 BeginWithForDomainKey( |
910 &cookie_monster(), url_google_, "A", &delete_cookie_callback)); | 924 "google.izzle", |
| 925 DeleteCookieAction( |
| 926 &cookie_monster(), url_google_, "A", &delete_cookie_callback)); |
911 | 927 |
912 WaitForLoadCall(); | 928 WaitForLoadCall(); |
913 | 929 |
914 EXPECT_CALL(delete_cookie_callback, Invoke()).WillOnce( | 930 EXPECT_CALL(delete_cookie_callback, Invoke()).WillOnce(DeleteCookieAction( |
915 DeleteCookieAction( | 931 &cookie_monster(), url_google_, "X", &delete_cookie_callback)); |
916 &cookie_monster(), url_google_, "X", &delete_cookie_callback)); | 932 EXPECT_CALL(delete_cookie_callback, Invoke()) |
917 EXPECT_CALL(delete_cookie_callback, Invoke()).WillOnce( | 933 .WillOnce(QuitCurrentMessageLoop()); |
918 QuitCurrentMessageLoop()); | |
919 | 934 |
920 CompleteLoadingAndWait(); | 935 CompleteLoadingAndWait(); |
921 } | 936 } |
922 | 937 |
923 TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) { | 938 TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) { |
924 MockSetCookiesCallback set_cookies_callback; | 939 MockSetCookiesCallback set_cookies_callback; |
925 | 940 |
926 CookiesInputInfo cookie_info = { | 941 CookiesInputInfo cookie_info = { |
927 url_google_foo_, "A", "B", std::string(), "/foo", | 942 url_google_foo_, "A", "B", std::string(), "/foo", |
928 base::Time(), false, false, COOKIE_PRIORITY_DEFAULT | 943 base::Time(), false, false, COOKIE_PRIORITY_DEFAULT}; |
929 }; | 944 BeginWithForDomainKey( |
930 BeginWithForDomainKey("google.izzle", SetCookieWithDetailsAction( | 945 "google.izzle", |
931 &cookie_monster(), cookie_info, &set_cookies_callback)); | 946 SetCookieWithDetailsAction( |
| 947 &cookie_monster(), cookie_info, &set_cookies_callback)); |
932 | 948 |
933 WaitForLoadCall(); | 949 WaitForLoadCall(); |
934 | 950 |
935 CookiesInputInfo cookie_info_exp = { | 951 CookiesInputInfo cookie_info_exp = { |
936 url_google_foo_, "A", "B", std::string(), "/foo", | 952 url_google_foo_, "A", "B", std::string(), "/foo", |
937 base::Time(), false, false, COOKIE_PRIORITY_DEFAULT | 953 base::Time(), false, false, COOKIE_PRIORITY_DEFAULT}; |
938 }; | 954 EXPECT_CALL(set_cookies_callback, Invoke(true)) |
939 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( | 955 .WillOnce(SetCookieWithDetailsAction( |
940 SetCookieWithDetailsAction( | |
941 &cookie_monster(), cookie_info_exp, &set_cookies_callback)); | 956 &cookie_monster(), cookie_info_exp, &set_cookies_callback)); |
942 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( | 957 EXPECT_CALL(set_cookies_callback, Invoke(true)) |
943 QuitCurrentMessageLoop()); | 958 .WillOnce(QuitCurrentMessageLoop()); |
944 | 959 |
945 CompleteLoadingAndWait(); | 960 CompleteLoadingAndWait(); |
946 } | 961 } |
947 | 962 |
948 TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) { | 963 TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) { |
949 DeclareLoadedCookie("www.google.izzle", | 964 DeclareLoadedCookie("www.google.izzle", |
950 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 965 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
951 Time::Now() + TimeDelta::FromDays(3)); | 966 Time::Now() + TimeDelta::FromDays(3)); |
952 | 967 |
953 MockGetCookieListCallback get_cookie_list_callback; | 968 MockGetCookieListCallback get_cookie_list_callback; |
954 | 969 |
955 BeginWith(GetAllCookiesAction( | 970 BeginWith(GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback)); |
956 &cookie_monster(), &get_cookie_list_callback)); | |
957 | 971 |
958 WaitForLoadCall(); | 972 WaitForLoadCall(); |
959 | 973 |
960 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 974 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( |
961 GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback)); | 975 GetAllCookiesAction(&cookie_monster(), &get_cookie_list_callback)); |
962 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 976 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) |
963 QuitCurrentMessageLoop()); | 977 .WillOnce(QuitCurrentMessageLoop()); |
964 | 978 |
965 CompleteLoadingAndWait(); | 979 CompleteLoadingAndWait(); |
966 } | 980 } |
967 | 981 |
968 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) { | 982 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) { |
969 DeclareLoadedCookie("www.google.izzle", | 983 DeclareLoadedCookie("www.google.izzle", |
970 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 984 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
971 Time::Now() + TimeDelta::FromDays(3)); | 985 Time::Now() + TimeDelta::FromDays(3)); |
972 | 986 |
973 MockGetCookieListCallback get_cookie_list_callback; | 987 MockGetCookieListCallback get_cookie_list_callback; |
974 | 988 |
975 BeginWithForDomainKey("google.izzle", GetAllCookiesForUrlAction( | 989 BeginWithForDomainKey( |
976 &cookie_monster(), url_google_, &get_cookie_list_callback)); | 990 "google.izzle", |
| 991 GetAllCookiesForUrlAction( |
| 992 &cookie_monster(), url_google_, &get_cookie_list_callback)); |
977 | 993 |
978 WaitForLoadCall(); | 994 WaitForLoadCall(); |
979 | 995 |
980 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 996 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) |
981 GetAllCookiesForUrlAction( | 997 .WillOnce(GetAllCookiesForUrlAction( |
982 &cookie_monster(), url_google_, &get_cookie_list_callback)); | 998 &cookie_monster(), url_google_, &get_cookie_list_callback)); |
983 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 999 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) |
984 QuitCurrentMessageLoop()); | 1000 .WillOnce(QuitCurrentMessageLoop()); |
985 | 1001 |
986 CompleteLoadingAndWait(); | 1002 CompleteLoadingAndWait(); |
987 } | 1003 } |
988 | 1004 |
989 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) { | 1005 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) { |
990 DeclareLoadedCookie("www.google.izzle", | 1006 DeclareLoadedCookie("www.google.izzle", |
991 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1007 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
992 Time::Now() + TimeDelta::FromDays(3)); | 1008 Time::Now() + TimeDelta::FromDays(3)); |
993 | 1009 |
994 MockGetCookieListCallback get_cookie_list_callback; | 1010 MockGetCookieListCallback get_cookie_list_callback; |
995 | 1011 |
996 BeginWithForDomainKey("google.izzle", GetAllCookiesForUrlWithOptionsAction( | 1012 BeginWithForDomainKey( |
997 &cookie_monster(), url_google_, &get_cookie_list_callback)); | 1013 "google.izzle", |
| 1014 GetAllCookiesForUrlWithOptionsAction( |
| 1015 &cookie_monster(), url_google_, &get_cookie_list_callback)); |
998 | 1016 |
999 WaitForLoadCall(); | 1017 WaitForLoadCall(); |
1000 | 1018 |
1001 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 1019 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) |
1002 GetAllCookiesForUrlWithOptionsAction( | 1020 .WillOnce(GetAllCookiesForUrlWithOptionsAction( |
1003 &cookie_monster(), url_google_, &get_cookie_list_callback)); | 1021 &cookie_monster(), url_google_, &get_cookie_list_callback)); |
1004 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 1022 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)) |
1005 QuitCurrentMessageLoop()); | 1023 .WillOnce(QuitCurrentMessageLoop()); |
1006 | 1024 |
1007 CompleteLoadingAndWait(); | 1025 CompleteLoadingAndWait(); |
1008 } | 1026 } |
1009 | 1027 |
1010 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCookies) { | 1028 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCookies) { |
1011 MockDeleteCallback delete_callback; | 1029 MockDeleteCallback delete_callback; |
1012 | 1030 |
1013 BeginWith(DeleteAllAction( | 1031 BeginWith(DeleteAllAction(&cookie_monster(), &delete_callback)); |
1014 &cookie_monster(), &delete_callback)); | |
1015 | 1032 |
1016 WaitForLoadCall(); | 1033 WaitForLoadCall(); |
1017 | 1034 |
1018 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 1035 EXPECT_CALL(delete_callback, Invoke(false)) |
1019 DeleteAllAction(&cookie_monster(), &delete_callback)); | 1036 .WillOnce(DeleteAllAction(&cookie_monster(), &delete_callback)); |
1020 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 1037 EXPECT_CALL(delete_callback, Invoke(false)) |
1021 QuitCurrentMessageLoop()); | 1038 .WillOnce(QuitCurrentMessageLoop()); |
1022 | 1039 |
1023 CompleteLoadingAndWait(); | 1040 CompleteLoadingAndWait(); |
1024 } | 1041 } |
1025 | 1042 |
1026 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCreatedBetweenCookies) { | 1043 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllCreatedBetweenCookies) { |
1027 MockDeleteCallback delete_callback; | 1044 MockDeleteCallback delete_callback; |
1028 | 1045 |
1029 BeginWith(DeleteAllCreatedBetweenAction( | 1046 BeginWith(DeleteAllCreatedBetweenAction( |
1030 &cookie_monster(), base::Time(), base::Time::Now(), &delete_callback)); | 1047 &cookie_monster(), base::Time(), base::Time::Now(), &delete_callback)); |
1031 | 1048 |
1032 WaitForLoadCall(); | 1049 WaitForLoadCall(); |
1033 | 1050 |
1034 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 1051 EXPECT_CALL(delete_callback, Invoke(false)) |
1035 DeleteAllCreatedBetweenAction( | 1052 .WillOnce(DeleteAllCreatedBetweenAction(&cookie_monster(), |
1036 &cookie_monster(), base::Time(), base::Time::Now(), | 1053 base::Time(), |
1037 &delete_callback)); | 1054 base::Time::Now(), |
1038 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 1055 &delete_callback)); |
1039 QuitCurrentMessageLoop()); | 1056 EXPECT_CALL(delete_callback, Invoke(false)) |
| 1057 .WillOnce(QuitCurrentMessageLoop()); |
1040 | 1058 |
1041 CompleteLoadingAndWait(); | 1059 CompleteLoadingAndWait(); |
1042 } | 1060 } |
1043 | 1061 |
1044 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCookies) { | 1062 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCookies) { |
1045 MockDeleteCallback delete_callback; | 1063 MockDeleteCallback delete_callback; |
1046 | 1064 |
1047 BeginWithForDomainKey("google.izzle", DeleteAllForHostAction( | 1065 BeginWithForDomainKey( |
1048 &cookie_monster(), url_google_, &delete_callback)); | 1066 "google.izzle", |
| 1067 DeleteAllForHostAction(&cookie_monster(), url_google_, &delete_callback)); |
1049 | 1068 |
1050 WaitForLoadCall(); | 1069 WaitForLoadCall(); |
1051 | 1070 |
1052 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 1071 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( |
1053 DeleteAllForHostAction( | 1072 DeleteAllForHostAction(&cookie_monster(), url_google_, &delete_callback)); |
1054 &cookie_monster(), url_google_, &delete_callback)); | 1073 EXPECT_CALL(delete_callback, Invoke(false)) |
1055 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 1074 .WillOnce(QuitCurrentMessageLoop()); |
1056 QuitCurrentMessageLoop()); | |
1057 | 1075 |
1058 CompleteLoadingAndWait(); | 1076 CompleteLoadingAndWait(); |
1059 } | 1077 } |
1060 | 1078 |
1061 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { | 1079 TEST_F(DeferredCookieTaskTest, DeferredDeleteCanonicalCookie) { |
1062 std::vector<CanonicalCookie*> cookies; | 1080 std::vector<CanonicalCookie*> cookies; |
1063 CanonicalCookie cookie = BuildCanonicalCookie( | 1081 CanonicalCookie cookie = |
1064 "www.google.com", "X=1; path=/", base::Time::Now()); | 1082 BuildCanonicalCookie("www.google.com", "X=1; path=/", base::Time::Now()); |
1065 | 1083 |
1066 MockDeleteCookieCallback delete_cookie_callback; | 1084 MockDeleteCookieCallback delete_cookie_callback; |
1067 | 1085 |
1068 BeginWith(DeleteCanonicalCookieAction( | 1086 BeginWith(DeleteCanonicalCookieAction( |
1069 &cookie_monster(), cookie, &delete_cookie_callback)); | 1087 &cookie_monster(), cookie, &delete_cookie_callback)); |
1070 | 1088 |
1071 WaitForLoadCall(); | 1089 WaitForLoadCall(); |
1072 | 1090 |
1073 EXPECT_CALL(delete_cookie_callback, Invoke(false)).WillOnce( | 1091 EXPECT_CALL(delete_cookie_callback, Invoke(false)) |
1074 DeleteCanonicalCookieAction( | 1092 .WillOnce(DeleteCanonicalCookieAction( |
1075 &cookie_monster(), cookie, &delete_cookie_callback)); | 1093 &cookie_monster(), cookie, &delete_cookie_callback)); |
1076 EXPECT_CALL(delete_cookie_callback, Invoke(false)).WillOnce( | 1094 EXPECT_CALL(delete_cookie_callback, Invoke(false)) |
1077 QuitCurrentMessageLoop()); | 1095 .WillOnce(QuitCurrentMessageLoop()); |
1078 | 1096 |
1079 CompleteLoadingAndWait(); | 1097 CompleteLoadingAndWait(); |
1080 } | 1098 } |
1081 | 1099 |
1082 TEST_F(DeferredCookieTaskTest, DeferredDeleteSessionCookies) { | 1100 TEST_F(DeferredCookieTaskTest, DeferredDeleteSessionCookies) { |
1083 MockDeleteCallback delete_callback; | 1101 MockDeleteCallback delete_callback; |
1084 | 1102 |
1085 BeginWith(DeleteSessionCookiesAction( | 1103 BeginWith(DeleteSessionCookiesAction(&cookie_monster(), &delete_callback)); |
1086 &cookie_monster(), &delete_callback)); | |
1087 | 1104 |
1088 WaitForLoadCall(); | 1105 WaitForLoadCall(); |
1089 | 1106 |
1090 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 1107 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( |
1091 DeleteSessionCookiesAction(&cookie_monster(), &delete_callback)); | 1108 DeleteSessionCookiesAction(&cookie_monster(), &delete_callback)); |
1092 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 1109 EXPECT_CALL(delete_callback, Invoke(false)) |
1093 QuitCurrentMessageLoop()); | 1110 .WillOnce(QuitCurrentMessageLoop()); |
1094 | 1111 |
1095 CompleteLoadingAndWait(); | 1112 CompleteLoadingAndWait(); |
1096 } | 1113 } |
1097 | 1114 |
1098 // Verify that a series of queued tasks are executed in order upon loading of | 1115 // Verify that a series of queued tasks are executed in order upon loading of |
1099 // the backing store and that new tasks received while the queued tasks are | 1116 // the backing store and that new tasks received while the queued tasks are |
1100 // being dispatched go to the end of the queue. | 1117 // being dispatched go to the end of the queue. |
1101 TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) { | 1118 TEST_F(DeferredCookieTaskTest, DeferredTaskOrder) { |
1102 DeclareLoadedCookie("www.google.izzle", | 1119 DeclareLoadedCookie("www.google.izzle", |
1103 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1120 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
1104 Time::Now() + TimeDelta::FromDays(3)); | 1121 Time::Now() + TimeDelta::FromDays(3)); |
1105 | 1122 |
1106 MockGetCookiesCallback get_cookies_callback; | 1123 MockGetCookiesCallback get_cookies_callback; |
1107 MockSetCookiesCallback set_cookies_callback; | 1124 MockSetCookiesCallback set_cookies_callback; |
1108 MockGetCookiesCallback get_cookies_callback_deferred; | 1125 MockGetCookiesCallback get_cookies_callback_deferred; |
1109 | 1126 |
1110 EXPECT_CALL(*this, Begin()).WillOnce(testing::DoAll( | 1127 EXPECT_CALL(*this, Begin()).WillOnce(testing::DoAll( |
1111 GetCookiesAction( | 1128 GetCookiesAction(&cookie_monster(), url_google_, &get_cookies_callback), |
1112 &cookie_monster(), url_google_, &get_cookies_callback), | |
1113 SetCookieAction( | 1129 SetCookieAction( |
1114 &cookie_monster(), url_google_, "A=B", &set_cookies_callback))); | 1130 &cookie_monster(), url_google_, "A=B", &set_cookies_callback))); |
1115 ExpectLoadCall(); | 1131 ExpectLoadCall(); |
1116 ExpectLoadForKeyCall("google.izzle", false); | 1132 ExpectLoadForKeyCall("google.izzle", false); |
1117 Begin(); | 1133 Begin(); |
1118 | 1134 |
1119 WaitForLoadCall(); | 1135 WaitForLoadCall(); |
1120 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( | 1136 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce(GetCookiesAction( |
1121 GetCookiesAction( | 1137 &cookie_monster(), url_google_, &get_cookies_callback_deferred)); |
1122 &cookie_monster(), url_google_, &get_cookies_callback_deferred)); | |
1123 EXPECT_CALL(set_cookies_callback, Invoke(true)); | 1138 EXPECT_CALL(set_cookies_callback, Invoke(true)); |
1124 EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1")).WillOnce( | 1139 EXPECT_CALL(get_cookies_callback_deferred, Invoke("A=B; X=1")) |
1125 QuitCurrentMessageLoop()); | 1140 .WillOnce(QuitCurrentMessageLoop()); |
1126 | 1141 |
1127 CompleteLoadingAndWait(); | 1142 CompleteLoadingAndWait(); |
1128 } | 1143 } |
1129 | 1144 |
1130 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { | 1145 TEST_F(CookieMonsterTest, TestCookieDeleteAll) { |
1131 scoped_refptr<MockPersistentCookieStore> store( | 1146 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
1132 new MockPersistentCookieStore); | |
1133 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 1147 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); |
1134 CookieOptions options; | 1148 CookieOptions options; |
1135 options.set_include_httponly(); | 1149 options.set_include_httponly(); |
1136 | 1150 |
1137 EXPECT_TRUE(SetCookie(cm.get(), url_google_, kValidCookieLine)); | 1151 EXPECT_TRUE(SetCookie(cm.get(), url_google_, kValidCookieLine)); |
1138 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_)); | 1152 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_)); |
1139 | 1153 |
1140 EXPECT_TRUE( | 1154 EXPECT_TRUE( |
1141 SetCookieWithOptions(cm.get(), url_google_, "C=D; httponly", options)); | 1155 SetCookieWithOptions(cm.get(), url_google_, "C=D; httponly", options)); |
1142 EXPECT_EQ("A=B; C=D", GetCookiesWithOptions(cm.get(), url_google_, options)); | 1156 EXPECT_EQ("A=B; C=D", GetCookiesWithOptions(cm.get(), url_google_, options)); |
(...skipping 21 matching lines...) Expand all Loading... |
1164 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1178 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
1165 Time now = Time::Now(); | 1179 Time now = Time::Now(); |
1166 | 1180 |
1167 // Nothing has been added so nothing should be deleted. | 1181 // Nothing has been added so nothing should be deleted. |
1168 EXPECT_EQ( | 1182 EXPECT_EQ( |
1169 0, | 1183 0, |
1170 DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), Time())); | 1184 DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), Time())); |
1171 | 1185 |
1172 // Create 3 cookies with creation date of today, yesterday and the day before. | 1186 // Create 3 cookies with creation date of today, yesterday and the day before. |
1173 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-0=Now", now)); | 1187 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-0=Now", now)); |
1174 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-1=Yesterday", | 1188 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
1175 now - TimeDelta::FromDays(1))); | 1189 url_google_, "T-1=Yesterday", now - TimeDelta::FromDays(1))); |
1176 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-2=DayBefore", | 1190 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
1177 now - TimeDelta::FromDays(2))); | 1191 url_google_, "T-2=DayBefore", now - TimeDelta::FromDays(2))); |
1178 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-3=ThreeDays", | 1192 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
1179 now - TimeDelta::FromDays(3))); | 1193 url_google_, "T-3=ThreeDays", now - TimeDelta::FromDays(3))); |
1180 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "T-7=LastWeek", | 1194 EXPECT_TRUE(cm->SetCookieWithCreationTime( |
1181 now - TimeDelta::FromDays(7))); | 1195 url_google_, "T-7=LastWeek", now - TimeDelta::FromDays(7))); |
1182 | 1196 |
1183 // Try to delete threedays and the daybefore. | 1197 // Try to delete threedays and the daybefore. |
1184 EXPECT_EQ(2, | 1198 EXPECT_EQ(2, |
1185 DeleteAllCreatedBetween(cm.get(), | 1199 DeleteAllCreatedBetween(cm.get(), |
1186 now - TimeDelta::FromDays(3), | 1200 now - TimeDelta::FromDays(3), |
1187 now - TimeDelta::FromDays(1))); | 1201 now - TimeDelta::FromDays(1))); |
1188 | 1202 |
1189 // Try to delete yesterday, also make sure that delete_end is not | 1203 // Try to delete yesterday, also make sure that delete_end is not |
1190 // inclusive. | 1204 // inclusive. |
1191 EXPECT_EQ( | 1205 EXPECT_EQ( |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A3; path=/bar")); | 1391 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=A3; path=/bar")); |
1378 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B1; path=/")); | 1392 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B1; path=/")); |
1379 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B2; path=/foo")); | 1393 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B2; path=/foo")); |
1380 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B3; path=/bar")); | 1394 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "B=B3; path=/bar")); |
1381 | 1395 |
1382 DeleteCookie(cm.get(), GURL(std::string(kUrlGoogle) + "/foo/bar"), "A"); | 1396 DeleteCookie(cm.get(), GURL(std::string(kUrlGoogle) + "/foo/bar"), "A"); |
1383 | 1397 |
1384 CookieList cookies = GetAllCookies(cm.get()); | 1398 CookieList cookies = GetAllCookies(cm.get()); |
1385 size_t expected_size = 4; | 1399 size_t expected_size = 4; |
1386 EXPECT_EQ(expected_size, cookies.size()); | 1400 EXPECT_EQ(expected_size, cookies.size()); |
1387 for (CookieList::iterator it = cookies.begin(); | 1401 for (CookieList::iterator it = cookies.begin(); it != cookies.end(); ++it) { |
1388 it != cookies.end(); ++it) { | |
1389 EXPECT_NE("A1", it->Value()); | 1402 EXPECT_NE("A1", it->Value()); |
1390 EXPECT_NE("A2", it->Value()); | 1403 EXPECT_NE("A2", it->Value()); |
1391 } | 1404 } |
1392 } | 1405 } |
1393 | 1406 |
1394 TEST_F(CookieMonsterTest, InitializeFromCookieMonster) { | 1407 TEST_F(CookieMonsterTest, InitializeFromCookieMonster) { |
1395 scoped_refptr<CookieMonster> cm_1(new CookieMonster(NULL, NULL)); | 1408 scoped_refptr<CookieMonster> cm_1(new CookieMonster(NULL, NULL)); |
1396 CookieOptions options; | 1409 CookieOptions options; |
1397 | 1410 |
1398 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_foo_, | 1411 EXPECT_TRUE(SetCookieWithOptions( |
1399 "A1=B; path=/foo;", | 1412 cm_1.get(), url_google_foo_, "A1=B; path=/foo;", options)); |
1400 options)); | 1413 EXPECT_TRUE(SetCookieWithOptions( |
1401 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_bar_, | 1414 cm_1.get(), url_google_bar_, "A2=D; path=/bar;", options)); |
1402 "A2=D; path=/bar;", | 1415 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_, "A3=F;", options)); |
1403 options)); | |
1404 EXPECT_TRUE(SetCookieWithOptions(cm_1.get(), url_google_, | |
1405 "A3=F;", | |
1406 options)); | |
1407 | 1416 |
1408 CookieList cookies_1 = GetAllCookies(cm_1.get()); | 1417 CookieList cookies_1 = GetAllCookies(cm_1.get()); |
1409 scoped_refptr<CookieMonster> cm_2(new CookieMonster(NULL, NULL)); | 1418 scoped_refptr<CookieMonster> cm_2(new CookieMonster(NULL, NULL)); |
1410 ASSERT_TRUE(cm_2->InitializeFrom(cookies_1)); | 1419 ASSERT_TRUE(cm_2->InitializeFrom(cookies_1)); |
1411 CookieList cookies_2 = GetAllCookies(cm_2.get()); | 1420 CookieList cookies_2 = GetAllCookies(cm_2.get()); |
1412 | 1421 |
1413 size_t expected_size = 3; | 1422 size_t expected_size = 3; |
1414 EXPECT_EQ(expected_size, cookies_2.size()); | 1423 EXPECT_EQ(expected_size, cookies_2.size()); |
1415 | 1424 |
1416 CookieList::iterator it = cookies_2.begin(); | 1425 CookieList::iterator it = cookies_2.begin(); |
(...skipping 10 matching lines...) Expand all Loading... |
1427 EXPECT_EQ("A3", it->Name()); | 1436 EXPECT_EQ("A3", it->Name()); |
1428 EXPECT_EQ("/", it->Path()); | 1437 EXPECT_EQ("/", it->Path()); |
1429 } | 1438 } |
1430 | 1439 |
1431 // Tests importing from a persistent cookie store that contains duplicate | 1440 // Tests importing from a persistent cookie store that contains duplicate |
1432 // equivalent cookies. This situation should be handled by removing the | 1441 // equivalent cookies. This situation should be handled by removing the |
1433 // duplicate cookie (both from the in-memory cache, and from the backing store). | 1442 // duplicate cookie (both from the in-memory cache, and from the backing store). |
1434 // | 1443 // |
1435 // This is a regression test for: http://crbug.com/17855. | 1444 // This is a regression test for: http://crbug.com/17855. |
1436 TEST_F(CookieMonsterTest, DontImportDuplicateCookies) { | 1445 TEST_F(CookieMonsterTest, DontImportDuplicateCookies) { |
1437 scoped_refptr<MockPersistentCookieStore> store( | 1446 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
1438 new MockPersistentCookieStore); | |
1439 | 1447 |
1440 // We will fill some initial cookies into the PersistentCookieStore, | 1448 // We will fill some initial cookies into the PersistentCookieStore, |
1441 // to simulate a database with 4 duplicates. Note that we need to | 1449 // to simulate a database with 4 duplicates. Note that we need to |
1442 // be careful not to have any duplicate creation times at all (as it's a | 1450 // be careful not to have any duplicate creation times at all (as it's a |
1443 // violation of a CookieMonster invariant) even if Time::Now() doesn't | 1451 // violation of a CookieMonster invariant) even if Time::Now() doesn't |
1444 // move between calls. | 1452 // move between calls. |
1445 std::vector<CanonicalCookie*> initial_cookies; | 1453 std::vector<CanonicalCookie*> initial_cookies; |
1446 | 1454 |
1447 // Insert 4 cookies with name "X" on path "/", with varying creation | 1455 // Insert 4 cookies with name "X" on path "/", with varying creation |
1448 // dates. We expect only the most recent one to be preserved following | 1456 // dates. We expect only the most recent one to be preserved following |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1510 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type); | 1518 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[2].type); |
1511 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); | 1519 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
1512 } | 1520 } |
1513 | 1521 |
1514 // Tests importing from a persistent cookie store that contains cookies | 1522 // Tests importing from a persistent cookie store that contains cookies |
1515 // with duplicate creation times. This situation should be handled by | 1523 // with duplicate creation times. This situation should be handled by |
1516 // dropping the cookies before insertion/visibility to user. | 1524 // dropping the cookies before insertion/visibility to user. |
1517 // | 1525 // |
1518 // This is a regression test for: http://crbug.com/43188. | 1526 // This is a regression test for: http://crbug.com/43188. |
1519 TEST_F(CookieMonsterTest, DontImportDuplicateCreationTimes) { | 1527 TEST_F(CookieMonsterTest, DontImportDuplicateCreationTimes) { |
1520 scoped_refptr<MockPersistentCookieStore> store( | 1528 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
1521 new MockPersistentCookieStore); | |
1522 | 1529 |
1523 Time now(Time::Now()); | 1530 Time now(Time::Now()); |
1524 Time earlier(now - TimeDelta::FromDays(1)); | 1531 Time earlier(now - TimeDelta::FromDays(1)); |
1525 | 1532 |
1526 // Insert 8 cookies, four with the current time as creation times, and | 1533 // Insert 8 cookies, four with the current time as creation times, and |
1527 // four with the earlier time as creation times. We should only get | 1534 // four with the earlier time as creation times. We should only get |
1528 // two cookies remaining, but which two (other than that there should | 1535 // two cookies remaining, but which two (other than that there should |
1529 // be one from each set) will be random. | 1536 // be one from each set) will be random. |
1530 std::vector<CanonicalCookie*> initial_cookies; | 1537 std::vector<CanonicalCookie*> initial_cookies; |
1531 AddCookieToList("www.google.com", "X=1; path=/", now, &initial_cookies); | 1538 AddCookieToList("www.google.com", "X=1; path=/", now, &initial_cookies); |
(...skipping 15 matching lines...) Expand all Loading... |
1547 EXPECT_EQ(2U, list.size()); | 1554 EXPECT_EQ(2U, list.size()); |
1548 // Confirm that we have one of each. | 1555 // Confirm that we have one of each. |
1549 std::string name1(list[0].Name()); | 1556 std::string name1(list[0].Name()); |
1550 std::string name2(list[1].Name()); | 1557 std::string name2(list[1].Name()); |
1551 EXPECT_TRUE(name1 == "X" || name2 == "X"); | 1558 EXPECT_TRUE(name1 == "X" || name2 == "X"); |
1552 EXPECT_TRUE(name1 == "Y" || name2 == "Y"); | 1559 EXPECT_TRUE(name1 == "Y" || name2 == "Y"); |
1553 EXPECT_NE(name1, name2); | 1560 EXPECT_NE(name1, name2); |
1554 } | 1561 } |
1555 | 1562 |
1556 TEST_F(CookieMonsterTest, CookieMonsterDelegate) { | 1563 TEST_F(CookieMonsterTest, CookieMonsterDelegate) { |
1557 scoped_refptr<MockPersistentCookieStore> store( | 1564 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
1558 new MockPersistentCookieStore); | |
1559 scoped_refptr<MockCookieMonsterDelegate> delegate( | 1565 scoped_refptr<MockCookieMonsterDelegate> delegate( |
1560 new MockCookieMonsterDelegate); | 1566 new MockCookieMonsterDelegate); |
1561 scoped_refptr<CookieMonster> cm( | 1567 scoped_refptr<CookieMonster> cm( |
1562 new CookieMonster(store.get(), delegate.get())); | 1568 new CookieMonster(store.get(), delegate.get())); |
1563 | 1569 |
1564 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); | 1570 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); |
1565 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "C=D")); | 1571 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "C=D")); |
1566 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "E=F")); | 1572 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "E=F")); |
1567 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), url_google_)); | 1573 EXPECT_EQ("A=B; C=D; E=F", GetCookies(cm.get(), url_google_)); |
1568 ASSERT_EQ(3u, delegate->changes().size()); | 1574 ASSERT_EQ(3u, delegate->changes().size()); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1769 // the http_only cookie, the host secure cookie, and the two host | 1775 // the http_only cookie, the host secure cookie, and the two host |
1770 // path cookies. http_only, secure, and paths are ignored by | 1776 // path cookies. http_only, secure, and paths are ignored by |
1771 // this call, and domain cookies arent touched. | 1777 // this call, and domain cookies arent touched. |
1772 PopulateCmForDeleteAllForHost(cm); | 1778 PopulateCmForDeleteAllForHost(cm); |
1773 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1779 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
1774 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1780 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
1775 EXPECT_EQ("dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", | 1781 EXPECT_EQ("dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", |
1776 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1782 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
1777 EXPECT_EQ("dom_1=X; host_1=X", | 1783 EXPECT_EQ("dom_1=X; host_1=X", |
1778 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1784 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
1779 EXPECT_EQ("dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; " | 1785 EXPECT_EQ( |
1780 "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", | 1786 "dom_path_2=X; host_path_2=X; dom_path_1=X; host_path_1=X; " |
1781 GetCookies(cm.get(), | 1787 "dom_1=X; dom_2=X; host_2=X; sec_dom=X; sec_host=X", |
1782 GURL(kTopLevelDomainPlus2Secure + | 1788 GetCookies( |
1783 std::string("/dir1/dir2/xxx")))); | 1789 cm.get(), |
| 1790 GURL(kTopLevelDomainPlus2Secure + std::string("/dir1/dir2/xxx")))); |
1784 | 1791 |
1785 EXPECT_EQ(5, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2))); | 1792 EXPECT_EQ(5, DeleteAllForHost(cm.get(), GURL(kTopLevelDomainPlus2))); |
1786 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); | 1793 EXPECT_EQ(8U, GetAllCookies(cm.get()).size()); |
1787 | 1794 |
1788 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", | 1795 EXPECT_EQ("dom_1=X; dom_2=X; dom_3=X; host_3=X", |
1789 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); | 1796 GetCookies(cm.get(), GURL(kTopLevelDomainPlus3))); |
1790 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", | 1797 EXPECT_EQ("dom_1=X; dom_2=X; sec_dom=X", |
1791 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); | 1798 GetCookies(cm.get(), GURL(kTopLevelDomainPlus2Secure))); |
1792 EXPECT_EQ("dom_1=X; host_1=X", | 1799 EXPECT_EQ("dom_1=X; host_1=X", |
1793 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); | 1800 GetCookies(cm.get(), GURL(kTopLevelDomainPlus1))); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1884 Time(), | 1891 Time(), |
1885 false, | 1892 false, |
1886 false, | 1893 false, |
1887 COOKIE_PRIORITY_DEFAULT); | 1894 COOKIE_PRIORITY_DEFAULT); |
1888 | 1895 |
1889 // Now we check | 1896 // Now we check |
1890 CookieList cookie_list(GetAllCookies(cm.get())); | 1897 CookieList cookie_list(GetAllCookies(cm.get())); |
1891 typedef std::map<int64, CanonicalCookie> TimeCookieMap; | 1898 typedef std::map<int64, CanonicalCookie> TimeCookieMap; |
1892 TimeCookieMap check_map; | 1899 TimeCookieMap check_map; |
1893 for (CookieList::const_iterator it = cookie_list.begin(); | 1900 for (CookieList::const_iterator it = cookie_list.begin(); |
1894 it != cookie_list.end(); it++) { | 1901 it != cookie_list.end(); |
| 1902 it++) { |
1895 const int64 creation_date = it->CreationDate().ToInternalValue(); | 1903 const int64 creation_date = it->CreationDate().ToInternalValue(); |
1896 TimeCookieMap::const_iterator | 1904 TimeCookieMap::const_iterator existing_cookie_it( |
1897 existing_cookie_it(check_map.find(creation_date)); | 1905 check_map.find(creation_date)); |
1898 EXPECT_TRUE(existing_cookie_it == check_map.end()) | 1906 EXPECT_TRUE(existing_cookie_it == check_map.end()) |
1899 << "Cookie " << it->Name() << " has same creation date (" | 1907 << "Cookie " << it->Name() << " has same creation date (" |
1900 << it->CreationDate().ToInternalValue() | 1908 << it->CreationDate().ToInternalValue() |
1901 << ") as previously entered cookie " | 1909 << ") as previously entered cookie " |
1902 << existing_cookie_it->second.Name(); | 1910 << existing_cookie_it->second.Name(); |
1903 | 1911 |
1904 if (existing_cookie_it == check_map.end()) { | 1912 if (existing_cookie_it == check_map.end()) { |
1905 check_map.insert(TimeCookieMap::value_type( | 1913 check_map.insert( |
1906 it->CreationDate().ToInternalValue(), *it)); | 1914 TimeCookieMap::value_type(it->CreationDate().ToInternalValue(), *it)); |
1907 } | 1915 } |
1908 } | 1916 } |
1909 } | 1917 } |
1910 | 1918 |
1911 // Mainly a test of GetEffectiveDomain, or more specifically, of the | 1919 // Mainly a test of GetEffectiveDomain, or more specifically, of the |
1912 // expected behavior of GetEffectiveDomain within the CookieMonster. | 1920 // expected behavior of GetEffectiveDomain within the CookieMonster. |
1913 TEST_F(CookieMonsterTest, GetKey) { | 1921 TEST_F(CookieMonsterTest, GetKey) { |
1914 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1922 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
1915 | 1923 |
1916 // This test is really only interesting if GetKey() actually does something. | 1924 // This test is really only interesting if GetKey() actually does something. |
(...skipping 19 matching lines...) Expand all Loading... |
1936 TEST_F(CookieMonsterTest, BackingStoreCommunication) { | 1944 TEST_F(CookieMonsterTest, BackingStoreCommunication) { |
1937 // Store details for cookies transforming through the backing store interface. | 1945 // Store details for cookies transforming through the backing store interface. |
1938 | 1946 |
1939 base::Time current(base::Time::Now()); | 1947 base::Time current(base::Time::Now()); |
1940 scoped_refptr<MockSimplePersistentCookieStore> store( | 1948 scoped_refptr<MockSimplePersistentCookieStore> store( |
1941 new MockSimplePersistentCookieStore); | 1949 new MockSimplePersistentCookieStore); |
1942 base::Time new_access_time; | 1950 base::Time new_access_time; |
1943 base::Time expires(base::Time::Now() + base::TimeDelta::FromSeconds(100)); | 1951 base::Time expires(base::Time::Now() + base::TimeDelta::FromSeconds(100)); |
1944 | 1952 |
1945 const CookiesInputInfo input_info[] = { | 1953 const CookiesInputInfo input_info[] = { |
1946 {GURL("http://a.b.google.com"), "a", "1", "", "/path/to/cookie", expires, | 1954 {GURL("http://a.b.google.com"), "a", "1", "", "/path/to/cookie", expires, |
1947 false, false, COOKIE_PRIORITY_DEFAULT}, | 1955 false, false, COOKIE_PRIORITY_DEFAULT}, |
1948 {GURL("https://www.google.com"), "b", "2", ".google.com", | 1956 {GURL("https://www.google.com"), "b", "2", ".google.com", |
1949 "/path/from/cookie", expires + TimeDelta::FromSeconds(10), | 1957 "/path/from/cookie", expires + TimeDelta::FromSeconds(10), true, true, |
1950 true, true, COOKIE_PRIORITY_DEFAULT}, | 1958 COOKIE_PRIORITY_DEFAULT}, |
1951 {GURL("https://google.com"), "c", "3", "", "/another/path/to/cookie", | 1959 {GURL("https://google.com"), "c", "3", "", "/another/path/to/cookie", |
1952 base::Time::Now() + base::TimeDelta::FromSeconds(100), | 1960 base::Time::Now() + base::TimeDelta::FromSeconds(100), true, false, |
1953 true, false, COOKIE_PRIORITY_DEFAULT} | 1961 COOKIE_PRIORITY_DEFAULT}}; |
1954 }; | |
1955 const int INPUT_DELETE = 1; | 1962 const int INPUT_DELETE = 1; |
1956 | 1963 |
1957 // Create new cookies and flush them to the store. | 1964 // Create new cookies and flush them to the store. |
1958 { | 1965 { |
1959 scoped_refptr<CookieMonster> cmout(new CookieMonster(store.get(), NULL)); | 1966 scoped_refptr<CookieMonster> cmout(new CookieMonster(store.get(), NULL)); |
1960 for (const CookiesInputInfo* p = input_info; | 1967 for (const CookiesInputInfo* p = input_info; |
1961 p < &input_info[ARRAYSIZE_UNSAFE(input_info)]; | 1968 p < &input_info[ARRAYSIZE_UNSAFE(input_info)]; |
1962 p++) { | 1969 p++) { |
1963 EXPECT_TRUE(SetCookieWithDetails(cmout.get(), | 1970 EXPECT_TRUE(SetCookieWithDetails(cmout.get(), |
1964 p->url, | 1971 p->url, |
1965 p->name, | 1972 p->name, |
1966 p->value, | 1973 p->value, |
1967 p->domain, | 1974 p->domain, |
1968 p->path, | 1975 p->path, |
1969 p->expiration_time, | 1976 p->expiration_time, |
1970 p->secure, | 1977 p->secure, |
1971 p->http_only, | 1978 p->http_only, |
1972 p->priority)); | 1979 p->priority)); |
1973 } | 1980 } |
1974 GURL del_url(input_info[INPUT_DELETE].url.Resolve( | 1981 GURL del_url(input_info[INPUT_DELETE] |
1975 input_info[INPUT_DELETE].path).spec()); | 1982 .url.Resolve(input_info[INPUT_DELETE].path) |
| 1983 .spec()); |
1976 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name); | 1984 DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name); |
1977 } | 1985 } |
1978 | 1986 |
1979 // Create a new cookie monster and make sure that everything is correct | 1987 // Create a new cookie monster and make sure that everything is correct |
1980 { | 1988 { |
1981 scoped_refptr<CookieMonster> cmin(new CookieMonster(store.get(), NULL)); | 1989 scoped_refptr<CookieMonster> cmin(new CookieMonster(store.get(), NULL)); |
1982 CookieList cookies(GetAllCookies(cmin.get())); | 1990 CookieList cookies(GetAllCookies(cmin.get())); |
1983 ASSERT_EQ(2u, cookies.size()); | 1991 ASSERT_EQ(2u, cookies.size()); |
1984 // Ordering is path length, then creation time. So second cookie | 1992 // Ordering is path length, then creation time. So second cookie |
1985 // will come first, and we need to swap them. | 1993 // will come first, and we need to swap them. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2077 // Now we explore a series of relationships between cookie last access | 2085 // Now we explore a series of relationships between cookie last access |
2078 // time and size of store to make sure we only get rid of cookies when | 2086 // time and size of store to make sure we only get rid of cookies when |
2079 // we really should. | 2087 // we really should. |
2080 const struct TestCase { | 2088 const struct TestCase { |
2081 size_t num_cookies; | 2089 size_t num_cookies; |
2082 size_t num_old_cookies; | 2090 size_t num_old_cookies; |
2083 size_t expected_initial_cookies; | 2091 size_t expected_initial_cookies; |
2084 // Indexed by ExpiryAndKeyScheme | 2092 // Indexed by ExpiryAndKeyScheme |
2085 size_t expected_cookies_after_set; | 2093 size_t expected_cookies_after_set; |
2086 } test_cases[] = { | 2094 } test_cases[] = { |
2087 { | 2095 {// A whole lot of recent cookies; gc shouldn't happen. |
2088 // A whole lot of recent cookies; gc shouldn't happen. | 2096 CookieMonster::kMaxCookies * 2, 0, CookieMonster::kMaxCookies * 2, |
2089 CookieMonster::kMaxCookies * 2, | 2097 CookieMonster::kMaxCookies * 2 + 1}, |
2090 0, | 2098 {// Some old cookies, but still overflowing max. |
2091 CookieMonster::kMaxCookies * 2, | 2099 CookieMonster::kMaxCookies * 2, CookieMonster::kMaxCookies / 2, |
2092 CookieMonster::kMaxCookies * 2 + 1 | 2100 CookieMonster::kMaxCookies * 2, |
2093 }, { | 2101 CookieMonster::kMaxCookies * 2 - CookieMonster::kMaxCookies / 2 + 1}, |
2094 // Some old cookies, but still overflowing max. | 2102 {// Old cookies enough to bring us right down to our purge line. |
2095 CookieMonster::kMaxCookies * 2, | 2103 CookieMonster::kMaxCookies * 2, |
2096 CookieMonster::kMaxCookies / 2, | 2104 CookieMonster::kMaxCookies + CookieMonster::kPurgeCookies + 1, |
2097 CookieMonster::kMaxCookies * 2, | 2105 CookieMonster::kMaxCookies * 2, |
2098 CookieMonster::kMaxCookies * 2 - CookieMonster::kMaxCookies / 2 + 1 | 2106 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}, |
2099 }, { | 2107 {// Old cookies enough to bring below our purge line (which we |
2100 // Old cookies enough to bring us right down to our purge line. | 2108 // shouldn't do). |
2101 CookieMonster::kMaxCookies * 2, | 2109 CookieMonster::kMaxCookies * 2, CookieMonster::kMaxCookies * 3 / 2, |
2102 CookieMonster::kMaxCookies + CookieMonster::kPurgeCookies + 1, | 2110 CookieMonster::kMaxCookies * 2, |
2103 CookieMonster::kMaxCookies * 2, | 2111 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies}}; |
2104 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies | |
2105 }, { | |
2106 // Old cookies enough to bring below our purge line (which we | |
2107 // shouldn't do). | |
2108 CookieMonster::kMaxCookies * 2, | |
2109 CookieMonster::kMaxCookies * 3 / 2, | |
2110 CookieMonster::kMaxCookies * 2, | |
2111 CookieMonster::kMaxCookies - CookieMonster::kPurgeCookies | |
2112 } | |
2113 }; | |
2114 | 2112 |
2115 for (int ci = 0; ci < static_cast<int>(ARRAYSIZE_UNSAFE(test_cases)); ++ci) { | 2113 for (int ci = 0; ci < static_cast<int>(ARRAYSIZE_UNSAFE(test_cases)); ++ci) { |
2116 const TestCase *test_case = &test_cases[ci]; | 2114 const TestCase* test_case = &test_cases[ci]; |
2117 scoped_refptr<CookieMonster> cm( | 2115 scoped_refptr<CookieMonster> cm(CreateMonsterFromStoreForGC( |
2118 CreateMonsterFromStoreForGC( | 2116 test_case->num_cookies, |
2119 test_case->num_cookies, test_case->num_old_cookies, | 2117 test_case->num_old_cookies, |
2120 CookieMonster::kSafeFromGlobalPurgeDays * 2)); | 2118 CookieMonster::kSafeFromGlobalPurgeDays * 2)); |
2121 EXPECT_EQ(test_case->expected_initial_cookies, | 2119 EXPECT_EQ(test_case->expected_initial_cookies, |
2122 GetAllCookies(cm.get()).size()) << "For test case " << ci; | 2120 GetAllCookies(cm.get()).size()) |
| 2121 << "For test case " << ci; |
2123 // Will trigger GC | 2122 // Will trigger GC |
2124 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); | 2123 SetCookie(cm.get(), GURL("http://newdomain.com"), "b=2"); |
2125 EXPECT_EQ(test_case->expected_cookies_after_set, | 2124 EXPECT_EQ(test_case->expected_cookies_after_set, |
2126 GetAllCookies(cm.get()).size()) << "For test case " << ci; | 2125 GetAllCookies(cm.get()).size()) |
| 2126 << "For test case " << ci; |
2127 } | 2127 } |
2128 } | 2128 } |
2129 | 2129 |
2130 // This test checks that keep expired cookies flag is working. | 2130 // This test checks that keep expired cookies flag is working. |
2131 TEST_F(CookieMonsterTest, KeepExpiredCookies) { | 2131 TEST_F(CookieMonsterTest, KeepExpiredCookies) { |
2132 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2132 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
2133 cm->SetKeepExpiredCookies(); | 2133 cm->SetKeepExpiredCookies(); |
2134 CookieOptions options; | 2134 CookieOptions options; |
2135 | 2135 |
2136 // Set a persistent cookie. | 2136 // Set a persistent cookie. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2183 virtual void UpdateCookieAccessTime(const CanonicalCookie&) OVERRIDE {} | 2183 virtual void UpdateCookieAccessTime(const CanonicalCookie&) OVERRIDE {} |
2184 virtual void DeleteCookie(const CanonicalCookie&) OVERRIDE {} | 2184 virtual void DeleteCookie(const CanonicalCookie&) OVERRIDE {} |
2185 virtual void SetForceKeepSessionState() OVERRIDE {} | 2185 virtual void SetForceKeepSessionState() OVERRIDE {} |
2186 | 2186 |
2187 virtual void Flush(const base::Closure& callback) OVERRIDE { | 2187 virtual void Flush(const base::Closure& callback) OVERRIDE { |
2188 ++flush_count_; | 2188 ++flush_count_; |
2189 if (!callback.is_null()) | 2189 if (!callback.is_null()) |
2190 callback.Run(); | 2190 callback.Run(); |
2191 } | 2191 } |
2192 | 2192 |
2193 int flush_count() { | 2193 int flush_count() { return flush_count_; } |
2194 return flush_count_; | |
2195 } | |
2196 | 2194 |
2197 private: | 2195 private: |
2198 virtual ~FlushablePersistentStore() {} | 2196 virtual ~FlushablePersistentStore() {} |
2199 | 2197 |
2200 volatile int flush_count_; | 2198 volatile int flush_count_; |
2201 }; | 2199 }; |
2202 | 2200 |
2203 // Counts the number of times Callback() has been run. | 2201 // Counts the number of times Callback() has been run. |
2204 class CallbackCounter : public base::RefCountedThreadSafe<CallbackCounter> { | 2202 class CallbackCounter : public base::RefCountedThreadSafe<CallbackCounter> { |
2205 public: | 2203 public: |
2206 CallbackCounter() : callback_count_(0) {} | 2204 CallbackCounter() : callback_count_(0) {} |
2207 | 2205 |
2208 void Callback() { | 2206 void Callback() { ++callback_count_; } |
2209 ++callback_count_; | |
2210 } | |
2211 | 2207 |
2212 int callback_count() { | 2208 int callback_count() { return callback_count_; } |
2213 return callback_count_; | |
2214 } | |
2215 | 2209 |
2216 private: | 2210 private: |
2217 friend class base::RefCountedThreadSafe<CallbackCounter>; | 2211 friend class base::RefCountedThreadSafe<CallbackCounter>; |
2218 ~CallbackCounter() {} | 2212 ~CallbackCounter() {} |
2219 | 2213 |
2220 volatile int callback_count_; | 2214 volatile int callback_count_; |
2221 }; | 2215 }; |
2222 | 2216 |
2223 } // namespace | 2217 } // namespace |
2224 | 2218 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2273 | 2267 |
2274 ASSERT_EQ(3, counter->callback_count()); | 2268 ASSERT_EQ(3, counter->callback_count()); |
2275 } | 2269 } |
2276 | 2270 |
2277 TEST_F(CookieMonsterTest, HistogramCheck) { | 2271 TEST_F(CookieMonsterTest, HistogramCheck) { |
2278 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2272 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
2279 // Should match call in InitializeHistograms, but doesn't really matter | 2273 // Should match call in InitializeHistograms, but doesn't really matter |
2280 // since the histogram should have been initialized by the CM construction | 2274 // since the histogram should have been initialized by the CM construction |
2281 // above. | 2275 // above. |
2282 base::HistogramBase* expired_histogram = | 2276 base::HistogramBase* expired_histogram = |
2283 base::Histogram::FactoryGet( | 2277 base::Histogram::FactoryGet("Cookie.ExpirationDurationMinutes", |
2284 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, | 2278 1, |
2285 base::Histogram::kUmaTargetedHistogramFlag); | 2279 10 * 365 * 24 * 60, |
| 2280 50, |
| 2281 base::Histogram::kUmaTargetedHistogramFlag); |
2286 | 2282 |
2287 scoped_ptr<base::HistogramSamples> samples1( | 2283 scoped_ptr<base::HistogramSamples> samples1( |
2288 expired_histogram->SnapshotSamples()); | 2284 expired_histogram->SnapshotSamples()); |
2289 ASSERT_TRUE( | 2285 ASSERT_TRUE( |
2290 SetCookieWithDetails(cm.get(), | 2286 SetCookieWithDetails(cm.get(), |
2291 GURL("http://fake.a.url"), | 2287 GURL("http://fake.a.url"), |
2292 "a", | 2288 "a", |
2293 "b", | 2289 "b", |
2294 "a.url", | 2290 "a.url", |
2295 "/", | 2291 "/", |
(...skipping 16 matching lines...) Expand all Loading... |
2312 | 2308 |
2313 namespace { | 2309 namespace { |
2314 | 2310 |
2315 class MultiThreadedCookieMonsterTest : public CookieMonsterTest { | 2311 class MultiThreadedCookieMonsterTest : public CookieMonsterTest { |
2316 public: | 2312 public: |
2317 MultiThreadedCookieMonsterTest() : other_thread_("CMTthread") {} | 2313 MultiThreadedCookieMonsterTest() : other_thread_("CMTthread") {} |
2318 | 2314 |
2319 // Helper methods for calling the asynchronous CookieMonster methods | 2315 // Helper methods for calling the asynchronous CookieMonster methods |
2320 // from a different thread. | 2316 // from a different thread. |
2321 | 2317 |
2322 void GetAllCookiesTask(CookieMonster* cm, | 2318 void GetAllCookiesTask(CookieMonster* cm, GetCookieListCallback* callback) { |
2323 GetCookieListCallback* callback) { | |
2324 cm->GetAllCookiesAsync( | 2319 cm->GetAllCookiesAsync( |
2325 base::Bind(&GetCookieListCallback::Run, base::Unretained(callback))); | 2320 base::Bind(&GetCookieListCallback::Run, base::Unretained(callback))); |
2326 } | 2321 } |
2327 | 2322 |
2328 void GetAllCookiesForURLTask(CookieMonster* cm, | 2323 void GetAllCookiesForURLTask(CookieMonster* cm, |
2329 const GURL& url, | 2324 const GURL& url, |
2330 GetCookieListCallback* callback) { | 2325 GetCookieListCallback* callback) { |
2331 cm->GetAllCookiesForURLAsync( | 2326 cm->GetAllCookiesForURLAsync( |
2332 url, | 2327 url, |
2333 base::Bind(&GetCookieListCallback::Run, base::Unretained(callback))); | 2328 base::Bind(&GetCookieListCallback::Run, base::Unretained(callback))); |
2334 } | 2329 } |
2335 | 2330 |
2336 void GetAllCookiesForURLWithOptionsTask(CookieMonster* cm, | 2331 void GetAllCookiesForURLWithOptionsTask(CookieMonster* cm, |
2337 const GURL& url, | 2332 const GURL& url, |
2338 const CookieOptions& options, | 2333 const CookieOptions& options, |
2339 GetCookieListCallback* callback) { | 2334 GetCookieListCallback* callback) { |
2340 cm->GetAllCookiesForURLWithOptionsAsync( | 2335 cm->GetAllCookiesForURLWithOptionsAsync( |
2341 url, options, | 2336 url, |
| 2337 options, |
2342 base::Bind(&GetCookieListCallback::Run, base::Unretained(callback))); | 2338 base::Bind(&GetCookieListCallback::Run, base::Unretained(callback))); |
2343 } | 2339 } |
2344 | 2340 |
2345 void SetCookieWithDetailsTask(CookieMonster* cm, const GURL& url, | 2341 void SetCookieWithDetailsTask(CookieMonster* cm, |
| 2342 const GURL& url, |
2346 ResultSavingCookieCallback<bool>* callback) { | 2343 ResultSavingCookieCallback<bool>* callback) { |
2347 // Define the parameters here instead of in the calling fucntion. | 2344 // Define the parameters here instead of in the calling fucntion. |
2348 // The maximum number of parameters for Bind function is 6. | 2345 // The maximum number of parameters for Bind function is 6. |
2349 std::string name = "A"; | 2346 std::string name = "A"; |
2350 std::string value = "B"; | 2347 std::string value = "B"; |
2351 std::string domain = std::string(); | 2348 std::string domain = std::string(); |
2352 std::string path = "/foo"; | 2349 std::string path = "/foo"; |
2353 base::Time expiration_time = base::Time(); | 2350 base::Time expiration_time = base::Time(); |
2354 bool secure = false; | 2351 bool secure = false; |
2355 bool http_only = false; | 2352 bool http_only = false; |
2356 CookiePriority priority = COOKIE_PRIORITY_DEFAULT; | 2353 CookiePriority priority = COOKIE_PRIORITY_DEFAULT; |
2357 cm->SetCookieWithDetailsAsync( | 2354 cm->SetCookieWithDetailsAsync( |
2358 url, name, value, domain, path, expiration_time, secure, http_only, | 2355 url, |
| 2356 name, |
| 2357 value, |
| 2358 domain, |
| 2359 path, |
| 2360 expiration_time, |
| 2361 secure, |
| 2362 http_only, |
2359 priority, | 2363 priority, |
2360 base::Bind( | 2364 base::Bind(&ResultSavingCookieCallback<bool>::Run, |
2361 &ResultSavingCookieCallback<bool>::Run, | 2365 base::Unretained(callback))); |
2362 base::Unretained(callback))); | |
2363 } | 2366 } |
2364 | 2367 |
2365 void DeleteAllCreatedBetweenTask(CookieMonster* cm, | 2368 void DeleteAllCreatedBetweenTask(CookieMonster* cm, |
2366 const base::Time& delete_begin, | 2369 const base::Time& delete_begin, |
2367 const base::Time& delete_end, | 2370 const base::Time& delete_end, |
2368 ResultSavingCookieCallback<int>* callback) { | 2371 ResultSavingCookieCallback<int>* callback) { |
2369 cm->DeleteAllCreatedBetweenAsync( | 2372 cm->DeleteAllCreatedBetweenAsync( |
2370 delete_begin, delete_end, | 2373 delete_begin, |
2371 base::Bind( | 2374 delete_end, |
2372 &ResultSavingCookieCallback<int>::Run, base::Unretained(callback))); | 2375 base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 2376 base::Unretained(callback))); |
2373 } | 2377 } |
2374 | 2378 |
2375 void DeleteAllForHostTask(CookieMonster* cm, | 2379 void DeleteAllForHostTask(CookieMonster* cm, |
2376 const GURL& url, | 2380 const GURL& url, |
2377 ResultSavingCookieCallback<int>* callback) { | 2381 ResultSavingCookieCallback<int>* callback) { |
2378 cm->DeleteAllForHostAsync( | 2382 cm->DeleteAllForHostAsync(url, |
2379 url, | 2383 base::Bind(&ResultSavingCookieCallback<int>::Run, |
2380 base::Bind( | 2384 base::Unretained(callback))); |
2381 &ResultSavingCookieCallback<int>::Run, base::Unretained(callback))); | |
2382 } | 2385 } |
2383 | 2386 |
2384 void DeleteAllCreatedBetweenForHostTask( | 2387 void DeleteAllCreatedBetweenForHostTask( |
2385 CookieMonster* cm, | 2388 CookieMonster* cm, |
2386 const base::Time delete_begin, | 2389 const base::Time delete_begin, |
2387 const base::Time delete_end, | 2390 const base::Time delete_end, |
2388 const GURL& url, | 2391 const GURL& url, |
2389 ResultSavingCookieCallback<int>* callback) { | 2392 ResultSavingCookieCallback<int>* callback) { |
2390 cm->DeleteAllCreatedBetweenForHostAsync( | 2393 cm->DeleteAllCreatedBetweenForHostAsync( |
2391 delete_begin, delete_end, url, | 2394 delete_begin, |
2392 base::Bind( | 2395 delete_end, |
2393 &ResultSavingCookieCallback<int>::Run, | 2396 url, |
2394 base::Unretained(callback))); | 2397 base::Bind(&ResultSavingCookieCallback<int>::Run, |
| 2398 base::Unretained(callback))); |
2395 } | 2399 } |
2396 | 2400 |
2397 void DeleteCanonicalCookieTask(CookieMonster* cm, | 2401 void DeleteCanonicalCookieTask(CookieMonster* cm, |
2398 const CanonicalCookie& cookie, | 2402 const CanonicalCookie& cookie, |
2399 ResultSavingCookieCallback<bool>* callback) { | 2403 ResultSavingCookieCallback<bool>* callback) { |
2400 cm->DeleteCanonicalCookieAsync( | 2404 cm->DeleteCanonicalCookieAsync( |
2401 cookie, | 2405 cookie, |
2402 base::Bind( | 2406 base::Bind(&ResultSavingCookieCallback<bool>::Run, |
2403 &ResultSavingCookieCallback<bool>::Run, | 2407 base::Unretained(callback))); |
2404 base::Unretained(callback))); | |
2405 } | 2408 } |
2406 | 2409 |
2407 protected: | 2410 protected: |
2408 void RunOnOtherThread(const base::Closure& task) { | 2411 void RunOnOtherThread(const base::Closure& task) { |
2409 other_thread_.Start(); | 2412 other_thread_.Start(); |
2410 other_thread_.message_loop()->PostTask(FROM_HERE, task); | 2413 other_thread_.message_loop()->PostTask(FROM_HERE, task); |
2411 RunFor(kTimeout); | 2414 RunFor(kTimeout); |
2412 other_thread_.Stop(); | 2415 other_thread_.Stop(); |
2413 } | 2416 } |
2414 | 2417 |
2415 Thread other_thread_; | 2418 Thread other_thread_; |
2416 }; | 2419 }; |
2417 | 2420 |
2418 } // namespace | 2421 } // namespace |
2419 | 2422 |
2420 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) { | 2423 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookies) { |
2421 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2424 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
2422 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); | 2425 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); |
2423 CookieList cookies = GetAllCookies(cm.get()); | 2426 CookieList cookies = GetAllCookies(cm.get()); |
2424 CookieList::const_iterator it = cookies.begin(); | 2427 CookieList::const_iterator it = cookies.begin(); |
2425 ASSERT_TRUE(it != cookies.end()); | 2428 ASSERT_TRUE(it != cookies.end()); |
2426 EXPECT_EQ("www.google.izzle", it->Domain()); | 2429 EXPECT_EQ("www.google.izzle", it->Domain()); |
2427 EXPECT_EQ("A", it->Name()); | 2430 EXPECT_EQ("A", it->Name()); |
2428 ASSERT_TRUE(++it == cookies.end()); | 2431 ASSERT_TRUE(++it == cookies.end()); |
2429 GetCookieListCallback callback(&other_thread_); | 2432 GetCookieListCallback callback(&other_thread_); |
2430 base::Closure task = | 2433 base::Closure task = |
2431 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesTask, | 2434 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesTask, |
2432 base::Unretained(this), | 2435 base::Unretained(this), |
2433 cm, &callback); | 2436 cm, |
| 2437 &callback); |
2434 RunOnOtherThread(task); | 2438 RunOnOtherThread(task); |
2435 EXPECT_TRUE(callback.did_run()); | 2439 EXPECT_TRUE(callback.did_run()); |
2436 it = callback.cookies().begin(); | 2440 it = callback.cookies().begin(); |
2437 ASSERT_TRUE(it != callback.cookies().end()); | 2441 ASSERT_TRUE(it != callback.cookies().end()); |
2438 EXPECT_EQ("www.google.izzle", it->Domain()); | 2442 EXPECT_EQ("www.google.izzle", it->Domain()); |
2439 EXPECT_EQ("A", it->Name()); | 2443 EXPECT_EQ("A", it->Name()); |
2440 ASSERT_TRUE(++it == callback.cookies().end()); | 2444 ASSERT_TRUE(++it == callback.cookies().end()); |
2441 } | 2445 } |
2442 | 2446 |
2443 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) { | 2447 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURL) { |
2444 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2448 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
2445 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); | 2449 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); |
2446 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_); | 2450 CookieList cookies = GetAllCookiesForURL(cm.get(), url_google_); |
2447 CookieList::const_iterator it = cookies.begin(); | 2451 CookieList::const_iterator it = cookies.begin(); |
2448 ASSERT_TRUE(it != cookies.end()); | 2452 ASSERT_TRUE(it != cookies.end()); |
2449 EXPECT_EQ("www.google.izzle", it->Domain()); | 2453 EXPECT_EQ("www.google.izzle", it->Domain()); |
2450 EXPECT_EQ("A", it->Name()); | 2454 EXPECT_EQ("A", it->Name()); |
2451 ASSERT_TRUE(++it == cookies.end()); | 2455 ASSERT_TRUE(++it == cookies.end()); |
2452 GetCookieListCallback callback(&other_thread_); | 2456 GetCookieListCallback callback(&other_thread_); |
2453 base::Closure task = | 2457 base::Closure task = |
2454 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask, | 2458 base::Bind(&net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLTask, |
2455 base::Unretained(this), | 2459 base::Unretained(this), |
2456 cm, url_google_, &callback); | 2460 cm, |
| 2461 url_google_, |
| 2462 &callback); |
2457 RunOnOtherThread(task); | 2463 RunOnOtherThread(task); |
2458 EXPECT_TRUE(callback.did_run()); | 2464 EXPECT_TRUE(callback.did_run()); |
2459 it = callback.cookies().begin(); | 2465 it = callback.cookies().begin(); |
2460 ASSERT_TRUE(it != callback.cookies().end()); | 2466 ASSERT_TRUE(it != callback.cookies().end()); |
2461 EXPECT_EQ("www.google.izzle", it->Domain()); | 2467 EXPECT_EQ("www.google.izzle", it->Domain()); |
2462 EXPECT_EQ("A", it->Name()); | 2468 EXPECT_EQ("A", it->Name()); |
2463 ASSERT_TRUE(++it == callback.cookies().end()); | 2469 ASSERT_TRUE(++it == callback.cookies().end()); |
2464 } | 2470 } |
2465 | 2471 |
2466 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) { | 2472 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckGetAllCookiesForURLWithOpt) { |
2467 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2473 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
2468 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); | 2474 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); |
2469 CookieOptions options; | 2475 CookieOptions options; |
2470 CookieList cookies = | 2476 CookieList cookies = |
2471 GetAllCookiesForURLWithOptions(cm.get(), url_google_, options); | 2477 GetAllCookiesForURLWithOptions(cm.get(), url_google_, options); |
2472 CookieList::const_iterator it = cookies.begin(); | 2478 CookieList::const_iterator it = cookies.begin(); |
2473 ASSERT_TRUE(it != cookies.end()); | 2479 ASSERT_TRUE(it != cookies.end()); |
2474 EXPECT_EQ("www.google.izzle", it->Domain()); | 2480 EXPECT_EQ("www.google.izzle", it->Domain()); |
2475 EXPECT_EQ("A", it->Name()); | 2481 EXPECT_EQ("A", it->Name()); |
2476 ASSERT_TRUE(++it == cookies.end()); | 2482 ASSERT_TRUE(++it == cookies.end()); |
2477 GetCookieListCallback callback(&other_thread_); | 2483 GetCookieListCallback callback(&other_thread_); |
2478 base::Closure task = base::Bind( | 2484 base::Closure task = base::Bind( |
2479 &net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLWithOptionsTask, | 2485 &net::MultiThreadedCookieMonsterTest::GetAllCookiesForURLWithOptionsTask, |
2480 base::Unretained(this), | 2486 base::Unretained(this), |
2481 cm, url_google_, options, &callback); | 2487 cm, |
| 2488 url_google_, |
| 2489 options, |
| 2490 &callback); |
2482 RunOnOtherThread(task); | 2491 RunOnOtherThread(task); |
2483 EXPECT_TRUE(callback.did_run()); | 2492 EXPECT_TRUE(callback.did_run()); |
2484 it = callback.cookies().begin(); | 2493 it = callback.cookies().begin(); |
2485 ASSERT_TRUE(it != callback.cookies().end()); | 2494 ASSERT_TRUE(it != callback.cookies().end()); |
2486 EXPECT_EQ("www.google.izzle", it->Domain()); | 2495 EXPECT_EQ("www.google.izzle", it->Domain()); |
2487 EXPECT_EQ("A", it->Name()); | 2496 EXPECT_EQ("A", it->Name()); |
2488 ASSERT_TRUE(++it == callback.cookies().end()); | 2497 ASSERT_TRUE(++it == callback.cookies().end()); |
2489 } | 2498 } |
2490 | 2499 |
2491 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) { | 2500 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) { |
2492 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2501 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
2493 EXPECT_TRUE(SetCookieWithDetails(cm.get(), | 2502 EXPECT_TRUE(SetCookieWithDetails(cm.get(), |
2494 url_google_foo_, | 2503 url_google_foo_, |
2495 "A", | 2504 "A", |
2496 "B", | 2505 "B", |
2497 std::string(), | 2506 std::string(), |
2498 "/foo", | 2507 "/foo", |
2499 base::Time(), | 2508 base::Time(), |
2500 false, | 2509 false, |
2501 false, | 2510 false, |
2502 COOKIE_PRIORITY_DEFAULT)); | 2511 COOKIE_PRIORITY_DEFAULT)); |
2503 ResultSavingCookieCallback<bool> callback(&other_thread_); | 2512 ResultSavingCookieCallback<bool> callback(&other_thread_); |
2504 base::Closure task = base::Bind( | 2513 base::Closure task = |
2505 &net::MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask, | 2514 base::Bind(&net::MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask, |
2506 base::Unretained(this), | 2515 base::Unretained(this), |
2507 cm, url_google_foo_, &callback); | 2516 cm, |
| 2517 url_google_foo_, |
| 2518 &callback); |
2508 RunOnOtherThread(task); | 2519 RunOnOtherThread(task); |
2509 EXPECT_TRUE(callback.did_run()); | 2520 EXPECT_TRUE(callback.did_run()); |
2510 EXPECT_TRUE(callback.result()); | 2521 EXPECT_TRUE(callback.result()); |
2511 } | 2522 } |
2512 | 2523 |
2513 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) { | 2524 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) { |
2514 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2525 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
2515 CookieOptions options; | 2526 CookieOptions options; |
2516 Time now = Time::Now(); | 2527 Time now = Time::Now(); |
2517 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); | 2528 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); |
2518 EXPECT_EQ( | 2529 EXPECT_EQ( |
2519 1, | 2530 1, |
2520 DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), Time())); | 2531 DeleteAllCreatedBetween(cm.get(), now - TimeDelta::FromDays(99), Time())); |
2521 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); | 2532 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); |
2522 ResultSavingCookieCallback<int> callback(&other_thread_); | 2533 ResultSavingCookieCallback<int> callback(&other_thread_); |
2523 base::Closure task = base::Bind( | 2534 base::Closure task = base::Bind( |
2524 &net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask, | 2535 &net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask, |
2525 base::Unretained(this), | 2536 base::Unretained(this), |
2526 cm, now - TimeDelta::FromDays(99), | 2537 cm, |
2527 Time(), &callback); | 2538 now - TimeDelta::FromDays(99), |
| 2539 Time(), |
| 2540 &callback); |
2528 RunOnOtherThread(task); | 2541 RunOnOtherThread(task); |
2529 EXPECT_TRUE(callback.did_run()); | 2542 EXPECT_TRUE(callback.did_run()); |
2530 EXPECT_EQ(1, callback.result()); | 2543 EXPECT_EQ(1, callback.result()); |
2531 } | 2544 } |
2532 | 2545 |
2533 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) { | 2546 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) { |
2534 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2547 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
2535 CookieOptions options; | 2548 CookieOptions options; |
2536 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); | 2549 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); |
2537 EXPECT_EQ(1, DeleteAllForHost(cm.get(), url_google_)); | 2550 EXPECT_EQ(1, DeleteAllForHost(cm.get(), url_google_)); |
2538 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); | 2551 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); |
2539 ResultSavingCookieCallback<int> callback(&other_thread_); | 2552 ResultSavingCookieCallback<int> callback(&other_thread_); |
2540 base::Closure task = base::Bind( | 2553 base::Closure task = |
2541 &net::MultiThreadedCookieMonsterTest::DeleteAllForHostTask, | 2554 base::Bind(&net::MultiThreadedCookieMonsterTest::DeleteAllForHostTask, |
2542 base::Unretained(this), | 2555 base::Unretained(this), |
2543 cm, url_google_, &callback); | 2556 cm, |
| 2557 url_google_, |
| 2558 &callback); |
2544 RunOnOtherThread(task); | 2559 RunOnOtherThread(task); |
2545 EXPECT_TRUE(callback.did_run()); | 2560 EXPECT_TRUE(callback.did_run()); |
2546 EXPECT_EQ(1, callback.result()); | 2561 EXPECT_EQ(1, callback.result()); |
2547 } | 2562 } |
2548 | 2563 |
2549 TEST_F(MultiThreadedCookieMonsterTest, | 2564 TEST_F(MultiThreadedCookieMonsterTest, |
2550 ThreadCheckDeleteAllCreatedBetweenForHost) { | 2565 ThreadCheckDeleteAllCreatedBetweenForHost) { |
2551 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2566 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
2552 GURL url_not_google("http://www.notgoogle.com"); | 2567 GURL url_not_google("http://www.notgoogle.com"); |
2553 | 2568 |
(...skipping 12 matching lines...) Expand all Loading... |
2566 // This cookie does not match host. | 2581 // This cookie does not match host. |
2567 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_not_google, "E=F", options)); | 2582 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_not_google, "E=F", options)); |
2568 | 2583 |
2569 // This cookie does not match time range: [ago3, inf], for first deletion, but | 2584 // This cookie does not match time range: [ago3, inf], for first deletion, but |
2570 // matches for the second deletion. | 2585 // matches for the second deletion. |
2571 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "G=H", ago2)); | 2586 EXPECT_TRUE(cm->SetCookieWithCreationTime(url_google_, "G=H", ago2)); |
2572 | 2587 |
2573 // 1. First set of deletions. | 2588 // 1. First set of deletions. |
2574 EXPECT_EQ( | 2589 EXPECT_EQ( |
2575 3, // Deletes A=B, C=D, Y=Z | 2590 3, // Deletes A=B, C=D, Y=Z |
2576 DeleteAllCreatedBetweenForHost( | 2591 DeleteAllCreatedBetweenForHost(cm.get(), ago3, Time::Max(), url_google_)); |
2577 cm.get(), ago3, Time::Max(), url_google_)); | |
2578 | 2592 |
2579 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); | 2593 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); |
2580 ResultSavingCookieCallback<int> callback(&other_thread_); | 2594 ResultSavingCookieCallback<int> callback(&other_thread_); |
2581 | 2595 |
2582 // 2. Second set of deletions. | 2596 // 2. Second set of deletions. |
2583 base::Closure task = base::Bind( | 2597 base::Closure task = base::Bind( |
2584 &net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenForHostTask, | 2598 &net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenForHostTask, |
2585 base::Unretained(this), | 2599 base::Unretained(this), |
2586 cm, ago1, Time(), url_google_, | 2600 cm, |
| 2601 ago1, |
| 2602 Time(), |
| 2603 url_google_, |
2587 &callback); | 2604 &callback); |
2588 RunOnOtherThread(task); | 2605 RunOnOtherThread(task); |
2589 EXPECT_TRUE(callback.did_run()); | 2606 EXPECT_TRUE(callback.did_run()); |
2590 EXPECT_EQ(2, callback.result()); // Deletes A=B, G=H. | 2607 EXPECT_EQ(2, callback.result()); // Deletes A=B, G=H. |
2591 } | 2608 } |
2592 | 2609 |
2593 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) { | 2610 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) { |
2594 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 2611 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
2595 CookieOptions options; | 2612 CookieOptions options; |
2596 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); | 2613 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); |
2597 CookieList cookies = GetAllCookies(cm.get()); | 2614 CookieList cookies = GetAllCookies(cm.get()); |
2598 CookieList::iterator it = cookies.begin(); | 2615 CookieList::iterator it = cookies.begin(); |
2599 EXPECT_TRUE(DeleteCanonicalCookie(cm.get(), *it)); | 2616 EXPECT_TRUE(DeleteCanonicalCookie(cm.get(), *it)); |
2600 | 2617 |
2601 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); | 2618 EXPECT_TRUE(SetCookieWithOptions(cm.get(), url_google_, "A=B", options)); |
2602 ResultSavingCookieCallback<bool> callback(&other_thread_); | 2619 ResultSavingCookieCallback<bool> callback(&other_thread_); |
2603 cookies = GetAllCookies(cm.get()); | 2620 cookies = GetAllCookies(cm.get()); |
2604 it = cookies.begin(); | 2621 it = cookies.begin(); |
2605 base::Closure task = base::Bind( | 2622 base::Closure task = base::Bind( |
2606 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, | 2623 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, |
2607 base::Unretained(this), | 2624 base::Unretained(this), |
2608 cm, *it, &callback); | 2625 cm, |
| 2626 *it, |
| 2627 &callback); |
2609 RunOnOtherThread(task); | 2628 RunOnOtherThread(task); |
2610 EXPECT_TRUE(callback.did_run()); | 2629 EXPECT_TRUE(callback.did_run()); |
2611 EXPECT_TRUE(callback.result()); | 2630 EXPECT_TRUE(callback.result()); |
2612 } | 2631 } |
2613 | 2632 |
2614 TEST_F(CookieMonsterTest, InvalidExpiryTime) { | 2633 TEST_F(CookieMonsterTest, InvalidExpiryTime) { |
2615 std::string cookie_line = | 2634 std::string cookie_line = |
2616 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; | 2635 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; |
2617 scoped_ptr<CanonicalCookie> cookie( | 2636 scoped_ptr<CanonicalCookie> cookie(CanonicalCookie::Create( |
2618 CanonicalCookie::Create(url_google_, cookie_line, Time::Now(), | 2637 url_google_, cookie_line, Time::Now(), CookieOptions())); |
2619 CookieOptions())); | |
2620 ASSERT_FALSE(cookie->IsPersistent()); | 2638 ASSERT_FALSE(cookie->IsPersistent()); |
2621 } | 2639 } |
2622 | 2640 |
2623 // Test that CookieMonster writes session cookies into the underlying | 2641 // Test that CookieMonster writes session cookies into the underlying |
2624 // CookieStore if the "persist session cookies" option is on. | 2642 // CookieStore if the "persist session cookies" option is on. |
2625 TEST_F(CookieMonsterTest, PersistSessionCookies) { | 2643 TEST_F(CookieMonsterTest, PersistSessionCookies) { |
2626 scoped_refptr<MockPersistentCookieStore> store( | 2644 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
2627 new MockPersistentCookieStore); | |
2628 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2645 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); |
2629 cm->SetPersistSessionCookies(true); | 2646 cm->SetPersistSessionCookies(true); |
2630 | 2647 |
2631 // All cookies set with SetCookie are session cookies. | 2648 // All cookies set with SetCookie are session cookies. |
2632 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); | 2649 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B")); |
2633 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_)); | 2650 EXPECT_EQ("A=B", GetCookies(cm.get(), url_google_)); |
2634 | 2651 |
2635 // The cookie was written to the backing store. | 2652 // The cookie was written to the backing store. |
2636 EXPECT_EQ(1u, store->commands().size()); | 2653 EXPECT_EQ(1u, store->commands().size()); |
2637 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 2654 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
(...skipping 15 matching lines...) Expand all Loading... |
2653 DeleteCookie(cm.get(), url_google_, "A"); | 2670 DeleteCookie(cm.get(), url_google_, "A"); |
2654 EXPECT_EQ("", GetCookies(cm.get(), url_google_)); | 2671 EXPECT_EQ("", GetCookies(cm.get(), url_google_)); |
2655 EXPECT_EQ(4u, store->commands().size()); | 2672 EXPECT_EQ(4u, store->commands().size()); |
2656 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); | 2673 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
2657 EXPECT_EQ("A", store->commands()[3].cookie.Name()); | 2674 EXPECT_EQ("A", store->commands()[3].cookie.Name()); |
2658 EXPECT_EQ("C", store->commands()[3].cookie.Value()); | 2675 EXPECT_EQ("C", store->commands()[3].cookie.Value()); |
2659 } | 2676 } |
2660 | 2677 |
2661 // Test the commands sent to the persistent cookie store. | 2678 // Test the commands sent to the persistent cookie store. |
2662 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) { | 2679 TEST_F(CookieMonsterTest, PersisentCookieStorageTest) { |
2663 scoped_refptr<MockPersistentCookieStore> store( | 2680 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
2664 new MockPersistentCookieStore); | |
2665 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2681 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); |
2666 | 2682 |
2667 // Add a cookie. | 2683 // Add a cookie. |
2668 EXPECT_TRUE(SetCookie( | 2684 EXPECT_TRUE(SetCookie( |
2669 cm.get(), url_google_, "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); | 2685 cm.get(), url_google_, "A=B; expires=Mon, 18-Apr-22 22:50:13 GMT")); |
2670 this->MatchCookieLines("A=B", GetCookies(cm.get(), url_google_)); | 2686 this->MatchCookieLines("A=B", GetCookies(cm.get(), url_google_)); |
2671 ASSERT_EQ(1u, store->commands().size()); | 2687 ASSERT_EQ(1u, store->commands().size()); |
2672 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); | 2688 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
2673 // Remove it. | 2689 // Remove it. |
2674 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B; max-age=0")); | 2690 EXPECT_TRUE(SetCookie(cm.get(), url_google_, "A=B; max-age=0")); |
(...skipping 26 matching lines...) Expand all Loading... |
2701 // See http://crbug.com/238041 for background. | 2717 // See http://crbug.com/238041 for background. |
2702 TEST_F(CookieMonsterTest, ControlCharacterPurge) { | 2718 TEST_F(CookieMonsterTest, ControlCharacterPurge) { |
2703 const Time now1(Time::Now()); | 2719 const Time now1(Time::Now()); |
2704 const Time now2(Time::Now() + TimeDelta::FromSeconds(1)); | 2720 const Time now2(Time::Now() + TimeDelta::FromSeconds(1)); |
2705 const Time now3(Time::Now() + TimeDelta::FromSeconds(2)); | 2721 const Time now3(Time::Now() + TimeDelta::FromSeconds(2)); |
2706 const Time later(now1 + TimeDelta::FromDays(1)); | 2722 const Time later(now1 + TimeDelta::FromDays(1)); |
2707 const GURL url("http://host/path"); | 2723 const GURL url("http://host/path"); |
2708 const std::string domain("host"); | 2724 const std::string domain("host"); |
2709 const std::string path("/path"); | 2725 const std::string path("/path"); |
2710 | 2726 |
2711 scoped_refptr<MockPersistentCookieStore> store( | 2727 scoped_refptr<MockPersistentCookieStore> store(new MockPersistentCookieStore); |
2712 new MockPersistentCookieStore); | |
2713 | 2728 |
2714 std::vector<CanonicalCookie*> initial_cookies; | 2729 std::vector<CanonicalCookie*> initial_cookies; |
2715 | 2730 |
2716 AddCookieToList(domain, | 2731 AddCookieToList(domain, "foo=bar; path=" + path, now1, &initial_cookies); |
2717 "foo=bar; path=" + path, | |
2718 now1, | |
2719 &initial_cookies); | |
2720 | 2732 |
2721 // We have to manually build this cookie because it contains a control | 2733 // We have to manually build this cookie because it contains a control |
2722 // character, and our cookie line parser rejects control characters. | 2734 // character, and our cookie line parser rejects control characters. |
2723 CanonicalCookie *cc = new CanonicalCookie(url, "baz", "\x05" "boo", domain, | 2735 CanonicalCookie* cc = new CanonicalCookie(url, |
2724 path, now2, later, now2, false, | 2736 "baz", |
2725 false, COOKIE_PRIORITY_DEFAULT); | 2737 "\x05" |
| 2738 "boo", |
| 2739 domain, |
| 2740 path, |
| 2741 now2, |
| 2742 later, |
| 2743 now2, |
| 2744 false, |
| 2745 false, |
| 2746 COOKIE_PRIORITY_DEFAULT); |
2726 initial_cookies.push_back(cc); | 2747 initial_cookies.push_back(cc); |
2727 | 2748 |
2728 AddCookieToList(domain, | 2749 AddCookieToList(domain, "hello=world; path=" + path, now3, &initial_cookies); |
2729 "hello=world; path=" + path, | |
2730 now3, | |
2731 &initial_cookies); | |
2732 | 2750 |
2733 // Inject our initial cookies into the mock PersistentCookieStore. | 2751 // Inject our initial cookies into the mock PersistentCookieStore. |
2734 store->SetLoadExpectation(true, initial_cookies); | 2752 store->SetLoadExpectation(true, initial_cookies); |
2735 | 2753 |
2736 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | 2754 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); |
2737 | 2755 |
2738 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); | 2756 EXPECT_EQ("foo=bar; hello=world", GetCookies(cm.get(), url)); |
2739 } | 2757 } |
2740 | 2758 |
2741 } // namespace net | 2759 } // namespace net |
OLD | NEW |