Skip to content

Commit

Permalink
Restore help icon after password search
Browse files Browse the repository at this point in the history
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/962425
Reviewed-by: Theresa <twellington@chromium.org>
Commit-Queue: Friedrich Horschig <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543334}
  • Loading branch information
FHorschig authored and Commit Bot committed Mar 15, 2018
1 parent dcbfc95 commit fb1c498
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ private void sendExportIntent() {
private boolean filterPasswords(String query) {
mSearchQuery = query;
// 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);
rebuildPasswordLists();
return false; // Query has been handled. Don't trigger default action of SearchView.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,58 @@ public void testSearchTextInOverflowMenuVisibleWithFeature() throws Exception {
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.
*/
Expand Down

0 comments on commit fb1c498

Please sign in to comment.