| OLD | NEW |
| 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 Loading... |
| 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.use_cache, actual.use_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 Loading... |
| 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.use_cache = true; |
| 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 Loading... |
| 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.use_cache = true; |
| 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 std::vector<Resource> resources1; | 1111 std::vector<Resource> resources1; |
| 1109 resources1.push_back(CreateResource(1, data1.script, 100)); | 1112 resources1.push_back(CreateResource(1, data1.script, 100)); |
| 1110 | 1113 |
| 1111 // Add registration 2. | 1114 // Add registration 2. |
| 1112 RegistrationData data2; | 1115 RegistrationData data2; |
| 1113 data2.registration_id = 101; | 1116 data2.registration_id = 101; |
| 1114 data2.scope = URL(kOrigin, "/bar"); | 1117 data2.scope = URL(kOrigin, "/bar"); |
| 1115 data2.script = URL(kOrigin, "/script2.js"); | 1118 data2.script = URL(kOrigin, "/script2.js"); |
| 1116 data2.version_id = 201; | 1119 data2.version_id = 201; |
| 1117 data2.resources_total_size_bytes = 200; | 1120 data2.resources_total_size_bytes = 200; |
| 1121 data2.use_cache = true; |
| 1118 std::vector<Resource> resources2; | 1122 std::vector<Resource> resources2; |
| 1119 resources2.push_back(CreateResource(2, data2.script, 200)); | 1123 resources2.push_back(CreateResource(2, data2.script, 200)); |
| 1120 | 1124 |
| 1121 ServiceWorkerDatabase::RegistrationData deleted_version; | 1125 ServiceWorkerDatabase::RegistrationData deleted_version; |
| 1122 std::vector<int64_t> newly_purgeable_resources; | 1126 std::vector<int64_t> newly_purgeable_resources; |
| 1123 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, | 1127 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, |
| 1124 database->WriteRegistration(data1, resources1, &deleted_version, | 1128 database->WriteRegistration(data1, resources1, &deleted_version, |
| 1125 &newly_purgeable_resources)); | 1129 &newly_purgeable_resources)); |
| 1126 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, | 1130 ASSERT_EQ(ServiceWorkerDatabase::STATUS_OK, |
| 1127 database->WriteRegistration(data2, resources2, &deleted_version, | 1131 database->WriteRegistration(data2, resources2, &deleted_version, |
| (...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1811 // The database should detect lack of the main resource (i.e. "/resource1"). | 1815 // The database should detect lack of the main resource (i.e. "/resource1"). |
| 1812 RegistrationData data_out; | 1816 RegistrationData data_out; |
| 1813 std::vector<Resource> resources_out; | 1817 std::vector<Resource> resources_out; |
| 1814 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED, | 1818 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED, |
| 1815 database->ReadRegistration(data.registration_id, origin, &data_out, | 1819 database->ReadRegistration(data.registration_id, origin, &data_out, |
| 1816 &resources_out)); | 1820 &resources_out)); |
| 1817 EXPECT_TRUE(resources_out.empty()); | 1821 EXPECT_TRUE(resources_out.empty()); |
| 1818 } | 1822 } |
| 1819 | 1823 |
| 1820 } // namespace content | 1824 } // namespace content |
| OLD | NEW |