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

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

Issue 2640443003: 📰 Use first seen position in suggestion UMA (Closed)
Patch Set: rebase 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/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 452238ffd3a4d5c17d800c7f682cafb976718005..a477c2ca1c4de3d2833c688638a83bf3389f96a4 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
@@ -85,12 +85,51 @@ public void testGetSuggestionRank() {
SectionList sectionList = new SectionList(mNtpManager, mOfflinePageBridge);
+ bindViewHolders(sectionList);
+
assertThat(articles.get(0).getGlobalRank(), equalTo(0));
assertThat(articles.get(0).getPerSectionRank(), equalTo(0));
assertThat(articles.get(2).getGlobalRank(), equalTo(2));
assertThat(articles.get(2).getPerSectionRank(), equalTo(2));
assertThat(bookmarks.get(1).getGlobalRank(), equalTo(4));
assertThat(bookmarks.get(1).getPerSectionRank(), equalTo(1));
+ }
+
+ @Test
+ @Feature({"Ntp"})
+ public void testGetSuggestionRankWithChanges() {
+ // Setup the section list the following way:
+ //
+ // Item type | local rank | global rank
+ // -----------+------------+-------------
+ // HEADER | |
+ // ARTICLE | 0 | 0
+ // ARTICLE | 1 | 1
+ // ARTICLE | 2 | 2
+ // HEADER | |
+ // STATUS | |
+ // ACTION | 0 |
+ // BOOKMARK | 0 | 3
+ // BOOKMARK | 1 | 4
+ // BOOKMARK | 2 | 5
+ // BOOKMARK | 3 | 6
+ List<SnippetArticle> articles =
+ registerCategory(mSuggestionSource, KnownCategories.ARTICLES, 3);
+ registerCategory(mSuggestionSource, KnownCategories.DOWNLOADS, 0);
+ List<SnippetArticle> bookmarks =
+ registerCategory(mSuggestionSource, KnownCategories.BOOKMARKS, 4);
+
+ SectionList sectionList = new SectionList(mNtpManager, mOfflinePageBridge);
+
+ bindViewHolders(sectionList, 0, 5); // Bind until after the third article.
+
+ assertThat(articles.get(0).getGlobalRank(), equalTo(0));
+ assertThat(articles.get(0).getPerSectionRank(), equalTo(0));
+ assertThat(articles.get(2).getGlobalRank(), equalTo(2));
+ assertThat(articles.get(2).getPerSectionRank(), equalTo(2));
+ assertThat(bookmarks.get(1).getGlobalRank(), equalTo(-1)); // Not bound nor ranked yet.
+ assertThat(bookmarks.get(1).getPerSectionRank(), equalTo(-1));
+
// Test ranks after changes: remove then add some items.
@SuppressWarnings("unchecked")
@@ -103,9 +142,11 @@ public void testGetSuggestionRank() {
List<SnippetArticle> newBookmarks =
createDummySuggestions(6, KnownCategories.BOOKMARKS).subList(4, 6);
- sectionList.onMoreSuggestions(KnownCategories.ARTICLES, newArticles);
+ sectionList.onMoreSuggestions(KnownCategories.ARTICLES, newArticles.subList(0, 1));
sectionList.onMoreSuggestions(KnownCategories.BOOKMARKS, newBookmarks);
+ bindViewHolders(sectionList, 3, sectionList.getItemCount());
+
// After the changes we should have:
// Item type | local rank | global rank
// -----------+------------+-------------
@@ -113,31 +154,62 @@ public void testGetSuggestionRank() {
// ARTICLE | 0 | 0
// ARTICLE | 1 | 1
// | - | - (deleted)
- // ARTICLE | 3 | 7 (new)
- // ARTICLE | 4 | 8 (new)
+ // ARTICLE | 3 | 3 (new)
// HEADER | |
// STATUS | |
// ACTION | 0 |
- // BOOKMARK | 0 | 3
- // BOOKMARK | 1 | 4
- // BOOKMARK | 2 | 5
- // BOOKMARK | 3 | 6
- // BOOKMARK | 4 | 9 (new)
- // BOOKMARK | 5 | 10 (new)
+ // BOOKMARK | 0 | 4 (old but not seen until now)
+ // BOOKMARK | 1 | 5 (old but not seen until now)
+ // BOOKMARK | 2 | 6 (old but not seen until now)
+ // BOOKMARK | 3 | 7 (old but not seen until now)
+ // BOOKMARK | 4 | 8 (new)
+ // BOOKMARK | 5 | 9 (new)
+
+
+ // The new article is seen first and gets the next global rank
+ assertThat(newArticles.get(0).getGlobalRank(), equalTo(3));
+ assertThat(newArticles.get(0).getPerSectionRank(), equalTo(3));
+
+ // Bookmarks old and new are seen after the new article and have higher global ranks
+ assertThat(bookmarks.get(1).getGlobalRank(), equalTo(5));
+ assertThat(bookmarks.get(1).getPerSectionRank(), equalTo(1));
+ assertThat(newBookmarks.get(1).getGlobalRank(), equalTo(9));
+ assertThat(newBookmarks.get(1).getPerSectionRank(), equalTo(5));
- // The old ranks should not change.
+ // Add one more article
+ sectionList.onMoreSuggestions(KnownCategories.ARTICLES, newArticles.subList(1, 2));
+ bindViewHolders(sectionList);
+
+ // After the changes we should have:
+ // Item type | local rank | global rank
+ // -----------+------------+-------------
+ // HEADER | |
+ // ARTICLE | 0 | 0
+ // ARTICLE | 1 | 1
+ // | - | - (deleted)
+ // ARTICLE | 3 | 3
+ // ARTICLE | 4 | 10 (new)
+ // HEADER | |
+ // STATUS | |
+ // ACTION | 0 |
+ // BOOKMARK | 0 | 4
+ // BOOKMARK | 1 | 5
+ // BOOKMARK | 2 | 6
+ // BOOKMARK | 3 | 7
+ // BOOKMARK | 4 | 8
+ // BOOKMARK | 5 | 9
+
+ // Old suggestions' ranks should not change.
assertThat(articles.get(0).getGlobalRank(), equalTo(0));
assertThat(articles.get(0).getPerSectionRank(), equalTo(0));
assertThat(articles.get(2).getGlobalRank(), equalTo(2));
assertThat(articles.get(2).getPerSectionRank(), equalTo(2));
- assertThat(bookmarks.get(1).getGlobalRank(), equalTo(4));
+ assertThat(bookmarks.get(1).getGlobalRank(), equalTo(5));
assertThat(bookmarks.get(1).getPerSectionRank(), equalTo(1));
- // New ranks take into account the previously existing items.
- assertThat(newArticles.get(1).getGlobalRank(), equalTo(8));
+ // The new article should get the last global rank
+ assertThat(newArticles.get(1).getGlobalRank(), equalTo(10));
assertThat(newArticles.get(1).getPerSectionRank(), equalTo(4));
- assertThat(newBookmarks.get(1).getGlobalRank(), equalTo(10));
- assertThat(newBookmarks.get(1).getPerSectionRank(), equalTo(5));
}
@Test

Powered by Google App Engine
This is Rietveld 408576698