Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2557)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java

Issue 2710833002: Refactor ChromeContextMenuPopulator population (Closed)
Patch Set: Fixed based off rebase + tedchoc comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java
index be2cf7e01fd71bfd0aa5d016806ed85ab3913943..646ebf5c779d19dd29a3b212ba7ecfd5c14cf47b 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/contextmenu/ContextMenuTest.java
@@ -9,6 +9,8 @@ import android.content.ClipboardManager;
import android.content.Context;
import android.support.test.filters.LargeTest;
import android.support.test.filters.MediumTest;
+import android.support.test.filters.SmallTest;
+import android.test.MoreAsserts;
import android.view.ContextMenu;
import android.view.KeyEvent;
@@ -34,6 +36,9 @@ import org.chromium.content.browser.test.util.TestTouchUtils;
import org.chromium.net.test.EmbeddedTestServer;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
@@ -348,6 +353,80 @@ public class ContextMenuTest extends DownloadTestBase {
assertEquals(imageUrl, tabModel.getTabAt(indexOfLinkPage2).getUrl());
}
+ @SmallTest
+ @Feature({"Browser", "ContextMenu"})
+ public void testContextMenuRetrievesLinkOptions()
+ throws TimeoutException, InterruptedException {
+ Tab tab = getActivity().getActivityTab();
+ ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testLink");
+
+ List<Integer> expectedItems = new ArrayList<>();
+ Collections.addAll(expectedItems, R.id.contextmenu_open_in_new_tab,
+ R.id.contextmenu_open_in_incognito_tab, R.id.contextmenu_copy_link_address,
+ R.id.contextmenu_copy_link_text, R.id.contextmenu_save_link_as);
+ assertMenuItemsAreEqual(menu, expectedItems);
+ }
+
+ @SmallTest
+ @Feature({"Browser", "ContextMenu"})
+ public void testContextMenuRetrievesImageOptions()
+ throws TimeoutException, InterruptedException {
+ Tab tab = getActivity().getActivityTab();
+ ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImage");
+
+ List<Integer> expectedItems = new ArrayList<>();
+ Collections.addAll(expectedItems, R.id.contextmenu_save_image,
+ R.id.contextmenu_open_image_in_new_tab, R.id.contextmenu_search_by_image,
+ R.id.contextmenu_share_image);
+ assertMenuItemsAreEqual(menu, expectedItems);
+ }
+
+ @SmallTest
+ @Feature({"Browser", "ContextMenu"})
+ public void testContextMenuRetrievesImageLinkOptions()
+ throws TimeoutException, InterruptedException {
+ Tab tab = getActivity().getActivityTab();
+ ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "testImageLink");
+
+ List<Integer> expectedItems = new ArrayList<>();
+ Collections.addAll(expectedItems, R.id.contextmenu_open_in_new_tab,
+ R.id.contextmenu_open_in_incognito_tab, R.id.contextmenu_copy_link_address,
+ R.id.contextmenu_save_link_as, R.id.contextmenu_save_image,
+ R.id.contextmenu_open_image_in_new_tab, R.id.contextmenu_search_by_image,
+ R.id.contextmenu_share_image);
+ assertMenuItemsAreEqual(menu, expectedItems);
+ }
+
+ @SmallTest
+ @Feature({"Browser", "ContextMenu"})
+ public void testContextMenuRetrievesVideoOptions()
+ throws TimeoutException, InterruptedException {
+ Tab tab = getActivity().getActivityTab();
+ DOMUtils.clickNode(getActivity().getCurrentContentViewCore(), "videoDOMElement");
+ ContextMenu menu = ContextMenuUtils.openContextMenu(tab, "videoDOMElement");
+
+ List<Integer> expectedItems = new ArrayList<>();
+ expectedItems.add(R.id.contextmenu_save_video);
+ assertMenuItemsAreEqual(menu, expectedItems);
+ }
+
+ /**
+ * Takes all the visible items on the menu and compares them to a the list of expected items.
+ * @param menu A context menu that is displaying visible items.
+ * @param expectedItems A list of items that is expected to appear within a context menu. The
+ * list does not need to be ordered.
+ */
+ private void assertMenuItemsAreEqual(ContextMenu menu, List<Integer> expectedItems) {
+ List<Integer> actualItems = new ArrayList<>();
+ for (int i = 0; i < menu.size(); i++) {
+ if (menu.getItem(i).isVisible()) {
+ actualItems.add(menu.getItem(i).getItemId());
+ }
+ }
+
+ MoreAsserts.assertContentsInAnyOrder(actualItems, expectedItems.toArray());
+ }
+
private void saveMediaFromContextMenu(String mediaDOMElement, int saveMenuID,
String expectedFilename) throws InterruptedException, TimeoutException,
SecurityException, IOException {

Powered by Google App Engine
This is Rietveld 408576698