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

Unified Diff: chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/ContentSuggestionsTestUtils.java

Issue 2651743002: 📰 Fix card style when a neighbour is added or removed (Closed)
Patch Set: Revert to previous implementation Created 3 years, 11 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/junit/src/org/chromium/chrome/browser/ntp/cards/ContentSuggestionsTestUtils.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/ContentSuggestionsTestUtils.java b/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/ContentSuggestionsTestUtils.java
index b1fbb1839d41b19a4d75ea9dec3adf12708128dc..7ca06c3a1cfbbecce5f3f4a158c15da14f688ba8 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/ContentSuggestionsTestUtils.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/ContentSuggestionsTestUtils.java
@@ -18,6 +18,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
/** Utilities to make testing content suggestions code easier. */
public final class ContentSuggestionsTestUtils {
@@ -191,4 +192,41 @@ private static NewTabPageViewHolder makeViewHolder(@CategoryInt int viewType) {
return mock(NewTabPageViewHolder.class);
}
}
+
+ /** Helper method to print the current state of a node. */
+ public static String stringify(TreeNode root) {
+ return explainFailedExpectation(root, -1, ItemViewType.ALL_DISMISSED);
+ }
+
+ /**
+ * Helper method to print the current state of a node, highlighting something that went wrong.
+ * @param root node to print information about.
+ * @param errorIndex index where an unexpected item was found.
+ * @param expectedType item type that was expected at {@code errorIndex}.
+ */
+ public static String explainFailedExpectation(
+ TreeNode root, int errorIndex, @ItemViewType int expectedType) {
+ StringBuilder stringBuilder = new StringBuilder();
+
+ stringBuilder.append("explainFailedExpectation -- START -- \n");
+ for (int i = 0; i < root.getItemCount(); ++i) {
+ if (errorIndex == i) {
+ addLine(stringBuilder, "%d - %s <= expected: %s", i,
+ viewTypeToString(root.getItemViewType(i)), viewTypeToString(expectedType));
+ } else {
+ addLine(stringBuilder, "%d - %s", i, viewTypeToString(root.getItemViewType(i)));
+ }
+ }
+ if (errorIndex >= root.getItemCount()) {
+ addLine(stringBuilder, "<end of list>");
+ addLine(stringBuilder, "%d - <NONE> <= expected: %s", errorIndex,
+ viewTypeToString(expectedType));
+ }
+ addLine(stringBuilder, "explainFailedExpectation -- END --");
+ return stringBuilder.toString();
+ }
+
+ private static void addLine(StringBuilder stringBuilder, String template, Object... args) {
+ stringBuilder.append(String.format(Locale.US, template + "\n", args));
+ }
}

Powered by Google App Engine
This is Rietveld 408576698