OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "net/url_request/url_request_job_factory_impl.h" | 21 #include "net/url_request/url_request_job_factory_impl.h" |
22 #include "net/url_request/url_request_test_job.h" | 22 #include "net/url_request/url_request_test_job.h" |
23 #include "net/url_request/url_request_test_util.h" | 23 #include "net/url_request/url_request_test_util.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 class AppCacheUpdateJobTest; | 27 class AppCacheUpdateJobTest; |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 // Values should match values used in appcache_update_job.cc. | |
32 const base::TimeDelta kFullUpdateInterval = | |
33 base::TimeDelta::FromHours(24); | |
34 const base::TimeDelta kMaxEvictableErrorDuration = | |
35 base::TimeDelta::FromDays(14); | |
36 const base::TimeDelta kOneHour = | |
37 base::TimeDelta::FromHours(1); | |
38 | |
31 const char kManifest1Contents[] = | 39 const char kManifest1Contents[] = |
32 "CACHE MANIFEST\n" | 40 "CACHE MANIFEST\n" |
33 "explicit1\n" | 41 "explicit1\n" |
34 "FALLBACK:\n" | 42 "FALLBACK:\n" |
35 "fallback1 fallback1a\n" | 43 "fallback1 fallback1a\n" |
36 "NETWORK:\n" | 44 "NETWORK:\n" |
37 "*\n"; | 45 "*\n"; |
38 | 46 |
39 // There are a handful of http accessible resources that we need to conduct | 47 // There are a handful of http accessible resources that we need to conduct |
40 // these tests. Instead of running a seperate server to host these resources, | 48 // these tests. Instead of running a seperate server to host these resources, |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 }; | 592 }; |
585 | 593 |
586 class AppCacheUpdateJobTest : public testing::Test, | 594 class AppCacheUpdateJobTest : public testing::Test, |
587 public AppCacheGroup::UpdateObserver { | 595 public AppCacheGroup::UpdateObserver { |
588 public: | 596 public: |
589 AppCacheUpdateJobTest() | 597 AppCacheUpdateJobTest() |
590 : do_checks_after_update_finished_(false), | 598 : do_checks_after_update_finished_(false), |
591 expect_group_obsolete_(false), | 599 expect_group_obsolete_(false), |
592 expect_group_has_cache_(false), | 600 expect_group_has_cache_(false), |
593 expect_group_is_being_deleted_(false), | 601 expect_group_is_being_deleted_(false), |
602 expect_evictable_error_(false), | |
603 expect_eviction_(false), | |
594 expect_old_cache_(NULL), | 604 expect_old_cache_(NULL), |
595 expect_newest_cache_(NULL), | 605 expect_newest_cache_(NULL), |
596 expect_non_null_update_time_(false), | 606 expect_non_null_update_time_(false), |
597 tested_manifest_(NONE), | 607 tested_manifest_(NONE), |
598 tested_manifest_path_override_(NULL) { | 608 tested_manifest_path_override_(NULL) { |
599 io_thread_.reset(new IOThread("AppCacheUpdateJob IO test thread")); | 609 io_thread_.reset(new IOThread("AppCacheUpdateJob IO test thread")); |
600 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); | 610 base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); |
601 io_thread_->StartWithOptions(options); | 611 io_thread_->StartWithOptions(options); |
602 } | 612 } |
603 | 613 |
(...skipping 22 matching lines...) Expand all Loading... | |
626 | 636 |
627 MockFrontend mock_frontend; | 637 MockFrontend mock_frontend; |
628 AppCacheHost host(1, &mock_frontend, service_.get()); | 638 AppCacheHost host(1, &mock_frontend, service_.get()); |
629 | 639 |
630 update->StartUpdate(&host, GURL()); | 640 update->StartUpdate(&host, GURL()); |
631 | 641 |
632 // Verify state. | 642 // Verify state. |
633 EXPECT_EQ(AppCacheUpdateJob::CACHE_ATTEMPT, update->update_type_); | 643 EXPECT_EQ(AppCacheUpdateJob::CACHE_ATTEMPT, update->update_type_); |
634 EXPECT_EQ(AppCacheUpdateJob::FETCH_MANIFEST, update->internal_state_); | 644 EXPECT_EQ(AppCacheUpdateJob::FETCH_MANIFEST, update->internal_state_); |
635 EXPECT_EQ(AppCacheGroup::CHECKING, group_->update_status()); | 645 EXPECT_EQ(AppCacheGroup::CHECKING, group_->update_status()); |
646 EXPECT_TRUE(update->doing_full_update_check_); | |
636 | 647 |
637 // Verify notifications. | 648 // Verify notifications. |
638 MockFrontend::RaisedEvents& events = mock_frontend.raised_events_; | 649 MockFrontend::RaisedEvents& events = mock_frontend.raised_events_; |
639 size_t expected = 1; | 650 size_t expected = 1; |
640 EXPECT_EQ(expected, events.size()); | 651 EXPECT_EQ(expected, events.size()); |
641 EXPECT_EQ(expected, events[0].first.size()); | 652 EXPECT_EQ(expected, events[0].first.size()); |
642 EXPECT_EQ(host.host_id(), events[0].first[0]); | 653 EXPECT_EQ(host.host_id(), events[0].first[0]); |
643 EXPECT_EQ(APPCACHE_CHECKING_EVENT, events[0].second); | 654 EXPECT_EQ(APPCACHE_CHECKING_EVENT, events[0].second); |
644 | 655 |
645 // Abort as we're not testing actual URL fetches in this test. | 656 // Abort as we're not testing actual URL fetches in this test. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 | 688 |
678 AppCacheUpdateJob* update = | 689 AppCacheUpdateJob* update = |
679 new AppCacheUpdateJob(service_.get(), group_.get()); | 690 new AppCacheUpdateJob(service_.get(), group_.get()); |
680 group_->update_job_ = update; | 691 group_->update_job_ = update; |
681 update->StartUpdate(&host4, GURL()); | 692 update->StartUpdate(&host4, GURL()); |
682 | 693 |
683 // Verify state after starting an update. | 694 // Verify state after starting an update. |
684 EXPECT_EQ(AppCacheUpdateJob::UPGRADE_ATTEMPT, update->update_type_); | 695 EXPECT_EQ(AppCacheUpdateJob::UPGRADE_ATTEMPT, update->update_type_); |
685 EXPECT_EQ(AppCacheUpdateJob::FETCH_MANIFEST, update->internal_state_); | 696 EXPECT_EQ(AppCacheUpdateJob::FETCH_MANIFEST, update->internal_state_); |
686 EXPECT_EQ(AppCacheGroup::CHECKING, group_->update_status()); | 697 EXPECT_EQ(AppCacheGroup::CHECKING, group_->update_status()); |
698 EXPECT_FALSE(update->doing_full_update_check_); | |
687 | 699 |
688 // Verify notifications. | 700 // Verify notifications. |
689 MockFrontend::RaisedEvents& events = mock_frontend1.raised_events_; | 701 MockFrontend::RaisedEvents& events = mock_frontend1.raised_events_; |
690 size_t expected = 1; | 702 size_t expected = 1; |
691 EXPECT_EQ(expected, events.size()); | 703 EXPECT_EQ(expected, events.size()); |
692 expected = 2; // 2 hosts using frontend1 | 704 expected = 2; // 2 hosts using frontend1 |
693 EXPECT_EQ(expected, events[0].first.size()); | 705 EXPECT_EQ(expected, events[0].first.size()); |
694 MockFrontend::HostIds& host_ids = events[0].first; | 706 MockFrontend::HostIds& host_ids = events[0].first; |
695 EXPECT_TRUE(std::find(host_ids.begin(), host_ids.end(), host1.host_id()) | 707 EXPECT_TRUE(std::find(host_ids.begin(), host_ids.end(), host1.host_id()) |
696 != host_ids.end()); | 708 != host_ids.end()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
735 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), | 747 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), |
736 APPCACHE_CHECKING_EVENT); | 748 APPCACHE_CHECKING_EVENT); |
737 | 749 |
738 WaitForUpdateToFinish(); | 750 WaitForUpdateToFinish(); |
739 } | 751 } |
740 | 752 |
741 void UpgradeFetchManifestFailTest() { | 753 void UpgradeFetchManifestFailTest() { |
742 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent()); | 754 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent()); |
743 | 755 |
744 MakeService(); | 756 MakeService(); |
745 group_ = new AppCacheGroup(service_->storage(), GURL("http://failme"), | 757 group_ = new AppCacheGroup(service_->storage(), |
758 MockHttpServer::GetMockUrl("files/servererror"), | |
746 service_->storage()->NewGroupId()); | 759 service_->storage()->NewGroupId()); |
747 AppCacheUpdateJob* update = | 760 AppCacheUpdateJob* update = |
748 new AppCacheUpdateJob(service_.get(), group_.get()); | 761 new AppCacheUpdateJob(service_.get(), group_.get()); |
749 group_->update_job_ = update; | 762 group_->update_job_ = update; |
750 | 763 |
751 AppCache* cache = MakeCacheForGroup(1, 111); | 764 AppCache* cache = MakeCacheForGroup(1, 111); |
752 MockFrontend* frontend1 = MakeMockFrontend(); | 765 MockFrontend* frontend1 = MakeMockFrontend(); |
753 MockFrontend* frontend2 = MakeMockFrontend(); | 766 MockFrontend* frontend2 = MakeMockFrontend(); |
754 AppCacheHost* host1 = MakeHost(1, frontend1); | 767 AppCacheHost* host1 = MakeHost(1, frontend1); |
755 AppCacheHost* host2 = MakeHost(2, frontend2); | 768 AppCacheHost* host2 = MakeHost(2, frontend2); |
756 host1->AssociateCompleteCache(cache); | 769 host1->AssociateCompleteCache(cache); |
757 host2->AssociateCompleteCache(cache); | 770 host2->AssociateCompleteCache(cache); |
758 | 771 |
772 group_->set_last_full_update_check_time( | |
773 base::Time::Now() - kFullUpdateInterval - kOneHour); | |
759 update->StartUpdate(NULL, GURL()); | 774 update->StartUpdate(NULL, GURL()); |
775 EXPECT_TRUE(update->doing_full_update_check_); | |
760 | 776 |
761 // Set up checks for when update job finishes. | 777 // Set up checks for when update job finishes. |
762 do_checks_after_update_finished_ = true; | 778 do_checks_after_update_finished_ = true; |
763 expect_group_obsolete_ = false; | 779 expect_group_obsolete_ = false; |
764 expect_group_has_cache_ = true; | 780 expect_group_has_cache_ = true; |
781 expect_evictable_error_ = true; | |
765 expect_newest_cache_ = cache; // newest cache unaffected by update | 782 expect_newest_cache_ = cache; // newest cache unaffected by update |
783 expect_full_update_time_equal_to_ = group_->last_full_update_check_time(); | |
766 MockFrontend::HostIds ids1(1, host1->host_id()); | 784 MockFrontend::HostIds ids1(1, host1->host_id()); |
767 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT); | 785 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT); |
768 frontend1->AddExpectedEvent(ids1, APPCACHE_ERROR_EVENT); | 786 frontend1->AddExpectedEvent(ids1, APPCACHE_ERROR_EVENT); |
769 MockFrontend::HostIds ids2(1, host2->host_id()); | 787 MockFrontend::HostIds ids2(1, host2->host_id()); |
770 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT); | 788 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT); |
771 frontend2->AddExpectedEvent(ids2, APPCACHE_ERROR_EVENT); | 789 frontend2->AddExpectedEvent(ids2, APPCACHE_ERROR_EVENT); |
772 | 790 |
773 WaitForUpdateToFinish(); | 791 WaitForUpdateToFinish(); |
774 } | 792 } |
775 | 793 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
937 group_->update_job_ = update; | 955 group_->update_job_ = update; |
938 | 956 |
939 AppCache* cache = MakeCacheForGroup(1, 111); | 957 AppCache* cache = MakeCacheForGroup(1, 111); |
940 MockFrontend* frontend1 = MakeMockFrontend(); | 958 MockFrontend* frontend1 = MakeMockFrontend(); |
941 MockFrontend* frontend2 = MakeMockFrontend(); | 959 MockFrontend* frontend2 = MakeMockFrontend(); |
942 AppCacheHost* host1 = MakeHost(1, frontend1); | 960 AppCacheHost* host1 = MakeHost(1, frontend1); |
943 AppCacheHost* host2 = MakeHost(2, frontend2); | 961 AppCacheHost* host2 = MakeHost(2, frontend2); |
944 host1->AssociateCompleteCache(cache); | 962 host1->AssociateCompleteCache(cache); |
945 host2->AssociateCompleteCache(cache); | 963 host2->AssociateCompleteCache(cache); |
946 | 964 |
965 group_->set_last_full_update_check_time( | |
966 base::Time::Now() - kFullUpdateInterval - kOneHour); | |
967 group_->set_first_evictable_error_time(base::Time::Now()); | |
947 update->StartUpdate(NULL, GURL()); | 968 update->StartUpdate(NULL, GURL()); |
969 EXPECT_TRUE(update->doing_full_update_check_); | |
948 | 970 |
949 // Set up checks for when update job finishes. | 971 // Set up checks for when update job finishes. |
950 do_checks_after_update_finished_ = true; | 972 do_checks_after_update_finished_ = true; |
951 expect_group_obsolete_ = false; | 973 expect_group_obsolete_ = false; |
952 expect_group_has_cache_ = true; | 974 expect_group_has_cache_ = true; |
953 expect_newest_cache_ = cache; // newest cache unaffected by update | 975 expect_newest_cache_ = cache; // newest cache unaffected by update |
976 expect_evictable_error_ = false; // should be reset | |
977 expect_full_update_time_newer_than_ = group_->last_full_update_check_time(); | |
954 MockFrontend::HostIds ids1(1, host1->host_id()); | 978 MockFrontend::HostIds ids1(1, host1->host_id()); |
955 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT); | 979 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT); |
956 frontend1->AddExpectedEvent(ids1, APPCACHE_NO_UPDATE_EVENT); | 980 frontend1->AddExpectedEvent(ids1, APPCACHE_NO_UPDATE_EVENT); |
957 MockFrontend::HostIds ids2(1, host2->host_id()); | 981 MockFrontend::HostIds ids2(1, host2->host_id()); |
958 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT); | 982 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT); |
959 frontend2->AddExpectedEvent(ids2, APPCACHE_NO_UPDATE_EVENT); | 983 frontend2->AddExpectedEvent(ids2, APPCACHE_NO_UPDATE_EVENT); |
960 | 984 |
961 WaitForUpdateToFinish(); | 985 WaitForUpdateToFinish(); |
962 } | 986 } |
963 | 987 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1057 | 1081 |
1058 void BasicCacheAttemptSuccessTest() { | 1082 void BasicCacheAttemptSuccessTest() { |
1059 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent()); | 1083 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent()); |
1060 | 1084 |
1061 GURL manifest_url = MockHttpServer::GetMockUrl("files/manifest1"); | 1085 GURL manifest_url = MockHttpServer::GetMockUrl("files/manifest1"); |
1062 | 1086 |
1063 MakeService(); | 1087 MakeService(); |
1064 group_ = new AppCacheGroup( | 1088 group_ = new AppCacheGroup( |
1065 service_->storage(), manifest_url, | 1089 service_->storage(), manifest_url, |
1066 service_->storage()->NewGroupId()); | 1090 service_->storage()->NewGroupId()); |
1091 ASSERT_TRUE(group_->last_full_update_check_time().is_null()); | |
1067 AppCacheUpdateJob* update = | 1092 AppCacheUpdateJob* update = |
1068 new AppCacheUpdateJob(service_.get(), group_.get()); | 1093 new AppCacheUpdateJob(service_.get(), group_.get()); |
1069 group_->update_job_ = update; | 1094 group_->update_job_ = update; |
1070 | 1095 |
1071 MockFrontend* frontend = MakeMockFrontend(); | 1096 MockFrontend* frontend = MakeMockFrontend(); |
1072 AppCacheHost* host = MakeHost(1, frontend); | 1097 AppCacheHost* host = MakeHost(1, frontend); |
1073 update->StartUpdate(host, GURL()); | 1098 update->StartUpdate(host, GURL()); |
1074 | 1099 |
1075 // Set up checks for when update job finishes. | 1100 // Set up checks for when update job finishes. |
1076 do_checks_after_update_finished_ = true; | 1101 do_checks_after_update_finished_ = true; |
1077 expect_group_obsolete_ = false; | 1102 expect_group_obsolete_ = false; |
1078 expect_group_has_cache_ = true; | 1103 expect_group_has_cache_ = true; |
1104 expect_full_update_time_newer_than_ = base::Time::Now() - kOneHour; | |
1079 tested_manifest_ = MANIFEST1; | 1105 tested_manifest_ = MANIFEST1; |
1080 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), | 1106 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), |
1081 APPCACHE_CHECKING_EVENT); | 1107 APPCACHE_CHECKING_EVENT); |
1082 | 1108 |
1083 WaitForUpdateToFinish(); | 1109 WaitForUpdateToFinish(); |
1084 } | 1110 } |
1085 | 1111 |
1086 void DownloadInterceptEntriesTest() { | 1112 void DownloadInterceptEntriesTest() { |
1087 // Ensures we download intercept entries too. | 1113 // Ensures we download intercept entries too. |
1088 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent()); | 1114 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1130 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), | 1156 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), |
1131 response_writer_->response_id()); | 1157 response_writer_->response_id()); |
1132 MockFrontend* frontend1 = MakeMockFrontend(); | 1158 MockFrontend* frontend1 = MakeMockFrontend(); |
1133 MockFrontend* frontend2 = MakeMockFrontend(); | 1159 MockFrontend* frontend2 = MakeMockFrontend(); |
1134 AppCacheHost* host1 = MakeHost(1, frontend1); | 1160 AppCacheHost* host1 = MakeHost(1, frontend1); |
1135 AppCacheHost* host2 = MakeHost(2, frontend2); | 1161 AppCacheHost* host2 = MakeHost(2, frontend2); |
1136 host1->AssociateCompleteCache(cache); | 1162 host1->AssociateCompleteCache(cache); |
1137 host2->AssociateCompleteCache(cache); | 1163 host2->AssociateCompleteCache(cache); |
1138 frontend1->SetVerifyProgressEvents(true); | 1164 frontend1->SetVerifyProgressEvents(true); |
1139 frontend2->SetVerifyProgressEvents(true); | 1165 frontend2->SetVerifyProgressEvents(true); |
1166 group_->set_last_full_update_check_time( | |
1167 base::Time::Now() - kFullUpdateInterval - kOneHour); | |
1140 | 1168 |
1141 // Set up checks for when update job finishes. | 1169 // Set up checks for when update job finishes. |
1142 do_checks_after_update_finished_ = true; | 1170 do_checks_after_update_finished_ = true; |
1143 expect_group_obsolete_ = false; | 1171 expect_group_obsolete_ = false; |
1144 expect_group_has_cache_ = true; | 1172 expect_group_has_cache_ = true; |
1145 expect_old_cache_ = cache; | 1173 expect_old_cache_ = cache; |
1146 tested_manifest_ = MANIFEST1; | 1174 tested_manifest_ = MANIFEST1; |
1175 expect_full_update_time_newer_than_ = group_->last_full_update_check_time(); | |
1147 MockFrontend::HostIds ids1(1, host1->host_id()); | 1176 MockFrontend::HostIds ids1(1, host1->host_id()); |
1148 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT); | 1177 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT); |
1149 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT); | 1178 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT); |
1150 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); | 1179 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); |
1151 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); | 1180 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); |
1152 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // final | 1181 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // final |
1153 frontend1->AddExpectedEvent(ids1, APPCACHE_UPDATE_READY_EVENT); | 1182 frontend1->AddExpectedEvent(ids1, APPCACHE_UPDATE_READY_EVENT); |
1154 MockFrontend::HostIds ids2(1, host2->host_id()); | 1183 MockFrontend::HostIds ids2(1, host2->host_id()); |
1155 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT); | 1184 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT); |
1156 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT); | 1185 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT); |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1435 | 1464 |
1436 MakeService(); | 1465 MakeService(); |
1437 group_ = new AppCacheGroup(service_->storage(), | 1466 group_ = new AppCacheGroup(service_->storage(), |
1438 MockHttpServer::GetMockUrl("files/manifest-fb-404"), | 1467 MockHttpServer::GetMockUrl("files/manifest-fb-404"), |
1439 service_->storage()->NewGroupId()); | 1468 service_->storage()->NewGroupId()); |
1440 AppCacheUpdateJob* update = | 1469 AppCacheUpdateJob* update = |
1441 new AppCacheUpdateJob(service_.get(), group_.get()); | 1470 new AppCacheUpdateJob(service_.get(), group_.get()); |
1442 group_->update_job_ = update; | 1471 group_->update_job_ = update; |
1443 | 1472 |
1444 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 99); | 1473 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 99); |
1474 group_->set_first_evictable_error_time( | |
1475 base::Time::Now() - kMaxEvictableErrorDuration - kOneHour); | |
1445 MockFrontend* frontend1 = MakeMockFrontend(); | 1476 MockFrontend* frontend1 = MakeMockFrontend(); |
1446 MockFrontend* frontend2 = MakeMockFrontend(); | 1477 MockFrontend* frontend2 = MakeMockFrontend(); |
1447 frontend1->SetIgnoreProgressEvents(true); | 1478 frontend1->SetIgnoreProgressEvents(true); |
1448 frontend2->SetIgnoreProgressEvents(true); | 1479 frontend2->SetIgnoreProgressEvents(true); |
1449 AppCacheHost* host1 = MakeHost(1, frontend1); | 1480 AppCacheHost* host1 = MakeHost(1, frontend1); |
1450 AppCacheHost* host2 = MakeHost(2, frontend2); | 1481 AppCacheHost* host2 = MakeHost(2, frontend2); |
1451 host1->AssociateCompleteCache(cache); | 1482 host1->AssociateCompleteCache(cache); |
1452 host2->AssociateCompleteCache(cache); | 1483 host2->AssociateCompleteCache(cache); |
1453 | 1484 |
1454 update->StartUpdate(NULL, GURL()); | 1485 update->StartUpdate(NULL, GURL()); |
1455 | 1486 |
1456 // Set up checks for when update job finishes. | 1487 // Set up checks for when update job finishes. |
1457 do_checks_after_update_finished_ = true; | 1488 do_checks_after_update_finished_ = true; |
1458 expect_group_obsolete_ = false; | 1489 expect_group_obsolete_ = false; |
1459 expect_group_has_cache_ = true; | 1490 expect_group_has_cache_ = true; |
1460 expect_newest_cache_ = cache; // newest cache unaffectd by failed update | 1491 expect_newest_cache_ = cache; // newest cache unaffectd by failed update |
1492 expect_eviction_ = true; | |
1461 MockFrontend::HostIds ids1(1, host1->host_id()); | 1493 MockFrontend::HostIds ids1(1, host1->host_id()); |
1462 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT); | 1494 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT); |
1463 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT); | 1495 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT); |
1464 frontend1->AddExpectedEvent(ids1, APPCACHE_ERROR_EVENT); | 1496 frontend1->AddExpectedEvent(ids1, APPCACHE_ERROR_EVENT); |
1465 MockFrontend::HostIds ids2(1, host2->host_id()); | 1497 MockFrontend::HostIds ids2(1, host2->host_id()); |
1466 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT); | 1498 frontend2->AddExpectedEvent(ids2, APPCACHE_CHECKING_EVENT); |
1467 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT); | 1499 frontend2->AddExpectedEvent(ids2, APPCACHE_DOWNLOADING_EVENT); |
1468 frontend2->AddExpectedEvent(ids2, APPCACHE_ERROR_EVENT); | 1500 frontend2->AddExpectedEvent(ids2, APPCACHE_ERROR_EVENT); |
1469 | 1501 |
1470 WaitForUpdateToFinish(); | 1502 WaitForUpdateToFinish(); |
(...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2716 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent()); | 2748 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent()); |
2717 | 2749 |
2718 HttpHeadersRequestTestJob::Initialize("Sat, 29 Oct 1994 19:43:31 GMT", | 2750 HttpHeadersRequestTestJob::Initialize("Sat, 29 Oct 1994 19:43:31 GMT", |
2719 std::string()); | 2751 std::string()); |
2720 net::URLRequestJobFactoryImpl* new_factory( | 2752 net::URLRequestJobFactoryImpl* new_factory( |
2721 new net::URLRequestJobFactoryImpl); | 2753 new net::URLRequestJobFactoryImpl); |
2722 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); | 2754 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); |
2723 io_thread_->SetNewJobFactory(new_factory); | 2755 io_thread_->SetNewJobFactory(new_factory); |
2724 | 2756 |
2725 MakeService(); | 2757 MakeService(); |
2726 group_ =new AppCacheGroup( | 2758 group_ = new AppCacheGroup( |
2727 service_->storage(), | 2759 service_->storage(), |
2728 MockHttpServer::GetMockUrl("files/manifest1"), | 2760 MockHttpServer::GetMockUrl("files/manifest1"), |
2729 111); | 2761 111); |
2730 AppCacheUpdateJob* update = | 2762 AppCacheUpdateJob* update = |
2731 new AppCacheUpdateJob(service_.get(), group_.get()); | 2763 new AppCacheUpdateJob(service_.get(), group_.get()); |
2732 group_->update_job_ = update; | 2764 group_->update_job_ = update; |
2733 | 2765 |
2734 // Give the newest cache a manifest enry that is in storage. | 2766 // Give the newest cache a manifest enry that is in storage. |
2735 response_writer_.reset( | 2767 response_writer_.reset( |
2736 service_->storage()->CreateResponseWriter(group_->manifest_url(), | 2768 service_->storage()->CreateResponseWriter(group_->manifest_url(), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2783 net::URLRequestJobFactoryImpl* new_factory( | 2815 net::URLRequestJobFactoryImpl* new_factory( |
2784 new net::URLRequestJobFactoryImpl); | 2816 new net::URLRequestJobFactoryImpl); |
2785 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); | 2817 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); |
2786 io_thread_->SetNewJobFactory(new_factory); | 2818 io_thread_->SetNewJobFactory(new_factory); |
2787 | 2819 |
2788 MakeService(); | 2820 MakeService(); |
2789 group_ = new AppCacheGroup( | 2821 group_ = new AppCacheGroup( |
2790 service_->storage(), | 2822 service_->storage(), |
2791 MockHttpServer::GetMockUrl("files/manifest1"), | 2823 MockHttpServer::GetMockUrl("files/manifest1"), |
2792 111); | 2824 111); |
2825 group_->set_last_full_update_check_time(base::Time::Now()); | |
michaeln
2015/06/22 23:39:47
i don't think i need this line, if not i'll remove
palmer
2015/06/26 20:41:27
You're a better judge of that than I.
| |
2793 AppCacheUpdateJob* update = | 2826 AppCacheUpdateJob* update = |
2794 new AppCacheUpdateJob(service_.get(), group_.get()); | 2827 new AppCacheUpdateJob(service_.get(), group_.get()); |
2795 group_->update_job_ = update; | 2828 group_->update_job_ = update; |
2796 | 2829 |
2797 // Give the newest cache a manifest enry that is in storage. | 2830 // Give the newest cache a manifest enry that is in storage. |
2798 response_writer_.reset( | 2831 response_writer_.reset( |
2799 service_->storage()->CreateResponseWriter(group_->manifest_url(), | 2832 service_->storage()->CreateResponseWriter(group_->manifest_url(), |
2800 group_->group_id())); | 2833 group_->group_id())); |
2801 | 2834 |
2802 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), | 2835 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3015 | 3048 |
3016 AppCache* MakeCacheForGroup(int64 cache_id, int64 manifest_response_id) { | 3049 AppCache* MakeCacheForGroup(int64 cache_id, int64 manifest_response_id) { |
3017 return MakeCacheForGroup(cache_id, group_->manifest_url(), | 3050 return MakeCacheForGroup(cache_id, group_->manifest_url(), |
3018 manifest_response_id); | 3051 manifest_response_id); |
3019 } | 3052 } |
3020 | 3053 |
3021 AppCache* MakeCacheForGroup(int64 cache_id, const GURL& manifest_entry_url, | 3054 AppCache* MakeCacheForGroup(int64 cache_id, const GURL& manifest_entry_url, |
3022 int64 manifest_response_id) { | 3055 int64 manifest_response_id) { |
3023 AppCache* cache = new AppCache(service_->storage(), cache_id); | 3056 AppCache* cache = new AppCache(service_->storage(), cache_id); |
3024 cache->set_complete(true); | 3057 cache->set_complete(true); |
3025 cache->set_update_time(base::Time::Now()); | 3058 cache->set_update_time(base::Time::Now() - kOneHour); |
3026 group_->AddCache(cache); | 3059 group_->AddCache(cache); |
3060 group_->set_last_full_update_check_time(cache->update_time()); | |
3027 | 3061 |
3028 // Add manifest entry to cache. | 3062 // Add manifest entry to cache. |
3029 cache->AddEntry(manifest_entry_url, | 3063 cache->AddEntry(manifest_entry_url, |
3030 AppCacheEntry(AppCacheEntry::MANIFEST, manifest_response_id)); | 3064 AppCacheEntry(AppCacheEntry::MANIFEST, manifest_response_id)); |
3031 | 3065 |
3066 // Specific tests that expect a newer time should set | |
3067 // expect_full_update_time_newer_than_ which causes this | |
3068 // equality expectation to be ignored. | |
3069 expect_full_update_time_equal_to_ = cache->update_time(); | |
3070 | |
3032 return cache; | 3071 return cache; |
3033 } | 3072 } |
3034 | 3073 |
3035 AppCacheHost* MakeHost(int host_id, AppCacheFrontend* frontend) { | 3074 AppCacheHost* MakeHost(int host_id, AppCacheFrontend* frontend) { |
3036 AppCacheHost* host = new AppCacheHost(host_id, frontend, service_.get()); | 3075 AppCacheHost* host = new AppCacheHost(host_id, frontend, service_.get()); |
3037 hosts_.push_back(host); | 3076 hosts_.push_back(host); |
3038 return host; | 3077 return host; |
3039 } | 3078 } |
3040 | 3079 |
3041 AppCacheResponseInfo* MakeAppCacheResponseInfo( | 3080 AppCacheResponseInfo* MakeAppCacheResponseInfo( |
(...skipping 14 matching lines...) Expand all Loading... | |
3056 return frontend; | 3095 return frontend; |
3057 } | 3096 } |
3058 | 3097 |
3059 // Verifies conditions about the group and notifications after an update | 3098 // Verifies conditions about the group and notifications after an update |
3060 // has finished. Cannot verify update job internals as update is deleted. | 3099 // has finished. Cannot verify update job internals as update is deleted. |
3061 void VerifyExpectations() { | 3100 void VerifyExpectations() { |
3062 RetryRequestTestJob::Verify(); | 3101 RetryRequestTestJob::Verify(); |
3063 HttpHeadersRequestTestJob::Verify(); | 3102 HttpHeadersRequestTestJob::Verify(); |
3064 | 3103 |
3065 EXPECT_EQ(expect_group_obsolete_, group_->is_obsolete()); | 3104 EXPECT_EQ(expect_group_obsolete_, group_->is_obsolete()); |
3066 EXPECT_EQ(expect_group_is_being_deleted_, group_->is_being_deleted()); | 3105 EXPECT_EQ(expect_group_is_being_deleted_ || expect_eviction_, |
3106 group_->is_being_deleted()); | |
3107 | |
3108 if (!expect_eviction_) { | |
3109 EXPECT_EQ(expect_evictable_error_, | |
3110 !group_->first_evictable_error_time().is_null()); | |
3111 if (expect_evictable_error_) { | |
3112 MockAppCacheStorage* storage = | |
3113 reinterpret_cast<MockAppCacheStorage*>(service_->storage()); | |
3114 EXPECT_EQ(group_->first_evictable_error_time(), | |
3115 storage->stored_eviction_times_[group_->group_id()].second); | |
3116 } | |
3117 } | |
3118 | |
3119 if (!expect_full_update_time_newer_than_.is_null()) { | |
3120 EXPECT_LT(expect_full_update_time_newer_than_, | |
3121 group_->last_full_update_check_time()); | |
3122 } else if (!expect_full_update_time_equal_to_.is_null()) { | |
3123 EXPECT_EQ(expect_full_update_time_equal_to_, | |
3124 group_->last_full_update_check_time()); | |
3125 } | |
3067 | 3126 |
3068 if (expect_group_has_cache_) { | 3127 if (expect_group_has_cache_) { |
3069 EXPECT_TRUE(group_->newest_complete_cache() != NULL); | 3128 EXPECT_TRUE(group_->newest_complete_cache() != NULL); |
3070 | 3129 |
3071 if (expect_non_null_update_time_) | 3130 if (expect_non_null_update_time_) |
3072 EXPECT_TRUE(!group_->newest_complete_cache()->update_time().is_null()); | 3131 EXPECT_TRUE(!group_->newest_complete_cache()->update_time().is_null()); |
3073 | 3132 |
3074 if (expect_old_cache_) { | 3133 if (expect_old_cache_) { |
3075 EXPECT_NE(expect_old_cache_, group_->newest_complete_cache()); | 3134 EXPECT_NE(expect_old_cache_, group_->newest_complete_cache()); |
3076 EXPECT_TRUE(group_->old_caches().end() != | 3135 EXPECT_TRUE(group_->old_caches().end() != |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3359 | 3418 |
3360 // Response infos used by an async test that need to live until update job | 3419 // Response infos used by an async test that need to live until update job |
3361 // finishes. | 3420 // finishes. |
3362 std::vector<scoped_refptr<AppCacheResponseInfo> > response_infos_; | 3421 std::vector<scoped_refptr<AppCacheResponseInfo> > response_infos_; |
3363 | 3422 |
3364 // Flag indicating if test cares to verify the update after update finishes. | 3423 // Flag indicating if test cares to verify the update after update finishes. |
3365 bool do_checks_after_update_finished_; | 3424 bool do_checks_after_update_finished_; |
3366 bool expect_group_obsolete_; | 3425 bool expect_group_obsolete_; |
3367 bool expect_group_has_cache_; | 3426 bool expect_group_has_cache_; |
3368 bool expect_group_is_being_deleted_; | 3427 bool expect_group_is_being_deleted_; |
3428 bool expect_evictable_error_; | |
3429 bool expect_eviction_; | |
3430 base::Time expect_full_update_time_newer_than_; | |
3431 base::Time expect_full_update_time_equal_to_; | |
3369 AppCache* expect_old_cache_; | 3432 AppCache* expect_old_cache_; |
3370 AppCache* expect_newest_cache_; | 3433 AppCache* expect_newest_cache_; |
3371 bool expect_non_null_update_time_; | 3434 bool expect_non_null_update_time_; |
3372 std::vector<MockFrontend*> frontends_; // to check expected events | 3435 std::vector<MockFrontend*> frontends_; // to check expected events |
3373 TestedManifest tested_manifest_; | 3436 TestedManifest tested_manifest_; |
3374 const char* tested_manifest_path_override_; | 3437 const char* tested_manifest_path_override_; |
3375 AppCache::EntryMap expect_extra_entries_; | 3438 AppCache::EntryMap expect_extra_entries_; |
3376 std::map<GURL, int64> expect_response_ids_; | 3439 std::map<GURL, int64> expect_response_ids_; |
3377 }; | 3440 }; |
3378 | 3441 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3646 | 3709 |
3647 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { | 3710 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { |
3648 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); | 3711 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); |
3649 } | 3712 } |
3650 | 3713 |
3651 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { | 3714 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { |
3652 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); | 3715 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); |
3653 } | 3716 } |
3654 | 3717 |
3655 } // namespace content | 3718 } // namespace content |
OLD | NEW |