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

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

Issue 2658603003: ServiceWorker: Enable UseCounter for ServiceWorkerGlobalScope (Closed)
Patch Set: int32_t -> uint32_t Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 EXPECT_EQ(expected.scope, actual.scope); 65 EXPECT_EQ(expected.scope, actual.scope);
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 } 76 }
76 77
77 void VerifyResourceRecords(const std::vector<Resource>& expected, 78 void VerifyResourceRecords(const std::vector<Resource>& expected,
78 const std::vector<Resource>& actual) { 79 const std::vector<Resource>& actual) {
79 ASSERT_EQ(expected.size(), actual.size()); 80 ASSERT_EQ(expected.size(), actual.size());
80 for (size_t i = 0; i < expected.size(); ++i) { 81 for (size_t i = 0; i < expected.size(); ++i) {
81 EXPECT_EQ(expected[i].resource_id, actual[i].resource_id); 82 EXPECT_EQ(expected[i].resource_id, actual[i].resource_id);
82 EXPECT_EQ(expected[i].url, actual[i].url); 83 EXPECT_EQ(expected[i].url, actual[i].url);
83 EXPECT_EQ(expected[i].size_bytes, actual[i].size_bytes); 84 EXPECT_EQ(expected[i].size_bytes, actual[i].size_bytes);
84 } 85 }
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 std::unique_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory()); 617 std::unique_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory());
617 618
618 GURL origin("http://example.com"); 619 GURL origin("http://example.com");
619 RegistrationData data; 620 RegistrationData data;
620 data.registration_id = 100; 621 data.registration_id = 100;
621 data.scope = URL(origin, "/foo"); 622 data.scope = URL(origin, "/foo");
622 data.script = URL(origin, "/resource1"); 623 data.script = URL(origin, "/resource1");
623 data.version_id = 200; 624 data.version_id = 200;
624 data.resources_total_size_bytes = 10939 + 200; 625 data.resources_total_size_bytes = 10939 + 200;
625 data.foreign_fetch_scopes.push_back(URL(origin, "/foo/bar")); 626 data.foreign_fetch_scopes.push_back(URL(origin, "/foo/bar"));
627 data.used_features = {124, 901, 1019};
626 628
627 std::vector<Resource> resources; 629 std::vector<Resource> resources;
628 resources.push_back(CreateResource(1, URL(origin, "/resource1"), 10939)); 630 resources.push_back(CreateResource(1, URL(origin, "/resource1"), 10939));
629 resources.push_back(CreateResource(2, URL(origin, "/resource2"), 200)); 631 resources.push_back(CreateResource(2, URL(origin, "/resource2"), 200));
630 632
631 // Write a resource to the uncommitted list to make sure that writing 633 // Write a resource to the uncommitted list to make sure that writing
632 // registration removes resource ids associated with the registration from 634 // registration removes resource ids associated with the registration from
633 // the uncommitted list. 635 // the uncommitted list.
634 std::set<int64_t> uncommitted_ids; 636 std::set<int64_t> uncommitted_ids;
635 uncommitted_ids.insert(resources[0].resource_id); 637 uncommitted_ids.insert(resources[0].resource_id);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 GURL origin("http://example.com"); 757 GURL origin("http://example.com");
756 RegistrationData data; 758 RegistrationData data;
757 data.registration_id = 100; 759 data.registration_id = 100;
758 data.scope = URL(origin, "/foo"); 760 data.scope = URL(origin, "/foo");
759 data.script = URL(origin, "/resource1"); 761 data.script = URL(origin, "/resource1");
760 data.version_id = 200; 762 data.version_id = 200;
761 data.resources_total_size_bytes = 10 + 11; 763 data.resources_total_size_bytes = 10 + 11;
762 data.foreign_fetch_scopes.push_back(URL(origin, "/foo")); 764 data.foreign_fetch_scopes.push_back(URL(origin, "/foo"));
763 data.foreign_fetch_origins.push_back( 765 data.foreign_fetch_origins.push_back(
764 url::Origin(GURL("https://chromium.org"))); 766 url::Origin(GURL("https://chromium.org")));
767 data.used_features = {124, 901, 1019};
765 768
766 std::vector<Resource> resources1; 769 std::vector<Resource> resources1;
767 resources1.push_back(CreateResource(1, URL(origin, "/resource1"), 10)); 770 resources1.push_back(CreateResource(1, URL(origin, "/resource1"), 10));
768 resources1.push_back(CreateResource(2, URL(origin, "/resource2"), 11)); 771 resources1.push_back(CreateResource(2, URL(origin, "/resource2"), 11));
769 772
770 ServiceWorkerDatabase::RegistrationData deleted_version; 773 ServiceWorkerDatabase::RegistrationData deleted_version;
771 deleted_version.version_id = 222; // Dummy inital value 774 deleted_version.version_id = 222; // Dummy inital value
772 std::vector<int64_t> newly_purgeable_resources; 775 std::vector<int64_t> newly_purgeable_resources;
773 776
774 EXPECT_EQ( 777 EXPECT_EQ(
(...skipping 12 matching lines...) Expand all
787 VerifyResourceRecords(resources1, resources_out); 790 VerifyResourceRecords(resources1, resources_out);
788 791
789 // Update the registration. 792 // Update the registration.
790 RegistrationData updated_data = data; 793 RegistrationData updated_data = data;
791 updated_data.script = URL(origin, "/resource3"); 794 updated_data.script = URL(origin, "/resource3");
792 updated_data.version_id = data.version_id + 1; 795 updated_data.version_id = data.version_id + 1;
793 updated_data.resources_total_size_bytes = 12 + 13; 796 updated_data.resources_total_size_bytes = 12 + 13;
794 updated_data.foreign_fetch_scopes.clear(); 797 updated_data.foreign_fetch_scopes.clear();
795 updated_data.foreign_fetch_origins.push_back( 798 updated_data.foreign_fetch_origins.push_back(
796 url::Origin(GURL("https://example.com"))); 799 url::Origin(GURL("https://example.com")));
800 updated_data.used_features = {109, 421, 9101};
797 std::vector<Resource> resources2; 801 std::vector<Resource> resources2;
798 resources2.push_back(CreateResource(3, URL(origin, "/resource3"), 12)); 802 resources2.push_back(CreateResource(3, URL(origin, "/resource3"), 12));
799 resources2.push_back(CreateResource(4, URL(origin, "/resource4"), 13)); 803 resources2.push_back(CreateResource(4, URL(origin, "/resource4"), 13));
800 804
801 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK, 805 EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
802 database->WriteRegistration(updated_data, 806 database->WriteRegistration(updated_data,
803 resources2, 807 resources2,
804 &deleted_version, 808 &deleted_version,
805 &newly_purgeable_resources)); 809 &newly_purgeable_resources));
806 EXPECT_EQ(data.version_id, deleted_version.version_id); 810 EXPECT_EQ(data.version_id, deleted_version.version_id);
(...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after
1807 // The database should detect lack of the main resource (i.e. "/resource1"). 1811 // The database should detect lack of the main resource (i.e. "/resource1").
1808 RegistrationData data_out; 1812 RegistrationData data_out;
1809 std::vector<Resource> resources_out; 1813 std::vector<Resource> resources_out;
1810 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED, 1814 EXPECT_EQ(ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED,
1811 database->ReadRegistration(data.registration_id, origin, &data_out, 1815 database->ReadRegistration(data.registration_id, origin, &data_out,
1812 &resources_out)); 1816 &resources_out));
1813 EXPECT_TRUE(resources_out.empty()); 1817 EXPECT_TRUE(resources_out.empty());
1814 } 1818 }
1815 1819
1816 } // namespace content 1820 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698