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