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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 // Can be found by id too. | 376 // Can be found by id too. |
377 EXPECT_EQ(SERVICE_WORKER_OK, | 377 EXPECT_EQ(SERVICE_WORKER_OK, |
378 FindRegistrationForId( | 378 FindRegistrationForId( |
379 kRegistrationId, kScope.GetOrigin(), &found_registration)); | 379 kRegistrationId, kScope.GetOrigin(), &found_registration)); |
380 ASSERT_TRUE(found_registration.get()); | 380 ASSERT_TRUE(found_registration.get()); |
381 EXPECT_EQ(kRegistrationId, found_registration->id()); | 381 EXPECT_EQ(kRegistrationId, found_registration->id()); |
382 EXPECT_EQ(live_registration, found_registration); | 382 EXPECT_EQ(live_registration, found_registration); |
383 found_registration = NULL; | 383 found_registration = NULL; |
384 | 384 |
385 // Drop the live registration, but keep the version live. | 385 // Drop the live registration, but keep the version live. |
386 live_registration = NULL; | 386 live_registration = NULL; |
michaeln
2014/10/31 23:10:58
After this point, the size value will have to be r
dmurph
2014/10/31 23:41:02
Done.
| |
387 | 387 |
388 // Now FindRegistrationForDocument should be async. | 388 // Now FindRegistrationForDocument should be async. |
389 EXPECT_EQ(SERVICE_WORKER_OK, | 389 EXPECT_EQ(SERVICE_WORKER_OK, |
390 FindRegistrationForDocument(kDocumentUrl, &found_registration)); | 390 FindRegistrationForDocument(kDocumentUrl, &found_registration)); |
391 ASSERT_TRUE(found_registration.get()); | 391 ASSERT_TRUE(found_registration.get()); |
392 EXPECT_EQ(kRegistrationId, found_registration->id()); | 392 EXPECT_EQ(kRegistrationId, found_registration->id()); |
393 EXPECT_TRUE(found_registration->HasOneRef()); | 393 EXPECT_TRUE(found_registration->HasOneRef()); |
394 EXPECT_EQ(live_version.get(), found_registration->waiting_version()); | 394 EXPECT_EQ(live_version.get(), found_registration->waiting_version()); |
395 found_registration = NULL; | 395 found_registration = NULL; |
396 | 396 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 EXPECT_EQ(SERVICE_WORKER_OK, | 458 EXPECT_EQ(SERVICE_WORKER_OK, |
459 DeleteRegistration(kRegistrationId + 1, kScope.GetOrigin())); | 459 DeleteRegistration(kRegistrationId + 1, kScope.GetOrigin())); |
460 } | 460 } |
461 | 461 |
462 TEST_F(ServiceWorkerStorageTest, InstallingRegistrationsAreFindable) { | 462 TEST_F(ServiceWorkerStorageTest, InstallingRegistrationsAreFindable) { |
463 const GURL kScope("http://www.test.not/scope/"); | 463 const GURL kScope("http://www.test.not/scope/"); |
464 const GURL kScript("http://www.test.not/script.js"); | 464 const GURL kScript("http://www.test.not/script.js"); |
465 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); | 465 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); |
466 const int64 kRegistrationId = 0; | 466 const int64 kRegistrationId = 0; |
467 const int64 kVersionId = 0; | 467 const int64 kVersionId = 0; |
468 const int64 kWorkerSize = 12592; | |
468 | 469 |
469 scoped_refptr<ServiceWorkerRegistration> found_registration; | 470 scoped_refptr<ServiceWorkerRegistration> found_registration; |
470 | 471 |
471 // Create an unstored registration. | 472 // Create an unstored registration. |
472 scoped_refptr<ServiceWorkerRegistration> live_registration = | 473 scoped_refptr<ServiceWorkerRegistration> live_registration = |
473 new ServiceWorkerRegistration( | 474 new ServiceWorkerRegistration( |
474 kScope, kRegistrationId, context_ptr_); | 475 kScope, kRegistrationId, context_ptr_); |
476 live_registration->set_resources_total_size_bytes(kWorkerSize); | |
475 scoped_refptr<ServiceWorkerVersion> live_version = | 477 scoped_refptr<ServiceWorkerVersion> live_version = |
476 new ServiceWorkerVersion( | 478 new ServiceWorkerVersion( |
477 live_registration.get(), kScript, kVersionId, context_ptr_); | 479 live_registration.get(), kScript, kVersionId, context_ptr_); |
478 live_version->SetStatus(ServiceWorkerVersion::INSTALLING); | 480 live_version->SetStatus(ServiceWorkerVersion::INSTALLING); |
479 live_registration->SetWaitingVersion(live_version.get()); | 481 live_registration->SetWaitingVersion(live_version.get()); |
480 | 482 |
481 // Should not be findable, including by GetAllRegistrations. | 483 // Should not be findable, including by GetAllRegistrations. |
482 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, | 484 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
483 FindRegistrationForId( | 485 FindRegistrationForId( |
484 kRegistrationId, kScope.GetOrigin(), &found_registration)); | 486 kRegistrationId, kScope.GetOrigin(), &found_registration)); |
(...skipping 26 matching lines...) Expand all Loading... | |
511 EXPECT_EQ(live_registration, found_registration); | 513 EXPECT_EQ(live_registration, found_registration); |
512 found_registration = NULL; | 514 found_registration = NULL; |
513 | 515 |
514 EXPECT_EQ(SERVICE_WORKER_OK, | 516 EXPECT_EQ(SERVICE_WORKER_OK, |
515 FindRegistrationForPattern(kScope, &found_registration)); | 517 FindRegistrationForPattern(kScope, &found_registration)); |
516 EXPECT_EQ(live_registration, found_registration); | 518 EXPECT_EQ(live_registration, found_registration); |
517 found_registration = NULL; | 519 found_registration = NULL; |
518 | 520 |
519 GetAllRegistrations(&all_registrations); | 521 GetAllRegistrations(&all_registrations); |
520 EXPECT_EQ(1u, all_registrations.size()); | 522 EXPECT_EQ(1u, all_registrations.size()); |
523 ServiceWorkerRegistrationInfo info = all_registrations[0]; | |
524 EXPECT_EQ(kWorkerSize, info.stored_version_size_bytes); | |
michaeln
2014/10/31 23:10:58
This test hits the case where the ServiceWorkerReg
dmurph
2014/10/31 23:41:02
Done.
| |
521 all_registrations.clear(); | 525 all_registrations.clear(); |
522 | 526 |
523 // Notify storage of installation no longer happening. | 527 // Notify storage of installation no longer happening. |
524 storage()->NotifyDoneInstallingRegistration( | 528 storage()->NotifyDoneInstallingRegistration( |
525 live_registration.get(), NULL, SERVICE_WORKER_OK); | 529 live_registration.get(), NULL, SERVICE_WORKER_OK); |
526 | 530 |
527 // Once again, should not be findable. | 531 // Once again, should not be findable. |
528 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, | 532 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
529 FindRegistrationForId( | 533 FindRegistrationForId( |
530 kRegistrationId, kScope.GetOrigin(), &found_registration)); | 534 kRegistrationId, kScope.GetOrigin(), &found_registration)); |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1047 are_equal = true; | 1051 are_equal = true; |
1048 storage()->CompareScriptResources( | 1052 storage()->CompareScriptResources( |
1049 5, 6, | 1053 5, 6, |
1050 base::Bind(&OnCompareComplete, &status, &are_equal)); | 1054 base::Bind(&OnCompareComplete, &status, &are_equal)); |
1051 base::RunLoop().RunUntilIdle(); | 1055 base::RunLoop().RunUntilIdle(); |
1052 EXPECT_EQ(SERVICE_WORKER_OK, status); | 1056 EXPECT_EQ(SERVICE_WORKER_OK, status); |
1053 EXPECT_FALSE(are_equal); | 1057 EXPECT_FALSE(are_equal); |
1054 } | 1058 } |
1055 | 1059 |
1056 } // namespace content | 1060 } // namespace content |
OLD | NEW |