Skip to content

Commit

Permalink
Do case-insensitive file extension matching for Guest OS tasks
Browse files Browse the repository at this point in the history
(cherry picked from commit 1ef26d2)

Bug: 1258348
Change-Id: I955b2ac1120d7477e940ba56e6f2e765d95e4234
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3216926
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Reviewed-by: Timothy Loh <timloh@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#930029}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3216776
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/branch-heads/4664@{#14}
Cr-Branched-From: 24dc4ee-refs/heads/main@{#929512}
  • Loading branch information
Joel Hockey authored and Chromium LUCI CQ committed Oct 11, 2021
1 parent f9e0ab5 commit 53a3e45
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions chrome/browser/ash/file_manager/guest_os_file_tasks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ bool HasSupportedExtension(const std::set<std::string>& supported_extensions,
const auto& extension = entry.path.Extension();
if (extension.size() <= 1 || extension[0] != '.')
return false;
// Strip the leading period.
return supported_extensions.find({extension.begin() + 1, extension.end()}) !=
// Strip the leading period, convert to lower case for insensitive match.
return supported_extensions.find(base::ToLowerASCII(extension.substr(1))) !=
supported_extensions.end();
}

Expand Down
10 changes: 10 additions & 0 deletions chrome/browser/ash/file_manager/guest_os_file_tasks_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ TEST_F(GuestOsFileTasksTest, PluginVm_AppRegistered) {
EXPECT_THAT(app_vm_types_, testing::ElementsAre(PLUGIN_VM));
}

TEST_F(GuestOsFileTasksTest, PluginVm_IgnoreCase) {
AddApp("app1", "name1", {}, {"Txt"}, PLUGIN_VM);
AddEntry("entry.txT", "test/mime1");
FindGuestOsApps(&profile_, entries_, urls_, &app_ids_, &app_names_,
&app_vm_types_);
EXPECT_THAT(app_ids_, testing::ElementsAre("app1"));
EXPECT_THAT(app_names_, testing::ElementsAre("name1 (Windows)"));
EXPECT_THAT(app_vm_types_, testing::ElementsAre(PLUGIN_VM));
}

TEST_F(GuestOsFileTasksTest, PluginVm_NotEnabled) {
fake_plugin_vm_features_.set_enabled(false);
AddApp("app1", "name1", {}, {"txt"}, PLUGIN_VM);
Expand Down
14 changes: 10 additions & 4 deletions chrome/browser/ash/guest_os/guest_os_registry_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ base::Value ProtoToDictionary(const App::LocaleString& locale_string) {
return result;
}

std::set<std::string> ListToStringSet(const base::Value* list) {
std::set<std::string> ListToStringSet(const base::Value* list,
bool to_lower_ascii = false) {
std::set<std::string> result;
if (!list)
return result;
for (const base::Value& value : list->GetList())
result.insert(value.GetString());
result.insert(to_lower_ascii ? base::ToLowerASCII(value.GetString())
: value.GetString());
return result;
}

Expand Down Expand Up @@ -407,15 +409,19 @@ std::string GuestOsRegistryService::Registration::ExecutableFileName() const {
std::set<std::string> GuestOsRegistryService::Registration::Extensions() const {
if (pref_.is_none())
return {};
// Convert to lowercase ASCII to allow case-insensitive match.
return ListToStringSet(pref_.FindKeyOfType(guest_os::prefs::kAppExtensionsKey,
base::Value::Type::LIST));
base::Value::Type::LIST),
/*to_lower_ascii=*/true);
}

std::set<std::string> GuestOsRegistryService::Registration::MimeTypes() const {
if (pref_.is_none())
return {};
// TODO(crbug.com/1258348): It may make sense for mime types to ignore case.
return ListToStringSet(pref_.FindKeyOfType(guest_os::prefs::kAppMimeTypesKey,
base::Value::Type::LIST));
base::Value::Type::LIST),
/*to_lower_ascii=*/false);
}

std::set<std::string> GuestOsRegistryService::Registration::Keywords() const {
Expand Down

0 comments on commit 53a3e45

Please sign in to comment.