Commit 97e0d982 authored by Sinan Sahin's avatar Sinan Sahin Committed by Commit Bot

Fix failing ContextMenu tests

Tests testCopyImageLinkCopiesLinkURL and
testContextMenuRetrievesImageLinkOptions were failing when LayoutNG
is enabled. The issue seems to be that the context menu is
populated for the HTML element directly below the one the test is
trying to long press.

This CL works around the issue by adding an extra line break after the
element in the test HTML.

Bug: 959265
Change-Id: Ia5dd780c2b5edd4152412c6e61c8e6fb8749b0b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1721809Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Commit-Queue: Sinan Sahin <sinansahin@google.com>
Cr-Commit-Position: refs/heads/master@{#683256}
parent 0e48fee6
......@@ -142,7 +142,7 @@ public class ChromeContextMenuItem implements ContextMenuItem {
* @param item #Item Item ID.
* @return Returns the string that describes the action of the item.
*/
private static @StringRes int getStringID(@Item int item) {
private static @StringRes int getStringId(@Item int item) {
assert STRING_IDS.length == Item.NUM_ENTRIES;
if (FeatureUtilities.isTabGroupsAndroidEnabled() && item == Item.OPEN_IN_NEW_TAB) {
......@@ -164,19 +164,19 @@ public class ChromeContextMenuItem implements ContextMenuItem {
case Item.OPEN_IN_BROWSER_ID:
return DefaultBrowserInfo.getTitleOpenInDefaultBrowser(false);
case Item.SEARCH_BY_IMAGE:
return context.getString(getStringID(mItem),
return context.getString(getStringId(mItem),
TemplateUrlServiceFactory.get()
.getDefaultSearchEngineTemplateUrl()
.getShortName());
case Item.OPEN_IN_EPHEMERAL_TAB:
case Item.OPEN_IMAGE_IN_EPHEMERAL_TAB:
return SpanApplier.applySpans(context.getString(getStringID(mItem)),
return SpanApplier.applySpans(context.getString(getStringId(mItem)),
new SpanInfo("<new>", "</new>", new SuperscriptSpan(),
new RelativeSizeSpan(0.75f),
new ForegroundColorSpan(ApiCompatibilityUtils.getColor(
context.getResources(), R.color.default_text_color_blue))));
default:
return context.getString(getStringID(mItem));
return context.getString(getStringId(mItem));
}
}
}
......@@ -119,8 +119,6 @@ public class ContextMenuTest implements CustomMainActivityStart {
@Test
@MediumTest
@Feature({"Browser"})
@RetryOnFailure
@DisabledTest(message = "https://crbug.com/959265")
public void testCopyImageLinkCopiesLinkURL() throws Throwable {
Tab tab = mDownloadTestRule.getActivity().getActivityTab();
ContextMenuUtils.selectContextMenuItem(InstrumentationRegistry.getInstrumentation(),
......@@ -415,8 +413,6 @@ public class ContextMenuTest implements CustomMainActivityStart {
@Test
@SmallTest
@Feature({"Browser", "ContextMenu"})
@RetryOnFailure
@DisabledTest(message = "https://crbug.com/959265")
public void testContextMenuRetrievesImageLinkOptions()
throws TimeoutException, InterruptedException {
Tab tab = mDownloadTestRule.getActivity().getActivityTab();
......@@ -464,7 +460,18 @@ public class ContextMenuTest implements CustomMainActivityStart {
}
}
Assert.assertThat(actualItems, Matchers.containsInAnyOrder(expectedItems));
Assert.assertThat("Populated menu items were:" + getMenuTitles(menu), actualItems,
Matchers.containsInAnyOrder(expectedItems));
}
private String getMenuTitles(ContextMenu menu) {
StringBuilder items = new StringBuilder();
for (int i = 0; i < menu.size(); i++) {
if (menu.getItem(i).isVisible()) {
items.append("\n").append(menu.getItem(i).getTitle());
}
}
return items.toString();
}
/**
......
......@@ -10,7 +10,7 @@
<a href="test_link2.html" id="testLink2">Test Link 2></a><br />
<a href="test_link.html" id="testImageLink"><img src="test_image.png"></a><br />
<a href="test_link.html" id="testImageLink"><img src="test_image.png"></a><br /><br />
<a href="mailto:someone1@example.com,someone2@example.com?Subject=EmailTest" id="testEmail">EmailTest</a><br />
......
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