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
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
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 result = ath.getProviderForMessage(message: mockData)
XCTAssertEqual(result?.name, BasicSearchProvider.google.rawValue)
}
func testGetProviderDuckDuckGo() {
let mockData: [String: String] = ["url": "https://duckduckgo.com/?q=iphone&t=ha&va=j&ia=web"]
let result = ath.getProviderForMessage(message: mockData)
XCTAssertEqual(result?.name, BasicSearchProvider.duckduckgo.rawValue)
}
func testGetProviderBing() {
let result = ath.getProviderForMessage(message: mockData)
XCTAssertEqual(result?.name, BasicSearchProvider.bing.rawValue)
}
func testGetProviderYahoo() {
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]
let urls: [String] = ["https://eune.op.gg"]
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]
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]
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]
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]
XCTAssertEqual(provider.listAdUrls(urls: urls), [])
}
}