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

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

Issue 2771823002: Implement updateViaCache flag and no-cache by default for main service worker scripts
Patch Set: change useCache to updateViaCache Created 3 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_database.h" 5 #include "content/browser/service_worker/service_worker_database.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 EXPECT_EQ(expected.script, actual.script); 66 EXPECT_EQ(expected.script, actual.script);
67 EXPECT_EQ(expected.version_id, actual.version_id); 67 EXPECT_EQ(expected.version_id, actual.version_id);
68 EXPECT_EQ(expected.is_active, actual.is_active); 68 EXPECT_EQ(expected.is_active, actual.is_active);
69 EXPECT_EQ(expected.has_fetch_handler, actual.has_fetch_handler); 69 EXPECT_EQ(expected.has_fetch_handler, actual.has_fetch_handler);
70 EXPECT_EQ(expected.last_update_check, actual.last_update_check); 70 EXPECT_EQ(expected.last_update_check, actual.last_update_check);
71 EXPECT_EQ(expected.resources_total_size_bytes, 71 EXPECT_EQ(expected.resources_total_size_bytes,
72 actual.resources_total_size_bytes); 72 actual.resources_total_size_bytes);
73 EXPECT_EQ(expected.foreign_fetch_scopes, actual.foreign_fetch_scopes); 73 EXPECT_EQ(expected.foreign_fetch_scopes, actual.foreign_fetch_scopes);
74 EXPECT_EQ(expected.foreign_fetch_origins, actual.foreign_fetch_origins); 74 EXPECT_EQ(expected.foreign_fetch_origins, actual.foreign_fetch_origins);
75 EXPECT_EQ(expected.used_features, actual.used_features); 75 EXPECT_EQ(expected.used_features, actual.used_features);
76 EXPECT_EQ(expected.update_via_cache, actual.update_via_cache);
76 } 77 }
77 78
78 void VerifyResourceRecords(const std::vector<Resource>& expected, 79 void VerifyResourceRecords(const std::vector<Resource>& expected,
79 const std::vector<Resource>& actual) { 80 const std::vector<Resource>& actual) {
80 ASSERT_EQ(expected.size(), actual.size()); 81 ASSERT_EQ(expected.size(), actual.size());
81 for (size_t i = 0; i < expected.size(); ++i) { 82 for (size_t i = 0; i < expected.size(); ++i) {
82 EXPECT_EQ(expected[i].resource_id, actual[i].resource_id); 83 EXPECT_EQ(expected[i].resource_id, actual[i].resource_id);
83 EXPECT_EQ(expected[i].url, actual[i].url); 84 EXPECT_EQ(expected[i].url, actual[i].url);
84 EXPECT_EQ(expected[i].size_bytes, actual[i].size_bytes); 85 EXPECT_EQ(expected[i].size_bytes, actual[i].size_bytes);
85 } 86 }
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 database->WriteRegistration(data1, resources1, &deleted_version, 565 database->WriteRegistration(data1, resources1, &deleted_version,
565 &newly_purgeable_resources)); 566 &newly_purgeable_resources));
566 567
567 GURL origin2("http://www2.example.com"); 568 GURL origin2("http://www2.example.com");
568 RegistrationData data2; 569 RegistrationData data2;
569 data2.registration_id = 200; 570 data2.registration_id = 200;
570 data2.scope = URL(origin2, "/bar"); 571 data2.scope = URL(origin2, "/bar");
571 data2.script = URL(origin2, "/script2.js"); 572 data2.script = URL(origin2, "/script2.js");
572 data2.version_id = 2000; 573 data2.version_id = 2000;
573 data2.resources_total_size_bytes = 200; 574 data2.resources_total_size_bytes = 200;
575 data2.update_via_cache = blink::WebServiceWorkerUpdateViaCache::kNone;
574 std::vector<Resource> resources2; 576 std::vector<Resource> resources2;
575 resources2.push_back(CreateResource(2, data2.script, 200)); 577 resources2.push_back(CreateResource(2, data2.script, 200));
576 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, 578 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK,
577 database->WriteRegistration(data2, resources2, &deleted_version, 579 database->WriteRegistration(data2, resources2, &deleted_version,
578 &newly_purgeable_resources)); 580 &newly_purgeable_resources));
579 581
580 GURL origin3("http://www3.example.com"); 582 GURL origin3("http://www3.example.com");
581 RegistrationData data3; 583 RegistrationData data3;
582 data3.registration_id = 300; 584 data3.registration_id = 300;
583 data3.scope = URL(origin3, "/hoge"); 585 data3.scope = URL(origin3, "/hoge");
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 793
792 // Update the registration. 794 // Update the registration.
793 RegistrationData updated_data = data; 795 RegistrationData updated_data = data;
794 updated_data.script = URL(origin, "/resource3"); 796 updated_data.script = URL(origin, "/resource3");
795 updated_data.version_id = data.version_id + 1; 797 updated_data.version_id = data.version_id + 1;
796 updated_data.resources_total_size_bytes = 12 + 13; 798 updated_data.resources_total_size_bytes = 12 + 13;
797 updated_data.foreign_fetch_scopes.clear(); 799 updated_data.foreign_fetch_scopes.clear();
798 updated_data.foreign_fetch_origins.push_back( 800 updated_data.foreign_fetch_origins.push_back(
799 url::Origin(GURL("https://example.com"))); 801 url::Origin(GURL("https://example.com")));
800 updated_data.used_features = {109, 421, 9101}; 802 updated_data.used_features = {109, 421, 9101};
803 updated_data.update_via_cache = blink::WebServiceWorkerUpdateViaCache::kAll;
801 std::vector<Resource> resources2; 804 std::vector<Resource> resources2;
802 resources2.push_back(CreateResource(3, URL(origin, "/resource3"), 12)); 805 resources2.push_back(CreateResource(3, URL(origin, "/resource3"), 12));
803 resources2.push_back(CreateResource(4, URL(origin, "/resource4"), 13)); 806 resources2.push_back(CreateResource(4, URL(origin, "/resource4"), 13));
804 807
805 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 808 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
806 database->WriteRegistration(updated_data, 809 database->WriteRegistration(updated_data,
807 resources2, 810 resources2,
808 &deleted_version, 811 &deleted_version,
809 &newly_purgeable_resources)); 812 &newly_purgeable_resources));
810 EXPECT_EQ(data.version_id, deleted_version.version_id); 813 EXPECT_EQ(data.version_id, deleted_version.version_id);
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 std::vector<Resource> resources1; 1189 std::vector<Resource> resources1;
1187 resources1.push_back(CreateResource(1, data1.script, 100)); 1190 resources1.push_back(CreateResource(1, data1.script, 100));
1188 1191
1189 // Add registration 2. 1192 // Add registration 2.
1190 RegistrationData data2; 1193 RegistrationData data2;
1191 data2.registration_id = 101; 1194 data2.registration_id = 101;
1192 data2.scope = URL(kOrigin, "/bar"); 1195 data2.scope = URL(kOrigin, "/bar");
1193 data2.script = URL(kOrigin, "/script2.js"); 1196 data2.script = URL(kOrigin, "/script2.js");
1194 data2.version_id = 201; 1197 data2.version_id = 201;
1195 data2.resources_total_size_bytes = 200; 1198 data2.resources_total_size_bytes = 200;
1199 data2.update_via_cache = blink::WebServiceWorkerUpdateViaCache::kImports;
1196 std::vector<Resource> resources2; 1200 std::vector<Resource> resources2;
1197 resources2.push_back(CreateResource(2, data2.script, 200)); 1201 resources2.push_back(CreateResource(2, data2.script, 200));
1198 1202
1199 ServiceWorkerDatabase::RegistrationData deleted_version; 1203 ServiceWorkerDatabase::RegistrationData deleted_version;
1200 std::vector<int64_t> newly_purgeable_resources; 1204 std::vector<int64_t> newly_purgeable_resources;
1201 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, 1205 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK,
1202 database->WriteRegistration(data1, resources1, &deleted_version, 1206 database->WriteRegistration(data1, resources1, &deleted_version,
1203 &newly_purgeable_resources)); 1207 &newly_purgeable_resources));
1204 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, 1208 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK,
1205 database->WriteRegistration(data2, resources2, &deleted_version, 1209 database->WriteRegistration(data2, resources2, &deleted_version,
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 // The database should detect lack of the main resource (i.e. "/resource1"). 1893 // The database should detect lack of the main resource (i.e. "/resource1").
1890 RegistrationData data_out; 1894 RegistrationData data_out;
1891 std::vector<Resource> resources_out; 1895 std::vector<Resource> resources_out;
1892 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED, 1896 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED,
1893 database->ReadRegistration(data.registration_id, origin, &data_out, 1897 database->ReadRegistration(data.registration_id, origin, &data_out,
1894 &resources_out)); 1898 &resources_out));
1895 EXPECT_TRUE(resources_out.empty()); 1899 EXPECT_TRUE(resources_out.empty());
1896 } 1900 }
1897 1901
1898 } // namespace content 1902 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698