Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(701)

Side by Side Diff: net/base/cookie_monster_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698