[image search] Fix crash when typing characters with control menu open
If a user types a character with search control menu open, the menu will automatically execute the item where the first character matches the one pressed (and this actually works for every menu). This triggers executing commands when the menu is closed and crashes because of the CHECK. Fixes that by removing the check. Bug: 339769067 Change-Id: I91a6f105e87b9242e806c482758d1b981433e960 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5540198 Reviewed-by: Toni Barzic <tbarzic@chromium.org> Commit-Queue: Wen-Chien Wang <wcwang@chromium.org> Cr-Commit-Position: refs/heads/main@{#1301606}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
ddf2f2ec4e
commit
fac4891f76
ash/app_list/views
@ -762,6 +762,60 @@ TEST_P(SearchResultImageViewTest, SearchCategoryMenuItemToggleTest) {
|
||||
app_list_client->set_search_callback(TestAppListClient::SearchCallback());
|
||||
}
|
||||
|
||||
TEST_P(SearchResultImageViewTest,
|
||||
TypingInitialCharacterWithMenuOpenTogglesCheckbox) {
|
||||
GetAppListTestHelper()->ShowAppList();
|
||||
auto* app_list_client = GetAppListTestHelper()->app_list_client();
|
||||
|
||||
app_list_client->set_available_categories_for_test(
|
||||
{AppListSearchControlCategory::kApps,
|
||||
AppListSearchControlCategory::kFiles,
|
||||
AppListSearchControlCategory::kWeb});
|
||||
|
||||
// Press a character key to open the search.
|
||||
PressAndReleaseKey(ui::VKEY_A);
|
||||
GetSearchBoxView()->GetWidget()->LayoutRootViewIfNecessary();
|
||||
views::ImageButton* filter_button = GetSearchBoxView()->filter_button();
|
||||
EXPECT_TRUE(filter_button->GetVisible());
|
||||
|
||||
// Open the filter menu.
|
||||
LeftClickOn(filter_button);
|
||||
EXPECT_TRUE(GetSearchBoxView()->IsFilterMenuOpen());
|
||||
|
||||
// Set up the search callback to notify that the search is triggered.
|
||||
bool is_search_triggered = false;
|
||||
app_list_client->set_search_callback(base::BindLambdaForTesting(
|
||||
[&](const std::u16string& query) { is_search_triggered = true; }));
|
||||
|
||||
// Toggleable categories are on by default.
|
||||
PrefService* prefs =
|
||||
Shell::Get()->session_controller()->GetLastActiveUserPrefService();
|
||||
EXPECT_TRUE(prefs->GetDict(prefs::kLauncherSearchCategoryControlStatus)
|
||||
.FindBool(GetAppListControlCategoryName(
|
||||
AppListSearchControlCategory::kApps))
|
||||
.value_or(true));
|
||||
|
||||
// Pressing a key that is not an initial of the items does not do anything to
|
||||
// the menu.
|
||||
PressAndReleaseKey(ui::VKEY_X);
|
||||
EXPECT_TRUE(GetSearchBoxView()->IsFilterMenuOpen());
|
||||
|
||||
// As "A" is the initial character if "Apps", the corresponding menu item is
|
||||
// automatically toggled and the menu is closed.
|
||||
PressAndReleaseKey(ui::VKEY_A);
|
||||
std::optional apps_search_enabled =
|
||||
prefs->GetDict(prefs::kLauncherSearchCategoryControlStatus)
|
||||
.FindBool(GetAppListControlCategoryName(
|
||||
AppListSearchControlCategory::kApps));
|
||||
ASSERT_TRUE(apps_search_enabled.has_value());
|
||||
EXPECT_FALSE(*apps_search_enabled);
|
||||
EXPECT_FALSE(GetSearchBoxView()->IsFilterMenuOpen());
|
||||
EXPECT_TRUE(is_search_triggered);
|
||||
|
||||
// Reset the search callback.
|
||||
app_list_client->set_search_callback(TestAppListClient::SearchCallback());
|
||||
}
|
||||
|
||||
// Verifies that the filter button and all menu items in the search category
|
||||
// filter have tooltips.
|
||||
TEST_P(SearchResultImageViewTest, SearchCategoryMenuItemTooltips) {
|
||||
|
@ -437,7 +437,6 @@ class FilterMenuAdapter : public views::MenuModelAdapter {
|
||||
// Returns the menu item view at `index` in the category filter menu. This
|
||||
// should only be called when the menu is opened.
|
||||
views::MenuItemView* GetFilterMenuItemByIdx(int index) {
|
||||
CHECK(IsFilterMenuOpen());
|
||||
return filter_menu_root_->GetSubmenu()->GetMenuItemAt(index);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user