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