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

Unified Diff: content/browser/service_worker/service_worker_storage_unittest.cc

Issue 1146913004: Service Worker: Add ServiceWorkerContainer.getRegistrations() method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update tools/metrics/histograms/histograms.xml. Created 5 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_storage_unittest.cc
diff --git a/content/browser/service_worker/service_worker_storage_unittest.cc b/content/browser/service_worker/service_worker_storage_unittest.cc
index aa2ceb56ebe52236d14dad86a4fcdacb1b604ef1..e6a444e3e77ee72a34759c5307133e9ddab302be 100644
--- a/content/browser/service_worker/service_worker_storage_unittest.cc
+++ b/content/browser/service_worker/service_worker_storage_unittest.cc
@@ -68,18 +68,33 @@ ServiceWorkerStorage::FindRegistrationCallback MakeFindCallback(
void GetAllCallback(
bool* was_called,
+ std::vector<scoped_refptr<ServiceWorkerRegistration>>* all_out,
+ const std::vector<scoped_refptr<ServiceWorkerRegistration>>& all) {
+ *was_called = true;
+ *all_out = all;
+}
+
+void GetAllInfosCallback(
+ bool* was_called,
std::vector<ServiceWorkerRegistrationInfo>* all_out,
const std::vector<ServiceWorkerRegistrationInfo>& all) {
*was_called = true;
*all_out = all;
}
-ServiceWorkerStorage::GetRegistrationsInfosCallback
-MakeGetRegistrationsCallback(bool* was_called,
- std::vector<ServiceWorkerRegistrationInfo>* all) {
+ServiceWorkerStorage::GetRegistrationsCallback MakeGetRegistrationsCallback(
+ bool* was_called,
+ std::vector<scoped_refptr<ServiceWorkerRegistration>>* all) {
return base::Bind(&GetAllCallback, was_called, all);
}
+ServiceWorkerStorage::GetRegistrationsInfosCallback
+MakeGetRegistrationsInfosCallback(
+ bool* was_called,
+ std::vector<ServiceWorkerRegistrationInfo>* all) {
+ return base::Bind(&GetAllInfosCallback, was_called, all);
+}
+
void GetUserDataCallback(
bool* was_called,
std::string* data_out,
@@ -329,11 +344,11 @@ class ServiceWorkerStorageTest : public testing::Test {
return result;
}
- void GetAllRegistrations(
+ void GetAllRegistrationsInfos(
std::vector<ServiceWorkerRegistrationInfo>* registrations) {
bool was_called = false;
- storage()->GetAllRegistrations(
- MakeGetRegistrationsCallback(&was_called, registrations));
+ storage()->GetAllRegistrationsInfos(
+ MakeGetRegistrationsInfosCallback(&was_called, registrations));
EXPECT_FALSE(was_called); // always async
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(was_called);
@@ -341,11 +356,10 @@ class ServiceWorkerStorageTest : public testing::Test {
void GetRegistrationsForOrigin(
const GURL& origin,
- std::vector<ServiceWorkerRegistrationInfo>* registrations) {
+ std::vector<scoped_refptr<ServiceWorkerRegistration>>* registrations) {
bool was_called = false;
storage()->GetRegistrationsForOrigin(
- origin,
- MakeGetRegistrationsCallback(&was_called, registrations));
+ origin, MakeGetRegistrationsCallback(&was_called, registrations));
EXPECT_FALSE(was_called); // always async
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(was_called);
@@ -579,22 +593,22 @@ TEST_F(ServiceWorkerStorageTest, StoreFindUpdateDeleteRegistration) {
EXPECT_EQ(kResource1Size + kResource2Size,
found_registration->resources_total_size_bytes());
std::vector<ServiceWorkerRegistrationInfo> all_registrations;
- GetAllRegistrations(&all_registrations);
+ GetAllRegistrationsInfos(&all_registrations);
EXPECT_EQ(1u, all_registrations.size());
ServiceWorkerRegistrationInfo info = all_registrations[0];
EXPECT_EQ(kResource1Size + kResource2Size, info.stored_version_size_bytes);
all_registrations.clear();
- // Finding by origin should provide the same result iif origin is kScope.
- std::vector<ServiceWorkerRegistrationInfo> registrations_origin;
- GetRegistrationsForOrigin(kScope.GetOrigin(), &registrations_origin);
- EXPECT_EQ(1u, registrations_origin.size());
- registrations_origin.clear();
+ // Finding by origin should provide the same result if origin is kScope.
+ std::vector<scoped_refptr<ServiceWorkerRegistration>>
+ registrations_for_origin;
+ GetRegistrationsForOrigin(kScope.GetOrigin(), &registrations_for_origin);
+ EXPECT_EQ(1u, registrations_for_origin.size());
+ registrations_for_origin.clear();
- GetRegistrationsForOrigin(
- GURL("http://example.com/").GetOrigin(),
- &registrations_origin);
- EXPECT_TRUE(registrations_origin.empty());
+ GetRegistrationsForOrigin(GURL("http://example.com/").GetOrigin(),
+ &registrations_for_origin);
+ EXPECT_TRUE(registrations_for_origin.empty());
found_registration = NULL;
@@ -685,7 +699,7 @@ TEST_F(ServiceWorkerStorageTest, InstallingRegistrationsAreFindable) {
live_version->SetStatus(ServiceWorkerVersion::INSTALLING);
live_registration->SetWaitingVersion(live_version);
- // Should not be findable, including by GetAllRegistrations.
+ // Should not be findable, including by GetAllRegistrationsInfos.
EXPECT_EQ(SERVICE_WORKER_ERROR_NOT_FOUND,
FindRegistrationForId(
kRegistrationId, kScope.GetOrigin(), &found_registration));
@@ -704,17 +718,17 @@ TEST_F(ServiceWorkerStorageTest, InstallingRegistrationsAreFindable) {
EXPECT_FALSE(found_registration.get());
std::vector<ServiceWorkerRegistrationInfo> all_registrations;
- GetAllRegistrations(&all_registrations);
+ GetAllRegistrationsInfos(&all_registrations);
EXPECT_TRUE(all_registrations.empty());
- std::vector<ServiceWorkerRegistrationInfo> registrations_origin;
- GetRegistrationsForOrigin(kScope.GetOrigin(), &registrations_origin);
- EXPECT_TRUE(registrations_origin.empty());
+ std::vector<scoped_refptr<ServiceWorkerRegistration>>
+ registrations_for_origin;
+ GetRegistrationsForOrigin(kScope.GetOrigin(), &registrations_for_origin);
+ EXPECT_TRUE(registrations_for_origin.empty());
- GetRegistrationsForOrigin(
- GURL("http://example.com/").GetOrigin(),
- &registrations_origin);
- EXPECT_TRUE(registrations_origin.empty());
+ GetRegistrationsForOrigin(GURL("http://example.com/").GetOrigin(),
+ &registrations_for_origin);
+ EXPECT_TRUE(registrations_for_origin.empty());
// Notify storage of it being installed.
storage()->NotifyInstallingRegistration(live_registration.get());
@@ -741,19 +755,18 @@ TEST_F(ServiceWorkerStorageTest, InstallingRegistrationsAreFindable) {
EXPECT_EQ(live_registration, found_registration);
found_registration = NULL;
- GetAllRegistrations(&all_registrations);
+ GetAllRegistrationsInfos(&all_registrations);
EXPECT_EQ(1u, all_registrations.size());
all_registrations.clear();
- // Finding by origin should provide the same result iif origin is kScope.
- GetRegistrationsForOrigin(kScope.GetOrigin(), &registrations_origin);
- EXPECT_EQ(1u, registrations_origin.size());
- registrations_origin.clear();
+ // Finding by origin should provide the same result if origin is kScope.
+ GetRegistrationsForOrigin(kScope.GetOrigin(), &registrations_for_origin);
+ EXPECT_EQ(1u, registrations_for_origin.size());
+ registrations_for_origin.clear();
- GetRegistrationsForOrigin(
- GURL("http://example.com/").GetOrigin(),
- &registrations_origin);
- EXPECT_TRUE(registrations_origin.empty());
+ GetRegistrationsForOrigin(GURL("http://example.com/").GetOrigin(),
+ &registrations_for_origin);
+ EXPECT_TRUE(registrations_for_origin.empty());
// Notify storage of installation no longer happening.
storage()->NotifyDoneInstallingRegistration(
@@ -777,16 +790,15 @@ TEST_F(ServiceWorkerStorageTest, InstallingRegistrationsAreFindable) {
FindRegistrationForPattern(kScope, &found_registration));
EXPECT_FALSE(found_registration.get());
- GetAllRegistrations(&all_registrations);
+ GetAllRegistrationsInfos(&all_registrations);
EXPECT_TRUE(all_registrations.empty());
- GetRegistrationsForOrigin(kScope.GetOrigin(), &registrations_origin);
- EXPECT_TRUE(registrations_origin.empty());
+ GetRegistrationsForOrigin(kScope.GetOrigin(), &registrations_for_origin);
+ EXPECT_TRUE(registrations_for_origin.empty());
- GetRegistrationsForOrigin(
- GURL("http://example.com/").GetOrigin(),
- &registrations_origin);
- EXPECT_TRUE(registrations_origin.empty());
+ GetRegistrationsForOrigin(GURL("http://example.com/").GetOrigin(),
+ &registrations_for_origin);
+ EXPECT_TRUE(registrations_for_origin.empty());
}
TEST_F(ServiceWorkerStorageTest, StoreUserData) {

Powered by Google App Engine
This is Rietveld 408576698