OLD | NEW |
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.browser.ntp.snippets; | 5 package org.chromium.chrome.browser.ntp.snippets; |
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; |
11 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus.CategoryStatusEnu
m; | 11 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus.CategoryStatusEnu
m; |
12 | 12 |
13 import java.util.ArrayList; | 13 import java.util.ArrayList; |
14 import java.util.Collections; | 14 import java.util.Collections; |
15 import java.util.HashMap; | 15 import java.util.HashMap; |
| 16 import java.util.LinkedHashMap; |
16 import java.util.List; | 17 import java.util.List; |
17 import java.util.Map; | 18 import java.util.Map; |
18 import java.util.Set; | 19 import java.util.Set; |
19 | 20 |
20 /** | 21 /** |
21 * A fake Suggestions source for use in unit and instrumentation tests. | 22 * A fake Suggestions source for use in unit and instrumentation tests. |
22 */ | 23 */ |
23 public class FakeSuggestionsSource implements SuggestionsSource { | 24 public class FakeSuggestionsSource implements SuggestionsSource { |
24 private SuggestionsSource.Observer mObserver; | 25 private SuggestionsSource.Observer mObserver; |
25 private final Map<Integer, List<SnippetArticle>> mSuggestions = new HashMap<
>(); | 26 private final Map<Integer, List<SnippetArticle>> mSuggestions = new HashMap<
>(); |
26 private final Map<Integer, Integer> mCategoryStatus = new HashMap<>(); | 27 private final Map<Integer, Integer> mCategoryStatus = new LinkedHashMap<>(); |
27 private final Map<Integer, SuggestionsCategoryInfo> mCategoryInfo = new Hash
Map<>(); | 28 private final Map<Integer, SuggestionsCategoryInfo> mCategoryInfo = new Hash
Map<>(); |
28 private final Map<String, Bitmap> mThumbnails = new HashMap<>(); | 29 private final Map<String, Bitmap> mThumbnails = new HashMap<>(); |
29 | 30 |
30 /** | 31 /** |
31 * Sets the status to be returned for a given category. | 32 * Sets the status to be returned for a given category. |
32 */ | 33 */ |
33 public void setStatusForCategory(@CategoryInt int category, | 34 public void setStatusForCategory(@CategoryInt int category, |
34 @CategoryStatusEnum int status) { | 35 @CategoryStatusEnum int status) { |
35 mCategoryStatus.put(category, status); | 36 mCategoryStatus.put(category, status); |
36 if (mObserver != null) mObserver.onCategoryStatusChanged(category, statu
s); | 37 if (mObserver != null) mObserver.onCategoryStatusChanged(category, statu
s); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 130 |
130 @Override | 131 @Override |
131 public List<SnippetArticle> getSuggestionsForCategory(int category) { | 132 public List<SnippetArticle> getSuggestionsForCategory(int category) { |
132 if (!SnippetsBridge.isCategoryStatusAvailable(mCategoryStatus.get(catego
ry))) { | 133 if (!SnippetsBridge.isCategoryStatusAvailable(mCategoryStatus.get(catego
ry))) { |
133 return Collections.emptyList(); | 134 return Collections.emptyList(); |
134 } | 135 } |
135 List<SnippetArticle> result = mSuggestions.get(category); | 136 List<SnippetArticle> result = mSuggestions.get(category); |
136 return result == null ? Collections.<SnippetArticle>emptyList() : result
; | 137 return result == null ? Collections.<SnippetArticle>emptyList() : result
; |
137 } | 138 } |
138 } | 139 } |
OLD | NEW |