+TEST(ServiceWorkerDatabaseTest, DeleteNonExistentRegistration) {
+ scoped_ptr<ServiceWorkerDatabase> database(CreateDatabaseInMemory());
+
+ GURL origin("http://example.com");
+ RegistrationData data;
+ data.registration_id = 100;
+ data.scope = URL(origin, "/foo");
+ data.script = URL(origin, "/script.js");
+ data.version_id = 200;
+
+ std::vector<Resource> resources;
+ resources.push_back(CreateResource(1, URL(origin, "/resource1")));
+ resources.push_back(CreateResource(2, URL(origin, "/resource2")));
+
+ const int64 kNonExistentRegistrationId = 999;
+ const int64 kArbitraryVersionId = 222; // Used as a dummy initial value
+
+ int64 deleted_version_id = kArbitraryVersionId;
+ std::vector<int64> newly_purgeable_resources;
+ EXPECT_EQ(
+ ServiceWorkerDatabase::STATUS_OK,
+ database->WriteRegistration(
+ data, resources, &deleted_version_id, &newly_purgeable_resources));
+ EXPECT_EQ(kInvalidServiceWorkerVersionId, deleted_version_id);
+ EXPECT_TRUE(newly_purgeable_resources.empty());
+
+ // Delete from an origin that has a registration.
+ deleted_version_id = kArbitraryVersionId;
+ newly_purgeable_resources.clear();
+ EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
+ database->DeleteRegistration(kNonExistentRegistrationId,
+ origin,
+ &deleted_version_id,
+ &newly_purgeable_resources));
+ EXPECT_EQ(kInvalidServiceWorkerVersionId, deleted_version_id);
+ EXPECT_TRUE(newly_purgeable_resources.empty());
+
+ // Delete from an origin that has no registration.
+ deleted_version_id = kArbitraryVersionId;
+ newly_purgeable_resources.clear();
+ EXPECT_EQ(ServiceWorkerDatabase::STATUS_OK,
+ database->DeleteRegistration(kNonExistentRegistrationId,
+ GURL("http://example.net"),
+ &deleted_version_id,
+ &newly_purgeable_resources));
+ EXPECT_EQ(kInvalidServiceWorkerVersionId, deleted_version_id);
+ EXPECT_TRUE(newly_purgeable_resources.empty());
+}
+