Skip to content

Commit

Permalink
Bugfix FXIOS-10642 #23292 Fix Siteimageview ImageHandlerTests (#23410)
Browse files Browse the repository at this point in the history
* Change bundle name

* Swiftlint
  • Loading branch information
lmarceau authored Nov 26, 2024
1 parent 65b7f9a commit 228d929
Showing 1 changed file with 54 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 228d929

Please sign in to comment.