Skip to content

Commit

Permalink
Add an integration test for filterlist (disabled)
Browse files Browse the repository at this point in the history
  • Loading branch information
muodov committed Dec 6, 2024
1 parent dca35fd commit 9adcbee
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions IntegrationTests/AutoconsentIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,56 @@ class AutoconsentIntegrationTests: XCTestCase {
XCTAssertTrue(isBannerHidden == true)
}

@MainActor
func disabled_testFilterlistRule_whenFakeCookieBannerIsDisplayed_bannerIsHidden() async throws {
// enable the feature
CookiePopupProtectionPreferences.shared.isAutoconsentEnabled = true
let url = URL(string: "http://privacy-test-pages.site/features/autoconsent/filterlist.html")!
let tab = self.tabViewModel.tab
// expect `cosmetic` to be published
let cookieConsentManagedPromise = tab.privacyInfoPublisher
.compactMap {
return $0?.$cookieConsentManaged
}
.switchToLatest()
.compactMap {
return $0?.isCosmeticRuleApplied == true ? true : nil
}
.receive(on: DispatchQueue.main)
.timeout(10)
.first()
.promise()

_=await tab.setUrl(url, source: .link)?.result

do {
let cookieConsentManaged = try await cookieConsentManagedPromise.value
XCTAssertTrue(cookieConsentManaged == true)
} catch {
struct ErrorWithHTML: Error, LocalizedError, CustomDebugStringConvertible {
let originalError: Error
let html: String

var errorDescription: String? {
(originalError as CustomDebugStringConvertible).debugDescription + "\nHTML:\n\(html)"
}
var debugDescription: String {
errorDescription!
}
}
let html = try await tab.webView.evaluateJavaScript("document.documentElement.outerHTML") as String?

if let html {
throw ErrorWithHTML(originalError: error, html: html)
} else {
throw error
}
}

let isBannerHidden = try await tab.webView.evaluateJavaScript("window.getComputedStyle(banner).opacity === '0'") as Bool?
XCTAssertTrue(isBannerHidden == true)
}

}

private extension CookieConsentInfo {
Expand Down

0 comments on commit 9adcbee

Please sign in to comment.