Commit 8c03425c authored by Justin DeWitt's avatar Justin DeWitt Committed by Commit Bot

[EoS] Removes unusable context menus from the ExploreSites tile.

The ExploreSites tile is a special one that can't be removed or used
inside an incognito tab.

Bug: 966024
Change-Id: Idf2340ee879575ffe1c0f3402a4d7725326df248
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1635853
Commit-Queue: Justin DeWitt <dewittj@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarCathy Li <chili@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664535}
parent 96fc0dca
......@@ -548,11 +548,15 @@ public class TileGroup implements MostVisitedSites.Observer {
@Override
public boolean isItemSupported(@ContextMenuItemId int menuItemId) {
switch (menuItemId) {
// Personalized tiles are the only tiles that can be removed.
// Personalized tiles are the only tiles that can be removed. Additionally, the
// Explore tile counts as a personalized tile but cannot be removed.
case ContextMenuItemId.REMOVE:
return mSuggestion.sectionType == TileSectionType.PERSONALIZED;
return mSuggestion.sectionType == TileSectionType.PERSONALIZED
&& mSuggestion.source != TileSource.EXPLORE;
case ContextMenuItemId.LEARN_MORE:
return SuggestionsConfig.scrollToLoad();
case ContextMenuItemId.OPEN_IN_INCOGNITO_TAB:
return mSuggestion.source != TileSource.EXPLORE;
default:
return true;
}
......
......@@ -44,6 +44,8 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.browser.test.util.TestTouchUtils;
import org.chromium.net.test.EmbeddedTestServer;
import java.util.ArrayList;
import java.util.Date;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
......@@ -81,7 +83,10 @@ public class TileGroupTest {
mMostVisitedSites.setTileSuggestions(mSiteSuggestionUrls);
mSuggestionsDeps.getFactory().suggestionsSource = new FakeSuggestionsSource();
initializeTab();
}
public void initializeTab() throws Exception {
mActivityTestRule.startMainActivityWithURL(UrlConstants.NTP_URL);
Tab mTab = mActivityTestRule.getActivity().getActivityTab();
NewTabPageTestUtils.waitForNtpLoaded(mTab);
......@@ -119,6 +124,23 @@ public class TileGroupTest {
Assert.assertEquals(2, getTileGridLayout().getChildCount());
}
@Test
@MediumTest
@Feature({"NewTabPage"})
public void testDismissExploreTileWithContextMenuFails() throws Exception {
SiteSuggestion exploreTile = recreateSuggestionsWithExploreTile();
initializeTab();
Assert.assertEquals(4, getTileGridLayout().getChildCount());
final View tileView = getTileViewFor(exploreTile);
TestTouchUtils.performLongClickOnMainSync(
InstrumentationRegistry.getInstrumentation(), tileView);
Assert.assertFalse(InstrumentationRegistry.getInstrumentation().invokeContextMenuAction(
mActivityTestRule.getActivity(), ContextMenuManager.ContextMenuItemId.REMOVE, 0));
Assert.assertEquals(4, getTileGridLayout().getChildCount());
}
@Test
@MediumTest
@Feature({"NewTabPage"})
......@@ -239,4 +261,19 @@ public class TileGroupTest {
callback.waitForCallback("The expected tile was not added.", 0);
tileContainer.setOnHierarchyChangeListener(null);
}
private SiteSuggestion recreateSuggestionsWithExploreTile() {
// need a copy of the list in order to modify it.
final ArrayList<SiteSuggestion> currentSuggestions =
new ArrayList<>(mMostVisitedSites.getCurrentSites());
SiteSuggestion exploreTile = new SiteSuggestion("chrome-native://explore",
"chrome-native://explore", "", TileTitleSource.UNKNOWN, TileSource.EXPLORE,
TileSectionType.PERSONALIZED, new Date());
currentSuggestions.add(exploreTile);
TestThreadUtils.runOnUiThreadBlocking(
() -> mMostVisitedSites.setTileSuggestions(currentSuggestions));
return exploreTile;
}
}
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