IGListKit/Tests
Cameron Roth fc3443fb9f Fix VoiceOver infinite recursion crash when delegate set to collectionView (Issue 1658)
Summary:
https://github.com/Instagram/IGListKit/issues/1658

This fix addresses a crash that occurs when VoiceOver is enabled and `scrollViewDelegate` or `collectionViewDelegate` is set to the adapter's own `UICollectionView`.

## The Problem

When VoiceOver is enabled, accessibility queries trigger delegate method calls on the collection view. If the collection view is also set as its own scroll view delegate (via `IGListAdapter`'s proxy), these delegate calls get forwarded back to the collection view, creating infinite recursion:

1. VoiceOver queries accessibility on collectionView
2. `collectionView.delegate` (the proxy) forwards to `scrollViewTarget`
3. `scrollViewTarget` IS the collectionView → back to step 1
4. Stack overflow crash

Example crash-triggering code:
```
adapter.collectionView = collectionView
adapter.scrollViewDelegate = collectionView  // Crash with VoiceOver!
```

## The Fix

Here I've added validation in three places to prevent this configuration:

1. `setScrollViewDelegate:` - Rejects if `delegate == collectionView`
2. `setCollectionViewDelegate:` - Rejects if `delegate == collectionView`
3. `setCollectionView:` - Clears delegates if they equal the new collectionView

## Why This Is Safe (No Negative Side Effects)

**Setting UICollectionView as its own delegate provides no useful functionality:**
- `UICollectionView` already handles scroll events internally (it's a `UIScrollView` subclass)
- The `collectionView` doesn't implement custom `UIScrollViewDelegate` methods
- This configuration ONLY results in crashes when VoiceOver is enabled

**Behavior change is strictly beneficial:**
- Before: Works without VoiceOver, crashes WITH VoiceOver
- After: Silently rejects invalid config, works with VoiceOver

**Developer feedback is preserved:**
- `IGFailAssert` fires in `DEBUG` builds to alert developers to fix their code
- Production gracefully handles the situation instead of crashing

**No breaking changes for valid usage:**
- Normal delegate patterns (separate delegate objects) are unaffected
- Only the invalid self-referential pattern is blocked

See: https://github.com/Instagram/IGListKit/issues/1658

Reviewed By: dinhvh

Differential Revision: D100641752

fbshipit-source-id: a1885c4ede6ca0555f3f94dd0c72b328a5af62bc
2026-04-13 19:35:45 -07:00
..
Assets Support supplementaryViews created from nibs (continued) 2016-11-05 16:29:06 -07:00
Objects Enable unit test suite for tvOS (#1649) 2025-12-11 00:46:38 -08:00
IGListAdapterDelegateAnnouncerTests.m Bring Test Coverage back to > 99% (#1654) 2026-01-27 21:10:09 -08:00
IGListAdapterE2ETests.m Bring Test Coverage back to > 99% (#1654) 2026-01-27 21:10:09 -08:00
IGListAdapterProxyTests.m Standarize the copyright notice in all source files 2023-04-06 02:44:16 -07:00
IGListAdapterStoryboardTests.m Enable unit test suite for tvOS (#1649) 2025-12-11 00:46:38 -08:00
IGListAdapterTests.m Fix VoiceOver infinite recursion crash when delegate set to collectionView (Issue 1658) 2026-04-13 19:35:45 -07:00
IGListAdapterUpdaterTests.m Bring Test Coverage back to > 99% (#1654) 2026-01-27 21:10:09 -08:00
IGListBatchUpdateDataTests.m clean up ig_ios_listkit_fix_net_item_count 2024-12-12 04:02:03 -08:00
IGListBindingSectionControllerTests.m Bring Test Coverage back to > 99% (#1654) 2026-01-27 21:10:09 -08:00
IGListBindingSingleSectionControllerTests.m Add remaining test coverage for IGListBindingSingleSectionController 2023-04-20 14:26:11 -07:00
IGListCollectionScrollingTraitsTests.m Standarize the copyright notice in all source files 2023-04-06 02:44:16 -07:00
IGListCollectionViewLayoutTests.m Adding missing NS_UNAVAILABLE NSCoder constructor declaration to IGListKit 2025-06-24 19:38:02 -07:00
IGListCollectionViewTests.m fbobjc 2025-01-11 10:23:14 -08:00
IGListContentInsetTests.m Standarize the copyright notice in all source files 2023-04-06 02:44:16 -07:00
IGListDebugDescriptionTests.m clean up ig_ios_listkit_fix_net_item_count 2024-12-12 04:02:03 -08:00
IGListDebuggerTests.m Add test coverage for list adapter debugger class 2023-04-17 20:41:49 -07:00
IGListDiffDescriptionStringTests.m clean up ig_ios_listkit_fix_net_item_count 2024-12-12 04:02:03 -08:00
IGListDiffResultTests.m Standarize the copyright notice in all source files 2023-04-06 02:44:16 -07:00
IGListDiffSwiftTests.swift Standarize the copyright notice in all source files 2023-04-06 02:44:16 -07:00
IGListDiffTests.h Standarize the copyright notice in all source files 2023-04-06 02:44:16 -07:00
IGListDiffTests.m Bring IGListDiffKit test coverage to 100% 2023-04-17 20:41:49 -07:00
IGListDisplayHandlerTests.m Add IGListAdapterDelegate Methods 3/n 2025-04-24 13:07:16 -07:00
IGListGenericSectionControllerTests.m Standarize the copyright notice in all source files 2023-04-06 02:44:16 -07:00
IGListInteractiveMovingTests.m fbobjc 2025-01-11 10:23:14 -08:00
IGListItemUpdatesCollectorTests.m Bring Test Coverage back to > 99% (#1654) 2026-01-27 21:10:09 -08:00
IGListKitTests-Bridging-Header.h Standarize the copyright notice in all source files 2023-04-06 02:44:16 -07:00
IGListPerformDiffTests.m Bring Test Coverage back to > 99% (#1654) 2026-01-27 21:10:09 -08:00
IGListReloadDataUpdaterTests.m Bring Test Coverage back to > 99% (#1654) 2026-01-27 21:10:09 -08:00
IGListSectionControllerTests.m Bring Test Coverage back to > 99% (#1654) 2026-01-27 21:10:09 -08:00
IGListSectionMapTests.m Bring Test Coverage back to > 99% (#1654) 2026-01-27 21:10:09 -08:00
IGListSingleNibItemControllerTests.m Enable unit test suite for tvOS (#1649) 2025-12-11 00:46:38 -08:00
IGListSingleSectionControllerTests.m Standarize the copyright notice in all source files 2023-04-06 02:44:16 -07:00
IGListSingleStoryboardItemControllerTests.m Enable unit test suite for tvOS (#1649) 2025-12-11 00:46:38 -08:00
IGListTestCase.h Standarize the copyright notice in all source files 2023-04-06 02:44:16 -07:00
IGListTestCase.m Standarize the copyright notice in all source files 2023-04-06 02:44:16 -07:00
IGListTestHelpers.h Standarize the copyright notice in all source files 2023-04-06 02:44:16 -07:00
IGListTransactionTests.m fix test_withIncorrectUpdatesState_thatInconsistencyExceptionIsCaught 2023-10-31 13:22:24 -07:00
IGListUpdateCoalescerTests.m Bring Test Coverage back to > 99% (#1654) 2026-01-27 21:10:09 -08:00
IGListViewVisibilityTrackerTests.m Bring Test Coverage back to > 99% (#1654) 2026-01-27 21:10:09 -08:00
IGListWorkingRangeHandlerTests.m Standarize the copyright notice in all source files 2023-04-06 02:44:16 -07:00
Info.plist Update deployment targets to silence Xcode 14 warnings (#1573) 2023-05-01 22:48:23 -07:00
UIViewControllerIGListAdapterTests.m Bring Test Coverage back to > 99% (#1654) 2026-01-27 21:10:09 -08:00