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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/suggestions/SuggestionsBottomSheetContent.java

Issue 2670863004: 🏠 Add instrumentation test for Suggestions BottomSheet (Closed)
Patch Set: Wait for recyclerview to stabilise and check view type Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/suggestions/SuggestionsBottomSheetContent.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/suggestions/SuggestionsBottomSheetContent.java b/chrome/android/java/src/org/chromium/chrome/browser/suggestions/SuggestionsBottomSheetContent.java
index 3c4c706c015df59358a52fc4b6b38cd139f27143..10aec24a84d9ae5bd8465dc7c7d4abad6bb1c35d 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/suggestions/SuggestionsBottomSheetContent.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/suggestions/SuggestionsBottomSheetContent.java
@@ -15,6 +15,7 @@
import org.chromium.chrome.browser.ntp.cards.NewTabPageAdapter;
import org.chromium.chrome.browser.ntp.cards.NewTabPageRecyclerView;
import org.chromium.chrome.browser.ntp.snippets.SnippetsBridge;
+import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource;
import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.Tab;
@@ -29,26 +30,26 @@
* notified of it, at least when it is pulled up on the new tab.
*/
public class SuggestionsBottomSheetContent implements BottomSheet.BottomSheetContent {
+ private static SuggestionsSource sSuggestionsSourceForTesting;
+ private static SuggestionsMetricsReporter sMetricsReporterForTesting;
+
private final NewTabPageRecyclerView mRecyclerView;
private final ContextMenuManager mContextMenuManager;
private final SuggestionsUiDelegateImpl mSuggestionsManager;
- private final SnippetsBridge mSnippetsBridge;
private final TileGroup.Delegate mTileGroupDelegate;
public SuggestionsBottomSheetContent(
final ChromeActivity activity, Tab tab, TabModelSelector tabModelSelector) {
- mRecyclerView = (NewTabPageRecyclerView) LayoutInflater.from(activity).inflate(
- R.layout.new_tab_page_recycler_view, null, false);
Profile profile = Profile.getLastUsedProfile();
- UiConfig uiConfig = new UiConfig(mRecyclerView);
-
- mSnippetsBridge = new SnippetsBridge(profile);
SuggestionsNavigationDelegate navigationDelegate =
new SuggestionsNavigationDelegateImpl(activity, profile, tab, tabModelSelector);
+ mTileGroupDelegate =
+ new TileGroupDelegateImpl(activity, tab, tabModelSelector, navigationDelegate);
+ mSuggestionsManager = createSuggestionsDelegate(profile, navigationDelegate, tab);
- mSuggestionsManager = new SuggestionsUiDelegateImpl(
- mSnippetsBridge, mSnippetsBridge, navigationDelegate, profile, tab);
+ mRecyclerView = (NewTabPageRecyclerView) LayoutInflater.from(activity).inflate(
+ R.layout.new_tab_page_recycler_view, null, false);
mContextMenuManager = new ContextMenuManager(activity, navigationDelegate, mRecyclerView);
activity.getWindowAndroid().addContextMenuCloseListener(mContextMenuManager);
@@ -59,8 +60,7 @@ public void onDestroy() {
}
});
- mTileGroupDelegate =
- new TileGroupDelegateImpl(activity, tab, tabModelSelector, navigationDelegate);
+ UiConfig uiConfig = new UiConfig(mRecyclerView);
NewTabPageAdapter adapter = new NewTabPageAdapter(mSuggestionsManager,
/* aboveTheFoldView = */ null, uiConfig, OfflinePageBridge.getForProfile(profile),
@@ -84,8 +84,42 @@ public ContextMenuManager getContextMenuManager() {
}
public void destroy() {
- mSnippetsBridge.destroy();
mSuggestionsManager.onDestroy();
mTileGroupDelegate.destroy();
}
+
+ public static void setSuggestionsSourceForTesting(SuggestionsSource suggestionsSource) {
+ sSuggestionsSourceForTesting = suggestionsSource;
+ }
+
+ public static void setMetricsReporterForTesting(SuggestionsMetricsReporter metricsReporter) {
+ sMetricsReporterForTesting = metricsReporter;
+ }
+
+ private static SuggestionsUiDelegateImpl createSuggestionsDelegate(
dgn 2017/02/06 16:51:22 not really happy about this bit... the main issue
+ Profile profile, SuggestionsNavigationDelegate navigationDelegate, Tab tab) {
+ SnippetsBridge snippetsBridge = null;
+ SuggestionsSource suggestionsSource;
+ SuggestionsMetricsReporter metricsReporter;
+
+ if (sSuggestionsSourceForTesting == null) {
+ snippetsBridge = new SnippetsBridge(profile);
+ suggestionsSource = snippetsBridge;
+ } else {
+ suggestionsSource = sSuggestionsSourceForTesting;
+ }
+
+ if (sMetricsReporterForTesting == null) {
+ if (snippetsBridge == null) snippetsBridge = new SnippetsBridge(profile);
+ metricsReporter = snippetsBridge;
+ } else {
+ metricsReporter = sMetricsReporterForTesting;
+ }
+
+ SuggestionsUiDelegateImpl delegate = new SuggestionsUiDelegateImpl(
+ suggestionsSource, metricsReporter, navigationDelegate, profile, tab);
+ if (snippetsBridge != null) delegate.addDestructionObserver(snippetsBridge);
+
+ return delegate;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698