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

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

Issue 2431313003: Mojofy unittests related to service workers (Closed)
Patch Set: Rebase Created 4 years, 2 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
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "content/browser/browser_thread_impl.h" 18 #include "content/browser/browser_thread_impl.h"
19 #include "content/browser/service_worker/embedded_worker_test_helper.h" 19 #include "content/browser/service_worker/embedded_worker_test_helper.h"
20 #include "content/browser/service_worker/service_worker_context_core.h" 20 #include "content/browser/service_worker/service_worker_context_core.h"
21 #include "content/browser/service_worker/service_worker_disk_cache.h" 21 #include "content/browser/service_worker/service_worker_disk_cache.h"
22 #include "content/browser/service_worker/service_worker_registration.h" 22 #include "content/browser/service_worker/service_worker_registration.h"
23 #include "content/browser/service_worker/service_worker_test_utils.h"
23 #include "content/browser/service_worker/service_worker_version.h" 24 #include "content/browser/service_worker/service_worker_version.h"
24 #include "content/common/service_worker/service_worker_status_code.h" 25 #include "content/common/service_worker/service_worker_status_code.h"
25 #include "content/common/service_worker/service_worker_utils.h" 26 #include "content/common/service_worker/service_worker_utils.h"
26 #include "content/public/common/content_client.h" 27 #include "content/public/common/content_client.h"
27 #include "content/public/common/origin_trial_policy.h" 28 #include "content/public/common/origin_trial_policy.h"
28 #include "content/public/test/test_browser_thread_bundle.h" 29 #include "content/public/test/test_browser_thread_bundle.h"
29 #include "ipc/ipc_message.h" 30 #include "ipc/ipc_message.h"
30 #include "net/base/io_buffer.h" 31 #include "net/base/io_buffer.h"
31 #include "net/base/net_errors.h" 32 #include "net/base/net_errors.h"
32 #include "net/base/test_completion_callback.h" 33 #include "net/base/test_completion_callback.h"
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 return result; 523 return result;
523 } 524 }
524 525
525 // user_data_directory_ must be declared first to preserve destructor order. 526 // user_data_directory_ must be declared first to preserve destructor order.
526 base::ScopedTempDir user_data_directory_; 527 base::ScopedTempDir user_data_directory_;
527 base::FilePath user_data_directory_path_; 528 base::FilePath user_data_directory_path_;
528 std::unique_ptr<EmbeddedWorkerTestHelper> helper_; 529 std::unique_ptr<EmbeddedWorkerTestHelper> helper_;
529 TestBrowserThreadBundle browser_thread_bundle_; 530 TestBrowserThreadBundle browser_thread_bundle_;
530 }; 531 };
531 532
532 TEST_F(ServiceWorkerStorageTest, DisabledStorage) { 533 class ServiceWorkerStorageTestP
534 : public MojoServiceWorkerTestP<ServiceWorkerStorageTest> {};
535
536 TEST_P(ServiceWorkerStorageTestP, DisabledStorage) {
533 const GURL kScope("http://www.example.com/scope/"); 537 const GURL kScope("http://www.example.com/scope/");
534 const GURL kScript("http://www.example.com/script.js"); 538 const GURL kScript("http://www.example.com/script.js");
535 const GURL kDocumentUrl("http://www.example.com/scope/document.html"); 539 const GURL kDocumentUrl("http://www.example.com/scope/document.html");
536 const int64_t kRegistrationId = 0; 540 const int64_t kRegistrationId = 0;
537 const int64_t kVersionId = 0; 541 const int64_t kVersionId = 0;
538 const int64_t kResourceId = 0; 542 const int64_t kResourceId = 0;
539 543
540 LazyInitialize(); 544 LazyInitialize();
541 storage()->Disable(); 545 storage()->Disable();
542 546
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 EXPECT_FALSE( 604 EXPECT_FALSE(
601 storage()->OriginHasForeignFetchRegistrations(kScope.GetOrigin())); 605 storage()->OriginHasForeignFetchRegistrations(kScope.GetOrigin()));
602 606
603 // Next available ids should be invalid. 607 // Next available ids should be invalid.
604 EXPECT_EQ(kInvalidServiceWorkerRegistrationId, 608 EXPECT_EQ(kInvalidServiceWorkerRegistrationId,
605 storage()->NewRegistrationId()); 609 storage()->NewRegistrationId());
606 EXPECT_EQ(kInvalidServiceWorkerVersionId, storage()->NewVersionId()); 610 EXPECT_EQ(kInvalidServiceWorkerVersionId, storage()->NewVersionId());
607 EXPECT_EQ(kInvalidServiceWorkerResourceId, storage()->NewRegistrationId()); 611 EXPECT_EQ(kInvalidServiceWorkerResourceId, storage()->NewRegistrationId());
608 } 612 }
609 613
610 TEST_F(ServiceWorkerStorageTest, StoreFindUpdateDeleteRegistration) { 614 TEST_P(ServiceWorkerStorageTestP, StoreFindUpdateDeleteRegistration) {
611 const GURL kScope("http://www.test.not/scope/"); 615 const GURL kScope("http://www.test.not/scope/");
612 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); 616 const GURL kDocumentUrl("http://www.test.not/scope/document.html");
613 const GURL kResource1("http://www.test.not/scope/resource1.js"); 617 const GURL kResource1("http://www.test.not/scope/resource1.js");
614 const int64_t kResource1Size = 1591234; 618 const int64_t kResource1Size = 1591234;
615 const GURL kResource2("http://www.test.not/scope/resource2.js"); 619 const GURL kResource2("http://www.test.not/scope/resource2.js");
616 const int64_t kResource2Size = 51; 620 const int64_t kResource2Size = 51;
617 const int64_t kRegistrationId = 0; 621 const int64_t kRegistrationId = 0;
618 const int64_t kVersionId = 0; 622 const int64_t kVersionId = 0;
619 const GURL kForeignFetchScope("http://www.test.not/scope/ff/"); 623 const GURL kForeignFetchScope("http://www.test.not/scope/ff/");
620 const url::Origin kForeignFetchOrigin(GURL("https://example.com/")); 624 const url::Origin kForeignFetchOrigin(GURL("https://example.com/"));
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 EXPECT_FALSE(found_registration.get()); 806 EXPECT_FALSE(found_registration.get());
803 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND, 807 EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND,
804 FindRegistrationForIdOnly(kRegistrationId, &found_registration)); 808 FindRegistrationForIdOnly(kRegistrationId, &found_registration));
805 EXPECT_FALSE(found_registration.get()); 809 EXPECT_FALSE(found_registration.get());
806 810
807 // Deleting an unstored registration should succeed. 811 // Deleting an unstored registration should succeed.
808 EXPECT_EQ(SERVICE_WORKER_OK, 812 EXPECT_EQ(SERVICE_WORKER_OK,
809 DeleteRegistration(kRegistrationId + 1, kScope.GetOrigin())); 813 DeleteRegistration(kRegistrationId + 1, kScope.GetOrigin()));
810 } 814 }
811 815
812 TEST_F(ServiceWorkerStorageTest, InstallingRegistrationsAreFindable) { 816 TEST_P(ServiceWorkerStorageTestP, InstallingRegistrationsAreFindable) {
813 const GURL kScope("http://www.test.not/scope/"); 817 const GURL kScope("http://www.test.not/scope/");
814 const GURL kScript("http://www.test.not/script.js"); 818 const GURL kScript("http://www.test.not/script.js");
815 const GURL kDocumentUrl("http://www.test.not/scope/document.html"); 819 const GURL kDocumentUrl("http://www.test.not/scope/document.html");
816 const int64_t kRegistrationId = 0; 820 const int64_t kRegistrationId = 0;
817 const int64_t kVersionId = 0; 821 const int64_t kVersionId = 0;
818 822
819 scoped_refptr<ServiceWorkerRegistration> found_registration; 823 scoped_refptr<ServiceWorkerRegistration> found_registration;
820 824
821 // Create an unstored registration. 825 // Create an unstored registration.
822 scoped_refptr<ServiceWorkerRegistration> live_registration = 826 scoped_refptr<ServiceWorkerRegistration> live_registration =
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 SERVICE_WORKER_OK, 935 SERVICE_WORKER_OK,
932 GetRegistrationsForOrigin(kScope.GetOrigin(), &registrations_for_origin)); 936 GetRegistrationsForOrigin(kScope.GetOrigin(), &registrations_for_origin));
933 EXPECT_TRUE(registrations_for_origin.empty()); 937 EXPECT_TRUE(registrations_for_origin.empty());
934 938
935 EXPECT_EQ(SERVICE_WORKER_OK, 939 EXPECT_EQ(SERVICE_WORKER_OK,
936 GetRegistrationsForOrigin(GURL("http://example.com/").GetOrigin(), 940 GetRegistrationsForOrigin(GURL("http://example.com/").GetOrigin(),
937 &registrations_for_origin)); 941 &registrations_for_origin));
938 EXPECT_TRUE(registrations_for_origin.empty()); 942 EXPECT_TRUE(registrations_for_origin.empty());
939 } 943 }
940 944
941 TEST_F(ServiceWorkerStorageTest, StoreUserData) { 945 TEST_P(ServiceWorkerStorageTestP, StoreUserData) {
942 const GURL kScope("http://www.test.not/scope/"); 946 const GURL kScope("http://www.test.not/scope/");
943 const GURL kScript("http://www.test.not/script.js"); 947 const GURL kScript("http://www.test.not/script.js");
944 const int64_t kRegistrationId = 0; 948 const int64_t kRegistrationId = 0;
945 const int64_t kVersionId = 0; 949 const int64_t kVersionId = 0;
946 950
947 LazyInitialize(); 951 LazyInitialize();
948 952
949 // Store a registration. 953 // Store a registration.
950 scoped_refptr<ServiceWorkerRegistration> live_registration = 954 scoped_refptr<ServiceWorkerRegistration> live_registration =
951 new ServiceWorkerRegistration(kScope, kRegistrationId, 955 new ServiceWorkerRegistration(kScope, kRegistrationId,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 ClearUserData(kRegistrationId, std::vector<std::string>())); 1074 ClearUserData(kRegistrationId, std::vector<std::string>()));
1071 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED, 1075 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED,
1072 ClearUserData(kRegistrationId, {std::string()})); 1076 ClearUserData(kRegistrationId, {std::string()}));
1073 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED, 1077 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED,
1074 ClearUserData(kRegistrationId, {std::string(), "key"})); 1078 ClearUserData(kRegistrationId, {std::string(), "key"}));
1075 data_list_out.clear(); 1079 data_list_out.clear();
1076 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED, 1080 EXPECT_EQ(SERVICE_WORKER_ERROR_FAILED,
1077 GetUserDataForAllRegistrations(std::string(), &data_list_out)); 1081 GetUserDataForAllRegistrations(std::string(), &data_list_out));
1078 } 1082 }
1079 1083
1080 class ServiceWorkerResourceStorageTest : public ServiceWorkerStorageTest { 1084 class ServiceWorkerResourceStorageTest : public ServiceWorkerStorageTestP {
1081 public: 1085 public:
1082 void SetUp() override { 1086 void SetUp() override {
1083 ServiceWorkerStorageTest::SetUp(); 1087 ServiceWorkerStorageTestP::SetUp();
1084 LazyInitialize(); 1088 LazyInitialize();
1085 1089
1086 scope_ = GURL("http://www.test.not/scope/"); 1090 scope_ = GURL("http://www.test.not/scope/");
1087 script_ = GURL("http://www.test.not/script.js"); 1091 script_ = GURL("http://www.test.not/script.js");
1088 import_ = GURL("http://www.test.not/import.js"); 1092 import_ = GURL("http://www.test.not/import.js");
1089 document_url_ = GURL("http://www.test.not/scope/document.html"); 1093 document_url_ = GURL("http://www.test.not/scope/document.html");
1090 registration_id_ = storage()->NewRegistrationId(); 1094 registration_id_ = storage()->NewRegistrationId();
1091 version_id_ = storage()->NewVersionId(); 1095 version_id_ = storage()->NewVersionId();
1092 resource_id1_ = storage()->NewResourceId(); 1096 resource_id1_ = storage()->NewResourceId();
1093 resource_id2_ = storage()->NewResourceId(); 1097 resource_id2_ = storage()->NewResourceId();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 class ServiceWorkerResourceStorageDiskTest 1156 class ServiceWorkerResourceStorageDiskTest
1153 : public ServiceWorkerResourceStorageTest { 1157 : public ServiceWorkerResourceStorageTest {
1154 public: 1158 public:
1155 void SetUp() override { 1159 void SetUp() override {
1156 ASSERT_TRUE(InitUserDataDirectory()); 1160 ASSERT_TRUE(InitUserDataDirectory());
1157 ServiceWorkerResourceStorageTest::SetUp(); 1161 ServiceWorkerResourceStorageTest::SetUp();
1158 } 1162 }
1159 1163
1160 }; 1164 };
1161 1165
1162 TEST_F(ServiceWorkerResourceStorageTest, 1166 TEST_P(ServiceWorkerResourceStorageTest,
1163 WriteMetadataWithServiceWorkerResponseMetadataWriter) { 1167 WriteMetadataWithServiceWorkerResponseMetadataWriter) {
1164 const char kMetadata1[] = "Test metadata"; 1168 const char kMetadata1[] = "Test metadata";
1165 const char kMetadata2[] = "small"; 1169 const char kMetadata2[] = "small";
1166 int64_t new_resource_id_ = storage()->NewResourceId(); 1170 int64_t new_resource_id_ = storage()->NewResourceId();
1167 // Writing metadata to nonexistent resoirce ID must fail. 1171 // Writing metadata to nonexistent resoirce ID must fail.
1168 EXPECT_GE(0, WriteResponseMetadata(storage(), new_resource_id_, kMetadata1)); 1172 EXPECT_GE(0, WriteResponseMetadata(storage(), new_resource_id_, kMetadata1));
1169 1173
1170 // Check metadata is written. 1174 // Check metadata is written.
1171 EXPECT_EQ(static_cast<int>(strlen(kMetadata1)), 1175 EXPECT_EQ(static_cast<int>(strlen(kMetadata1)),
1172 WriteResponseMetadata(storage(), resource_id1_, kMetadata1)); 1176 WriteResponseMetadata(storage(), resource_id1_, kMetadata1));
1173 EXPECT_TRUE(VerifyResponseMetadata(storage(), resource_id1_, kMetadata1)); 1177 EXPECT_TRUE(VerifyResponseMetadata(storage(), resource_id1_, kMetadata1));
1174 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); 1178 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true));
1175 1179
1176 // Check metadata is written and truncated. 1180 // Check metadata is written and truncated.
1177 EXPECT_EQ(static_cast<int>(strlen(kMetadata2)), 1181 EXPECT_EQ(static_cast<int>(strlen(kMetadata2)),
1178 WriteResponseMetadata(storage(), resource_id1_, kMetadata2)); 1182 WriteResponseMetadata(storage(), resource_id1_, kMetadata2));
1179 EXPECT_TRUE(VerifyResponseMetadata(storage(), resource_id1_, kMetadata2)); 1183 EXPECT_TRUE(VerifyResponseMetadata(storage(), resource_id1_, kMetadata2));
1180 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); 1184 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true));
1181 1185
1182 // Check metadata is deleted. 1186 // Check metadata is deleted.
1183 EXPECT_EQ(0, WriteResponseMetadata(storage(), resource_id1_, "")); 1187 EXPECT_EQ(0, WriteResponseMetadata(storage(), resource_id1_, ""));
1184 EXPECT_FALSE(VerifyResponseMetadata(storage(), resource_id1_, "")); 1188 EXPECT_FALSE(VerifyResponseMetadata(storage(), resource_id1_, ""));
1185 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); 1189 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true));
1186 } 1190 }
1187 1191
1188 TEST_F(ServiceWorkerResourceStorageTest, 1192 TEST_P(ServiceWorkerResourceStorageTest,
1189 WriteMetadataWithServiceWorkerScriptCacheMap) { 1193 WriteMetadataWithServiceWorkerScriptCacheMap) {
1190 const char kMetadata1[] = "Test metadata"; 1194 const char kMetadata1[] = "Test metadata";
1191 const char kMetadata2[] = "small"; 1195 const char kMetadata2[] = "small";
1192 ServiceWorkerVersion* version = registration_->waiting_version(); 1196 ServiceWorkerVersion* version = registration_->waiting_version();
1193 EXPECT_TRUE(version); 1197 EXPECT_TRUE(version);
1194 1198
1195 // Writing metadata to nonexistent URL must fail. 1199 // Writing metadata to nonexistent URL must fail.
1196 EXPECT_GE(0, 1200 EXPECT_GE(0,
1197 WriteMetadata(version, GURL("http://www.test.not/nonexistent.js"), 1201 WriteMetadata(version, GURL("http://www.test.not/nonexistent.js"),
1198 kMetadata1)); 1202 kMetadata1));
(...skipping 12 matching lines...) Expand all
1211 WriteMetadata(version, script_, kMetadata2)); 1215 WriteMetadata(version, script_, kMetadata2));
1212 EXPECT_TRUE(VerifyResponseMetadata(storage(), resource_id1_, kMetadata2)); 1216 EXPECT_TRUE(VerifyResponseMetadata(storage(), resource_id1_, kMetadata2));
1213 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); 1217 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true));
1214 1218
1215 // Check metadata is deleted. 1219 // Check metadata is deleted.
1216 EXPECT_EQ(0, ClearMetadata(version, script_)); 1220 EXPECT_EQ(0, ClearMetadata(version, script_));
1217 EXPECT_FALSE(VerifyResponseMetadata(storage(), resource_id1_, "")); 1221 EXPECT_FALSE(VerifyResponseMetadata(storage(), resource_id1_, ""));
1218 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true)); 1222 EXPECT_TRUE(VerifyBasicResponse(storage(), resource_id1_, true));
1219 } 1223 }
1220 1224
1221 TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_NoLiveVersion) { 1225 TEST_P(ServiceWorkerResourceStorageTest, DeleteRegistration_NoLiveVersion) {
1222 bool was_called = false; 1226 bool was_called = false;
1223 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; 1227 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED;
1224 std::set<int64_t> verify_ids; 1228 std::set<int64_t> verify_ids;
1225 1229
1226 registration_->SetWaitingVersion(NULL); 1230 registration_->SetWaitingVersion(NULL);
1227 registration_ = NULL; 1231 registration_ = NULL;
1228 1232
1229 // Deleting the registration should result in the resources being added to the 1233 // Deleting the registration should result in the resources being added to the
1230 // purgeable list and then doomed in the disk cache and removed from that 1234 // purgeable list and then doomed in the disk cache and removed from that
1231 // list. 1235 // list.
(...skipping 11 matching lines...) Expand all
1243 EXPECT_EQ(2u, verify_ids.size()); 1247 EXPECT_EQ(2u, verify_ids.size());
1244 verify_ids.clear(); 1248 verify_ids.clear();
1245 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 1249 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
1246 storage()->database_->GetPurgeableResourceIds(&verify_ids)); 1250 storage()->database_->GetPurgeableResourceIds(&verify_ids));
1247 EXPECT_TRUE(verify_ids.empty()); 1251 EXPECT_TRUE(verify_ids.empty());
1248 1252
1249 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); 1253 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false));
1250 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); 1254 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false));
1251 } 1255 }
1252 1256
1253 TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_WaitingVersion) { 1257 TEST_P(ServiceWorkerResourceStorageTest, DeleteRegistration_WaitingVersion) {
1254 bool was_called = false; 1258 bool was_called = false;
1255 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED; 1259 ServiceWorkerStatusCode result = SERVICE_WORKER_ERROR_FAILED;
1256 std::set<int64_t> verify_ids; 1260 std::set<int64_t> verify_ids;
1257 1261
1258 // Deleting the registration should result in the resources being added to the 1262 // Deleting the registration should result in the resources being added to the
1259 // purgeable list and then doomed in the disk cache and removed from that 1263 // purgeable list and then doomed in the disk cache and removed from that
1260 // list. 1264 // list.
1261 storage()->DeleteRegistration( 1265 storage()->DeleteRegistration(
1262 registration_->id(), 1266 registration_->id(),
1263 scope_.GetOrigin(), 1267 scope_.GetOrigin(),
(...skipping 21 matching lines...) Expand all
1285 EXPECT_EQ(2u, verify_ids.size()); 1289 EXPECT_EQ(2u, verify_ids.size());
1286 verify_ids.clear(); 1290 verify_ids.clear();
1287 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 1291 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
1288 storage()->database_->GetPurgeableResourceIds(&verify_ids)); 1292 storage()->database_->GetPurgeableResourceIds(&verify_ids));
1289 EXPECT_TRUE(verify_ids.empty()); 1293 EXPECT_TRUE(verify_ids.empty());
1290 1294
1291 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); 1295 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false));
1292 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); 1296 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false));
1293 } 1297 }
1294 1298
1295 TEST_F(ServiceWorkerResourceStorageTest, DeleteRegistration_ActiveVersion) { 1299 TEST_P(ServiceWorkerResourceStorageTest, DeleteRegistration_ActiveVersion) {
1296 // Promote the worker to active and add a controllee. 1300 // Promote the worker to active and add a controllee.
1297 registration_->SetActiveVersion(registration_->waiting_version()); 1301 registration_->SetActiveVersion(registration_->waiting_version());
1298 storage()->UpdateToActiveState( 1302 storage()->UpdateToActiveState(
1299 registration_.get(), base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1303 registration_.get(), base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1300 std::unique_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( 1304 std::unique_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
1301 33 /* dummy render process id */, MSG_ROUTING_NONE, 1305 33 /* dummy render process id */, MSG_ROUTING_NONE,
1302 1 /* dummy provider_id */, SERVICE_WORKER_PROVIDER_FOR_WINDOW, 1306 1 /* dummy provider_id */, SERVICE_WORKER_PROVIDER_FOR_WINDOW,
1303 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE, 1307 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE,
1304 context()->AsWeakPtr(), NULL)); 1308 context()->AsWeakPtr(), NULL));
1305 registration_->active_version()->AddControllee(host.get()); 1309 registration_->active_version()->AddControllee(host.get());
(...skipping 30 matching lines...) Expand all
1336 base::RunLoop().RunUntilIdle(); 1340 base::RunLoop().RunUntilIdle();
1337 verify_ids.clear(); 1341 verify_ids.clear();
1338 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 1342 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
1339 storage()->database_->GetPurgeableResourceIds(&verify_ids)); 1343 storage()->database_->GetPurgeableResourceIds(&verify_ids));
1340 EXPECT_TRUE(verify_ids.empty()); 1344 EXPECT_TRUE(verify_ids.empty());
1341 1345
1342 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); 1346 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false));
1343 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); 1347 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false));
1344 } 1348 }
1345 1349
1346 TEST_F(ServiceWorkerResourceStorageDiskTest, CleanupOnRestart) { 1350 TEST_P(ServiceWorkerResourceStorageDiskTest, CleanupOnRestart) {
1347 // Promote the worker to active and add a controllee. 1351 // Promote the worker to active and add a controllee.
1348 registration_->SetActiveVersion(registration_->waiting_version()); 1352 registration_->SetActiveVersion(registration_->waiting_version());
1349 registration_->SetWaitingVersion(NULL); 1353 registration_->SetWaitingVersion(NULL);
1350 storage()->UpdateToActiveState( 1354 storage()->UpdateToActiveState(
1351 registration_.get(), base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1355 registration_.get(), base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1352 std::unique_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( 1356 std::unique_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
1353 33 /* dummy render process id */, MSG_ROUTING_NONE, 1357 33 /* dummy render process id */, MSG_ROUTING_NONE,
1354 1 /* dummy provider_id */, SERVICE_WORKER_PROVIDER_FOR_WINDOW, 1358 1 /* dummy provider_id */, SERVICE_WORKER_PROVIDER_FOR_WINDOW,
1355 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE, 1359 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE,
1356 context()->AsWeakPtr(), NULL)); 1360 context()->AsWeakPtr(), NULL));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 1425 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
1422 storage()->database_->GetPurgeableResourceIds(&verify_ids)); 1426 storage()->database_->GetPurgeableResourceIds(&verify_ids));
1423 EXPECT_TRUE(verify_ids.empty()); 1427 EXPECT_TRUE(verify_ids.empty());
1424 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); 1428 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false));
1425 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); 1429 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false));
1426 EXPECT_FALSE( 1430 EXPECT_FALSE(
1427 VerifyBasicResponse(storage(), kStaleUncommittedResourceId, false)); 1431 VerifyBasicResponse(storage(), kStaleUncommittedResourceId, false));
1428 EXPECT_TRUE(VerifyBasicResponse(storage(), kNewResourceId, true)); 1432 EXPECT_TRUE(VerifyBasicResponse(storage(), kNewResourceId, true));
1429 } 1433 }
1430 1434
1431 TEST_F(ServiceWorkerResourceStorageDiskTest, DeleteAndStartOver) { 1435 TEST_P(ServiceWorkerResourceStorageDiskTest, DeleteAndStartOver) {
1432 EXPECT_FALSE(storage()->IsDisabled()); 1436 EXPECT_FALSE(storage()->IsDisabled());
1433 ASSERT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath())); 1437 ASSERT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath()));
1434 ASSERT_TRUE(base::DirectoryExists(storage()->GetDatabasePath())); 1438 ASSERT_TRUE(base::DirectoryExists(storage()->GetDatabasePath()));
1435 1439
1436 base::RunLoop run_loop; 1440 base::RunLoop run_loop;
1437 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; 1441 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
1438 storage()->DeleteAndStartOver( 1442 storage()->DeleteAndStartOver(
1439 base::Bind(&StatusAndQuitCallback, &status, run_loop.QuitClosure())); 1443 base::Bind(&StatusAndQuitCallback, &status, run_loop.QuitClosure()));
1440 run_loop.Run(); 1444 run_loop.Run();
1441 1445
1442 EXPECT_EQ(SERVICE_WORKER_OK, status); 1446 EXPECT_EQ(SERVICE_WORKER_OK, status);
1443 EXPECT_TRUE(storage()->IsDisabled()); 1447 EXPECT_TRUE(storage()->IsDisabled());
1444 EXPECT_FALSE(base::DirectoryExists(storage()->GetDiskCachePath())); 1448 EXPECT_FALSE(base::DirectoryExists(storage()->GetDiskCachePath()));
1445 EXPECT_FALSE(base::DirectoryExists(storage()->GetDatabasePath())); 1449 EXPECT_FALSE(base::DirectoryExists(storage()->GetDatabasePath()));
1446 } 1450 }
1447 1451
1448 TEST_F(ServiceWorkerResourceStorageDiskTest, 1452 TEST_P(ServiceWorkerResourceStorageDiskTest,
1449 DeleteAndStartOver_UnrelatedFileExists) { 1453 DeleteAndStartOver_UnrelatedFileExists) {
1450 EXPECT_FALSE(storage()->IsDisabled()); 1454 EXPECT_FALSE(storage()->IsDisabled());
1451 ASSERT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath())); 1455 ASSERT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath()));
1452 ASSERT_TRUE(base::DirectoryExists(storage()->GetDatabasePath())); 1456 ASSERT_TRUE(base::DirectoryExists(storage()->GetDatabasePath()));
1453 1457
1454 // Create an unrelated file in the database directory to make sure such a file 1458 // Create an unrelated file in the database directory to make sure such a file
1455 // does not prevent DeleteAndStartOver. 1459 // does not prevent DeleteAndStartOver.
1456 base::FilePath file_path; 1460 base::FilePath file_path;
1457 ASSERT_TRUE( 1461 ASSERT_TRUE(
1458 base::CreateTemporaryFileInDir(storage()->GetDatabasePath(), &file_path)); 1462 base::CreateTemporaryFileInDir(storage()->GetDatabasePath(), &file_path));
1459 ASSERT_TRUE(base::PathExists(file_path)); 1463 ASSERT_TRUE(base::PathExists(file_path));
1460 1464
1461 base::RunLoop run_loop; 1465 base::RunLoop run_loop;
1462 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE; 1466 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_MAX_VALUE;
1463 storage()->DeleteAndStartOver( 1467 storage()->DeleteAndStartOver(
1464 base::Bind(&StatusAndQuitCallback, &status, run_loop.QuitClosure())); 1468 base::Bind(&StatusAndQuitCallback, &status, run_loop.QuitClosure()));
1465 run_loop.Run(); 1469 run_loop.Run();
1466 1470
1467 EXPECT_EQ(SERVICE_WORKER_OK, status); 1471 EXPECT_EQ(SERVICE_WORKER_OK, status);
1468 EXPECT_TRUE(storage()->IsDisabled()); 1472 EXPECT_TRUE(storage()->IsDisabled());
1469 EXPECT_FALSE(base::DirectoryExists(storage()->GetDiskCachePath())); 1473 EXPECT_FALSE(base::DirectoryExists(storage()->GetDiskCachePath()));
1470 EXPECT_FALSE(base::DirectoryExists(storage()->GetDatabasePath())); 1474 EXPECT_FALSE(base::DirectoryExists(storage()->GetDatabasePath()));
1471 } 1475 }
1472 1476
1473 TEST_F(ServiceWorkerResourceStorageDiskTest, 1477 TEST_P(ServiceWorkerResourceStorageDiskTest,
1474 DeleteAndStartOver_OpenedFileExists) { 1478 DeleteAndStartOver_OpenedFileExists) {
1475 EXPECT_FALSE(storage()->IsDisabled()); 1479 EXPECT_FALSE(storage()->IsDisabled());
1476 ASSERT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath())); 1480 ASSERT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath()));
1477 ASSERT_TRUE(base::DirectoryExists(storage()->GetDatabasePath())); 1481 ASSERT_TRUE(base::DirectoryExists(storage()->GetDatabasePath()));
1478 1482
1479 // Create an unrelated opened file in the database directory to make sure such 1483 // Create an unrelated opened file in the database directory to make sure such
1480 // a file does not prevent DeleteAndStartOver on non-Windows platforms. 1484 // a file does not prevent DeleteAndStartOver on non-Windows platforms.
1481 base::FilePath file_path; 1485 base::FilePath file_path;
1482 base::ScopedFILE file(base::CreateAndOpenTemporaryFileInDir( 1486 base::ScopedFILE file(base::CreateAndOpenTemporaryFileInDir(
1483 storage()->GetDatabasePath(), &file_path)); 1487 storage()->GetDatabasePath(), &file_path));
(...skipping 13 matching lines...) Expand all
1497 EXPECT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath())); 1501 EXPECT_TRUE(base::DirectoryExists(storage()->GetDiskCachePath()));
1498 EXPECT_TRUE(base::DirectoryExists(storage()->GetDatabasePath())); 1502 EXPECT_TRUE(base::DirectoryExists(storage()->GetDatabasePath()));
1499 #else 1503 #else
1500 EXPECT_EQ(SERVICE_WORKER_OK, status); 1504 EXPECT_EQ(SERVICE_WORKER_OK, status);
1501 EXPECT_TRUE(storage()->IsDisabled()); 1505 EXPECT_TRUE(storage()->IsDisabled());
1502 EXPECT_FALSE(base::DirectoryExists(storage()->GetDiskCachePath())); 1506 EXPECT_FALSE(base::DirectoryExists(storage()->GetDiskCachePath()));
1503 EXPECT_FALSE(base::DirectoryExists(storage()->GetDatabasePath())); 1507 EXPECT_FALSE(base::DirectoryExists(storage()->GetDatabasePath()));
1504 #endif 1508 #endif
1505 } 1509 }
1506 1510
1507 TEST_F(ServiceWorkerResourceStorageTest, UpdateRegistration) { 1511 TEST_P(ServiceWorkerResourceStorageTest, UpdateRegistration) {
1508 // Promote the worker to active worker and add a controllee. 1512 // Promote the worker to active worker and add a controllee.
1509 registration_->SetActiveVersion(registration_->waiting_version()); 1513 registration_->SetActiveVersion(registration_->waiting_version());
1510 storage()->UpdateToActiveState( 1514 storage()->UpdateToActiveState(
1511 registration_.get(), base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1515 registration_.get(), base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1512 std::unique_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( 1516 std::unique_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost(
1513 33 /* dummy render process id */, MSG_ROUTING_NONE, 1517 33 /* dummy render process id */, MSG_ROUTING_NONE,
1514 1 /* dummy provider_id */, SERVICE_WORKER_PROVIDER_FOR_WINDOW, 1518 1 /* dummy provider_id */, SERVICE_WORKER_PROVIDER_FOR_WINDOW,
1515 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE, 1519 ServiceWorkerProviderHost::FrameSecurityLevel::SECURE,
1516 context()->AsWeakPtr(), NULL)); 1520 context()->AsWeakPtr(), NULL));
1517 registration_->active_version()->AddControllee(host.get()); 1521 registration_->active_version()->AddControllee(host.get());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1562 base::RunLoop().RunUntilIdle(); 1566 base::RunLoop().RunUntilIdle();
1563 verify_ids.clear(); 1567 verify_ids.clear();
1564 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 1568 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
1565 storage()->database_->GetPurgeableResourceIds(&verify_ids)); 1569 storage()->database_->GetPurgeableResourceIds(&verify_ids));
1566 EXPECT_TRUE(verify_ids.empty()); 1570 EXPECT_TRUE(verify_ids.empty());
1567 1571
1568 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false)); 1572 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id1_, false));
1569 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false)); 1573 EXPECT_FALSE(VerifyBasicResponse(storage(), resource_id2_, false));
1570 } 1574 }
1571 1575
1572 TEST_F(ServiceWorkerStorageTest, FindRegistration_LongestScopeMatch) { 1576 TEST_P(ServiceWorkerStorageTestP, FindRegistration_LongestScopeMatch) {
1573 const GURL kDocumentUrl("http://www.example.com/scope/foo"); 1577 const GURL kDocumentUrl("http://www.example.com/scope/foo");
1574 scoped_refptr<ServiceWorkerRegistration> found_registration; 1578 scoped_refptr<ServiceWorkerRegistration> found_registration;
1575 1579
1576 // Registration for "/scope/". 1580 // Registration for "/scope/".
1577 const GURL kScope1("http://www.example.com/scope/"); 1581 const GURL kScope1("http://www.example.com/scope/");
1578 const GURL kScript1("http://www.example.com/script1.js"); 1582 const GURL kScript1("http://www.example.com/script1.js");
1579 const int64_t kRegistrationId1 = 1; 1583 const int64_t kRegistrationId1 = 1;
1580 const int64_t kVersionId1 = 1; 1584 const int64_t kVersionId1 = 1;
1581 scoped_refptr<ServiceWorkerRegistration> live_registration1 = 1585 scoped_refptr<ServiceWorkerRegistration> live_registration1 =
1582 new ServiceWorkerRegistration(kScope1, kRegistrationId1, 1586 new ServiceWorkerRegistration(kScope1, kRegistrationId1,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 live_registration2.get(), NULL, SERVICE_WORKER_OK); 1660 live_registration2.get(), NULL, SERVICE_WORKER_OK);
1657 storage()->NotifyDoneInstallingRegistration( 1661 storage()->NotifyDoneInstallingRegistration(
1658 live_registration3.get(), NULL, SERVICE_WORKER_OK); 1662 live_registration3.get(), NULL, SERVICE_WORKER_OK);
1659 1663
1660 // Find a registration among installed ones. 1664 // Find a registration among installed ones.
1661 EXPECT_EQ(SERVICE_WORKER_OK, 1665 EXPECT_EQ(SERVICE_WORKER_OK,
1662 FindRegistrationForDocument(kDocumentUrl, &found_registration)); 1666 FindRegistrationForDocument(kDocumentUrl, &found_registration));
1663 EXPECT_EQ(live_registration2, found_registration); 1667 EXPECT_EQ(live_registration2, found_registration);
1664 } 1668 }
1665 1669
1666 class ServiceWorkerStorageDiskTest : public ServiceWorkerStorageTest { 1670 class ServiceWorkerStorageDiskTest : public ServiceWorkerStorageTestP {
1667 public: 1671 public:
1668 void SetUp() override { 1672 void SetUp() override {
1669 ASSERT_TRUE(InitUserDataDirectory()); 1673 ASSERT_TRUE(InitUserDataDirectory());
1670 ServiceWorkerStorageTest::SetUp(); 1674 ServiceWorkerStorageTestP::SetUp();
1671 } 1675 }
1672 }; 1676 };
1673 1677
1674 TEST_F(ServiceWorkerStorageDiskTest, OriginHasForeignFetchRegistrations) { 1678 TEST_P(ServiceWorkerStorageDiskTest, OriginHasForeignFetchRegistrations) {
1675 LazyInitialize(); 1679 LazyInitialize();
1676 1680
1677 // Registration 1 for http://www.example.com 1681 // Registration 1 for http://www.example.com
1678 const GURL kScope1("http://www.example.com/scope/"); 1682 const GURL kScope1("http://www.example.com/scope/");
1679 const GURL kScript1("http://www.example.com/script1.js"); 1683 const GURL kScript1("http://www.example.com/script1.js");
1680 const int64_t kRegistrationId1 = 1; 1684 const int64_t kRegistrationId1 = 1;
1681 const int64_t kVersionId1 = 1; 1685 const int64_t kVersionId1 = 1;
1682 scoped_refptr<ServiceWorkerRegistration> live_registration1 = 1686 scoped_refptr<ServiceWorkerRegistration> live_registration1 =
1683 new ServiceWorkerRegistration(kScope1, kRegistrationId1, 1687 new ServiceWorkerRegistration(kScope1, kRegistrationId1,
1684 context()->AsWeakPtr()); 1688 context()->AsWeakPtr());
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 1779
1776 // Remove other registration at first origin. 1780 // Remove other registration at first origin.
1777 EXPECT_EQ(SERVICE_WORKER_OK, 1781 EXPECT_EQ(SERVICE_WORKER_OK,
1778 DeleteRegistration(kRegistrationId2, kScope2.GetOrigin())); 1782 DeleteRegistration(kRegistrationId2, kScope2.GetOrigin()));
1779 1783
1780 // No foreign fetch registrations remain. 1784 // No foreign fetch registrations remain.
1781 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin1)); 1785 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin1));
1782 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin2)); 1786 EXPECT_FALSE(storage()->OriginHasForeignFetchRegistrations(kOrigin2));
1783 } 1787 }
1784 1788
1785 class ServiceWorkerStorageOriginTrialsTest : public ServiceWorkerStorageTest { 1789 class ServiceWorkerStorageOriginTrialsTest : public ServiceWorkerStorageTestP {
1786 public: 1790 public:
1787 ServiceWorkerStorageOriginTrialsTest() {} 1791 ServiceWorkerStorageOriginTrialsTest() {}
1788 ~ServiceWorkerStorageOriginTrialsTest() override {} 1792 ~ServiceWorkerStorageOriginTrialsTest() override {}
1789 1793
1790 protected: 1794 protected:
1791 void WriteRegistration(const RegistrationData& registration, 1795 void WriteRegistration(const RegistrationData& registration,
1792 const std::vector<ResourceRecord>& resources) { 1796 const std::vector<ResourceRecord>& resources) {
1793 ServiceWorkerDatabase::RegistrationData deleted_version; 1797 ServiceWorkerDatabase::RegistrationData deleted_version;
1794 std::vector<int64_t> newly_purgeable_resources; 1798 std::vector<int64_t> newly_purgeable_resources;
1795 1799
1796 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, 1800 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK,
1797 storage()->database_->WriteRegistration( 1801 storage()->database_->WriteRegistration(
1798 registration, resources, &deleted_version, 1802 registration, resources, &deleted_version,
1799 &newly_purgeable_resources)); 1803 &newly_purgeable_resources));
1800 } 1804 }
1801 }; 1805 };
1802 1806
1803 TEST_F(ServiceWorkerStorageOriginTrialsTest, AbsentEntryAndEmptyEntry) { 1807 TEST_P(ServiceWorkerStorageOriginTrialsTest, AbsentEntryAndEmptyEntry) {
1804 const GURL origin1("http://www1.example.com"); 1808 const GURL origin1("http://www1.example.com");
1805 const GURL scope1("http://www1.example.com/foo/"); 1809 const GURL scope1("http://www1.example.com/foo/");
1806 RegistrationData data1; 1810 RegistrationData data1;
1807 data1.registration_id = 100; 1811 data1.registration_id = 100;
1808 data1.scope = scope1; 1812 data1.scope = scope1;
1809 data1.script = GURL(origin1.spec() + "/script.js"); 1813 data1.script = GURL(origin1.spec() + "/script.js");
1810 data1.version_id = 1000; 1814 data1.version_id = 1000;
1811 data1.is_active = true; 1815 data1.is_active = true;
1812 data1.resources_total_size_bytes = 100; 1816 data1.resources_total_size_bytes = 100;
1813 // Don't set origin_trial_tokens to simulate old database entry. 1817 // Don't set origin_trial_tokens to simulate old database entry.
(...skipping 29 matching lines...) Expand all
1843 EXPECT_EQ(SERVICE_WORKER_OK, 1847 EXPECT_EQ(SERVICE_WORKER_OK,
1844 FindRegistrationForDocument(scope2, &found_registration)); 1848 FindRegistrationForDocument(scope2, &found_registration));
1845 ASSERT_TRUE(found_registration->active_version()); 1849 ASSERT_TRUE(found_registration->active_version());
1846 // Empty origin_trial_tokens must exist. 1850 // Empty origin_trial_tokens must exist.
1847 ASSERT_TRUE(found_registration->active_version()->origin_trial_tokens()); 1851 ASSERT_TRUE(found_registration->active_version()->origin_trial_tokens());
1848 EXPECT_TRUE( 1852 EXPECT_TRUE(
1849 found_registration->active_version()->origin_trial_tokens()->empty()); 1853 found_registration->active_version()->origin_trial_tokens()->empty());
1850 } 1854 }
1851 1855
1852 class ServiceWorkerStorageOriginTrialsDiskTest 1856 class ServiceWorkerStorageOriginTrialsDiskTest
1853 : public ServiceWorkerStorageTest { 1857 : public ServiceWorkerStorageTestP {
1854 public: 1858 public:
1855 ServiceWorkerStorageOriginTrialsDiskTest() { 1859 ServiceWorkerStorageOriginTrialsDiskTest() {
1856 SetContentClient(&test_content_client_); 1860 SetContentClient(&test_content_client_);
1857 } 1861 }
1858 ~ServiceWorkerStorageOriginTrialsDiskTest() override { 1862 ~ServiceWorkerStorageOriginTrialsDiskTest() override {
1859 SetContentClient(nullptr); 1863 SetContentClient(nullptr);
1860 } 1864 }
1861 void SetUp() override { 1865 void SetUp() override {
1862 ASSERT_TRUE(InitUserDataDirectory()); 1866 ASSERT_TRUE(InitUserDataDirectory());
1863 ServiceWorkerStorageTest::SetUp(); 1867 ServiceWorkerStorageTestP::SetUp();
1864 } 1868 }
1865 1869
1866 private: 1870 private:
1867 class TestOriginTrialPolicy : public OriginTrialPolicy { 1871 class TestOriginTrialPolicy : public OriginTrialPolicy {
1868 public: 1872 public:
1869 base::StringPiece GetPublicKey() const override { 1873 base::StringPiece GetPublicKey() const override {
1870 return base::StringPiece(reinterpret_cast<const char*>(kTestPublicKey), 1874 return base::StringPiece(reinterpret_cast<const char*>(kTestPublicKey),
1871 arraysize(kTestPublicKey)); 1875 arraysize(kTestPublicKey));
1872 } 1876 }
1873 bool IsFeatureDisabled(base::StringPiece feature) const override { 1877 bool IsFeatureDisabled(base::StringPiece feature) const override {
1874 return false; 1878 return false;
1875 } 1879 }
1876 }; 1880 };
1877 class TestContentClient : public ContentClient { 1881 class TestContentClient : public ContentClient {
1878 public: 1882 public:
1879 // ContentRendererClient methods 1883 // ContentRendererClient methods
1880 OriginTrialPolicy* GetOriginTrialPolicy() override { 1884 OriginTrialPolicy* GetOriginTrialPolicy() override {
1881 return &origin_trial_policy_; 1885 return &origin_trial_policy_;
1882 } 1886 }
1883 1887
1884 private: 1888 private:
1885 TestOriginTrialPolicy origin_trial_policy_; 1889 TestOriginTrialPolicy origin_trial_policy_;
1886 }; 1890 };
1887 TestContentClient test_content_client_; 1891 TestContentClient test_content_client_;
1888 }; 1892 };
1889 1893
1890 TEST_F(ServiceWorkerStorageOriginTrialsDiskTest, FromMainScript) { 1894 TEST_P(ServiceWorkerStorageOriginTrialsDiskTest, FromMainScript) {
1891 LazyInitialize(); 1895 LazyInitialize();
1892 const GURL kScope("https://valid.example.com/scope"); 1896 const GURL kScope("https://valid.example.com/scope");
1893 const GURL kScript("https://valid.example.com/script.js"); 1897 const GURL kScript("https://valid.example.com/script.js");
1894 const int64_t kRegistrationId = 1; 1898 const int64_t kRegistrationId = 1;
1895 const int64_t kVersionId = 1; 1899 const int64_t kVersionId = 1;
1896 scoped_refptr<ServiceWorkerRegistration> registration = 1900 scoped_refptr<ServiceWorkerRegistration> registration =
1897 new ServiceWorkerRegistration(kScope, kRegistrationId, 1901 new ServiceWorkerRegistration(kScope, kRegistrationId,
1898 context()->AsWeakPtr()); 1902 context()->AsWeakPtr());
1899 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion( 1903 scoped_refptr<ServiceWorkerVersion> version = new ServiceWorkerVersion(
1900 registration.get(), kScript, kVersionId, context()->AsWeakPtr()); 1904 registration.get(), kScript, kVersionId, context()->AsWeakPtr());
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1975 const TrialTokenValidator::FeatureToTokensMap& found_tokens = 1979 const TrialTokenValidator::FeatureToTokensMap& found_tokens =
1976 *found_registration->active_version()->origin_trial_tokens(); 1980 *found_registration->active_version()->origin_trial_tokens();
1977 ASSERT_EQ(2UL, found_tokens.size()); 1981 ASSERT_EQ(2UL, found_tokens.size());
1978 ASSERT_EQ(1UL, found_tokens.at("Feature1").size()); 1982 ASSERT_EQ(1UL, found_tokens.at("Feature1").size());
1979 EXPECT_EQ(kFeature1Token, found_tokens.at("Feature1")[0]); 1983 EXPECT_EQ(kFeature1Token, found_tokens.at("Feature1")[0]);
1980 ASSERT_EQ(2UL, found_tokens.at("Feature2").size()); 1984 ASSERT_EQ(2UL, found_tokens.at("Feature2").size());
1981 EXPECT_EQ(kFeature2Token1, found_tokens.at("Feature2")[0]); 1985 EXPECT_EQ(kFeature2Token1, found_tokens.at("Feature2")[0]);
1982 EXPECT_EQ(kFeature2Token2, found_tokens.at("Feature2")[1]); 1986 EXPECT_EQ(kFeature2Token2, found_tokens.at("Feature2")[1]);
1983 } 1987 }
1984 1988
1989 INSTANTIATE_TEST_CASE_P(ServiceWorkerResourceStorageDiskTest,
1990 ServiceWorkerResourceStorageDiskTest,
1991 testing::Bool());
1992 INSTANTIATE_TEST_CASE_P(ServiceWorkerResourceStorageTest,
1993 ServiceWorkerResourceStorageTest,
1994 testing::Bool());
1995 INSTANTIATE_TEST_CASE_P(ServiceWorkerStorageDiskTest,
1996 ServiceWorkerStorageDiskTest,
1997 testing::Bool());
1998 INSTANTIATE_TEST_CASE_P(ServiceWorkerStorageOriginTrialsDiskTest,
1999 ServiceWorkerStorageOriginTrialsDiskTest,
2000 testing::Bool());
2001 INSTANTIATE_TEST_CASE_P(ServiceWorkerStorageOriginTrialsTest,
2002 ServiceWorkerStorageOriginTrialsTest,
2003 testing::Bool());
2004 INSTANTIATE_TEST_CASE_P(ServiceWorkerStorageTestP,
2005 ServiceWorkerStorageTestP,
2006 testing::Bool());
2007
1985 } // namespace content 2008 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698