| 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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 const GURL kResource1("http://www.test.not/scope/resource1.js"); | 629 const GURL kResource1("http://www.test.not/scope/resource1.js"); |
| 630 const int64_t kResource1Size = 1591234; | 630 const int64_t kResource1Size = 1591234; |
| 631 const GURL kResource2("http://www.test.not/scope/resource2.js"); | 631 const GURL kResource2("http://www.test.not/scope/resource2.js"); |
| 632 const int64_t kResource2Size = 51; | 632 const int64_t kResource2Size = 51; |
| 633 const int64_t kRegistrationId = 0; | 633 const int64_t kRegistrationId = 0; |
| 634 const int64_t kVersionId = 0; | 634 const int64_t kVersionId = 0; |
| 635 const GURL kForeignFetchScope("http://www.test.not/scope/ff/"); | 635 const GURL kForeignFetchScope("http://www.test.not/scope/ff/"); |
| 636 const url::Origin kForeignFetchOrigin(GURL("https://example.com/")); | 636 const url::Origin kForeignFetchOrigin(GURL("https://example.com/")); |
| 637 const base::Time kToday = base::Time::Now(); | 637 const base::Time kToday = base::Time::Now(); |
| 638 const base::Time kYesterday = kToday - base::TimeDelta::FromDays(1); | 638 const base::Time kYesterday = kToday - base::TimeDelta::FromDays(1); |
| 639 std::set<uint32_t> used_features = {124, 901, 1019}; |
| 639 | 640 |
| 640 scoped_refptr<ServiceWorkerRegistration> found_registration; | 641 scoped_refptr<ServiceWorkerRegistration> found_registration; |
| 641 | 642 |
| 642 // We shouldn't find anything without having stored anything. | 643 // We shouldn't find anything without having stored anything. |
| 643 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, | 644 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
| 644 FindRegistrationForDocument(kDocumentUrl, &found_registration)); | 645 FindRegistrationForDocument(kDocumentUrl, &found_registration)); |
| 645 EXPECT_FALSE(found_registration.get()); | 646 EXPECT_FALSE(found_registration.get()); |
| 646 | 647 |
| 647 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, | 648 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, |
| 648 FindRegistrationForPattern(kScope, &found_registration)); | 649 FindRegistrationForPattern(kScope, &found_registration)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 666 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( | 667 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( |
| 667 live_registration.get(), kResource1, kVersionId, context()->AsWeakPtr()); | 668 live_registration.get(), kResource1, kVersionId, context()->AsWeakPtr()); |
| 668 live_version->set_fetch_handler_existence( | 669 live_version->set_fetch_handler_existence( |
| 669 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); | 670 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); |
| 670 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); | 671 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); |
| 671 live_version->script_cache_map()->SetResources(resources); | 672 live_version->script_cache_map()->SetResources(resources); |
| 672 live_version->set_foreign_fetch_scopes( | 673 live_version->set_foreign_fetch_scopes( |
| 673 std::vector<GURL>(1, kForeignFetchScope)); | 674 std::vector<GURL>(1, kForeignFetchScope)); |
| 674 live_version->set_foreign_fetch_origins( | 675 live_version->set_foreign_fetch_origins( |
| 675 std::vector<url::Origin>(1, kForeignFetchOrigin)); | 676 std::vector<url::Origin>(1, kForeignFetchOrigin)); |
| 677 live_version->set_used_features(used_features); |
| 676 live_registration->SetWaitingVersion(live_version); | 678 live_registration->SetWaitingVersion(live_version); |
| 677 live_registration->set_last_update_check(kYesterday); | 679 live_registration->set_last_update_check(kYesterday); |
| 678 EXPECT_EQ(SERVICE_WORKER_OK, | 680 EXPECT_EQ(SERVICE_WORKER_OK, |
| 679 StoreRegistration(live_registration, live_version)); | 681 StoreRegistration(live_registration, live_version)); |
| 680 | 682 |
| 681 // Now we should find it and get the live ptr back immediately. | 683 // Now we should find it and get the live ptr back immediately. |
| 682 EXPECT_EQ(SERVICE_WORKER_OK, | 684 EXPECT_EQ(SERVICE_WORKER_OK, |
| 683 FindRegistrationForDocument(kDocumentUrl, &found_registration)); | 685 FindRegistrationForDocument(kDocumentUrl, &found_registration)); |
| 684 EXPECT_EQ(live_registration, found_registration); | 686 EXPECT_EQ(live_registration, found_registration); |
| 685 EXPECT_EQ(kResource1Size + kResource2Size, | 687 EXPECT_EQ(kResource1Size + kResource2Size, |
| 686 live_registration->resources_total_size_bytes()); | 688 live_registration->resources_total_size_bytes()); |
| 687 EXPECT_EQ(kResource1Size + kResource2Size, | 689 EXPECT_EQ(kResource1Size + kResource2Size, |
| 688 found_registration->resources_total_size_bytes()); | 690 found_registration->resources_total_size_bytes()); |
| 691 EXPECT_EQ(used_features, |
| 692 found_registration->waiting_version()->used_features()); |
| 689 found_registration = NULL; | 693 found_registration = NULL; |
| 690 | 694 |
| 691 // But FindRegistrationForPattern is always async. | 695 // But FindRegistrationForPattern is always async. |
| 692 EXPECT_EQ(SERVICE_WORKER_OK, | 696 EXPECT_EQ(SERVICE_WORKER_OK, |
| 693 FindRegistrationForPattern(kScope, &found_registration)); | 697 FindRegistrationForPattern(kScope, &found_registration)); |
| 694 EXPECT_EQ(live_registration, found_registration); | 698 EXPECT_EQ(live_registration, found_registration); |
| 695 found_registration = NULL; | 699 found_registration = NULL; |
| 696 | 700 |
| 697 // Can be found by id too. | 701 // Can be found by id too. |
| 698 EXPECT_EQ(SERVICE_WORKER_OK, | 702 EXPECT_EQ(SERVICE_WORKER_OK, |
| (...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2128 EXPECT_TRUE(registration_state.enabled); | 2132 EXPECT_TRUE(registration_state.enabled); |
| 2129 EXPECT_EQ(kHeaderValue, registration_state.header); | 2133 EXPECT_EQ(kHeaderValue, registration_state.header); |
| 2130 ASSERT_TRUE(found_registration->active_version()); | 2134 ASSERT_TRUE(found_registration->active_version()); |
| 2131 const NavigationPreloadState& state = | 2135 const NavigationPreloadState& state = |
| 2132 found_registration->active_version()->navigation_preload_state(); | 2136 found_registration->active_version()->navigation_preload_state(); |
| 2133 EXPECT_TRUE(state.enabled); | 2137 EXPECT_TRUE(state.enabled); |
| 2134 EXPECT_EQ(kHeaderValue, state.header); | 2138 EXPECT_EQ(kHeaderValue, state.header); |
| 2135 } | 2139 } |
| 2136 | 2140 |
| 2137 } // namespace content | 2141 } // namespace content |
| OLD | NEW |