Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1346)

Side by Side Diff: content/browser/service_worker/service_worker_storage_unittest.cc

Issue 2658603003: ServiceWorker: Enable UseCounter for ServiceWorkerGlobalScope (Closed)
Patch Set: ready to review Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion( 666 scoped_refptr<ServiceWorkerVersion> live_version = new ServiceWorkerVersion(
667 live_registration.get(), kResource1, kVersionId, context()->AsWeakPtr()); 667 live_registration.get(), kResource1, kVersionId, context()->AsWeakPtr());
668 live_version->set_fetch_handler_existence( 668 live_version->set_fetch_handler_existence(
669 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 669 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
670 live_version->SetStatus(ServiceWorkerVersion::INSTALLED); 670 live_version->SetStatus(ServiceWorkerVersion::INSTALLED);
671 live_version->script_cache_map()->SetResources(resources); 671 live_version->script_cache_map()->SetResources(resources);
672 live_version->set_foreign_fetch_scopes( 672 live_version->set_foreign_fetch_scopes(
673 std::vector<GURL>(1, kForeignFetchScope)); 673 std::vector<GURL>(1, kForeignFetchScope));
674 live_version->set_foreign_fetch_origins( 674 live_version->set_foreign_fetch_origins(
675 std::vector<url::Origin>(1, kForeignFetchOrigin)); 675 std::vector<url::Origin>(1, kForeignFetchOrigin));
676 live_version->set_used_features({124, 901, 1019});
676 live_registration->SetWaitingVersion(live_version); 677 live_registration->SetWaitingVersion(live_version);
677 live_registration->set_last_update_check(kYesterday); 678 live_registration->set_last_update_check(kYesterday);
678 EXPECT_EQ(SERVICE_WORKER_OK, 679 EXPECT_EQ(SERVICE_WORKER_OK,
679 StoreRegistration(live_registration, live_version)); 680 StoreRegistration(live_registration, live_version));
680 681
681 // Now we should find it and get the live ptr back immediately. 682 // Now we should find it and get the live ptr back immediately.
682 EXPECT_EQ(SERVICE_WORKER_OK, 683 EXPECT_EQ(SERVICE_WORKER_OK,
683 FindRegistrationForDocument(kDocumentUrl, &found_registration)); 684 FindRegistrationForDocument(kDocumentUrl, &found_registration));
684 EXPECT_EQ(live_registration, found_registration); 685 EXPECT_EQ(live_registration, found_registration);
685 EXPECT_EQ(kResource1Size + kResource2Size, 686 EXPECT_EQ(kResource1Size + kResource2Size,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 EXPECT_EQ(ServiceWorkerVersion::INSTALLED, 764 EXPECT_EQ(ServiceWorkerVersion::INSTALLED,
764 found_registration->waiting_version()->status()); 765 found_registration->waiting_version()->status());
765 EXPECT_EQ( 766 EXPECT_EQ(
766 1u, found_registration->waiting_version()->foreign_fetch_scopes().size()); 767 1u, found_registration->waiting_version()->foreign_fetch_scopes().size());
767 EXPECT_EQ(kForeignFetchScope, 768 EXPECT_EQ(kForeignFetchScope,
768 found_registration->waiting_version()->foreign_fetch_scopes()[0]); 769 found_registration->waiting_version()->foreign_fetch_scopes()[0]);
769 EXPECT_EQ( 770 EXPECT_EQ(
770 1u, 771 1u,
771 found_registration->waiting_version()->foreign_fetch_origins().size()); 772 found_registration->waiting_version()->foreign_fetch_origins().size());
772 EXPECT_EQ(kForeignFetchOrigin, 773 EXPECT_EQ(kForeignFetchOrigin,
773 found_registration->waiting_version()->foreign_fetch_origins()[0]); 774 found_registration->waiting_version()->foreign_fetch_origins()[0]);
falken 2017/02/08 05:01:53 Should we check the used features somewhere in thi
nhiroki 2017/02/09 05:11:31 Yeah, I should have checked it. Done.
774 775
775 // Update to active and update the last check time. 776 // Update to active and update the last check time.
776 scoped_refptr<ServiceWorkerVersion> temp_version = 777 scoped_refptr<ServiceWorkerVersion> temp_version =
777 found_registration->waiting_version(); 778 found_registration->waiting_version();
778 temp_version->SetStatus(ServiceWorkerVersion::ACTIVATED); 779 temp_version->SetStatus(ServiceWorkerVersion::ACTIVATED);
779 found_registration->SetActiveVersion(temp_version); 780 found_registration->SetActiveVersion(temp_version);
780 temp_version = NULL; 781 temp_version = NULL;
781 EXPECT_EQ(SERVICE_WORKER_OK, UpdateToActiveState(found_registration)); 782 EXPECT_EQ(SERVICE_WORKER_OK, UpdateToActiveState(found_registration));
782 found_registration->set_last_update_check(kToday); 783 found_registration->set_last_update_check(kToday);
783 UpdateLastUpdateCheckTime(found_registration.get()); 784 UpdateLastUpdateCheckTime(found_registration.get());
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 resource_id1_size_ = 239193; 1140 resource_id1_size_ = 239193;
1140 resource_id2_size_ = 59923; 1141 resource_id2_size_ = 59923;
1141 1142
1142 // Cons up a new registration+version with two script resources. 1143 // Cons up a new registration+version with two script resources.
1143 RegistrationData data; 1144 RegistrationData data;
1144 data.registration_id = registration_id_; 1145 data.registration_id = registration_id_;
1145 data.scope = scope_; 1146 data.scope = scope_;
1146 data.script = script_; 1147 data.script = script_;
1147 data.version_id = version_id_; 1148 data.version_id = version_id_;
1148 data.is_active = false; 1149 data.is_active = false;
1150 data.used_features = {109, 421, 9101};
1149 std::vector<ResourceRecord> resources; 1151 std::vector<ResourceRecord> resources;
1150 resources.push_back( 1152 resources.push_back(
1151 ResourceRecord(resource_id1_, script_, resource_id1_size_)); 1153 ResourceRecord(resource_id1_, script_, resource_id1_size_));
1152 resources.push_back( 1154 resources.push_back(
1153 ResourceRecord(resource_id2_, import_, resource_id2_size_)); 1155 ResourceRecord(resource_id2_, import_, resource_id2_size_));
1154 registration_ = storage()->GetOrCreateRegistration(data, resources); 1156 registration_ = storage()->GetOrCreateRegistration(data, resources);
1155 registration_->waiting_version()->SetStatus(ServiceWorkerVersion::NEW); 1157 registration_->waiting_version()->SetStatus(ServiceWorkerVersion::NEW);
1156 1158
1157 // Add the resources ids to the uncommitted list. 1159 // Add the resources ids to the uncommitted list.
1158 storage()->StoreUncommittedResourceId(resource_id1_); 1160 storage()->StoreUncommittedResourceId(resource_id1_);
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 registration_.get(), script_, storage()->NewVersionId(), 1572 registration_.get(), script_, storage()->NewVersionId(),
1571 context()->AsWeakPtr()); 1573 context()->AsWeakPtr());
1572 live_version->SetStatus(ServiceWorkerVersion::NEW); 1574 live_version->SetStatus(ServiceWorkerVersion::NEW);
1573 registration_->SetWaitingVersion(live_version); 1575 registration_->SetWaitingVersion(live_version);
1574 std::vector<ServiceWorkerDatabase::ResourceRecord> records; 1576 std::vector<ServiceWorkerDatabase::ResourceRecord> records;
1575 records.push_back(ServiceWorkerDatabase::ResourceRecord( 1577 records.push_back(ServiceWorkerDatabase::ResourceRecord(
1576 10, live_version->script_url(), 100)); 1578 10, live_version->script_url(), 100));
1577 live_version->script_cache_map()->SetResources(records); 1579 live_version->script_cache_map()->SetResources(records);
1578 live_version->set_fetch_handler_existence( 1580 live_version->set_fetch_handler_existence(
1579 ServiceWorkerVersion::FetchHandlerExistence::EXISTS); 1581 ServiceWorkerVersion::FetchHandlerExistence::EXISTS);
1582 live_version->set_used_features({124, 901, 1019});
falken 2017/02/08 05:01:53 Just curious why we set the used features here. Sh
nhiroki 2017/02/09 05:11:31 Yeah, this doesn't really make sense. I meant to c
1580 1583
1581 // Writing the registration should move the old version's resources to the 1584 // Writing the registration should move the old version's resources to the
1582 // purgeable list but keep them available. 1585 // purgeable list but keep them available.
1583 storage()->StoreRegistration( 1586 storage()->StoreRegistration(
1584 registration_.get(), 1587 registration_.get(),
1585 registration_->waiting_version(), 1588 registration_->waiting_version(),
1586 base::Bind(&VerifyPurgeableListStatusCallback, 1589 base::Bind(&VerifyPurgeableListStatusCallback,
1587 base::Unretained(storage()->database_.get()), 1590 base::Unretained(storage()->database_.get()),
1588 &verify_ids, 1591 &verify_ids,
1589 &was_called, 1592 &was_called,
1590 &result)); 1593 &result));
1591 base::RunLoop().RunUntilIdle(); 1594 base::RunLoop().RunUntilIdle();
1592 ASSERT_TRUE(was_called); 1595 ASSERT_TRUE(was_called);
1593 EXPECT_EQ(SERVICE_WORKER_OK, result); 1596 EXPECT_EQ(SERVICE_WORKER_OK, result);
1594 EXPECT_EQ(2u, verify_ids.size()); 1597 EXPECT_EQ(2u, verify_ids.size());
1595 verify_ids.clear(); 1598 verify_ids.clear();
1596 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 1599 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
1597 storage()->database_->GetPurgeableResourceIds(&verify_ids)); 1600 storage()->database_->GetPurgeableResourceIds(&verify_ids));
1598 EXPECT_EQ(2u, verify_ids.size()); 1601 EXPECT_EQ(2u, verify_ids.size());
1599 1602
1600 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, false)); 1603 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, false));
1601 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id2_, false)); 1604 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id2_, false));
1602 1605
1606 scoped_refptr<ServiceWorkerRegistration> found_registration;
1607 EXPECT_EQ(SERVICE_WORKER_OK,
1608 FindRegistrationForDocument(document_url_, &found_registration));
1609 EXPECT_EQ(registration_, found_registration);
1610
1603 // Removing the controllee should cause the old version's resources to be 1611 // Removing the controllee should cause the old version's resources to be
1604 // deleted. 1612 // deleted.
1605 registration_->active_version()->RemoveControllee(host.get()); 1613 registration_->active_version()->RemoveControllee(host.get());
1606 registration_->active_version()->Doom(); 1614 registration_->active_version()->Doom();
1607 base::RunLoop().RunUntilIdle(); 1615 base::RunLoop().RunUntilIdle();
1608 verify_ids.clear(); 1616 verify_ids.clear();
1609 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 1617 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
1610 storage()->database_->GetPurgeableResourceIds(&verify_ids)); 1618 storage()->database_->GetPurgeableResourceIds(&verify_ids));
1611 EXPECT_TRUE(verify_ids.empty()); 1619 EXPECT_TRUE(verify_ids.empty());
1612 1620
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 EXPECT_TRUE(registration_state.enabled); 2136 EXPECT_TRUE(registration_state.enabled);
2129 EXPECT_EQ(kHeaderValue, registration_state.header); 2137 EXPECT_EQ(kHeaderValue, registration_state.header);
2130 ASSERT_TRUE(found_registration->active_version()); 2138 ASSERT_TRUE(found_registration->active_version());
2131 const NavigationPreloadState& state = 2139 const NavigationPreloadState& state =
2132 found_registration->active_version()->navigation_preload_state(); 2140 found_registration->active_version()->navigation_preload_state();
2133 EXPECT_TRUE(state.enabled); 2141 EXPECT_TRUE(state.enabled);
2134 EXPECT_EQ(kHeaderValue, state.header); 2142 EXPECT_EQ(kHeaderValue, state.header);
2135 } 2143 }
2136 2144
2137 } // namespace content 2145 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698