Commit bb4205e3 authored by edchin's avatar edchin Committed by Commit Bot

[ios] Fix test ReplaceScrolledOffScreenCell

Re-enables disabled test ReplaceScrolledOffScreenCell.
Uses hardcoded number of items in test instead of flakey
dynamic approach.

Bug: 1104872
Change-Id: Ic7ca34b7fa8936452fbc6efaee12563803eb023e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2450812Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814776}
parent a7402521
...@@ -183,14 +183,7 @@ TEST_F(GridViewControllerTest, MoveUnselectedItem) { ...@@ -183,14 +183,7 @@ TEST_F(GridViewControllerTest, MoveUnselectedItem) {
// Tests that |-replaceItemID:withItem:| does not crash when updating an item // Tests that |-replaceItemID:withItem:| does not crash when updating an item
// that is scrolled offscreen. // that is scrolled offscreen.
TEST_F(GridViewControllerTest, DISABLED_ReplaceScrolledOffScreenCell) { TEST_F(GridViewControllerTest, ReplaceScrolledOffScreenCell) {
// TODO(crbug.com/1104872): On iOS 14 iPhone X, visibleCellsCount is always
// equal to the total number of cells, so the while loop below never
// terminates.
if (@available(iOS 14, *)) {
return;
}
// This test requires that the collection view be placed on the screen. // This test requires that the collection view be placed on the screen.
SetRootViewController(view_controller_); SetRootViewController(view_controller_);
EXPECT_TRUE(base::test::ios::WaitUntilConditionOrTimeout( EXPECT_TRUE(base::test::ios::WaitUntilConditionOrTimeout(
...@@ -198,17 +191,16 @@ TEST_F(GridViewControllerTest, DISABLED_ReplaceScrolledOffScreenCell) { ...@@ -198,17 +191,16 @@ TEST_F(GridViewControllerTest, DISABLED_ReplaceScrolledOffScreenCell) {
return view_controller_.collectionView.visibleCells.count > 0; return view_controller_.collectionView.visibleCells.count > 0;
})); }));
NSArray* items = view_controller_.items; NSArray* items = view_controller_.items;
// Keep adding items until we get an item that is offscreen. Since device // Keep adding items until we get an item that is offscreen.
// sizes may vary, this is better than creating a fixed number of items that // TODO(crbug.com/1104872): Since device sizes may vary, it would be better to
// we think will overflow to offscreen items. // not use a fixed number of items. But that approach (using the count of
NSUInteger visibleCellsCount = // visibleCells) was flakey. 30 items should be plenty to produce offscreen
view_controller_.collectionView.visibleCells.count; // items even on and iPad.
while (visibleCellsCount >= items.count) { while (items.count <= 30) {
NSString* uniqueID = NSString* uniqueID =
[NSString stringWithFormat:@"%d", base::checked_cast<int>(items.count)]; [NSString stringWithFormat:@"%d", base::checked_cast<int>(items.count)];
GridItem* item = [[GridItem alloc] initWithIdentifier:uniqueID]; GridItem* item = [[GridItem alloc] initWithIdentifier:uniqueID];
[view_controller_ insertItem:item atIndex:0 selectedItemID:@"A"]; [view_controller_ insertItem:item atIndex:0 selectedItemID:@"A"];
visibleCellsCount = view_controller_.collectionView.visibleCells.count;
} }
// The last item ("B") is scrolled off screen. // The last item ("B") is scrolled off screen.
GridItem* item = [[GridItem alloc] initWithIdentifier:@"NEW-ITEM"]; GridItem* item = [[GridItem alloc] initWithIdentifier:@"NEW-ITEM"];
......
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