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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/ntp/snippets/ArticleSnippetsTest.java

Issue 2865963003: [Suggestions UI] Drop Bitmap references from articles under memory pressure. (Closed)
Patch Set: remove annotation Created 3 years, 7 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.browser.ntp.snippets; 5 package org.chromium.chrome.browser.ntp.snippets;
6 6
7 import android.graphics.Bitmap;
7 import android.graphics.BitmapFactory; 8 import android.graphics.BitmapFactory;
8 import android.support.test.InstrumentationRegistry; 9 import android.support.test.InstrumentationRegistry;
9 import android.support.test.filters.MediumTest; 10 import android.support.test.filters.MediumTest;
10 import android.util.TypedValue; 11 import android.util.TypedValue;
11 import android.view.ViewGroup; 12 import android.view.ViewGroup;
12 import android.widget.FrameLayout; 13 import android.widget.FrameLayout;
13 14
14 import org.junit.Before; 15 import org.junit.Before;
15 import org.junit.Rule; 16 import org.junit.Rule;
16 import org.junit.Test; 17 import org.junit.Test;
17 import org.junit.runner.RunWith; 18 import org.junit.runner.RunWith;
18 19
20 import org.chromium.base.DiscardableReferencePool;
19 import org.chromium.base.ThreadUtils; 21 import org.chromium.base.ThreadUtils;
20 import org.chromium.base.test.util.CommandLineFlags; 22 import org.chromium.base.test.util.CommandLineFlags;
21 import org.chromium.base.test.util.Feature; 23 import org.chromium.base.test.util.Feature;
22 import org.chromium.base.test.util.RetryOnFailure; 24 import org.chromium.base.test.util.RetryOnFailure;
23 import org.chromium.chrome.R; 25 import org.chromium.chrome.R;
24 import org.chromium.chrome.browser.ChromeActivity; 26 import org.chromium.chrome.browser.ChromeActivity;
25 import org.chromium.chrome.browser.ChromeSwitches; 27 import org.chromium.chrome.browser.ChromeSwitches;
26 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; 28 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback;
27 import org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallbac k; 29 import org.chromium.chrome.browser.favicon.FaviconHelper.IconAvailabilityCallbac k;
28 import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback; 30 import org.chromium.chrome.browser.favicon.LargeIconBridge.LargeIconCallback;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 private void setupTestData() { 141 private void setupTestData() {
140 @CategoryInt 142 @CategoryInt
141 int fullCategory = 0; 143 int fullCategory = 0;
142 @CategoryInt 144 @CategoryInt
143 int minimalCategory = 1; 145 int minimalCategory = 1;
144 SnippetArticle shortSnippet = new SnippetArticle(fullCategory, "id1", "S nippet", 146 SnippetArticle shortSnippet = new SnippetArticle(fullCategory, "id1", "S nippet",
145 "Publisher", "Preview Text", "www.google.com", 147 "Publisher", "Preview Text", "www.google.com",
146 1466614774, // Publish timestamp 148 1466614774, // Publish timestamp
147 10f, // Score 149 10f, // Score
148 1466634774); // Fetch timestamp 150 1466634774); // Fetch timestamp
149 shortSnippet.setThumbnailBitmap( 151
152 Bitmap thumbnail =
150 BitmapFactory.decodeResource(mActivityTestRule.getActivity().get Resources(), 153 BitmapFactory.decodeResource(mActivityTestRule.getActivity().get Resources(),
151 R.drawable.signin_promo_illustration)); 154 R.drawable.signin_promo_illustration);
155 shortSnippet.setThumbnailBitmap(mUiDelegate.getReferencePool().put(thumb nail));
152 156
153 SnippetArticle longSnippet = new SnippetArticle(fullCategory, "id2", 157 SnippetArticle longSnippet = new SnippetArticle(fullCategory, "id2",
154 new String(new char[20]).replace("\0", "Snippet "), 158 new String(new char[20]).replace("\0", "Snippet "),
155 new String(new char[20]).replace("\0", "Publisher "), 159 new String(new char[20]).replace("\0", "Publisher "),
156 new String(new char[80]).replace("\0", "Preview Text "), "www.go ogle.com", 160 new String(new char[80]).replace("\0", "Preview Text "), "www.go ogle.com",
157 1466614074, // Publish timestamp 161 1466614074, // Publish timestamp
158 20f, // Score 162 20f, // Score
159 1466634774); // Fetch timestamp 163 1466634774); // Fetch timestamp
160 164
161 SnippetArticle minimalSnippet = new SnippetArticle(minimalCategory, "id3 ", 165 SnippetArticle minimalSnippet = new SnippetArticle(minimalCategory, "id3 ",
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 mSnippetsSource = new FakeSuggestionsSource(); 203 mSnippetsSource = new FakeSuggestionsSource();
200 } 204 }
201 205
202 /** 206 /**
203 * A SuggestionsUiDelegate to initialize our Adapter. 207 * A SuggestionsUiDelegate to initialize our Adapter.
204 */ 208 */
205 private class MockUiDelegate implements SuggestionsUiDelegate { 209 private class MockUiDelegate implements SuggestionsUiDelegate {
206 private SuggestionsEventReporter mSuggestionsEventReporter = 210 private SuggestionsEventReporter mSuggestionsEventReporter =
207 new DummySuggestionsEventReporter(); 211 new DummySuggestionsEventReporter();
208 private SuggestionsRanker mSuggestionsRanker = new SuggestionsRanker(); 212 private SuggestionsRanker mSuggestionsRanker = new SuggestionsRanker();
213 private final DiscardableReferencePool mReferencePool = new DiscardableR eferencePool();
209 214
210 @Override 215 @Override
211 public void getLocalFaviconImageForURL( 216 public void getLocalFaviconImageForURL(
212 final String url, int size, final FaviconImageCallback faviconCa llback) { 217 final String url, int size, final FaviconImageCallback faviconCa llback) {
213 // Run the callback asynchronously incase the caller made that assum ption. 218 // Run the callback asynchronously incase the caller made that assum ption.
214 ThreadUtils.postOnUiThread(new Runnable(){ 219 ThreadUtils.postOnUiThread(new Runnable(){
215 @Override 220 @Override
216 public void run() { 221 public void run() {
217 // Return an arbitrary drawable. 222 // Return an arbitrary drawable.
218 faviconCallback.onFaviconAvailable( 223 faviconCallback.onFaviconAvailable(
(...skipping 20 matching lines...) Expand all
239 public SuggestionsSource getSuggestionsSource() { 244 public SuggestionsSource getSuggestionsSource() {
240 return mSnippetsSource; 245 return mSnippetsSource;
241 } 246 }
242 247
243 @Override 248 @Override
244 public SuggestionsRanker getSuggestionsRanker() { 249 public SuggestionsRanker getSuggestionsRanker() {
245 return mSuggestionsRanker; 250 return mSuggestionsRanker;
246 } 251 }
247 252
248 @Override 253 @Override
254 public DiscardableReferencePool getReferencePool() {
255 return mReferencePool;
256 }
257
258 @Override
249 public void addDestructionObserver(DestructionObserver destructionObserv er) {} 259 public void addDestructionObserver(DestructionObserver destructionObserv er) {}
250 260
251 @Override 261 @Override
252 public boolean isVisible() { 262 public boolean isVisible() {
253 return true; 263 return true;
254 } 264 }
255 265
256 @Override 266 @Override
257 public SuggestionsEventReporter getEventReporter() { 267 public SuggestionsEventReporter getEventReporter() {
258 return mSuggestionsEventReporter; 268 return mSuggestionsEventReporter;
259 } 269 }
260 270
261 @Override 271 @Override
262 public SuggestionsNavigationDelegate getNavigationDelegate() { 272 public SuggestionsNavigationDelegate getNavigationDelegate() {
263 return null; 273 return null;
264 } 274 }
265 } 275 }
266 276
267 } 277 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698