Skip to content

Commit

Permalink
[APS] Update server proto file to latest version.
Browse files Browse the repository at this point in the history
This CL updates the app_provisioning.proto file to the latest version.
Updates include:
- Renaming response and request messages
- Refactoring the web app related messages

For more information on why these changes are being made, please see
b/261632289.

Bug: b/262301639
Change-Id: Ia35c240bf6a5a3edc0176b356194a82345da243e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4104684
Reviewed-by: Tim Sergeant <tsergeant@chromium.org>
Auto-Submit: Jeevan Shikaram <jshikaram@chromium.org>
Commit-Queue: Jeevan Shikaram <jshikaram@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1083541}
  • Loading branch information
jeevan-shikaram authored and Chromium LUCI CQ committed Dec 15, 2022
1 parent 08afd25 commit 7ccb396
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation =
}
)");

apps::proto::AppProvisioningRequest::UserType ConvertStringUserTypeToProto(
const std::string& user_type) {
apps::proto::AppProvisioningListAppsRequest::UserType
ConvertStringUserTypeToProto(const std::string& user_type) {
if (user_type == apps::kUserTypeUnmanaged) {
return apps::proto::AppProvisioningRequest::USERTYPE_UNMANAGED;
return apps::proto::AppProvisioningListAppsRequest::USERTYPE_UNMANAGED;
} else if (user_type == apps::kUserTypeManaged) {
return apps::proto::AppProvisioningRequest::USERTYPE_MANAGED;
return apps::proto::AppProvisioningListAppsRequest::USERTYPE_MANAGED;
} else if (user_type == apps::kUserTypeChild) {
return apps::proto::AppProvisioningRequest::USERTYPE_CHILD;
return apps::proto::AppProvisioningListAppsRequest::USERTYPE_CHILD;
} else if (user_type == apps::kUserTypeGuest) {
return apps::proto::AppProvisioningRequest::USERTYPE_GUEST;
return apps::proto::AppProvisioningListAppsRequest::USERTYPE_GUEST;
}
return apps::proto::AppProvisioningRequest::USERTYPE_UNKNOWN;
return apps::proto::AppProvisioningListAppsRequest::USERTYPE_UNKNOWN;
}

std::string BuildGetAppsForFirstLoginRequestBody(const apps::DeviceInfo& info) {
apps::proto::AppProvisioningRequest request_proto;
apps::proto::AppProvisioningListAppsRequest request_proto;
request_proto.set_board(info.board);
request_proto.set_model(info.model);
request_proto.set_language(info.locale);
Expand Down Expand Up @@ -146,7 +146,7 @@ void AppPreloadServerConnector::OnGetAppsForFirstLoginResponse(
return;
}

proto::AppProvisioningResponse response;
proto::AppProvisioningListAppsResponse response;

if (!response.ParseFromString(*response_body)) {
LOG(ERROR) << "Parsing failed";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,20 @@ TEST_F(AppPreloadServerConnectorTest, GetAppsForFirstLoginRequest) {
EXPECT_EQ(method_override_header, "GET");
EXPECT_EQ(content_type, "application/x-protobuf");

proto::AppProvisioningRequest request;
proto::AppProvisioningListAppsRequest request;
ASSERT_TRUE(request.ParseFromString(body));

EXPECT_EQ(request.board(), "brya");
EXPECT_EQ(request.language(), "en-US");
EXPECT_EQ(request.model(), "taniks");
EXPECT_EQ(request.user_type(),
apps::proto::AppProvisioningRequest::USERTYPE_UNMANAGED);
apps::proto::AppProvisioningListAppsRequest::USERTYPE_UNMANAGED);
EXPECT_EQ(request.chrome_os_version().ash_chrome(), "10.10.10");
EXPECT_EQ(request.chrome_os_version().platform(), "12345.0.0");
}

TEST_F(AppPreloadServerConnectorTest, GetAppsForFirstLoginSuccessfulResponse) {
proto::AppProvisioningResponse response;
proto::AppProvisioningListAppsResponse response;
auto* app = response.add_apps_to_install();
app->set_name("Peanut Types");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ const base::Value::Dict& GetStateManager(Profile* profile) {
return profile->GetPrefs()->GetDict(kApsStateManager);
}

void FillWebExtras(apps::proto::AppProvisioningResponse_WebExtras* extras,
const std::string& start_url) {
extras->set_manifest_id(start_url);
extras->set_start_url(start_url);
extras->set_scope(start_url);
extras->set_display_mode(
apps::proto::AppProvisioningResponse::DISPLAY_MODE_STANDALONE);
void FillWebExtras(
apps::proto::AppProvisioningListAppsResponse_WebExtras* extras,
const std::string& manifest_id,
const std::string& manifest_url) {
extras->set_manifest_id(manifest_id);
extras->set_manifest_url(manifest_url);
}

} // namespace
Expand Down Expand Up @@ -160,7 +159,7 @@ TEST_F(AppPreloadServiceTest, FirstLoginStartedPrefSet) {
TEST_F(AppPreloadServiceTest, FirstLoginCompletedPrefSetAfterSuccess) {
// An empty response indicates that the request completed successfully, but
// there are no apps to install.
proto::AppProvisioningResponse response;
proto::AppProvisioningListAppsResponse response;

url_loader_factory_.AddResponse(
AppPreloadServerConnector::GetServerUrl().spec(),
Expand Down Expand Up @@ -194,12 +193,14 @@ TEST_F(AppPreloadServiceTest, FirstLoginExistingUserNotStarted) {

// TODO(b/261632289): temporarily disabled while refactoring is in progress.
TEST_F(AppPreloadServiceTest, DISABLED_WebAppInstall) {
proto::AppProvisioningResponse response;
proto::AppProvisioningListAppsResponse response;
auto* app = response.add_apps_to_install();
app->set_name("Peanut Types");
app->set_platform(proto::AppProvisioningResponse::PLATFORM_WEB);
app->set_install_reason(proto::AppProvisioningResponse::INSTALL_REASON_OEM);
FillWebExtras(app->mutable_web_extras(), "https://peanuttypes.com/app");
app->set_platform(proto::AppProvisioningListAppsResponse::PLATFORM_WEB);
app->set_install_reason(
proto::AppProvisioningListAppsResponse::INSTALL_REASON_OEM);
FillWebExtras(app->mutable_web_extras(), "https://peanuttypes.com/app",
"https://meltingpot.googleusercontent.com/manifest.json");

url_loader_factory_.AddResponse(
AppPreloadServerConnector::GetServerUrl().spec(),
Expand All @@ -224,13 +225,14 @@ TEST_F(AppPreloadServiceTest, DISABLED_WebAppInstall) {
}

TEST_F(AppPreloadServiceTest, IgnoreDefaultAppInstall) {
proto::AppProvisioningResponse response;
proto::AppProvisioningListAppsResponse response;
auto* app = response.add_apps_to_install();
app->set_name("Peanut Types");
app->set_platform(proto::AppProvisioningResponse::PLATFORM_WEB);
app->set_platform(proto::AppProvisioningListAppsResponse::PLATFORM_WEB);
app->set_install_reason(
proto::AppProvisioningResponse::INSTALL_REASON_DEFAULT);
FillWebExtras(app->mutable_web_extras(), "https://peanuttypes.com/app");
proto::AppProvisioningListAppsResponse::INSTALL_REASON_DEFAULT);
FillWebExtras(app->mutable_web_extras(), "https://peanuttypes.com/app",
"https://meltingpot.googleusercontent.com/manifest.json");

url_loader_factory_.AddResponse(
AppPreloadServerConnector::GetServerUrl().spec(),
Expand All @@ -253,11 +255,12 @@ TEST_F(AppPreloadServiceTest, IgnoreAndroidAppInstall) {
constexpr char kPackageName[] = "com.peanuttypes";
constexpr char kActivityName[] = "com.peanuttypes.PeanutTypesActivity";

proto::AppProvisioningResponse response;
proto::AppProvisioningListAppsResponse response;
auto* app = response.add_apps_to_install();
app->set_name("Peanut Types");
app->set_platform(proto::AppProvisioningResponse::PLATFORM_ANDROID);
app->set_install_reason(proto::AppProvisioningResponse::INSTALL_REASON_OEM);
app->set_platform(proto::AppProvisioningListAppsResponse::PLATFORM_ANDROID);
app->set_install_reason(
proto::AppProvisioningListAppsResponse::INSTALL_REASON_OEM);
app->mutable_android_extras()->set_package_name(kPackageName);
app->mutable_android_extras()->set_activity_name(kActivityName);

Expand All @@ -281,19 +284,22 @@ TEST_F(AppPreloadServiceTest, IgnoreAndroidAppInstall) {

// TODO(b/261632289): temporarily disabled while refactoring is in progress.
TEST_F(AppPreloadServiceTest, DISABLED_InstallOverUserApp) {
constexpr char kStartUrl[] = "https://www.example.com/";
constexpr char kManifestId[] = "https://www.example.com/";
constexpr char kManifestUrl[] =
"https://meltingpot.googleusercontent.com/manifest.json";
constexpr char kUserAppName[] = "User Installed App";

auto app_id = web_app::test::InstallDummyWebApp(GetProfile(), kUserAppName,
GURL(kStartUrl));
GURL(kManifestId));

proto::AppProvisioningResponse response;
proto::AppProvisioningListAppsResponse response;
auto* app = response.add_apps_to_install();

app->set_name("OEM Installed app");
app->set_platform(proto::AppProvisioningResponse::PLATFORM_WEB);
app->set_install_reason(proto::AppProvisioningResponse::INSTALL_REASON_OEM);
FillWebExtras(app->mutable_web_extras(), kStartUrl);
app->set_platform(proto::AppProvisioningListAppsResponse::PLATFORM_WEB);
app->set_install_reason(
proto::AppProvisioningListAppsResponse::INSTALL_REASON_OEM);
FillWebExtras(app->mutable_web_extras(), kManifestId, kManifestUrl);

url_loader_factory_.AddResponse(
AppPreloadServerConnector::GetServerUrl().spec(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ std::string PreloadAppDefinition::GetName() const {

AppType PreloadAppDefinition::GetPlatform() const {
switch (app_proto_.platform()) {
case proto::AppProvisioningResponse::PLATFORM_UNKNOWN:
case proto::AppProvisioningListAppsResponse::PLATFORM_UNKNOWN:
return AppType::kUnknown;
case proto::AppProvisioningResponse::PLATFORM_WEB:
case proto::AppProvisioningListAppsResponse::PLATFORM_WEB:
return AppType::kWeb;
case proto::AppProvisioningResponse::PLATFORM_ANDROID:
case proto::AppProvisioningListAppsResponse::PLATFORM_ANDROID:
return AppType::kArc;
}
}

bool PreloadAppDefinition::IsOemApp() const {
return app_proto_.install_reason() ==
proto::AppProvisioningResponse_InstallReason::
AppProvisioningResponse_InstallReason_INSTALL_REASON_OEM;
proto::AppProvisioningListAppsResponse::INSTALL_REASON_OEM;
}

std::string PreloadAppDefinition::GetWebAppManifestId() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace apps {
// extraction and conversion of information.
class PreloadAppDefinition {
public:
explicit PreloadAppDefinition(proto::AppProvisioningResponse_App app_proto)
explicit PreloadAppDefinition(
proto::AppProvisioningListAppsResponse_App app_proto)
: app_proto_(app_proto) {}
PreloadAppDefinition(const PreloadAppDefinition&) = default;
PreloadAppDefinition& operator=(const PreloadAppDefinition&) = default;
Expand All @@ -35,7 +36,7 @@ class PreloadAppDefinition {
std::string GetWebAppManifestId() const;

private:
proto::AppProvisioningResponse_App app_proto_;
proto::AppProvisioningListAppsResponse_App app_proto_;
};

std::ostream& operator<<(std::ostream& os, const PreloadAppDefinition& app);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@ namespace {

// Returns a sample valid web App response proto. Tests should overwrite the
// individual fields that they need to verify.
proto::AppProvisioningResponse_App CreateTestWebApp() {
proto::AppProvisioningResponse_App app;
proto::AppProvisioningListAppsResponse_App CreateTestWebApp() {
proto::AppProvisioningListAppsResponse_App app;
app.set_name("Test app");
app.set_platform(proto::AppProvisioningResponse::PLATFORM_WEB);
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_start_url("https://www.example.com/home");
web_extras->set_scope("https://www.example.com/");
web_extras->set_display_mode(
proto::AppProvisioningResponse::DISPLAY_MODE_STANDALONE);
web_extras->set_manifest_url("https://www.example.com/home/manifest.json");
return app;
}
} // namespace
Expand All @@ -37,66 +34,66 @@ class PreloadAppDefinitionTest : public testing::Test {
};

TEST_F(PreloadAppDefinitionTest, GetNameWhenNotSet) {
proto::AppProvisioningResponse_App app;
proto::AppProvisioningListAppsResponse_App app;

auto app_def = PreloadAppDefinition(app);
ASSERT_EQ(app_def.GetName(), "");
}

TEST_F(PreloadAppDefinitionTest, GetName) {
const std::string test_name = "test_app_name";
proto::AppProvisioningResponse_App app;
proto::AppProvisioningListAppsResponse_App app;

app.set_name(test_name);
auto app_def = PreloadAppDefinition(app);
ASSERT_EQ(app_def.GetName(), test_name);
}

TEST_F(PreloadAppDefinitionTest, GetPlatformWhenNotSet) {
proto::AppProvisioningResponse_App app;
proto::AppProvisioningListAppsResponse_App app;

auto app_def = PreloadAppDefinition(app);
ASSERT_EQ(app_def.GetPlatform(), AppType::kUnknown);
}

TEST_F(PreloadAppDefinitionTest, GetPlatform) {
proto::AppProvisioningResponse_App app;
proto::AppProvisioningListAppsResponse_App app;

app.set_platform(proto::AppProvisioningResponse_Platform::
AppProvisioningResponse_Platform_PLATFORM_WEB);
app.set_platform(proto::AppProvisioningListAppsResponse_Platform::
AppProvisioningListAppsResponse_Platform_PLATFORM_WEB);
auto app_def = PreloadAppDefinition(app);
ASSERT_EQ(app_def.GetPlatform(), AppType::kWeb);
}

TEST_F(PreloadAppDefinitionTest, IsOemAppWhenNotSet) {
proto::AppProvisioningResponse_App app;
proto::AppProvisioningListAppsResponse_App app;

auto app_def = PreloadAppDefinition(app);
ASSERT_FALSE(app_def.IsOemApp());
}

TEST_F(PreloadAppDefinitionTest, IsOemApp) {
proto::AppProvisioningResponse_App app;
proto::AppProvisioningListAppsResponse_App app;

app.set_install_reason(
proto::AppProvisioningResponse_InstallReason::
AppProvisioningResponse_InstallReason_INSTALL_REASON_OEM);
proto::AppProvisioningListAppsResponse_InstallReason::
AppProvisioningListAppsResponse_InstallReason_INSTALL_REASON_OEM);
auto app_def = PreloadAppDefinition(app);
ASSERT_TRUE(app_def.IsOemApp());
}

TEST_F(PreloadAppDefinitionTest, IsNotOemApp) {
proto::AppProvisioningResponse_App app;
proto::AppProvisioningListAppsResponse_App app;

app.set_install_reason(
proto::AppProvisioningResponse_InstallReason::
AppProvisioningResponse_InstallReason_INSTALL_REASON_DEFAULT);
proto::AppProvisioningListAppsResponse_InstallReason::
AppProvisioningListAppsResponse_InstallReason_INSTALL_REASON_DEFAULT);
auto app_def = PreloadAppDefinition(app);
ASSERT_FALSE(app_def.IsOemApp());
}

TEST_F(PreloadAppDefinitionTest, GetWebAppManifestId) {
proto::AppProvisioningResponse_App app = CreateTestWebApp();
proto::AppProvisioningListAppsResponse_App app = CreateTestWebApp();
app.mutable_web_extras()->set_manifest_id(
"https://www.example.com/manifest_id/");

Expand All @@ -107,8 +104,8 @@ TEST_F(PreloadAppDefinitionTest, GetWebAppManifestId) {
}

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

PreloadAppDefinition app_def(app);

Expand Down
Loading

0 comments on commit 7ccb396

Please sign in to comment.