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

Side by Side Diff: webkit/appcache/appcache_storage_impl_unittest.cc

Issue 8515019: base::Bind: Convert most of webkit/appcache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unused include. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stack> 5 #include <stack>
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/callback.h"
7 #include "base/message_loop.h" 10 #include "base/message_loop.h"
8 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
9 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
10 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
11 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
12 #include "webkit/appcache/appcache.h" 15 #include "webkit/appcache/appcache.h"
13 #include "webkit/appcache/appcache_database.h" 16 #include "webkit/appcache/appcache_database.h"
14 #include "webkit/appcache/appcache_entry.h" 17 #include "webkit/appcache/appcache_entry.h"
15 #include "webkit/appcache/appcache_group.h" 18 #include "webkit/appcache/appcache_group.h"
16 #include "webkit/appcache/appcache_service.h" 19 #include "webkit/appcache/appcache_service.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 db_thread->message_loop_proxy(), 134 db_thread->message_loop_proxy(),
132 NULL), 135 NULL),
133 async_(false) {} 136 async_(false) {}
134 137
135 virtual void GetUsageAndQuota( 138 virtual void GetUsageAndQuota(
136 const GURL& origin, quota::StorageType type, 139 const GURL& origin, quota::StorageType type,
137 const GetUsageAndQuotaCallback& callback) OVERRIDE { 140 const GetUsageAndQuotaCallback& callback) OVERRIDE {
138 EXPECT_EQ(kOrigin, origin); 141 EXPECT_EQ(kOrigin, origin);
139 EXPECT_EQ(quota::kStorageTypeTemporary, type); 142 EXPECT_EQ(quota::kStorageTypeTemporary, type);
140 if (async_) { 143 if (async_) {
141 MessageLoop::current()->PostTask(FROM_HERE, 144 MessageLoop::current()->PostTask(
142 NewRunnableMethod(this, &MockQuotaManager::CallCallback, 145 FROM_HERE, base::Bind(&MockQuotaManager::CallCallback,
143 callback)); 146 base::Unretained(this), callback));
144 return; 147 return;
145 } 148 }
146 CallCallback(callback); 149 CallCallback(callback);
147 } 150 }
148 151
149 void CallCallback(const GetUsageAndQuotaCallback& callback) { 152 void CallCallback(const GetUsageAndQuotaCallback& callback) {
150 callback.Run(quota::kQuotaStatusOk, 0, kMockQuota); 153 callback.Run(quota::kQuotaStatusOk, 0, kMockQuota);
151 } 154 }
152 155
153 bool async_; 156 bool async_;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 210
208 virtual void Run() OVERRIDE { 211 virtual void Run() OVERRIDE {
209 test_->SetUpTest(); 212 test_->SetUpTest();
210 213
211 // Ensure InitTask execution prior to conducting a test. 214 // Ensure InitTask execution prior to conducting a test.
212 test_->FlushDbThreadTasks(); 215 test_->FlushDbThreadTasks();
213 216
214 // We also have to wait for InitTask completion call to be performed 217 // We also have to wait for InitTask completion call to be performed
215 // on the IO thread prior to running the test. Its guaranteed to be 218 // on the IO thread prior to running the test. Its guaranteed to be
216 // queued by this time. 219 // queued by this time.
217 MessageLoop::current()->PostTask(FROM_HERE, 220 MessageLoop::current()->PostTask(
218 NewRunnableFunction(&RunMethod, test_, method_)); 221 FROM_HERE, base::Bind(&RunMethod, test_, method_));
219 } 222 }
220 223
221 static void RunMethod(AppCacheStorageImplTest* test, Method method) { 224 static void RunMethod(AppCacheStorageImplTest* test, Method method) {
222 (test->*method)(); 225 (test->*method)();
223 } 226 }
224 227
225 private: 228 private:
226 AppCacheStorageImplTest* test_; 229 AppCacheStorageImplTest* test_;
227 Method method_; 230 Method method_;
228 }; 231 };
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 mock_quota_manager_proxy_ = NULL; 276 mock_quota_manager_proxy_ = NULL;
274 delegate_.reset(); 277 delegate_.reset();
275 service_.reset(); 278 service_.reset();
276 FlushDbThreadTasks(); 279 FlushDbThreadTasks();
277 } 280 }
278 281
279 void TestFinished() { 282 void TestFinished() {
280 // We unwind the stack prior to finishing up to let stack 283 // We unwind the stack prior to finishing up to let stack
281 // based objects get deleted. 284 // based objects get deleted.
282 DCHECK(MessageLoop::current() == io_thread->message_loop()); 285 DCHECK(MessageLoop::current() == io_thread->message_loop());
283 MessageLoop::current()->PostTask(FROM_HERE, 286 MessageLoop::current()->PostTask(
284 NewRunnableMethod(this, &AppCacheStorageImplTest::TestFinishedUnwound)); 287 FROM_HERE, base::Bind(&AppCacheStorageImplTest::TestFinishedUnwound,
288 base::Unretained(this)));
285 } 289 }
286 290
287 void TestFinishedUnwound() { 291 void TestFinishedUnwound() {
288 TearDownTest(); 292 TearDownTest();
289 test_finished_event_->Signal(); 293 test_finished_event_->Signal();
290 } 294 }
291 295
292 void PushNextTask(Task* task) { 296 void PushNextTask(const base::Closure& task) {
293 task_stack_.push(task); 297 task_stack_.push(task);
294 } 298 }
295 299
296 void ScheduleNextTask() { 300 void ScheduleNextTask() {
297 DCHECK(MessageLoop::current() == io_thread->message_loop()); 301 DCHECK(MessageLoop::current() == io_thread->message_loop());
298 if (task_stack_.empty()) { 302 if (task_stack_.empty()) {
299 return; 303 return;
300 } 304 }
301 MessageLoop::current()->PostTask(FROM_HERE, task_stack_.top()); 305 MessageLoop::current()->PostTask(FROM_HERE, task_stack_.top());
302 task_stack_.pop(); 306 task_stack_.pop();
303 } 307 }
304 308
305 static void SignalEvent(base::WaitableEvent* event) { 309 static void SignalEvent(base::WaitableEvent* event) {
306 event->Signal(); 310 event->Signal();
307 } 311 }
308 312
309 void FlushDbThreadTasks() { 313 void FlushDbThreadTasks() {
310 // We pump a task thru the db thread to ensure any tasks previously 314 // We pump a task thru the db thread to ensure any tasks previously
311 // scheduled on that thread have been performed prior to return. 315 // scheduled on that thread have been performed prior to return.
312 base::WaitableEvent event(false, false); 316 base::WaitableEvent event(false, false);
313 db_thread->message_loop()->PostTask(FROM_HERE, 317 db_thread->message_loop()->PostTask(
314 NewRunnableFunction(&AppCacheStorageImplTest::SignalEvent, 318 FROM_HERE, base::Bind(&AppCacheStorageImplTest::SignalEvent, &event));
315 &event));
316 event.Wait(); 319 event.Wait();
317 } 320 }
318 321
319 // LoadCache_Miss ---------------------------------------------------- 322 // LoadCache_Miss ----------------------------------------------------
320 323
321 void LoadCache_Miss() { 324 void LoadCache_Miss() {
322 // Attempt to load a cache that doesn't exist. Should 325 // Attempt to load a cache that doesn't exist. Should
323 // complete asyncly. 326 // complete asynchronously.
324 PushNextTask(NewRunnableMethod( 327 PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_LoadCache_Miss,
325 this, &AppCacheStorageImplTest::Verify_LoadCache_Miss)); 328 base::Unretained(this)));
326 329
327 storage()->LoadCache(111, delegate()); 330 storage()->LoadCache(111, delegate());
328 EXPECT_NE(111, delegate()->loaded_cache_id_); 331 EXPECT_NE(111, delegate()->loaded_cache_id_);
329 } 332 }
330 333
331 void Verify_LoadCache_Miss() { 334 void Verify_LoadCache_Miss() {
332 EXPECT_EQ(111, delegate()->loaded_cache_id_); 335 EXPECT_EQ(111, delegate()->loaded_cache_id_);
333 EXPECT_FALSE(delegate()->loaded_cache_); 336 EXPECT_FALSE(delegate()->loaded_cache_);
334 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_accessed_count_); 337 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_accessed_count_);
335 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_); 338 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_);
(...skipping 29 matching lines...) Expand all
365 368
366 // Since the origin has no groups, the storage class will respond 369 // Since the origin has no groups, the storage class will respond
367 // syncly. 370 // syncly.
368 storage()->LoadOrCreateGroup(kManifestUrl, delegate()); 371 storage()->LoadOrCreateGroup(kManifestUrl, delegate());
369 Verify_CreateGroup(); 372 Verify_CreateGroup();
370 } 373 }
371 374
372 void CreateGroupInPopulatedOrigin() { 375 void CreateGroupInPopulatedOrigin() {
373 // Attempt to load a group that doesn't exist, one should 376 // Attempt to load a group that doesn't exist, one should
374 // be created for us, but not stored. 377 // be created for us, but not stored.
375 PushNextTask(NewRunnableMethod( 378 PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_CreateGroup,
376 this, &AppCacheStorageImplTest::Verify_CreateGroup)); 379 base::Unretained(this)));
377 380
378 // Since the origin has groups, storage class will have to 381 // Since the origin has groups, storage class will have to
379 // consult the database and completion will be async. 382 // consult the database and completion will be async.
380 storage()->usage_map_[kOrigin] = kDefaultEntrySize; 383 storage()->usage_map_[kOrigin] = kDefaultEntrySize;
381 384
382 storage()->LoadOrCreateGroup(kManifestUrl, delegate()); 385 storage()->LoadOrCreateGroup(kManifestUrl, delegate());
383 EXPECT_FALSE(delegate()->loaded_group_.get()); 386 EXPECT_FALSE(delegate()->loaded_group_.get());
384 } 387 }
385 388
386 void Verify_CreateGroup() { 389 void Verify_CreateGroup() {
(...skipping 11 matching lines...) Expand all
398 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_); 401 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_);
399 402
400 TestFinished(); 403 TestFinished();
401 } 404 }
402 405
403 // LoadGroupAndCache_FarHit -------------------------------------- 406 // LoadGroupAndCache_FarHit --------------------------------------
404 407
405 void LoadGroupAndCache_FarHit() { 408 void LoadGroupAndCache_FarHit() {
406 // Attempt to load a cache that is not currently in use 409 // Attempt to load a cache that is not currently in use
407 // and does require loading from disk. This 410 // and does require loading from disk. This
408 // load should complete asyncly. 411 // load should complete asynchronously.
409 PushNextTask(NewRunnableMethod( 412 PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_LoadCache_Far_Hit,
410 this, &AppCacheStorageImplTest::Verify_LoadCache_Far_Hit)); 413 base::Unretained(this)));
411 414
412 // Setup some preconditions. Create a group and newest cache that 415 // Setup some preconditions. Create a group and newest cache that
413 // appear to be "stored" and "not currently in use". 416 // appear to be "stored" and "not currently in use".
414 MakeCacheAndGroup(kManifestUrl, 1, 1, true); 417 MakeCacheAndGroup(kManifestUrl, 1, 1, true);
415 group_ = NULL; 418 group_ = NULL;
416 cache_ = NULL; 419 cache_ = NULL;
417 420
418 // Conduct the cache load test, completes async 421 // Conduct the cache load test, completes async
419 storage()->LoadCache(1, delegate()); 422 storage()->LoadCache(1, delegate());
420 } 423 }
421 424
422 void Verify_LoadCache_Far_Hit() { 425 void Verify_LoadCache_Far_Hit() {
423 EXPECT_TRUE(delegate()->loaded_cache_); 426 EXPECT_TRUE(delegate()->loaded_cache_);
424 EXPECT_TRUE(delegate()->loaded_cache_->HasOneRef()); 427 EXPECT_TRUE(delegate()->loaded_cache_->HasOneRef());
425 EXPECT_EQ(1, delegate()->loaded_cache_id_); 428 EXPECT_EQ(1, delegate()->loaded_cache_id_);
426 429
427 // The group should also have been loaded. 430 // The group should also have been loaded.
428 EXPECT_TRUE(delegate()->loaded_cache_->owning_group()); 431 EXPECT_TRUE(delegate()->loaded_cache_->owning_group());
429 EXPECT_TRUE(delegate()->loaded_cache_->owning_group()->HasOneRef()); 432 EXPECT_TRUE(delegate()->loaded_cache_->owning_group()->HasOneRef());
430 EXPECT_EQ(1, delegate()->loaded_cache_->owning_group()->group_id()); 433 EXPECT_EQ(1, delegate()->loaded_cache_->owning_group()->group_id());
431 434
432 EXPECT_EQ(1, mock_quota_manager_proxy_->notify_storage_accessed_count_); 435 EXPECT_EQ(1, mock_quota_manager_proxy_->notify_storage_accessed_count_);
433 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_); 436 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_);
434 437
435 // Drop things from the working set. 438 // Drop things from the working set.
436 delegate()->loaded_cache_ = NULL; 439 delegate()->loaded_cache_ = NULL;
437 EXPECT_FALSE(delegate()->loaded_group_); 440 EXPECT_FALSE(delegate()->loaded_group_);
438 441
439 // Conduct the group load test, also complete asyncly. 442 // Conduct the group load test, also complete asynchronously.
440 PushNextTask(NewRunnableMethod( 443 PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_LoadGroup_Far_Hit,
441 this, &AppCacheStorageImplTest::Verify_LoadGroup_Far_Hit)); 444 base::Unretained(this)));
442 445
443 storage()->LoadOrCreateGroup(kManifestUrl, delegate()); 446 storage()->LoadOrCreateGroup(kManifestUrl, delegate());
444 } 447 }
445 448
446 void Verify_LoadGroup_Far_Hit() { 449 void Verify_LoadGroup_Far_Hit() {
447 EXPECT_TRUE(delegate()->loaded_group_); 450 EXPECT_TRUE(delegate()->loaded_group_);
448 EXPECT_EQ(kManifestUrl, delegate()->loaded_manifest_url_); 451 EXPECT_EQ(kManifestUrl, delegate()->loaded_manifest_url_);
449 EXPECT_TRUE(delegate()->loaded_group_->newest_complete_cache()); 452 EXPECT_TRUE(delegate()->loaded_group_->newest_complete_cache());
450 delegate()->loaded_groups_newest_cache_ = NULL; 453 delegate()->loaded_groups_newest_cache_ = NULL;
451 EXPECT_TRUE(delegate()->loaded_group_->HasOneRef()); 454 EXPECT_TRUE(delegate()->loaded_group_->HasOneRef());
452 EXPECT_EQ(2, mock_quota_manager_proxy_->notify_storage_accessed_count_); 455 EXPECT_EQ(2, mock_quota_manager_proxy_->notify_storage_accessed_count_);
453 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_); 456 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_);
454 TestFinished(); 457 TestFinished();
455 } 458 }
456 459
457 // StoreNewGroup -------------------------------------- 460 // StoreNewGroup --------------------------------------
458 461
459 void StoreNewGroup() { 462 void StoreNewGroup() {
460 // Store a group and its newest cache. Should complete asyncly. 463 // Store a group and its newest cache. Should complete asynchronously.
461 PushNextTask(NewRunnableMethod( 464 PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_StoreNewGroup,
462 this, &AppCacheStorageImplTest::Verify_StoreNewGroup)); 465 base::Unretained(this)));
463 466
464 // Setup some preconditions. Create a group and newest cache that 467 // Setup some preconditions. Create a group and newest cache that
465 // appear to be "unstored". 468 // appear to be "unstored".
466 group_ = new AppCacheGroup( 469 group_ = new AppCacheGroup(
467 service(), kManifestUrl, storage()->NewGroupId()); 470 service(), kManifestUrl, storage()->NewGroupId());
468 cache_ = new AppCache(service(), storage()->NewCacheId()); 471 cache_ = new AppCache(service(), storage()->NewCacheId());
469 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, 1, 472 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, 1,
470 kDefaultEntrySize)); 473 kDefaultEntrySize));
471 // Hold a ref to the cache simulate the UpdateJob holding that ref, 474 // Hold a ref to the cache simulate the UpdateJob holding that ref,
472 // and hold a ref to the group to simulate the CacheHost holding that ref. 475 // and hold a ref to the group to simulate the CacheHost holding that ref.
473 476
474 // Have the quota manager retrun asyncly for this test. 477 // Have the quota manager retrun asynchronously for this test.
475 mock_quota_manager_proxy_->mock_manager_->async_ = true; 478 mock_quota_manager_proxy_->mock_manager_->async_ = true;
476 479
477 // Conduct the store test. 480 // Conduct the store test.
478 storage()->StoreGroupAndNewestCache(group_, cache_, delegate()); 481 storage()->StoreGroupAndNewestCache(group_, cache_, delegate());
479 EXPECT_FALSE(delegate()->stored_group_success_); 482 EXPECT_FALSE(delegate()->stored_group_success_);
480 } 483 }
481 484
482 void Verify_StoreNewGroup() { 485 void Verify_StoreNewGroup() {
483 EXPECT_TRUE(delegate()->stored_group_success_); 486 EXPECT_TRUE(delegate()->stored_group_success_);
484 EXPECT_EQ(group_.get(), delegate()->stored_group_.get()); 487 EXPECT_EQ(group_.get(), delegate()->stored_group_.get());
(...skipping 11 matching lines...) Expand all
496 EXPECT_EQ(1, mock_quota_manager_proxy_->notify_storage_modified_count_); 499 EXPECT_EQ(1, mock_quota_manager_proxy_->notify_storage_modified_count_);
497 EXPECT_EQ(kOrigin, mock_quota_manager_proxy_->last_origin_); 500 EXPECT_EQ(kOrigin, mock_quota_manager_proxy_->last_origin_);
498 EXPECT_EQ(kDefaultEntrySize, mock_quota_manager_proxy_->last_delta_); 501 EXPECT_EQ(kDefaultEntrySize, mock_quota_manager_proxy_->last_delta_);
499 502
500 TestFinished(); 503 TestFinished();
501 } 504 }
502 505
503 // StoreExistingGroup -------------------------------------- 506 // StoreExistingGroup --------------------------------------
504 507
505 void StoreExistingGroup() { 508 void StoreExistingGroup() {
506 // Store a group and its newest cache. Should complete asyncly. 509 // Store a group and its newest cache. Should complete asynchronously.
507 PushNextTask(NewRunnableMethod( 510 PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_StoreExistingGroup,
508 this, &AppCacheStorageImplTest::Verify_StoreExistingGroup)); 511 base::Unretained(this)));
509 512
510 // Setup some preconditions. Create a group and old complete cache 513 // Setup some preconditions. Create a group and old complete cache
511 // that appear to be "stored" 514 // that appear to be "stored"
512 MakeCacheAndGroup(kManifestUrl, 1, 1, true); 515 MakeCacheAndGroup(kManifestUrl, 1, 1, true);
513 EXPECT_EQ(kDefaultEntrySize, storage()->usage_map_[kOrigin]); 516 EXPECT_EQ(kDefaultEntrySize, storage()->usage_map_[kOrigin]);
514 517
515 // And a newest unstored complete cache. 518 // And a newest unstored complete cache.
516 cache2_ = new AppCache(service(), 2); 519 cache2_ = new AppCache(service(), 2);
517 cache2_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::MASTER, 1, 520 cache2_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::MASTER, 1,
518 kDefaultEntrySize + 100)); 521 kDefaultEntrySize + 100));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 // Setup some preconditions. Create a group and old complete cache 559 // Setup some preconditions. Create a group and old complete cache
557 // that appear to be "stored" 560 // that appear to be "stored"
558 MakeCacheAndGroup(kManifestUrl, 1, 1, true); 561 MakeCacheAndGroup(kManifestUrl, 1, 1, true);
559 EXPECT_EQ(kDefaultEntrySize, storage()->usage_map_[kOrigin]); 562 EXPECT_EQ(kDefaultEntrySize, storage()->usage_map_[kOrigin]);
560 563
561 // Change the cache. 564 // Change the cache.
562 base::Time now = base::Time::Now(); 565 base::Time now = base::Time::Now();
563 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::MASTER, 1, 100)); 566 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::MASTER, 1, 100));
564 cache_->set_update_time(now); 567 cache_->set_update_time(now);
565 568
566 PushNextTask(NewRunnableMethod( 569 PushNextTask(base::Bind(
567 this, &AppCacheStorageImplTest::Verify_StoreExistingGroupExistingCache, 570 &AppCacheStorageImplTest::Verify_StoreExistingGroupExistingCache,
568 now)); 571 base::Unretained(this), now));
569 572
570 // Conduct the test. 573 // Conduct the test.
571 EXPECT_EQ(cache_, group_->newest_complete_cache()); 574 EXPECT_EQ(cache_, group_->newest_complete_cache());
572 storage()->StoreGroupAndNewestCache(group_, cache_, delegate()); 575 storage()->StoreGroupAndNewestCache(group_, cache_, delegate());
573 EXPECT_FALSE(delegate()->stored_group_success_); 576 EXPECT_FALSE(delegate()->stored_group_success_);
574 } 577 }
575 578
576 void Verify_StoreExistingGroupExistingCache( 579 void Verify_StoreExistingGroupExistingCache(
577 base::Time expected_update_time) { 580 base::Time expected_update_time) {
578 EXPECT_TRUE(delegate()->stored_group_success_); 581 EXPECT_TRUE(delegate()->stored_group_success_);
(...skipping 23 matching lines...) Expand all
602 EXPECT_EQ(1, mock_quota_manager_proxy_->notify_storage_modified_count_); 605 EXPECT_EQ(1, mock_quota_manager_proxy_->notify_storage_modified_count_);
603 EXPECT_EQ(kOrigin, mock_quota_manager_proxy_->last_origin_); 606 EXPECT_EQ(kOrigin, mock_quota_manager_proxy_->last_origin_);
604 EXPECT_EQ(100, mock_quota_manager_proxy_->last_delta_); 607 EXPECT_EQ(100, mock_quota_manager_proxy_->last_delta_);
605 608
606 TestFinished(); 609 TestFinished();
607 } 610 }
608 611
609 // FailStoreGroup -------------------------------------- 612 // FailStoreGroup --------------------------------------
610 613
611 void FailStoreGroup() { 614 void FailStoreGroup() {
612 // Store a group and its newest cache. Should complete asyncly. 615 // Store a group and its newest cache. Should complete asynchronously.
613 PushNextTask(NewRunnableMethod( 616 PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_FailStoreGroup,
614 this, &AppCacheStorageImplTest::Verify_FailStoreGroup)); 617 base::Unretained(this)));
615 618
616 // Setup some preconditions. Create a group and newest cache that 619 // Setup some preconditions. Create a group and newest cache that
617 // appear to be "unstored" and big enough to exceed the 5M limit. 620 // appear to be "unstored" and big enough to exceed the 5M limit.
618 const int64 kTooBig = 10 * 1024 * 1024; // 10M 621 const int64 kTooBig = 10 * 1024 * 1024; // 10M
619 group_ = new AppCacheGroup( 622 group_ = new AppCacheGroup(
620 service(), kManifestUrl, storage()->NewGroupId()); 623 service(), kManifestUrl, storage()->NewGroupId());
621 cache_ = new AppCache(service(), storage()->NewCacheId()); 624 cache_ = new AppCache(service(), storage()->NewCacheId());
622 cache_->AddEntry(kManifestUrl, 625 cache_->AddEntry(kManifestUrl,
623 AppCacheEntry(AppCacheEntry::MANIFEST, 1, kTooBig)); 626 AppCacheEntry(AppCacheEntry::MANIFEST, 1, kTooBig));
624 // Hold a ref to the cache simulate the UpdateJob holding that ref, 627 // Hold a ref to the cache simulate the UpdateJob holding that ref,
(...skipping 16 matching lines...) Expand all
641 644
642 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_accessed_count_); 645 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_accessed_count_);
643 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_); 646 EXPECT_EQ(0, mock_quota_manager_proxy_->notify_storage_modified_count_);
644 647
645 TestFinished(); 648 TestFinished();
646 } 649 }
647 650
648 // MakeGroupObsolete ------------------------------- 651 // MakeGroupObsolete -------------------------------
649 652
650 void MakeGroupObsolete() { 653 void MakeGroupObsolete() {
651 // Make a group obsolete, should complete asyncly. 654 // Make a group obsolete, should complete asynchronously.
652 PushNextTask(NewRunnableMethod( 655 PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_MakeGroupObsolete,
653 this, &AppCacheStorageImplTest::Verify_MakeGroupObsolete)); 656 base::Unretained(this)));
654 657
655 // Setup some preconditions. Create a group and newest cache that 658 // Setup some preconditions. Create a group and newest cache that
656 // appears to be "stored" and "currently in use". 659 // appears to be "stored" and "currently in use".
657 MakeCacheAndGroup(kManifestUrl, 1, 1, true); 660 MakeCacheAndGroup(kManifestUrl, 1, 1, true);
658 EXPECT_EQ(kDefaultEntrySize, storage()->usage_map_[kOrigin]); 661 EXPECT_EQ(kDefaultEntrySize, storage()->usage_map_[kOrigin]);
659 662
660 // Also insert some related records. 663 // Also insert some related records.
661 AppCacheDatabase::EntryRecord entry_record; 664 AppCacheDatabase::EntryRecord entry_record;
662 entry_record.cache_id = 1; 665 entry_record.cache_id = 1;
663 entry_record.flags = AppCacheEntry::FALLBACK; 666 entry_record.flags = AppCacheEntry::FALLBACK;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 EXPECT_FALSE(cache_->GetEntry(kEntryUrl)->IsForeign()); 734 EXPECT_FALSE(cache_->GetEntry(kEntryUrl)->IsForeign());
732 735
733 // Conduct the test. 736 // Conduct the test.
734 storage()->MarkEntryAsForeign(kEntryUrl, 1); 737 storage()->MarkEntryAsForeign(kEntryUrl, 1);
735 738
736 // The entry in the working set should have been updated syncly. 739 // The entry in the working set should have been updated syncly.
737 EXPECT_TRUE(cache_->GetEntry(kEntryUrl)->IsForeign()); 740 EXPECT_TRUE(cache_->GetEntry(kEntryUrl)->IsForeign());
738 EXPECT_TRUE(cache_->GetEntry(kEntryUrl)->IsExplicit()); 741 EXPECT_TRUE(cache_->GetEntry(kEntryUrl)->IsExplicit());
739 742
740 // And the entry in storage should also be updated, but that 743 // And the entry in storage should also be updated, but that
741 // happens asyncly on the db thread. 744 // happens asynchronously on the db thread.
742 FlushDbThreadTasks(); 745 FlushDbThreadTasks();
743 AppCacheDatabase::EntryRecord entry_record2; 746 AppCacheDatabase::EntryRecord entry_record2;
744 EXPECT_TRUE(database()->FindEntry(1, kEntryUrl, &entry_record2)); 747 EXPECT_TRUE(database()->FindEntry(1, kEntryUrl, &entry_record2));
745 EXPECT_EQ(AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN, 748 EXPECT_EQ(AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN,
746 entry_record2.flags); 749 entry_record2.flags);
747 TestFinished(); 750 TestFinished();
748 } 751 }
749 752
750 // MarkEntryAsForeignWithLoadInProgress ------------------------------- 753 // MarkEntryAsForeignWithLoadInProgress -------------------------------
751 754
752 void MarkEntryAsForeignWithLoadInProgress() { 755 void MarkEntryAsForeignWithLoadInProgress() {
753 PushNextTask(NewRunnableMethod(this, 756 PushNextTask(base::Bind(
754 &AppCacheStorageImplTest::Verify_MarkEntryAsForeignWithLoadInProgress)); 757 &AppCacheStorageImplTest::Verify_MarkEntryAsForeignWithLoadInProgress,
758 base::Unretained(this)));
755 759
756 // Setup some preconditions. Create a cache with an entry 760 // Setup some preconditions. Create a cache with an entry
757 // in storage, but not in the working set. 761 // in storage, but not in the working set.
758 MakeCacheAndGroup(kManifestUrl, 1, 1, true); 762 MakeCacheAndGroup(kManifestUrl, 1, 1, true);
759 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT)); 763 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT));
760 AppCacheDatabase::EntryRecord entry_record; 764 AppCacheDatabase::EntryRecord entry_record;
761 entry_record.cache_id = 1; 765 entry_record.cache_id = 1;
762 entry_record.url = kEntryUrl; 766 entry_record.url = kEntryUrl;
763 entry_record.flags = AppCacheEntry::EXPLICIT; 767 entry_record.flags = AppCacheEntry::EXPLICIT;
764 entry_record.response_id = 0; 768 entry_record.response_id = 0;
(...skipping 22 matching lines...) Expand all
787 AppCacheDatabase::EntryRecord entry_record; 791 AppCacheDatabase::EntryRecord entry_record;
788 EXPECT_TRUE(database()->FindEntry(1, kEntryUrl, &entry_record)); 792 EXPECT_TRUE(database()->FindEntry(1, kEntryUrl, &entry_record));
789 EXPECT_EQ(AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN, 793 EXPECT_EQ(AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN,
790 entry_record.flags); 794 entry_record.flags);
791 TestFinished(); 795 TestFinished();
792 } 796 }
793 797
794 // FindNoMainResponse ------------------------------- 798 // FindNoMainResponse -------------------------------
795 799
796 void FindNoMainResponse() { 800 void FindNoMainResponse() {
797 PushNextTask(NewRunnableMethod( 801 PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_FindNoMainResponse,
798 this, &AppCacheStorageImplTest::Verify_FindNoMainResponse)); 802 base::Unretained(this)));
799 803
800 // Conduct the test. 804 // Conduct the test.
801 storage()->FindResponseForMainRequest(kEntryUrl, GURL(), delegate()); 805 storage()->FindResponseForMainRequest(kEntryUrl, GURL(), delegate());
802 EXPECT_NE(kEntryUrl, delegate()->found_url_); 806 EXPECT_NE(kEntryUrl, delegate()->found_url_);
803 } 807 }
804 808
805 void Verify_FindNoMainResponse() { 809 void Verify_FindNoMainResponse() {
806 EXPECT_EQ(kEntryUrl, delegate()->found_url_); 810 EXPECT_EQ(kEntryUrl, delegate()->found_url_);
807 EXPECT_TRUE(delegate()->found_manifest_url_.is_empty()); 811 EXPECT_TRUE(delegate()->found_manifest_url_.is_empty());
808 EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_); 812 EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_);
809 EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id()); 813 EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id());
810 EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id()); 814 EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id());
811 EXPECT_TRUE(delegate()->found_fallback_url_.is_empty()); 815 EXPECT_TRUE(delegate()->found_fallback_url_.is_empty());
812 EXPECT_EQ(0, delegate()->found_entry_.types()); 816 EXPECT_EQ(0, delegate()->found_entry_.types());
813 EXPECT_EQ(0, delegate()->found_fallback_entry_.types()); 817 EXPECT_EQ(0, delegate()->found_fallback_entry_.types());
814 TestFinished(); 818 TestFinished();
815 } 819 }
816 820
817 // BasicFindMainResponse ------------------------------- 821 // BasicFindMainResponse -------------------------------
818 822
819 void BasicFindMainResponseInDatabase() { 823 void BasicFindMainResponseInDatabase() {
820 BasicFindMainResponse(true); 824 BasicFindMainResponse(true);
821 } 825 }
822 826
823 void BasicFindMainResponseInWorkingSet() { 827 void BasicFindMainResponseInWorkingSet() {
824 BasicFindMainResponse(false); 828 BasicFindMainResponse(false);
825 } 829 }
826 830
827 void BasicFindMainResponse(bool drop_from_working_set) { 831 void BasicFindMainResponse(bool drop_from_working_set) {
828 PushNextTask(NewRunnableMethod( 832 PushNextTask(base::Bind(
829 this, &AppCacheStorageImplTest::Verify_BasicFindMainResponse)); 833 &AppCacheStorageImplTest::Verify_BasicFindMainResponse,
834 base::Unretained(this)));
830 835
831 // Setup some preconditions. Create a complete cache with an entry 836 // Setup some preconditions. Create a complete cache with an entry
832 // in storage. 837 // in storage.
833 MakeCacheAndGroup(kManifestUrl, 2, 1, true); 838 MakeCacheAndGroup(kManifestUrl, 2, 1, true);
834 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, 1)); 839 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, 1));
835 AppCacheDatabase::EntryRecord entry_record; 840 AppCacheDatabase::EntryRecord entry_record;
836 entry_record.cache_id = 1; 841 entry_record.cache_id = 1;
837 entry_record.url = kEntryUrl; 842 entry_record.url = kEntryUrl;
838 entry_record.flags = AppCacheEntry::EXPLICIT; 843 entry_record.flags = AppCacheEntry::EXPLICIT;
839 entry_record.response_id = 1; 844 entry_record.response_id = 1;
(...skipping 27 matching lines...) Expand all
867 872
868 void BasicFindMainFallbackResponseInDatabase() { 873 void BasicFindMainFallbackResponseInDatabase() {
869 BasicFindMainFallbackResponse(true); 874 BasicFindMainFallbackResponse(true);
870 } 875 }
871 876
872 void BasicFindMainFallbackResponseInWorkingSet() { 877 void BasicFindMainFallbackResponseInWorkingSet() {
873 BasicFindMainFallbackResponse(false); 878 BasicFindMainFallbackResponse(false);
874 } 879 }
875 880
876 void BasicFindMainFallbackResponse(bool drop_from_working_set) { 881 void BasicFindMainFallbackResponse(bool drop_from_working_set) {
877 PushNextTask(NewRunnableMethod( 882 PushNextTask(base::Bind(
878 this, &AppCacheStorageImplTest::Verify_BasicFindMainFallbackResponse)); 883 &AppCacheStorageImplTest::Verify_BasicFindMainFallbackResponse,
884 base::Unretained(this)));
879 885
880 // Setup some preconditions. Create a complete cache with a 886 // Setup some preconditions. Create a complete cache with a
881 // fallback namespace and entry. 887 // fallback namespace and entry.
882 MakeCacheAndGroup(kManifestUrl, 2, 1, true); 888 MakeCacheAndGroup(kManifestUrl, 2, 1, true);
883 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::FALLBACK, 1)); 889 cache_->AddEntry(kEntryUrl, AppCacheEntry(AppCacheEntry::FALLBACK, 1));
884 cache_->AddEntry(kEntryUrl2, AppCacheEntry(AppCacheEntry::FALLBACK, 2)); 890 cache_->AddEntry(kEntryUrl2, AppCacheEntry(AppCacheEntry::FALLBACK, 2));
885 cache_->fallback_namespaces_.push_back( 891 cache_->fallback_namespaces_.push_back(
886 FallbackNamespace(kFallbackNamespace2, kEntryUrl2)); 892 FallbackNamespace(kFallbackNamespace2, kEntryUrl2));
887 cache_->fallback_namespaces_.push_back( 893 cache_->fallback_namespaces_.push_back(
888 FallbackNamespace(kFallbackNamespace, kEntryUrl)); 894 FallbackNamespace(kFallbackNamespace, kEntryUrl));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 EXPECT_FALSE(delegate()->found_entry_.has_response_id()); 931 EXPECT_FALSE(delegate()->found_entry_.has_response_id());
926 EXPECT_EQ(2, delegate()->found_fallback_entry_.response_id()); 932 EXPECT_EQ(2, delegate()->found_fallback_entry_.response_id());
927 EXPECT_EQ(kEntryUrl2, delegate()->found_fallback_url_); 933 EXPECT_EQ(kEntryUrl2, delegate()->found_fallback_url_);
928 EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback()); 934 EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback());
929 TestFinished(); 935 TestFinished();
930 } 936 }
931 937
932 // FindMainResponseWithMultipleHits ------------------------------- 938 // FindMainResponseWithMultipleHits -------------------------------
933 939
934 void FindMainResponseWithMultipleHits() { 940 void FindMainResponseWithMultipleHits() {
935 PushNextTask(NewRunnableMethod(this, 941 PushNextTask(base::Bind(
936 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits)); 942 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits,
943 base::Unretained(this)));
937 944
938 // Setup some preconditions, create a few caches with an identical set 945 // Setup some preconditions, create a few caches with an identical set
939 // of entries and fallback namespaces. Only the last one remains in 946 // of entries and fallback namespaces. Only the last one remains in
940 // the working set to simulate appearing as "in use". 947 // the working set to simulate appearing as "in use".
941 MakeMultipleHitCacheAndGroup(kManifestUrl, 1); 948 MakeMultipleHitCacheAndGroup(kManifestUrl, 1);
942 MakeMultipleHitCacheAndGroup(kManifestUrl2, 2); 949 MakeMultipleHitCacheAndGroup(kManifestUrl2, 2);
943 MakeMultipleHitCacheAndGroup(kManifestUrl3, 3); 950 MakeMultipleHitCacheAndGroup(kManifestUrl3, 3);
944 951
945 // Conduct the test, we should find the response from the last cache 952 // Conduct the test, we should find the response from the last cache
946 // since it's "in use". 953 // since it's "in use".
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 EXPECT_EQ(kEntryUrl, delegate()->found_url_); 1003 EXPECT_EQ(kEntryUrl, delegate()->found_url_);
997 EXPECT_EQ(kManifestUrl3, delegate()->found_manifest_url_); 1004 EXPECT_EQ(kManifestUrl3, delegate()->found_manifest_url_);
998 EXPECT_EQ(3, delegate()->found_cache_id_); 1005 EXPECT_EQ(3, delegate()->found_cache_id_);
999 EXPECT_EQ(3, delegate()->found_group_id_); 1006 EXPECT_EQ(3, delegate()->found_group_id_);
1000 EXPECT_EQ(3, delegate()->found_entry_.response_id()); 1007 EXPECT_EQ(3, delegate()->found_entry_.response_id());
1001 EXPECT_TRUE(delegate()->found_entry_.IsExplicit()); 1008 EXPECT_TRUE(delegate()->found_entry_.IsExplicit());
1002 EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id()); 1009 EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id());
1003 1010
1004 // Conduct another test perferring kManifestUrl 1011 // Conduct another test perferring kManifestUrl
1005 delegate_.reset(new MockStorageDelegate(this)); 1012 delegate_.reset(new MockStorageDelegate(this));
1006 PushNextTask(NewRunnableMethod(this, 1013 PushNextTask(base::Bind(
1007 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits2)); 1014 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits2,
1015 base::Unretained(this)));
1008 storage()->FindResponseForMainRequest(kEntryUrl, kManifestUrl, delegate()); 1016 storage()->FindResponseForMainRequest(kEntryUrl, kManifestUrl, delegate());
1009 EXPECT_NE(kEntryUrl, delegate()->found_url_); 1017 EXPECT_NE(kEntryUrl, delegate()->found_url_);
1010 } 1018 }
1011 1019
1012 void Verify_FindMainResponseWithMultipleHits2() { 1020 void Verify_FindMainResponseWithMultipleHits2() {
1013 EXPECT_EQ(kEntryUrl, delegate()->found_url_); 1021 EXPECT_EQ(kEntryUrl, delegate()->found_url_);
1014 EXPECT_EQ(kManifestUrl, delegate()->found_manifest_url_); 1022 EXPECT_EQ(kManifestUrl, delegate()->found_manifest_url_);
1015 EXPECT_EQ(1, delegate()->found_cache_id_); 1023 EXPECT_EQ(1, delegate()->found_cache_id_);
1016 EXPECT_EQ(1, delegate()->found_group_id_); 1024 EXPECT_EQ(1, delegate()->found_group_id_);
1017 EXPECT_EQ(1, delegate()->found_entry_.response_id()); 1025 EXPECT_EQ(1, delegate()->found_entry_.response_id());
1018 EXPECT_TRUE(delegate()->found_entry_.IsExplicit()); 1026 EXPECT_TRUE(delegate()->found_entry_.IsExplicit());
1019 EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id()); 1027 EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id());
1020 1028
1021 // Conduct the another test perferring kManifestUrl2 1029 // Conduct the another test perferring kManifestUrl2
1022 delegate_.reset(new MockStorageDelegate(this)); 1030 delegate_.reset(new MockStorageDelegate(this));
1023 PushNextTask(NewRunnableMethod(this, 1031 PushNextTask(base::Bind(
1024 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits3)); 1032 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits3,
1033 base::Unretained(this)));
1025 storage()->FindResponseForMainRequest(kEntryUrl, kManifestUrl2, delegate()); 1034 storage()->FindResponseForMainRequest(kEntryUrl, kManifestUrl2, delegate());
1026 EXPECT_NE(kEntryUrl, delegate()->found_url_); 1035 EXPECT_NE(kEntryUrl, delegate()->found_url_);
1027 } 1036 }
1028 1037
1029 void Verify_FindMainResponseWithMultipleHits3() { 1038 void Verify_FindMainResponseWithMultipleHits3() {
1030 EXPECT_EQ(kEntryUrl, delegate()->found_url_); 1039 EXPECT_EQ(kEntryUrl, delegate()->found_url_);
1031 EXPECT_EQ(kManifestUrl2, delegate()->found_manifest_url_); 1040 EXPECT_EQ(kManifestUrl2, delegate()->found_manifest_url_);
1032 EXPECT_EQ(2, delegate()->found_cache_id_); 1041 EXPECT_EQ(2, delegate()->found_cache_id_);
1033 EXPECT_EQ(2, delegate()->found_group_id_); 1042 EXPECT_EQ(2, delegate()->found_group_id_);
1034 EXPECT_EQ(2, delegate()->found_entry_.response_id()); 1043 EXPECT_EQ(2, delegate()->found_entry_.response_id());
1035 EXPECT_TRUE(delegate()->found_entry_.IsExplicit()); 1044 EXPECT_TRUE(delegate()->found_entry_.IsExplicit());
1036 EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id()); 1045 EXPECT_FALSE(delegate()->found_fallback_entry_.has_response_id());
1037 1046
1038 // Conduct another test with no preferred manifest that hits the fallback. 1047 // Conduct another test with no preferred manifest that hits the fallback.
1039 delegate_.reset(new MockStorageDelegate(this)); 1048 delegate_.reset(new MockStorageDelegate(this));
1040 PushNextTask(NewRunnableMethod(this, 1049 PushNextTask(base::Bind(
1041 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits4)); 1050 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits4,
1051 base::Unretained(this)));
1042 storage()->FindResponseForMainRequest( 1052 storage()->FindResponseForMainRequest(
1043 kFallbackTestUrl, GURL(), delegate()); 1053 kFallbackTestUrl, GURL(), delegate());
1044 EXPECT_NE(kFallbackTestUrl, delegate()->found_url_); 1054 EXPECT_NE(kFallbackTestUrl, delegate()->found_url_);
1045 } 1055 }
1046 1056
1047 void Verify_FindMainResponseWithMultipleHits4() { 1057 void Verify_FindMainResponseWithMultipleHits4() {
1048 EXPECT_EQ(kFallbackTestUrl, delegate()->found_url_); 1058 EXPECT_EQ(kFallbackTestUrl, delegate()->found_url_);
1049 EXPECT_EQ(kManifestUrl3, delegate()->found_manifest_url_); 1059 EXPECT_EQ(kManifestUrl3, delegate()->found_manifest_url_);
1050 EXPECT_EQ(3, delegate()->found_cache_id_); 1060 EXPECT_EQ(3, delegate()->found_cache_id_);
1051 EXPECT_EQ(3, delegate()->found_group_id_); 1061 EXPECT_EQ(3, delegate()->found_group_id_);
1052 EXPECT_FALSE(delegate()->found_entry_.has_response_id()); 1062 EXPECT_FALSE(delegate()->found_entry_.has_response_id());
1053 EXPECT_EQ(3 + kFallbackEntryIdOffset, 1063 EXPECT_EQ(3 + kFallbackEntryIdOffset,
1054 delegate()->found_fallback_entry_.response_id()); 1064 delegate()->found_fallback_entry_.response_id());
1055 EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback()); 1065 EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback());
1056 EXPECT_EQ(kEntryUrl2, delegate()->found_fallback_url_); 1066 EXPECT_EQ(kEntryUrl2, delegate()->found_fallback_url_);
1057 1067
1058 // Conduct another test preferring kManifestUrl2 that hits the fallback. 1068 // Conduct another test preferring kManifestUrl2 that hits the fallback.
1059 delegate_.reset(new MockStorageDelegate(this)); 1069 delegate_.reset(new MockStorageDelegate(this));
1060 PushNextTask(NewRunnableMethod(this, 1070 PushNextTask(base::Bind(
1061 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits5)); 1071 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits5,
1072 base::Unretained(this)));
1062 storage()->FindResponseForMainRequest( 1073 storage()->FindResponseForMainRequest(
1063 kFallbackTestUrl, kManifestUrl2, delegate()); 1074 kFallbackTestUrl, kManifestUrl2, delegate());
1064 EXPECT_NE(kFallbackTestUrl, delegate()->found_url_); 1075 EXPECT_NE(kFallbackTestUrl, delegate()->found_url_);
1065 } 1076 }
1066 1077
1067 void Verify_FindMainResponseWithMultipleHits5() { 1078 void Verify_FindMainResponseWithMultipleHits5() {
1068 EXPECT_EQ(kFallbackTestUrl, delegate()->found_url_); 1079 EXPECT_EQ(kFallbackTestUrl, delegate()->found_url_);
1069 EXPECT_EQ(kManifestUrl2, delegate()->found_manifest_url_); 1080 EXPECT_EQ(kManifestUrl2, delegate()->found_manifest_url_);
1070 EXPECT_EQ(2, delegate()->found_cache_id_); 1081 EXPECT_EQ(2, delegate()->found_cache_id_);
1071 EXPECT_EQ(2, delegate()->found_group_id_); 1082 EXPECT_EQ(2, delegate()->found_group_id_);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 database()->InsertFallbackNameSpace(&fallback_namespace_record)); 1133 database()->InsertFallbackNameSpace(&fallback_namespace_record));
1123 whitelist_record.cache_id = 1; 1134 whitelist_record.cache_id = 1;
1124 whitelist_record.namespace_url = kOnlineNamespaceWithinFallback; 1135 whitelist_record.namespace_url = kOnlineNamespaceWithinFallback;
1125 EXPECT_TRUE(database()->InsertOnlineWhiteList(&whitelist_record)); 1136 EXPECT_TRUE(database()->InsertOnlineWhiteList(&whitelist_record));
1126 if (drop_from_working_set) { 1137 if (drop_from_working_set) {
1127 cache_ = NULL; 1138 cache_ = NULL;
1128 group_ = NULL; 1139 group_ = NULL;
1129 } 1140 }
1130 1141
1131 // We should not find anything for the foreign entry. 1142 // We should not find anything for the foreign entry.
1132 PushNextTask(NewRunnableMethod( 1143 PushNextTask(base::Bind(&AppCacheStorageImplTest::Verify_ExclusionNotFound,
1133 this, &AppCacheStorageImplTest::Verify_ExclusionNotFound, 1144 base::Unretained(this), kEntryUrl, 1));
1134 kEntryUrl, 1));
1135 storage()->FindResponseForMainRequest(kEntryUrl, GURL(), delegate()); 1145 storage()->FindResponseForMainRequest(kEntryUrl, GURL(), delegate());
1136 } 1146 }
1137 1147
1138 void Verify_ExclusionNotFound(GURL expected_url, int phase) { 1148 void Verify_ExclusionNotFound(GURL expected_url, int phase) {
1139 EXPECT_EQ(expected_url, delegate()->found_url_); 1149 EXPECT_EQ(expected_url, delegate()->found_url_);
1140 EXPECT_TRUE(delegate()->found_manifest_url_.is_empty()); 1150 EXPECT_TRUE(delegate()->found_manifest_url_.is_empty());
1141 EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_); 1151 EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_);
1142 EXPECT_EQ(0, delegate()->found_group_id_); 1152 EXPECT_EQ(0, delegate()->found_group_id_);
1143 EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id()); 1153 EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id());
1144 EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id()); 1154 EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id());
1145 EXPECT_TRUE(delegate()->found_fallback_url_.is_empty()); 1155 EXPECT_TRUE(delegate()->found_fallback_url_.is_empty());
1146 EXPECT_EQ(0, delegate()->found_entry_.types()); 1156 EXPECT_EQ(0, delegate()->found_entry_.types());
1147 EXPECT_EQ(0, delegate()->found_fallback_entry_.types()); 1157 EXPECT_EQ(0, delegate()->found_fallback_entry_.types());
1148 1158
1149 if (phase == 1) { 1159 if (phase == 1) {
1150 // We should not find anything for the online namespace. 1160 // We should not find anything for the online namespace.
1151 PushNextTask(NewRunnableMethod(this, 1161 PushNextTask(
1152 &AppCacheStorageImplTest::Verify_ExclusionNotFound, 1162 base::Bind(&AppCacheStorageImplTest::Verify_ExclusionNotFound,
1153 kOnlineNamespace, 2)); 1163 base::Unretained(this), kOnlineNamespace, 2));
1154 storage()->FindResponseForMainRequest( 1164 storage()->FindResponseForMainRequest(
1155 kOnlineNamespace, GURL(), delegate()); 1165 kOnlineNamespace, GURL(), delegate());
1156 return; 1166 return;
1157 } 1167 }
1158 if (phase == 2) { 1168 if (phase == 2) {
1159 // We should not find anything for the online namespace nested within 1169 // We should not find anything for the online namespace nested within
1160 // the fallback namespace. 1170 // the fallback namespace.
1161 PushNextTask(NewRunnableMethod(this, 1171 PushNextTask(base::Bind(
1162 &AppCacheStorageImplTest::Verify_ExclusionNotFound, 1172 &AppCacheStorageImplTest::Verify_ExclusionNotFound,
1163 kOnlineNamespaceWithinFallback, 3)); 1173 base::Unretained(this), kOnlineNamespaceWithinFallback, 3));
1164 storage()->FindResponseForMainRequest( 1174 storage()->FindResponseForMainRequest(
1165 kOnlineNamespaceWithinFallback, GURL(), delegate()); 1175 kOnlineNamespaceWithinFallback, GURL(), delegate());
1166 return; 1176 return;
1167 } 1177 }
1168 1178
1169 TestFinished(); 1179 TestFinished();
1170 } 1180 }
1171 1181
1172 // Test case helpers -------------------------------------------------- 1182 // Test case helpers --------------------------------------------------
1173 1183
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 EXPECT_TRUE(database()->InsertEntry(&entry_record)); 1230 EXPECT_TRUE(database()->InsertEntry(&entry_record));
1221 1231
1222 storage()->usage_map_[manifest_url.GetOrigin()] = 1232 storage()->usage_map_[manifest_url.GetOrigin()] =
1223 default_entry.response_size(); 1233 default_entry.response_size();
1224 } 1234 }
1225 } 1235 }
1226 1236
1227 // Data members -------------------------------------------------- 1237 // Data members --------------------------------------------------
1228 1238
1229 scoped_ptr<base::WaitableEvent> test_finished_event_; 1239 scoped_ptr<base::WaitableEvent> test_finished_event_;
1230 std::stack<Task*> task_stack_; 1240 std::stack<base::Closure> task_stack_;
1231 scoped_ptr<AppCacheService> service_; 1241 scoped_ptr<AppCacheService> service_;
1232 scoped_ptr<MockStorageDelegate> delegate_; 1242 scoped_ptr<MockStorageDelegate> delegate_;
1233 scoped_refptr<MockQuotaManagerProxy> mock_quota_manager_proxy_; 1243 scoped_refptr<MockQuotaManagerProxy> mock_quota_manager_proxy_;
1234 scoped_refptr<AppCacheGroup> group_; 1244 scoped_refptr<AppCacheGroup> group_;
1235 scoped_refptr<AppCache> cache_; 1245 scoped_refptr<AppCache> cache_;
1236 scoped_refptr<AppCache> cache2_; 1246 scoped_refptr<AppCache> cache2_;
1237 }; 1247 };
1238 1248
1239 1249
1240 TEST_F(AppCacheStorageImplTest, LoadCache_Miss) { 1250 TEST_F(AppCacheStorageImplTest, LoadCache_Miss) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 } 1331 }
1322 1332
1323 TEST_F(AppCacheStorageImplTest, FindMainResponseExclusionsInWorkingSet) { 1333 TEST_F(AppCacheStorageImplTest, FindMainResponseExclusionsInWorkingSet) {
1324 RunTestOnIOThread( 1334 RunTestOnIOThread(
1325 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet); 1335 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet);
1326 } 1336 }
1327 1337
1328 // That's all folks! 1338 // That's all folks!
1329 1339
1330 } // namespace appcache 1340 } // namespace appcache
1331
1332 // AppCacheStorageImplTest is expected to always live longer than the
1333 // runnable methods. This lets us call NewRunnableMethod on its instances.
1334 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest);
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_response_unittest.cc ('k') | webkit/appcache/appcache_update_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698