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 <set> |
5 #include <sstream> | 6 #include <sstream> |
6 #include <vector> | 7 #include <vector> |
7 | 8 |
8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
9 #include "base/memory/scoped_callback_factory.h" | 10 #include "base/memory/scoped_callback_factory.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
12 #include "base/message_loop_proxy.h" | 13 #include "base/message_loop_proxy.h" |
13 #include "base/scoped_temp_dir.h" | 14 #include "base/scoped_temp_dir.h" |
14 #include "base/stl_util-inl.h" | 15 #include "base/stl_util-inl.h" |
(...skipping 15 matching lines...) Expand all Loading... |
30 namespace quota { | 31 namespace quota { |
31 | 32 |
32 // For shorter names. | 33 // For shorter names. |
33 const StorageType kTemp = kStorageTypeTemporary; | 34 const StorageType kTemp = kStorageTypeTemporary; |
34 const StorageType kPerm = kStorageTypePersistent; | 35 const StorageType kPerm = kStorageTypePersistent; |
35 | 36 |
36 class QuotaManagerTest : public testing::Test { | 37 class QuotaManagerTest : public testing::Test { |
37 protected: | 38 protected: |
38 typedef QuotaManager::QuotaTableEntry QuotaTableEntry; | 39 typedef QuotaManager::QuotaTableEntry QuotaTableEntry; |
39 typedef QuotaManager::QuotaTableEntries QuotaTableEntries; | 40 typedef QuotaManager::QuotaTableEntries QuotaTableEntries; |
40 typedef QuotaManager::LastAccessTimeTableEntry LastAccessTimeTableEntry; | 41 typedef QuotaManager::OriginInfoTableEntries OriginInfoTableEntries; |
41 typedef QuotaManager::LastAccessTimeTableEntries LastAccessTimeTableEntries; | |
42 | 42 |
43 public: | 43 public: |
44 QuotaManagerTest() | 44 QuotaManagerTest() |
45 : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 45 : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
46 virtual_time_counter_(0) { | 46 mock_time_counter_(0) { |
47 } | 47 } |
48 | 48 |
49 void SetUp() { | 49 void SetUp() { |
50 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); | 50 ASSERT_TRUE(data_dir_.CreateUniqueTempDir()); |
51 mock_special_storage_policy_ = new MockSpecialStoragePolicy; | 51 mock_special_storage_policy_ = new MockSpecialStoragePolicy; |
52 quota_manager_ = new QuotaManager( | 52 quota_manager_ = new QuotaManager( |
53 false /* is_incognito */, | 53 false /* is_incognito */, |
54 data_dir_.path(), | 54 data_dir_.path(), |
55 MessageLoopProxy::CreateForCurrentThread(), | 55 MessageLoopProxy::CreateForCurrentThread(), |
56 MessageLoopProxy::CreateForCurrentThread(), | 56 MessageLoopProxy::CreateForCurrentThread(), |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 ASSERT_TRUE(origins != NULL); | 195 ASSERT_TRUE(origins != NULL); |
196 origins->clear(); | 196 origins->clear(); |
197 quota_manager_->GetCachedOrigins(type, origins); | 197 quota_manager_->GetCachedOrigins(type, origins); |
198 } | 198 } |
199 | 199 |
200 void NotifyStorageAccessed(QuotaClient* client, | 200 void NotifyStorageAccessed(QuotaClient* client, |
201 const GURL& origin, | 201 const GURL& origin, |
202 StorageType type) { | 202 StorageType type) { |
203 DCHECK(client); | 203 DCHECK(client); |
204 quota_manager_->NotifyStorageAccessedInternal( | 204 quota_manager_->NotifyStorageAccessedInternal( |
205 client->id(), origin, type, GetCurrentMockTime()); | 205 client->id(), origin, type, IncrementMockTime()); |
206 } | 206 } |
207 | 207 |
208 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) { | 208 void DeleteOriginFromDatabase(const GURL& origin, StorageType type) { |
209 quota_manager_->DeleteOriginFromDatabase(origin, type); | 209 quota_manager_->DeleteOriginFromDatabase(origin, type); |
210 } | 210 } |
211 | 211 |
212 void GetLRUOrigin(StorageType type) { | 212 void GetLRUOrigin(StorageType type) { |
213 lru_origin_ = GURL(); | 213 lru_origin_ = GURL(); |
214 quota_manager_->GetLRUOrigin(type, | 214 quota_manager_->GetLRUOrigin(type, |
215 callback_factory_.NewCallback(&QuotaManagerTest::DidGetLRUOrigin)); | 215 callback_factory_.NewCallback(&QuotaManagerTest::DidGetLRUOrigin)); |
216 } | 216 } |
217 | 217 |
218 void NotifyOriginInUse(const GURL& origin) { | 218 void NotifyOriginInUse(const GURL& origin) { |
219 quota_manager_->NotifyOriginInUse(origin); | 219 quota_manager_->NotifyOriginInUse(origin); |
220 } | 220 } |
221 | 221 |
222 void NotifyOriginNoLongerInUse(const GURL& origin) { | 222 void NotifyOriginNoLongerInUse(const GURL& origin) { |
223 quota_manager_->NotifyOriginNoLongerInUse(origin); | 223 quota_manager_->NotifyOriginNoLongerInUse(origin); |
224 } | 224 } |
225 | 225 |
| 226 void GetOriginsModifiedSince(StorageType type, base::Time modified_since) { |
| 227 modified_origins_.clear(); |
| 228 quota_manager_->GetOriginsModifiedSince(type, modified_since, |
| 229 callback_factory_.NewCallback( |
| 230 &QuotaManagerTest::DidGetModifiedOrigins)); |
| 231 } |
| 232 |
226 void DumpQuotaTable() { | 233 void DumpQuotaTable() { |
227 quota_table_.clear(); | 234 quota_entries_.clear(); |
228 quota_manager_->DumpQuotaTable( | 235 quota_manager_->DumpQuotaTable( |
229 callback_factory_.NewCallback( | 236 callback_factory_.NewCallback( |
230 &QuotaManagerTest::DidDumpQuotaTable)); | 237 &QuotaManagerTest::DidDumpQuotaTable)); |
231 } | 238 } |
232 | 239 |
233 void DumpLastAccessTimeTable() { | 240 void DumpOriginInfoTable() { |
234 last_access_time_table_.clear(); | 241 origin_info_entries_.clear(); |
235 quota_manager_->DumpLastAccessTimeTable( | 242 quota_manager_->DumpOriginInfoTable( |
236 callback_factory_.NewCallback( | 243 callback_factory_.NewCallback( |
237 &QuotaManagerTest::DidDumpLastAccessTimeTable)); | 244 &QuotaManagerTest::DidDumpOriginInfoTable)); |
238 } | 245 } |
239 | 246 |
240 void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) { | 247 void DidGetUsageAndQuota(QuotaStatusCode status, int64 usage, int64 quota) { |
241 quota_status_ = status; | 248 quota_status_ = status; |
242 usage_ = usage; | 249 usage_ = usage; |
243 quota_ = quota; | 250 quota_ = quota; |
244 } | 251 } |
245 | 252 |
246 void DidGetQuota(QuotaStatusCode status, | 253 void DidGetQuota(QuotaStatusCode status, |
247 StorageType type, | 254 StorageType type, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 usage_ = usage; | 299 usage_ = usage; |
293 unlimited_usage_ = unlimited_usage; | 300 unlimited_usage_ = unlimited_usage; |
294 quota_ = quota; | 301 quota_ = quota; |
295 available_space_ = available_space; | 302 available_space_ = available_space; |
296 } | 303 } |
297 | 304 |
298 void DidGetLRUOrigin(const GURL& origin) { | 305 void DidGetLRUOrigin(const GURL& origin) { |
299 lru_origin_ = origin; | 306 lru_origin_ = origin; |
300 } | 307 } |
301 | 308 |
302 void DidDumpQuotaTable(const QuotaTableEntries& entries) { | 309 void DidGetModifiedOrigins(const std::set<GURL>& origins) { |
303 quota_table_ = entries; | 310 modified_origins_ = origins; |
304 } | 311 } |
305 | 312 |
306 void DidDumpLastAccessTimeTable(const LastAccessTimeTableEntries& entries) { | 313 void DidDumpQuotaTable(const QuotaTableEntries& entries) { |
307 last_access_time_table_ = entries; | 314 quota_entries_ = entries; |
| 315 } |
| 316 |
| 317 void DidDumpOriginInfoTable(const OriginInfoTableEntries& entries) { |
| 318 origin_info_entries_ = entries; |
308 } | 319 } |
309 | 320 |
310 void GetUsage_WithModifyTestBody(const StorageType type); | 321 void GetUsage_WithModifyTestBody(const StorageType type); |
311 | 322 |
312 void set_additional_callback_count(int c) { additional_callback_count_ = c; } | 323 void set_additional_callback_count(int c) { additional_callback_count_ = c; } |
313 int additional_callback_count() const { return additional_callback_count_; } | 324 int additional_callback_count() const { return additional_callback_count_; } |
314 void DidGetUsageAndQuotaAdditional( | 325 void DidGetUsageAndQuotaAdditional( |
315 QuotaStatusCode status, int64 usage, int64 quota) { | 326 QuotaStatusCode status, int64 usage, int64 quota) { |
316 ++additional_callback_count_; | 327 ++additional_callback_count_; |
317 } | 328 } |
318 | 329 |
319 QuotaManager* quota_manager() const { return quota_manager_.get(); } | 330 QuotaManager* quota_manager() const { return quota_manager_.get(); } |
320 void set_quota_manager(QuotaManager* quota_manager) { | 331 void set_quota_manager(QuotaManager* quota_manager) { |
321 quota_manager_ = quota_manager; | 332 quota_manager_ = quota_manager; |
322 } | 333 } |
323 | 334 |
324 MockSpecialStoragePolicy* mock_special_storage_policy() const { | 335 MockSpecialStoragePolicy* mock_special_storage_policy() const { |
325 return mock_special_storage_policy_.get(); | 336 return mock_special_storage_policy_.get(); |
326 } | 337 } |
327 | 338 |
328 QuotaStatusCode status() const { return quota_status_; } | 339 QuotaStatusCode status() const { return quota_status_; } |
329 const std::string& host() const { return host_; } | 340 const std::string& host() const { return host_; } |
330 StorageType type() const { return type_; } | 341 StorageType type() const { return type_; } |
331 int64 usage() const { return usage_; } | 342 int64 usage() const { return usage_; } |
332 int64 unlimited_usage() const { return unlimited_usage_; } | 343 int64 unlimited_usage() const { return unlimited_usage_; } |
333 int64 quota() const { return quota_; } | 344 int64 quota() const { return quota_; } |
334 int64 available_space() const { return available_space_; } | 345 int64 available_space() const { return available_space_; } |
335 const GURL& lru_origin() const { return lru_origin_; } | 346 const GURL& lru_origin() const { return lru_origin_; } |
336 const QuotaTableEntries& quota_table() const { return quota_table_; } | 347 const std::set<GURL>& modified_origins() const { return modified_origins_; } |
337 const LastAccessTimeTableEntries& last_access_time_table() const { | 348 const QuotaTableEntries& quota_entries() const { return quota_entries_; } |
338 return last_access_time_table_; | 349 const OriginInfoTableEntries& origin_info_entries() const { |
| 350 return origin_info_entries_; |
339 } | 351 } |
340 FilePath profile_path() const { return data_dir_.path(); } | 352 FilePath profile_path() const { return data_dir_.path(); } |
341 int status_callback_count() const { return status_callback_count_; } | 353 int status_callback_count() const { return status_callback_count_; } |
342 void reset_status_callback_count() { status_callback_count_ = 0; } | 354 void reset_status_callback_count() { status_callback_count_ = 0; } |
343 | 355 |
344 private: | 356 private: |
345 base::Time GetCurrentMockTime() { | 357 base::Time IncrementMockTime() { |
346 ++virtual_time_counter_; | 358 ++mock_time_counter_; |
347 return base::Time::FromDoubleT(virtual_time_counter_ * 10.0); | 359 return base::Time::FromDoubleT(mock_time_counter_ * 10.0); |
348 } | 360 } |
349 | 361 |
350 ScopedTempDir data_dir_; | 362 ScopedTempDir data_dir_; |
351 base::ScopedCallbackFactory<QuotaManagerTest> callback_factory_; | 363 base::ScopedCallbackFactory<QuotaManagerTest> callback_factory_; |
352 | 364 |
353 scoped_refptr<QuotaManager> quota_manager_; | 365 scoped_refptr<QuotaManager> quota_manager_; |
354 scoped_refptr<MockSpecialStoragePolicy> mock_special_storage_policy_; | 366 scoped_refptr<MockSpecialStoragePolicy> mock_special_storage_policy_; |
355 | 367 |
356 QuotaStatusCode quota_status_; | 368 QuotaStatusCode quota_status_; |
357 std::string host_; | 369 std::string host_; |
358 StorageType type_; | 370 StorageType type_; |
359 int64 usage_; | 371 int64 usage_; |
360 int64 unlimited_usage_; | 372 int64 unlimited_usage_; |
361 int64 quota_; | 373 int64 quota_; |
362 int64 available_space_; | 374 int64 available_space_; |
363 GURL lru_origin_; | 375 GURL lru_origin_; |
364 QuotaTableEntries quota_table_; | 376 std::set<GURL> modified_origins_; |
365 LastAccessTimeTableEntries last_access_time_table_; | 377 QuotaTableEntries quota_entries_; |
| 378 OriginInfoTableEntries origin_info_entries_; |
366 int status_callback_count_; | 379 int status_callback_count_; |
367 | 380 |
368 int additional_callback_count_; | 381 int additional_callback_count_; |
369 | 382 |
370 int virtual_time_counter_; | 383 int mock_time_counter_; |
371 | 384 |
372 DISALLOW_COPY_AND_ASSIGN(QuotaManagerTest); | 385 DISALLOW_COPY_AND_ASSIGN(QuotaManagerTest); |
373 }; | 386 }; |
374 | 387 |
375 TEST_F(QuotaManagerTest, GetUsageAndQuota_Simple) { | 388 TEST_F(QuotaManagerTest, GetUsageAndQuota_Simple) { |
376 static const MockOriginData kData[] = { | 389 static const MockOriginData kData[] = { |
377 { "http://foo.com/", kTemp, 10 }, | 390 { "http://foo.com/", kTemp, 10 }, |
378 { "http://foo.com/", kPerm, 80 }, | 391 { "http://foo.com/", kPerm, 80 }, |
379 }; | 392 }; |
380 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData))); | 393 RegisterClient(CreateClient(kData, ARRAYSIZE_UNSAFE(kData))); |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 quota_manager()->NotifyStorageAccessed(QuotaClient::kMockStart, | 1057 quota_manager()->NotifyStorageAccessed(QuotaClient::kMockStart, |
1045 GURL(kData1[i].origin), kData1[i].type); | 1058 GURL(kData1[i].origin), kData1[i].type); |
1046 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData2); ++i) | 1059 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData2); ++i) |
1047 quota_manager()->NotifyStorageAccessed(QuotaClient::kMockStart, | 1060 quota_manager()->NotifyStorageAccessed(QuotaClient::kMockStart, |
1048 GURL(kData2[i].origin), kData2[i].type); | 1061 GURL(kData2[i].origin), kData2[i].type); |
1049 MessageLoop::current()->RunAllPending(); | 1062 MessageLoop::current()->RunAllPending(); |
1050 | 1063 |
1051 EvictOriginData(GURL("http://foo.com/"), kTemp); | 1064 EvictOriginData(GURL("http://foo.com/"), kTemp); |
1052 MessageLoop::current()->RunAllPending(); | 1065 MessageLoop::current()->RunAllPending(); |
1053 | 1066 |
1054 DumpLastAccessTimeTable(); | 1067 DumpOriginInfoTable(); |
1055 MessageLoop::current()->RunAllPending(); | 1068 MessageLoop::current()->RunAllPending(); |
1056 | 1069 |
1057 typedef LastAccessTimeTableEntries::const_iterator iterator; | 1070 typedef OriginInfoTableEntries::const_iterator iterator; |
1058 for (iterator itr(last_access_time_table().begin()), | 1071 for (iterator itr(origin_info_entries().begin()), |
1059 end(last_access_time_table().end()); | 1072 end(origin_info_entries().end()); |
1060 itr != end; ++itr) { | 1073 itr != end; ++itr) { |
1061 if (itr->type == kTemp) | 1074 if (itr->type == kTemp) |
1062 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec()); | 1075 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec()); |
1063 } | 1076 } |
1064 | 1077 |
1065 GetGlobalUsage(kTemp); | 1078 GetGlobalUsage(kTemp); |
1066 MessageLoop::current()->RunAllPending(); | 1079 MessageLoop::current()->RunAllPending(); |
1067 EXPECT_EQ(predelete_global_tmp - (1 + 50000), usage()); | 1080 EXPECT_EQ(predelete_global_tmp - (1 + 50000), usage()); |
1068 | 1081 |
1069 GetHostUsage("foo.com", kTemp); | 1082 GetHostUsage("foo.com", kTemp); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 client->AddOriginToErrorSet(GURL("http://foo.com/"), kTemp); | 1118 client->AddOriginToErrorSet(GURL("http://foo.com/"), kTemp); |
1106 | 1119 |
1107 for (int i = 0; | 1120 for (int i = 0; |
1108 i < QuotaManager::kThresholdOfErrorsToBeBlacklisted + 1; | 1121 i < QuotaManager::kThresholdOfErrorsToBeBlacklisted + 1; |
1109 ++i) { | 1122 ++i) { |
1110 EvictOriginData(GURL("http://foo.com/"), kTemp); | 1123 EvictOriginData(GURL("http://foo.com/"), kTemp); |
1111 MessageLoop::current()->RunAllPending(); | 1124 MessageLoop::current()->RunAllPending(); |
1112 EXPECT_EQ(kQuotaErrorInvalidModification, status()); | 1125 EXPECT_EQ(kQuotaErrorInvalidModification, status()); |
1113 } | 1126 } |
1114 | 1127 |
1115 DumpLastAccessTimeTable(); | 1128 DumpOriginInfoTable(); |
1116 MessageLoop::current()->RunAllPending(); | 1129 MessageLoop::current()->RunAllPending(); |
1117 | 1130 |
1118 bool found_origin_in_database = false; | 1131 bool found_origin_in_database = false; |
1119 typedef LastAccessTimeTableEntries::const_iterator iterator; | 1132 typedef OriginInfoTableEntries::const_iterator iterator; |
1120 for (iterator itr(last_access_time_table().begin()), | 1133 for (iterator itr(origin_info_entries().begin()), |
1121 end(last_access_time_table().end()); | 1134 end(origin_info_entries().end()); |
1122 itr != end; ++itr) { | 1135 itr != end; ++itr) { |
1123 if (itr->type == kTemp && | 1136 if (itr->type == kTemp && |
1124 GURL("http://foo.com/") == itr->origin) { | 1137 GURL("http://foo.com/") == itr->origin) { |
1125 found_origin_in_database = true; | 1138 found_origin_in_database = true; |
1126 break; | 1139 break; |
1127 } | 1140 } |
1128 } | 1141 } |
1129 // The origin "http://foo.com/" should be in the database. | 1142 // The origin "http://foo.com/" should be in the database. |
1130 EXPECT_TRUE(found_origin_in_database); | 1143 EXPECT_TRUE(found_origin_in_database); |
1131 | 1144 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 MessageLoop::current()->RunAllPending(); | 1246 MessageLoop::current()->RunAllPending(); |
1234 | 1247 |
1235 reset_status_callback_count(); | 1248 reset_status_callback_count(); |
1236 DeleteOriginData(GURL("http://foo.com/"), kTemp); | 1249 DeleteOriginData(GURL("http://foo.com/"), kTemp); |
1237 DeleteOriginData(GURL("http://bar.com/"), kTemp); | 1250 DeleteOriginData(GURL("http://bar.com/"), kTemp); |
1238 DeleteOriginData(GURL("http://foo.com/"), kTemp); | 1251 DeleteOriginData(GURL("http://foo.com/"), kTemp); |
1239 MessageLoop::current()->RunAllPending(); | 1252 MessageLoop::current()->RunAllPending(); |
1240 | 1253 |
1241 EXPECT_EQ(3, status_callback_count()); | 1254 EXPECT_EQ(3, status_callback_count()); |
1242 | 1255 |
1243 DumpLastAccessTimeTable(); | 1256 DumpOriginInfoTable(); |
1244 MessageLoop::current()->RunAllPending(); | 1257 MessageLoop::current()->RunAllPending(); |
1245 | 1258 |
1246 typedef LastAccessTimeTableEntries::const_iterator iterator; | 1259 typedef OriginInfoTableEntries::const_iterator iterator; |
1247 for (iterator itr(last_access_time_table().begin()), | 1260 for (iterator itr(origin_info_entries().begin()), |
1248 end(last_access_time_table().end()); | 1261 end(origin_info_entries().end()); |
1249 itr != end; ++itr) { | 1262 itr != end; ++itr) { |
1250 if (itr->type == kTemp) { | 1263 if (itr->type == kTemp) { |
1251 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec()); | 1264 EXPECT_NE(std::string("http://foo.com/"), itr->origin.spec()); |
1252 EXPECT_NE(std::string("http://bar.com/"), itr->origin.spec()); | 1265 EXPECT_NE(std::string("http://bar.com/"), itr->origin.spec()); |
1253 } | 1266 } |
1254 } | 1267 } |
1255 | 1268 |
1256 GetGlobalUsage(kTemp); | 1269 GetGlobalUsage(kTemp); |
1257 MessageLoop::current()->RunAllPending(); | 1270 MessageLoop::current()->RunAllPending(); |
1258 EXPECT_EQ(predelete_global_tmp - (1 + 4000 + 50000 + 9), usage()); | 1271 EXPECT_EQ(predelete_global_tmp - (1 + 4000 + 50000 + 9), usage()); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1401 // see empty result here. | 1414 // see empty result here. |
1402 EXPECT_TRUE(lru_origin().is_empty()); | 1415 EXPECT_TRUE(lru_origin().is_empty()); |
1403 | 1416 |
1404 NotifyOriginNoLongerInUse(GURL("http://a.com/")); | 1417 NotifyOriginNoLongerInUse(GURL("http://a.com/")); |
1405 NotifyOriginNoLongerInUse(GURL("https://a.com/")); | 1418 NotifyOriginNoLongerInUse(GURL("https://a.com/")); |
1406 GetLRUOrigin(kTemp); | 1419 GetLRUOrigin(kTemp); |
1407 MessageLoop::current()->RunAllPending(); | 1420 MessageLoop::current()->RunAllPending(); |
1408 EXPECT_EQ("http://a.com/", lru_origin().spec()); | 1421 EXPECT_EQ("http://a.com/", lru_origin().spec()); |
1409 } | 1422 } |
1410 | 1423 |
| 1424 TEST_F(QuotaManagerTest, GetOriginsModifiedSince) { |
| 1425 static const MockOriginData kData[] = { |
| 1426 { "http://a.com/", kTemp, 0 }, |
| 1427 { "http://a.com:1/", kTemp, 0 }, |
| 1428 { "https://a.com/", kTemp, 0 }, |
| 1429 { "http://b.com/", kPerm, 0 }, // persistent |
| 1430 { "http://c.com/", kTemp, 0 }, |
| 1431 }; |
| 1432 MockStorageClient* client = CreateClient(kData, ARRAYSIZE_UNSAFE(kData)); |
| 1433 RegisterClient(client); |
| 1434 |
| 1435 GetOriginsModifiedSince(kTemp, base::Time()); |
| 1436 MessageLoop::current()->RunAllPending(); |
| 1437 EXPECT_TRUE(modified_origins().empty()); |
| 1438 |
| 1439 base::Time time1 = client->IncrementMockTime(); |
| 1440 client->ModifyOriginAndNotify(GURL("http://a.com/"), kTemp, 10); |
| 1441 client->ModifyOriginAndNotify(GURL("http://a.com:1/"), kTemp, 10); |
| 1442 client->ModifyOriginAndNotify(GURL("http://b.com/"), kPerm, 10); |
| 1443 base::Time time2 = client->IncrementMockTime(); |
| 1444 client->ModifyOriginAndNotify(GURL("https://a.com/"), kTemp, 10); |
| 1445 client->ModifyOriginAndNotify(GURL("http://c.com/"), kTemp, 10); |
| 1446 base::Time time3 = client->IncrementMockTime(); |
| 1447 |
| 1448 GetOriginsModifiedSince(kTemp, time1); |
| 1449 MessageLoop::current()->RunAllPending(); |
| 1450 EXPECT_EQ(4U, modified_origins().size()); |
| 1451 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kData); ++i) { |
| 1452 if (kData[i].type == kTemp) |
| 1453 EXPECT_EQ(1U, modified_origins().count(GURL(kData[i].origin))); |
| 1454 } |
| 1455 |
| 1456 GetOriginsModifiedSince(kTemp, time2); |
| 1457 MessageLoop::current()->RunAllPending(); |
| 1458 EXPECT_EQ(2U, modified_origins().size()); |
| 1459 |
| 1460 GetOriginsModifiedSince(kTemp, time3); |
| 1461 MessageLoop::current()->RunAllPending(); |
| 1462 EXPECT_TRUE(modified_origins().empty()); |
| 1463 |
| 1464 client->ModifyOriginAndNotify(GURL("http://a.com/"), kTemp, 10); |
| 1465 |
| 1466 GetOriginsModifiedSince(kTemp, time3); |
| 1467 MessageLoop::current()->RunAllPending(); |
| 1468 EXPECT_EQ(1U, modified_origins().size()); |
| 1469 EXPECT_EQ(1U, modified_origins().count(GURL("http://a.com/"))); |
| 1470 } |
| 1471 |
1411 TEST_F(QuotaManagerTest, DumpQuotaTable) { | 1472 TEST_F(QuotaManagerTest, DumpQuotaTable) { |
1412 SetPersistentHostQuota("example1.com", 1); | 1473 SetPersistentHostQuota("example1.com", 1); |
1413 SetPersistentHostQuota("example2.com", 20); | 1474 SetPersistentHostQuota("example2.com", 20); |
1414 SetPersistentHostQuota("example3.com", 300); | 1475 SetPersistentHostQuota("example3.com", 300); |
1415 MessageLoop::current()->RunAllPending(); | 1476 MessageLoop::current()->RunAllPending(); |
1416 | 1477 |
1417 DumpQuotaTable(); | 1478 DumpQuotaTable(); |
1418 MessageLoop::current()->RunAllPending(); | 1479 MessageLoop::current()->RunAllPending(); |
1419 | 1480 |
1420 const QuotaTableEntry kEntries[] = { | 1481 const QuotaTableEntry kEntries[] = { |
1421 {"example1.com", kPerm, 1}, | 1482 QuotaTableEntry("example1.com", kPerm, 1), |
1422 {"example2.com", kPerm, 20}, | 1483 QuotaTableEntry("example2.com", kPerm, 20), |
1423 {"example3.com", kPerm, 300}, | 1484 QuotaTableEntry("example3.com", kPerm, 300), |
1424 }; | 1485 }; |
1425 std::set<QuotaTableEntry> entries | 1486 std::set<QuotaTableEntry> entries |
1426 (kEntries, kEntries + ARRAYSIZE_UNSAFE(kEntries)); | 1487 (kEntries, kEntries + ARRAYSIZE_UNSAFE(kEntries)); |
1427 | 1488 |
1428 typedef QuotaTableEntries::const_iterator iterator; | 1489 typedef QuotaTableEntries::const_iterator iterator; |
1429 for (iterator itr(quota_table().begin()), end(quota_table().end()); | 1490 for (iterator itr(quota_entries().begin()), end(quota_entries().end()); |
1430 itr != end; ++itr) { | 1491 itr != end; ++itr) { |
1431 SCOPED_TRACE(testing::Message() | 1492 SCOPED_TRACE(testing::Message() |
1432 << "host = " << itr->host << ", " | 1493 << "host = " << itr->host << ", " |
1433 << "quota = " << itr->quota); | 1494 << "quota = " << itr->quota); |
1434 EXPECT_EQ(1u, entries.erase(*itr)); | 1495 EXPECT_EQ(1u, entries.erase(*itr)); |
1435 } | 1496 } |
1436 EXPECT_TRUE(entries.empty()); | 1497 EXPECT_TRUE(entries.empty()); |
1437 } | 1498 } |
1438 | 1499 |
1439 TEST_F(QuotaManagerTest, DumpLastAccessTimeTable) { | 1500 TEST_F(QuotaManagerTest, DumpOriginInfoTable) { |
1440 using std::make_pair; | 1501 using std::make_pair; |
1441 | 1502 |
1442 quota_manager()->NotifyStorageAccessed( | 1503 quota_manager()->NotifyStorageAccessed( |
1443 QuotaClient::kMockStart, | 1504 QuotaClient::kMockStart, |
1444 GURL("http://example.com/"), | 1505 GURL("http://example.com/"), |
1445 kTemp); | 1506 kTemp); |
1446 quota_manager()->NotifyStorageAccessed( | 1507 quota_manager()->NotifyStorageAccessed( |
1447 QuotaClient::kMockStart, | 1508 QuotaClient::kMockStart, |
1448 GURL("http://example.com/"), | 1509 GURL("http://example.com/"), |
1449 kPerm); | 1510 kPerm); |
1450 quota_manager()->NotifyStorageAccessed( | 1511 quota_manager()->NotifyStorageAccessed( |
1451 QuotaClient::kMockStart, | 1512 QuotaClient::kMockStart, |
1452 GURL("http://example.com/"), | 1513 GURL("http://example.com/"), |
1453 kPerm); | 1514 kPerm); |
1454 MessageLoop::current()->RunAllPending(); | 1515 MessageLoop::current()->RunAllPending(); |
1455 | 1516 |
1456 DumpLastAccessTimeTable(); | 1517 DumpOriginInfoTable(); |
1457 MessageLoop::current()->RunAllPending(); | 1518 MessageLoop::current()->RunAllPending(); |
1458 | 1519 |
1459 typedef std::pair<GURL, StorageType> TypedOrigin; | 1520 typedef std::pair<GURL, StorageType> TypedOrigin; |
1460 typedef std::pair<TypedOrigin, int> Entry; | 1521 typedef std::pair<TypedOrigin, int> Entry; |
1461 const Entry kEntries[] = { | 1522 const Entry kEntries[] = { |
1462 make_pair(make_pair(GURL("http://example.com/"), kTemp), 1), | 1523 make_pair(make_pair(GURL("http://example.com/"), kTemp), 1), |
1463 make_pair(make_pair(GURL("http://example.com/"), kPerm), 2), | 1524 make_pair(make_pair(GURL("http://example.com/"), kPerm), 2), |
1464 }; | 1525 }; |
1465 std::set<Entry> entries | 1526 std::set<Entry> entries |
1466 (kEntries, kEntries + ARRAYSIZE_UNSAFE(kEntries)); | 1527 (kEntries, kEntries + ARRAYSIZE_UNSAFE(kEntries)); |
1467 | 1528 |
1468 typedef LastAccessTimeTableEntries::const_iterator iterator; | 1529 typedef OriginInfoTableEntries::const_iterator iterator; |
1469 for (iterator itr(last_access_time_table().begin()), | 1530 for (iterator itr(origin_info_entries().begin()), |
1470 end(last_access_time_table().end()); | 1531 end(origin_info_entries().end()); |
1471 itr != end; ++itr) { | 1532 itr != end; ++itr) { |
1472 SCOPED_TRACE(testing::Message() | 1533 SCOPED_TRACE(testing::Message() |
1473 << "host = " << itr->origin << ", " | 1534 << "host = " << itr->origin << ", " |
1474 << "type = " << itr->type << ", " | 1535 << "type = " << itr->type << ", " |
1475 << "used_count = " << itr->used_count); | 1536 << "used_count = " << itr->used_count); |
1476 EXPECT_EQ(1u, entries.erase( | 1537 EXPECT_EQ(1u, entries.erase( |
1477 make_pair(make_pair(itr->origin, itr->type), | 1538 make_pair(make_pair(itr->origin, itr->type), |
1478 itr->used_count))); | 1539 itr->used_count))); |
1479 } | 1540 } |
1480 EXPECT_TRUE(entries.empty()); | 1541 EXPECT_TRUE(entries.empty()); |
1481 } | 1542 } |
1482 | 1543 |
1483 TEST_F(QuotaManagerTest, QuotaForEmptyHost) { | 1544 TEST_F(QuotaManagerTest, QuotaForEmptyHost) { |
1484 GetPersistentHostQuota(std::string()); | 1545 GetPersistentHostQuota(std::string()); |
1485 MessageLoop::current()->RunAllPending(); | 1546 MessageLoop::current()->RunAllPending(); |
1486 EXPECT_EQ(kQuotaStatusOk, status()); | 1547 EXPECT_EQ(kQuotaStatusOk, status()); |
1487 EXPECT_EQ(0, quota()); | 1548 EXPECT_EQ(0, quota()); |
1488 | 1549 |
1489 SetPersistentHostQuota(std::string(), 10); | 1550 SetPersistentHostQuota(std::string(), 10); |
1490 MessageLoop::current()->RunAllPending(); | 1551 MessageLoop::current()->RunAllPending(); |
1491 EXPECT_EQ(kQuotaErrorNotSupported, status()); | 1552 EXPECT_EQ(kQuotaErrorNotSupported, status()); |
1492 } | 1553 } |
1493 } // namespace quota | 1554 } // namespace quota |
OLD | NEW |