Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Osbourne committed Oct 31, 2023
1 parent ce8ce75 commit dcf7f34
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
16 changes: 13 additions & 3 deletions DuckDuckGo/BrokenSiteInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public struct BrokenSiteInfo {

static let allowedQueryReservedCharacters = CharacterSet(charactersIn: ",")

enum ProtectionsState: String {
case enabled = "1"
case disabled = "0"
}

private struct Keys {
static let url = "siteUrl"
static let category = "category"
Expand All @@ -40,6 +45,7 @@ public struct BrokenSiteInfo {
static let gpc = "gpc"
static let ampUrl = "ampUrl"
static let urlParametersRemoved = "urlParametersRemoved"
static let protectionsState = "protectionsState"
}

private let url: URL?
Expand All @@ -54,12 +60,14 @@ public struct BrokenSiteInfo {
private let manufacturer: String
private let systemVersion: String
private let gpc: Bool

private let protectionsState: ProtectionsState

public init(url: URL?, httpsUpgrade: Bool,
blockedTrackerDomains: [String], installedSurrogates: [String],
isDesktop: Bool, tdsETag: String?,
ampUrl: String?,
urlParametersRemoved: Bool,
protected: Bool,
model: String = UIDevice.current.model,
manufacturer: String = "Apple",
systemVersion: String = UIDevice.current.systemVersion,
Expand All @@ -76,7 +84,8 @@ public struct BrokenSiteInfo {
self.model = model
self.manufacturer = manufacturer
self.systemVersion = systemVersion

self.protectionsState = protected ? .enabled : .disabled

if let gpcParam = gpc {
self.gpc = gpcParam
} else {
Expand All @@ -101,7 +110,8 @@ public struct BrokenSiteInfo {
Keys.model: model,
Keys.gpc: gpc ? "true" : "false",
Keys.ampUrl: ampUrl ?? "",
Keys.urlParametersRemoved: urlParametersRemoved ? "true" : "false"
Keys.urlParametersRemoved: urlParametersRemoved ? "true" : "false",
Keys.protectionsState: protectionsState.rawValue
]

Pixel.fire(pixel: .brokenSiteReport,
Expand Down
8 changes: 6 additions & 2 deletions DuckDuckGo/TabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -866,15 +866,19 @@ class TabViewController: UIViewController {

public func getCurrentWebsiteInfo() -> BrokenSiteInfo {
let blockedTrackerDomains = privacyInfo?.trackerInfo.trackersBlocked.compactMap { $0.domain } ?? []


let configuration = ContentBlocking.shared.privacyConfigurationManager.privacyConfig
let protected = configuration.isFeature(.contentBlocking, enabledForDomain: url?.host)

return BrokenSiteInfo(url: url,
httpsUpgrade: httpsForced,
blockedTrackerDomains: blockedTrackerDomains,
installedSurrogates: privacyInfo?.trackerInfo.installedSurrogates.map { $0 } ?? [],
isDesktop: tabModel.isDesktop,
tdsETag: ContentBlocking.shared.contentBlockingManager.currentMainRules?.etag ?? "",
ampUrl: linkProtection.lastAMPURLString,
urlParametersRemoved: linkProtection.urlParametersRemoved)
urlParametersRemoved: linkProtection.urlParametersRemoved,
protected: protected)
}

public func print() {
Expand Down
1 change: 1 addition & 0 deletions DuckDuckGoTests/BrokenSiteReportingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ final class BrokenSiteReportingTests: XCTestCase {
tdsETag: test.blocklistVersion,
ampUrl: nil,
urlParametersRemoved: false,
protected: true,
model: test.model ?? "",
manufacturer: test.manufacturer ?? "",
systemVersion: test.os ?? "",
Expand Down

0 comments on commit dcf7f34

Please sign in to comment.