Commit a757a98d authored by gambard's avatar gambard Committed by Commit bot

Do not reload UI if the Reading List entry does not exist

The custom accessibility actions check for the existence of the ReadingListModel
entry when configuring a cell. This CL changes this behavior to do nothing when
the entry does not exist instead of reloading the UI.

BUG=676290, 701956

Review-Url: https://codereview.chromium.org/2750623006
Cr-Commit-Position: refs/heads/master@{#457382}
parent 8552274e
......@@ -120,7 +120,7 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
// Stops observing the ReadingListModel.
- (void)stopObservingReadingListModel;
// Returns the ReadingListEntry associated with the |item|. If there is not such
// an entry, returns nullptr and reloads the UI.
// an entry, returns nullptr.
- (const ReadingListEntry*)readingListEntryForItem:
(ReadingListCollectionViewItem*)item;
// Updates the toolbar state according to the selected items.
......@@ -698,12 +698,6 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
const ReadingListEntry* readingListEntry =
self.readingListModel->GetEntryByURL(item.url);
if (!readingListEntry) {
// The entry has been removed from the model, reload all data to synchronize
// the UI with the model.
[self reloadData];
}
return readingListEntry;
}
......
......@@ -13,6 +13,7 @@
#import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
#include "ios/chrome/browser/ui/commands/ios_command_ids.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_empty_collection_background.h"
#include "ios/chrome/browser/ui/ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ios/chrome/grit/ios_theme_resources.h"
......@@ -195,6 +196,12 @@ size_t ModelReadSize(ReadingListModel* model) {
}
return size;
}
// Returns a match for the Reading List Empty Collection Background.
id<GREYMatcher> EmptyBackground() {
return grey_accessibilityID(
[ReadingListEmptyCollectionBackground accessibilityIdentifier]);
}
} // namespace
// Test class for the Reading List menu.
......@@ -528,4 +535,29 @@ size_t ModelReadSize(ReadingListModel* model) {
GetReadingListModel()->unread_size());
}
// Tests that you can delete multiple read items in the Reading List without
// creating a crash (crbug.com/701956).
- (void)testDeleteMultipleItems {
// Add entries.
ReadingListModel* model = GetReadingListModel();
for (int i = 0; i < 11; i++) {
std::string increment = std::to_string(i);
model->AddEntry(GURL(kReadURL + increment),
std::string(kReadTitle + increment),
reading_list::ADDED_VIA_CURRENT_APP);
model->SetReadStatus(GURL(kReadURL + increment), true);
}
// Delete them from the Reading List view.
OpenReadingList();
[[EarlGrey selectElementWithMatcher:EmptyBackground()]
assertWithMatcher:grey_nil()];
TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON);
TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON);
// Verify the background string is displayed.
[[EarlGrey selectElementWithMatcher:EmptyBackground()]
assertWithMatcher:grey_notNil()];
}
@end
......@@ -14,6 +14,8 @@
- (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
+ (NSString*)accessibilityIdentifier;
@end
#endif // IOS_CHROME_BROWSER_UI_READING_LIST_READING_LIST_EMPTY_COLLECTION_BACKGROUND_H_
......@@ -64,6 +64,8 @@ const CGFloat kPercentageFromTopForPosition = 0.4;
@implementation ReadingListEmptyCollectionBackground
#pragma mark - Public
- (instancetype)init {
self = [super initWithFrame:CGRectZero];
if (self) {
......@@ -172,6 +174,8 @@ const CGFloat kPercentageFromTopForPosition = 0.4;
label.numberOfLines = 0;
label.textAlignment = NSTextAlignmentCenter;
label.accessibilityLabel = accessibilityLabel;
label.accessibilityIdentifier =
[ReadingListEmptyCollectionBackground accessibilityIdentifier];
[label setTranslatesAutoresizingMaskIntoConstraints:NO];
[self addSubview:label];
......@@ -185,6 +189,12 @@ const CGFloat kPercentageFromTopForPosition = 0.4;
return self;
}
+ (NSString*)accessibilityIdentifier {
return @"ReadingListBackgroundViewIdentifier";
}
#pragma mark - Private
- (void)attachIconNamed:(NSString*)iconName
toString:(NSMutableAttributedString*)instructionString
withCaret:(NSMutableAttributedString*)caret
......
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