Revision control
Copy as Markdown
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
import XCTest
#if FOCUS
@testable import Firefox_Focus
#else
@testable import Firefox_Klar
#endif
class TrackingAdsTests: XCTestCase {
let ath = AdsTelemetryHelper()
func testGetProviderNil() {
let mockData: [String: String] = ["url": "saasj"]
let result = ath.getProviderForMessage(message: mockData)
XCTAssertEqual(result?.name, nil)
}
func testGetProviderGoogle() {
let mockData: [String: String] = ["url": "https://www.google.com/search?q=iphone&rlz=1C5CHFA_enRO979RO979&oq=iphone&aqs=chrome..69i57j0i512l9.2034j0j7&sourceid=chrome&ie=UTF-8"]
let result = ath.getProviderForMessage(message: mockData)
XCTAssertEqual(result?.name, BasicSearchProvider.google.rawValue)
}
func testGetProviderDuckDuckGo() {
let result = ath.getProviderForMessage(message: mockData)
XCTAssertEqual(result?.name, BasicSearchProvider.duckduckgo.rawValue)
}
func testGetProviderBing() {
let mockData: [String: String] = ["url": "https://www.bing.com/search?q=iphone&form=QBLH&sp=-1&pq=ipho&sc=10-4&qs=n&sk=&cvid=3AE803700EA346D0A67F5E6FE8E661A9&ghsh=0&ghacc=0&ghpl="]
let result = ath.getProviderForMessage(message: mockData)
XCTAssertEqual(result?.name, BasicSearchProvider.bing.rawValue)
}
func testGetProviderYahoo() {
let mockData: [String: String] = ["url": "https://ro.search.yahoo.com/search?p=iphone&fr=yfp-t&fr2=p%3Afp%2Cm%3Asb&ei=UTF-8&fp=1"]
let result = ath.getProviderForMessage(message: mockData)
XCTAssertEqual(result?.name, BasicSearchProvider.yahoo.rawValue)
}
func testListAdUrlsNil() {
let provider = SearchProviderModel.searchProviderList[0]
let urls: [String] = []
XCTAssertEqual(provider.listAdUrls(urls: urls), [])
}
func testListAdUrlsWrongURL() {
let provider = SearchProviderModel.searchProviderList[0]
XCTAssertEqual(provider.listAdUrls(urls: urls), [])
}
func testListAdUrlsGoogle() {
let provider = SearchProviderModel.searchProviderList[0]
XCTAssertEqual(provider.listAdUrls(urls: urls), urls)
}
func testListAdUrlsGoogleFromMoreUrls() {
let provider = SearchProviderModel.searchProviderList[0]
let urls: [String] = ["https://www.googleadservices.com/pagead/aclk?sa=L&ai=DChcSEwih-5P99c35AhUGkGgJHXg8DEoYABAMGgJ3Zg&ohost=www.google.com&cid=CAASJeRoYucil5gTx1Dra7a5t4AxPQJZ8Lm70ggAP3L_VOoLiZZzUuw&sig=AOD64_1dSBtVL11huUaOUS4NYZZgwPM9Cg&ctype=5&q=&ved=2ahUKEwiM8Iz99c35AhXwh_0HHacsALkQwg8oAHoECAEQCw&adurl=", "https://eune.op.gg"]
XCTAssertEqual(provider.listAdUrls(urls: urls), [urls[0]])
}
func testListAdUrlsDuckDuckGo() {
XCTSkip("#3693 - Test failed on XCode 14.1 and MacOS 13 on Bitrise")
let provider = SearchProviderModel.searchProviderList[1]
XCTAssertEqual(provider.listAdUrls(urls: urls), [])
}
func testListAdUrlsDuckDuckGoFromMoreUrls() {
let provider = SearchProviderModel.searchProviderList[1]
let urls: [String] = ["https://www.googleadservices.com/pagead/aclk?sa=L&ai=DChcSEwih-5P99c35AhUGkGgJHXg8DEoYABAMGgJ3Zg&ohost=www.google.com&cid=CAASJeRoYucil5gTx1Dra7a5t4AxPQJZ8Lm70ggAP3L_VOoLiZZzUuw&sig=AOD64_1dSBtVL11huUaOUS4NYZZgwPM9Cg&ctype=5&q=&ved=2ahUKEwiM8Iz99c35AhXwh_0HHacsALkQwg8oAHoECAEQCw&adurl=", "https://eune.op.gg"]
XCTAssertEqual(provider.listAdUrls(urls: urls), [])
}
func testListAdUrlsBing() {
let provider = SearchProviderModel.searchProviderList[3]
XCTAssertEqual(provider.listAdUrls(urls: urls), urls)
}
func testListAdUrlsBingFromMoreUrls() {
let provider = SearchProviderModel.searchProviderList[3]
let urls: [String] = ["https://www.bing.com/aclick?ld=e8ksZMewU3OvVXAtm0bMf8MjVUCUyvjlOgnO69Tj5FxmIJ0M5G4_lITqu8IiD1X1070BKQb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sa2lkJTNkZDZhMDAxZWI2YTIzMTFmMzdkNTc2MzE3OTg3YTk3Mzc&rlid=d6a001eb6a2311f37d576317987a9737", "https://eune.op.gg"]
XCTAssertEqual(provider.listAdUrls(urls: urls), [urls[0]])
}
func testListAdUrlsYahoo() {
let provider = SearchProviderModel.searchProviderList[2]
XCTAssertEqual(provider.listAdUrls(urls: urls), [])
}
func testListAdUrlsYahooFromMoreUrls() {
let provider = SearchProviderModel.searchProviderList[2]
let urls: [String] = ["https://www.googleadservices.com/pagead/aclk?sa=L&ai=DChcSEwih-5P99c35AhUGkGgJHXg8DEoYABAMGgJ3Zg&ohost=www.google.com&cid=CAASJeRoYucil5gTx1Dra7a5t4AxPQJZ8Lm70ggAP3L_VOoLiZZzUuw&sig=AOD64_1dSBtVL11huUaOUS4NYZZgwPM9Cg&ctype=5&q=&ved=2ahUKEwiM8Iz99c35AhXwh_0HHacsALkQwg8oAHoECAEQCw&adurl=", "https://eune.op.gg"]
XCTAssertEqual(provider.listAdUrls(urls: urls), [])
}
}