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

[Android] Prevent keyboard accessory from cleaning cache early

Cleaning the cached password accessory right when the tab is closed was
too early: undo closing the tab would cause the cache to be unable to
restore the tab properly. Most visible impact: the key icon would be
gone temporarily.

This CL waits for committed tab closure (i.e. past the point of undoing)
to clear the cache.

Bug: 874798
Change-Id: I2dee7559e8c036f04dff2f2b0daf6c49c73ec8e5
Reviewed-on: https://chromium-review.googlesource.com/1185017Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Friedrich Horschig [CEST] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585433}
parent 091271ad
......@@ -155,8 +155,13 @@ class ManualFillingMediator
}
@Override
public void willCloseTab(Tab tab, boolean animate) {
public void tabClosureCommitted(Tab tab) {
mModel.remove(tab);
}
@Override
public void willCloseTab(Tab tab, boolean animate) {
if (mActiveBrowserTab == tab) mActiveBrowserTab = null;
restoreCachedState(mActiveBrowserTab);
}
};
......
......@@ -261,6 +261,36 @@ public class ManualFillingControllerTest {
assertThat(accessorySheetModel.getTabList().size(), is(0));
}
@Test
public void testPasswordTabRestoredWhenClosingTabIsUndone() {
ManualFillingMediator mediator = mController.getMediatorForTesting();
KeyboardAccessoryModel keyboardAccessoryModel =
mediator.getKeyboardAccessory().getMediatorForTesting().getModelForTesting();
assertThat(keyboardAccessoryModel.getTabList().size(), is(0));
// Create a new tab with a passwords tab:
Tab tab = addTab(mediator, 1111, null);
mController.registerPasswordProvider(new PropertyProvider<>());
assertThat(keyboardAccessoryModel.getTabList().size(), is(1));
// Simulate closing the tab:
mediator.getTabModelObserverForTesting().willCloseTab(tab, false);
mediator.getTabObserverForTesting().onHidden(tab);
// Temporary removes the tab, but keeps it in memory so it can be brought back on undo:
assertThat(keyboardAccessoryModel.getTabList().size(), is(0));
// Simulate undo closing the tab and selecting it:
mediator.getTabModelObserverForTesting().tabClosureUndone(tab);
switchTab(mediator, null, tab);
// There should still be a tab in the accessory:
assertThat(keyboardAccessoryModel.getTabList().size(), is(1));
// Simulate closing the tab and committing to it (i.e. wait out undo message):
closeTab(mediator, tab, null);
mediator.getTabModelObserverForTesting().tabClosureCommitted(tab);
assertThat(keyboardAccessoryModel.getTabList().size(), is(0));
}
@Test
public void testRecoversFromInvalidState() {
ManualFillingMediator mediator = mController.getMediatorForTesting();
......
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