Commit 49983345 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Fix section reload in NTP

When a ContentSuggestions section is reloaded in the NTP, it is possible
that new sections/items in other sections are added.
This CL makes sure that the collection is updated to take those new
elements into account.

Bug: 866849
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Id474ca33afdafb18871b2bb77e4a94e8bfe1cc68
Reviewed-on: https://chromium-review.googlesource.com/1154986
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579416}
parent 5d41d7b5
......@@ -336,9 +336,6 @@ NSString* const kContentSuggestionsCollectionUpdaterSnackbarCategory =
for (NSInteger i = 0; i < numberOfItems; i++) {
[oldItems addObject:[NSIndexPath indexPathForItem:i inSection:section]];
}
[self.collectionViewController
collectionView:self.collectionViewController.collectionView
willDeleteItemsAtIndexPaths:oldItems];
// Reset collection model data for |sectionIdentifier|
[self.collectionViewController.collectionViewModel
......@@ -349,11 +346,30 @@ NSString* const kContentSuggestionsCollectionUpdaterSnackbarCategory =
forSectionWithIdentifier:sectionIdentifier];
[self.sectionIdentifiersFromContentSuggestions
removeObject:@(sectionIdentifier)];
[self.collectionViewController.collectionViewModel
removeSectionWithIdentifier:sectionIdentifier];
[self addSectionsForSectionInfoToModel:@[ sectionInfo ]];
[self addSuggestionsToModel:[self.dataSource itemsForSectionInfo:sectionInfo]
// Update the section and the other ones.
auto addSectionBlock = ^{
[self.collectionViewController.collectionViewModel
removeSectionWithIdentifier:sectionIdentifier];
[self.collectionViewController.collectionView
deleteSections:[NSIndexSet indexSetWithIndex:section]];
NSIndexSet* addedSections =
[self addSectionsForSectionInfoToModel:@[ sectionInfo ]];
[self.collectionViewController.collectionView insertSections:addedSections];
NSArray<NSIndexPath*>* addedItems = [self
addSuggestionsToModel:[self.dataSource itemsForSectionInfo:sectionInfo]
withSectionInfo:sectionInfo];
[self.collectionViewController.collectionView
insertItemsAtIndexPaths:addedItems];
};
[self.collectionViewController.collectionView
performBatchUpdates:addSectionBlock
completion:nil];
// Make sure we get the right index for the section.
section = [model sectionForSectionIdentifier:sectionIdentifier];
[self.collectionViewController.collectionView
reloadSections:[NSIndexSet indexSetWithIndex:section]];
......
......@@ -794,8 +794,10 @@ GREYElementInteraction* CellWithMatcher(id<GREYMatcher> matcher) {
// Check the tile is back.
[[EarlGrey selectElementWithMatcher:
chrome_test_util::StaticTextWithAccessibilityLabel(pageTitle)]
assertWithMatcher:grey_sufficientlyVisible()];
grey_allOf(chrome_test_util::StaticTextWithAccessibilityLabel(
pageTitle),
grey_sufficientlyVisible(), nil)]
assertWithMatcher:grey_notNil()];
}
// Tests that the context menu has the correct actions.
......
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