OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <time.h> | 5 #include <time.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 using base::TimeDelta; | 30 using base::TimeDelta; |
31 using base::Thread; | 31 using base::Thread; |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 // TODO(erikwright): Replace the pre-existing MockPersistentCookieStore (and | 35 // TODO(erikwright): Replace the pre-existing MockPersistentCookieStore (and |
36 // brethren) with this one, and remove the 'New' prefix. | 36 // brethren) with this one, and remove the 'New' prefix. |
37 class NewMockPersistentCookieStore | 37 class NewMockPersistentCookieStore |
38 : public CookieMonster::PersistentCookieStore { | 38 : public CookieMonster::PersistentCookieStore { |
39 public: | 39 public: |
40 MOCK_METHOD1(Load, bool(const LoadedCallback& loaded_callback)); | 40 MOCK_METHOD1(Load, void(const LoadedCallback& loaded_callback)); |
41 MOCK_METHOD2(LoadCookiesForKey, void(const std::string& key, | |
42 const LoadedCallback& loaded_callback)); | |
41 MOCK_METHOD1(AddCookie, void(const CookieMonster::CanonicalCookie& cc)); | 43 MOCK_METHOD1(AddCookie, void(const CookieMonster::CanonicalCookie& cc)); |
42 MOCK_METHOD1(UpdateCookieAccessTime, | 44 MOCK_METHOD1(UpdateCookieAccessTime, |
43 void(const CookieMonster::CanonicalCookie& cc)); | 45 void(const CookieMonster::CanonicalCookie& cc)); |
44 MOCK_METHOD1(DeleteCookie, void(const CookieMonster::CanonicalCookie& cc)); | 46 MOCK_METHOD1(DeleteCookie, void(const CookieMonster::CanonicalCookie& cc)); |
45 MOCK_METHOD1(SetClearLocalStateOnExit, void(bool clear_local_state)); | 47 MOCK_METHOD1(SetClearLocalStateOnExit, void(bool clear_local_state)); |
46 MOCK_METHOD1(Flush, void(Task* completion_task)); | 48 MOCK_METHOD1(Flush, void(Task* completion_task)); |
47 }; | 49 }; |
48 | 50 |
49 const int kTimeout = 1000; | 51 const int kTimeout = 1000; |
50 | 52 |
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1003 cookie_monster->GetAllCookiesForURLWithOptionsAsync( | 1005 cookie_monster->GetAllCookiesForURLWithOptionsAsync( |
1004 url, CookieOptions(), callback->AsCallback()); | 1006 url, CookieOptions(), callback->AsCallback()); |
1005 } | 1007 } |
1006 | 1008 |
1007 ACTION_P3(GetAllCookiesForUrlAction, cookie_monster, url, callback) { | 1009 ACTION_P3(GetAllCookiesForUrlAction, cookie_monster, url, callback) { |
1008 cookie_monster->GetAllCookiesForURLAsync(url, callback->AsCallback()); | 1010 cookie_monster->GetAllCookiesForURLAsync(url, callback->AsCallback()); |
1009 } | 1011 } |
1010 | 1012 |
1011 } // namespace | 1013 } // namespace |
1012 | 1014 |
1013 // This test suite verifies the task deferral behaviour of the CookieMonster. | 1015 // This test suite verifies the task deferral behaviour of the CookieMonster. |
erikwright (departed)
2011/10/04 19:55:02
To avoid having a vector of raw pointers (that you
guohui
2011/10/06 15:40:00
Done.
| |
1014 // Specifically, for each asynchronous method, verify that: | 1016 // Specifically, for each asynchronous method, verify that: |
1015 // 1. invoking it on an uninitialized cookie store causes the store to begin | 1017 // 1. invoking it on an uninitialized cookie store causes the store to begin |
1016 // loading its backing data. | 1018 // chainlloading its backing data or loading data for a specific domain key |
erikwright (departed)
2011/10/04 19:55:02
chainlloading => chain-loading
guohui
2011/10/06 15:40:00
Done.
| |
1019 // (eTLD+1). | |
1017 // 2. The initial invocation does not complete until the loading completes. | 1020 // 2. The initial invocation does not complete until the loading completes. |
1018 // 3. Invocations after the loading has completed complete immediately. | 1021 // 3. Invocations after the loading has completed complete immediately. |
1019 class DeferredCookieTaskTest : public CookieMonsterTest { | 1022 class DeferredCookieTaskTest : public CookieMonsterTest { |
1020 protected: | 1023 protected: |
1021 DeferredCookieTaskTest() { | 1024 DeferredCookieTaskTest() { |
1022 persistent_store_ = new NewMockPersistentCookieStore(); | 1025 persistent_store_ = new NewMockPersistentCookieStore(); |
1023 cookie_monster_ = new CookieMonster(persistent_store_.get(), NULL); | 1026 cookie_monster_ = new CookieMonster(persistent_store_.get(), NULL); |
1024 } | 1027 } |
1025 | 1028 |
1026 // Defines a cookie to be returned from PersistentCookieStore::Load | 1029 // Defines a cookie to be returned from PersistentCookieStore::Load |
1027 void DeclareLoadedCookie(const std::string& key, | 1030 void DeclareLoadedCookie(const std::string& key, |
1028 const std::string& cookie_line, | 1031 const std::string& cookie_line, |
1029 const base::Time& creation_time) { | 1032 const base::Time& creation_time) { |
1030 AddCookieToList(key, cookie_line, creation_time, &loaded_cookies_); | 1033 AddCookieToList(key, cookie_line, creation_time, &loaded_cookies_); |
1031 } | 1034 } |
1032 | 1035 |
1033 // Runs the message loop, waiting until PersistentCookieStore::Load is called. | 1036 // Runs the message loop, waiting until PersistentCookieStore::Load is called. |
1034 // Call CompleteLoadingAndWait to cause the load to complete. | 1037 // Call CompleteLoadingAndWait to cause the load to complete. |
1035 void WaitForLoadCall() { | 1038 void WaitForLoadCall() { |
1036 RunFor(kTimeout); | 1039 RunFor(kTimeout); |
1037 | 1040 |
1038 // Verify that PeristentStore::Load was called. | 1041 // Verify that PeristentStore::Load was called. |
1039 testing::Mock::VerifyAndClear(persistent_store_.get()); | 1042 testing::Mock::VerifyAndClear(persistent_store_.get()); |
1040 } | 1043 } |
1041 | 1044 |
1042 // Invokes the PersistentCookieStore::Load completion callback and waits | 1045 // Invokes the PersistentCookieStore::LoadCookiesForKey completion callbacks |
1046 // and PersistentCookieStore::Load completion callback and waits | |
1043 // until the message loop is quit. | 1047 // until the message loop is quit. |
1044 void CompleteLoadingAndWait() { | 1048 void CompleteLoadingAndWait() { |
1049 std::vector<CookieMonster::PersistentCookieStore::LoadedCallback *> | |
1050 ::iterator it = loaded_for_key_callbacks_.begin(); | |
1051 for (; it != loaded_for_key_callbacks_.end(); it++) { | |
1052 (*it)->Run(loaded_cookies_); | |
1053 loaded_cookies_.clear(); | |
1054 delete *it; | |
1055 } | |
erikwright (departed)
2011/10/04 19:55:02
Clear the loaded_for_key_callbacks_ after line 105
guohui
2011/10/06 15:40:00
Done.
| |
1045 loaded_callback_.Run(loaded_cookies_); | 1056 loaded_callback_.Run(loaded_cookies_); |
1046 RunFor(kTimeout); | 1057 RunFor(kTimeout); |
1047 } | 1058 } |
1048 | 1059 |
1049 // Performs the provided action, expecting it to cause a call to | 1060 // Performs the provided action, expecting it to cause a call to |
1050 // PersistentCookieStore::Load. Call WaitForLoadCall to verify the load call | 1061 // PersistentCookieStore::Load. Call WaitForLoadCall to verify the load call |
1051 // is received. | 1062 // is receievd. |
erikwright (departed)
2011/10/04 19:55:02
receivd => received
guohui
2011/10/06 15:40:00
Done.
| |
1052 void BeginWith(testing::Action<void(void)> action) { | 1063 void BeginWith(testing::Action<void(void)> action) { |
1053 EXPECT_CALL(*this, Begin()).WillOnce(action); | 1064 EXPECT_CALL(*this, Begin()).WillOnce(action); |
1054 ExpectLoadCall(); | 1065 ExpectLoadCall(); |
1055 Begin(); | 1066 Begin(); |
1056 } | 1067 } |
1057 | 1068 |
1069 void BeginWithForDomainKey(testing::Action<void(void)> action) { | |
erikwright (departed)
2011/10/04 19:55:02
Accept a parameter for the domain key, pass it int
erikwright (departed)
2011/10/04 19:55:02
This looks unbalanced to me:
ExpectLoadCall and E
guohui
2011/10/06 15:40:00
Done.
| |
1070 EXPECT_CALL(*this, Begin()).WillOnce(action); | |
1071 ExpectLoadCall(); | |
1072 ExpectLoadForKeyCall(); | |
1073 Begin(); | |
1074 } | |
1075 | |
1058 // Declares an expectation that PersistentCookieStore::Load will be called, | 1076 // Declares an expectation that PersistentCookieStore::Load will be called, |
1059 // saving the provided callback and sending a quit to the message loop. | 1077 // saving the provided callback and sending a quit to the message loop. |
1060 void ExpectLoadCall() { | 1078 void ExpectLoadCall() { |
1061 EXPECT_CALL(*persistent_store_, Load(testing::_)).WillOnce(testing::DoAll( | 1079 EXPECT_CALL(*persistent_store_, Load(testing::_)).WillOnce(testing::DoAll( |
1062 testing::SaveArg<0>(&loaded_callback_), | 1080 testing::SaveArg<0>(&loaded_callback_), |
1063 QuitCurrentMessageLoop(), | 1081 QuitCurrentMessageLoop())); |
1064 testing::Return(true))); | 1082 } |
1083 | |
1084 // Declares an expectation that PersistentCookieStore::LoadCookiesForKey | |
1085 // will be called, saving the provided callback and sending a quit to the | |
1086 // message loop. | |
1087 void ExpectLoadForKeyCall() { | |
1088 CookieMonster::PersistentCookieStore::LoadedCallback * | |
1089 callback = new CookieMonster::PersistentCookieStore::LoadedCallback(); | |
1090 EXPECT_CALL(*persistent_store_, LoadCookiesForKey(testing::_, testing::_)). | |
1091 WillOnce(testing::DoAll( | |
1092 testing::SaveArg<1>(callback), | |
1093 QuitCurrentMessageLoop())); | |
1094 loaded_for_key_callbacks_.push_back(callback); | |
1065 } | 1095 } |
1066 | 1096 |
1067 // Invokes the initial action. | 1097 // Invokes the initial action. |
1068 MOCK_METHOD0(Begin, void(void)); | 1098 MOCK_METHOD0(Begin, void(void)); |
1069 | 1099 |
1070 // Returns the CookieMonster instance under test. | 1100 // Returns the CookieMonster instance under test. |
1071 CookieMonster& cookie_monster() { return *cookie_monster_; } | 1101 CookieMonster& cookie_monster() { return *cookie_monster_; } |
1072 | 1102 |
1073 private: | 1103 private: |
1074 // Declares that mock expectations in this test suite are strictly ordered. | 1104 // Declares that mock expectations in this test suite are strictly ordered. |
1075 testing::InSequence in_sequence_; | 1105 testing::InSequence in_sequence_; |
1076 // Holds cookies to be returned from PersistentCookieStore::Load. | 1106 // Holds cookies to be returned from PersistentCookieStore::Load or |
1107 // PersistentCookieStore::LoadCookiesForKey. | |
1077 std::vector<CookieMonster::CanonicalCookie*> loaded_cookies_; | 1108 std::vector<CookieMonster::CanonicalCookie*> loaded_cookies_; |
1078 // Stores the callback passed from the CookieMonster to the | 1109 // Stores the callback passed from the CookieMonster to the |
1079 // PersistentCookieStore | 1110 // PersistentCookieStore::Load |
1080 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; | 1111 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback_; |
1112 // Stores the callback passed from the CookieMonster to the | |
1113 // PersistentCookieStore::LoadCookiesForKey | |
1114 std::vector<CookieMonster::PersistentCookieStore::LoadedCallback*> | |
1115 loaded_for_key_callbacks_; | |
1116 | |
1081 // Stores the CookieMonster under test. | 1117 // Stores the CookieMonster under test. |
1082 scoped_refptr<CookieMonster> cookie_monster_; | 1118 scoped_refptr<CookieMonster> cookie_monster_; |
1083 // Stores the mock PersistentCookieStore. | 1119 // Stores the mock PersistentCookieStore. |
1084 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; | 1120 scoped_refptr<NewMockPersistentCookieStore> persistent_store_; |
1085 }; | 1121 }; |
1086 | 1122 |
erikwright (departed)
2011/10/04 19:55:02
Some of the new functionality is untested:
(1) Ad
guohui
2011/10/06 15:40:00
Done.
| |
1087 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { | 1123 TEST_F(DeferredCookieTaskTest, DeferredGetCookies) { |
1088 DeclareLoadedCookie("www.google.izzle", | 1124 DeclareLoadedCookie("www.google.izzle", |
1089 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1125 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
1090 Time::Now() + TimeDelta::FromDays(3)); | 1126 Time::Now() + TimeDelta::FromDays(3)); |
1091 | 1127 |
1092 MockGetCookiesCallback get_cookies_callback; | 1128 MockGetCookiesCallback get_cookies_callback; |
1093 | 1129 |
1094 BeginWith(GetCookiesAction( | 1130 BeginWithForDomainKey(GetCookiesAction( |
1095 &cookie_monster(), url_google_, &get_cookies_callback)); | 1131 &cookie_monster(), url_google_, &get_cookies_callback)); |
1096 | 1132 |
1097 WaitForLoadCall(); | 1133 WaitForLoadCall(); |
1098 | 1134 |
1099 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( | 1135 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( |
1100 GetCookiesAction(&cookie_monster(), url_google_, &get_cookies_callback)); | 1136 GetCookiesAction(&cookie_monster(), url_google_, &get_cookies_callback)); |
1101 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( | 1137 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( |
1102 QuitCurrentMessageLoop()); | 1138 QuitCurrentMessageLoop()); |
1103 | 1139 |
1104 CompleteLoadingAndWait(); | 1140 CompleteLoadingAndWait(); |
1105 } | 1141 } |
1106 | 1142 |
1107 TEST_F(DeferredCookieTaskTest, DeferredGetCookiesWithInfo) { | 1143 TEST_F(DeferredCookieTaskTest, DeferredGetCookiesWithInfo) { |
1108 DeclareLoadedCookie("www.google.izzle", | 1144 DeclareLoadedCookie("www.google.izzle", |
1109 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1145 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
1110 Time::Now() + TimeDelta::FromDays(3)); | 1146 Time::Now() + TimeDelta::FromDays(3)); |
1111 | 1147 |
1112 MockGetCookieInfoCallback get_cookie_info_callback; | 1148 MockGetCookieInfoCallback get_cookie_info_callback; |
1113 | 1149 |
1114 BeginWith(GetCookiesWithInfoAction( | 1150 BeginWithForDomainKey(GetCookiesWithInfoAction( |
1115 &cookie_monster(), url_google_, &get_cookie_info_callback)); | 1151 &cookie_monster(), url_google_, &get_cookie_info_callback)); |
1116 | 1152 |
1117 WaitForLoadCall(); | 1153 WaitForLoadCall(); |
1118 | 1154 |
1119 EXPECT_CALL(get_cookie_info_callback, Invoke("X=1", testing::_)).WillOnce( | 1155 EXPECT_CALL(get_cookie_info_callback, Invoke("X=1", testing::_)).WillOnce( |
1120 GetCookiesWithInfoAction( | 1156 GetCookiesWithInfoAction( |
1121 &cookie_monster(), url_google_, &get_cookie_info_callback)); | 1157 &cookie_monster(), url_google_, &get_cookie_info_callback)); |
1122 EXPECT_CALL(get_cookie_info_callback, Invoke("X=1", testing::_)).WillOnce( | 1158 EXPECT_CALL(get_cookie_info_callback, Invoke("X=1", testing::_)).WillOnce( |
1123 QuitCurrentMessageLoop()); | 1159 QuitCurrentMessageLoop()); |
1124 | 1160 |
1125 CompleteLoadingAndWait(); | 1161 CompleteLoadingAndWait(); |
1126 } | 1162 } |
1127 | 1163 |
1128 TEST_F(DeferredCookieTaskTest, DeferredSetCookie) { | 1164 TEST_F(DeferredCookieTaskTest, DeferredSetCookie) { |
1129 MockSetCookiesCallback set_cookies_callback; | 1165 MockSetCookiesCallback set_cookies_callback; |
1130 | 1166 |
1131 BeginWith(SetCookieAction( | 1167 BeginWithForDomainKey(SetCookieAction( |
1132 &cookie_monster(), url_google_, "A=B", &set_cookies_callback)); | 1168 &cookie_monster(), url_google_, "A=B", &set_cookies_callback)); |
1133 | 1169 |
1134 WaitForLoadCall(); | 1170 WaitForLoadCall(); |
1135 | 1171 |
1136 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( | 1172 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( |
1137 SetCookieAction( | 1173 SetCookieAction( |
1138 &cookie_monster(), url_google_, "X=Y", &set_cookies_callback)); | 1174 &cookie_monster(), url_google_, "X=Y", &set_cookies_callback)); |
1139 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( | 1175 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( |
1140 QuitCurrentMessageLoop()); | 1176 QuitCurrentMessageLoop()); |
1141 | 1177 |
1142 CompleteLoadingAndWait(); | 1178 CompleteLoadingAndWait(); |
1143 } | 1179 } |
1144 | 1180 |
1145 TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) { | 1181 TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) { |
1146 MockClosure delete_cookie_callback; | 1182 MockClosure delete_cookie_callback; |
1147 | 1183 |
1148 BeginWith(DeleteCookieAction( | 1184 BeginWithForDomainKey(DeleteCookieAction( |
1149 &cookie_monster(), url_google_, "A", &delete_cookie_callback)); | 1185 &cookie_monster(), url_google_, "A", &delete_cookie_callback)); |
1150 | 1186 |
1151 WaitForLoadCall(); | 1187 WaitForLoadCall(); |
1152 | 1188 |
1153 EXPECT_CALL(delete_cookie_callback, Invoke()).WillOnce( | 1189 EXPECT_CALL(delete_cookie_callback, Invoke()).WillOnce( |
1154 DeleteCookieAction( | 1190 DeleteCookieAction( |
1155 &cookie_monster(), url_google_, "X", &delete_cookie_callback)); | 1191 &cookie_monster(), url_google_, "X", &delete_cookie_callback)); |
1156 EXPECT_CALL(delete_cookie_callback, Invoke()).WillOnce( | 1192 EXPECT_CALL(delete_cookie_callback, Invoke()).WillOnce( |
1157 QuitCurrentMessageLoop()); | 1193 QuitCurrentMessageLoop()); |
1158 | 1194 |
1159 CompleteLoadingAndWait(); | 1195 CompleteLoadingAndWait(); |
1160 } | 1196 } |
1161 | 1197 |
1162 TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) { | 1198 TEST_F(DeferredCookieTaskTest, DeferredSetCookieWithDetails) { |
1163 MockSetCookiesCallback set_cookies_callback; | 1199 MockSetCookiesCallback set_cookies_callback; |
1164 | 1200 |
1165 BeginWith(SetCookieWithDetailsAction( | 1201 BeginWithForDomainKey(SetCookieWithDetailsAction( |
1166 &cookie_monster(), url_google_foo_, "A", "B", std::string(), "/foo", | 1202 &cookie_monster(), url_google_foo_, "A", "B", std::string(), "/foo", |
1167 base::Time(), false, false, &set_cookies_callback)); | 1203 base::Time(), false, false, &set_cookies_callback)); |
1168 | 1204 |
1169 WaitForLoadCall(); | 1205 WaitForLoadCall(); |
1170 | 1206 |
1171 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( | 1207 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( |
1172 SetCookieWithDetailsAction( | 1208 SetCookieWithDetailsAction( |
1173 &cookie_monster(), url_google_foo_, "A", "B", std::string(), "/foo", | 1209 &cookie_monster(), url_google_foo_, "A", "B", std::string(), "/foo", |
1174 base::Time(), false, false, &set_cookies_callback)); | 1210 base::Time(), false, false, &set_cookies_callback)); |
1175 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( | 1211 EXPECT_CALL(set_cookies_callback, Invoke(true)).WillOnce( |
(...skipping 22 matching lines...) Expand all Loading... | |
1198 CompleteLoadingAndWait(); | 1234 CompleteLoadingAndWait(); |
1199 } | 1235 } |
1200 | 1236 |
1201 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) { | 1237 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlCookies) { |
1202 DeclareLoadedCookie("www.google.izzle", | 1238 DeclareLoadedCookie("www.google.izzle", |
1203 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1239 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
1204 Time::Now() + TimeDelta::FromDays(3)); | 1240 Time::Now() + TimeDelta::FromDays(3)); |
1205 | 1241 |
1206 MockGetCookieListCallback get_cookie_list_callback; | 1242 MockGetCookieListCallback get_cookie_list_callback; |
1207 | 1243 |
1208 BeginWith(GetAllCookiesForUrlAction( | 1244 BeginWithForDomainKey(GetAllCookiesForUrlAction( |
1209 &cookie_monster(), url_google_, &get_cookie_list_callback)); | 1245 &cookie_monster(), url_google_, &get_cookie_list_callback)); |
1210 | 1246 |
1211 WaitForLoadCall(); | 1247 WaitForLoadCall(); |
1212 | 1248 |
1213 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 1249 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( |
1214 GetAllCookiesForUrlAction( | 1250 GetAllCookiesForUrlAction( |
1215 &cookie_monster(), url_google_, &get_cookie_list_callback)); | 1251 &cookie_monster(), url_google_, &get_cookie_list_callback)); |
1216 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 1252 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( |
1217 QuitCurrentMessageLoop()); | 1253 QuitCurrentMessageLoop()); |
1218 | 1254 |
1219 CompleteLoadingAndWait(); | 1255 CompleteLoadingAndWait(); |
1220 } | 1256 } |
1221 | 1257 |
1222 | 1258 |
1223 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) { | 1259 TEST_F(DeferredCookieTaskTest, DeferredGetAllForUrlWithOptionsCookies) { |
1224 DeclareLoadedCookie("www.google.izzle", | 1260 DeclareLoadedCookie("www.google.izzle", |
1225 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", | 1261 "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT", |
1226 Time::Now() + TimeDelta::FromDays(3)); | 1262 Time::Now() + TimeDelta::FromDays(3)); |
1227 | 1263 |
1228 MockGetCookieListCallback get_cookie_list_callback; | 1264 MockGetCookieListCallback get_cookie_list_callback; |
1229 | 1265 |
1230 BeginWith(GetAllCookiesForUrlWithOptionsAction( | 1266 BeginWithForDomainKey(GetAllCookiesForUrlWithOptionsAction( |
1231 &cookie_monster(), url_google_, &get_cookie_list_callback)); | 1267 &cookie_monster(), url_google_, &get_cookie_list_callback)); |
1232 | 1268 |
1233 WaitForLoadCall(); | 1269 WaitForLoadCall(); |
1234 | 1270 |
1235 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 1271 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( |
1236 GetAllCookiesForUrlWithOptionsAction( | 1272 GetAllCookiesForUrlWithOptionsAction( |
1237 &cookie_monster(), url_google_, &get_cookie_list_callback)); | 1273 &cookie_monster(), url_google_, &get_cookie_list_callback)); |
1238 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( | 1274 EXPECT_CALL(get_cookie_list_callback, Invoke(testing::_)).WillOnce( |
1239 QuitCurrentMessageLoop()); | 1275 QuitCurrentMessageLoop()); |
1240 | 1276 |
(...skipping 30 matching lines...) Expand all Loading... | |
1271 &delete_callback)); | 1307 &delete_callback)); |
1272 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 1308 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( |
1273 QuitCurrentMessageLoop()); | 1309 QuitCurrentMessageLoop()); |
1274 | 1310 |
1275 CompleteLoadingAndWait(); | 1311 CompleteLoadingAndWait(); |
1276 } | 1312 } |
1277 | 1313 |
1278 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCookies) { | 1314 TEST_F(DeferredCookieTaskTest, DeferredDeleteAllForHostCookies) { |
1279 MockDeleteCallback delete_callback; | 1315 MockDeleteCallback delete_callback; |
1280 | 1316 |
1281 BeginWith(DeleteAllForHostAction( | 1317 BeginWithForDomainKey(DeleteAllForHostAction( |
1282 &cookie_monster(), url_google_, &delete_callback)); | 1318 &cookie_monster(), url_google_, &delete_callback)); |
1283 | 1319 |
1284 WaitForLoadCall(); | 1320 WaitForLoadCall(); |
1285 | 1321 |
1286 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 1322 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( |
1287 DeleteAllForHostAction( | 1323 DeleteAllForHostAction( |
1288 &cookie_monster(), url_google_, &delete_callback)); | 1324 &cookie_monster(), url_google_, &delete_callback)); |
1289 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( | 1325 EXPECT_CALL(delete_callback, Invoke(false)).WillOnce( |
1290 QuitCurrentMessageLoop()); | 1326 QuitCurrentMessageLoop()); |
1291 | 1327 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1327 MockGetCookieInfoCallback get_cookie_info_callback; | 1363 MockGetCookieInfoCallback get_cookie_info_callback; |
1328 | 1364 |
1329 EXPECT_CALL(*this, Begin()).WillOnce(testing::DoAll( | 1365 EXPECT_CALL(*this, Begin()).WillOnce(testing::DoAll( |
1330 GetCookiesAction( | 1366 GetCookiesAction( |
1331 &cookie_monster(), url_google_, &get_cookies_callback), | 1367 &cookie_monster(), url_google_, &get_cookies_callback), |
1332 SetCookieAction( | 1368 SetCookieAction( |
1333 &cookie_monster(), url_google_, "A=B", &set_cookies_callback), | 1369 &cookie_monster(), url_google_, "A=B", &set_cookies_callback), |
1334 DeleteCookieAction( | 1370 DeleteCookieAction( |
1335 &cookie_monster(), url_google_, "A", &delete_cookie_callback))); | 1371 &cookie_monster(), url_google_, "A", &delete_cookie_callback))); |
1336 ExpectLoadCall(); | 1372 ExpectLoadCall(); |
1373 ExpectLoadForKeyCall(); | |
1337 Begin(); | 1374 Begin(); |
1338 | 1375 |
1339 WaitForLoadCall(); | 1376 WaitForLoadCall(); |
1340 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( | 1377 EXPECT_CALL(get_cookies_callback, Invoke("X=1")).WillOnce( |
1341 GetCookiesWithInfoAction( | 1378 GetCookiesWithInfoAction( |
1342 &cookie_monster(), url_google_, &get_cookie_info_callback)); | 1379 &cookie_monster(), url_google_, &get_cookie_info_callback)); |
1343 | 1380 EXPECT_CALL(get_cookie_info_callback, Invoke("X=1", testing::_)).WillOnce( |
1381 QuitCurrentMessageLoop()); | |
1344 EXPECT_CALL(set_cookies_callback, Invoke(true)); | 1382 EXPECT_CALL(set_cookies_callback, Invoke(true)); |
1345 EXPECT_CALL(delete_cookie_callback, Invoke()); | 1383 EXPECT_CALL(delete_cookie_callback, Invoke()); |
1346 EXPECT_CALL(get_cookie_info_callback, Invoke("X=1", testing::_)).WillOnce( | |
1347 QuitCurrentMessageLoop()); | |
1348 | 1384 |
1349 CompleteLoadingAndWait(); | 1385 CompleteLoadingAndWait(); |
1350 } | 1386 } |
1351 | 1387 |
1352 TEST_F(CookieMonsterTest, DomainTest) { | 1388 TEST_F(CookieMonsterTest, DomainTest) { |
1353 scoped_refptr<MockPersistentCookieStore> store( | 1389 scoped_refptr<MockPersistentCookieStore> store( |
1354 new MockPersistentCookieStore); | 1390 new MockPersistentCookieStore); |
1355 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); | 1391 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
1356 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); | 1392 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
1357 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); | 1393 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
(...skipping 1605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2963 ASSERT_TRUE(cookie_list[0].IsExpired(Time::Now())); | 2999 ASSERT_TRUE(cookie_list[0].IsExpired(Time::Now())); |
2964 } | 3000 } |
2965 | 3001 |
2966 namespace { | 3002 namespace { |
2967 | 3003 |
2968 // Mock PersistentCookieStore that keeps track of the number of Flush() calls. | 3004 // Mock PersistentCookieStore that keeps track of the number of Flush() calls. |
2969 class FlushablePersistentStore : public CookieMonster::PersistentCookieStore { | 3005 class FlushablePersistentStore : public CookieMonster::PersistentCookieStore { |
2970 public: | 3006 public: |
2971 FlushablePersistentStore() : flush_count_(0) {} | 3007 FlushablePersistentStore() : flush_count_(0) {} |
2972 | 3008 |
2973 bool Load(const LoadedCallback& loaded_callback) { | 3009 void Load(const LoadedCallback& loaded_callback) { |
2974 std::vector<CookieMonster::CanonicalCookie*> out_cookies; | 3010 std::vector<CookieMonster::CanonicalCookie*> out_cookies; |
2975 loaded_callback.Run(out_cookies); | 3011 loaded_callback.Run(out_cookies); |
2976 return false; | 3012 } |
3013 | |
3014 void LoadCookiesForKey(const std::string& key, | |
3015 const LoadedCallback& loaded_callback) { | |
3016 Load(loaded_callback); | |
2977 } | 3017 } |
2978 | 3018 |
2979 void AddCookie(const CookieMonster::CanonicalCookie&) {} | 3019 void AddCookie(const CookieMonster::CanonicalCookie&) {} |
2980 void UpdateCookieAccessTime(const CookieMonster::CanonicalCookie&) {} | 3020 void UpdateCookieAccessTime(const CookieMonster::CanonicalCookie&) {} |
2981 void DeleteCookie(const CookieMonster::CanonicalCookie&) {} | 3021 void DeleteCookie(const CookieMonster::CanonicalCookie&) {} |
2982 void SetClearLocalStateOnExit(bool clear_local_state) {} | 3022 void SetClearLocalStateOnExit(bool clear_local_state) {} |
2983 | 3023 |
2984 void Flush(Task* completion_callback) { | 3024 void Flush(Task* completion_callback) { |
2985 ++flush_count_; | 3025 ++flush_count_; |
2986 if (completion_callback) { | 3026 if (completion_callback) { |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3486 base::Closure task = base::Bind( | 3526 base::Closure task = base::Bind( |
3487 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, | 3527 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, |
3488 base::Unretained(this), | 3528 base::Unretained(this), |
3489 cm, *it, &callback); | 3529 cm, *it, &callback); |
3490 RunOnOtherThread(task); | 3530 RunOnOtherThread(task); |
3491 EXPECT_TRUE(callback.did_run()); | 3531 EXPECT_TRUE(callback.did_run()); |
3492 EXPECT_TRUE(callback.result()); | 3532 EXPECT_TRUE(callback.result()); |
3493 } | 3533 } |
3494 | 3534 |
3495 } // namespace net | 3535 } // namespace net |
OLD | NEW |