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