Commit f0c92bd8 authored by Esmael El-Moslimany's avatar Esmael El-Moslimany Committed by Commit Bot

History WebUI: fix out of bound index error when deleting history item

When a history item is removed, we want to move the focus to next menu
button. This was done by updating the items and focusing on the item
with the same index. When removing the last item, this was causing an
error since the index is now out of bounds of the items. This CL focuses
on the new last item if there is one.

Fixed: 1055956
Change-Id: I41934486f01c1c10afcf34a296585cb23d955592
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2073149
Commit-Queue: Esmael Elmoslimany <aee@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744745}
parent c2800fbb
...@@ -439,13 +439,17 @@ Polymer({ ...@@ -439,13 +439,17 @@ Polymer({
if (index === undefined) { if (index === undefined) {
return; return;
} }
setTimeout(() => {
this.$['infinite-list'].focusItem(index); if (this.historyData_.length > 0) {
const item = getDeepActiveElement(); setTimeout(() => {
if (item) { this.$['infinite-list'].focusItem(
item.focusOnMenuButton(); Math.min(this.historyData_.length - 1, index));
} const item = getDeepActiveElement();
}, 1); if (item && item.focusOnMenuButton) {
item.focusOnMenuButton();
}
}, 1);
}
const browserService = BrowserService.getInstance(); const browserService = BrowserService.getInstance();
browserService.recordHistogram( browserService.recordHistogram(
......
...@@ -13,6 +13,7 @@ import {pressAndReleaseKeyOn} from 'chrome://resources/polymer/v3_0/iron-test-he ...@@ -13,6 +13,7 @@ import {pressAndReleaseKeyOn} from 'chrome://resources/polymer/v3_0/iron-test-he
suite('<history-list>', function() { suite('<history-list>', function() {
let app; let app;
let element; let element;
let testService;
const TEST_HISTORY_RESULTS = [ const TEST_HISTORY_RESULTS = [
createHistoryEntry('2016-03-15', 'https://www.google.com'), createHistoryEntry('2016-03-15', 'https://www.google.com'),
createHistoryEntry('2016-03-14 10:00', 'https://www.example.com'), createHistoryEntry('2016-03-14 10:00', 'https://www.example.com'),
...@@ -24,7 +25,7 @@ suite('<history-list>', function() { ...@@ -24,7 +25,7 @@ suite('<history-list>', function() {
setup(function() { setup(function() {
window.history.replaceState({}, '', '/'); window.history.replaceState({}, '', '/');
PolymerTest.clearBody(); PolymerTest.clearBody();
const testService = new TestBrowserService(); testService = new TestBrowserService();
BrowserService.instance_ = testService; BrowserService.instance_ = testService;
testService.setQueryResult({ testService.setQueryResult({
info: createHistoryInfo(), info: createHistoryInfo(),
...@@ -136,4 +137,20 @@ suite('<history-list>', function() { ...@@ -136,4 +137,20 @@ suite('<history-list>', function() {
[false, false, false, false], [false, false, false, false],
element.historyData_.map(i => i.selected)); element.historyData_.map(i => i.selected));
}); });
test('deleting last item will focus on new last item', async () => {
let focused;
await flushTasks();
flush();
const items = polymerSelectAll(element, 'history-item');
assertEquals(4, element.historyData_.length);
assertEquals(4, items.length);
items[3].$['menu-button'].click();
element.$$('#menuRemoveButton').click();
assertNotEquals(items[2].$['menu-button'], element.lastFocused_);
await testService.whenCalled('removeVisits');
await flushTasks();
assertEquals(3, element.historyData_.length);
assertEquals(items[2].$['menu-button'], element.lastFocused_);
});
}); });
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