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.BitmapFactory; | 7 import android.graphics.BitmapFactory; |
8 import android.support.test.filters.MediumTest; | 8 import android.support.test.filters.MediumTest; |
9 import android.util.TypedValue; | 9 import android.util.TypedValue; |
10 import android.view.View; | 10 import android.view.View; |
11 import android.view.ViewGroup; | 11 import android.view.ViewGroup; |
12 import android.widget.FrameLayout; | 12 import android.widget.FrameLayout; |
13 | 13 |
14 import org.chromium.base.Callback; | 14 import org.chromium.base.Callback; |
15 import org.chromium.base.ThreadUtils; | 15 import org.chromium.base.ThreadUtils; |
16 import org.chromium.base.test.util.Feature; | 16 import org.chromium.base.test.util.Feature; |
17 import org.chromium.base.test.util.RetryOnFailure; | 17 import org.chromium.base.test.util.RetryOnFailure; |
18 import org.chromium.chrome.R; | 18 import org.chromium.chrome.R; |
19 import org.chromium.chrome.browser.ChromeActivity; | 19 import org.chromium.chrome.browser.ChromeActivity; |
20 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; | 20 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; |
21 import org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallbac
k; | 21 import org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallbac
k; |
22 import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback; | 22 import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback; |
23 import org.chromium.chrome.browser.ntp.ContextMenuManager; | 23 import org.chromium.chrome.browser.ntp.ContextMenuManager; |
24 import org.chromium.chrome.browser.ntp.LogoBridge.LogoObserver; | 24 import org.chromium.chrome.browser.ntp.LogoBridge.LogoObserver; |
25 import org.chromium.chrome.browser.ntp.MostVisitedItem; | 25 import org.chromium.chrome.browser.ntp.MostVisitedItem; |
26 import org.chromium.chrome.browser.ntp.NewTabPage.DestructionObserver; | 26 import org.chromium.chrome.browser.ntp.NewTabPage.DestructionObserver; |
27 import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager; | 27 import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager; |
28 import org.chromium.chrome.browser.ntp.UiConfig; | 28 import org.chromium.chrome.browser.ntp.UiConfig; |
| 29 import org.chromium.chrome.browser.ntp.cards.ActionItem; |
29 import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter; | 30 import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter; |
30 import org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView; | 31 import org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView; |
31 import org.chromium.chrome.browser.ntp.cards.SuggestionsCategoryInfo; | 32 import org.chromium.chrome.browser.ntp.cards.SuggestionsCategoryInfo; |
32 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; | 33 import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; |
33 import org.chromium.chrome.browser.profiles.MostVisitedSites.MostVisitedURLsObse
rver; | 34 import org.chromium.chrome.browser.profiles.MostVisitedSites.MostVisitedURLsObse
rver; |
34 import org.chromium.chrome.browser.profiles.Profile; | 35 import org.chromium.chrome.browser.profiles.Profile; |
| 36 import org.chromium.chrome.browser.suggestions.SuggestionsMetricsReporter; |
| 37 import org.chromium.chrome.browser.suggestions.SuggestionsRanker; |
35 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 38 import org.chromium.chrome.test.ChromeActivityTestCaseBase; |
36 import org.chromium.chrome.test.util.RenderUtils.ViewRenderer; | 39 import org.chromium.chrome.test.util.RenderUtils.ViewRenderer; |
37 | 40 |
38 import java.io.IOException; | 41 import java.io.IOException; |
39 import java.util.Arrays; | 42 import java.util.Arrays; |
40 import java.util.Set; | 43 import java.util.Set; |
41 | 44 |
42 /** | 45 /** |
43 * Tests for the appearance of Article Snippets. | 46 * Tests for the appearance of Article Snippets. |
44 */ | 47 */ |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 mViewRenderer.renderAndCompare(mRecyclerView.getChildAt(firstOfSecondCat
egory + 1), | 124 mViewRenderer.renderAndCompare(mRecyclerView.getChildAt(firstOfSecondCat
egory + 1), |
122 "short_minimal_snippet_narrow"); | 125 "short_minimal_snippet_narrow"); |
123 mViewRenderer.renderAndCompare(mRecyclerView, "snippets_narrow"); | 126 mViewRenderer.renderAndCompare(mRecyclerView, "snippets_narrow"); |
124 } | 127 } |
125 | 128 |
126 private void setupTestData() { | 129 private void setupTestData() { |
127 @CategoryInt | 130 @CategoryInt |
128 int fullCategory = 0; | 131 int fullCategory = 0; |
129 @CategoryInt | 132 @CategoryInt |
130 int minimalCategory = 1; | 133 int minimalCategory = 1; |
131 SnippetArticle shortSnippet = new SnippetArticle( | 134 SnippetArticle shortSnippet = new SnippetArticle(fullCategory, "id1", "S
nippet", |
132 fullCategory, | 135 "Publisher", "Preview Text", "www.google.com", |
133 "id1", | 136 1466614774, // Timestamp |
134 "Snippet", | 137 10f); // Score |
135 "Publisher", | |
136 "Preview Text", | |
137 "www.google.com", | |
138 1466614774, // Timestamp | |
139 10f, // Score | |
140 0); // Position | |
141 shortSnippet.setThumbnailBitmap(BitmapFactory.decodeResource(getActivity
().getResources(), | 138 shortSnippet.setThumbnailBitmap(BitmapFactory.decodeResource(getActivity
().getResources(), |
142 R.drawable.signin_promo_illustration)); | 139 R.drawable.signin_promo_illustration)); |
143 | 140 |
144 SnippetArticle longSnippet = new SnippetArticle( | 141 SnippetArticle longSnippet = new SnippetArticle(fullCategory, "id2", |
145 fullCategory, | |
146 "id2", | |
147 new String(new char[20]).replace("\0", "Snippet "), | 142 new String(new char[20]).replace("\0", "Snippet "), |
148 new String(new char[20]).replace("\0", "Publisher "), | 143 new String(new char[20]).replace("\0", "Publisher "), |
149 new String(new char[80]).replace("\0", "Preview Text "), | 144 new String(new char[80]).replace("\0", "Preview Text "), "www.go
ogle.com", |
150 "www.google.com", | 145 1466614074, // Timestamp |
151 1466614074, // Timestamp | 146 20f); // Score |
152 20f, // Score | |
153 1); // Position | |
154 | 147 |
155 SnippetArticle minimalSnippet = new SnippetArticle( | 148 SnippetArticle minimalSnippet = new SnippetArticle(minimalCategory, "id3
", |
156 minimalCategory, | 149 new String(new char[20]).replace("\0", "Bookmark "), "Publisher"
, |
157 "id3", | 150 "This should not be displayed", "www.google.com", |
158 new String(new char[20]).replace("\0", "Bookmark "), | 151 1466614774, // Timestamp |
159 "Publisher", | 152 10f); // Score |
160 "This should not be displayed", | |
161 "www.google.com", | |
162 1466614774, // Timestamp | |
163 10f, // Score | |
164 0); // Position | |
165 | 153 |
166 SnippetArticle minimalSnippet2 = new SnippetArticle( | 154 SnippetArticle minimalSnippet2 = new SnippetArticle(minimalCategory, "id
4", "Bookmark", |
167 minimalCategory, | 155 "Publisher", "This should not be displayed", "www.google.com", |
168 "id4", | 156 1466614774, // Timestamp |
169 "Bookmark", | 157 10f); // Score |
170 "Publisher", | |
171 "This should not be displayed", | |
172 "www.google.com", | |
173 1466614774, // Timestamp | |
174 10f, // Score | |
175 0); // Position | |
176 | 158 |
177 mSnippetsSource.setInfoForCategory( | 159 mSnippetsSource.setInfoForCategory( |
178 fullCategory, new SuggestionsCategoryInfo(fullCategory, "Section
Title", | 160 fullCategory, new SuggestionsCategoryInfo(fullCategory, "Section
Title", |
179 ContentSuggestionsCardLayout.FULL_CARD, fa
lse, false, false, | 161 ContentSuggestionsCardLayout.FULL_CARD, fa
lse, false, false, |
180 true, "No suggestions")); | 162 true, "No suggestions")); |
181 mSnippetsSource.setStatusForCategory(fullCategory, CategoryStatus.AVAILA
BLE); | 163 mSnippetsSource.setStatusForCategory(fullCategory, CategoryStatus.AVAILA
BLE); |
182 mSnippetsSource.setSuggestionsForCategory( | 164 mSnippetsSource.setSuggestionsForCategory( |
183 fullCategory, Arrays.asList(shortSnippet, longSnippet)); | 165 fullCategory, Arrays.asList(shortSnippet, longSnippet)); |
184 | 166 |
185 mSnippetsSource.setInfoForCategory( | 167 mSnippetsSource.setInfoForCategory( |
(...skipping 19 matching lines...) Expand all Loading... |
205 mSnippetsSource = new FakeSuggestionsSource(); | 187 mSnippetsSource = new FakeSuggestionsSource(); |
206 } | 188 } |
207 | 189 |
208 /** | 190 /** |
209 * A NewTabPageManager to initialize our Adapter. | 191 * A NewTabPageManager to initialize our Adapter. |
210 */ | 192 */ |
211 private class MockNewTabPageManager implements NewTabPageManager { | 193 private class MockNewTabPageManager implements NewTabPageManager { |
212 // TODO(dgn): provide a RecyclerView if we need to test the context menu
. | 194 // TODO(dgn): provide a RecyclerView if we need to test the context menu
. |
213 private ContextMenuManager mContextMenuManager = | 195 private ContextMenuManager mContextMenuManager = |
214 new ContextMenuManager(getActivity(), this, null); | 196 new ContextMenuManager(getActivity(), this, null); |
| 197 private SuggestionsMetricsReporter mSuggestionsMetricsReporter = |
| 198 new DummySuggestionsMetricsReporter(); |
215 | 199 |
216 @Override | 200 @Override |
217 public void getLocalFaviconImageForURL( | 201 public void getLocalFaviconImageForURL( |
218 final String url, int size, final FaviconImageCallback faviconCa
llback) { | 202 final String url, int size, final FaviconImageCallback faviconCa
llback) { |
219 // Run the callback asynchronously incase the caller made that assum
ption. | 203 // Run the callback asynchronously incase the caller made that assum
ption. |
220 ThreadUtils.postOnUiThread(new Runnable(){ | 204 ThreadUtils.postOnUiThread(new Runnable(){ |
221 @Override | 205 @Override |
222 public void run() { | 206 public void run() { |
223 // Return an arbitrary drawable. | 207 // Return an arbitrary drawable. |
224 faviconCallback.onFaviconAvailable( | 208 faviconCallback.onFaviconAvailable( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 public void navigateToBookmarks() { | 242 public void navigateToBookmarks() { |
259 throw new UnsupportedOperationException(); | 243 throw new UnsupportedOperationException(); |
260 } | 244 } |
261 | 245 |
262 @Override | 246 @Override |
263 public void navigateToRecentTabs() { | 247 public void navigateToRecentTabs() { |
264 throw new UnsupportedOperationException(); | 248 throw new UnsupportedOperationException(); |
265 } | 249 } |
266 | 250 |
267 @Override | 251 @Override |
268 public void trackSnippetsPageImpression(int[] categories, int[] suggesti
onsPerCategory) {} | 252 public void openSnippet(int windowOpenDisposition, SnippetArticle articl
e) { |
269 | |
270 @Override | |
271 public void trackSnippetImpression(SnippetArticle article) {} | |
272 | |
273 @Override | |
274 public void trackSnippetMenuOpened(SnippetArticle article) {} | |
275 | |
276 @Override | |
277 public void trackSnippetCategoryActionImpression(int category, int posit
ion) {} | |
278 | |
279 @Override | |
280 public void trackSnippetCategoryActionClick(int category, int position)
{} | |
281 | |
282 @Override | |
283 public void openSnippet( | |
284 int windowOpenDisposition, SnippetArticle article, int categoryI
ndex) { | |
285 throw new UnsupportedOperationException(); | 253 throw new UnsupportedOperationException(); |
286 } | 254 } |
287 | 255 |
288 @Override | 256 @Override |
289 public void focusSearchBox(boolean beginVoiceSearch, String pastedText)
{ | 257 public void focusSearchBox(boolean beginVoiceSearch, String pastedText)
{ |
290 throw new UnsupportedOperationException(); | 258 throw new UnsupportedOperationException(); |
291 } | 259 } |
292 | 260 |
293 @Override | 261 @Override |
294 public void setMostVisitedURLsObserver(MostVisitedURLsObserver observer,
int numResults) { | 262 public void setMostVisitedURLsObserver(MostVisitedURLsObserver observer,
int numResults) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 324 |
357 @Override | 325 @Override |
358 public boolean isCurrentPage() { | 326 public boolean isCurrentPage() { |
359 return true; | 327 return true; |
360 } | 328 } |
361 | 329 |
362 @Override | 330 @Override |
363 public ContextMenuManager getContextMenuManager() { | 331 public ContextMenuManager getContextMenuManager() { |
364 return mContextMenuManager; | 332 return mContextMenuManager; |
365 } | 333 } |
| 334 |
| 335 public SuggestionsMetricsReporter getSuggestionsMetricsReporter() { |
| 336 return mSuggestionsMetricsReporter; |
| 337 } |
| 338 } |
| 339 |
| 340 private static class DummySuggestionsMetricsReporter implements SuggestionsM
etricsReporter { |
| 341 @Override |
| 342 public void onPageShown(int[] categories, int[] suggestionsPerCategory)
{} |
| 343 |
| 344 @Override |
| 345 public void onSuggestionShown(SnippetArticle suggestion) {} |
| 346 |
| 347 @Override |
| 348 public void onSuggestionOpened(SnippetArticle suggestion, int windowOpen
Disposition) {} |
| 349 |
| 350 @Override |
| 351 public void onSuggestionMenuOpened(SnippetArticle suggestion) {} |
| 352 |
| 353 @Override |
| 354 public void onMoreButtonShown(@CategoryInt ActionItem category) {} |
| 355 |
| 356 @Override |
| 357 public void onMoreButtonClicked(@CategoryInt ActionItem category) {} |
| 358 |
| 359 @Override |
| 360 public void setRanker(SuggestionsRanker suggestionsRanker) {} |
366 } | 361 } |
367 } | 362 } |
OLD | NEW |