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 <stack> | 5 #include <stack> |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "webkit/appcache/appcache.h" | 12 #include "webkit/appcache/appcache.h" |
13 #include "webkit/appcache/appcache_database.h" | 13 #include "webkit/appcache/appcache_database.h" |
14 #include "webkit/appcache/appcache_entry.h" | 14 #include "webkit/appcache/appcache_entry.h" |
15 #include "webkit/appcache/appcache_group.h" | 15 #include "webkit/appcache/appcache_group.h" |
16 #include "webkit/appcache/appcache_policy.h" | 16 #include "webkit/appcache/appcache_policy.h" |
17 #include "webkit/appcache/appcache_service.h" | 17 #include "webkit/appcache/appcache_service.h" |
18 #include "webkit/appcache/appcache_storage_impl.h" | 18 #include "webkit/appcache/appcache_storage_impl.h" |
| 19 #include "webkit/quota/quota_manager.h" |
19 #include "webkit/tools/test_shell/simple_appcache_system.h" | 20 #include "webkit/tools/test_shell/simple_appcache_system.h" |
20 | 21 |
21 namespace appcache { | 22 namespace appcache { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 const base::Time kZeroTime; | 26 const base::Time kZeroTime; |
26 const GURL kManifestUrl("http://blah/manifest"); | 27 const GURL kManifestUrl("http://blah/manifest"); |
27 const GURL kManifestUrl2("http://blah/manifest2"); | 28 const GURL kManifestUrl2("http://blah/manifest2"); |
28 const GURL kManifestUrl3("http://blah/manifest3"); | 29 const GURL kManifestUrl3("http://blah/manifest3"); |
29 const GURL kEntryUrl("http://blah/entry"); | 30 const GURL kEntryUrl("http://blah/entry"); |
30 const GURL kEntryUrl2("http://blah/entry2"); | 31 const GURL kEntryUrl2("http://blah/entry2"); |
31 const GURL kFallbackNamespace("http://blah/fallback_namespace/"); | 32 const GURL kFallbackNamespace("http://blah/fallback_namespace/"); |
32 const GURL kFallbackNamespace2("http://blah/fallback_namespace/longer"); | 33 const GURL kFallbackNamespace2("http://blah/fallback_namespace/longer"); |
33 const GURL kFallbackTestUrl("http://blah/fallback_namespace/longer/test"); | 34 const GURL kFallbackTestUrl("http://blah/fallback_namespace/longer/test"); |
34 const GURL kOnlineNamespace("http://blah/online_namespace"); | 35 const GURL kOnlineNamespace("http://blah/online_namespace"); |
35 const GURL kOnlineNamespaceWithinFallback( | 36 const GURL kOnlineNamespaceWithinFallback( |
36 "http://blah/fallback_namespace/online/"); | 37 "http://blah/fallback_namespace/online/"); |
| 38 const GURL kOrigin(kManifestUrl.GetOrigin()); |
37 | 39 |
38 const int kManifestEntryIdOffset = 100; | 40 const int kManifestEntryIdOffset = 100; |
39 const int kFallbackEntryIdOffset = 1000; | 41 const int kFallbackEntryIdOffset = 1000; |
40 | 42 |
| 43 const GURL kDefaultEntryUrl("http://blah/makecacheandgroup_default_entry"); |
| 44 const int kDefaultEntrySize = 10; |
| 45 const int kDefaultEntryIdOffset = 12345; |
| 46 |
| 47 const int kMockQuota = 5000; |
| 48 |
41 // For the duration of this test case, we hijack the AppCacheThread API | 49 // For the duration of this test case, we hijack the AppCacheThread API |
42 // calls and implement them in terms of the io and db threads created here. | 50 // calls and implement them in terms of the io and db threads created here. |
43 | 51 |
44 scoped_ptr<base::Thread> io_thread; | 52 scoped_ptr<base::Thread> io_thread; |
45 scoped_ptr<base::Thread> db_thread; | 53 scoped_ptr<base::Thread> db_thread; |
46 | 54 |
47 class TestThreadProvider : public SimpleAppCacheSystem::ThreadProvider { | 55 class TestThreadProvider : public SimpleAppCacheSystem::ThreadProvider { |
48 public: | 56 public: |
49 virtual bool PostTask( | 57 virtual bool PostTask( |
50 int id, | 58 int id, |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 return can_create_return_value_; | 177 return can_create_return_value_; |
170 } | 178 } |
171 | 179 |
172 bool can_load_return_value_; | 180 bool can_load_return_value_; |
173 int can_create_return_value_; | 181 int can_create_return_value_; |
174 GURL requested_manifest_url_; | 182 GURL requested_manifest_url_; |
175 net::CompletionCallback* callback_; | 183 net::CompletionCallback* callback_; |
176 AppCacheStorageImplTest* test_; | 184 AppCacheStorageImplTest* test_; |
177 }; | 185 }; |
178 | 186 |
| 187 class MockQuotaManager : public quota::QuotaManager { |
| 188 public: |
| 189 MockQuotaManager() |
| 190 : QuotaManager(true /* is_incognito */, FilePath(), |
| 191 io_thread->message_loop_proxy(), |
| 192 db_thread->message_loop_proxy(), |
| 193 NULL), |
| 194 async_(false) {} |
| 195 |
| 196 virtual void GetUsageAndQuota( |
| 197 const GURL& origin, quota::StorageType type, |
| 198 GetUsageAndQuotaCallback* callback) { |
| 199 EXPECT_EQ(kOrigin, origin); |
| 200 EXPECT_EQ(quota::kStorageTypeTemporary, type); |
| 201 if (async_) { |
| 202 MessageLoop::current()->PostTask(FROM_HERE, |
| 203 NewRunnableMethod(this, &MockQuotaManager::CallCallbackAndDelete, |
| 204 callback)); |
| 205 return; |
| 206 } |
| 207 CallCallbackAndDelete(callback); |
| 208 } |
| 209 |
| 210 void CallCallbackAndDelete(GetUsageAndQuotaCallback* callback) { |
| 211 callback->Run(quota::kQuotaStatusOk, 0, kMockQuota); |
| 212 delete callback; |
| 213 } |
| 214 |
| 215 bool async_; |
| 216 }; |
| 217 |
| 218 class MockQuotaManagerProxy : public quota::QuotaManagerProxy { |
| 219 public: |
| 220 MockQuotaManagerProxy() |
| 221 : QuotaManagerProxy(NULL, NULL), |
| 222 notify_storage_accessed_count_(0), |
| 223 notify_storage_modified_count_(0), |
| 224 last_delta_(0), |
| 225 mock_manager_(new MockQuotaManager) { |
| 226 manager_ = mock_manager_; |
| 227 } |
| 228 |
| 229 virtual void NotifyStorageAccessed(quota::QuotaClient::ID client_id, |
| 230 const GURL& origin, |
| 231 quota::StorageType type) { |
| 232 EXPECT_EQ(quota::QuotaClient::kAppcache, client_id); |
| 233 EXPECT_EQ(quota::kStorageTypeTemporary, type); |
| 234 ++notify_storage_accessed_count_; |
| 235 last_origin_ = origin; |
| 236 } |
| 237 |
| 238 virtual void NotifyStorageModified(quota::QuotaClient::ID client_id, |
| 239 const GURL& origin, |
| 240 quota::StorageType type, |
| 241 int64 delta) { |
| 242 EXPECT_EQ(quota::QuotaClient::kAppcache, client_id); |
| 243 EXPECT_EQ(quota::kStorageTypeTemporary, type); |
| 244 ++notify_storage_modified_count_; |
| 245 last_origin_ = origin; |
| 246 last_delta_ = delta; |
| 247 } |
| 248 |
| 249 // Not needed for our tests. |
| 250 virtual void RegisterClient(quota::QuotaClient* client) {} |
| 251 virtual void NotifyOriginInUse(const GURL& origin) {} |
| 252 virtual void NotifyOriginNoLongerInUse(const GURL& origin) {} |
| 253 |
| 254 int notify_storage_accessed_count_; |
| 255 int notify_storage_modified_count_; |
| 256 GURL last_origin_; |
| 257 int last_delta_; |
| 258 scoped_refptr<MockQuotaManager> mock_manager_; |
| 259 }; |
| 260 |
179 // Helper class run a test on our io_thread. The io_thread | 261 // Helper class run a test on our io_thread. The io_thread |
180 // is spun up once and reused for all tests. | 262 // is spun up once and reused for all tests. |
181 template <class Method> | 263 template <class Method> |
182 class WrapperTask : public Task { | 264 class WrapperTask : public Task { |
183 public: | 265 public: |
184 WrapperTask(AppCacheStorageImplTest* test, Method method) | 266 WrapperTask(AppCacheStorageImplTest* test, Method method) |
185 : test_(test), method_(method) { | 267 : test_(test), method_(method) { |
186 } | 268 } |
187 | 269 |
188 virtual void Run() { | 270 virtual void Run() { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 test_finished_event_ .reset(new base::WaitableEvent(false, false)); | 318 test_finished_event_ .reset(new base::WaitableEvent(false, false)); |
237 io_thread->message_loop()->PostTask( | 319 io_thread->message_loop()->PostTask( |
238 FROM_HERE, new WrapperTask<Method>(this, method)); | 320 FROM_HERE, new WrapperTask<Method>(this, method)); |
239 test_finished_event_->Wait(); | 321 test_finished_event_->Wait(); |
240 } | 322 } |
241 | 323 |
242 void SetUpTest() { | 324 void SetUpTest() { |
243 DCHECK(MessageLoop::current() == io_thread->message_loop()); | 325 DCHECK(MessageLoop::current() == io_thread->message_loop()); |
244 service_.reset(new AppCacheService(NULL)); | 326 service_.reset(new AppCacheService(NULL)); |
245 service_->Initialize(FilePath(), NULL); | 327 service_->Initialize(FilePath(), NULL); |
| 328 mock_quota_manager_proxy_ = new MockQuotaManagerProxy(); |
| 329 service_->quota_manager_proxy_ = mock_quota_manager_proxy_; |
246 delegate_.reset(new MockStorageDelegate(this)); | 330 delegate_.reset(new MockStorageDelegate(this)); |
247 } | 331 } |
248 | 332 |
249 void TearDownTest() { | 333 void TearDownTest() { |
250 DCHECK(MessageLoop::current() == io_thread->message_loop()); | 334 DCHECK(MessageLoop::current() == io_thread->message_loop()); |
251 storage()->CancelDelegateCallbacks(delegate()); | 335 storage()->CancelDelegateCallbacks(delegate()); |
252 group_ = NULL; | 336 group_ = NULL; |
253 cache_ = NULL; | 337 cache_ = NULL; |
254 cache2_ = NULL; | 338 cache2_ = NULL; |
| 339 mock_quota_manager_proxy_ = NULL; |
255 delegate_.reset(); | 340 delegate_.reset(); |
256 service_.reset(); | 341 service_.reset(); |
257 FlushDbThreadTasks(); | 342 FlushDbThreadTasks(); |
258 } | 343 } |
259 | 344 |
260 void TestFinished() { | 345 void TestFinished() { |
261 // We unwind the stack prior to finishing up to let stack | 346 // We unwind the stack prior to finishing up to let stack |
262 // based objects get deleted. | 347 // based objects get deleted. |
263 DCHECK(MessageLoop::current() == io_thread->message_loop()); | 348 DCHECK(MessageLoop::current() == io_thread->message_loop()); |
264 MessageLoop::current()->PostTask(FROM_HERE, | 349 MessageLoop::current()->PostTask(FROM_HERE, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 PushNextTask(NewRunnableMethod( | 390 PushNextTask(NewRunnableMethod( |
306 this, &AppCacheStorageImplTest::Verify_LoadCache_Miss)); | 391 this, &AppCacheStorageImplTest::Verify_LoadCache_Miss)); |
307 | 392 |
308 storage()->LoadCache(111, delegate()); | 393 storage()->LoadCache(111, delegate()); |
309 EXPECT_NE(111, delegate()->loaded_cache_id_); | 394 EXPECT_NE(111, delegate()->loaded_cache_id_); |
310 } | 395 } |
311 | 396 |
312 void Verify_LoadCache_Miss() { | 397 void Verify_LoadCache_Miss() { |
313 EXPECT_EQ(111, delegate()->loaded_cache_id_); | 398 EXPECT_EQ(111, delegate()->loaded_cache_id_); |
314 EXPECT_FALSE(delegate()->loaded_cache_); | 399 EXPECT_FALSE(delegate()->loaded_cache_); |
| 400 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_accessed_count_); |
| 401 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_); |
315 TestFinished(); | 402 TestFinished(); |
316 } | 403 } |
317 | 404 |
318 // LoadCache_NearHit ------------------------------------------------- | 405 // LoadCache_NearHit ------------------------------------------------- |
319 | 406 |
320 void LoadCache_NearHit() { | 407 void LoadCache_NearHit() { |
321 // Attempt to load a cache that is currently in use | 408 // Attempt to load a cache that is currently in use |
322 // and does not require loading from storage. This | 409 // and does not require loading from storage. This |
323 // load should complete syncly. | 410 // load should complete syncly. |
324 | 411 |
325 // Setup some preconditions. Make an 'unstored' cache for | 412 // Setup some preconditions. Make an 'unstored' cache for |
326 // us to load. The ctor should put it in the working set. | 413 // us to load. The ctor should put it in the working set. |
327 int64 cache_id = storage()->NewCacheId(); | 414 int64 cache_id = storage()->NewCacheId(); |
328 scoped_refptr<AppCache> cache(new AppCache(service(), cache_id)); | 415 scoped_refptr<AppCache> cache(new AppCache(service(), cache_id)); |
329 | 416 |
330 // Conduct the test. | 417 // Conduct the test. |
331 storage()->LoadCache(cache_id, delegate()); | 418 storage()->LoadCache(cache_id, delegate()); |
332 EXPECT_EQ(cache_id, delegate()->loaded_cache_id_); | 419 EXPECT_EQ(cache_id, delegate()->loaded_cache_id_); |
333 EXPECT_EQ(cache.get(), delegate()->loaded_cache_.get()); | 420 EXPECT_EQ(cache.get(), delegate()->loaded_cache_.get()); |
| 421 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_accessed_count_); |
| 422 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_); |
334 TestFinished(); | 423 TestFinished(); |
335 } | 424 } |
336 | 425 |
337 // CreateGroup -------------------------------------------- | 426 // CreateGroup -------------------------------------------- |
338 | 427 |
339 void CreateGroupInEmptyOrigin() { | 428 void CreateGroupInEmptyOrigin() { |
340 // Attempt to load a group that doesn't exist, one should | 429 // Attempt to load a group that doesn't exist, one should |
341 // be created for us, but not stored. | 430 // be created for us, but not stored. |
342 | 431 |
343 // Since the origin has no groups, the storage class will respond | 432 // Since the origin has no groups, the storage class will respond |
344 // syncly. | 433 // syncly. |
345 storage()->LoadOrCreateGroup(kManifestUrl, delegate()); | 434 storage()->LoadOrCreateGroup(kManifestUrl, delegate()); |
346 Verify_CreateGroup(); | 435 Verify_CreateGroup(); |
347 } | 436 } |
348 | 437 |
349 void CreateGroupInPopulatedOrigin() { | 438 void CreateGroupInPopulatedOrigin() { |
350 // Attempt to load a group that doesn't exist, one should | 439 // Attempt to load a group that doesn't exist, one should |
351 // be created for us, but not stored. | 440 // be created for us, but not stored. |
352 PushNextTask(NewRunnableMethod( | 441 PushNextTask(NewRunnableMethod( |
353 this, &AppCacheStorageImplTest::Verify_CreateGroup)); | 442 this, &AppCacheStorageImplTest::Verify_CreateGroup)); |
354 | 443 |
355 // Since the origin has groups, storage class will have to | 444 // Since the origin has groups, storage class will have to |
356 // consult the database and completion will be async. | 445 // consult the database and completion will be async. |
357 storage()->origins_with_groups_.insert(kManifestUrl.GetOrigin()); | 446 storage()->usage_map_[kOrigin] = kDefaultEntrySize; |
358 | 447 |
359 storage()->LoadOrCreateGroup(kManifestUrl, delegate()); | 448 storage()->LoadOrCreateGroup(kManifestUrl, delegate()); |
360 EXPECT_FALSE(delegate()->loaded_group_.get()); | 449 EXPECT_FALSE(delegate()->loaded_group_.get()); |
361 } | 450 } |
362 | 451 |
363 void Verify_CreateGroup() { | 452 void Verify_CreateGroup() { |
364 EXPECT_EQ(kManifestUrl, delegate()->loaded_manifest_url_); | 453 EXPECT_EQ(kManifestUrl, delegate()->loaded_manifest_url_); |
365 EXPECT_TRUE(delegate()->loaded_group_.get()); | 454 EXPECT_TRUE(delegate()->loaded_group_.get()); |
366 EXPECT_TRUE(delegate()->loaded_group_->HasOneRef()); | 455 EXPECT_TRUE(delegate()->loaded_group_->HasOneRef()); |
367 EXPECT_FALSE(delegate()->loaded_group_->newest_complete_cache()); | 456 EXPECT_FALSE(delegate()->loaded_group_->newest_complete_cache()); |
368 | 457 |
369 // Should not have been stored in the database. | 458 // Should not have been stored in the database. |
370 AppCacheDatabase::GroupRecord record; | 459 AppCacheDatabase::GroupRecord record; |
371 EXPECT_FALSE(database()->FindGroup( | 460 EXPECT_FALSE(database()->FindGroup( |
372 delegate()->loaded_group_->group_id(), &record)); | 461 delegate()->loaded_group_->group_id(), &record)); |
373 | 462 |
| 463 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_accessed_count_); |
| 464 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_); |
| 465 |
374 TestFinished(); | 466 TestFinished(); |
375 } | 467 } |
376 | 468 |
377 // LoadGroupAndCache_FarHit -------------------------------------- | 469 // LoadGroupAndCache_FarHit -------------------------------------- |
378 | 470 |
379 void LoadGroupAndCache_FarHit() { | 471 void LoadGroupAndCache_FarHit() { |
380 // Attempt to load a cache that is not currently in use | 472 // Attempt to load a cache that is not currently in use |
381 // and does require loading from disk. This | 473 // and does require loading from disk. This |
382 // load should complete asyncly. | 474 // load should complete asyncly. |
383 PushNextTask(NewRunnableMethod( | 475 PushNextTask(NewRunnableMethod( |
(...skipping 12 matching lines...) Expand all Loading... |
396 void Verify_LoadCache_Far_Hit() { | 488 void Verify_LoadCache_Far_Hit() { |
397 EXPECT_TRUE(delegate()->loaded_cache_); | 489 EXPECT_TRUE(delegate()->loaded_cache_); |
398 EXPECT_TRUE(delegate()->loaded_cache_->HasOneRef()); | 490 EXPECT_TRUE(delegate()->loaded_cache_->HasOneRef()); |
399 EXPECT_EQ(1, delegate()->loaded_cache_id_); | 491 EXPECT_EQ(1, delegate()->loaded_cache_id_); |
400 | 492 |
401 // The group should also have been loaded. | 493 // The group should also have been loaded. |
402 EXPECT_TRUE(delegate()->loaded_cache_->owning_group()); | 494 EXPECT_TRUE(delegate()->loaded_cache_->owning_group()); |
403 EXPECT_TRUE(delegate()->loaded_cache_->owning_group()->HasOneRef()); | 495 EXPECT_TRUE(delegate()->loaded_cache_->owning_group()->HasOneRef()); |
404 EXPECT_EQ(1, delegate()->loaded_cache_->owning_group()->group_id()); | 496 EXPECT_EQ(1, delegate()->loaded_cache_->owning_group()->group_id()); |
405 | 497 |
| 498 EXPECT_EQ(1, mock_quota_manager_proxy_->notify_storage_accessed_count_); |
| 499 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_); |
| 500 |
406 // Drop things from the working set. | 501 // Drop things from the working set. |
407 delegate()->loaded_cache_ = NULL; | 502 delegate()->loaded_cache_ = NULL; |
408 EXPECT_FALSE(delegate()->loaded_group_); | 503 EXPECT_FALSE(delegate()->loaded_group_); |
409 | 504 |
410 // Conduct the group load test, also complete asyncly. | 505 // Conduct the group load test, also complete asyncly. |
411 PushNextTask(NewRunnableMethod( | 506 PushNextTask(NewRunnableMethod( |
412 this, &AppCacheStorageImplTest::Verify_LoadGroup_Far_Hit)); | 507 this, &AppCacheStorageImplTest::Verify_LoadGroup_Far_Hit)); |
413 | 508 |
414 storage()->LoadOrCreateGroup(kManifestUrl, delegate()); | 509 storage()->LoadOrCreateGroup(kManifestUrl, delegate()); |
415 } | 510 } |
416 | 511 |
417 void Verify_LoadGroup_Far_Hit() { | 512 void Verify_LoadGroup_Far_Hit() { |
418 EXPECT_TRUE(delegate()->loaded_group_); | 513 EXPECT_TRUE(delegate()->loaded_group_); |
419 EXPECT_EQ(kManifestUrl, delegate()->loaded_manifest_url_); | 514 EXPECT_EQ(kManifestUrl, delegate()->loaded_manifest_url_); |
420 EXPECT_TRUE(delegate()->loaded_group_->newest_complete_cache()); | 515 EXPECT_TRUE(delegate()->loaded_group_->newest_complete_cache()); |
421 delegate()->loaded_groups_newest_cache_ = NULL; | 516 delegate()->loaded_groups_newest_cache_ = NULL; |
422 EXPECT_TRUE(delegate()->loaded_group_->HasOneRef()); | 517 EXPECT_TRUE(delegate()->loaded_group_->HasOneRef()); |
| 518 EXPECT_EQ(2, mock_quota_manager_proxy_->notify_storage_accessed_count_); |
| 519 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_); |
423 TestFinished(); | 520 TestFinished(); |
424 } | 521 } |
425 | 522 |
426 // StoreNewGroup -------------------------------------- | 523 // StoreNewGroup -------------------------------------- |
427 | 524 |
428 void StoreNewGroup() { | 525 void StoreNewGroup() { |
429 // Store a group and its newest cache. Should complete asyncly. | 526 // Store a group and its newest cache. Should complete asyncly. |
430 PushNextTask(NewRunnableMethod( | 527 PushNextTask(NewRunnableMethod( |
431 this, &AppCacheStorageImplTest::Verify_StoreNewGroup)); | 528 this, &AppCacheStorageImplTest::Verify_StoreNewGroup)); |
432 | 529 |
433 // Setup some preconditions. Create a group and newest cache that | 530 // Setup some preconditions. Create a group and newest cache that |
434 // appear to be "unstored". | 531 // appear to be "unstored". |
435 group_ = new AppCacheGroup( | 532 group_ = new AppCacheGroup( |
436 service(), kManifestUrl, storage()->NewGroupId()); | 533 service(), kManifestUrl, storage()->NewGroupId()); |
437 cache_ = new AppCache(service(), storage()->NewCacheId()); | 534 cache_ = new AppCache(service(), storage()->NewCacheId()); |
| 535 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, 1, |
| 536 kDefaultEntrySize)); |
438 // Hold a ref to the cache simulate the UpdateJob holding that ref, | 537 // Hold a ref to the cache simulate the UpdateJob holding that ref, |
439 // and hold a ref to the group to simulate the CacheHost holding that ref. | 538 // and hold a ref to the group to simulate the CacheHost holding that ref. |
440 | 539 |
| 540 // Have the quota manager retrun asyncly for this test. |
| 541 mock_quota_manager_proxy_->mock_manager_->async_ = true; |
| 542 |
441 // Conduct the store test. | 543 // Conduct the store test. |
442 storage()->StoreGroupAndNewestCache(group_, cache_, delegate()); | 544 storage()->StoreGroupAndNewestCache(group_, cache_, delegate()); |
443 EXPECT_FALSE(delegate()->stored_group_success_); | 545 EXPECT_FALSE(delegate()->stored_group_success_); |
444 } | 546 } |
445 | 547 |
446 void Verify_StoreNewGroup() { | 548 void Verify_StoreNewGroup() { |
447 EXPECT_TRUE(delegate()->stored_group_success_); | 549 EXPECT_TRUE(delegate()->stored_group_success_); |
448 EXPECT_EQ(group_.get(), delegate()->stored_group_.get()); | 550 EXPECT_EQ(group_.get(), delegate()->stored_group_.get()); |
449 EXPECT_EQ(cache_.get(), group_->newest_complete_cache()); | 551 EXPECT_EQ(cache_.get(), group_->newest_complete_cache()); |
450 EXPECT_TRUE(cache_->is_complete()); | 552 EXPECT_TRUE(cache_->is_complete()); |
451 | 553 |
452 // Should have been stored in the database. | 554 // Should have been stored in the database. |
453 AppCacheDatabase::GroupRecord group_record; | 555 AppCacheDatabase::GroupRecord group_record; |
454 AppCacheDatabase::CacheRecord cache_record; | 556 AppCacheDatabase::CacheRecord cache_record; |
455 EXPECT_TRUE(database()->FindGroup(group_->group_id(), &group_record)); | 557 EXPECT_TRUE(database()->FindGroup(group_->group_id(), &group_record)); |
456 EXPECT_TRUE(database()->FindCache(cache_->cache_id(), &cache_record)); | 558 EXPECT_TRUE(database()->FindCache(cache_->cache_id(), &cache_record)); |
| 559 |
| 560 // Verify quota bookkeeping |
| 561 EXPECT_EQ(kDefaultEntrySize, storage()->usage_map_[kOrigin]); |
| 562 EXPECT_EQ(1, mock_quota_manager_proxy_->notify_storage_modified_count_); |
| 563 EXPECT_EQ(kOrigin, mock_quota_manager_proxy_->last_origin_); |
| 564 EXPECT_EQ(kDefaultEntrySize, mock_quota_manager_proxy_->last_delta_); |
| 565 |
457 TestFinished(); | 566 TestFinished(); |
458 } | 567 } |
459 | 568 |
460 // StoreExistingGroup -------------------------------------- | 569 // StoreExistingGroup -------------------------------------- |
461 | 570 |
462 void StoreExistingGroup() { | 571 void StoreExistingGroup() { |
463 // Store a group and its newest cache. Should complete asyncly. | 572 // Store a group and its newest cache. Should complete asyncly. |
464 PushNextTask(NewRunnableMethod( | 573 PushNextTask(NewRunnableMethod( |
465 this, &AppCacheStorageImplTest::Verify_StoreExistingGroup)); | 574 this, &AppCacheStorageImplTest::Verify_StoreExistingGroup)); |
466 | 575 |
467 // Setup some preconditions. Create a group and old complete cache | 576 // Setup some preconditions. Create a group and old complete cache |
468 // that appear to be "stored" | 577 // that appear to be "stored" |
469 MakeCacheAndGroup(kManifestUrl, 1, 1, true); | 578 MakeCacheAndGroup(kManifestUrl, 1, 1, true); |
| 579 EXPECT_EQ(kDefaultEntrySize, storage()->usage_map_[kOrigin]); |
470 | 580 |
471 // And a newest unstored complete cache. | 581 // And a newest unstored complete cache. |
472 cache2_ = new AppCache(service(), 2); | 582 cache2_ = new AppCache(service(), 2); |
| 583 cache2_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::MASTER, 1, |
| 584 kDefaultEntrySize + 100)); |
473 | 585 |
474 // Conduct the test. | 586 // Conduct the test. |
475 storage()->StoreGroupAndNewestCache(group_, cache2_, delegate()); | 587 storage()->StoreGroupAndNewestCache(group_, cache2_, delegate()); |
476 EXPECT_FALSE(delegate()->stored_group_success_); | 588 EXPECT_FALSE(delegate()->stored_group_success_); |
477 } | 589 } |
478 | 590 |
479 void Verify_StoreExistingGroup() { | 591 void Verify_StoreExistingGroup() { |
480 EXPECT_TRUE(delegate()->stored_group_success_); | 592 EXPECT_TRUE(delegate()->stored_group_success_); |
481 EXPECT_EQ(group_.get(), delegate()->stored_group_.get()); | 593 EXPECT_EQ(group_.get(), delegate()->stored_group_.get()); |
482 EXPECT_EQ(cache2_.get(), group_->newest_complete_cache()); | 594 EXPECT_EQ(cache2_.get(), group_->newest_complete_cache()); |
483 EXPECT_TRUE(cache2_->is_complete()); | 595 EXPECT_TRUE(cache2_->is_complete()); |
484 | 596 |
485 // The new cache should have been stored in the database. | 597 // The new cache should have been stored in the database. |
486 AppCacheDatabase::GroupRecord group_record; | 598 AppCacheDatabase::GroupRecord group_record; |
487 AppCacheDatabase::CacheRecord cache_record; | 599 AppCacheDatabase::CacheRecord cache_record; |
488 EXPECT_TRUE(database()->FindGroup(1, &group_record)); | 600 EXPECT_TRUE(database()->FindGroup(1, &group_record)); |
489 EXPECT_TRUE(database()->FindCache(2, &cache_record)); | 601 EXPECT_TRUE(database()->FindCache(2, &cache_record)); |
490 | 602 |
491 // The old cache should have been deleted | 603 // The old cache should have been deleted |
492 EXPECT_FALSE(database()->FindCache(1, &cache_record)); | 604 EXPECT_FALSE(database()->FindCache(1, &cache_record)); |
| 605 |
| 606 // Verify quota bookkeeping |
| 607 EXPECT_EQ(kDefaultEntrySize + 100, storage()->usage_map_[kOrigin]); |
| 608 EXPECT_EQ(1, mock_quota_manager_proxy_->notify_storage_modified_count_); |
| 609 EXPECT_EQ(kOrigin, mock_quota_manager_proxy_->last_origin_); |
| 610 EXPECT_EQ(100, mock_quota_manager_proxy_->last_delta_); |
| 611 |
493 TestFinished(); | 612 TestFinished(); |
494 } | 613 } |
495 | 614 |
496 // StoreExistingGroupExistingCache ------------------------------- | 615 // StoreExistingGroupExistingCache ------------------------------- |
497 | 616 |
498 void StoreExistingGroupExistingCache() { | 617 void StoreExistingGroupExistingCache() { |
499 // Store a group with updates to its existing newest complete cache. | 618 // Store a group with updates to its existing newest complete cache. |
500 // Setup some preconditions. Create a group and a complete cache that | 619 // Setup some preconditions. Create a group and a complete cache that |
501 // appear to be "stored". | 620 // appear to be "stored". |
502 | 621 |
503 // Setup some preconditions. Create a group and old complete cache | 622 // Setup some preconditions. Create a group and old complete cache |
504 // that appear to be "stored" | 623 // that appear to be "stored" |
505 MakeCacheAndGroup(kManifestUrl, 1, 1, true); | 624 MakeCacheAndGroup(kManifestUrl, 1, 1, true); |
| 625 EXPECT_EQ(kDefaultEntrySize, storage()->usage_map_[kOrigin]); |
506 | 626 |
507 // Change the cache. | 627 // Change the cache. |
508 base::Time now = base::Time::Now(); | 628 base::Time now = base::Time::Now(); |
509 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::MASTER, 1, 100)); | 629 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::MASTER, 1, 100)); |
510 cache_->set_update_time(now); | 630 cache_->set_update_time(now); |
511 | 631 |
512 PushNextTask(NewRunnableMethod( | 632 PushNextTask(NewRunnableMethod( |
513 this, &AppCacheStorageImplTest::Verify_StoreExistingGroupExistingCache, | 633 this, &AppCacheStorageImplTest::Verify_StoreExistingGroupExistingCache, |
514 now)); | 634 now)); |
515 | 635 |
516 // Conduct the test. | 636 // Conduct the test. |
517 EXPECT_EQ(cache_, group_->newest_complete_cache()); | 637 EXPECT_EQ(cache_, group_->newest_complete_cache()); |
518 storage()->StoreGroupAndNewestCache(group_, cache_, delegate()); | 638 storage()->StoreGroupAndNewestCache(group_, cache_, delegate()); |
519 EXPECT_FALSE(delegate()->stored_group_success_); | 639 EXPECT_FALSE(delegate()->stored_group_success_); |
520 } | 640 } |
521 | 641 |
522 void Verify_StoreExistingGroupExistingCache( | 642 void Verify_StoreExistingGroupExistingCache( |
523 base::Time expected_update_time) { | 643 base::Time expected_update_time) { |
524 EXPECT_TRUE(delegate()->stored_group_success_); | 644 EXPECT_TRUE(delegate()->stored_group_success_); |
525 EXPECT_EQ(cache_, group_->newest_complete_cache()); | 645 EXPECT_EQ(cache_, group_->newest_complete_cache()); |
526 | 646 |
527 AppCacheDatabase::CacheRecord cache_record; | 647 AppCacheDatabase::CacheRecord cache_record; |
528 EXPECT_TRUE(database()->FindCache(1, &cache_record)); | 648 EXPECT_TRUE(database()->FindCache(1, &cache_record)); |
529 EXPECT_EQ(1, cache_record.cache_id); | 649 EXPECT_EQ(1, cache_record.cache_id); |
530 EXPECT_EQ(1, cache_record.group_id); | 650 EXPECT_EQ(1, cache_record.group_id); |
531 EXPECT_FALSE(cache_record.online_wildcard); | 651 EXPECT_FALSE(cache_record.online_wildcard); |
532 EXPECT_TRUE(expected_update_time == cache_record.update_time); | 652 EXPECT_TRUE(expected_update_time == cache_record.update_time); |
533 EXPECT_EQ(100, cache_record.cache_size); | 653 EXPECT_EQ(100 + kDefaultEntrySize, cache_record.cache_size); |
534 | 654 |
535 std::vector<AppCacheDatabase::EntryRecord> entry_records; | 655 std::vector<AppCacheDatabase::EntryRecord> entry_records; |
536 EXPECT_TRUE(database()->FindEntriesForCache(1, &entry_records)); | 656 EXPECT_TRUE(database()->FindEntriesForCache(1, &entry_records)); |
537 EXPECT_EQ(1U, entry_records.size()); | 657 EXPECT_EQ(2U, entry_records.size()); |
| 658 if (entry_records[0].url == kDefaultEntryUrl) |
| 659 entry_records.erase(entry_records.begin()); |
538 EXPECT_EQ(1 , entry_records[0].cache_id); | 660 EXPECT_EQ(1 , entry_records[0].cache_id); |
539 EXPECT_EQ(kEntryUrl, entry_records[0].url); | 661 EXPECT_EQ(kEntryUrl, entry_records[0].url); |
540 EXPECT_EQ(AppCacheEntry::MASTER, entry_records[0].flags); | 662 EXPECT_EQ(AppCacheEntry::MASTER, entry_records[0].flags); |
541 EXPECT_EQ(1, entry_records[0].response_id); | 663 EXPECT_EQ(1, entry_records[0].response_id); |
542 EXPECT_EQ(100, entry_records[0].response_size); | 664 EXPECT_EQ(100, entry_records[0].response_size); |
543 | 665 |
| 666 // Verify quota bookkeeping |
| 667 EXPECT_EQ(100 + kDefaultEntrySize, storage()->usage_map_[kOrigin]); |
| 668 EXPECT_EQ(1, mock_quota_manager_proxy_->notify_storage_modified_count_); |
| 669 EXPECT_EQ(kOrigin, mock_quota_manager_proxy_->last_origin_); |
| 670 EXPECT_EQ(100, mock_quota_manager_proxy_->last_delta_); |
| 671 |
544 TestFinished(); | 672 TestFinished(); |
545 } | 673 } |
546 | 674 |
547 // FailStoreGroup -------------------------------------- | 675 // FailStoreGroup -------------------------------------- |
548 | 676 |
549 void FailStoreGroup() { | 677 void FailStoreGroup() { |
550 // Store a group and its newest cache. Should complete asyncly. | 678 // Store a group and its newest cache. Should complete asyncly. |
551 PushNextTask(NewRunnableMethod( | 679 PushNextTask(NewRunnableMethod( |
552 this, &AppCacheStorageImplTest::Verify_FailStoreGroup)); | 680 this, &AppCacheStorageImplTest::Verify_FailStoreGroup)); |
553 | 681 |
(...skipping 16 matching lines...) Expand all Loading... |
570 void Verify_FailStoreGroup() { | 698 void Verify_FailStoreGroup() { |
571 EXPECT_FALSE(delegate()->stored_group_success_); | 699 EXPECT_FALSE(delegate()->stored_group_success_); |
572 EXPECT_TRUE(delegate()->would_exceed_quota_); | 700 EXPECT_TRUE(delegate()->would_exceed_quota_); |
573 | 701 |
574 // Should not have been stored in the database. | 702 // Should not have been stored in the database. |
575 AppCacheDatabase::GroupRecord group_record; | 703 AppCacheDatabase::GroupRecord group_record; |
576 AppCacheDatabase::CacheRecord cache_record; | 704 AppCacheDatabase::CacheRecord cache_record; |
577 EXPECT_FALSE(database()->FindGroup(group_->group_id(), &group_record)); | 705 EXPECT_FALSE(database()->FindGroup(group_->group_id(), &group_record)); |
578 EXPECT_FALSE(database()->FindCache(cache_->cache_id(), &cache_record)); | 706 EXPECT_FALSE(database()->FindCache(cache_->cache_id(), &cache_record)); |
579 | 707 |
| 708 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_accessed_count_); |
| 709 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_); |
| 710 |
580 TestFinished(); | 711 TestFinished(); |
581 } | 712 } |
582 | 713 |
583 // MakeGroupObsolete ------------------------------- | 714 // MakeGroupObsolete ------------------------------- |
584 | 715 |
585 void MakeGroupObsolete() { | 716 void MakeGroupObsolete() { |
586 // Make a group obsolete, should complete asyncly. | 717 // Make a group obsolete, should complete asyncly. |
587 PushNextTask(NewRunnableMethod( | 718 PushNextTask(NewRunnableMethod( |
588 this, &AppCacheStorageImplTest::Verify_MakeGroupObsolete)); | 719 this, &AppCacheStorageImplTest::Verify_MakeGroupObsolete)); |
589 | 720 |
590 // Setup some preconditions. Create a group and newest cache that | 721 // Setup some preconditions. Create a group and newest cache that |
591 // appears to be "stored" and "currently in use". | 722 // appears to be "stored" and "currently in use". |
592 MakeCacheAndGroup(kManifestUrl, 1, 1, true); | 723 MakeCacheAndGroup(kManifestUrl, 1, 1, true); |
593 EXPECT_FALSE(storage()->origins_with_groups_.empty()); | 724 EXPECT_EQ(kDefaultEntrySize, storage()->usage_map_[kOrigin]); |
594 | 725 |
595 // Also insert some related records. | 726 // Also insert some related records. |
596 AppCacheDatabase::EntryRecord entry_record; | 727 AppCacheDatabase::EntryRecord entry_record; |
597 entry_record.cache_id = 1; | 728 entry_record.cache_id = 1; |
598 entry_record.flags = AppCacheEntry::FALLBACK; | 729 entry_record.flags = AppCacheEntry::FALLBACK; |
599 entry_record.response_id = 1; | 730 entry_record.response_id = 1; |
600 entry_record.url = kEntryUrl; | 731 entry_record.url = kEntryUrl; |
601 EXPECT_TRUE(database()->InsertEntry(&entry_record)); | 732 EXPECT_TRUE(database()->InsertEntry(&entry_record)); |
602 | 733 |
603 AppCacheDatabase::FallbackNameSpaceRecord fallback_namespace_record; | 734 AppCacheDatabase::FallbackNameSpaceRecord fallback_namespace_record; |
(...skipping 11 matching lines...) Expand all Loading... |
615 | 746 |
616 // Conduct the test. | 747 // Conduct the test. |
617 storage()->MakeGroupObsolete(group_, delegate()); | 748 storage()->MakeGroupObsolete(group_, delegate()); |
618 EXPECT_FALSE(group_->is_obsolete()); | 749 EXPECT_FALSE(group_->is_obsolete()); |
619 } | 750 } |
620 | 751 |
621 void Verify_MakeGroupObsolete() { | 752 void Verify_MakeGroupObsolete() { |
622 EXPECT_TRUE(delegate()->obsoleted_success_); | 753 EXPECT_TRUE(delegate()->obsoleted_success_); |
623 EXPECT_EQ(group_.get(), delegate()->obsoleted_group_.get()); | 754 EXPECT_EQ(group_.get(), delegate()->obsoleted_group_.get()); |
624 EXPECT_TRUE(group_->is_obsolete()); | 755 EXPECT_TRUE(group_->is_obsolete()); |
625 EXPECT_TRUE(storage()->origins_with_groups_.empty()); | 756 EXPECT_TRUE(storage()->usage_map_.empty()); |
626 | 757 |
627 // The cache and group have been deleted from the database. | 758 // The cache and group have been deleted from the database. |
628 AppCacheDatabase::GroupRecord group_record; | 759 AppCacheDatabase::GroupRecord group_record; |
629 AppCacheDatabase::CacheRecord cache_record; | 760 AppCacheDatabase::CacheRecord cache_record; |
630 EXPECT_FALSE(database()->FindGroup(1, &group_record)); | 761 EXPECT_FALSE(database()->FindGroup(1, &group_record)); |
631 EXPECT_FALSE(database()->FindCache(1, &cache_record)); | 762 EXPECT_FALSE(database()->FindCache(1, &cache_record)); |
632 | 763 |
633 // The related records should have been deleted too. | 764 // The related records should have been deleted too. |
634 std::vector<AppCacheDatabase::EntryRecord> entry_records; | 765 std::vector<AppCacheDatabase::EntryRecord> entry_records; |
635 database()->FindEntriesForCache(1, &entry_records); | 766 database()->FindEntriesForCache(1, &entry_records); |
636 EXPECT_TRUE(entry_records.empty()); | 767 EXPECT_TRUE(entry_records.empty()); |
637 std::vector<AppCacheDatabase::FallbackNameSpaceRecord> fallback_records; | 768 std::vector<AppCacheDatabase::FallbackNameSpaceRecord> fallback_records; |
638 database()->FindFallbackNameSpacesForCache(1, &fallback_records); | 769 database()->FindFallbackNameSpacesForCache(1, &fallback_records); |
639 EXPECT_TRUE(fallback_records.empty()); | 770 EXPECT_TRUE(fallback_records.empty()); |
640 std::vector<AppCacheDatabase::OnlineWhiteListRecord> whitelist_records; | 771 std::vector<AppCacheDatabase::OnlineWhiteListRecord> whitelist_records; |
641 database()->FindOnlineWhiteListForCache(1, &whitelist_records); | 772 database()->FindOnlineWhiteListForCache(1, &whitelist_records); |
642 EXPECT_TRUE(whitelist_records.empty()); | 773 EXPECT_TRUE(whitelist_records.empty()); |
643 | 774 |
| 775 // Verify quota bookkeeping |
| 776 EXPECT_TRUE(storage()->usage_map_.empty()); |
| 777 EXPECT_EQ(1, mock_quota_manager_proxy_->notify_storage_modified_count_); |
| 778 EXPECT_EQ(kOrigin, mock_quota_manager_proxy_->last_origin_); |
| 779 EXPECT_EQ(-kDefaultEntrySize, mock_quota_manager_proxy_->last_delta_); |
| 780 |
644 TestFinished(); | 781 TestFinished(); |
645 } | 782 } |
646 | 783 |
647 // MarkEntryAsForeign ------------------------------- | 784 // MarkEntryAsForeign ------------------------------- |
648 | 785 |
649 void MarkEntryAsForeign() { | 786 void MarkEntryAsForeign() { |
650 // Setup some preconditions. Create a cache with an entry | 787 // Setup some preconditions. Create a cache with an entry |
651 // in storage and in the working set. | 788 // in storage and in the working set. |
652 MakeCacheAndGroup(kManifestUrl, 1, 1, true); | 789 MakeCacheAndGroup(kManifestUrl, 1, 1, true); |
653 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT)); | 790 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT)); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 cache_->fallback_namespaces_.push_back( | 966 cache_->fallback_namespaces_.push_back( |
830 FallbackNamespace(kFallbackNamespace2, kEntryUrl2)); | 967 FallbackNamespace(kFallbackNamespace2, kEntryUrl2)); |
831 cache_->fallback_namespaces_.push_back( | 968 cache_->fallback_namespaces_.push_back( |
832 FallbackNamespace(kFallbackNamespace, kEntryUrl)); | 969 FallbackNamespace(kFallbackNamespace, kEntryUrl)); |
833 AppCacheDatabase::CacheRecord cache_record; | 970 AppCacheDatabase::CacheRecord cache_record; |
834 std::vector<AppCacheDatabase::EntryRecord> entries; | 971 std::vector<AppCacheDatabase::EntryRecord> entries; |
835 std::vector<AppCacheDatabase::FallbackNameSpaceRecord> fallbacks; | 972 std::vector<AppCacheDatabase::FallbackNameSpaceRecord> fallbacks; |
836 std::vector<AppCacheDatabase::OnlineWhiteListRecord> whitelists; | 973 std::vector<AppCacheDatabase::OnlineWhiteListRecord> whitelists; |
837 cache_->ToDatabaseRecords(group_, | 974 cache_->ToDatabaseRecords(group_, |
838 &cache_record, &entries, &fallbacks, &whitelists); | 975 &cache_record, &entries, &fallbacks, &whitelists); |
839 EXPECT_TRUE(database()->InsertEntryRecords(entries)); | 976 |
| 977 std::vector<AppCacheDatabase::EntryRecord>::const_iterator iter = |
| 978 entries.begin(); |
| 979 while (iter != entries.end()) { |
| 980 // MakeCacheAndGroup has inserted the default entry record already |
| 981 if (iter->url != kDefaultEntryUrl) |
| 982 EXPECT_TRUE(database()->InsertEntry(&(*iter))); |
| 983 ++iter; |
| 984 } |
| 985 |
840 EXPECT_TRUE(database()->InsertFallbackNameSpaceRecords(fallbacks)); | 986 EXPECT_TRUE(database()->InsertFallbackNameSpaceRecords(fallbacks)); |
841 EXPECT_TRUE(database()->InsertOnlineWhiteListRecords(whitelists)); | 987 EXPECT_TRUE(database()->InsertOnlineWhiteListRecords(whitelists)); |
842 if (drop_from_working_set) { | 988 if (drop_from_working_set) { |
843 EXPECT_TRUE(cache_->HasOneRef()); | 989 EXPECT_TRUE(cache_->HasOneRef()); |
844 cache_ = NULL; | 990 cache_ = NULL; |
845 EXPECT_TRUE(group_->HasOneRef()); | 991 EXPECT_TRUE(group_->HasOneRef()); |
846 group_ = NULL; | 992 group_ = NULL; |
847 } | 993 } |
848 | 994 |
849 // Conduct the test. The test url is in both fallback namespace urls, | 995 // Conduct the test. The test url is in both fallback namespace urls, |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 return storage()->database_; | 1264 return storage()->database_; |
1119 } | 1265 } |
1120 | 1266 |
1121 MockStorageDelegate* delegate() { | 1267 MockStorageDelegate* delegate() { |
1122 return delegate_.get(); | 1268 return delegate_.get(); |
1123 } | 1269 } |
1124 | 1270 |
1125 void MakeCacheAndGroup( | 1271 void MakeCacheAndGroup( |
1126 const GURL& manifest_url, int64 group_id, int64 cache_id, | 1272 const GURL& manifest_url, int64 group_id, int64 cache_id, |
1127 bool add_to_database) { | 1273 bool add_to_database) { |
| 1274 AppCacheEntry default_entry( |
| 1275 AppCacheEntry::EXPLICIT, cache_id + kDefaultEntryIdOffset, |
| 1276 kDefaultEntrySize); |
1128 group_ = new AppCacheGroup(service(), manifest_url, group_id); | 1277 group_ = new AppCacheGroup(service(), manifest_url, group_id); |
1129 cache_ = new AppCache(service(), cache_id); | 1278 cache_ = new AppCache(service(), cache_id); |
| 1279 cache_->AddEntry(kDefaultEntryUrl, default_entry); |
1130 cache_->set_complete(true); | 1280 cache_->set_complete(true); |
1131 group_->AddCache(cache_); | 1281 group_->AddCache(cache_); |
1132 if (add_to_database) { | 1282 if (add_to_database) { |
1133 AppCacheDatabase::GroupRecord group_record; | 1283 AppCacheDatabase::GroupRecord group_record; |
1134 group_record.group_id = group_id; | 1284 group_record.group_id = group_id; |
1135 group_record.manifest_url = manifest_url; | 1285 group_record.manifest_url = manifest_url; |
1136 group_record.origin = manifest_url.GetOrigin(); | 1286 group_record.origin = manifest_url.GetOrigin(); |
1137 EXPECT_TRUE(database()->InsertGroup(&group_record)); | 1287 EXPECT_TRUE(database()->InsertGroup(&group_record)); |
1138 AppCacheDatabase::CacheRecord cache_record; | 1288 AppCacheDatabase::CacheRecord cache_record; |
1139 cache_record.cache_id = cache_id; | 1289 cache_record.cache_id = cache_id; |
1140 cache_record.group_id = group_id; | 1290 cache_record.group_id = group_id; |
1141 cache_record.online_wildcard = false; | 1291 cache_record.online_wildcard = false; |
1142 cache_record.update_time = kZeroTime; | 1292 cache_record.update_time = kZeroTime; |
| 1293 cache_record.cache_size = kDefaultEntrySize; |
1143 EXPECT_TRUE(database()->InsertCache(&cache_record)); | 1294 EXPECT_TRUE(database()->InsertCache(&cache_record)); |
1144 storage()->origins_with_groups_.insert(manifest_url.GetOrigin()); | 1295 AppCacheDatabase::EntryRecord entry_record; |
| 1296 entry_record.cache_id = cache_id; |
| 1297 entry_record.url = kDefaultEntryUrl; |
| 1298 entry_record.flags = default_entry.types(); |
| 1299 entry_record.response_id = default_entry.response_id(); |
| 1300 entry_record.response_size = default_entry.response_size(); |
| 1301 EXPECT_TRUE(database()->InsertEntry(&entry_record)); |
| 1302 |
| 1303 storage()->usage_map_[manifest_url.GetOrigin()] = |
| 1304 default_entry.response_size(); |
1145 } | 1305 } |
1146 } | 1306 } |
1147 | 1307 |
1148 // Data members -------------------------------------------------- | 1308 // Data members -------------------------------------------------- |
1149 | 1309 |
1150 scoped_ptr<base::WaitableEvent> test_finished_event_; | 1310 scoped_ptr<base::WaitableEvent> test_finished_event_; |
1151 std::stack<Task*> task_stack_; | 1311 std::stack<Task*> task_stack_; |
1152 MockAppCachePolicy policy_; | 1312 MockAppCachePolicy policy_; |
1153 scoped_ptr<AppCacheService> service_; | 1313 scoped_ptr<AppCacheService> service_; |
1154 scoped_ptr<MockStorageDelegate> delegate_; | 1314 scoped_ptr<MockStorageDelegate> delegate_; |
| 1315 scoped_refptr<MockQuotaManagerProxy> mock_quota_manager_proxy_; |
1155 scoped_refptr<AppCacheGroup> group_; | 1316 scoped_refptr<AppCacheGroup> group_; |
1156 scoped_refptr<AppCache> cache_; | 1317 scoped_refptr<AppCache> cache_; |
1157 scoped_refptr<AppCache> cache2_; | 1318 scoped_refptr<AppCache> cache2_; |
1158 }; | 1319 }; |
1159 | 1320 |
1160 | 1321 |
1161 TEST_F(AppCacheStorageImplTest, LoadCache_Miss) { | 1322 TEST_F(AppCacheStorageImplTest, LoadCache_Miss) { |
1162 RunTestOnIOThread(&AppCacheStorageImplTest::LoadCache_Miss); | 1323 RunTestOnIOThread(&AppCacheStorageImplTest::LoadCache_Miss); |
1163 } | 1324 } |
1164 | 1325 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1251 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet); | 1412 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet); |
1252 } | 1413 } |
1253 | 1414 |
1254 // That's all folks! | 1415 // That's all folks! |
1255 | 1416 |
1256 } // namespace appcache | 1417 } // namespace appcache |
1257 | 1418 |
1258 // AppCacheStorageImplTest is expected to always live longer than the | 1419 // AppCacheStorageImplTest is expected to always live longer than the |
1259 // runnable methods. This lets us call NewRunnableMethod on its instances. | 1420 // runnable methods. This lets us call NewRunnableMethod on its instances. |
1260 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest); | 1421 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest); |
OLD | NEW |