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 "content/browser/service_worker/service_worker_storage.h" | 5 #include "content/browser/service_worker/service_worker_storage.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 const GURL kScope("http://www.test.not/scope/"); | 497 const GURL kScope("http://www.test.not/scope/"); |
498 const GURL kScript("http://www.test.not/script.js"); | 498 const GURL kScript("http://www.test.not/script.js"); |
499 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); | 499 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); |
500 const GURL kResource1("http://www.test.not/scope/resource1.js"); | 500 const GURL kResource1("http://www.test.not/scope/resource1.js"); |
501 const int64_t kResource1Size = 1591234; | 501 const int64_t kResource1Size = 1591234; |
502 const GURL kResource2("http://www.test.not/scope/resource2.js"); | 502 const GURL kResource2("http://www.test.not/scope/resource2.js"); |
503 const int64_t kResource2Size = 51; | 503 const int64_t kResource2Size = 51; |
504 const int64_t kRegistrationId = 0; | 504 const int64_t kRegistrationId = 0; |
505 const int64_t kVersionId = 0; | 505 const int64_t kVersionId = 0; |
506 const GURL kForeignFetchScope("http://www.test.not/scope/ff/"); | 506 const GURL kForeignFetchScope("http://www.test.not/scope/ff/"); |
| 507 const url::Origin kForeignFetchOrigin(GURL("https://example.com/")); |
507 const base::Time kToday = base::Time::Now(); | 508 const base::Time kToday = base::Time::Now(); |
508 const base::Time kYesterday = kToday - base::TimeDelta::FromDays(1); | 509 const base::Time kYesterday = kToday - base::TimeDelta::FromDays(1); |
509 | 510 |
510 scoped_refptr<ServiceWorkerRegistration> found_registration; | 511 scoped_refptr<ServiceWorkerRegistration> found_registration; |
511 | 512 |
512 // We shouldn't find anything without having stored anything. | 513 // We shouldn't find anything without having stored anything. |
513 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, | 514 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
514 FindRegistrationForDocument(kDocumentUrl, &found_registration)); | 515 FindRegistrationForDocument(kDocumentUrl, &found_registration)); |
515 EXPECT_FALSE(found_registration.get()); | 516 EXPECT_FALSE(found_registration.get()); |
516 | 517 |
(...skipping 15 matching lines...) Expand all Loading... |
532 // Store something. | 533 // Store something. |
533 scoped_refptr<ServiceWorkerRegistration> live_registration = | 534 scoped_refptr<ServiceWorkerRegistration> live_registration = |
534 new ServiceWorkerRegistration(kScope, kRegistrationId, | 535 new ServiceWorkerRegistration(kScope, kRegistrationId, |
535 context()->AsWeakPtr()); | 536 context()->AsWeakPtr()); |
536 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( | 537 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( |
537 live_registration.get(), kScript, kVersionId, context()->AsWeakPtr()); | 538 live_registration.get(), kScript, kVersionId, context()->AsWeakPtr()); |
538 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); | 539 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); |
539 live_version->script_cache_map()->SetResources(resources); | 540 live_version->script_cache_map()->SetResources(resources); |
540 live_version->set_foreign_fetch_scopes( | 541 live_version->set_foreign_fetch_scopes( |
541 std::vector<GURL>(1, kForeignFetchScope)); | 542 std::vector<GURL>(1, kForeignFetchScope)); |
| 543 live_version->set_foreign_fetch_origins( |
| 544 std::vector<url::Origin>(1, kForeignFetchOrigin)); |
542 live_registration->SetWaitingVersion(live_version); | 545 live_registration->SetWaitingVersion(live_version); |
543 live_registration->set_last_update_check(kYesterday); | 546 live_registration->set_last_update_check(kYesterday); |
544 EXPECT_EQ(SERVICE_WORKER_OK, | 547 EXPECT_EQ(SERVICE_WORKER_OK, |
545 StoreRegistration(live_registration, live_version)); | 548 StoreRegistration(live_registration, live_version)); |
546 | 549 |
547 // Now we should find it and get the live ptr back immediately. | 550 // Now we should find it and get the live ptr back immediately. |
548 EXPECT_EQ(SERVICE_WORKER_OK, | 551 EXPECT_EQ(SERVICE_WORKER_OK, |
549 FindRegistrationForDocument(kDocumentUrl, &found_registration)); | 552 FindRegistrationForDocument(kDocumentUrl, &found_registration)); |
550 EXPECT_EQ(live_registration, found_registration); | 553 EXPECT_EQ(live_registration, found_registration); |
551 EXPECT_EQ(kResource1Size + kResource2Size, | 554 EXPECT_EQ(kResource1Size + kResource2Size, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 EXPECT_TRUE(found_registration->HasOneRef()); | 625 EXPECT_TRUE(found_registration->HasOneRef()); |
623 EXPECT_FALSE(found_registration->active_version()); | 626 EXPECT_FALSE(found_registration->active_version()); |
624 ASSERT_TRUE(found_registration->waiting_version()); | 627 ASSERT_TRUE(found_registration->waiting_version()); |
625 EXPECT_EQ(kYesterday, found_registration->last_update_check()); | 628 EXPECT_EQ(kYesterday, found_registration->last_update_check()); |
626 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, | 629 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, |
627 found_registration->waiting_version()->status()); | 630 found_registration->waiting_version()->status()); |
628 EXPECT_EQ( | 631 EXPECT_EQ( |
629 1u, found_registration->waiting_version()->foreign_fetch_scopes().size()); | 632 1u, found_registration->waiting_version()->foreign_fetch_scopes().size()); |
630 EXPECT_EQ(kForeignFetchScope, | 633 EXPECT_EQ(kForeignFetchScope, |
631 found_registration->waiting_version()->foreign_fetch_scopes()[0]); | 634 found_registration->waiting_version()->foreign_fetch_scopes()[0]); |
| 635 EXPECT_EQ( |
| 636 1u, |
| 637 found_registration->waiting_version()->foreign_fetch_origins().size()); |
| 638 EXPECT_EQ(kForeignFetchOrigin, |
| 639 found_registration->waiting_version()->foreign_fetch_origins()[0]); |
632 | 640 |
633 // Update to active and update the last check time. | 641 // Update to active and update the last check time. |
634 scoped_refptr<ServiceWorkerVersion> temp_version = | 642 scoped_refptr<ServiceWorkerVersion> temp_version = |
635 found_registration->waiting_version(); | 643 found_registration->waiting_version(); |
636 temp_version->SetStatus(ServiceWorkerVersion::ACTIVATED); | 644 temp_version->SetStatus(ServiceWorkerVersion::ACTIVATED); |
637 found_registration->SetActiveVersion(temp_version); | 645 found_registration->SetActiveVersion(temp_version); |
638 temp_version = NULL; | 646 temp_version = NULL; |
639 EXPECT_EQ(SERVICE_WORKER_OK, UpdateToActiveState(found_registration)); | 647 EXPECT_EQ(SERVICE_WORKER_OK, UpdateToActiveState(found_registration)); |
640 found_registration->set_last_update_check(kToday); | 648 found_registration->set_last_update_check(kToday); |
641 UpdateLastUpdateCheckTime(found_registration.get()); | 649 UpdateLastUpdateCheckTime(found_registration.get()); |
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 // Remove other registration at first origin. | 1576 // Remove other registration at first origin. |
1569 EXPECT_EQ(SERVICE_WORKER_OK, | 1577 EXPECT_EQ(SERVICE_WORKER_OK, |
1570 DeleteRegistration(kRegistrationId2, kScope2.GetOrigin())); | 1578 DeleteRegistration(kRegistrationId2, kScope2.GetOrigin())); |
1571 | 1579 |
1572 // No foreign fetch registrations remain. | 1580 // No foreign fetch registrations remain. |
1573 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin1)); | 1581 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin1)); |
1574 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin2)); | 1582 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin2)); |
1575 } | 1583 } |
1576 | 1584 |
1577 } // namespace content | 1585 } // namespace content |
OLD | NEW |