Commit ce0e6322 authored by treib's avatar treib Committed by Commit bot

Cleanup: Remove CategoryStatus::SIGNED_OUT

BUG=699979

Review-Url: https://codereview.chromium.org/2740783004
Cr-Commit-Position: refs/heads/master@{#456073}
parent f351604c
......@@ -164,10 +164,6 @@ public class SectionList
removeSection(mSections.get(category));
return;
case CategoryStatus.SIGNED_OUT:
resetSection(category, status, /* alwaysAllowEmptySections = */ false);
return;
default:
mSections.get(category).setStatus(status);
return;
......
......@@ -42,7 +42,6 @@ public class SnippetsBridge
case CategoryStatus.INITIALIZING:
case CategoryStatus.AVAILABLE:
case CategoryStatus.AVAILABLE_LOADING:
case CategoryStatus.SIGNED_OUT:
return true;
}
return false;
......
......@@ -277,15 +277,18 @@ public class NewTabPageAdapterTest {
mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.AVAILABLE);
assertItemsFor(section(4));
// When the category is disabled, the suggestions are cleared and we should go back to
// the situation with the status card.
mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.SIGNED_OUT);
assertItemsFor(sectionWithStatusCard());
// When the category is disabled, the section should go away completely.
mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.CATEGORY_EXPLICITLY_DISABLED);
assertItemsFor();
// The adapter should now be waiting for new suggestions.
// Now we're in the "all dismissed" state. No suggestions should be accepted.
suggestions = createDummySuggestions(6, TEST_CATEGORY);
mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.AVAILABLE);
mSource.setSuggestionsForCategory(TEST_CATEGORY, suggestions);
assertItemsFor();
// After a full refresh, the adapter should accept suggestions again.
mSource.fireFullRefreshRequired();
assertItemsFor(section(6));
}
......@@ -306,20 +309,26 @@ public class NewTabPageAdapterTest {
suggestions.add(new SnippetArticle(TEST_CATEGORY, "https://site.com/url1", "title1", "pub1",
"txt1", "https://site.com/url1", 0, 0, 0));
// When suggestion are disabled, we should not be able to load them.
mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.SIGNED_OUT);
// When the provider is removed, we should not be able to load suggestions. The UI should
// stay the same though.
mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.NOT_PROVIDED);
mSource.setSuggestionsForCategory(TEST_CATEGORY, suggestions);
assertItemsFor(sectionWithStatusCard());
assertItemsFor(section(3));
// INITIALIZING lets us load suggestion still.
// INITIALIZING lets us load suggestions still.
mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.INITIALIZING);
mSource.setSuggestionsForCategory(TEST_CATEGORY, suggestions);
assertItemsFor(sectionWithStatusCard().withProgress());
// The adapter should now be waiting for new suggestion and the fourth one should appear.
// The adapter should now be waiting for new suggestions and the fourth one should appear.
mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.AVAILABLE);
mSource.setSuggestionsForCategory(TEST_CATEGORY, suggestions);
assertItemsFor(section(4));
// When the category gets disabled, the section should go away and not load any suggestions.
mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.CATEGORY_EXPLICITLY_DISABLED);
mSource.setSuggestionsForCategory(TEST_CATEGORY, suggestions);
assertItemsFor();
}
/**
......@@ -341,8 +350,10 @@ public class NewTabPageAdapterTest {
mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.AVAILABLE_LOADING);
assertTrue(progress.isVisible());
mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.SIGNED_OUT);
assertFalse(progress.isVisible());
// After the section gets disabled, it should gone completely, so checking the progress
// indicator doesn't make sense anymore.
mSource.setStatusForCategory(TEST_CATEGORY, CategoryStatus.CATEGORY_EXPLICITLY_DISABLED);
assertEquals(mAdapter.getSectionListForTesting().getSectionForTesting(TEST_CATEGORY), null);
}
/**
......@@ -733,11 +744,12 @@ public class NewTabPageAdapterTest {
suggestionsSource.setSuggestionsForCategory(
TEST_CATEGORY, createDummySuggestions(0, TEST_CATEGORY));
mAdapter.getSectionListForTesting().onCategoryStatusChanged(
TEST_CATEGORY, CategoryStatus.SIGNED_OUT);
verify(dataObserver).onItemRangeRemoved(2, newSuggestionCount);
verify(dataObserver).onItemRangeChanged(4, 1, null); // Spacer refresh
verify(dataObserver).onItemRangeInserted(2, 1); // Status card added
verify(dataObserver).onItemRangeChanged(5, 1, null); // Spacer refresh
TEST_CATEGORY, CategoryStatus.CATEGORY_EXPLICITLY_DISABLED);
// All suggestions as well as the header and the action should be gone.
verify(dataObserver).onItemRangeRemoved(1, newSuggestionCount + 2);
// The spacer gets refreshed twice: Once when the section is removed, and then again when
// the "all dismissed" item gets added.
verify(dataObserver, times(2)).onItemRangeChanged(2, 1, null);
}
@Test
......
......@@ -183,7 +183,7 @@ public class SuggestionsSectionTest {
verifyNoMoreInteractions(mParent);
// We clear existing suggestions when the status is not AVAILABLE, and show the status card.
section.setStatus(CategoryStatus.SIGNED_OUT);
section.setStatus(CategoryStatus.CATEGORY_EXPLICITLY_DISABLED);
verify(mParent).onItemRangeRemoved(section, 1, suggestionCount);
verify(mParent).onItemRangeInserted(section, 1, 1);
......
......@@ -152,19 +152,9 @@ class ContentSuggestionsNotifierService::NotifyingObserver
if (!category.IsKnownCategory(KnownCategories::ARTICLES)) {
return;
}
switch (new_status) {
case CategoryStatus::AVAILABLE:
case CategoryStatus::AVAILABLE_LOADING:
break; // nothing to do
case CategoryStatus::INITIALIZING:
case CategoryStatus::ALL_SUGGESTIONS_EXPLICITLY_DISABLED:
case CategoryStatus::CATEGORY_EXPLICITLY_DISABLED:
case CategoryStatus::LOADING_ERROR:
case CategoryStatus::NOT_PROVIDED:
case CategoryStatus::SIGNED_OUT:
ContentSuggestionsNotificationHelper::HideAllNotifications(
CONTENT_SUGGESTIONS_HIDE_DISABLED);
break;
if (!ntp_snippets::IsCategoryStatusAvailable(new_status)) {
ContentSuggestionsNotificationHelper::HideAllNotifications(
CONTENT_SUGGESTIONS_HIDE_DISABLED);
}
}
......
......@@ -76,9 +76,6 @@ std::ostream& operator<<(std::ostream& os, const CategoryStatus& value) {
case CategoryStatus::CATEGORY_EXPLICITLY_DISABLED:
os << "CATEGORY_EXPLICITLY_DISABLED";
break;
case CategoryStatus::SIGNED_OUT:
os << "SIGNED_OUT";
break;
case CategoryStatus::LOADING_ERROR:
os << "LOADING_ERROR";
break;
......
......@@ -75,8 +75,6 @@ std::string GetCategoryStatusName(CategoryStatus status) {
return "ALL_SUGGESTIONS_EXPLICITLY_DISABLED";
case CategoryStatus::CATEGORY_EXPLICITLY_DISABLED:
return "CATEGORY_EXPLICITLY_DISABLED";
case CategoryStatus::SIGNED_OUT:
return "SIGNED_OUT";
case CategoryStatus::LOADING_ERROR:
return "LOADING_ERROR";
}
......
......@@ -90,6 +90,13 @@ public class FakeSuggestionsSource implements SuggestionsSource {
mObserver.onSuggestionInvalidated(category, idWithinCategory);
}
/**
* Notifies the observer that a full refresh is required.
*/
public void fireFullRefreshRequired() {
mObserver.onFullRefreshRequired();
}
/**
* Removes a category from the fake source without notifying anyone.
*/
......
......@@ -31,9 +31,6 @@ enum class CategoryStatus {
// the service configuration.
CATEGORY_EXPLICITLY_DISABLED,
// Content suggestions are not available because the user is not signed in.
SIGNED_OUT,
// Content suggestions are not available because an error occurred when
// loading or updating them.
LOADING_ERROR
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment