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