OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 data.is_active = false; | 904 data.is_active = false; |
905 std::vector<ResourceRecord> resources; | 905 std::vector<ResourceRecord> resources; |
906 resources.push_back( | 906 resources.push_back( |
907 ResourceRecord(resource_id1_, script_, resource_id1_size_)); | 907 ResourceRecord(resource_id1_, script_, resource_id1_size_)); |
908 resources.push_back( | 908 resources.push_back( |
909 ResourceRecord(resource_id2_, import_, resource_id2_size_)); | 909 ResourceRecord(resource_id2_, import_, resource_id2_size_)); |
910 registration_ = storage()->GetOrCreateRegistration(data, resources); | 910 registration_ = storage()->GetOrCreateRegistration(data, resources); |
911 registration_->waiting_version()->SetStatus(ServiceWorkerVersion::NEW); | 911 registration_->waiting_version()->SetStatus(ServiceWorkerVersion::NEW); |
912 | 912 |
913 // Add the resources ids to the uncommitted list. | 913 // Add the resources ids to the uncommitted list. |
914 storage()->StoreUncommittedResponseId(resource_id1_); | 914 storage()->StoreUncommittedResourceId(resource_id1_); |
915 storage()->StoreUncommittedResponseId(resource_id2_); | 915 storage()->StoreUncommittedResourceId(resource_id2_); |
916 base::RunLoop().RunUntilIdle(); | 916 base::RunLoop().RunUntilIdle(); |
917 std::set<int64> verify_ids; | 917 std::set<int64> verify_ids; |
918 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 918 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
919 storage()->database_->GetUncommittedResourceIds(&verify_ids)); | 919 storage()->database_->GetUncommittedResourceIds(&verify_ids)); |
920 EXPECT_EQ(2u, verify_ids.size()); | 920 EXPECT_EQ(2u, verify_ids.size()); |
921 | 921 |
922 // And dump something in the disk cache for them. | 922 // And dump something in the disk cache for them. |
923 WriteBasicResponse(storage(), resource_id1_); | 923 WriteBasicResponse(storage(), resource_id1_); |
924 WriteBasicResponse(storage(), resource_id2_); | 924 WriteBasicResponse(storage(), resource_id2_); |
925 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); | 925 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 verify_ids.clear(); | 1182 verify_ids.clear(); |
1183 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 1183 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
1184 storage()->database_->GetPurgeableResourceIds(&verify_ids)); | 1184 storage()->database_->GetPurgeableResourceIds(&verify_ids)); |
1185 EXPECT_EQ(2u, verify_ids.size()); | 1185 EXPECT_EQ(2u, verify_ids.size()); |
1186 | 1186 |
1187 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); | 1187 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); |
1188 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id2_, true)); | 1188 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id2_, true)); |
1189 | 1189 |
1190 // Also add an uncommitted resource. | 1190 // Also add an uncommitted resource. |
1191 int64 kStaleUncommittedResourceId = storage()->NewResourceId(); | 1191 int64 kStaleUncommittedResourceId = storage()->NewResourceId(); |
1192 storage()->StoreUncommittedResponseId(kStaleUncommittedResourceId); | 1192 storage()->StoreUncommittedResourceId(kStaleUncommittedResourceId); |
1193 base::RunLoop().RunUntilIdle(); | 1193 base::RunLoop().RunUntilIdle(); |
1194 verify_ids.clear(); | 1194 verify_ids.clear(); |
1195 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 1195 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
1196 storage()->database_->GetUncommittedResourceIds(&verify_ids)); | 1196 storage()->database_->GetUncommittedResourceIds(&verify_ids)); |
1197 EXPECT_EQ(1u, verify_ids.size()); | 1197 EXPECT_EQ(1u, verify_ids.size()); |
1198 WriteBasicResponse(storage(), kStaleUncommittedResourceId); | 1198 WriteBasicResponse(storage(), kStaleUncommittedResourceId); |
1199 EXPECT_TRUE( | 1199 EXPECT_TRUE( |
1200 VerifyBasicResponse(storage(), kStaleUncommittedResourceId, true)); | 1200 VerifyBasicResponse(storage(), kStaleUncommittedResourceId, true)); |
1201 | 1201 |
1202 // Simulate browser shutdown. The purgeable and uncommitted resources are now | 1202 // Simulate browser shutdown. The purgeable and uncommitted resources are now |
1203 // stale. | 1203 // stale. |
1204 context_.reset(); | 1204 context_.reset(); |
1205 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager( | 1205 scoped_ptr<ServiceWorkerDatabaseTaskManager> database_task_manager( |
1206 new MockServiceWorkerDatabaseTaskManager( | 1206 new MockServiceWorkerDatabaseTaskManager( |
1207 base::ThreadTaskRunnerHandle::Get())); | 1207 base::ThreadTaskRunnerHandle::Get())); |
1208 context_.reset( | 1208 context_.reset( |
1209 new ServiceWorkerContextCore(GetUserDataDirectory(), | 1209 new ServiceWorkerContextCore(GetUserDataDirectory(), |
1210 database_task_manager.Pass(), | 1210 database_task_manager.Pass(), |
1211 base::ThreadTaskRunnerHandle::Get(), | 1211 base::ThreadTaskRunnerHandle::Get(), |
1212 NULL, | 1212 NULL, |
1213 NULL, | 1213 NULL, |
1214 NULL, | 1214 NULL, |
1215 NULL)); | 1215 NULL)); |
1216 storage()->LazyInitialize(base::Bind(&base::DoNothing)); | 1216 storage()->LazyInitialize(base::Bind(&base::DoNothing)); |
1217 base::RunLoop().RunUntilIdle(); | 1217 base::RunLoop().RunUntilIdle(); |
1218 | 1218 |
1219 // Store a new uncommitted resource. This triggers stale resource cleanup. | 1219 // Store a new uncommitted resource. This triggers stale resource cleanup. |
1220 int64 kNewResourceId = storage()->NewResourceId(); | 1220 int64 kNewResourceId = storage()->NewResourceId(); |
1221 WriteBasicResponse(storage(), kNewResourceId); | 1221 WriteBasicResponse(storage(), kNewResourceId); |
1222 storage()->StoreUncommittedResponseId(kNewResourceId); | 1222 storage()->StoreUncommittedResourceId(kNewResourceId); |
1223 base::RunLoop().RunUntilIdle(); | 1223 base::RunLoop().RunUntilIdle(); |
1224 | 1224 |
1225 // The stale resources should be purged, but the new resource should persist. | 1225 // The stale resources should be purged, but the new resource should persist. |
1226 verify_ids.clear(); | 1226 verify_ids.clear(); |
1227 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, | 1227 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, |
1228 storage()->database_->GetUncommittedResourceIds(&verify_ids)); | 1228 storage()->database_->GetUncommittedResourceIds(&verify_ids)); |
1229 ASSERT_EQ(1u, verify_ids.size()); | 1229 ASSERT_EQ(1u, verify_ids.size()); |
1230 EXPECT_EQ(kNewResourceId, *verify_ids.begin()); | 1230 EXPECT_EQ(kNewResourceId, *verify_ids.begin()); |
1231 | 1231 |
1232 // Purging resources needs interactions with SimpleCache's worker thread, | 1232 // Purging resources needs interactions with SimpleCache's worker thread, |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 storage()->NotifyDoneInstallingRegistration( | 1467 storage()->NotifyDoneInstallingRegistration( |
1468 live_registration3.get(), NULL, SERVICE_WORKER_OK); | 1468 live_registration3.get(), NULL, SERVICE_WORKER_OK); |
1469 | 1469 |
1470 // Find a registration among installed ones. | 1470 // Find a registration among installed ones. |
1471 EXPECT_EQ(SERVICE_WORKER_OK, | 1471 EXPECT_EQ(SERVICE_WORKER_OK, |
1472 FindRegistrationForDocument(kDocumentUrl, &found_registration)); | 1472 FindRegistrationForDocument(kDocumentUrl, &found_registration)); |
1473 EXPECT_EQ(live_registration2, found_registration); | 1473 EXPECT_EQ(live_registration2, found_registration); |
1474 } | 1474 } |
1475 | 1475 |
1476 } // namespace content | 1476 } // namespace content |
OLD | NEW |