Skip to content

Commit

Permalink
[M111] Add openWebFeed command implementation.
Browse files Browse the repository at this point in the history
Direct copy of https://chromium-review.googlesource.com/c/chromium/src/+/4028845

(cherry picked from commit 104b927)

Bug: 1380541
Change-Id: I8bb66b696256c58b080be32c1a18fcd28e444f59
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4205190
Commit-Queue: Sophey Dong <sophey@chromium.org>
Reviewed-by: Carlos Knippschild <carlosk@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1098898}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4220051
Reviewed-by: Peter Williamson <petewil@chromium.org>
Cr-Commit-Position: refs/branch-heads/5563@{#121}
Cr-Branched-From: 3ac59a6-refs/heads/main@{#1097615}
  • Loading branch information
Sophey authored and Chromium LUCI CQ committed Feb 2, 2023
1 parent f33670a commit bdcd09d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public void openCrow(String url) {
// Unused; feature is deprecated and does not launch from the feed.
}

@Override
public void openWebFeed(String webFeedName) {
// Unused; the Creator feed does not need to navigate to another feed.
}

@Override
public void onContentsChanged() {
// Not sure if this needs to be implemented.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
package org.chromium.chrome.browser.app.feed;

import android.content.Context;
import android.content.Intent;

import org.chromium.base.Callback;
import org.chromium.base.FeatureList;
import org.chromium.base.ThreadUtils;
import org.chromium.chrome.browser.app.creator.CreatorActivity;
import org.chromium.chrome.browser.bookmarks.BookmarkModel;
import org.chromium.chrome.browser.bookmarks.BookmarkUtils;
import org.chromium.chrome.browser.feed.FeedActionDelegate;
Expand Down Expand Up @@ -131,6 +133,20 @@ public void openCrow(String url) {
}
}

@Override
public void openWebFeed(String webFeedName) {
if (!FeatureList.isInitialized()
|| !ChromeFeatureList.isEnabled(ChromeFeatureList.CORMORANT)) {
return;
}

assert ThreadUtils.runningOnUiThread();
Class<?> creatorActivityClass = CreatorActivity.class;
Intent intent = new Intent(mActivityContext, creatorActivityClass);
intent.putExtra("CREATOR_WEB_FEED_ID", webFeedName);
mActivityContext.startActivity(intent);
}

@Override
public void onContentsChanged() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import android.content.Context;
import android.content.Intent;

import com.google.common.collect.ImmutableMap;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import org.chromium.base.ContextUtils;
import org.chromium.base.FeatureList;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.chrome.browser.app.feed.FeedActionDelegateImpl;
Expand Down Expand Up @@ -46,19 +51,25 @@ public final class FeedActionDelegateImplTest {
@Mock
private BookmarkModel mMockBookmarkModel;

@Mock
private Context mActivityContext;

@Mock
private CrowButtonDelegate mMockCrowButtonDelegate;

@Captor
ArgumentCaptor<Intent> mIntentCaptor;

private FeedActionDelegateImpl mFeedActionDelegateImpl;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);

SyncConsentActivityLauncherImpl.setLauncherForTest(mMockSyncConsentActivityLauncher);
mFeedActionDelegateImpl = new FeedActionDelegateImpl(ContextUtils.getApplicationContext(),
mMockSnackbarManager, mMockNavigationDelegate, mMockBookmarkModel,
mMockCrowButtonDelegate, BrowserUiUtils.HostSurface.NOT_SET);
mFeedActionDelegateImpl = new FeedActionDelegateImpl(mActivityContext, mMockSnackbarManager,
mMockNavigationDelegate, mMockBookmarkModel, mMockCrowButtonDelegate,
BrowserUiUtils.HostSurface.NOT_SET);
}

@Test
Expand All @@ -78,4 +89,22 @@ public void testShowSignInActivity_dontShowWhenFlagDisabled() {
verify(mMockSyncConsentActivityLauncher, never())
.launchActivityIfAllowed(any(), eq(SigninAccessPoint.NTP_CONTENT_SUGGESTIONS));
}

@Test
public void testOpenWebFeed_enabledWhenCormorantFlagEnabled() {
FeatureList.setTestFeatures(ImmutableMap.of(ChromeFeatureList.CORMORANT, true));

mFeedActionDelegateImpl.openWebFeed("SomeFeedName");

verify(mActivityContext).startActivity(mIntentCaptor.capture());
Assert.assertEquals("Feed ID not passed correctly.", "SomeFeedName",
mIntentCaptor.getValue().getStringExtra("CREATOR_WEB_FEED_ID"));
}

@Test
public void testOpenWebFeed_disabledWhenCormorantFlagDisabled() {
FeatureList.setTestFeatures(ImmutableMap.of(ChromeFeatureList.CORMORANT, false));
mFeedActionDelegateImpl.openWebFeed("SomeFeedName");
verify(mActivityContext, never()).startActivity(any());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ void openSuggestionUrl(int disposition, LoadUrlParams params, boolean inGroup,
*/
void openCrow(String url);

/**
* Opens a specific WebFeed by name.
* @param webFeedName the relevant web feed name.
*/
void openWebFeed(String webFeedName);

//
// Optional methods for handing events.
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ public void updateWebFeedFollowState(WebFeedFollowUpdate update) {
}
}

@Override
public void openWebFeed(String webFeedName) {
mActionDelegate.openWebFeed(webFeedName);
}

private void openSuggestionUrl(
String url, int disposition, boolean inGroup, OpenUrlOptions openOptions) {
boolean inNewTab = (disposition == WindowOpenDisposition.NEW_BACKGROUND_TAB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ default int webFeedChangeReason() {
*/
default void updateWebFeedFollowState(WebFeedFollowUpdate update) {}

/**
* Opens a specific WebFeed by name.
* @param webFeedName the relevant web feed name.
*/
default void openWebFeed(String webFeedName) {}

/**
* Navigates a new tab in group to a particular URL.
* @param url The url for which to navigate.
Expand Down

0 comments on commit bdcd09d

Please sign in to comment.