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

Side by Side 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: Expand the FakeSuggestionsSource 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.test.util.browser.suggestions; 5 package org.chromium.chrome.test.util.browser.suggestions;
6 6
7 import android.graphics.Bitmap; 7 import android.graphics.Bitmap;
8 8
9 import org.chromium.base.Callback; 9 import org.chromium.base.Callback;
10 import org.chromium.chrome.browser.ntp.cards.SuggestionsCategoryInfo; 10 import org.chromium.chrome.browser.ntp.cards.SuggestionsCategoryInfo;
(...skipping 14 matching lines...) Expand all
25 /** 25 /**
26 * A fake Suggestions source for use in unit and instrumentation tests. 26 * A fake Suggestions source for use in unit and instrumentation tests.
27 */ 27 */
28 public class FakeSuggestionsSource implements SuggestionsSource { 28 public class FakeSuggestionsSource implements SuggestionsSource {
29 private SuggestionsSource.Observer mObserver; 29 private SuggestionsSource.Observer mObserver;
30 private final List<Integer> mCategories = new ArrayList<>(); 30 private final List<Integer> mCategories = new ArrayList<>();
31 private final Map<Integer, List<SnippetArticle>> mSuggestions = new HashMap< >(); 31 private final Map<Integer, List<SnippetArticle>> mSuggestions = new HashMap< >();
32 private final Map<Integer, Integer> mCategoryStatus = new LinkedHashMap<>(); 32 private final Map<Integer, Integer> mCategoryStatus = new LinkedHashMap<>();
33 private final Map<Integer, SuggestionsCategoryInfo> mCategoryInfo = new Hash Map<>(); 33 private final Map<Integer, SuggestionsCategoryInfo> mCategoryInfo = new Hash Map<>();
34 private final Map<String, Bitmap> mThumbnails = new HashMap<>(); 34 private final Map<String, Bitmap> mThumbnails = new HashMap<>();
35 private final Map<String, Bitmap> mFavicons = new HashMap<>();
Michael van Ouwerkerk 2017/03/28 11:23:56 Please document what the String represents.
jkrcal 2017/03/28 13:12:53 Done.
35 36
36 private final List<Integer> mDismissedCategories = new ArrayList<>(); 37 private final List<Integer> mDismissedCategories = new ArrayList<>();
37 private final Map<Integer, List<SnippetArticle>> mDismissedCategorySuggestio ns = 38 private final Map<Integer, List<SnippetArticle>> mDismissedCategorySuggestio ns =
38 new HashMap<>(); 39 new HashMap<>();
39 private final Map<Integer, Integer> mDismissedCategoryStatus = new LinkedHas hMap<>(); 40 private final Map<Integer, Integer> mDismissedCategoryStatus = new LinkedHas hMap<>();
40 private final Map<Integer, SuggestionsCategoryInfo> mDismissedCategoryInfo = new HashMap<>(); 41 private final Map<Integer, SuggestionsCategoryInfo> mDismissedCategoryInfo = new HashMap<>();
41 42
42 /** 43 /**
43 * Sets the status to be returned for a given category. 44 * Sets the status to be returned for a given category.
44 */ 45 */
(...skipping 25 matching lines...) Expand all
70 } 71 }
71 72
72 /** 73 /**
73 * Sets the bitmap to be returned when the thumbnail is requested for a snip pet with that id. 74 * Sets the bitmap to be returned when the thumbnail is requested for a snip pet with that id.
74 */ 75 */
75 public void setThumbnailForId(String id, Bitmap bitmap) { 76 public void setThumbnailForId(String id, Bitmap bitmap) {
76 mThumbnails.put(id, bitmap); 77 mThumbnails.put(id, bitmap);
77 } 78 }
78 79
79 /** 80 /**
81 * Sets the bitmap to be returned when the favicon is requested for a snippe t with that id.
Michael van Ouwerkerk 2017/03/28 11:23:56 We're trying to move away from this use of the wor
jkrcal 2017/03/28 13:12:53 Done.
82 */
83 public void setFaviconForId(String id, Bitmap bitmap) {
84 mFavicons.put(id, bitmap);
85 }
86
87 /**
80 * Removes the given suggestion from the source and notifies any observer th at it has been 88 * Removes the given suggestion from the source and notifies any observer th at it has been
81 * invalidated. 89 * invalidated.
82 */ 90 */
83 public void fireSuggestionInvalidated(@CategoryInt int category, String idWi thinCategory) { 91 public void fireSuggestionInvalidated(@CategoryInt int category, String idWi thinCategory) {
84 for (SnippetArticle suggestion : mSuggestions.get(category)) { 92 for (SnippetArticle suggestion : mSuggestions.get(category)) {
85 if (suggestion.mIdWithinCategory.equals(idWithinCategory)) { 93 if (suggestion.mIdWithinCategory.equals(idWithinCategory)) {
86 mSuggestions.get(category).remove(suggestion); 94 mSuggestions.get(category).remove(suggestion);
87 break; 95 break;
88 } 96 }
89 } 97 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 146 }
139 147
140 @Override 148 @Override
141 public void fetchSuggestionImage(SnippetArticle suggestion, Callback<Bitmap> callback) { 149 public void fetchSuggestionImage(SnippetArticle suggestion, Callback<Bitmap> callback) {
142 if (mThumbnails.containsKey(suggestion.mIdWithinCategory)) { 150 if (mThumbnails.containsKey(suggestion.mIdWithinCategory)) {
143 callback.onResult(mThumbnails.get(suggestion.mIdWithinCategory)); 151 callback.onResult(mThumbnails.get(suggestion.mIdWithinCategory));
144 } 152 }
145 } 153 }
146 154
147 @Override 155 @Override
156 public void fetchSuggestionFavicon(SnippetArticle suggestion, int minimumSiz eInPixel,
157 int desiredSizeInPixel, Callback<Bitmap> callback) {
158 if (mFavicons.containsKey(suggestion.mIdWithinCategory)) {
159 callback.onResult(mFavicons.get(suggestion.mIdWithinCategory));
Michael van Ouwerkerk 2017/03/28 11:23:56 The documentation for fetchSuggestionFavicon expli
jkrcal 2017/03/28 13:12:53 Done.
160 }
161 }
162
163 @Override
148 public void fetchSuggestions(@CategoryInt int category, String[] displayedSu ggestionIds) { 164 public void fetchSuggestions(@CategoryInt int category, String[] displayedSu ggestionIds) {
149 throw new UnsupportedOperationException(); 165 throw new UnsupportedOperationException();
150 } 166 }
151 167
152 @Override 168 @Override
153 public void setObserver(Observer observer) { 169 public void setObserver(Observer observer) {
154 mObserver = observer; 170 mObserver = observer;
155 } 171 }
156 172
157 @Override 173 @Override
(...skipping 17 matching lines...) Expand all
175 191
176 @Override 192 @Override
177 public List<SnippetArticle> getSuggestionsForCategory(int category) { 193 public List<SnippetArticle> getSuggestionsForCategory(int category) {
178 if (!SnippetsBridge.isCategoryStatusAvailable(mCategoryStatus.get(catego ry))) { 194 if (!SnippetsBridge.isCategoryStatusAvailable(mCategoryStatus.get(catego ry))) {
179 return Collections.emptyList(); 195 return Collections.emptyList();
180 } 196 }
181 List<SnippetArticle> result = mSuggestions.get(category); 197 List<SnippetArticle> result = mSuggestions.get(category);
182 return result == null ? Collections.<SnippetArticle>emptyList() : new Ar rayList<>(result); 198 return result == null ? Collections.<SnippetArticle>emptyList() : new Ar rayList<>(result);
183 } 199 }
184 } 200 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698