Commit c2d2ff88 authored by Marcin Wiacek's avatar Marcin Wiacek Committed by Commit Bot

Optimize ChromeContextMenuItem & ChromeContextMenuPopulator

1. replace enum in the ChromeContextMenuItem with @IntDef
2. rewrite buildContextMenu in the ChromeContextMenuPopulator:
   * remove unnecessary variables and code paths
   * instead of included / excluded rules put easy to understand
     "if" conditions

Change-Id: If617448a96e4bd78777507d36d6cc29c6f668a5a
Reviewed-on: https://chromium-review.googlesource.com/1175119
Commit-Queue: Marcin Wiącek <marcin@mwiacek.com>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587524}
parent 6e4f7dc4
...@@ -176,14 +176,21 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe ...@@ -176,14 +176,21 @@ public class BrowserActionsContextMenuHelper implements OnCreateContextMenuListe
R.string.browser_actions_share, R.id.browser_actions_share, true); R.string.browser_actions_share, R.id.browser_actions_share, true);
shareItem.setCreatorPackageName(sourcePackageName); shareItem.setCreatorPackageName(sourcePackageName);
if (FirstRunStatus.getFirstRunFlowComplete()) { if (FirstRunStatus.getFirstRunFlowComplete()) {
mBrowserActionsLinkGroup = mBrowserActionsLinkGroup = Arrays.asList(
Arrays.asList(ChromeContextMenuItem.BROWSER_ACTIONS_OPEN_IN_BACKGROUND, new ChromeContextMenuItem(
ChromeContextMenuItem.BROWSER_ACTIONS_OPEN_IN_INCOGNITO_TAB, ChromeContextMenuItem.Item.BROWSER_ACTIONS_OPEN_IN_BACKGROUND),
ChromeContextMenuItem.BROWSER_ACTION_SAVE_LINK_AS, new ChromeContextMenuItem(
ChromeContextMenuItem.BROWSER_ACTIONS_COPY_ADDRESS, shareItem); ChromeContextMenuItem.Item.BROWSER_ACTIONS_OPEN_IN_INCOGNITO_TAB),
new ChromeContextMenuItem(
ChromeContextMenuItem.Item.BROWSER_ACTION_SAVE_LINK_AS),
new ChromeContextMenuItem(
ChromeContextMenuItem.Item.BROWSER_ACTIONS_COPY_ADDRESS),
shareItem);
} else { } else {
mBrowserActionsLinkGroup = mBrowserActionsLinkGroup =
Arrays.asList(ChromeContextMenuItem.BROWSER_ACTIONS_COPY_ADDRESS, shareItem); Arrays.asList(new ChromeContextMenuItem(
ChromeContextMenuItem.Item.BROWSER_ACTIONS_COPY_ADDRESS),
shareItem);
} }
mMenuItemDelegate = new BrowserActionsContextMenuItemDelegate(mActivity, sourcePackageName); mMenuItemDelegate = new BrowserActionsContextMenuItemDelegate(mActivity, sourcePackageName);
mOnBrowserActionSelectedCallback = onBrowserActionSelectedCallback; mOnBrowserActionSelectedCallback = onBrowserActionSelectedCallback;
......
...@@ -27,6 +27,7 @@ import org.chromium.base.test.util.Feature; ...@@ -27,6 +27,7 @@ import org.chromium.base.test.util.Feature;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.contextmenu.ChromeContextMenuItem.Item;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.content_public.common.Referrer; import org.chromium.content_public.common.Referrer;
...@@ -86,8 +87,9 @@ public class TabularContextMenuUiTest { ...@@ -86,8 +87,9 @@ public class TabularContextMenuUiTest {
final List<Pair<Integer, List<ContextMenuItem>>> itemGroups = new ArrayList<>(); final List<Pair<Integer, List<ContextMenuItem>>> itemGroups = new ArrayList<>();
List<? extends ContextMenuItem> item = List<? extends ContextMenuItem> item =
CollectionUtil.newArrayList(ChromeContextMenuItem.ADD_TO_CONTACTS, CollectionUtil.newArrayList(new ChromeContextMenuItem(Item.ADD_TO_CONTACTS),
ChromeContextMenuItem.CALL, ChromeContextMenuItem.COPY_LINK_ADDRESS); new ChromeContextMenuItem(Item.CALL),
new ChromeContextMenuItem(Item.COPY_LINK_ADDRESS));
itemGroups.add( itemGroups.add(
new Pair<>(R.string.contextmenu_link_title, Collections.unmodifiableList(item))); new Pair<>(R.string.contextmenu_link_title, Collections.unmodifiableList(item)));
final String url = "http://google.com"; final String url = "http://google.com";
...@@ -115,8 +117,9 @@ public class TabularContextMenuUiTest { ...@@ -115,8 +117,9 @@ public class TabularContextMenuUiTest {
final List<Pair<Integer, List<ContextMenuItem>>> itemGroups = new ArrayList<>(); final List<Pair<Integer, List<ContextMenuItem>>> itemGroups = new ArrayList<>();
List<? extends ContextMenuItem> item = List<? extends ContextMenuItem> item =
CollectionUtil.newArrayList(ChromeContextMenuItem.ADD_TO_CONTACTS, CollectionUtil.newArrayList(new ChromeContextMenuItem(Item.ADD_TO_CONTACTS),
ChromeContextMenuItem.CALL, ChromeContextMenuItem.COPY_LINK_ADDRESS); new ChromeContextMenuItem(Item.CALL),
new ChromeContextMenuItem(Item.COPY_LINK_ADDRESS));
itemGroups.add( itemGroups.add(
new Pair<>(R.string.contextmenu_link_title, Collections.unmodifiableList(item))); new Pair<>(R.string.contextmenu_link_title, Collections.unmodifiableList(item)));
itemGroups.add( itemGroups.add(
...@@ -144,8 +147,9 @@ public class TabularContextMenuUiTest { ...@@ -144,8 +147,9 @@ public class TabularContextMenuUiTest {
public void testURLIsShownOnContextMenu() throws ExecutionException { public void testURLIsShownOnContextMenu() throws ExecutionException {
final TabularContextMenuUi dialog = new TabularContextMenuUi(null); final TabularContextMenuUi dialog = new TabularContextMenuUi(null);
final List<? extends ContextMenuItem> item = final List<? extends ContextMenuItem> item =
CollectionUtil.newArrayList(ChromeContextMenuItem.ADD_TO_CONTACTS, CollectionUtil.newArrayList(new ChromeContextMenuItem(Item.ADD_TO_CONTACTS),
ChromeContextMenuItem.CALL, ChromeContextMenuItem.COPY_LINK_ADDRESS); new ChromeContextMenuItem(Item.CALL),
new ChromeContextMenuItem(Item.COPY_LINK_ADDRESS));
final String createdUrl = "http://google.com"; final String createdUrl = "http://google.com";
final String expectedUrlWithFormatUrlForDisplayOmitHTTPScheme = "google.com"; final String expectedUrlWithFormatUrlForDisplayOmitHTTPScheme = "google.com";
View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() {
...@@ -170,8 +174,9 @@ public class TabularContextMenuUiTest { ...@@ -170,8 +174,9 @@ public class TabularContextMenuUiTest {
public void testHeaderIsNotShownWhenThereIsNoParams() throws ExecutionException { public void testHeaderIsNotShownWhenThereIsNoParams() throws ExecutionException {
final TabularContextMenuUi dialog = new TabularContextMenuUi(null); final TabularContextMenuUi dialog = new TabularContextMenuUi(null);
final List<? extends ContextMenuItem> item = final List<? extends ContextMenuItem> item =
CollectionUtil.newArrayList(ChromeContextMenuItem.ADD_TO_CONTACTS, CollectionUtil.newArrayList(new ChromeContextMenuItem(Item.ADD_TO_CONTACTS),
ChromeContextMenuItem.CALL, ChromeContextMenuItem.COPY_LINK_ADDRESS); new ChromeContextMenuItem(Item.CALL),
new ChromeContextMenuItem(Item.COPY_LINK_ADDRESS));
View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() {
@Override @Override
public View call() { public View call() {
...@@ -190,8 +195,9 @@ public class TabularContextMenuUiTest { ...@@ -190,8 +195,9 @@ public class TabularContextMenuUiTest {
public void testLinkShowsMultipleLinesWhenClicked() throws ExecutionException { public void testLinkShowsMultipleLinesWhenClicked() throws ExecutionException {
final TabularContextMenuUi dialog = new TabularContextMenuUi(null); final TabularContextMenuUi dialog = new TabularContextMenuUi(null);
final List<? extends ContextMenuItem> item = final List<? extends ContextMenuItem> item =
CollectionUtil.newArrayList(ChromeContextMenuItem.ADD_TO_CONTACTS, CollectionUtil.newArrayList(new ChromeContextMenuItem(Item.ADD_TO_CONTACTS),
ChromeContextMenuItem.CALL, ChromeContextMenuItem.COPY_LINK_ADDRESS); new ChromeContextMenuItem(Item.CALL),
new ChromeContextMenuItem(Item.COPY_LINK_ADDRESS));
View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() { View view = ThreadUtils.runOnUiThreadBlocking(new Callable<View>() {
@Override @Override
public View call() { public View call() {
......
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