diff --git a/BrowserKit/Tests/SiteImageViewTests/ImageProcessing/ImageHandlerTests.swift b/BrowserKit/Tests/SiteImageViewTests/ImageProcessing/ImageHandlerTests.swift index 8119e66dd5e5..354af714fea2 100644 --- a/BrowserKit/Tests/SiteImageViewTests/ImageProcessing/ImageHandlerTests.swift +++ b/BrowserKit/Tests/SiteImageViewTests/ImageProcessing/ImageHandlerTests.swift @@ -63,61 +63,60 @@ final class ImageHandlerTests: XCTestCase { XCTAssertEqual(letterImageGenerator.generateLetterImageCalled, 0) } - // TODO: FXIOS-10642, loading images from the bundle this way doesn't work in XCode 16 -// func testFavicon_whenSiteResourceNil_imageIsInBundle_noCachedImage_returnsBundleImage() async { -// // provide this site url, since the cache key is "google" and default favicons are store with cacheKey as name -// // in bundle -// let siteURL = URL(string: "https://www.google.com")! -// let subject = createSubject() -// let model = SiteImageModel(id: UUID(), imageType: .favicon, siteURL: siteURL) -// let image = await subject.fetchFavicon(imageModel: model) -// -// let siteImageBundle = Bundle.allBundles.first { -// return $0.bundleIdentifier?.contains("SiteImageView-resources") ?? false -// }! -// let expectedImage = UIImage(named: "google", in: siteImageBundle, with: nil) -// XCTAssertEqual(expectedImage, image) -// XCTAssertEqual(siteImageCache.cacheImageCalled, 0) -// XCTAssertEqual(faviconFetcher.fetchImageSucceedCalled, 0) -// XCTAssertEqual(faviconFetcher.fetchImageFailedCalled, 0) -// XCTAssertEqual(letterImageGenerator.generateLetterImageCalled, 0) -// } -// -// func testFavicon_whenSiteResourceNil_imageIsInBundle_cachedImagePresent_returnsBundleImage() async { -// let siteURL = URL(string: "https://www.google.com")! -// siteImageCache.image = UIImage() -// let subject = createSubject() -// let model = SiteImageModel(id: UUID(), imageType: .favicon, siteURL: siteURL) -// let image = await subject.fetchFavicon(imageModel: model) -// -// let siteImageBundle = Bundle.allBundles.first { -// return $0.bundleIdentifier?.contains("SiteImageView-resources") ?? false -// }! -// let expectedImage = UIImage(named: "google", in: siteImageBundle, with: nil) -// XCTAssertEqual(expectedImage, image) -// XCTAssertEqual(siteImageCache.cacheImageCalled, 0) -// XCTAssertEqual(faviconFetcher.fetchImageSucceedCalled, 0) -// XCTAssertEqual(faviconFetcher.fetchImageFailedCalled, 0) -// XCTAssertEqual(letterImageGenerator.generateLetterImageCalled, 0) -// } -// -// func testFavicon_whenSiteResourceIsInBundle_returnsBundleImage() async { -// let siteURL = URL(string: "https://www.facebook.com")! -// let subject = createSubject() -// let resource: SiteResource = .bundleAsset(name: "facebook", forRemoteResource: siteURL) -// let model = SiteImageModel(id: UUID(), imageType: .favicon, siteURL: siteURL, siteResource: resource) -// let image = await subject.fetchFavicon(imageModel: model) -// -// let siteImageBundle = Bundle.allBundles.first { -// return $0.bundleIdentifier?.contains("SiteImageView-resources") ?? false -// }! -// let expectedImage = UIImage(named: "facebook", in: siteImageBundle, with: nil) -// XCTAssertEqual(expectedImage, image) -// XCTAssertEqual(siteImageCache.cacheImageCalled, 0) -// XCTAssertEqual(faviconFetcher.fetchImageSucceedCalled, 0) -// XCTAssertEqual(faviconFetcher.fetchImageFailedCalled, 0) -// XCTAssertEqual(letterImageGenerator.generateLetterImageCalled, 0) -// } + func testFavicon_whenSiteResourceNil_imageIsInBundle_noCachedImage_returnsBundleImage() async { + // provide this site url, since the cache key is "google" and default favicons are store with cacheKey as name + // in bundle + let siteURL = URL(string: "https://www.google.com")! + let subject = createSubject() + let model = SiteImageModel(id: UUID(), imageType: .favicon, siteURL: siteURL) + let image = await subject.fetchFavicon(imageModel: model) + + let siteImageBundle = Bundle.allBundles.first { + return $0.bundleIdentifier?.contains("browserkit.SiteImageView.resources") ?? false + }! + let expectedImage = UIImage(named: "google", in: siteImageBundle, with: nil) + XCTAssertEqual(expectedImage, image) + XCTAssertEqual(siteImageCache.cacheImageCalled, 0) + XCTAssertEqual(faviconFetcher.fetchImageSucceedCalled, 0) + XCTAssertEqual(faviconFetcher.fetchImageFailedCalled, 0) + XCTAssertEqual(letterImageGenerator.generateLetterImageCalled, 0) + } + + func testFavicon_whenSiteResourceNil_imageIsInBundle_cachedImagePresent_returnsBundleImage() async { + let siteURL = URL(string: "https://www.google.com")! + siteImageCache.image = UIImage() + let subject = createSubject() + let model = SiteImageModel(id: UUID(), imageType: .favicon, siteURL: siteURL) + let image = await subject.fetchFavicon(imageModel: model) + + let siteImageBundle = Bundle.allBundles.first { + return $0.bundleIdentifier?.contains("browserkit.SiteImageView.resources") ?? false + }! + let expectedImage = UIImage(named: "google", in: siteImageBundle, with: nil) + XCTAssertEqual(expectedImage, image) + XCTAssertEqual(siteImageCache.cacheImageCalled, 0) + XCTAssertEqual(faviconFetcher.fetchImageSucceedCalled, 0) + XCTAssertEqual(faviconFetcher.fetchImageFailedCalled, 0) + XCTAssertEqual(letterImageGenerator.generateLetterImageCalled, 0) + } + + func testFavicon_whenSiteResourceIsInBundle_returnsBundleImage() async { + let siteURL = URL(string: "https://www.facebook.com")! + let subject = createSubject() + let resource: SiteResource = .bundleAsset(name: "facebook", forRemoteResource: siteURL) + let model = SiteImageModel(id: UUID(), imageType: .favicon, siteURL: siteURL, siteResource: resource) + let image = await subject.fetchFavicon(imageModel: model) + + let siteImageBundle = Bundle.allBundles.first { + return $0.bundleIdentifier?.contains("browserkit.SiteImageView.resources") ?? false + }! + let expectedImage = UIImage(named: "facebook", in: siteImageBundle, with: nil) + XCTAssertEqual(expectedImage, image) + XCTAssertEqual(siteImageCache.cacheImageCalled, 0) + XCTAssertEqual(faviconFetcher.fetchImageSucceedCalled, 0) + XCTAssertEqual(faviconFetcher.fetchImageFailedCalled, 0) + XCTAssertEqual(letterImageGenerator.generateLetterImageCalled, 0) + } func testFavicon_whenNoImages_returnsFallbackLetterFavicon_forHardcodedFaviconURL() async { let subject = createSubject()