| 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.browser.ntp.cards; | 5 package org.chromium.chrome.browser.ntp.cards; |
| 6 | 6 |
| 7 import static org.hamcrest.Matchers.is; | 7 import static org.hamcrest.Matchers.is; |
| 8 import static org.hamcrest.collection.IsIterableContainingInOrder.contains; | 8 import static org.hamcrest.collection.IsIterableContainingInOrder.contains; |
| 9 import static org.junit.Assert.assertEquals; | 9 import static org.junit.Assert.assertEquals; |
| 10 import static org.junit.Assert.assertFalse; | 10 import static org.junit.Assert.assertFalse; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 // With snippets. | 111 // With snippets. |
| 112 section.setSuggestions(snippets, CategoryStatus.AVAILABLE, /* replaceExi
sting = */ true); | 112 section.setSuggestions(snippets, CategoryStatus.AVAILABLE, /* replaceExi
sting = */ true); |
| 113 assertEquals(ItemViewType.HEADER, section.getItemViewType(0)); | 113 assertEquals(ItemViewType.HEADER, section.getItemViewType(0)); |
| 114 assertEquals(Collections.emptySet(), section.getItemDismissalGroup(0)); | 114 assertEquals(Collections.emptySet(), section.getItemDismissalGroup(0)); |
| 115 assertEquals(ItemViewType.SNIPPET, section.getItemViewType(1)); | 115 assertEquals(ItemViewType.SNIPPET, section.getItemViewType(1)); |
| 116 assertEquals(Collections.singleton(1), section.getItemDismissalGroup(1))
; | 116 assertEquals(Collections.singleton(1), section.getItemDismissalGroup(1))
; |
| 117 } | 117 } |
| 118 | 118 |
| 119 @Test | 119 @Test |
| 120 @Feature({"Ntp"}) | 120 @Feature({"Ntp"}) |
| 121 public void testGetDismissalGroupWithoutHeader() { |
| 122 SuggestionsSection section = createSectionWithFetchAction(true); |
| 123 section.setHeaderVisibility(false); |
| 124 |
| 125 assertEquals(ItemViewType.STATUS, section.getItemViewType(0)); |
| 126 assertEquals(setOf(0, 1), section.getItemDismissalGroup(0)); |
| 127 |
| 128 assertEquals(ItemViewType.ACTION, section.getItemViewType(1)); |
| 129 assertEquals(setOf(0, 1), section.getItemDismissalGroup(1)); |
| 130 } |
| 131 |
| 132 @Test |
| 133 @Feature({"Ntp"}) |
| 134 public void testGetDismissalGroupWithoutAction() { |
| 135 SuggestionsSection section = createSectionWithFetchAction(false); |
| 136 |
| 137 assertEquals(ItemViewType.STATUS, section.getItemViewType(1)); |
| 138 assertEquals(Collections.singleton(1), section.getItemDismissalGroup(1))
; |
| 139 } |
| 140 |
| 141 @Test |
| 142 @Feature({"Ntp"}) |
| 143 public void testGetDismissalGroupActionAndHeader() { |
| 144 SuggestionsSection section = createSectionWithFetchAction(false); |
| 145 section.setHeaderVisibility(false); |
| 146 |
| 147 assertEquals(ItemViewType.STATUS, section.getItemViewType(0)); |
| 148 assertEquals(Collections.singleton(0), section.getItemDismissalGroup(0))
; |
| 149 } |
| 150 |
| 151 @Test |
| 152 @Feature({"Ntp"}) |
| 121 public void testAddSuggestionsNotification() { | 153 public void testAddSuggestionsNotification() { |
| 122 final int suggestionCount = 5; | 154 final int suggestionCount = 5; |
| 123 List<SnippetArticle> snippets = createDummySuggestions(suggestionCount, | 155 List<SnippetArticle> snippets = createDummySuggestions(suggestionCount, |
| 124 TEST_CATEGORY_ID); | 156 TEST_CATEGORY_ID); |
| 125 | 157 |
| 126 SuggestionsSection section = createSectionWithFetchAction(false); | 158 SuggestionsSection section = createSectionWithFetchAction(false); |
| 127 // Simulate initialisation by the adapter. Here we don't care about the
notifications, since | 159 // Simulate initialisation by the adapter. Here we don't care about the
notifications, since |
| 128 // the RecyclerView will be updated through notifyDataSetChanged. | 160 // the RecyclerView will be updated through notifyDataSetChanged. |
| 129 section.setStatus(CategoryStatus.AVAILABLE); | 161 section.setStatus(CategoryStatus.AVAILABLE); |
| 130 reset(mParent); | 162 reset(mParent); |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 | 759 |
| 728 private static void verifySnippets(SuggestionsSection section, List<SnippetA
rticle> snippets) { | 760 private static void verifySnippets(SuggestionsSection section, List<SnippetA
rticle> snippets) { |
| 729 assertEquals(snippets.size(), section.getSuggestionsCount()); | 761 assertEquals(snippets.size(), section.getSuggestionsCount()); |
| 730 // Indices in section are off-by-one (index 0 is the header). | 762 // Indices in section are off-by-one (index 0 is the header). |
| 731 int index = 1; | 763 int index = 1; |
| 732 for (SnippetArticle snippet : snippets) { | 764 for (SnippetArticle snippet : snippets) { |
| 733 assertEquals(snippet, section.getSuggestionAt(index++)); | 765 assertEquals(snippet, section.getSuggestionAt(index++)); |
| 734 } | 766 } |
| 735 } | 767 } |
| 736 } | 768 } |
| OLD | NEW |