Commit fb1c4988 authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

Restore help icon after password search

If the screen space doesn't suffice for multiple action bar icons, the
help icon will be pushed to the Overflow menu which is what happens when
a search is triggered.
Even after the search is closed, the item wasn't moved back but stayed
in the overflow menu. With this CL, we ensure that the help icon stays
in the action bar if sufficient space is available.

Bug: 821687
Change-Id: Icb438f9988f9114f563e920ddc95f27ebdac5434
Reviewed-on: https://chromium-review.googlesource.com/962425Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Friedrich Horschig <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543334}
parent dcbfc950
...@@ -651,7 +651,7 @@ public class SavePasswordsPreferences ...@@ -651,7 +651,7 @@ public class SavePasswordsPreferences
private boolean filterPasswords(String query) { private boolean filterPasswords(String query) {
mSearchQuery = query; mSearchQuery = query;
// Hide the help option. It's not useful during search but might be clicked by accident. // Hide the help option. It's not useful during search but might be clicked by accident.
mHelpItem.setShowAsAction(mSearchQuery == null ? MenuItem.SHOW_AS_ACTION_NEVER mHelpItem.setShowAsAction(mSearchQuery != null ? MenuItem.SHOW_AS_ACTION_NEVER
: MenuItem.SHOW_AS_ACTION_IF_ROOM); : MenuItem.SHOW_AS_ACTION_IF_ROOM);
rebuildPasswordLists(); rebuildPasswordLists();
return false; // Query has been handled. Don't trigger default action of SearchView. return false; // Query has been handled. Don't trigger default action of SearchView.
......
...@@ -1523,6 +1523,58 @@ public class SavePasswordsPreferencesTest { ...@@ -1523,6 +1523,58 @@ public class SavePasswordsPreferencesTest {
Espresso.onView(withText(R.string.search)).check(matches(isDisplayed())); Espresso.onView(withText(R.string.search)).check(matches(isDisplayed()));
} }
/**
* Check that searching doesn't push the help icon into the overflow menu permanently.
* On screen sizes where the help item starts out in the overflow menu, ensure it stays there.
*/
@Test
@SmallTest
@Feature({"Preferences"})
@EnableFeatures(ChromeFeatureList.PASSWORD_SEARCH)
public void testTriggeringSearchRestoresHelpIcon() throws Exception {
setPasswordSource(null);
PreferencesTest.startPreferences(InstrumentationRegistry.getInstrumentation(),
SavePasswordsPreferences.class.getName());
Espresso.onView(isRoot()).check(
(root, e)
-> waitForView(
(ViewGroup) root, withText(R.string.prefs_saved_passwords_title)));
// Retrieve the initial status and ensure that the help option is there at all.
final AtomicReference<Boolean> helpInOverflowMenu = new AtomicReference<>(false);
Espresso.onView(withId(R.id.menu_id_general_help)).check((helpMenuItem, e) -> {
ActionMenuItemView view = (ActionMenuItemView) helpMenuItem;
helpInOverflowMenu.set(view == null || !view.showsIcon());
});
if (helpInOverflowMenu.get()) {
openActionBarOverflowOrOptionsMenu(
InstrumentationRegistry.getInstrumentation().getTargetContext());
Espresso.onView(withText(R.string.menu_help)).check(matches(isDisplayed()));
Espresso.pressBack(); // to close the Overflow menu.
} else {
Espresso.onView(withId(R.id.menu_id_general_help)).check(matches(isDisplayed()));
}
// Trigger the search, close it and wait for UI to be restored.
Espresso.onView(withSearchMenuIdOrText()).perform(click());
Espresso.onView(withId(R.id.search_close_btn)).perform(click());
Espresso.onView(isRoot()).check(
(root, e)
-> waitForView(
(ViewGroup) root, withText(R.string.prefs_saved_passwords_title)));
// Check that the help option is exactly where it was to begin with.
if (helpInOverflowMenu.get()) {
openActionBarOverflowOrOptionsMenu(
InstrumentationRegistry.getInstrumentation().getTargetContext());
Espresso.onView(withText(R.string.menu_help)).check(matches(isDisplayed()));
Espresso.onView(withId(R.id.menu_id_general_help)).check(doesNotExist());
} else {
Espresso.onView(withText(R.string.menu_help)).check(doesNotExist());
Espresso.onView(withId(R.id.menu_id_general_help)).check(matches(isDisplayed()));
}
}
/** /**
* Check that the search item is not visible if the Feature is disabled. * Check that the search item is not visible if the Feature is disabled.
*/ */
......
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