| 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/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 | 797 |
| 798 LazyInitialize(); | 798 LazyInitialize(); |
| 799 | 799 |
| 800 // Store a registration. | 800 // Store a registration. |
| 801 scoped_refptr<ServiceWorkerRegistration> live_registration = | 801 scoped_refptr<ServiceWorkerRegistration> live_registration = |
| 802 new ServiceWorkerRegistration( | 802 new ServiceWorkerRegistration( |
| 803 kScope, kRegistrationId, context_ptr_); | 803 kScope, kRegistrationId, context_ptr_); |
| 804 scoped_refptr<ServiceWorkerVersion> live_version = | 804 scoped_refptr<ServiceWorkerVersion> live_version = |
| 805 new ServiceWorkerVersion( | 805 new ServiceWorkerVersion( |
| 806 live_registration.get(), kScript, kVersionId, context_ptr_); | 806 live_registration.get(), kScript, kVersionId, context_ptr_); |
| 807 std::vector<ServiceWorkerDatabase::ResourceRecord> records; |
| 808 records.push_back(ServiceWorkerDatabase::ResourceRecord( |
| 809 1, live_version->script_url(), 100)); |
| 810 live_version->script_cache_map()->SetResources(records); |
| 807 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); | 811 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); |
| 808 live_registration->SetWaitingVersion(live_version); | 812 live_registration->SetWaitingVersion(live_version); |
| 809 EXPECT_EQ(SERVICE_WORKER_OK, | 813 EXPECT_EQ(SERVICE_WORKER_OK, |
| 810 StoreRegistration(live_registration, live_version)); | 814 StoreRegistration(live_registration, live_version)); |
| 811 | 815 |
| 812 // Store user data associated with the registration. | 816 // Store user data associated with the registration. |
| 813 std::string data_out; | 817 std::string data_out; |
| 814 EXPECT_EQ(SERVICE_WORKER_OK, | 818 EXPECT_EQ(SERVICE_WORKER_OK, |
| 815 StoreUserData(kRegistrationId, kScope.GetOrigin(), "key", "data")); | 819 StoreUserData(kRegistrationId, kScope.GetOrigin(), "key", "data")); |
| 816 EXPECT_EQ(SERVICE_WORKER_OK, GetUserData(kRegistrationId, "key", &data_out)); | 820 EXPECT_EQ(SERVICE_WORKER_OK, GetUserData(kRegistrationId, "key", &data_out)); |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1250 | 1254 |
| 1251 bool was_called = false; | 1255 bool was_called = false; |
| 1252 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; | 1256 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; |
| 1253 std::set<int64> verify_ids; | 1257 std::set<int64> verify_ids; |
| 1254 | 1258 |
| 1255 // Make an updated registration. | 1259 // Make an updated registration. |
| 1256 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( | 1260 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( |
| 1257 registration_.get(), script_, storage()->NewVersionId(), context_ptr_); | 1261 registration_.get(), script_, storage()->NewVersionId(), context_ptr_); |
| 1258 live_version->SetStatus(ServiceWorkerVersion::NEW); | 1262 live_version->SetStatus(ServiceWorkerVersion::NEW); |
| 1259 registration_->SetWaitingVersion(live_version); | 1263 registration_->SetWaitingVersion(live_version); |
| 1264 std::vector<ServiceWorkerDatabase::ResourceRecord> records; |
| 1265 records.push_back(ServiceWorkerDatabase::ResourceRecord( |
| 1266 10, live_version->script_url(), 100)); |
| 1267 live_version->script_cache_map()->SetResources(records); |
| 1260 | 1268 |
| 1261 // Writing the registration should move the old version's resources to the | 1269 // Writing the registration should move the old version's resources to the |
| 1262 // purgeable list but keep them available. | 1270 // purgeable list but keep them available. |
| 1263 storage()->StoreRegistration( | 1271 storage()->StoreRegistration( |
| 1264 registration_.get(), | 1272 registration_.get(), |
| 1265 registration_->waiting_version(), | 1273 registration_->waiting_version(), |
| 1266 base::Bind(&VerifyPurgeableListStatusCallback, | 1274 base::Bind(&VerifyPurgeableListStatusCallback, |
| 1267 base::Unretained(storage()->database_.get()), | 1275 base::Unretained(storage()->database_.get()), |
| 1268 &verify_ids, | 1276 &verify_ids, |
| 1269 &was_called, | 1277 &was_called, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 const GURL kScope1("http://www.example.com/scope/"); | 1310 const GURL kScope1("http://www.example.com/scope/"); |
| 1303 const GURL kScript1("http://www.example.com/script1.js"); | 1311 const GURL kScript1("http://www.example.com/script1.js"); |
| 1304 const int64 kRegistrationId1 = 1; | 1312 const int64 kRegistrationId1 = 1; |
| 1305 const int64 kVersionId1 = 1; | 1313 const int64 kVersionId1 = 1; |
| 1306 scoped_refptr<ServiceWorkerRegistration> live_registration1 = | 1314 scoped_refptr<ServiceWorkerRegistration> live_registration1 = |
| 1307 new ServiceWorkerRegistration( | 1315 new ServiceWorkerRegistration( |
| 1308 kScope1, kRegistrationId1, context_ptr_); | 1316 kScope1, kRegistrationId1, context_ptr_); |
| 1309 scoped_refptr<ServiceWorkerVersion> live_version1 = | 1317 scoped_refptr<ServiceWorkerVersion> live_version1 = |
| 1310 new ServiceWorkerVersion( | 1318 new ServiceWorkerVersion( |
| 1311 live_registration1.get(), kScript1, kVersionId1, context_ptr_); | 1319 live_registration1.get(), kScript1, kVersionId1, context_ptr_); |
| 1320 std::vector<ServiceWorkerDatabase::ResourceRecord> records1; |
| 1321 records1.push_back(ServiceWorkerDatabase::ResourceRecord( |
| 1322 1, live_version1->script_url(), 100)); |
| 1323 live_version1->script_cache_map()->SetResources(records1); |
| 1312 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); | 1324 live_version1->SetStatus(ServiceWorkerVersion::INSTALLED); |
| 1313 live_registration1->SetWaitingVersion(live_version1); | 1325 live_registration1->SetWaitingVersion(live_version1); |
| 1314 | 1326 |
| 1315 // Registration for "/scope/foo". | 1327 // Registration for "/scope/foo". |
| 1316 const GURL kScope2("http://www.example.com/scope/foo"); | 1328 const GURL kScope2("http://www.example.com/scope/foo"); |
| 1317 const GURL kScript2("http://www.example.com/script2.js"); | 1329 const GURL kScript2("http://www.example.com/script2.js"); |
| 1318 const int64 kRegistrationId2 = 2; | 1330 const int64 kRegistrationId2 = 2; |
| 1319 const int64 kVersionId2 = 2; | 1331 const int64 kVersionId2 = 2; |
| 1320 scoped_refptr<ServiceWorkerRegistration> live_registration2 = | 1332 scoped_refptr<ServiceWorkerRegistration> live_registration2 = |
| 1321 new ServiceWorkerRegistration( | 1333 new ServiceWorkerRegistration( |
| 1322 kScope2, kRegistrationId2, context_ptr_); | 1334 kScope2, kRegistrationId2, context_ptr_); |
| 1323 scoped_refptr<ServiceWorkerVersion> live_version2 = | 1335 scoped_refptr<ServiceWorkerVersion> live_version2 = |
| 1324 new ServiceWorkerVersion( | 1336 new ServiceWorkerVersion( |
| 1325 live_registration2.get(), kScript2, kVersionId2, context_ptr_); | 1337 live_registration2.get(), kScript2, kVersionId2, context_ptr_); |
| 1338 std::vector<ServiceWorkerDatabase::ResourceRecord> records2; |
| 1339 records2.push_back(ServiceWorkerDatabase::ResourceRecord( |
| 1340 2, live_version2->script_url(), 100)); |
| 1341 live_version2->script_cache_map()->SetResources(records2); |
| 1326 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); | 1342 live_version2->SetStatus(ServiceWorkerVersion::INSTALLED); |
| 1327 live_registration2->SetWaitingVersion(live_version2); | 1343 live_registration2->SetWaitingVersion(live_version2); |
| 1328 | 1344 |
| 1329 // Registration for "/scope/foobar". | 1345 // Registration for "/scope/foobar". |
| 1330 const GURL kScope3("http://www.example.com/scope/foobar"); | 1346 const GURL kScope3("http://www.example.com/scope/foobar"); |
| 1331 const GURL kScript3("http://www.example.com/script3.js"); | 1347 const GURL kScript3("http://www.example.com/script3.js"); |
| 1332 const int64 kRegistrationId3 = 3; | 1348 const int64 kRegistrationId3 = 3; |
| 1333 const int64 kVersionId3 = 3; | 1349 const int64 kVersionId3 = 3; |
| 1334 scoped_refptr<ServiceWorkerRegistration> live_registration3 = | 1350 scoped_refptr<ServiceWorkerRegistration> live_registration3 = |
| 1335 new ServiceWorkerRegistration( | 1351 new ServiceWorkerRegistration( |
| 1336 kScope3, kRegistrationId3, context_ptr_); | 1352 kScope3, kRegistrationId3, context_ptr_); |
| 1337 scoped_refptr<ServiceWorkerVersion> live_version3 = | 1353 scoped_refptr<ServiceWorkerVersion> live_version3 = |
| 1338 new ServiceWorkerVersion( | 1354 new ServiceWorkerVersion( |
| 1339 live_registration3.get(), kScript3, kVersionId3, context_ptr_); | 1355 live_registration3.get(), kScript3, kVersionId3, context_ptr_); |
| 1356 std::vector<ServiceWorkerDatabase::ResourceRecord> records3; |
| 1357 records3.push_back(ServiceWorkerDatabase::ResourceRecord( |
| 1358 3, live_version3->script_url(), 100)); |
| 1359 live_version3->script_cache_map()->SetResources(records3); |
| 1340 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); | 1360 live_version3->SetStatus(ServiceWorkerVersion::INSTALLED); |
| 1341 live_registration3->SetWaitingVersion(live_version3); | 1361 live_registration3->SetWaitingVersion(live_version3); |
| 1342 | 1362 |
| 1343 // Notify storage of they being installed. | 1363 // Notify storage of they being installed. |
| 1344 storage()->NotifyInstallingRegistration(live_registration1.get()); | 1364 storage()->NotifyInstallingRegistration(live_registration1.get()); |
| 1345 storage()->NotifyInstallingRegistration(live_registration2.get()); | 1365 storage()->NotifyInstallingRegistration(live_registration2.get()); |
| 1346 storage()->NotifyInstallingRegistration(live_registration3.get()); | 1366 storage()->NotifyInstallingRegistration(live_registration3.get()); |
| 1347 | 1367 |
| 1348 // Find a registration among installing ones. | 1368 // Find a registration among installing ones. |
| 1349 EXPECT_EQ(SERVICE_WORKER_OK, | 1369 EXPECT_EQ(SERVICE_WORKER_OK, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1429 are_equal = true; | 1449 are_equal = true; |
| 1430 storage()->CompareScriptResources( | 1450 storage()->CompareScriptResources( |
| 1431 5, 6, | 1451 5, 6, |
| 1432 base::Bind(&OnCompareComplete, &status, &are_equal)); | 1452 base::Bind(&OnCompareComplete, &status, &are_equal)); |
| 1433 base::RunLoop().RunUntilIdle(); | 1453 base::RunLoop().RunUntilIdle(); |
| 1434 EXPECT_EQ(SERVICE_WORKER_OK, status); | 1454 EXPECT_EQ(SERVICE_WORKER_OK, status); |
| 1435 EXPECT_FALSE(are_equal); | 1455 EXPECT_FALSE(are_equal); |
| 1436 } | 1456 } |
| 1437 | 1457 |
| 1438 } // namespace content | 1458 } // namespace content |
| OLD | NEW |