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

Unified Diff: chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/suggestions/FakeSuggestionsSource.java

Issue 2781583002: [Content suggestions] Add a function to the service API to fetch favicons (Closed)
Patch Set: Fix compilation #2 Created 3 years, 9 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/test/android/javatests/src/org/chromium/chrome/test/util/browser/suggestions/FakeSuggestionsSource.java
diff --git a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/suggestions/FakeSuggestionsSource.java b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/suggestions/FakeSuggestionsSource.java
index b2969cadbb0cf229382cdc2751a2b43bf0a49a20..b8d20edf55f010949396517c7516d6271de9606a 100644
--- a/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/suggestions/FakeSuggestionsSource.java
+++ b/chrome/test/android/javatests/src/org/chromium/chrome/test/util/browser/suggestions/FakeSuggestionsSource.java
@@ -7,6 +7,7 @@ package org.chromium.chrome.test.util.browser.suggestions;
import android.graphics.Bitmap;
import org.chromium.base.Callback;
+import org.chromium.base.ThreadUtils;
import org.chromium.chrome.browser.ntp.cards.SuggestionsCategoryInfo;
import org.chromium.chrome.browser.ntp.snippets.CategoryInt;
import org.chromium.chrome.browser.ntp.snippets.CategoryStatus;
@@ -31,7 +32,10 @@ public class FakeSuggestionsSource implements SuggestionsSource {
private final Map<Integer, List<SnippetArticle>> mSuggestions = new HashMap<>();
private final Map<Integer, Integer> mCategoryStatus = new LinkedHashMap<>();
private final Map<Integer, SuggestionsCategoryInfo> mCategoryInfo = new HashMap<>();
+
+ // Maps within-category ids to their fake bitmaps.
private final Map<String, Bitmap> mThumbnails = new HashMap<>();
+ private final Map<String, Bitmap> mFavicons = new HashMap<>();
private final List<Integer> mDismissedCategories = new ArrayList<>();
private final Map<Integer, List<SnippetArticle>> mDismissedCategorySuggestions =
@@ -70,13 +74,22 @@ public class FakeSuggestionsSource implements SuggestionsSource {
}
/**
- * Sets the bitmap to be returned when the thumbnail is requested for a snippet with that id.
+ * Sets the bitmap to be returned when the thumbnail is requested for a suggestion with that
+ * (within-category) id.
*/
public void setThumbnailForId(String id, Bitmap bitmap) {
mThumbnails.put(id, bitmap);
}
/**
+ * Sets the bitmap to be returned when the favicon is requested for a suggestion with that
+ * (within-category) id.
+ */
+ public void setFaviconForId(String id, Bitmap bitmap) {
+ mFavicons.put(id, bitmap);
+ }
+
+ /**
* Removes the given suggestion from the source and notifies any observer that it has been
* invalidated.
*/
@@ -138,9 +151,28 @@ public class FakeSuggestionsSource implements SuggestionsSource {
}
@Override
- public void fetchSuggestionImage(SnippetArticle suggestion, Callback<Bitmap> callback) {
+ public void fetchSuggestionImage(
+ final SnippetArticle suggestion, final Callback<Bitmap> callback) {
if (mThumbnails.containsKey(suggestion.mIdWithinCategory)) {
- callback.onResult(mThumbnails.get(suggestion.mIdWithinCategory));
+ ThreadUtils.postOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ callback.onResult(mThumbnails.get(suggestion.mIdWithinCategory));
+ }
+ });
+ }
+ }
+
+ @Override
+ public void fetchSuggestionFavicon(final SnippetArticle suggestion, int minimumSizePx,
+ int desiredSizePx, final Callback<Bitmap> callback) {
+ if (mFavicons.containsKey(suggestion.mIdWithinCategory)) {
+ ThreadUtils.postOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ callback.onResult(mFavicons.get(suggestion.mIdWithinCategory));
+ }
+ });
}
}
« no previous file with comments | « chrome/browser/android/ntp/ntp_snippets_bridge.cc ('k') | components/ntp_snippets/content_suggestions_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698