Commit 7e14a87d authored by Filip Gorski's avatar Filip Gorski Committed by Commit Bot

[Zine] Old favicon code clean up

Bug: 751628
Change-Id: Ief50f500266330c5ecceff718001f92bd7d4f467
Reviewed-on: https://chromium-review.googlesource.com/c/1291840Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Filip Gorski <fgorski@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610962}
parent 06ef9411
......@@ -206,7 +206,7 @@ public class SuggestionsBinder {
setFaviconOnView(drawable, publisherFaviconSizePx);
};
mImageFetcher.makeFaviconRequest(mSuggestion, publisherFaviconSizePx, faviconCallback);
mImageFetcher.makeFaviconRequest(mSuggestion, faviconCallback);
}
private void setThumbnail() {
......
......@@ -41,7 +41,7 @@ public class SuggestionsUiDelegateImpl implements SuggestionsUiDelegate {
mSuggestionsRanker = new SuggestionsRanker();
mSuggestionsEventReporter = eventReporter;
mSuggestionsNavigationDelegate = navigationDelegate;
mImageFetcher = new ImageFetcher(suggestionsSource, profile, referencePool, host);
mImageFetcher = new ImageFetcher(suggestionsSource, profile, referencePool);
mSnackbarManager = snackbarManager;
mHost = host;
......
......@@ -485,12 +485,12 @@ public class ArticleSnippetsTest {
private class MockImageFetcher extends ImageFetcher {
public MockImageFetcher(
SuggestionsSource suggestionsSource, DiscardableReferencePool referencePool) {
super(suggestionsSource, null, referencePool, null);
super(suggestionsSource, null, referencePool);
}
@Override
public void makeFaviconRequest(SnippetArticle suggestion, final int faviconSizePx,
final Callback<Bitmap> faviconCallback) {
public void makeFaviconRequest(
SnippetArticle suggestion, final Callback<Bitmap> faviconCallback) {
// Run the callback asynchronously in case the caller made that assumption.
ThreadUtils.postOnUiThread(() -> {
// Return an arbitrary drawable.
......
......@@ -4,10 +4,11 @@
package org.chromium.chrome.browser.suggestions;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.chromium.chrome.test.util.browser.suggestions.ContentSuggestionsTestUtils.createDummySuggestion;
......@@ -23,11 +24,8 @@ import org.robolectric.annotation.Config;
import org.chromium.base.Callback;
import org.chromium.base.DiscardableReferencePool;
import org.chromium.base.test.BaseRobolectricTestRunner;
import org.chromium.chrome.browser.favicon.FaviconHelper;
import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback;
import org.chromium.chrome.browser.favicon.LargeIconBridge;
import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback;
import org.chromium.chrome.browser.native_page.NativePageHost;
import org.chromium.chrome.browser.ntp.cards.CardsVariationParameters;
import org.chromium.chrome.browser.ntp.snippets.KnownCategories;
import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
......@@ -38,8 +36,8 @@ import org.chromium.chrome.browser.widget.ThumbnailProvider;
import org.chromium.chrome.test.support.DisableHistogramsRule;
import org.chromium.chrome.test.util.browser.suggestions.SuggestionsDependenciesRule;
import java.net.URI;
import java.util.HashMap;
/**
* Unit tests for {@link ImageFetcher}.
*/
......@@ -56,8 +54,6 @@ public class ImageFetcherTest {
private DiscardableReferencePool mReferencePool = new DiscardableReferencePool();
@Mock
private FaviconHelper mFaviconHelper;
@Mock
private ThumbnailProvider mThumbnailProvider;
@Mock
......@@ -72,30 +68,46 @@ public class ImageFetcherTest {
mSuggestionsDeps.getFactory().largeIconBridge = mLargeIconBridge;
mSuggestionsDeps.getFactory().thumbnailProvider = mThumbnailProvider;
mSuggestionsDeps.getFactory().faviconHelper = mFaviconHelper;
mSuggestionsDeps.getFactory().suggestionsSource = mSuggestionsSource;
}
@SuppressWarnings("unchecked")
@Test
public void testFaviconFetch() {
ImageFetcher imageFetcher = new ImageFetcher(mSuggestionsSource, mock(Profile.class),
mReferencePool, mock(NativePageHost.class));
SnippetArticle suggestion = createDummySuggestion(KnownCategories.BOOKMARKS);
imageFetcher.makeFaviconRequest(suggestion, IMAGE_SIZE_PX, mock(Callback.class));
String expectedFaviconDomain =
ImageFetcher.getSnippetDomain(URI.create(suggestion.getUrl()));
verify(mFaviconHelper)
.getLocalFaviconImageForURL(any(Profile.class), eq(expectedFaviconDomain),
eq(IMAGE_SIZE_PX), any(FaviconImageCallback.class));
ImageFetcher imageFetcher =
new ImageFetcher(mSuggestionsSource, mock(Profile.class), mReferencePool);
Callback mockCallback = mock(Callback.class);
@KnownCategories
int[] categoriesWithIcon = new int[] {KnownCategories.ARTICLES, KnownCategories.CONTEXTUAL};
for (@KnownCategories int category : categoriesWithIcon) {
SnippetArticle suggestion = createDummySuggestion(category);
imageFetcher.makeFaviconRequest(suggestion, mockCallback);
verify(mSuggestionsSource)
.fetchSuggestionFavicon(eq(suggestion),
eq(ImageFetcher.PUBLISHER_FAVICON_MINIMUM_SIZE_PX),
eq(ImageFetcher.PUBLISHER_FAVICON_DESIRED_SIZE_PX),
any(Callback.class));
}
@KnownCategories
int[] categoriesThatDontFetch = new int[] {
KnownCategories.DOWNLOADS, KnownCategories.BOOKMARKS, KnownCategories.READING_LIST};
for (@KnownCategories int category : categoriesThatDontFetch) {
SnippetArticle suggestion = createDummySuggestion(category);
imageFetcher.makeFaviconRequest(suggestion, mockCallback);
verify(mSuggestionsSource, never())
.fetchSuggestionFavicon(
eq(suggestion), anyInt(), anyInt(), any(Callback.class));
}
}
@Test
public void testDownloadThumbnailFetch() {
ImageFetcher imageFetcher = new ImageFetcher(mSuggestionsSource, mock(Profile.class),
mReferencePool, mock(NativePageHost.class));
ImageFetcher imageFetcher =
new ImageFetcher(mSuggestionsSource, mock(Profile.class), mReferencePool);
SnippetArticle suggestion = createDummySuggestion(KnownCategories.DOWNLOADS);
......@@ -110,8 +122,8 @@ public class ImageFetcherTest {
@SuppressWarnings("unchecked")
@Test
public void testArticleThumbnailFetch() {
ImageFetcher imageFetcher = new ImageFetcher(mSuggestionsSource, mock(Profile.class),
mReferencePool, mock(NativePageHost.class));
ImageFetcher imageFetcher =
new ImageFetcher(mSuggestionsSource, mock(Profile.class), mReferencePool);
SnippetArticle suggestion = createDummySuggestion(KnownCategories.ARTICLES);
imageFetcher.makeArticleThumbnailRequest(suggestion, mock(Callback.class));
......@@ -121,24 +133,13 @@ public class ImageFetcherTest {
@Test
public void testLargeIconFetch() {
ImageFetcher imageFetcher = new ImageFetcher(mSuggestionsSource, mock(Profile.class),
mReferencePool, mock(NativePageHost.class));
ImageFetcher imageFetcher =
new ImageFetcher(mSuggestionsSource, mock(Profile.class), mReferencePool);
imageFetcher.makeLargeIconRequest(URL_STRING, IMAGE_SIZE_PX, mock(LargeIconCallback.class));
String expectedIconDomain = ImageFetcher.getSnippetDomain(URI.create(URL_STRING));
verify(mLargeIconBridge)
.getLargeIconForUrl(
eq(expectedIconDomain), eq(IMAGE_SIZE_PX), any(LargeIconCallback.class));
}
@Test
public void testSnippetDomainExtraction() {
URI uri = URI.create(URL_STRING + "/test");
String expected = URL_STRING;
String actual = ImageFetcher.getSnippetDomain(uri);
assertEquals(expected, actual);
eq(URL_STRING), eq(IMAGE_SIZE_PX), any(LargeIconCallback.class));
}
}
......@@ -479,7 +479,7 @@ public class TileGroupUnitTest {
private final List<LargeIconCallback> mCallbackList = new ArrayList<>();
public FakeImageFetcher() {
super(null, null, null, null);
super(null, null, null);
}
@Override
......
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