Commit 9b708053 authored by David Maunder's avatar David Maunder Committed by Commit Bot

Prioritize group over close when returning TabSuggestions

Suggestions for grouping tabs together or closing tabs are made to
the user. Grouping suggestions should be given precedence over
closing suggestions.

Bug: 1095182
Change-Id: Iba648eef8ec704e5687fb5ee02f1dd1f91ce350f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2247241
Commit-Queue: David Maunder <davidjm@chromium.org>
Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#778977}
parent 6d9c3390
......@@ -97,7 +97,8 @@ public class TabSuggestionsOrchestrator implements TabSuggestions, Destroyable {
}
}
private List<TabSuggestion> aggregateResults(List<TabSuggestion> tabSuggestions) {
@VisibleForTesting
protected static List<TabSuggestion> aggregateResults(List<TabSuggestion> tabSuggestions) {
List<TabSuggestion> aggregated = new LinkedList<>();
for (TabSuggestion tabSuggestion : tabSuggestions) {
switch (tabSuggestion.getAction()) {
......@@ -118,7 +119,7 @@ public class TabSuggestionsOrchestrator implements TabSuggestions, Destroyable {
}
}
// TODO(crbug.com/1085452): Sort the suggestion based on priority.
Collections.shuffle(aggregated);
Collections.sort(aggregated, (t1, t2) -> Integer.compare(t1.getAction(), t2.getAction()));
return aggregated;
}
......
......@@ -51,7 +51,9 @@ import java.util.List;
@RunWith(LocalRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class TabSuggestionsOrchestratorTest {
private static final int[] TAB_IDS = {0, 1, 2};
private static final int[] TAB_IDS = {0, 1, 2, 3, 4};
private static final String GROUPING_PROVIDER = "groupingProvider";
private static final String CLOSE_PROVIDER = "closeProvider";
@Rule
public TestRule mProcessor = new Features.JUnitProcessor();
......@@ -74,7 +76,8 @@ public class TabSuggestionsOrchestratorTest {
@Mock
private ActivityLifecycleDispatcher mDispatcher;
private static Tab[] sTabs = {mockTab(TAB_IDS[0]), mockTab(TAB_IDS[1]), mockTab(TAB_IDS[2])};
private static Tab[] sTabs = {mockTab(TAB_IDS[0]), mockTab(TAB_IDS[1]), mockTab(TAB_IDS[2]),
mockTab(TAB_IDS[3]), mockTab(TAB_IDS[4])};
private static Tab mockTab(int id) {
TabImpl tab = mock(TabImpl.class);
......@@ -198,4 +201,24 @@ public class TabSuggestionsOrchestratorTest {
Assert.assertEquals(
(int) tabSuggestionsOrchestrator.mTabSuggestionFeedback.selectedTabIds.get(0), 1);
}
@Test
public void testAggregationSorting() {
TabSuggestion groupSuggestion =
new TabSuggestion(Arrays.asList(TabContext.TabInfo.createFromTab(sTabs[0]),
TabContext.TabInfo.createFromTab(sTabs[1])),
TabSuggestion.TabSuggestionAction.GROUP, GROUPING_PROVIDER);
TabSuggestion closeSuggestion =
new TabSuggestion(Arrays.asList(TabContext.TabInfo.createFromTab(sTabs[2]),
TabContext.TabInfo.createFromTab(sTabs[3]),
TabContext.TabInfo.createFromTab(sTabs[4])),
TabSuggestion.TabSuggestionAction.CLOSE, CLOSE_PROVIDER);
List<TabSuggestion> sortedSuggestions = TabSuggestionsOrchestrator.aggregateResults(
Arrays.asList(closeSuggestion, groupSuggestion));
// Grouping suggestions should come first
Assert.assertEquals(
TabSuggestion.TabSuggestionAction.GROUP, sortedSuggestions.get(0).getAction());
Assert.assertEquals(
TabSuggestion.TabSuggestionAction.CLOSE, sortedSuggestions.get(1).getAction());
}
}
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