Commit 504ac1c3 authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Payments] Cache multiple package names per web app manifest.

Before this patch, caching a web app manifest with multiple "id" values
in "related_applications" sections would not always clear the stale data
from the cache. Multiple "id" values in the same web app manifest are
useful for using both prod and dev version of a payment app in the same
web app manifest, for example.

This patch clears the stale data for all "id" values in
"related_applications" of a web app manifest that is being cached.

Bug: 745765
Change-Id: I116e356d5181792668aa26c6ff4da7258cd11d49
Reviewed-on: https://chromium-review.googlesource.com/575845
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487632}
parent 22bd78d6
......@@ -114,9 +114,12 @@ bool WebAppManifestSectionTable::AddWebAppManifest(
sql::Statement s1(db_->GetUniqueStatement(
"DELETE FROM web_app_manifest_section WHERE id=? "));
s1.BindString(0, manifest[0]->id);
if (!s1.Run())
return false;
for (const auto& section : manifest) {
s1.BindString(0, section->id);
if (!s1.Run())
return false;
s1.Reset(true);
}
sql::Statement s2(
db_->GetUniqueStatement("INSERT INTO web_app_manifest_section "
......@@ -125,7 +128,6 @@ bool WebAppManifestSectionTable::AddWebAppManifest(
const time_t expire_date_in_seconds =
base::Time::NowFromSystemTime().ToTimeT() + DATA_VALID_TIME_IN_SECONDS;
for (const auto& section : manifest) {
DCHECK_EQ(manifest[0]->id, section->id);
int index = 0;
s2.BindInt64(index++, expire_date_in_seconds);
s2.BindString(index++, section->id);
......
......@@ -140,6 +140,61 @@ TEST_F(WebAppManifestSectionTableTest, AddAndGetMultipleManifests) {
ASSERT_TRUE(alicepay_manifest[0]->fingerprints[1] == fingerprint_four);
}
// A single manifest can have multiple package names, e.g., one for developer
// and one for production version of the app. A package name is unique among all
// the apps on Android, so this means we can define multiple apps in a single
// manifest.
TEST_F(WebAppManifestSectionTableTest, AddAndGetSingleManifestWithTwoIds) {
std::vector<uint8_t> fingerprint_dev = GenerateFingerprint(1);
std::vector<uint8_t> fingerprint_prod = GenerateFingerprint(32);
WebAppManifestSectionTable* web_app_manifest_section_table =
WebAppManifestSectionTable::FromWebDatabase(db_.get());
std::vector<mojom::WebAppManifestSectionPtr> manifest;
{
// Adds dev version to the manifest.
mojom::WebAppManifestSectionPtr manifest_dev_section =
mojom::WebAppManifestSection::New();
manifest_dev_section->id = "com.bobpay.dev";
manifest_dev_section->min_version = static_cast<int64_t>(2);
manifest_dev_section->fingerprints.push_back(fingerprint_dev);
manifest.emplace_back(std::move(manifest_dev_section));
}
{
// Adds prod version to the manifest.
mojom::WebAppManifestSectionPtr manifest_prod_section =
mojom::WebAppManifestSection::New();
manifest_prod_section->id = "com.bobpay.prod";
manifest_prod_section->min_version = static_cast<int64_t>(1);
manifest_prod_section->fingerprints.push_back(fingerprint_prod);
manifest.emplace_back(std::move(manifest_prod_section));
}
ASSERT_TRUE(web_app_manifest_section_table->AddWebAppManifest(manifest));
{
// Verify the dev manifest.
std::vector<mojom::WebAppManifestSectionPtr> actual_manifest =
web_app_manifest_section_table->GetWebAppManifest("com.bobpay.dev");
ASSERT_EQ(actual_manifest.size(), 1U);
EXPECT_EQ(actual_manifest[0]->id, "com.bobpay.dev");
EXPECT_EQ(actual_manifest[0]->min_version, 2);
ASSERT_EQ(actual_manifest[0]->fingerprints.size(), 1U);
EXPECT_TRUE(actual_manifest[0]->fingerprints[0] == fingerprint_dev);
}
{
// Verify the prod manifest.
std::vector<mojom::WebAppManifestSectionPtr> actual_manifest =
web_app_manifest_section_table->GetWebAppManifest("com.bobpay.prod");
ASSERT_EQ(actual_manifest.size(), 1U);
EXPECT_EQ(actual_manifest[0]->id, "com.bobpay.prod");
EXPECT_EQ(actual_manifest[0]->min_version, 1);
ASSERT_EQ(actual_manifest[0]->fingerprints.size(), 1U);
EXPECT_TRUE(actual_manifest[0]->fingerprints[0] == fingerprint_prod);
}
}
} // namespace
} // namespace payments
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment