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

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

Issue 2846123002: 📰 Consider hidden categories when checking staleness (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SectionList.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/SectionListTest.java
diff --git a/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/SectionListTest.java b/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/SectionListTest.java
index e7ee137d8521d29c3bfe4512bc53df40ec3d9cb1..f6b74fa701e3ccec15cba8fb57ff839c14d5e9bd 100644
--- a/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/SectionListTest.java
+++ b/chrome/android/junit/src/org/chromium/chrome/browser/ntp/cards/SectionListTest.java
@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.ntp.cards;
import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
@@ -38,6 +39,7 @@
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.DisableHistogramsRule;
import org.chromium.chrome.browser.ntp.snippets.CategoryInt;
+import org.chromium.chrome.browser.ntp.snippets.CategoryStatus;
import org.chromium.chrome.browser.ntp.snippets.KnownCategories;
import org.chromium.chrome.browser.ntp.snippets.SnippetArticle;
import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
@@ -392,4 +394,57 @@ public void testSynchroniseWithSourceWithChangedCategories() {
inOrder.verify(mSuggestionSource).getSuggestionsForCategory(CATEGORY1);
inOrder.verify(mSuggestionSource).getSuggestionsForCategory(CATEGORY2);
}
+
+ @Test
+ public void testCategoryChangeWithSameCategories() {
+ registerCategory(mSuggestionSource, CATEGORY1, 1);
+ registerCategory(mSuggestionSource, CATEGORY2, 1);
+
+ SectionList sectionList = spy(new SectionList(mUiDelegate, mOfflinePageBridge));
+ sectionList.refreshSuggestions();
+
+ assertFalse(sectionList.categoriesChanged(mSuggestionSource.getCategories()));
+ }
+
+ @Test
+ public void testCategoryChangeWithDifferentOrderOrNumberInCategories() {
+ registerCategory(mSuggestionSource, CATEGORY1, 1);
+ registerCategory(mSuggestionSource, CATEGORY2, 1);
+
+ SectionList sectionList = spy(new SectionList(mUiDelegate, mOfflinePageBridge));
+ sectionList.refreshSuggestions();
+
+ // Not using the same categories as present in the source here, change should be detected.
+ assertTrue(sectionList.categoriesChanged(new int[] {CATEGORY2, CATEGORY1}));
+ assertTrue(sectionList.categoriesChanged(new int[] {CATEGORY1}));
+ assertTrue(sectionList.categoriesChanged(new int[] {CATEGORY1, CATEGORY2, CATEGORY2 + 1}));
+ }
+
+ @Test
+ public void testCategoryChangeWithEmptyHiddenCategory() {
+ registerCategory(mSuggestionSource, CATEGORY1, 1);
+ registerCategory(mSuggestionSource, new CategoryInfoBuilder(CATEGORY2).build(), 0);
+
+ SectionList sectionList = spy(new SectionList(mUiDelegate, mOfflinePageBridge));
+ sectionList.refreshSuggestions();
+
+ // The check here ignores |CATEGORY2| which is present during the construction but not shown
+ // because empty. It does not detect changes whether the reference array includes it or not.
+ assertThat(
+ mSuggestionSource.getCategories(), is(equalTo(new int[] {CATEGORY1, CATEGORY2})));
+ assertFalse(sectionList.categoriesChanged(mSuggestionSource.getCategories()));
+ assertFalse(sectionList.categoriesChanged(new int[] {CATEGORY1}));
+
+ mSuggestionSource.setStatusForCategory(CATEGORY2, CategoryStatus.AVAILABLE_LOADING);
+
+ // After notifying of a change for the category, it stops being ignored.
+ assertTrue(sectionList.categoriesChanged(mSuggestionSource.getCategories()));
+ assertFalse(sectionList.categoriesChanged(new int[] {CATEGORY1}));
+
+ sectionList.refreshSuggestions();
+
+ // And after a refresh we start ignoring it again.
+ assertFalse(sectionList.categoriesChanged(mSuggestionSource.getCategories()));
+ assertFalse(sectionList.categoriesChanged(new int[] {CATEGORY1}));
+ }
}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SectionList.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698