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

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

Issue 2627543002: ServiceWorker: Returns true for IsMojoForServiceWorkerEnabled (Closed)
Patch Set: Created 3 years, 11 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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 &newly_purgeable_resources)); 538 &newly_purgeable_resources));
539 } 539 }
540 540
541 // user_data_directory_ must be declared first to preserve destructor order. 541 // user_data_directory_ must be declared first to preserve destructor order.
542 base::ScopedTempDir user_data_directory_; 542 base::ScopedTempDir user_data_directory_;
543 base::FilePath user_data_directory_path_; 543 base::FilePath user_data_directory_path_;
544 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; 544 std::unique_ptr<EmbeddedWorkerTestHelper> helper_;
545 TestBrowserThreadBundle browser_thread_bundle_; 545 TestBrowserThreadBundle browser_thread_bundle_;
546 }; 546 };
547 547
548 class ServiceWorkerStorageTestP 548 TEST_F(ServiceWorkerStorageTest, DisabledStorage) {
549 : public MojoServiceWorkerTestP<ServiceWorkerStorageTest> {};
550
551 TEST_P(ServiceWorkerStorageTestP, DisabledStorage) {
552 const GURL kScope("http://www.example.com/scope/"); 549 const GURL kScope("http://www.example.com/scope/");
553 const GURL kScript("http://www.example.com/script.js"); 550 const GURL kScript("http://www.example.com/script.js");
554 const GURL kDocumentUrl("http://www.example.com/scope/document.html"); 551 const GURL kDocumentUrl("http://www.example.com/scope/document.html");
555 const int64_t kRegistrationId = 0; 552 const int64_t kRegistrationId = 0;
556 const int64_t kVersionId = 0; 553 const int64_t kVersionId = 0;
557 const int64_t kResourceId = 0; 554 const int64_t kResourceId = 0;
558 555
559 LazyInitialize(); 556 LazyInitialize();
560 storage()->Disable(); 557 storage()->Disable();
561 558
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 EXPECT_FALSE( 616 EXPECT_FALSE(
620 storage()->OriginHasForeignFetchRegistrations(kScope.GetOrigin())); 617 storage()->OriginHasForeignFetchRegistrations(kScope.GetOrigin()));
621 618
622 // Next available ids should be invalid. 619 // Next available ids should be invalid.
623 EXPECT_EQ(kInvalidServiceWorkerRegistrationId, 620 EXPECT_EQ(kInvalidServiceWorkerRegistrationId,
624 storage()->NewRegistrationId()); 621 storage()->NewRegistrationId());
625 EXPECT_EQ(kInvalidServiceWorkerVersionId, storage()->NewVersionId()); 622 EXPECT_EQ(kInvalidServiceWorkerVersionId, storage()->NewVersionId());
626 EXPECT_EQ(kInvalidServiceWorkerResourceId, storage()->NewRegistrationId()); 623 EXPECT_EQ(kInvalidServiceWorkerResourceId, storage()->NewRegistrationId());
627 } 624 }
628 625
629 TEST_P(ServiceWorkerStorageTestP, StoreFindUpdateDeleteRegistration) { 626 TEST_F(ServiceWorkerStorageTest, StoreFindUpdateDeleteRegistration) {
630 const GURL kScope("http://www.test.not/scope/"); 627 const GURL kScope("http://www.test.not/scope/");
631 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); 628 const GURL kDocumentUrl("http://www.test.not/scope/document.html");
632 const GURL kResource1("http://www.test.not/scope/resource1.js"); 629 const GURL kResource1("http://www.test.not/scope/resource1.js");
633 const int64_t kResource1Size = 1591234; 630 const int64_t kResource1Size = 1591234;
634 const GURL kResource2("http://www.test.not/scope/resource2.js"); 631 const GURL kResource2("http://www.test.not/scope/resource2.js");
635 const int64_t kResource2Size = 51; 632 const int64_t kResource2Size = 51;
636 const int64_t kRegistrationId = 0; 633 const int64_t kRegistrationId = 0;
637 const int64_t kVersionId = 0; 634 const int64_t kVersionId = 0;
638 const GURL kForeignFetchScope("http://www.test.not/scope/ff/"); 635 const GURL kForeignFetchScope("http://www.test.not/scope/ff/");
639 const url::Origin kForeignFetchOrigin(GURL("https://example.com/")); 636 const url::Origin kForeignFetchOrigin(GURL("https://example.com/"));
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 EXPECT_FALSE(found_registration.get()); 818 EXPECT_FALSE(found_registration.get());
822 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, 819 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND,
823 FindRegistrationForIdOnly(kRegistrationId, &found_registration)); 820 FindRegistrationForIdOnly(kRegistrationId, &found_registration));
824 EXPECT_FALSE(found_registration.get()); 821 EXPECT_FALSE(found_registration.get());
825 822
826 // Deleting an unstored registration should succeed. 823 // Deleting an unstored registration should succeed.
827 EXPECT_EQ(SERVICE_WORKER_OK, 824 EXPECT_EQ(SERVICE_WORKER_OK,
828 DeleteRegistration(kRegistrationId + 1, kScope.GetOrigin())); 825 DeleteRegistration(kRegistrationId + 1, kScope.GetOrigin()));
829 } 826 }
830 827
831 TEST_P(ServiceWorkerStorageTestP, InstallingRegistrationsAreFindable) { 828 TEST_F(ServiceWorkerStorageTest, InstallingRegistrationsAreFindable) {
832 const GURL kScope("http://www.test.not/scope/"); 829 const GURL kScope("http://www.test.not/scope/");
833 const GURL kScript("http://www.test.not/script.js"); 830 const GURL kScript("http://www.test.not/script.js");
834 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); 831 const GURL kDocumentUrl("http://www.test.not/scope/document.html");
835 const int64_t kRegistrationId = 0; 832 const int64_t kRegistrationId = 0;
836 const int64_t kVersionId = 0; 833 const int64_t kVersionId = 0;
837 834
838 scoped_refptr<ServiceWorkerRegistration> found_registration; 835 scoped_refptr<ServiceWorkerRegistration> found_registration;
839 836
840 // Create an unstored registration. 837 // Create an unstored registration.
841 scoped_refptr<ServiceWorkerRegistration> live_registration = 838 scoped_refptr<ServiceWorkerRegistration> live_registration =
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 SERVICE_WORKER_OK, 947 SERVICE_WORKER_OK,
951 GetRegistrationsForOrigin(kScope.GetOrigin(), &registrations_for_origin)); 948 GetRegistrationsForOrigin(kScope.GetOrigin(), &registrations_for_origin));
952 EXPECT_TRUE(registrations_for_origin.empty()); 949 EXPECT_TRUE(registrations_for_origin.empty());
953 950
954 EXPECT_EQ(SERVICE_WORKER_OK, 951 EXPECT_EQ(SERVICE_WORKER_OK,
955 GetRegistrationsForOrigin(GURL("http://example.com/").GetOrigin(), 952 GetRegistrationsForOrigin(GURL("http://example.com/").GetOrigin(),
956 &registrations_for_origin)); 953 &registrations_for_origin));
957 EXPECT_TRUE(registrations_for_origin.empty()); 954 EXPECT_TRUE(registrations_for_origin.empty());
958 } 955 }
959 956
960 TEST_P(ServiceWorkerStorageTestP, StoreUserData) { 957 TEST_F(ServiceWorkerStorageTest, StoreUserData) {
961 const GURL kScope("http://www.test.not/scope/"); 958 const GURL kScope("http://www.test.not/scope/");
962 const GURL kScript("http://www.test.not/script.js"); 959 const GURL kScript("http://www.test.not/script.js");
963 const int64_t kRegistrationId = 0; 960 const int64_t kRegistrationId = 0;
964 const int64_t kVersionId = 0; 961 const int64_t kVersionId = 0;
965 962
966 LazyInitialize(); 963 LazyInitialize();
967 964
968 // Store a registration. 965 // Store a registration.
969 scoped_refptr<ServiceWorkerRegistration> live_registration = 966 scoped_refptr<ServiceWorkerRegistration> live_registration =
970 new ServiceWorkerRegistration(kScope, kRegistrationId, 967 new ServiceWorkerRegistration(kScope, kRegistrationId,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 ClearUserData(kRegistrationId, {std::string()})); 1088 ClearUserData(kRegistrationId, {std::string()}));
1092 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED, 1089 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED,
1093 ClearUserData(kRegistrationId, {std::string(), "key"})); 1090 ClearUserData(kRegistrationId, {std::string(), "key"}));
1094 data_list_out.clear(); 1091 data_list_out.clear();
1095 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED, 1092 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED,
1096 GetUserDataForAllRegistrations(std::string(), &data_list_out)); 1093 GetUserDataForAllRegistrations(std::string(), &data_list_out));
1097 } 1094 }
1098 1095
1099 // The *_BeforeInitialize tests exercise the API before LazyInitialize() is 1096 // The *_BeforeInitialize tests exercise the API before LazyInitialize() is
1100 // called. 1097 // called.
1101 TEST_P(ServiceWorkerStorageTestP, StoreUserData_BeforeInitialize) { 1098 TEST_F(ServiceWorkerStorageTest, StoreUserData_BeforeInitialize) {
1102 const int kRegistrationId = 0; 1099 const int kRegistrationId = 0;
1103 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, 1100 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND,
1104 StoreUserData(kRegistrationId, GURL("https://example.com"), 1101 StoreUserData(kRegistrationId, GURL("https://example.com"),
1105 {{"key", "data"}})); 1102 {{"key", "data"}}));
1106 } 1103 }
1107 1104
1108 TEST_P(ServiceWorkerStorageTestP, GetUserData_BeforeInitialize) { 1105 TEST_F(ServiceWorkerStorageTest, GetUserData_BeforeInitialize) {
1109 const int kRegistrationId = 0; 1106 const int kRegistrationId = 0;
1110 std::vector<std::string> data_out; 1107 std::vector<std::string> data_out;
1111 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, 1108 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND,
1112 GetUserData(kRegistrationId, {"key"}, &data_out)); 1109 GetUserData(kRegistrationId, {"key"}, &data_out));
1113 } 1110 }
1114 1111
1115 TEST_P(ServiceWorkerStorageTestP, ClearUserData_BeforeInitialize) { 1112 TEST_F(ServiceWorkerStorageTest, ClearUserData_BeforeInitialize) {
1116 const int kRegistrationId = 0; 1113 const int kRegistrationId = 0;
1117 EXPECT_EQ(SERVICE_WORKER_OK, ClearUserData(kRegistrationId, {"key"})); 1114 EXPECT_EQ(SERVICE_WORKER_OK, ClearUserData(kRegistrationId, {"key"}));
1118 } 1115 }
1119 1116
1120 TEST_P(ServiceWorkerStorageTestP, 1117 TEST_F(ServiceWorkerStorageTest,
1121 GetUserDataForAllRegistrations_BeforeInitialize) { 1118 GetUserDataForAllRegistrations_BeforeInitialize) {
1122 std::vector<std::pair<int64_t, std::string>> data_list_out; 1119 std::vector<std::pair<int64_t, std::string>> data_list_out;
1123 EXPECT_EQ(SERVICE_WORKER_OK, 1120 EXPECT_EQ(SERVICE_WORKER_OK,
1124 GetUserDataForAllRegistrations("key", &data_list_out)); 1121 GetUserDataForAllRegistrations("key", &data_list_out));
1125 EXPECT_TRUE(data_list_out.empty()); 1122 EXPECT_TRUE(data_list_out.empty());
1126 } 1123 }
1127 1124
1128 class ServiceWorkerResourceStorageTest : public ServiceWorkerStorageTestP { 1125 class ServiceWorkerResourceStorageTest : public ServiceWorkerStorageTest {
1129 public: 1126 public:
1130 void SetUp() override { 1127 void SetUp() override {
1131 ServiceWorkerStorageTestP::SetUp(); 1128 ServiceWorkerStorageTest::SetUp();
1132 LazyInitialize(); 1129 LazyInitialize();
1133 1130
1134 scope_ = GURL("http://www.test.not/scope/"); 1131 scope_ = GURL("http://www.test.not/scope/");
1135 script_ = GURL("http://www.test.not/script.js"); 1132 script_ = GURL("http://www.test.not/script.js");
1136 import_ = GURL("http://www.test.not/import.js"); 1133 import_ = GURL("http://www.test.not/import.js");
1137 document_url_ = GURL("http://www.test.not/scope/document.html"); 1134 document_url_ = GURL("http://www.test.not/scope/document.html");
1138 registration_id_ = storage()->NewRegistrationId(); 1135 registration_id_ = storage()->NewRegistrationId();
1139 version_id_ = storage()->NewVersionId(); 1136 version_id_ = storage()->NewVersionId();
1140 resource_id1_ = storage()->NewResourceId(); 1137 resource_id1_ = storage()->NewResourceId();
1141 resource_id2_ = storage()->NewResourceId(); 1138 resource_id2_ = storage()->NewResourceId();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 class ServiceWorkerResourceStorageDiskTest 1197 class ServiceWorkerResourceStorageDiskTest
1201 : public ServiceWorkerResourceStorageTest { 1198 : public ServiceWorkerResourceStorageTest {
1202 public: 1199 public:
1203 void SetUp() override { 1200 void SetUp() override {
1204 ASSERT_TRUE(InitUserDataDirectory()); 1201 ASSERT_TRUE(InitUserDataDirectory());
1205 ServiceWorkerResourceStorageTest::SetUp(); 1202 ServiceWorkerResourceStorageTest::SetUp();
1206 } 1203 }
1207 1204
1208 }; 1205 };
1209 1206
1210 TEST_P(ServiceWorkerResourceStorageTest, 1207 TEST_F(ServiceWorkerResourceStorageTest,
1211 WriteMetadataWithServiceWorkerResponseMetadataWriter) { 1208 WriteMetadataWithServiceWorkerResponseMetadataWriter) {
1212 const char kMetadata1[] = "Test metadata"; 1209 const char kMetadata1[] = "Test metadata";
1213 const char kMetadata2[] = "small"; 1210 const char kMetadata2[] = "small";
1214 int64_t new_resource_id_ = storage()->NewResourceId(); 1211 int64_t new_resource_id_ = storage()->NewResourceId();
1215 // Writing metadata to nonexistent resoirce ID must fail. 1212 // Writing metadata to nonexistent resoirce ID must fail.
1216 EXPECT_GE(0, WriteResponseMetadata(storage(), new_resource_id_, kMetadata1)); 1213 EXPECT_GE(0, WriteResponseMetadata(storage(), new_resource_id_, kMetadata1));
1217 1214
1218 // Check metadata is written. 1215 // Check metadata is written.
1219 EXPECT_EQ(static_cast<int>(strlen(kMetadata1)), 1216 EXPECT_EQ(static_cast<int>(strlen(kMetadata1)),
1220 WriteResponseMetadata(storage(), resource_id1_, kMetadata1)); 1217 WriteResponseMetadata(storage(), resource_id1_, kMetadata1));
1221 EXPECT_TRUE(VerifyResponseMetadata(storage(), resource_id1_, kMetadata1)); 1218 EXPECT_TRUE(VerifyResponseMetadata(storage(), resource_id1_, kMetadata1));
1222 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); 1219 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true));
1223 1220
1224 // Check metadata is written and truncated. 1221 // Check metadata is written and truncated.
1225 EXPECT_EQ(static_cast<int>(strlen(kMetadata2)), 1222 EXPECT_EQ(static_cast<int>(strlen(kMetadata2)),
1226 WriteResponseMetadata(storage(), resource_id1_, kMetadata2)); 1223 WriteResponseMetadata(storage(), resource_id1_, kMetadata2));
1227 EXPECT_TRUE(VerifyResponseMetadata(storage(), resource_id1_, kMetadata2)); 1224 EXPECT_TRUE(VerifyResponseMetadata(storage(), resource_id1_, kMetadata2));
1228 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); 1225 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true));
1229 1226
1230 // Check metadata is deleted. 1227 // Check metadata is deleted.
1231 EXPECT_EQ(0, WriteResponseMetadata(storage(), resource_id1_, "")); 1228 EXPECT_EQ(0, WriteResponseMetadata(storage(), resource_id1_, ""));
1232 EXPECT_FALSE(VerifyResponseMetadata(storage(), resource_id1_, "")); 1229 EXPECT_FALSE(VerifyResponseMetadata(storage(), resource_id1_, ""));
1233 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); 1230 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true));
1234 } 1231 }
1235 1232
1236 TEST_P(ServiceWorkerResourceStorageTest, 1233 TEST_F(ServiceWorkerResourceStorageTest,
1237 WriteMetadataWithServiceWorkerScriptCacheMap) { 1234 WriteMetadataWithServiceWorkerScriptCacheMap) {
1238 const char kMetadata1[] = "Test metadata"; 1235 const char kMetadata1[] = "Test metadata";
1239 const char kMetadata2[] = "small"; 1236 const char kMetadata2[] = "small";
1240 ServiceWorkerVersion* version = registration_->waiting_version(); 1237 ServiceWorkerVersion* version = registration_->waiting_version();
1241 EXPECT_TRUE(version); 1238 EXPECT_TRUE(version);
1242 1239
1243 // Writing metadata to nonexistent URL must fail. 1240 // Writing metadata to nonexistent URL must fail.
1244 EXPECT_GE(0, 1241 EXPECT_GE(0,
1245 WriteMetadata(version, GURL("http://www.test.not/nonexistent.js"), 1242 WriteMetadata(version, GURL("http://www.test.not/nonexistent.js"),
1246 kMetadata1)); 1243 kMetadata1));
(...skipping 12 matching lines...) Expand all
1259 WriteMetadata(version, script_, kMetadata2)); 1256 WriteMetadata(version, script_, kMetadata2));
1260 EXPECT_TRUE(VerifyResponseMetadata(storage(), resource_id1_, kMetadata2)); 1257 EXPECT_TRUE(VerifyResponseMetadata(storage(), resource_id1_, kMetadata2));
1261 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); 1258 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true));
1262 1259
1263 // Check metadata is deleted. 1260 // Check metadata is deleted.
1264 EXPECT_EQ(0, ClearMetadata(version, script_)); 1261 EXPECT_EQ(0, ClearMetadata(version, script_));
1265 EXPECT_FALSE(VerifyResponseMetadata(storage(), resource_id1_, "")); 1262 EXPECT_FALSE(VerifyResponseMetadata(storage(), resource_id1_, ""));
1266 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); 1263 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true));
1267 } 1264 }
1268 1265
1269 TEST_P(ServiceWorkerResourceStorageTest, DeleteRegistration_NoLiveVersion) { 1266 TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_NoLiveVersion) {
1270 bool was_called = false; 1267 bool was_called = false;
1271 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; 1268 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED;
1272 std::set<int64_t> verify_ids; 1269 std::set<int64_t> verify_ids;
1273 1270
1274 registration_->SetWaitingVersion(NULL); 1271 registration_->SetWaitingVersion(NULL);
1275 registration_ = NULL; 1272 registration_ = NULL;
1276 1273
1277 // Deleting the registration should result in the resources being added to the 1274 // Deleting the registration should result in the resources being added to the
1278 // purgeable list and then doomed in the disk cache and removed from that 1275 // purgeable list and then doomed in the disk cache and removed from that
1279 // list. 1276 // list.
(...skipping 11 matching lines...) Expand all
1291 EXPECT_EQ(2u, verify_ids.size()); 1288 EXPECT_EQ(2u, verify_ids.size());
1292 verify_ids.clear(); 1289 verify_ids.clear();
1293 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 1290 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
1294 storage()->database_->GetPurgeableResourceIds(&verify_ids)); 1291 storage()->database_->GetPurgeableResourceIds(&verify_ids));
1295 EXPECT_TRUE(verify_ids.empty()); 1292 EXPECT_TRUE(verify_ids.empty());
1296 1293
1297 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); 1294 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false));
1298 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); 1295 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false));
1299 } 1296 }
1300 1297
1301 TEST_P(ServiceWorkerResourceStorageTest, DeleteRegistration_WaitingVersion) { 1298 TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_WaitingVersion) {
1302 bool was_called = false; 1299 bool was_called = false;
1303 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; 1300 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED;
1304 std::set<int64_t> verify_ids; 1301 std::set<int64_t> verify_ids;
1305 1302
1306 // Deleting the registration should result in the resources being added to the 1303 // Deleting the registration should result in the resources being added to the
1307 // purgeable list and then doomed in the disk cache and removed from that 1304 // purgeable list and then doomed in the disk cache and removed from that
1308 // list. 1305 // list.
1309 storage()->DeleteRegistration( 1306 storage()->DeleteRegistration(
1310 registration_->id(), 1307 registration_->id(),
1311 scope_.GetOrigin(), 1308 scope_.GetOrigin(),
(...skipping 21 matching lines...) Expand all
1333 EXPECT_EQ(2u, verify_ids.size()); 1330 EXPECT_EQ(2u, verify_ids.size());
1334 verify_ids.clear(); 1331 verify_ids.clear();
1335 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 1332 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
1336 storage()->database_->GetPurgeableResourceIds(&verify_ids)); 1333 storage()->database_->GetPurgeableResourceIds(&verify_ids));
1337 EXPECT_TRUE(verify_ids.empty()); 1334 EXPECT_TRUE(verify_ids.empty());
1338 1335
1339 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); 1336 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false));
1340 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); 1337 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false));
1341 } 1338 }
1342 1339
1343 TEST_P(ServiceWorkerResourceStorageTest, DeleteRegistration_ActiveVersion) { 1340 TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_ActiveVersion) {
1344 // Promote the worker to active and add a controllee. 1341 // Promote the worker to active and add a controllee.
1345 registration_->SetActiveVersion(registration_->waiting_version()); 1342 registration_->SetActiveVersion(registration_->waiting_version());
1346 storage()->UpdateToActiveState( 1343 storage()->UpdateToActiveState(
1347 registration_.get(), base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1344 registration_.get(), base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1348 std::unique_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( 1345 std::unique_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
1349 33 /* dummy render process id */, MSG_ROUTING_NONE, 1346 33 /* dummy render process id */, MSG_ROUTING_NONE,
1350 1 /* dummy provider_id */, SERVICE_WORKER_PROVIDER_FOR_WINDOW, 1347 1 /* dummy provider_id */, SERVICE_WORKER_PROVIDER_FOR_WINDOW,
1351 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE, 1348 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE,
1352 context()->AsWeakPtr(), NULL)); 1349 context()->AsWeakPtr(), NULL));
1353 registration_->active_version()->AddControllee(host.get()); 1350 registration_->active_version()->AddControllee(host.get());
(...skipping 30 matching lines...) Expand all
1384 base::RunLoop().RunUntilIdle(); 1381 base::RunLoop().RunUntilIdle();
1385 verify_ids.clear(); 1382 verify_ids.clear();
1386 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 1383 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
1387 storage()->database_->GetPurgeableResourceIds(&verify_ids)); 1384 storage()->database_->GetPurgeableResourceIds(&verify_ids));
1388 EXPECT_TRUE(verify_ids.empty()); 1385 EXPECT_TRUE(verify_ids.empty());
1389 1386
1390 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); 1387 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false));
1391 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); 1388 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false));
1392 } 1389 }
1393 1390
1394 TEST_P(ServiceWorkerResourceStorageDiskTest, CleanupOnRestart) { 1391 TEST_F(ServiceWorkerResourceStorageDiskTest, CleanupOnRestart) {
1395 // Promote the worker to active and add a controllee. 1392 // Promote the worker to active and add a controllee.
1396 registration_->SetActiveVersion(registration_->waiting_version()); 1393 registration_->SetActiveVersion(registration_->waiting_version());
1397 registration_->SetWaitingVersion(NULL); 1394 registration_->SetWaitingVersion(NULL);
1398 storage()->UpdateToActiveState( 1395 storage()->UpdateToActiveState(
1399 registration_.get(), base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1396 registration_.get(), base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1400 std::unique_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( 1397 std::unique_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
1401 33 /* dummy render process id */, MSG_ROUTING_NONE, 1398 33 /* dummy render process id */, MSG_ROUTING_NONE,
1402 1 /* dummy provider_id */, SERVICE_WORKER_PROVIDER_FOR_WINDOW, 1399 1 /* dummy provider_id */, SERVICE_WORKER_PROVIDER_FOR_WINDOW,
1403 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE, 1400 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE,
1404 context()->AsWeakPtr(), NULL)); 1401 context()->AsWeakPtr(), NULL));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 1466 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
1470 storage()->database_->GetPurgeableResourceIds(&verify_ids)); 1467 storage()->database_->GetPurgeableResourceIds(&verify_ids));
1471 EXPECT_TRUE(verify_ids.empty()); 1468 EXPECT_TRUE(verify_ids.empty());
1472 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); 1469 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false));
1473 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); 1470 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false));
1474 EXPECT_FALSE( 1471 EXPECT_FALSE(
1475 VerifyBasicResponse(storage(), kStaleUncommittedResourceId, false)); 1472 VerifyBasicResponse(storage(), kStaleUncommittedResourceId, false));
1476 EXPECT_TRUE(VerifyBasicResponse(storage(), kNewResourceId, true)); 1473 EXPECT_TRUE(VerifyBasicResponse(storage(), kNewResourceId, true));
1477 } 1474 }
1478 1475
1479 TEST_P(ServiceWorkerResourceStorageDiskTest, DeleteAndStartOver) { 1476 TEST_F(ServiceWorkerResourceStorageDiskTest, DeleteAndStartOver) {
1480 EXPECT_FALSE(storage()->IsDisabled()); 1477 EXPECT_FALSE(storage()->IsDisabled());
1481 ASSERT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath())); 1478 ASSERT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath()));
1482 ASSERT_TRUE(base::DirectoryExists(storage()->GetDatabasePath())); 1479 ASSERT_TRUE(base::DirectoryExists(storage()->GetDatabasePath()));
1483 1480
1484 base::RunLoop run_loop; 1481 base::RunLoop run_loop;
1485 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; 1482 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
1486 storage()->DeleteAndStartOver( 1483 storage()->DeleteAndStartOver(
1487 base::Bind(&StatusAndQuitCallback, &status, run_loop.QuitClosure())); 1484 base::Bind(&StatusAndQuitCallback, &status, run_loop.QuitClosure()));
1488 run_loop.Run(); 1485 run_loop.Run();
1489 1486
1490 EXPECT_EQ(SERVICE_WORKER_OK, status); 1487 EXPECT_EQ(SERVICE_WORKER_OK, status);
1491 EXPECT_TRUE(storage()->IsDisabled()); 1488 EXPECT_TRUE(storage()->IsDisabled());
1492 EXPECT_FALSE(base::DirectoryExists(storage()->GetDiskCachePath())); 1489 EXPECT_FALSE(base::DirectoryExists(storage()->GetDiskCachePath()));
1493 EXPECT_FALSE(base::DirectoryExists(storage()->GetDatabasePath())); 1490 EXPECT_FALSE(base::DirectoryExists(storage()->GetDatabasePath()));
1494 } 1491 }
1495 1492
1496 TEST_P(ServiceWorkerResourceStorageDiskTest, 1493 TEST_F(ServiceWorkerResourceStorageDiskTest,
1497 DeleteAndStartOver_UnrelatedFileExists) { 1494 DeleteAndStartOver_UnrelatedFileExists) {
1498 EXPECT_FALSE(storage()->IsDisabled()); 1495 EXPECT_FALSE(storage()->IsDisabled());
1499 ASSERT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath())); 1496 ASSERT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath()));
1500 ASSERT_TRUE(base::DirectoryExists(storage()->GetDatabasePath())); 1497 ASSERT_TRUE(base::DirectoryExists(storage()->GetDatabasePath()));
1501 1498
1502 // Create an unrelated file in the database directory to make sure such a file 1499 // Create an unrelated file in the database directory to make sure such a file
1503 // does not prevent DeleteAndStartOver. 1500 // does not prevent DeleteAndStartOver.
1504 base::FilePath file_path; 1501 base::FilePath file_path;
1505 ASSERT_TRUE( 1502 ASSERT_TRUE(
1506 base::CreateTemporaryFileInDir(storage()->GetDatabasePath(), &file_path)); 1503 base::CreateTemporaryFileInDir(storage()->GetDatabasePath(), &file_path));
1507 ASSERT_TRUE(base::PathExists(file_path)); 1504 ASSERT_TRUE(base::PathExists(file_path));
1508 1505
1509 base::RunLoop run_loop; 1506 base::RunLoop run_loop;
1510 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; 1507 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
1511 storage()->DeleteAndStartOver( 1508 storage()->DeleteAndStartOver(
1512 base::Bind(&StatusAndQuitCallback, &status, run_loop.QuitClosure())); 1509 base::Bind(&StatusAndQuitCallback, &status, run_loop.QuitClosure()));
1513 run_loop.Run(); 1510 run_loop.Run();
1514 1511
1515 EXPECT_EQ(SERVICE_WORKER_OK, status); 1512 EXPECT_EQ(SERVICE_WORKER_OK, status);
1516 EXPECT_TRUE(storage()->IsDisabled()); 1513 EXPECT_TRUE(storage()->IsDisabled());
1517 EXPECT_FALSE(base::DirectoryExists(storage()->GetDiskCachePath())); 1514 EXPECT_FALSE(base::DirectoryExists(storage()->GetDiskCachePath()));
1518 EXPECT_FALSE(base::DirectoryExists(storage()->GetDatabasePath())); 1515 EXPECT_FALSE(base::DirectoryExists(storage()->GetDatabasePath()));
1519 } 1516 }
1520 1517
1521 TEST_P(ServiceWorkerResourceStorageDiskTest, 1518 TEST_F(ServiceWorkerResourceStorageDiskTest,
1522 DeleteAndStartOver_OpenedFileExists) { 1519 DeleteAndStartOver_OpenedFileExists) {
1523 EXPECT_FALSE(storage()->IsDisabled()); 1520 EXPECT_FALSE(storage()->IsDisabled());
1524 ASSERT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath())); 1521 ASSERT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath()));
1525 ASSERT_TRUE(base::DirectoryExists(storage()->GetDatabasePath())); 1522 ASSERT_TRUE(base::DirectoryExists(storage()->GetDatabasePath()));
1526 1523
1527 // Create an unrelated opened file in the database directory to make sure such 1524 // Create an unrelated opened file in the database directory to make sure such
1528 // a file does not prevent DeleteAndStartOver on non-Windows platforms. 1525 // a file does not prevent DeleteAndStartOver on non-Windows platforms.
1529 base::FilePath file_path; 1526 base::FilePath file_path;
1530 base::ScopedFILE file(base::CreateAndOpenTemporaryFileInDir( 1527 base::ScopedFILE file(base::CreateAndOpenTemporaryFileInDir(
1531 storage()->GetDatabasePath(), &file_path)); 1528 storage()->GetDatabasePath(), &file_path));
(...skipping 13 matching lines...) Expand all
1545 EXPECT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath())); 1542 EXPECT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath()));
1546 EXPECT_TRUE(base::DirectoryExists(storage()->GetDatabasePath())); 1543 EXPECT_TRUE(base::DirectoryExists(storage()->GetDatabasePath()));
1547 #else 1544 #else
1548 EXPECT_EQ(SERVICE_WORKER_OK, status); 1545 EXPECT_EQ(SERVICE_WORKER_OK, status);
1549 EXPECT_TRUE(storage()->IsDisabled()); 1546 EXPECT_TRUE(storage()->IsDisabled());
1550 EXPECT_FALSE(base::DirectoryExists(storage()->GetDiskCachePath())); 1547 EXPECT_FALSE(base::DirectoryExists(storage()->GetDiskCachePath()));
1551 EXPECT_FALSE(base::DirectoryExists(storage()->GetDatabasePath())); 1548 EXPECT_FALSE(base::DirectoryExists(storage()->GetDatabasePath()));
1552 #endif 1549 #endif
1553 } 1550 }
1554 1551
1555 TEST_P(ServiceWorkerResourceStorageTest, UpdateRegistration) { 1552 TEST_F(ServiceWorkerResourceStorageTest, UpdateRegistration) {
1556 // Promote the worker to active worker and add a controllee. 1553 // Promote the worker to active worker and add a controllee.
1557 registration_->SetActiveVersion(registration_->waiting_version()); 1554 registration_->SetActiveVersion(registration_->waiting_version());
1558 storage()->UpdateToActiveState( 1555 storage()->UpdateToActiveState(
1559 registration_.get(), base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1556 registration_.get(), base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1560 std::unique_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( 1557 std::unique_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
1561 33 /* dummy render process id */, MSG_ROUTING_NONE, 1558 33 /* dummy render process id */, MSG_ROUTING_NONE,
1562 1 /* dummy provider_id */, SERVICE_WORKER_PROVIDER_FOR_WINDOW, 1559 1 /* dummy provider_id */, SERVICE_WORKER_PROVIDER_FOR_WINDOW,
1563 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE, 1560 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE,
1564 context()->AsWeakPtr(), NULL)); 1561 context()->AsWeakPtr(), NULL));
1565 registration_->active_version()->AddControllee(host.get()); 1562 registration_->active_version()->AddControllee(host.get());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 base::RunLoop().RunUntilIdle(); 1607 base::RunLoop().RunUntilIdle();
1611 verify_ids.clear(); 1608 verify_ids.clear();
1612 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 1609 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
1613 storage()->database_->GetPurgeableResourceIds(&verify_ids)); 1610 storage()->database_->GetPurgeableResourceIds(&verify_ids));
1614 EXPECT_TRUE(verify_ids.empty()); 1611 EXPECT_TRUE(verify_ids.empty());
1615 1612
1616 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); 1613 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false));
1617 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); 1614 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false));
1618 } 1615 }
1619 1616
1620 TEST_P(ServiceWorkerStorageTestP, FindRegistration_LongestScopeMatch) { 1617 TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) {
1621 const GURL kDocumentUrl("http://www.example.com/scope/foo"); 1618 const GURL kDocumentUrl("http://www.example.com/scope/foo");
1622 scoped_refptr<ServiceWorkerRegistration> found_registration; 1619 scoped_refptr<ServiceWorkerRegistration> found_registration;
1623 1620
1624 // Registration for "/scope/". 1621 // Registration for "/scope/".
1625 const GURL kScope1("http://www.example.com/scope/"); 1622 const GURL kScope1("http://www.example.com/scope/");
1626 const GURL kScript1("http://www.example.com/script1.js"); 1623 const GURL kScript1("http://www.example.com/script1.js");
1627 const int64_t kRegistrationId1 = 1; 1624 const int64_t kRegistrationId1 = 1;
1628 const int64_t kVersionId1 = 1; 1625 const int64_t kVersionId1 = 1;
1629 scoped_refptr<ServiceWorkerRegistration> live_registration1 = 1626 scoped_refptr<ServiceWorkerRegistration> live_registration1 =
1630 new ServiceWorkerRegistration(kScope1, kRegistrationId1, 1627 new ServiceWorkerRegistration(kScope1, kRegistrationId1,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1706 live_registration3.get(), NULL, SERVICE_WORKER_OK); 1703 live_registration3.get(), NULL, SERVICE_WORKER_OK);
1707 1704
1708 // Find a registration among installed ones. 1705 // Find a registration among installed ones.
1709 EXPECT_EQ(SERVICE_WORKER_OK, 1706 EXPECT_EQ(SERVICE_WORKER_OK,
1710 FindRegistrationForDocument(kDocumentUrl, &found_registration)); 1707 FindRegistrationForDocument(kDocumentUrl, &found_registration));
1711 EXPECT_EQ(live_registration2, found_registration); 1708 EXPECT_EQ(live_registration2, found_registration);
1712 } 1709 }
1713 1710
1714 // Test fixture that uses disk storage, rather than memory. Useful for tests 1711 // Test fixture that uses disk storage, rather than memory. Useful for tests
1715 // that test persistence by simulating browser shutdown and restart. 1712 // that test persistence by simulating browser shutdown and restart.
1716 class ServiceWorkerStorageDiskTest : public ServiceWorkerStorageTestP { 1713 class ServiceWorkerStorageDiskTest : public ServiceWorkerStorageTest {
1717 public: 1714 public:
1718 void SetUp() override { 1715 void SetUp() override {
1719 ASSERT_TRUE(InitUserDataDirectory()); 1716 ASSERT_TRUE(InitUserDataDirectory());
1720 ServiceWorkerStorageTestP::SetUp(); 1717 ServiceWorkerStorageTest::SetUp();
1721 } 1718 }
1722 }; 1719 };
1723 1720
1724 TEST_P(ServiceWorkerStorageDiskTest, OriginHasForeignFetchRegistrations) { 1721 TEST_F(ServiceWorkerStorageDiskTest, OriginHasForeignFetchRegistrations) {
1725 LazyInitialize(); 1722 LazyInitialize();
1726 1723
1727 // Registration 1 for http://www.example.com 1724 // Registration 1 for http://www.example.com
1728 const GURL kScope1("http://www.example.com/scope/"); 1725 const GURL kScope1("http://www.example.com/scope/");
1729 const GURL kScript1("http://www.example.com/script1.js"); 1726 const GURL kScript1("http://www.example.com/script1.js");
1730 const int64_t kRegistrationId1 = 1; 1727 const int64_t kRegistrationId1 = 1;
1731 const int64_t kVersionId1 = 1; 1728 const int64_t kVersionId1 = 1;
1732 scoped_refptr<ServiceWorkerRegistration> live_registration1 = 1729 scoped_refptr<ServiceWorkerRegistration> live_registration1 =
1733 new ServiceWorkerRegistration(kScope1, kRegistrationId1, 1730 new ServiceWorkerRegistration(kScope1, kRegistrationId1,
1734 context()->AsWeakPtr()); 1731 context()->AsWeakPtr());
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1825 1822
1826 // Remove other registration at first origin. 1823 // Remove other registration at first origin.
1827 EXPECT_EQ(SERVICE_WORKER_OK, 1824 EXPECT_EQ(SERVICE_WORKER_OK,
1828 DeleteRegistration(kRegistrationId2, kScope2.GetOrigin())); 1825 DeleteRegistration(kRegistrationId2, kScope2.GetOrigin()));
1829 1826
1830 // No foreign fetch registrations remain. 1827 // No foreign fetch registrations remain.
1831 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin1)); 1828 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin1));
1832 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin2)); 1829 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin2));
1833 } 1830 }
1834 1831
1835 TEST_P(ServiceWorkerStorageTestP, OriginTrialsAbsentEntryAndEmptyEntry) { 1832 TEST_F(ServiceWorkerStorageTest, OriginTrialsAbsentEntryAndEmptyEntry) {
1836 const GURL origin1("http://www1.example.com"); 1833 const GURL origin1("http://www1.example.com");
1837 const GURL scope1("http://www1.example.com/foo/"); 1834 const GURL scope1("http://www1.example.com/foo/");
1838 RegistrationData data1; 1835 RegistrationData data1;
1839 data1.registration_id = 100; 1836 data1.registration_id = 100;
1840 data1.scope = scope1; 1837 data1.scope = scope1;
1841 data1.script = GURL(origin1.spec() + "/script.js"); 1838 data1.script = GURL(origin1.spec() + "/script.js");
1842 data1.version_id = 1000; 1839 data1.version_id = 1000;
1843 data1.is_active = true; 1840 data1.is_active = true;
1844 data1.resources_total_size_bytes = 100; 1841 data1.resources_total_size_bytes = 100;
1845 // Don't set origin_trial_tokens to simulate old database entry. 1842 // Don't set origin_trial_tokens to simulate old database entry.
(...skipping 29 matching lines...) Expand all
1875 EXPECT_EQ(SERVICE_WORKER_OK, 1872 EXPECT_EQ(SERVICE_WORKER_OK,
1876 FindRegistrationForDocument(scope2, &found_registration)); 1873 FindRegistrationForDocument(scope2, &found_registration));
1877 ASSERT_TRUE(found_registration->active_version()); 1874 ASSERT_TRUE(found_registration->active_version());
1878 // Empty origin_trial_tokens must exist. 1875 // Empty origin_trial_tokens must exist.
1879 ASSERT_TRUE(found_registration->active_version()->origin_trial_tokens()); 1876 ASSERT_TRUE(found_registration->active_version()->origin_trial_tokens());
1880 EXPECT_TRUE( 1877 EXPECT_TRUE(
1881 found_registration->active_version()->origin_trial_tokens()->empty()); 1878 found_registration->active_version()->origin_trial_tokens()->empty());
1882 } 1879 }
1883 1880
1884 class ServiceWorkerStorageOriginTrialsDiskTest 1881 class ServiceWorkerStorageOriginTrialsDiskTest
1885 : public ServiceWorkerStorageTestP { 1882 : public ServiceWorkerStorageTest {
1886 public: 1883 public:
1887 ServiceWorkerStorageOriginTrialsDiskTest() { 1884 ServiceWorkerStorageOriginTrialsDiskTest() {
1888 SetContentClient(&test_content_client_); 1885 SetContentClient(&test_content_client_);
1889 } 1886 }
1890 ~ServiceWorkerStorageOriginTrialsDiskTest() override { 1887 ~ServiceWorkerStorageOriginTrialsDiskTest() override {
1891 SetContentClient(nullptr); 1888 SetContentClient(nullptr);
1892 } 1889 }
1893 void SetUp() override { 1890 void SetUp() override {
1894 ASSERT_TRUE(InitUserDataDirectory()); 1891 ASSERT_TRUE(InitUserDataDirectory());
1895 ServiceWorkerStorageTestP::SetUp(); 1892 ServiceWorkerStorageTest::SetUp();
1896 } 1893 }
1897 1894
1898 private: 1895 private:
1899 class TestOriginTrialPolicy : public OriginTrialPolicy { 1896 class TestOriginTrialPolicy : public OriginTrialPolicy {
1900 public: 1897 public:
1901 base::StringPiece GetPublicKey() const override { 1898 base::StringPiece GetPublicKey() const override {
1902 return base::StringPiece(reinterpret_cast<const char*>(kTestPublicKey), 1899 return base::StringPiece(reinterpret_cast<const char*>(kTestPublicKey),
1903 arraysize(kTestPublicKey)); 1900 arraysize(kTestPublicKey));
1904 } 1901 }
1905 bool IsFeatureDisabled(base::StringPiece feature) const override { 1902 bool IsFeatureDisabled(base::StringPiece feature) const override {
1906 return false; 1903 return false;
1907 } 1904 }
1908 }; 1905 };
1909 class TestContentClient : public ContentClient { 1906 class TestContentClient : public ContentClient {
1910 public: 1907 public:
1911 // ContentRendererClient methods 1908 // ContentRendererClient methods
1912 OriginTrialPolicy* GetOriginTrialPolicy() override { 1909 OriginTrialPolicy* GetOriginTrialPolicy() override {
1913 return &origin_trial_policy_; 1910 return &origin_trial_policy_;
1914 } 1911 }
1915 1912
1916 private: 1913 private:
1917 TestOriginTrialPolicy origin_trial_policy_; 1914 TestOriginTrialPolicy origin_trial_policy_;
1918 }; 1915 };
1919 TestContentClient test_content_client_; 1916 TestContentClient test_content_client_;
1920 }; 1917 };
1921 1918
1922 TEST_P(ServiceWorkerStorageOriginTrialsDiskTest, FromMainScript) { 1919 TEST_F(ServiceWorkerStorageOriginTrialsDiskTest, FromMainScript) {
1923 LazyInitialize(); 1920 LazyInitialize();
1924 const GURL kScope("https://valid.example.com/scope"); 1921 const GURL kScope("https://valid.example.com/scope");
1925 const GURL kScript("https://valid.example.com/script.js"); 1922 const GURL kScript("https://valid.example.com/script.js");
1926 const int64_t kRegistrationId = 1; 1923 const int64_t kRegistrationId = 1;
1927 const int64_t kVersionId = 1; 1924 const int64_t kVersionId = 1;
1928 scoped_refptr<ServiceWorkerRegistration> registration = 1925 scoped_refptr<ServiceWorkerRegistration> registration =
1929 new ServiceWorkerRegistration(kScope, kRegistrationId, 1926 new ServiceWorkerRegistration(kScope, kRegistrationId,
1930 context()->AsWeakPtr()); 1927 context()->AsWeakPtr());
1931 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 1928 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
1932 registration.get(), kScript, kVersionId, context()->AsWeakPtr()); 1929 registration.get(), kScript, kVersionId, context()->AsWeakPtr());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2008 *found_registration->active_version()->origin_trial_tokens(); 2005 *found_registration->active_version()->origin_trial_tokens();
2009 ASSERT_EQ(2UL, found_tokens.size()); 2006 ASSERT_EQ(2UL, found_tokens.size());
2010 ASSERT_EQ(1UL, found_tokens.at("Feature1").size()); 2007 ASSERT_EQ(1UL, found_tokens.at("Feature1").size());
2011 EXPECT_EQ(kFeature1Token, found_tokens.at("Feature1")[0]); 2008 EXPECT_EQ(kFeature1Token, found_tokens.at("Feature1")[0]);
2012 ASSERT_EQ(2UL, found_tokens.at("Feature2").size()); 2009 ASSERT_EQ(2UL, found_tokens.at("Feature2").size());
2013 EXPECT_EQ(kFeature2Token1, found_tokens.at("Feature2")[0]); 2010 EXPECT_EQ(kFeature2Token1, found_tokens.at("Feature2")[0]);
2014 EXPECT_EQ(kFeature2Token2, found_tokens.at("Feature2")[1]); 2011 EXPECT_EQ(kFeature2Token2, found_tokens.at("Feature2")[1]);
2015 } 2012 }
2016 2013
2017 // Tests loading a registration that has no navigation preload state. 2014 // Tests loading a registration that has no navigation preload state.
2018 TEST_P(ServiceWorkerStorageTestP, AbsentNavigationPreloadState) { 2015 TEST_F(ServiceWorkerStorageTest, AbsentNavigationPreloadState) {
2019 const GURL origin1("http://www1.example.com"); 2016 const GURL origin1("http://www1.example.com");
2020 const GURL scope1("http://www1.example.com/foo/"); 2017 const GURL scope1("http://www1.example.com/foo/");
2021 RegistrationData data1; 2018 RegistrationData data1;
2022 data1.registration_id = 100; 2019 data1.registration_id = 100;
2023 data1.scope = scope1; 2020 data1.scope = scope1;
2024 data1.script = GURL(origin1.spec() + "/script.js"); 2021 data1.script = GURL(origin1.spec() + "/script.js");
2025 data1.version_id = 1000; 2022 data1.version_id = 1000;
2026 data1.is_active = true; 2023 data1.is_active = true;
2027 data1.resources_total_size_bytes = 100; 2024 data1.resources_total_size_bytes = 100;
2028 // Don't set navigation preload state to simulate old database entry. 2025 // Don't set navigation preload state to simulate old database entry.
(...skipping 11 matching lines...) Expand all
2040 EXPECT_EQ("true", registration_state.header); 2037 EXPECT_EQ("true", registration_state.header);
2041 ASSERT_TRUE(found_registration->active_version()); 2038 ASSERT_TRUE(found_registration->active_version());
2042 const NavigationPreloadState& state = 2039 const NavigationPreloadState& state =
2043 found_registration->active_version()->navigation_preload_state(); 2040 found_registration->active_version()->navigation_preload_state();
2044 EXPECT_FALSE(state.enabled); 2041 EXPECT_FALSE(state.enabled);
2045 EXPECT_EQ("true", state.header); 2042 EXPECT_EQ("true", state.header);
2046 } 2043 }
2047 2044
2048 // Tests loading a registration with a disabled navigation preload 2045 // Tests loading a registration with a disabled navigation preload
2049 // state. 2046 // state.
2050 TEST_P(ServiceWorkerStorageDiskTest, DisabledNavigationPreloadState) { 2047 TEST_F(ServiceWorkerStorageDiskTest, DisabledNavigationPreloadState) {
2051 LazyInitialize(); 2048 LazyInitialize();
2052 const GURL kScope("https://valid.example.com/scope"); 2049 const GURL kScope("https://valid.example.com/scope");
2053 const GURL kScript("https://valid.example.com/script.js"); 2050 const GURL kScript("https://valid.example.com/script.js");
2054 const int64_t kRegistrationId = 1; 2051 const int64_t kRegistrationId = 1;
2055 const int64_t kVersionId = 1; 2052 const int64_t kVersionId = 1;
2056 scoped_refptr<ServiceWorkerRegistration> registration = 2053 scoped_refptr<ServiceWorkerRegistration> registration =
2057 new ServiceWorkerRegistration(kScope, kRegistrationId, 2054 new ServiceWorkerRegistration(kScope, kRegistrationId,
2058 context()->AsWeakPtr()); 2055 context()->AsWeakPtr());
2059 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 2056 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
2060 registration.get(), kScript, kVersionId, context()->AsWeakPtr()); 2057 registration.get(), kScript, kVersionId, context()->AsWeakPtr());
(...skipping 24 matching lines...) Expand all
2085 EXPECT_EQ("true", registration_state.header); 2082 EXPECT_EQ("true", registration_state.header);
2086 ASSERT_TRUE(found_registration->active_version()); 2083 ASSERT_TRUE(found_registration->active_version());
2087 const NavigationPreloadState& state = 2084 const NavigationPreloadState& state =
2088 found_registration->active_version()->navigation_preload_state(); 2085 found_registration->active_version()->navigation_preload_state();
2089 EXPECT_FALSE(state.enabled); 2086 EXPECT_FALSE(state.enabled);
2090 EXPECT_EQ("true", state.header); 2087 EXPECT_EQ("true", state.header);
2091 } 2088 }
2092 2089
2093 // Tests loading a registration with an enabled navigation preload state, as 2090 // Tests loading a registration with an enabled navigation preload state, as
2094 // well as a custom header value. 2091 // well as a custom header value.
2095 TEST_P(ServiceWorkerStorageDiskTest, EnabledNavigationPreloadState) { 2092 TEST_F(ServiceWorkerStorageDiskTest, EnabledNavigationPreloadState) {
2096 LazyInitialize(); 2093 LazyInitialize();
2097 const GURL kScope("https://valid.example.com/scope"); 2094 const GURL kScope("https://valid.example.com/scope");
2098 const GURL kScript("https://valid.example.com/script.js"); 2095 const GURL kScript("https://valid.example.com/script.js");
2099 const std::string kHeaderValue("custom header value"); 2096 const std::string kHeaderValue("custom header value");
2100 const int64_t kRegistrationId = 1; 2097 const int64_t kRegistrationId = 1;
2101 const int64_t kVersionId = 1; 2098 const int64_t kVersionId = 1;
2102 scoped_refptr<ServiceWorkerRegistration> registration = 2099 scoped_refptr<ServiceWorkerRegistration> registration =
2103 new ServiceWorkerRegistration(kScope, kRegistrationId, 2100 new ServiceWorkerRegistration(kScope, kRegistrationId,
2104 context()->AsWeakPtr()); 2101 context()->AsWeakPtr());
2105 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 2102 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
(...skipping 24 matching lines...) Expand all
2130 found_registration->navigation_preload_state(); 2127 found_registration->navigation_preload_state();
2131 EXPECT_TRUE(registration_state.enabled); 2128 EXPECT_TRUE(registration_state.enabled);
2132 EXPECT_EQ(kHeaderValue, registration_state.header); 2129 EXPECT_EQ(kHeaderValue, registration_state.header);
2133 ASSERT_TRUE(found_registration->active_version()); 2130 ASSERT_TRUE(found_registration->active_version());
2134 const NavigationPreloadState& state = 2131 const NavigationPreloadState& state =
2135 found_registration->active_version()->navigation_preload_state(); 2132 found_registration->active_version()->navigation_preload_state();
2136 EXPECT_TRUE(state.enabled); 2133 EXPECT_TRUE(state.enabled);
2137 EXPECT_EQ(kHeaderValue, state.header); 2134 EXPECT_EQ(kHeaderValue, state.header);
2138 } 2135 }
2139 2136
2140 INSTANTIATE_TEST_CASE_P(ServiceWorkerResourceStorageDiskTest,
2141 ServiceWorkerResourceStorageDiskTest,
2142 testing::Bool());
2143 INSTANTIATE_TEST_CASE_P(ServiceWorkerResourceStorageTest,
2144 ServiceWorkerResourceStorageTest,
2145 testing::Bool());
2146 INSTANTIATE_TEST_CASE_P(ServiceWorkerStorageDiskTest,
2147 ServiceWorkerStorageDiskTest,
2148 testing::Bool());
2149 INSTANTIATE_TEST_CASE_P(ServiceWorkerStorageOriginTrialsDiskTest,
2150 ServiceWorkerStorageOriginTrialsDiskTest,
2151 testing::Bool());
2152 INSTANTIATE_TEST_CASE_P(ServiceWorkerStorageTestP,
2153 ServiceWorkerStorageTestP,
2154 testing::Bool());
2155
2156 } // namespace content 2137 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698