Commit 7a59299c authored by Jeffrey Kardatzke's avatar Jeffrey Kardatzke Committed by Commit Bot

Enhanced crostini shelf app matching to search on name

This covers the case for the examples of xterm & uxterm where their
window_app_id was org.chromium.termain.wmclass.[U]XTerm but the desktop
file is debian-[u]xterm.desktop and the unlocalized name is [U]XTerm.

Bug: 819444
Test: Unit tests pass, verified xterm & uxterm show up on shelf
Change-Id: I3c86d82085450a769f36617b21df7fe73ca27a2a
Reviewed-on: https://chromium-review.googlesource.com/1031527Reviewed-by: default avatarNicholas Verne <nverne@chromium.org>
Reviewed-by: default avatarTimothy Loh <timloh@chromium.org>
Commit-Queue: Jeffrey Kardatzke <jkardatzke@google.com>
Cr-Commit-Position: refs/heads/master@{#554269}
parent 666a4b96
......@@ -122,11 +122,22 @@ FindAppIdResult FindAppId(const base::DictionaryValue* prefs,
->GetBool())
continue;
const std::string& value =
item.second.FindKeyOfType(prefs_key, base::Value::Type::STRING)
->GetString();
if (!EqualsCaseInsensitiveASCII(search_value, value))
const base::Value* value = item.second.FindKey(prefs_key);
if (!value)
continue;
if (value->type() == base::Value::Type::STRING) {
if (!EqualsCaseInsensitiveASCII(search_value, value->GetString()))
continue;
} else if (value->type() == base::Value::Type::DICTIONARY) {
// Look at the unlocalized name to see if that matches.
value = value->FindKeyOfType("", base::Value::Type::STRING);
if (!value ||
!EqualsCaseInsensitiveASCII(search_value, value->GetString())) {
continue;
}
} else {
continue;
}
if (!result->empty())
return FindAppIdResult::NonUniqueMatch;
......@@ -249,9 +260,11 @@ CrostiniRegistryService::~CrostiniRegistryService() = default;
// 2) If the Startup Id is set, look for a matching desktop file id.
// 3) If the App Id is not prefixed by org.chromium.termina., it's an app with
// native Wayland support. Look for a matching desktop file id.
// 4) If the App Id is prefixed by org.chromium.wmclass.:
// 4) If the App Id is prefixed by org.chromium.termina.wmclass.:
// 4.1) Look for an app where StartupWMClass is matches the suffix.
// 4.2) Look for an app where the desktop file id matches the suffix.
// 4.3) Look for an app where the unlocalized name matches the suffix. This
// handles the xterm & uxterm examples.
// 5) If we couldn't find a match, prefix the app id with 'crostini:' so we can
// easily identify shelf entries as Crostini apps.
std::string CrostiniRegistryService::GetCrostiniShelfAppId(
......@@ -305,6 +318,11 @@ std::string CrostiniRegistryService::GetCrostiniShelfAppId(
if (FindAppId(apps, kAppDesktopFileIdKey, key, &app_id) ==
FindAppIdResult::UniqueMatch)
return app_id;
if (FindAppId(apps, kAppNameKey, key, &app_id) ==
FindAppIdResult::UniqueMatch)
return app_id;
return kCrostiniAppIdPrefix + window_app_id;
}
......
......@@ -49,12 +49,13 @@ class CrostiniRegistryServiceTest : public testing::Test {
"crostini:" + vm_name + "/" + container_name + "/" + desktop_file_id);
}
App BasicApp(const std::string& desktop_file_id) {
App BasicApp(const std::string& desktop_file_id,
const std::string& name = "") {
App app;
app.set_desktop_file_id(desktop_file_id);
App::LocaleString::Entry* entry = app.mutable_name()->add_values();
entry->set_locale(std::string());
entry->set_value(desktop_file_id);
entry->set_value(name.empty() ? desktop_file_id : name);
return app;
}
......@@ -306,4 +307,14 @@ TEST_F(CrostiniRegistryServiceTest, GetCrostiniAppIdStartupNotify) {
"crostini:whatever");
}
TEST_F(CrostiniRegistryServiceTest, GetCrostiniAppIdName) {
ApplicationList app_list = BasicAppList("app", "vm", "container");
*app_list.add_apps() = BasicApp("app2", "name2");
service()->UpdateApplicationList(app_list);
EXPECT_EQ(
service()->GetCrostiniShelfAppId(WindowIdForWMClass("name2"), nullptr),
GenerateAppId("app2", "vm", "container"));
}
} // namespace crostini
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