Repository: SDWebImage/SDWebImage
File: Tests/Tests/SDAnimatedImageTest.m (Objective-C)

Code before:
            flag = false;
        } else if (index == 0) {
            cnt++;
            flag = true;
        }
        
        if (flag) {
            i++;
        } else {
            i--;
        }

        if (cnt >= 2) {
            [expectation fulfill];
            // Stop Animation to avoid extra callback
            [wimageView.player stopPlaying];
            [wimageView removeFromSuperview];
        }
    }];
    [player startPlaying];
    
    [self waitForExpectationsWithTimeout:15 handler:nil];
}

- (void)test36AnimatedImageMemoryCost {
    [[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];
    UIImage *image = [UIImage sd_imageWithData:[NSData dataWithContentsOfFile:[self testMemotyCostImagePath]]];
    NSUInteger cost = [image sd_memoryCost];
    expect(image.images.count).equal(5333);
    expect(image.scale).equal(1);
    expect(cost).equal(16 * image.size.width * image.size.height * 4);
}

#pragma mark - Helper
- (UIWindow *)window {
    if (!_window) {
        UIScreen *mainScreen = [UIScreen mainScreen];
#if SD_UIKIT
        _window = [[UIWindow alloc] initWithFrame:mainScreen.bounds];
#else
        _window = [[NSWindow alloc] initWithContentRect:mainScreen.frame styleMask:0 backing:NSBackingStoreBuffered defer:NO screen:mainScreen];
#endif
    }
    return _window;
}

- (NSString *)testGIFPath {
    NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
    NSString *testPath = [testBundle pathForResource:@"TestImage" ofType:@"gif"];
    return testPath;
}

Review comment (suggestion):
~Since `SDImageIOCoder` can decode WebP as well on iOS 14. I think we don't need to do anything here.~
Sorry, this is Animated WebP, not static webp.

Code after:
        } else if (index == 0) {
            cnt++;
            flag = true;
        }
        
        if (flag) {
            i++;
        } else {
            i--;
        }

        if (cnt >= 2) {
            [expectation fulfill];
            // Stop Animation to avoid extra callback
            [wimageView.player stopPlaying];
            [wimageView removeFromSuperview];
        }
    }];
    [player startPlaying];
    
    [self waitForExpectationsWithTimeout:15 handler:nil];
}

- (void)test36AnimatedImageMemoryCost {
    if (@available(iOS 14, tvOS 14, macOS 11, watchOS 7, *)) {
        [[SDImageCodersManager sharedManager] addCoder:[SDImageAWebPCoder sharedCoder]];
        UIImage *image = [UIImage sd_imageWithData:[NSData dataWithContentsOfFile:[self testMemotyCostImagePath]]];
        NSUInteger cost = [image sd_memoryCost];
        expect(image.images.count).equal(5333);
        expect(image.scale).equal(1);
        expect(cost).equal(16 * image.size.width * image.size.height * 4);
        [[SDImageCodersManager sharedManager] removeCoder:[SDImageAWebPCoder sharedCoder]];
    }
}

#pragma mark - Helper
- (UIWindow *)window {
    if (!_window) {
        UIScreen *mainScreen = [UIScreen mainScreen];
#if SD_UIKIT
        _window = [[UIWindow alloc] initWithFrame:mainScreen.bounds];
#else
        _window = [[NSWindow alloc] initWithContentRect:mainScreen.frame styleMask:0 backing:NSBackingStoreBuffered defer:NO screen:mainScreen];
#endif
    }
    return _window;
}

- (NSString *)testGIFPath {
    NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
    NSString *testPath = [testBundle pathForResource:@"TestImage" ofType:@"gif"];