Skip to content

Commit

Permalink
[APS] Add GetWebAppOriginalManifestUrl to PreloadAppDefinition.
Browse files Browse the repository at this point in the history
This CL adds a getter for a web app's original manifest URL.

Bug: b/262301639
Change-Id: Ic336416dcba51a0910d7d6ca8e7d915e48953d87
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4112723
Commit-Queue: Jeevan Shikaram <jshikaram@chromium.org>
Auto-Submit: Jeevan Shikaram <jshikaram@chromium.org>
Reviewed-by: Melissa Zhang <melzhang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1084829}
  • Loading branch information
jeevan-shikaram authored and Chromium LUCI CQ committed Dec 19, 2022
1 parent e1ee2d3 commit 34a6072
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
Expand Up @@ -40,6 +40,12 @@ GURL PreloadAppDefinition::GetWebAppManifestUrl() const {
return GURL(app_proto_.web_extras().manifest_url());
}

GURL PreloadAppDefinition::GetWebAppOriginalManifestUrl() const {
DCHECK_EQ(GetPlatform(), AppType::kWeb);

return GURL(app_proto_.web_extras().original_manifest_url());
}

std::ostream& operator<<(std::ostream& os, const PreloadAppDefinition& app) {
os << std::boolalpha;
os << "- Name: " << app.GetName() << std::endl;
Expand All @@ -49,6 +55,9 @@ std::ostream& operator<<(std::ostream& os, const PreloadAppDefinition& app) {
if (app.GetPlatform() == AppType::kWeb) {
os << "- Web Extras:" << std::endl;
os << " - Manifest ID: " << app.GetWebAppManifestId() << std::endl;
os << " - Manifest URL: " << app.GetWebAppManifestUrl() << std::endl;
os << " - Original Manifest URL: " << app.GetWebAppOriginalManifestUrl()
<< std::endl;
}

os << std::noboolalpha;
Expand Down
Expand Up @@ -43,6 +43,11 @@ class PreloadAppDefinition {
// `GetPlatform()` returns `AppType::kWeb`.
GURL GetWebAppManifestUrl() const;

// Returns the original Web App manifest URL for the app. This is the URL
// where the manifest was originally hosted. Does not attempt to validate the
// GURL. Must only be called if `GetPlatform()` returns `AppType::kWeb`.
GURL GetWebAppOriginalManifestUrl() const;

private:
proto::AppProvisioningListAppsResponse_App app_proto_;
};
Expand Down
Expand Up @@ -22,9 +22,6 @@ proto::AppProvisioningListAppsResponse_App CreateTestWebApp() {
proto::AppProvisioningListAppsResponse_App app;
app.set_name("Test app");
app.set_platform(proto::AppProvisioningListAppsResponse::PLATFORM_WEB);
auto* web_extras = app.mutable_web_extras();
web_extras->set_manifest_id("https://www.example.com/home");
web_extras->set_manifest_url("https://www.example.com/home/manifest.json");
return app;
}
} // namespace
Expand Down Expand Up @@ -105,8 +102,7 @@ TEST_F(PreloadAppDefinitionTest, GetWebAppManifestId) {
}

TEST_F(PreloadAppDefinitionTest, GetWebAppManifestIdNotSpecified) {
proto::AppProvisioningListAppsResponse_App app;
app.set_platform(proto::AppProvisioningListAppsResponse::PLATFORM_WEB);
proto::AppProvisioningListAppsResponse_App app = CreateTestWebApp();

PreloadAppDefinition app_def(app);

Expand Down Expand Up @@ -151,12 +147,41 @@ TEST_F(PreloadAppDefinitionTest, GetWebAppManifestUrlInvalidUrl) {
}

TEST_F(PreloadAppDefinitionTest, GetWebAppManifestUrlNotSpecified) {
proto::AppProvisioningListAppsResponse_App app;
app.set_platform(proto::AppProvisioningListAppsResponse::PLATFORM_WEB);
proto::AppProvisioningListAppsResponse_App app = CreateTestWebApp();

PreloadAppDefinition app_def(app);

ASSERT_TRUE(app_def.GetWebAppManifestUrl().is_empty());
}

TEST_F(PreloadAppDefinitionTest, GetWebAppOriginalManifestUrl) {
proto::AppProvisioningListAppsResponse_App app = CreateTestWebApp();
app.mutable_web_extras()->set_original_manifest_url(
"https://www.example.com/app/manifest.json");

PreloadAppDefinition app_def(app);

GURL manifest_url = app_def.GetWebAppOriginalManifestUrl();

ASSERT_TRUE(manifest_url.is_valid());
ASSERT_EQ(manifest_url.spec(), "https://www.example.com/app/manifest.json");
}

TEST_F(PreloadAppDefinitionTest, GetWebAppOriginalManifestUrlInvalidUrl) {
proto::AppProvisioningListAppsResponse_App app = CreateTestWebApp();
app.mutable_web_extras()->set_original_manifest_url("invalid url");

PreloadAppDefinition app_def(app);

ASSERT_FALSE(app_def.GetWebAppOriginalManifestUrl().is_valid());
}

TEST_F(PreloadAppDefinitionTest, GetWebAppOriginalManifestUrlNotSpecified) {
proto::AppProvisioningListAppsResponse_App app = CreateTestWebApp();

PreloadAppDefinition app_def(app);

ASSERT_TRUE(app_def.GetWebAppOriginalManifestUrl().is_empty());
}

} // namespace apps

0 comments on commit 34a6072

Please sign in to comment.