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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/suggestions/FakeMostVisitedSites.java

Issue 2754203004: 📰 Add tests for context menu usage (Closed)
Patch Set: y 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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.suggestions; 5 package org.chromium.chrome.browser.suggestions;
6 6
7 import org.chromium.base.ThreadUtils; 7 import org.chromium.base.ThreadUtils;
8 import org.chromium.chrome.browser.profiles.Profile; 8 import org.chromium.chrome.browser.ntp.NTPTileSource;
9 9
10 import java.util.ArrayList; 10 import java.util.ArrayList;
11 import java.util.Arrays;
11 import java.util.List; 12 import java.util.List;
12 13
13 /** 14 /**
14 * A fake implementation of MostVisitedSites that returns a fixed list of most v isited sites. 15 * A fake implementation of MostVisitedSites that returns a fixed list of most v isited sites.
15 */ 16 */
16 public class FakeMostVisitedSites extends MostVisitedSites { 17 public class FakeMostVisitedSites implements MostVisitedSites {
17 private final List<String> mBlacklistedUrls = new ArrayList<>(); 18 private final List<String> mBlacklistedUrls = new ArrayList<>();
18 19
19 private String[] mTitles = new String[] {}; 20 private String[] mTitles = new String[] {};
20 private String[] mUrls = new String[] {}; 21 private String[] mUrls = new String[] {};
21 private String[] mWhitelistIconPaths = new String[] {}; 22 private String[] mWhitelistIconPaths = new String[] {};
22 private int[] mSources = new int[] {}; 23 private int[] mSources = new int[] {};
23 private Observer mObserver; 24 private Observer mObserver;
24 25
25 /** 26 @Override
26 * @param profile The profile for which to fetch site suggestions. 27 public void destroy() {}
27 */
28 public FakeMostVisitedSites(Profile profile) {
29 // TODO(mvanouwerkerk): Do not let the fake inherit from the real implem entation.
30 super(profile);
31 }
32 28
33 @Override 29 @Override
34 public void setObserver(Observer observer, int numResults) { 30 public void setObserver(Observer observer, int numResults) {
35 mObserver = observer; 31 mObserver = observer;
36 notifyTileSuggestionsAvailable(); 32 notifyTileSuggestionsAvailable();
37 } 33 }
38 34
39 @Override 35 @Override
40 public void addBlacklistedUrl(String url) { 36 public void addBlacklistedUrl(String url) {
41 mBlacklistedUrls.add(url); 37 mBlacklistedUrls.add(url);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 public void setTileSuggestions( 70 public void setTileSuggestions(
75 String[] titles, String[] urls, String[] whitelistIconPaths, int[] s ources) { 71 String[] titles, String[] urls, String[] whitelistIconPaths, int[] s ources) {
76 assert titles.length == urls.length; 72 assert titles.length == urls.length;
77 mTitles = titles.clone(); 73 mTitles = titles.clone();
78 mUrls = urls.clone(); 74 mUrls = urls.clone();
79 mWhitelistIconPaths = whitelistIconPaths.clone(); 75 mWhitelistIconPaths = whitelistIconPaths.clone();
80 mSources = sources.clone(); 76 mSources = sources.clone();
81 notifyTileSuggestionsAvailable(); 77 notifyTileSuggestionsAvailable();
82 } 78 }
83 79
80 /**
81 * Sets new tile suggestion data, generating dummy data for the missing prop erties.
82 * If there is an observer it is notified.
83 *
84 * @param urls The URLs of the site suggestions.
85 * @see #setTileSuggestions(String[], String[], String[], int[])
86 */
87 public void setTileSuggestions(String... urls) {
88 String[] whitelistIconPaths = new String[urls.length];
89 Arrays.fill(whitelistIconPaths, "");
90
91 int[] sources = new int[urls.length];
92 Arrays.fill(sources, NTPTileSource.TOP_SITES);
93
94 setTileSuggestions(urls, urls.clone(), whitelistIconPaths, sources);
95 }
96
84 private void notifyTileSuggestionsAvailable() { 97 private void notifyTileSuggestionsAvailable() {
85 if (mObserver == null) return; 98 if (mObserver == null) return;
86 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 99 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
87 @Override 100 @Override
88 public void run() { 101 public void run() {
89 mObserver.onMostVisitedURLsAvailable(mTitles.clone(), mUrls.clon e(), 102 mObserver.onMostVisitedURLsAvailable(mTitles.clone(), mUrls.clon e(),
90 mWhitelistIconPaths.clone(), mSources.clone()); 103 mWhitelistIconPaths.clone(), mSources.clone());
91 } 104 }
92 }); 105 });
93 } 106 }
94 } 107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698