Commit d8b03037 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Handle case in BadgeMediator when there are no badges

If there are no badges retrieved from GetInfobarBadgeItems(),
then just set self.badges to nil instead of attempting to copy the vector
into an array.

Bug: 1016360
Change-Id: I591e48ad28232856da6e0ce695850522e37d425d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872484Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709742}
parent a4f9f94e
...@@ -42,6 +42,8 @@ class InfobarBadgeTabHelper ...@@ -42,6 +42,8 @@ class InfobarBadgeTabHelper
void UpdateBadgeForInfobarBannerDismissed(InfobarType infobar_type); void UpdateBadgeForInfobarBannerDismissed(InfobarType infobar_type);
// Returns all BadgeItems for the TabHelper Webstate. // Returns all BadgeItems for the TabHelper Webstate.
// TODO(crbug.com/1016360): Consider changing to return an array instead of a
// vector here.
std::vector<id<BadgeItem>> GetInfobarBadgeItems(); std::vector<id<BadgeItem>> GetInfobarBadgeItems();
~InfobarBadgeTabHelper() override; ~InfobarBadgeTabHelper() override;
......
...@@ -285,9 +285,15 @@ const int kMinimumNonFullScreenBadgesForOverflow = 2; ...@@ -285,9 +285,15 @@ const int kMinimumNonFullScreenBadgesForOverflow = 2;
// InfobarBadgeTabHelper for all the badges for that WebState. // InfobarBadgeTabHelper for all the badges for that WebState.
std::vector<id<BadgeItem>> infobarBadges = std::vector<id<BadgeItem>> infobarBadges =
infobarBadgeTabHelper->GetInfobarBadgeItems(); infobarBadgeTabHelper->GetInfobarBadgeItems();
// Copy all contents of vector into array. if (infobarBadges.size() == 0) {
self.badges = [[NSArray arrayWithObjects:&infobarBadges[0] // If there are no Infobar badges, then just set |badges| to nil since
count:infobarBadges.size()] mutableCopy]; // &infobarBadges[0] will fail.
self.badges = nil;
} else {
// Copy all contents of vector into array.
self.badges = [NSMutableArray arrayWithObjects:&infobarBadges[0]
count:infobarBadges.size()];
}
id<BadgeItem> displayedBadge; id<BadgeItem> displayedBadge;
if ([self.badges count] > 1) { if ([self.badges count] > 1) {
// Show the overflow menu badge when there are multiple badges. // Show the overflow menu badge when there are multiple badges.
......
...@@ -152,6 +152,14 @@ class BadgeMediatorTest : public PlatformTest { ...@@ -152,6 +152,14 @@ class BadgeMediatorTest : public PlatformTest {
FakeWebStateListDelegate web_state_list_delegate_; FakeWebStateListDelegate web_state_list_delegate_;
}; };
// Test that the BadgeMediator responds with no displayed and fullscreen badge
// when there are no Infobars added and the BrowserState is not OffTheRecord.
TEST_F(BadgeMediatorTest, BadgeMediatorTestNoInfobar) {
AddAndActivateWebState(0, false);
EXPECT_FALSE(badge_consumer_.displayedBadge);
EXPECT_FALSE(badge_consumer_.hasIncognitoBadge);
}
// Test that the BadgeMediator responds with one new badge when an infobar is // Test that the BadgeMediator responds with one new badge when an infobar is
// added // added
TEST_F(BadgeMediatorTest, BadgeMediatorTestAddInfobar) { TEST_F(BadgeMediatorTest, BadgeMediatorTestAddInfobar) {
......
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