| 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.test.util.browser.suggestions; | 5 package org.chromium.chrome.test.util.browser.suggestions; |
| 6 | 6 |
| 7 import org.chromium.chrome.browser.ntp.cards.ItemViewType; | 7 import org.chromium.chrome.browser.ntp.cards.ItemViewType; |
| 8 import org.chromium.chrome.browser.ntp.cards.SuggestionsCategoryInfo; | 8 import org.chromium.chrome.browser.ntp.cards.SuggestionsCategoryInfo; |
| 9 import org.chromium.chrome.browser.ntp.cards.TreeNode; | 9 import org.chromium.chrome.browser.ntp.cards.TreeNode; |
| 10 import org.chromium.chrome.browser.ntp.snippets.CategoryInt; | 10 import org.chromium.chrome.browser.ntp.snippets.CategoryInt; |
| 11 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus; | 11 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus; |
| 12 import org.chromium.chrome.browser.ntp.snippets.ContentSuggestionsCardLayout; | 12 import org.chromium.chrome.browser.ntp.snippets.ContentSuggestionsCardLayout; |
| 13 import org.chromium.chrome.browser.ntp.snippets.ContentSuggestionsCardLayout.Con
tentSuggestionsCardLayoutEnum; | |
| 14 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; | 13 import org.chromium.chrome.browser.ntp.snippets.SnippetArticle; |
| 15 import org.chromium.chrome.browser.suggestions.ContentSuggestionsAdditionalActio
n; | 14 import org.chromium.chrome.browser.suggestions.ContentSuggestionsAdditionalActio
n; |
| 16 import org.chromium.chrome.browser.suggestions.ContentSuggestionsAdditionalActio
n.ContentSuggestionsAdditionalActionEnum; | |
| 17 | 15 |
| 18 import java.util.ArrayList; | 16 import java.util.ArrayList; |
| 19 import java.util.List; | 17 import java.util.List; |
| 20 import java.util.Locale; | 18 import java.util.Locale; |
| 21 | 19 |
| 22 /** Utilities to make testing content suggestions code easier. */ | 20 /** Utilities to make testing content suggestions code easier. */ |
| 23 public final class ContentSuggestionsTestUtils { | 21 public final class ContentSuggestionsTestUtils { |
| 24 private ContentSuggestionsTestUtils() {} | 22 private ContentSuggestionsTestUtils() {} |
| 25 | 23 |
| 26 public static List<SnippetArticle> createDummySuggestions( | 24 public static List<SnippetArticle> createDummySuggestions( |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 /** | 99 /** |
| 102 * Uses the builder pattern to simplify constructing category info objects f
or tests. | 100 * Uses the builder pattern to simplify constructing category info objects f
or tests. |
| 103 */ | 101 */ |
| 104 public static class CategoryInfoBuilder { | 102 public static class CategoryInfoBuilder { |
| 105 @CategoryInt | 103 @CategoryInt |
| 106 private final int mCategory; | 104 private final int mCategory; |
| 107 private int mAdditionalAction; | 105 private int mAdditionalAction; |
| 108 private boolean mShowIfEmpty; | 106 private boolean mShowIfEmpty; |
| 109 private String mTitle = ""; | 107 private String mTitle = ""; |
| 110 private String mNoSuggestionsMessage = ""; | 108 private String mNoSuggestionsMessage = ""; |
| 111 @ContentSuggestionsCardLayoutEnum | 109 @ContentSuggestionsCardLayout |
| 112 private int mCardLayout = ContentSuggestionsCardLayout.FULL_CARD; | 110 private int mCardLayout = ContentSuggestionsCardLayout.FULL_CARD; |
| 113 | 111 |
| 114 public CategoryInfoBuilder(@CategoryInt int category) { | 112 public CategoryInfoBuilder(@CategoryInt int category) { |
| 115 mCategory = category; | 113 mCategory = category; |
| 116 } | 114 } |
| 117 | 115 |
| 118 public CategoryInfoBuilder withAction(@ContentSuggestionsAdditionalActio
nEnum int action) { | 116 public CategoryInfoBuilder withAction(@ContentSuggestionsAdditionalActio
n int action) { |
| 119 mAdditionalAction = action; | 117 mAdditionalAction = action; |
| 120 return this; | 118 return this; |
| 121 } | 119 } |
| 122 public CategoryInfoBuilder showIfEmpty() { | 120 public CategoryInfoBuilder showIfEmpty() { |
| 123 mShowIfEmpty = true; | 121 mShowIfEmpty = true; |
| 124 return this; | 122 return this; |
| 125 } | 123 } |
| 126 | 124 |
| 127 public CategoryInfoBuilder withTitle(String title) { | 125 public CategoryInfoBuilder withTitle(String title) { |
| 128 mTitle = title; | 126 mTitle = title; |
| 129 return this; | 127 return this; |
| 130 } | 128 } |
| 131 | 129 |
| 132 public CategoryInfoBuilder withNoSuggestionsMessage(String message) { | 130 public CategoryInfoBuilder withNoSuggestionsMessage(String message) { |
| 133 mNoSuggestionsMessage = message; | 131 mNoSuggestionsMessage = message; |
| 134 return this; | 132 return this; |
| 135 } | 133 } |
| 136 | 134 |
| 137 public CategoryInfoBuilder withCardLayout( | 135 public CategoryInfoBuilder withCardLayout(@ContentSuggestionsCardLayout
int cardLayout) { |
| 138 @ContentSuggestionsCardLayoutEnum int cardLayout) { | |
| 139 mCardLayout = cardLayout; | 136 mCardLayout = cardLayout; |
| 140 return this; | 137 return this; |
| 141 } | 138 } |
| 142 | 139 |
| 143 public SuggestionsCategoryInfo build() { | 140 public SuggestionsCategoryInfo build() { |
| 144 return new SuggestionsCategoryInfo(mCategory, mTitle, mCardLayout, m
AdditionalAction, | 141 return new SuggestionsCategoryInfo(mCategory, mTitle, mCardLayout, m
AdditionalAction, |
| 145 mShowIfEmpty, mNoSuggestionsMessage); | 142 mShowIfEmpty, mNoSuggestionsMessage); |
| 146 } | 143 } |
| 147 } | 144 } |
| 148 | 145 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 176 viewTypeToString(expectedType)); | 173 viewTypeToString(expectedType)); |
| 177 } | 174 } |
| 178 addLine(stringBuilder, "explainFailedExpectation -- END --"); | 175 addLine(stringBuilder, "explainFailedExpectation -- END --"); |
| 179 return stringBuilder.toString(); | 176 return stringBuilder.toString(); |
| 180 } | 177 } |
| 181 | 178 |
| 182 private static void addLine(StringBuilder stringBuilder, String template, Ob
ject... args) { | 179 private static void addLine(StringBuilder stringBuilder, String template, Ob
ject... args) { |
| 183 stringBuilder.append(String.format(Locale.US, template + "\n", args)); | 180 stringBuilder.append(String.format(Locale.US, template + "\n", args)); |
| 184 } | 181 } |
| 185 } | 182 } |
| OLD | NEW |